@gameslate/sdk 0.3.24 → 0.3.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/build/build-plugin.mjs +18 -3
- package/build/spread-limit.d.mts +6 -0
- package/build/spread-limit.mjs +202 -0
- package/lib/arrays.d.ts +10 -0
- package/lib/arrays.js +31 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/plugin/wasm.js +3 -1
- package/package.json +2 -1
- package/template/claude/skills/build-gameslate-plugin/SKILL.md +50 -0
package/README.md
CHANGED
|
@@ -66,6 +66,21 @@ no file system, no network. Read the game through `GameMemory`, the player's fil
|
|
|
66
66
|
`InputFile`, and bytes with `Bytes`. Return data (states, drawings, pixels, meshes, notes); the core
|
|
67
67
|
validates it and writes every file.
|
|
68
68
|
|
|
69
|
+
The sandbox refuses a call of more than 65535 arguments, where Node (and so vitest) takes far more:
|
|
70
|
+
`Math.min(...xs)`, `out.push(...items)` or `String.fromCharCode(...bytes)` over a map's worth of
|
|
71
|
+
data passes the tests and fails in the core. So `gameslate-plugin build` refuses a spread argument,
|
|
72
|
+
and `x.apply(t, list)` (also `x['apply']`, `apply.call`), `Reflect.apply(fn, t, list)` and
|
|
73
|
+
`Reflect.construct(C, list)` with a list that isn't an array literal, in the plugin's own code,
|
|
74
|
+
naming the file and line; a file it can't parse fails the build too. Fold and append by loop with
|
|
75
|
+
`extent(values, what)` (`{ min, max }`; throws on no values or a non-finite one) and
|
|
76
|
+
`append(into, items)` from `@gameslate/sdk`. A spread whose length the code fixes (four header
|
|
77
|
+
bytes, a triangle's corners) stays with `/* spread-ok: <why> */` on the line directly above its
|
|
78
|
+
statement (a function, class, `export default` or class property counts as one). The marker covers
|
|
79
|
+
the calls that start on that statement's first line, including those of a statement nested there
|
|
80
|
+
(`for (…) f(...p)`), and nothing on later lines: not a loop body, not a multi-line arrow's body. A
|
|
81
|
+
marker needs a reason and must mark something. Dependencies under `node_modules` aren't checked
|
|
82
|
+
(they can't be marked).
|
|
83
|
+
|
|
69
84
|
A file the asset code needs from the web (a port's source at a pinned commit) is a download in the
|
|
70
85
|
game's manifest entry: `downloads: [{ id, url, sha256 }]`, an exact https URL. The core fetches it
|
|
71
86
|
when a build for that game starts, checks the hash, and hands it to `listAssets` / `buildAsset` as
|
|
@@ -75,6 +90,11 @@ the input `downloads/<id>`; the player sees it among the plugin's permissions.
|
|
|
75
90
|
|
|
76
91
|
`0.3.x` speaks plugin contract (`sdkApi`) 3: new 0.3 versions add tools, never change the contract. The core refuses a plugin built for another contract.
|
|
77
92
|
|
|
93
|
+
- **0.3.25**: `extent` and `append` fold and append by loop; `gameslate-plugin build` refuses a
|
|
94
|
+
call whose argument count is an array's length (a spread argument, `.apply`, `Reflect.apply`,
|
|
95
|
+
`Reflect.construct`) unless a `/* spread-ok: <why> */` marker sits directly above its
|
|
96
|
+
statement: the sandbox refuses more than 65535 arguments. The sdk now depends on `typescript` (the check
|
|
97
|
+
parses the plugin's source).
|
|
78
98
|
- **0.3.24**: `gameslate-plugin addresses` takes `sourceTypes` (`[{ file, types }]`): types a
|
|
79
99
|
decomp declares only in a `.c` file, lifted into the probe at probe time so their `offsetof`
|
|
80
100
|
and `sizeof` can be checked. A declaration inside an `#if` region, or holding a preprocessor
|
package/build/build-plugin.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { createHash } from 'node:crypto';
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import { createRequire } from 'node:module';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
+
import { checkSpreadLimit } from './spread-limit.mjs';
|
|
7
8
|
import { renderLicences } from './third-party-licences.mjs';
|
|
8
9
|
import { zipFolder } from './zip.mjs';
|
|
9
10
|
|
|
@@ -24,7 +25,9 @@ export { zipEntries } from './zip.mjs';
|
|
|
24
25
|
* registry/ the plugin's registry data, copied as it is (the core checks it on load:
|
|
25
26
|
* src/host/plugin-registry.ts; `gameslate-plugin validate` runs the same check)
|
|
26
27
|
* Sandbox scripts are built for a neutral platform, so a Node API in them fails the build. No plugin
|
|
27
|
-
* code runs outside the sandbox: an `extract.ts` (the old unsandboxed hooks) fails the build.
|
|
28
|
+
* code runs outside the sandbox: an `extract.ts` (the old unsandboxed hooks) fails the build. A
|
|
29
|
+
* call whose argument count is an array's length (`f(...xs)`, `.apply`) fails it too, unless its
|
|
30
|
+
* site is marked as staying small: the sandbox refuses more than 65535 (spread-limit.mjs).
|
|
28
31
|
*
|
|
29
32
|
* With `release` (a folder), it also writes what a release uploads, side by side:
|
|
30
33
|
* <id>-<version>.zip the built folder, under <id>/
|
|
@@ -68,11 +71,22 @@ const nodeResolution = {
|
|
|
68
71
|
|
|
69
72
|
const hashOf = file => createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
|
70
73
|
|
|
71
|
-
|
|
74
|
+
const SANDBOX_ENTRY = 'sandbox-entry.ts';
|
|
75
|
+
|
|
72
76
|
/* the absolute paths of the modules an esbuild result bundled */
|
|
73
77
|
const inputsOf = (srcDir, result) =>
|
|
74
78
|
Object.keys(result.metafile.inputs).map(input => path.resolve(srcDir, input));
|
|
75
79
|
|
|
80
|
+
/* the absolute paths of the modules that put code into the bundle (an output's inputs: a module
|
|
81
|
+
* only imported for what tree shaking dropped isn't one), without the generated entry */
|
|
82
|
+
const contributorsOf = (srcDir, result) =>
|
|
83
|
+
Object.values(result.metafile.outputs).flatMap(output =>
|
|
84
|
+
Object.keys(output.inputs)
|
|
85
|
+
.filter(input => input !== SANDBOX_ENTRY)
|
|
86
|
+
.map(input => path.resolve(srcDir, input)),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
/* a sandbox script: `entry`'s default export handed to the sdk's `expose` function */
|
|
76
90
|
async function buildSandboxed({ srcDir, entry, expose, outfile, alias }) {
|
|
77
91
|
const result = await esbuild.build({
|
|
78
92
|
absWorkingDir: srcDir,
|
|
@@ -83,7 +97,7 @@ async function buildSandboxed({ srcDir, entry, expose, outfile, alias }) {
|
|
|
83
97
|
`${expose}(plugin);`,
|
|
84
98
|
].join('\n'),
|
|
85
99
|
resolveDir: srcDir,
|
|
86
|
-
sourcefile:
|
|
100
|
+
sourcefile: SANDBOX_ENTRY,
|
|
87
101
|
loader: 'ts',
|
|
88
102
|
},
|
|
89
103
|
outfile,
|
|
@@ -98,6 +112,7 @@ async function buildSandboxed({ srcDir, entry, expose, outfile, alias }) {
|
|
|
98
112
|
metafile: true,
|
|
99
113
|
logLevel: 'warning',
|
|
100
114
|
});
|
|
115
|
+
checkSpreadLimit(contributorsOf(srcDir, result), path.dirname(srcDir));
|
|
101
116
|
return inputsOf(srcDir, result);
|
|
102
117
|
}
|
|
103
118
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** One source file's problems, each `<file>:<line>: <what>` (see spread-limit.mjs). */
|
|
2
|
+
export function spreadProblems(file: string, text: string): string[];
|
|
3
|
+
|
|
4
|
+
/** Throws, listing every problem, when the plugin code in `modules` calls with an unbounded
|
|
5
|
+
* argument count; files are named relative to `baseDir`. */
|
|
6
|
+
export function checkSpreadLimit(modules: readonly string[], baseDir: string): void;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* The core's QuickJS sandbox refuses a call of more than 65535 arguments; Node takes far more, so
|
|
7
|
+
* `Math.min(...xs)` over a big map passes vitest and fails in the sandbox (DK64's Frantic Factory,
|
|
8
|
+
* 2026-12-06). The build refuses every call whose argument count is the length of an array:
|
|
9
|
+
* a spread argument, and `.apply` (also as `['apply']` and `apply.call`), `Reflect.apply` and
|
|
10
|
+
* `Reflect.construct` with a list that isn't an array literal.
|
|
11
|
+
*
|
|
12
|
+
* A site whose length the code fixes (a triangle's corners) stays only with a block comment
|
|
13
|
+
* `spread-ok: <why>` on the line directly above its statement. A statement here is also a function,
|
|
14
|
+
* class, `export default` or class property declaration. The marker covers the calls that start on
|
|
15
|
+
* that statement's first line, its own and those of statements nested on the same line
|
|
16
|
+
* (`for (…) f(...xs)`), and nothing on later lines: not a loop body, not an arrow's body. A marker
|
|
17
|
+
* needs a reason, and one that marks nothing is refused.
|
|
18
|
+
*
|
|
19
|
+
* The plugin's own source is read, not the bundle: esbuild drops plain comments, so the marker
|
|
20
|
+
* wouldn't reach the bundle. Only the modules that put code into the bundle are read (esbuild's
|
|
21
|
+
* metafile), and not those under node_modules: a dependency can't be marked.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const MARKER = /^\/\*\s*spread-ok\b:?\s*(.*?)\s*\*\/$/s;
|
|
25
|
+
const LIMIT =
|
|
26
|
+
"the sandbox refuses a call of more than 65535 arguments: fold or append by loop (extent, append from '@gameslate/sdk'), or mark a statement whose spread stays small with /* spread-ok: <why> */ on the line directly above";
|
|
27
|
+
|
|
28
|
+
const lineAt = (source, pos) => source.getLineAndCharacterOfPosition(pos).line + 1;
|
|
29
|
+
const lineOf = (source, node) => lineAt(source, node.getStart(source));
|
|
30
|
+
|
|
31
|
+
/* what a marker can lead */
|
|
32
|
+
const isStatement = node =>
|
|
33
|
+
(node.kind >= ts.SyntaxKind.FirstStatement && node.kind <= ts.SyntaxKind.LastStatement) ||
|
|
34
|
+
ts.isFunctionDeclaration(node) ||
|
|
35
|
+
ts.isClassDeclaration(node) ||
|
|
36
|
+
ts.isExportAssignment(node) ||
|
|
37
|
+
ts.isPropertyDeclaration(node);
|
|
38
|
+
|
|
39
|
+
/* the statement `node` is in, and any enclosing one that starts on the same line */
|
|
40
|
+
function statementsOf(source, node) {
|
|
41
|
+
const found = [];
|
|
42
|
+
for (let n = node.parent; n !== undefined && !ts.isSourceFile(n); n = n.parent) {
|
|
43
|
+
if (!isStatement(n)) continue;
|
|
44
|
+
const first = found[0];
|
|
45
|
+
if (first !== undefined && lineOf(source, n) !== lineOf(source, first)) break;
|
|
46
|
+
found.push(n);
|
|
47
|
+
}
|
|
48
|
+
return found;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* a list whose length is fixed in the source: an array literal without spreads */
|
|
52
|
+
const isFixedList = node =>
|
|
53
|
+
ts.isArrayLiteralExpression(node) && !node.elements.some(e => ts.isSpreadElement(e));
|
|
54
|
+
|
|
55
|
+
/* `object.name` or `object['name']`, parentheses skipped: `{ object, name }`, or undefined */
|
|
56
|
+
function memberOf(expression) {
|
|
57
|
+
const e = ts.skipParentheses(expression);
|
|
58
|
+
if (ts.isPropertyAccessExpression(e)) return { object: e.expression, name: e.name.text };
|
|
59
|
+
if (ts.isElementAccessExpression(e) && ts.isStringLiteralLike(e.argumentExpression))
|
|
60
|
+
return { object: e.expression, name: e.argumentExpression.text };
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* the list `call` spreads into a call through apply or Reflect: `{ rule, list }`, or undefined */
|
|
65
|
+
function appliedList(call) {
|
|
66
|
+
const member = memberOf(call.expression);
|
|
67
|
+
if (!member) return undefined;
|
|
68
|
+
const object = ts.skipParentheses(member.object);
|
|
69
|
+
const onReflect = ts.isIdentifier(object) && object.text === 'Reflect';
|
|
70
|
+
const args = call.arguments;
|
|
71
|
+
if (onReflect && member.name === 'apply') return { rule: 'Reflect.apply', list: args[2] };
|
|
72
|
+
if (onReflect && member.name === 'construct')
|
|
73
|
+
return { rule: 'Reflect.construct', list: args[1] };
|
|
74
|
+
if (member.name === 'apply') return { rule: '.apply with an argument list', list: args[1] };
|
|
75
|
+
if (member.name === 'call' && memberOf(object)?.name === 'apply')
|
|
76
|
+
return { rule: '.apply.call with an argument list', list: args[2] };
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Sites in `source` that pass an array's length of arguments: `{ node, call, rule }`. */
|
|
81
|
+
function unboundedSites(source) {
|
|
82
|
+
const found = [];
|
|
83
|
+
const visit = node => {
|
|
84
|
+
if (ts.isCallExpression(node) || ts.isNewExpression(node)) {
|
|
85
|
+
for (const arg of node.arguments ?? [])
|
|
86
|
+
if (ts.isSpreadElement(arg))
|
|
87
|
+
found.push({ node: arg, call: node, rule: 'a spread argument' });
|
|
88
|
+
}
|
|
89
|
+
if (ts.isCallExpression(node)) {
|
|
90
|
+
const applied = appliedList(node);
|
|
91
|
+
if (applied?.list && !isFixedList(applied.list))
|
|
92
|
+
found.push({ node: applied.list, call: node, rule: applied.rule });
|
|
93
|
+
}
|
|
94
|
+
ts.forEachChild(node, visit);
|
|
95
|
+
};
|
|
96
|
+
visit(source);
|
|
97
|
+
return found;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* the spread-ok marker on the line directly above one of the statements whose first line `site`'s
|
|
101
|
+
* call starts on: `{ pos, reason }`, or undefined */
|
|
102
|
+
function markerOf(source, site) {
|
|
103
|
+
const statements = statementsOf(source, site.node);
|
|
104
|
+
const first = statements[0];
|
|
105
|
+
if (first === undefined || lineOf(source, site.call) !== lineOf(source, first))
|
|
106
|
+
return undefined;
|
|
107
|
+
for (const statement of statements) {
|
|
108
|
+
const ranges = ts.getLeadingCommentRanges(source.text, statement.getFullStart()) ?? [];
|
|
109
|
+
for (const range of ranges) {
|
|
110
|
+
if (lineAt(source, range.end) !== lineOf(source, statement) - 1) continue;
|
|
111
|
+
const match = MARKER.exec(source.text.slice(range.pos, range.end));
|
|
112
|
+
if (match) return { pos: range.pos, reason: match[1] ?? '' };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* the positions of every spread-ok comment in `source`; every token is visited (getChildren,
|
|
119
|
+
* not forEachChild), since a comment after `(` is trivia of the parenthesis, not of a node */
|
|
120
|
+
function markerPositions(source) {
|
|
121
|
+
const found = new Set();
|
|
122
|
+
const collect = ranges => {
|
|
123
|
+
for (const range of ranges ?? [])
|
|
124
|
+
if (MARKER.test(source.text.slice(range.pos, range.end))) found.add(range.pos);
|
|
125
|
+
};
|
|
126
|
+
const visit = node => {
|
|
127
|
+
collect(ts.getLeadingCommentRanges(source.text, node.pos));
|
|
128
|
+
collect(ts.getTrailingCommentRanges(source.text, node.end));
|
|
129
|
+
for (const child of node.getChildren(source)) visit(child);
|
|
130
|
+
};
|
|
131
|
+
visit(source);
|
|
132
|
+
return found;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function scriptKindOf(file) {
|
|
136
|
+
if (/\.tsx$/.test(file)) return ts.ScriptKind.TSX;
|
|
137
|
+
if (/\.[cm]?ts$/.test(file)) return ts.ScriptKind.TS;
|
|
138
|
+
if (/\.jsx$/.test(file)) return ts.ScriptKind.JSX;
|
|
139
|
+
if (/\.[cm]?js$/.test(file)) return ts.ScriptKind.JS;
|
|
140
|
+
throw new Error(`${file}: not a script the spread check can read`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* The problems in one source file, each `<file>:<line>: <what>`: unmarked sites, markers without
|
|
145
|
+
* a reason and markers that mark nothing. `file` names it in the messages. Throws on a file that
|
|
146
|
+
* doesn't parse: a misparse can hide a spread.
|
|
147
|
+
*/
|
|
148
|
+
export function spreadProblems(file, text) {
|
|
149
|
+
const source = ts.createSourceFile(
|
|
150
|
+
file,
|
|
151
|
+
text,
|
|
152
|
+
ts.ScriptTarget.Latest,
|
|
153
|
+
true,
|
|
154
|
+
scriptKindOf(file),
|
|
155
|
+
);
|
|
156
|
+
const [syntax] = source.parseDiagnostics;
|
|
157
|
+
if (syntax)
|
|
158
|
+
throw new Error(
|
|
159
|
+
`${file}:${lineAt(source, syntax.start)}: the spread check can't parse it: ${ts.flattenDiagnosticMessageText(syntax.messageText, ' ')}`,
|
|
160
|
+
);
|
|
161
|
+
const problems = [];
|
|
162
|
+
const used = new Set();
|
|
163
|
+
for (const site of unboundedSites(source)) {
|
|
164
|
+
const marker = markerOf(source, site);
|
|
165
|
+
if (!marker) {
|
|
166
|
+
problems.push({ line: lineOf(source, site.node), text: `${site.rule}: ${LIMIT}` });
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (used.has(marker.pos)) continue;
|
|
170
|
+
used.add(marker.pos);
|
|
171
|
+
if (!marker.reason)
|
|
172
|
+
problems.push({
|
|
173
|
+
line: lineAt(source, marker.pos),
|
|
174
|
+
text: 'a spread-ok marker needs a reason: /* spread-ok: <why it stays small> */',
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
for (const pos of markerPositions(source))
|
|
178
|
+
if (!used.has(pos))
|
|
179
|
+
problems.push({
|
|
180
|
+
line: lineAt(source, pos),
|
|
181
|
+
text: 'a spread-ok marker that marks no spread, .apply or Reflect call: it goes on the line directly above the statement',
|
|
182
|
+
});
|
|
183
|
+
return problems.sort((a, b) => a.line - b.line).map(p => `${file}:${p.line}: ${p.text}`);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* modules read as code, not data an esbuild loader bundles (JSON, text) */
|
|
187
|
+
const CODE = /\.([cm]?[jt]sx?)$/;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Throws, listing every problem, when the plugin code in `modules` (absolute paths) calls with an
|
|
191
|
+
* unbounded argument count. Files are named relative to `baseDir`.
|
|
192
|
+
*/
|
|
193
|
+
export function checkSpreadLimit(modules, baseDir) {
|
|
194
|
+
const own = modules.filter(m => CODE.test(m) && !m.split(path.sep).includes('node_modules'));
|
|
195
|
+
const problems = own.flatMap(m =>
|
|
196
|
+
spreadProblems(path.relative(baseDir, m), fs.readFileSync(m, 'utf8')),
|
|
197
|
+
);
|
|
198
|
+
if (problems.length)
|
|
199
|
+
throw new Error(
|
|
200
|
+
`plugin code calls with an unbounded argument count:\n${problems.map(p => ` ${p}`).join('\n')}`,
|
|
201
|
+
);
|
|
202
|
+
}
|
package/lib/arrays.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The least and greatest of `values`. Throws on none, or on one that isn't a finite number: either
|
|
3
|
+
* would frame or band a drawing on NaN or infinite pixels. `what` names the values in the error.
|
|
4
|
+
*/
|
|
5
|
+
export declare function extent(values: Iterable<number>, what: string): {
|
|
6
|
+
min: number;
|
|
7
|
+
max: number;
|
|
8
|
+
};
|
|
9
|
+
/** Appends `items` to `into`, in order. */
|
|
10
|
+
export declare function append<T>(into: T[], items: Iterable<T>): void;
|
package/lib/arrays.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Folds and appends by loop, never by spreading an array into a call: the core's QuickJS sandbox
|
|
3
|
+
* refuses a call of more than 65535 arguments where Node takes far more, so `Math.min(...xs)` over
|
|
4
|
+
* a big map passes vitest and fails in the sandbox (`gameslate-plugin build` refuses the spread).
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The least and greatest of `values`. Throws on none, or on one that isn't a finite number: either
|
|
8
|
+
* would frame or band a drawing on NaN or infinite pixels. `what` names the values in the error.
|
|
9
|
+
*/
|
|
10
|
+
export function extent(values, what) {
|
|
11
|
+
let min = Infinity;
|
|
12
|
+
let max = -Infinity;
|
|
13
|
+
let seen = false;
|
|
14
|
+
for (const v of values) {
|
|
15
|
+
if (!Number.isFinite(v))
|
|
16
|
+
throw new Error(`${what} include ${v}`);
|
|
17
|
+
seen = true;
|
|
18
|
+
if (v < min)
|
|
19
|
+
min = v;
|
|
20
|
+
if (v > max)
|
|
21
|
+
max = v;
|
|
22
|
+
}
|
|
23
|
+
if (!seen)
|
|
24
|
+
throw new Error(`no ${what}`);
|
|
25
|
+
return { min, max };
|
|
26
|
+
}
|
|
27
|
+
/** Appends `items` to `into`, in order. */
|
|
28
|
+
export function append(into, items) {
|
|
29
|
+
for (const item of items)
|
|
30
|
+
into.push(item);
|
|
31
|
+
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/plugin/wasm.js
CHANGED
|
@@ -7,8 +7,10 @@ export function wasmModule(file) {
|
|
|
7
7
|
throw new Error('the core gave no WebAssembly capability');
|
|
8
8
|
return bridge;
|
|
9
9
|
};
|
|
10
|
+
/* spread-ok: a WebAssembly export's parameters, a handful of numbers */
|
|
11
|
+
const call = (fn, ...args) => host().call(file, fn, ...args);
|
|
10
12
|
return {
|
|
11
|
-
call
|
|
13
|
+
call,
|
|
12
14
|
read: (ptr, length) => new Uint8Array(host().read(file, ptr, length)),
|
|
13
15
|
/* an exact-size copy, so only these bytes cross */
|
|
14
16
|
write: (ptr, bytes) => host().write(file, ptr, bytes.slice().buffer),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gameslate/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.25",
|
|
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",
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"@jitl/quickjs-wasmfile-release-sync": "0.31.0",
|
|
77
77
|
"esbuild": "^0.24.0",
|
|
78
78
|
"quickjs-emscripten-core": "0.31.0",
|
|
79
|
+
"typescript": "^5.7.2",
|
|
79
80
|
"zod": "^3.24.1"
|
|
80
81
|
},
|
|
81
82
|
"gameslate": {
|
|
@@ -812,6 +812,56 @@ the plugin repos) in the same change as the fix. The next game should not have t
|
|
|
812
812
|
- **A place that covers several maps can't get a drawing.** DK64's live reader groups 95
|
|
813
813
|
unnamed maps as a world's "elsewhere"; plan for one place per map when a game has unnamed
|
|
814
814
|
maps.
|
|
815
|
+
- **A place name is a stated fact: two written sources, or the id.** Name a map only as far as
|
|
816
|
+
two written sources agree (decomp code or tables, a survey note, a recorded live run), cite both
|
|
817
|
+
beside the name, and otherwise name it by id ("map 0x38") while the live read supplies context.
|
|
818
|
+
Uncited player knowledge isn't a source: 33 of 44 names in DK64's first pass didn't survive
|
|
819
|
+
this. Slug unnamed places by id alone (`map-0c`), so a later name or ruling never changes a
|
|
820
|
+
slug; and a decomp's `.data` tables copied from the ROM (DK64's map → world table) are the
|
|
821
|
+
publisher's data, read live, not committed (DK64 review, 2026-12-05).
|
|
822
|
+
- **A counter declared only for `describeState` also reaches the AI.** Shared code puts every
|
|
823
|
+
declared counter the state carries into LIVE_STATE (`readableCountersFor`): DK64's world counter
|
|
824
|
+
told the model the main menu was "a shop". Send such a counter only where its value means
|
|
825
|
+
something to the model, and throw in `describeState` where it must be present.
|
|
826
|
+
- **The 65535-argument limit.** The core's QuickJS sandbox refuses a call of more than 65535
|
|
827
|
+
arguments; Node allows far more, so `Math.min(...xs)`, `out.push(...items)` and
|
|
828
|
+
`String.fromCharCode(...bytes)` over map-sized data pass vitest and throw in the sandbox (DK64's
|
|
829
|
+
Frantic Factory, 2026-12-06). `gameslate-plugin build` (sdk >= 0.3.25) reads your own code (what
|
|
830
|
+
`live.ts` and `assets.ts` bundle, not `node_modules`) and refuses, naming file:line, a spread
|
|
831
|
+
argument to any call or `new`, and `x.apply(t, list)`, `x['apply'](t, list)`,
|
|
832
|
+
`Function.prototype.apply.call(f, t, list)`, `Reflect.apply` and `Reflect.construct` unless the
|
|
833
|
+
list is an array literal without spreads; a file it can't parse fails too. Fold with
|
|
834
|
+
`extent(values, 'corner xs')` (it throws on no values or a non-finite one, so a bad frame fails
|
|
835
|
+
loud) and append with `append(into, items)`, both from `@gameslate/sdk`. When the length is fixed,
|
|
836
|
+
prefer plain arguments (`f(p[0], p[1], p[2])`). Otherwise put `/* spread-ok: <why it stays small>
|
|
837
|
+
*/` on the line directly above the statement (a function, class, `export default` or class
|
|
838
|
+
property counts); it covers only calls that start on that statement's first line, never a loop
|
|
839
|
+
body or a multi-line arrow's body below, and the build refuses an empty reason or a marker that
|
|
840
|
+
marks nothing. Decode text in chunks of at most 0x2000 bytes (marked) or by loop. Dependencies
|
|
841
|
+
aren't checked: if one handles map-sized arrays, test a big input in the sandbox
|
|
842
|
+
(`@gameslate/sdk/host`). After a change that grows the geometry, run `gameslate extract-assets
|
|
843
|
+
<game> --input <rom> --out-dir <scratch>` (the core's `dist/gameslate.mjs` with
|
|
844
|
+
`GAMESLATE_PLUGINS_DIR=<plugin>/dist`).
|
|
845
|
+
- **Follow every source the floor or water query asks.** DK64's floor query merges the map mesh,
|
|
846
|
+
placed models and actor boxes; Conker's water height comes from water props, trigger-zone
|
|
847
|
+
volumes and surface type 8 at once. Port the game's query, not one of its sources, and say in
|
|
848
|
+
Known Gaps which sources are built at run time (animated bones, actor floors, scripted water)
|
|
849
|
+
and so aren't drawn.
|
|
850
|
+
- **A trigger volume isn't a surface.** Port its contains-test exactly (Conker's
|
|
851
|
+
`zone_isOutside`: thresholds, integer truncation, rotation order), draw the floors it holds as
|
|
852
|
+
water rather than its outline, check whether overlaps resolve last-wins or highest-wins, and
|
|
853
|
+
check any pre-filter the caller applies (a bounds box that rotates when the test doesn't).
|
|
854
|
+
Recolour floors under water as water, so a band painter can't hide a pond under ground of the
|
|
855
|
+
same band.
|
|
856
|
+
- **Prove a rotation's sign at a non-90° angle, axes combined.** A 90° turn or one axis lets a
|
|
857
|
+
sign error through, and a ROM check over mostly unrotated objects can't see it: derive order and
|
|
858
|
+
sign from the game's matrix chain (row vectors, `guMtxCatF` is a × b), pin per-axis goldens,
|
|
859
|
+
order goldens and an independent matrix oracle. Use the SDK's documented conventions, not the
|
|
860
|
+
decomp's copy of libultra, which is Nintendo's code.
|
|
861
|
+
- **Read the spawn function before blaming a spawn with no floor.** DK64's "nothing under"
|
|
862
|
+
spawns were doorway walk-ins (the kong walks 50 units along its yaw): test the walk's end over
|
|
863
|
+
a floor instead of raising a cap.
|
|
864
|
+
- **Padded record files:** accept a zero tail shorter than one record, refuse anything else.
|
|
815
865
|
- **Keep exploration tests out of a shared tree.** A `*.scratch.test.ts` broke another agent's
|
|
816
866
|
check: explore from the scratchpad.
|
|
817
867
|
- **Mirror modes: draw the course as built.** `roomId` means a room to shared code (layer
|