dredless 0.2.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/LICENSE +21 -0
- package/README.md +48 -0
- package/docs/API_REFERENCE.md +2481 -0
- package/docs/BROWSER_API.md +98 -0
- package/docs/NODE_API.md +359 -0
- package/package.json +173 -0
- package/src/browser.d.ts +212 -0
- package/src/browser.js +133 -0
- package/src/client/core.js +1202 -0
- package/src/client/domains/index.js +1818 -0
- package/src/client/index.d.ts +2 -0
- package/src/client/index.js +1 -0
- package/src/compression/lz4.d.ts +1 -0
- package/src/compression/lz4.js +112 -0
- package/src/constants.js +74 -0
- package/src/crypto/chacha-native.d.ts +9 -0
- package/src/crypto/chacha-native.js +48 -0
- package/src/crypto/chacha.d.ts +25 -0
- package/src/crypto/chacha.js +274 -0
- package/src/data/item-schema.js +2235 -0
- package/src/data/official-client-data.js +156 -0
- package/src/events.js +39 -0
- package/src/index.d.ts +2277 -0
- package/src/index.js +125 -0
- package/src/network/browser-session.js +291 -0
- package/src/network/connection.d.ts +1 -0
- package/src/network/connection.js +31 -0
- package/src/network/cookies.js +85 -0
- package/src/network/http.js +34 -0
- package/src/network/index.d.ts +4 -0
- package/src/network/index.js +4 -0
- package/src/network/servers.d.ts +7 -0
- package/src/network/servers.js +133 -0
- package/src/network/session.d.ts +7 -0
- package/src/network/session.js +320 -0
- package/src/network/ships.d.ts +12 -0
- package/src/network/ships.js +73 -0
- package/src/node.d.ts +2 -0
- package/src/node.js +8 -0
- package/src/protocol/codec/binary.d.ts +3 -0
- package/src/protocol/codec/binary.js +52 -0
- package/src/protocol/codec/msgpack.d.ts +3 -0
- package/src/protocol/codec/msgpack.js +555 -0
- package/src/protocol/inbound/frame.d.ts +1 -0
- package/src/protocol/inbound/frame.js +8 -0
- package/src/protocol/inbound/world-payload.d.ts +3 -0
- package/src/protocol/inbound/world-payload.js +21 -0
- package/src/protocol/index.d.ts +11 -0
- package/src/protocol/index.js +19 -0
- package/src/protocol/outbound/blueprint.d.ts +22 -0
- package/src/protocol/outbound/blueprint.js +36 -0
- package/src/protocol/outbound/commands.d.ts +3 -0
- package/src/protocol/outbound/commands.js +149 -0
- package/src/protocol/outbound/comms.d.ts +28 -0
- package/src/protocol/outbound/comms.js +40 -0
- package/src/protocol/outbound/inventory.d.ts +64 -0
- package/src/protocol/outbound/inventory.js +147 -0
- package/src/protocol/outbound/ship-management.d.ts +84 -0
- package/src/protocol/outbound/ship-management.js +221 -0
- package/src/protocol/outbound/sign.d.ts +18 -0
- package/src/protocol/outbound/sign.js +45 -0
- package/src/protocol/outbound/ui-config.d.ts +157 -0
- package/src/protocol/outbound/ui-config.js +578 -0
- package/src/runtime.js +36 -0
- package/src/state/generator-maze.d.ts +32 -0
- package/src/state/generator-maze.js +370 -0
- package/src/state/index.d.ts +3 -0
- package/src/state/index.js +3 -0
- package/src/state/items.js +20 -0
- package/src/state/model/decoder.js +1554 -0
- package/src/state/model/index.d.ts +33 -0
- package/src/state/model/index.js +2 -0
- package/src/state/model/loader-config.js +1020 -0
- package/src/state/model/reader.js +69 -0
- package/src/state/model/state.js +1257 -0
- package/src/state/overworld.js +72 -0
- package/src/state/tilesets.js +53 -0
- package/src/state/world/index.d.ts +29 -0
- package/src/state/world/index.js +180 -0
- package/src/state/world/state.js +297 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {toUint8Array} from "../../protocol/codec/binary.js";
|
|
2
|
+
|
|
3
|
+
export class ModelReader {
|
|
4
|
+
constructor(bytes) {
|
|
5
|
+
this.bytes = toUint8Array(bytes);
|
|
6
|
+
this.offset = 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get remaining() {
|
|
10
|
+
return this.bytes.length - this.offset;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
readByte() {
|
|
14
|
+
if (this.offset >= this.bytes.length) throw new Error("model_data read past end");
|
|
15
|
+
return this.bytes[this.offset++];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
readUnsigned() {
|
|
19
|
+
let result = 0;
|
|
20
|
+
let shift = 0;
|
|
21
|
+
while (true) {
|
|
22
|
+
const byte = this.readByte();
|
|
23
|
+
result += (byte & 0x7f) * (2 ** shift);
|
|
24
|
+
if ((byte & 0x80) === 0) return result;
|
|
25
|
+
shift += 7;
|
|
26
|
+
if (shift > 70) throw new Error("model_data varint too large");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
readStreamInt() {
|
|
31
|
+
const raw = this.readUnsigned();
|
|
32
|
+
return (raw & 1) === 0 ? raw / 2 : -((raw + 1) / 2);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
readFieldDelta() {
|
|
36
|
+
const raw = this.readUnsigned();
|
|
37
|
+
return (raw & 1) === 0 ? raw / 2 : -(raw >> 1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
readBlob() {
|
|
41
|
+
const length = this.readStreamInt();
|
|
42
|
+
if (length < 0) throw new Error(`negative blob length ${length}`);
|
|
43
|
+
const end = this.offset + length;
|
|
44
|
+
if (end > this.bytes.length) throw new Error("model_data blob read past end");
|
|
45
|
+
const blob = this.bytes.slice(this.offset, end);
|
|
46
|
+
this.offset = end;
|
|
47
|
+
return blob;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Called once per section while scanning, so a fresh tail scan each time is
|
|
51
|
+
// O(bytes x sections). The index of the last non-zero byte is fixed for the
|
|
52
|
+
// packet, so compute it once and compare offsets thereafter.
|
|
53
|
+
trailingZeroOnly() {
|
|
54
|
+
if (this._lastNonZero === undefined) {
|
|
55
|
+
let last = -1;
|
|
56
|
+
for (let i = this.bytes.length - 1; i >= 0; i--) {
|
|
57
|
+
if (this.bytes[i] !== 0) {
|
|
58
|
+
last = i;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
this._lastNonZero = last;
|
|
63
|
+
}
|
|
64
|
+
return this.offset > this._lastNonZero;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// `key` is precomputed: it is fixed per field but was rebuilt as a template
|
|
69
|
+
|