Hi all,
I was thinking about implementing a metric system in my game where I could store some stats about the players gameplay e.g.: kill count, all time damage damage, highest damage, etc. Also I want to store it so the player can’t manipulate it directly so not like in a readable fomat.
(It is a vampire survive like game for now)
Any advice how it should be done?
If you don’t want the player to manipulate it, store it on your own server.
Server side is the only practical way. Storing it in a format that is difficult to read won’t do anything as the data can just be manipulated in memory with a tool like Cheat Engine (Windows and macOS), GameConqueror w/ scanmem (Linux), GameGuardian (Android), or iGameGod (iOS), or the game source decompiled with dotPeek.
Encrypt the save file, or even just serialize it as binary.
People could decrypt it or convert it back but this handles 99% of the use cases of someone editing a raw file.
For memory manipulation like Ryiah mentioned there’s ways of detecting that.
Memory manipulation would still work with a server based save-file approach unless you go on a full on server-authorized gameplay where your gamers need network connection all the time when playing.
No need to think in extremes here. You know the saying “Locks exist to keep honest people honest”?
Easiest way: Have your save state inside a single [Serializable] instance and use the JsonUtility of unity. Before writing the string to a file, run this xor-crypt snippet:
Tip: Use a SerializableObject as that instance so you can see the state in the editor nicely and also comfortably use that for purposes like testing.
Locks are only necessary in that example because turning a door knob is easy. The actual simplest in my opinion isn’t JsonUtility because it’s troublesome to work with if you want to do anything complex since it’s made for the editor. If you’re going down that route just use Unity’s Serialization package and tell it to use binary JSON.
https://docs.unity3d.com/Packages/com.unity.serialization@3.1/manual/index.html
Alternatively Easy Save 3 can compress and encrypt save data while having a very simple API. It’s even possible to use it in a way that doesn’t require you to write code.
Answered already. Bumped by spammers.