dredless 1.4.1 → 1.5.0
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/dist/browser/dredless.global.js +856 -309
- package/dist/browser/dredless.global.js.map +4 -4
- package/docs/EVENTS.md +1 -1
- package/docs/MACHINES.md +43 -0
- package/docs/MANAGEMENT.md +2 -2
- package/docs/WORLD_STATE.md +70 -1
- package/package.json +1 -1
- package/src/browser.d.ts +1 -0
- package/src/browser.js +1 -1
- package/src/client/core.js +19 -1
- package/src/client/domains/index.js +50 -0
- package/src/crypto/chacha.js +27 -8
- package/src/data/item-schema.js +18 -2
- package/src/index.d.ts +137 -6
- package/src/index.js +2 -1
- package/src/protocol/codec/binary.js +3 -0
- package/src/protocol/codec/msgpack.js +32 -1
- package/src/protocol/codec/ui-integer.js +7 -0
- package/src/protocol/outbound/advanced-expando.js +65 -0
- package/src/protocol/outbound/machine-config.js +1 -6
- package/src/protocol/outbound/ui-config.d.ts +6 -0
- package/src/protocol/outbound/ui-config.js +7 -9
- package/src/state/index.js +1 -1
- package/src/state/model/decoder.js +47 -11
- package/src/state/model/state.js +75 -16
- package/src/state/world/index.d.ts +4 -0
- package/src/state/world/index.js +9 -3
- package/src/state/world/state.js +382 -45
package/docs/EVENTS.md
CHANGED
|
@@ -66,7 +66,7 @@ These events receive an update object with `.world` referencing the already-upda
|
|
|
66
66
|
| Event | Callback arguments | Important fields |
|
|
67
67
|
|-----------------|--------------------|-------------------------------------------------------------------------------|
|
|
68
68
|
| `world` | `(update)` | `update.world` with metadata applied |
|
|
69
|
-
| `tiles` | `(update)` | `world`, `decoded`, `updates`, `errors`
|
|
69
|
+
| `tiles` | `(update)` | `world`, `decoded`, `updates`, `errors`; chunk `tiles` are built when read |
|
|
70
70
|
| `model` | `(update)` | `world`, `result` with model changes, side events, command number, timing |
|
|
71
71
|
| `comms-bubble` | `(update)` | `world`, `packet`, `bubble` |
|
|
72
72
|
| `world-removed` | See below | World removed from store |
|
package/docs/MACHINES.md
CHANGED
|
@@ -437,3 +437,46 @@ Cargo ejector rendering state uses table 49 `q20 / 100` for `progress`,
|
|
|
437
437
|
`q24` for the signed `direction` offset, `q28 / 100` for `extension`, and
|
|
438
438
|
`q33` for `noMount`. `active` reports a nonzero cycle or extension; it is
|
|
439
439
|
not the mount flag. The summary also exposes the raw `state`.
|
|
440
|
+
|
|
441
|
+
## Advanced Expando Boxes
|
|
442
|
+
|
|
443
|
+
Item `266` is an Advanced Expando Box; item `267` is the Advanced Logistics Controller
|
|
444
|
+
crafting component. `ship.machines.expandoBoxes()` includes both basic and advanced boxes.
|
|
445
|
+
An advanced box exposes `state.advanced === true` and `state.config`, containing its
|
|
446
|
+
minimum/maximum dimensions, enable flags, RGB colors, and opacity. Actual observed
|
|
447
|
+
`state.width` and `state.height` remain separate from the configured limits.
|
|
448
|
+
|
|
449
|
+
```js
|
|
450
|
+
const box = client.currentShip().machines.expandoBox(entityId);
|
|
451
|
+
box.configure({minEnabled: true, minWidth: 4, minHeight: 2, opacity: 0.5});
|
|
452
|
+
box.copy(); // Copies observed settings into clipboard class 11.
|
|
453
|
+
box.paste({backgroundColor: 0x224466});
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
`configure`, `copy`, and `paste` preserve omitted settings from the observed configuration.
|
|
457
|
+
They require an advanced box and return immediately; observe subsequent replicated state
|
|
458
|
+
for confirmation. Basic boxes retain their inventory and dimensions but reject these methods.
|
|
459
|
+
|
|
460
|
+
`AdvancedExpandoBoxConfig` fields:
|
|
461
|
+
|
|
462
|
+
| Field | Meaning |
|
|
463
|
+
| --- | --- |
|
|
464
|
+
| `minWidth`, `minHeight` | Minimum dimensions; also the dimensions used by fixed-size mode |
|
|
465
|
+
| `maxWidth`, `maxHeight` | Maximum dimensions |
|
|
466
|
+
| `minEnabled`, `maxEnabled` | Enable the respective limits |
|
|
467
|
+
| `fixedSize` | Request fixed dimensions instead of automatic expansion |
|
|
468
|
+
| `backgroundColor`, `borderColor` | Integer RGB colors, `0x000000`–`0xffffff` |
|
|
469
|
+
| `opacity` | Background opacity, `0`–`1` |
|
|
470
|
+
|
|
471
|
+
Dimensions use world units and accept values from `2` to `100`. Defaults are minimum
|
|
472
|
+
`2×2`, maximum `10×10`, all limit flags disabled, background `0xdddddd`, border
|
|
473
|
+
`0x404040`, and opacity `1`. The server enforces expansion space, capacity, and the
|
|
474
|
+
4:1 aspect-ratio limit. Like the official client, Dredless permits minimum dimensions
|
|
475
|
+
larger than maximum dimensions; the maximum applies where enabled.
|
|
476
|
+
|
|
477
|
+
Low-level builders are `buildAdvancedExpandoBoxConfigData(entity, config?)`,
|
|
478
|
+
`buildAdvancedExpandoBoxCopyConfigData(config?)`, and
|
|
479
|
+
`buildAdvancedExpandoBoxPasteConfigData(entity, config?)`. They return UI configuration
|
|
480
|
+
bytes and use defaults for omitted fields; they cannot read observed state. Direct client
|
|
481
|
+
methods are `sendAdvancedExpandoBoxConfig`, `copyAdvancedExpandoBoxConfig`, and
|
|
482
|
+
`pasteAdvancedExpandoBoxConfig`, each taking an entity ID and optional settings.
|
package/docs/MANAGEMENT.md
CHANGED
|
@@ -80,12 +80,12 @@ client.management.save(options?: {timeout?: number}): Promise<DisconnectInfo>;
|
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
`canSave()` requires a connected/ready client, a current ship with a known parent world, and parent `danger_level === 0`
|
|
83
|
-
(Safe Zone). Missing or unsafe metadata returns `false`. It does not check all server-side permission rules.
|
|
83
|
+
(Safe Zone). Missing or unsafe metadata returns `false`. Partial metadata updates retain the last known danger level. It does not check all server-side permission rules.
|
|
84
84
|
|
|
85
85
|
**Fragment:** this saves the ship and ejects its players:
|
|
86
86
|
|
|
87
87
|
```js
|
|
88
|
-
if (!client.management.canSave()) throw new Error("Ship is not
|
|
88
|
+
if (!client.management.canSave()) throw new Error("Ship is not locally eligible to save");
|
|
89
89
|
const result = await client.management.save();
|
|
90
90
|
console.log(result.name); // Saved
|
|
91
91
|
```
|
package/docs/WORLD_STATE.md
CHANGED
|
@@ -27,7 +27,7 @@ The ship world describes its interior. The overworld contains ship entities and
|
|
|
27
27
|
represented in the overworld without their interiors being decoded. An entity ID is meaningful only together with its
|
|
28
28
|
world.
|
|
29
29
|
|
|
30
|
-
A `WorldDomain` exposes `id`, `exists()`, `entities`, `machines`, `players`, `blocks`, and `
|
|
30
|
+
A `WorldDomain` exposes `id`, `exists()`, `entities`, `machines`, `players`, `blocks`, `materials`, and `tiles`, plus
|
|
31
31
|
`snapshot(options?)`. A `ShipDomain` adds `metadata`, `entity()`, and `overworldEntity`. These refer to the ship's
|
|
32
32
|
associated overworld entity when available, not its local player.
|
|
33
33
|
|
|
@@ -107,6 +107,50 @@ not freeze them.
|
|
|
107
107
|
Materials summarize decoded blocks; they are not an authoritative ship inventory. A missing collection or component can
|
|
108
108
|
reflect incomplete decoding, not an absent server object.
|
|
109
109
|
|
|
110
|
+
### Tiles
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
world.tiles.count: number;
|
|
114
|
+
world.tiles.version: number; // Bumped on every tile write.
|
|
115
|
+
world.tiles.chunks(): TileChunkView[]; // Live typed-array views; no allocation.
|
|
116
|
+
world.tiles.at(x: number, y: number): Tile | null;
|
|
117
|
+
world.tiles.all(): Tile[]; // Builds tile objects.
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Tiles are stored as byte columns per 64x64 chunk, not as objects. `chunks()` reads that storage directly, so it is the
|
|
121
|
+
read to use when scanning every tile each tick: it allocates nothing and does not add garbage-collection work to packet
|
|
122
|
+
handling. `all()` builds `Tile` objects; use it for occasional reads. Each kind of read has one entry point. On a
|
|
123
|
+
`WorldState` the same reads are `tileChunks()`, `tileAt()`, `tileVersion`, `tiles.size`, and `tiles.toArray()`;
|
|
124
|
+
`WorldState.tiles` is not a `Map` and is not iterable.
|
|
125
|
+
|
|
126
|
+
A `TileChunkView` has `chunkX`, `chunkY`, `originX`, `originY`, `version`, and the `material`, `shape`, `hp`, `color`,
|
|
127
|
+
and `flags` byte arrays. Cell `i` is the tile at `(originX + (i & 63), originY + (i >> 6))`. A `flags` value of `0`
|
|
128
|
+
means the cell is empty; `TileFlags.NoColor` means the tile has no color. Views stay valid for the life of the chunk and
|
|
129
|
+
always show current state, so treat them as read-only and compare `version` to skip chunks that have not changed.
|
|
130
|
+
|
|
131
|
+
**Fragment:** rescan only the chunks that changed since the last tick:
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
import {TileFlags} from "dredless";
|
|
135
|
+
|
|
136
|
+
const seen = new Map();
|
|
137
|
+
function scanChangedTiles(world) {
|
|
138
|
+
for (const chunk of world.tiles.chunks()) {
|
|
139
|
+
if (seen.get(chunk) === chunk.version) continue;
|
|
140
|
+
seen.set(chunk, chunk.version);
|
|
141
|
+
const {material, hp, flags, originX, originY} = chunk;
|
|
142
|
+
for (let i = 0; i < flags.length; i++) {
|
|
143
|
+
if (!(flags[i] & TileFlags.Present)) continue;
|
|
144
|
+
onTile(originX + (i & 63), originY + (i >> 6), material[i], hp[i]);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Tile objects are built on demand, so two reads may return different objects for the same tile and changing a returned
|
|
151
|
+
object does not change client state. A tile set through `WorldState.setTile()` with non-byte values or extra fields is
|
|
152
|
+
kept as given and appears in `at()` and `all()`, but not in chunk views.
|
|
153
|
+
|
|
110
154
|
## Projectiles, bots, and special entities
|
|
111
155
|
|
|
112
156
|
Every world domain exposes these collections. They return current component summaries; `get()` returns `null` when
|
|
@@ -362,3 +406,28 @@ discrete direction enums have operation-specific wire mappings. [Machines](MACHI
|
|
|
362
406
|
Readiness does not guarantee all component tables, a local player, a panel, or another ship's interior. Watch `model`/
|
|
363
407
|
`world` events, tolerate missing fields, and inspect [decode errors](PROTOCOL.md#debug-domains-and-state-classes) when
|
|
364
408
|
apparently present objects cannot be read.
|
|
409
|
+
|
|
410
|
+
## Direct component reads
|
|
411
|
+
|
|
412
|
+
Renderers and other frequent readers can use `WorldState.model` without building entity debug summaries or category lists:
|
|
413
|
+
|
|
414
|
+
```js
|
|
415
|
+
const model = client.worlds.shipWorld()?.model;
|
|
416
|
+
if (model) {
|
|
417
|
+
for (const id of model.componentEntityIds()) {
|
|
418
|
+
const revision = model.entityRevision(id);
|
|
419
|
+
const transform = model.record(0, id);
|
|
420
|
+
// Retain derived render data until this entity's revision changes.
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
`componentEntityIds()` returns a sorted iterator over live component entity IDs. `entityRevision(id)` returns the last local
|
|
426
|
+
apply revision that touched the entity, or zero after removal. `revision` increases on every `apply()`, independently of the
|
|
427
|
+
wire generation counter. This covers several packets between reads, removal/recreation of the same ID, and partially
|
|
428
|
+
applied records when decoding reports an error. These indexes are maintained by the decoder; they describe decoded
|
|
429
|
+
component mutations, not local-player selection or other external rendering context.
|
|
430
|
+
|
|
431
|
+
Raw records mutate in place. `recordRevision(record)` reports their last local apply revision; retain copied render values
|
|
432
|
+
rather than relying on raw record identity. `navigationDestination(id)` reads the tracked navigation destination without
|
|
433
|
+
constructing entity summaries, preserving the destination across flag-only updates.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dredless",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "A fully-featured and from-scratch headless drednot.io client implementation written in pure js.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/certainhuman/dredless#readme",
|
package/src/browser.d.ts
CHANGED
package/src/browser.js
CHANGED
|
@@ -13,7 +13,7 @@ export {
|
|
|
13
13
|
export {Connection} from "./network/connection.js";
|
|
14
14
|
export {DropReason, DisconnectError, normalizeDisconnect} from "./network/disconnect.js";
|
|
15
15
|
export {DredlessClient, WrenchMode, TurretMode} from "./client/index.js";
|
|
16
|
-
export {WorldStore, WorldState} from "./state/world/index.js";
|
|
16
|
+
export {WorldStore, WorldState, TileFlags} from "./state/world/index.js";
|
|
17
17
|
export {FabricatorType, ModelState, decodeModelData} from "./state/model/index.js";
|
|
18
18
|
export {generateGeneratorMaze, solveGeneratorMazeSeed, maybeSolveGeneratorMazeSeed} from "./state/generator-maze.js";
|
|
19
19
|
export {buildBlueprintPlacementMessage} from "./protocol/outbound/blueprint.js";
|
package/src/client/core.js
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
} from "../protocol/outbound/ship-management.js";
|
|
37
37
|
import {buildSignTextMessage} from "../protocol/outbound/sign.js";
|
|
38
38
|
import {
|
|
39
|
+
buildAdvancedExpandoBoxConfigData, buildAdvancedExpandoBoxCopyConfigData, buildAdvancedExpandoBoxPasteConfigData,
|
|
39
40
|
buildLauncherConfigData,
|
|
40
41
|
buildLauncherCopyConfigData,
|
|
41
42
|
buildLauncherPasteConfigData,
|
|
@@ -571,6 +572,23 @@ export class DredlessClient extends EventBus {
|
|
|
571
572
|
return this.sendFabricatorMessage("eject", [row, -1, -1]);
|
|
572
573
|
}
|
|
573
574
|
|
|
575
|
+
#advancedExpandoBoxConfigDefaults(entity, config) {
|
|
576
|
+
const observed = this.worlds.shipWorld()?.entity(entity)?.contents?.expandoBox?.config;
|
|
577
|
+
return {...observed, ...Object.fromEntries(Object.entries(config).filter(([, value]) => value !== undefined))};
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
sendAdvancedExpandoBoxConfig(entity, config = {}) {
|
|
581
|
+
return this.sendUiConfig(buildAdvancedExpandoBoxConfigData(entity, this.#advancedExpandoBoxConfigDefaults(entity, config)));
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
copyAdvancedExpandoBoxConfig(entity, config = {}) {
|
|
585
|
+
return this.sendUiConfig(buildAdvancedExpandoBoxCopyConfigData(this.#advancedExpandoBoxConfigDefaults(entity, config)));
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
pasteAdvancedExpandoBoxConfig(entity, config = {}) {
|
|
589
|
+
return this.sendUiConfig(buildAdvancedExpandoBoxPasteConfigData(entity, this.#advancedExpandoBoxConfigDefaults(entity, config)));
|
|
590
|
+
}
|
|
591
|
+
|
|
574
592
|
sendLauncherConfig(entity, config = {}) {
|
|
575
593
|
return this.sendUiConfig(buildLauncherConfigData(entity, this.#launcherConfigDefaults(entity, config)));
|
|
576
594
|
}
|
|
@@ -1464,7 +1482,7 @@ export class DredlessClient extends EventBus {
|
|
|
1464
1482
|
}
|
|
1465
1483
|
|
|
1466
1484
|
#navigationUnitConfigDefaults(entity, config = {}) {
|
|
1467
|
-
const summary = this.entity(entity)?.contents?.navigationUnit || null;
|
|
1485
|
+
const summary = this.worlds.shipWorld()?.entity(entity)?.contents?.navigationUnit || null;
|
|
1468
1486
|
return {
|
|
1469
1487
|
destination: config.destination ?? summary?.destination,
|
|
1470
1488
|
page: config.page ?? 0,
|
|
@@ -435,6 +435,7 @@ export class WorldDomain {
|
|
|
435
435
|
this.recyclers = new EntitySummaryCollection(client, scope, "recyclers");
|
|
436
436
|
this.blocks = new BlockCollection(client, scope);
|
|
437
437
|
this.materials = new MaterialCollection(client, scope);
|
|
438
|
+
this.tiles = new TileDomain(client, scope);
|
|
438
439
|
}
|
|
439
440
|
|
|
440
441
|
get id() {
|
|
@@ -681,6 +682,36 @@ export class MaterialCollection {
|
|
|
681
682
|
}
|
|
682
683
|
}
|
|
683
684
|
|
|
685
|
+
// Tile reads for a world. `chunks()` reads the columnar store directly and
|
|
686
|
+
// allocates nothing, so it is safe to scan every tick; `all()` and `at()` build
|
|
687
|
+
// tile objects.
|
|
688
|
+
export class TileDomain {
|
|
689
|
+
constructor(client, scope) {
|
|
690
|
+
this.client = client;
|
|
691
|
+
this.scope = scope;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
get count() {
|
|
695
|
+
return worldStateFor(this.client, this.scope)?.tiles.size ?? 0;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
get version() {
|
|
699
|
+
return worldStateFor(this.client, this.scope)?.tileVersion ?? 0;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
chunks() {
|
|
703
|
+
return worldStateFor(this.client, this.scope)?.tileChunks() || [];
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
at(x, y) {
|
|
707
|
+
return worldStateFor(this.client, this.scope)?.tileAt(x, y) ?? null;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
all() {
|
|
711
|
+
return worldStateFor(this.client, this.scope)?.tiles.toArray() || [];
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
684
715
|
export class MachineCollection {
|
|
685
716
|
constructor(client, scope) {
|
|
686
717
|
this.client = client;
|
|
@@ -1487,6 +1518,25 @@ export class ExpandoBoxHandle extends MachineHandle {
|
|
|
1487
1518
|
get count() {
|
|
1488
1519
|
return this.state?.count;
|
|
1489
1520
|
}
|
|
1521
|
+
#requireAdvanced() {
|
|
1522
|
+
if (!this.state?.advanced) throw new Error("Configuration requires an Advanced Expando Box");
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
configure(config = {}) {
|
|
1526
|
+
this.#requireAdvanced();
|
|
1527
|
+
return this.client.sendAdvancedExpandoBoxConfig(this.id, config);
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
copy(config = {}) {
|
|
1531
|
+
this.#requireAdvanced();
|
|
1532
|
+
return this.client.copyAdvancedExpandoBoxConfig(this.id, config);
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
paste(config = {}) {
|
|
1536
|
+
this.#requireAdvanced();
|
|
1537
|
+
return this.client.pasteAdvancedExpandoBoxConfig(this.id, config);
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1490
1540
|
}
|
|
1491
1541
|
|
|
1492
1542
|
export class CargoEjectorHandle extends MachineHandle {
|
package/src/crypto/chacha.js
CHANGED
|
@@ -246,19 +246,38 @@ function chacha20Xor(key, nonce, data) {
|
|
|
246
246
|
return chacha20Into(out, key, nonce, data.length, data);
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
// A world's key bytes are fixed for its lifetime, so encode them once rather
|
|
250
|
+
// than on every packet.
|
|
251
|
+
const WORLD_KEY_CACHE = new Map();
|
|
252
|
+
const WORLD_KEY_CACHE_LIMIT = 64;
|
|
253
|
+
// Reused per packet: the key and nonce are consumed synchronously.
|
|
254
|
+
const MATERIAL_SCRATCH = new Uint8Array(44);
|
|
255
|
+
|
|
256
|
+
function worldKeyBytes(worldId, seed) {
|
|
257
|
+
const text = `${worldId}${seed}`;
|
|
258
|
+
let bytes = WORLD_KEY_CACHE.get(text);
|
|
259
|
+
if (!bytes) {
|
|
260
|
+
if (WORLD_KEY_CACHE.size >= WORLD_KEY_CACHE_LIMIT) WORLD_KEY_CACHE.clear();
|
|
261
|
+
bytes = encoder.encode(text);
|
|
262
|
+
WORLD_KEY_CACHE.set(text, bytes);
|
|
263
|
+
}
|
|
264
|
+
return bytes;
|
|
265
|
+
}
|
|
266
|
+
|
|
249
267
|
function decryptPayload(wireBytes, worldId, seed) {
|
|
250
268
|
const wire = toUint8Array(wireBytes);
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const packetWordA =
|
|
254
|
-
const packetWordB =
|
|
255
|
-
const material =
|
|
256
|
-
const worldKey =
|
|
269
|
+
const length = wire.length;
|
|
270
|
+
if (length < 8) throw new Error("payload too short");
|
|
271
|
+
const packetWordA = readLe32(wire, 0);
|
|
272
|
+
const packetWordB = readLe32(wire, length - 4);
|
|
273
|
+
const material = MATERIAL_SCRATCH;
|
|
274
|
+
const worldKey = worldKeyBytes(worldId, seed);
|
|
275
|
+
const keyLength = worldKey.length;
|
|
257
276
|
for (let i = 0, l = 0, r = 0; i < 44; i++, l += 7, r += 11) {
|
|
258
|
-
material[i]
|
|
277
|
+
material[i] = SHARED_CHACHA_MATERIAL[i] ^ worldKey[i % keyLength] ^ (rotl32(packetWordA, l) & 0xff) ^ (rotr32(packetWordB, r) & 0xff);
|
|
259
278
|
}
|
|
260
279
|
// subarray, not slice: the key and nonce are only read.
|
|
261
|
-
const ciphertext = wire.subarray(4,
|
|
280
|
+
const ciphertext = wire.subarray(4, length - 4);
|
|
262
281
|
return chacha20Xor(material.subarray(0, 32), material.subarray(32, 44), ciphertext);
|
|
263
282
|
}
|
|
264
283
|
|
package/src/data/item-schema.js
CHANGED
|
@@ -938,7 +938,7 @@ export const ITEM_SCHEMA = Object.freeze([
|
|
|
938
938
|
{
|
|
939
939
|
"id": 219,
|
|
940
940
|
"name": "Spawn Point (Packaged)",
|
|
941
|
-
"desc": "Buildable. Can be set to spawn
|
|
941
|
+
"desc": "Buildable. Can be set to spawn specific ranks.",
|
|
942
942
|
"image": "item/spawn",
|
|
943
943
|
"rarity": 0,
|
|
944
944
|
"max_stack": 1,
|
|
@@ -959,7 +959,7 @@ export const ITEM_SCHEMA = Object.freeze([
|
|
|
959
959
|
{
|
|
960
960
|
"id": 220,
|
|
961
961
|
"name": "Door (Packaged)",
|
|
962
|
-
"desc": "Buildable. Can be restricted to specific ranks.
|
|
962
|
+
"desc": "Buildable. Can be restricted to specific ranks.",
|
|
963
963
|
"image": "item/door",
|
|
964
964
|
"rarity": 0,
|
|
965
965
|
"max_stack": 1,
|
|
@@ -1638,6 +1638,22 @@ export const ITEM_SCHEMA = Object.freeze([
|
|
|
1638
1638
|
"rarity": 1,
|
|
1639
1639
|
"max_stack": 1
|
|
1640
1640
|
},
|
|
1641
|
+
{
|
|
1642
|
+
"id": 266,
|
|
1643
|
+
"name": "Advanced Expando Box (Packaged)",
|
|
1644
|
+
"desc": "Buildable. Dense bulk storage with configurable size limits. Spills more items when shot.",
|
|
1645
|
+
"image": "item/exbox_adv",
|
|
1646
|
+
"rarity": 2,
|
|
1647
|
+
"max_stack": 1
|
|
1648
|
+
},
|
|
1649
|
+
{
|
|
1650
|
+
"id": 267,
|
|
1651
|
+
"name": "Advanced Logistics Controller",
|
|
1652
|
+
"desc": "Component. Used to produce advanced logistics machinery.",
|
|
1653
|
+
"image": "item/adv_logi_controller",
|
|
1654
|
+
"rarity": 2,
|
|
1655
|
+
"max_stack": 1
|
|
1656
|
+
},
|
|
1641
1657
|
{
|
|
1642
1658
|
"id": 300,
|
|
1643
1659
|
"name": "Eternal Bronze Wrench",
|
package/src/index.d.ts
CHANGED
|
@@ -438,6 +438,24 @@ export interface RankFilterConfig {
|
|
|
438
438
|
/** 0–7, or 0xffffffff for all current and future ranks. */
|
|
439
439
|
rankMask?: number;
|
|
440
440
|
}
|
|
441
|
+
/** Advanced Expando Box settings. Dimensions are world units (2–100).
|
|
442
|
+
* fixedSize uses minWidth/minHeight; RGB colors are integers 0–0xffffff.
|
|
443
|
+
* The server applies expansion, capacity and aspect-ratio rules.
|
|
444
|
+
*/
|
|
445
|
+
export interface AdvancedExpandoBoxConfig {
|
|
446
|
+
minWidth?: number;
|
|
447
|
+
maxWidth?: number;
|
|
448
|
+
minHeight?: number;
|
|
449
|
+
maxHeight?: number;
|
|
450
|
+
minEnabled?: boolean;
|
|
451
|
+
maxEnabled?: boolean;
|
|
452
|
+
fixedSize?: boolean;
|
|
453
|
+
backgroundColor?: number;
|
|
454
|
+
borderColor?: number;
|
|
455
|
+
/** Background opacity, from 0 to 1. */
|
|
456
|
+
opacity?: number;
|
|
457
|
+
}
|
|
458
|
+
|
|
441
459
|
export interface LauncherConfig {
|
|
442
460
|
/** Degrees, 0–360. */
|
|
443
461
|
angle?: number;
|
|
@@ -485,7 +503,7 @@ export interface AccountDetails {
|
|
|
485
503
|
}
|
|
486
504
|
|
|
487
505
|
export class Session {
|
|
488
|
-
constructor(gameSession?: string | null, gameVersion?: string | null);
|
|
506
|
+
constructor(gameSession?: string | null, gameVersion?: string | null, baseUrl?: string);
|
|
489
507
|
|
|
490
508
|
baseUrl: string;
|
|
491
509
|
cookies: Map<string, string>;
|
|
@@ -505,7 +523,7 @@ export class Session {
|
|
|
505
523
|
get noticeVersion(): number | string | null;
|
|
506
524
|
set noticeVersion(value: number | string | null);
|
|
507
525
|
|
|
508
|
-
request(path: string, init?: RequestInit & { body?:
|
|
526
|
+
request(path: string, init?: Omit<RequestInit, "body"> & { body?: RequestInit["body"] | Record<string, unknown> | null }): Promise<Response>;
|
|
509
527
|
|
|
510
528
|
fetchAccountStatus(): Promise<unknown>;
|
|
511
529
|
|
|
@@ -543,7 +561,7 @@ export class Session {
|
|
|
543
561
|
}
|
|
544
562
|
|
|
545
563
|
export class AnonSession extends Session {
|
|
546
|
-
constructor(gameSession?: string | null, anonKey?: string | null, gameVersion?: string | null);
|
|
564
|
+
constructor(gameSession?: string | null, anonKey?: string | null, gameVersion?: string | null, baseUrl?: string);
|
|
547
565
|
|
|
548
566
|
get anonKey(): string;
|
|
549
567
|
}
|
|
@@ -658,6 +676,10 @@ export class DredlessClient {
|
|
|
658
676
|
|
|
659
677
|
whenReady(): Promise<this>;
|
|
660
678
|
|
|
679
|
+
sendAdvancedExpandoBoxConfig(entity: number, config?: AdvancedExpandoBoxConfig): DredlessClient;
|
|
680
|
+
copyAdvancedExpandoBoxConfig(entity: number, config?: AdvancedExpandoBoxConfig): DredlessClient;
|
|
681
|
+
pasteAdvancedExpandoBoxConfig(entity: number, config?: AdvancedExpandoBoxConfig): DredlessClient;
|
|
682
|
+
|
|
661
683
|
sendLauncherConfig(entity: number, config?: LauncherConfig): DredlessClient;
|
|
662
684
|
setLauncherAngle(entity: number, angle: number, config?: LauncherConfig): DredlessClient;
|
|
663
685
|
setLauncherPower(entity: number, power: number, config?: LauncherConfig): DredlessClient;
|
|
@@ -979,6 +1001,7 @@ export interface WorldDomain {
|
|
|
979
1001
|
recyclers: EntitySummaryCollection<RecyclerSummary>;
|
|
980
1002
|
blocks: BlockCollection;
|
|
981
1003
|
materials: MaterialCollection;
|
|
1004
|
+
tiles: TileDomain;
|
|
982
1005
|
|
|
983
1006
|
exists(): boolean;
|
|
984
1007
|
|
|
@@ -1100,6 +1123,22 @@ export interface MaterialCollection {
|
|
|
1100
1123
|
all(): MaterialSummary[];
|
|
1101
1124
|
}
|
|
1102
1125
|
|
|
1126
|
+
/** Tile reads for one world. `chunks()` allocates nothing and is safe to scan every tick. */
|
|
1127
|
+
export interface TileDomain {
|
|
1128
|
+
/** Number of tiles currently stored. */
|
|
1129
|
+
readonly count: number;
|
|
1130
|
+
/** Bumped on every tile write; 0 when the world is unknown. */
|
|
1131
|
+
readonly version: number;
|
|
1132
|
+
|
|
1133
|
+
/** Live, zero-copy views of each 64x64 chunk. Treat as read-only. */
|
|
1134
|
+
chunks(): TileChunkView[];
|
|
1135
|
+
|
|
1136
|
+
at(x: number, y: number): Tile | null;
|
|
1137
|
+
|
|
1138
|
+
/** Every tile as an object. Prefer `chunks()` for per-tick scans. */
|
|
1139
|
+
all(): Tile[];
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1103
1142
|
export interface MachineCollection {
|
|
1104
1143
|
state(): MachineSummary;
|
|
1105
1144
|
|
|
@@ -1524,6 +1563,10 @@ export interface FluidTankHandle extends MachineHandle {
|
|
|
1524
1563
|
|
|
1525
1564
|
export interface ExpandoBoxHandle extends MachineHandle {
|
|
1526
1565
|
state: ExpandoBoxSummary | null;
|
|
1566
|
+
/** Configure/copy/paste require an Advanced Expando Box. */
|
|
1567
|
+
configure(config?: AdvancedExpandoBoxConfig): DredlessClient;
|
|
1568
|
+
copy(config?: AdvancedExpandoBoxConfig): DredlessClient;
|
|
1569
|
+
paste(config?: AdvancedExpandoBoxConfig): DredlessClient;
|
|
1527
1570
|
item: number | null | undefined;
|
|
1528
1571
|
count: number | null | undefined;
|
|
1529
1572
|
}
|
|
@@ -1812,7 +1855,10 @@ export class WorldState {
|
|
|
1812
1855
|
blockHeight: number | null;
|
|
1813
1856
|
parentWorld: number | null;
|
|
1814
1857
|
parentEntity: number | null;
|
|
1815
|
-
tiles:
|
|
1858
|
+
/** This world's tiles as objects: `size` and `toArray()`. */
|
|
1859
|
+
tiles: TileCollection;
|
|
1860
|
+
/** Bumped on every tile write. */
|
|
1861
|
+
readonly tileVersion: number;
|
|
1816
1862
|
chunks: unknown[];
|
|
1817
1863
|
events: unknown[];
|
|
1818
1864
|
modelPackets: unknown[];
|
|
@@ -1832,6 +1878,18 @@ export class WorldState {
|
|
|
1832
1878
|
|
|
1833
1879
|
applyChunk(value: unknown): Tile[] | null;
|
|
1834
1880
|
|
|
1881
|
+
/** Applies a chunk patch; the returned entry builds its `tiles` array on first read. */
|
|
1882
|
+
applyChunkPatch(value: unknown): TileChunkPatch | null;
|
|
1883
|
+
|
|
1884
|
+
/** Live, zero-copy views of each 64x64 chunk. Stable for the life of the chunk; treat as read-only. */
|
|
1885
|
+
tileChunks(): TileChunkView[];
|
|
1886
|
+
|
|
1887
|
+
/** O(1) lookup of the tile at a coordinate. */
|
|
1888
|
+
tileAt(x: number, y: number): Tile | null;
|
|
1889
|
+
|
|
1890
|
+
/** Drops tile objects retained for repeated `tiles.toArray()` reads. */
|
|
1891
|
+
releaseTileObjects(): void;
|
|
1892
|
+
|
|
1835
1893
|
setTile(tile: Tile): Tile;
|
|
1836
1894
|
|
|
1837
1895
|
normalizeTile(tile: Tile): Tile;
|
|
@@ -1873,6 +1931,58 @@ export interface Tile {
|
|
|
1873
1931
|
hpValue?: number | null;
|
|
1874
1932
|
}
|
|
1875
1933
|
|
|
1934
|
+
/**
|
|
1935
|
+
* Tile objects for a world. Objects are built on demand from columnar storage:
|
|
1936
|
+
* they are not identity-stable across writes and mutating one does not change
|
|
1937
|
+
* stored state. There is intentionally no iterator; iterate the array.
|
|
1938
|
+
*/
|
|
1939
|
+
export interface TileCollection {
|
|
1940
|
+
readonly size: number;
|
|
1941
|
+
|
|
1942
|
+
/** A fresh array of every tile, ordered by chunk. */
|
|
1943
|
+
toArray(): Tile[];
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
/** Values of `TileChunkView.flags`. Zero means the cell holds no tile. */
|
|
1947
|
+
export const TileFlags: {
|
|
1948
|
+
/** The cell holds a tile. */
|
|
1949
|
+
readonly Present: 1;
|
|
1950
|
+
/** The tile was sent without a color; its `color` is null. */
|
|
1951
|
+
readonly NoColor: 2;
|
|
1952
|
+
};
|
|
1953
|
+
|
|
1954
|
+
/**
|
|
1955
|
+
* One 64x64 chunk of tiles as byte columns. Cell `i` is the tile at
|
|
1956
|
+
* `(originX + (i & 63), originY + (i >> 6))`. The arrays are live views of
|
|
1957
|
+
* client state: they change as packets arrive and must not be written to.
|
|
1958
|
+
*/
|
|
1959
|
+
export interface TileChunkView {
|
|
1960
|
+
readonly chunkX: number;
|
|
1961
|
+
readonly chunkY: number;
|
|
1962
|
+
readonly originX: number;
|
|
1963
|
+
readonly originY: number;
|
|
1964
|
+
/** `WorldState.tileVersion` at this chunk's last write. */
|
|
1965
|
+
readonly version: number;
|
|
1966
|
+
readonly material: Uint8Array;
|
|
1967
|
+
readonly shape: Uint8Array;
|
|
1968
|
+
/** Raw 0-255 HP fraction byte. */
|
|
1969
|
+
readonly hp: Uint8Array;
|
|
1970
|
+
/** Meaningful only where `flags` lacks `TileFlags.NoColor`. */
|
|
1971
|
+
readonly color: Uint8Array;
|
|
1972
|
+
readonly flags: Uint8Array;
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
export interface TileChunkPatch {
|
|
1976
|
+
chunkX: number;
|
|
1977
|
+
chunkY: number;
|
|
1978
|
+
minX: number;
|
|
1979
|
+
minY: number;
|
|
1980
|
+
maxX: number;
|
|
1981
|
+
maxY: number;
|
|
1982
|
+
/** Built on first read. */
|
|
1983
|
+
readonly tiles: Tile[];
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1876
1986
|
export interface MaterialSummary {
|
|
1877
1987
|
material: number;
|
|
1878
1988
|
name: string | null;
|
|
@@ -1995,6 +2105,16 @@ export interface CommsBubbleSummary {
|
|
|
1995
2105
|
}
|
|
1996
2106
|
|
|
1997
2107
|
export class ModelState {
|
|
2108
|
+
/** Local monotonic apply revision; independent of wire generation values. */
|
|
2109
|
+
readonly revision: number;
|
|
2110
|
+
/** Sorted live component IDs without materializing debug summaries. */
|
|
2111
|
+
componentEntityIds(): IterableIterator<number>;
|
|
2112
|
+
/** Latest mutation revision of a live entity, zero after removal. */
|
|
2113
|
+
entityRevision(entityId: number): number;
|
|
2114
|
+
/** Last local apply revision that touched this decoded record. */
|
|
2115
|
+
recordRevision(record: ModelRecord | null | undefined): number;
|
|
2116
|
+
/** Stateful navigation destination without materializing entity summaries. */
|
|
2117
|
+
navigationDestination(entityId: number): number;
|
|
1998
2118
|
/** Local entity identified by the decrypted camera-focus message, when known. */
|
|
1999
2119
|
readonly localPlayerEntity: number | null;
|
|
2000
2120
|
setLocalPlayerEntity(entity: number | null): void;
|
|
@@ -2099,14 +2219,21 @@ export interface ItemCrateSummary {
|
|
|
2099
2219
|
count: number | null;
|
|
2100
2220
|
/** Use the box sprite instead of the item's normal sprite. */
|
|
2101
2221
|
boxSprite: boolean;
|
|
2222
|
+
/** Dimensions in world units; raw dimensions use tenths of a unit. */
|
|
2102
2223
|
width: number | null;
|
|
2103
2224
|
height: number | null;
|
|
2225
|
+
rawWidth: number | null;
|
|
2226
|
+
rawHeight: number | null;
|
|
2104
2227
|
itemState: ModelRecord;
|
|
2105
2228
|
sizeState: ModelRecord;
|
|
2106
2229
|
}
|
|
2107
2230
|
|
|
2108
2231
|
export interface ExpandoBoxSummary {
|
|
2109
2232
|
entity: number;
|
|
2233
|
+
advanced: boolean;
|
|
2234
|
+
config: Required<AdvancedExpandoBoxConfig> | null;
|
|
2235
|
+
sizeConfigState: ModelRecord;
|
|
2236
|
+
colorConfigState: ModelRecord;
|
|
2110
2237
|
itemId: number | null;
|
|
2111
2238
|
itemName: string | null;
|
|
2112
2239
|
count: number | null;
|
|
@@ -2146,8 +2273,8 @@ export interface MapMarkerSummary {
|
|
|
2146
2273
|
export interface DockingSpringSummary {
|
|
2147
2274
|
entity: number;
|
|
2148
2275
|
id: number | null;
|
|
2149
|
-
width: number;
|
|
2150
|
-
height: number;
|
|
2276
|
+
width: number | null;
|
|
2277
|
+
height: number | null;
|
|
2151
2278
|
state: ModelRecord;
|
|
2152
2279
|
}
|
|
2153
2280
|
|
|
@@ -2912,3 +3039,7 @@ export interface DredlessNamespace {
|
|
|
2912
3039
|
}
|
|
2913
3040
|
export const Dredless: DredlessNamespace;
|
|
2914
3041
|
export default Dredless;
|
|
3042
|
+
|
|
3043
|
+
export function buildAdvancedExpandoBoxConfigData(entity: number, config?: AdvancedExpandoBoxConfig): Uint8Array;
|
|
3044
|
+
export function buildAdvancedExpandoBoxCopyConfigData(config?: AdvancedExpandoBoxConfig): Uint8Array;
|
|
3045
|
+
export function buildAdvancedExpandoBoxPasteConfigData(entity: number, config?: AdvancedExpandoBoxConfig): Uint8Array;
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export {buildAdvancedExpandoBoxConfigData, buildAdvancedExpandoBoxCopyConfigData, buildAdvancedExpandoBoxPasteConfigData} from "./protocol/outbound/advanced-expando.js";
|
|
1
2
|
export {
|
|
2
3
|
buildLauncherConfigData,
|
|
3
4
|
buildLauncherCopyConfigData,
|
|
@@ -14,7 +15,7 @@ export {Session, AnonSession} from "./network/session.js";
|
|
|
14
15
|
export {Connection} from "./network/connection.js";
|
|
15
16
|
export {DropReason, DisconnectError, normalizeDisconnect} from "./network/disconnect.js";
|
|
16
17
|
export {DredlessClient, WrenchMode, TurretMode} from "./client/index.js";
|
|
17
|
-
export {WorldStore, WorldState} from "./state/world/index.js";
|
|
18
|
+
export {WorldStore, WorldState, TileFlags} from "./state/world/index.js";
|
|
18
19
|
export {FabricatorType, ModelState, decodeModelData} from "./state/model/index.js";
|
|
19
20
|
export {generateGeneratorMaze, solveGeneratorMazeSeed, maybeSolveGeneratorMazeSeed} from "./state/generator-maze.js";
|
|
20
21
|
export {buildBlueprintPlacementMessage} from "./protocol/outbound/blueprint.js";
|
|
@@ -11,6 +11,9 @@ function isArrayBufferLike(value) {
|
|
|
11
11
|
|
|
12
12
|
function toUint8Array(value) {
|
|
13
13
|
if (value instanceof Uint8Array) return value;
|
|
14
|
+
// Fast path for the websocket's own buffers; the tag check below covers
|
|
15
|
+
// cross-realm ArrayBuffers and SharedArrayBuffer.
|
|
16
|
+
if (value instanceof ArrayBuffer) return new Uint8Array(value);
|
|
14
17
|
if (isArrayBufferLike(value)) return new Uint8Array(value);
|
|
15
18
|
if (ArrayBuffer.isView(value)) {
|
|
16
19
|
return new Uint8Array(value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength));
|