using HarmonyLib; using RimWorld; using rjw; using rjw.Modules.Interactions.Internals.Implementation; using rjw.Modules.Interactions.Objects; using RJWSexperience.Ideology.HistoryEvents; using RJWSexperience.Ideology.Precepts; using System; using System.Collections.Generic; using System.Reflection.Emit; using Verse; namespace RJWSexperience.Ideology.Patches { [HarmonyPatch(typeof(xxx), nameof(xxx.can_rape))] public static class RJW_Patch_CannotRapeBecauseIdeo { /// /// Injects IdeoCanRape call into is_human block of xxx.can_rape /// /// Original method instructions /// Modified method instructions [HarmonyTranspiler] public static IEnumerable AddIdeoCheck(IEnumerable instructions, ILGenerator generator) { using IEnumerator enumerator = instructions.GetEnumerator(); System.Reflection.FieldInfo wildMode = AccessTools.Field(typeof(RJWSettings), nameof(RJWSettings.WildMode)); Label labelWildMode = generator.DefineLabel(); bool done = false; while (enumerator.MoveNext()) { if (!done && enumerator.Current.LoadsField(wildMode)) { // Found RJWSettings.WildMode check, insert before // Need to move labels to our instruction because previous check jumps to one of them, skipping our call var existingLabels = enumerator.Current.labels; enumerator.Current.labels = new List