Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
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.º 3
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);
            }
        }
Exemplo n.º 4
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);
                }
            }
        }
        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.º 6
0
 static Initialization()
 {
     HPatcher.Init();
 }
Exemplo n.º 7
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.º 8
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));
                }
            }
        }
Exemplo n.º 10
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)
            };
            IEnumerable <CodeInstruction> result = HPatcher.ReplaceFragment(opCodesToReplace, operandsToReplace, instructions, replacment, nameof(ITab_Pawn_Visitor) + ": patch display ideo ico");

            OpCode[] opCodesToFindForCustomConvert =
            {
                OpCodes.Ldsfld,
                OpCodes.Bne_Un_S,
            };
            string[] operandsToFindForCustomConvert =
            {
                "RimWorld.PrisonerInteractionModeDef Convert",
                "System.Reflection.Emit.Label"
            };
            var labelCustomConvert = (Label)HPatcher.FindOperandAfter(opCodesToFindForCustomConvert, operandsToFindForCustomConvert, instructions);


            OpCode[] opCodesToReplaceForCustomConvert =
            {
                OpCodes.Ldsfld,
                OpCodes.Bne_Un_S,
            };
            string[] operandsToReplaceForCustomConvert =
            {
                "RimWorld.PrisonerInteractionModeDef Convert",
                "System.Reflection.Emit.Label"
            };

            CodeInstruction[] replacmentForCustomConvert =
            {
                new CodeInstruction(OpCodes.Call,    typeof(Patch_VisitorTab_TabDraw).GetMethod(nameof(IsConvert))),
                new CodeInstruction(OpCodes.Brfalse, labelCustomConvert)
            };

            return(HPatcher.ReplaceFragment(opCodesToReplaceForCustomConvert, operandsToReplaceForCustomConvert, result, replacmentForCustomConvert, nameof(ITab_Pawn_Visitor) + ": patch prisoner tab window"));
        }