Skip to content

Instantly share code, notes, and snippets.

@nramsbottom
Created May 11, 2014 01:05
Show Gist options
  • Select an option

  • Save nramsbottom/3a4d9e7dc267c9ee61b8 to your computer and use it in GitHub Desktop.

Select an option

Save nramsbottom/3a4d9e7dc267c9ee61b8 to your computer and use it in GitHub Desktop.
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <stdio.h>
#include <stdint.h>
#include <conio.h>
int albion_boost_gold(const char *filename, uint16_t gold_to_give) {
int fd;
char buf[4];
uint16_t gold;
char found = 0;
// open save file
fd = _open(filename, _O_RDWR);
if (fd == -1) {
printf("error: failed to open file.\n");
return 1;
}
// scan until we find the first "XLD0"
while (!_eof(fd)) {
_read(fd, buf, 4);
if (buf[0] == 'X' && buf[1] == 'L' && buf[2] == 'D' && buf[3] == '0') {
//printf("found xld0 at offset %X\n", _lseek(fd, 0, SEEK_CUR));
found = 1;
break;
}
}
if (!found) {
printf("error: unable to locate XLD record.\n");
return 2;
}
// skip 245 bytes to the start of the "hero" record
_lseek(fd, 245, SEEK_CUR);
// skip to the gold
_lseek(fd, 15, SEEK_CUR);
// read existing value
_read(fd, &gold, 2);
_lseek(fd, -2, SEEK_CUR);
printf("Tom has %d gold. Do you want to boost? : ",
gold / 10);
if (_getch() != 'y') {
printf("\n");
return 3;
}
printf("\nBoosting by %d to %d.\n",
gold_to_give,
gold / 10 + gold_to_give);
// increase "Tom" character gold by X
gold += gold_to_give * 10;
_write(fd, &gold, 2);
// close save file
_close(fd);
return 0;
}
int main(int argc, char *argv[]) {
if (argc <= 1) {
printf("error: filename required.\n");
return 1;
}
return albion_boost_gold(argv[1], 100);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment