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 1: | Line 1: | ||
{{BackToTutorials}} | {{BackToTutorials}} | ||
+ | {{Credit|[[User:Alistaire|Alistaire]]}}<br/> | ||
− | The base game provides a bunch of code snippets in ''../Source/'', relative to your Rimworld installation. Since this isn't a lot, one might want to take a look at the game's full source code | + | The base game provides a bunch of code snippets in ''../Source/'', relative to your Rimworld installation. Since this isn't a lot, one might want to take a look at the game's full source code:<br/><br/> |
− | + | =Decompiling source code= | |
− | = | + | ===dnSpy=== |
+ | dnSpy is a great application for decompiling or debugging and is packed full of features. It even has a Visual Studio editor feel to it. It's currently only for Windows. It is also better than most other decompilers at iterator blocks and async/await methods.<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 | + | One method is to use ILSpy. This software is recommended because its settings are correct on a clean install. It is for Windows only, but you can compile it yourself as a CLI application for Mono framework on OS X and Linux, see [https://github.com/icsharpcode/ILSpy/issues/691 (This issue)] or [https://github.com/icsharpcode/ILSpy/issues/416 (This issue)] on GitHub for more info.<br/> |
− | # Download [http://ilspy.net/ ILSpy] ( | + | # Download [http://ilspy.net/ ILSpy] (Download Binaries) 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 | + | ## Navigate to ''Assembly-CSharp.dll'' in ''../Rimworld***_Data/Managed/'', relative to your Rimworld installation and with *** being a version number; |
## Right-click "Open with" and select a standard program. Navigate to your ILSpy installation and double-click ''ILSpy.exe'', tick the checkbox and accept; | ## Right-click "Open with" and select a standard program. Navigate to your ILSpy installation and double-click ''ILSpy.exe'', tick the checkbox and accept; | ||
## Double-click ''Assembly-CSharp.dll'', | ## Double-click ''Assembly-CSharp.dll'', | ||
# '''Or''': open ILSpy and open a .dll: | # '''Or''': open ILSpy and open a .dll: | ||
## Open ILSpy; | ## Open ILSpy; | ||
− | ## Go to File -> Open or press Ctrl+O, navigate to ''../Rimworld***_Data/Managed/'', relative to your Rimworld installation and with *** being a version number | + | ## Go to File -> Open or press Ctrl+O, navigate to ''../Rimworld***_Data/Managed/'', relative to your Rimworld installation and with *** being a version number; |
## Select ''Assembly-CSharp.dll'' and confirm, | ## Select ''Assembly-CSharp.dll'' and confirm, | ||
# 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''; | ||
Line 25: | Line 32: | ||
## 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/> | ||
− | + | Zhentar released an optimized version of ILSpy that decompiles iterators. It can be found [https://github.com/Zhentar/ILSpy/releases/ here]. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===MonoDevelop=== | ===MonoDevelop=== | ||
Line 54: | Line 40: | ||
# Download [http://www.monodevelop.com/download/ MonoDevelop] and install it; | # Download [http://www.monodevelop.com/download/ MonoDevelop] and install it; | ||
# '''Either''': associate the .dll extension with MonoDevelop: | # '''Either''': associate the .dll extension with MonoDevelop: | ||
− | ## Navigate to ''Assembly-CSharp.dll'' in ''../Rimworld***_Data/Managed/'', relative to your Rimworld installation and with *** being a version number | + | ## Navigate to ''Assembly-CSharp.dll'' in ''../Rimworld***_Data/Managed/'', relative to your Rimworld installation and with *** being a version number; |
## Right-click "Open with" and select MonoDevelop as standard program; | ## Right-click "Open with" and select MonoDevelop as standard program; | ||
## Double-click ''Assembly-CSharp.dll'', | ## Double-click ''Assembly-CSharp.dll'', | ||
# '''Or''': open MonoDevelop and open a .dll: | # '''Or''': open MonoDevelop and open a .dll: | ||
## Open MonoDevelop; | ## Open MonoDevelop; | ||
− | ## Go to File -> Open, navigate to ''../Rimworld***_Data/Managed/'', relative to your Rimworld installation and with *** being a version number | + | ## Go to File -> Open, navigate to ''../Rimworld***_Data/Managed/'', relative to your Rimworld installation and with *** being a version number; |
## Select ''Assembly-CSharp.dll'' and confirm, | ## Select ''Assembly-CSharp.dll'' and confirm, | ||
# '''Very important''': search for a dropdown called "Visibility" and change it from "Only public members" to "All members"; | # '''Very important''': search for a dropdown called "Visibility" and change it from "Only public members" to "All members"; | ||
Line 66: | Line 52: | ||
# 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_.28works_on_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. | |
− | |||
− | |||
− | |||
=See also= | =See also= |