- Home /
Obfuscate variables in release build?
I know that anyone with enough time and skill will always be able to read the code from your game and that is not something I really worry about. My issue is that my game is very story driven and there are some puzzles that players are supposed to be stuck for a long time, and if you are able to read the code, you can solve them pretty fast...
So the only thing I really need is for variable names to be scrambled in a way they don't make sense if someone decompiles the Assemblies with a tool like ILSpy (which would take like 5 minutes of effort). After that, if someone digs further than I don't really care.
Is this possible? Any suggestions? Would it even be possible to do in the source code, rather than the assemblies? Does Unity provide any protection for this?
Answer by phxvyper · Nov 30, 2015 at 11:33 AM
Is the game single player? Is there a leaderboard? If there is no leaderboard, then logically speaking there isn't much of a reason to protect against cheaters like that.
The majority of people don't know how to decompile .NET or Mono assemblies anyway, so that's okay.
Also, when you compile C# via Mono or .NET, the IL code that is generated is basically already obfuscated, and it becomes very very difficult to read it. Variable names are almost always very weird and the only way to actually figure out what code is doing what is to read it - ALL OF IT.
So, in short: don't worry! Its highly unlikely that anyone will manage to solve your puzzles via cheating. Besides, someone might post the solution online and someone else might use that solution. You can't protect against that (usually).
The issue is not cheaters and the game is only single-player without any leaderboards. If you use something like ILSpy its EXTRE$$anonymous$$ELY easy to read all the scripts inside the Assemblies. It literally takes a few $$anonymous$$utes and doesn't require any advanced knowledge.
I know that probably someone will post a walk through immediately but still I would like to hide it slightly better on my side.
Here is an example from the web of how well it reads the files...
Totally agree with @phxvyper - 99% of players won't know how to decompile your code. The 1% that can will also be tech-savvy enough to be able to unobfuscate it as well (or, tbh, cheat your game in other trivial ways), and once story-driven puzzles are solved once, they can be solved by everybody.
If your game is not multiplayer or rewards-based, why does it matter if the player "cheats" in this way? I$$anonymous$$O, obfsucation makes your game much harder to manage, it has the potential to break any method calls such as calling coroutines by name, and is really not worth the effort.
Your answer
Follow this Question
Related Questions
Hide variables in PlayerPrefs 2 Answers
How can you hide variables within a region in a c# script? 1 Answer
Public variables not updating? 1 Answer
cleanup variables on editor BUG? 1 Answer