Basic Concepts
This page is mostly theory and will focus on concepts and basic information without putting it into practice.
We will learn basic terms used in the RimWorld Modding community and how some of the systems operate.
Concepts and terminology
Before jumping into how to do mods, you need to understand the nature of mods and how they operate within the game, at least to a superficial level.
RimWorld is highly configurable
Usually, games put all their data and information in their code. If they want to change a value, number, label, they have to modify their code in order to do so. Unlike them, RimWorld exposes most of its data outside its code to facilitate making value adjustments and, by extension, to allow us to make modifications in an easier way.
As shown in this diagram, RimWorld has two "environments", to put it simply.
- Code: the code handles the logic, behavior, and mechanics of the game. It responds to: how will colonists shoot at their targets, how strong will the incoming raid be, etc.
- The programming language to code in RimWorld is C# (C-sharp). One of the most used programming languages. It's very flexible and relatively easy to understand (we will get to the coding tutorials later on).
- XML files: these files hold simple data, most of them being numbers, text, and references to other things. These files are just configuration.
- XML is a markup language, not a programming one. It doesn't do any logic, only holds values.
- XML is used to create "Defs", one of the most important parts of RimWorld.
Basics of Defs
XML is mainly used to make Defs. "Def" is a short-term for "definition". Defs are like blueprints or a list of ingredients, they contain most of the necessary values that the code needs to implement something.
For example, let's say the code handles how a gun is used, how is it equipped, how the graphics are shown in the game, and so on. The XML contains values like how much the gun costs, its mass, cooldown, material, cost list.
Defs are recipes, not in-game things
Using a cooking analogy, Defs are recipes, NOT a dish (the final product). So, RimWorld takes a ThingDef to create a Thing, a ResearchProjectDef to create a ResearchProject, our colonists don't have ThoughtDefs, they have Thoughts and so on. What we see in-game are not Defs, we see and interact with the final product!
Basics of Patching
There are two types of patches:
- Patches for Defs (XML)
- A lot of times we don't need to add "content" to the game (guns, items, biomes, etc), we might only need to change a number to something higher or lower.
- XML Patching consists on changing or modifying parts of a Def. If a gun has a range of 30, and we only need to change it to 35, we have to patch the gun's Def.
- Patches for code
- If we need to change existing behavior or logic into something different, we might need to patch the game's code. For this, we use a tool called Harmony.
- In simple terms, Harmony allows us to add more code in different parts of the game's code or even skip mechanics entirely, thus changing the end-result of some behavior.
Basics of Assemblies
While XML can be accessed and edited with any text editor, even Notepad, code works differently. In sum, you use a software to write and then "compile" your code. This software allows you to write the logic and behavior in the programming language of your preference (in RimWorld's case, only C#). Then, it "compiles" what you wrote, transforming and translating it into something that RimWorld and the Game Engine can understand better.
- Compiling means turning your C# code into an assembly, with a .dll extension, that the game can interpret.
- The code, in a .dll extension, cannot be easily altered or modified, unlike XML.