8

Unity3D Game Code Obfuscation

posted by admin
Creating games it is always a lot of fun especially if you are using a complete game development framework like Unity3D.
Unity3D provide a native code game engine that can load compiled C# scripts that define the behavior of all the objects inside the game loop. The compiled scripts are embedded into a .NET assembly called Assembly-CSharp.dll that will be deployed along with the game engine. The Unity3D engine uses reflection to hook types inside the Assembly-CSharp assembly. Those types are then used by the game engine to call methods or set fields and properties that can be edited in the Unity3D editor. 

You can use Babel Obfuscator to obfuscate the Assembly-CSharp.dll although you need some extra XML rules tailored for Unity3D to get reflection working properly. These rules prevent the renaming of all members used by the game engine, renaming all other public symbols that are not accessed externally.

You can find the rules file Unity3DRules.xml attached to this article. Just drag & drop the file in the Rules tab under the Assembly-CSharp.dll assembly:



Then you can enable the following obfuscations:

Renaming:

  • Types, Methods, Properties, Fields, Events, Virtuals, Overloaded
  • Flatten Namespaces
  • Unicode

Control Flow:

  • Obfuscate Control Flow (Goto, Switch, Case, If, Call)

Encryption:

  • Encrypt Strings (xor)

Optimizations:

  • Seal Classes
  • Remove Const Fields

The rule set defined in Unity3DRules.xml was tested successfully on several Unity3D games available to download for free from the Unity3D asset store.
This file doesn't claim to contain a complete set of rules, so if you find some other rules, please do not hesitate to contact us and we'll update the file.

Back to List