mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-08-05 11:30:14 +08:00
refactor: register static-state resets on game end
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user