Saving player information to a file. Which is the best file type?

Seems most of the good answers are here, but like most things, you need to set your expectations around what you need to achieve.

It all comes down to a few requirements for your save files:

  • Do you want it readable? - If so json is small, xml is verbose, text is also large. Binary or hex if not
  • Do you want to protect against alteration - If yes, then also consider encrypting your saves.
  • Multi-platform - be aware that some serialisers work differently on different platforms. Not too much of an issue unless you want cross-platform saves. Test on each platform
  • Upgradability - Always ensure your config is always upgradable, nothing kills a game more than a game that is reset because it was upgraded. Also be clear how old a save can be before it isnā€™t upgradable (donā€™t just support the last version). Test, Test, Test upgrading save games and keep old save files to test with.
  • Modding - Does your game support modding and if so, ensure your saves support modding (else things get messy). If you want to support modding, use interfaces and save data that allows extensibility.

Iā€™m sure there is more, just take the advice and base it against the aspirations for your game, And donā€™t be afraid to start small and then build on it.

I use JSON but I encrypt it and include a simple checksum so userā€™s canā€™t (easily) edit it.

For debugging I donā€™t have to bother with the encryption - all human-readable and editable - easy!

For release the very simple encryption I use will put off the vast majority of users from trying to hack it but if support issues arise I can easily get users to send me the file and I can convert back to human-readable format.

Note that there are options in JSON.net to write in a more readable way rather than the ā€˜everything on one line with pretty much no whitespaceā€™ default.

  • Do you want to protect against alteration - If yes, then also consider encrypting your saves.

This oneā€™s been on my mind for a while as well. How exactly do Monogame devs usually encrypt save files to discourage alteration?

I use Aes. Simple and easy to implement on binary files. You can stream a text file to a binary stream if you need to.

1 Like