@gameslate/sdk 0.3.6 → 0.3.7
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 +17 -0
- package/bin/gameslate-plugin.mjs +14 -0
- package/build/init-plugin.mjs +2 -0
- package/build/verify-effects.mjs +120 -0
- package/lib/assets.d.ts +155 -8
- package/lib/assets.js +15 -2
- package/lib/catalogue.d.ts +6 -6
- package/lib/host/asset-sandbox.d.ts +17 -3
- package/lib/host/asset-sandbox.js +27 -6
- package/lib/host/index.d.ts +1 -0
- package/lib/host/index.js +1 -0
- package/lib/host/quickjs-guest.d.ts +3 -0
- package/lib/host/quickjs-guest.js +17 -1
- package/lib/host/verify.d.ts +210 -0
- package/lib/host/verify.js +146 -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 +182 -0
- package/template/claude/skills/verify-gameslate-plugin/SKILL.md +121 -0
- package/template/test/live.test.ts +5 -2
package/lib/plugin-manifest.js
CHANGED
|
@@ -16,15 +16,39 @@ const Id = z
|
|
|
16
16
|
.regex(/^[a-z0-9][a-z0-9-]*$/, 'plugin and game ids are lower-case words and dashes');
|
|
17
17
|
/* a file next to the manifest, never a path out of the plugin's folder */
|
|
18
18
|
const FileName = z.string().regex(/^[A-Za-z0-9_][A-Za-z0-9_.-]*$/, 'a plain file name');
|
|
19
|
-
/*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
/* Hidden folders where games live; any other (`~/.ssh`, `~/.config/gameslate` with the pairing
|
|
20
|
+
* token) is refused, since a sandboxed plugin can read every file in an offered folder and show
|
|
21
|
+
* it in what it builds. */
|
|
22
|
+
const GAME_DOT_FOLDERS = ['~/.var/app/', '~/.local/share/', '~/.steam/'];
|
|
23
|
+
const OWN_FOLDER = '~/.local/share/gameslate';
|
|
24
|
+
/** Why a manifest may not offer `folder`, or null. */
|
|
25
|
+
export function homeFolderProblem(folder) {
|
|
26
|
+
if (!/^~\/[^\0]+$/.test(folder))
|
|
27
|
+
return 'a folder under the home directory, starting with ~/';
|
|
28
|
+
const parts = folder.split('/');
|
|
29
|
+
if (parts.includes('..') || parts.includes('.'))
|
|
30
|
+
return 'no "." or ".." in folders';
|
|
31
|
+
const prefix = GAME_DOT_FOLDERS.find(p => folder.startsWith(p));
|
|
32
|
+
const rest = prefix ? folder.slice(prefix.length) : folder.slice(2);
|
|
33
|
+
if (rest === '' || rest.split('/').some(p => p.startsWith('.')))
|
|
34
|
+
return `a game's folder: no hidden folders except under ${GAME_DOT_FOLDERS.join(', ')}`;
|
|
35
|
+
if (`${folder}/`.startsWith(`${OWN_FOLDER}/`))
|
|
36
|
+
return "not GameSlate's own folder";
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
/* A folder under the player's home (`~/...`) that a game's files may be in. */
|
|
40
|
+
const HomeFolder = z.string().superRefine((p, ctx) => {
|
|
41
|
+
const problem = homeFolderProblem(p);
|
|
42
|
+
if (problem)
|
|
43
|
+
ctx.addIssue({ code: 'custom', message: problem });
|
|
44
|
+
});
|
|
24
45
|
/** Where to find the files an extractor builds from, offered to the player to pick from. */
|
|
25
46
|
const InputLocation = z.object({
|
|
26
47
|
label: z.string().min(1).max(100),
|
|
27
48
|
folders: z.array(HomeFolder).min(1).max(20),
|
|
49
|
+
/** folders inside the picked one whose files are inputs too, named `<subfolder>/<file>`
|
|
50
|
+
* (e.g. a port's `mods`) */
|
|
51
|
+
subfolders: z.array(FileName).max(10).optional(),
|
|
28
52
|
});
|
|
29
53
|
const CodeFile = z.object({
|
|
30
54
|
file: FileName,
|
|
@@ -41,12 +65,15 @@ export const PluginManifestSchema = z.object({
|
|
|
41
65
|
code: CodeFile,
|
|
42
66
|
/** asset extractors, run in the core's sandbox by extraction jobs */
|
|
43
67
|
assets: CodeFile.optional(),
|
|
44
|
-
/**
|
|
68
|
+
/** steps that run unsandboxed after a game's extraction job (e.g. data fetched over the
|
|
69
|
+
* network); the Python renderer's hooks lived here too */
|
|
45
70
|
extract: CodeFile.optional(),
|
|
46
71
|
games: z
|
|
47
72
|
.array(z.object({
|
|
48
73
|
id: Id,
|
|
49
74
|
title: z.string().min(1),
|
|
75
|
+
/** short names a player may type for it (`gameslate extract-assets oot`) */
|
|
76
|
+
aliases: z.array(Id).max(5).optional(),
|
|
50
77
|
/** where the player's own files for asset extraction usually are */
|
|
51
78
|
inputs: z.array(InputLocation).default([]),
|
|
52
79
|
}))
|
package/lib/plugins-api.d.ts
CHANGED
|
@@ -134,7 +134,10 @@ export declare const JobStatusSchema: z.ZodObject<{
|
|
|
134
134
|
/** assets skipped because an earlier run built them from the same code and inputs */
|
|
135
135
|
upToDate: z.ZodNumber;
|
|
136
136
|
failed: z.ZodNumber;
|
|
137
|
+
/** the asset that finished last */
|
|
137
138
|
current: z.ZodOptional<z.ZodString>;
|
|
139
|
+
/** the assets being built right now (several, across builder threads) */
|
|
140
|
+
building: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
138
141
|
notes: z.ZodArray<z.ZodString, "many">;
|
|
139
142
|
failures: z.ZodArray<z.ZodObject<{
|
|
140
143
|
label: z.ZodString;
|
|
@@ -164,6 +167,7 @@ export declare const JobStatusSchema: z.ZodObject<{
|
|
|
164
167
|
}[];
|
|
165
168
|
current?: string | undefined;
|
|
166
169
|
error?: string | undefined;
|
|
170
|
+
building?: string[] | undefined;
|
|
167
171
|
}, {
|
|
168
172
|
id: number;
|
|
169
173
|
done: number;
|
|
@@ -181,6 +185,7 @@ export declare const JobStatusSchema: z.ZodObject<{
|
|
|
181
185
|
}[];
|
|
182
186
|
current?: string | undefined;
|
|
183
187
|
error?: string | undefined;
|
|
188
|
+
building?: string[] | undefined;
|
|
184
189
|
}>;
|
|
185
190
|
export type JobStatus = z.infer<typeof JobStatusSchema>;
|
|
186
191
|
export declare const PluginsResponseSchema: z.ZodObject<{
|
|
@@ -317,7 +322,10 @@ export declare const PluginsResponseSchema: z.ZodObject<{
|
|
|
317
322
|
/** assets skipped because an earlier run built them from the same code and inputs */
|
|
318
323
|
upToDate: z.ZodNumber;
|
|
319
324
|
failed: z.ZodNumber;
|
|
325
|
+
/** the asset that finished last */
|
|
320
326
|
current: z.ZodOptional<z.ZodString>;
|
|
327
|
+
/** the assets being built right now (several, across builder threads) */
|
|
328
|
+
building: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
321
329
|
notes: z.ZodArray<z.ZodString, "many">;
|
|
322
330
|
failures: z.ZodArray<z.ZodObject<{
|
|
323
331
|
label: z.ZodString;
|
|
@@ -347,6 +355,7 @@ export declare const PluginsResponseSchema: z.ZodObject<{
|
|
|
347
355
|
}[];
|
|
348
356
|
current?: string | undefined;
|
|
349
357
|
error?: string | undefined;
|
|
358
|
+
building?: string[] | undefined;
|
|
350
359
|
}, {
|
|
351
360
|
id: number;
|
|
352
361
|
done: number;
|
|
@@ -364,6 +373,7 @@ export declare const PluginsResponseSchema: z.ZodObject<{
|
|
|
364
373
|
}[];
|
|
365
374
|
current?: string | undefined;
|
|
366
375
|
error?: string | undefined;
|
|
376
|
+
building?: string[] | undefined;
|
|
367
377
|
}>>;
|
|
368
378
|
}, "strip", z.ZodTypeAny, {
|
|
369
379
|
plugins: {
|
|
@@ -407,6 +417,7 @@ export declare const PluginsResponseSchema: z.ZodObject<{
|
|
|
407
417
|
}[];
|
|
408
418
|
current?: string | undefined;
|
|
409
419
|
error?: string | undefined;
|
|
420
|
+
building?: string[] | undefined;
|
|
410
421
|
} | null;
|
|
411
422
|
}, {
|
|
412
423
|
plugins: {
|
|
@@ -450,6 +461,7 @@ export declare const PluginsResponseSchema: z.ZodObject<{
|
|
|
450
461
|
}[];
|
|
451
462
|
current?: string | undefined;
|
|
452
463
|
error?: string | undefined;
|
|
464
|
+
building?: string[] | undefined;
|
|
453
465
|
} | null;
|
|
454
466
|
}>;
|
|
455
467
|
export type PluginsResponse = z.infer<typeof PluginsResponseSchema>;
|
package/lib/plugins-api.js
CHANGED
|
@@ -29,7 +29,10 @@ export const JobStatusSchema = z.object({
|
|
|
29
29
|
/** assets skipped because an earlier run built them from the same code and inputs */
|
|
30
30
|
upToDate: z.number().int(),
|
|
31
31
|
failed: z.number().int(),
|
|
32
|
+
/** the asset that finished last */
|
|
32
33
|
current: z.string().optional(),
|
|
34
|
+
/** the assets being built right now (several, across builder threads) */
|
|
35
|
+
building: z.array(z.string()).optional(),
|
|
33
36
|
notes: z.array(z.string()),
|
|
34
37
|
failures: z.array(z.object({ label: z.string(), error: z.string() })),
|
|
35
38
|
error: z.string().optional(),
|
|
@@ -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.7",
|
|
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,182 @@
|
|
|
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
|
+
## 4. Memory addresses, verified
|
|
73
|
+
|
|
74
|
+
**Pin the build.** List the exact builds you verified in the source's `supportedBuildIds` (a
|
|
75
|
+
`Map` from build id to `{ region }` on the `GamePlugin` in `live.ts`, not in the manifest):
|
|
76
|
+
|
|
77
|
+
- ELF or PE build id for PC games;
|
|
78
|
+
- `CODE.version` from the ROM header for N64 (e.g. `CZLE.2`).
|
|
79
|
+
|
|
80
|
+
An unknown build means refuse to attach, never "try the nearest offsets".
|
|
81
|
+
|
|
82
|
+
**Open-source ports.** Compile a probe against the game's headers: print `sizeof` of a big struct
|
|
83
|
+
(it must equal what the shipped build uses) and the `offsetof` of each field. Put each value in
|
|
84
|
+
`offsets.ts`, with a comment naming the struct field and where the number came from. Header
|
|
85
|
+
comments like `/* 0x0E9C */` are not a source.
|
|
86
|
+
|
|
87
|
+
**Console decompilations:**
|
|
88
|
+
|
|
89
|
+
1. Build the decomp and check the output's **md5 equals the player's ROM**. Mind the region: some
|
|
90
|
+
Makefiles default to another region and still print "OK" against their own checksum.
|
|
91
|
+
2. Probe the struct offsets by compiling the decomp's headers for the console's ABI. For N64 that's
|
|
92
|
+
MIPS o32: `clang --target=mips-unknown-linux-gnu -mabi=32 -S`, then read the constants back.
|
|
93
|
+
3. Take global addresses from the build's symbol map.
|
|
94
|
+
4. If a global pointer outlives its object (a pointer that isn't cleared when the scene unloads),
|
|
95
|
+
trust it only with a check from the same build, such as "this state's update function is the
|
|
96
|
+
one the map says".
|
|
97
|
+
|
|
98
|
+
**Leads, from LiveSplit or RetroAchievements:**
|
|
99
|
+
|
|
100
|
+
- A lead is not a source. Verify every value live, across levels, menus and loads.
|
|
101
|
+
- Record where it came from, and **never copy their code**: addresses are facts, scripts aren't.
|
|
102
|
+
- **RetroAchievements N64 addresses are in the emulator's little-endian 32-bit words.** To get the
|
|
103
|
+
console's big-endian address: byte = address ^ 3, 16-bit = address ^ 2, 32-bit as is.
|
|
104
|
+
- RA notes are per game, not per revision. Struct offsets carry across revisions; absolute
|
|
105
|
+
addresses don't.
|
|
106
|
+
- A byte-pattern lead stays a pattern: read it with `memory.scan({ pattern, kind, offset })`, so it
|
|
107
|
+
survives patches. It must match exactly once.
|
|
108
|
+
|
|
109
|
+
**Reading:** read whole blocks (the save struct in one read) where the values sit together.
|
|
110
|
+
Sample with `seqlockSample(readFrameCounter, readPayload)` (from `@gameslate/sdk/plugin`) so a
|
|
111
|
+
frame isn't half old and half new: it rereads until the game's frame counter is the same before
|
|
112
|
+
and after. A game without a frame counter you can read has nothing to sample against: read once
|
|
113
|
+
per poll. Numbers are explicit about width, sign and byte order (`readUInt16BE` for N64,
|
|
114
|
+
`readInt32LE` for PC).
|
|
115
|
+
|
|
116
|
+
## 5. Assets (optional): maps, icons, meshes from the player's files
|
|
117
|
+
|
|
118
|
+
`assets.ts` exports an extractor per game:
|
|
119
|
+
|
|
120
|
+
- `listAssets(inputs, pick)` must be cheap: name what can be built.
|
|
121
|
+
- `buildAsset(id, inputs)` returns outputs in the SDK's shapes: floorplan, location, nav, mesh
|
|
122
|
+
(GS3D), and image.
|
|
123
|
+
|
|
124
|
+
Images have a `purpose` (`atlas`, `map`, `icon`, `actor`, which picks the folder) and an `encoding`:
|
|
125
|
+
|
|
126
|
+
- PNG;
|
|
127
|
+
- `{ format: 'webp', lossless: true }`;
|
|
128
|
+
- `{ format: 'webp', quality: 88 }`.
|
|
129
|
+
|
|
130
|
+
Every image of a game uses one format. In the sandbox:
|
|
131
|
+
|
|
132
|
+
- **No `TextDecoder`, `TextEncoder` or `Buffer`.** Decode UTF-8 by hand, and decode files in
|
|
133
|
+
chunks (`String.fromCharCode(...bytes)` has an argument limit).
|
|
134
|
+
- **One asset per unit of work** (per map, per actor): each gets its own time budget (10 minutes)
|
|
135
|
+
and its own up-to-date stamp, and jobs build assets across several threads.
|
|
136
|
+
- Inputs are named relative to the folder the player picked (`mods/pack.o2r`). The core also hands
|
|
137
|
+
in the game's registry manifest as `registry/manifest.json` when there is one, so renders line up
|
|
138
|
+
with the registry's maps.
|
|
139
|
+
- **Data licensing:** ship the extractor, never its output. Textures, models and renders are
|
|
140
|
+
built on the player's machine and never committed.
|
|
141
|
+
|
|
142
|
+
## 6. Tests
|
|
143
|
+
|
|
144
|
+
- **Decoders:** fixture snapshot in, expected `GameState` out, including menus, no save, and edge
|
|
145
|
+
values.
|
|
146
|
+
- **Conditions:** table tests, one row per branch.
|
|
147
|
+
- **The sandbox bundle:** the template's test runs the built `live.js` in the core's sandbox. Keep
|
|
148
|
+
it, and add an extraction test on a synthetic archive.
|
|
149
|
+
- **Ports of existing tools:** compare against the original's real output with **the same library
|
|
150
|
+
versions** that made it. A newer Pillow or numpy changes pixels on its own: Pillow 12 changed its
|
|
151
|
+
resample order, and numpy's matmul differs per CPU.
|
|
152
|
+
- **Every bug fix gets a test that fails without the fix.** Break the code, watch it fail, restore.
|
|
153
|
+
- **No game data in fixtures:** build synthetic ones (bytes you wrote) and record what the reference
|
|
154
|
+
tool produced from them.
|
|
155
|
+
|
|
156
|
+
## 7. Verify live
|
|
157
|
+
|
|
158
|
+
Use the `verify-gameslate-plugin` skill. It runs the game from a save state, reads what your plugin
|
|
159
|
+
reports, screenshots the game and GameSlate, and checks them against `verify.json`. Until a build
|
|
160
|
+
passes, say so in the README ("unverified: offsets from leads") and keep it out of a release.
|
|
161
|
+
|
|
162
|
+
## 8. Release
|
|
163
|
+
|
|
164
|
+
```sh
|
|
165
|
+
yarn check
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
That's the typecheck, the tests, the build, then `validate dist/<id>`, which checks the built
|
|
169
|
+
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
|
|
170
|
+
`plugins.lock.json` (an entry with the release URL and its sha256).
|
|
171
|
+
|
|
172
|
+
## Pitfalls seen in real plugins
|
|
173
|
+
|
|
174
|
+
- **Texture packs:** a port's HD packs (`mods/*.o2r`) replace textures. Read them the way the game
|
|
175
|
+
does: packs first, in name order, each preferring its `alt/` asset, then the base archive.
|
|
176
|
+
Otherwise you overwrite HD output with vanilla.
|
|
177
|
+
- **Big inputs:** files over 256 MiB are identified by size and modification time, not hashed.
|
|
178
|
+
Don't rely on a byte change inside a huge file being noticed unless its size or mtime changes too.
|
|
179
|
+
- **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.
|
|
181
|
+
- **Prove it on real data before writing to a player's files.** Back up what's there before the
|
|
182
|
+
first run on a real machine.
|
|
@@ -0,0 +1,121 @@
|
|
|
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 (GameSlate's `docs/emulator-driving.md`):
|
|
23
|
+
|
|
24
|
+
1. **Pause:** `SIGSTOP` the emulator process. `SIGCONT` resumes it. Memory stays readable while
|
|
25
|
+
it's stopped.
|
|
26
|
+
2. **Read the plugin:** a local GameSlate daemon with your build reports the state over its
|
|
27
|
+
WebSocket (step 4 below).
|
|
28
|
+
3. **Read the screen from the game's own memory**, not the window: libultra's `__osViCurr`
|
|
29
|
+
points at the video context, whose word at +4 is the framebuffer (RGBA5551, 320×240 for most
|
|
30
|
+
games). Without symbols, find `__osViCurr` as two adjacent words in the first 4 MB pointing at
|
|
31
|
+
two contexts 0x30 bytes apart that sit just before them, each holding a framebuffer pointer.
|
|
32
|
+
Grabbing an emulator's window can come back black (WSLg, GPU surfaces).
|
|
33
|
+
4. **Press buttons:** XTEST key events into the emulator's window (Gopher64 maps Start to Return,
|
|
34
|
+
A to Left Shift, B to Left Ctrl, Z to `z`, the stick to the arrows).
|
|
35
|
+
5. **Wait on state, not time:** after each input, read until the game state you expect appears
|
|
36
|
+
(for example "game state = racing"), with a timeout.
|
|
37
|
+
|
|
38
|
+
Script the route per game as inputs plus checks, such as "Start until game state 4, hold A for
|
|
39
|
+
9 s, expect place and lap". Prefer moments a route reaches from boot.
|
|
40
|
+
|
|
41
|
+
- **Deeper moments:** TASVideos input recordings replay from boot to documented frames (check
|
|
42
|
+
that the replay arrived; they can drift between emulator versions). Battery saves
|
|
43
|
+
(`.eep`/`.sra`) work across emulators. A save state is the last resort: tied to one emulator
|
|
44
|
+
version, and it needs a person to make it. Keep saves and states out of the repo: they're game
|
|
45
|
+
data.
|
|
46
|
+
- **RetroArch** can load a state at start (`-e <slot>`) and answers network commands, but its
|
|
47
|
+
N64 core crashed on one dev machine. Check that it boots a game before relying on it.
|
|
48
|
+
- **PC games:** a save file at that moment, loaded by hand. Then the tool only reads; leave
|
|
49
|
+
`retroarch` out of the spec.
|
|
50
|
+
|
|
51
|
+
## 3. Write `verify.json`
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"game": "2ship2harkinian",
|
|
56
|
+
"retroarch": {
|
|
57
|
+
"binary": "/path/to/retroarch",
|
|
58
|
+
"core": "/path/to/mupen64plus_next_libretro.so",
|
|
59
|
+
"rom": "/path/to/game.z64",
|
|
60
|
+
"stateSlot": 1,
|
|
61
|
+
"config": "verify-retroarch.cfg"
|
|
62
|
+
},
|
|
63
|
+
"ui": "http://localhost:4310/",
|
|
64
|
+
"settleMs": 5000,
|
|
65
|
+
"expect": {
|
|
66
|
+
"phase": "in_stage",
|
|
67
|
+
"locationId": "south_clock_town",
|
|
68
|
+
"difficulty": "day_1",
|
|
69
|
+
"counters": { "rupees": 123, "health": { "min": 0.4, "max": 0.6 } }
|
|
70
|
+
},
|
|
71
|
+
"memory": [{ "address": "0x801EF6AA", "size": 2, "signed": true, "counter": "rupees" }]
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
- 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 state stay on your machine.
|
|
77
|
+
- `memory` reads each address through RetroArch (`READ_CORE_RAM`, RetroAchievements'
|
|
78
|
+
addressing; the tool converts a guest address for you) and requires it to equal the plugin's
|
|
79
|
+
counter. That second opinion catches a wrong offset that still looks plausible. Use it for at
|
|
80
|
+
least one value per struct the plugin reads (save, live game state).
|
|
81
|
+
- Where only a game's parent may read its memory (ptrace_scope 1, as on ChimeraOS), add
|
|
82
|
+
`"launchPrefix": ["node", "<gameslate>/dist/gameslate.mjs", "run", "--"]` so the game starts
|
|
83
|
+
through GameSlate's launch wrapper.
|
|
84
|
+
|
|
85
|
+
## 4. Run it
|
|
86
|
+
|
|
87
|
+
1. Build the plugin: `yarn check`.
|
|
88
|
+
2. Start a local GameSlate daemon with your build:
|
|
89
|
+
`GAMESLATE_PLUGINS_DIR=$PWD/dist node <gameslate>/dist/gameslate.mjs`.
|
|
90
|
+
3. `yarn dlx -p @gameslate/sdk gameslate-plugin verify verify/<moment>.json`
|
|
91
|
+
|
|
92
|
+
It starts RetroArch on the state, waits `settleMs`, then reads the daemon's next state for the
|
|
93
|
+
game. It compares that state with `expect` and the emulator's reads with `memory`, takes a game
|
|
94
|
+
screenshot (RetroArch's `SCREENSHOT`, into its screenshot directory), and screenshots the
|
|
95
|
+
GameSlate page if Playwright is installed. Then it stops RetroArch. It exits 0 only when
|
|
96
|
+
everything matched.
|
|
97
|
+
|
|
98
|
+
## 5. Look at the screenshots
|
|
99
|
+
|
|
100
|
+
The JSON checks what you predicted. The screenshots catch what you didn't: a pin in the wrong
|
|
101
|
+
room, a counter shown under the wrong label, a menu reported as gameplay. Open both and compare
|
|
102
|
+
them with the game's screen. Write down anything odd as a finding, even if the JSON passed.
|
|
103
|
+
|
|
104
|
+
## 6. Record the result
|
|
105
|
+
|
|
106
|
+
- In the README, list each verified build id with the date, the moments, and the emulator.
|
|
107
|
+
- A failure is a finding about the offsets, never about the expectation. Don't loosen
|
|
108
|
+
`expect` to make it pass. Find which read is wrong; the `memory` checks usually say which.
|
|
109
|
+
- An emulator that disagrees with the plugin on a value the screen confirms means the
|
|
110
|
+
translation is wrong, not the plugin. Check the size and the byte order: RetroAchievements'
|
|
111
|
+
N64 addresses are little-endian words, so a byte moves by `^3` and a 16-bit value by `^2`.
|
|
112
|
+
|
|
113
|
+
## When the tool can't run
|
|
114
|
+
|
|
115
|
+
- **RetroArch doesn't answer** (`didn't answer "READ_CORE_RAM …"`): network commands are off, or
|
|
116
|
+
the port is taken. Check the appended config.
|
|
117
|
+
- **No state from the daemon:** is the daemon running with your plugin (its log lists the
|
|
118
|
+
plugins it loaded), and does `validate` pass? Does the ROM's build id match one in
|
|
119
|
+
`supportedBuildIds`? The daemon reports an unsupported build to the page.
|
|
120
|
+
- **The game never starts** (the emulator idles at about 0% CPU): the display or GPU stack is
|
|
121
|
+
broken (seen in WSL). Restart it; that's not the plugin.
|
|
@@ -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
|
});
|