0
\$\begingroup\$

My game uses big const data which i need to retrieve it to use data used on each level when its needed data security is important

I got two options in my head which one is better?

Note the data is const and it never changes during game and only i can change it on coding for using it on some levels and after build it always same data

1: using return "data"

Something like this which means data stored in script and finding script will expose data

if(level_number < 10)
{
switch level_number

case 1: 
return data_1;
.
.
.
}
if(10<level_number <20)
{
.
.
.
}

2: saving in binary file

Check if the file exist read it and if it isn't then create it during game and use it next time

This one uses binary formatter to save/load data and there is two options for this too

2.1: creating file during game which still have same problem like first solution

2.2: creating file on the editor and load it from plugin folder etc

And second one also have storage usage when first one just a script which returns some const data

I know you cant stop hackers from hacking offline file but i'm also looking better way to save this big const data and retrieve it to use it

Which one is better and if you have better solution i'm happy to hear it

\$\endgroup\$
  • \$\begingroup\$ What kind of data are we talking about here? And by what criteria are we to judge what's "better"? In terms of anti-cheat, there's no meaningful difference with anything you do client-side. The data is in the hands of the enemy and they can manipulate it any way they want to if sufficiently motivated, whether it's in code they can decompile & edit, or a binary file they can decode (even encrypted, you've handed them the decryption key in the game executable. Even signed, you've handed them the signature check they can disable). So what really matters for your needs here? \$\endgroup\$ – DMGregory Aug 4 at 14:28
  • \$\begingroup\$ You say for the second option that you'd "Check if the file exist read it and if it isn't then create it during game and use it next time" but if you can create the file and populate during the game, you already have the data you need in memory. So what is the point of saving it somewhere else? \$\endgroup\$ – Josh Aug 4 at 14:33
  • \$\begingroup\$ @DMGregory Data type is string and it's used to some calculation and changes in levels so it's just need anti-cheat to remove player finding levels details and secret items. i just wanted to find best way to save and retrieve them since big data and performance problems can occur . and i liked how you said "The data is in the hands of the enemy and they can manipulate it any way" true :)) \$\endgroup\$ – ata_2 Aug 4 at 14:40
  • \$\begingroup\$ @Josh well data is big and if i store it on memory memory usage can be high for low-end mobiles it's android game. imagine 500 strings each with 2 to 6 letter \$\endgroup\$ – ata_2 Aug 4 at 14:43
  • \$\begingroup\$ 500 strings at 6 characters each might be something on the order of 6 KiB or smaller, ie. probably a fraction of the size of the smallest texture or sound effect in your game. This is probably not where you need to be looking for memory savings. \$\endgroup\$ – DMGregory Aug 4 at 14:51
0
\$\begingroup\$

From a security standpoint, as you note, they're basically equivalent (which is to say not secure at all). So it doesn't particular matter on that front.

Generally speaking I'd suggest you keep data (constant or otherwise) distinct from code, because then you don't have to go through the process of rebuilding the game (and in some cases repackaging it also) to change some data.

That implies storing it in a file along with the levels or (in the case where sometimes the same set of data is shared between multiple levels) alongside the levels in separate files.

In your case, however, it sounds like the whole question is a bit irrelevant, since you note that one option related to storing it a file is to

Check if the file exist read it and if it isn't then create it during game and use it next time

which implies you already have the data in memory (otherwise you couldn't create a file with anything meaningful in it). In your case, since your dataset seems very small and simple, it may be more pragmatic at this point to simply keep continuing with the data (a list of strings, as you note in the comments) in code.

\$\endgroup\$
0
\$\begingroup\$

When you want to prevent your players from reverse-engineering your game, you are fighting a battle against windmills. You can make them jump through hoops, but you can not prevent it. And if anyone ever finds your level details and secret items through the regular ingame methods, they will just create a wiki and share it with the whole community. You can't keep secrets in the Internet age.

If you want to manage static data in Unity, then you might want to look into ScriptableObjects. ScriptableObjects are a technique which allows you to create custom, data-based assets which you can create and manage in the Unity editor and assign to inspector-exposed fields of your MonoBehaviours. Just like any of the regular Unity assets.

\$\endgroup\$
  • 1
    \$\begingroup\$ On top of that I would like to add, if anyone is making an offline game there is no point in trying to prevent hacking. If a user has fun hacking your game, why does it matter ? The whole point is for users to have fun. Not to mention that someone might create some weird mods that could actually boost the popularity of your game. \$\endgroup\$ – TomTsagk Aug 5 at 11:57

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.