Skip to content

Commit

Permalink
Add more PPatchManager patch locations (#525)
Browse files Browse the repository at this point in the history
Add two new available settings for the `RunAt` for `PPatchManager` patches:
* `DetailsScreen.OnPrefabInit` - For registering custom SideScreenContents
* `Db.PostProcess` - For patching after all buildings, entities and other prefabs have been fully created
  • Loading branch information
SanchozzDeponianin authored Nov 21, 2024
1 parent 7837264 commit 2ae119c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
20 changes: 19 additions & 1 deletion PLibCore/PatchManager/PPatchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ private static void Initialize_Postfix() {
Instance?.InvokeAllProcess(RunAt.AfterDbInit, null);
}

private static void PostProcess_Prefix() {
Instance?.InvokeAllProcess(RunAt.BeforeDbPostProcess, null);
}

private static void PostProcess_Postfix() {
Instance?.InvokeAllProcess(RunAt.AfterDbPostProcess, null);
}

private static void Instance_Postfix() {
bool load = false;
if (Instance != null)
Expand All @@ -87,6 +95,10 @@ private static void MainMenu_OnSpawn_Postfix() {
Instance?.InvokeAllProcess(RunAt.InMainMenu, null);
}

private static void DetailsScreen_OnPrefabInit_Postfix() {
Instance?.InvokeAllProcess(RunAt.OnDetailsScreenInit, null);
}

public override Version Version => VERSION;

/// <summary>
Expand Down Expand Up @@ -147,7 +159,7 @@ public PPatchManager(Harmony harmony) {
GetNameSafe());
}
this.harmony = harmony;
patches = new Dictionary<uint, PrivateRunList>(8);
patches = new Dictionary<uint, PrivateRunList>(11);
InstanceData = patches;
}

Expand All @@ -168,6 +180,8 @@ public override void Initialize(Harmony plibInstance) {
// Db
plibInstance.Patch(typeof(Db), nameof(Db.Initialize), prefix: PatchMethod(nameof(
Initialize_Prefix)), postfix: PatchMethod(nameof(Initialize_Postfix)));
plibInstance.Patch(typeof(Db), nameof(Db.PostProcess), prefix: PatchMethod(nameof(
PostProcess_Prefix)), postfix: PatchMethod(nameof(PostProcess_Postfix)));

// Game
plibInstance.Patch(typeof(Game), "DestroyInstances", postfix: PatchMethod(nameof(
Expand All @@ -182,6 +196,10 @@ public override void Initialize(Harmony plibInstance) {
// MainMenu
plibInstance.Patch(typeof(MainMenu), "OnSpawn", postfix: PatchMethod(
nameof(MainMenu_OnSpawn_Postfix)));

// DetailsScreen
plibInstance.Patch(typeof(DetailsScreen), "OnPrefabInit", postfix: PatchMethod(
nameof(DetailsScreen_OnPrefabInit_Postfix)));
}

public override void PostInitialize(Harmony plibInstance) {
Expand Down
15 changes: 15 additions & 0 deletions PLibCore/PatchManager/RunAt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ public static class RunAt {
/// </summary>
public const uint AfterLayerableLoad = 7U;

/// <summary>
/// Runs immediately before Db.PostProcess.
/// </summary>
public const uint BeforeDbPostProcess = 8U;

/// <summary>
/// Runs immediately after Db.PostProcess.
/// </summary>
public const uint AfterDbPostProcess = 9U;

/// <summary>
/// Runs when DetailsScreen.OnPrefabInit has completed.
/// </summary>
public const uint OnDetailsScreenInit = 10U;

/// <summary>
/// The string equivalents of each constant for debugging.
/// </summary>
Expand Down

0 comments on commit 2ae119c

Please sign in to comment.