diff --git a/CheatEnabler/FactoryPatch.cs b/CheatEnabler/FactoryPatch.cs index e734464..99e7125 100644 --- a/CheatEnabler/FactoryPatch.cs +++ b/CheatEnabler/FactoryPatch.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection.Emit; using BepInEx.Configuration; using CommonAPI.Systems; @@ -387,15 +388,47 @@ public static class FactoryPatch [HarmonyTranspiler, HarmonyPriority(Priority.Last)] [HarmonyPatch(typeof(BuildTool_Addon), nameof(BuildTool_Addon.CheckBuildConditions))] - // [HarmonyPatch(typeof(BuildTool_Click), nameof(BuildTool_Click.CheckBuildConditions))] [HarmonyPatch(typeof(BuildTool_Inserter), nameof(BuildTool_Inserter.CheckBuildConditions))] - [HarmonyPatch(typeof(BuildTool_Path), nameof(BuildTool_Path.CheckBuildConditions))] private static IEnumerable BuildTool_CheckBuildConditions_Transpiler(IEnumerable instructions) { yield return new CodeInstruction(OpCodes.Ldc_I4_1); yield return new CodeInstruction(OpCodes.Ret); } + [HarmonyPatch(typeof(BuildTool_Path), nameof(BuildTool_Path.CheckBuildConditions))] + private static IEnumerable BuildTool_Path_CheckBuildConditions_Transpiler(IEnumerable instructions, ILGenerator generator) + { + var matcher = new CodeMatcher(instructions, generator); + var label1 = generator.DefineLabel(); + var label2 = generator.DefineLabel(); + matcher.Start().InsertAndAdvance( + new CodeInstruction(OpCodes.Br, label1) + ); + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Call, AccessTools.PropertyGetter(typeof(BuildTool), nameof(BuildTool.buildPreviews))), + new CodeMatch(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(List), nameof(List.Count))), + new CodeMatch(ci => ci.IsStloc()) + ); + matcher.Labels.Add(label1); + matcher.Advance(4).InsertAndAdvance( + new CodeInstruction(OpCodes.Br, label2) + ); + matcher.MatchForward(false, + new CodeMatch(ci => ci.IsLdloc()), + new CodeMatch(ci => ci.Branches(out _)), + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(BuildTool), nameof(BuildTool_Path.waitForConfirm))), + new CodeMatch(ci => ci.Branches(out _)) + ); + var operand = matcher.Operand; + matcher.InsertAndAdvance( + new CodeInstruction(OpCodes.Ldc_I4_1).WithLabels(label2), + new CodeInstruction(OpCodes.Stloc_S, operand) + ); + return matcher.InstructionEnumeration(); + } + [HarmonyTranspiler, HarmonyPriority(Priority.Last)] [HarmonyPatch(typeof(BuildTool_BlueprintPaste), nameof(BuildTool_BlueprintPaste.CheckBuildConditions))] [HarmonyPatch(typeof(BuildTool_Click), nameof(BuildTool_Click.CheckBuildConditions))]