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> DoGrowSubplant(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator) { List <CodeInstruction> instructionsList = instructions.ToList(); Type loadLockObjectType = typeof(List <Thing>); List <CodeInstruction> loadLockObjectInstructions = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(CompSpawnSubplant), "subplants")) }; List <CodeInstruction> searchInstructions = loadLockObjectInstructions.ListFullCopy(); searchInstructions.Add(new CodeInstruction(OpCodes.Ldarg_0)); searchInstructions.Add(new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(CompSpawnSubplant), "get_Props"))); searchInstructions.Add(new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(CompProperties_SpawnSubplant), "subplant"))); searchInstructions.Add(new CodeInstruction(OpCodes.Ldloc_2)); searchInstructions.Add(new CodeInstruction(OpCodes.Ldarg_0)); searchInstructions.Add(new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(ThingComp), "parent"))); searchInstructions.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Thing), "get_Map"))); searchInstructions.Add(new CodeInstruction(OpCodes.Ldc_I4_0)); searchInstructions.Add(new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(GenSpawn), "Spawn", new Type[] { typeof(ThingDef), typeof(IntVec3), typeof(Map), typeof(WipeMode) }))); searchInstructions.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(loadLockObjectType, "Add"))); int i = 0; int matchesFound = 0; while (i < instructionsList.Count) { if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, i)) { matchesFound++; foreach (CodeInstruction codeInstruction in RimThreadedHarmony.GetLockCodeInstructions( iLGenerator, instructionsList, i, searchInstructions.Count, loadLockObjectInstructions, loadLockObjectType)) { yield return(codeInstruction); } i += searchInstructions.Count; } else { yield return(instructionsList[i]); i++; } } if (matchesFound < 1) { 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> 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> AddDirect(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_2), new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Hediff>), "get_Item")), new CodeInstruction(OpCodes.Ldarg_1), new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Hediff), "TryMergeWith")), new CodeInstruction(OpCodes.Brfalse_S) }; List <CodeInstruction> instructionsList = instructions.ToList(); int currentInstructionIndex = 0; bool matchFound = false; while (currentInstructionIndex < instructionsList.Count) { if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, currentInstructionIndex)) { matchFound = true; for (int i = 0; i < 4; i++) { CodeInstruction codeInstruction = instructionsList[currentInstructionIndex + i]; yield return(new CodeInstruction(codeInstruction.opcode, codeInstruction.operand)); } yield return(new CodeInstruction(OpCodes.Brfalse_S, instructionsList[currentInstructionIndex + 6].operand)); yield return(instructionsList[currentInstructionIndex]); currentInstructionIndex++; } else { yield return(instructionsList[currentInstructionIndex]); currentInstructionIndex++; } } if (!matchFound) { Log.Error("IL code instructions not found"); } }
public static IEnumerable <CodeInstruction> GetExtendedDataFor(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator) { Type typeDictionaryIntData = typeof(Dictionary <,>).MakeGenericType(new Type[] { typeof(int), RimThreadedHarmony.giddyUpCoreStorageExtendedPawnData }); List <CodeInstruction> loadLockObjectInstructions = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(RimThreadedHarmony.giddyUpCoreStorageExtendedDataStorage, "_store")), }; List <CodeInstruction> searchInstructions = loadLockObjectInstructions.ListFullCopy(); searchInstructions.Add(new CodeInstruction(OpCodes.Ldloc_0)); searchInstructions.Add(new CodeInstruction(OpCodes.Ldloc_2)); searchInstructions.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeDictionaryIntData, "set_Item", new Type[] { typeof(int) }))); //searchInstructions.Add(new CodeInstruction(OpCodes.Pop)); 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.GetLockCodeInstructions( iLGenerator, instructionsList, currentInstructionIndex, searchInstructions.Count, loadLockObjectInstructions, typeDictionaryIntData)) { 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"); } }
public static IEnumerable <CodeInstruction> Reserve(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator) { List <CodeInstruction> instructionsList = instructions.ToList(); Type loadLockObjectType = typeof(List <AttackTargetReservation>); List <CodeInstruction> loadLockObjectInstructions = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(AttackTargetReservationManager), "reservations")) }; List <CodeInstruction> searchInstructions = loadLockObjectInstructions.ListFullCopy(); searchInstructions.Add(new CodeInstruction(OpCodes.Ldloc_0)); searchInstructions.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(loadLockObjectType, "Add"))); int i = 0; int matchesFound = 0; while (i < instructionsList.Count) { if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, i)) { matchesFound++; foreach (CodeInstruction codeInstruction in RimThreadedHarmony.GetLockCodeInstructions( iLGenerator, instructionsList, i, searchInstructions.Count, loadLockObjectInstructions, loadLockObjectType)) { yield return(codeInstruction); } i += searchInstructions.Count; } else { yield return(instructionsList[i]); i++; } } if (matchesFound < 1) { Log.Error("IL code instructions not found"); } }
public static IEnumerable <CodeInstruction> OnPawnRemoved(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator) { List <CodeInstruction> instructionsList = instructions.ToList(); Type loadLockObjectType = typeof(Dictionary <,>).MakeGenericType(new Type[] { typeof(Pawn), RimThreadedHarmony.hospitalityCompGuest }); List <CodeInstruction> loadLockObjectInstructions = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(RimThreadedHarmony.hospitalityCompUtility, "guestComps")) }; List <CodeInstruction> searchInstructions = loadLockObjectInstructions.ListFullCopy(); searchInstructions.Add(new CodeInstruction(OpCodes.Ldarg_0)); searchInstructions.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(loadLockObjectType, "Remove", new Type[] { typeof(Pawn) }))); searchInstructions.Add(new CodeInstruction(OpCodes.Pop)); int i = 0; int matchesFound = 0; while (i < instructionsList.Count) { if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, i)) { matchesFound++; foreach (CodeInstruction codeInstruction in RimThreadedHarmony.GetLockCodeInstructions( iLGenerator, instructionsList, i, searchInstructions.Count, loadLockObjectInstructions, loadLockObjectType)) { yield return(codeInstruction); } i += searchInstructions.Count; } else { yield return(instructionsList[i]); i++; } } if (matchesFound < 1) { Log.Error("IL code instructions not found"); } }
public static IEnumerable <CodeInstruction> PopState(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator) { Type typeDictionaryIntData = typeof(Stack <ulong>); List <CodeInstruction> loadLockObjectInstructions = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldsfld, Field(typeof(Rand), "stateStack")), }; List <CodeInstruction> searchInstructions = loadLockObjectInstructions.ListFullCopy(); searchInstructions.Add(new CodeInstruction(OpCodes.Callvirt, Method(typeDictionaryIntData, "Pop"))); searchInstructions.Add(new CodeInstruction(OpCodes.Call, Method(typeof(Rand), "set_StateCompressed"))); 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.GetLockCodeInstructions( iLGenerator, instructionsList, currentInstructionIndex, searchInstructions.Count, loadLockObjectInstructions, typeDictionaryIntData)) { 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> 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"); } }
public static IEnumerable <CodeInstruction> WaitForRider(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator) { List <CodeInstruction> searchInstructions2 = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Call, AccessTools.Method(RimThreadedHarmony.giddyUpCoreJobsJobDriver_Mounted, "get_Rider")), new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Pawn), "get_CurJob")), }; List <CodeInstruction> searchInstructions = searchInstructions2.ListFullCopy(); searchInstructions.Add(new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(Job), "def"))); searchInstructions.Add(new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(RimThreadedHarmony.giddyUpCoreJobsGUC_JobDefOf, "Mount"))); searchInstructions.Add(new CodeInstruction(OpCodes.Beq_S)); List <CodeInstruction> instructionsList = instructions.ToList(); int currentInstructionIndex = 0; bool matchFound = false; LocalBuilder curJob = iLGenerator.DeclareLocal(typeof(Job)); while (currentInstructionIndex < instructionsList.Count) { if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, currentInstructionIndex)) { matchFound = true; for (int i = 0; i < 3; i++) { yield return(instructionsList[currentInstructionIndex]); currentInstructionIndex++; } yield return(new CodeInstruction(OpCodes.Stloc, curJob.LocalIndex)); yield return(new CodeInstruction(OpCodes.Ldloc, curJob.LocalIndex)); yield return(new CodeInstruction(OpCodes.Brfalse_S, instructionsList[currentInstructionIndex + 2].operand)); //this may need to be a jump to a line 5 lines above this yield return(new CodeInstruction(OpCodes.Ldloc, curJob.LocalIndex)); for (int i = 0; i < 3; i++) { yield return(instructionsList[currentInstructionIndex]); currentInstructionIndex++; } } else if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions2, instructionsList, currentInstructionIndex)) { matchFound = true; yield return(new CodeInstruction(OpCodes.Ldloc, curJob.LocalIndex)); for (int i = 0; i < 3; i++) { //yield return instructionsList[currentInstructionIndex]; currentInstructionIndex++; } } else { yield return(instructionsList[currentInstructionIndex]); currentInstructionIndex++; } } if (!matchFound) { Log.Error("IL code instructions not found"); } }
public static IEnumerable <CodeInstruction> Formatted(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator) { List <CodeInstruction> instructionsList = instructions.ToList(); Type loadLockObjectType = typeof(List <string>); List <CodeInstruction> loadLockObjectInstructions = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_1), }; List <CodeInstruction> searchInstructions = loadLockObjectInstructions.ListFullCopy(); searchInstructions.Add(new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Enumerable), "ToList").MakeGenericMethod(typeof(string)))); searchInstructions.Add(new CodeInstruction(OpCodes.Stloc_S, 5)); Type loadLockObjectType2 = typeof(List <object>); List <CodeInstruction> loadLockObjectInstructions2 = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_2), }; List <CodeInstruction> searchInstructions2 = loadLockObjectInstructions2.ListFullCopy(); searchInstructions2.Add(new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Enumerable), "ToList").MakeGenericMethod(typeof(object)))); searchInstructions2.Add(new CodeInstruction(OpCodes.Stloc_S, 6)); /* Original PathFinder.FindPath * * ---START ORIG--- IL_000b: ldsfld bool Verse.GrammarResolverSimple::working * * ---END ORIG--- * * ---START TARGET--- * IL_0000: ldc-i4-1 * ---END TARGET--- * * */ //LocalBuilder tmpCells = iLGenerator.DeclareLocal(typeof(List<IntVec3>)); int i = 0; //yield return new CodeInstruction(OpCodes.Newobj, typeof(List<IntVec3>).GetConstructor(Type.EmptyTypes)); //yield return new CodeInstruction(OpCodes.Stloc_S, tmpCells.LocalIndex); int matchesFound = 0; while (i < instructionsList.Count) { //---START ORIG-- - // IL_000b: ldsfld bool Verse.GrammarResolverSimple::working //-- - END ORIG-- - //---START TARGET-- - //IL_0000: Ldc_I4_0 //-- - END TARGET-- - if ( instructionsList[i].opcode == OpCodes.Ldsfld && (FieldInfo)instructionsList[i].operand == AccessTools.Field(typeof(GrammarResolverSimple), "working") ) { instructionsList[i].opcode = OpCodes.Ldc_I4_1; instructionsList[i].operand = null; yield return(instructionsList[i]); i++; } else if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, i)) { matchesFound++; foreach (CodeInstruction codeInstruction in RimThreadedHarmony.GetLockCodeInstructions( iLGenerator, instructionsList, i, searchInstructions.Count, loadLockObjectInstructions, loadLockObjectType)) { yield return(codeInstruction); } i += searchInstructions.Count; } else if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions2, instructionsList, i)) { matchesFound++; foreach (CodeInstruction codeInstruction in RimThreadedHarmony.GetLockCodeInstructions( iLGenerator, instructionsList, i, searchInstructions2.Count, loadLockObjectInstructions2, loadLockObjectType2)) { yield return(codeInstruction); } i += searchInstructions.Count; } else { yield return(instructionsList[i]); i++; } } if (matchesFound < 2) { Log.Error("IL code instructions not found"); } }
public static IEnumerable <CodeInstruction> Remove(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator) { List <CodeInstruction> instructionsList = instructions.ToList(); Type loadLockObjectType = typeof(List <Thing>); List <CodeInstruction> loadLockObjectInstructions = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, Field(typeof(ListerThings), "listsByDef")), new CodeInstruction(OpCodes.Ldarg_1), new CodeInstruction(OpCodes.Ldfld, Field(typeof(Thing), "def")), new CodeInstruction(OpCodes.Callvirt, Method(typeof(Dictionary <ThingDef, List <Thing> >), "get_Item")) }; List <CodeInstruction> searchInstructions = loadLockObjectInstructions.ListFullCopy(); searchInstructions.Add(new CodeInstruction(OpCodes.Ldarg_1)); searchInstructions.Add(new CodeInstruction(OpCodes.Callvirt, Method(typeof(Thing), "Remove"))); searchInstructions.Add(new CodeInstruction(OpCodes.Pop)); Type loadLockObjectType2 = typeof(List <Thing>); List <CodeInstruction> loadLockObjectInstructions2 = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, Field(typeof(ListerThings), "listsByGroup")), new CodeInstruction(OpCodes.Ldloc_1), new CodeInstruction(OpCodes.Ldelem_Ref) }; List <CodeInstruction> searchInstructions2 = loadLockObjectInstructions2.ListFullCopy(); searchInstructions2.Add(new CodeInstruction(OpCodes.Ldarg_1)); searchInstructions2.Add(new CodeInstruction(OpCodes.Callvirt, Method(loadLockObjectType2, "Remove"))); searchInstructions2.Add(new CodeInstruction(OpCodes.Pop)); int i = 0; int matchesFound = 0; while (i < instructionsList.Count) { if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, i)) { matchesFound++; foreach (CodeInstruction codeInstruction in RimThreadedHarmony.GetLockCodeInstructions( iLGenerator, instructionsList, i, searchInstructions.Count, loadLockObjectInstructions, loadLockObjectType)) { yield return(codeInstruction); } i += searchInstructions.Count; } else if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions2, instructionsList, i)) { matchesFound++; foreach (CodeInstruction codeInstruction in RimThreadedHarmony.GetLockCodeInstructions( iLGenerator, instructionsList, i, searchInstructions2.Count, loadLockObjectInstructions2, loadLockObjectType2)) { yield return(codeInstruction); } i += searchInstructions2.Count; } else { yield return(instructionsList[i]); i++; } } if (matchesFound < 1) { Log.Error("IL code instructions not found"); } }
public static IEnumerable <CodeInstruction> DeRegisterPawn(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator) { List <CodeInstruction> instructionsList = instructions.ToList(); Type loadLockObjectType = typeof(List <Pawn>); List <CodeInstruction> loadLockObjectInstructions = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(MapPawns), "pawnsSpawned")) }; List <CodeInstruction> searchInstructions = loadLockObjectInstructions.ListFullCopy(); searchInstructions.Add(new CodeInstruction(OpCodes.Ldarg_1)); searchInstructions.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Pawn>), "Remove"))); searchInstructions.Add(new CodeInstruction(OpCodes.Pop)); Type loadLockObjectType2 = typeof(Dictionary <Faction, List <Pawn> >); List <CodeInstruction> loadLockObjectInstructions2 = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(MapPawns), "pawnsInFactionSpawned")) }; List <CodeInstruction> searchInstructions2 = new List <CodeInstruction>(); //loadLockObjectInstructions2.ListFullCopy(); searchInstructions2.Add(new CodeInstruction(OpCodes.Ldloc_0)); searchInstructions2.Add(new CodeInstruction(OpCodes.Ldloc_1)); searchInstructions2.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Faction>), "get_Item"))); searchInstructions2.Add(new CodeInstruction(OpCodes.Stloc_2)); searchInstructions2.Add(new CodeInstruction(OpCodes.Ldarg_0)); searchInstructions2.Add(new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(MapPawns), "pawnsInFactionSpawned"))); searchInstructions2.Add(new CodeInstruction(OpCodes.Ldloc_2)); searchInstructions2.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Dictionary <Faction, List <Pawn> >), "get_Item"))); searchInstructions2.Add(new CodeInstruction(OpCodes.Ldarg_1)); searchInstructions2.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Pawn>), "Remove"))); searchInstructions2.Add(new CodeInstruction(OpCodes.Pop)); Type loadLockObjectType3 = typeof(List <Pawn>); List <CodeInstruction> loadLockObjectInstructions3 = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(MapPawns), "prisonersOfColonySpawned")) }; List <CodeInstruction> searchInstructions3 = loadLockObjectInstructions3.ListFullCopy(); searchInstructions3.Add(new CodeInstruction(OpCodes.Ldarg_1)); searchInstructions3.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Pawn>), "Remove"))); searchInstructions3.Add(new CodeInstruction(OpCodes.Pop)); int i = 0; int[] matchesFound = { 0, 0, 0 }; while (i < instructionsList.Count) { if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, i)) { matchesFound[0]++; foreach (CodeInstruction codeInstruction in RimThreadedHarmony.GetLockCodeInstructions( iLGenerator, instructionsList, i, searchInstructions.Count, loadLockObjectInstructions, loadLockObjectType)) { yield return(codeInstruction); } i += searchInstructions.Count; } else if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions2, instructionsList, i)) { matchesFound[1]++; foreach (CodeInstruction codeInstruction in RimThreadedHarmony.GetLockCodeInstructions( iLGenerator, instructionsList, i, searchInstructions2.Count, loadLockObjectInstructions2, loadLockObjectType2)) { yield return(codeInstruction); } i += searchInstructions.Count; } else if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions3, instructionsList, i)) { matchesFound[2]++; foreach (CodeInstruction codeInstruction in RimThreadedHarmony.GetLockCodeInstructions( iLGenerator, instructionsList, i, searchInstructions3.Count, loadLockObjectInstructions3, loadLockObjectType3)) { yield return(codeInstruction); } i += searchInstructions.Count; } else { yield return(instructionsList[i]); i++; } } for (int mIndex = 0; mIndex < matchesFound.Length; mIndex++) { if (matchesFound[mIndex] < 1) { Log.Error("IL code instruction set " + mIndex + " not found"); } } }
public static IEnumerable <CodeInstruction> RegisterPawn(IEnumerable <CodeInstruction> instructions, ILGenerator iLGenerator) { List <CodeInstruction> instructionsList = instructions.ToList(); Type loadLockObjectType = typeof(List <Pawn>); List <CodeInstruction> loadLockObjectInstructions = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(MapPawns), "pawnsSpawned")) }; List <CodeInstruction> searchInstructions = loadLockObjectInstructions.ListFullCopy(); searchInstructions.Add(new CodeInstruction(OpCodes.Ldarg_1)); searchInstructions.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Pawn>), "Contains"))); searchInstructions.Add(new CodeInstruction(OpCodes.Brtrue_S)); searchInstructions.Add(new CodeInstruction(OpCodes.Ldarg_0)); searchInstructions.Add(new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(MapPawns), "pawnsSpawned"))); searchInstructions.Add(new CodeInstruction(OpCodes.Ldarg_1)); searchInstructions.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Pawn>), "Add"))); Type loadLockObjectType2 = typeof(Dictionary <Faction, List <Pawn> >); List <CodeInstruction> loadLockObjectInstructions2 = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(MapPawns), "pawnsInFactionSpawned")) }; List <CodeInstruction> searchInstructions2 = new List <CodeInstruction>(); //loadLockObjectInstructions2.ListFullCopy(); searchInstructions2.Add(new CodeInstruction(OpCodes.Ldarg_1)); searchInstructions2.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Thing), "get_Faction"))); searchInstructions2.Add(new CodeInstruction(OpCodes.Brfalse_S)); /* * searchInstructions2.Add(new CodeInstruction(OpCodes.Ldarg_1)); * searchInstructions2.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Thing), "get_Faction"))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Dictionary<Faction, List<Pawn>>), "get_Item"))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Ldarg_1)); * searchInstructions2.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List<Pawn>), "Contains"))); */ /* * searchInstructions2.Add(new CodeInstruction(OpCodes.Brtrue_S)); * searchInstructions2.Add(new CodeInstruction(OpCodes.Ldarg_0)); * searchInstructions2.Add(new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(MapPawns), "pawnsInFactionSpawned"))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Ldarg_1)); * searchInstructions2.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Thing), "get_Faction"))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List<Pawn>), "get_Item"))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Ldarg_1)); * searchInstructions2.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List<Pawn>), "Add"))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Ldarg_1)); * searchInstructions2.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Thing), "get_Faction"))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Faction), "get_OfPlayer"))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Bne_Un_S)); * searchInstructions2.Add(new CodeInstruction(OpCodes.Ldarg_0)); * searchInstructions2.Add(new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(MapPawns), "pawnsInFactionSpawned"))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Faction), "get_OfPlayer"))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List<Pawn>), "get_Item"))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(AccessTools.TypeByName("Verse.MapPawns+<>c"), "<>9__82_0"))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Dup)); * searchInstructions2.Add(new CodeInstruction(OpCodes.Brtrue_S)); * searchInstructions2.Add(new CodeInstruction(OpCodes.Pop)); * searchInstructions2.Add(new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(AccessTools.TypeByName("Verse.MapPawns+<>c"), "<>9"))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Ldftn, AccessTools.Method(AccessTools.TypeByName("Verse.MapPawns+<>c"), "<RegisterPawn>b__82_0"))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Newobj, AccessTools.Constructor(typeof(Comparison<Pawn>), new Type[] { typeof(object), typeof(int) } ))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Dup)); * searchInstructions2.Add(new CodeInstruction(OpCodes.Stsfld, AccessTools.Field(AccessTools.TypeByName("Verse.MapPawns+<>c"), "<>9__82_0"))); * searchInstructions2.Add(new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(GenList), "InsertionSort"))); */ Type loadLockObjectType3 = typeof(List <Pawn>); List <CodeInstruction> loadLockObjectInstructions3 = new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(MapPawns), "prisonersOfColonySpawned")) }; List <CodeInstruction> searchInstructions3 = new List <CodeInstruction>(); searchInstructions3.Add(new CodeInstruction(OpCodes.Ldarg_1)); searchInstructions3.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Pawn), "get_IsPrisonerOfColony"))); searchInstructions3.Add(new CodeInstruction(OpCodes.Brfalse_S)); searchInstructions3.Add(new CodeInstruction(OpCodes.Ldarg_0)); searchInstructions3.Add(new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(MapPawns), "prisonersOfColonySpawned"))); searchInstructions3.Add(new CodeInstruction(OpCodes.Ldarg_1)); searchInstructions3.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Pawn>), "Contains"))); searchInstructions3.Add(new CodeInstruction(OpCodes.Brtrue_S)); searchInstructions3.Add(new CodeInstruction(OpCodes.Ldarg_0)); searchInstructions3.Add(new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(MapPawns), "prisonersOfColonySpawned"))); searchInstructions3.Add(new CodeInstruction(OpCodes.Ldarg_1)); searchInstructions3.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(List <Pawn>), "Add"))); int i = 0; int[] matchesFound = { 0, 0, 0 }; while (i < instructionsList.Count) { if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions, instructionsList, i)) { matchesFound[0]++; foreach (CodeInstruction codeInstruction in RimThreadedHarmony.GetLockCodeInstructions( iLGenerator, instructionsList, i, searchInstructions.Count, loadLockObjectInstructions, loadLockObjectType)) { yield return(codeInstruction); } i += searchInstructions.Count; //yield return new CodeInstruction(OpCodes.Ldarg_0); //yield return new CodeInstruction(OpCodes.Ldarg_1); //yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(MapPawns_Patch), "RegisterPawn3")); //i += searchInstructions.Count; } else if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions2, instructionsList, i)) { matchesFound[1]++; /* * LocalBuilder lockObject = iLGenerator.DeclareLocal(loadLockObjectType2); * LocalBuilder lockTaken = iLGenerator.DeclareLocal(typeof(bool)); * loadLockObjectInstructions2[0].labels = instructionsList[i].labels; * for (int j = 0; j < loadLockObjectInstructions2.Count; j++) * { * yield return (loadLockObjectInstructions2[j]); * } * instructionsList[i].labels = new List<Label>(); * yield return (new CodeInstruction(OpCodes.Stloc, lockObject.LocalIndex)); * yield return (new CodeInstruction(OpCodes.Ldc_I4_0)); * yield return (new CodeInstruction(OpCodes.Stloc, lockTaken.LocalIndex)); * CodeInstruction codeInstruction = new CodeInstruction(OpCodes.Ldloc, lockObject.LocalIndex); * codeInstruction.blocks.Add(new ExceptionBlock(ExceptionBlockType.BeginExceptionBlock)); * yield return (codeInstruction); * yield return (new CodeInstruction(OpCodes.Ldloca_S, lockTaken.LocalIndex)); * yield return (new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Monitor), "Enter", * new Type[] { typeof(object), typeof(bool).MakeByRefType() }))); * //searchInstructions2.Add(new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(GenList), "InsertionSort"))); * while (i < instructionsList.Count - 1 && (instructionsList[i + 1].opcode != OpCodes.Callvirt || * (MethodInfo)instructionsList[i + 1].operand != AccessTools.Method(typeof(Pawn), "get_IsPrisonerOfColony"))) * { * yield return (instructionsList[i]); * i++; * } * Label endHandlerDestination = iLGenerator.DefineLabel(); * yield return (new CodeInstruction(OpCodes.Leave_S, endHandlerDestination)); * codeInstruction = new CodeInstruction(OpCodes.Ldloc, lockTaken.LocalIndex); * codeInstruction.blocks.Add(new ExceptionBlock(ExceptionBlockType.BeginFinallyBlock)); * yield return (codeInstruction); * Label endFinallyDestination = iLGenerator.DefineLabel(); * yield return (new CodeInstruction(OpCodes.Brfalse_S, endFinallyDestination)); * yield return (new CodeInstruction(OpCodes.Ldloc, lockObject.LocalIndex)); * yield return (new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Monitor), "Exit"))); * codeInstruction = new CodeInstruction(OpCodes.Endfinally); * codeInstruction.labels.Add(endFinallyDestination); * codeInstruction.blocks.Add(new ExceptionBlock(ExceptionBlockType.EndExceptionBlock)); * yield return (codeInstruction); * instructionsList[i].labels.Add(endHandlerDestination); */ instructionsList[i].opcode = OpCodes.Ldarg_0; instructionsList[i].operand = null; yield return(instructionsList[i]); //yield return new CodeInstruction(OpCodes.Ldarg_0); yield return(new CodeInstruction(OpCodes.Ldarg_1)); yield return(new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(MapPawns_Patch), "RegisterPawn2"))); while (i < instructionsList.Count - 1 && (instructionsList[i + 1].opcode != OpCodes.Callvirt || (MethodInfo)instructionsList[i + 1].operand != AccessTools.Method(typeof(Pawn), "get_IsPrisonerOfColony"))) { //yield return (instructionsList[i]); i++; } } else if (RimThreadedHarmony.IsCodeInstructionsMatching(searchInstructions3, instructionsList, i)) { matchesFound[2]++; /* * foreach (CodeInstruction codeInstruction in RimThreadedHarmony.GetLockCodeInstructions( * iLGenerator, instructionsList, i, searchInstructions3.Count, loadLockObjectInstructions3, loadLockObjectType3)) * { * yield return codeInstruction; * } * i += searchInstructions3.Count; */ instructionsList[i].opcode = OpCodes.Ldarg_0; instructionsList[i].operand = null; yield return(instructionsList[i]); //yield return new CodeInstruction(OpCodes.Ldarg_0); yield return(new CodeInstruction(OpCodes.Ldarg_1)); yield return(new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(MapPawns_Patch), "RegisterPawn3"))); i += searchInstructions3.Count; } else { yield return(instructionsList[i]); i++; } } for (int mIndex = 0; mIndex < matchesFound.Length; mIndex++) { if (matchesFound[mIndex] < 1) { Log.Error("IL code instruction set " + mIndex + " not found"); } } }