@gameslate/sdk 0.3.10 → 0.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ description: Build a GameSlate plugin for a game, from choosing how to read its
7
7
 
8
8
  A plugin teaches GameSlate one or more games. It runs in GameSlate's sandbox (QuickJS: no files, no
9
9
  network, no Node APIs) and gets only what the core hands it: a game's memory (`GameMemory`) for live
10
- state, and the player's own files (`InputFile`s) for assets. Work through the steps in order. Don't
10
+ state (plus `memory.log?.(...)` for session-deduplicated diagnostic lines), and the player's own files (`InputFile`s) for assets. Work through the steps in order. Don't
11
11
  skip verification: a wrong address that looks plausible is worse than no address.
12
12
 
13
13
  ## 1. Pick the state source
@@ -32,11 +32,17 @@ Then `yarn install && yarn check`. `check` runs the typecheck, the tests, the bu
32
32
 
33
33
  - `plugin/manifest.json`: the plugin's id, name, version, `sdkApi`, and `games[]`;
34
34
  - `plugin/live.ts`: the plugin module, with its packs and memory sources. Put the decoder in
35
- `plugin/decode.ts` and the offsets in `plugin/offsets.ts`, both imported by `live.ts`. The
35
+ `plugin/decode.ts` and the offsets in `plugin/offsets.ts`, both imported by `live.ts`. When a
36
+ plugin supports multiple games (like `gameslate-n64`), give each game its own folder
37
+ `plugin/<game-id>/` (`source.ts`, `pack.ts`, `addresses.ts`, `map.ts`, `assets.ts`, etc.) and
38
+ keep only `manifest.json`, `live.ts`, `assets.ts` and shared helpers at `plugin/` root. The
36
39
  bundler follows the imports.
37
40
  - optionally `plugin/assets.ts`: asset extractors (add `assets` to the manifest);
38
- - `test/live.test.ts`: builds the plugin, loads it in the core's own sandbox, reads a fake
41
+ - `plugin/live.test.ts`: builds the plugin, loads it in the core's own sandbox, reads a fake
39
42
  memory, and runs the pack contract check (`checkCatalogue`). Keep it.
43
+ - Tests sit beside the code they test (`plugin/<game-id>/source.ts` → `source.test.ts`), never in
44
+ a separate `test/` folder. The bundle takes only what `live.ts` and `assets.ts` import, so tests
45
+ and test helpers in `plugin/` never ship.
40
46
  - CI, and `.claude/skills/`: this skill and `verify-gameslate-plugin`.
41
47
 
42
48
  Each manifest game has:
@@ -98,7 +104,9 @@ An unknown build means refuse to attach, never "try the nearest offsets".
98
104
  **Open-source ports.** Compile a probe against the game's headers: print `sizeof` of a big struct
99
105
  (it must equal what the shipped build uses) and the `offsetof` of each field. Put each value in
100
106
  `offsets.ts`, with a comment naming the struct field and where the number came from. Header
101
- comments like `/* 0x0E9C */` are not a source.
107
+ comments like `/* 0x0E9C */` are not a source, and never carry N64 decomp offsets onto a 64-bit PC
108
+ port (pointer widening shifts every downstream member: Perfect Dark's `chrdata` grows `0x354 → 0x3d0`
109
+ and `floorroom` moves `0x2b2 → 0x2fe`).
102
110
 
103
111
  **Console decompilations:**
104
112
 
@@ -137,7 +145,13 @@ fails to compile). Constants come back signed.
137
145
  comments or a symbol's `size:` over its count: the run fails if the probe disagrees. And compile
138
146
  the probe in the C standard the game was built with (`-std=gnu89` for IDO and KMC GCC games):
139
147
  Dr. Mario 64's `bool` is a 4-byte enum under C89 but clang's 1-byte `_Bool` under C17, which put
140
- every field after it 6 bytes early while looking perfectly plausible.
148
+ every field after it 6 bytes early while looking perfectly plausible. Check
149
+ the SDK you run has it (0.3.9 or later): 0.3.8 accepts the key and ignores it, which hid a wrong
150
+ size in GoldenEye's spec. IDO accepts members that clang drops without a word:
151
+ `struct coord16;` inside a struct (GoldenEye's `inherits` macro) is an anonymous member to IDO
152
+ and an empty forward declaration to clang, so `sizeof(StandTilePoint)` probed 2, not 8.
153
+ `-fms-extensions` fixes that one and breaks other headers; probe the file-format twin
154
+ (`StandFilePoint`) or take the stride from the compiled code.
141
155
 
142
156
  For another revision add `"subtract": "0xA190"` (and check the delta against verified leads
143
157
  first). Commit the spec and the generated table; the decomp and ROM stay local.
@@ -165,8 +179,18 @@ first). Commit the spec and the generated table; the decomp and ROM stay local.
165
179
  blank save reads as zeros anywhere, so a zero read proves nothing.
166
180
  7. **Sizes and signs come from declarations and probes, never from guesses:** a 14-byte struct
167
181
  isn't 16 (`CourseVtx` has 2-byte alignment); a `u8` read as `getInt8` turns 0xFD into -3.
168
-
169
- **Leads, from LiveSplit or RetroAchievements:**
182
+ 8. **Check each offset in the compiled code as well.** A matching decomp's objects are the
183
+ truth the probe models: `mips-linux-gnu-objdump -dr build/<region>/src/<file>.o` (or
184
+ `llvm-objdump -dr`) on an accessor gives the offset, width and array stride (GoldenEye's
185
+ `getCurrentPlayerWeaponId` is a shift-add chain making ×0x3A8, then `lw v0,2160(t8)`:
186
+ `struct hand` is 0x3A8 bytes and `weaponnum` sits at 0x870; `DestroyObjectRecord.ObjRefID` sits
187
+ in a pointer union so `lhu 0x4` reads the upper zero halfword on big-endian MIPS whereas
188
+ `objective_status.o` executes `lw $4, 0x4($18)` + mask). Likewise, check helper macros before
189
+ reading binary asset streams: GoldenEye's `ntohs`/`ntohl` (`CharArrayTo16`/`CharArrayTo32`) read
190
+ unaligned big-endian bytes even though generated `.c` assets write reversed hex literals via
191
+ `CharArrayFrom*Rev`.
192
+
193
+ **Leads, from LiveSplit, RetroAchievements or GameShark lists:**
170
194
 
171
195
  - A lead is not a source. Verify every value live, across levels, menus and loads.
172
196
  - Record where it came from, and **never copy their code**: addresses are facts, scripts aren't.
@@ -174,9 +198,49 @@ first). Commit the spec and the generated table; the decomp and ROM stay local.
174
198
  console's big-endian address: byte = address ^ 3, 16-bit = address ^ 2, 32-bit as is.
175
199
  - RA notes are per game, not per revision. Struct offsets carry across revisions; absolute
176
200
  addresses don't.
201
+ - **N64 GameShark / Action Replay codes** (`80AAAAAA 00VV`, `81AAAAAA VVVV`) are big-endian guest
202
+ addresses as written. `gameslate drive codes <snapshot dir> <cheats.txt>` reads every value a
203
+ list names across a TAS series. Lists are per revision, and a code writes the smallest width
204
+ that works (Banjo-Kazooie's health code is the low byte of an s32): find the field's start.
205
+ Project64's `Config/Cheats/*.cht` files are per revision; `drive codes` reads them with
206
+ `--rom <rom>` and refuses a list whose header CRC isn't that ROM's.
177
207
  - A byte-pattern lead stays a pattern: read it with `memory.scan({ pattern, kind, offset })`, so it
178
208
  survives patches. It must match exactly once.
179
209
 
210
+ **Finding an address the decomp doesn't name:** replay a TAS to snapshots (`drive tas
211
+ --emulator bizhawk --watch …`), then `gameslate drive find <snapshot dir> --at <frames>
212
+ --values 10,19,30 --decomp <decomp>` ranks the aligned 1/2/4-byte values holding exactly what the
213
+ screen showed (or `--changes changed,same`: moved, then held) and lists the functions that load
214
+ or store each (docs/emulator-driving.md, "Finding an address from snapshots"). Three distinct
215
+ values pin a count; a 0/1 flag needs the whole series. A hit is a lead: read those functions and
216
+ confirm the width and sign there, as with any lead.
217
+
218
+ **A game with no decomp (Castlevania: Legacy of Darkness is the worked example):** the leads and
219
+ the screen are all the evidence there is, so `addresses.ts` is hand-written with each address's
220
+ frames and what the screen showed.
221
+ - **Name stage ids from their title cards.** `--watch` on the map id snapshots the dark
222
+ transition. Replay again to 240 frames after each change, where the stage's name card shows,
223
+ and tile the screenshots (`ffmpeg -i %03d.png -vf tile=4x4`) to read them at once.
224
+ - **Name only the ids the run visited.** Leave the rest as `area-0x..`, not the list's guess.
225
+ - **A value seen in one stretch is not a phase flag.** A byte constant on the title and in play
226
+ can be a counter: LoD's 0x801CAA87 read 0 on the title and 6 in all 90 play snapshots, but a
227
+ `--watch` on it showed 0, 2, 6 in the first 2400 frames. Watch a candidate through its change
228
+ before using it, and leave the phase undetected (a Known Gap) when no candidate holds.
229
+ - **`screen.png` can be blank** when the screen isn't drawn from RDRAM. Judge by BizHawk's own
230
+ `bizhawk.png` and say so in the README.
231
+ - `--watch` also snapshots the movie's end, so a watched run plays the whole movie. Snapshot
232
+ folders are zero-padded (`024000/`).
233
+
234
+ **Naming a struct the decomp leaves `unkNN`:** when the address is known but the fields aren't
235
+ (Mario Party 3's `GwStory`), print the struct's bytes at every snapshot of a TAS that plays that
236
+ mode through, and keep only the frames where they change. A counter climbs once per stage, an
237
+ array fills slot by slot, and the final screen fixes what the values mean (seven 4s and six 3s
238
+ against seven S and six A). Name only the values a screen showed; count the rest together
239
+ ("below A") until a run shows them. Then:
240
+ - **Count only the slots the progress index has reached.** The struct keeps the last game's bytes
241
+ until a new one overwrites them.
242
+ - **Gate on the mode bit the game uses.** For example, `playMode & 4` for Story play.
243
+
180
244
  **Reading:** read whole blocks (the save struct in one read) where the values sit together.
181
245
  Sample with `seqlockSample(readFrameCounter, readPayload)` (from `@gameslate/sdk/plugin`) so a
182
246
  frame isn't half old and half new: it rereads until the game's frame counter is the same before
@@ -186,6 +250,10 @@ per poll. Numbers are explicit about width, sign and byte order (`readUInt16BE`
186
250
 
187
251
  ## 5. Assets (optional): maps, icons, meshes from the player's files
188
252
 
253
+ **No space to map?** A single-screen puzzle (Dr. Mario's bottle, Puzzle League's stack) gets no
254
+ map: set `panels: { map: false }` on the pack (sdk 0.3.12) and the app leaves the map panel out.
255
+ Anything with a place to move through, a track or a board still gets one.
256
+
189
257
  `assets.ts` exports an extractor per game:
190
258
 
191
259
  - `listAssets(inputs, pick)` must be cheap: name what can be built.
@@ -237,6 +305,70 @@ Every image of a game uses one format. In the sandbox:
237
305
  the gameslate repo's `yarn vite-node tools/registry-add-game.ts <spec.json>`, which writes the
238
306
  manifest, keeps any hints, sets the index entry and rehashes channels with the registry
239
307
  builders' own writers (gameslate-n64's `tools/registry-specs.ts` writes its specs).
308
+ 8. **No mesh traced? Map what the game itself navigates by.** Wave Race 64's course meshes sit in
309
+ unsplit MIO0 blobs, but its buoy and AI node lists are plain 8-byte records (x, z, type,
310
+ angle) in a raw course file, one list per difficulty: they give the course's shape, the start
311
+ line and every buoy. Port the game's own classification of each record (jump tables, the
312
+ flags its draw loop tests) rather than guessing from what the dots look like, and when the
313
+ layout changes with a setting (difficulty), pin per setting with `hiddenWhen`. Lines from
314
+ waypoint to waypoint can cut across land: draw the dense lane nodes, not the sparse "next
315
+ buoy" chain.
316
+ 9. **Tables in a code segment's `.data`** are read from the ROM at `vram − segment vram + segment
317
+ ROM start`. Those two are linker-script symbols the `.map` reader skips: take them from the
318
+ map's `.<segment> 0x<vram> … load address 0x<rom>` line, say so in the source, and check a
319
+ value you know (a pointer the code loads) so a wrong mapping fails loud.
320
+ 10. **Positions an unnamed decomp hides:** look for code comparing a struct's floats with world
321
+ things (a water or floor height lookup taking `(unk44, unk4C)`, a look-ahead adding `512 ×
322
+ unk6C`): that names position and facing. Confirm the struct's stride in the compiled code.
323
+ 11. **Spline courses (F-Zero X):** when a course is control points joined by a curve, port the
324
+ curve exactly (F-Zero X's per-point tension from `func_8009DB28`, the cardinal weights of
325
+ `Course_SplineGetPosition`) and draw the ribbon from it: centre ± the basis' side vector
326
+ (up × forward, the up vector banked about the tangent as `Matrix_SetAxisRotation` does) times
327
+ each side's radius, interpolated by length along the segment. Then **follow the course from
328
+ ROM to race**, not just the load: F-Zero X recentres the points on their x/z extent
329
+ (`func_80074634`) and restarts the loop after the start line piece (`Course_SegmentsInit`), so
330
+ the ROM's coordinates sat 300-450 units off every machine. Check against the game's own spline
331
+ point for a machine (`segmentPositionInfo.segmentPos`) read live, not just its position: that
332
+ tells "my curve is wrong" from "my track is in the wrong place". Sample all racers, not only
333
+ player 1: 30 machines across the grid catch a sideways offset one machine can hide.
334
+ 12. **Object-placement maps (Star Fox 64):** when a level is a list of placed objects, not a mesh,
335
+ draw the list where the game's *loader* puts each one, per loader: SF64's on-rails
336
+ `Object_Load` sets z = −zPos1 − 3000 + zPos2, while its all-range loaders use +zPos1
337
+ (Fortuna, Corneria) or −zPos1 (Bolse, Sector Z, Venom). Pick the player coordinate in the
338
+ same frame: on rails SF64's `pos.z` runs along the path and `trueZpos` is the Arwing's place
339
+ among the objects (collisions compare them directly). A decomp built for another revision can
340
+ still give asset offsets: parse every list at them in the player's ROM and refuse one that
341
+ isn't a sorted, terminated list. Levels that switch modes (on rails → all-range boss, warp
342
+ zones) get one layer per mode, chosen by a `roomId` the reader sets from the mode variable;
343
+ size an arena to include how far past its edge the player can fly before turning back.
344
+ **Every `roomId` the reader can emit needs a layer; test it.** List each mode the game can
345
+ put each level in (grep every write to the mode variable in the decomp, not only the obvious
346
+ one: SF64's Andross goes all-range in two places), drive the reader through them all and
347
+ assert each `roomId` is in some layer's `rooms`. A missing layer fails silently: the SDK falls
348
+ back to another layer and the arrow lands in the wrong place. Check each loader for extra
349
+ terms too (Andross's alone adds zPos2).
350
+ **Sides from the game's own checks:** allies and enemies can share an object id and AI type
351
+ (Katina's Cornerian fighters differ from its enemies only by `animFrame`). Find the field the
352
+ game's ally logic reads, and scope it to the levels where that logic runs.
353
+ 13. **Stale pointers at a level change:** a player pointer and mode variables can still hold the
354
+ last level's values for a few frames. Gate position on the game's own "level running" state
355
+ (SF64's `gPlayState == PLAY_UPDATE`), not on plausible-looking values, and drop cutscene states
356
+ that fly the player off the map (level complete, warp entry). TAS snapshots taken at stage
357
+ starts show exactly these frames; ask `drive tas` for mid-level frames too.
358
+ 14. **Walkable-floor data makes the map, and its rooms pick the floor (GoldenEye).** When a game
359
+ keeps a "where can I stand" list (GoldenEye's stan tiles: polygons, each filed under a room),
360
+ draw that, not the render geometry, and let the room choose the layer: read the room of the
361
+ tile under the player (`prop->stan->room`) and under each guard, put every room on exactly one
362
+ floor (rooms that lie over each other more than a storey apart go on different floors; test
363
+ that no room is on two), and list them in `rooms`. Heights then never have to separate floors.
364
+ Divide by the game's own unit scale (`levelscale`) where it does. Shade height by rank, not by
365
+ range: one far-off drop (Dam's foot of the wall, 270 m down) flattens a linear scale.
366
+ 15. **Compressed files need the game's decompressor in the sandbox.** There is no zlib there:
367
+ GoldenEye's files are 0x1172 + raw DEFLATE, so `plugin/inflate.ts` is a small DEFLATE port
368
+ tested against node's zlib (stored, fixed, dynamic). The tables naming the files can sit in a
369
+ compressed data segment too (GoldenEye's `.cdata`): unpack it once per run and read the
370
+ tables at `vaddr − segment vaddr`, checking what you read (the empty first entry, each
371
+ entry's index) so a wrong mapping fails loud. A run over all 20 stages took 5 s in the sandbox.
240
372
 
241
373
  ## 6. Tests
242
374
 
@@ -259,12 +391,35 @@ Every image of a game uses one format. In the sandbox:
259
391
  `review-correctness` lens, or a fresh agent given the code and the decomp's paths, not your
260
392
  conclusions). On Mario Kart 64 it found three real bugs the renders didn't show.
261
393
 
262
- ## 7. Verify live
394
+ ## 7. Verify live and document support
263
395
 
264
396
  Use the `verify-gameslate-plugin` skill. It drives the game to a known moment, reads what your
265
397
  plugin reports, screenshots the game and GameSlate, and checks them against `verify.json`. Until a build
266
398
  passes, say so in the README ("unverified: offsets from leads") and keep it out of a release.
267
399
 
400
+ Every game ships a `<game>/README.md` (`plugin/<game-id>/README.md` in a multi-game plugin, or
401
+ `src/README.md` / `plugin/README.md` in a single-game plugin) whose YAML frontmatter conforms to
402
+ `@gameslate/sdk`'s `GameSupportSchema` (pinned `builds` + verification tier; `map` status,
403
+ `assetSource`, `geometry`, `layers`, `controls`, live `player`/`actors`, `pins`; and `panels` for
404
+ vitals, inventory, missions, reference, timelines, and AI) followed by the five required headings
405
+ in order:
406
+
407
+ 1. `## Builds & Asset Extraction`
408
+ 2. `## Map`
409
+ 3. `## Vitals, Inventory, Missions & Reference`
410
+ 4. `## Known Gaps`
411
+ 5. `## Verification`
412
+
413
+ Keep `<!-- gameslate:support-table:start -->` … `<!-- gameslate:support-table:end -->` in the
414
+ repo's top-level `README.md` and run:
415
+
416
+ ```sh
417
+ gameslate-plugin support plugin --built dist/<id> --write
418
+ ```
419
+
420
+ It cross-checks every per-game `README.md` against the built `GamePack`, `supportedBuildIds`,
421
+ `capabilities`, and `assets.ts` extractors, and splices the updated summary table into `README.md`.
422
+
268
423
  ## 8. Release
269
424
 
270
425
  ```sh
@@ -281,10 +436,87 @@ plugin exactly as the core will before running it. Then bump `version`, tag `vX.
281
436
  game could repeat, add it here (in `@gameslate/sdk`'s `template/claude/skills`, then copy it into
282
437
  the plugin repos) in the same change as the fix. The next game should not have to find it again.
283
438
 
439
+ - **Write a different value at each address in a poll test.** Bomberman Hero's poll test wrote 3
440
+ to both bombs and fire, so a swap of the two in `readRaw` still passed. Take a snapshot where
441
+ the fields differ (frame 15000 had bombs 4 and fire 3 on the HUD).
442
+ - **Bound what makes cleared memory impossible.** With no title byte found, Bomberman Hero's
443
+ all-zero RAM read as play with health 0 of 0, and the "one hit left" chip fired. The bar starts
444
+ at 4 segments and only grows, so a bar under 4 now throws; and a chip for "one left" says
445
+ `gte: 1, lte: 1`, since 0 is not one left.
446
+ - **Check each RE address note against a snapshot before using it.** DOOM64-RE's notes were right
447
+ for `gamemap` and `players[]`, but its `totalkills`/`totalitems`/`totalsecret` addresses read 0
448
+ all through MAP01, a level full of monsters. One note being right says nothing about the next.
449
+ - **Don't take a threshold from a game message without reading its condition.** Doom 64's
450
+ "medikit that you REALLY need" tests health after the medikit is added, so it never shows; a
451
+ chip citing it as "the game's own 25" cited a bug. A health chip also wants `gte: 1`: a dead
452
+ player still lies in the level.
453
+ - **Declare `'map_2d'` on `source.capabilities`, not only in the registry manifest.** Five N64
454
+ games shipped map extractors and `map_2d` in `gameslate-registry` while omitting `'map_2d'` from
455
+ `source.capabilities` in `source.ts`. `gameslate-plugin support` cross-checks `map.status`
456
+ against `source.capabilities` so the two cannot drift.
457
+ - **A table the decomp hasn't split is still in the ROM.** Quest 64's `gBossData` (8 bosses,
458
+ 0x18 bytes each) lives in an unsplit data blob. Scanning the ROM for the struct's shape found
459
+ it at 0xD873A0: plausible map ids, zero padding, RAM pointers, and a `bossNumber` that is a
460
+ permutation of 0..7. Pin what you take from it with a ROM-gated test (`Q64_ROM`), so the table
461
+ is checked against the player's dump, not committed as an unchecked copy.
462
+ - **Map from the collision data, not the display meshes.** Wave Race 64's land sat in compressed
463
+ display lists with untraced matrices, but its collision walls and ground triangles were already
464
+ uncompressed, in world units, inside the course file the buoys came from. Find the function that
465
+ answers "what floor is under this point" or "push this point out of a wall", and read what it
466
+ reads. Rebuild a triangle stored as planes (normal, edge planes, distance) by meeting the planes,
467
+ and check each one against the game's own inside test.
468
+ - **No symbol file? Build the decomp for its linker map, without root.** Super Mario 64's decomp
469
+ ships no symbol list, and this machine had no MIPS binutils, no docker and no sudo.
470
+ `apt-get download binutils-mips-linux-gnu` then `dpkg -x <deb> <dir>` unpacks a working
471
+ `mips-linux-gnu-*` into your home (run it with `LD_LIBRARY_PATH=<dir>/usr/lib/x86_64-linux-gnu`
472
+ and the `bin` dir on `PATH`); `make VERSION=us COMPARE=1` then built the matching ROM and
473
+ `build/us/sm64.us.map`, which `addresses` reads as an ld map (statics such as `sCurrPlayMode`
474
+ included). A decomp that refuses non-IDO compilers (`#error Matching build is only possible on
475
+ IDO`) needs the probe's clang args to define what the guard asks for (`NON_MATCHING`,
476
+ `AVOID_UB`): check the guarded headers change only macros, and let `expectSizes` and the
477
+ decomp's own `/*0xA8*/` offset comments confirm the layout.
478
+ Some decomps also need a MIPS gcc (Diddy Kong Racing's `make setup` builds binutils from source
479
+ unless both `<prefix>-ld` and `<prefix>-gcc` exist): unpack `gcc-13-mips-linux-gnu`,
480
+ `cpp-13-mips-linux-gnu` and `gcc-13-mips-linux-gnu-base` the same way and link
481
+ `mips-linux-gnu-gcc` to `-gcc-13`. A tool that wants a missing `-dev` header (`pcre2.h`) takes
482
+ the unpacked dev package through `CPATH` and `LIBRARY_PATH`.
483
+ - **IDO statics and structs declared in `.c` files.** IDO keeps `static` variables out of the ld
484
+ map and the object's symbol table, and clang can't `offsetof` a struct the headers don't
485
+ declare. Both come from the build's objects: `objdump -dr` on the accessor shows the static as
486
+ `.bss` + offset (Banjo-Kazooie's `playerPosition_get`: `lui/addiu a1, .bss+0`), which goes in
487
+ the address spec's `statics` with that accessor as its `evidence`; and a field's offset and
488
+ width are the load the accessor does (`getGameMode`: `lw v0, 4(sGameState)`). Cite each in the
489
+ source.
490
+ - **Take level and map ids from the decomp's enums, not the ROM's tables.** Diddy Kong Racing's
491
+ `include/asset_enums.h` names all 65 level headers (`ASSET_LEVEL_*`), and `addresses` copies
492
+ them as constants: the place table is then source code, with nothing game-derived committed.
493
+ - **Dump the real "empty" record before you write the empty check.** A review asked for Wave Race
494
+ 64's "no ground" to be "all eight header words zero"; Port Blue's header has zero extents but
495
+ still names an 8 x 6 grid, so that check would have thrown on a real course. Match the empty
496
+ case to what the game's own empty data holds, and test it on the ROM.
497
+ - **Two cheat lists that disagree are not evidence.** Quest 64's element bytes are Fire, Earth,
498
+ Water, Wind in one Action Replay list, and Fire, Water, Wind, Earth in another site's table.
499
+ Leave the values unnamed and say what run would settle it. Count claims from the log, too:
500
+ a README said a TAS "saw all seven" Kirby bases, but its watch log held six.
501
+ - **A second build with the same fields at a fixed shift gets its own source.** The sandbox picks
502
+ the source whose `supportedBuildIds` has the build, so make the source a function of the
503
+ delta (Star Fox 64: US 1.1 = US 1.0 + 0xA190), and add a test pinning each lead plus the delta
504
+ to the decomp's own symbol. Give the extractor each build's ROM table offset, not one
505
+ hard-coded.
284
506
  - **"Racing" is more than one state.** Wave Race 64 runs the race in its race state, then in five
285
507
  more after the finish line, a retire or a quit, until the results (0x29-0x2D): reading only the
286
508
  named race state dropped the final place as it was decided. Find the function that dispatches
287
509
  on the game state and list every state it runs as the race.
510
+ A stage's phase can live in another variable than its mode: GoldenEye keeps `current_menu` at
511
+ RUN_STAGE for the whole stage, and `g_CameraMode` says what the player sees (intro, fade,
512
+ swirl, first person, the AI's cuts and exit cinemas, two death cameras that alternate, a
513
+ one-frame return to Bond). Map every value the stage runs under, and keep the mission as the
514
+ location through the debrief that follows it.
515
+ - **The probe can need what IDO forgives.** GoldenEye's headers declare `extern` arrays of
516
+ incomplete struct types and a prototype with an undeclared type: IDO builds them, clang
517
+ refuses. Use the decomp's own switch that skips the header (`-DAIPARSE` skips
518
+ `chrobjdata.h`) or `-D` the missing type, only when it touches no layout you read, say so in
519
+ the source, and confirm the offsets in the compiled code (§ 4, step 8).
288
520
  - **Player arrays hold more than players.** Mario Kart 64's time-trial ghosts are human-flagged
289
521
  karts with one extra bit (`PLAYER_INVISIBLE_OR_BOMB`), and a replay puts a ghost in slot 0.
290
522
  Read every function that spawns into the array before deciding which slots are rivals, ghosts
@@ -302,6 +534,26 @@ the plugin repos) in the same change as the fix. The next game should not have t
302
534
  emulator's command line, and the game must have booted. CIC-6103 and 6106 games (Paper Mario,
303
535
  Banjo-Kazooie) load below their header's entry point; the core works that out from the boot
304
536
  code's CRC.
537
+ RetroArch's `SCREENSHOT` under WSLg can save a black frame while the game runs (Donkey Kong 64,
538
+ even with the pause menu up): judge the screen by RAM (the frame counter, the map, the
539
+ actor), not by the capture. To see the screen, use the software renderer and draw the
540
+ framebuffer from a save state (Pokémon Puzzle League, 2026-12-03). In the `--appendconfig`
541
+ file:
542
+ - `core_options_path` names a file with `mupen64plus-rdp-plugin = "angrylion"`.
543
+ - `global_core_options = "true"` and `game_specific_options = "false"` are set. Without them,
544
+ the per-core `Mupen64Plus-Next.opt` wins and the option is ignored.
545
+ - `savestate_file_compression = "false"` is set.
546
+
547
+ Then send `SAVE_STATE` over the network port. The state lands in a `Mupen64Plus-Next/` folder
548
+ under `savestate_directory`. Draw it with `rdramFromState` (`packages/daemon/src/drive/retroarch-state.ts`)
549
+ and `readScreen`. GLideN64 doesn't write the framebuffer to RDRAM, so this needs angrylion.
550
+ Kill RetroArch by pid: `pkill -f <rom>` also matches the shell running it.
551
+ - **A HUD slot can change meaning.** Before calling a read wrong because the HUD disagrees, read
552
+ the draw code. Puzzle League draws the stop timer where the speed level goes while "STOP"
553
+ shows (`text.c`), so a HUD "01" against a `currLevel` of 2 was right.
554
+ - **A menu's type can name the mode through play.** Puzzle League's `geTypeMenu` keeps the
555
+ mode's own range of `enum_TypeMenu` while the round runs. Map ranges, not single values, and
556
+ play each mode you can to confirm it.
305
557
  - **A symbol may be a pointer, not the struct.** The gap to the next symbol in the map is its
306
558
  size: Super Smash Bros.' `gSCManagerBattleState` is 4 bytes, a pointer that the opening movies
307
559
  aim at their own staged fights. Read through it, and check the pointer lands in RAM.
@@ -311,7 +563,65 @@ the plugin repos) in the same change as the fix. The next game should not have t
311
563
  pointer aims at) when one variable isn't enough.
312
564
  - **Attract demos** run the real game loop with the demo's own data (Paper Mario's demo story,
313
565
  Dr. Mario's demo bottles, Smash's auto-demo and openings): find the flag or scene that marks
314
- them before trusting any value, and make them read as the title.
566
+ them before trusting any value, and make them read as the title. Credits that fly through real
567
+ levels are the same trap (Super Mario 64: `gCurrDemoInput` marks the demos, which play real
568
+ courses on file 1; `gCurrCreditsEntry` marks the credits flythrough). Grep the decomp for the
569
+ checks the game itself makes before it saves or counts (`save_file.c` skips both).
570
+ Donkey Kong 64's demo runs under `GAME_MODE_PLAY` on real maps with a real kong actor; only
571
+ `gMenuCurrentMode == MENU_MODE_DEMO` marks it, and the live run caught it reading `in_stage`.
572
+ When the enum lives in a `.c` file the header probe can't reach, name the value in the source
573
+ with that citation.
574
+ - **A map loads over several frames: find the game's "hold the screen" test.** Donkey Kong 64 sets
575
+ the new map, then spends 30 or more frames loading behind a black screen with the player at a
576
+ placeholder (700, 0, 70) and the game mode already back to play. Only the main loop's own test,
577
+ `gScreenRenderFlags & 1` with `gScreenFadeProgress == 31.0f`, marks them. A TAS replay caught
578
+ it: snapshots a few frames after each map change read `in_stage` over a black screen. Read the
579
+ main loop for the condition under which it skips drawing, and send those frames to `loading`.
580
+ - **Read the game's own lookup tables live, don't copy them.** A per-map table in `.data` (Donkey
581
+ Kong 64's map → world `gMapHubWorldIndex`, 221 bytes) is in RAM from boot: read the one byte
582
+ for the current map each poll instead of committing a copy (it is game data, and a copy can
583
+ drift). Bound the index first, and refuse a value past the table's range.
584
+ - **"No player" is not always "a menu".** Super Mario 64's cake ending spawns no Mario, so a
585
+ phase that tested "Mario exists" first sent the ending to the title screen; the unit test fed
586
+ the ending with Mario present, a state the game never makes. Read the level script of every
587
+ screen you name, and test each row with the values the game really holds there.
588
+ - **A mode without a file can still fill the save.** Diddy Kong Racing's Tracks mode merges every
589
+ save into the settings the adventure reads (`menu.c`), so tracks unlocked anywhere looked like
590
+ this file's progress. Find each mode that plays without a file and leave the save out there.
591
+ - **Some "menus" are films.** Diddy Kong Racing runs the new adventure's opening and the credits
592
+ as menus (`MENU_NEWGAME_CINEMATIC`, `MENU_CREDITS`) under the same game mode as file select;
593
+ the live run caught the opening reading `menu`. Read the menu id too, and send films to
594
+ `cutscene`.
595
+ - **A zero is a value too: check what BSS reads as before boot sets it.** Diddy Kong Racing's
596
+ `gGameMode` is 0 (`GAMEMODE_INGAME`) and `gMapId` 0 (Central Area) from the settings'
597
+ allocation until `thread3_main` sets the intro, so a "settings allocated" guard alone reported
598
+ the player in the hub during boot. For each mode or map variable, find where it is first set
599
+ and what its zero means. When the variable has no "not yet" value, gate on a neighbour that
600
+ does: Mario Party's current overlay is BSS (0 is Memory Match), but `omovlhisidx` is `.data`
601
+ initialised to -1 until boot's first `omOvlCallEx`, so a negative index is "no state".
602
+ - **Show the number the HUD shows, by its draw call.** A stored count and the HUD's can differ:
603
+ Conker's US HUD draws the lives less the one in use, and draws a cash score of 0x7D00 as
604
+ 1000000 (`hud_drawMain`). Find where the HUD draws each counter and apply the same transform,
605
+ citing it, so the phone agrees with the TV.
606
+ - **Probe with the build's version define.** A decomp that builds several versions from one tree
607
+ changes struct layouts under `#if VERSION` (Conker's US `Actor` gained `ceilingY`: 0x32C, not
608
+ the debug build's 0x328). Pass the Makefile's `-DVERSION=…` to the probe and pin the size in
609
+ `expectSizes` against the header's own comment.
610
+ - **A global the decomp doesn't name: read its setter from the ROM.** When the value you need is
611
+ only stored inside a function still in asm (Mario Party's current overlay, in `omOvlGotoEx`),
612
+ disassemble that function straight from the ROM: its ROM offset is `vram - segment vram +
613
+ segment start` from the splat yaml, and `mips-linux-gnu-objdump -D -b binary -m mips -EB
614
+ --adjust-vma=<vram>` on a `dd` slice shows the `lui/sw` pair. Keep the address as a named
615
+ constant whose comment quotes those instructions, and check every path that changes the value
616
+ (a call, a return, a plain goto) goes through that store.
617
+ - **A count is often set before its list is filled.** Diddy Kong Racing's `spawn_racers` sets
618
+ `gNumRacers` and only then fills `gRacersByPort` (an unzeroed pool), so a poll mid-load sees
619
+ NULL or stale slots. Read such lists only in the state that owns them (a loaded level), treat a
620
+ NULL slot as not ready, and keep throwing on a non-NULL pointer outside RAM.
621
+ - **Before a file is chosen, the save index is stale.** Super Mario 64's `gCurrSaveFileNum` starts
622
+ at 1 and keeps the last file after Save & Quit, so file select showed file 1's stars as fact.
623
+ Leave save-derived flags and counters out until a file is entered (an absent flag reads as
624
+ untracked), and keep them where a file is known (in play, the ending).
315
625
  - **The game mode can be a function pointer:** when the decomp keeps the current mode in a
316
626
  file-static the symbol maps don't list, read the mode table instead (Paper Mario:
317
627
  `gMainGameMode[0].step` equals a `state_step_*` symbol).
@@ -322,8 +632,19 @@ the plugin repos) in the same change as the fix. The next game should not have t
322
632
  directly, and let a route's `expect` check what the daemon actually sends.
323
633
  - **Unnamed values and globals:** a decomp with few names (Kirby 64) still gives addresses: a
324
634
  splat `D_<address>` is its address. Cite the function that reads it, and confirm each live.
635
+ - **Check the decomp names the game before writing anything** (`gameslate-plugin names <map>`
636
+ counts the game's own names against `func_`/`D_` placeholders and lists its `g…` globals). List the map's names that aren't
637
+ `func_`/`D_`/libultra, and look for an unsplit `bin` segment in the splat yaml. Yoshi's Story's
638
+ matching decomp names only boot, threads, fault, EEPROM, DMA and pad code, and everything past
639
+ ROM 0xB58B0 is one `unkbin` blob: no game state, level or player at all, so there was nothing
640
+ to read without guessing. Stop there and say so; matching isn't the same as named.
325
641
  - **Menus may read only the d-pad.** Gopher64's d-pad is `w` `a` `s` `d` and its arrows are the
326
642
  stick (`~/.config/gopher64/config.json`); Kirby 64's menus ignore the stick.
643
+ - **Steer by the highlight, not the selection.** A menu's "selected" variable is often set only
644
+ when the choice is confirmed (GoldenEye's `selected_difficulty`), while the stick moves a cursor
645
+ and a separate "highlighted" one (`mission_difficulty_highlighted`). A route pushes the stick
646
+ until the highlight reads the choice, on the menu that shows it (`current_menu` 8 there, not
647
+ the briefing after it), then confirms and checks the selection.
327
648
  - **Menus remember:** many games save the last menu choices, so a route that only presses Start
328
649
  lands somewhere else next time. Pin each choice with the game's own menu variables.
329
650
  - **Prove it on real data before writing to a player's files.** Back up what's there before the
@@ -46,9 +46,15 @@ The steps:
46
46
  `network_remote_enable_user_p1 = "true"` and `pause_nonactive = "false"`, and write the
47
47
  route's `press` steps as `pad:` keys. With mupen64plus-next, RetroPad **B is the N64's A**
48
48
  (confirms menus in Mario Kart 64 and F-Zero X, accelerates in F-Zero X) and RetroPad A is the
49
- N64's B.
50
- 5. **Wait on state, not time:** after each input, read until the game state you expect appears
51
- (for example "game state = racing"), with a timeout.
49
+ N64's B. gameslate-n64's `verify/mk64-gp-start-retroarch.json` (with
50
+ `verify/retroarch-pad.cfg`) is the worked example: it passed `gameslate-plugin verify` from
51
+ boot to a Grand Prix race with nobody at the machine.
52
+ The network RetroPad takes the **analog sticks** too: `pad:LSTICK:<x>,<y>` (and `RSTICK`,
53
+ the C buttons under mupen64plus-next), each -1..1 with +x right and +y down, held for the
54
+ hold time and then recentred. It moved Mario Kart 64's menu cursor live. Menus with an
55
+ analog cursor (GoldenEye's folders, missions and difficulties) can now be steered; a route
56
+ written before this, like `verify/ge-dam-start-retroarch.json`, may still pin whatever the
57
+ cursor rested on.
52
58
 
53
59
  Script the route per game as inputs plus checks, such as "Start until game state 4, hold A for
54
60
  9 s, expect place and lap". Prefer moments a route reaches from boot.
@@ -58,11 +64,63 @@ Script the route per game as inputs plus checks, such as "Start until game state
58
64
  (`.eep`/`.sra`) work across emulators. A save state is the last resort: tied to one emulator
59
65
  version, and it needs a person to make it. Keep saves and states out of the repo: they're game
60
66
  data.
67
+ - **Replaying a TAS (N64, BizHawk `.bk2`)**: `gameslate drive tas <movie.bk2> <rom> <frame>,…
68
+ --retroarch <AppImage> --core <…_libretro.so>` replays it in RetroArch, unattended, and
69
+ leaves a snapshot per frame in `~/.cache/gameslate/snapshots/` (state, EEPROM, `rdram.bin`,
70
+ `screen.png`); later runs start from the nearest one. Diff `rdram.bin` before and after an
71
+ event the screen shows (a fruit eaten, a hit) for candidate addresses, then confirm each in the
72
+ decomp. Before trusting a frame, prove the replay is in sync: check moments the run must hit
73
+ (a menu choice, a random roll it stops on, a count) in memory and on the screen, and compare
74
+ the game's own frame counter between cores. Limits: it stops before the movie's first reset;
75
+ `mupen64plus_next` (resumable, screens via angrylion) clamps sticks past ±119, which the game
76
+ can tell; `parallel_n64` sends −128..127 exactly (`--options <file>` sets its RSP/video) but
77
+ only plays from power-on, and booted slower than the movie expects. Neither kept Yoshi's
78
+ Story's 100% movie in sync (`docs/emulator-driving.md`), so use the snapshots for diffing real
79
+ events, not "frame N is event X". Fetch the movie on demand and keep it, and the snapshots,
80
+ out of every repo.
81
+ - **Replay a TAS in BizHawk** when you can: `drive tas … --emulator bizhawk` runs the movie in its
82
+ own emulator (Windows BizHawk from WSL, version from the movie's header; an older movie needs
83
+ the nearest release that runs: 2.2.1's N64 plugins heap-crash on Windows 11 24H2), so it
84
+ should stay in sync where RetroArch's cores drift. Star Fox 64's glitchless 7190 played in
85
+ sync on 2.9.1. From WSL, start Windows
86
+ programs through `/init <exe>` (Mono's binfmt handler intercepts `.exe`s otherwise), never
87
+ through a shell-built command line (a lost apostrophe in a ROM name gave an empty window),
88
+ and tell the user before a window opens. A modal box stalls an unattended run: find one with
89
+ UI Automation or EnumWindows on the PID, and check the Application event log for APPCRASH.
90
+ Prove sync as above before using a frame. Pick the movie in this order: glitchless/100%/standard
91
+ categories that play the game as intended, the newest BizHawk, the default core and plugin;
92
+ avoid ACE, wrong-warp and game-end-glitch runs, and read the submission (`tasvideos.org/<n>S`)
93
+ for sync steps. On Windows 11 24H2 old Mupen64Plus code fails (the dynarec,
94
+ Glide64mk2): a movie that sits at frame 0 or crashes may run with `Core` 1 (interpreter) in a
95
+ copy of its `SyncSettings.json`, but such a copy is a deviation: prove sync (menu picks, counts
96
+ rising steadily, no lost health, level clears) before trusting any frame of it.
97
+ - **Naming an enum's values from a TAS** (an ability, a character, a fruit): the decomp often
98
+ proves the address and the numbering but not which value is which. Replay with `--watch
99
+ <addr>:<size>` and "-" for frames to log every change, then replay to a few hundred frames
100
+ after each value's first change and read the HUD (the change frame itself often predates the
101
+ HUD update). On 2026-12-03 this settled Kirby 64's base abilities (1 Burning, 2 Stone, 3 Ice …)
102
+ where the first table, written without it, had five of seven wrong. Never name values from
103
+ memory or from a sibling game's order.
61
104
  - **RetroArch** can load a state at start (`-e <slot>`), answers network commands and takes the
62
105
  network RetroPad. Its mupen64plus-next core crashed on one dev machine with one build and ran
63
106
  for an hour with another (`stable-cores`): check that it boots a game first. Under it,
64
107
  `drive frame` comes back black (the renderer doesn't write the frame to RDRAM) and so do its own
65
108
  screenshots under WSL: take frames from Gopher64, or check values with `peek` instead.
109
+ Navigating blind, poll the game's menu id (`gCurrentMenuId`) after each press so you know
110
+ which screen you're on. Its `RESET` network command did nothing on 1.22.2: to start over, quit
111
+ RetroArch and launch it again.
112
+ - **No TAS for your build? Drive RetroArch and check against the game's own numbers.** Super
113
+ Mario 64 US had no `.bk2` (TASVideos' only one is the Japanese ROM). With the network RetroPad
114
+ and `drive ra READ_CORE_MEMORY` it was checked in minutes: title → file select → in level, the
115
+ spawn against the level script's `MARIO_POS`, Start for pause. For save bits nobody can earn
116
+ by pressing buttons blind, write known bits into the save buffer at file select (after the
117
+ boot load, before the file is entered), enter the file, and compare your count with the one
118
+ the game computes from them (SM64's `numStars`, shown on the HUD). Two traps: mupen64plus-next
119
+ answers `READ_CORE_MEMORY` and takes `WRITE_CORE_MEMORY` in host order (little-endian words),
120
+ so read and write aligned words and swap them (`retroarch-command.ts` does for reads); and in
121
+ JavaScript `0x8033bac6 & ~3` is negative, so align with `(a & ~3) >>> 0`. A second Start on
122
+ SM64's file select already enters file A: check the "in a level" pointer is still null before
123
+ writing.
66
124
  - **PC games:** a save file at that moment, loaded by hand. Then the tool only reads; leave
67
125
  `retroarch` out of the spec.
68
126
 
@@ -119,6 +177,9 @@ map), because the game saves the last choices.
119
177
  whose address moves.
120
178
  - `"times": 3` needs that many matching reads in a row. Transitions can pass through a state
121
179
  for an instant: MM's opening reads as gameplay between its shots.
180
+ - `press` with `until` presses again before every read, so `"times": 2` there means two
181
+ presses. On a toggle (a pause menu, GoldenEye's watch) the second press undoes the first:
182
+ use `"times": 1`, or press once and `waitFor` the state, with a `waitMs` while it animates.
122
183
 
123
184
  The first step that can't do what it says stops the run and names itself.
124
185
  - **Pin every menu choice.** A route that presses Start until "racing" goes wherever the saved
@@ -156,6 +217,10 @@ puts their terminal in front and stalls the run.
156
217
  1. Build the plugin: `yarn check`.
157
218
  2. Start a local GameSlate daemon with your build:
158
219
  `GAMESLATE_PLUGINS_DIR=$PWD/dist node <gameslate>/dist/gameslate.mjs`.
220
+ Beside a daemon that's already running, give yours its own `GAMESLATE_PORT`, a `HOME` holding
221
+ `.config/gameslate/config.json` (a `pairingToken`), and a short `GAMESLATE_SOCK`: a UNIX
222
+ socket path over 107 bytes fails with `EINVAL`, and a scratch folder's often is. Then set the
223
+ spec's `"daemon": { "url": "ws://localhost:<port>/ws" }`; `verify` reads 4310 otherwise.
159
224
  3. `yarn dlx -p @gameslate/sdk gameslate-plugin verify verify/<moment>.json`
160
225
 
161
226
  It starts the emulator (`emulator.command`, with `${NAME}` taken from the environment, so specs
@@ -197,8 +262,16 @@ the start straight, so holding A long enough fetches an item to check the held-i
197
262
 
198
263
  - **RetroArch doesn't answer** (`didn't answer "READ_CORE_RAM …"`): network commands are off, or
199
264
  the port is taken. Check the appended config.
265
+ - **Stopping an emulator you started:** keep its PID (`… & echo $! > ra.pid`, then `kill $(cat
266
+ ra.pid)`). `pkill -f <pattern>` also matches the shell running that command line, so it kills
267
+ your own command and leaves the emulator running (twice on 2026-12-01).
200
268
  - **No state from the daemon:** is the daemon running with your plugin (its log lists the
201
269
  plugins it loaded), and does `validate` pass? Does the ROM's build id match one in
202
270
  `supportedBuildIds`? The daemon reports an unsupported build to the page.
203
271
  - **The game never starts** (the emulator idles at about 0% CPU): the display or GPU stack is
204
272
  broken (seen in WSL). Restart it; that's not the plugin.
273
+ - **"the game's RAM is in 2 places"**: two copies of the game's code both looked like live RAM.
274
+ The emulator's cartridge copy is rejected (the core checks for the ROM header in front of the
275
+ code first). Under RetroArch, Yoshi's Story also shows two full RAM copies, one in the heap and
276
+ one in a large mapping, both with a valid RAM size (2026-12-01, not yet resolved; MK64, F-Zero X,
277
+ Dr. Mario and GoldenEye don't). Verify such a game in Gopher64, and report the two addresses.
@@ -11,7 +11,7 @@ import { expect, it } from 'vitest';
11
11
  it('reads health in the sandbox', async () => {
12
12
  const out = fs.mkdtempSync(path.join(os.tmpdir(), '{{id}}-'));
13
13
  await buildPlugin({
14
- srcDir: path.resolve(__dirname, '../plugin'),
14
+ srcDir: path.resolve(__dirname),
15
15
  outDir: out,
16
16
  testedWith: ['test'],
17
17
  });
@@ -10,5 +10,5 @@
10
10
  "types": ["node"],
11
11
  "noEmit": true
12
12
  },
13
- "include": ["plugin/**/*", "test/**/*"]
13
+ "include": ["plugin/**/*"]
14
14
  }