Skip to content

stats(P).researched and .upgrades read Brood War's own rows - #92

Closed
mstephenhunt wants to merge 1 commit into
scm-js:mainfrom
mstephenhunt:bw-research-tables
Closed

mstephenhunt wants to merge 1 commit into
scm-js:mainfrom
mstephenhunt:bw-research-tables

Conversation

@mstephenhunt

Copy link
Copy Markdown
Contributor

Fixes #91.

Why

I'm building a TrigScript library call that makes Medics cast Restore on their own, and it has to check whether the Medic's owner has researched Restoration. stats(P1).researched[techs.Restoration] read Player 2's Stim Packs instead, and that goes for every Brood War tech and upgrade.

What changes

  • Brood War's rows. The game keeps Brood War's techs (ids 24–43) and upgrades (ids 46–60) in tables of their own: techResearchedBW, 20 bytes a player at 0x58F140, and currentUpgradeLevelBW, 15 bytes a player at 0x58F32C (BWAPI BWGame.h, Game at 0x57F0F0 + 0x10050 / 0x1023C). A key from 24 (techs) or 46 (upgrades) up now lands at key - 24 / key - 46 in that row. The original ids are unchanged.
  • The simulator keys a table cell by its row's base as well, so stats(P1).researched[techs.Restoration] and stats(P1).researched[techs.StimPacks], both 0 bytes into their rows now, stay separate cells.
  • placeOfAddress names an address in the Brood War rows as the stats() field it is, instead of "no table TrigScript knows".

Both new tables are covered by the allowlist's 0x57F0F0 entry. I haven't read or written them in a played Remastered game yet.

Testing

  • npm run typecheck and npm test (1,447 passed).
  • New test in tests/ownGame.test.ts decodes the Set Deaths each write emits: P1 Restoration → 0x58F140, P12 Restoration → 0x58F140 + 220, P3 Caduceus Reactor → 0x58F32C + 35, and P2 Stim Packs / P1 Protoss Ground Armor where they were. It fails on main.
  • New tests/eud-error.test.ts line for a Brood War address; fails on main.
  • New tests/units.test.ts case: Restoration and Stim Packs for the same player are separate cells in the simulator.

The game keeps Brood War's techs (ids 24-43) and upgrades (ids 46-60) in tables of
their own, 20 and 15 a player wide. stats() had one table for each, 24 and 46 wide,
so P1's Restoration was P2's Stim Packs, and P12's ran past the table. A Brood War
key now lands in its row of techResearchedBW (0x58F140) or currentUpgradeLevelBW
(0x58F32C), the places BWAPI's BWGame.h gives.

The simulator keys a cell by its row's base too, so a Brood War id and the original
id at the same place in the row stay apart, and placeOfAddress names the Brood War
rows.

Fixes scm-js#91.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mstephenhunt

Copy link
Copy Markdown
Contributor Author

Closing in favor of #96, which now carries this PR's commits along with the rest of the auto-mining, auto-restore and toggle work, so it can be reviewed and merged as one PR.

@mstephenhunt
mstephenhunt deleted the bw-research-tables branch November 13, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stats(P).researched reads the wrong byte for Brood War techs (and upgrades 46+)

1 participant