@gameslate/sdk 0.3.5 → 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 +26 -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/live-sandbox.js +10 -1
- 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 +2 -0
- package/lib/index.js +2 -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 +16 -1
- package/lib/plugin/sandbox-guest.js +8 -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 +10 -8
- package/lib/signature.d.ts +46 -0
- package/lib/signature.js +80 -0
- 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
|
@@ -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
|
});
|