I know this may have been asked tons of times before. I’m interested in a easy way to save game data. Requisites:
Easy to use
Hard to hack
“Simple amount of data data”. Think more of high scores, solved levels and such, there is no need to store tons of data like CoC does.
Looking at forum, I’ve seen talks about
UserDefault: Useful for storing data such as user preferences, volume mute and such. Not encrypted, a rooted device could be used to read/modify your data.
FlatBuffers: There are files in cocos2D-X engine but hard to find any info on official docs. Not even on API reference. (API reference v3.5 gives info, but not v3.13)
ProtocolBuffers: Same here
SQLite3: As pointed in this post it is also included in external folder, and can be encrypted. No info about it, and the acronym SQL sounds more like what I’d use to build a client/server game rather than a simple puzzle like game.
Many of these posts are of 2013/2014. An updated answer would be nice, and links to cocos2d-x tutorials/sample code using these tools would be awesome.
Last but not least. Reading all these posts has arisen another newbie question:
How much protected is my game data? How easy could be to open an android APK or IOS equivalent and modify my files? Is my text data safe if I use a JSON stored in Resource folder or should I use encrypted data for that too?
I can only answer this one. Nobody is opening your apk! Why? because it’s not million dollars or may be nor it would be that difficult to build… If the device is rooted, then your game data file can be easily and very easily found.
So, 1) If you’re using UserDefault, your file can be easily opened and read and hence modified. 2) If you’re using sqlite3(yes you can use for very simple games), then it can also be found but it can’t be easily opened and read.
Don’t know about other formats.
sqlite3 might be a bit costly operation. But also note that it won’t be slow for a CPU as you won’t have 100s of things to read all at once. But better to show a loader in the starting.
If using, UserDefault, don’t simply store 100 for 100 which lof of games do(as some don’t care and some don’t know). It’s better to write ~15 lines of code and make your own very basic encryption-descryption mechanism.
Eg-
Some random ideas:
15050 score can been encoded using 2*score + 3 and if number doesn’t fits your encoding, you can do whatever you want.
r1i5s0h5m0a => ishmar(rishma-permutations) mixed with 15050.
Using 1 and 2 together…
A bit complex and better one…(Integer based operations are better than string based)
15050 * (your lucky no. except 1 or 0) % 25 + 15050. where % = remainder.
And save your critical info, like total coins and all at 2 places with 2 different algorithms and check if they match. It’s also less likely that user will modify both of them.
x Don’t simply use “score” as the key to save in the file.
You can even show a simple value 15050 as the 2nd one and he will most likely change it because he can clearly see it as a score, but this isn’t the score that you display. So, if he changes this too 15200 but the score you display is 15050 encrypted as something then you can show display score as 15050-little value while your actual score is safe in other encrypted value, which will confuse him that he changed something which did reflect but no rightly and he’ll waste time over there in experimenting with the wrong score value.
And on closing your game, you should reset the value.
But it’s too naive and boring right?
So, look at this. http://hashids.org/ Go to git. Conver the code to C++ and save it in your project and use it
Apologies for my late reply. Been busy with other projects.
@catch_up, ok, I’ve checked SQLite a bit more and seems it won’t be that big nightmare. I was asking about these classes as in some posts people stated that we should use them, but guess SQLite will be the way to go. About using XOR encode, although simple (already knew this and some other tricks like rotating N bits at each char), was wondering if cocos had any kind of support for that, as doing it by myself can lead to unexpected surprises in localization and/or little/big endianess.
@nite: Haven’t been able to check yours yet, but surely will take a deep look as it looks really interesting too. According to existing project files, my guess is that it works both for IOS and Android? Is it a WIP or is it fully integrated with existing SDKBOX?