DLL Modding Guide, Lesson 4 - Adding Your Power to the Game

Next Lesson - Uploading Your Mod

Previous Lesson - Creating a New Power

Table of Contents

In our last lesson, we created a brand-new god power. It’s there, but there’s nothing in particular that gives the player access to this power. We’re going to sort that out in this lesson.

As mentioned in Lesson 2, creating a class means that that type of object can be accessed by other parts of the game, but that class being written doesn’t do anything on its own. There’s one exception to this, and that exception is what makes DLL modding practical.

Right click your project in the Solution Manager, then click Add/New Item. We’ll name it Kernel\_Snap.cs. There’s no rule that each class has to be in a different file, but conventional wisdom is that this is how you keep your projects clean.

Rename “**internal class Kernel\_Snap**” to “**public class Kernel\_Snap : ModKernel**”. The game will create an instance of every ModKernel subclass available as it initiates, and then call various “hook” functions when certain things happen in-game. For example, the game calls ModKernel.onTurnStart (Map map) for an instance of every modKernel whenever the turn starts. For the ModKernel class itself these hooks do nothing, but they are virtual functions, which means we can override them to instead loop our new mechanics into the game.

Add the following function to Kernel\_Snap:

```
public override void afterMapGenAfterHistorical(Map map)
{
 map.overmind.god.powers.Add(new P\_ThanosSnap(map));
 map.overmind.god.powerLevelReqs.Add(0);
}

```

* afterMapGenAfterHistorical runs right before Turn 1 starts. You could also use afterMapGenBeforeHistorical, which runs right before turn -150 starts. If you’re looking for hooks for more specific things, you can take a look in Assets.Code.Modding.ModKernel.dll, or type in “public override “ inside your ModKernel subclass and then see what other hooks come up.
* powers and powerLevelReqs are Lists (of Powers for powers and of ints for powerLevelReqs), and Add() is a function that lets us put something new on the end of a list. powerLevelReqs tracks the number of seal breaks we need to unlock the power that’s in the same place as the power is in its list, so adding a “0” to the end means that the Thanos Snap power will be unlocked at 0 seal breaks.
* We use the word “new” whenever we’re creating an instance of anything fancier than a variable. If the class has one or more constructors we need to feed it the right parameters (remember that we need to give Powers the map), but even if it doesn’t we still need to write “new myClass()”.
* The Overmind class acts as a sort of “game manager”, storing a bunch of things like agent list, world panic, and the magical arms race. For our purposes, it also stores the god we’re playing as.

With that, we have our new Power, we have something to give it to the player, and all we have to do is put the DLL in our mod folder.

Click “Build” on the top toolbar, then “Build Solution” or “Rebuild Solution”.

This will create your .dll file. Open up your Visual Studio project folder, go into bin/debug (or bin/release if bin/debug is empty), and copy ShadowsThanosSnap.dll. Paste that into your mod folder in Shadows of Forbidden Gods/data/optionalData, and you now have a fully working mod. It’ll be activated by default, or you can deactivate it by pressing the Mod Configuration button in SoFG’s main menu. Boot it up, revel at the raw power at your fingertips, and realize your world panic is now through the roof despite not having got any closer to winning.

This guide has focused on a very simple and narrow power, added to your god in a very simple way, but the methods we’ve used can be applied to just about anything in SoFG. Find something in the base game that does something similar to what you want, copy+paste it into your own mod, and make what changes are needed. I would never propose that DLL modding this game from zero coding knowledge is easy, and this definitely isn’t enough to understand every piece of code in the game, but I hope you now have enough coding literacy to learn the rest of what you need to learn. If you’re stuck on something or are unclear on how something in the base game works, the Shadows of Forbidden Gods Discord is (as of November 2023) very active and helpful toward people trying to figure out modding. I encourage you to stop by.

This concludes Lesson 4. In the next lesson, we’ll learn how to share your mod with others.

Next Lesson - Uploading Your Mod

Previous Lesson - Creating a New Power

Table of Contents