diff --git a/Projects/SupermarketTogether/SupermarketTogether/AutoPricer.cs b/Projects/SupermarketTogether/SupermarketTogether/AutoPricer.cs index 8059184..4cd62c3 100644 --- a/Projects/SupermarketTogether/SupermarketTogether/AutoPricer.cs +++ b/Projects/SupermarketTogether/SupermarketTogether/AutoPricer.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Reflection.Emit; using HarmonyLib; using UnityEngine; @@ -130,5 +132,42 @@ namespace DavesPhatStore { newPrice = realPricePerUnit * Main.setPriceMultiplier.Value; Console.WriteLine($"Adjusted price to {newPrice} for product {productID}"); } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(PlayerNetwork), "Update")] + static IEnumerable UpdateTranspiler(IEnumerable instructions) { + var codes = new List(instructions); + + // for (int i = 0; i < codes.Count; i++) { + // var codeInstruction = codes[i]; + // if (codeInstruction.operand == null) { + // Console.WriteLine($"{i}: '{codeInstruction.opcode}' '{codeInstruction.operand}'"); + // continue; + // } + // Console.WriteLine($"{i}: '{codeInstruction.opcode}' '{codeInstruction.operand}' ('{codeInstruction.operand.GetType()}')"); + // } + + int start = 0, end = 0; + for (int i = 0; i < codes.Count; ++i) { + if (codes[i].opcode == OpCodes.Brfalse + && codes[i + 1].opcode == OpCodes.Ldsfld + && codes[i + 2].opcode == OpCodes.Ldfld + && codes[i + 2].operand.ToString().Equals("System.Single[] productPlayerPricing")) { + start = i; + } + + if (codes[i].opcode == OpCodes.Beq + && codes[i - 1].opcode == OpCodes.Ldfld + && codes[i - 2].opcode == OpCodes.Ldarg_0 + && codes[i - 1].operand.ToString().Equals("System.Single pPrice")) { + end = i; + break; + } + } + Console.WriteLine($"Found UpdateTranspiler start at {start}, end at {end}"); + codes.RemoveRange(start, end - start + 1); + + return instructions; + } } } \ No newline at end of file diff --git a/Projects/SupermarketTogether/SupermarketTogether/Class1.cs b/Projects/SupermarketTogether/SupermarketTogether/Class1.cs index e09f8c1..ffb0767 100644 --- a/Projects/SupermarketTogether/SupermarketTogether/Class1.cs +++ b/Projects/SupermarketTogether/SupermarketTogether/Class1.cs @@ -44,6 +44,9 @@ namespace DavesPhatStore { harmony.PatchAll(); var originalMethods = harmony.GetPatchedMethods(); Logger.LogInfo("Patched " + originalMethods.Count() + " methods"); + foreach (var method in originalMethods) { + Logger.LogInfo("Patched " + method.Name); + } } }