@gameslate/sdk 0.3.17 → 0.3.19
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 +23 -3
- package/bin/gameslate-plugin.mjs +6 -2
- package/build/build-plugin.d.mts +8 -2
- package/build/build-plugin.mjs +40 -36
- package/build/zip.d.mts +6 -0
- package/build/zip.mjs +94 -0
- package/lib/assets.d.ts +41 -1
- package/lib/assets.js +22 -0
- package/lib/host/asset-sandbox.d.ts +2 -1
- package/lib/host/asset-sandbox.js +7 -2
- package/lib/host/inspect.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/plugin/contract.d.ts +2 -45
- package/lib/plugin-manifest.d.ts +172 -21
- package/lib/plugin-manifest.js +88 -11
- package/lib/plugin-permissions.d.ts +20 -0
- package/lib/plugin-permissions.js +58 -0
- package/lib/plugins-api.d.ts +470 -0
- package/lib/plugins-api.js +56 -1
- package/package.json +1 -1
- package/template/README.md +8 -0
- package/template/claude/skills/build-gameslate-plugin/SKILL.md +144 -4
- package/template/github/workflows/release.yml +38 -0
- package/template/gitignore +2 -0
- package/template/plugin/tracked-documents.test.ts +68 -0
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ cd gameslate-mygame && yarn install && yarn check
|
|
|
33
33
|
## A plugin folder
|
|
34
34
|
|
|
35
35
|
```text
|
|
36
|
-
manifest.json id, name, version, sdkApi, games (
|
|
36
|
+
manifest.json id, name, version, sdkApi, games (where their files usually are, and any downloads)
|
|
37
37
|
live.ts default export: { id, packs, sources }: game data and memory readers
|
|
38
38
|
assets.ts optional, default export: { id, extractors }: maps and meshes from the player's files
|
|
39
39
|
```
|
|
@@ -43,6 +43,14 @@ gameslate-plugin build ./my-plugin --out ./dist/my-plugin --tested-with 2.3.0
|
|
|
43
43
|
gameslate-plugin validate ./dist/my-plugin
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
For a release, `--release <dir>` also writes `<id>-<version>.zip`, its `.sha256`, and the published
|
|
47
|
+
`manifest.json` naming the zip and its sha256 (`bundle`). Upload all three: players add the plugin in
|
|
48
|
+
GameSlate's settings by the manifest's URL (for GitHub,
|
|
49
|
+
`https://github.com/<owner>/<repo>/releases/latest/download/manifest.json`), and GameSlate checks it
|
|
50
|
+
for updates. An update asking for new permissions (another game's memory, another folder, another
|
|
51
|
+
download) waits for the player's consent; any other installs itself. All of a plugin's code runs in
|
|
52
|
+
the sandbox: there is no `extract` module any more, and the build refuses an `extract.ts`.
|
|
53
|
+
|
|
46
54
|
For closed-source games, `memory.scan({ pattern: '48 8B 05 ?? ?? ?? ??', offset: 3, kind: 'rip32' })`
|
|
47
55
|
finds an address by a byte pattern in the game's own code (once per session, exactly one match),
|
|
48
56
|
so the plugin survives patches. It is optional: check `memory.scan` exists (cores before 0.3.6,
|
|
@@ -54,13 +62,25 @@ shuffled? }`) for every `variant` your decoder emits.
|
|
|
54
62
|
|
|
55
63
|
`live.js` and `assets.js` run in the core's sandbox, built for a neutral platform: no Node APIs,
|
|
56
64
|
no file system, no network. Read the game through `GameMemory`, the player's files through
|
|
57
|
-
`InputFile`, and bytes with `Bytes`. Return data (states, drawings, pixels, meshes); the core
|
|
65
|
+
`InputFile`, and bytes with `Bytes`. Return data (states, drawings, pixels, meshes, notes); the core
|
|
58
66
|
validates it and writes every file.
|
|
59
67
|
|
|
68
|
+
A file the asset code needs from the web (a port's source at a pinned commit) is a download in the
|
|
69
|
+
game's manifest entry: `downloads: [{ id, url, sha256 }]`, an exact https URL. The core fetches it
|
|
70
|
+
when a build for that game starts, checks the hash, and hands it to `listAssets` / `buildAsset` as
|
|
71
|
+
the input `downloads/<id>`; the player sees it among the plugin's permissions.
|
|
72
|
+
|
|
60
73
|
## Versions
|
|
61
74
|
|
|
62
75
|
`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.
|
|
63
76
|
|
|
77
|
+
- **0.3.19** (not yet published): no plugin code runs outside the sandbox.
|
|
78
|
+
- `extract` (`afterAssets`, `pythonExtract`) is gone from the contract: the manifest schema is
|
|
79
|
+
strict and refuses it, and `gameslate-plugin build` refuses an `extract.ts`;
|
|
80
|
+
- games declare `downloads: [{ id, url, sha256 }]`, fetched by the core and read as the input
|
|
81
|
+
`downloads/<id>`;
|
|
82
|
+
- a `notes` asset output (`{ kind: 'notes', id, json }`, the text of one JSON object), written as
|
|
83
|
+
`notes/<id>.json` for a pack's `localSource`.
|
|
64
84
|
- **Next** (not yet published): `gameslate-plugin addresses` takes `statics`, file-static
|
|
65
85
|
variables placed at their object's section base in the ld map plus the offset their accessor
|
|
66
86
|
shows (IDO keeps statics out of the map), each with its `evidence`.
|
|
@@ -94,7 +114,7 @@ validates it and writes every file.
|
|
|
94
114
|
relative to the picked folder;
|
|
95
115
|
- offered folders can't be hidden folders except where games live (`~/.var/app`,
|
|
96
116
|
`~/.local/share`, `~/.steam`);
|
|
97
|
-
- `afterAssets` steps replace `pythonExtract` (deprecated);
|
|
117
|
+
- `afterAssets` steps replace `pythonExtract` (deprecated; both removed in 0.3.19);
|
|
98
118
|
- `raToGuest` / `guestToRa` translate RetroAchievements' N64 addresses;
|
|
99
119
|
- `gameslate-plugin verify`, and the two agent skills in the template;
|
|
100
120
|
- a plugin's sandbox refuses a build none of its sources verified, instead of using the first
|
package/bin/gameslate-plugin.mjs
CHANGED
|
@@ -6,8 +6,9 @@ import { buildPlugin } from '../build/build-plugin.mjs';
|
|
|
6
6
|
import { initPlugin } from '../build/init-plugin.mjs';
|
|
7
7
|
|
|
8
8
|
/*
|
|
9
|
-
* gameslate-plugin build <pluginDir> --out <dir> [--tested-with <coreVersion> ...]
|
|
9
|
+
* gameslate-plugin build <pluginDir> --out <dir> [--tested-with <coreVersion> ...] [--release <dir>]
|
|
10
10
|
* Builds a plugin folder into what the GameSlate core loads (see build/build-plugin.mjs).
|
|
11
|
+
* --release also writes the release zip, its .sha256 and the published manifest.json.
|
|
11
12
|
* gameslate-plugin init <dir> --id <id> [--name <name>]
|
|
12
13
|
* Scaffolds a new plugin repository: an example plugin, a sandbox test, CI.
|
|
13
14
|
* gameslate-plugin validate <builtDir> [--core-version <version>]
|
|
@@ -25,6 +26,7 @@ import { initPlugin } from '../build/init-plugin.mjs';
|
|
|
25
26
|
const { values, positionals } = parseArgs({
|
|
26
27
|
options: {
|
|
27
28
|
out: { type: 'string' },
|
|
29
|
+
release: { type: 'string' },
|
|
28
30
|
'tested-with': { type: 'string', multiple: true },
|
|
29
31
|
'core-version': { type: 'string' },
|
|
30
32
|
id: { type: 'string' },
|
|
@@ -38,7 +40,7 @@ const { values, positionals } = parseArgs({
|
|
|
38
40
|
const [command, dir] = positionals;
|
|
39
41
|
const USAGE = [
|
|
40
42
|
'usage: gameslate-plugin init <dir> --id <id> [--name <name>]',
|
|
41
|
-
' gameslate-plugin build <pluginDir> --out <dir> [--tested-with <version>]',
|
|
43
|
+
' gameslate-plugin build <pluginDir> --out <dir> [--tested-with <version>] [--release <dir>]',
|
|
42
44
|
' gameslate-plugin validate <builtDir> [--core-version <version>]',
|
|
43
45
|
' gameslate-plugin verify <verify.json>',
|
|
44
46
|
' gameslate-plugin addresses <spec.json> [--out <file.ts>]',
|
|
@@ -74,8 +76,10 @@ if (command === 'build' && dir && values.out) {
|
|
|
74
76
|
srcDir: path.resolve(dir),
|
|
75
77
|
outDir: path.resolve(values.out),
|
|
76
78
|
testedWith: values['tested-with'] ?? [],
|
|
79
|
+
release: values.release ? path.resolve(values.release) : undefined,
|
|
77
80
|
});
|
|
78
81
|
console.log(`built ${built.id} ${built.version} -> ${values.out}`);
|
|
82
|
+
if (values.release) console.log(`release (zip, .sha256, manifest.json) -> ${values.release}`);
|
|
79
83
|
} else if (command === 'init' && dir && values.id) {
|
|
80
84
|
const { SDK_API } = await import('../lib/index.js');
|
|
81
85
|
const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
package/build/build-plugin.d.mts
CHANGED
|
@@ -7,8 +7,9 @@ export interface BuildPluginOptions {
|
|
|
7
7
|
testedWith: string[];
|
|
8
8
|
/** esbuild aliases for the sandbox builds (a monorepo pointing at sources) */
|
|
9
9
|
alias?: Record<string, string>;
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/** also write the release here: `<id>-<version>.zip`, its `.sha256`, and the published
|
|
11
|
+
* `manifest.json` whose `bundle` names the zip and its sha256 */
|
|
12
|
+
release?: string;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
/** The built manifest (id, version, code hashes, …). */
|
|
@@ -19,3 +20,8 @@ export interface BuiltManifest {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export function buildPlugin(options: BuildPluginOptions): Promise<BuiltManifest>;
|
|
23
|
+
|
|
24
|
+
/** A zip of these entries (deflated, sorted, fixed dates); `mode` is the unix mode, 0644 if absent. */
|
|
25
|
+
export function zipEntries(
|
|
26
|
+
entries: Array<{ name: string; data: Uint8Array; mode?: number }>,
|
|
27
|
+
): Buffer;
|
package/build/build-plugin.mjs
CHANGED
|
@@ -4,24 +4,33 @@ import fs from 'node:fs';
|
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { renderLicences } from './third-party-licences.mjs';
|
|
7
|
+
import { zipFolder } from './zip.mjs';
|
|
8
|
+
|
|
9
|
+
export { zipEntries } from './zip.mjs';
|
|
7
10
|
|
|
8
11
|
/*
|
|
9
|
-
* Builds one plugin folder (manifest.json, live.ts, optionally assets.ts
|
|
10
|
-
*
|
|
12
|
+
* Builds one plugin folder (manifest.json, live.ts, optionally assets.ts) into what the GameSlate
|
|
13
|
+
* core loads, with a manifest carrying each code file's hash:
|
|
11
14
|
* live.js live.ts's default export behind `exposeToHost`, for the core's QuickJS sandbox
|
|
12
15
|
* assets.js assets.ts's default export behind `exposeAssetsToHost`, for extraction jobs
|
|
13
|
-
* extract.mjs extract.ts, Node code the core runs unsandboxed (legacy hooks; avoid)
|
|
14
16
|
* THIRD_PARTY_LICENSES.txt the licence of every npm package the code files bundle (one
|
|
15
17
|
* without a licence file fails the build), and THIRD_PARTY_NOTICES.md copied from
|
|
16
18
|
* the plugin's repository (beside its plugin folder) when it has one
|
|
17
19
|
* registry/ the plugin's registry data, copied as it is (the core checks it on load:
|
|
18
20
|
* src/host/plugin-registry.ts; `gameslate-plugin validate` runs the same check)
|
|
19
|
-
* Sandbox scripts are built for a neutral platform, so a Node API in them fails the build.
|
|
21
|
+
* Sandbox scripts are built for a neutral platform, so a Node API in them fails the build. No plugin
|
|
22
|
+
* code runs outside the sandbox: an `extract.ts` (the old unsandboxed hooks) fails the build.
|
|
23
|
+
*
|
|
24
|
+
* With `release` (a folder), it also writes what a release uploads, side by side:
|
|
25
|
+
* <id>-<version>.zip the built folder, under <id>/
|
|
26
|
+
* <id>-<version>.zip.sha256 its hash, in sha256sum's format
|
|
27
|
+
* manifest.json the published manifest: the built one plus `bundle`, naming the
|
|
28
|
+
* zip (relative to the URL players give for the manifest) and its sha256. A player adds
|
|
29
|
+
* the plugin by this file's URL, and the core checks for updates there.
|
|
20
30
|
*/
|
|
21
31
|
|
|
22
32
|
const LIVE_FILE = 'live.js';
|
|
23
33
|
const ASSETS_FILE = 'assets.js';
|
|
24
|
-
const EXTRACT_FILE = 'extract.mjs';
|
|
25
34
|
const LICENCES_FILE = 'THIRD_PARTY_LICENSES.txt';
|
|
26
35
|
const NOTICES_FILE = 'THIRD_PARTY_NOTICES.md';
|
|
27
36
|
|
|
@@ -81,35 +90,17 @@ async function buildSandboxed({ srcDir, entry, expose, outfile, alias }) {
|
|
|
81
90
|
return inputsOf(srcDir, result);
|
|
82
91
|
}
|
|
83
92
|
|
|
84
|
-
async function buildNode(srcDir, entry, outfile, alias) {
|
|
85
|
-
const result = await esbuild.build({
|
|
86
|
-
absWorkingDir: srcDir,
|
|
87
|
-
entryPoints: [path.join(srcDir, entry)],
|
|
88
|
-
outfile,
|
|
89
|
-
bundle: true,
|
|
90
|
-
platform: 'node',
|
|
91
|
-
target: 'node20',
|
|
92
|
-
format: 'esm',
|
|
93
|
-
alias,
|
|
94
|
-
plugins: Object.keys(alias).length ? [] : [nodeResolution],
|
|
95
|
-
banner: {
|
|
96
|
-
js: [
|
|
97
|
-
"import { createRequire as __gsCreateRequire } from 'node:module';",
|
|
98
|
-
'const require = __gsCreateRequire(import.meta.url);',
|
|
99
|
-
].join('\n'),
|
|
100
|
-
},
|
|
101
|
-
metafile: true,
|
|
102
|
-
logLevel: 'warning',
|
|
103
|
-
});
|
|
104
|
-
return inputsOf(srcDir, result);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
93
|
/**
|
|
108
94
|
* Builds `srcDir` into `outDir` (replaced). `testedWith`: the core versions it was tested with.
|
|
109
|
-
* `alias
|
|
110
|
-
*
|
|
95
|
+
* `alias`: esbuild aliases for the sandbox builds (a monorepo pointing at sources). Returns the
|
|
96
|
+
* built manifest.
|
|
111
97
|
*/
|
|
112
|
-
export async function buildPlugin({ srcDir, outDir, testedWith, alias = {},
|
|
98
|
+
export async function buildPlugin({ srcDir, outDir, testedWith, alias = {}, release }) {
|
|
99
|
+
if (fs.existsSync(path.join(srcDir, 'extract.ts')))
|
|
100
|
+
throw new Error(
|
|
101
|
+
'extract.ts is no longer part of the plugin contract: no plugin code runs outside the ' +
|
|
102
|
+
"sandbox. Build in assets.ts, and declare files from the web as the game's `downloads`.",
|
|
103
|
+
);
|
|
113
104
|
const manifest = JSON.parse(fs.readFileSync(path.join(srcDir, 'manifest.json'), 'utf8'));
|
|
114
105
|
fs.rmSync(outDir, { recursive: true, force: true });
|
|
115
106
|
fs.mkdirSync(outDir, { recursive: true });
|
|
@@ -135,11 +126,6 @@ export async function buildPlugin({ srcDir, outDir, testedWith, alias = {}, node
|
|
|
135
126
|
);
|
|
136
127
|
built.assets = { file: ASSETS_FILE, sha256: hashOf(out) };
|
|
137
128
|
}
|
|
138
|
-
if (fs.existsSync(path.join(srcDir, 'extract.ts'))) {
|
|
139
|
-
const out = path.join(outDir, EXTRACT_FILE);
|
|
140
|
-
bundled.push(...(await buildNode(srcDir, 'extract.ts', out, nodeAlias)));
|
|
141
|
-
built.extract = { file: EXTRACT_FILE, sha256: hashOf(out) };
|
|
142
|
-
}
|
|
143
129
|
fs.writeFileSync(
|
|
144
130
|
path.join(outDir, LICENCES_FILE),
|
|
145
131
|
renderLicences(`${manifest.id} ${manifest.version}: third-party licences`, bundled),
|
|
@@ -150,5 +136,23 @@ export async function buildPlugin({ srcDir, outDir, testedWith, alias = {}, node
|
|
|
150
136
|
if (fs.existsSync(registry))
|
|
151
137
|
fs.cpSync(registry, path.join(outDir, 'registry'), { recursive: true });
|
|
152
138
|
fs.writeFileSync(path.join(outDir, 'manifest.json'), `${JSON.stringify(built, null, 4)}\n`);
|
|
139
|
+
if (release) writeRelease(outDir, built, release);
|
|
153
140
|
return built;
|
|
154
141
|
}
|
|
142
|
+
|
|
143
|
+
/* The zip, its .sha256 and the published manifest naming both (see the top of this file). */
|
|
144
|
+
function writeRelease(outDir, built, releaseDir) {
|
|
145
|
+
if (path.resolve(releaseDir) === path.resolve(outDir))
|
|
146
|
+
throw new Error('--release needs a folder other than --out (the zip is made from --out)');
|
|
147
|
+
const zipName = `${built.id}-${built.version}.zip`;
|
|
148
|
+
const zip = zipFolder(outDir, built.id);
|
|
149
|
+
const sha256 = createHash('sha256').update(zip).digest('hex');
|
|
150
|
+
fs.mkdirSync(releaseDir, { recursive: true });
|
|
151
|
+
fs.writeFileSync(path.join(releaseDir, zipName), zip);
|
|
152
|
+
fs.writeFileSync(path.join(releaseDir, `${zipName}.sha256`), `${sha256} ${zipName}\n`);
|
|
153
|
+
const published = { ...built, bundle: { url: zipName, sha256 } };
|
|
154
|
+
fs.writeFileSync(
|
|
155
|
+
path.join(releaseDir, 'manifest.json'),
|
|
156
|
+
`${JSON.stringify(published, null, 4)}\n`,
|
|
157
|
+
);
|
|
158
|
+
}
|
package/build/zip.d.mts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** A zip of these entries (deflated, sorted, fixed dates); `mode` is the unix mode, 0644 if absent. */
|
|
2
|
+
export function zipEntries(
|
|
3
|
+
entries: Array<{ name: string; data: Uint8Array; mode?: number }>,
|
|
4
|
+
): Buffer;
|
|
5
|
+
/** A zip of folder `dir`, its files under `<prefix>/`. */
|
|
6
|
+
export function zipFolder(dir: string, prefix: string): Buffer;
|
package/build/zip.mjs
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import zlib from 'node:zlib';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* A zip writer for plugin releases: the build makes the zip itself, so the published manifest
|
|
7
|
+
* can carry its sha256. Entries are deflated, sorted by name and dated 1980-01-01, so the same
|
|
8
|
+
* files always give the same zip (and the same hash). No zip64: a plugin is a few MB.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const LOCAL_HEADER = 0x04034b50;
|
|
12
|
+
const CENTRAL_HEADER = 0x02014b50;
|
|
13
|
+
const END_OF_CENTRAL = 0x06054b50;
|
|
14
|
+
const METHOD_DEFLATE = 8;
|
|
15
|
+
const UNIX_VERSION_MADE_BY = (3 << 8) | 20;
|
|
16
|
+
const VERSION_NEEDED = 20;
|
|
17
|
+
/* 1980-01-01 00:00 in DOS date/time */
|
|
18
|
+
const DOS_DATE = (0 << 9) | (1 << 5) | 1;
|
|
19
|
+
const DOS_TIME = 0;
|
|
20
|
+
const FILE_MODE = 0o100644;
|
|
21
|
+
const UTF8_NAMES = 1 << 11;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A zip of `entries` (`name` with `/` separators; `mode` is the unix mode stored in the external
|
|
25
|
+
* attributes, a regular 0644 file unless given).
|
|
26
|
+
* @param {Array<{ name: string, data: Uint8Array, mode?: number }>} entries
|
|
27
|
+
* @returns {Buffer}
|
|
28
|
+
*/
|
|
29
|
+
export function zipEntries(entries) {
|
|
30
|
+
const locals = [];
|
|
31
|
+
const centrals = [];
|
|
32
|
+
let offset = 0;
|
|
33
|
+
for (const entry of [...entries].sort((a, b) => (a.name < b.name ? -1 : 1))) {
|
|
34
|
+
const name = Buffer.from(entry.name, 'utf8');
|
|
35
|
+
const data = zlib.deflateRawSync(entry.data, { level: 9 });
|
|
36
|
+
const crc = zlib.crc32(entry.data);
|
|
37
|
+
const local = Buffer.alloc(30);
|
|
38
|
+
local.writeUInt32LE(LOCAL_HEADER, 0);
|
|
39
|
+
local.writeUInt16LE(VERSION_NEEDED, 4);
|
|
40
|
+
local.writeUInt16LE(UTF8_NAMES, 6);
|
|
41
|
+
local.writeUInt16LE(METHOD_DEFLATE, 8);
|
|
42
|
+
local.writeUInt16LE(DOS_TIME, 10);
|
|
43
|
+
local.writeUInt16LE(DOS_DATE, 12);
|
|
44
|
+
local.writeUInt32LE(crc, 14);
|
|
45
|
+
local.writeUInt32LE(data.length, 18);
|
|
46
|
+
local.writeUInt32LE(entry.data.length, 22);
|
|
47
|
+
local.writeUInt16LE(name.length, 26);
|
|
48
|
+
local.writeUInt16LE(0, 28);
|
|
49
|
+
const central = Buffer.alloc(46);
|
|
50
|
+
central.writeUInt32LE(CENTRAL_HEADER, 0);
|
|
51
|
+
central.writeUInt16LE(UNIX_VERSION_MADE_BY, 4);
|
|
52
|
+
central.writeUInt16LE(VERSION_NEEDED, 6);
|
|
53
|
+
central.writeUInt16LE(UTF8_NAMES, 8);
|
|
54
|
+
central.writeUInt16LE(METHOD_DEFLATE, 10);
|
|
55
|
+
central.writeUInt16LE(DOS_TIME, 12);
|
|
56
|
+
central.writeUInt16LE(DOS_DATE, 14);
|
|
57
|
+
central.writeUInt32LE(crc, 16);
|
|
58
|
+
central.writeUInt32LE(data.length, 20);
|
|
59
|
+
central.writeUInt32LE(entry.data.length, 24);
|
|
60
|
+
central.writeUInt16LE(name.length, 28);
|
|
61
|
+
central.writeUInt32LE(((entry.mode ?? FILE_MODE) << 16) >>> 0, 38);
|
|
62
|
+
central.writeUInt32LE(offset, 42);
|
|
63
|
+
locals.push(local, name, data);
|
|
64
|
+
centrals.push(central, name);
|
|
65
|
+
offset += local.length + name.length + data.length;
|
|
66
|
+
}
|
|
67
|
+
const centralSize = centrals.reduce((n, b) => n + b.length, 0);
|
|
68
|
+
const end = Buffer.alloc(22);
|
|
69
|
+
end.writeUInt32LE(END_OF_CENTRAL, 0);
|
|
70
|
+
end.writeUInt16LE(centrals.length / 2, 8);
|
|
71
|
+
end.writeUInt16LE(centrals.length / 2, 10);
|
|
72
|
+
end.writeUInt32LE(centralSize, 12);
|
|
73
|
+
end.writeUInt32LE(offset, 16);
|
|
74
|
+
return Buffer.concat([...locals, ...centrals, end]);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A zip of folder `dir`, its files under `<prefix>/`.
|
|
79
|
+
* @param {string} dir
|
|
80
|
+
* @param {string} prefix
|
|
81
|
+
* @returns {Buffer}
|
|
82
|
+
*/
|
|
83
|
+
export function zipFolder(dir, prefix) {
|
|
84
|
+
const files = fs
|
|
85
|
+
.readdirSync(dir, { recursive: true, withFileTypes: true })
|
|
86
|
+
.filter(e => e.isFile())
|
|
87
|
+
.map(e => path.join(e.parentPath, e.name));
|
|
88
|
+
return zipEntries(
|
|
89
|
+
files.map(file => ({
|
|
90
|
+
name: `${prefix}/${path.relative(dir, file).split(path.sep).join('/')}`,
|
|
91
|
+
data: fs.readFileSync(file),
|
|
92
|
+
})),
|
|
93
|
+
);
|
|
94
|
+
}
|
package/lib/assets.d.ts
CHANGED
|
@@ -127,6 +127,8 @@ export declare const FloorplanDrawingSchema: z.ZodObject<{
|
|
|
127
127
|
export type FloorplanDrawing = z.infer<typeof FloorplanDrawingSchema>;
|
|
128
128
|
/** The SVG for a drawing. Every value in it has passed the schema, so it's safe to serve. */
|
|
129
129
|
export declare function floorplanToSvg(drawing: FloorplanDrawing): string;
|
|
130
|
+
/** The largest notes output, in characters. */
|
|
131
|
+
export declare const NOTES_MAX_CHARS: number;
|
|
130
132
|
export declare const ImagePurposeSchema: z.ZodEnum<["atlas", "map", "icon", "actor"]>;
|
|
131
133
|
export type ImagePurpose = z.infer<typeof ImagePurposeSchema>;
|
|
132
134
|
/** PNG, lossless WebP, or lossy WebP at a quality from 1 to 100. */
|
|
@@ -161,6 +163,7 @@ export type ImageEncoding = z.infer<typeof ImageEncodingSchema>;
|
|
|
161
163
|
* floorplan → maps/<id>.svg location → manifest.json (locations[id])
|
|
162
164
|
* nav → navs/<id>.json mesh → meshes/<id>.bin (+ its atlas beside it)
|
|
163
165
|
* image → by purpose: atlases/ (default), maps/, icons/ or actors/<id>.png | .webp
|
|
166
|
+
* notes → notes/<id>.json (what a pack's `localSource` reads)
|
|
164
167
|
* The core encodes images from the pixels; every image of a game uses one format (the web app
|
|
165
168
|
* reads one extension per game).
|
|
166
169
|
*/
|
|
@@ -922,6 +925,20 @@ export declare const AssetOutputSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodOb
|
|
|
922
925
|
format: "webp";
|
|
923
926
|
quality: number;
|
|
924
927
|
} | undefined;
|
|
928
|
+
}>, z.ZodObject<{
|
|
929
|
+
kind: z.ZodLiteral<"notes">;
|
|
930
|
+
id: z.ZodEffects<z.ZodString, string, string>;
|
|
931
|
+
/** a JSON object, as text: the order of keys that look like numbers ("3", "12") survives
|
|
932
|
+
* only as text, since JavaScript objects list those first */
|
|
933
|
+
json: z.ZodEffects<z.ZodString, string, string>;
|
|
934
|
+
}, "strip", z.ZodTypeAny, {
|
|
935
|
+
id: string;
|
|
936
|
+
kind: "notes";
|
|
937
|
+
json: string;
|
|
938
|
+
}, {
|
|
939
|
+
id: string;
|
|
940
|
+
kind: "notes";
|
|
941
|
+
json: string;
|
|
925
942
|
}>]>;
|
|
926
943
|
export type AssetOutputWire = z.infer<typeof AssetOutputSchema>;
|
|
927
944
|
export declare const AssetResultSchema: z.ZodObject<{
|
|
@@ -1683,6 +1700,20 @@ export declare const AssetResultSchema: z.ZodObject<{
|
|
|
1683
1700
|
format: "webp";
|
|
1684
1701
|
quality: number;
|
|
1685
1702
|
} | undefined;
|
|
1703
|
+
}>, z.ZodObject<{
|
|
1704
|
+
kind: z.ZodLiteral<"notes">;
|
|
1705
|
+
id: z.ZodEffects<z.ZodString, string, string>;
|
|
1706
|
+
/** a JSON object, as text: the order of keys that look like numbers ("3", "12") survives
|
|
1707
|
+
* only as text, since JavaScript objects list those first */
|
|
1708
|
+
json: z.ZodEffects<z.ZodString, string, string>;
|
|
1709
|
+
}, "strip", z.ZodTypeAny, {
|
|
1710
|
+
id: string;
|
|
1711
|
+
kind: "notes";
|
|
1712
|
+
json: string;
|
|
1713
|
+
}, {
|
|
1714
|
+
id: string;
|
|
1715
|
+
kind: "notes";
|
|
1716
|
+
json: string;
|
|
1686
1717
|
}>]>, "many">;
|
|
1687
1718
|
}, "strip", z.ZodTypeAny, {
|
|
1688
1719
|
outputs: ({
|
|
@@ -1796,6 +1827,10 @@ export declare const AssetResultSchema: z.ZodObject<{
|
|
|
1796
1827
|
format: "webp";
|
|
1797
1828
|
quality: number;
|
|
1798
1829
|
} | undefined;
|
|
1830
|
+
} | {
|
|
1831
|
+
id: string;
|
|
1832
|
+
kind: "notes";
|
|
1833
|
+
json: string;
|
|
1799
1834
|
})[];
|
|
1800
1835
|
}, {
|
|
1801
1836
|
outputs: ({
|
|
@@ -1909,6 +1944,10 @@ export declare const AssetResultSchema: z.ZodObject<{
|
|
|
1909
1944
|
format: "webp";
|
|
1910
1945
|
quality: number;
|
|
1911
1946
|
} | undefined;
|
|
1947
|
+
} | {
|
|
1948
|
+
id: string;
|
|
1949
|
+
kind: "notes";
|
|
1950
|
+
json: string;
|
|
1912
1951
|
})[];
|
|
1913
1952
|
}>;
|
|
1914
1953
|
/** An output as plugin code builds it: binary data as bytes. */
|
|
@@ -1928,7 +1967,8 @@ export type AssetOutput = Exclude<AssetOutputWire, {
|
|
|
1928
1967
|
export type InputPick = 'files' | 'folder';
|
|
1929
1968
|
/** A player's file the core opened for an extraction: its name and size, read by range. */
|
|
1930
1969
|
export interface InputFile {
|
|
1931
|
-
/** the file's name
|
|
1970
|
+
/** the file's name: relative to the picked folder (`mods/x.o2r`), or one the core gives a
|
|
1971
|
+
* file from elsewhere (`registry/manifest.json`, `downloads/<id>`) */
|
|
1932
1972
|
readonly name: string;
|
|
1933
1973
|
readonly size: number;
|
|
1934
1974
|
read(offset: number, length: number): Uint8Array;
|
package/lib/assets.js
CHANGED
|
@@ -74,6 +74,17 @@ export function floorplanToSvg(drawing) {
|
|
|
74
74
|
'',
|
|
75
75
|
].join('\n');
|
|
76
76
|
}
|
|
77
|
+
/** The largest notes output, in characters. */
|
|
78
|
+
export const NOTES_MAX_CHARS = 16 * 1024 * 1024;
|
|
79
|
+
function isJsonObjectText(text) {
|
|
80
|
+
try {
|
|
81
|
+
const value = JSON.parse(text);
|
|
82
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
77
88
|
/** Binary data in an output: in plugin code a Uint8Array; across the sandbox boundary, an index
|
|
78
89
|
* into the chunks the guest handed the core during that call. */
|
|
79
90
|
const BinaryRef = z.number().int().nonnegative();
|
|
@@ -89,6 +100,7 @@ export const ImageEncodingSchema = z.union([
|
|
|
89
100
|
* floorplan → maps/<id>.svg location → manifest.json (locations[id])
|
|
90
101
|
* nav → navs/<id>.json mesh → meshes/<id>.bin (+ its atlas beside it)
|
|
91
102
|
* image → by purpose: atlases/ (default), maps/, icons/ or actors/<id>.png | .webp
|
|
103
|
+
* notes → notes/<id>.json (what a pack's `localSource` reads)
|
|
92
104
|
* The core encodes images from the pixels; every image of a game uses one format (the web app
|
|
93
105
|
* reads one extension per game).
|
|
94
106
|
*/
|
|
@@ -116,5 +128,15 @@ export const AssetOutputSchema = z.discriminatedUnion('kind', [
|
|
|
116
128
|
/** how the core encodes it (default PNG) */
|
|
117
129
|
encoding: ImageEncodingSchema.optional(),
|
|
118
130
|
}),
|
|
131
|
+
z.object({
|
|
132
|
+
kind: z.literal('notes'),
|
|
133
|
+
id: AssetIdSchema,
|
|
134
|
+
/** a JSON object, as text: the order of keys that look like numbers ("3", "12") survives
|
|
135
|
+
* only as text, since JavaScript objects list those first */
|
|
136
|
+
json: z
|
|
137
|
+
.string()
|
|
138
|
+
.max(NOTES_MAX_CHARS)
|
|
139
|
+
.refine(isJsonObjectText, 'notes are the text of one JSON object'),
|
|
140
|
+
}),
|
|
119
141
|
]);
|
|
120
142
|
export const AssetResultSchema = z.object({ outputs: z.array(AssetOutputSchema).max(1000) });
|
|
@@ -22,7 +22,8 @@ export declare const inputName: (file: string, root: string | undefined) => stri
|
|
|
22
22
|
export declare class InputSet {
|
|
23
23
|
private readonly files;
|
|
24
24
|
/** `named`: files from outside the picked folder, under the name the plugin sees (the core's
|
|
25
|
-
* registry data for the game, `registry/manifest.json`)
|
|
25
|
+
* registry data for the game, `registry/manifest.json`, and its `downloads/<id>`); a picked
|
|
26
|
+
* file may not share one's name */
|
|
26
27
|
constructor(paths: readonly string[], root?: string, named?: ReadonlyArray<{
|
|
27
28
|
path: string;
|
|
28
29
|
name: string;
|
|
@@ -30,9 +30,14 @@ export const inputName = (file, root) => root ? path.relative(root, file).split(
|
|
|
30
30
|
export class InputSet {
|
|
31
31
|
files = [];
|
|
32
32
|
/** `named`: files from outside the picked folder, under the name the plugin sees (the core's
|
|
33
|
-
* registry data for the game, `registry/manifest.json`)
|
|
33
|
+
* registry data for the game, `registry/manifest.json`, and its `downloads/<id>`); a picked
|
|
34
|
+
* file may not share one's name */
|
|
34
35
|
constructor(paths, root, named = []) {
|
|
35
|
-
const
|
|
36
|
+
const picked = paths.map(p => ({ path: p, name: inputName(p, root) }));
|
|
37
|
+
const clash = picked.find(f => named.some(n => n.name === f.name));
|
|
38
|
+
if (clash)
|
|
39
|
+
throw new Error(`a picked file is named ${clash.name}, one of the core's own inputs`);
|
|
40
|
+
const all = [...picked, ...named];
|
|
36
41
|
try {
|
|
37
42
|
for (const { path: p, name } of all) {
|
|
38
43
|
const fd = fs.openSync(p, 'r');
|
package/lib/host/inspect.js
CHANGED
|
@@ -78,7 +78,7 @@ export function inspectPlugin(quickJs, dir, manifest, opts) {
|
|
|
78
78
|
if (manifest.sdkApi !== SDK_API) {
|
|
79
79
|
return `built for plugin contract ${manifest.sdkApi}, this core speaks ${SDK_API}`;
|
|
80
80
|
}
|
|
81
|
-
const bad = [manifest.code, manifest.assets
|
|
81
|
+
const bad = [manifest.code, manifest.assets]
|
|
82
82
|
.flatMap(code => (code ? [codeProblem(dir, code)] : []))
|
|
83
83
|
.find(reason => reason !== null);
|
|
84
84
|
if (bad)
|
package/lib/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './views.js';
|
|
|
11
11
|
export * from './bytes.js';
|
|
12
12
|
export * from './navigation.js';
|
|
13
13
|
export * from './plugin-manifest.js';
|
|
14
|
+
export * from './plugin-permissions.js';
|
|
14
15
|
export * from './sandbox-protocol.js';
|
|
15
16
|
export * from './assets.js';
|
|
16
17
|
export * from './plugins-api.js';
|
package/lib/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export * from './views.js';
|
|
|
11
11
|
export * from './bytes.js';
|
|
12
12
|
export * from './navigation.js';
|
|
13
13
|
export * from './plugin-manifest.js';
|
|
14
|
+
export * from './plugin-permissions.js';
|
|
14
15
|
export * from './sandbox-protocol.js';
|
|
15
16
|
export * from './assets.js';
|
|
16
17
|
export * from './plugins-api.js';
|
package/lib/plugin/contract.d.ts
CHANGED
|
@@ -73,7 +73,8 @@ export interface PluginSession {
|
|
|
73
73
|
/**
|
|
74
74
|
* Builds a game's assets from the player's files, one at a time, in the core's sandbox. The core
|
|
75
75
|
* makes one instance per run (so it can keep parsed files between assets), hands in the files it
|
|
76
|
-
* opened
|
|
76
|
+
* opened (the game's declared downloads among them, as `downloads/<id>`), and writes and
|
|
77
|
+
* validates whatever comes back (docs/plugin-architecture.md).
|
|
77
78
|
*/
|
|
78
79
|
export interface AssetExtractor {
|
|
79
80
|
/** what can be built from these files: cheap, no heavy parsing */
|
|
@@ -81,32 +82,6 @@ export interface AssetExtractor {
|
|
|
81
82
|
/** one asset's outputs: data in the sdk's shapes, never files */
|
|
82
83
|
buildAsset(id: string, inputs: readonly InputFile[]): AssetOutput[];
|
|
83
84
|
}
|
|
84
|
-
/** A Python-based extraction (the Zelda map renderer, until it's ported): what to run. */
|
|
85
|
-
export type PythonExtractPlan = {
|
|
86
|
-
kind: 'error';
|
|
87
|
-
message: string;
|
|
88
|
-
} | {
|
|
89
|
-
kind: 'run';
|
|
90
|
-
gameId: string;
|
|
91
|
-
pythonArgs: string[];
|
|
92
|
-
playerArgs: string[];
|
|
93
|
-
outDir: string;
|
|
94
|
-
};
|
|
95
|
-
export interface PythonExtract {
|
|
96
|
-
/** the games it extracts */
|
|
97
|
-
games: readonly string[];
|
|
98
|
-
plan(args: readonly string[], paths: {
|
|
99
|
-
script: string;
|
|
100
|
-
registryDir: string;
|
|
101
|
-
localAssetsDir: string;
|
|
102
|
-
}): PythonExtractPlan;
|
|
103
|
-
/** a game's step after the renderer succeeded */
|
|
104
|
-
after: ReadonlyMap<string, (ctx: {
|
|
105
|
-
args: readonly string[];
|
|
106
|
-
outDir: string;
|
|
107
|
-
extractorScript: string;
|
|
108
|
-
}) => Promise<void>>;
|
|
109
|
-
}
|
|
110
85
|
/**
|
|
111
86
|
* What a plugin's live code exports (its default export): the packs and memory sources for the
|
|
112
87
|
* games it covers. It runs in the core's sandbox, built with `exposeToHost`, so it may use no Node
|
|
@@ -125,21 +100,3 @@ export interface PluginAssetsModule {
|
|
|
125
100
|
/** a new extractor for each run, by game id */
|
|
126
101
|
extractors: ReadonlyMap<string, () => AssetExtractor>;
|
|
127
102
|
}
|
|
128
|
-
/**
|
|
129
|
-
* The Python map renderer's hooks (the Zelda ports). Still unsandboxed, with Node, until the
|
|
130
|
-
* renderer is ported and those games get an AssetExtractor.
|
|
131
|
-
*/
|
|
132
|
-
/** What a game's after-assets step gets: where its assets were written. */
|
|
133
|
-
export interface AfterAssetsContext {
|
|
134
|
-
outDir: string;
|
|
135
|
-
}
|
|
136
|
-
export interface PluginExtractModule {
|
|
137
|
-
/** must equal the manifest's id */
|
|
138
|
-
id: string;
|
|
139
|
-
/** @deprecated the Python map renderer is gone (GameSlate builds assets in the sandbox);
|
|
140
|
-
* kept so plugins built against older sdk versions still load */
|
|
141
|
-
pythonExtract?: PythonExtract;
|
|
142
|
-
/** per game: a step after its extraction job, unsandboxed (e.g. notes built from data fetched
|
|
143
|
-
* over the network); it must not fail the extraction when it can't run */
|
|
144
|
-
afterAssets?: ReadonlyMap<string, (ctx: AfterAssetsContext) => Promise<void>>;
|
|
145
|
-
}
|