@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.
@@ -1,4 +1,4 @@
1
- import { GameStateSchema, PackViewsSchema, SandboxDescriptionSchema, } from '../index.js';
1
+ import { SignatureSchema, GameStateSchema, PackViewsSchema, SandboxDescriptionSchema, } from '../index.js';
2
2
  import { errorText, QuickJsGuest } from './quickjs-guest.js';
3
3
  export { loadQuickJs } from './quickjs-guest.js';
4
4
  /*
@@ -193,6 +193,15 @@ export class PluginSandbox {
193
193
  refreshMappings: handle => {
194
194
  this.memory(handle).refreshMappings();
195
195
  },
196
+ /* the guest's signature is untrusted: parsed here, before the core scans anything */
197
+ scan: (handle, signature) => {
198
+ const memory = this.memory(handle);
199
+ if (!memory.scan)
200
+ throw new Error('signature scans are not available for this game');
201
+ const sig = SignatureSchema.parse(JSON.parse(vm().getString(signature)));
202
+ const at = memory.scan(sig);
203
+ return at === null ? vm().null : vm().newString(at.toString());
204
+ },
196
205
  };
197
206
  }
198
207
  }
@@ -15,6 +15,7 @@ export declare class QuickJsGuest {
15
15
  private readonly runtime;
16
16
  private readonly api;
17
17
  private disabled;
18
+ private corrupted;
18
19
  constructor(quickJs: QuickJSWASMModule, opts: {
19
20
  name: string;
20
21
  code: string;
@@ -28,6 +29,8 @@ export declare class QuickJsGuest {
28
29
  });
29
30
  /** Calls a guest function within the budget; its JSON-able result, dumped to the host. */
30
31
  call(fn: string, args: ReadonlyArray<string | number>): unknown;
32
+ /** whether it broke a limit and refuses every call from now on */
33
+ get switchedOff(): boolean;
31
34
  dispose(): void;
32
35
  private disable;
33
36
  private callGuest;
@@ -23,12 +23,16 @@ export async function loadQuickJs() {
23
23
  return newQuickJSWASMModuleFromVariant(newVariant(releaseSync, { wasmBinary }));
24
24
  }
25
25
  export const errorText = (e) => (e instanceof Error ? e.message : String(e));
26
+ const CORRUPTED_GUESTS = [];
26
27
  export class QuickJsGuest {
27
28
  opts;
28
29
  vm;
29
30
  runtime;
30
31
  api;
31
32
  disabled = null;
33
+ /* runaway guest recursion exhausts the host's stack mid-call and leaves the runtime holding
34
+ * objects it can't account for: freeing it then aborts the whole QuickJS module */
35
+ corrupted = false;
32
36
  constructor(quickJs, opts) {
33
37
  this.opts = opts;
34
38
  this.runtime = quickJs.newRuntime();
@@ -66,7 +70,9 @@ export class QuickJsGuest {
66
70
  }
67
71
  catch (e) {
68
72
  const message = errorText(e);
69
- if (/interrupted|out of memory|stack overflow/i.test(message))
73
+ if (/maximum call stack/i.test(message))
74
+ this.corrupted = true;
75
+ if (/interrupted|out of memory|stack overflow|maximum call stack/i.test(message))
70
76
  this.disable(message);
71
77
  throw e;
72
78
  }
@@ -78,7 +84,17 @@ export class QuickJsGuest {
78
84
  }
79
85
  }
80
86
  }
87
+ /** whether it broke a limit and refuses every call from now on */
88
+ get switchedOff() {
89
+ return this.disabled !== null;
90
+ }
81
91
  dispose() {
92
+ if (this.corrupted) {
93
+ /* never freed (see `corrupted`); kept referenced so the library's finaliser doesn't
94
+ * free it either. Its memory goes with the thread or process. */
95
+ CORRUPTED_GUESTS.push(this);
96
+ return;
97
+ }
82
98
  if (this.api.alive)
83
99
  this.api.dispose();
84
100
  this.vm.dispose();
@@ -0,0 +1,210 @@
1
+ import { z } from 'zod';
2
+ import { type GameState } from '../types.js';
3
+ export declare const VerifySpecSchema: z.ZodObject<{
4
+ /** the game id the daemon must report */
5
+ game: z.ZodString;
6
+ /** RetroArch with a core, a ROM and a save state slot, loaded on start (no input needed) */
7
+ retroarch: z.ZodOptional<z.ZodObject<{
8
+ binary: z.ZodString;
9
+ core: z.ZodString;
10
+ rom: z.ZodString;
11
+ stateSlot: z.ZodNumber;
12
+ /** run RetroArch through this (`["node", "<gameslate>/dist/gameslate.mjs", "run", "--"]`)
13
+ * where only a game's parent may read its memory (ptrace_scope 1, ChimeraOS) */
14
+ launchPrefix: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
15
+ /** a config appended to RetroArch's, which must turn network commands on */
16
+ config: z.ZodOptional<z.ZodString>;
17
+ port: z.ZodDefault<z.ZodNumber>;
18
+ }, "strip", z.ZodTypeAny, {
19
+ binary: string;
20
+ core: string;
21
+ rom: string;
22
+ stateSlot: number;
23
+ launchPrefix: string[];
24
+ port: number;
25
+ config?: string | undefined;
26
+ }, {
27
+ binary: string;
28
+ core: string;
29
+ rom: string;
30
+ stateSlot: number;
31
+ launchPrefix?: string[] | undefined;
32
+ config?: string | undefined;
33
+ port?: number | undefined;
34
+ }>>;
35
+ daemon: z.ZodDefault<z.ZodObject<{
36
+ url: z.ZodDefault<z.ZodString>;
37
+ }, "strip", z.ZodTypeAny, {
38
+ url: string;
39
+ }, {
40
+ url?: string | undefined;
41
+ }>>;
42
+ /** the GameSlate page to screenshot beside the game */
43
+ ui: z.ZodOptional<z.ZodString>;
44
+ /** how long to let the game run before reading */
45
+ settleMs: z.ZodDefault<z.ZodNumber>;
46
+ timeoutMs: z.ZodDefault<z.ZodNumber>;
47
+ expect: z.ZodObject<{
48
+ phase: z.ZodOptional<z.ZodString>;
49
+ locationId: z.ZodOptional<z.ZodString>;
50
+ difficulty: z.ZodOptional<z.ZodString>;
51
+ variant: z.ZodOptional<z.ZodString>;
52
+ roomId: z.ZodOptional<z.ZodNumber>;
53
+ counters: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodNumber, z.ZodObject<{
54
+ min: z.ZodNumber;
55
+ max: z.ZodNumber;
56
+ }, "strip", z.ZodTypeAny, {
57
+ min: number;
58
+ max: number;
59
+ }, {
60
+ min: number;
61
+ max: number;
62
+ }>]>>>;
63
+ }, "strip", z.ZodTypeAny, {
64
+ counters: Record<string, number | {
65
+ min: number;
66
+ max: number;
67
+ }>;
68
+ roomId?: number | undefined;
69
+ phase?: string | undefined;
70
+ locationId?: string | undefined;
71
+ difficulty?: string | undefined;
72
+ variant?: string | undefined;
73
+ }, {
74
+ roomId?: number | undefined;
75
+ phase?: string | undefined;
76
+ locationId?: string | undefined;
77
+ difficulty?: string | undefined;
78
+ variant?: string | undefined;
79
+ counters?: Record<string, number | {
80
+ min: number;
81
+ max: number;
82
+ }> | undefined;
83
+ }>;
84
+ /** values to read through the emulator too: each must equal the plugin's counter */
85
+ memory: z.ZodDefault<z.ZodArray<z.ZodEffects<z.ZodObject<{
86
+ address: z.ZodEffects<z.ZodString, number, string>;
87
+ size: z.ZodUnion<[z.ZodLiteral<1>, z.ZodLiteral<2>, z.ZodLiteral<4>]>;
88
+ signed: z.ZodDefault<z.ZodBoolean>;
89
+ counter: z.ZodString;
90
+ }, "strip", z.ZodTypeAny, {
91
+ counter: string;
92
+ size: 2 | 1 | 4;
93
+ address: number;
94
+ signed: boolean;
95
+ }, {
96
+ counter: string;
97
+ size: 2 | 1 | 4;
98
+ address: string;
99
+ signed?: boolean | undefined;
100
+ }>, {
101
+ counter: string;
102
+ size: 2 | 1 | 4;
103
+ address: number;
104
+ signed: boolean;
105
+ }, {
106
+ counter: string;
107
+ size: 2 | 1 | 4;
108
+ address: string;
109
+ signed?: boolean | undefined;
110
+ }>, "many">>;
111
+ }, "strip", z.ZodTypeAny, {
112
+ game: string;
113
+ daemon: {
114
+ url: string;
115
+ };
116
+ settleMs: number;
117
+ timeoutMs: number;
118
+ expect: {
119
+ counters: Record<string, number | {
120
+ min: number;
121
+ max: number;
122
+ }>;
123
+ roomId?: number | undefined;
124
+ phase?: string | undefined;
125
+ locationId?: string | undefined;
126
+ difficulty?: string | undefined;
127
+ variant?: string | undefined;
128
+ };
129
+ memory: {
130
+ counter: string;
131
+ size: 2 | 1 | 4;
132
+ address: number;
133
+ signed: boolean;
134
+ }[];
135
+ retroarch?: {
136
+ binary: string;
137
+ core: string;
138
+ rom: string;
139
+ stateSlot: number;
140
+ launchPrefix: string[];
141
+ port: number;
142
+ config?: string | undefined;
143
+ } | undefined;
144
+ ui?: string | undefined;
145
+ }, {
146
+ game: string;
147
+ expect: {
148
+ roomId?: number | undefined;
149
+ phase?: string | undefined;
150
+ locationId?: string | undefined;
151
+ difficulty?: string | undefined;
152
+ variant?: string | undefined;
153
+ counters?: Record<string, number | {
154
+ min: number;
155
+ max: number;
156
+ }> | undefined;
157
+ };
158
+ retroarch?: {
159
+ binary: string;
160
+ core: string;
161
+ rom: string;
162
+ stateSlot: number;
163
+ launchPrefix?: string[] | undefined;
164
+ config?: string | undefined;
165
+ port?: number | undefined;
166
+ } | undefined;
167
+ daemon?: {
168
+ url?: string | undefined;
169
+ } | undefined;
170
+ ui?: string | undefined;
171
+ settleMs?: number | undefined;
172
+ timeoutMs?: number | undefined;
173
+ memory?: {
174
+ counter: string;
175
+ size: 2 | 1 | 4;
176
+ address: string;
177
+ signed?: boolean | undefined;
178
+ }[] | undefined;
179
+ }>;
180
+ export type VerifySpec = z.infer<typeof VerifySpecSchema>;
181
+ type MemoryCheck = VerifySpec['memory'][number];
182
+ /** What doesn't match: one line each. */
183
+ export declare function stateMismatches(expect: VerifySpec['expect'], state: GameState): string[];
184
+ /** RetroArch's network command reading a value with RetroAchievements' addressing. */
185
+ export declare function readCoreRamCommand(check: Pick<MemoryCheck, 'address' | 'size'>): string;
186
+ /** The value in RetroArch's reply (bytes in the emulator's little-endian words), or why not. */
187
+ export declare function valueFromReply(reply: string, check: Pick<MemoryCheck, 'address' | 'size' | 'signed'>): number | string;
188
+ /** The effects a run needs. */
189
+ export interface VerifyEffects {
190
+ /** starts the game; resolves once it's running */
191
+ launch(spec: VerifySpec): Promise<{
192
+ stop(): void;
193
+ }>;
194
+ wait(ms: number): Promise<void>;
195
+ /** the daemon's next full state for `game` */
196
+ state(spec: VerifySpec): Promise<unknown>;
197
+ /** a RetroArch network command's reply */
198
+ command(spec: VerifySpec, line: string): Promise<string>;
199
+ /** screenshots of the game and the UI; the files written */
200
+ screenshots(spec: VerifySpec): Promise<string[]>;
201
+ }
202
+ export interface VerifyResult {
203
+ ok: boolean;
204
+ problems: string[];
205
+ screenshots: string[];
206
+ state: GameState | null;
207
+ }
208
+ /** Runs one check: start the game, let it settle, compare, screenshot, stop. */
209
+ export declare function runVerify(spec: VerifySpec, effects: VerifyEffects): Promise<VerifyResult>;
210
+ export {};
@@ -0,0 +1,146 @@
1
+ import { z } from 'zod';
2
+ import { guestToRa } from '../n64-address.js';
3
+ import { GameStateSchema } from '../types.js';
4
+ /*
5
+ * `gameslate-plugin verify`: run a game to a known moment, read what the plugin reports through
6
+ * a local GameSlate daemon, and check it against what the moment shows (`verify.json`). For an
7
+ * emulated console the emulator's own memory reads are a second opinion on the plugin's: RetroArch
8
+ * answers READ_CORE_RAM with RetroAchievements' addressing, independent of GameSlate's.
9
+ * The steps take their effects as parameters (verify-effects.ts has the real ones).
10
+ */
11
+ const Hex = z
12
+ .string()
13
+ .regex(/^0x[0-9a-fA-F]{1,8}$/, 'a hex address such as 0x801EF6AA')
14
+ .transform(h => Number.parseInt(h, 16));
15
+ const Expected = z.union([z.number(), z.object({ min: z.number(), max: z.number() })]);
16
+ export const VerifySpecSchema = z.object({
17
+ /** the game id the daemon must report */
18
+ game: z.string().min(1),
19
+ /** RetroArch with a core, a ROM and a save state slot, loaded on start (no input needed) */
20
+ retroarch: z
21
+ .object({
22
+ binary: z.string(),
23
+ core: z.string(),
24
+ rom: z.string(),
25
+ stateSlot: z.number().int().min(0).max(999),
26
+ /** run RetroArch through this (`["node", "<gameslate>/dist/gameslate.mjs", "run", "--"]`)
27
+ * where only a game's parent may read its memory (ptrace_scope 1, ChimeraOS) */
28
+ launchPrefix: z.array(z.string()).default([]),
29
+ /** a config appended to RetroArch's, which must turn network commands on */
30
+ config: z.string().optional(),
31
+ port: z.number().int().default(55355),
32
+ })
33
+ .optional(),
34
+ daemon: z.object({ url: z.string().default('ws://localhost:4310/ws') }).default({}),
35
+ /** the GameSlate page to screenshot beside the game */
36
+ ui: z.string().optional(),
37
+ /** how long to let the game run before reading */
38
+ settleMs: z.number().int().min(0).default(5000),
39
+ timeoutMs: z.number().int().min(1000).default(60_000),
40
+ expect: z.object({
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
+ }),
48
+ /** values to read through the emulator too: each must equal the plugin's counter */
49
+ memory: z
50
+ .array(z
51
+ .object({
52
+ address: Hex,
53
+ size: z.union([z.literal(1), z.literal(2), z.literal(4)]),
54
+ signed: z.boolean().default(false),
55
+ counter: z.string(),
56
+ })
57
+ .refine(m => m.address % m.size === 0, {
58
+ message: 'a memory address must be aligned to its size',
59
+ }))
60
+ .default([]),
61
+ });
62
+ /** What doesn't match: one line each. */
63
+ export function stateMismatches(expect, state) {
64
+ const out = [];
65
+ const same = (what, want, got) => {
66
+ if (want !== undefined && want !== got)
67
+ out.push(`${what}: expected ${String(want)}, got ${String(got)}`);
68
+ };
69
+ same('phase', expect.phase, state.phase);
70
+ same('location', expect.locationId, state.locationId);
71
+ same('difficulty', expect.difficulty, state.difficulty);
72
+ same('variant', expect.variant, state.variant);
73
+ same('room', expect.roomId, state.position?.roomId);
74
+ for (const [id, want] of Object.entries(expect.counters)) {
75
+ const got = state.counters?.[id];
76
+ if (got === undefined)
77
+ out.push(`counter ${id}: not reported`);
78
+ else if (typeof want === 'number')
79
+ same(`counter ${id}`, want, got);
80
+ else if (got < want.min || got > want.max)
81
+ out.push(`counter ${id}: expected ${want.min}..${want.max}, got ${got}`);
82
+ }
83
+ return out;
84
+ }
85
+ /** RetroArch's network command reading a value with RetroAchievements' addressing. */
86
+ export function readCoreRamCommand(check) {
87
+ return `READ_CORE_RAM ${guestToRa(check.address, check.size).toString(16)} ${check.size}`;
88
+ }
89
+ /** The value in RetroArch's reply (bytes in the emulator's little-endian words), or why not. */
90
+ export function valueFromReply(reply, check) {
91
+ const parts = reply.trim().split(/\s+/);
92
+ if (parts[0] !== 'READ_CORE_RAM' || parts.length < 3)
93
+ return `unexpected reply "${reply}"`;
94
+ if (parts[2] === '-1')
95
+ return `RetroArch couldn't read it: "${reply}"`;
96
+ const bytes = parts.slice(2).map(b => Number.parseInt(b, 16));
97
+ if (bytes.length !== check.size || bytes.some(b => Number.isNaN(b)))
98
+ return `malformed reply "${reply}"`;
99
+ const unsigned = bytes.reduceRight((value, b) => value * 256 + b, 0);
100
+ const bits = check.size * 8;
101
+ return check.signed && unsigned >= 2 ** (bits - 1) ? unsigned - 2 ** bits : unsigned;
102
+ }
103
+ async function memoryProblems(spec, state, effects) {
104
+ const out = [];
105
+ for (const check of spec.memory) {
106
+ const reply = await effects
107
+ .command(spec, readCoreRamCommand(check))
108
+ .catch((e) => (e instanceof Error ? e.message : String(e)));
109
+ const read = reply.startsWith('READ_CORE_RAM') ? valueFromReply(reply, check) : reply;
110
+ const reported = state.counters?.[check.counter];
111
+ const at = `0x${check.address.toString(16)}`;
112
+ if (typeof read === 'string')
113
+ out.push(`memory ${at}: ${read}`);
114
+ else if (reported !== read)
115
+ out.push(`memory ${at}: the emulator reads ${read}, the plugin reports ${check.counter} = ${String(reported)}`);
116
+ }
117
+ return out;
118
+ }
119
+ /** Runs one check: start the game, let it settle, compare, screenshot, stop. */
120
+ export async function runVerify(spec, effects) {
121
+ const game = await effects.launch(spec);
122
+ try {
123
+ await effects.wait(spec.settleMs);
124
+ const raw = await effects.state(spec).catch((e) => e);
125
+ if (raw instanceof Error)
126
+ return { ok: false, problems: [raw.message], screenshots: [], state: null };
127
+ const parsed = GameStateSchema.safeParse(raw);
128
+ if (!parsed.success)
129
+ return {
130
+ ok: false,
131
+ problems: [`the daemon's state: ${parsed.error.message}`],
132
+ screenshots: [],
133
+ state: null,
134
+ };
135
+ const state = parsed.data;
136
+ const problems = [
137
+ ...stateMismatches(spec.expect, state),
138
+ ...(await memoryProblems(spec, state, effects)),
139
+ ];
140
+ const screenshots = await effects.screenshots(spec);
141
+ return { ok: problems.length === 0, problems, screenshots, state };
142
+ }
143
+ finally {
144
+ game.stop();
145
+ }
146
+ }
package/lib/index.d.ts CHANGED
@@ -14,3 +14,5 @@ export * from './plugin-manifest.js';
14
14
  export * from './sandbox-protocol.js';
15
15
  export * from './assets.js';
16
16
  export * from './plugins-api.js';
17
+ export * from './signature.js';
18
+ export * from './n64-address.js';
package/lib/index.js CHANGED
@@ -14,3 +14,5 @@ export * from './plugin-manifest.js';
14
14
  export * from './sandbox-protocol.js';
15
15
  export * from './assets.js';
16
16
  export * from './plugins-api.js';
17
+ export * from './signature.js';
18
+ export * from './n64-address.js';
@@ -0,0 +1,5 @@
1
+ export type N64ValueBytes = 1 | 2 | 4;
2
+ /** A guest address (0x80…) for a value RA notes at `ra` (an RDRAM offset), of `size` bytes. */
3
+ export declare function raToGuest(ra: number, size: N64ValueBytes): number;
4
+ /** The RA address (an RDRAM offset) of the `size`-byte value at guest address `guest`. */
5
+ export declare function guestToRa(guest: number, size: N64ValueBytes): number;
@@ -0,0 +1,25 @@
1
+ /*
2
+ * RetroAchievements' N64 addresses and the console's own. RA (rcheevos) reads RDRAM as the
3
+ * emulator stores it: physical offsets in little-endian 32-bit words. GameSlate reads guest
4
+ * addresses (0x80…) in the console's big-endian order. A value's bytes keep their place within
5
+ * its aligned word, so only the address moves: a byte by ^3, a 16-bit value by ^2, a 32-bit one
6
+ * not at all. (Checked on 2026-11-29: 16 OoT and 16 MM save fields land on RA's notes this way.)
7
+ */
8
+ const KSEG0 = 0x80000000;
9
+ const PHYSICAL_MASK = 0x1fffffff;
10
+ const swizzle = (size) => (size === 1 ? 3 : size === 2 ? 2 : 0);
11
+ function checkAligned(address, size, what) {
12
+ if (address % size !== 0)
13
+ throw new Error(`${what} 0x${address.toString(16)} isn't aligned to ${size}`);
14
+ }
15
+ /** A guest address (0x80…) for a value RA notes at `ra` (an RDRAM offset), of `size` bytes. */
16
+ export function raToGuest(ra, size) {
17
+ const physical = ra ^ swizzle(size);
18
+ checkAligned(physical, size, 'RA address');
19
+ return (KSEG0 | physical) >>> 0;
20
+ }
21
+ /** The RA address (an RDRAM offset) of the `size`-byte value at guest address `guest`. */
22
+ export function guestToRa(guest, size) {
23
+ checkAligned(guest, size, 'guest address');
24
+ return (guest & PHYSICAL_MASK) ^ swizzle(size);
25
+ }
package/lib/pack.d.ts CHANGED
@@ -44,17 +44,17 @@ export declare const PackDataSchema: z.ZodObject<{
44
44
  id: string;
45
45
  icon?: string | undefined;
46
46
  max?: string | number | undefined;
47
+ format?: "number" | "percent" | undefined;
47
48
  display?: Record<string, string> | undefined;
48
49
  role?: "keys" | "health" | "magic" | "armor" | undefined;
49
- format?: "number" | "percent" | undefined;
50
50
  }, {
51
51
  label: string;
52
52
  id: string;
53
53
  icon?: string | undefined;
54
54
  max?: string | number | undefined;
55
+ format?: "number" | "percent" | undefined;
55
56
  display?: Record<string, string> | undefined;
56
57
  role?: "keys" | "health" | "magic" | "armor" | undefined;
57
- format?: "number" | "percent" | undefined;
58
58
  }>, "many">;
59
59
  flagSets: z.ZodArray<z.ZodString, "many">;
60
60
  inventoryLayouts: z.ZodArray<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
@@ -459,9 +459,9 @@ export declare const PackDataSchema: z.ZodObject<{
459
459
  id: string;
460
460
  icon?: string | undefined;
461
461
  max?: string | number | undefined;
462
+ format?: "number" | "percent" | undefined;
462
463
  display?: Record<string, string> | undefined;
463
464
  role?: "keys" | "health" | "magic" | "armor" | undefined;
464
- format?: "number" | "percent" | undefined;
465
465
  }[];
466
466
  flagSets: string[];
467
467
  items: {
@@ -578,9 +578,9 @@ export declare const PackDataSchema: z.ZodObject<{
578
578
  id: string;
579
579
  icon?: string | undefined;
580
580
  max?: string | number | undefined;
581
+ format?: "number" | "percent" | undefined;
581
582
  display?: Record<string, string> | undefined;
582
583
  role?: "keys" | "health" | "magic" | "armor" | undefined;
583
- format?: "number" | "percent" | undefined;
584
584
  }[];
585
585
  flagSets: string[];
586
586
  items: {
@@ -717,9 +717,9 @@ export declare const PackDataSchema: z.ZodObject<{
717
717
  id: string;
718
718
  icon?: string | undefined;
719
719
  max?: string | number | undefined;
720
+ format?: "number" | "percent" | undefined;
720
721
  display?: Record<string, string> | undefined;
721
722
  role?: "keys" | "health" | "magic" | "armor" | undefined;
722
- format?: "number" | "percent" | undefined;
723
723
  }[];
724
724
  flagSets: string[];
725
725
  items: {
@@ -844,9 +844,9 @@ export declare const PackDataSchema: z.ZodObject<{
844
844
  id: string;
845
845
  icon?: string | undefined;
846
846
  max?: string | number | undefined;
847
+ format?: "number" | "percent" | undefined;
847
848
  display?: Record<string, string> | undefined;
848
849
  role?: "keys" | "health" | "magic" | "armor" | undefined;
849
- format?: "number" | "percent" | undefined;
850
850
  }[];
851
851
  flagSets: string[];
852
852
  items: {
@@ -1,4 +1,4 @@
1
- import type { AssetList, AssetOutput, Bytes, GameCapability, GamePack, GameState, InputFile, InputPick } from '../index.js';
1
+ import type { AssetList, AssetOutput, Bytes, GameCapability, GamePack, GameState, InputFile, InputPick, Signature } from '../index.js';
2
2
  /**
3
3
  * What a plugin may do with the matched game's memory: read it, and nothing else. The core opens
4
4
  * and closes the process; a plugin never sees a pid, a path or a file handle.
@@ -15,6 +15,12 @@ export interface GameMemory {
15
15
  resolveSymbol(name: string): bigint | null;
16
16
  /** Re-read the process's memory map (after a level load moves heap regions). */
17
17
  refreshMappings(): void;
18
+ /**
19
+ * Where a byte pattern in the game's own executable points (issue #14): null when it isn't
20
+ * there; throws when it matches more than once. Run once per session and cached by the core.
21
+ * Absent on cores before sdk 0.3.6 and for memory without an executable image (emulators).
22
+ */
23
+ scan?(signature: Signature): bigint | null;
18
24
  }
19
25
  /** A memory-read state source for one game. Packs export theirs from games/<id>/source.ts. */
20
26
  export interface GamePlugin {
@@ -104,8 +110,17 @@ export interface PluginAssetsModule {
104
110
  * The Python map renderer's hooks (the Zelda ports). Still unsandboxed, with Node, until the
105
111
  * renderer is ported and those games get an AssetExtractor.
106
112
  */
113
+ /** What a game's after-assets step gets: where its assets were written. */
114
+ export interface AfterAssetsContext {
115
+ outDir: string;
116
+ }
107
117
  export interface PluginExtractModule {
108
118
  /** must equal the manifest's id */
109
119
  id: string;
120
+ /** @deprecated the Python map renderer is gone (GameSlate builds assets in the sandbox);
121
+ * kept so plugins built against older sdk versions still load */
110
122
  pythonExtract?: PythonExtract;
123
+ /** per game: a step after its extraction job, unsandboxed (e.g. notes built from data fetched
124
+ * over the network); it must not fail the extraction when it can't run */
125
+ afterAssets?: ReadonlyMap<string, (ctx: AfterAssetsContext) => Promise<void>>;
111
126
  }
@@ -14,6 +14,10 @@ function memoryFor(host, handle, info) {
14
14
  return at === null ? null : BigInt(at);
15
15
  },
16
16
  refreshMappings: () => host.refreshMappings(handle),
17
+ scan: signature => {
18
+ const at = host.scan(handle, JSON.stringify(signature));
19
+ return at === null ? null : BigInt(at);
20
+ },
17
21
  };
18
22
  }
19
23
  function describe(plugin) {
@@ -53,7 +57,9 @@ function find(list, match, what) {
53
57
  /** Makes `plugin` callable by the core. A plugin bundle's entry calls this once. */
54
58
  export function exposeToHost(plugin) {
55
59
  const sessions = new Map();
56
- const source = (gameId) => find(plugin.sources, s => s.gameId === gameId, `source for ${gameId}`);
60
+ /* One game can have a source per kind of build (Ocarina of Time on PC and in an N64
61
+ * emulator): the one that verified this build. No other: its offsets would be guesses. */
62
+ const source = (gameId, buildId) => find(plugin.sources, s => s.gameId === gameId && buildId !== null && s.supportedBuildIds.has(buildId), `source for ${gameId} that verified build ${buildId ?? '(none)'}`);
57
63
  const pack = (gameId) => find(plugin.packs, p => p.id === gameId, `pack for ${gameId}`);
58
64
  globalThis.__gs = {
59
65
  describe: () => JSON.stringify(describe(plugin)),
@@ -62,7 +68,7 @@ export function exposeToHost(plugin) {
62
68
  if (!host)
63
69
  throw new Error('the core gave no memory capability');
64
70
  const info = SandboxMemoryInfoSchema.parse(JSON.parse(memoryInfo));
65
- const session = source(gameId).createSession(memoryFor(host, handle, info));
71
+ const session = source(gameId, info.buildId).createSession(memoryFor(host, handle, info));
66
72
  if (session)
67
73
  sessions.set(handle, session);
68
74
  return session !== null;