Protecting Game Data

just downloaded an game made with monogame… and i can easy go to game folder and edit all files…
and it is an big game title made with monogame.

Is that so bad? Your assets are copywritten, it’s not worth much if nobody but you can legally use and redistribute them.
Still, if you care that much, some games use a proprietary binary format that all their assets are encoded as. You can also use encryption. If you use either of those solutions, you’ll probably want to write the decoder/decrypter in an unmanaged language that isn’t as easy to decompile as managed ones.

If the developer decided to pack PNGs and WAVs that would be true. We never recommend that, but people do it all the time anyway.

If they packaged XNBs it is at least required for the user to figure out how to decompress an XNB (not a tool MonoGame provides) to extract the data. However that has totally been done before… but not easy for most people.

If you want to go beyond that a developer can bundle and archive the assets with some sort of encryption… MonoGame totally allows for that if you wish. However since the game needs to read those assets any determined hacker can figure out how to decrypt your data.

The only true protection is copyright and the legal system. Beyond that all you can do is make it difficult for most people to hack.

Also none of this is exclusive to MonoGame.

You can extract assets in Unity or Unreal with some simple open source tools.

I would just like to add that in some cases it was even helpful to specific games that didn`t provided modding tools, yet community used xnb extractors to mod a game to some degree. Terraria being one example, it definitely didn’t hurt sales. As far as stealing your assets goes… as Tom said, copyright is protection tool here which will work better than any encryption to some degree (even more so if your game is 2D without complex rendering and postprocessing).

It is not a big deal to write a small app that can convert your contents into a custom format and to create the decoder that your game can use to create the original content that can be used by Monogame. This is what I have done in my game that I am currently developing. All the images are in binary format, with some custom data in it that I could use to create the pngs back. The process is simple:

  • Load the pngs into your converter app the usual way (you will not distribute this conerter app, so you dont have to worry about the raw png contents).
  • Load the png as Texture2D.
  • From this point on, it is only up to you what and how would you like to use from the file. I, for example, extract the RGBA color data and some additional info.
  • The last step in the converter is to save the data in binary format with a BinaryWriter.

Jobs done, you have a custom ‘whatever.yourextension’ file that cannot be opened by any third party program, because to do so, you need to know what is in your binary file, and how can you extract that info.

In your game:

  • Iterate through your custom binary files.
  • You know how you have saved your data into binary format, so create a BinaryReader and read the content in the order just how you saved it (if you saved an integer, then a string, then the color data, then read a int, a string, and color data from the file).
  • From the color data it is not a big deal to create a Texture2D variable by using SetData method. Of course, you need additional information, like image width/height as you need to work with Color arrays.
  • When you have the Texture2D variable, it is again up to you how you use it.

Hope that helps. For me it took something like 2 hours to create this encoder/decoder logic.