Saving World Data/Game Saves

Started by
1 comment, last by Noegddgeon 12 years, 8 months ago
Hey, everybody! Been a while since I've posted.

Basically, I'm working on a side-scrolling game now, having been inspired greatly by the fantastic game Terraria and spending 50+ hours playing it. My question is, how does one go about saving all of their world data, and the game data for that matter (all the images, sounds, etc.), in such a way as to make it invisible to the player to prevent them from going in and messing up the files and whatnot? I've got a bunch of games on my computer, and they all save their information in obscure random file formats that I assume are proprietary and crafted to prevent exactly what I mentioned. Terraria, for example, saves everything regarding world data in a single .wld file that contains just about everything that has to do with the world and the level, from all the items to the terrain to the water. For that game, I know the graphical assets are stored as .xnb files, which was easy to research and figure out. In my particular case, I'm using Java and not XNA. To store my levels, I'm using pixel maps in .png format.

If anyone could provide me a link or some information that might assist me in figuring this out, I would be very appreciative. Thank you!

Colton
Advertisement

.. and they all save their information in obscure random file formats that I assume are proprietary and crafted to prevent exactly what I mentioned.

Believe me, it is more than easy to generate binary files that are obscure, random and proprietary even if you didn't want to and tried your best to document them to your fellow developers :).


Have a look on how to write out binary files (as opposed to text files). Saving the game state is nothing more than an arduous investigation of all the game variables which are important to the current state, so that when you load up the game you are able to reconstruct the previous situation. Create a function which dumps all that data to file using an unambiguous structure, and write a matching load function which performs exactly the reverse steps to load the game state. There's not really much more to it.


As for security, you have to ask if you want your data file to be unreadable, or only safe from being modified. If it is enough to restrict that nobody can tamper the savegame, you can create a hash of the file contents using a custom prepended "hidden" nonce/salt, which you have only in the binary file of your game. Being able to modify the savegame will then require the user to more or less reverse-engineer your code to be able to break the savegames, which I think will not happen (unless your game will be a huge hit like MineCraft ;).

If you want to also shield your savegames from being read, you can encrypt it, again hiding the encryption key somewhere inside your program.

Thanks for the response, clb! I definitely wouldn't mind achieving Minecraft's status.... I myself am quite a fan of the Minecraft. ;]

I was planning on writing several functions for several various states of the game in different files to make accessing the information highly organized, but the binary idea is something I never really thought of before. I'll have to look into that.

After a bit more looking around through the game folders on my computer, I noticed that a lot of the games actually did have their assets out in the open, so to speak, so I'm not as concerned about that anymore. Plus, having the assets easy to access and modify would be a plus on the player side, I think, because modding is a wonderful and glorious thing. I've heard Java offers a lot of encryption options in just the stock API as well, so I think I'll have a look through those and see what I can do.

Thanks again!

Colton

This topic is closed to new replies.

Advertisement