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")));
                }
            }
        }
示例#3
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;

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