From d2adba353f245e979b692a9c465abaa0b4b7c864 Mon Sep 17 00:00:00 2001 From: KlaasWhite <45828001+KlaasWhite@users.noreply.github.com> Date: Sat, 6 Dec 2025 15:39:45 +0100 Subject: [PATCH 1/3] Do not try to unload the assembly load contexts (#44) --- StarMap.Core/ModRepository/LoadedModRepository.cs | 5 ----- StarMap/GameSurveyer.cs | 1 - 2 files changed, 6 deletions(-) diff --git a/StarMap.Core/ModRepository/LoadedModRepository.cs b/StarMap.Core/ModRepository/LoadedModRepository.cs index e309818..b1177d1 100644 --- a/StarMap.Core/ModRepository/LoadedModRepository.cs +++ b/StarMap.Core/ModRepository/LoadedModRepository.cs @@ -150,11 +150,6 @@ public void Dispose() method.Invoke(@object, []); } - foreach (var modLoadContext in _modLoadContexts.Values) - { - modLoadContext.Unload(); - } - _mods.Dispose(); } } diff --git a/StarMap/GameSurveyer.cs b/StarMap/GameSurveyer.cs index a706090..bdd67e8 100644 --- a/StarMap/GameSurveyer.cs +++ b/StarMap/GameSurveyer.cs @@ -57,7 +57,6 @@ public void RunGame() public void Dispose() { - _gameAssemblyContext.Unload(); _core?.DeInit(); } } From 082edb393cba21ab0f417350f8bb6434edb53a6e Mon Sep 17 00:00:00 2001 From: Eduardo Martin Date: Sun, 14 Dec 2025 17:32:57 +0100 Subject: [PATCH 2/3] Program.OnFrame Harmony patch --- StarMap.API/OnFrameAttributes.cs | 46 ++++++++++++++++++++++++++ StarMap.Core/Patches/ProgramPatcher.cs | 13 ++++++++ 2 files changed, 59 insertions(+) create mode 100644 StarMap.API/OnFrameAttributes.cs diff --git a/StarMap.API/OnFrameAttributes.cs b/StarMap.API/OnFrameAttributes.cs new file mode 100644 index 0000000..5844277 --- /dev/null +++ b/StarMap.API/OnFrameAttributes.cs @@ -0,0 +1,46 @@ +using System.Reflection; + +namespace StarMap.API +{ + /// + /// Methods marked with this attribute will be called after KSA Program.OnFrame is called. + /// + /// + /// Methods using this attribute must match the following signature: + /// + /// + /// public void MethodName(double currentPlayerTime, double dtPlayer); + /// + /// + /// Parameter requirements: + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// Requirements: + /// + /// Return type must be . + /// Method must be an instance method (non-static). + /// + /// + public sealed class StarMapAfterOnFrameAttribute : StarMapMethodAttribute + { + public override bool IsValidSignature(MethodInfo method) + { + return method.ReturnType == typeof(void) && + method.GetParameters().Length == 2 && + method.GetParameters()[0].ParameterType == typeof(double) && + method.GetParameters()[1].ParameterType == typeof(double); + + } + } +} diff --git a/StarMap.Core/Patches/ProgramPatcher.cs b/StarMap.Core/Patches/ProgramPatcher.cs index 69b79ca..9bc2710 100644 --- a/StarMap.Core/Patches/ProgramPatcher.cs +++ b/StarMap.Core/Patches/ProgramPatcher.cs @@ -8,6 +8,7 @@ namespace StarMap.Core.Patches internal static class ProgramPatcher { private const string OnDrawUiMethodName = "OnDrawUi"; + private const string OnFrameMethodName = "OnFrame"; [HarmonyPatch(OnDrawUiMethodName)] [HarmonyPrefix] @@ -32,5 +33,17 @@ public static void AfterOnDrawUi(double dt) method.Invoke(@object, [dt]); } } + + [HarmonyPatch(OnFrameMethodName)] + [HarmonyPostfix] + public static void AfterOnFrame(double currentPlayerTime, double dtPlayer) + { + var methods = StarMapCore.Instance?.LoadedMods.Mods.Get() ?? []; + + foreach (var (_, @object, method) in methods) + { + method.Invoke(@object, new object[] { currentPlayerTime, dtPlayer }); + } + } } } From 8f3d8eb61563ab8ecfca125c75989e5e7bce7e27 Mon Sep 17 00:00:00 2001 From: Eduardo Martin Date: Sun, 14 Dec 2025 17:39:24 +0100 Subject: [PATCH 3/3] Updated the API readme --- StarMap.API/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/StarMap.API/README.md b/StarMap.API/README.md index 0ee0184..b414faa 100644 --- a/StarMap.API/README.md +++ b/StarMap.API/README.md @@ -14,3 +14,4 @@ Any method within this class that has any of the attributes will used, so if two - StarMapUnload: Called when KSA is unloaded. - StarMapBeforeGui: Called just before KSA starts drawing its Ui. - StarMapAfterGui: Called after KSA has drawn its Ui. +- StarMapAfterOnFrame: Called after KSA calls Program.OnFrame