From 3e02cf8092da6caf2f7d610720265b846d7c6cc2 Mon Sep 17 00:00:00 2001 From: KlaasWhite <45828001+KlaasWhite@users.noreply.github.com> Date: Sat, 15 Nov 2025 19:47:50 +0100 Subject: [PATCH 1/2] Fix package release --- .github/workflows/release-zip.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release-zip.yml b/.github/workflows/release-zip.yml index 46b6c20..f4cc563 100644 --- a/.github/workflows/release-zip.yml +++ b/.github/workflows/release-zip.yml @@ -141,5 +141,4 @@ jobs: /p:Version=${{ steps.version.outputs.new }} \ /p:AssemblyVersion=${{ steps.version.outputs.new }} \ /p:FileVersion=${{ steps.version.outputs.new }} - dotnet nuget add source --username "${{ github.actor }}" --password "${{ secrets.GITHUB_TOKEN }}" --store-password-in-clear-text --name github "${{ env.NUGET_SOURCE }}" dotnet nuget push ./nupkg/*.nupkg --source github --api-key "${{ secrets.GITHUB_TOKEN }}" --skip-duplicate From 2abf16ad8c32e1ffd5a53fc9a49f7a955645b852 Mon Sep 17 00:00:00 2001 From: mihe Date: Mon, 15 Dec 2025 18:03:49 +0100 Subject: [PATCH 2/2] Onframepatch clean (#47) * Do not try to unload the assembly load contexts (#44) * Program.OnFrame Harmony patch * Updated the API readme --------- Co-authored-by: KlaasWhite <45828001+KlaasWhite@users.noreply.github.com> --- StarMap.API/OnFrameAttributes.cs | 46 +++++++++++++++++++ StarMap.API/README.md | 1 + .../ModRepository/LoadedModRepository.cs | 5 -- StarMap.Core/Patches/ProgramPatcher.cs | 13 ++++++ StarMap/GameSurveyer.cs | 1 - 5 files changed, 60 insertions(+), 6 deletions(-) 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.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 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.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 }); + } + } } } 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(); } }