I am occasionally curious to peek at the source code of a Unity game, mainly to see how it is broken into classes. This is easy to do with MonoDevelop.

The solution in this post has some limitations. Comments and the project structure will be lost. Assets can not be viewed. Obfuscated source code will be unintelligible.

Make sure you are not breaking any EULAs before trying this.

Software Versions

$ date -u "+%Y-%m-%d %H:%M:%S +0000"
2016-04-06 19:12:17 +0000
$ uname -vm
Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
$ ex -s +'%s/<[^>].\{-}>//ge' +'%s/\s\+//e' +'%norm J' +'g/^$/d' +%p +q! /System/Library/CoreServices/SystemVersion.plist | grep -E 'ProductName|ProductVersion' | sed 's/^[^ ]* //g' | sed 'N; s/\n/ /g'
Mac OS X 10.11.4
$ ex -s +'%s/<[^>].\{-}>//ge' +'%s/\s\+//e' +'%norm J' +'g/^$/d' +%p +q! /Applications/Unity/MonoDevelop.app/Contents/Info.plist | grep -E 'CFBundleName|CFBundleShortVersionString' | sed 's/^[^ ]* //g' | sed 'N; s/\n/ /g'
MonoDevelop 5.9.6

Instructions

The easiest way to peek at the source code of a Unity game is to start with an Android APK. Find an Android APK that you know or suspect was made with Unity and unzip it.

unzip unity_game.apk -d unzipped_unity_game
cd unzipped_unity_game

Open MonoDevelop and the assets/bin/Data/Managed directory.

open -a MonoDevelop
open assets/bin/Data/Managed/

If the APK was made with Unity, UnityEngine.dll will be in the directory. The interesting source code tends to be stored in the following files. There may also be some libraries that are used by the game.

  • Assembly-CSharp-firstpass.dll
  • Assembly-CSharp.dll
  • Assembly-UnityScript-firstpass.dll
  • Assembly-UnityScript.dll

Drag one or all of the above dll files into MonoDevelop and an Assembly Browser window should open. Select the class you want to view on left hand side of the window. Change Visibility to All members and Language to C# to see a complete decompiled code listing.

References: