Exemplo n.º 1
0
        /*  === Orignal code Look-up===
         *
         *  if (t.Faction != pawn.Faction)
         *	{
         *		return false;
         *	}
         *
         *  === CIL Instructions ===
         *
         *  ldarg.2 |  | no labels
         *  callvirt | RimWorld.Faction get_Faction() | no labels
         *  ldarg.1 |  | no labels
         *  callvirt | RimWorld.Faction get_Faction() | no labels
         *  beq | Label 1 | no labels
         *  ldc.i4.0 |  | no labels
         *  ret |  | no labels
         *  ldarg.2 |  | Label 1
         */

        static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, MethodBase mBase, IEnumerable <CodeInstruction> instructions)
        {
            //find label to jump
            OpCode[] opCodes1 =
            {
                OpCodes.Ldarg_2,
                OpCodes.Callvirt,
                OpCodes.Ldarg_1,
                OpCodes.Callvirt,
                OpCodes.Beq,
            };
            string[] operands1 =
            {
                "",
                "RimWorld.Faction get_Faction()",
                "",
                "RimWorld.Faction get_Faction()",
                "System.Reflection.Emit.Label",
            };
            var label = HPatcher.FindOperandAfter(opCodes1, operands1, instructions, true);

            //Add If(pawn.IsPrisonerOfColony) {jump next condition}
            yield return(new CodeInstruction(OpCodes.Ldarg_1));

            yield return(new CodeInstruction(OpCodes.Callvirt, typeof(Pawn).GetProperty(nameof(Pawn.IsPrisoner)).GetGetMethod()));

            yield return(new CodeInstruction(OpCodes.Brtrue, label));

            foreach (var instr in instructions)
            {
                yield return(instr);
            }
        }
        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.º 3
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")));
                }
            }
        }
Exemplo n.º 4
0
        static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, MethodBase mBase, IEnumerable <CodeInstruction> instructions)
        {
            OpCode[] opCodesToFind =
            {
                OpCodes.Call,
                OpCodes.Ldfld,
                OpCodes.Ldfld,
                OpCodes.Ldsfld,
                OpCodes.Bne_Un
            };
            string[] operandsToFind =
            {
                "Verse.Pawn get_SelPawn()",
                "RimWorld.Pawn_GuestTracker guest",
                "RimWorld.PrisonerInteractionModeDef interactionMode",
                "RimWorld.PrisonerInteractionModeDef Convert",
                "System.Reflection.Emit.Label"
            };

            OpCode[] opCodesToReplace =
            {
                OpCodes.Call,
                OpCodes.Ldfld,
                OpCodes.Ldfld,
                OpCodes.Ldsfld,
                OpCodes.Bne_Un
            };
            string[] operandsToReplace =
            {
                "Verse.Pawn get_SelPawn()",
                "RimWorld.Pawn_GuestTracker guest",
                "RimWorld.PrisonerInteractionModeDef interactionMode",
                "RimWorld.PrisonerInteractionModeDef Convert",
                "System.Reflection.Emit.Label"
            };

            var label = (Label)HPatcher.FindOperandAfter(opCodesToFind, operandsToFind, instructions);

            CodeInstruction[] replacment =
            {
                new CodeInstruction(OpCodes.Call,    typeof(Patch_VisitorTab_TabDraw).GetMethod(nameof(ShouldDisplayConvertIco))),
                new CodeInstruction(OpCodes.Brfalse, label)
            };

            return(HPatcher.ReplaceFragment(opCodesToReplace, operandsToReplace, instructions, replacment, nameof(ITab_Pawn_Visitor) + ": patch display ideo ico"));
        }
        private static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, IEnumerable <CodeInstruction> instr)
        {
            // Find >> priorities
            var priorities = HPatcher.FindOperandAfter(new[] { OpCodes.Ldflda }, new[] { "Verse.DefMap`2[Verse.WorkTypeDef,System.Int32] priorities" }, instr);

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

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

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

            yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_JailorTypeSaveCompatibility).GetMethod(nameof(AddJailor))));

            //yield return new CodeInstruction(OpCodes.Pop);
            //yield return new CodeInstruction(OpCodes.Ldarg_0);
            yield return(new CodeInstruction(OpCodes.Stfld, priorities));

            foreach (var ci in instr)
            {
                yield return(ci);
            }
        }
        private static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, MethodBase mBase, IEnumerable <CodeInstruction> instr)
        {
            //Searches for pawn
            var pawn = HPatcher.FindOperandAfter(new[] { OpCodes.Ldfld }, new[] { "Verse.Pawn pawn" }, instr);
            // Define label to the begining of the original code
            var jumpTo = gen.DefineLabel();

            //Load argument onto stack
            yield return(new CodeInstruction(OpCodes.Ldarg_1));

            //Load pawn onto stack
            yield return(new CodeInstruction(OpCodes.Ldarg_0));

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

            //Call function
            yield return(new CodeInstruction(OpCodes.Call, typeof(Patch_NeedOnlyByPrisoners).GetMethod(nameof(ShouldHaveNeedPrisoner))));

            //If true continue
            yield return(new CodeInstruction(OpCodes.Brtrue, jumpTo));

            //Load false to stack
            yield return(new CodeInstruction(OpCodes.Ldc_I4_0));

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

            var first = true;

            foreach (var ci in instr)
            {
                if (first)
                {
                    first = false;
                    ci.labels.Add(jumpTo);
                }
                yield return(ci);
            }
        }
Exemplo n.º 7
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.º 8
0
        static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            OpCode[] opCodes1 =
            {
                OpCodes.Ldarg_2,
                OpCodes.Callvirt,
                OpCodes.Ldarg_1,
                OpCodes.Callvirt,
                OpCodes.Beq_S,
            };
            string[] operands1 =
            {
                "",
                "RimWorld.Faction get_Faction()",
                "",
                "RimWorld.Faction get_Faction()",
                "System.Reflection.Emit.Label",
            };


            var label = HPatcher.FindOperandAfter(opCodes1, operands1, instructions, true);

            //Add If(pawn.IsPrisonerOfColony) {jump next condition}
            yield return(new CodeInstruction(OpCodes.Ldarg_2));

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

            yield return(new CodeInstruction(OpCodes.Call, typeof(ConstructionUtils).GetMethod(nameof(ConstructionUtils.IsPrisonerWork))));

            yield return(new CodeInstruction(OpCodes.Brtrue, label));

            foreach (var instr in instructions)
            {
                yield return(instr);
            }
        }
        private static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, IEnumerable <CodeInstruction> instr)
        {
            OpCode[] opCodesToFind =
            {
                OpCodes.Ldloc_0,
                OpCodes.Callvirt,
                OpCodes.Brtrue_S
            };
            string[] operandsToFind =
            {
                "",
                "RimWorld.Faction get_HostFaction()",
                "System.Reflection.Emit.Label"
            };
            Label label = (Label)HPatcher.FindOperandAfter(opCodesToFind, operandsToFind, instr);

            CodeInstruction[] replacemnt =
            {
                new CodeInstruction(OpCodes.Nop),
                new CodeInstruction(OpCodes.Nop),
                new CodeInstruction(OpCodes.Nop, label),
            };
            return(HPatcher.ReplaceFragment(opCodesToFind, operandsToFind, instr, replacemnt, "Patch_Bill_ProductionWithUft"));
        }
Exemplo n.º 10
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));
                }
            }
        }
Exemplo n.º 11
0
        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.Ldstr,
                OpCodes.Call,
                OpCodes.Call,
                OpCodes.Ldnull,
                OpCodes.Callvirt,
                OpCodes.Brfalse_S
            };
            String[] operands1 =
            {
                "NotSuspended",
                "Verse.TaggedString Translate(System.String)",
                "System.String op_Implicit(Verse.TaggedString)",
                "",
                "Boolean ButtonText(System.String, System.String)",
                "System.Reflection.Emit.Label",
            };
            var label = HPatcher.FindOperandAfter(opCodes1, operands1, instr);

            // Find listing standard for buttons on left
            OpCode[] opCodes4 =
            {
                OpCodes.Call,
                OpCodes.Br_S,
                OpCodes.Ldloc_S,
            };
            String[] operands4 =
            {
                "Void PlayOneShotOnCamera(Verse.SoundDef, Verse.Map)",
                "System.Reflection.Emit.Label",
                "Verse.Listing_Standard (28)",
            };
            var listing = HPatcher.FindOperandAfter(opCodes4, operands4, instr);

            foreach (var ci in instr)
            {
                if (ci.labels.Contains((Label)label))
                {
                    var injectedInstruction = new CodeInstruction(OpCodes.Ldloc_S, listing);
                    foreach (var item in ci.labels)
                    {
                        injectedInstruction.labels.Add(item);
                    }
                    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(nameof(GroupExclusionButton))));

                    ci.labels.Clear();
                }

                yield return(ci);
            }
        }
        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));
                }
            }
        }