Audit fixes batch 1: STS2-update build unblock + four confirmed stat bugs #248

Closed
nelsong6 wants to merge 4 commits from claude/audit-fixes-batch1 into main
nelsong6 commented 2026-07-03 02:27:21 -07:00 (Migrated from github.com)

First batch of fixes from a full-codebase quality audit. Stacks on #246 (killing-blow / Continue-stranding work) — until that merges, the diff shows its commits too. The STS2-update commit (6354d6c) is a P0 build unblock and can be cherry-picked to land independently first.

P0 — Slay the Spire 2 update broke the build (commit 6354d6c)

Steam shipped an STS2 update (game DLL dated 2026-07-02) that removed Hook.AfterTurnEnd. Two block-window cleanup patches referenced it via nameof(...), a compile-time reference, so the mod no longer builds against the live game at all — this blocks every build/deploy, including #246. Discovered when the audit's post-fix build failed with CS0117: 'Hook' does not contain a definition for 'AfterTurnEnd'.

  • Bind the Orichalcum + Cloak Clasp end-of-turn cleanup patches via runtime TargetMethods() lookup instead of compile-time nameof, matching the resilient AccessTools pattern their sibling patches already use. Missing method → patch skipped, not a broken build.
  • Replace bare Harmony.PatchAll() in CoreMain.Initialize with per-class install in try/catch, so one patch whose target a game update reshaped can't abort all patching and silently kill every stat hook.

Core builds against the updated DLL; all 238 tests pass. Not verified: runtime patch binding against the new game (needs an in-game launch). This change ensures graceful degradation if another patch fails to bind; a full compat pass is filed as a tracking issue.

Four confirmed stat-attribution bugs (commit e6c0126)

Each confirmed against decompiled game behaviour by an adversarial verification pass; each localized and independent.

Bug Effect Fix
Poison killing-tick effective damage effective = unblocked - overkill double-subtracted overkill → every poison kill recorded ~0 effective damage (a poison deck's normal finisher) Route through the canonical ComputeEnemyDamageTotals helper (effective = unblocked); include overkill in the tick-size denominator. One convention for all damage sites; pinned by a lethal-overkill test
Osty phantom enemy aggregate Osty (Creature, Monster set, IsPlayer=false) absorbing hits counted as damage-to-player, doubled DamageInstances per DieForYou redirect, and Osty's own attacks minted a bogus MONSTER.OSTY enemy aggregate every Necrobinder run RecordEnemyDamage returns early unless Receiver.IsPlayer (matches sibling method + primer spec)
Block-clear on retain Game fires AfterBlockCleared even when a retain effect (Barricade/Blur/Sturdy Clamp) prevented the clear; unarmed fallback charged the whole ledger as wasted and anonymized the survivors → retain decks showed inflated block-wasted, ~0 block-effective every turn Unarmed fallback → 0; let ReconcilePlayerBlockLedgerLocked waste exactly max(0, tracked-actual)
Save durability Unordered fire-and-forget Task.Run writes with non-atomic File.WriteAllText; a won/lost run's two back-to-back saves raced (outcome save dropped or stale in_progress wins), and a crash mid-write truncated the whole run file Single ordered continuation chain + atomic temp-file + File.Move overwrite; path resolution off the pool thread

Test plan

  • dotnet test Tests/SpireLens.Core.Tests — 238/238 pass against the live updated game DLL.
  • The four stat fixes were additionally validated against the checked-in lib/ reference stub; the only stub failures are 11 pre-existing asset-coupled tooltip-icon tests (identical set with or without these changes).

Remaining audit findings (attribution-window architecture, MP ownership, repair-path asymmetry, full STS2-compat pass, etc.) are being filed as separate tracked issues.

🤖 Generated with Claude Code

First batch of fixes from a full-codebase quality audit. **Stacks on #246** (killing-blow / Continue-stranding work) — until that merges, the diff shows its commits too. The STS2-update commit (6354d6c) is a P0 build unblock and can be cherry-picked to land independently first. ## P0 — Slay the Spire 2 update broke the build (commit 6354d6c) Steam shipped an STS2 update (game DLL dated 2026-07-02) that **removed `Hook.AfterTurnEnd`**. Two block-window cleanup patches referenced it via `nameof(...)`, a compile-time reference, so the mod no longer builds against the live game at all — this blocks every build/deploy, including #246. Discovered when the audit's post-fix build failed with `CS0117: 'Hook' does not contain a definition for 'AfterTurnEnd'`. - Bind the Orichalcum + Cloak Clasp end-of-turn cleanup patches via runtime `TargetMethods()` lookup instead of compile-time `nameof`, matching the resilient `AccessTools` pattern their sibling patches already use. Missing method → patch skipped, not a broken build. - Replace bare `Harmony.PatchAll()` in `CoreMain.Initialize` with per-class install in try/catch, so one patch whose target a game update reshaped can't abort all patching and silently kill every stat hook. Core builds against the updated DLL; all 238 tests pass. **Not verified:** runtime patch *binding* against the new game (needs an in-game launch). This change ensures graceful degradation if another patch fails to bind; a full compat pass is filed as a tracking issue. ## Four confirmed stat-attribution bugs (commit e6c0126) Each confirmed against decompiled game behaviour by an adversarial verification pass; each localized and independent. | Bug | Effect | Fix | |---|---|---| | Poison killing-tick effective damage | `effective = unblocked - overkill` double-subtracted overkill → every poison **kill** recorded ~0 effective damage (a poison deck's normal finisher) | Route through the canonical `ComputeEnemyDamageTotals` helper (effective = unblocked); include overkill in the tick-size denominator. One convention for all damage sites; pinned by a lethal-overkill test | | Osty phantom enemy aggregate | Osty (Creature, Monster set, `IsPlayer=false`) absorbing hits counted as damage-to-player, doubled `DamageInstances` per DieForYou redirect, and Osty's own attacks minted a bogus `MONSTER.OSTY` enemy aggregate every Necrobinder run | `RecordEnemyDamage` returns early unless `Receiver.IsPlayer` (matches sibling method + primer spec) | | Block-clear on retain | Game fires `AfterBlockCleared` even when a retain effect (Barricade/Blur/Sturdy Clamp) *prevented* the clear; unarmed fallback charged the whole ledger as wasted and anonymized the survivors → retain decks showed inflated block-wasted, ~0 block-effective every turn | Unarmed fallback → 0; let `ReconcilePlayerBlockLedgerLocked` waste exactly `max(0, tracked-actual)` | | Save durability | Unordered fire-and-forget `Task.Run` writes with non-atomic `File.WriteAllText`; a won/lost run's two back-to-back saves raced (outcome save dropped or stale `in_progress` wins), and a crash mid-write truncated the whole run file | Single ordered continuation chain + atomic temp-file + `File.Move` overwrite; path resolution off the pool thread | ## Test plan - `dotnet test Tests/SpireLens.Core.Tests` — **238/238 pass** against the live updated game DLL. - The four stat fixes were additionally validated against the checked-in `lib/` reference stub; the only stub failures are 11 pre-existing asset-coupled tooltip-icon tests (identical set with or without these changes). Remaining audit findings (attribution-window architecture, MP ownership, repair-path asymmetry, full STS2-compat pass, etc.) are being filed as separate tracked issues. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
nelsong6 commented 2026-07-03 10:33:37 -07:00 (Migrated from github.com)

Superseded by #267, which consolidates this and the rest of the audit work onto current main (these branches all conflicted after #247 landed). Closing in favor of the single mergeable PR.

Superseded by #267, which consolidates this and the rest of the audit work onto current main (these branches all conflicted after #247 landed). Closing in favor of the single mergeable PR.

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
romaine-life/spirelens!248
No description provided.