public static IEnumerable <CodeInstruction> PartIsMissing(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator)
        {
            List <CodeInstruction> searchInstructions = new List <CodeInstruction>
            {
                new CodeInstruction(OpCodes.Ldarg_0),
                new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(HediffSet), "hediffs")),
                new CodeInstruction(OpCodes.Ldloc_0),
                new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Hediff>), "get_Item")),
                new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Hediff), "get_Part")),
                new CodeInstruction(OpCodes.Ldarg_1),
                new CodeInstruction(OpCodes.Bne_Un_S),
                new CodeInstruction(OpCodes.Ldarg_0),
                new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(HediffSet), "hediffs")),
                new CodeInstruction(OpCodes.Ldloc_0),
                new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Hediff>), "get_Item")),
                new CodeInstruction(OpCodes.Isinst, typeof(Hediff_MissingPart)),
                new CodeInstruction(OpCodes.Brfalse_S),
                new CodeInstruction(OpCodes.Ldc_I4_1),
                new CodeInstruction(OpCodes.Ret),
            };
            List <CodeInstruction> instructionsList = instructions.ToList();
            int  currentInstructionIndex            = 0;
            bool matchFound = false;

            while (currentInstructionIndex < instructionsList.Count)
            {
                if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, currentInstructionIndex))
                {
                    matchFound = true;
                    yield return(new CodeInstruction(OpCodes.Ldarg_0));

                    yield return(new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(HediffSet), "hediffs")));

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

                    yield return(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Hediff>), "get_Item")));

                    yield return(new CodeInstruction(OpCodes.Brfalse, instructionsList[currentInstructionIndex + 6].operand));

                    foreach (CodeInstruction codeInstruction in RimThreadedHarmony.UpdateTryCatchCodeInstructions(
                                 iLGenerator, instructionsList, currentInstructionIndex, searchInstructions.Count))
                    {
                        yield return(codeInstruction);
                    }
                    currentInstructionIndex += searchInstructions.Count;
                }
                else
                {
                    yield return(instructionsList[currentInstructionIndex]);

                    currentInstructionIndex++;
                }
            }
            if (!matchFound)
            {
                Log.Error("IL code instructions not found");
            }
        }
        public static IEnumerable <CodeInstruction> CanReserve(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator)
        {
            List <CodeInstruction> searchInstructions = new List <CodeInstruction>
            {
                new CodeInstruction(OpCodes.Ldarg_0),
                new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(ReservationManager), "reservations")),
                new CodeInstruction(OpCodes.Ldloc_S, 4),
                new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <ReservationManager.Reservation>), "get_Item")),
                new CodeInstruction(OpCodes.Stloc_S, 5)
            };
            List <CodeInstruction> searchInstructions2 = new List <CodeInstruction>
            {
                new CodeInstruction(OpCodes.Ldarg_0),
                new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(ReservationManager), "reservations")),
                new CodeInstruction(OpCodes.Ldloc_S, 6),
                new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <ReservationManager.Reservation>), "get_Item")),
                new CodeInstruction(OpCodes.Stloc_S, 7)
            };
            List <CodeInstruction> instructionsList = instructions.ToList();
            int  currentInstructionIndex            = 0;
            bool matchFound = false;

            while (currentInstructionIndex < instructionsList.Count)
            {
                if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, currentInstructionIndex))
                {
                    matchFound = true;
                    foreach (CodeInstruction codeInstruction in RimThreadedHarmony.UpdateTryCatchCodeInstructions(
                                 iLGenerator, instructionsList, currentInstructionIndex, searchInstructions.Count))
                    {
                        yield return(codeInstruction);
                    }
                    currentInstructionIndex += searchInstructions.Count;
                }
                if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions2, instructionsList, currentInstructionIndex))
                {
                    matchFound = true;
                    foreach (CodeInstruction codeInstruction in RimThreadedHarmony.UpdateTryCatchCodeInstructions(
                                 iLGenerator, instructionsList, currentInstructionIndex, searchInstructions2.Count))
                    {
                        yield return(codeInstruction);
                    }
                    currentInstructionIndex += searchInstructions2.Count;
                }
                else
                {
                    yield return(instructionsList[currentInstructionIndex]);

                    currentInstructionIndex++;
                }
            }
            if (!matchFound)
            {
                Log.Error("IL code instructions not found");
            }
        }
        public static IEnumerable <CodeInstruction> IsReservedBy(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator)
        {
            List <CodeInstruction> searchInstructions = new List <CodeInstruction>
            {
                new CodeInstruction(OpCodes.Ldarg_0),
                new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(Verse.AI.AttackTargetReservationManager), "reservations")),
                new CodeInstruction(OpCodes.Ldloc_0),
                new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Verse.AI.AttackTargetReservationManager.AttackTargetReservation>), "get_Item")),
                new CodeInstruction(OpCodes.Stloc_1)
            };
            List <CodeInstruction> instructionsList = instructions.ToList();
            int currentInstructionIndex             = 0;
            int matchFound = 0;

            while (currentInstructionIndex < instructionsList.Count)
            {
                if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, currentInstructionIndex))
                {
                    matchFound++;
                    foreach (CodeInstruction codeInstruction in RimThreadedHarmony.UpdateTryCatchCodeInstructions(
                                 iLGenerator, instructionsList, currentInstructionIndex, searchInstructions.Count))
                    {
                        yield return(codeInstruction);
                    }
                    currentInstructionIndex += searchInstructions.Count;
                }
                else if (
                    instructionsList[currentInstructionIndex].opcode == OpCodes.Ldfld &&
                    (FieldInfo)instructionsList[currentInstructionIndex].operand == AccessTools.Field(typeof(AttackTargetReservation), "target")
                    )
                {
                    matchFound++;
                    yield return(new CodeInstruction(OpCodes.Brfalse, instructionsList[currentInstructionIndex + 2].operand));

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

                    yield return(instructionsList[currentInstructionIndex]);

                    currentInstructionIndex++;
                }
                else
                {
                    yield return(instructionsList[currentInstructionIndex]);

                    currentInstructionIndex++;
                }
            }
            if (matchFound < 2)
            {
                Log.Error("IL code instructions not found");
            }
        }
        public static IEnumerable <CodeInstruction> GetGas(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator)
        {
            List <CodeInstruction> searchInstructions = new List <CodeInstruction>
            {
                new CodeInstruction(OpCodes.Ldloc_0),
                new CodeInstruction(OpCodes.Ldloc_1),
                new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Thing>), "get_Item")),
                new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(Thing), "def")),
                new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(ThingDef), "category")),
                new CodeInstruction(OpCodes.Ldc_I4_7),
                new CodeInstruction(OpCodes.Bne_Un_S),
                new CodeInstruction(OpCodes.Ldloc_0),
                new CodeInstruction(OpCodes.Ldloc_1),
                new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Thing>), "get_Item")),
                new CodeInstruction(OpCodes.Castclass, typeof(Gas)),
                new CodeInstruction(OpCodes.Ret),
            };
            List <CodeInstruction> instructionsList = instructions.ToList();
            int  currentInstructionIndex            = 0;
            bool matchFound = false;

            while (currentInstructionIndex < instructionsList.Count)
            {
                if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, currentInstructionIndex))
                {
                    matchFound = true;
                    foreach (CodeInstruction codeInstruction in RimThreadedHarmony.UpdateTryCatchCodeInstructions(
                                 iLGenerator, instructionsList, currentInstructionIndex, searchInstructions.Count))
                    {
                        yield return(codeInstruction);
                    }
                    currentInstructionIndex += searchInstructions.Count;
                }
                else
                {
                    yield return(instructionsList[currentInstructionIndex]);

                    currentInstructionIndex++;
                }
            }
            if (!matchFound)
            {
                Log.Error("IL code instructions not found");
            }
        }
        public static IEnumerable <CodeInstruction> FoodOptimality(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator)
        {
            List <CodeInstruction> searchInstructions = new List <CodeInstruction>
            {
                new CodeInstruction(OpCodes.Ldloc_0),
                new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(FoodUtility), "FoodOptimalityEffectFromMoodCurve")),
                new CodeInstruction(OpCodes.Ldloc_3),
                new CodeInstruction(OpCodes.Ldloc_S, 4),
                new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <ThoughtDef>), "get_Item")),
                new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(ThoughtDef), "stages")),
                new CodeInstruction(OpCodes.Ldc_I4_0),
                new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <ThoughtStage>), "get_Item")),
                new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(ThoughtStage), "baseMoodEffect")),
                new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(SimpleCurve), "Evaluate")),
                new CodeInstruction(OpCodes.Add),
                new CodeInstruction(OpCodes.Stloc_0)
            };
            List <CodeInstruction> instructionsList = instructions.ToList();
            int  currentInstructionIndex            = 0;
            bool matchFound = false;

            while (currentInstructionIndex < instructionsList.Count)
            {
                if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, currentInstructionIndex))
                {
                    matchFound = true;
                    foreach (CodeInstruction codeInstruction in RimThreadedHarmony.UpdateTryCatchCodeInstructions(
                                 iLGenerator, instructionsList, currentInstructionIndex, searchInstructions.Count))
                    {
                        yield return(codeInstruction);
                    }
                    currentInstructionIndex += searchInstructions.Count;
                }
                else
                {
                    yield return(instructionsList[currentInstructionIndex]);

                    currentInstructionIndex++;
                }
            }
            if (!matchFound)
            {
                Log.Error("IL code instructions not found");
            }
        }
        public static IEnumerable <CodeInstruction> ForceAllowPlaceOver(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator)
        {
            List <CodeInstruction> searchInstructions = new List <CodeInstruction>
            {
                new CodeInstruction(OpCodes.Ldarg_0),
                new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(BuildableDef), "get_PlaceWorkers")),
                new CodeInstruction(OpCodes.Ldloc_0),
                new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <PlaceWorker>), "get_Item")),
                new CodeInstruction(OpCodes.Ldarg_1),
                new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(PlaceWorker), "ForceAllowPlaceOver")),
                new CodeInstruction(OpCodes.Brfalse_S),
                new CodeInstruction(OpCodes.Ldc_I4_1),
                new CodeInstruction(OpCodes.Ret)
            };
            List <CodeInstruction> instructionsList = instructions.ToList();
            int  currentInstructionIndex            = 0;
            bool matchFound = false;

            while (currentInstructionIndex < instructionsList.Count)
            {
                if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, currentInstructionIndex))
                {
                    matchFound = true;
                    foreach (CodeInstruction codeInstruction in RimThreadedHarmony.UpdateTryCatchCodeInstructions(
                                 iLGenerator, instructionsList, currentInstructionIndex, searchInstructions.Count))
                    {
                        yield return(codeInstruction);
                    }
                    currentInstructionIndex += searchInstructions.Count;
                }
                else
                {
                    yield return(instructionsList[currentInstructionIndex]);

                    currentInstructionIndex++;
                }
            }
            if (!matchFound)
            {
                Log.Error("IL code instructions not found");
            }
        }
Beispiel #7
0
        public static IEnumerable <CodeInstruction> get_BlockedOpenMomentary(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator)
        {
            List <CodeInstruction> searchInstructions = new List <CodeInstruction>
            {
                new CodeInstruction(OpCodes.Ldloc_0),
                new CodeInstruction(OpCodes.Ldloc_1),
                new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Thing>), "get_Item")),
                new CodeInstruction(OpCodes.Stloc_2)
            };
            List <CodeInstruction> instructionsList = instructions.ToList();
            int  currentInstructionIndex            = 0;
            bool matchFound = false;

            while (currentInstructionIndex < instructionsList.Count)
            {
                if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, currentInstructionIndex))
                {
                    matchFound = true;
                    foreach (CodeInstruction codeInstruction in RimThreadedHarmony.UpdateTryCatchCodeInstructions(
                                 iLGenerator, instructionsList, currentInstructionIndex, searchInstructions.Count))
                    {
                        yield return(codeInstruction);
                    }
                    currentInstructionIndex += searchInstructions.Count;
                }
                else
                {
                    yield return(instructionsList[currentInstructionIndex]);

                    currentInstructionIndex++;
                }
            }
            if (!matchFound)
            {
                Log.Error("IL code instructions not found");
            }
        }