dredless 1.3.1 → 1.4.1

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/src/index.d.ts CHANGED
@@ -376,6 +376,11 @@ export const LoaderPriority: {
376
376
  export type LoaderPriority = typeof LoaderPriority[keyof typeof LoaderPriority];
377
377
  export type ClipboardTarget =
378
378
  number
379
+ | "launcher"
380
+ | "door"
381
+ | "spawn"
382
+ | "spawn-point"
383
+ | "spawnPoint"
379
384
  | "loader"
380
385
  | "loader-config"
381
386
  | "loaderConfig"
@@ -424,6 +429,28 @@ export interface LoaderConfig {
424
429
  waitForStack?: boolean;
425
430
  }
426
431
 
432
+ export type AllowedRank = "guest" | "crew" | "captain";
433
+ export type AllowedRanks = readonly AllowedRank[] | "all";
434
+
435
+ export interface RankFilterConfig {
436
+ /** Specify allowedRanks or rankMask, not both. Empty disables all ranks. */
437
+ allowedRanks?: AllowedRanks;
438
+ /** 0–7, or 0xffffffff for all current and future ranks. */
439
+ rankMask?: number;
440
+ }
441
+ export interface LauncherConfig {
442
+ /** Degrees, 0–360. */
443
+ angle?: number;
444
+ /** 0–30; fractional values are supported. */
445
+ power?: number;
446
+ }
447
+ export interface DoorConfig extends RankFilterConfig {}
448
+ export interface DoorClipboardConfig extends DoorConfig {
449
+ /** Placement orientation; does not rotate an existing door. */
450
+ orientation?: "vertical" | "horizontal";
451
+ }
452
+ export interface SpawnPointConfig extends RankFilterConfig {}
453
+
427
454
  export interface LoaderFullConfig extends LoaderConfig {
428
455
  filterMode?: LoaderFilterMode;
429
456
  filterSlots?: Array<number | null | undefined>;
@@ -631,6 +658,18 @@ export class DredlessClient {
631
658
 
632
659
  whenReady(): Promise<this>;
633
660
 
661
+ sendLauncherConfig(entity: number, config?: LauncherConfig): DredlessClient;
662
+ setLauncherAngle(entity: number, angle: number, config?: LauncherConfig): DredlessClient;
663
+ setLauncherPower(entity: number, power: number, config?: LauncherConfig): DredlessClient;
664
+ copyLauncherConfig(entity: number, config?: LauncherConfig): DredlessClient;
665
+ pasteLauncherConfig(entity: number, config?: LauncherConfig): DredlessClient;
666
+ sendDoorConfig(entity: number, config?: DoorConfig): DredlessClient;
667
+ copyDoorConfig(entity: number, config?: DoorClipboardConfig): DredlessClient;
668
+ pasteDoorConfig(entity: number, config?: DoorClipboardConfig): DredlessClient;
669
+ sendSpawnPointConfig(entity: number, config?: SpawnPointConfig): DredlessClient;
670
+ copySpawnPointConfig(entity: number, config?: SpawnPointConfig): DredlessClient;
671
+ pasteSpawnPointConfig(entity: number, config?: SpawnPointConfig): DredlessClient;
672
+
634
673
  close(code?: number, reason?: string): this;
635
674
 
636
675
  disconnect(code?: number, reason?: string): this;
@@ -1340,9 +1379,13 @@ export interface PusherHandle extends MachineHandle {
1340
1379
  export interface LauncherHandle extends MachineHandle {
1341
1380
  state: LauncherSummary | null;
1342
1381
 
1343
- setAngle(angle: number): DredlessClient;
1382
+ configure(config?: LauncherConfig): DredlessClient;
1383
+ copy(config?: LauncherConfig): DredlessClient;
1384
+ paste(config?: LauncherConfig): DredlessClient;
1385
+ setAngle(angle: number, config?: LauncherConfig): DredlessClient;
1344
1386
 
1345
- setPower(power: number): DredlessClient;
1387
+ setPower(power: number, config?: LauncherConfig): DredlessClient;
1388
+ power: number | null | undefined;
1346
1389
 
1347
1390
  angleDegrees: number | undefined;
1348
1391
  angleRadians: number | undefined;
@@ -1448,15 +1491,25 @@ export interface HelmHandle extends MachineHandle {
1448
1491
 
1449
1492
  export interface DoorHandle extends EntityHandle {
1450
1493
  state: DoorSummary | null;
1451
- rank: number | undefined;
1494
+ rankMask: number | null | undefined;
1495
+ allowedRanks: ("guest" | "crew" | "captain")[] | null | undefined;
1452
1496
  open: boolean | undefined;
1453
- setRank(rank: ShipPlayerRank, options?: TipOptions): Promise<DredlessClient>;
1497
+ configure(config?: DoorConfig): DredlessClient;
1498
+ copy(config?: DoorClipboardConfig): DredlessClient;
1499
+ paste(config?: DoorClipboardConfig): DredlessClient;
1500
+ setAllowedRanks(allowedRanks: AllowedRanks): DredlessClient;
1501
+ setRankMask(rankMask: number): DredlessClient;
1454
1502
  }
1455
1503
 
1456
1504
  export interface SpawnPointHandle extends MachineHandle {
1457
1505
  state: SpawnPointSummary | null;
1458
- rank: number | undefined;
1459
- setRank(rank: ShipPlayerRank, options?: TipOptions): Promise<DredlessClient>;
1506
+ rankMask: number | null | undefined;
1507
+ allowedRanks: ("guest" | "crew" | "captain")[] | null | undefined;
1508
+ configure(config?: SpawnPointConfig): DredlessClient;
1509
+ copy(config?: SpawnPointConfig): DredlessClient;
1510
+ paste(config?: SpawnPointConfig): DredlessClient;
1511
+ setAllowedRanks(allowedRanks: AllowedRanks): DredlessClient;
1512
+ setRankMask(rankMask: number): DredlessClient;
1460
1513
  }
1461
1514
 
1462
1515
  export interface ShieldProjectorHandle extends MachineHandle {
@@ -2044,6 +2097,8 @@ export interface ItemCrateSummary {
2044
2097
  itemId: number | null;
2045
2098
  itemName: string | null;
2046
2099
  count: number | null;
2100
+ /** Use the box sprite instead of the item's normal sprite. */
2101
+ boxSprite: boolean;
2047
2102
  width: number | null;
2048
2103
  height: number | null;
2049
2104
  itemState: ModelRecord;
@@ -2123,6 +2178,10 @@ export interface HealthSummary {
2123
2178
  hp: number | null;
2124
2179
  maxHp: number | null;
2125
2180
  ratio: number | null;
2181
+ /** Full width of the rendered health bar, in world units. */
2182
+ barWidth: number;
2183
+ /** Vertical displacement from the entity position, in world units. */
2184
+ barOffsetY: number;
2126
2185
  state: ModelRecord;
2127
2186
  }
2128
2187
 
@@ -2297,6 +2356,9 @@ export interface LauncherSummary {
2297
2356
  angleRaw: number | null;
2298
2357
  angleRadians: number | null;
2299
2358
  angleDegrees: number | null;
2359
+ /** Replicated launcher power; null on legacy servers. */
2360
+ power: number | null;
2361
+ configState: ModelRecord | null;
2300
2362
  state: ModelRecord;
2301
2363
  }
2302
2364
 
@@ -2353,19 +2415,23 @@ export interface SignSummary {
2353
2415
  state: ModelRecord;
2354
2416
  }
2355
2417
 
2356
- export interface SpawnPointSummary {
2418
+ export interface RankFilterSummary {
2419
+ /** Unsigned rank bits: guest=1, crew=2, captain=4; null if unavailable. */
2420
+ rankMask: number | null;
2421
+ allowedRanks: ("guest" | "crew" | "captain")[] | null;
2422
+ /** True for the all-ranks mask, including future ranks. */
2423
+ allRanks: boolean;
2424
+ rankState: ModelRecord;
2425
+ }
2426
+
2427
+ export interface SpawnPointSummary extends RankFilterSummary {
2357
2428
  entity: number;
2358
- rank: number;
2359
- rankName: string | null;
2360
2429
  state: ModelRecord;
2361
2430
  }
2362
2431
 
2363
- export interface DoorSummary {
2432
+ export interface DoorSummary extends RankFilterSummary {
2364
2433
  entity: number;
2365
- rank: number;
2366
- rankName: string | null;
2367
2434
  open: boolean;
2368
- rankState: ModelRecord;
2369
2435
  state: ModelRecord;
2370
2436
  }
2371
2437
 
@@ -2769,6 +2835,17 @@ export function buildLoaderFullConfigData(entity: number, config?: LoaderFullCon
2769
2835
 
2770
2836
  export function buildPusherConfigData(entity: number, config?: PusherConfig): Uint8Array;
2771
2837
 
2838
+ export function normalizeRankMask(config?: RankFilterConfig): number;
2839
+ export function buildLauncherConfigData(entity: number, config?: LauncherConfig): Uint8Array;
2840
+ export function buildLauncherCopyConfigData(config?: LauncherConfig): Uint8Array;
2841
+ export function buildLauncherPasteConfigData(entity: number, config?: LauncherConfig): Uint8Array;
2842
+ export function buildDoorConfigData(entity: number, config?: DoorConfig): Uint8Array;
2843
+ export function buildDoorCopyConfigData(config?: DoorClipboardConfig): Uint8Array;
2844
+ export function buildDoorPasteConfigData(entity: number, config?: DoorClipboardConfig): Uint8Array;
2845
+ export function buildSpawnPointConfigData(entity: number, config?: SpawnPointConfig): Uint8Array;
2846
+ export function buildSpawnPointCopyConfigData(config?: SpawnPointConfig): Uint8Array;
2847
+ export function buildSpawnPointPasteConfigData(entity: number, config?: SpawnPointConfig): Uint8Array;
2848
+
2772
2849
  export function buildPusherFilterItemsData(entity: number, filterSlots?: Array<number | null | undefined>): Uint8Array;
2773
2850
 
2774
2851
  export function generateGeneratorMaze(seed: number): GeneratorMaze;
package/src/index.js CHANGED
@@ -1,3 +1,15 @@
1
+ export {
2
+ buildLauncherConfigData,
3
+ buildLauncherCopyConfigData,
4
+ buildLauncherPasteConfigData,
5
+ buildDoorConfigData,
6
+ buildDoorCopyConfigData,
7
+ buildDoorPasteConfigData,
8
+ buildSpawnPointConfigData,
9
+ buildSpawnPointCopyConfigData,
10
+ buildSpawnPointPasteConfigData,
11
+ normalizeRankMask,
12
+ } from "./protocol/outbound/machine-config.js";
1
13
  export {Session, AnonSession} from "./network/session.js";
2
14
  export {Connection} from "./network/connection.js";
3
15
  export {DropReason, DisconnectError, normalizeDisconnect} from "./network/disconnect.js";
@@ -0,0 +1,19 @@
1
+ export {
2
+ buildLauncherConfigData,
3
+ buildLauncherCopyConfigData,
4
+ buildLauncherPasteConfigData,
5
+ buildDoorConfigData,
6
+ buildDoorCopyConfigData,
7
+ buildDoorPasteConfigData,
8
+ buildSpawnPointConfigData,
9
+ buildSpawnPointCopyConfigData,
10
+ buildSpawnPointPasteConfigData,
11
+ normalizeRankMask,
12
+ type AllowedRank,
13
+ type AllowedRanks,
14
+ type RankFilterConfig,
15
+ type LauncherConfig,
16
+ type DoorConfig,
17
+ type DoorClipboardConfig,
18
+ type SpawnPointConfig,
19
+ } from "../../index.js";
@@ -0,0 +1,112 @@
1
+ import {encoder} from "../../constants.js";
2
+
3
+ function uint32(value, name) {
4
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0 || value > 0xffffffff) {
5
+ throw new RangeError(`${name} must be an unsigned 32-bit integer`);
6
+ }
7
+ return value;
8
+ }
9
+
10
+ function encodeUnsigned(value) {
11
+ if (value < 64) return [value];
12
+ if (value < 256) return [0x80, value];
13
+ if (value < 65536) return [0x81, value & 255, value >>> 8];
14
+ return [0x82, value & 255, value >>> 8 & 255, value >>> 16 & 255, value >>> 24];
15
+ }
16
+
17
+ function encodeFloat(value, name, max) {
18
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > max) {
19
+ throw new RangeError(`${name} must be a finite number between 0 and ${max}`);
20
+ }
21
+ const number = Math.fround(value);
22
+ if (Number.isInteger(number)) {
23
+ if (number < 64) return [number];
24
+ if (number < 128) return [0x84, number];
25
+ return [0x85, number & 255, number >>> 8];
26
+ }
27
+ const bytes = new Uint8Array(5);
28
+ bytes[0] = 0x88;
29
+ new DataView(bytes.buffer).setFloat32(1, number, true);
30
+ return [...bytes];
31
+ }
32
+
33
+ function section(name, values) {
34
+ const bytes = encoder.encode(name);
35
+ return [0x8a, bytes.length, ...bytes, 0, 0x90, ...values, 0x91];
36
+ }
37
+
38
+ function message(target, action, sections) {
39
+ return Uint8Array.from([0x90, action, ...encodeUnsigned(uint32(target, "target")), ...sections.flat(), 0x91]);
40
+ }
41
+
42
+ export function normalizeRankMask({allowedRanks, rankMask} = {}) {
43
+ if (allowedRanks !== undefined && rankMask !== undefined) {
44
+ throw new TypeError("provide allowedRanks or rankMask, not both");
45
+ }
46
+ if (rankMask !== undefined) {
47
+ const value = uint32(rankMask, "rankMask");
48
+ if (value > 7 && value !== 0xffffffff) throw new RangeError("rankMask must be 0–7 or 0xffffffff");
49
+ return value;
50
+ }
51
+ if (allowedRanks === undefined) return 4;
52
+ if (allowedRanks === "all") return 0xffffffff;
53
+ if (!Array.isArray(allowedRanks)) throw new TypeError('allowedRanks must be an array of rank names or "all"');
54
+ let mask = 0;
55
+ for (const rank of allowedRanks) {
56
+ const bit = {guest: 1, crew: 2, captain: 4}[rank];
57
+ if (typeof rank !== "string" || !["guest", "crew", "captain"].includes(rank)) throw new RangeError(`unsupported rank: ${rank}`);
58
+ mask |= bit;
59
+ }
60
+ return mask;
61
+ }
62
+
63
+ function rankSection(config) {
64
+ return section("filter_ranks", encodeUnsigned(normalizeRankMask(config)));
65
+ }
66
+
67
+ function launcherSection({angle = 0, power = 30} = {}) {
68
+ return section("config_item_launcher", [...encodeFloat(angle, "angle", 360), ...encodeFloat(power, "power", 30)]);
69
+ }
70
+
71
+ function doorSections(config = {}, clipboard = false) {
72
+ if (!clipboard && config.orientation !== undefined) {
73
+ throw new TypeError("door orientation is only available for placement/clipboard configuration");
74
+ }
75
+ const sections = [rankSection(config)];
76
+ if (clipboard) {
77
+ const orientation = config.orientation ?? "vertical";
78
+ if (orientation !== "vertical" && orientation !== "horizontal") {
79
+ throw new RangeError('orientation must be "vertical" or "horizontal"');
80
+ }
81
+ sections.unshift(section("angle_symmetric", [orientation === "horizontal" ? 1 : 0]));
82
+ }
83
+ return sections;
84
+ }
85
+
86
+ export function buildLauncherConfigData(entity, config = {}) {
87
+ return message(entity, 0, [launcherSection(config)]);
88
+ }
89
+ export function buildLauncherCopyConfigData(config = {}) {
90
+ return message(8, 1, [launcherSection(config)]);
91
+ }
92
+ export function buildLauncherPasteConfigData(entity, config = {}) {
93
+ return message(entity, 2, [launcherSection(config)]);
94
+ }
95
+ export function buildDoorConfigData(entity, config = {}) {
96
+ return message(entity, 0, doorSections(config));
97
+ }
98
+ export function buildDoorCopyConfigData(config = {}) {
99
+ return message(10, 1, doorSections(config, true));
100
+ }
101
+ export function buildDoorPasteConfigData(entity, config = {}) {
102
+ return message(entity, 2, doorSections(config, true));
103
+ }
104
+ export function buildSpawnPointConfigData(entity, config = {}) {
105
+ return message(entity, 0, [rankSection(config)]);
106
+ }
107
+ export function buildSpawnPointCopyConfigData(config = {}) {
108
+ return message(9, 1, [rankSection(config)]);
109
+ }
110
+ export function buildSpawnPointPasteConfigData(entity, config = {}) {
111
+ return message(entity, 2, [rankSection(config)]);
112
+ }
@@ -1,3 +1,23 @@
1
+ export {
2
+ buildLauncherConfigData,
3
+ buildLauncherCopyConfigData,
4
+ buildLauncherPasteConfigData,
5
+ buildDoorConfigData,
6
+ buildDoorCopyConfigData,
7
+ buildDoorPasteConfigData,
8
+ buildSpawnPointConfigData,
9
+ buildSpawnPointCopyConfigData,
10
+ buildSpawnPointPasteConfigData,
11
+ normalizeRankMask,
12
+ type AllowedRank,
13
+ type AllowedRanks,
14
+ type RankFilterConfig,
15
+ type LauncherConfig,
16
+ type DoorConfig,
17
+ type DoorClipboardConfig,
18
+ type SpawnPointConfig,
19
+ } from "../../index.js";
20
+
1
21
  export interface NavigationUnitConfig {
2
22
  destination: number;
3
23
  page?: number;
@@ -38,6 +58,11 @@ export const LoaderPriority: {
38
58
  export type LoaderPriority = typeof LoaderPriority[keyof typeof LoaderPriority];
39
59
  export type ClipboardTarget =
40
60
  number
61
+ | "launcher"
62
+ | "door"
63
+ | "spawn"
64
+ | "spawn-point"
65
+ | "spawnPoint"
41
66
  | "loader"
42
67
  | "loader-config"
43
68
  | "loaderConfig"
@@ -1,4 +1,5 @@
1
1
  import {encoder} from "../../constants.js";
2
+ export * from "./machine-config.js";
2
3
 
3
4
  const NAV_UNIT_COMMAND = "config_nav_unit";
4
5
  const GENERATOR_MAZE_PUZZLE_COMMAND = "maze_puzzle";
@@ -117,6 +118,11 @@ function requireLoaderFilterMode(value, name) {
117
118
  }
118
119
 
119
120
  const CLIPBOARD_TARGET_VALUES = new Map([
121
+ ["launcher", 8],
122
+ ["spawn", 9],
123
+ ["spawn-point", 9],
124
+ ["spawnPoint", 9],
125
+ ["door", 10],
120
126
  ["loader", 1],
121
127
  ["loader-config", 1],
122
128
  ["loaderConfig", 1],
@@ -125,7 +125,7 @@ export const MODEL_TABLE_SPECS = new Map([
125
125
  [4, {name: "motion_aux", packedBits: [{bit: 8, offset: 33}], fields: numericFields({1: 20, 2: 24, 4: 28})}],
126
126
  [5, {
127
127
  name: "entity_health",
128
- // The official table starts both bar dimensions at 10 (one world unit).
128
+ // Bar half-width and vertical offset start at 10 (one world unit).
129
129
  // Field values on the wire are deltas relative to these defaults.
130
130
  defaults: {q28: 10, q32: 10},
131
131
  fields: numericFields({1: 20, 2: 24, 4: 28, 8: 32})
@@ -352,7 +352,11 @@ export const MODEL_TABLE_SPECS = new Map([
352
352
  record.q44 = (record.q44 || 0) + reader.readFieldDelta();
353
353
  }
354
354
  }
355
- }]
355
+ }],
356
+ // Append new wire components without shifting stable Dredless table IDs.
357
+ [79, {name: "launcher_config", defaults: {q20: 0, q24: 300}, fields: numericFields({1: 20, 2: 24})}],
358
+ [80, {name: "rank_filter", defaults: {q20: 4}, fields: numericFields({1: 20})}],
359
+ [81, {name: "spawn_point", fields: []}]
356
360
  ]);
357
361
 
358
362
  // Precompute everything about a spec that is fixed at module load. Decoding a
@@ -455,7 +459,10 @@ export const WIRE_TAG_TABLES = new Map([
455
459
  [166, 75],
456
460
  [167, 76],
457
461
  [168, 78],
458
- [169, 77]
462
+ [169, 77],
463
+ [170, 79],
464
+ [171, 80],
465
+ [172, 81]
459
466
  ]);
460
467
 
461
468
  export const MASK_ONLY_TABLES = new Set([13, 22, 23, 27, 28, 30, 36, 40, 46, 48, 52, 58, 64, 65, 66, 68, 73, 74]);
@@ -823,6 +830,8 @@ export function summarizeHealth(entity, record) {
823
830
  hp,
824
831
  maxHp,
825
832
  ratio: typeof hp === "number" && typeof maxHp === "number" && maxHp !== 0 ? hp / maxHp : null,
833
+ barWidth: (record.q28 ?? 10) / 5,
834
+ barOffsetY: (record.q32 ?? 10) / 10,
826
835
  state: cloneRecord(record)
827
836
  };
828
837
  }
@@ -1208,6 +1217,7 @@ export function summarizeItemCrate(entity, sizeRecord, itemRecord = null, health
1208
1217
  return {
1209
1218
  entity,
1210
1219
  ...itemSummary(itemId, count),
1220
+ boxSprite: Boolean(itemRecord?.q29),
1211
1221
  width: sizeRecord.q20 ?? null,
1212
1222
  height: sizeRecord.q24 ?? null,
1213
1223
  itemState: cloneRecord(itemRecord || healthRecord || {}),
@@ -1388,15 +1398,19 @@ export function normalizeDegrees(value) {
1388
1398
  return ((Number(value) % 360) + 360) % 360;
1389
1399
  }
1390
1400
 
1391
- export function summarizeItemLauncher(entity, typeId, launcherRecord) {
1392
- if (typeId !== ITEM_LAUNCHER_TYPE_ID || !launcherRecord) return null;
1393
- const angleRadians = numberOrNull(launcherRecord.q32 ?? 0, 200);
1401
+ export function summarizeItemLauncher(entity, typeId, launcherRecord, configRecord = null) {
1402
+ if (typeId !== ITEM_LAUNCHER_TYPE_ID || (!launcherRecord && !configRecord)) return null;
1403
+ const angleRadians = configRecord
1404
+ ? (configRecord.q20 ?? 0) / 10 * Math.PI / 180
1405
+ : numberOrNull(launcherRecord.q32 ?? 0, 200);
1394
1406
  return {
1395
1407
  entity,
1396
- angleRaw: launcherRecord.q32 ?? null,
1408
+ angleRaw: configRecord ? configRecord.q20 ?? 0 : launcherRecord.q32 ?? null,
1397
1409
  angleRadians,
1398
1410
  angleDegrees: angleRadians == null ? null : normalizeDegrees((angleRadians * 180) / Math.PI),
1399
- state: cloneRecord(launcherRecord)
1411
+ power: configRecord ? (configRecord.q24 ?? 300) / 10 : null,
1412
+ configState: configRecord ? cloneRecord(configRecord) : null,
1413
+ state: cloneRecord(launcherRecord || {})
1400
1414
  };
1401
1415
  }
1402
1416
 
@@ -1420,24 +1434,31 @@ export function summarizeShieldProjector(entity, projectorRecord) {
1420
1434
  };
1421
1435
  }
1422
1436
 
1423
- export function summarizeSpawnPoint(entity, spawnRecord) {
1424
- const rank = Number.isFinite(Number(spawnRecord?.q20)) ? Number(spawnRecord.q20) : 0;
1437
+ function summarizeRankFilter(legacyRecord, filterRecord, modern = false) {
1438
+ const legacyRank = Number.isFinite(Number(legacyRecord?.q20)) ? Number(legacyRecord.q20) : 0;
1439
+ const rankMask = filterRecord ? (filterRecord.q20 ?? 4) >>> 0
1440
+ : modern ? null : ({0: 7, 1: 6, 3: 4}[legacyRank] ?? 0);
1441
+ return {
1442
+ rankMask,
1443
+ allowedRanks: rankMask == null ? null : ["guest", "crew", "captain"].filter((_, i) => rankMask & (1 << i)),
1444
+ allRanks: rankMask === 0xffffffff,
1445
+ rankState: cloneRecord(filterRecord || legacyRecord || {})
1446
+ };
1447
+ }
1448
+
1449
+ export function summarizeSpawnPoint(entity, spawnRecord, filterRecord = null, markerRecord = null) {
1425
1450
  return {
1426
1451
  entity,
1427
- rank,
1428
- rankName: enumValueName(TEAM_RANK_NAMES, rank),
1429
- state: cloneRecord(spawnRecord || {})
1452
+ ...summarizeRankFilter(spawnRecord, filterRecord, markerRecord != null),
1453
+ state: cloneRecord(markerRecord || spawnRecord || {})
1430
1454
  };
1431
1455
  }
1432
1456
 
1433
- export function summarizeDoor(entity, rankRecord, doorRecord) {
1434
- const rank = Number.isFinite(Number(rankRecord?.q20)) ? Number(rankRecord.q20) : 0;
1457
+ export function summarizeDoor(entity, rankRecord, doorRecord, filterRecord = null) {
1435
1458
  return {
1436
1459
  entity,
1437
- rank,
1438
- rankName: enumValueName(TEAM_RANK_NAMES, rank),
1460
+ ...summarizeRankFilter(rankRecord, filterRecord),
1439
1461
  open: doorRecord?.q21 === 1,
1440
- rankState: cloneRecord(rankRecord || {}),
1441
1462
  state: cloneRecord(doorRecord || {})
1442
1463
  };
1443
1464
  }
@@ -16,14 +16,18 @@ export class ModelReader {
16
16
  }
17
17
 
18
18
  readUnsigned() {
19
- let result = 0;
20
- let shift = 0;
19
+ const first = this.readByte();
20
+ if (first < 0x80) return first;
21
+ let result = first & 0x7f;
22
+ let multiplier = 128;
23
+ let shift = 7;
21
24
  while (true) {
22
25
  const byte = this.readByte();
23
- result += (byte & 0x7f) * (2 ** shift);
26
+ result += (byte & 0x7f) * multiplier;
24
27
  if ((byte & 0x80) === 0) return result;
25
28
  shift += 7;
26
29
  if (shift > 70) throw new Error("model_data varint too large");
30
+ multiplier *= 128;
27
31
  }
28
32
  }
29
33
 
@@ -891,7 +891,7 @@ export class ModelState {
891
891
  const thruster = summarizeThruster(entityId, typeId, thrusterRecord);
892
892
  const pusher = summarizePusher(entityId, pusherRecord, loaderFilterSlotsRecord);
893
893
  const pusherBeam = summarizePusherBeam(entityId, pusherBeamRecord);
894
- const launcher = summarizeItemLauncher(entityId, typeId, launcherRecord);
894
+ const launcher = summarizeItemLauncher(entityId, typeId, launcherRecord, rec(79));
895
895
  const loader = (typeId === LOADER_TYPE_ID || (typeId == null && (loaderRecord || loaderFilterRecord || loaderFilterSlotsRecord)))
896
896
  ? summarizeLoader(entityId, loaderRecord, loaderFilterRecord, loaderFilterSlotsRecord, typeId === LOADER_TYPE_ID, itemHolderRecord)
897
897
  : null;
@@ -910,8 +910,9 @@ export class ModelState {
910
910
  const helm = summarizeHelm(entityId, typeId, this.#helmOccupied.get(entityId));
911
911
  const commsStation = summarizeCommsStation(entityId, typeId, commsStationRecord, this.#commsStationOccupied.get(entityId));
912
912
  const sign = typeId === 218 ? summarizeSign(entityId, signRecord) : null;
913
- const spawnPoint = typeId === 219 ? summarizeSpawnPoint(entityId, spawnPointRecord) : null;
914
- const door = typeId === 220 ? summarizeDoor(entityId, spawnPointRecord, doorRecord) : null;
913
+ const spawnPoint = typeId === 219 || rec(81)
914
+ ? summarizeSpawnPoint(entityId, spawnPointRecord, rec(80), rec(81)) : null;
915
+ const door = typeId === 220 ? summarizeDoor(entityId, spawnPointRecord, doorRecord, rec(80)) : null;
915
916
  const shipSize = shipControl && this.isOverworld ? summarizeShipSize(entityId, rec(3)) : null;
916
917
  const hoverOutline = summarizeHoverOutline(entityId, crateSizeRecord);
917
918
  const expandoBox = isExpandoBox ? summarizeExpandoBox(entityId, itemHolderRecord, expandoSizeRecord) : null;
@@ -1154,6 +1155,8 @@ export class ModelState {
1154
1155
 
1155
1156
  #readSectionRecords(reader, tag, tableId, spec) {
1156
1157
  const section = {tag, table: tableId, name: spec?.name || null, records: []};
1158
+ // Resolve the table once per section rather than twice per record.
1159
+ let records = this.tables.get(tableId);
1157
1160
  let entity = 0;
1158
1161
  while (reader.remaining > 0) {
1159
1162
  const recordOffset = reader.offset;
@@ -1171,7 +1174,9 @@ export class ModelState {
1171
1174
  } catch (error) {
1172
1175
  throw new Error(`model table ${tableId} tag ${tag} entity ${entity} mask offset ${reader.offset}: ${error.message}`);
1173
1176
  }
1174
- const record = this.#getRecord(tableId, entity);
1177
+ if (!records) this.tables.set(tableId, records = new Map());
1178
+ let record = records.get(entity);
1179
+ if (!record) records.set(entity, record = {...spec?.defaults});
1175
1180
  record.lastMask = mask;
1176
1181
 
1177
1182
  try {
@@ -1187,13 +1192,6 @@ export class ModelState {
1187
1192
  return section;
1188
1193
  }
1189
1194
 
1190
- #getRecord(tableId, entity) {
1191
- if (!this.tables.has(tableId)) this.tables.set(tableId, new Map());
1192
- const records = this.tables.get(tableId);
1193
- if (!records.has(entity)) records.set(entity, {...MODEL_TABLE_SPECS.get(tableId)?.defaults});
1194
- return records.get(entity);
1195
- }
1196
-
1197
1195
  #applyRecordSpec(reader, record, mask, spec) {
1198
1196
  if (typeof spec.read === "function") {
1199
1197
  spec.read(reader, record, mask);