The player can save and load the game through "File" > "Save/Load" ("F7") which shows a window. With "New" a player can create a save game, which can be loaded by double-clicking the save game name in the list:

A mod could make use of this process to also save and load its data. This page describes how to do this.
Verified versions: v2025.12.31.3103 ~ v2026.10.19.5638
The "Save Games" window is drawn by the KSA.GameSaves.GameSavesWindow class. The KSA.GameSaves.GameSavesWindo.DrawMenuBar() draws the menu with the New button. If the user presses the menu button, a pop-up is created that will call the KSA.GameSaves.MakeUncompressedSave(string name) function with the save game name filled by the user. This function will call KSA.UncompressedSave.Make(string name) which will call the KSA.UncompressedSave.Write() function. The latter function will delete and create the save game directory with the name provided by the user, and returns false if it could not. Then KSA.UniverseData.WriteTo(Directory) is called to write a universe.xml file, which is the XML serialized version of the KSA.UniverseData class, in which Kitten Space Agency stores its internal data. The save game folder can be found in KSA.GameSaves.SaveFolderPath, which is the "saves" directory in the documents directory.
The "Save Games" window is drawn by the KSA.GameSaves.GameSavesWindow class. The DrawContent() function draws the table with the available game saves. Each row in this table represents a save game and is drawn by calling the KSA.GameSave.DrawInTable() function. Currently, all game saves are a KSA.UncompressedSave instance (which is a child class of KSA.GameSave).
If the user user loads the game same, a pop-up to confirm is created, which will call the KSA.UncompressedSave.Load() function. This function calls the Universe.DeserializeSave(UniverseData) function, where UniverseData is the data loaded from the universe.xml file in the save game directory.
With the help of Harmony a mod can patch functions in KSA to add code to be executed.
The mod should define a patch that will do a Postfix to the KSA.UniverseData.WriteTo() function.
WriteTo runs inside a try/catch in UncompressedSave.Write(). If your postfix throws, the game does not crash; the player sees "Save 'name' could not be written" even though universe.xml was written. Catch your own exceptions and log them so that message is not blamed on the game.
Patching KSA.UncompressedSave.Write() won't work. As a Prefix patch, the directory is not yet created, or would be deleted by KSA.UncompressedSave.Write(). As a Postfix patch, the KSA.UncompressedSave.CacheStrings() has already been called.
Example UniverseDataPatch.cs:
using HarmonyLib;
using KSA;
using System;
using System.Collections.Generic;
using System.Text;
namespace YOURMODNAME
{
[HarmonyPatch]
internal static class UniverseDataPatchWriteTo
{
private static Harmony? _harmony = new Harmony("YOURMODNAME");
public static void Patch()
{
Console.WriteLine("Patching UniverseData...");
_harmony?.PatchAll(typeof(UniverseDataPatchWriteTo).Assembly);
}
public static void Unload()
{
_harmony?.UnpatchAll(_harmony.Id);
_harmony = null;
}
[HarmonyPatch(typeof(KSA.UniverseData), nameof(KSA.UniverseData.WriteTo), typeof(DirectoryInfo))]
[HarmonyPostfix]
public static void WriteToPostfix(DirectoryInfo directory)
{
Console.WriteLine($"UniverseDataPatchWriteTo.WriteToPostfix() writing data to '{directory.FullName}'");
// Write mod data to disk
}
}
}
The mod should define a patch that will do a Postfix to the KSA.UncompressedSave.Load() function.
Example UncompressedSavePatch.cs:
using HarmonyLib;
using KSA;
using System;
using System.Collections.Generic;
using System.Text;
namespace YOURMODNAME
{
[HarmonyPatch]
internal static class UncompressedSavePatchLoad
{
private static Harmony? _harmony = new Harmony("YOURMODNAME");
public static void Patch()
{
Console.WriteLine("Patching UncompressedSave...");
_harmony?.PatchAll(typeof(UncompressedSavePatchLoad).Assembly);
}
public static void Unload()
{
_harmony?.UnpatchAll(_harmony.Id);
_harmony = null;
}
[HarmonyPatch(typeof(KSA.UncompressedSave), nameof(KSA.UncompressedSave.Load))]
[HarmonyPostfix]
public static void LoadPostfix(ref KSA.UncompressedSave __instance)
{
Console.WriteLine($"UncompressedSavePatchLoad.LoadPostfix() loading data from '{__instance.Directory.FullName}'");
// Read mod data from disk
}
}
}
Writing and reading mod data could be done in many ways. However, since KSA uses .xml file(s), a mod could use the same to be consistent with the game.
C# offers an easy way to write and read data in XML format using System.XML.Serialization.
Example:
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml.Linq;
using System.Xml.Serialization;
namespace YOURMODNAME
{
public class YourModData
{
// XML serializable fields
// The version for which the data was saved.
[XmlElement("version")]
public string version { get; set; } = "0.0.1";
// example int
[XmlElement("exampleInt")]
public int exampleInt { get; set; } = 42;
// Write data to save file
public void WriteTo(DirectoryInfo directory)
{
XmlSerializer serializer = new XmlSerializer(typeof(YourModData));
XmlHelper.SerializeWithoutNaN(serializer, this, Path.Combine(directory.FullName, "yourmodname.xml"));
}
// Load data from save file.
public bool LoadFrom(DirectoryInfo directory)
{
string filePathXmlFile = Path.Combine(directory.FullName, "yourmodname.xml");
if (!File.Exists(filePathXmlFile)) { return false; }
XDocument? xmlDocument = null;
using (var reader = new System.IO.StreamReader(filePathXmlFile))
{
xmlDocument = XDocument.Load(reader);
}
XmlSerializer serializer = new XmlSerializer(typeof(YourModData));
YourModData? yourModData = (YourModData)serializer.Deserialize(new StringReader(xmlDocument.ToString()));
}
}
}