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 7, 2024
1 parent 441f2d7 commit 9dfdeaf
Show file tree
Hide file tree
Showing 2 changed files with 16 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>

0 comments on commit 9dfdeaf

Please sign in to comment.