@gameslate/sdk 0.3.7 → 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 +20 -0
- package/bin/gameslate-plugin.mjs +63 -2
- package/build/verify-effects.mjs +75 -7
- package/lib/host/addresses.d.ts +103 -0
- package/lib/host/addresses.js +150 -0
- package/lib/host/index.d.ts +1 -0
- package/lib/host/index.js +1 -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/verify.d.ts +705 -8
- package/lib/host/verify.js +160 -14
- package/package.json +1 -1
- package/template/claude/skills/build-gameslate-plugin/SKILL.md +101 -3
- package/template/claude/skills/verify-gameslate-plugin/SKILL.md +97 -24
- package/template/gitignore +5 -0
package/lib/host/verify.js
CHANGED
|
@@ -13,6 +13,50 @@ const Hex = z
|
|
|
13
13
|
.regex(/^0x[0-9a-fA-F]{1,8}$/, 'a hex address such as 0x801EF6AA')
|
|
14
14
|
.transform(h => Number.parseInt(h, 16));
|
|
15
15
|
const Expected = z.union([z.number(), z.object({ min: z.number(), max: z.number() })]);
|
|
16
|
+
/** A guest value to watch while driving: `{ "peek": "0x800dc50c:4", "equals": 4 }`. */
|
|
17
|
+
const PeekCheck = z.object({
|
|
18
|
+
peek: z.string().regex(/^0x[0-9a-fA-F]{1,8}:[124]$/, 'a guest address and size: 0x800dc50c:4'),
|
|
19
|
+
equals: z.number().int(),
|
|
20
|
+
});
|
|
21
|
+
/** What a moment must read: the plugin's state, field by field (counters exact or in a range). */
|
|
22
|
+
const ExpectSchema = z.object({
|
|
23
|
+
phase: z.string().optional(),
|
|
24
|
+
locationId: z.string().optional(),
|
|
25
|
+
difficulty: z.string().optional(),
|
|
26
|
+
variant: z.string().optional(),
|
|
27
|
+
roomId: z.number().int().optional(),
|
|
28
|
+
counters: z.record(z.string(), Expected).default({}),
|
|
29
|
+
});
|
|
30
|
+
/** Wait on the plugin's own state, for moments no fixed address shows (a PlayState that moves):
|
|
31
|
+
* `{ "state": { "phase": "in_stage", "locationId": "lost_woods_intro" } }`. */
|
|
32
|
+
const StateCheck = z.object({ state: ExpectSchema });
|
|
33
|
+
/* `times`: how many reads in a row must match. Transitions can pass through a state for a frame
|
|
34
|
+
* (MM's opening reads as gameplay between its scripted shots), which shouldn't count. */
|
|
35
|
+
const Times = { times: z.number().int().min(1).default(1) };
|
|
36
|
+
const WaitCheck = z.union([PeekCheck.extend(Times), StateCheck.extend(Times)]);
|
|
37
|
+
/* One step of driving the game to its moment, run through `gameslate drive`. */
|
|
38
|
+
const StepSchema = z.union([
|
|
39
|
+
z.object({
|
|
40
|
+
/** a key (X keysym name) to press, once, or until a value matches; several keys take
|
|
41
|
+
* turns (a map where Start selects and A reads on through the briefing) */
|
|
42
|
+
press: z.union([z.string().min(1), z.array(z.string().min(1)).min(1)]),
|
|
43
|
+
holdMs: z.number().int().min(0).default(100),
|
|
44
|
+
until: WaitCheck.optional(),
|
|
45
|
+
everyMs: z.number().int().min(0).default(2000),
|
|
46
|
+
maxTries: z.number().int().min(1).default(20),
|
|
47
|
+
}),
|
|
48
|
+
z.object({
|
|
49
|
+
waitFor: WaitCheck,
|
|
50
|
+
timeoutMs: z.number().int().min(0).default(30_000),
|
|
51
|
+
everyMs: z.number().int().min(100).default(1000),
|
|
52
|
+
}),
|
|
53
|
+
/** the screen the game drew, saved under this name beside the spec */
|
|
54
|
+
z.object({ frame: z.string().min(1) }),
|
|
55
|
+
/** a pause, for screens nothing in memory marks (a boot, a menu's fade) */
|
|
56
|
+
z.object({ waitMs: z.number().int().min(0) }),
|
|
57
|
+
]);
|
|
58
|
+
/* the web app's tabs; one missing for a game (a pack without missions) is reported, not an error */
|
|
59
|
+
const UI_TABS = ['Map', 'Inventory', 'Missions', 'Ref'];
|
|
16
60
|
export const VerifySpecSchema = z.object({
|
|
17
61
|
/** the game id the daemon must report */
|
|
18
62
|
game: z.string().min(1),
|
|
@@ -31,20 +75,31 @@ export const VerifySpecSchema = z.object({
|
|
|
31
75
|
port: z.number().int().default(55355),
|
|
32
76
|
})
|
|
33
77
|
.optional(),
|
|
78
|
+
/** any emulator, started with this command (the ROM on its command line, so the core finds it) */
|
|
79
|
+
emulator: z
|
|
80
|
+
.object({
|
|
81
|
+
command: z.array(z.string()).min(1),
|
|
82
|
+
/** as for RetroArch: through GameSlate's launch wrapper where only a parent may read */
|
|
83
|
+
launchPrefix: z.array(z.string()).default([]),
|
|
84
|
+
})
|
|
85
|
+
.optional(),
|
|
86
|
+
/** GameSlate's `dist/gameslate.mjs`, whose `drive` commands run the steps */
|
|
87
|
+
gameslate: z.string().optional(),
|
|
88
|
+
/** how to get to the moment: keys, waits on values, screenshots (docs/emulator-driving.md) */
|
|
89
|
+
steps: z.array(StepSchema).default([]),
|
|
34
90
|
daemon: z.object({ url: z.string().default('ws://localhost:4310/ws') }).default({}),
|
|
35
|
-
/** the GameSlate page to screenshot beside the game
|
|
36
|
-
|
|
91
|
+
/** the GameSlate page to screenshot beside the game: a URL (with its `#token=`), or the URL and
|
|
92
|
+
* the tabs to open and screenshot one by one at the moment */
|
|
93
|
+
ui: z
|
|
94
|
+
.union([
|
|
95
|
+
z.string().transform(url => ({ url, tabs: [...UI_TABS] })),
|
|
96
|
+
z.object({ url: z.string(), tabs: z.array(z.string().min(1)).default([...UI_TABS]) }),
|
|
97
|
+
])
|
|
98
|
+
.optional(),
|
|
37
99
|
/** how long to let the game run before reading */
|
|
38
100
|
settleMs: z.number().int().min(0).default(5000),
|
|
39
101
|
timeoutMs: z.number().int().min(1000).default(60_000),
|
|
40
|
-
expect:
|
|
41
|
-
phase: z.string().optional(),
|
|
42
|
-
locationId: z.string().optional(),
|
|
43
|
-
difficulty: z.string().optional(),
|
|
44
|
-
variant: z.string().optional(),
|
|
45
|
-
roomId: z.number().int().optional(),
|
|
46
|
-
counters: z.record(z.string(), Expected).default({}),
|
|
47
|
-
}),
|
|
102
|
+
expect: ExpectSchema,
|
|
48
103
|
/** values to read through the emulator too: each must equal the plugin's counter */
|
|
49
104
|
memory: z
|
|
50
105
|
.array(z
|
|
@@ -59,6 +114,25 @@ export const VerifySpecSchema = z.object({
|
|
|
59
114
|
}))
|
|
60
115
|
.default([]),
|
|
61
116
|
});
|
|
117
|
+
/**
|
|
118
|
+
* `${NAME}` in any string of a spec, from the environment, so a spec can be shared without one
|
|
119
|
+
* machine's paths (`"${GOPHER64}"`, `"${N64_ROMS}/Mario Kart 64 (U).z64"`). Throws on a name that
|
|
120
|
+
* isn't set.
|
|
121
|
+
*/
|
|
122
|
+
export function expandEnv(value, env) {
|
|
123
|
+
if (typeof value === 'string')
|
|
124
|
+
return value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (_, name) => {
|
|
125
|
+
const set = env[name];
|
|
126
|
+
if (set === undefined)
|
|
127
|
+
throw new Error(`the spec uses \${${name}}, which isn't set`);
|
|
128
|
+
return set;
|
|
129
|
+
});
|
|
130
|
+
if (Array.isArray(value))
|
|
131
|
+
return value.map(v => expandEnv(v, env));
|
|
132
|
+
if (typeof value === 'object' && value !== null)
|
|
133
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, expandEnv(v, env)]));
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
62
136
|
/** What doesn't match: one line each. */
|
|
63
137
|
export function stateMismatches(expect, state) {
|
|
64
138
|
const out = [];
|
|
@@ -116,20 +190,92 @@ async function memoryProblems(spec, state, effects) {
|
|
|
116
190
|
}
|
|
117
191
|
return out;
|
|
118
192
|
}
|
|
119
|
-
|
|
193
|
+
/* A watched value (through `gameslate drive peek`) or the plugin's state (from the daemon). */
|
|
194
|
+
async function checkMatches(d, check) {
|
|
195
|
+
if ('state' in check) {
|
|
196
|
+
const parsed = GameStateSchema.safeParse(await d.effects.state(d.spec));
|
|
197
|
+
return parsed.success && stateMismatches(check.state, parsed.data).length === 0;
|
|
198
|
+
}
|
|
199
|
+
const out = await d.effects.drive(d.spec, ['peek', String(d.pid), check.peek]);
|
|
200
|
+
const values = JSON.parse(out);
|
|
201
|
+
return (typeof values === 'object' &&
|
|
202
|
+
values !== null &&
|
|
203
|
+
Reflect.get(values, check.peek) === check.equals);
|
|
204
|
+
}
|
|
205
|
+
const describeCheck = (check) => 'state' in check
|
|
206
|
+
? `the state ${JSON.stringify(check.state)}`
|
|
207
|
+
: `${check.peek} = ${check.equals}`;
|
|
208
|
+
/* One step; a problem when it couldn't do what it says, or null. */
|
|
209
|
+
async function runStep(d, step, frames) {
|
|
210
|
+
if ('frame' in step) {
|
|
211
|
+
await d.effects.drive(d.spec, ['frame', String(d.pid), step.frame]);
|
|
212
|
+
frames.push(step.frame);
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
if ('waitMs' in step) {
|
|
216
|
+
await d.effects.wait(step.waitMs);
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
if ('waitFor' in step) {
|
|
220
|
+
let streak = 0;
|
|
221
|
+
for (let waited = 0; waited <= step.timeoutMs; waited += step.everyMs) {
|
|
222
|
+
streak = (await checkMatches(d, step.waitFor)) ? streak + 1 : 0;
|
|
223
|
+
if (streak >= step.waitFor.times)
|
|
224
|
+
return null;
|
|
225
|
+
await d.effects.wait(step.everyMs);
|
|
226
|
+
}
|
|
227
|
+
return `waited ${step.timeoutMs} ms for ${describeCheck(step.waitFor)}`;
|
|
228
|
+
}
|
|
229
|
+
const keys = typeof step.press === 'string' ? [step.press] : step.press;
|
|
230
|
+
let streak = 0;
|
|
231
|
+
for (let i = 0; i < (step.until ? step.maxTries : 1); i++) {
|
|
232
|
+
const key = keys[i % keys.length] ?? '';
|
|
233
|
+
await d.effects.drive(d.spec, ['press', '--pid', String(d.pid), key, String(step.holdMs)]);
|
|
234
|
+
if (!step.until)
|
|
235
|
+
return null;
|
|
236
|
+
await d.effects.wait(step.everyMs);
|
|
237
|
+
streak = (await checkMatches(d, step.until)) ? streak + 1 : 0;
|
|
238
|
+
if (streak >= step.until.times)
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
return `pressed ${keys.join('/')} ${step.maxTries} times without ${step.until ? describeCheck(step.until) : ''}`;
|
|
242
|
+
}
|
|
243
|
+
/** Drives the game to its moment; the first problem stops it. */
|
|
244
|
+
async function runSteps(spec, effects, pid) {
|
|
245
|
+
const frames = [];
|
|
246
|
+
if (!spec.steps.length)
|
|
247
|
+
return { problem: null, frames };
|
|
248
|
+
if (pid === undefined)
|
|
249
|
+
return { problem: 'steps need an emulator the run started', frames };
|
|
250
|
+
for (const step of spec.steps) {
|
|
251
|
+
const problem = await runStep({ spec, effects, pid }, step, frames).catch((e) => e instanceof Error ? e.message : String(e));
|
|
252
|
+
if (problem)
|
|
253
|
+
return { problem, frames };
|
|
254
|
+
}
|
|
255
|
+
return { problem: null, frames };
|
|
256
|
+
}
|
|
257
|
+
/** Runs one check: start the game, drive it to its moment, let it settle, compare, screenshot, stop. */
|
|
120
258
|
export async function runVerify(spec, effects) {
|
|
121
259
|
const game = await effects.launch(spec);
|
|
122
260
|
try {
|
|
261
|
+
const driven = await runSteps(spec, effects, game.pid);
|
|
262
|
+
if (driven.problem)
|
|
263
|
+
return {
|
|
264
|
+
ok: false,
|
|
265
|
+
problems: [driven.problem],
|
|
266
|
+
screenshots: driven.frames,
|
|
267
|
+
state: null,
|
|
268
|
+
};
|
|
123
269
|
await effects.wait(spec.settleMs);
|
|
124
270
|
const raw = await effects.state(spec).catch((e) => e);
|
|
125
271
|
if (raw instanceof Error)
|
|
126
|
-
return { ok: false, problems: [raw.message], screenshots:
|
|
272
|
+
return { ok: false, problems: [raw.message], screenshots: driven.frames, state: null };
|
|
127
273
|
const parsed = GameStateSchema.safeParse(raw);
|
|
128
274
|
if (!parsed.success)
|
|
129
275
|
return {
|
|
130
276
|
ok: false,
|
|
131
277
|
problems: [`the daemon's state: ${parsed.error.message}`],
|
|
132
|
-
screenshots:
|
|
278
|
+
screenshots: driven.frames,
|
|
133
279
|
state: null,
|
|
134
280
|
};
|
|
135
281
|
const state = parsed.data;
|
|
@@ -137,7 +283,7 @@ export async function runVerify(spec, effects) {
|
|
|
137
283
|
...stateMismatches(spec.expect, state),
|
|
138
284
|
...(await memoryProblems(spec, state, effects)),
|
|
139
285
|
];
|
|
140
|
-
const screenshots = await effects.screenshots(spec);
|
|
286
|
+
const screenshots = [...driven.frames, ...(await effects.screenshots(spec))];
|
|
141
287
|
return { ok: problems.length === 0, problems, screenshots, state };
|
|
142
288
|
}
|
|
143
289
|
finally {
|
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",
|
|
@@ -69,6 +69,22 @@ evaluator in the SDK decides "done", "collected" and "available". Rules:
|
|
|
69
69
|
- Give counters a `role` (`health`, `magic`, `armor`, `keys`) so shared UI finds them.
|
|
70
70
|
- Use `format: 'percent'` with a `max` for meters.
|
|
71
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
|
+
|
|
72
88
|
## 4. Memory addresses, verified
|
|
73
89
|
|
|
74
90
|
**Pin the build.** List the exact builds you verified in the source's `supportedBuildIds` (a
|
|
@@ -86,6 +102,40 @@ comments like `/* 0x0E9C */` are not a source.
|
|
|
86
102
|
|
|
87
103
|
**Console decompilations:**
|
|
88
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`.
|
|
89
139
|
1. Build the decomp and check the output's **md5 equals the player's ROM**. Mind the region: some
|
|
90
140
|
Makefiles default to another region and still print "OK" against their own checksum.
|
|
91
141
|
2. Probe the struct offsets by compiling the decomp's headers for the console's ABI. For N64 that's
|
|
@@ -95,6 +145,16 @@ comments like `/* 0x0E9C */` are not a source.
|
|
|
95
145
|
trust it only with a check from the same build, such as "this state's update function is the
|
|
96
146
|
one the map says".
|
|
97
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
|
+
|
|
98
158
|
**Leads, from LiveSplit or RetroAchievements:**
|
|
99
159
|
|
|
100
160
|
- A lead is not a source. Verify every value live, across levels, menus and loads.
|
|
@@ -139,6 +199,30 @@ Every image of a game uses one format. In the sandbox:
|
|
|
139
199
|
- **Data licensing:** ship the extractor, never its output. Textures, models and renders are
|
|
140
200
|
built on the player's machine and never committed.
|
|
141
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
|
+
|
|
142
226
|
## 6. Tests
|
|
143
227
|
|
|
144
228
|
- **Decoders:** fixture snapshot in, expected `GameState` out, including menus, no save, and edge
|
|
@@ -152,11 +236,18 @@ Every image of a game uses one format. In the sandbox:
|
|
|
152
236
|
- **Every bug fix gets a test that fails without the fix.** Break the code, watch it fail, restore.
|
|
153
237
|
- **No game data in fixtures:** build synthetic ones (bytes you wrote) and record what the reference
|
|
154
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.
|
|
155
246
|
|
|
156
247
|
## 7. Verify live
|
|
157
248
|
|
|
158
|
-
Use the `verify-gameslate-plugin` skill. It
|
|
159
|
-
reports, screenshots the game and GameSlate, and checks them against `verify.json`. Until a build
|
|
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
|
|
160
251
|
passes, say so in the README ("unverified: offsets from leads") and keep it out of a release.
|
|
161
252
|
|
|
162
253
|
## 8. Release
|
|
@@ -177,6 +268,13 @@ plugin exactly as the core will before running it. Then bump `version`, tag `vX.
|
|
|
177
268
|
- **Big inputs:** files over 256 MiB are identified by size and modification time, not hashed.
|
|
178
269
|
Don't rely on a byte change inside a huge file being noticed unless its size or mtime changes too.
|
|
179
270
|
- **Emulators:** the core finds an N64 game's RAM by the ROM's boot code. The ROM must be on the
|
|
180
|
-
emulator's command line, and the game must have booted.
|
|
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.
|
|
181
279
|
- **Prove it on real data before writing to a player's files.** Back up what's there before the
|
|
182
280
|
first run on a real machine.
|
|
@@ -19,7 +19,15 @@ one moment that's **not** gameplay (title or file select), so "no save loaded" i
|
|
|
19
19
|
## 2. Get to the moment
|
|
20
20
|
|
|
21
21
|
**Drive the game yourself; don't wait for a person.** For an emulated console, this loop is
|
|
22
|
-
proven
|
|
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:
|
|
23
31
|
|
|
24
32
|
1. **Pause:** `SIGSTOP` the emulator process. `SIGCONT` resumes it. Memory stays readable while
|
|
25
33
|
it's stopped.
|
|
@@ -50,31 +58,74 @@ Script the route per game as inputs plus checks, such as "Start until game state
|
|
|
50
58
|
|
|
51
59
|
## 3. Write `verify.json`
|
|
52
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
|
+
|
|
53
67
|
```json
|
|
54
68
|
{
|
|
55
|
-
"game": "
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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,
|
|
65
89
|
"expect": {
|
|
66
90
|
"phase": "in_stage",
|
|
67
|
-
"locationId": "
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
}
|
|
72
96
|
}
|
|
73
97
|
```
|
|
74
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.
|
|
75
125
|
- Paths are relative to the file. Keep one file per moment (`verify/<moment>.json`), next to the
|
|
76
|
-
tests. They hold no game data; the ROM and the
|
|
77
|
-
- `
|
|
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'
|
|
78
129
|
addressing; the tool converts a guest address for you) and requires it to equal the plugin's
|
|
79
130
|
counter. That second opinion catches a wrong offset that still looks plausible. Use it for at
|
|
80
131
|
least one value per struct the plugin reads (save, live game state).
|
|
@@ -84,23 +135,45 @@ Script the route per game as inputs plus checks, such as "Start until game state
|
|
|
84
135
|
|
|
85
136
|
## 4. Run it
|
|
86
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
|
+
|
|
87
146
|
1. Build the plugin: `yarn check`.
|
|
88
147
|
2. Start a local GameSlate daemon with your build:
|
|
89
148
|
`GAMESLATE_PLUGINS_DIR=$PWD/dist node <gameslate>/dist/gameslate.mjs`.
|
|
90
149
|
3. `yarn dlx -p @gameslate/sdk gameslate-plugin verify verify/<moment>.json`
|
|
91
150
|
|
|
92
|
-
It starts
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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.
|
|
97
157
|
|
|
98
|
-
## 5. Look at the screenshots
|
|
158
|
+
## 5. Look at the screenshots, and every tab
|
|
99
159
|
|
|
100
160
|
The JSON checks what you predicted. The screenshots catch what you didn't: a pin in the wrong
|
|
101
161
|
room, a counter shown under the wrong label, a menu reported as gameplay. Open both and compare
|
|
102
162
|
them with the game's screen. Write down anything odd as a finding, even if the JSON passed.
|
|
103
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
|
+
|
|
104
177
|
## 6. Record the result
|
|
105
178
|
|
|
106
179
|
- In the README, list each verified build id with the date, the moments, and the emulator.
|