@gameslate/sdk 0.3.25 → 0.3.26

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 CHANGED
@@ -90,6 +90,10 @@ the input `downloads/<id>`; the player sees it among the plugin's permissions.
90
90
 
91
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.
92
92
 
93
+ - **0.3.26**: `Bytes#toString` decodes 8 KiB per call and joins the pieces, since building the
94
+ string a byte at a time was quadratic in QuickJS (a 1 MB string took 147 s). `isCoreInput(name)`
95
+ and `REGISTRY_INPUT_NAME` name the inputs the core adds (the registry manifest, downloads), which
96
+ code reading every picked file must leave out.
93
97
  - **0.3.25**: `extent` and `append` fold and append by loop; `gameslate-plugin build` refuses a
94
98
  call whose argument count is an array's length (a spread argument, `.apply`, `Reflect.apply`,
95
99
  `Reflect.construct`) unless a `/* spread-ok: <why> */` marker sits directly above its
package/lib/bytes.js CHANGED
@@ -4,6 +4,10 @@
4
4
  * match Buffer's so decoders read the same either way. Reads past the end throw a RangeError,
5
5
  * as Buffer's do.
6
6
  */
7
+ /* Text is decoded this many bytes per call and the pieces joined: QuickJS copies the whole string
8
+ * on every `+=`, so a byte at a time is quadratic (a 1 MB string took 147 s in the sandbox), and
9
+ * one call per string would pass the sandbox's 65535-argument limit. */
10
+ const TEXT_CHUNK_BYTES = 8192;
7
11
  export class Bytes {
8
12
  data;
9
13
  view;
@@ -79,11 +83,14 @@ export class Bytes {
79
83
  * clears the high bit first, as Buffer does.
80
84
  */
81
85
  toString(encoding, start = 0, end = this.data.length) {
82
- const mask = encoding === 'ascii' ? 0x7f : 0xff;
83
- let out = '';
84
- for (let i = Math.max(0, start); i < Math.min(end, this.data.length); i++) {
85
- out += String.fromCharCode((this.data[i] ?? 0) & mask);
86
+ const to = Math.min(end, this.data.length);
87
+ const parts = [];
88
+ for (let i = Math.max(0, start); i < to; i += TEXT_CHUNK_BYTES) {
89
+ const raw = this.data.subarray(i, Math.min(to, i + TEXT_CHUNK_BYTES));
90
+ const chunk = encoding === 'ascii' ? raw.map(b => b & 0x7f) : raw;
91
+ /* spread-ok: at most TEXT_CHUNK_BYTES bytes */
92
+ parts.push(String.fromCharCode(...chunk));
86
93
  }
87
- return out;
94
+ return parts.join('');
88
95
  }
89
96
  }
@@ -35,6 +35,11 @@ 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
+ /** The input name the game's registry manifest reaches the asset code under. */
39
+ export declare const REGISTRY_INPUT_NAME = "registry/manifest.json";
40
+ /** Whether an input is one the core adds (a download, the registry manifest), not the player's
41
+ * own file: code reading every picked file must leave these out. */
42
+ export declare const isCoreInput: (name: string) => boolean;
38
43
  /**
39
44
  * A build of a game that the plugin's live code reads memory from: the id its source matches
40
45
  * (an ELF or PE build id, or an N64 ROM's code and version such as `CZLE.2`) and what the player
@@ -97,8 +97,14 @@ export const PluginDownloadSchema = z
97
97
  sha256: Sha256,
98
98
  })
99
99
  .strict();
100
+ const DOWNLOADS_FOLDER = 'downloads/';
100
101
  /** The input name a download reaches the asset code under. */
101
- export const downloadInputName = (id) => `downloads/${id}`;
102
+ export const downloadInputName = (id) => `${DOWNLOADS_FOLDER}${id}`;
103
+ /** The input name the game's registry manifest reaches the asset code under. */
104
+ export const REGISTRY_INPUT_NAME = 'registry/manifest.json';
105
+ /** Whether an input is one the core adds (a download, the registry manifest), not the player's
106
+ * own file: code reading every picked file must leave these out. */
107
+ export const isCoreInput = (name) => name === REGISTRY_INPUT_NAME || name.startsWith(DOWNLOADS_FOLDER);
102
108
  /**
103
109
  * A build of a game that the plugin's live code reads memory from: the id its source matches
104
110
  * (an ELF or PE build id, or an N64 ROM's code and version such as `CZLE.2`) and what the player
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gameslate/sdk",
3
- "version": "0.3.25",
3
+ "version": "0.3.26",
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",
@@ -355,13 +355,16 @@ Images have a `purpose` (`atlas`, `map`, `icon`, `actor`, which picks the folder
355
355
 
356
356
  Every image of a game uses one format. In the sandbox:
357
357
 
358
- - **No `TextDecoder`, `TextEncoder` or `Buffer`.** Decode UTF-8 by hand, and decode files in
359
- chunks (`String.fromCharCode(...bytes)` has an argument limit).
358
+ - **No `TextDecoder`, `TextEncoder` or `Buffer`.** Decode Latin-1 and ASCII with `new
359
+ Bytes(data).toString('latin1', start, end)` (sdk >= 0.3.26 is fast at any length), and UTF-8 by
360
+ hand.
360
361
  - **One asset per unit of work** (per map, per actor): each gets its own time budget (10 minutes)
361
362
  and its own up-to-date stamp, and jobs build assets across several threads.
362
363
  - Inputs are named relative to the folder the player picked (`mods/pack.o2r`). The core also hands
363
364
  in the game's registry manifest as `registry/manifest.json` when there is one, so renders line up
364
- with the registry's maps.
365
+ with the registry's maps, and each download as `downloads/<id>`. Code that reads every picked
366
+ file leaves those out with `isCoreInput(name)` (sdk 0.3.26): idtech1 read the registry manifest
367
+ as a WAD, so every build from picked WADs failed until 2026-12-06.
365
368
  - **Data from the web is a download, never a fetch.** Plugin code has no network and nothing
366
369
  runs outside the sandbox (`extract.ts` fails the build). Declare the file in the game's
367
370
  manifest entry, `downloads: [{ id, url, sha256 }]` with an exact https URL (a release asset, a
@@ -837,11 +840,20 @@ the plugin repos) in the same change as the fix. The next game should not have t
837
840
  */` on the line directly above the statement (a function, class, `export default` or class
838
841
  property counts); it covers only calls that start on that statement's first line, never a loop
839
842
  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
843
+ marks nothing. Decode text with `Bytes#toString`. Before marking a spread "small", find what
844
+ bounds it (a 4-byte field, a 3-vertex triangle, a format's u8 count): a string that only looks
845
+ short (a name, a path) is bounded by nothing. Test a fix with at least 300k items (Node starts
846
+ throwing at about 150k); a test that size also catches a loop that went quadratic. Name
847
+ `extent`'s `what` as a plural (`'vertex xs'`): its errors read "no vertex xs". Dependencies
841
848
  aren't checked: if one handles map-sized arrays, test a big input in the sandbox
842
849
  (`@gameslate/sdk/host`). After a change that grows the geometry, run `gameslate extract-assets
843
850
  <game> --input <rom> --out-dir <scratch>` (the core's `dist/gameslate.mjs` with
844
851
  `GAMESLATE_PLUGINS_DIR=<plugin>/dist`).
852
+ - **Never build a long string with `+=` a piece at a time.** QuickJS copies the whole string on
853
+ every `+=`, so it is quadratic where Node is linear: a 1 MB string a byte at a time took 147 s
854
+ in the sandbox (the sdk's own `Bytes#toString` did this until 0.3.26). Push the pieces into an
855
+ array and `join('')`, and run a multi-MB input through the sandbox
856
+ (`@gameslate/sdk/host`'s `loadQuickJs`), not only vitest.
845
857
  - **Follow every source the floor or water query asks.** DK64's floor query merges the map mesh,
846
858
  placed models and actor boxes; Conker's water height comes from water props, trigger-zone
847
859
  volumes and surface type 8 at once. Port the game's query, not one of its sources, and say in