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
+8
View File
@@ -25,6 +25,7 @@ public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
_totalNodeSpInfo = AccessTools.Field(typeof(DysonSphereLayer), "totalNodeSP");
_totalFrameSpInfo = AccessTools.Field(typeof(DysonSphereLayer), "totalFrameSP");
_totalCpInfo = AccessTools.Field(typeof(DysonSphereLayer), "totalCP");
GameLogicProc.OnGameEnd += StopEjectOnNodeComplete.ResetState;
}
public static void Start()
@@ -35,6 +36,7 @@ public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
public static void Uninit()
{
GameLogicProc.OnGameEnd -= StopEjectOnNodeComplete.ResetState;
StopEjectOnNodeComplete.Enable(false);
OnlyConstructNodes.Enable(false);
Enable(false);
@@ -346,6 +348,12 @@ public class DysonSpherePatch : PatchImpl<DysonSpherePatch>
return comp is { Count: > 0 };
}
internal static void ResetState()
{
_initialized = false;
_nodeForAbsorb = null;
}
private static void OnGameBegin()
{
InitNodeForAbsorb();
@@ -6,10 +6,12 @@ using System.Reflection;
using HarmonyLib;
using UXAssist.Common;
using UXAssist.Common.GameConstants;
using UXAssist.Common.ModFeatures;
using GameLogicProc = UXAssist.Common.GameLogic;
namespace UXAssist.Patches.Factory;
[ModFeature("BeltSignalsForBuyOut")]
internal static class BeltSignalPatch
{
public static void Enable(bool enable)
@@ -41,6 +43,16 @@ internal static class BeltSignalPatch
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>
{
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 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()
{
Persist.Enable(true);
@@ -2,9 +2,12 @@ using System;
using System.Collections.Generic;
using HarmonyLib;
using UXAssist.Common;
using UXAssist.Common.ModFeatures;
using GameLogicProc = UXAssist.Common.GameLogic;
namespace UXAssist.Patches.Factory;
[ModFeature("VeinProtection")]
internal static class VeinProtectionPatch
{
public static void Enable(bool enable)
@@ -17,6 +20,16 @@ internal static class VeinProtectionPatch
ProtectVeinsFromExhaustion.InitConfig();
}
public static void Init()
{
GameLogicProc.OnGameEnd += ProtectVeinsFromExhaustion.ResetState;
}
public static void Uninit()
{
GameLogicProc.OnGameEnd -= ProtectVeinsFromExhaustion.ResetState;
}
internal class ProtectVeinsFromExhaustion : PatchImpl<ProtectVeinsFromExhaustion>
{
public static int KeepVeinAmount = 100;
@@ -28,6 +41,11 @@ internal static class VeinProtectionPatch
_keepOilAmount = Math.Max((int)(KeepOilSpeed / 0.00004f + 0.5f), 2500);
}
internal static void ResetState()
{
InitConfig();
}
[HarmonyPrefix]
[HarmonyPatch(typeof(MinerComponent), nameof(MinerComponent.InternalUpdate))]
private static bool MinerComponent_InternalUpdate_Prefix(PlanetFactory factory, VeinData[] veinPool, float power, float miningRate, float miningSpeed, int[] productRegister,