Rimworld Mod – Part 2

I’ve never had the need to decompile any code in the past. I know it’s a good skill for any software engineer to have, but it’s always felt cryptic to get into. If I wanted to proceed with my mod then I’d have to decompile the game’s source code to understand how to set up new menus and to know which classes to extend.

The Rimworld modding wiki recommended ILSpy and dnSpy, I decided to go with ILSpy. I downloaded the x64 executable and followed the wiki’s instruction on decompiling the source code. The process was unexpectedly simple. I simply pointed the ILSpy executable to the primary game “Assembly-CSharp.dll”, and the program loaded up with the full list of classes in the code. I was then able to click on any class and decompile it to see it’s c# source code.

I decided I would place the link to my Mod’s menu in the main bar in the bottom of the game screen. I was able to poke around the xml configs and determine that the given menu was configured in the MianButtons.xml file. Each button had it’s own config section which linked to class that defined the submenu. I looked up the classes used in the decompiled code and determined they all derive from the “MainTabMenu” class, so that was the class I was going to extend.

I followed the overall guidance in the plague gun tutorial in how to hook up the c# code to the xml. I did run into some linking issues, but they were due to typos on my part and the game provided helpful debug logs that enabled me to fix them. And with that I had my basic menu mod in the game !

All of the UI elements in the game are rendered by the Widgets class. I don’t expect to have to create any custom widgets at this point, so using the existing widgets should suffice. The next step is getting the actual data for the various objects in the game, so I can use it to calculate optimal build orders.

So far the xml files have been the primary entry point for the functionality I’ve added, it’s the xml files that link to the code classes. But now I need to work the other way around, and have the code pull all the item data that is provided in the xml files, and this should include any additional modded items added to the game.