From b2d6d5ae1a2baa0d047ef9c33369030ca731a929 Mon Sep 17 00:00:00 2001 From: Alvin Meng Date: Sun, 7 Jul 2024 16:14:41 -0400 Subject: [PATCH] Always run KSPCF first in MMPostLoad --- KSPCommunityFixes/KSPCommunityFixes.cs | 14 +++++++++++--- KSPCommunityFixes/KSPCommunityFixes.csproj | 6 +++++- KSPCommunityFixes/Properties/AssemblyInfo.cs | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/KSPCommunityFixes/KSPCommunityFixes.cs b/KSPCommunityFixes/KSPCommunityFixes.cs index 5e094c9..6cde182 100644 --- a/KSPCommunityFixes/KSPCommunityFixes.cs +++ b/KSPCommunityFixes/KSPCommunityFixes.cs @@ -63,7 +63,7 @@ void Start() Destroy(Instance); Instance = null; } - + if (Instance.IsNullOrDestroyed()) { Instance = this; @@ -77,9 +77,17 @@ void Start() #endif LocalizationUtils.GenerateLocTemplateIfRequested(); LocalizationUtils.ParseLocalization(); + + // Insert KSPCF as the first entry in the explicit callback list. + // This guarantees that KSPCF will run before all other post load callbacks. + // Note that this is cumbersome to access via publicizer because it references + // assemblies via file name, and ModuleManager's dll is versioned. + AccessTools + .StaticFieldRefAccess>(typeof(ModuleManager.PostPatchLoader), "postPatchCallbacks") + .Insert(0, MMPostLoadCallback); } - public void ModuleManagerPostLoad() + public void MMPostLoadCallback() { if (Instance.IsNullOrDestroyed() || !Instance.RefEquals(this)) return; @@ -106,7 +114,7 @@ public void ModuleManagerPostLoad() if (!type.IsAbstract && type.IsSubclassOf(basePatchType)) { patchesTypes.Add(type); - + } } diff --git a/KSPCommunityFixes/KSPCommunityFixes.csproj b/KSPCommunityFixes/KSPCommunityFixes.csproj index 5ccec49..7dc8389 100644 --- a/KSPCommunityFixes/KSPCommunityFixes.csproj +++ b/KSPCommunityFixes/KSPCommunityFixes.csproj @@ -84,6 +84,10 @@ Harmony False + + ModuleManager + False + @@ -407,4 +411,4 @@ - \ No newline at end of file + diff --git a/KSPCommunityFixes/Properties/AssemblyInfo.cs b/KSPCommunityFixes/Properties/AssemblyInfo.cs index 4d1d068..029bdff 100644 --- a/KSPCommunityFixes/Properties/AssemblyInfo.cs +++ b/KSPCommunityFixes/Properties/AssemblyInfo.cs @@ -34,3 +34,4 @@ [assembly: KSPAssembly("KSPCommunityFixes", 1, 35, 2)] [assembly: KSPAssemblyDependency("MultipleModulePartAPI", 1, 0, 0)] +[assembly: KSPAssemblyDependency("ModuleManager", 1, 0)]