Tested with: KSA Version 2026.10.19.5638
This guide will cover how to setup harmony.
"Harmony gives you an elegant and high level way to alter the functionality in applications written in C#." [1]
This guide continues from the First-Steps Guide
for this guide you will need:
Harmony loads classes the same way StarMap does so we will create a second class to not confuse the 2.
This class will be called Patcher and it will use the HarmonyPatch attribute.
using HarmonyLib to the top of your fileusing HarmonyLib
Patcher class."SimpleMod" should always match the name of your mod .dll file.[HarmonyPatch]
internal static class Patcher
{
private static Harmony? m_harmony = new Harmony("SimpleMod");
}
Now we need to have methods that can initialize harmony when the mod is loaded.
Add the following methods to Patcher
public static void patch()
{
m_harmony?.PatchAll(typeof(Patcher).Assembly);
}
public static void unload()
{
m_harmony?.UnpatchAll("SimpleMod");
m_harmony = null;
}
The patcher class is now done and ready to use. So lets put it to work.
Go to your main mod class (In our case: SimpleMod) and add the following functions:
[StarMapAllModsLoaded]
public void fullyLoaded()
{
Patcher.patch();
}
[StarMapUnload]
public void unload()
{
Patcher.unload();
}
fullyLoaded will be called when all other mods are loaded and will start the patcher class.
unload will be called when unloading the mod and will handle cleanup.
That's it you are now setup with Harmony.