Blax Laws 1.0.0: lawbook, act catalogue, enforcement and jail
- Laws tab with the lawbook and the case log; the book starts empty and
the mod watches nothing until a law exists.
- Act catalogue built from the game's defs (breaks, food, drugs, usables,
interactions, recorded acts, records, bills) plus special acts, with
groups, break links and a starter lawbook.
- Enforcement: warn, guilty, subdue, jail for N days and subdue then jail,
one case per incident, danger waits, role holders and mechanitors held
for Arrest now.
- Headless test suite green in every DLC combination, core only and with
the compat mods.
2026-12-02 20:07:17 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Verse;
|
|
|
|
|
|
|
|
|
|
namespace BlaxLaws
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// One-time logging. Every hook sits in try/catch and logs through HookGuard, which logs here, so a
|
|
|
|
|
/// broken hook logs once per game instead of every call. The flags reset in
|
|
|
|
|
/// GameComponent_BlaxLaws.FinalizeInit, so a failure in a later game logs again.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class LawsLog
|
|
|
|
|
{
|
|
|
|
|
private static readonly HashSet<string> logged = new HashSet<string>();
|
|
|
|
|
|
|
|
|
|
/// <summary>Logs "[Blax Laws] where failed" with the exception, once per key until the next reset.</summary>
|
|
|
|
|
public static void Once(string where, Exception e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
lock (logged)
|
|
|
|
|
{
|
|
|
|
|
if (!logged.Add(where))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Log.Error("[Blax Laws] " + where + " failed (logged once per game): " + e);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Logging must never throw into a hook.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>A one-time message (stand-downs, hints), not an error.</summary>
|
|
|
|
|
public static void MessageOnce(string key, string text)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
lock (logged)
|
|
|
|
|
{
|
|
|
|
|
if (!logged.Add("msg:" + key))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Log.Message("[Blax Laws] " + text);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>A one-time warning, for data the game hands over that Laws can't use (a broken def, a saved name it can't read).</summary>
|
|
|
|
|
public static void WarningOnce(string key, string text)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
lock (logged)
|
|
|
|
|
{
|
|
|
|
|
if (!logged.Add("warn:" + key))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Log.Warning("[Blax Laws] " + text);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ResetOnce()
|
|
|
|
|
{
|
|
|
|
|
lock (logged) logged.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
Blax Laws 1.0.0: tests for every shipped claim, escape and custody fixes
- Tests for the end-to-end subdue and jail, halved pain, the role hold,
every way a sentence ends, pruning, the nobody-to-enforce letter and
performance; each fails when its feature is broken.
- A jailed colonist that escapes closes as Escaped, also when the world
deletes it before the sentence check or a save falls in between. One
sold, given away, kidnapped or lost with a map closes with its own
message instead of "escaped".
- The release fallback also frees a prisoner on a caravan.
- An arrest waits while the offender carries someone, and ends an
offender job that holds reservations, so no reservation errors.
- Release text says a colonist, not a warden: Basic work also releases
prisoners.
- Test harness: test order, fixture hardening, roof cleanup and logging.
2026-12-03 14:46:28 +00:00
|
|
|
/// Switches the test mod flips to force failure paths or to measure the game without Laws. Not game
|
|
|
|
|
/// state: nothing here is saved and the test runner resets every field after each test.
|
Blax Laws 1.0.0: lawbook, act catalogue, enforcement and jail
- Laws tab with the lawbook and the case log; the book starts empty and
the mod watches nothing until a law exists.
- Act catalogue built from the game's defs (breaks, food, drugs, usables,
interactions, recorded acts, records, bills) plus special acts, with
groups, break links and a starter lawbook.
- Enforcement: warn, guilty, subdue, jail for N days and subdue then jail,
one case per incident, danger waits, role holders and mechanitors held
for Arrest now.
- Headless test suite green in every DLC combination, core only and with
the compat mods.
2026-12-02 20:07:17 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public static class LawsTestHooks
|
|
|
|
|
{
|
|
|
|
|
/// <summary>CaseFiler.Report throws, to test that a hook's HookGuard keeps vanilla running.</summary>
|
|
|
|
|
public static bool ReportThrows;
|
|
|
|
|
|
2026-12-03 18:28:31 +00:00
|
|
|
/// <summary>Hook P's gizmo postfix throws inside its guard, to test that the gizmo bar keeps vanilla's gizmos.</summary>
|
|
|
|
|
public static bool CourtGizmoThrows;
|
|
|
|
|
|
|
|
|
|
/// <summary>The court place switch throws while it is built, to test the guard around it in hook P.</summary>
|
|
|
|
|
public static bool CourtSwitchThrows;
|
|
|
|
|
|
Blax Laws 1.0.0: tests for every shipped claim, escape and custody fixes
- Tests for the end-to-end subdue and jail, halved pain, the role hold,
every way a sentence ends, pruning, the nobody-to-enforce letter and
performance; each fails when its feature is broken.
- A jailed colonist that escapes closes as Escaped, also when the world
deletes it before the sentence check or a save falls in between. One
sold, given away, kidnapped or lost with a map closes with its own
message instead of "escaped".
- The release fallback also frees a prisoner on a caravan.
- An arrest waits while the offender carries someone, and ends an
offender job that holds reservations, so no reservation errors.
- Release text says a colonist, not a warden: Basic work also releases
prisoners.
- Test harness: test order, fixture hardening, roof cleanup and logging.
2026-12-03 14:46:28 +00:00
|
|
|
/// <summary>GameComponent_BlaxLaws skips its tick, as if the mod were absent (the performance test's baseline).</summary>
|
|
|
|
|
public static bool TickSuspended;
|
|
|
|
|
|
|
|
|
|
/// <summary>Every Laws patch is removed (RemovePatches) until RestorePatches or Reset.</summary>
|
|
|
|
|
public static bool PatchesRemoved { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>Removes every Harmony patch of Laws, as if the mod were absent. RestorePatches puts them back.</summary>
|
|
|
|
|
public static void RemovePatches()
|
|
|
|
|
{
|
|
|
|
|
if (PatchesRemoved)
|
|
|
|
|
return;
|
|
|
|
|
BlaxLawsStartup.Harmony.UnpatchAll(BlaxLawsStartup.HarmonyId);
|
|
|
|
|
PatchesRemoved = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Applies the patches again after RemovePatches. Returns the patch classes that failed.</summary>
|
|
|
|
|
public static List<string> RestorePatches()
|
|
|
|
|
{
|
|
|
|
|
var failed = new List<string>();
|
|
|
|
|
if (!PatchesRemoved)
|
|
|
|
|
return failed;
|
|
|
|
|
BlaxLawsStartup.PatchAll(failed);
|
|
|
|
|
PatchesRemoved = false;
|
|
|
|
|
return failed;
|
|
|
|
|
}
|
|
|
|
|
|
Blax Laws 1.0.0: lawbook, act catalogue, enforcement and jail
- Laws tab with the lawbook and the case log; the book starts empty and
the mod watches nothing until a law exists.
- Act catalogue built from the game's defs (breaks, food, drugs, usables,
interactions, recorded acts, records, bills) plus special acts, with
groups, break links and a starter lawbook.
- Enforcement: warn, guilty, subdue, jail for N days and subdue then jail,
one case per incident, danger waits, role holders and mechanitors held
for Arrest now.
- Headless test suite green in every DLC combination, core only and with
the compat mods.
2026-12-02 20:07:17 +00:00
|
|
|
public static void Reset()
|
|
|
|
|
{
|
|
|
|
|
ReportThrows = false;
|
2026-12-03 18:28:31 +00:00
|
|
|
CourtGizmoThrows = false;
|
|
|
|
|
CourtSwitchThrows = false;
|
Blax Laws 1.0.0: tests for every shipped claim, escape and custody fixes
- Tests for the end-to-end subdue and jail, halved pain, the role hold,
every way a sentence ends, pruning, the nobody-to-enforce letter and
performance; each fails when its feature is broken.
- A jailed colonist that escapes closes as Escaped, also when the world
deletes it before the sentence check or a save falls in between. One
sold, given away, kidnapped or lost with a map closes with its own
message instead of "escaped".
- The release fallback also frees a prisoner on a caravan.
- An arrest waits while the offender carries someone, and ends an
offender job that holds reservations, so no reservation errors.
- Release text says a colonist, not a warden: Basic work also releases
prisoners.
- Test harness: test order, fixture hardening, roof cleanup and logging.
2026-12-03 14:46:28 +00:00
|
|
|
TickSuspended = false;
|
|
|
|
|
RestorePatches();
|
Blax Laws 1.0.0: lawbook, act catalogue, enforcement and jail
- Laws tab with the lawbook and the case log; the book starts empty and
the mod watches nothing until a law exists.
- Act catalogue built from the game's defs (breaks, food, drugs, usables,
interactions, recorded acts, records, bills) plus special acts, with
groups, break links and a starter lawbook.
- Enforcement: warn, guilty, subdue, jail for N days and subdue then jail,
one case per incident, danger waits, role holders and mechanitors held
for Arrest now.
- Headless test suite green in every DLC combination, core only and with
the compat mods.
2026-12-02 20:07:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|