From a133fd9e144a9d133d9079bd267f3a4a1f58ad82 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Tue, 23 Jun 2026 20:24:36 +0800 Subject: [PATCH] refactor(UXAssist): replace magic numbers with constants --- AGENTS.md | 1 + UXAssist/Functions/TechFunctions.cs | 2 +- UXAssist/Patches/Factory/BeltSignalPatch.cs | 9 ++- UXAssist/Patches/Logistics/AutoConfigPatch.cs | 3 +- UXAssist/Patches/Logistics/CapacityPatch.cs | 63 ++++++++-------- UXAssist/Patches/Logistics/LogisticsPatch.cs | 7 +- .../Logistics/RealtimeInfoPanelPatch.cs | 40 +++++----- UXAssist/Patches/TechPatch.cs | 75 +++---------------- 8 files changed, 76 insertions(+), 124 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 8df13fa..fc66494 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -144,5 +144,6 @@ The sync is implemented as an inline PowerShell `Exec` step inside the `ZipMod` - **Shared library:** `UXAssist` acts as a common library. `CheatEnabler` and `UniverseGenTweaks` reference `UXAssist.csproj` directly to reuse `Common/`, `UI/`, and config panel infrastructure. - **Preloader pattern:** `DustbinPreloader` and `LabOptPreloader` use Mono.Cecil to inject new fields into game assemblies at BepInEx preload time, enabling their corresponding main mods to read/write those fields via normal C# without reflection. - **Internationalization:** `UXAssist/Common/I18N.cs` provides bilingual (EN + ZH) string lookup used across UXAssist and CheatEnabler. +- **Centralized game constants:** Hard-coded item IDs, tech IDs, logistics capacities, and Dyson sphere geometry defaults live in `UXAssist/Common/GameConstants` (`ItemIds`, `TechIds`, `LogisticsConstants`, `DysonSphereConstants`). Prefer these constants over inline literals in UXAssist patches. - **Transpiler patches:** Performance-critical mods (LabOpt, MechaDronesTweaks) use `[HarmonyTranspiler]` to rewrite IL instructions directly for maximum efficiency. - **Save persistence:** Mods that need to persist data use the `IModCanSave` interface from DSPModSave. diff --git a/UXAssist/Functions/TechFunctions.cs b/UXAssist/Functions/TechFunctions.cs index 80dbacb..51a7dda 100644 --- a/UXAssist/Functions/TechFunctions.cs +++ b/UXAssist/Functions/TechFunctions.cs @@ -281,7 +281,7 @@ public static class TechFunctions var history = GameMain.data?.history; if (history == null) return; history.inserterStackCountObsolete = 1; - for (var id = 3301; id <= 3305; id++) + for (var id = global::UXAssist.Common.GameConstants.TechIds.SorterCargoStackingCustomStart; id <= global::UXAssist.Common.GameConstants.TechIds.SorterCargoStackingCustomEnd - 1; id++) { history.techStates.TryGetValue(id, out var state); if (!state.unlocked) continue; diff --git a/UXAssist/Patches/Factory/BeltSignalPatch.cs b/UXAssist/Patches/Factory/BeltSignalPatch.cs index c83fc75..3a37ed8 100644 --- a/UXAssist/Patches/Factory/BeltSignalPatch.cs +++ b/UXAssist/Patches/Factory/BeltSignalPatch.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Reflection; using HarmonyLib; using UXAssist.Common; +using UXAssist.Common.GameConstants; using GameLogicProc = UXAssist.Common.GameLogic; namespace UXAssist.Patches.Factory; @@ -45,7 +46,7 @@ internal static class BeltSignalPatch private static bool _initialized; private static bool _loaded; private static long _clusterSeedKey; - private static readonly int[] DarkFogItemIds = [5201, 5206, 5202, 5204, 5203, 5205]; + private static readonly int[] DarkFogItemIds = ItemIds.DarkFogItemIds; private static readonly int[] DarkFogItemExchangeRate = [20, 60, 30, 30, 30, 10]; public static readonly int[] DarkFogItemsInVoid = [0, 0, 0, 0, 0, 0]; private static Dictionary[] _signalBelts = new Dictionary[64]; @@ -340,13 +341,13 @@ internal static class BeltSignalPatch var consume = (byte)Math.Min(DarkFogItemsInVoid[itemIdx], 4); if (consume < 4) { - var metaverseLong = propertySystem.GetItemAvaliableProperty(_clusterSeedKey, 6006); + var metaverseLong = propertySystem.GetItemAvaliableProperty(_clusterSeedKey, ItemIds.Metaverse); if (metaverseLong > 0L) { var metaverse = metaverseLong > 10 ? 10 : (int)metaverseLong; - propertySystem.AddItemConsumption(_clusterSeedKey, 6006, metaverse); + propertySystem.AddItemConsumption(_clusterSeedKey, ItemIds.Metaverse, metaverse); var mainPlayer = GameMain.mainPlayer; - GameMain.history.AddPropertyItemConsumption(6006, metaverse, true); + GameMain.history.AddPropertyItemConsumption(ItemIds.Metaverse, metaverse, true); var count = DarkFogItemExchangeRate[itemIdx] * metaverse; DarkFogItemsInVoid[itemIdx] += count; consume = (byte)Math.Min(DarkFogItemsInVoid[itemIdx], 4); diff --git a/UXAssist/Patches/Logistics/AutoConfigPatch.cs b/UXAssist/Patches/Logistics/AutoConfigPatch.cs index 648d844..907d114 100644 --- a/UXAssist/Patches/Logistics/AutoConfigPatch.cs +++ b/UXAssist/Patches/Logistics/AutoConfigPatch.cs @@ -5,6 +5,7 @@ using BepInEx.Configuration; using HarmonyLib; using UnityEngine; using UXAssist.Common; +using UXAssist.Common.GameConstants; namespace UXAssist.Patches.Logistics; @@ -85,7 +86,7 @@ internal class AutoConfigLogistics : PatchImpl { if (__instance.handPrefabDesc.isDispenser) { - __instance.handBpParams[bpIndex][2] = (int)(long)(5000.0 * LogisticsPatch.AutoConfigDispenserChargePower.Value + 0.5); + __instance.handBpParams[bpIndex][2] = (int)(long)(LogisticsConstants.DispenserChargePowerMultiplier * LogisticsPatch.AutoConfigDispenserChargePower.Value + 0.5); } } diff --git a/UXAssist/Patches/Logistics/CapacityPatch.cs b/UXAssist/Patches/Logistics/CapacityPatch.cs index d709fb6..21ed2ce 100644 --- a/UXAssist/Patches/Logistics/CapacityPatch.cs +++ b/UXAssist/Patches/Logistics/CapacityPatch.cs @@ -7,6 +7,7 @@ using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using UXAssist.Common; +using UXAssist.Common.GameConstants; namespace UXAssist.Patches.Logistics; @@ -29,13 +30,13 @@ internal class LogisticsCapacityTweaks : PatchImpl if (code != _lastKey) { _lastKey = code; - _nextKeyTick = main.timei + 30; + _nextKeyTick = main.timei + LogisticsConstants.KeyRepeatInitialDelay; return true; } var currTick = main.timei; if (_nextKeyTick > currTick) return false; - _nextKeyTick = currTick + 4; + _nextKeyTick = currTick + LogisticsConstants.KeyRepeatInterval; return true; } @@ -54,38 +55,38 @@ internal class LogisticsCapacityTweaks : PatchImpl if (UpdateKeyPressed(KeyCode.LeftArrow)) { if (ctrl) - delta = -100000; + delta = -LogisticsConstants.MassiveAdjustment; else if (alt) - delta = -1000; + delta = -LogisticsConstants.LargeAdjustment; else - delta = -10; + delta = -LogisticsConstants.SmallAdjustment; } else if (UpdateKeyPressed(KeyCode.RightArrow)) { if (ctrl) - delta = 100000; + delta = LogisticsConstants.MassiveAdjustment; else if (alt) - delta = 1000; + delta = LogisticsConstants.LargeAdjustment; else - delta = 10; + delta = LogisticsConstants.SmallAdjustment; } else if (UpdateKeyPressed(KeyCode.DownArrow)) { if (ctrl) - delta = -1000000; + delta = -LogisticsConstants.GargantuanAdjustment; else if (alt) - delta = -10000; + delta = -LogisticsConstants.HugeAdjustment; else - delta = -100; + delta = -LogisticsConstants.MediumAdjustment; } else if (UpdateKeyPressed(KeyCode.UpArrow)) { if (ctrl) - delta = 1000000; + delta = LogisticsConstants.GargantuanAdjustment; else if (alt) - delta = 10000; + delta = LogisticsConstants.HugeAdjustment; else - delta = 100; + delta = LogisticsConstants.MediumAdjustment; } else { @@ -129,7 +130,7 @@ internal class LogisticsCapacityTweaks : PatchImpl int itemCountMax; if (LogisticsPatch.AllowOverflowInLogisticsEnabled.Value) { - itemCountMax = 90000000; + itemCountMax = LogisticsConstants.OverflowStorageMax; } else { @@ -230,7 +231,7 @@ internal class LogisticsCapacityTweaks : PatchImpl { var max = storage[j].max; if (max + 10 < intOldMaxCount || max >= intNewMaxCount) continue; - storage[j].max = Mathf.RoundToInt((float)(max * ratio / 50.0)) * 50; + storage[j].max = Mathf.RoundToInt((float)(max * ratio / LogisticsConstants.LocalStorageRounding)) * LogisticsConstants.LocalStorageRounding; } } @@ -256,7 +257,7 @@ internal class LogisticsCapacityTweaks : PatchImpl { var max = storage[j].max; if (max + 10 < intOldMaxCount || max >= intNewMaxCount) continue; - storage[j].max = Mathf.RoundToInt((float)(max * ratio / 100.0)) * 100; + storage[j].max = Mathf.RoundToInt((float)(max * ratio / LogisticsConstants.RemoteStorageRounding)) * LogisticsConstants.RemoteStorageRounding; } } @@ -275,7 +276,7 @@ internal class GreaterPowerUsageInLogistics : PatchImpl { - window.maxMiningSpeedSlider.maxValue = 27f; + window.maxMiningSpeedSlider.maxValue = LogisticsConstants.MiningSpeedSliderMaxExtended; }) ).MatchForward(false, new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(UIStationWindow), nameof(UIStationWindow.maxChargePowerSlider))), new CodeMatch(ci => ci.IsLdloc()), - new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(0xC350)), + new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(LogisticsConstants.ChargePowerSliderScale)), new CodeMatch(OpCodes.Conv_I8) ); var pos = matcher.Pos + 1; @@ -318,11 +319,11 @@ internal class GreaterPowerUsageInLogistics : PatchImpl { - var maxSliderValue = maxWorkEnergy / 50000L; + var maxSliderValue = maxWorkEnergy / LogisticsConstants.ChargePowerSliderScale; window.maxChargePowerSlider.maxValue = maxSliderValue + 9; - window.maxChargePowerSlider.minValue = maxWorkEnergy / 500000L; + window.maxChargePowerSlider.minValue = maxWorkEnergy / LogisticsConstants.ChargePowerSliderMinScale; if (workEnergyPerTick <= maxWorkEnergy) - window.maxChargePowerSlider.Set(workEnergyPerTick / 50000L, false); + window.maxChargePowerSlider.Set(workEnergyPerTick / LogisticsConstants.ChargePowerSliderScale, false); else window.maxChargePowerSlider.Set(maxSliderValue + (workEnergyPerTick - 1) / maxWorkEnergy + 1, false); }) @@ -348,9 +349,9 @@ internal class GreaterPowerUsageInLogistics : PatchImpl { - if (speed <= 30000) - return (speed - 10000) / 1000; - return (speed - 30000) / 10000 + 20; + if (speed <= LogisticsConstants.MaxMiningSpeedBase) + return (speed - LogisticsConstants.MinMiningSpeedBase) / LogisticsConstants.MiningSpeedFineStep; + return (speed - LogisticsConstants.MaxMiningSpeedBase) / LogisticsConstants.MiningSpeedCoarseStep + LogisticsConstants.MiningSpeedSliderMaxDefault; }) ); return matcher.InstructionEnumeration(); @@ -362,7 +363,7 @@ internal class GreaterPowerUsageInLogistics : PatchImpl ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(10000)), + new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(LogisticsConstants.MinMiningSpeedBase)), new CodeMatch(OpCodes.Ldarg_1) ); var pos = matcher.Pos; @@ -378,9 +379,9 @@ internal class GreaterPowerUsageInLogistics : PatchImpl { var intval = (int)(value + 0.5f); - if (intval <= 20) - return intval * 1000 + 10000; - return (intval - 20) * 10000 + 30000; + if (intval <= LogisticsConstants.MiningSpeedSliderMaxDefault) + return intval * LogisticsConstants.MiningSpeedFineStep + LogisticsConstants.MinMiningSpeedBase; + return (intval - LogisticsConstants.MiningSpeedSliderMaxDefault) * LogisticsConstants.MiningSpeedCoarseStep + LogisticsConstants.MaxMiningSpeedBase; }) ); return matcher.InstructionEnumeration(); diff --git a/UXAssist/Patches/Logistics/LogisticsPatch.cs b/UXAssist/Patches/Logistics/LogisticsPatch.cs index a73ceab..73d258d 100644 --- a/UXAssist/Patches/Logistics/LogisticsPatch.cs +++ b/UXAssist/Patches/Logistics/LogisticsPatch.cs @@ -5,6 +5,7 @@ using HarmonyLib; using UnityEngine; using UXAssist.Common; using UXAssist.Common.ModFeatures; +using UXAssist.Common.GameConstants; using GameLogicProc = UXAssist.Common.GameLogic; namespace UXAssist.Patches.Logistics; @@ -178,7 +179,7 @@ public static class LogisticsPatch { ref var entity = ref factory.entityPool[station.entityId]; if (entity.id != station.entityId || entity.minerId <= 0 || entity.minerId >= factory.factorySystem.minerCursor) return false; - factory.factorySystem.minerPool[entity.minerId].speed = 10000 + AutoConfigVeinCollectorHarvestSpeed.Value * 1000; + factory.factorySystem.minerPool[entity.minerId].speed = LogisticsConstants.MinMiningSpeedBase + AutoConfigVeinCollectorHarvestSpeed.Value * LogisticsConstants.MiningSpeedFineStep; return true; } @@ -186,7 +187,7 @@ public static class LogisticsPatch station.pilerCount = AutoConfigVeinCollectorMinPilerValue.Value; internal static void DispenserSetChargePower(PlanetFactory factory, DispenserComponent dispenser) => - factory.powerSystem.consumerPool[dispenser.pcId].workEnergyPerTick = (long)(5000.0 * AutoConfigDispenserChargePower.Value + 0.5); + factory.powerSystem.consumerPool[dispenser.pcId].workEnergyPerTick = (long)(LogisticsConstants.DispenserChargePowerMultiplier * AutoConfigDispenserChargePower.Value + 0.5); internal static void DispenserFillCouriers(PlanetFactory factory, DispenserComponent dispenser) { @@ -195,7 +196,7 @@ public static class LogisticsPatch } internal static void BattleBaseSetChargePower(PlanetFactory factory, BattleBaseComponent battleBase) => - factory.powerSystem.consumerPool[battleBase.pcId].workEnergyPerTick = (long)(5000.0 * AutoConfigBattleBaseChargePower.Value + 0.5); + factory.powerSystem.consumerPool[battleBase.pcId].workEnergyPerTick = (long)(LogisticsConstants.DispenserChargePowerMultiplier * AutoConfigBattleBaseChargePower.Value + 0.5); // === Per-facility "apply all settings" (also used as auto-config-on-build entry point) === diff --git a/UXAssist/Patches/Logistics/RealtimeInfoPanelPatch.cs b/UXAssist/Patches/Logistics/RealtimeInfoPanelPatch.cs index 0cb7c83..5ebb862 100644 --- a/UXAssist/Patches/Logistics/RealtimeInfoPanelPatch.cs +++ b/UXAssist/Patches/Logistics/RealtimeInfoPanelPatch.cs @@ -8,6 +8,7 @@ using UnityEngine.EventSystems; using UnityEngine.Serialization; using UnityEngine.UI; using UXAssist.Common; +using UXAssist.Common.GameConstants; using Object = UnityEngine.Object; namespace UXAssist.Patches.Logistics; @@ -181,19 +182,18 @@ internal static class RealtimeLogisticsInfoPanel private static int _lastPlanetId; - private static int _localStorageMax = 5000; - private static int _remoteStorageMax = 10000; + private static int _localStorageMax = LogisticsConstants.DefaultLocalStorageMax; + private static int _remoteStorageMax = LogisticsConstants.DefaultRemoteStorageMax; private static int _localStorageExtra; private static int _remoteStorageExtra; private static int _localStorageMaxTotal = _localStorageMax; private static int _remoteStorageMaxTotal = _remoteStorageMax; - private static float _localStoragePixelPerItem = StorageSliderWidth / _localStorageMaxTotal; - private static float _remoteStoragePixelPerItem = StorageSliderWidth / _remoteStorageMaxTotal; + private static float _localStoragePixelPerItem = LogisticsConstants.StorageSliderWidth / _localStorageMaxTotal; + private static float _remoteStoragePixelPerItem = LogisticsConstants.StorageSliderWidth / _remoteStorageMaxTotal; - private static int _storageMaxSlotCount = 5; + private static int _storageMaxSlotCount = LogisticsConstants.DefaultStorageSlotCount; private const int CarrierSlotCount = 3; - private const float StorageSliderWidth = 70f; - private const float StorageSliderHeight = 5f; + private static bool UpdateStorageMax() { @@ -204,8 +204,8 @@ internal static class RealtimeLogisticsInfoPanel _remoteStorageExtra = history.remoteStationExtraStorage; _localStorageMaxTotal = _localStorageMax + _localStorageExtra; _remoteStorageMaxTotal = _remoteStorageMax + _remoteStorageExtra; - _localStoragePixelPerItem = StorageSliderWidth / _localStorageMaxTotal; - _remoteStoragePixelPerItem = StorageSliderWidth / _remoteStorageMaxTotal; + _localStoragePixelPerItem = LogisticsConstants.StorageSliderWidth / _localStorageMaxTotal; + _remoteStoragePixelPerItem = LogisticsConstants.StorageSliderWidth / _remoteStorageMaxTotal; return true; } @@ -258,9 +258,9 @@ internal static class RealtimeLogisticsInfoPanel internal static void OnDataLoaded() { - _storageMaxSlotCount = 5; - _localStorageMax = 5000; - _remoteStorageMax = 10000; + _storageMaxSlotCount = LogisticsConstants.DefaultStorageSlotCount; + _localStorageMax = LogisticsConstants.DefaultLocalStorageMax; + _remoteStorageMax = LogisticsConstants.DefaultRemoteStorageMax; foreach (var model in LDB.models.dataArray) { var prefabDesc = model?.prefabDesc; @@ -361,25 +361,25 @@ internal static class RealtimeLogisticsInfoPanel var sliderBg = Object.Instantiate(sliderBgPrefab.gameObject, new Vector3(0, 0, 0), Quaternion.identity, _tipPrefab.transform); sliderBg.name = "sliderBg" + index; rectTrans = (RectTransform)sliderBg.transform; - rectTrans.sizeDelta = new Vector2(StorageSliderWidth, StorageSliderHeight); + rectTrans.sizeDelta = new Vector2(LogisticsConstants.StorageSliderWidth, LogisticsConstants.StorageSliderHeight); rectTrans.anchorMax = new Vector2(0f, 1f); rectTrans.anchorMin = new Vector2(0f, 1f); rectTrans.pivot = new Vector2(0f, 1f); rectTrans.anchoredPosition3D = new Vector3(30f, y - 22f, 0f); rectTrans = (RectTransform)sliderBg.transform.Find("current-fg").transform; - rectTrans.sizeDelta = new Vector2(0f, StorageSliderHeight); + rectTrans.sizeDelta = new Vector2(0f, LogisticsConstants.StorageSliderHeight); rectTrans.anchorMax = new Vector2(0f, 1f); rectTrans.anchorMin = new Vector2(0f, 1f); rectTrans.pivot = new Vector2(0f, 1f); rectTrans.localPosition = new Vector3(0f, 0f, 0f); rectTrans = (RectTransform)sliderBg.transform.Find("ordered-fg").transform; - rectTrans.sizeDelta = new Vector2(0f, StorageSliderHeight); + rectTrans.sizeDelta = new Vector2(0f, LogisticsConstants.StorageSliderHeight); rectTrans.anchorMax = new Vector2(0f, 1f); rectTrans.anchorMin = new Vector2(0f, 1f); rectTrans.pivot = new Vector2(0f, 1f); rectTrans.localPosition = new Vector3(0f, 0f, 0f); rectTrans = (RectTransform)sliderBg.transform.Find("max-fg").transform; - rectTrans.sizeDelta = new Vector2(StorageSliderWidth, StorageSliderHeight); + rectTrans.sizeDelta = new Vector2(LogisticsConstants.StorageSliderWidth, LogisticsConstants.StorageSliderHeight); rectTrans.anchorMax = new Vector2(0f, 1f); rectTrans.anchorMin = new Vector2(0f, 1f); rectTrans.pivot = new Vector2(0f, 1f); @@ -934,7 +934,7 @@ internal static class RealtimeLogisticsInfoPanel { ((RectTransform)_sliderCurrent[i].transform).sizeDelta = new Vector2( _pixelPerItem * itemCount, - StorageSliderHeight + LogisticsConstants.StorageSliderHeight ); _sliderCurrent[i].gameObject.SetActive(true); } @@ -968,7 +968,7 @@ internal static class RealtimeLogisticsInfoPanel ); rectTrans.sizeDelta = new Vector2( _pixelPerItem * itemOrdered + 0.49f, - StorageSliderHeight + LogisticsConstants.StorageSliderHeight ); break; case < 0: @@ -981,7 +981,7 @@ internal static class RealtimeLogisticsInfoPanel ); rectTrans.sizeDelta = new Vector2( _pixelPerItem * -itemOrdered + 0.49f, - StorageSliderHeight + LogisticsConstants.StorageSliderHeight ); break; } @@ -997,7 +997,7 @@ internal static class RealtimeLogisticsInfoPanel if (itemMax > itemLimit) itemMax = itemLimit; ((RectTransform)_sliderMax[i].transform).sizeDelta = new Vector2( _pixelPerItem * itemMax, - StorageSliderHeight + LogisticsConstants.StorageSliderHeight ); } } diff --git a/UXAssist/Patches/TechPatch.cs b/UXAssist/Patches/TechPatch.cs index db36121..d918246 100644 --- a/UXAssist/Patches/TechPatch.cs +++ b/UXAssist/Patches/TechPatch.cs @@ -6,6 +6,7 @@ using HarmonyLib; using UnityEngine; using UnityEngine.UI; using UXAssist.Common; +using UXAssist.Common.GameConstants; using GameLogicProc = UXAssist.Common.GameLogic; namespace UXAssist.Patches; @@ -66,7 +67,7 @@ public static class TechPatch var delim = -26.0f; var x = 9.0f; var y = -27.0f; - var tp3301 = techs.Select(3301); + var tp3301 = techs.Select(TechIds.SorterCargoStackingCustomStart); if (tp3301 != null && tp3301.IsObsolete) { _protoPatched = false; @@ -84,11 +85,11 @@ public static class TechPatch { switch (tp.ID) { - case >= 3301 and <= 3305: - tp.UnlockValues[0] = tp.ID - 3300 + 1; + case >= TechIds.SorterCargoStackingCustomStart and <= TechIds.SorterCargoStackingCustomEnd - 1: + tp.UnlockValues[0] = tp.ID - TechIds.SorterCargoStackingCustomStart + 2; tp.IsObsolete = false; - tp.Position = new Vector2(x + 4.0f * (tp.ID - 3301), y); - if (tp.ID == 3305) + tp.Position = new Vector2(x + 4.0f * (tp.ID - TechIds.SorterCargoStackingCustomStart), y); + if (tp.ID == TechIds.SorterCargoStackingCustomEnd - 1) { tp.postTechArray = []; if (UIRoot.instance.uiGame.techTree.nodes.TryGetValue(tp.ID, out var node)) @@ -97,10 +98,10 @@ public static class TechPatch } } continue; - case 3306: + case TechIds.SorterCargoStackingCustomEnd: tp.PreTechs = []; tp.preTechArray = []; - tp.Position = new Vector2(x + 4.0f * (tp.ID - 3301), y); + tp.Position = new Vector2(x + 4.0f * (tp.ID - TechIds.SorterCargoStackingCustomStart), y); continue; } @@ -113,7 +114,7 @@ public static class TechPatch else { var delim = -28.0f; - var tp3301 = techs.Select(3301); + var tp3301 = techs.Select(TechIds.SorterCargoStackingCustomStart); if (tp3301 != null && !tp3301.IsObsolete) { _protoPatched = true; @@ -122,7 +123,7 @@ public static class TechPatch if (!_protoPatched) return; foreach (var tp in techs.dataArray) { - if (tp.ID is >= 3301 and <= 3306) + if (tp.ID is >= TechIds.SorterCargoStackingCustomStart and <= TechIds.SorterCargoStackingCustomEnd) { tp.IsObsolete = true; continue; @@ -154,61 +155,7 @@ public static class TechPatch public static void Enable(bool enable) { - if (_techsToDisableSet == null) - { - (int, int)[] techListToDisable = - [ - // Explosive Unit, Crystal Explosive Unit - // 爆破单元,晶石爆破单元 - (1803, 1804), - // Implosion Cannon - // 聚爆加农炮 - (1807, 1807), - // Signal Tower, Planetary Defense System, Jammer Tower, Plasma Turret, Titanium Ammo Box, Superalloy Ammo Box, High-Explosive Shell Set, Supersonic Missile Set, Crystal Shell Set, Gravity Missile Set, Antimatter Capsule, Precision Drone, Prototype, Attack Drone, Corvette, Destroyer, Suppressing Capsule, EM Capsule Mk.III - // 信号塔, 行星防御系统, 干扰塔, 磁化电浆炮, 钛化弹箱, 超合金弹箱, 高爆炮弹组, 超音速导弹组, 晶石炮弹组, 引力导弹组, 反物质胶囊, 地面战斗机-A型, 地面战斗机-E型, 地面战斗机-F型, 太空战斗机-A型, 太空战斗机-F型, 电磁胶囊II, 电磁胶囊III - (1809, 1825), - // Auto Reconstruction Marking - // 自动标记重建 - (2951, 2956), - // Energy Shield - // 能量护盾 - (2801, 2807), - // Kinetic Weapon Damage - // 动能武器伤害 - (5001, 5006), - // Energy Weapon Damage - // 能量武器伤害 - (5101, 5106), - // Explosive Weapon Damage - // 爆炸武器伤害 - (5201, 5206), - // Combat Drone Damage - // 战斗无人机伤害 - (5301, 5305), - // Combat Drone Attack Speed - // 战斗无人机攻击速度 - (5401, 5405), - // Combat Drone Engine - // 战斗无人机引擎 - (5601, 5605), - // Combat Drone Durability - // 战斗无人机耐久 - (5701, 5705), - // Ground Squadron Expansion - // 地面编队扩容 - (5801, 5807), - // Space Fleet Expansion - // 太空编队扩容 - (5901, 5907), - // Enhanced Structure - // 结构强化 - (6001, 6006), - // Planetary Shield - // 行星护盾 - (6101, 6106), - ]; - _techsToDisableSet = [.. techListToDisable.SelectMany(t => Enumerable.Range(t.Item1, t.Item2 - t.Item1 + 1))]; - } + _techsToDisableSet ??= new HashSet(TechIds.CombatTechs); if (enable) { if (DSPGame.GameDesc != null)