Skip to content

Commit 0a7b143

Browse files
committed
Update TankComponentPatches.cs
1 parent 255a5c2 commit 0a7b143

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/Patches/Hooks/TankComponentPatches.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Reflection.Emit;
33
using HarmonyLib;
4+
using ProjectGenesis.Utils;
45

56
namespace ProjectGenesis.Patches
67
{
@@ -74,36 +75,40 @@ public static IEnumerable<CodeInstruction> TankComponent_GameTick_Transpiler(IEn
7475
*/
7576

7677
matcher.MatchForward(false, new CodeMatch(OpCodes.Ldarg_0),
77-
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(TankComponent), nameof(TankComponent.fluidCount))),
78-
new CodeMatch(OpCodes.Div));
78+
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(TankComponent), nameof(TankComponent.fluidInc))),
79+
CodeMatchUtils.BrFalse);
7980

8081
if (matcher.IsInvalid) break;
8182

83+
// calc currentOutputStack
8284
matcher.InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0),
83-
new CodeInstruction(OpCodes.Call,
84-
AccessTools.Method(typeof(TankComponentPatches), nameof(TankComponent_GameTick_Insert_Method))),
85+
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(TankComponentPatches), nameof(CalcCurrentOutputStack))),
8586
new CodeInstruction(OpCodes.Stloc_S, localIndex));
8687

88+
matcher.MatchForward(false, new CodeMatch(OpCodes.Ldarg_0),
89+
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(TankComponent), nameof(TankComponent.fluidCount))),
90+
new CodeMatch(OpCodes.Div));
91+
8792
// tankComponent.fluidInc * currentOutputStack;
8893
matcher.InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, localIndex), new CodeInstruction(OpCodes.Mul));
8994

90-
// stack = (byte) currentOutputStack;
9195
matcher.MatchForward(true, new CodeMatch(OpCodes.Ldarg_0),
9296
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(TankComponent), nameof(TankComponent.fluidId))),
9397
new CodeMatch(OpCodes.Ldc_I4_1));
9498

95-
matcher.SetAndAdvance(OpCodes.Ldloc_S, localIndex).InsertAndAdvance(new CodeInstruction(OpCodes.Conv_U1));
99+
// stack = currentOutputStack;
100+
matcher.SetAndAdvance(OpCodes.Ldloc_S, localIndex);
96101

97-
// this.fluidCount -= currentOutputStack;
98102
matcher.MatchForward(false, new CodeMatch(OpCodes.Ldc_I4_1), new CodeMatch(OpCodes.Sub));
99103

104+
// this.fluidCount -= currentOutputStack;
100105
matcher.SetAndAdvance(OpCodes.Ldloc_S, localIndex);
101106
}
102107

103108
return matcher.InstructionEnumeration();
104109
}
105110

106-
public static int TankComponent_GameTick_Insert_Method(ref TankComponent component)
111+
public static int CalcCurrentOutputStack(ref TankComponent component)
107112
{
108113
int componentFluidCount = component.fluidCount;
109114
int historyStationPilerLevel = GameMain.history.stationPilerLevel;

0 commit comments

Comments
 (0)