I'm learning C++, and as a learning project I'm trying to write an application that will read the information from an FF7 save file ("savexx.ff7") and display it on screen.
I've created the following structures:
struct FF7HEAD { // The header part of the FF7 save
unsigned char dummy [11];
} ;
struct FF7DESC { // The save description part
USHORT checksum;
BYTE level;
BYTE charOne, charTwo, charThree;
STRING name[16];
short charCHP;
short charMHP;
short charCMP;
short charMMP;
long gil;
long time;
STRING location[32];
} ;
struct FF7SLOT { // The individual save slot
FF7DESC description;
} ;
struct FF7 { // The save file as a whole.
FF7HEAD header;
FF7SLOT slotOne;
} ff7file;
In my main() function, I load the save file into the memory location of ff7file (see above for it)
int main() {
FILE *ff7save;
char ff7name[] = "save00.ff7";
ff7save = fopen(ff7name, "rb");
fread(&ff7file, sizeof(ff7file), 1, ff7save);
cout << "Header:\n";
for(int i=0; i<11; i++) {
cout << (int)ff7file.header.dummy[i] << " ";
}
[snip -- just output code here]
}
the above code doesn't load the correct values into the right spot (i think they're offset a bit but i'm too tired to check right now).
when you jumble the code around and load the FF7HEAD and FF7 object (minus the header) seperately it does work... except when you get to loading gil, where it loads the 4 bytes two bytes after the current file position.
I'm pretty much a newb at c++ (have experience with PHP and java) and this is giving me a real headache... you guys are great at this kind of stuff... can you help me please?
Do note there are a bunch of shortcuts in there (the header simply contains 'dummy[]' instead of actual variables, etc), since I suck so much at C++.
(footnote: the above code was sloppily 'renewed' back to the original loading method so if anything doesn't work i screwed it up -- or i'm just a newb)
Oh, and the output that version creates is...
Header:
113 115 39 6 0 1 0 0 0 5 99
Checksum:
1792
Character Level: 0
Character 1: Barret
Character 2: None
Character 3: Unknown
HP: 14080/11777
MP: 14592/16384
Gil Held: 135168 4
Playtime: 240070144 seconds
And I'm using Dev-C++ if you wanted to know.
Mod Edit: Do not double-post