/* === Orignal code Look-up===
         *
         * <BestFoodSourceOnMap>c__AnonStorey.foodValidator = delegate(Thing t)
         *
         * === CIL Instructions ===
         *
         * ldloc.0 |  | Label 6Label 8
         * ldloc.0 |  | no labels
         * ldftn | Boolean <>m__0(Verse.Thing) | no labels
         * newobj | Void .ctor(Object, IntPtr) | no labels
         * stfld | System.Predicate`1[Verse.Thing] foodValidator | no labels
         *
         */

        static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, IEnumerable <CodeInstruction> instructions)
        {
            OpCode[] opCodes =
            {
                OpCodes.Ldftn,
                OpCodes.Newobj,
                OpCodes.Stfld,
            };
            string[] operands =
            {
                "Boolean <>m__0(Verse.Thing)",
                "Void .ctor(Object, IntPtr)",
                "foodValidator",
            };
            int step = 0;

            foreach (var instr in instructions)
            {
                if (HPatcher.IsFragment(opCodes, operands, instr, ref step, nameof(AddCustomFoodReservation), false))
                {
                    yield return(new CodeInstruction(OpCodes.Ldarg_0));

                    yield return(new CodeInstruction(OpCodes.Ldarg_1));

                    yield return(new CodeInstruction(OpCodes.Ldarg_2));

                    yield return(new CodeInstruction(OpCodes.Call, typeof(AddCustomFoodReservation).GetMethod(nameof(AddContitionToPredicate))));
                }
                yield return(instr);
            }
        }
            /* === Original code look-up===
             * if (pawn.IsColonist)
             *
             * === CIL instructions===
             * ldloc.0 |  | Label 17Label 18
             * ldfld | Verse.Pawn pawn | no labels
             * callvirt | Boolean get_IsColonist() | no labels
             *
             */

            static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, MethodBase mBase, IEnumerable <CodeInstruction> instructions)
            {
                OpCode[] opCodes =
                {
                    OpCodes.Ldloc_0,
                    OpCodes.Ldfld,
                    OpCodes.Callvirt,
                };
                string[] operands =
                {
                    "",
                    "Verse.Pawn pawn",
                    "Boolean get_IsColonist()",
                };
                int step = 0;

                foreach (var instr in instructions)
                {
                    if (HPatcher.IsFragment(opCodes, operands, instr, ref step, nameof(Patch_RenamePrisoners) + nameof(EnableRenamingPrisoners), true))
                    {
                        yield return(new CodeInstruction(OpCodes.Call, typeof(EnableRenamingPrisoners).GetMethod(nameof(IsColonistOrPrisonerOfColony))));
                    }
                    else
                    {
                        yield return(instr);
                    }
                }
            }
Exemplo n.º 3
0
        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);
                }
            }
        }
Exemplo n.º 4
0
        static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, IEnumerable <CodeInstruction> instr)
        {
            // "listing_Standard.End()" fragment
            OpCode[] opCodes =
            {
                OpCodes.Ldloc_2,
                OpCodes.Callvirt,
            };
            string[] operands =
            {
                "",
                "Void End()",
            };
            int step2 = 0;

            foreach (var ci in instr)
            {
                if (HPatcher.IsFragment(opCodes, operands, ci, ref step2, "Patch_PrisonerTab listing_standard.End()"))
                {
                    yield return(new CodeInstruction(OpCodes.Ldloc_2));

                    yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_PrisonerTab).GetMethod(nameof(AddRecruitButton))));

                    // Append Dev lines (When dev mode is on)
                    yield return(new CodeInstruction(OpCodes.Ldloc_2));

                    yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_PrisonerTab).GetMethod(nameof(AppendDevLines))));
                }

                yield return(ci);
            }
        }
Exemplo n.º 5
0
Arquivo: SoS2.cs Projeto: Aviuz/Locks
        public static IEnumerable <CodeInstruction> AirLockTranspiler(ILGenerator gen, MethodBase mBase, IEnumerable <CodeInstruction> instr)
        {
            OpCode[] codeToFind =
            {
                OpCodes.Ldarg_1,
                OpCodes.Call,
                OpCodes.Stloc_0
            };

            string[] labelToFind =
            {
                "",
                "Verse.AI.Group.Lord GetLord(Verse.Pawn)",
                ""
            };
            int step = 0;

            foreach (CodeInstruction codeInst in instr)
            {
                yield return(codeInst);

                if (HPatcher.IsFragment(codeToFind, labelToFind, codeInst, ref step))
                {
                    yield return(new CodeInstruction(OpCodes.Ldarg_0));

                    yield return(new CodeInstruction(OpCodes.Ldarg_1));

                    yield return(new CodeInstruction(OpCodes.Call, typeof(LockUtility).GetMethod("PawnCanOpen")));

                    yield return(new CodeInstruction(OpCodes.Ret));
                }
            }
        }
        /*  === Orignal code Look-up===
         *
         *  if (!pawn2.Position.IsInPrisonCell(pawn2.Map))
         *  {
         *      return null;
         *  }
         *
         *  === CIL Instructions ===
         *
         *  ldloc.0 |  | Label 2
         *  callvirt | IntVec3 get_Position() | no labels
         *  ldloc.0 |  | no labels
         *  callvirt | Verse.Map get_Map() | no labels
         *  call | Boolean IsInPrisonCell(IntVec3, Verse.Map) | no labels
         *  brtrue | Label 3 | no labels
         *  ldnull |  | no labels
         *  ret |  | no labels
         *
         *  ldloc.0 |  | Label 3
         */

        static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, IEnumerable <CodeInstruction> instructions)
        {
            OpCode[] opCodes =
            {
                OpCodes.Call,
                OpCodes.Brtrue,
            };
            string[] operands =
            {
                "Boolean IsInPrisonCell(IntVec3, Verse.Map)",
                "System.Reflection.Emit.Label",
            };
            int step = 0;

            foreach (var instr in instructions)
            {
                if (HPatcher.IsFragment(opCodes, operands, instr, ref step, nameof(DeliverEvenOutsidePrisonCell), true))
                {
                    yield return(new CodeInstruction(OpCodes.Pop));

                    instr.opcode = OpCodes.Br;
                }
                yield return(instr);
            }
        }
        /*  === Original code Look-up ===
         *
         *  if (!allowSociallyImproper)
         *  {
         *      bool animalsCare = !getter.RaceProps.Animal;
         *      if (!t.IsSociallyProper(getter) && !t.IsSociallyProper(eater, eater.IsPrisonerOfColony, animalsCare))
         *      {
         *          return false;
         *      }
         *  }
         *  return true;
         *
         *  === CIL Instructions ===
         *
         *  ldarg.3 |  | no labels
         *  brtrue | Label 1 | no labels
         *  ldarg.1 |  | no labels
         *  callvirt | Verse.RaceProperties get_RaceProps() | no labels
         *  callvirt | Boolean get_Animal() | no labels
         *  ldc.i4.0 |  | no labels
         *  ceq |  | no labels
         *  stloc.0 |  | no labels
         *  ldarg.0 |  | no labels
         *  ldarg.1 |  | no labels
         *  call | Boolean IsSociallyProper(Verse.Thing, Verse.Pawn) | no labels
         *  brtrue | Label 2 | no labels
         *  ldarg.0 |  | no labels
         *  ldarg.2 |  | no labels
         *  ldarg.2 |  | no labels
         *  callvirt | Boolean get_IsPrisonerOfColony() | no labels
         *  ldloc.0 |  | no labels
         *  call | Boolean IsSociallyProper(Verse.Thing, Verse.Pawn, Boolean, Boolean) | no labels
         *  brtrue | Label 3 | no labels
         *  ldc.i4.0 |  | no labels
         *  ret |  | no labels
         *  ldc.i4.1 |  | Label 1Label 2Label 3
         *  ret |  | no labels
         */

        static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, IEnumerable <CodeInstruction> instructions)
        {
            OpCode[] opCodes =
            {
                OpCodes.Ldarg_3,
                OpCodes.Brtrue_S,
            };
            string[] operands =
            {
                "",
                "",
            };
            int step = 0;

            foreach (var instr in instructions)
            {
                if (HPatcher.IsFragment(opCodes, operands, instr, ref step, nameof(FoodUtility_IsFoodSourceOnMapSociallyProper), false))
                {
                    yield return(new CodeInstruction(OpCodes.Pop));

                    instr.opcode = OpCodes.Br;
                }
                yield return(instr);
            }
        }
Exemplo n.º 8
0
        static private IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, IEnumerable <CodeInstruction> instr)
        {
            // if (forPrisoner)
            OpCode[] opCodes =
            {
                OpCodes.Ldarg_2,
                OpCodes.Brfalse_S,
            };
            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));
                }
            }
        }
        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(nameof(IsForCertainGroup))));

                    yield return(new CodeInstruction(OpCodes.Brfalse, label));
                }
            }
        }
Exemplo n.º 10
0
        private static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, MethodBase mBase,
                                                                IEnumerable <CodeInstruction> instr)
        {
            // Temporary class for main loop
            OpCode[] opCodesClass =
            {
                OpCodes.Ldloc_S,
            };
            string[] operandsClass =
            {
                "RimWorld.JobGiver_Work+<>c__DisplayClass3_1 (9)",
            };
            var tempClass = HPatcher.FindOperandAfter(opCodesClass, operandsClass, instr, true);

            // Scanner
            OpCode[] opCodesScanner =
            {
                OpCodes.Ldfld,
            };
            string[] operandsScanner =
            {
                "RimWorld.WorkGiver_Scanner scanner",
            };
            var scanner = HPatcher.FindOperandAfter(opCodesScanner, operandsScanner, instr, true);

            // Fragment where cells are collected as IEnumerable
            OpCode[] opCodesFunc =
            {
                OpCodes.Callvirt,
            };
            string[] operandsFunc =
            {
                "System.Collections.Generic.IEnumerable`1[Verse.IntVec3] PotentialWorkCellsGlobal(Verse.Pawn)",
            };
            int stepFunc = 0;

            // Transpiler
            foreach (var instruction in instr)
            {
                yield return(instruction);

                if (HPatcher.IsFragment(opCodesFunc, operandsFunc, instruction, ref stepFunc, "LaborForbid", true))
                {
                    yield return(new CodeInstruction(OpCodes.Ldarg_1));

                    yield return(new CodeInstruction(OpCodes.Ldloc_S, tempClass));

                    yield return(new CodeInstruction(OpCodes.Ldfld, scanner));

                    yield return(new CodeInstruction(OpCodes.Ldfld, typeof(WorkGiver).GetField("def")));

                    yield return(new CodeInstruction(OpCodes.Ldfld, typeof(WorkGiverDef).GetField("workType")));

                    yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_LaborForbid).GetMethod("RemoveFromListForbiddenCells")));
                }
            }
        }
        /*  === Orignal code Look-up===
         *
         *  if (RestUtility.FindBedFor(prisoner, prisoner, true, true, false) != null)
         *  {
         *      return null;
         *  }
         *
         *  === CIL Instructions ===
         *
         *  ldarg.1 |  | Label 2
         *  ldarg.1 |  | no labels
         *  ldc.i4.1 |  | no labels
         *  ldc.i4.1 |  | no labels
         *  ldc.i4.0 |  | no labels
         *  call | RimWorld.Building_Bed FindBedFor(Verse.Pawn, Verse.Pawn, Boolean, Boolean, Boolean) | no labels
         *  brfalse | Label 3 | no labels
         */

        static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, MethodBase mBase, IEnumerable <CodeInstruction> instructions)
        {
            OpCode[] opCodes1 =
            {
                OpCodes.Ldarg_0,
                OpCodes.Ldarg_0,
                OpCodes.Ldc_I4_1,
                OpCodes.Ldc_I4_0,
                OpCodes.Ldc_I4_1,
                OpCodes.Newobj,
                OpCodes.Call,
                OpCodes.Brfalse_S,
            };
            string[] operands1 =
            {
                "",
                "",
                "",
                "",
                "",
                "Void .ctor(GuestStatus)",
                "RimWorld.Building_Bed FindBedFor(Verse.Pawn, Verse.Pawn, Boolean, Boolean, System.Nullable`1[RimWorld.GuestStatus])",
                "System.Reflection.Emit.Label",
            };
            int step1 = 0;

            var label_OriginalBranch = gen.DefineLabel();

            foreach (var instr in instructions)
            {
                if (HPatcher.IsFragment(opCodes1, operands1, instr, ref step1, nameof(Patch_TakePrisonersToOwnedBed), true))
                {
                    yield return(new CodeInstruction(OpCodes.Ldarg_1));

                    yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_TakePrisonersToOwnedBed).GetMethod(nameof(HaveOwnedBed))));

                    yield return(new CodeInstruction(OpCodes.Brfalse, label_OriginalBranch));

                    yield return(new CodeInstruction(OpCodes.Pop));

                    yield return(new CodeInstruction(OpCodes.Ldarg_1));

                    yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_TakePrisonersToOwnedBed).GetMethod(nameof(CanReachBed))));

                    yield return(new CodeInstruction(OpCodes.Brfalse, instr.operand));

                    yield return(new CodeInstruction(OpCodes.Ldnull));

                    yield return(new CodeInstruction(OpCodes.Ret));

                    instr.labels.Add(label_OriginalBranch);
                }
                yield return(instr);
            }
        }
Exemplo n.º 12
0
        static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, IEnumerable <CodeInstruction> instr)
        {
            // "if (Prefs.DevMode)" fragment
            OpCode[] opCodes1 =
            {
                OpCodes.Call,
                OpCodes.Brfalse,
            };
            string[] operands1 =
            {
                "Boolean get_DevMode()",
                "System.Reflection.Emit.Label",
            };
            int step1 = 0;

            // "listing_Standard.End()" fragment
            OpCode[] opCodes2 =
            {
                OpCodes.Ldloc_3,
                OpCodes.Callvirt,
            };
            string[] operands2 =
            {
                "",
                "Void End()",
            };
            int step2 = 0;

            foreach (var ci in instr)
            {
                if (HPatcher.IsFragment(opCodes2, operands2, ci, ref step2, "Patch_PrisonerTab listing_standard.End()"))
                {
                    yield return(new CodeInstruction(OpCodes.Ldloc_3));

                    yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_PrisonerTab).GetMethod(nameof(AddRecruitButton))));
                }

                yield return(ci);

                if (HPatcher.IsFragment(opCodes1, operands1, ci, ref step1, "Patch_PrisonerTab IfDevMode"))
                {
                    yield return(new CodeInstruction(OpCodes.Ldloc_3));

                    yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_PrisonerTab).GetMethod(nameof(AppendDevLines))));
                }
            }
        }
            /*  === Orignal code Look-up===
             *
             * catch
             * {
             *      (...)
             *      <---
             * }
             * finally
             * {
             *      (...)
             * }
             *
             *  === CIL Instructions ===
             *
             *  leave | label x | no labels
             *
             */

            static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, MethodBase mBase, IEnumerable <CodeInstruction> instructions)
            {
                OpCode[] opCodes1 =
                {
                    OpCodes.Leave_S,
                };
                string[] operands1 =
                {
                    "System.Reflection.Emit.Label",
                };
                int step1 = 0;

                foreach (var instr in instructions)
                {
                    if (HPatcher.IsFragment(opCodes1, operands1, instr, ref step1, nameof(Patch_LoadVersion), true))
                    {
                        yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_LoadVersion).GetMethod(nameof(ReadMetaData))));
                    }
                    yield return(instr);
                }
            }
Exemplo n.º 14
0
        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_S }, new[] { "System.Reflection.Emit.Label" }, instr);

            // if (!pawn.IsColonist)
            OpCode[] opCodes =
            {
                OpCodes.Ldarg_0,
                OpCodes.Ldfld,
                OpCodes.Callvirt,
                OpCodes.Brtrue_S,
            };
            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_S, label));
                }
            }
        }
Exemplo n.º 15
0
        /*  === Orignal code Look-up===
         *
         *  if (WorkGiver_Warden_DeliverFood.FoodAvailableInRoomTo(pawn2))
         *	{
         *		return null;
         *	}
         *
         *  === CIL Instructions ===
         *
         *  ldloc.0 |  | Label 7
         *  call | Boolean FoodAvailableInRoomTo(Verse.Pawn) | no labels
         *  brfalse | Label 8 | no labels
         *  ldnull |  | no labels
         *  ret |  | no labels
         *  ldloc.2 |  | Label 8
         */

        static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, IEnumerable <CodeInstruction> instructions)
        {
            OpCode[] opCodes =
            {
                OpCodes.Call,
            };
            string[] operands =
            {
                "Boolean FoodAvailableInRoomTo(Verse.Pawn)",
            };
            int step = 0;

            foreach (var instr in instructions)
            {
                if (HPatcher.IsFragment(opCodes, operands, instr, ref step, nameof(StopIfPrisonerCanGetFoodByHimself) + 1, true))
                {
                    yield return(new CodeInstruction(OpCodes.Call, typeof(StopIfPrisonerCanGetFoodByHimself).GetMethod(nameof(FoodAvailableForPrisoner))));
                }
                else
                {
                    yield return(instr);
                }
            }
        }
Exemplo n.º 16
0
        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;

            // Find else if with ..  && !current.IsForbidden(pawn) && scanner.HasJobOnCell(pawn, current, false) and add && IsDisabledByLabor()
            OpCode[] opCodes2 =
            {
                OpCodes.Bge_Un,
                OpCodes.Ldloc_S,
                OpCodes.Ldloc_0,
                OpCodes.Ldfld,
                OpCodes.Call,
                OpCodes.Brtrue,
                OpCodes.Ldloc_S,
                OpCodes.Ldfld,
                OpCodes.Ldloc_0,
                OpCodes.Ldfld,
                OpCodes.Ldloc_S,
                OpCodes.Ldc_I4_0,
                OpCodes.Callvirt,
                OpCodes.Brfalse,
            };
            String[] operands2 =
            {
                "System.Reflection.Emit.Label",
                "Verse.IntVec3 (33)",
                "",
                "Verse.Pawn pawn",
                "Boolean IsForbidden(IntVec3, Verse.Pawn)",
                "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, Boolean)",
                "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(nameof(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((nameof(GetWorkType)))));

                    yield return(new CodeInstruction(OpCodes.Call, typeof(PrisonLaborUtility).GetMethod((nameof(PrisonLaborUtility.IsDisabledByLabor)))));

                    yield return(new CodeInstruction(OpCodes.Brtrue, ci.operand));
                }
            }
        }
        private static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, IEnumerable <CodeInstruction> instr)
        {
            #region fragment>>GUI.BeginGroup(position);
            OpCode[] opCodes1 =
            {
                OpCodes.Call,
                OpCodes.Stloc_S,
                OpCodes.Ldloc_S,
                OpCodes.Call,
            };
            String[] operands1 =
            {
                "Rect ContractedBy(Rect, Single)",
                "UnityEngine.Rect (6)",
                "UnityEngine.Rect (6)",
                "Void BeginGroup(Rect)",
            };
            int step1 = 0;
            #endregion

            #region fragment>>GUI.EndGroup();
            OpCode[] opCodes2 =
            {
                OpCodes.Ldloc_S,
                OpCodes.Callvirt,
                OpCodes.Endfinally,
                OpCodes.Call,
            };
            String[] operands2 =
            {
                "System.Collections.Generic.IEnumerator`1[RimWorld.PrisonerInteractionModeDef] (9)",
                "Void Dispose()",
                "",
                "Void EndGroup()",
            };
            int step2 = 0;
            #endregion

            #region fragment>>Rect position = rect5.ContractedBy(10f);
            OpCode[] opCodes3 =
            {
                OpCodes.Ldc_R4,
                OpCodes.Call,
                OpCodes.Stloc_S,
                OpCodes.Ldloc_S,
            };
            String[] operands3 =
            {
                "10",
                "Rect ContractedBy(Rect, Single)",
                "UnityEngine.Rect (6)",
                "UnityEngine.Rect (6)",
            };
            int step3 = 0;
            var rect  = HPatcher.FindOperandAfter(opCodes3, operands3, instr);
            #endregion

            foreach (var ci in instr)
            {
                // end scroll
                if (HPatcher.IsFragment(opCodes2, operands2, ci, ref step2, "AddScrollToPrisonerTab2"))
                {
                    var instruction = new CodeInstruction(OpCodes.Call, typeof(Patch_AddScrollToPrisonerTab).GetMethod(nameof(StopScrolling)));
                    instruction.labels.AddRange(ci.labels);
                    ci.labels.Clear();
                    yield return(instruction);
                }

                // resize
                if (HPatcher.IsFragment(opCodes3, operands3, ci, ref step3, "AddScrollToPrisonerTab3"))
                {
                }

                yield return(ci);

                // begin scroll
                if (HPatcher.IsFragment(opCodes1, operands1, ci, ref step1, "AddScrollToPrisonerTab1"))
                {
                    yield return(new CodeInstruction(OpCodes.Ldloc_S, rect));

                    yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_AddScrollToPrisonerTab).GetMethod(nameof(StartScrolling))));

                    yield return(new CodeInstruction(OpCodes.Stloc_S, rect));
                }
            }
        }