@gameslate/sdk 0.3.6 → 0.3.8
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.
- package/README.md +37 -0
- package/bin/gameslate-plugin.mjs +75 -0
- package/build/init-plugin.mjs +2 -0
- package/build/verify-effects.mjs +188 -0
- package/lib/assets.d.ts +155 -8
- package/lib/assets.js +15 -2
- package/lib/catalogue.d.ts +6 -6
- package/lib/host/addresses.d.ts +103 -0
- package/lib/host/addresses.js +150 -0
- package/lib/host/asset-sandbox.d.ts +17 -3
- package/lib/host/asset-sandbox.js +27 -6
- package/lib/host/index.d.ts +2 -0
- package/lib/host/index.js +2 -0
- package/lib/host/inspect.js +1 -1
- package/lib/host/live-sandbox.d.ts +11 -2
- package/lib/host/live-sandbox.js +40 -6
- package/lib/host/quickjs-guest.d.ts +3 -0
- package/lib/host/quickjs-guest.js +17 -1
- package/lib/host/verify.d.ts +907 -0
- package/lib/host/verify.js +292 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/n64-address.d.ts +5 -0
- package/lib/n64-address.js +25 -0
- package/lib/pack.d.ts +6 -6
- package/lib/plugin/contract.d.ts +9 -0
- package/lib/plugin/sandbox-guest.js +4 -2
- package/lib/plugin-manifest.d.ts +19 -1
- package/lib/plugin-manifest.js +33 -6
- package/lib/plugins-api.d.ts +12 -0
- package/lib/plugins-api.js +3 -0
- package/lib/sandbox-protocol.d.ts +8 -8
- package/package.json +1 -1
- package/template/claude/skills/build-gameslate-plugin/SKILL.md +280 -0
- package/template/claude/skills/verify-gameslate-plugin/SKILL.md +194 -0
- package/template/gitignore +5 -0
- package/template/test/live.test.ts +5 -2
|
@@ -92,17 +92,17 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
92
92
|
id: string;
|
|
93
93
|
icon?: string | undefined;
|
|
94
94
|
max?: string | number | undefined;
|
|
95
|
+
format?: "number" | "percent" | undefined;
|
|
95
96
|
display?: Record<string, string> | undefined;
|
|
96
97
|
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
97
|
-
format?: "number" | "percent" | undefined;
|
|
98
98
|
}, {
|
|
99
99
|
label: string;
|
|
100
100
|
id: string;
|
|
101
101
|
icon?: string | undefined;
|
|
102
102
|
max?: string | number | undefined;
|
|
103
|
+
format?: "number" | "percent" | undefined;
|
|
103
104
|
display?: Record<string, string> | undefined;
|
|
104
105
|
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
105
|
-
format?: "number" | "percent" | undefined;
|
|
106
106
|
}>, "many">;
|
|
107
107
|
flagSets: z.ZodArray<z.ZodString, "many">;
|
|
108
108
|
inventoryLayouts: z.ZodArray<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
|
|
@@ -507,9 +507,9 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
507
507
|
id: string;
|
|
508
508
|
icon?: string | undefined;
|
|
509
509
|
max?: string | number | undefined;
|
|
510
|
+
format?: "number" | "percent" | undefined;
|
|
510
511
|
display?: Record<string, string> | undefined;
|
|
511
512
|
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
512
|
-
format?: "number" | "percent" | undefined;
|
|
513
513
|
}[];
|
|
514
514
|
flagSets: string[];
|
|
515
515
|
items: {
|
|
@@ -626,9 +626,9 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
626
626
|
id: string;
|
|
627
627
|
icon?: string | undefined;
|
|
628
628
|
max?: string | number | undefined;
|
|
629
|
+
format?: "number" | "percent" | undefined;
|
|
629
630
|
display?: Record<string, string> | undefined;
|
|
630
631
|
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
631
|
-
format?: "number" | "percent" | undefined;
|
|
632
632
|
}[];
|
|
633
633
|
flagSets: string[];
|
|
634
634
|
items: {
|
|
@@ -763,9 +763,9 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
763
763
|
id: string;
|
|
764
764
|
icon?: string | undefined;
|
|
765
765
|
max?: string | number | undefined;
|
|
766
|
+
format?: "number" | "percent" | undefined;
|
|
766
767
|
display?: Record<string, string> | undefined;
|
|
767
768
|
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
768
|
-
format?: "number" | "percent" | undefined;
|
|
769
769
|
}[];
|
|
770
770
|
flagSets: string[];
|
|
771
771
|
items: {
|
|
@@ -890,9 +890,9 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
890
890
|
id: string;
|
|
891
891
|
icon?: string | undefined;
|
|
892
892
|
max?: string | number | undefined;
|
|
893
|
+
format?: "number" | "percent" | undefined;
|
|
893
894
|
display?: Record<string, string> | undefined;
|
|
894
895
|
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
895
|
-
format?: "number" | "percent" | undefined;
|
|
896
896
|
}[];
|
|
897
897
|
flagSets: string[];
|
|
898
898
|
items: {
|
|
@@ -1070,9 +1070,9 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
1070
1070
|
id: string;
|
|
1071
1071
|
icon?: string | undefined;
|
|
1072
1072
|
max?: string | number | undefined;
|
|
1073
|
+
format?: "number" | "percent" | undefined;
|
|
1073
1074
|
display?: Record<string, string> | undefined;
|
|
1074
1075
|
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
1075
|
-
format?: "number" | "percent" | undefined;
|
|
1076
1076
|
}[];
|
|
1077
1077
|
flagSets: string[];
|
|
1078
1078
|
items: {
|
|
@@ -1214,9 +1214,9 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
1214
1214
|
id: string;
|
|
1215
1215
|
icon?: string | undefined;
|
|
1216
1216
|
max?: string | number | undefined;
|
|
1217
|
+
format?: "number" | "percent" | undefined;
|
|
1217
1218
|
display?: Record<string, string> | undefined;
|
|
1218
1219
|
role?: "keys" | "health" | "magic" | "armor" | undefined;
|
|
1219
|
-
format?: "number" | "percent" | undefined;
|
|
1220
1220
|
}[];
|
|
1221
1221
|
flagSets: string[];
|
|
1222
1222
|
items: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gameslate/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"description": "Build plugins for GameSlate, the second-screen companion for PC games: the plugin contract, game-state and catalogue schemas, and the plugin builder.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: build-gameslate-plugin
|
|
3
|
+
description: Build a GameSlate plugin for a game, from choosing how to read its state through memory addresses, packs, asset extractors, tests and release. Use when adding a game, reading a new value from a game, or making a plugin's map assets.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Building a GameSlate plugin
|
|
7
|
+
|
|
8
|
+
A plugin teaches GameSlate one or more games. It runs in GameSlate's sandbox (QuickJS: no files, no
|
|
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
|
|
11
|
+
skip verification: a wrong address that looks plausible is worse than no address.
|
|
12
|
+
|
|
13
|
+
## 1. Pick the state source
|
|
14
|
+
|
|
15
|
+
Decide before writing code, and write the decision in the README.
|
|
16
|
+
|
|
17
|
+
| The game is… | Read state from | Addresses come from |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| an open-source port (Ship of Harkinian, dsda-doom) | its process memory | `offsetof` / `sizeof` from its own headers, compiled for its ABI |
|
|
20
|
+
| a console game in an emulator (N64) | the emulated RAM (the core finds it) | a decompilation built **byte-identical** to the player's ROM |
|
|
21
|
+
| a closed PC game | its process memory | leads (LiveSplit autosplitters, RetroAchievements code notes), verified live, read by signature (`memory.scan()`) |
|
|
22
|
+
| protected by anti-cheat (VAC, EAC) | **nothing** | don't: use its mods or console, or skip it |
|
|
23
|
+
|
|
24
|
+
## 2. Scaffold
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
yarn dlx -p @gameslate/sdk gameslate-plugin init my-plugin --id my-plugin --name "My Plugin"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Then `yarn install && yarn check`. `check` runs the typecheck, the tests, the build and
|
|
31
|
+
`validate`, and it's what CI runs. You get:
|
|
32
|
+
|
|
33
|
+
- `plugin/manifest.json`: the plugin's id, name, version, `sdkApi`, and `games[]`;
|
|
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
|
|
36
|
+
bundler follows the imports.
|
|
37
|
+
- 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
|
|
39
|
+
memory, and runs the pack contract check (`checkCatalogue`). Keep it.
|
|
40
|
+
- CI, and `.claude/skills/`: this skill and `verify-gameslate-plugin`.
|
|
41
|
+
|
|
42
|
+
Each manifest game has:
|
|
43
|
+
|
|
44
|
+
- `id`, `title`, and optional `aliases` (short names a player may type);
|
|
45
|
+
- optional `inputs[]`, only for asset extractors: a `label`, the `folders` under `~` where the
|
|
46
|
+
player's files usually are, and `subfolders` whose files count too, such as a port's `mods/`.
|
|
47
|
+
Hidden folders are refused except under `~/.var/app`, `~/.local/share` and `~/.steam`.
|
|
48
|
+
|
|
49
|
+
The build fills in the code files' hashes. Never edit those by hand.
|
|
50
|
+
|
|
51
|
+
**Against an unreleased SDK** (you're changing the SDK too): `yarn pack` in the SDK, then depend
|
|
52
|
+
on the tarball (`"@gameslate/sdk": "file:../gameslate-sdk.tgz"`). With Yarn's PnP, `link:` skips
|
|
53
|
+
the SDK's own dependencies and type-checks its sources, so don't use it.
|
|
54
|
+
|
|
55
|
+
## 3. The pack: what the game means
|
|
56
|
+
|
|
57
|
+
Write the decoder against **fixtures first**: raw snapshots you captured, turned into `GameState`.
|
|
58
|
+
The catalogue (items, missions, counters, collectibles, reference) and its conditions are data. One
|
|
59
|
+
evaluator in the SDK decides "done", "collected" and "available". Rules:
|
|
60
|
+
|
|
61
|
+
- Every condition references ids that exist. `checkCatalogue(pack.catalogue)` checks it, and the
|
|
62
|
+
template's test already calls it.
|
|
63
|
+
- Every poll returns a whole `GameState`: `phase`, `provenance` (`{ source: 'ram', asOf, frame }`),
|
|
64
|
+
`locationId`, `position` (or `null`), `inventory`, `objectives`, `flags`, `enemies`. Add
|
|
65
|
+
`counters`, `difficulty` and `variant` as needed. The core validates every state against
|
|
66
|
+
`GameStateSchema` and drops one that fails.
|
|
67
|
+
- **Unknown is not false.** A value you can't read is "untracked", never "missing": leave the
|
|
68
|
+
counter out of `counters` rather than reporting 0.
|
|
69
|
+
- Give counters a `role` (`health`, `magic`, `armor`, `keys`) so shared UI finds them.
|
|
70
|
+
- Use `format: 'percent'` with a `max` for meters.
|
|
71
|
+
|
|
72
|
+
**What to put in a pack** (Mario Kart 64 and Star Fox 64 in gameslate-n64 are worked examples):
|
|
73
|
+
|
|
74
|
+
- **Inventory:** what the player holds or chose (driver, held item), as `slotGrid`s; the run's
|
|
75
|
+
numbers (place, lap, time, shields) as `counters` layouts. A shield or HP gets `role: 'health'`
|
|
76
|
+
and `max` naming another counter when its maximum changes (`shieldMax`).
|
|
77
|
+
- **Missions from the save:** one per thing the save records (a cup's trophy per class, a planet's
|
|
78
|
+
medal), with steps for each tier, and `availableWhen` for what the game unlocks later (Extra
|
|
79
|
+
after a 150cc gold in every cup, read from the unlock function, not a wiki).
|
|
80
|
+
- **Missions from live play:** a level's target while flying it (`availableWhen: { at }`,
|
|
81
|
+
`progress: { counter, target }`, steps per requirement).
|
|
82
|
+
- **Reference and chips:** tables the game's code defines (cups, points, routes), in your own
|
|
83
|
+
words; chips that ask about the current location.
|
|
84
|
+
- **Facts come from the code that decides them.** A game can show one number and check another:
|
|
85
|
+
Star Fox 64's HUD flags a medal at 200 hits on Macbeth, but the level's end checks 150, and
|
|
86
|
+
that's what the save records. Read the function that writes the save.
|
|
87
|
+
|
|
88
|
+
## 4. Memory addresses, verified
|
|
89
|
+
|
|
90
|
+
**Pin the build.** List the exact builds you verified in the source's `supportedBuildIds` (a
|
|
91
|
+
`Map` from build id to `{ region }` on the `GamePlugin` in `live.ts`, not in the manifest):
|
|
92
|
+
|
|
93
|
+
- ELF or PE build id for PC games;
|
|
94
|
+
- `CODE.version` from the ROM header for N64 (e.g. `CZLE.2`).
|
|
95
|
+
|
|
96
|
+
An unknown build means refuse to attach, never "try the nearest offsets".
|
|
97
|
+
|
|
98
|
+
**Open-source ports.** Compile a probe against the game's headers: print `sizeof` of a big struct
|
|
99
|
+
(it must equal what the shipped build uses) and the `offsetof` of each field. Put each value in
|
|
100
|
+
`offsets.ts`, with a comment naming the struct field and where the number came from. Header
|
|
101
|
+
comments like `/* 0x0E9C */` are not a source.
|
|
102
|
+
|
|
103
|
+
**Console decompilations:**
|
|
104
|
+
|
|
105
|
+
`gameslate-plugin addresses <spec.json> [--out plugin/addresses.ts]` does steps 2, 3 and 5 below
|
|
106
|
+
in one go: it reads the globals from the decomp's maps (ld `.map` or splat `symbol_addrs*.txt`),
|
|
107
|
+
subtracts a revision delta if given, compiles a probe of `offsetof`, `sizeof` and constants
|
|
108
|
+
against the headers, and writes a table whose header names the commit and every source. A symbol
|
|
109
|
+
the maps lack or a value clang can't fold fails the run. Example spec (the one that reproduced
|
|
110
|
+
Mario Kart 64's verified addresses):
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
{
|
|
114
|
+
"decomp": "${MK64_DECOMP}",
|
|
115
|
+
"symbolFiles": ["build/us/mk64.us.map"],
|
|
116
|
+
"includes": ["<ultra64.h>", "common_structs.h", "save_data.h", "course.h"],
|
|
117
|
+
"clang": { "args": ["--target=mips-unknown-linux-gnu", "-mabi=32", "-fno-pic", "-D_LANGUAGE_C",
|
|
118
|
+
"-DTARGET_N64=1", "-DVERSION_US=1", "-D_MIPS_SZLONG=32", "-nostdinc",
|
|
119
|
+
"-isystem", "${CLANG_INCLUDE}", "-Iinclude", "-Iinclude/libc", "-Isrc", "-Ibuild/us", "-I."] },
|
|
120
|
+
"symbols": ["gGamestate", "gPlayers", "gSaveData"],
|
|
121
|
+
"offsets": ["Player.rotation", "SaveData.main.saveInfo.grandPrixPoints"],
|
|
122
|
+
"sizes": ["Player", "CourseVtx"],
|
|
123
|
+
"constants": { "COURSE_LUIGI_RACEWAY": "COURSE_LUIGI_RACEWAY" }
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
A decomp that generates headers at build time (Paper Mario's `item_enum.h`) needn't be built:
|
|
128
|
+
list them in `"stubHeaders"` and the probe gets empty ones (a layout that really needs one still
|
|
129
|
+
fails to compile). Constants come back signed.
|
|
130
|
+
|
|
131
|
+
For another revision add `"subtract": "0xA190"` (and check the delta against verified leads
|
|
132
|
+
first). Commit the spec and the generated table; the decomp and ROM stay local.
|
|
133
|
+
|
|
134
|
+
0. **Check GameSlate can attach before writing a reader:** start the game in the emulator and
|
|
135
|
+
`gameslate drive peek <pid> <a code address>:4`; the word must equal the ROM's bytes for that
|
|
136
|
+
function (the symbol file's `rom:` offset). Paper Mario needed two core fixes here: its boot
|
|
137
|
+
chip (CIC-6103) loads the game 1 MB below the header's entry point, and its low memory has no
|
|
138
|
+
`osMemSize`.
|
|
139
|
+
1. Build the decomp and check the output's **md5 equals the player's ROM**. Mind the region: some
|
|
140
|
+
Makefiles default to another region and still print "OK" against their own checksum.
|
|
141
|
+
2. Probe the struct offsets by compiling the decomp's headers for the console's ABI. For N64 that's
|
|
142
|
+
MIPS o32: `clang --target=mips-unknown-linux-gnu -mabi=32 -S`, then read the constants back.
|
|
143
|
+
3. Take global addresses from the build's symbol map.
|
|
144
|
+
4. If a global pointer outlives its object (a pointer that isn't cleared when the scene unloads),
|
|
145
|
+
trust it only with a check from the same build, such as "this state's update function is the
|
|
146
|
+
one the map says".
|
|
147
|
+
|
|
148
|
+
5. **The decomp builds another revision** (Star Fox 64's builds US 1.1, the player has 1.0):
|
|
149
|
+
global addresses often differ by a constant per segment. Check every verified lead against
|
|
150
|
+
its symbol (`symbol − lead`); if they all agree, take the remaining globals as symbol − delta,
|
|
151
|
+
say so in the source, and verify the new ones live. Types and struct layouts carry over.
|
|
152
|
+
6. **Prove a save block's address with the game's own checksum:** read the block live, run the
|
|
153
|
+
game's checksum function over it (ported from the decomp), and compare with the stored one. A
|
|
154
|
+
blank save reads as zeros anywhere, so a zero read proves nothing.
|
|
155
|
+
7. **Sizes and signs come from declarations and probes, never from guesses:** a 14-byte struct
|
|
156
|
+
isn't 16 (`CourseVtx` has 2-byte alignment); a `u8` read as `getInt8` turns 0xFD into -3.
|
|
157
|
+
|
|
158
|
+
**Leads, from LiveSplit or RetroAchievements:**
|
|
159
|
+
|
|
160
|
+
- A lead is not a source. Verify every value live, across levels, menus and loads.
|
|
161
|
+
- Record where it came from, and **never copy their code**: addresses are facts, scripts aren't.
|
|
162
|
+
- **RetroAchievements N64 addresses are in the emulator's little-endian 32-bit words.** To get the
|
|
163
|
+
console's big-endian address: byte = address ^ 3, 16-bit = address ^ 2, 32-bit as is.
|
|
164
|
+
- RA notes are per game, not per revision. Struct offsets carry across revisions; absolute
|
|
165
|
+
addresses don't.
|
|
166
|
+
- A byte-pattern lead stays a pattern: read it with `memory.scan({ pattern, kind, offset })`, so it
|
|
167
|
+
survives patches. It must match exactly once.
|
|
168
|
+
|
|
169
|
+
**Reading:** read whole blocks (the save struct in one read) where the values sit together.
|
|
170
|
+
Sample with `seqlockSample(readFrameCounter, readPayload)` (from `@gameslate/sdk/plugin`) so a
|
|
171
|
+
frame isn't half old and half new: it rereads until the game's frame counter is the same before
|
|
172
|
+
and after. A game without a frame counter you can read has nothing to sample against: read once
|
|
173
|
+
per poll. Numbers are explicit about width, sign and byte order (`readUInt16BE` for N64,
|
|
174
|
+
`readInt32LE` for PC).
|
|
175
|
+
|
|
176
|
+
## 5. Assets (optional): maps, icons, meshes from the player's files
|
|
177
|
+
|
|
178
|
+
`assets.ts` exports an extractor per game:
|
|
179
|
+
|
|
180
|
+
- `listAssets(inputs, pick)` must be cheap: name what can be built.
|
|
181
|
+
- `buildAsset(id, inputs)` returns outputs in the SDK's shapes: floorplan, location, nav, mesh
|
|
182
|
+
(GS3D), and image.
|
|
183
|
+
|
|
184
|
+
Images have a `purpose` (`atlas`, `map`, `icon`, `actor`, which picks the folder) and an `encoding`:
|
|
185
|
+
|
|
186
|
+
- PNG;
|
|
187
|
+
- `{ format: 'webp', lossless: true }`;
|
|
188
|
+
- `{ format: 'webp', quality: 88 }`.
|
|
189
|
+
|
|
190
|
+
Every image of a game uses one format. In the sandbox:
|
|
191
|
+
|
|
192
|
+
- **No `TextDecoder`, `TextEncoder` or `Buffer`.** Decode UTF-8 by hand, and decode files in
|
|
193
|
+
chunks (`String.fromCharCode(...bytes)` has an argument limit).
|
|
194
|
+
- **One asset per unit of work** (per map, per actor): each gets its own time budget (10 minutes)
|
|
195
|
+
and its own up-to-date stamp, and jobs build assets across several threads.
|
|
196
|
+
- Inputs are named relative to the folder the player picked (`mods/pack.o2r`). The core also hands
|
|
197
|
+
in the game's registry manifest as `registry/manifest.json` when there is one, so renders line up
|
|
198
|
+
with the registry's maps.
|
|
199
|
+
- **Data licensing:** ship the extractor, never its output. Textures, models and renders are
|
|
200
|
+
built on the player's machine and never committed.
|
|
201
|
+
|
|
202
|
+
### Maps from a ROM (Mario Kart 64 in gameslate-n64 is the worked example)
|
|
203
|
+
|
|
204
|
+
1. **Follow the game's own load path** in the decomp: the table that names each level's data
|
|
205
|
+
(`gCourseTable`), how each segment is stored (MIO0, raw), how it's unpacked
|
|
206
|
+
(`displaylist_unpack`). Read the ROM's table at runtime and check what you read (MIO0 magic,
|
|
207
|
+
segment numbers) so a different ROM fails loud.
|
|
208
|
+
2. **Port decoders exactly:** for a byte-coded stream, write down each opcode's argument bytes
|
|
209
|
+
and how many commands it emits. Offsets into the unpacked data depend on every count being right.
|
|
210
|
+
3. **Draw what the player drives on:** the collision mesh, not the render lists. Use the lists the
|
|
211
|
+
game collides with, apply the same filters (section flags that drop flat or upright triangles,
|
|
212
|
+
vertices flagged "no collision"), keep floors facing up by winding, and colour by surface type.
|
|
213
|
+
Shade by height and draw higher floors later so bridges sit over roads.
|
|
214
|
+
4. **Location ids are asset ids:** lower-case words, dots and dashes, **no underscores**. The
|
|
215
|
+
`locationId` the live reader reports must equal them.
|
|
216
|
+
5. **Place the player:** the layer's affine maps world x/z onto the drawing exactly as it was
|
|
217
|
+
drawn. Find the heading convention live: drive straight, then steer one way, and compare the
|
|
218
|
+
movement with the yaw (MK64: yaw θ drives along (−sin θ, cos θ)). Mirror modes negate x: put the
|
|
219
|
+
player back on the unmirrored map.
|
|
220
|
+
6. **Look at it.** Render the SVGs (`rsvg-convert -w 500 map.svg -o map.png`) and compare with
|
|
221
|
+
the game's own minimap.
|
|
222
|
+
7. **A game needs a registry entry** (`gameslate-registry/games/<id>/manifest.json`: title,
|
|
223
|
+
capabilities with `map_2d`, difficulties, item names; locations empty) before the web app shows
|
|
224
|
+
extracted maps. Doom's is the pattern; update `index.json` and `channels.json` hashes too.
|
|
225
|
+
|
|
226
|
+
## 6. Tests
|
|
227
|
+
|
|
228
|
+
- **Decoders:** fixture snapshot in, expected `GameState` out, including menus, no save, and edge
|
|
229
|
+
values.
|
|
230
|
+
- **Conditions:** table tests, one row per branch.
|
|
231
|
+
- **The sandbox bundle:** the template's test runs the built `live.js` in the core's sandbox. Keep
|
|
232
|
+
it, and add an extraction test on a synthetic archive.
|
|
233
|
+
- **Ports of existing tools:** compare against the original's real output with **the same library
|
|
234
|
+
versions** that made it. A newer Pillow or numpy changes pixels on its own: Pillow 12 changed its
|
|
235
|
+
resample order, and numpy's matmul differs per CPU.
|
|
236
|
+
- **Every bug fix gets a test that fails without the fix.** Break the code, watch it fail, restore.
|
|
237
|
+
- **No game data in fixtures:** build synthetic ones (bytes you wrote) and record what the reference
|
|
238
|
+
tool produced from them.
|
|
239
|
+
- **Tests against the player's own files** run only when one is given
|
|
240
|
+
(`describe.runIf(process.env.MK64_ROM)`), read it in `beforeAll` (a describe body runs at
|
|
241
|
+
collection even when skipped, and a missing file fails the whole file), and pin live facts:
|
|
242
|
+
positions read in a real race must land on the decoded floors.
|
|
243
|
+
- **Get an independent review** of a decoder against the decomp's source (the
|
|
244
|
+
`review-correctness` lens, or a fresh agent given the code and the decomp's paths, not your
|
|
245
|
+
conclusions). On Mario Kart 64 it found three real bugs the renders didn't show.
|
|
246
|
+
|
|
247
|
+
## 7. Verify live
|
|
248
|
+
|
|
249
|
+
Use the `verify-gameslate-plugin` skill. It drives the game to a known moment, reads what your
|
|
250
|
+
plugin reports, screenshots the game and GameSlate, and checks them against `verify.json`. Until a build
|
|
251
|
+
passes, say so in the README ("unverified: offsets from leads") and keep it out of a release.
|
|
252
|
+
|
|
253
|
+
## 8. Release
|
|
254
|
+
|
|
255
|
+
```sh
|
|
256
|
+
yarn check
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
That's the typecheck, the tests, the build, then `validate dist/<id>`, which checks the built
|
|
260
|
+
plugin exactly as the core will before running it. Then bump `version`, tag `vX.Y.Z`, and publish the release bundle. GameSlate installs presets from
|
|
261
|
+
`plugins.lock.json` (an entry with the release URL and its sha256).
|
|
262
|
+
|
|
263
|
+
## Pitfalls seen in real plugins
|
|
264
|
+
|
|
265
|
+
- **Texture packs:** a port's HD packs (`mods/*.o2r`) replace textures. Read them the way the game
|
|
266
|
+
does: packs first, in name order, each preferring its `alt/` asset, then the base archive.
|
|
267
|
+
Otherwise you overwrite HD output with vanilla.
|
|
268
|
+
- **Big inputs:** files over 256 MiB are identified by size and modification time, not hashed.
|
|
269
|
+
Don't rely on a byte change inside a huge file being noticed unless its size or mtime changes too.
|
|
270
|
+
- **Emulators:** the core finds an N64 game's RAM by the ROM's boot code. The ROM must be on the
|
|
271
|
+
emulator's command line, and the game must have booted. CIC-6103 and 6106 games (Paper Mario,
|
|
272
|
+
Banjo-Kazooie) load below their header's entry point; the core works that out from the boot
|
|
273
|
+
code's CRC.
|
|
274
|
+
- **The game mode can be a function pointer:** when the decomp keeps the current mode in a
|
|
275
|
+
file-static the symbol maps don't list, read the mode table instead (Paper Mario:
|
|
276
|
+
`gMainGameMode[0].step` equals a `state_step_*` symbol).
|
|
277
|
+
- **Menus remember:** many games save the last menu choices, so a route that only presses Start
|
|
278
|
+
lands somewhere else next time. Pin each choice with the game's own menu variables.
|
|
279
|
+
- **Prove it on real data before writing to a player's files.** Back up what's there before the
|
|
280
|
+
first run on a real machine.
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: verify-gameslate-plugin
|
|
3
|
+
description: Verify a GameSlate plugin against the running game: load a known moment (an emulator save state), read what the plugin reports through a local GameSlate daemon, cross-check memory through the emulator, and screenshot both. Use before calling a build verified, after changing offsets, or when promoting a first-pass (unverified) pack.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Verifying a GameSlate plugin
|
|
7
|
+
|
|
8
|
+
Tests prove the decoder does what you think. Verifying proves what you think is true of the game.
|
|
9
|
+
A plugin's build is **verified** when a known moment of the game reads correctly: the right
|
|
10
|
+
location, counters that match the screen, and, for an emulated console, memory values the
|
|
11
|
+
emulator itself agrees with.
|
|
12
|
+
|
|
13
|
+
## 1. Pick moments the screen can confirm
|
|
14
|
+
|
|
15
|
+
For each build, pick one to three moments with distinct, visible values: a town with an odd rupee
|
|
16
|
+
count, a dungeon with keys, a menu. For each, write down what the screen shows. Include at least
|
|
17
|
+
one moment that's **not** gameplay (title or file select), so "no save loaded" is checked too.
|
|
18
|
+
|
|
19
|
+
## 2. Get to the moment
|
|
20
|
+
|
|
21
|
+
**Drive the game yourself; don't wait for a person.** For an emulated console, this loop is
|
|
22
|
+
proven, and GameSlate's `gameslate drive` does each step (`docs/emulator-driving.md`):
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
gameslate drive press Return 120 # keys, with hold times
|
|
26
|
+
gameslate drive peek <pid> 0x800dc50c:4 # guest values, read frozen
|
|
27
|
+
gameslate drive frame <pid> screen.png # the screen the game drew
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The steps:
|
|
31
|
+
|
|
32
|
+
1. **Pause:** `SIGSTOP` the emulator process. `SIGCONT` resumes it. Memory stays readable while
|
|
33
|
+
it's stopped.
|
|
34
|
+
2. **Read the plugin:** a local GameSlate daemon with your build reports the state over its
|
|
35
|
+
WebSocket (step 4 below).
|
|
36
|
+
3. **Read the screen from the game's own memory**, not the window: libultra's `__osViCurr`
|
|
37
|
+
points at the video context, whose word at +4 is the framebuffer (RGBA5551, 320×240 for most
|
|
38
|
+
games). Without symbols, find `__osViCurr` as two adjacent words in the first 4 MB pointing at
|
|
39
|
+
two contexts 0x30 bytes apart that sit just before them, each holding a framebuffer pointer.
|
|
40
|
+
Grabbing an emulator's window can come back black (WSLg, GPU surfaces).
|
|
41
|
+
4. **Press buttons:** XTEST key events into the emulator's window (Gopher64 maps Start to Return,
|
|
42
|
+
A to Left Shift, B to Left Ctrl, Z to `z`, the stick to the arrows).
|
|
43
|
+
5. **Wait on state, not time:** after each input, read until the game state you expect appears
|
|
44
|
+
(for example "game state = racing"), with a timeout.
|
|
45
|
+
|
|
46
|
+
Script the route per game as inputs plus checks, such as "Start until game state 4, hold A for
|
|
47
|
+
9 s, expect place and lap". Prefer moments a route reaches from boot.
|
|
48
|
+
|
|
49
|
+
- **Deeper moments:** TASVideos input recordings replay from boot to documented frames (check
|
|
50
|
+
that the replay arrived; they can drift between emulator versions). Battery saves
|
|
51
|
+
(`.eep`/`.sra`) work across emulators. A save state is the last resort: tied to one emulator
|
|
52
|
+
version, and it needs a person to make it. Keep saves and states out of the repo: they're game
|
|
53
|
+
data.
|
|
54
|
+
- **RetroArch** can load a state at start (`-e <slot>`) and answers network commands, but its
|
|
55
|
+
N64 core crashed on one dev machine. Check that it boots a game before relying on it.
|
|
56
|
+
- **PC games:** a save file at that moment, loaded by hand. Then the tool only reads; leave
|
|
57
|
+
`retroarch` out of the spec.
|
|
58
|
+
|
|
59
|
+
## 3. Write `verify.json`
|
|
60
|
+
|
|
61
|
+
An emulator, the route to the moment (`steps`), and what the moment must read. This one passed on
|
|
62
|
+
Mario Kart 64 on 2026-11-30: from boot to the start of a Grand Prix, untouched by a person. Each
|
|
63
|
+
menu choice (1 player, Grand Prix, 50cc, Mushroom Cup) is pinned by the game's own menu variables
|
|
64
|
+
(`gMainMenuSelection`, `gPlayerCount`, `gGameModeMenuColumn`, `gCupSelection` from the decomp's
|
|
65
|
+
map), because the game saves the last choices.
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"game": "mario-kart-64",
|
|
70
|
+
"gameslate": "/path/to/gameslate/dist/gameslate.mjs",
|
|
71
|
+
"emulator": { "command": ["/path/to/gopher64", "/path/to/Mario Kart 64 (U).z64"] },
|
|
72
|
+
"steps": [
|
|
73
|
+
{ "waitFor": { "peek": "0x800dc50c:4", "equals": 4 }, "timeoutMs": 60000, "everyMs": 2000 },
|
|
74
|
+
{ "press": "Return", "holdMs": 120, "until": { "peek": "0x800dc50c:4", "equals": 0 } },
|
|
75
|
+
{ "press": "Return", "holdMs": 120, "until": { "peek": "0x8018eded:1", "equals": 3 } },
|
|
76
|
+
{ "press": "Left", "holdMs": 120, "until": { "peek": "0x8018edf3:1", "equals": 1 } },
|
|
77
|
+
{ "press": "Shift_L", "holdMs": 120, "until": { "peek": "0x8018eded:1", "equals": 4 } },
|
|
78
|
+
{ "press": "Up", "holdMs": 120, "until": { "peek": "0x800e86ac:1", "equals": 0 } },
|
|
79
|
+
{ "press": "Shift_L", "holdMs": 120, "until": { "peek": "0x8018eded:1", "equals": 5 } },
|
|
80
|
+
{ "press": "Up", "holdMs": 120, "until": { "peek": "0x800e86b0:1", "equals": 0 } },
|
|
81
|
+
{ "press": "Shift_L", "holdMs": 120, "until": { "peek": "0x8018eded:1", "equals": 6 } },
|
|
82
|
+
{ "press": "Return", "holdMs": 120, "until": { "peek": "0x8018edec:1", "equals": 1 } },
|
|
83
|
+
{ "press": "Left", "holdMs": 120, "until": { "peek": "0x8018ee09:1", "equals": 0 } },
|
|
84
|
+
{ "press": "Return", "holdMs": 120, "until": { "peek": "0x800dc50c:4", "equals": 4 } },
|
|
85
|
+
{ "press": "Shift_L", "holdMs": 8000 },
|
|
86
|
+
{ "frame": "mk64-gp-start.png" }
|
|
87
|
+
],
|
|
88
|
+
"settleMs": 0,
|
|
89
|
+
"expect": {
|
|
90
|
+
"phase": "in_stage",
|
|
91
|
+
"locationId": "luigi-raceway",
|
|
92
|
+
"variant": "grand_prix",
|
|
93
|
+
"difficulty": "50cc",
|
|
94
|
+
"counters": { "lap": 1, "place": { "min": 1, "max": 8 }, "raceTime": { "min": 0.1, "max": 5 } }
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
- **Steps:**
|
|
100
|
+
- `press` sends a key to the emulator's window (focused first). With `until`, it repeats every
|
|
101
|
+
`everyMs` until the peeked value matches, up to `maxTries`. Given several keys
|
|
102
|
+
(`["Return", "Shift_L"]`), they take turns: menus differ in which button they take. Star
|
|
103
|
+
Fox 64's map needs Start to pick the planet and A through the briefing.
|
|
104
|
+
- `waitFor` waits on a check.
|
|
105
|
+
- `waitMs` pauses, for screens nothing in memory marks.
|
|
106
|
+
- `frame` saves the screen the game drew.
|
|
107
|
+
- A check is a peeked value (`{ "peek": "0x…:4", "equals": 4 }`) or the plugin's own state
|
|
108
|
+
(`{ "state": { "phase": "in_stage", "locationId": "lost_woods_intro" } }`), for moments
|
|
109
|
+
whose address moves.
|
|
110
|
+
- `"times": 3` needs that many matching reads in a row. Transitions can pass through a state
|
|
111
|
+
for an instant: MM's opening reads as gameplay between its shots.
|
|
112
|
+
|
|
113
|
+
The first step that can't do what it says stops the run and names itself.
|
|
114
|
+
- **Pin every menu choice.** A route that presses Start until "racing" goes wherever the saved
|
|
115
|
+
cursors point; after one run in 2-player Versus, the next run raced there too. Wait for each menu
|
|
116
|
+
screen by its variable, then press a direction until the cursor variable reads your choice.
|
|
117
|
+
- **Boot isn't the moment.** A state variable can already hold your target value during the boot
|
|
118
|
+
logo (MK64's game state reads 4, "racing", before the title), and keys are ignored there. Wait
|
|
119
|
+
for a value only the moment has, or for the attract demo after the logo.
|
|
120
|
+
- **Guard against games that drive themselves.** Attract demos cycle through the same states
|
|
121
|
+
your route waits on: a route whose keys never arrived once "passed" every step on the demo. Make
|
|
122
|
+
`expect` specific enough that the demo can't match it (this course, this mode, this class).
|
|
123
|
+
- Without `steps`, a `retroarch` block (binary, core, ROM, `stateSlot`) loads a save state
|
|
124
|
+
instead. That's the fallback when no route from boot is practical.
|
|
125
|
+
- Paths are relative to the file. Keep one file per moment (`verify/<moment>.json`), next to the
|
|
126
|
+
tests. They hold no game data; the ROM, any state, and the frames stay on your machine
|
|
127
|
+
(git-ignore `verify/*.png`).
|
|
128
|
+
- With RetroArch, `memory` reads each address through RetroArch (`READ_CORE_RAM`, RetroAchievements'
|
|
129
|
+
addressing; the tool converts a guest address for you) and requires it to equal the plugin's
|
|
130
|
+
counter. That second opinion catches a wrong offset that still looks plausible. Use it for at
|
|
131
|
+
least one value per struct the plugin reads (save, live game state).
|
|
132
|
+
- Where only a game's parent may read its memory (ptrace_scope 1, as on ChimeraOS), add
|
|
133
|
+
`"launchPrefix": ["node", "<gameslate>/dist/gameslate.mjs", "run", "--"]` so the game starts
|
|
134
|
+
through GameSlate's launch wrapper.
|
|
135
|
+
|
|
136
|
+
## 4. Run it
|
|
137
|
+
|
|
138
|
+
**Keep the emulator's window in front.** Keys go to whichever window has the keyboard. `press`
|
|
139
|
+
refuses to type into another window: it waits up to 30 s for you (or the person at the machine)
|
|
140
|
+
to click the emulator, and stops the run if focus moves while a key is held. Under WSLg a Windows
|
|
141
|
+
app in front leaves X with no focused window, so click the emulator once when it opens. Tell
|
|
142
|
+
anyone at the machine before a run, and that a long route (Paper Mario's opening is several
|
|
143
|
+
minutes of text) needs them to leave the keyboard alone throughout: sending a message to an agent
|
|
144
|
+
puts their terminal in front and stalls the run.
|
|
145
|
+
|
|
146
|
+
1. Build the plugin: `yarn check`.
|
|
147
|
+
2. Start a local GameSlate daemon with your build:
|
|
148
|
+
`GAMESLATE_PLUGINS_DIR=$PWD/dist node <gameslate>/dist/gameslate.mjs`.
|
|
149
|
+
3. `yarn dlx -p @gameslate/sdk gameslate-plugin verify verify/<moment>.json`
|
|
150
|
+
|
|
151
|
+
It starts the emulator (`emulator.command`, with `${NAME}` taken from the environment, so specs
|
|
152
|
+
hold no local paths), runs the `steps` through `gameslate drive`, waits `settleMs`, then reads the
|
|
153
|
+
daemon's next state for the game. It compares that state with `expect` (and, with RetroArch, the
|
|
154
|
+
emulator's own reads with `memory`), saves the frames the steps asked for, and screenshots the
|
|
155
|
+
GameSlate page if Playwright is installed. Then it stops the emulator. It exits 0 only when
|
|
156
|
+
everything matched. Run it twice: a route that passes once can depend on what the last run saved.
|
|
157
|
+
|
|
158
|
+
## 5. Look at the screenshots, and every tab
|
|
159
|
+
|
|
160
|
+
The JSON checks what you predicted. The screenshots catch what you didn't: a pin in the wrong
|
|
161
|
+
room, a counter shown under the wrong label, a menu reported as gameplay. Open both and compare
|
|
162
|
+
them with the game's screen. Write down anything odd as a finding, even if the JSON passed.
|
|
163
|
+
|
|
164
|
+
At the moment, `verify` also screenshots the web app's tabs when the spec has `ui`: a URL with
|
|
165
|
+
its pairing token (`"ui": "http://localhost:4310/#token=${GAMESLATE_TOKEN}"` opens Map,
|
|
166
|
+
Inventory, Missions and Ref in turn) or `{ "url": …, "tabs": ["Inventory"] }`. Look at each: the
|
|
167
|
+
counters, the item lit in a grid, the mission list, the map's arrow against the game's minimap.
|
|
168
|
+
A local daemon's token is in its config:
|
|
169
|
+
`export GAMESLATE_TOKEN=$(node -p "require('$HOME/.config/gameslate/config.json').pairingToken")`
|
|
170
|
+
(don't paste it anywhere else). To see extracted maps, run the daemon with `GAMESLATE_LOCAL_ASSETS_DIR` (and
|
|
171
|
+
`GAMESLATE_REGISTRY_DIR` for a registry entry not deployed yet).
|
|
172
|
+
"Couldn't load this game's map data from the registry" means the game has no registry entry yet.
|
|
173
|
+
|
|
174
|
+
For values the route doesn't show, drive to them: Luigi Raceway's first row of item boxes is on
|
|
175
|
+
the start straight, so holding A long enough fetches an item to check the held-item read.
|
|
176
|
+
|
|
177
|
+
## 6. Record the result
|
|
178
|
+
|
|
179
|
+
- In the README, list each verified build id with the date, the moments, and the emulator.
|
|
180
|
+
- A failure is a finding about the offsets, never about the expectation. Don't loosen
|
|
181
|
+
`expect` to make it pass. Find which read is wrong; the `memory` checks usually say which.
|
|
182
|
+
- An emulator that disagrees with the plugin on a value the screen confirms means the
|
|
183
|
+
translation is wrong, not the plugin. Check the size and the byte order: RetroAchievements'
|
|
184
|
+
N64 addresses are little-endian words, so a byte moves by `^3` and a 16-bit value by `^2`.
|
|
185
|
+
|
|
186
|
+
## When the tool can't run
|
|
187
|
+
|
|
188
|
+
- **RetroArch doesn't answer** (`didn't answer "READ_CORE_RAM …"`): network commands are off, or
|
|
189
|
+
the port is taken. Check the appended config.
|
|
190
|
+
- **No state from the daemon:** is the daemon running with your plugin (its log lists the
|
|
191
|
+
plugins it loaded), and does `validate` pass? Does the ROM's build id match one in
|
|
192
|
+
`supportedBuildIds`? The daemon reports an unsupported build to the page.
|
|
193
|
+
- **The game never starts** (the emulator idles at about 0% CPU): the display or GPU stack is
|
|
194
|
+
broken (seen in WSL). Restart it; that's not the plugin.
|
package/template/gitignore
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { Bytes } from '@gameslate/sdk';
|
|
4
|
+
import { Bytes, checkCatalogue } from '@gameslate/sdk';
|
|
5
5
|
import { buildPlugin } from '@gameslate/sdk/build';
|
|
6
6
|
import { inspectPlugin, loadQuickJs, readPluginManifest } from '@gameslate/sdk/host';
|
|
7
7
|
import type { GameMemory } from '@gameslate/sdk/plugin';
|
|
@@ -23,7 +23,8 @@ it('reads health in the sandbox', async () => {
|
|
|
23
23
|
});
|
|
24
24
|
if (typeof plugin === 'string') throw new Error(plugin);
|
|
25
25
|
const memory: GameMemory = {
|
|
26
|
-
|
|
26
|
+
/* the core attaches only to a build the source verified (plugin/live.ts) */
|
|
27
|
+
buildId: '0000000000000000000000000000000000000000',
|
|
27
28
|
commandLine: [],
|
|
28
29
|
moduleBase: 0n,
|
|
29
30
|
read: () => new Bytes(Uint8Array.of(73, 0, 0, 0)),
|
|
@@ -33,4 +34,6 @@ it('reads health in the sandbox', async () => {
|
|
|
33
34
|
};
|
|
34
35
|
const state = plugin.live.sources[0]?.createSession(memory)?.poll();
|
|
35
36
|
expect(state?.counters).toEqual({ health: 73 });
|
|
37
|
+
/* the pack contract: every condition, slot and counter names something the catalogue has */
|
|
38
|
+
for (const pack of plugin.live.packs) expect(checkCatalogue(pack.catalogue)).toEqual([]);
|
|
36
39
|
});
|