Rimworld Mod – Part 3

Parsing out the required data took more effort than I expected. My original assumption was that I’d read the xml files directly and use those to populate my optimizer table, but it turns out not all the required data was in the xml files. A given recipe refers to other recipes and also computes certain values in code, attempting to read the xml files directly would mean I would have to link the recipes together and figure out how to compute any missing values. That would essentially be recreating the game’s logic, so instead I started looking into the decompile C# code to see how the current menus were setup and where they were pulling their data from.

The issue with the decompiler is that it only surfaced class names, and would only decompile one class at a time, there wasn’t a way to decompile the complete code. That meant it took some guess work to find example classes for reading and displaying the data I cared about, and even after finding the class there wasn’t an easy way to find examples of it’s usage.

After making some limited progress I went on hiatus for winter break and Ramadan. Reexamining the code after coming back from break allowed me to look at the code from a fresh perspective. I wrote down pseudocode for my menu allowing me to break the problem down into smaller steps. These were roughly

  1. List all receipes
  2. Filter these to ones that can be actively crafted
  3. List market value of recepies
  4. List ingredients of each recipe
  5. List the total cost of all ingredients in a recipe
  6. List how much work is required for each recipe
  7. Calculate the percentage increase in value for each receipe
  8. Calculate how much the value increased per unit of work done by a pawn.

This breakdown allowed me to work through the problem systematically, and provided a tangible addition to the menu after each step. During this time the log file proved invaluable in debugging issues as any errors in miss parsed values halt the execution on the menu.

Once I had all the information on display I realized the usefulness was limited without the option to sort the list. This required some refactoring to prevent the list from being regenerated after every resort. Once the sorting was done and I added the ability to sort on different dimensions I felt the mod was in a good enough state to publish.

Publishing was a straight forward process. The mods menu in the game had a publish button against any mod not downloaded from the steam workshop. I added a short blurb on the mods functionality, took a screenshot to add to the description and uploaded the mod.

The mod can be found at the following link https://steamcommunity.com/sharedfiles/filedetails/?id=3457584424