From 2a4008deac508b4e3ba8ee99f17262479b19917e Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Sun, 21 Sep 2025 23:57:03 +0800 Subject: [PATCH] fixed rest issues --- CheatEnabler/Patches/FactoryPatch.cs | 15 +-- CheatEnabler/Patches/ResourcePatch.cs | 61 ++++++++--- UXAssist/Patches/FactoryPatch.cs | 147 ++++++++++++-------------- 3 files changed, 120 insertions(+), 103 deletions(-) diff --git a/CheatEnabler/Patches/FactoryPatch.cs b/CheatEnabler/Patches/FactoryPatch.cs index 3e2e13c..7e32722 100644 --- a/CheatEnabler/Patches/FactoryPatch.cs +++ b/CheatEnabler/Patches/FactoryPatch.cs @@ -1125,20 +1125,13 @@ public class FactoryPatch : PatchImpl DeepProfiler.EndSample(DPEntry.Belt); } - [HarmonyTranspiler] - [HarmonyPatch(typeof(GameLogic), nameof(GameLogic.LogicFrame))] - public static IEnumerable GameLogic_LogicFrame_Transpiler(IEnumerable instructions) + [HarmonyPostfix] + [HarmonyPatch(typeof(GameLogic), nameof(GameLogic.OnFactoryFrameBegin))] + public static void GameLogic_OnFactoryFrameBegin_Postfix() { - var matcher = new CodeMatcher(instructions); - matcher.MatchForward(false, - new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(DeepProfiler), nameof(DeepProfiler.EndSample), [typeof(int), typeof(long)])) - ).Advance(1).Insert( - new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(BeltSignalGenerator), nameof(ProcessBeltSignals))) - ); - return matcher.InstructionEnumeration(); + ProcessBeltSignals(); } - /* BEGIN: Item sources calculation */ private static readonly Dictionary ItemSources = []; private static bool _itemSourcesInitialized; diff --git a/CheatEnabler/Patches/ResourcePatch.cs b/CheatEnabler/Patches/ResourcePatch.cs index 878ab2f..3b4e214 100644 --- a/CheatEnabler/Patches/ResourcePatch.cs +++ b/CheatEnabler/Patches/ResourcePatch.cs @@ -31,10 +31,10 @@ public static class ResourcePatch private class InfiniteResource : PatchImpl { + static private readonly float InfiniteResourceRate = 0f; [HarmonyTranspiler] [HarmonyPatch(typeof(FactorySystem), nameof(FactorySystem.GameTick), typeof(long), typeof(bool))] - [HarmonyPatch(typeof(FactorySystem), nameof(FactorySystem.GameTick), typeof(long), typeof(bool), typeof(int), typeof(int), typeof(int))] - [HarmonyPatch(typeof(ItemProto), nameof(ItemProto.GetPropValue))] + [HarmonyPatch(typeof(GameLogic), nameof(GameLogic._miner_parallel))] [HarmonyPatch(typeof(PlanetTransport), nameof(PlanetTransport.GameTick))] [HarmonyPatch(typeof(UIChartAstroResource), nameof(UIChartAstroResource.CalculateMaxAmount))] [HarmonyPatch(typeof(UIChartVeinGroup), nameof(UIChartVeinGroup.CalculateMaxAmount))] @@ -42,18 +42,29 @@ public static class ResourcePatch [HarmonyPatch(typeof(UIControlPanelVeinCollectorPanel), nameof(UIControlPanelVeinCollectorPanel._OnUpdate))] [HarmonyPatch(typeof(UIMinerWindow), nameof(UIMinerWindow._OnUpdate))] [HarmonyPatch(typeof(UIMiningUpgradeLabel), nameof(UIMiningUpgradeLabel.Update))] - [HarmonyPatch(typeof(UIStationStorage), nameof(UIStationStorage.RefreshValues))] [HarmonyPatch(typeof(UIVeinCollectorPanel), nameof(UIVeinCollectorPanel._OnUpdate))] private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator) { var matcher = new CodeMatcher(instructions, generator); matcher.MatchForward(false, - new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(GameHistoryData), nameof(GameHistoryData.miningCostRate))) + new CodeMatch(ci => (ci.opcode == OpCodes.Ldfld || ci.opcode == OpCodes.Ldflda) && ci.OperandIs(AccessTools.Field(typeof(GameHistoryData), nameof(GameHistoryData.miningCostRate)))) ).Repeat(codeMatcher => - codeMatcher.RemoveInstruction().InsertAndAdvance( - new CodeInstruction(OpCodes.Pop), - new CodeInstruction(OpCodes.Ldc_R4, 0f) - ) + { + if (codeMatcher.Instruction.opcode == OpCodes.Ldfld) + { + codeMatcher.RemoveInstruction().InsertAndAdvance( + new CodeInstruction(OpCodes.Pop), + new CodeInstruction(OpCodes.Ldc_R4, InfiniteResourceRate) + ); + } + else + { + codeMatcher.RemoveInstruction().InsertAndAdvance( + new CodeInstruction(OpCodes.Pop), + new CodeInstruction(OpCodes.Ldsflda, AccessTools.Field(typeof(InfiniteResource), nameof(InfiniteResourceRate))) + ); + } + } ); return matcher.InstructionEnumeration(); } @@ -61,15 +72,25 @@ public static class ResourcePatch private class FastMining : PatchImpl { + static private readonly float FastMiningSpeed = 2400f; + [HarmonyTranspiler] + [HarmonyPatch(typeof(AstroResourceStatPlan), nameof(AstroResourceStatPlan.AddPlanetResources))] + [HarmonyPatch(typeof(BuildingGizmo), nameof(BuildingGizmo.Update))] [HarmonyPatch(typeof(FactorySystem), nameof(FactorySystem.GameTick), typeof(long), typeof(bool))] - [HarmonyPatch(typeof(FactorySystem), nameof(FactorySystem.GameTick), typeof(long), typeof(bool), typeof(int), typeof(int), typeof(int))] + [HarmonyPatch(typeof(GameLogic), nameof(GameLogic._miner_parallel))] [HarmonyPatch(typeof(ItemProto), nameof(ItemProto.GetPropValue))] [HarmonyPatch(typeof(PlanetTransport), nameof(PlanetTransport.GameTick))] + [HarmonyPatch(typeof(ProductionExtraInfoCalculator), nameof(ProductionExtraInfoCalculator.CalculateFactory))] + [HarmonyPatch(typeof(UIChartAstroResource), nameof(UIChartAstroResource.CalculateMaxAmount))] + [HarmonyPatch(typeof(UIChartVeinGroup), nameof(UIChartVeinGroup.CalculateMaxAmount))] + [HarmonyPatch(typeof(UIControlPanelStationStorage), nameof(UIControlPanelStationStorage.RefreshValues))] + [HarmonyPatch(typeof(UIControlPanelVeinCollectorPanel), nameof(UIControlPanelVeinCollectorPanel._OnUpdate))] [HarmonyPatch(typeof(UIMinerWindow), nameof(UIMinerWindow._OnUpdate))] [HarmonyPatch(typeof(UIMiningUpgradeLabel), nameof(UIMiningUpgradeLabel.Update))] [HarmonyPatch(typeof(UIPlanetDetail), nameof(UIPlanetDetail.OnPlanetDataSet))] [HarmonyPatch(typeof(UIPlanetDetail), nameof(UIPlanetDetail.RefreshDynamicProperties))] + [HarmonyPatch(typeof(UIReferenceSpeedTip), nameof(UIReferenceSpeedTip.AddEntryDataWithFactory))] [HarmonyPatch(typeof(UIStarDetail), nameof(UIStarDetail.OnStarDataSet))] [HarmonyPatch(typeof(UIStarDetail), nameof(UIStarDetail.RefreshDynamicProperties))] [HarmonyPatch(typeof(UIStationStorage), nameof(UIStationStorage.RefreshValues))] @@ -78,12 +99,24 @@ public static class ResourcePatch { var matcher = new CodeMatcher(instructions, generator); matcher.MatchForward(false, - new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(GameHistoryData), nameof(GameHistoryData.miningSpeedScale))) + new CodeMatch(ci => (ci.opcode == OpCodes.Ldfld || ci.opcode == OpCodes.Ldflda) && ci.OperandIs(AccessTools.Field(typeof(GameHistoryData), nameof(GameHistoryData.miningSpeedScale)))) ).Repeat(codeMatcher => - codeMatcher.RemoveInstruction().InsertAndAdvance( - new CodeInstruction(OpCodes.Pop), - new CodeInstruction(OpCodes.Ldc_R4, 2400f) - ) + { + if (codeMatcher.Instruction.opcode == OpCodes.Ldfld) + { + codeMatcher.RemoveInstruction().InsertAndAdvance( + new CodeInstruction(OpCodes.Pop), + new CodeInstruction(OpCodes.Ldc_R4, FastMiningSpeed) + ); + } + else + { + codeMatcher.RemoveInstruction().InsertAndAdvance( + new CodeInstruction(OpCodes.Pop), + new CodeInstruction(OpCodes.Ldsflda, AccessTools.Field(typeof(FastMining), nameof(FastMiningSpeed))) + ); + } + } ); return matcher.InstructionEnumeration(); } diff --git a/UXAssist/Patches/FactoryPatch.cs b/UXAssist/Patches/FactoryPatch.cs index f8d5ed8..7c065e4 100644 --- a/UXAssist/Patches/FactoryPatch.cs +++ b/UXAssist/Patches/FactoryPatch.cs @@ -1832,91 +1832,82 @@ public class FactoryPatch : PatchImpl } } - [HarmonyTranspiler] - [HarmonyPatch(typeof(GameLogic), nameof(GameLogic.LogicFrame))] - public static IEnumerable GameLogic_LogicFrame_Transpiler(IEnumerable instructions, ILGenerator generator) + [HarmonyPostfix] + [HarmonyPatch(typeof(GameLogic), nameof(GameLogic.OnFactoryFrameBegin))] + public static void GameLogic_OnFactoryFrameBegin_Postfix() { - var matcher = new CodeMatcher(instructions, generator); - matcher.MatchForward(false, - new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(DeepProfiler), nameof(DeepProfiler.EndSample), [typeof(int), typeof(long)])) - ).Advance(1).Insert( - Transpilers.EmitDelegate(() => + var factories = GameMain.data?.factories; + if (factories == null) return; + var factoriesCount = factories.Length; + var propertySystem = DSPGame.propertySystem; + List factoriesToRemove = null; + foreach (var factoryIndex in SignalBeltFactoryIndices) + { + if (factoryIndex >= factoriesCount) { - var factories = GameMain.data?.factories; - if (factories == null) return; - var factoriesCount = factories.Length; - var propertySystem = DSPGame.propertySystem; - List factoriesToRemove = null; - foreach (var factoryIndex in SignalBeltFactoryIndices) + if (factoriesToRemove == null) + factoriesToRemove = [factoryIndex]; + else + factoriesToRemove.Add(factoryIndex); + continue; + } + var signalBelts = GetSignalBelts(factoryIndex); + if (signalBelts == null) continue; + var factory = factories[factoryIndex]; + if (factory == null) continue; + var cargoTraffic = factory.cargoTraffic; + var beltCount = cargoTraffic.beltCursor; + List beltsToRemove = null; + foreach (var kvp in signalBelts) + { + if (kvp.Key >= beltCount) { - if (factoryIndex >= factoriesCount) - { - if (factoriesToRemove == null) - factoriesToRemove = [factoryIndex]; - else - factoriesToRemove.Add(factoryIndex); - continue; - } - var signalBelts = GetSignalBelts(factoryIndex); - if (signalBelts == null) continue; - var factory = factories[factoryIndex]; - if (factory == null) continue; - var cargoTraffic = factory.cargoTraffic; - var beltCount = cargoTraffic.beltCursor; - List beltsToRemove = null; - foreach (var kvp in signalBelts) - { - if (kvp.Key >= beltCount) - { - if (beltsToRemove == null) - beltsToRemove = [kvp.Key]; - else - beltsToRemove.Add(kvp.Key); - continue; - } - ref var belt = ref cargoTraffic.beltPool[kvp.Key]; - var cargoPath = cargoTraffic.GetCargoPath(belt.segPathId); - var itemIdx = kvp.Value; - if (cargoPath == null) continue; - var itemId = DarkFogItemIds[itemIdx]; - var consume = (byte)Math.Min(DarkFogItemsInVoid[itemIdx], 4); - if (consume < 4) - { - var metaverse = propertySystem.GetItemAvaliableProperty(_clusterSeedKey, 6006); - if (metaverse > 0) - { - if (metaverse > 10) - metaverse = 10; - propertySystem.AddItemConsumption(_clusterSeedKey, 6006, metaverse); - var mainPlayer = GameMain.mainPlayer; - GameMain.history.AddPropertyItemConsumption(6006, metaverse, true); - var count = DarkFogItemExchangeRate[itemIdx] * metaverse; - DarkFogItemsInVoid[itemIdx] += count; - consume = (byte)Math.Min(DarkFogItemsInVoid[itemIdx], 4); - mainPlayer.mecha.AddProductionStat(itemId, count, mainPlayer.nearestFactory); - } - } - - if (consume > 0 && cargoPath.TryInsertItem(belt.segIndex + belt.segPivotOffset, itemId, consume, 0)) - DarkFogItemsInVoid[itemIdx] -= consume; - } - if (beltsToRemove == null) continue; - foreach (var beltId in beltsToRemove) - signalBelts.Remove(beltId); - if (signalBelts.Count > 0) continue; - if (factoriesToRemove == null) - factoriesToRemove = [factoryIndex]; + if (beltsToRemove == null) + beltsToRemove = [kvp.Key]; else - factoriesToRemove.Add(factoryIndex); + beltsToRemove.Add(kvp.Key); + continue; } - if (factoriesToRemove == null) return; - foreach (var factoryIndex in factoriesToRemove) + ref var belt = ref cargoTraffic.beltPool[kvp.Key]; + var cargoPath = cargoTraffic.GetCargoPath(belt.segPathId); + var itemIdx = kvp.Value; + if (cargoPath == null) continue; + var itemId = DarkFogItemIds[itemIdx]; + var consume = (byte)Math.Min(DarkFogItemsInVoid[itemIdx], 4); + if (consume < 4) { - RemovePlanetSignalBelts(factoryIndex); + var metaverse = propertySystem.GetItemAvaliableProperty(_clusterSeedKey, 6006); + if (metaverse > 0) + { + if (metaverse > 10) + metaverse = 10; + propertySystem.AddItemConsumption(_clusterSeedKey, 6006, metaverse); + var mainPlayer = GameMain.mainPlayer; + GameMain.history.AddPropertyItemConsumption(6006, metaverse, true); + var count = DarkFogItemExchangeRate[itemIdx] * metaverse; + DarkFogItemsInVoid[itemIdx] += count; + consume = (byte)Math.Min(DarkFogItemsInVoid[itemIdx], 4); + mainPlayer.mecha.AddProductionStat(itemId, count, mainPlayer.nearestFactory); + } } - }) - ); - return matcher.InstructionEnumeration(); + + if (consume > 0 && cargoPath.TryInsertItem(belt.segIndex + belt.segPivotOffset, itemId, consume, 0)) + DarkFogItemsInVoid[itemIdx] -= consume; + } + if (beltsToRemove == null) continue; + foreach (var beltId in beltsToRemove) + signalBelts.Remove(beltId); + if (signalBelts.Count > 0) continue; + if (factoriesToRemove == null) + factoriesToRemove = [factoryIndex]; + else + factoriesToRemove.Add(factoryIndex); + } + if (factoriesToRemove == null) return; + foreach (var factoryIndex in factoriesToRemove) + { + RemovePlanetSignalBelts(factoryIndex); + } } }