@gameslate/sdk 0.3.20 → 0.3.22
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 +7 -0
- package/build/build-plugin.d.mts +4 -0
- package/build/build-plugin.mjs +46 -0
- package/build/verify-effects.mjs +11 -7
- package/lib/assets.d.ts +3 -0
- package/lib/host/asset-sandbox.d.ts +11 -0
- package/lib/host/asset-sandbox.js +42 -5
- package/lib/host/index.d.ts +1 -0
- package/lib/host/index.js +1 -0
- package/lib/host/inspect.d.ts +4 -1
- package/lib/host/inspect.js +72 -15
- package/lib/host/live-sandbox.d.ts +5 -0
- package/lib/host/live-sandbox.js +10 -0
- package/lib/host/quickjs-guest.d.ts +5 -0
- package/lib/host/quickjs-guest.js +53 -2
- package/lib/host/verify.d.ts +23 -17
- package/lib/host/verify.js +16 -3
- package/lib/host/wasm-host.d.ts +51 -0
- package/lib/host/wasm-host.js +270 -0
- package/lib/plugin/contract.d.ts +2 -1
- package/lib/plugin/index.d.ts +1 -0
- package/lib/plugin/index.js +3 -2
- package/lib/plugin/sandbox-guest.js +1 -0
- package/lib/plugin/wasm.d.ts +17 -0
- package/lib/plugin/wasm.js +17 -0
- package/lib/plugin-manifest.d.ts +110 -0
- package/lib/plugin-manifest.js +46 -0
- package/lib/plugin-permissions.js +21 -4
- package/lib/sandbox-protocol.d.ts +12 -0
- package/package.json +1 -1
- package/template/claude/skills/build-gameslate-plugin/SKILL.md +78 -4
- package/template/claude/skills/verify-gameslate-plugin/SKILL.md +4 -3
- package/template/github/workflows/ci.yml +2 -2
- package/template/github/workflows/release.yml +2 -2
- package/template/plugin/live.ts +2 -1
- package/template/plugin/manifest.json +7 -1
package/lib/plugin-manifest.d.ts
CHANGED
|
@@ -35,6 +35,41 @@ export declare const PluginDownloadSchema: z.ZodObject<{
|
|
|
35
35
|
export type PluginDownload = z.infer<typeof PluginDownloadSchema>;
|
|
36
36
|
/** The input name a download reaches the asset code under. */
|
|
37
37
|
export declare const downloadInputName: (id: string) => string;
|
|
38
|
+
/**
|
|
39
|
+
* A build of a game that the plugin's live code reads memory from: the id its source matches
|
|
40
|
+
* (an ELF or PE build id, or an N64 ROM's code and version such as `CZLE.2`) and what the player
|
|
41
|
+
* knows it as (the executable's file name, or the ROM's title). Each is a permission, keyed by
|
|
42
|
+
* both, so a plugin that starts matching another process asks first ("Closing the sandbox" item 4).
|
|
43
|
+
* When a game lists its builds, the core refuses live code that matches one it doesn't list.
|
|
44
|
+
*/
|
|
45
|
+
export declare const GameBuildSchema: z.ZodObject<{
|
|
46
|
+
id: z.ZodString;
|
|
47
|
+
name: z.ZodString;
|
|
48
|
+
}, "strict", z.ZodTypeAny, {
|
|
49
|
+
id: string;
|
|
50
|
+
name: string;
|
|
51
|
+
}, {
|
|
52
|
+
id: string;
|
|
53
|
+
name: string;
|
|
54
|
+
}>;
|
|
55
|
+
export type GameBuild = z.infer<typeof GameBuildSchema>;
|
|
56
|
+
/** How many WebAssembly modules one plugin may bundle (each gets its own capped memory). */
|
|
57
|
+
export declare const MAX_WASM_MODULES = 4;
|
|
58
|
+
/**
|
|
59
|
+
* A WebAssembly module the plugin bundles ("Closing the sandbox" item 3): its code calls the
|
|
60
|
+
* module's exports through `wasmModule(file)` and the core runs it with no imports but the
|
|
61
|
+
* sandbox's allow-list (src/host/wasm-host.ts).
|
|
62
|
+
*/
|
|
63
|
+
export declare const WasmFileSchema: z.ZodObject<{
|
|
64
|
+
file: z.ZodString;
|
|
65
|
+
sha256: z.ZodString;
|
|
66
|
+
}, "strict", z.ZodTypeAny, {
|
|
67
|
+
file: string;
|
|
68
|
+
sha256: string;
|
|
69
|
+
}, {
|
|
70
|
+
file: string;
|
|
71
|
+
sha256: string;
|
|
72
|
+
}>;
|
|
38
73
|
/** major.minor.patch, the only form `compareVersions` orders. */
|
|
39
74
|
export declare const PluginVersionSchema: z.ZodString;
|
|
40
75
|
/** The release zip a published manifest names: its URL (absolute, or relative to the URL the
|
|
@@ -79,6 +114,23 @@ export declare const PluginManifestSchema: z.ZodEffects<z.ZodObject<{
|
|
|
79
114
|
file: string;
|
|
80
115
|
sha256: string;
|
|
81
116
|
}>>;
|
|
117
|
+
/** WebAssembly modules the live and asset code may call, pinned like the code files */
|
|
118
|
+
wasm: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodObject<{
|
|
119
|
+
file: z.ZodString;
|
|
120
|
+
sha256: z.ZodString;
|
|
121
|
+
}, "strict", z.ZodTypeAny, {
|
|
122
|
+
file: string;
|
|
123
|
+
sha256: string;
|
|
124
|
+
}, {
|
|
125
|
+
file: string;
|
|
126
|
+
sha256: string;
|
|
127
|
+
}>, "many">, {
|
|
128
|
+
file: string;
|
|
129
|
+
sha256: string;
|
|
130
|
+
}[], {
|
|
131
|
+
file: string;
|
|
132
|
+
sha256: string;
|
|
133
|
+
}[]>>;
|
|
82
134
|
games: z.ZodArray<z.ZodObject<{
|
|
83
135
|
id: z.ZodString;
|
|
84
136
|
title: z.ZodString;
|
|
@@ -122,6 +174,24 @@ export declare const PluginManifestSchema: z.ZodEffects<z.ZodObject<{
|
|
|
122
174
|
url: string;
|
|
123
175
|
sha256: string;
|
|
124
176
|
}[]>>;
|
|
177
|
+
/** the builds its live code reads memory from. Absent in manifests from
|
|
178
|
+
* before sdk 0.3.21: then the permission names only the game. */
|
|
179
|
+
builds: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodObject<{
|
|
180
|
+
id: z.ZodString;
|
|
181
|
+
name: z.ZodString;
|
|
182
|
+
}, "strict", z.ZodTypeAny, {
|
|
183
|
+
id: string;
|
|
184
|
+
name: string;
|
|
185
|
+
}, {
|
|
186
|
+
id: string;
|
|
187
|
+
name: string;
|
|
188
|
+
}>, "many">, {
|
|
189
|
+
id: string;
|
|
190
|
+
name: string;
|
|
191
|
+
}[], {
|
|
192
|
+
id: string;
|
|
193
|
+
name: string;
|
|
194
|
+
}[]>>;
|
|
125
195
|
}, "strict", z.ZodTypeAny, {
|
|
126
196
|
id: string;
|
|
127
197
|
title: string;
|
|
@@ -135,10 +205,18 @@ export declare const PluginManifestSchema: z.ZodEffects<z.ZodObject<{
|
|
|
135
205
|
url: string;
|
|
136
206
|
sha256: string;
|
|
137
207
|
}[];
|
|
208
|
+
builds?: {
|
|
209
|
+
id: string;
|
|
210
|
+
name: string;
|
|
211
|
+
}[] | undefined;
|
|
138
212
|
aliases?: string[] | undefined;
|
|
139
213
|
}, {
|
|
140
214
|
id: string;
|
|
141
215
|
title: string;
|
|
216
|
+
builds?: {
|
|
217
|
+
id: string;
|
|
218
|
+
name: string;
|
|
219
|
+
}[] | undefined;
|
|
142
220
|
aliases?: string[] | undefined;
|
|
143
221
|
inputs?: {
|
|
144
222
|
label: string;
|
|
@@ -187,12 +265,20 @@ export declare const PluginManifestSchema: z.ZodEffects<z.ZodObject<{
|
|
|
187
265
|
url: string;
|
|
188
266
|
sha256: string;
|
|
189
267
|
}[];
|
|
268
|
+
builds?: {
|
|
269
|
+
id: string;
|
|
270
|
+
name: string;
|
|
271
|
+
}[] | undefined;
|
|
190
272
|
aliases?: string[] | undefined;
|
|
191
273
|
}[];
|
|
192
274
|
assets?: {
|
|
193
275
|
file: string;
|
|
194
276
|
sha256: string;
|
|
195
277
|
} | undefined;
|
|
278
|
+
wasm?: {
|
|
279
|
+
file: string;
|
|
280
|
+
sha256: string;
|
|
281
|
+
}[] | undefined;
|
|
196
282
|
bundle?: {
|
|
197
283
|
url: string;
|
|
198
284
|
sha256: string;
|
|
@@ -209,6 +295,10 @@ export declare const PluginManifestSchema: z.ZodEffects<z.ZodObject<{
|
|
|
209
295
|
games: {
|
|
210
296
|
id: string;
|
|
211
297
|
title: string;
|
|
298
|
+
builds?: {
|
|
299
|
+
id: string;
|
|
300
|
+
name: string;
|
|
301
|
+
}[] | undefined;
|
|
212
302
|
aliases?: string[] | undefined;
|
|
213
303
|
inputs?: {
|
|
214
304
|
label: string;
|
|
@@ -226,6 +316,10 @@ export declare const PluginManifestSchema: z.ZodEffects<z.ZodObject<{
|
|
|
226
316
|
sha256: string;
|
|
227
317
|
} | undefined;
|
|
228
318
|
testedWith?: string[] | undefined;
|
|
319
|
+
wasm?: {
|
|
320
|
+
file: string;
|
|
321
|
+
sha256: string;
|
|
322
|
+
}[] | undefined;
|
|
229
323
|
bundle?: {
|
|
230
324
|
url: string;
|
|
231
325
|
sha256: string;
|
|
@@ -253,12 +347,20 @@ export declare const PluginManifestSchema: z.ZodEffects<z.ZodObject<{
|
|
|
253
347
|
url: string;
|
|
254
348
|
sha256: string;
|
|
255
349
|
}[];
|
|
350
|
+
builds?: {
|
|
351
|
+
id: string;
|
|
352
|
+
name: string;
|
|
353
|
+
}[] | undefined;
|
|
256
354
|
aliases?: string[] | undefined;
|
|
257
355
|
}[];
|
|
258
356
|
assets?: {
|
|
259
357
|
file: string;
|
|
260
358
|
sha256: string;
|
|
261
359
|
} | undefined;
|
|
360
|
+
wasm?: {
|
|
361
|
+
file: string;
|
|
362
|
+
sha256: string;
|
|
363
|
+
}[] | undefined;
|
|
262
364
|
bundle?: {
|
|
263
365
|
url: string;
|
|
264
366
|
sha256: string;
|
|
@@ -275,6 +377,10 @@ export declare const PluginManifestSchema: z.ZodEffects<z.ZodObject<{
|
|
|
275
377
|
games: {
|
|
276
378
|
id: string;
|
|
277
379
|
title: string;
|
|
380
|
+
builds?: {
|
|
381
|
+
id: string;
|
|
382
|
+
name: string;
|
|
383
|
+
}[] | undefined;
|
|
278
384
|
aliases?: string[] | undefined;
|
|
279
385
|
inputs?: {
|
|
280
386
|
label: string;
|
|
@@ -292,6 +398,10 @@ export declare const PluginManifestSchema: z.ZodEffects<z.ZodObject<{
|
|
|
292
398
|
sha256: string;
|
|
293
399
|
} | undefined;
|
|
294
400
|
testedWith?: string[] | undefined;
|
|
401
|
+
wasm?: {
|
|
402
|
+
file: string;
|
|
403
|
+
sha256: string;
|
|
404
|
+
}[] | undefined;
|
|
295
405
|
bundle?: {
|
|
296
406
|
url: string;
|
|
297
407
|
sha256: string;
|
package/lib/plugin-manifest.js
CHANGED
|
@@ -99,10 +99,43 @@ export const PluginDownloadSchema = z
|
|
|
99
99
|
.strict();
|
|
100
100
|
/** The input name a download reaches the asset code under. */
|
|
101
101
|
export const downloadInputName = (id) => `downloads/${id}`;
|
|
102
|
+
/**
|
|
103
|
+
* A build of a game that the plugin's live code reads memory from: the id its source matches
|
|
104
|
+
* (an ELF or PE build id, or an N64 ROM's code and version such as `CZLE.2`) and what the player
|
|
105
|
+
* knows it as (the executable's file name, or the ROM's title). Each is a permission, keyed by
|
|
106
|
+
* both, so a plugin that starts matching another process asks first ("Closing the sandbox" item 4).
|
|
107
|
+
* When a game lists its builds, the core refuses live code that matches one it doesn't list.
|
|
108
|
+
*/
|
|
109
|
+
export const GameBuildSchema = z
|
|
110
|
+
.object({
|
|
111
|
+
id: z
|
|
112
|
+
.string()
|
|
113
|
+
.regex(/^[A-Za-z0-9._-]{1,128}$/, 'a build id: letters, digits, ".", "_" or "-"'),
|
|
114
|
+
name: z
|
|
115
|
+
.string()
|
|
116
|
+
.min(1)
|
|
117
|
+
.max(100)
|
|
118
|
+
/* shown to the player in a permission: one plain line */
|
|
119
|
+
.regex(/^[^\p{Cc}]+$/u, 'a name without control characters'),
|
|
120
|
+
})
|
|
121
|
+
.strict();
|
|
102
122
|
const CodeFile = z.object({
|
|
103
123
|
file: FileName,
|
|
104
124
|
sha256: Sha256,
|
|
105
125
|
});
|
|
126
|
+
/** How many WebAssembly modules one plugin may bundle (each gets its own capped memory). */
|
|
127
|
+
export const MAX_WASM_MODULES = 4;
|
|
128
|
+
/**
|
|
129
|
+
* A WebAssembly module the plugin bundles ("Closing the sandbox" item 3): its code calls the
|
|
130
|
+
* module's exports through `wasmModule(file)` and the core runs it with no imports but the
|
|
131
|
+
* sandbox's allow-list (src/host/wasm-host.ts).
|
|
132
|
+
*/
|
|
133
|
+
export const WasmFileSchema = z
|
|
134
|
+
.object({
|
|
135
|
+
file: FileName.regex(/\.wasm$/, 'a WebAssembly module is a .wasm file'),
|
|
136
|
+
sha256: Sha256,
|
|
137
|
+
})
|
|
138
|
+
.strict();
|
|
106
139
|
/** major.minor.patch, the only form `compareVersions` orders. */
|
|
107
140
|
export const PluginVersionSchema = z
|
|
108
141
|
.string()
|
|
@@ -125,6 +158,12 @@ export const PluginManifestSchema = z
|
|
|
125
158
|
code: CodeFile,
|
|
126
159
|
/** asset extractors, run in the core's sandbox by extraction jobs */
|
|
127
160
|
assets: CodeFile.optional(),
|
|
161
|
+
/** WebAssembly modules the live and asset code may call, pinned like the code files */
|
|
162
|
+
wasm: z
|
|
163
|
+
.array(WasmFileSchema)
|
|
164
|
+
.max(MAX_WASM_MODULES)
|
|
165
|
+
.refine(ws => new Set(ws.map(w => w.file)).size === ws.length, 'each WebAssembly file is listed once')
|
|
166
|
+
.optional(),
|
|
128
167
|
games: z
|
|
129
168
|
.array(z
|
|
130
169
|
.object({
|
|
@@ -140,6 +179,13 @@ export const PluginManifestSchema = z
|
|
|
140
179
|
.max(20)
|
|
141
180
|
.refine(ds => new Set(ds.map(d => d.id)).size === ds.length, "a game's download ids are unique")
|
|
142
181
|
.default([]),
|
|
182
|
+
/** the builds its live code reads memory from. Absent in manifests from
|
|
183
|
+
* before sdk 0.3.21: then the permission names only the game. */
|
|
184
|
+
builds: z
|
|
185
|
+
.array(GameBuildSchema)
|
|
186
|
+
.max(50)
|
|
187
|
+
.refine(bs => new Set(bs.map(b => b.id)).size === bs.length, "a game's build ids are unique")
|
|
188
|
+
.optional(),
|
|
143
189
|
})
|
|
144
190
|
/* a misspelt key (`download`) is refused, not dropped with what it declared */
|
|
145
191
|
.strict())
|
|
@@ -13,10 +13,7 @@ export const PluginPermissionSchema = z.object({
|
|
|
13
13
|
label: z.string(),
|
|
14
14
|
});
|
|
15
15
|
export function pluginPermissions(manifest) {
|
|
16
|
-
const memory = manifest.games.
|
|
17
|
-
key: `memory:${g.id}`,
|
|
18
|
-
label: `Read ${g.title}'s memory while it runs`,
|
|
19
|
-
}));
|
|
16
|
+
const memory = manifest.games.flatMap(memoryPermissions);
|
|
20
17
|
/* the offered folders are read only by asset code */
|
|
21
18
|
const folders = manifest.assets
|
|
22
19
|
? [...new Set(manifest.games.flatMap(g => g.inputs.flatMap(i => i.folders)))].map(f => ({
|
|
@@ -31,6 +28,26 @@ export function pluginPermissions(manifest) {
|
|
|
31
28
|
])));
|
|
32
29
|
return [...memory, ...folders, ...[...downloads].map(([key, label]) => ({ key, label }))];
|
|
33
30
|
}
|
|
31
|
+
const BUILD_ID_SHOWN = 8;
|
|
32
|
+
/* One per build, keyed by its id and name: matching another process, or calling a build by
|
|
33
|
+
* another name, asks again. A manifest from before builds were declared names only the game. */
|
|
34
|
+
function memoryPermissions(game) {
|
|
35
|
+
if (!game.builds) {
|
|
36
|
+
return [
|
|
37
|
+
{
|
|
38
|
+
key: `memory:${game.id}`,
|
|
39
|
+
label: `Read ${game.title}'s memory while it runs, when you launch it through GameSlate`,
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
return game.builds.map(b => ({
|
|
44
|
+
key: `memory:${game.id}:${b.id}#${b.name}`,
|
|
45
|
+
label: `Read the memory of ${b.name} (${game.title}, build ${shortBuildId(b.id)}), when you launch it through GameSlate`,
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
function shortBuildId(id) {
|
|
49
|
+
return id.length > BUILD_ID_SHOWN ? `${id.slice(0, BUILD_ID_SHOWN)}…` : id;
|
|
50
|
+
}
|
|
34
51
|
/* host and path, as the player reads a link ("example.com/a/b.tar.gz") */
|
|
35
52
|
function downloadPlace(url) {
|
|
36
53
|
const u = new URL(url);
|
|
@@ -1523,3 +1523,15 @@ export interface SandboxAssetsHostApi {
|
|
|
1523
1523
|
/** hands the core a block of output bytes; the index outputs refer to it by */
|
|
1524
1524
|
emitBinary(data: ArrayBuffer): number;
|
|
1525
1525
|
}
|
|
1526
|
+
/** The core's bridge to the plugin's own WebAssembly modules, on `globalThis.__gsWasm` (in both
|
|
1527
|
+
* sandboxes, when the manifest lists modules). Modules are named by their file name. */
|
|
1528
|
+
export interface SandboxWasmHostApi {
|
|
1529
|
+
/** calls an export with numbers; its number result, or undefined for none */
|
|
1530
|
+
call(file: string, fn: string, ...args: number[]): number | undefined;
|
|
1531
|
+
/** a copy of `length` bytes of the module's memory from `ptr` */
|
|
1532
|
+
read(file: string, ptr: number, length: number): ArrayBuffer;
|
|
1533
|
+
/** copies `data` into the module's memory at `ptr` */
|
|
1534
|
+
write(file: string, ptr: number, data: ArrayBuffer): void;
|
|
1535
|
+
/** the module's memory size now, in bytes */
|
|
1536
|
+
memoryBytes(file: string): number;
|
|
1537
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gameslate/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.22",
|
|
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",
|
|
@@ -97,13 +97,42 @@ evaluator in the SDK decides "done", "collected" and "available". Rules:
|
|
|
97
97
|
## 4. Memory addresses, verified
|
|
98
98
|
|
|
99
99
|
**Pin the build.** List the exact builds you verified in the source's `supportedBuildIds` (a
|
|
100
|
-
`Map` from build id to `{ region }` on the `GamePlugin` in `live.ts
|
|
100
|
+
`Map` from build id to `{ region }` on the `GamePlugin` in `live.ts`):
|
|
101
101
|
|
|
102
102
|
- ELF or PE build id for PC games;
|
|
103
103
|
- `CODE.version` from the ROM header for N64 (e.g. `CZLE.2`).
|
|
104
104
|
|
|
105
105
|
An unknown build means refuse to attach, never "try the nearest offsets".
|
|
106
106
|
|
|
107
|
+
**Declare the same builds in the manifest** (sdk 0.3.21), each with what the player knows it as,
|
|
108
|
+
the executable's file name or the ROM's title:
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
"games": [{ "id": "perfect-dark", "title": "Perfect Dark",
|
|
112
|
+
"builds": [{ "id": "0925a5f6…", "name": "pd.pal.x86_64" }] }]
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Each build is a permission ("Read the memory of pd.pal.x86_64 (Perfect Dark, build 0925a5f6…),
|
|
116
|
+
when you launch it through GameSlate"), keyed by id and name: adding a build or renaming one makes
|
|
117
|
+
every player confirm the update. The core (and `validate`) refuses live code that matches a build
|
|
118
|
+
the manifest doesn't list. A manifest without `builds` still loads, with a permission naming only
|
|
119
|
+
the game; declare them anyway, since that leniency is for releases built before 0.3.21.
|
|
120
|
+
|
|
121
|
+
Read each name from the build itself, never from memory. An N64 ROM's name is its header's own
|
|
122
|
+
title (bytes `0x20`-`0x33`, trimmed), which often differs from the box: `STARFOX64`,
|
|
123
|
+
`CASTLEVANIA2`, `Silicon Valley`. For a revision you have no ROM of (one the decomp builds but
|
|
124
|
+
nobody has dumped here), use the decomp's own name for that ROM and say so in the commit. And
|
|
125
|
+
`validate` checks only one way (every build the code matches is listed): add a test that the
|
|
126
|
+
manifest lists no build that no source matches, since a stray build still asks every player
|
|
127
|
+
(gameslate-n64's `plugin/manifest.test.ts`).
|
|
128
|
+
|
|
129
|
+
**Memory is read only from games launched through GameSlate.** The core reads a process only
|
|
130
|
+
when it descends from a `gameslate run --` launch wrapper that is connected to the daemon
|
|
131
|
+
(Steam launch options `~/.local/bin/gameslate run -- %command%`, or `n64-gameslate` for
|
|
132
|
+
ChimeraOS's N64 launcher). A game started any other way shows "Launch <game> through GameSlate
|
|
133
|
+
to read it" in the app instead. Test live runs that way too: `gameslate-plugin verify` starts
|
|
134
|
+
the emulator through the spec's `gameslate` wrapper by default.
|
|
135
|
+
|
|
107
136
|
**Open-source ports.** Compile a probe against the game's headers: print `sizeof` of a big struct
|
|
108
137
|
(it must equal what the shipped build uses) and the `offsetof` of each field. Put each value in
|
|
109
138
|
`offsets.ts`, with a comment naming the struct field and where the number came from. Header
|
|
@@ -326,6 +355,50 @@ Every image of a game uses one format. In the sandbox:
|
|
|
326
355
|
- **Data licensing:** ship the extractor, never its output. Textures, models and renders are
|
|
327
356
|
built on the player's machine and never committed.
|
|
328
357
|
|
|
358
|
+
### WebAssembly for hot loops (sdk 0.3.22)
|
|
359
|
+
|
|
360
|
+
QuickJS interprets: a tight pixel or decompression loop runs 20–150× slower than in V8 (the
|
|
361
|
+
core's palette-to-RGBA demonstration: 1330 ms against 10 ms for 16 M pixels). When a build is
|
|
362
|
+
slow, move the loop into a WebAssembly module the plugin bundles:
|
|
363
|
+
|
|
364
|
+
- **Build it in the plugin repo, with a toolchain the repo owns,** into `plugin/wasm/<name>.wasm`
|
|
365
|
+
(a `yarn build:wasm` script, run before `yarn build`). Commit the source; git-ignore
|
|
366
|
+
`plugin/wasm/` and have CI and the release build it, so the shipped binary is the one the
|
|
367
|
+
source makes. The folder holds built modules only: anything else fails the build. `gameslate-plugin build` copies every `wasm/*.wasm`
|
|
368
|
+
beside `live.js`, refuses one that isn't valid WebAssembly, and lists each in the manifest's
|
|
369
|
+
`wasm` with its sha256. Up to 4 modules, 8 MB each.
|
|
370
|
+
- **Imports: `env.memory` and the sandbox's capabilities only.** The core refuses a module that
|
|
371
|
+
imports anything else (WASI, `env.abort`, a global or a table) or defines its own memory. Link
|
|
372
|
+
so the memory is imported:
|
|
373
|
+
- Rust: `--target wasm32-unknown-unknown`, `-C link-arg=--import-memory`, no `std` I/O; import
|
|
374
|
+
capabilities in an `extern "C"` block under `#[link(wasm_import_module = "gameslate")]`
|
|
375
|
+
(`fn input_read(handle: i32, offset: i64, length: i32, ptr: i32);`).
|
|
376
|
+
- C (clang): `--target=wasm32 -nostdlib -Wl,--no-entry -Wl,--export-dynamic
|
|
377
|
+
-Wl,--import-memory`; declare `__attribute__((import_module("gameslate"),
|
|
378
|
+
import_name("input_read")))`.
|
|
379
|
+
- AssemblyScript: `--importMemory --runtime stub --use abort=` (its default `env.abort` import
|
|
380
|
+
is refused); `@external("gameslate", "input_read") declare function input_read(...)`.
|
|
381
|
+
- **Capabilities:** asset code's modules may import `gameslate.input_read(handle: i32, offset:
|
|
382
|
+
i64, length: i32, ptr: i32)`, which reads an input range (64 MB at most) straight into the
|
|
383
|
+
module's memory; the handle is `InputFile.handle`. Live code's modules import nothing.
|
|
384
|
+
- **Memory:** the core creates it with a maximum of 1 GB (asset code) or 16 MB (live code), or
|
|
385
|
+
the module's own smaller maximum. `memory.grow` past it returns -1. Declare a starting size
|
|
386
|
+
(`--initial-memory`) big enough for your buffers, or grow it yourself.
|
|
387
|
+
- **Calling it:** `wasmModule('<name>.wasm')` from `@gameslate/sdk/plugin` gives `call(fn,
|
|
388
|
+
...numbers)`, `write(ptr, bytes)`, `read(ptr, length)` (at most 64 MB, 16 MB in live code) and
|
|
389
|
+
`memoryBytes()`. Only numbers cross
|
|
390
|
+
(i32/f32/f64 arguments; an i64 result comes back as a number). Each call costs about 0.5 ms (a
|
|
391
|
+
watchdog guards it), so call once per buffer or per asset, never per pixel. Big inputs: let
|
|
392
|
+
the module read them with `input_read` instead of `write`-ing them through the interpreter.
|
|
393
|
+
- **Budget:** a call shares the guest call's time budget; a module still running at the deadline
|
|
394
|
+
is stopped mid-loop and the sandbox switches off (the asset fails, the next gets a fresh one).
|
|
395
|
+
- **Licence:** the module's source is code like any other: port only MIT/BSD/CC0 code into it
|
|
396
|
+
(see "Read the decomp's licence" under Pitfalls). Compilers drop the `/*! Derived from … */`
|
|
397
|
+
header, so the notice that ships is the repo's `THIRD_PARTY_NOTICES.md` (copied into every
|
|
398
|
+
build): list the ported source and every crate or C library linked into the module there
|
|
399
|
+
(`cargo about` can generate it). A game's own native library (a proprietary
|
|
400
|
+
decompressor DLL) can't be loaded this way.
|
|
401
|
+
|
|
329
402
|
### Registry data: what the plugin commits
|
|
330
403
|
|
|
331
404
|
A plugin carries its games' committed map data in `plugin/registry/games/<gameId>/` (sdk 0.3.17):
|
|
@@ -515,11 +588,12 @@ plugin exactly as the core will before running it. Then bump `version` in `packa
|
|
|
515
588
|
plugin's games and permissions, then downloads the zip, refuses it unless its sha256 matches, checks
|
|
516
589
|
the zip's own manifest is the published one, and unpacks it. It re-reads that URL about hourly: a
|
|
517
590
|
newer version that asks for **no new permissions** installs itself (once none of its games is
|
|
518
|
-
running); one that asks for more (a new game's memory, a new
|
|
519
|
-
confirm. A manifest naming an `extract` module (code outside the sandbox, removed in sdk 0.3.19)
|
|
591
|
+
running); one that asks for more (a new game's memory, a new or renamed build, a new folder)
|
|
592
|
+
waits for the player to confirm. A manifest naming an `extract` module (code outside the sandbox, removed in sdk 0.3.19)
|
|
520
593
|
fails the schema everywhere, presets included (docs/plugin-architecture.md, "Closing the
|
|
521
594
|
sandbox"). So adding a game, a folder or a download in a release
|
|
522
|
-
means every player is asked again: say why in the release notes.
|
|
595
|
+
means every player is asked again: say why in the release notes. So does a new build in
|
|
596
|
+
`builds`, or a changed build id or name. A plain zip URL works too
|
|
523
597
|
(validated the same way, its `.zip.sha256` used when present), but gets no updates.
|
|
524
598
|
|
|
525
599
|
GameSlate also builds a few plugins in as presets, from `plugins.lock.json` (the release URL and the
|
|
@@ -214,9 +214,10 @@ map), because the game saves the last choices.
|
|
|
214
214
|
addressing; the tool converts a guest address for you) and requires it to equal the plugin's
|
|
215
215
|
counter. That second opinion catches a wrong offset that still looks plausible. Use it for at
|
|
216
216
|
least one value per struct the plugin reads (save, live game state).
|
|
217
|
-
-
|
|
218
|
-
`
|
|
219
|
-
|
|
217
|
+
- GameSlate reads memory only from games launched through it, so the emulator starts through
|
|
218
|
+
the launch wrapper of the spec's `gameslate` (`node <gameslate> run -- <emulator>`). A spec
|
|
219
|
+
without `gameslate` needs its own `"launchPrefix"`; an emulator started bare is never read
|
|
220
|
+
(the daemon shows "Launch <game> through GameSlate to read it").
|
|
220
221
|
|
|
221
222
|
## 4. Run it
|
|
222
223
|
|
package/template/plugin/live.ts
CHANGED
|
@@ -33,7 +33,8 @@ const source: GamePlugin = {
|
|
|
33
33
|
gameId: GAME_ID,
|
|
34
34
|
stateSchemaVersion: 2,
|
|
35
35
|
capabilities: ['stats'],
|
|
36
|
-
/* the exact builds these reads were verified against (ELF/PE build id → label)
|
|
36
|
+
/* the exact builds these reads were verified against (ELF/PE build id → label); each is
|
|
37
|
+
* also in the manifest's `builds`, with the executable's name, or the core refuses it */
|
|
37
38
|
supportedBuildIds: new Map([
|
|
38
39
|
['0000000000000000000000000000000000000000', { region: 'example' }],
|
|
39
40
|
]),
|
|
@@ -3,5 +3,11 @@
|
|
|
3
3
|
"name": "{{name}}",
|
|
4
4
|
"version": "0.1.0",
|
|
5
5
|
"sdkApi": 0,
|
|
6
|
-
"games": [
|
|
6
|
+
"games": [
|
|
7
|
+
{
|
|
8
|
+
"id": "{{id}}-game",
|
|
9
|
+
"title": "{{name}}",
|
|
10
|
+
"builds": [{ "id": "0000000000000000000000000000000000000000", "name": "{{id}}" }]
|
|
11
|
+
}
|
|
12
|
+
]
|
|
7
13
|
}
|