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();
}
}