Enable setting prices even when they're the same

This commit is contained in:
2024-08-23 21:41:24 +02:00
parent a87821f2ad
commit 0ee56fc7b1
2 changed files with 42 additions and 0 deletions

View File

@@ -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<CodeInstruction> UpdateTranspiler(IEnumerable<CodeInstruction> instructions) {
var codes = new List<CodeInstruction>(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;
}
}
}

View File

@@ -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);
}
}
}