using HarmonyLib; using RimWorld; using System; using System.Collections.Generic; using System.Linq; using UnityEngine; using Verse; namespace RJW_Menstruation { [HarmonyPatch(typeof(Pawn), nameof(Pawn.SpawnSetup))] public class Pawn_Patch { public static void Postfix(Pawn __instance) { //Log.Message("Initialize on spawnsetup"); foreach (HediffComp_Menstruation comp in __instance.GetMenstruationComps()) { comp.Initialize(); } __instance.GetBreastComp()?.Initialize(); } } [HarmonyPatch(typeof(FloatMenuMakerMap), "AddHumanlikeOrders")] public class HumanlikeOrder_Patch { public static void Postfix(Vector3 clickPos, Pawn pawn, List opts) { IEnumerable selftargets = GenUI.TargetsAt(clickPos, TargetingParameters.ForSelf(pawn)); foreach (LocalTargetInfo t in selftargets) { if (t.Pawn == pawn && pawn.HasMenstruationComp()) opts.AddDistinct(MakeSelfMenu(pawn, t)); break; } } public static FloatMenuOption MakeSelfMenu(Pawn pawn, LocalTargetInfo target) { FloatMenuOption option = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(Translations.FloatMenu_CleanSelf, delegate () { pawn.jobs.TryTakeOrderedJob(new Verse.AI.Job(VariousDefOf.VaginaWashing, null, null, target.Cell)); }, MenuOptionPriority.Low), pawn, target); return option; } } [HarmonyPatch(typeof(HealthCardUtility), "DrawOverviewTab")] public class DrawOverviewTab_Patch { public const float buttonWidth = 50f; public const float buttonHeight = 20f; public static void Prefix(Rect leftRect, Pawn pawn, float curY) { if (Configurations.EnableButtonInHT && pawn.ShowStatus() && pawn.ShouldCycle()) { HediffComp_Menstruation comp = pawn.GetFirstMenstruationComp(); if (comp != null) { Text.Font = GameFont.Tiny; Rect buttonRect = new Rect(leftRect.xMax - buttonWidth - 8f, curY + 4f, buttonWidth, buttonHeight); if (Widgets.ButtonText(buttonRect, Translations.Button_HealthTab)) { Dialog_WombStatus.ToggleWindow(pawn, comp); } } } } } [HarmonyPatch(typeof(CompBiosculpterPod), nameof(CompBiosculpterPod.CannotUseNowPawnCycleReason), new Type[] { typeof(Pawn), typeof(Pawn), typeof(CompBiosculpterPod_Cycle), typeof(bool) })] public class CannotUseNowPawnCycleReason_Patch { private const string eggRestorationKey = "eggRestoration"; public static void Postfix(ref string __result, Pawn biosculptee, CompBiosculpterPod_Cycle cycle) { if (__result != null) return; if (cycle.Props.key == eggRestorationKey && !biosculptee.GetMenstruationComps().Any()) __result = Translations.CannotNoWomb; } } // Doesn't cover everything, but at least it'll get the auto equip [HarmonyPatch(typeof(Apparel), nameof(Apparel.PawnCanWear))] public class PawnCanWear_Patch { public static void Postfix(ref bool __result, Apparel __instance, Pawn pawn) { if (__result && __instance is Absorber) { __result = pawn.ShouldCycle() && pawn.GetMenstruationComps().Any(); } } } // Might cause issues when it comes to caravans //[HarmonyPatch(typeof(JobGiver_OptimizeApparel), nameof(JobGiver_OptimizeApparel.ApparelScoreRaw))] //public class ApparelScoreRaw_Patch //{ // public static void Postfix(ref float __result, Pawn pawn, Apparel ap) // { // if (__result > 0f && ap is Absorber && !pawn.GetMenstruationComps().Any(comp => comp.TotalCum > 0)) // __result = -10f; // } //} }