using System; using System.Collections.Generic; using HarmonyLib; using RimWorld; using Verse; namespace BlaxLaws { /// /// Hook K (design: "Enforcement runs a tick later"): a postfix on Pawn_GuestTracker.CapturedBy /// (RimWorld/Pawn_GuestTracker.cs:561-576, 16 lines with calls, not inlinable), which the arrest and /// capture jobs call when the enforcer picks the pawn up (JobDriver_TakeToBed.cs:164-178). It returns at /// once unless the pawn has a case in Enforcing whose own enforcer made the capture for a jail /// punishment; then the sentence starts (Sentences.OnCaptured). Nothing else of the capture changes. /// /// Hook point for later steps: "Release gives back what jail took" adds a prefix here that notes the /// weapon the pawn holds before SetGuestStatus drops it (:564; :461), and "Castes keeps the caste" sends /// Castes the blax.laws.jailed hint from that prefix. /// [HarmonyPatch(typeof(Pawn_GuestTracker), nameof(Pawn_GuestTracker.CapturedBy))] public static class Patch_Pawn_GuestTracker_CapturedBy { public static void Postfix(Pawn ___pawn, Faction by, Pawn byPawn) { try { if (byPawn == null || ___pawn == null || by == null || !by.IsPlayer) return; GameComponent_BlaxLaws comp = GameComponent_BlaxLaws.Instance; if (comp == null) return; IReadOnlyList list = comp.CasesOf(___pawn); if (list.Count == 0 || !___pawn.IsPrisonerOfColony) return; for (int i = list.Count - 1; i >= 0; i--) { LawCase c = list[i]; if (Sentences.IsOurCapture(c, byPawn)) { Sentences.OnCaptured(c); return; } } } catch (Exception e) { HookGuard.Fail("hook K, Pawn_GuestTracker.CapturedBy", e); } } } }