diff --git a/1.4/Assemblies/RJW_Menstruation.dll b/1.4/Assemblies/RJW_Menstruation.dll index 274ae52..0fea093 100644 Binary files a/1.4/Assemblies/RJW_Menstruation.dll and b/1.4/Assemblies/RJW_Menstruation.dll differ diff --git a/1.4/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_PregeneratedBabies.cs b/1.4/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_PregeneratedBabies.cs index f830211..c83daef 100644 --- a/1.4/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_PregeneratedBabies.cs +++ b/1.4/source/RJW_Menstruation/RJW_Menstruation/HediffComps/HediffComp_PregeneratedBabies.cs @@ -291,7 +291,9 @@ namespace RJW_Menstruation public static void Postfix(ref int __result, Pawn mother) { if (Configurations.PregnancySource != Configurations.PregnancyType.Biotech || !Configurations.EnableBiotechTwins) return; - __result = 0; + // 'mother' is the genetic mother, but unless she's in labor at the same time the birtherthing is spitting out, this will work as intended + if (mother?.health.hediffSet.GetFirstHediff()?.TryGetComp()?.HasBaby ?? false) + __result = 0; return; } } diff --git a/1.4/source/RJW_Menstruation/RJW_Menstruation/Patch/Biotech_Patch.cs b/1.4/source/RJW_Menstruation/RJW_Menstruation/Patch/Biotech_Patch.cs index 2d802d6..c60d3b4 100644 --- a/1.4/source/RJW_Menstruation/RJW_Menstruation/Patch/Biotech_Patch.cs +++ b/1.4/source/RJW_Menstruation/RJW_Menstruation/Patch/Biotech_Patch.cs @@ -4,8 +4,6 @@ using RimWorld; using Verse; using System.Collections.Generic; using System.Reflection; -using System; -using System.Reflection.Emit; namespace RJW_Menstruation { @@ -122,21 +120,9 @@ namespace RJW_Menstruation } } - [HarmonyPatch] - public class TerminatePregnancy_Patch + [HarmonyPatch(typeof(PregnancyUtility), nameof(PregnancyUtility.TryTerminatePregnancy))] + public class TryTerminatePregnancy_Patch { - public static IEnumerable TargetMethods() - { - yield return AccessTools.Method(typeof(PregnancyUtility), nameof(PregnancyUtility.TryTerminatePregnancy)); - yield return AccessTools.Method(typeof(Recipe_TerminatePregnancy), nameof(Recipe_TerminatePregnancy.ApplyOnPawn)); - } - - private static PregnancyAttitude? GetAttitude(Hediff pregnancy) - { - if (pregnancy is Hediff_Pregnant preg) return preg.Attitude; - else return null; - } - private static Hediff GetEarliestPregnancy(Pawn pawn) { Hediff Earliest_Pregnancy = PregnancyUtility.GetPregnancyHediff(pawn); @@ -150,30 +136,20 @@ namespace RJW_Menstruation return Earliest_Pregnancy; } - private static readonly MethodInfo GetPregnancyHediff = AccessTools.Method(typeof(PregnancyUtility), nameof(PregnancyUtility.GetPregnancyHediff), new Type[] { typeof(Pawn) }); - private static readonly MethodInfo Get_Attitude = AccessTools.DeclaredPropertyGetter(typeof(Hediff_Pregnant), nameof(Hediff_Pregnant.Attitude)); + private static readonly MethodInfo GetPregnancyHediff = AccessTools.Method(typeof(PregnancyUtility), nameof(PregnancyUtility.GetPregnancyHediff), new System.Type[] { typeof(Pawn) }); + // Also called for Recipe_TerminatePregnancy.ApplyOnPawn public static IEnumerable Transpiler(IEnumerable instructions) { - if (GetPregnancyHediff == null || GetPregnancyHediff.ReturnType != typeof(Hediff)) throw new InvalidOperationException("GetPregnancyHediff not found"); - if (Get_Attitude == null || Nullable.GetUnderlyingType(Get_Attitude.ReturnType) != typeof(PregnancyAttitude)) throw new InvalidOperationException("get_Attitude not found"); + if (GetPregnancyHediff == null || GetPregnancyHediff.ReturnType != typeof(Hediff)) throw new System.InvalidOperationException("GetPregnancyHediff not found"); foreach (CodeInstruction instruction in instructions) { if (instruction.Calls(GetPregnancyHediff)) - yield return CodeInstruction.Call(typeof(TerminatePregnancy_Patch), nameof(TerminatePregnancy_Patch.GetEarliestPregnancy)); - // Menstruation pregnancies don't have an attitude, so skip the cast to Hediff_Pregnant and call a version that handles it - else if (instruction.opcode == OpCodes.Castclass && (Type)instruction.operand == typeof(Hediff_Pregnant)) - yield return new CodeInstruction(OpCodes.Nop); - else if (instruction.Calls(Get_Attitude)) - yield return CodeInstruction.Call(typeof(TerminatePregnancy_Patch), nameof(TerminatePregnancy_Patch.GetAttitude)); + yield return CodeInstruction.Call(typeof(TryTerminatePregnancy_Patch), nameof(TryTerminatePregnancy_Patch.GetEarliestPregnancy)); else yield return instruction; } } - } - [HarmonyPatch(typeof(PregnancyUtility), nameof(PregnancyUtility.TryTerminatePregnancy))] - public class PregnancyUtility_TryTerminatePregnancy_Patch - { public static void Postfix(bool __result, Pawn pawn) { if (__result) @@ -192,6 +168,15 @@ namespace RJW_Menstruation } } + [HarmonyPatch(typeof(Recipe_TerminatePregnancy), nameof(Recipe_TerminatePregnancy.ApplyOnPawn))] + public class TerminatePregnancy_ApplyOnPawn_Patch + { + public static IEnumerable Transpiler(IEnumerable instructions) + { + return TryTerminatePregnancy_Patch.Transpiler(instructions); + } + } + [HarmonyPatch(typeof(Pawn_GeneTracker), "Notify_GenesChanged")] public class Notify_GenesChanged_Patch { diff --git a/changelogs.txt b/changelogs.txt index fc1e583..263dbc4 100644 --- a/changelogs.txt +++ b/changelogs.txt @@ -1,6 +1,5 @@ Version 1.0.8.6 - Updated Traditional Chinese translation by Hydrogen. - - Fix error when trying to terminate a non-Biotech pregnancy. - Added several menstruation-related genes. - Added experimental support for twins and hybrids with Biotech pregnancies, disabled by default.