[P1] Poison/Noxious Fumes tick-arming window is too wide (participants + dealer invariant) #252

Closed
opened 2026-07-03 02:30:50 -07:00 by nelsong6 · 3 comments
nelsong6 commented 2026-07-03 02:30:50 -07:00 (Migrated from github.com)

Priority: P1. From the 2026-07-02 audit. Confirmed against decompiled game code. (The poison effective-damage math bug is already fixed in PR #248; this is the separate arming-window width bug.)

Problem

The poison-tick attribution window is too wide in both dimensions:

  1. PoisonPowerAfterSideTurnStartPatch and NoxiousFumesAfterSideTurnStartPatch are unconditional prefixes, but decompiled Hook.AfterSideTurnStart invokes every power's AfterSideTurnStart on every side's turn start; the powers' own bodies gate on participants.Contains(Owner) — the prefixes do not. So every player turn start arms a phantom PendingPoisonTicks[enemy] for each poisoned enemy even though no tick will occur.

  2. The disarm guard historyCount >= pendingTick.ArmedAtHistoryCount (RunTracker.cs:~4990) is vacuously true, so an armed tick never expires and, while armed, bypasses both the dealer==null and amount-match fallback guards.

Failure (Necrobinder poison + Osty/Doom — the class's core mechanics): a player-turn-start phantom arm, then Osty attacks a poisoned enemy / a damage potion / DoomPower ticks first → each emits DamageReceivedEntry with CardSource==null → routed to TryRecordPoisonTickDamage → armedTick=true → the unrelated damage is credited to the poison-applying cards and the ownership ledger is corrupted for all later real ticks.

Fix

  • Bind participants in the prefixes (PoisonPowerAfterSideTurnStartPatch.cs:22, NoxiousFumesAfterSideTurnStartPatch.cs:27) — Harmony injects by parameter name — and only arm when participants.Contains(target) (mirrors the powers' own gate).
  • In TryRecordPoisonTickDamage, require entry.Dealer == null unconditionally and only consume the pending entry on dealer==null (real ticks always pass dealer:null), so Osty attacks / potions are excluded even if an armed entry lingers.
  • Replace the vacuous >= guard with a bounded freshness window (e.g. historyCount - ArmedAtHistoryCount <= 4).
  • Align Noxious Fumes recipient count with HittableEnemies.
  • Do not use a plain postfix on AfterSideTurnStart to clear — the method is async and the postfix runs at the first await, before the tick's damage entry.

This window folds naturally into the AttributionWindow registry issue.

**Priority: P1.** From the 2026-07-02 audit. Confirmed against decompiled game code. (The poison *effective-damage* math bug is already fixed in PR #248; this is the separate arming-**window** width bug.) ## Problem The poison-tick attribution window is too wide in both dimensions: 1. `PoisonPowerAfterSideTurnStartPatch` and `NoxiousFumesAfterSideTurnStartPatch` are unconditional prefixes, but decompiled `Hook.AfterSideTurnStart` invokes every power's `AfterSideTurnStart` on **every** side's turn start; the powers' own bodies gate on `participants.Contains(Owner)` — the prefixes do not. So every **player** turn start arms a phantom `PendingPoisonTicks[enemy]` for each poisoned enemy even though no tick will occur. 2. The disarm guard `historyCount >= pendingTick.ArmedAtHistoryCount` (`RunTracker.cs:~4990`) is vacuously true, so an armed tick never expires and, while armed, bypasses both the `dealer==null` and amount-match fallback guards. Failure (Necrobinder poison + Osty/Doom — the class's core mechanics): a player-turn-start phantom arm, then Osty attacks a poisoned enemy / a damage potion / DoomPower ticks first → each emits `DamageReceivedEntry` with `CardSource==null` → routed to `TryRecordPoisonTickDamage` → `armedTick=true` → the unrelated damage is credited to the poison-applying cards and the ownership ledger is corrupted for all later real ticks. ## Fix - Bind participants in the prefixes (`PoisonPowerAfterSideTurnStartPatch.cs:22`, `NoxiousFumesAfterSideTurnStartPatch.cs:27`) — Harmony injects by parameter name — and only arm when `participants.Contains(target)` (mirrors the powers' own gate). - In `TryRecordPoisonTickDamage`, require `entry.Dealer == null` unconditionally and only consume the pending entry on `dealer==null` (real ticks always pass `dealer:null`), so Osty attacks / potions are excluded even if an armed entry lingers. - Replace the vacuous `>=` guard with a bounded freshness window (e.g. `historyCount - ArmedAtHistoryCount <= 4`). - Align Noxious Fumes recipient count with `HittableEnemies`. - Do **not** use a plain postfix on `AfterSideTurnStart` to clear — the method is async and the postfix runs at the first `await`, before the tick's damage entry. This window folds naturally into the AttributionWindow registry issue.
nelsong6 commented 2026-07-03 09:34:23 -07:00 (Migrated from github.com)

Uncapped audit pass — confirmed detail: PoisonPowerAfterSideTurnStartPatch.cs:22-28 and NoxiousFumesAfterSideTurnStartPatch.cs:27 arm unconditionally on every side turn start, but the game gates on participants.Contains(Owner); the disarm guard historyCount >= ArmedAtHistoryCount (RunTracker.cs:4996) is vacuously true. Bind IReadOnlyList<Creature> participants by name into both prefixes, arm only when the resolved target/owner is a participant, and require Dealer==null when armed (#28, #68, both confirmed HIGH). NOTE: the poison effective-damage math half of the original report is already fixed in PR #248.

**Uncapped audit pass — confirmed detail:** `PoisonPowerAfterSideTurnStartPatch.cs:22-28` and `NoxiousFumesAfterSideTurnStartPatch.cs:27` arm unconditionally on every side turn start, but the game gates on `participants.Contains(Owner)`; the disarm guard `historyCount >= ArmedAtHistoryCount` (`RunTracker.cs:4996`) is vacuously true. Bind `IReadOnlyList<Creature> participants` by name into both prefixes, arm only when the resolved target/owner is a participant, and require `Dealer==null` when armed (#28, #68, both confirmed HIGH). NOTE: the poison *effective-damage* math half of the original report is already fixed in PR #248.
nelsong6 commented 2026-07-03 11:16:01 -07:00 (Migrated from github.com)

Implemented in #268: participants bound into the PoisonPower/NoxiousFumes AfterSideTurnStart prefixes, window armed only when the poisoned owner is a participant (mirrors PoisonPower.cs:57 / NoxiousFumesPower.cs:28); TryRecordPoisonTickDamage now requires Dealer==null before consuming and uses a bounded freshness window (<=24 history entries) instead of the vacuous guard. Prefix participants-binding verified live (patch binds, 0 failed). Behavioral tick-attribution still wants a live poison combat to confirm.

Implemented in #268: participants bound into the PoisonPower/NoxiousFumes AfterSideTurnStart prefixes, window armed only when the poisoned owner is a participant (mirrors PoisonPower.cs:57 / NoxiousFumesPower.cs:28); TryRecordPoisonTickDamage now requires Dealer==null before consuming and uses a bounded freshness window (<=24 history entries) instead of the vacuous guard. Prefix participants-binding verified live (patch binds, 0 failed). Behavioral tick-attribution still wants a live poison combat to confirm.
nelsong6 commented 2026-07-05 15:45:11 -07:00 (Migrated from github.com)

Closing during repository issue cleanup. If this becomes active work again, we can reopen or recreate it as a fresh, specific task.

Closing during repository issue cleanup. If this becomes active work again, we can reopen or recreate it as a fresh, specific task.
Sign in to join this conversation.
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#252
No description provided.