keeperfx icon indicating copy to clipboard operation
keeperfx copied to clipboard

Savegame files must have the correct (exact) size

Open AleWin32 opened this issue 3 years ago • 4 comments

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:

  • Start a new game
  • Save a game on first slot
  • Open the savegame file (fx1g000X.sav) with an hexadecimal editor
  • Add some random bytes at the end of the file
  • Load the savegame from first slot (it will work, it will ignore extra bytes if all headers are good)
  • Save the game again on first slot

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

AleWin32 avatar Aug 31 '22 09:08 AleWin32

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.

AleWin32 avatar Aug 31 '22 09:08 AleWin32

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

PieterVdc avatar Sep 01 '22 15:09 PieterVdc

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

xtremeqg avatar Sep 17 '22 21:09 xtremeqg

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

Loobinex avatar Sep 17 '22 23:09 Loobinex