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
@@ -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,