From 472933e192df07ffa1ac8557249513f0aa9811a1 Mon Sep 17 00:00:00 2001 From: amevarashi Date: Sun, 5 Nov 2023 10:42:07 +0500 Subject: [PATCH 1/4] Migrated project to SDK --- Source/IdeologyAddon/IdeologyAddon.csproj | 98 +++-------------------- 1 file changed, 9 insertions(+), 89 deletions(-) diff --git a/Source/IdeologyAddon/IdeologyAddon.csproj b/Source/IdeologyAddon/IdeologyAddon.csproj index f791556..a5593cf 100644 --- a/Source/IdeologyAddon/IdeologyAddon.csproj +++ b/Source/IdeologyAddon/IdeologyAddon.csproj @@ -1,113 +1,33 @@ - - - + - Debug - AnyCPU {B4481C38-31B1-422D-B5AA-0059FE7CCA1C} Library - Properties RJWSexperience.Ideology RJWSexperience.Ideology - v4.7.2 - 512 - true - - - true - full - false - ..\..\RJWSexperience_Ideology\Assemblies\ - DEBUG;TRACE - prompt - 4 - - - pdbonly + net48 true ..\..\1.4\Assemblies\ - TRACE - prompt - 4 + false + False + 8.0 + ..\..\..\rjw\1.4\Assemblies\RJW.dll False - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - 1.4.3704 + 1.4.* - 2.2.2 + 2.* runtime compile; build; native; contentfiles; analyzers; buildtransitive - \ No newline at end of file From 71df71a0eb1c62728796a4c5404131f84ce98074 Mon Sep 17 00:00:00 2001 From: amevarashi Date: Mon, 6 Nov 2023 16:28:08 +0500 Subject: [PATCH 2/4] Fixed: Pawns raping despite Rape-Abhorrent precept --- .../HistoryEventDefExtensionMethods.cs | 2 + .../IdeologyAddon/Patches/RJW_Patch_Ideo.cs | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/Source/IdeologyAddon/HistoryEvents/HistoryEventDefExtensionMethods.cs b/Source/IdeologyAddon/HistoryEvents/HistoryEventDefExtensionMethods.cs index 8f1a4ab..808170c 100644 --- a/Source/IdeologyAddon/HistoryEvents/HistoryEventDefExtensionMethods.cs +++ b/Source/IdeologyAddon/HistoryEvents/HistoryEventDefExtensionMethods.cs @@ -2,6 +2,7 @@ using Verse; using System.Linq; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace RJWSexperience.Ideology.HistoryEvents { @@ -27,6 +28,7 @@ namespace RJWSexperience.Ideology.HistoryEvents //Log.Message($"[RSI] Recorded event {historyEvent.def.ToStringWithPartner(pawn, partner)}"); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static HistoryEvent CreateEvent(this HistoryEventDef def, Pawn pawn) { return new HistoryEvent(def, pawn.Named(HistoryEventArgsNames.Doer)); diff --git a/Source/IdeologyAddon/Patches/RJW_Patch_Ideo.cs b/Source/IdeologyAddon/Patches/RJW_Patch_Ideo.cs index 4a06922..9e9a808 100644 --- a/Source/IdeologyAddon/Patches/RJW_Patch_Ideo.cs +++ b/Source/IdeologyAddon/Patches/RJW_Patch_Ideo.cs @@ -7,10 +7,55 @@ 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