Getting started with writing Code for KSA¶
Unofficial project
There is currently no official way to add custom code to Kitten Space Agency. The tools used in this guide are developed by the community. They are not affiliated with or endorsed by the KSA developers.
Overview¶
This guide explains how to add custom code execution to Kitten Space Agency.
Prerequisites¶
To develop mods using visual studio you need the following prerequisites
- Any Visual Studio version with c# .NET 9 development tools installed.
- A github account
- A github access token with access to package registries
Step 1: Setting up the development environment¶
Currently the most popular way to create mods is by using StarMap.
Before starting this guide it is recommended to set up the example mod and running it to verify StarMap is working. You can find a guide here and an example mod here
THIS GUIDE USES STARMAP 0.2.x MAKE SURE YOU HAVE THE CORRECT VERSION
Creating the Visual Studio project¶
-
Create a new visual studio project by pressing
Create a new project.
-
Filter for the C# language
- Select
Class Library -
Click next

-
Enter
FirstModas the name of the project - Select a location
-
Press next

-
Select .NET version 9 (Standard Term Support)
- Press create

Setting up StarMap¶
Now that we have a working Visual Studio project it is time to setup StarMap. For this step you will need the previously mentioned github access key so make sure you have that ready.
We will have to add a custom Package Source to nuget to be able to use StarMap
- Right click the project
-
Select
Manage NuGet Packages
-
Click the cogwheel

-
Under
NuGet Package ManagerSelectPackage Sources - Press
Add - Under Name write
StarMap - Under Source write
https://nuget.pkg.github.com/StarMapLoader/index.json - Press Save
-
Close the options tab

-
Under Package Source Select
StarMap - Open the Browse Tab
- A dialog box will open
- Under username Select
Personal Access Token - Instead of using your github password under password enter your Personal Access token.
-
Press
Ok
-
Select
StarMap.API - Press
Install - Complete the installation process

- StarMap should be set up
Setting up Harmony¶
- Under Package Source select
nuget.orgagain - Go to the
Browsetab - Search for
harmony - Select
Lib.Harmony - Press
Install - Wait for the instal to finish

Step 2: Adding dependencies¶
When using StarMap to mod the game you will eventually need external resources from the game itself called assemblies or .dll files. For a basic mod you only need one dependency: KSA.dll. So this first-steps guide will do just that.
- Right click on dependencies
-
Press Add Project Reference

-
Press Browse
- Now go to the KSA install directory (default: C:\Program Files\Kitten Space Agency) and find KSA.dll, Select it and click add
- Press OK

Step 3: Creating a Mod class¶
StarMap automatically loads the class with the same name as the .dll file and that has the [StarMapMod] attribute
Our first step will be creating this class. Our example will be using the name FirstMod for the mod.
Creating the class¶
Create a class under the namespace FirstMod with the name FirstMod. And let it inherit from IStarMapMod
using StarMap.API;
namespace FirstMod
{
[StarMapMod]
public class FirstMod
{
}
}
The api exposes a couple of attributes but for this simple hello world example we only need one:
[StarMapImmediateLoad]. The function marked with this attribute will be run when the mod is loaded. The function this attribute is assigned to does need to take in Mod definingMod as a parameter.
The Mod class needs the KSA namespace (found in KSA.dll) so we will add using KSA on the top of the file.
using StarMap.API;
using KSA;
namespace FirstMod
{
[StarMapMod]
public class FirstMod
{
[StarMapImmediateLoad]
public void Init(Mod definingMod)
{
}
}
}
Lets make a simple hello world program now.
Just add a Console.WriteLine("Hello World!")
Inside FirstMod:
[StarMapImmediateLoad]
public void Init(Mod definingMod)
{
Console.WriteLine("Hello World!");
}
Step 4: Creating mod.toml¶
A mod should always have a mod.toml file so it can be identified by StarMap. Lets Create that file.
- Create a new file in Visual Studio and call it
mod.toml. -
Edit the file and add this inside, name should always be the name of both the dll and the class that implements IStarMapMod.
name = "FirstMod" -
Now right click on mod.toml and select
Properties. - Under properties there is a field called
Copy To Output Directoryset it toCopy always.
Step 5: Compiling¶
If you did all steps correctly simply right clicking the project and selecting Build should build the files.
The compiled files will now be in the following directory: projectdir\FirstMod\bin\Debug\net9.0.
Now follow the installation guide to test your brand new mod. If you did all the steps correctly you should see Hello World! in the console output of StarMap.exe.