Rimworld Mod

I’ve been a avid fan of Rimworld for a fairly long time and as of writing this blog I have 700+ hours of playtime on it. Rimworld is a survival base building game, where the goal is to guide a group of pawns through various disasters and slowly build up your base to the point where you can construct a space ship and take your pawns offworld.

Rimworld has always had a very active modding community and I’ve heavily used mods in almost all my playthroughs. The data driven design of the game enables very easy modding of the game and I’ve always thought of creating my own mod, but I never found the right idea to make into a mod. If I did come up with an idea, it would normally already be implemented by someone, which took away the motivation of trying to create one myself.

In a recent playthrough I was trying to find the best items for my pawns to produce, to help optimize their output value. I started off creating a spreadsheet with the various items my pawns could produce, along with the amount of input resources and the time required to produce the item. This became complicated fairly quickly as most items can be crafted from different resources. The quality of the final product can also vary, which in-turn effects it’s value. The chance for the produced item to be of a given quality depends on the skill level of the pawn creating it, and the value it sells for depends on the charisma of the seller.

I started incorporating all of this into my spreadsheet, which involved a lot of digging through different in-game menus to find all the stats and then plugging them into the sheet. I soon realized that this spreadsheet would be a great thing to mod into the game. The game already has all the data in various xml files so I just need to create a new ingame UI to do the calculations and display them. Thus began my quest to create a rimworld mod.

There is a well known tutorial for creating a Rimworld mods targeted at beginners called the PlagueGun mod. It’s been a nice starting off point to understand how a mod is structured, but it does not deal with menus. So I’ve had to start digging into the files of the base game to understand how to create a new menu.

For a very basic mod, such as adding a new food type, you only need to deal with the xml files. But if you want to add new functionality to the game then you have to deal with C# code. Most of the tutorials I found used Visual Studio Community edition. The reason for this is that you need to create a C# “Class Library .NET Framework project”, which can then be compiled to a dll that the game will use. You also require dependencies on the .Net framework libs and the Unity3D dlls which have to be added as a dependency to the project file.

I prefer to use VSCode as it’s a much lighter weight editor, and I already have it configured to my preferences. So I started looking into setting things up in vscode. That took some trial and error until I came across this github project for a Rimworld Mod template, that already has everything configured. Cloning the project got me setup with being able to add new code to the game, and I continued with the plague gun project.

The Plague Gun tutorial walked me through setting up a new “plague gun bullet” class, which adds new functionality to the game whereby getting hit by the plague bullet has a random chance of adding a sickness to the pawn that was hit.

Modded code works by extending existing rimworld classes, in this case the “Bullet” class, which contain the bulk of the functionality for the in-game object. The tutorial outlined exactly which classes I needed to extend to add the tutorial functionality, but there wasn’t any resource with all the in-game classes. For that I needed to decompile the game’s dll to see what was available.

This seemed like a good place to stop before I dug into decompiling the game’s code and seeing how I could add the menu functionality I wanted for my mod.