mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-08-05 19:00:12 +08:00
refactor: register static-state resets on game end
This commit is contained in:
@@ -4,11 +4,13 @@ using System.Linq;
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UXAssist.Common;
|
using UXAssist.Common;
|
||||||
|
using UXAssist.Common.ModFeatures;
|
||||||
using GameLogicProc = UXAssist.Common.GameLogic;
|
using GameLogicProc = UXAssist.Common.GameLogic;
|
||||||
using UXAssist.Common.GameConstants;
|
using UXAssist.Common.GameConstants;
|
||||||
|
|
||||||
namespace CheatEnabler.Patches.Factory;
|
namespace CheatEnabler.Patches.Factory;
|
||||||
|
|
||||||
|
[ModFeature("BeltSignalGenerator")]
|
||||||
internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
|
internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
|
||||||
{
|
{
|
||||||
private static Dictionary<int, BeltSignal>[] _signalBelts;
|
private static Dictionary<int, BeltSignal>[] _signalBelts;
|
||||||
@@ -17,6 +19,25 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
|
|||||||
private static int _signalBeltsCapacity;
|
private static int _signalBeltsCapacity;
|
||||||
private static bool _initialized;
|
private static bool _initialized;
|
||||||
|
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
GameLogicProc.OnGameEnd += ResetState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Uninit()
|
||||||
|
{
|
||||||
|
GameLogicProc.OnGameEnd -= ResetState;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ResetState()
|
||||||
|
{
|
||||||
|
_initialized = false;
|
||||||
|
_signalBelts = null;
|
||||||
|
_portalFrom = null;
|
||||||
|
_portalTo = null;
|
||||||
|
_signalBeltsCapacity = 0;
|
||||||
|
}
|
||||||
|
|
||||||
private class BeltSignal
|
private class BeltSignal
|
||||||
{
|
{
|
||||||
public int SignalId;
|
public int SignalId;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using HarmonyLib;
|
|||||||
using UnityEngine.Bindings;
|
using UnityEngine.Bindings;
|
||||||
using UXAssist.Common;
|
using UXAssist.Common;
|
||||||
using UXAssist.Common.ModFeatures;
|
using UXAssist.Common.ModFeatures;
|
||||||
|
using GameLogicProc = UXAssist.Common.GameLogic;
|
||||||
|
|
||||||
namespace CheatEnabler.Patches;
|
namespace CheatEnabler.Patches;
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ public static class GamePatch
|
|||||||
DevShortcutsEnabled.SettingChanged += (_, _) => DevShortcuts.Enable(DevShortcutsEnabled.Value);
|
DevShortcutsEnabled.SettingChanged += (_, _) => DevShortcuts.Enable(DevShortcutsEnabled.Value);
|
||||||
AbnormalDisablerEnabled.SettingChanged += (_, _) => AbnormalDisabler.Enable(AbnormalDisablerEnabled.Value);
|
AbnormalDisablerEnabled.SettingChanged += (_, _) => AbnormalDisabler.Enable(AbnormalDisablerEnabled.Value);
|
||||||
UnlockTechEnabled.SettingChanged += (_, _) => UnlockTech.Enable(UnlockTechEnabled.Value);
|
UnlockTechEnabled.SettingChanged += (_, _) => UnlockTech.Enable(UnlockTechEnabled.Value);
|
||||||
|
GameLogicProc.OnGameEnd += ResetState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Start()
|
public static void Start()
|
||||||
@@ -32,11 +34,18 @@ public static class GamePatch
|
|||||||
|
|
||||||
public static void Uninit()
|
public static void Uninit()
|
||||||
{
|
{
|
||||||
|
GameLogicProc.OnGameEnd -= ResetState;
|
||||||
UnlockTech.Enable(false);
|
UnlockTech.Enable(false);
|
||||||
AbnormalDisabler.Enable(false);
|
AbnormalDisabler.Enable(false);
|
||||||
DevShortcuts.Enable(false);
|
DevShortcuts.Enable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ResetState()
|
||||||
|
{
|
||||||
|
AbnormalDisabler.ResetState();
|
||||||
|
DevShortcuts.ResetState();
|
||||||
|
}
|
||||||
|
|
||||||
public class AbnormalDisabler : PatchImpl<AbnormalDisabler>
|
public class AbnormalDisabler : PatchImpl<AbnormalDisabler>
|
||||||
{
|
{
|
||||||
private static Dictionary<int, AbnormalityDeterminator> _savedDeterminators;
|
private static Dictionary<int, AbnormalityDeterminator> _savedDeterminators;
|
||||||
@@ -66,6 +75,11 @@ public static class GamePatch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void ResetState()
|
||||||
|
{
|
||||||
|
_savedDeterminators = null;
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(typeof(AbnormalityLogic), nameof(AbnormalityLogic.NotifyBeforeGameSave))]
|
[HarmonyPatch(typeof(AbnormalityLogic), nameof(AbnormalityLogic.NotifyBeforeGameSave))]
|
||||||
[HarmonyPatch(typeof(AbnormalityLogic), nameof(AbnormalityLogic.NotifyOnAssemblerRecipePick))]
|
[HarmonyPatch(typeof(AbnormalityLogic), nameof(AbnormalityLogic.NotifyOnAssemblerRecipePick))]
|
||||||
@@ -106,6 +120,11 @@ public static class GamePatch
|
|||||||
if (_test != null) _test.active = false;
|
if (_test != null) _test.active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void ResetState()
|
||||||
|
{
|
||||||
|
_test = null;
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(PlayerController), nameof(PlayerController.Init))]
|
[HarmonyPatch(typeof(PlayerController), nameof(PlayerController.Init))]
|
||||||
private static void PlayerController_Init_Postfix(PlayerController __instance)
|
private static void PlayerController_Init_Postfix(PlayerController __instance)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using UnityEngine;
|
|||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using UXAssist.Common;
|
using UXAssist.Common;
|
||||||
using UXAssist.UI;
|
using UXAssist.UI;
|
||||||
|
using GameLogicProc = UXAssist.Common.GameLogic;
|
||||||
|
|
||||||
namespace UXAssist.Functions.UI;
|
namespace UXAssist.Functions.UI;
|
||||||
|
|
||||||
@@ -31,7 +32,8 @@ internal static class MilkyWayUI
|
|||||||
|
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
}
|
GameLogicProc.OnGameEnd += ResetState;
|
||||||
|
}
|
||||||
|
|
||||||
public static void Start()
|
public static void Start()
|
||||||
{
|
{
|
||||||
@@ -39,6 +41,13 @@ internal static class MilkyWayUI
|
|||||||
|
|
||||||
public static void Uninit()
|
public static void Uninit()
|
||||||
{
|
{
|
||||||
|
GameLogicProc.OnGameEnd -= ResetState;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ResetState()
|
||||||
|
{
|
||||||
|
ClearClusterUploadResults();
|
||||||
|
_topTenPlayerData = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OnInputUpdate()
|
public static void OnInputUpdate()
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
|
|||||||
_totalNodeSpInfo = AccessTools.Field(typeof(DysonSphereLayer), "totalNodeSP");
|
_totalNodeSpInfo = AccessTools.Field(typeof(DysonSphereLayer), "totalNodeSP");
|
||||||
_totalFrameSpInfo = AccessTools.Field(typeof(DysonSphereLayer), "totalFrameSP");
|
_totalFrameSpInfo = AccessTools.Field(typeof(DysonSphereLayer), "totalFrameSP");
|
||||||
_totalCpInfo = AccessTools.Field(typeof(DysonSphereLayer), "totalCP");
|
_totalCpInfo = AccessTools.Field(typeof(DysonSphereLayer), "totalCP");
|
||||||
|
GameLogicProc.OnGameEnd += StopEjectOnNodeComplete.ResetState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Start()
|
public static void Start()
|
||||||
@@ -35,6 +36,7 @@ public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
|
|||||||
|
|
||||||
public static void Uninit()
|
public static void Uninit()
|
||||||
{
|
{
|
||||||
|
GameLogicProc.OnGameEnd -= StopEjectOnNodeComplete.ResetState;
|
||||||
StopEjectOnNodeComplete.Enable(false);
|
StopEjectOnNodeComplete.Enable(false);
|
||||||
OnlyConstructNodes.Enable(false);
|
OnlyConstructNodes.Enable(false);
|
||||||
Enable(false);
|
Enable(false);
|
||||||
@@ -346,6 +348,12 @@ public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
|
|||||||
return comp is { Count: > 0 };
|
return comp is { Count: > 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void ResetState()
|
||||||
|
{
|
||||||
|
_initialized = false;
|
||||||
|
_nodeForAbsorb = null;
|
||||||
|
}
|
||||||
|
|
||||||
private static void OnGameBegin()
|
private static void OnGameBegin()
|
||||||
{
|
{
|
||||||
InitNodeForAbsorb();
|
InitNodeForAbsorb();
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ using System.Reflection;
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using UXAssist.Common;
|
using UXAssist.Common;
|
||||||
using UXAssist.Common.GameConstants;
|
using UXAssist.Common.GameConstants;
|
||||||
|
using UXAssist.Common.ModFeatures;
|
||||||
using GameLogicProc = UXAssist.Common.GameLogic;
|
using GameLogicProc = UXAssist.Common.GameLogic;
|
||||||
|
|
||||||
namespace UXAssist.Patches.Factory;
|
namespace UXAssist.Patches.Factory;
|
||||||
|
|
||||||
|
[ModFeature("BeltSignalsForBuyOut")]
|
||||||
internal static class BeltSignalPatch
|
internal static class BeltSignalPatch
|
||||||
{
|
{
|
||||||
public static void Enable(bool enable)
|
public static void Enable(bool enable)
|
||||||
@@ -41,6 +43,16 @@ internal static class BeltSignalPatch
|
|||||||
storage[i] = r.ReadInt32();
|
storage[i] = r.ReadInt32();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
GameLogicProc.OnGameEnd += BeltSignalsForBuyOut.ResetState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Uninit()
|
||||||
|
{
|
||||||
|
GameLogicProc.OnGameEnd -= BeltSignalsForBuyOut.ResetState;
|
||||||
|
}
|
||||||
|
|
||||||
internal class BeltSignalsForBuyOut : PatchImpl<BeltSignalsForBuyOut>
|
internal class BeltSignalsForBuyOut : PatchImpl<BeltSignalsForBuyOut>
|
||||||
{
|
{
|
||||||
private static bool _initialized;
|
private static bool _initialized;
|
||||||
@@ -52,6 +64,15 @@ internal static class BeltSignalPatch
|
|||||||
private static Dictionary<int, uint>[] _signalBelts = new Dictionary<int, uint>[64];
|
private static Dictionary<int, uint>[] _signalBelts = new Dictionary<int, uint>[64];
|
||||||
private static readonly HashSet<int> SignalBeltFactoryIndices = [];
|
private static readonly HashSet<int> SignalBeltFactoryIndices = [];
|
||||||
|
|
||||||
|
internal static void ResetState()
|
||||||
|
{
|
||||||
|
_clusterSeedKey = 0L;
|
||||||
|
_signalBelts = null;
|
||||||
|
SignalBeltFactoryIndices.Clear();
|
||||||
|
for (var i = 0; i < DarkFogItemsInVoid.Length; i++)
|
||||||
|
DarkFogItemsInVoid[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
public static void InitPersist()
|
public static void InitPersist()
|
||||||
{
|
{
|
||||||
Persist.Enable(true);
|
Persist.Enable(true);
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using UXAssist.Common;
|
using UXAssist.Common;
|
||||||
|
using UXAssist.Common.ModFeatures;
|
||||||
|
using GameLogicProc = UXAssist.Common.GameLogic;
|
||||||
|
|
||||||
namespace UXAssist.Patches.Factory;
|
namespace UXAssist.Patches.Factory;
|
||||||
|
|
||||||
|
[ModFeature("VeinProtection")]
|
||||||
internal static class VeinProtectionPatch
|
internal static class VeinProtectionPatch
|
||||||
{
|
{
|
||||||
public static void Enable(bool enable)
|
public static void Enable(bool enable)
|
||||||
@@ -17,6 +20,16 @@ internal static class VeinProtectionPatch
|
|||||||
ProtectVeinsFromExhaustion.InitConfig();
|
ProtectVeinsFromExhaustion.InitConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
GameLogicProc.OnGameEnd += ProtectVeinsFromExhaustion.ResetState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Uninit()
|
||||||
|
{
|
||||||
|
GameLogicProc.OnGameEnd -= ProtectVeinsFromExhaustion.ResetState;
|
||||||
|
}
|
||||||
|
|
||||||
internal class ProtectVeinsFromExhaustion : PatchImpl<ProtectVeinsFromExhaustion>
|
internal class ProtectVeinsFromExhaustion : PatchImpl<ProtectVeinsFromExhaustion>
|
||||||
{
|
{
|
||||||
public static int KeepVeinAmount = 100;
|
public static int KeepVeinAmount = 100;
|
||||||
@@ -28,6 +41,11 @@ internal static class VeinProtectionPatch
|
|||||||
_keepOilAmount = Math.Max((int)(KeepOilSpeed / 0.00004f + 0.5f), 2500);
|
_keepOilAmount = Math.Max((int)(KeepOilSpeed / 0.00004f + 0.5f), 2500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void ResetState()
|
||||||
|
{
|
||||||
|
InitConfig();
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(typeof(MinerComponent), nameof(MinerComponent.InternalUpdate))]
|
[HarmonyPatch(typeof(MinerComponent), nameof(MinerComponent.InternalUpdate))]
|
||||||
private static bool MinerComponent_InternalUpdate_Prefix(PlanetFactory factory, VeinData[] veinPool, float power, float miningRate, float miningSpeed, int[] productRegister,
|
private static bool MinerComponent_InternalUpdate_Prefix(PlanetFactory factory, VeinData[] veinPool, float power, float miningRate, float miningSpeed, int[] productRegister,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using UnityEngine.UI;
|
|||||||
using UXAssist.Common;
|
using UXAssist.Common;
|
||||||
using UXAssist.Common.GameConstants;
|
using UXAssist.Common.GameConstants;
|
||||||
using UXAssist.Common.ModFeatures;
|
using UXAssist.Common.ModFeatures;
|
||||||
|
using GameLogicProc = UXAssist.Common.GameLogic;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace UniverseGenTweaks;
|
namespace UniverseGenTweaks;
|
||||||
@@ -29,14 +30,21 @@ public static class GalaxySelectUIPatch
|
|||||||
{
|
{
|
||||||
MoreSettings.Enabled.SettingChanged += OnEnabledChanged;
|
MoreSettings.Enabled.SettingChanged += OnEnabledChanged;
|
||||||
Enable(MoreSettings.Enabled.Value);
|
Enable(MoreSettings.Enabled.Value);
|
||||||
|
GameLogicProc.OnGameEnd += ResetState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Uninit()
|
public static void Uninit()
|
||||||
{
|
{
|
||||||
|
GameLogicProc.OnGameEnd -= ResetState;
|
||||||
MoreSettings.Enabled.SettingChanged -= OnEnabledChanged;
|
MoreSettings.Enabled.SettingChanged -= OnEnabledChanged;
|
||||||
Enable(false);
|
Enable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ResetState()
|
||||||
|
{
|
||||||
|
// No per-game mutable fields in this file; UI references are lifecycle-safe.
|
||||||
|
}
|
||||||
|
|
||||||
private static void OnEnabledChanged(object sender, System.EventArgs e)
|
private static void OnEnabledChanged(object sender, System.EventArgs e)
|
||||||
{
|
{
|
||||||
Enable(MoreSettings.Enabled.Value);
|
Enable(MoreSettings.Enabled.Value);
|
||||||
|
|||||||
Reference in New Issue
Block a user