Search code examples
libgdxandroid-preferences

LibGDX - Storing highscore with 'Preferences' safely


I'm having trouble finding a way to store the highscore of a game in a password protected file.

I don't want the player to go in .prefs/ to change the high score and load the game with it.

I could make it hard to alter the values by encrypting them but that would not be a sure way of keeping the player from randomly using different encrypted values and one being the right format.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
   <entry key="highScore">4</entry> Not encrypted
   <entry key="lGTlMAdWzXQaem8c78FMow==">NiGac2LEgYO8uo0wkiKpasdLA==</entry> Encrypted
</properties>

Solution

  • I'm afraid that any data you store locally is vulnerable to being hacked if the player is determined enough. Even if you encrypted the entire file (like made it a binary file) a determined person could generate multiple highscore files and compare them.

    If players can share high scores (like there's some boast factor), then I would recommend you adopt a client-server model and store the high scores remotely in your database where the player couldn't modify them.

    If the high scores are kept locally, then I would posit that it's probably not worth making the file tamper-proof. If they want to inflate their private score instead of actually earning it, then let them. Your time is better spent developing an awesome new game mechanic.

    All that being said, another way to approach the problem would be not to make the file tamper-proof, but to detect when it had been tampered with. You could do this by doing sneaky things like tracking a checksum- if the checksum doesn't match the highscore file, you know it has been tampered with and add 'cheater' easter eggs into your game.