Skip to content

Commit

Permalink
Always run KSPCF first in MMPostLoad
Browse files Browse the repository at this point in the history
  • Loading branch information
al2me6 committed Jul 28, 2024
1 parent 441f2d7 commit b2d6d5a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
14 changes: 11 additions & 3 deletions KSPCommunityFixes/KSPCommunityFixes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void Start()
Destroy(Instance);
Instance = null;
}

if (Instance.IsNullOrDestroyed())
{
Instance = this;
Expand All @@ -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<List<ModuleManager.ModuleManagerPostPatchCallback>>(typeof(ModuleManager.PostPatchLoader), "postPatchCallbacks")
.Insert(0, MMPostLoadCallback);
}

public void ModuleManagerPostLoad()
public void MMPostLoadCallback()
{
if (Instance.IsNullOrDestroyed() || !Instance.RefEquals(this))
return;
Expand All @@ -106,7 +114,7 @@ public void ModuleManagerPostLoad()
if (!type.IsAbstract && type.IsSubclassOf(basePatchType))
{
patchesTypes.Add(type);

}
}

Expand Down
6 changes: 5 additions & 1 deletion KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
<Name>Harmony</Name>
<Private>False</Private>
</Reference>
<Reference Include="$(ReferencePath)\GameData\ModuleManager.*.dll">
<Name>ModuleManager</Name>
<Private>False</Private>
</Reference>
</ItemGroup>
<!--Krafs.Publicizer items-->
<ItemGroup>
Expand Down Expand Up @@ -407,4 +411,4 @@
<Error Condition="!Exists('..\packages\Krafs.Publicizer.2.2.1\build\Krafs.Publicizer.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Krafs.Publicizer.2.2.1\build\Krafs.Publicizer.targets'))" />
</Target>
<Import Project="..\packages\Krafs.Publicizer.2.2.1\build\Krafs.Publicizer.targets" Condition="Exists('..\packages\Krafs.Publicizer.2.2.1\build\Krafs.Publicizer.targets')" />
</Project>
</Project>
1 change: 1 addition & 0 deletions KSPCommunityFixes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@

[assembly: KSPAssembly("KSPCommunityFixes", 1, 35, 2)]
[assembly: KSPAssemblyDependency("MultipleModulePartAPI", 1, 0, 0)]
[assembly: KSPAssemblyDependency("ModuleManager", 1, 0)]

0 comments on commit b2d6d5a

Please sign in to comment.