diff --git a/Projects/SupermarketTogether/SupermarketTogether/Class1.cs b/Projects/SupermarketTogether/SupermarketTogether/Class1.cs index e29769c..a047c25 100644 --- a/Projects/SupermarketTogether/SupermarketTogether/Class1.cs +++ b/Projects/SupermarketTogether/SupermarketTogether/Class1.cs @@ -14,10 +14,10 @@ namespace CykaMod { private const string pluginName = "SupermarketTogether"; private const string pluginVersion = "1.0.0"; - // public static ConfigEntry skillCap; + public static ConfigEntry playersAdded; public void Awake() { - // skillCap = Config.Bind("General", "Skill Cap", 100f); + playersAdded = Config.Bind("General", "PlayersAdded", 0); Logger.LogInfo("Cyka mod loaded"); HarmonyFileLog.Enabled = true; @@ -28,6 +28,16 @@ namespace CykaMod { } } + [HarmonyPatch(typeof(GameData), "UserCode_CmdOpenSupermarket")] + public static class Debug { + static void Postfix(GameData __instance) { + Console.WriteLine("Called UserCode_CmdOpenSupermarket"); + Console.WriteLine($"timeFactor: {__instance.timeFactor}"); + Console.WriteLine($"maxProductsCustomersToBuy: {__instance.maxProductsCustomersToBuy}"); + Console.WriteLine($"maxCustomersNPCs: {__instance.maxCustomersNPCs}"); + } + } + [HarmonyPatch(typeof(UpgradesManager), "ManageExtraPerks")] public static class ConsoleProductionReductionPatch { static IEnumerable Transpiler(IEnumerable instructions) { @@ -43,4 +53,32 @@ namespace CykaMod { return codes.AsEnumerable(); } } + + [HarmonyPatch(typeof(GameData), "UserCode_CmdOpenSupermarket")] + public static class PlayersAddedTranspilePatch { + static IEnumerable Transpiler(IEnumerable instructions) { + var codes = new List(instructions); + + // foreach (var codeInstruction in codes) { + // Console.WriteLine(codeInstruction); + // } + + CodeInstruction previous = codes[0]; + for (int i = 1; i < codes.Count; i++) { + if (previous.opcode == OpCodes.Ldsfld && codes[i].opcode == OpCodes.Callvirt) { + Console.WriteLine("Found Ldsfld and Callvirt"); + codes.Insert(i + 1, new CodeInstruction(OpCodes.Ldc_I4, Main.playersAdded.Value)); + codes.Insert(i + 2, new CodeInstruction(OpCodes.Add)); + } + + previous = codes[i]; + } + + // foreach (var codeInstruction in codes) { + // Console.WriteLine(codeInstruction); + // } + + return codes.AsEnumerable(); + } + } } \ No newline at end of file