1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-11 17:53:32 +08:00

fixed rest issues

This commit is contained in:
2025-09-21 23:57:03 +08:00
parent 6b423225fe
commit 2a4008deac
3 changed files with 120 additions and 103 deletions

View File

@@ -1125,20 +1125,13 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
DeepProfiler.EndSample(DPEntry.Belt); DeepProfiler.EndSample(DPEntry.Belt);
} }
[HarmonyTranspiler] [HarmonyPostfix]
[HarmonyPatch(typeof(GameLogic), nameof(GameLogic.LogicFrame))] [HarmonyPatch(typeof(GameLogic), nameof(GameLogic.OnFactoryFrameBegin))]
public static IEnumerable<CodeInstruction> GameLogic_LogicFrame_Transpiler(IEnumerable<CodeInstruction> instructions) public static void GameLogic_OnFactoryFrameBegin_Postfix()
{ {
var matcher = new CodeMatcher(instructions); ProcessBeltSignals();
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();
} }
/* BEGIN: Item sources calculation */ /* BEGIN: Item sources calculation */
private static readonly Dictionary<int, ItemSource> ItemSources = []; private static readonly Dictionary<int, ItemSource> ItemSources = [];
private static bool _itemSourcesInitialized; private static bool _itemSourcesInitialized;

View File

@@ -31,10 +31,10 @@ public static class ResourcePatch
private class InfiniteResource : PatchImpl<InfiniteResource> private class InfiniteResource : PatchImpl<InfiniteResource>
{ {
static private readonly float InfiniteResourceRate = 0f;
[HarmonyTranspiler] [HarmonyTranspiler]
[HarmonyPatch(typeof(FactorySystem), nameof(FactorySystem.GameTick), typeof(long), typeof(bool))] [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(PlanetTransport), nameof(PlanetTransport.GameTick))]
[HarmonyPatch(typeof(UIChartAstroResource), nameof(UIChartAstroResource.CalculateMaxAmount))] [HarmonyPatch(typeof(UIChartAstroResource), nameof(UIChartAstroResource.CalculateMaxAmount))]
[HarmonyPatch(typeof(UIChartVeinGroup), nameof(UIChartVeinGroup.CalculateMaxAmount))] [HarmonyPatch(typeof(UIChartVeinGroup), nameof(UIChartVeinGroup.CalculateMaxAmount))]
@@ -42,18 +42,29 @@ public static class ResourcePatch
[HarmonyPatch(typeof(UIControlPanelVeinCollectorPanel), nameof(UIControlPanelVeinCollectorPanel._OnUpdate))] [HarmonyPatch(typeof(UIControlPanelVeinCollectorPanel), nameof(UIControlPanelVeinCollectorPanel._OnUpdate))]
[HarmonyPatch(typeof(UIMinerWindow), nameof(UIMinerWindow._OnUpdate))] [HarmonyPatch(typeof(UIMinerWindow), nameof(UIMinerWindow._OnUpdate))]
[HarmonyPatch(typeof(UIMiningUpgradeLabel), nameof(UIMiningUpgradeLabel.Update))] [HarmonyPatch(typeof(UIMiningUpgradeLabel), nameof(UIMiningUpgradeLabel.Update))]
[HarmonyPatch(typeof(UIStationStorage), nameof(UIStationStorage.RefreshValues))]
[HarmonyPatch(typeof(UIVeinCollectorPanel), nameof(UIVeinCollectorPanel._OnUpdate))] [HarmonyPatch(typeof(UIVeinCollectorPanel), nameof(UIVeinCollectorPanel._OnUpdate))]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{ {
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false, 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 => ).Repeat(codeMatcher =>
{
if (codeMatcher.Instruction.opcode == OpCodes.Ldfld)
{
codeMatcher.RemoveInstruction().InsertAndAdvance( codeMatcher.RemoveInstruction().InsertAndAdvance(
new CodeInstruction(OpCodes.Pop), new CodeInstruction(OpCodes.Pop),
new CodeInstruction(OpCodes.Ldc_R4, 0f) 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(); return matcher.InstructionEnumeration();
} }
@@ -61,15 +72,25 @@ public static class ResourcePatch
private class FastMining : PatchImpl<FastMining> private class FastMining : PatchImpl<FastMining>
{ {
static private readonly float FastMiningSpeed = 2400f;
[HarmonyTranspiler] [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))]
[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(ItemProto), nameof(ItemProto.GetPropValue))]
[HarmonyPatch(typeof(PlanetTransport), nameof(PlanetTransport.GameTick))] [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(UIMinerWindow), nameof(UIMinerWindow._OnUpdate))]
[HarmonyPatch(typeof(UIMiningUpgradeLabel), nameof(UIMiningUpgradeLabel.Update))] [HarmonyPatch(typeof(UIMiningUpgradeLabel), nameof(UIMiningUpgradeLabel.Update))]
[HarmonyPatch(typeof(UIPlanetDetail), nameof(UIPlanetDetail.OnPlanetDataSet))] [HarmonyPatch(typeof(UIPlanetDetail), nameof(UIPlanetDetail.OnPlanetDataSet))]
[HarmonyPatch(typeof(UIPlanetDetail), nameof(UIPlanetDetail.RefreshDynamicProperties))] [HarmonyPatch(typeof(UIPlanetDetail), nameof(UIPlanetDetail.RefreshDynamicProperties))]
[HarmonyPatch(typeof(UIReferenceSpeedTip), nameof(UIReferenceSpeedTip.AddEntryDataWithFactory))]
[HarmonyPatch(typeof(UIStarDetail), nameof(UIStarDetail.OnStarDataSet))] [HarmonyPatch(typeof(UIStarDetail), nameof(UIStarDetail.OnStarDataSet))]
[HarmonyPatch(typeof(UIStarDetail), nameof(UIStarDetail.RefreshDynamicProperties))] [HarmonyPatch(typeof(UIStarDetail), nameof(UIStarDetail.RefreshDynamicProperties))]
[HarmonyPatch(typeof(UIStationStorage), nameof(UIStationStorage.RefreshValues))] [HarmonyPatch(typeof(UIStationStorage), nameof(UIStationStorage.RefreshValues))]
@@ -78,12 +99,24 @@ public static class ResourcePatch
{ {
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false, 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 => ).Repeat(codeMatcher =>
{
if (codeMatcher.Instruction.opcode == OpCodes.Ldfld)
{
codeMatcher.RemoveInstruction().InsertAndAdvance( codeMatcher.RemoveInstruction().InsertAndAdvance(
new CodeInstruction(OpCodes.Pop), new CodeInstruction(OpCodes.Pop),
new CodeInstruction(OpCodes.Ldc_R4, 2400f) 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(); return matcher.InstructionEnumeration();
} }

View File

@@ -1832,15 +1832,9 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
} }
} }
[HarmonyTranspiler] [HarmonyPostfix]
[HarmonyPatch(typeof(GameLogic), nameof(GameLogic.LogicFrame))] [HarmonyPatch(typeof(GameLogic), nameof(GameLogic.OnFactoryFrameBegin))]
public static IEnumerable<CodeInstruction> GameLogic_LogicFrame_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) 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; var factories = GameMain.data?.factories;
if (factories == null) return; if (factories == null) return;
@@ -1914,9 +1908,6 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
{ {
RemovePlanetSignalBelts(factoryIndex); RemovePlanetSignalBelts(factoryIndex);
} }
})
);
return matcher.InstructionEnumeration();
} }
} }