Editing Modding Tutorials/Decompiling source code

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 6: Line 6:
  
 
=Decompiling source code=
 
=Decompiling source code=
 +
 +
===dnSpy===
 +
dnSpy is a great application for decompiling or debugging and has a Visual Studio editor feel to it. It's currently only for Windows.<br/>
 +
# Download [https://github.com/0xd4d/dnSpy/releases dnSpy] and extract it somewhere.
 +
# Open dnSpy.exe. Once it's open, click "open" on the top ribbon (or press Ctrl+O).
 +
# Navigate to ''../Rimworld***_Data/Managed/'', relative to your Rimworld installation and with *** being a version number.
 +
# Ctrl+Shift+K to open the search bar.
 +
# Explore the assembly and look through the source code to your heart's desire.
  
 
===ILSpy===
 
===ILSpy===
  
ILSpy is generally recommended as it is the best-maintained and most reliable decompiler. The core project only has binaries for Windows, but there is an [https://github.com/icsharpcode/AvaloniaILSpy Avalonia-based port] as well as a [https://github.com/icsharpcode/ILSpy#unix--mac CLI application for Mono framework] for OS X and Linux.<br/>
+
One method is to use ILSpy. This software is recommended because its settings are correct on a clean install. It provides binaries only for Windows, but you can compile it yourself as a CLI application for Mono framework on OS X and Linux, see its [https://github.com/icsharpcode/ILSpy#unix--mac "How to build" instructions] on GitHub for more info.<br/>
  
# Download [http://ilspy.net/ ILSpy] ([https://github.com/icsharpcode/ILSpy/releases Download latest release]) and extract it to a directory of your choosing. Optionally create a desktop shortcut;
+
# Download [http://ilspy.net/ ILSpy] (Download latest release) and extract it to a directory of your choosing. Optionally create a desktop shortcut;
 
# '''Either''': associate the .dll extension with ILSpy:
 
# '''Either''': associate the .dll extension with ILSpy:
 
## Navigate to ''Assembly-CSharp.dll'' in ''../Rimworld***_Data/Managed/'', relative to your Rimworld installation and with *** being a version number (See Note on MacOS below);
 
## Navigate to ''Assembly-CSharp.dll'' in ''../Rimworld***_Data/Managed/'', relative to your Rimworld installation and with *** being a version number (See Note on MacOS below);
Line 24: Line 32:
 
## Ctrl+Shift+F or Ctrl+E opens the search bar which can be used to search through all loaded assemblies;
 
## Ctrl+Shift+F or Ctrl+E opens the search bar which can be used to search through all loaded assemblies;
 
## Ctrl+F opens a search bar for the currently opened decompiled class.<br/><br/>
 
## Ctrl+F opens a search bar for the currently opened decompiled class.<br/><br/>
 
If using CLI application:
 
# Despite the instructions saying .NET 5.0 SDK is needed, you may also need [https://dotnet.microsoft.com/download/dotnet/3.1 .NET Core 3.1];
 
# It seems that it's possible to simply build from a [https://github.com/icsharpcode/ILSpy/releases release tarball], even if the instructions suggest to use a git checkout;
 
# After you've built ILSpy, find the ''ilspycmd'' tool (should be located at ''ICSharpCode.Decompiler.Console/bin/Release/netcoreapp3.1'');
 
# Run a command like ''ilspycmd RimWorld/RimWorld*_Data/Managed/Assembly-CSharp.dll -p -o <output directory>'' (use proper paths to RimWorld and for the output directory);
 
# The given output directory now contains decompiled sources.
 
 
===dnSpy===
 
 
dnSpy is an alternative with a Visual Studio editor feel. At the time of this writing, however, the original project has been archived for more than two years and none of its forks have reached a similar level of adoption. Decompilation glitches can occur.<br/>
 
 
# Download [https://github.com/dnSpyEx/dnSpy/releases dnSpy] and extract it somewhere.
 
# Open dnSpy.exe. Once it's open, click "open" on the top ribbon (or press Ctrl+O).
 
# Navigate to ''../Rimworld***_Data/Managed/'', relative to your Rimworld installation and with *** being a version number.
 
# Ctrl+Shift+K to open the search bar.
 
# Explore the assembly and look through the source code to your heart's desire.
 
 
===Rider / dotPeek===
 
 
Rider is a cross-platform IDE with a built-in decompiler. If you're using Rider as your IDE ([[Modding_Tutorials/Setting_up_a_solution#Rider_.28good_for_Mac.29|Setup Instructions]]), you can view the source of any RimWorld class or method by right-clicking its name and clicking Go To > Definition.
 
 
The developer of Rider also offers a free standalone decompiler in the form of [https://www.jetbrains.com/decompiler/ dotPeek]. dotPeek is preferred by some for reading IL Code for the purpose of Harmony transpilers, but suffers similar glitches and inconsistency as dnSpy when decompiling back to C# code.
 
  
 
===MonoDevelop===
 
===MonoDevelop===
Line 65: Line 50:
 
# Click the "+" next to ''Assembly-CSharp (***)'', you will now see a list including the items ''Rimworld'' and ''Verse'';
 
# Click the "+" next to ''Assembly-CSharp (***)'', you will now see a list including the items ''Rimworld'' and ''Verse'';
 
# Take your time to look through the source code, to make yourself familiar. If you ever need the source code, open ''Assembly-CSharp.dll'' again.<br/><br/>
 
# Take your time to look through the source code, to make yourself familiar. If you ever need the source code, open ''Assembly-CSharp.dll'' again.<br/><br/>
 +
 +
 +
===Rider===
 +
 +
Rider is a cross-platform IDE with a built-in decompiler. If you're using Rider as your IDE ([[Modding_Tutorials/Setting_up_a_solution#Rider_.28good_for_Mac.29|Setup Instructions]]), you can view the source of any RimWorld class or method by right-clicking its name and clicking Go To > Definition.
 +
  
 
===MacOS Directories===
 
===MacOS Directories===

Please note that all contributions to RimWorld Wiki are considered to be released under the CC BY-SA 3.0 (see RimWorld Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)