From f237789fa055cb0fb54d4162cd568316601bbce0 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Sat, 6 Dec 2025 22:41:18 +0900 Subject: [PATCH] minor fixes --- CheatEnabler/Patches/FactoryPatch.cs | 47 +++++++++++++++++++++++----- CheatEnabler/Patches/GamePatch.cs | 4 +-- LogisticMiner/LogisticMiner.cs | 2 +- UXAssist/Patches/FactoryPatch.cs | 2 +- UXAssist/Patches/LogisticsPatch.cs | 2 +- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/CheatEnabler/Patches/FactoryPatch.cs b/CheatEnabler/Patches/FactoryPatch.cs index 35aac5b..38ac1f2 100644 --- a/CheatEnabler/Patches/FactoryPatch.cs +++ b/CheatEnabler/Patches/FactoryPatch.cs @@ -675,11 +675,12 @@ public class FactoryPatch : PatchImpl private static void InitSignalBelts() { - if (!GameMain.isRunning) return; + if (DSPGame.IsMenuDemo) return; + InitItemSources(); _signalBelts = new Dictionary[64]; _signalBeltsCapacity = 64; - _portalFrom = new Dictionary(); - _portalTo = new Dictionary>(); + _portalFrom = []; + _portalTo = []; var factories = GameMain.data?.factories; if (factories == null) return; @@ -735,7 +736,7 @@ public class FactoryPatch : PatchImpl if (obj != null) return obj; } - obj = new Dictionary(); + obj = []; _signalBelts[index] = obj; return obj; } @@ -869,7 +870,6 @@ public class FactoryPatch : PatchImpl { if (DSPGame.IsMenuDemo) return; if (BeltSignalGeneratorEnabled.Value) InitSignalBelts(); - InitItemSources(); } [HarmonyPostfix] @@ -1171,7 +1171,7 @@ public class FactoryPatch : PatchImpl for (var i = 0; i < len; i++) { if (ItemSources.ContainsKey(res[i])) continue; - var rs = new ItemSource { Count = rescnt[i], From = new Dictionary() }; + var rs = new ItemSource { Count = rescnt[i], From = [] }; var it = recipe.Items; var itcnt = recipe.ItemCounts; var len2 = it.Length; @@ -1182,7 +1182,7 @@ public class FactoryPatch : PatchImpl if (len > 1) { - rs.Extra = new Dictionary(); + rs.Extra = []; for (var k = 0; k < len; k++) { if (i != k) @@ -1258,7 +1258,38 @@ public class FactoryPatch : PatchImpl if (itemSource.From == null) return; foreach (var p in itemSource.From) { - CalculateAllProductions(result, extra, p.Key, times * p.Value); + var value = p.Value * times; + if (extra.TryGetValue(p.Key, out var rcount)) + { + if (value <= rcount) + { + if (value == rcount) + { + extra.Remove(p.Key); + } + else + { + extra[p.Key] = rcount - value; + } + continue; + } + extra.Remove(p.Key); + value -= rcount; + } + if (result.TryGetValue(p.Key, out rcount)) + { + rcount -= value; + if (rcount <= 0) + { + result.Remove(p.Key); + } + else + { + result[p.Key] = rcount; + } + continue; + } + CalculateAllProductions(result, extra, p.Key, value); } } /* END: Item sources calculation */ diff --git a/CheatEnabler/Patches/GamePatch.cs b/CheatEnabler/Patches/GamePatch.cs index cee8154..a3f2953 100644 --- a/CheatEnabler/Patches/GamePatch.cs +++ b/CheatEnabler/Patches/GamePatch.cs @@ -48,7 +48,7 @@ public static class GamePatch p.Value.OnUnregEvent(); } - abnormalLogic.determinators = new Dictionary(); + abnormalLogic.determinators = []; } protected override void OnDisable() @@ -81,7 +81,7 @@ public static class GamePatch { _savedDeterminators = __instance.determinators; if (!AbnormalDisablerEnabled.Value) return; - __instance.determinators = new Dictionary(); + __instance.determinators = []; foreach (var p in _savedDeterminators) { p.Value.OnUnregEvent(); diff --git a/LogisticMiner/LogisticMiner.cs b/LogisticMiner/LogisticMiner.cs index 5aa5fed..f886c67 100644 --- a/LogisticMiner/LogisticMiner.cs +++ b/LogisticMiner/LogisticMiner.cs @@ -342,7 +342,7 @@ public class LogisticMiner : BaseUnityPlugin public float FrameNext; /* stores list of indices to veinData, with an extra INT which indicates cout of veinGroups at last */ - private Dictionary> _veins = new(); + private Dictionary> _veins = []; private int _mineIndex = -1; public bool HasVein(int productId) diff --git a/UXAssist/Patches/FactoryPatch.cs b/UXAssist/Patches/FactoryPatch.cs index c2a0871..5d56934 100644 --- a/UXAssist/Patches/FactoryPatch.cs +++ b/UXAssist/Patches/FactoryPatch.cs @@ -1747,7 +1747,7 @@ public class FactoryPatch : PatchImpl if (obj != null) return obj; } - obj = new Dictionary(); + obj = []; _signalBelts[index] = obj; return obj; } diff --git a/UXAssist/Patches/LogisticsPatch.cs b/UXAssist/Patches/LogisticsPatch.cs index 096ffb8..f9b42c5 100644 --- a/UXAssist/Patches/LogisticsPatch.cs +++ b/UXAssist/Patches/LogisticsPatch.cs @@ -1222,7 +1222,7 @@ public static class LogisticsPatch private float _pixelPerItem; private StorageItemData[] _storageItems; - private static readonly Dictionary ItemSprites = new(); + private static readonly Dictionary ItemSprites = []; private static readonly Color[] StateColor = [Color.gray, SupplyColor, DemandColor]; private struct StorageItemData