refactor: register static-state resets on game end

This commit is contained in:
2026-06-23 22:20:04 +08:00
parent b74005282e
commit 647b130993
7 changed files with 105 additions and 1 deletions
+19
View File
@@ -6,6 +6,7 @@ using HarmonyLib;
using UnityEngine.Bindings;
using UXAssist.Common;
using UXAssist.Common.ModFeatures;
using GameLogicProc = UXAssist.Common.GameLogic;
namespace CheatEnabler.Patches;
@@ -21,6 +22,7 @@ public static class GamePatch
DevShortcutsEnabled.SettingChanged += (_, _) => DevShortcuts.Enable(DevShortcutsEnabled.Value);
AbnormalDisablerEnabled.SettingChanged += (_, _) => AbnormalDisabler.Enable(AbnormalDisablerEnabled.Value);
UnlockTechEnabled.SettingChanged += (_, _) => UnlockTech.Enable(UnlockTechEnabled.Value);
GameLogicProc.OnGameEnd += ResetState;
}
public static void Start()
@@ -32,11 +34,18 @@ public static class GamePatch
public static void Uninit()
{
GameLogicProc.OnGameEnd -= ResetState;
UnlockTech.Enable(false);
AbnormalDisabler.Enable(false);
DevShortcuts.Enable(false);
}
private static void ResetState()
{
AbnormalDisabler.ResetState();
DevShortcuts.ResetState();
}
public class AbnormalDisabler : PatchImpl<AbnormalDisabler>
{
private static Dictionary<int, AbnormalityDeterminator> _savedDeterminators;
@@ -66,6 +75,11 @@ public static class GamePatch
}
}
internal static void ResetState()
{
_savedDeterminators = null;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(AbnormalityLogic), nameof(AbnormalityLogic.NotifyBeforeGameSave))]
[HarmonyPatch(typeof(AbnormalityLogic), nameof(AbnormalityLogic.NotifyOnAssemblerRecipePick))]
@@ -106,6 +120,11 @@ public static class GamePatch
if (_test != null) _test.active = false;
}
internal static void ResetState()
{
_test = null;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerController), nameof(PlayerController.Init))]
private static void PlayerController_Init_Postfix(PlayerController __instance)