|
1 | 1 | using System.Collections.Generic; |
2 | 2 | using System.Reflection.Emit; |
3 | 3 | using HarmonyLib; |
| 4 | +using ProjectGenesis.Utils; |
4 | 5 |
|
5 | 6 | namespace ProjectGenesis.Patches |
6 | 7 | { |
@@ -74,36 +75,40 @@ public static IEnumerable<CodeInstruction> TankComponent_GameTick_Transpiler(IEn |
74 | 75 | */ |
75 | 76 |
|
76 | 77 | 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); |
79 | 80 |
|
80 | 81 | if (matcher.IsInvalid) break; |
81 | 82 |
|
| 83 | + // calc currentOutputStack |
82 | 84 | 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))), |
85 | 86 | new CodeInstruction(OpCodes.Stloc_S, localIndex)); |
86 | 87 |
|
| 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 | + |
87 | 92 | // tankComponent.fluidInc * currentOutputStack; |
88 | 93 | matcher.InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, localIndex), new CodeInstruction(OpCodes.Mul)); |
89 | 94 |
|
90 | | - // stack = (byte) currentOutputStack; |
91 | 95 | matcher.MatchForward(true, new CodeMatch(OpCodes.Ldarg_0), |
92 | 96 | new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(TankComponent), nameof(TankComponent.fluidId))), |
93 | 97 | new CodeMatch(OpCodes.Ldc_I4_1)); |
94 | 98 |
|
95 | | - matcher.SetAndAdvance(OpCodes.Ldloc_S, localIndex).InsertAndAdvance(new CodeInstruction(OpCodes.Conv_U1)); |
| 99 | + // stack = currentOutputStack; |
| 100 | + matcher.SetAndAdvance(OpCodes.Ldloc_S, localIndex); |
96 | 101 |
|
97 | | - // this.fluidCount -= currentOutputStack; |
98 | 102 | matcher.MatchForward(false, new CodeMatch(OpCodes.Ldc_I4_1), new CodeMatch(OpCodes.Sub)); |
99 | 103 |
|
| 104 | + // this.fluidCount -= currentOutputStack; |
100 | 105 | matcher.SetAndAdvance(OpCodes.Ldloc_S, localIndex); |
101 | 106 | } |
102 | 107 |
|
103 | 108 | return matcher.InstructionEnumeration(); |
104 | 109 | } |
105 | 110 |
|
106 | | - public static int TankComponent_GameTick_Insert_Method(ref TankComponent component) |
| 111 | + public static int CalcCurrentOutputStack(ref TankComponent component) |
107 | 112 | { |
108 | 113 | int componentFluidCount = component.fluidCount; |
109 | 114 | int historyStationPilerLevel = GameMain.history.stationPilerLevel; |
|
0 commit comments