dkfans / keeperfx

Open source remake and Fan Expansion of Dungeon Keeper.
https://keeperfx.net/
GNU General Public License v2.0
718 stars 73 forks source link

Savegame files must have the correct (exact) size #1815

Open AleWin32 opened 1 year ago

AleWin32 commented 1 year ago

I am developping a binary template for parsing KeeperFX savegame files (i think it can be interesting to help debug) and i get confused when my code parsed the savegame file: there were extra bytes from the end of the file, so my code throwed an error.

This is because i downgraded my KeeperFX version and now the savegame files are lower in size, so if you play it (starting a new game) and now you do a savegame over that file, if it's lower in size, it keeps the extra bytes (that were from a most modern KeeperFX version that had more data).

Will be more clear (and disk space saving) that the savegame does not preserve extra bytes, and simply keep the exact savegame format size.

You can reproduce that in this way:

You will notice in the hexadecimal editor that the extra bytes are kept on the savegame file.

AleWin32 commented 1 year ago

In future KeeperFX versions, if hardcoded limit values are changed to be dynamic, savegame file sizes can vary in size and be small (for example now thing limit is 2048, but if we only have 1500 things in the level, 548 will not be written on the file), so this will save disk space and unnecessary data.

PieterVdc commented 1 year ago

the first one, I guess it usually gets bigger and rarely smaller between versions, but yeah does sound like something that shouldn't happen, the second one sure would be better, but idk if anyone would care about a couple mb more or less save file wise

xtremeqg commented 1 year ago

Save files are overwritten, they are not truncated before writing. So any trailing bytes simply remain.

Loobinex commented 1 year ago

Relevant: https://keeperklan.com/threads/7382