Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always run KSPCF first in ModuleManagerPostLoad #238

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)]
Loading