0
\$\begingroup\$

I am developing a game that saves its state in a text file. I am writing that file in Application.persistentDataPath but my issue is that the game progress file is available to user in Data/PACKAGE NAME/files/*.

How can I hide the game progress file so that user can't access the files ?

\$\endgroup\$
  • \$\begingroup\$ I'm not sure if you can hide those files but you can encrypt them. \$\endgroup\$ – kolenda May 17 '18 at 10:21
  • \$\begingroup\$ It's important to remember that no matter what you do, local files can be accessed and altered. \$\endgroup\$ – Tyyppi_77 May 17 '18 at 10:29
  • 1
    \$\begingroup\$ What's the end goal you're trying to achieve by hiding these files? How does this benefit the player experience? \$\endgroup\$ – DMGregory May 17 '18 at 11:51
  • \$\begingroup\$ The goal is to secure the app so that user cant alter or delete the game progress. \$\endgroup\$ – Faisal Imran May 17 '18 at 13:05
  • \$\begingroup\$ I can encrypt those file but still user can delete accidently \$\endgroup\$ – Faisal Imran May 17 '18 at 13:06
4
\$\begingroup\$

You can't.

The path represented by Application.persistentDataPath is a path on the user's computer. You can't really prevent the user from seeing and manipulating files on his or her own machine.

Application.persistentDataPath writes to locations that are hidden by default on macOS and Windows (I'm not sure about Android). In theory you could set the "hidden" attribute on the files you write, as well (if you access to an API to do so). But that doesn't prevent the user from toggling "show hidden files" or otherwise deleting them.

If you really want files to be written to a secure location where the user cannot tamper with them, you will need to write them on a machine you control (that is, a server), which is a whole new can of worms.

I suspect you're best off not worrying too much about this. Write a bit of code to handle the cases where the files don't exist (so for example your game doesn't crash), and that should be sufficient.

\$\endgroup\$
1
\$\begingroup\$

You can try using sqlite or go with encryption of the text.

\$\endgroup\$
  • 1
    \$\begingroup\$ I disagree that this does not provide an answer to the question. Encryption would indeed make a file more difficult to tamper with. Using sqlite, however, is probably more secure because the user can't edit what's not on their machine. The accepted answer doesn't mention any such practices. "I suspect you're best off not worrying too much about this." This would be true if you weren't developing a game that keeps track of high scores, which is literally every game that existed ever. \$\endgroup\$ – James M May 23 '18 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.