static private IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, IEnumerable <CodeInstruction> instr) { OpCode[] opCodes = { OpCodes.Ldarg_2, OpCodes.Brfalse, }; string[] operands = { "", "System.Reflection.Emit.Label", }; int step = 0; foreach (var ci in instr) { yield return(ci); if (HPatcher.IsFragment(opCodes, operands, ci, ref step, "Patch_SocialPropernessFix")) { yield return(new CodeInstruction(OpCodes.Ldc_I4_1)); yield return(new CodeInstruction(OpCodes.Ret)); } } }
public static IEnumerable <CodeInstruction> InjectFragmentBefore(OpCode[] opCodes, String[] operands, IEnumerable <CodeInstruction> instr, IEnumerable <CodeInstruction> newFragment, string fragmentName, bool perfectMatch = true) { // Convert to list, to freely jump between lines var instructions = instr.ToList(); // Find last index of fragment int index = -1; int step = 0; for (int i = 0; i < instructions.Count; i++) { if (HPatcher.IsFragment(opCodes, operands, instructions[i], ref step, fragmentName, perfectMatch)) { index = i; break; } } // Jump back to begining of fragment index -= operands.Length; // If no fragment is found throw exception (or somehow begining of fragment is lower than 0) if (index < 0) { throw new Exception($"Couldn't find fragment {fragmentName}"); } // Add fragment instructions.InsertRange(index + 1, newFragment); return(instructions); }
private static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, IEnumerable <CodeInstruction> instr) { OpCode[] opCodes = { OpCodes.Call, OpCodes.Brfalse, }; String[] operands = { "Boolean InRestraints(Verse.Pawn)", "System.Reflection.Emit.Label", }; int step = 0; foreach (var ci in instr) { if (HPatcher.IsFragment(opCodes, operands, ci, ref step, "Patch_RestrainsPatch")) { yield return(new CodeInstruction(OpCodes.Pop)); yield return(new CodeInstruction(OpCodes.Br, ci.operand)); } else { yield return(ci); } } }
private static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, MethodBase mBase, IEnumerable <CodeInstruction> instr) { OpCode[] opCodes = { OpCodes.Ldfld, OpCodes.Ldfld, OpCodes.Beq, OpCodes.Br, }; String[] operands = { "RimWorld.WorkGiverDef def", "Verse.WorkTypeDef workType", "System.Reflection.Emit.Label", "System.Reflection.Emit.Label", }; var label = (Label)HPatcher.FindOperandAfter(opCodes, operands, instr); OpCode[] opCodes2 = { OpCodes.Ldc_I4_0, OpCodes.Stloc_0, OpCodes.Br, OpCodes.Ldarg_2, OpCodes.Callvirt, OpCodes.Ldloc_0, OpCodes.Callvirt, OpCodes.Stloc_1, }; String[] operands2 = { "", "", "System.Reflection.Emit.Label", "", "RimWorld.BillStack get_BillStack()", "", "RimWorld.Bill get_Item(Int32)", "", }; var step = 0; foreach (var ci in instr) { yield return(ci); if (HPatcher.IsFragment(opCodes2, operands2, ci, ref step, "Patch_BillPrevention")) { yield return(new CodeInstruction(OpCodes.Ldarg_1)); yield return(new CodeInstruction(OpCodes.Ldloc_1)); yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_BillPrevention).GetMethod("IsForCertainGroup"))); yield return(new CodeInstruction(OpCodes.Brfalse, label)); } } }
private static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, IEnumerable <CodeInstruction> instr) { var pawn = HPatcher.FindOperandAfter(new[] { OpCodes.Ldfld }, new[] { "Verse.Pawn pawn" }, instr); var label = HPatcher.FindOperandAfter(new[] { OpCodes.Brtrue }, new[] { "System.Reflection.Emit.Label" }, instr); OpCode[] opCodes = { OpCodes.Ldarg_0, OpCodes.Ldfld, OpCodes.Callvirt, OpCodes.Brtrue, }; string[] operands = { "", "Verse.Pawn pawn", "Boolean get_IsColonist()", "System.Reflection.Emit.Label", }; int step = 0; foreach (var ci in instr) { yield return(ci); if (HPatcher.IsFragment(opCodes, operands, ci, ref step, "Patch_TimetableFix")) { yield return(new CodeInstruction(OpCodes.Ldarg_0)); yield return(new CodeInstruction(OpCodes.Ldfld, pawn)); yield return(new CodeInstruction(OpCodes.Callvirt, typeof(Pawn).GetMethod("get_IsPrisonerOfColony"))); yield return(new CodeInstruction(OpCodes.Brtrue, label)); } } }
private static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, MethodBase mBase, IEnumerable <CodeInstruction> instr) { // Find >> this.bill OpCode[] opCodes0 = { OpCodes.Ldfld, }; String[] operands0 = { "RimWorld.Bill_Production bill", }; var billField = HPatcher.FindOperandAfter(opCodes0, operands0, instr); // Find label after >> if (listing_Standard.ButtonText(label, null)) OpCode[] opCodes1 = { OpCodes.Ldloc_S, OpCodes.Ldloc_S, OpCodes.Ldnull, OpCodes.Callvirt, OpCodes.Brfalse }; String[] operands1 = { "Verse.Listing_Standard (6)", "System.String (7)", "", "Boolean ButtonText(System.String, System.String)", "System.Reflection.Emit.Label", }; var label = HPatcher.FindOperandAfter(opCodes1, operands1, instr); // Begin rect - start of scrollable view int step2 = 0; int step4 = 0; // Find fragment >> listing_Standard.Begin(rect3); OpCode[] opCodes2 = { OpCodes.Ldloc_S, OpCodes.Ldloc_2, OpCodes.Callvirt, }; String[] operands2 = { "Verse.Listing_Standard (6)", "", "Void Begin(Rect)", }; // End rect - end of scrollable view int step3 = 0; // Find fragment >> listing_Standard.End(); OpCode[] opCodes3 = { OpCodes.Call, OpCodes.Stfld, OpCodes.Ldloc_S, }; String[] operands3 = { "Int32 RoundToInt(Single)", "System.Int32 unpauseWhenYouHave", "Verse.Listing_Standard (6)", }; foreach (var ci in instr) { if (ci.labels.Contains((Label)label)) { var injectedInstruction = new CodeInstruction(OpCodes.Ldloc_S, ci.operand); injectedInstruction.labels.Add((Label)label); yield return(injectedInstruction); yield return(new CodeInstruction(OpCodes.Ldarg_0)); yield return(new CodeInstruction(OpCodes.Ldfld, billField)); yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_BillCheckbox).GetMethod("GroupExclusionButton"))); ci.labels.Remove((Label)label); } if (HPatcher.IsFragment(opCodes3, operands3, ci, ref step3, "Patch_BillCheckbox1")) { var instruction = new CodeInstruction(OpCodes.Call, typeof(Patch_BillCheckbox).GetMethod("StopScrolling")); instruction.labels.AddRange(ci.labels); ci.labels.Clear(); yield return(instruction); } if (HPatcher.IsFragment(opCodes2, operands2, ci, ref step4, "Patch_BillCheckbox2")) { yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_BillCheckbox).GetMethod("SetRect"))); } yield return(ci); if (HPatcher.IsFragment(opCodes2, operands2, ci, ref step2, "Patch_BillCheckbox3")) { yield return(new CodeInstruction(OpCodes.Ldloc_2)); yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_BillCheckbox).GetMethod("StartScrolling"))); } } }
private static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, MethodBase mBase, IEnumerable <CodeInstruction> instr) { //var pawn = HPatcher.FindOperandAfter(new[] { OpCodes.Ldfld }, new[] { "Verse.Pawn pawn" }, instr); var jobgiver = HPatcher.FindOperandAfter(new[] { OpCodes.Ldloc_S }, new[] { "RimWorld.JobGiver_Work+<TryIssueJobPackage>c__AnonStorey1 (11)" }, instr); var scanner = HPatcher.FindOperandAfter(new[] { OpCodes.Ldfld }, new[] { "RimWorld.WorkGiver_Scanner scanner" }, instr); var cell = HPatcher.FindOperandAfter(new[] { OpCodes.Ldloc_S }, new[] { "Verse.IntVec3 (33)" }, instr); OpCode[] opcodes1 = { OpCodes.Ldloc_S, OpCodes.Ldftn, OpCodes.Newobj, }; String[] operands1 = { "RimWorld.JobGiver_Work+<TryIssueJobPackage>c__AnonStorey1 (11)", "Boolean <>m__0(Verse.Thing)", "Void .ctor(Object, IntPtr)", }; int step1 = 0; OpCode[] opCodes2 = { OpCodes.Bge_Un, OpCodes.Ldloc_S, OpCodes.Ldfld, OpCodes.Ldloc_0, OpCodes.Ldfld, OpCodes.Ldloc_S, OpCodes.Callvirt, OpCodes.Brfalse, }; String[] operands2 = { "System.Reflection.Emit.Label", "RimWorld.JobGiver_Work+<TryIssueJobPackage>c__AnonStorey1 (11)", "RimWorld.WorkGiver_Scanner scanner", "", "Verse.Pawn pawn", "Verse.IntVec3 (33)", "Boolean HasJobOnCell(Verse.Pawn, IntVec3)", "System.Reflection.Emit.Label", }; int step2 = 0; foreach (var ci in instr) { yield return(ci); if (HPatcher.IsFragment(opcodes1, operands1, ci, ref step1, "Patch_LaborForbid1")) { yield return(new CodeInstruction(OpCodes.Pop)); yield return(new CodeInstruction(OpCodes.Ldarg_1)); yield return(new CodeInstruction(OpCodes.Ldloc_S, jobgiver)); yield return(new CodeInstruction(OpCodes.Ldfld, scanner)); yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_LaborForbid).GetMethod("CreatePredicate"))); } if (HPatcher.IsFragment(opCodes2, operands2, ci, ref step2, "Patch_LaborForbid2")) { yield return(new CodeInstruction(OpCodes.Ldloc_S, cell)); yield return(new CodeInstruction(OpCodes.Ldarg_1)); yield return(new CodeInstruction(OpCodes.Ldloc_S, jobgiver)); yield return(new CodeInstruction(OpCodes.Ldfld, scanner)); yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_LaborForbid).GetMethod("GetWorkType"))); yield return(new CodeInstruction(OpCodes.Call, typeof(LaborExclusionUtility).GetMethod("IsDisabledByLabor"))); yield return(new CodeInstruction(OpCodes.Brtrue, ci.operand)); } } }