Today I’ll show you how to get the source code of any game that’s made using C#, the .NET Framework and Microsoft’s XNA Framework. Basically, this will also work for all .NET Applications, but for XNA Games it’s more difficult, so I will explain it for XNA here.
I hope you understand and like it, if there are any issues, please comment to help me improving this tutorial!
Warning: You may violate copyright laws in your country if you try to obtain property (in this case source code) that you don’t own! Check your legal situation before following this tutorial! I won’t be responsible for any criminal offence done with the information provided!
Step-by-step tutorial to disassemble the game
Things you need
- An XNA-based game
- .NET Reflector
- Visual Studio 2005/2008
- XNA Game Studio 1.0/2.0/3.0
Decompiling the binary file
First of all, you need a really great tool called .NET Reflector. You can download it from the official website or from my server. The .NET Reflector can look inside .NET binaries (.exe and .dll files) and disassemble the code to any of these programming languages: IL, C#, Visual Basic, Delphi, MC++ and Chrome.
Once you start .NET Reflector, it should look something like the image above. As you can see, on the left is a list of all Assemblies found on your computer, and on the right the code of the selected one. If you don’t see the yellow part on the right, just go into any Namespace and class and double-click on a function.
Here you can already play around with it and look into the .NET Framework source, maybe you find some interesting parts of code ![]()
Back to decompiling your game… I assume you have a complete game on your hard disk (the binary file and a content folder with all the game data inside).
For this tutorial, I’ll use Mircosoft’s PickingSample, I think I don’t violate any copyright laws doing it since it’s open source anyway. If I do, please tell me!
In .NET Reflector, select Open File, navigate to your game’s .exe file and double-click it. The application should immediately show the Assembly in the Assembly list. If you just want to have a look at the code, click at the Assembly and select the class/method you want, the Reflector will show the code on the right.
But we want to have the whole game’s code as a Visual Studio project. Rightclick on the Assembly (in this case “PickingSample”, click on “Export…” and enter the path where you want to project to be stored.
If you see a Window popping up like the one below, tell Reflector to load your XNA Framework binary files (click on the three dots on the right, then navigate to C:\Program Files\Microsoft XNA\XNA Game Studio\v3.0\References\Windows\x86 and select the required file, in this case Microsoft.Xna.Framework.Game.dll).
Creating a Visual Studio project
When the export is done, navigate to the directory where you exported the game to and open the project file .csproj (here PickingSample.csproj).
Probably, your Visual Studio will ask you to convert the outdated project file, allow to do it and there you are! Now we have the whole source code in a Visual Studio project and can work on it, make changes and recompile it!
The first compilation of the disassembled code
Press F5 to try to compile the project. The game will crash immediately after startup when trying to load models, sprites, sounds etc. because it can’t find your data files.
All the data files required are within the original game you want to decompile, but converted to the XNB file format. Currently, there is no way to reverse-engineer these files, so we will just let them be as they are. Copy your original game’s content folder into your new project’s \bin\Debug folder and compile the project again. Now it should work!
Missing things in the project
In your new project, all the comments of the original code will be gone, the structure may be different and settings and resource files may cause some problems. But all in all, you have the source code of the original game!
Additional steps
If you still want to get more, like the Windows Explorer icon of the game, use a free tool like IrfanView, drag the .exe file into it, save the icon as PNG and import it into your project.
Trouble-shooting
I copied the content folder into my new project, but the game still crashes when loading the media files!
Look properly at the error message you get. Is it similar to this one?
Error loading “Content\Fonts\Menu”. Cannot find ContentTypeReader Microsoft.Xna.Framework.Content.ListReader`1[[Microsoft.Xna.Framework.Rectangle, Microsoft.Xna.Framework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d]].
In this case, the game was compiled using XNA Game Studio 2.0 and thus the Content Pipeline 2.0, but I was running Visual Studio 2008 with Game Studio 3.0. The new Game Studio seems to have problems using older files, so the only thing you can do is installing Visual Studio 2005 and Game Studio 2.0 again. The same thing for Game Studio 1.0
If you encounter any problems following this tutorial, please comment so I can search for solutions and make this tutorial more complete!





