dredless 1.2.2 → 1.3.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/dist/browser/dredless.global.js +414 -20
- package/dist/browser/dredless.global.js.map +4 -4
- package/docs/API_REFERENCE.md +1 -0
- package/docs/NODE_API.md +2 -0
- package/docs/PROTOCOL.md +27 -0
- package/docs/README.md +2 -1
- package/docs/WORLD_STATE.md +99 -0
- package/package.json +6 -1
- package/src/browser.d.ts +14 -0
- package/src/browser.js +1 -0
- package/src/client/core.js +2 -0
- package/src/client/domains/index.js +63 -0
- package/src/index.d.ts +92 -0
- package/src/index.js +1 -0
- package/src/network/bundle-metadata.js +191 -0
- package/src/network/servers.js +48 -23
- package/src/protocol/index.d.ts +1 -0
- package/src/protocol/index.js +1 -0
- package/src/protocol/outbound/pvp.d.ts +13 -0
- package/src/protocol/outbound/pvp.js +45 -0
- package/src/state/model/decoder.js +48 -0
- package/src/state/model/index.d.ts +4 -0
- package/src/state/model/state.js +27 -0
- package/src/state/world/index.d.ts +4 -0
- package/src/state/world/state.js +2 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// A deliberately limited reader, not a JavaScript evaluator. Only constant
|
|
2
|
+
// strings, booleans, and arrays of strings may back the requested exports.
|
|
3
|
+
const identifier = /^[A-Za-z_$][\w$]*$/;
|
|
4
|
+
const regexPrefix = new Set(['(', '[', '{', '=', ':', ',', ';', '!', '?', '&', '|', '=>', 'return', 'throw', 'case', 'typeof', 'void', 'delete']);
|
|
5
|
+
|
|
6
|
+
function quoted(source, start) {
|
|
7
|
+
const quote = source[start];
|
|
8
|
+
let value = '', valid = true, i = start + 1;
|
|
9
|
+
for (; i < source.length; i++) {
|
|
10
|
+
const c = source[i];
|
|
11
|
+
if (c === quote) return {value, valid, end: i + 1};
|
|
12
|
+
if (c !== '\\') { value += c; if (c === '\n' || c === '\r') valid = false; continue; }
|
|
13
|
+
const escape = source[++i];
|
|
14
|
+
const simple = {n: '\n', r: '\r', t: '\t', b: '\b', f: '\f', v: '\v', '0': '\0'};
|
|
15
|
+
if (escape === '\n') continue;
|
|
16
|
+
if (escape === '\r') { if (source[i + 1] === '\n') i++; continue; }
|
|
17
|
+
if (escape === 'x' || escape === 'u') {
|
|
18
|
+
const braced = escape === 'u' && source[i + 1] === '{';
|
|
19
|
+
const first = i + (braced ? 2 : 1);
|
|
20
|
+
const end = braced ? source.indexOf('}', first) : first + (escape === 'x' ? 2 : 4);
|
|
21
|
+
const digits = source.slice(first, end);
|
|
22
|
+
if (end < first) return {value, valid: false, end: source.length};
|
|
23
|
+
if (!/^[\da-f]+$/i.test(digits) || Number.parseInt(digits, 16) > 0x10ffff) valid = false;
|
|
24
|
+
else value += String.fromCodePoint(Number.parseInt(digits, 16));
|
|
25
|
+
i = braced ? end : end - 1;
|
|
26
|
+
} else if (escape === '0' && /\d/.test(source[i + 1] || '')) valid = false;
|
|
27
|
+
else if (escape in simple) value += simple[escape];
|
|
28
|
+
else if (escape && !/[1-9]/.test(escape)) value += escape;
|
|
29
|
+
else valid = false;
|
|
30
|
+
}
|
|
31
|
+
return {value, valid: false, end: i};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function skipRegex(source, start) {
|
|
35
|
+
let inClass = false, i = start + 1;
|
|
36
|
+
for (; i < source.length; i++) {
|
|
37
|
+
if (source[i] === '\\') { i++; continue; }
|
|
38
|
+
if (source[i] === '[') inClass = true;
|
|
39
|
+
if (source[i] === ']') inClass = false;
|
|
40
|
+
if (source[i] === '/' && !inClass) {
|
|
41
|
+
while (/[a-z]/i.test(source[i + 1] || '')) i++;
|
|
42
|
+
return i + 1;
|
|
43
|
+
}
|
|
44
|
+
if (source[i] === '\n') break;
|
|
45
|
+
}
|
|
46
|
+
return i;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function skipTemplate(source, start) {
|
|
50
|
+
let i = start + 1;
|
|
51
|
+
while (i < source.length) {
|
|
52
|
+
if (source[i] === '\\') { i += 2; continue; }
|
|
53
|
+
if (source[i] === '`') return i + 1;
|
|
54
|
+
if (source[i] === '$' && source[i + 1] === '{') {
|
|
55
|
+
const expression = lex(source, i + 2, true);
|
|
56
|
+
i = expression.end;
|
|
57
|
+
} else i++;
|
|
58
|
+
}
|
|
59
|
+
return i;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function lex(source, start = 0, interpolation = false) {
|
|
63
|
+
const tokens = [];
|
|
64
|
+
let i = start, depth = 0;
|
|
65
|
+
while (i < source.length) {
|
|
66
|
+
const c = source[i];
|
|
67
|
+
if (/\s/.test(c)) { i++; continue; }
|
|
68
|
+
if (source.startsWith('//', i)) { const end = source.indexOf('\n', i); i = end < 0 ? source.length : end; continue; }
|
|
69
|
+
if (source.startsWith('/*', i)) { const end = source.indexOf('*/', i + 2); i = end < 0 ? source.length : end + 2; continue; }
|
|
70
|
+
let token;
|
|
71
|
+
if (c === '"' || c === "'") {
|
|
72
|
+
const string = quoted(source, i);
|
|
73
|
+
token = {kind: 'string', value: string.value, valid: string.valid}; i = string.end;
|
|
74
|
+
} else if (c === '`') { i = skipTemplate(source, i); token = {kind: 'opaque', value: 'template'}; }
|
|
75
|
+
else if (c === '/' && (!tokens.length || regexPrefix.has(tokens.at(-1).value))) {
|
|
76
|
+
i = skipRegex(source, i); token = {kind: 'opaque', value: 'regex'};
|
|
77
|
+
} else if (/[A-Za-z_$]/.test(c)) {
|
|
78
|
+
const first = i++;
|
|
79
|
+
while (/[\w$]/.test(source[i] || '')) i++;
|
|
80
|
+
token = {kind: 'identifier', value: source.slice(first, i)};
|
|
81
|
+
} else {
|
|
82
|
+
token = {kind: 'punctuation', value: source.startsWith('=>', i) ? '=>' : c};
|
|
83
|
+
i += token.value.length;
|
|
84
|
+
}
|
|
85
|
+
if (interpolation && token.kind === 'punctuation' && token.value === '}' && depth === 0) return {tokens, end: i};
|
|
86
|
+
if (token.value === '{' && token.kind === 'punctuation') depth++;
|
|
87
|
+
if (token.value === '}' && token.kind === 'punctuation') depth--;
|
|
88
|
+
tokens.push(token);
|
|
89
|
+
}
|
|
90
|
+
return {tokens, end: i};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function literal(tokens, start) {
|
|
94
|
+
const token = tokens[start];
|
|
95
|
+
if (token?.kind === 'string' && token.valid) return {value: token.value, end: start + 1};
|
|
96
|
+
if (token?.kind === 'identifier' && ['true', 'false'].includes(token.value)) return {value: token.value === 'true', end: start + 1};
|
|
97
|
+
if (token?.kind !== 'punctuation' || token.value !== '[') return null;
|
|
98
|
+
const value = [];
|
|
99
|
+
let i = start + 1;
|
|
100
|
+
while (!(tokens[i]?.kind === 'punctuation' && tokens[i].value === ']')) {
|
|
101
|
+
if (tokens[i]?.kind !== 'string' || !tokens[i].valid) return null;
|
|
102
|
+
value.push(tokens[i++].value);
|
|
103
|
+
if (tokens[i]?.kind === 'punctuation' && tokens[i].value === ']') break;
|
|
104
|
+
if (tokens[i++]?.value !== ',') return null;
|
|
105
|
+
}
|
|
106
|
+
return tokens[i]?.value === ']' ? {value, end: i + 1} : null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function getter(tokens, start) {
|
|
110
|
+
let i = start;
|
|
111
|
+
if (tokens[i++]?.value !== '(' || tokens[i++]?.value !== ')' || tokens[i++]?.value !== '=>') return null;
|
|
112
|
+
if (tokens[i]?.kind === 'identifier' && identifier.test(tokens[i].value) && [',', '}'].includes(tokens[i + 1]?.value)) return tokens[i].value;
|
|
113
|
+
if (tokens[i++]?.value !== '{' || tokens[i++]?.value !== 'return') return null;
|
|
114
|
+
const name = tokens[i++];
|
|
115
|
+
if (tokens[i]?.value === ';') i++;
|
|
116
|
+
return name?.kind === 'identifier' && tokens[i]?.value === '}' ? name.value : null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function readBundleExports(text, names) {
|
|
120
|
+
const wanted = new Set(names), found = new Map();
|
|
121
|
+
// HTML and raw JS are both accepted. Never scan markup as JavaScript.
|
|
122
|
+
const scripts = /^\s*</.test(text) ? [...text.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script\s*>/gi)].map((match) => match[1]) : [];
|
|
123
|
+
for (const source of scripts.length ? scripts : [text]) {
|
|
124
|
+
const {tokens} = lex(source);
|
|
125
|
+
const root = new Map(), scopes = [root];
|
|
126
|
+
const brackets = [];
|
|
127
|
+
for (const [index, token] of tokens.entries()) {
|
|
128
|
+
token.scope = scopes.at(-1);
|
|
129
|
+
if (token.kind !== 'punctuation') continue;
|
|
130
|
+
if (['(', '[', '{'].includes(token.value)) brackets.push(index);
|
|
131
|
+
if ([')', ']', '}'].includes(token.value)) {
|
|
132
|
+
const opening = brackets.pop();
|
|
133
|
+
if (opening !== undefined) tokens[opening].close = index;
|
|
134
|
+
}
|
|
135
|
+
if (token.value === '{') { token.child = new Map(); scopes.push(token.child); }
|
|
136
|
+
if (token.value === '}' && scopes.length > 1) scopes.pop();
|
|
137
|
+
}
|
|
138
|
+
// Resolve after scanning declarations, so export/definition order is irrelevant.
|
|
139
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
140
|
+
if (tokens[i].kind !== 'identifier' || tokens[i].value !== 'const') continue;
|
|
141
|
+
const scope = tokens[i].scope;
|
|
142
|
+
let j = i + 1;
|
|
143
|
+
while (tokens[j]?.kind === 'identifier' && tokens[j + 1]?.value === '=') {
|
|
144
|
+
const name = tokens[j].value, result = literal(tokens, j + 2);
|
|
145
|
+
let end = j + 2;
|
|
146
|
+
while (end < tokens.length) {
|
|
147
|
+
const token = tokens[end];
|
|
148
|
+
if (token.scope === scope && token.kind === 'punctuation' && [';', ',', '}'].includes(token.value)) break;
|
|
149
|
+
end = token.close !== undefined ? token.close + 1 : end + 1;
|
|
150
|
+
}
|
|
151
|
+
const valid = result && result.end === end;
|
|
152
|
+
scope.set(name, scope.has(name) ? null : valid ? result.value : null);
|
|
153
|
+
if (tokens[end]?.value !== ',') break;
|
|
154
|
+
j = end + 1;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const record = (name, binding, scope) => {
|
|
158
|
+
if (!wanted.has(name)) return;
|
|
159
|
+
const value = binding ? scope.get(binding) : undefined;
|
|
160
|
+
if (value == null) throw new Error(`Unable to resolve bundle export ${name}: expected a constant literal in the same module`);
|
|
161
|
+
if (found.has(name) && JSON.stringify(found.get(name)) !== JSON.stringify(value)) throw new Error(`Ambiguous bundle export ${name}`);
|
|
162
|
+
found.set(name, value);
|
|
163
|
+
};
|
|
164
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
165
|
+
if (tokens[i].kind !== 'identifier') continue;
|
|
166
|
+
const method = tokens[i].value === 'Object' && tokens[i + 1]?.value === '.' ? tokens[i + 2]?.value : null;
|
|
167
|
+
// The game also uses a minified helper: helper(exports,{NAME:()=>x}).
|
|
168
|
+
const call = ['defineProperties', 'defineProperty'].includes(method) ? i + 3 : i + 1;
|
|
169
|
+
if (tokens[call]?.value !== '(' || tokens[call + 1]?.kind !== 'identifier' || tokens[call + 2]?.value !== ',') continue;
|
|
170
|
+
let j = call + 3;
|
|
171
|
+
if (method === 'defineProperty') {
|
|
172
|
+
const name = tokens[j++];
|
|
173
|
+
if (name?.kind !== 'string' || !wanted.has(name.value) || tokens[j++]?.value !== ',') continue;
|
|
174
|
+
const object = tokens[j++];
|
|
175
|
+
if (object?.value !== '{' || !object.child) continue;
|
|
176
|
+
for (; j < tokens.length && tokens[j].scope !== object.scope; j++) {
|
|
177
|
+
if (tokens[j].scope === object.child && tokens[j].value === 'get' && tokens[j + 1]?.value === ':') record(name.value, getter(tokens, j + 2), tokens[i].scope);
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
const object = tokens[j++];
|
|
181
|
+
if (object?.value !== '{' || !object.child) continue;
|
|
182
|
+
for (; j < tokens.length && tokens[j].scope !== object.scope; j++) {
|
|
183
|
+
const key = tokens[j];
|
|
184
|
+
if (key.scope === object.child && ['identifier', 'string'].includes(key.kind) && wanted.has(key.value) && tokens[j + 1]?.value === ':') record(key.value, getter(tokens, j + 2), tokens[i].scope);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
for (const name of wanted) if (!found.has(name)) throw new Error(`Missing bundle export ${name}`);
|
|
190
|
+
return Object.fromEntries(found);
|
|
191
|
+
}
|
package/src/network/servers.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {DEFAULT_BASE_URL} from "../constants.js";
|
|
2
2
|
import {getWebSocket, hostName, normalizeBaseUrl} from "../runtime.js";
|
|
3
3
|
import {HttpClient} from "./http.js";
|
|
4
|
+
import {readBundleExports} from "./bundle-metadata.js";
|
|
4
5
|
|
|
5
6
|
const cache = new Map();
|
|
6
7
|
|
|
@@ -11,20 +12,26 @@ class ServerDirectory {
|
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
async load() {
|
|
14
|
-
if (cache.has(this.baseUrl))
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
if (!cache.has(this.baseUrl)) cache.set(this.baseUrl, this.#fetchMeta());
|
|
16
|
+
const pending = cache.get(this.baseUrl);
|
|
17
|
+
try {
|
|
18
|
+
this.meta = await pending;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (cache.get(this.baseUrl) === pending) cache.delete(this.baseUrl);
|
|
21
|
+
throw error;
|
|
17
22
|
}
|
|
18
|
-
const promise = this.#fetchMeta();
|
|
19
|
-
cache.set(this.baseUrl, promise);
|
|
20
|
-
this.meta = await promise;
|
|
21
23
|
return this;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
async version() {
|
|
25
27
|
await this.load();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
try {
|
|
29
|
+
this.meta.version ??= parseGameVersion(this.meta.text);
|
|
30
|
+
return this.meta.version;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
cache.delete(this.baseUrl);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
async list() {
|
|
@@ -33,8 +40,13 @@ class ServerDirectory {
|
|
|
33
40
|
|
|
34
41
|
async servers() {
|
|
35
42
|
await this.load();
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
try {
|
|
44
|
+
this.meta.serverInfo ??= parseServerInfo(this.meta.text, this.baseUrl);
|
|
45
|
+
return this.meta.serverInfo.servers;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
cache.delete(this.baseUrl);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
38
50
|
}
|
|
39
51
|
|
|
40
52
|
async get(id = null) {
|
|
@@ -50,7 +62,7 @@ class ServerDirectory {
|
|
|
50
62
|
const response = await new HttpClient({baseUrl: this.baseUrl}).request("index.html");
|
|
51
63
|
if (!response.ok) throw new Error(`Failed to fetch bundle: ${response.status} ${response.statusText}`);
|
|
52
64
|
const text = await response.text();
|
|
53
|
-
return {text
|
|
65
|
+
return {text};
|
|
54
66
|
}
|
|
55
67
|
}
|
|
56
68
|
|
|
@@ -132,7 +144,9 @@ export function serverId(server) {
|
|
|
132
144
|
}
|
|
133
145
|
|
|
134
146
|
function parseGameVersion(text) {
|
|
135
|
-
|
|
147
|
+
const {GAME_VERSION} = readBundleExports(text, ["GAME_VERSION"]);
|
|
148
|
+
if (typeof GAME_VERSION !== "string" || !GAME_VERSION.trim()) throw new Error("Invalid bundle export GAME_VERSION: expected a nonempty string");
|
|
149
|
+
return GAME_VERSION;
|
|
136
150
|
}
|
|
137
151
|
|
|
138
152
|
function parseNoticeVersion(text) {
|
|
@@ -159,18 +173,29 @@ function parseNoticeVersion(text) {
|
|
|
159
173
|
|
|
160
174
|
function parseServerInfo(text, baseUrl) {
|
|
161
175
|
const host = hostName(baseUrl);
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
176
|
+
const config = readBundleExports(text, ["LOCAL_DOMAIN", "BASE_DOMAIN", "TEST_DOMAIN", "TEST_GAME_DOMAIN",
|
|
177
|
+
"GAME_DOMAINS", "GAME_SERVER_NAMES", "MASTER_DOMAIN", "TEST_MASTER_DOMAIN"]);
|
|
178
|
+
const domain = (value, name) => {
|
|
179
|
+
if (typeof value !== "string" || value.length > 253 || !/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i.test(value)) {
|
|
180
|
+
throw new Error(`Invalid bundle export ${name}: expected a hostname`);
|
|
181
|
+
}
|
|
182
|
+
return value;
|
|
183
|
+
};
|
|
184
|
+
const localDomain = domain(config.LOCAL_DOMAIN, "LOCAL_DOMAIN");
|
|
185
|
+
const baseDomain = domain(config.BASE_DOMAIN, "BASE_DOMAIN");
|
|
186
|
+
const testDomain = domain(config.TEST_DOMAIN, "TEST_DOMAIN");
|
|
187
|
+
const testGameDomain = domain(config.TEST_GAME_DOMAIN, "TEST_GAME_DOMAIN");
|
|
188
|
+
const domains = config.GAME_DOMAINS;
|
|
189
|
+
const names = config.GAME_SERVER_NAMES;
|
|
190
|
+
if (!Array.isArray(domains) || !domains.length) throw new Error("Invalid bundle export GAME_DOMAINS: expected nonempty hostname array");
|
|
191
|
+
domains.forEach((value) => domain(value, "GAME_DOMAINS"));
|
|
192
|
+
if (!Array.isArray(names) || names.length !== domains.length || names.some((name) => typeof name !== "string")) {
|
|
193
|
+
throw new Error("Invalid bundle export GAME_SERVER_NAMES: expected one string per game domain");
|
|
194
|
+
}
|
|
167
195
|
const meta = {
|
|
168
|
-
localDomain,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
testGameDomain,
|
|
172
|
-
masterDomain: match[8],
|
|
173
|
-
testMasterDomain: match[9]
|
|
196
|
+
localDomain, baseDomain, testDomain, testGameDomain,
|
|
197
|
+
masterDomain: domain(config.MASTER_DOMAIN, "MASTER_DOMAIN"),
|
|
198
|
+
testMasterDomain: domain(config.TEST_MASTER_DOMAIN, "TEST_MASTER_DOMAIN")
|
|
174
199
|
};
|
|
175
200
|
if (host === localDomain) return {mode: "local", servers: [server(0, localDomain, "Local Test 1")], meta};
|
|
176
201
|
if (host === testDomain) return {mode: "test", servers: [server(0, testGameDomain, "Public Test")], meta};
|
package/src/protocol/index.d.ts
CHANGED
|
@@ -8,5 +8,6 @@ export * from "./outbound/comms.js";
|
|
|
8
8
|
export * from "./outbound/commands.js";
|
|
9
9
|
export * from "./outbound/inventory.js";
|
|
10
10
|
export * from "./outbound/ship-management.js";
|
|
11
|
+
export * from "./outbound/pvp.js";
|
|
11
12
|
export * from "./outbound/sign.js";
|
|
12
13
|
export * from "./outbound/ui-config.js";
|
package/src/protocol/index.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export {
|
|
2
|
+
buildPvpPartyMessage,
|
|
3
|
+
buildCreatePvpPartyMessage,
|
|
4
|
+
buildLeavePvpPartyMessage,
|
|
5
|
+
buildJoinPvpPartyMessage,
|
|
6
|
+
buildInvitePvpPartyMessage,
|
|
7
|
+
buildKickPvpPartyMessage,
|
|
8
|
+
buildCancelPvpPartyJoinMessage,
|
|
9
|
+
buildCancelPvpPartyInviteMessage,
|
|
10
|
+
type PvpPartyCommandKind,
|
|
11
|
+
type PvpPartyMessage,
|
|
12
|
+
type PvpPartyInfo
|
|
13
|
+
} from "../../index.js";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const TARGETED_KINDS = new Set(["Join", "Invite", "Kick", "JoinCancel", "InviteCancel"]);
|
|
2
|
+
|
|
3
|
+
function requireHexCode(value) {
|
|
4
|
+
if (typeof value !== "string") throw new TypeError("hexCode must be a ship hex code string");
|
|
5
|
+
const hexCode = value.trim();
|
|
6
|
+
if (!/^[0-9a-f]+$/i.test(hexCode)) throw new RangeError("hexCode must contain hexadecimal digits");
|
|
7
|
+
return hexCode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function buildPvpPartyMessage(kind, hexCode) {
|
|
11
|
+
if (kind === "NewTeam" || kind === "Leave") {
|
|
12
|
+
if (hexCode !== undefined) throw new TypeError(`${kind} does not take a ship hex code`);
|
|
13
|
+
return {type: 10, info: {kind}};
|
|
14
|
+
}
|
|
15
|
+
if (!TARGETED_KINDS.has(kind)) throw new RangeError("unsupported PvP party command kind");
|
|
16
|
+
return {type: 10, info: {kind, hex: requireHexCode(hexCode)}};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function buildCreatePvpPartyMessage() {
|
|
20
|
+
return buildPvpPartyMessage("NewTeam");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function buildLeavePvpPartyMessage() {
|
|
24
|
+
return buildPvpPartyMessage("Leave");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function buildJoinPvpPartyMessage(hexCode) {
|
|
28
|
+
return buildPvpPartyMessage("Join", hexCode);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function buildInvitePvpPartyMessage(hexCode) {
|
|
32
|
+
return buildPvpPartyMessage("Invite", hexCode);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function buildKickPvpPartyMessage(hexCode) {
|
|
36
|
+
return buildPvpPartyMessage("Kick", hexCode);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function buildCancelPvpPartyJoinMessage(hexCode) {
|
|
40
|
+
return buildPvpPartyMessage("JoinCancel", hexCode);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function buildCancelPvpPartyInviteMessage(hexCode) {
|
|
44
|
+
return buildPvpPartyMessage("InviteCancel", hexCode);
|
|
45
|
+
}
|
|
@@ -240,6 +240,19 @@ export const MODEL_TABLE_SPECS = new Map([
|
|
|
240
240
|
defaults: {q28: 10},
|
|
241
241
|
fields: numericFields({1: 20, 2: 24, 4: 28})
|
|
242
242
|
}],
|
|
243
|
+
[33, {
|
|
244
|
+
name: "pvp_event",
|
|
245
|
+
fields: numericFields({2: 20, 4: 24, 8: 28, 16: 32, 32: 36, 64: 40, 128: 44, 256: 48, 512: 52})
|
|
246
|
+
}],
|
|
247
|
+
[34, {name: "pvp_party_config", fields: numericFields({2: 20})}],
|
|
248
|
+
[35, {
|
|
249
|
+
name: "pvp_party_entry",
|
|
250
|
+
packedBeforeValues: true,
|
|
251
|
+
orderedValues: true,
|
|
252
|
+
packedBits: [{bit: 4, offset: 37}],
|
|
253
|
+
blobs: [{bit: 1, offset: 24}],
|
|
254
|
+
fields: numericFields({2: 20})
|
|
255
|
+
}],
|
|
243
256
|
[37, {name: "loose_item_marker", packedBits: [{bit: 2, offset: 29}], fields: numericFields({1: 20, 4: 24})}],
|
|
244
257
|
[38, {name: "flag_state", packedBits: [{bit: 1, offset: 21}], fields: []}],
|
|
245
258
|
[39, {name: "comms_transmit", ...TWO_FIELD_SPEC}],
|
|
@@ -395,6 +408,9 @@ export const WIRE_TAG_TABLES = new Map([
|
|
|
395
408
|
[93, 30],
|
|
396
409
|
[94, 31],
|
|
397
410
|
[95, 32],
|
|
411
|
+
[96, 33],
|
|
412
|
+
[97, 34],
|
|
413
|
+
[98, 35],
|
|
398
414
|
[99, 36],
|
|
399
415
|
[120, 37],
|
|
400
416
|
[121, 38],
|
|
@@ -1118,6 +1134,38 @@ export function summarizeShipControl(entity, record) {
|
|
|
1118
1134
|
};
|
|
1119
1135
|
}
|
|
1120
1136
|
|
|
1137
|
+
export function summarizePvpEvent(entity, record, shipsLeft) {
|
|
1138
|
+
if (!record) return null;
|
|
1139
|
+
const damageBonusPercent = record.q52 ?? 0;
|
|
1140
|
+
return {
|
|
1141
|
+
entity,
|
|
1142
|
+
active: (record.q44 ?? 0) >= 0,
|
|
1143
|
+
bounds: {
|
|
1144
|
+
minX: (record.q20 ?? 0) / 10,
|
|
1145
|
+
minY: (record.q24 ?? 0) / 10,
|
|
1146
|
+
maxX: (record.q28 ?? 0) / 10,
|
|
1147
|
+
maxY: (record.q32 ?? 0) / 10
|
|
1148
|
+
},
|
|
1149
|
+
worldBounds: {minX: 0, minY: 0, maxX: record.q36 ?? 0, maxY: record.q40 ?? 0},
|
|
1150
|
+
timeSeconds: record.q44 ?? 0,
|
|
1151
|
+
damageBonusPercent,
|
|
1152
|
+
damagePercent: damageBonusPercent + 100,
|
|
1153
|
+
damageMultiplier: (damageBonusPercent + 100) / 100,
|
|
1154
|
+
shipsLeft,
|
|
1155
|
+
state: cloneRecord(record)
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
export function summarizePvpPartyEntry(entity, record) {
|
|
1160
|
+
return {
|
|
1161
|
+
entity,
|
|
1162
|
+
partyId: record.q20 ?? 0,
|
|
1163
|
+
hexCode: decodeText(record.blob24),
|
|
1164
|
+
kind: record.q37 ? "join-request" : "invitation",
|
|
1165
|
+
state: cloneRecord(record)
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1121
1169
|
export function summarizeShipSize(entity, record) {
|
|
1122
1170
|
if (!record) return null;
|
|
1123
1171
|
return {
|
package/src/state/model/state.js
CHANGED
|
@@ -83,6 +83,8 @@ const {
|
|
|
83
83
|
botIdentifierFromState,
|
|
84
84
|
summarizeShieldGenerator,
|
|
85
85
|
summarizeShipControl,
|
|
86
|
+
summarizePvpEvent,
|
|
87
|
+
summarizePvpPartyEntry,
|
|
86
88
|
summarizeShipSize,
|
|
87
89
|
summarizeShipWorldMetadata,
|
|
88
90
|
summarizeItemCrate,
|
|
@@ -278,6 +280,8 @@ export class ModelState {
|
|
|
278
280
|
balls: derived.specialEntities.balls.slice(),
|
|
279
281
|
recyclers: derived.specialEntities.recyclers.slice(),
|
|
280
282
|
shipControls: derived.shipControls.slice(),
|
|
283
|
+
pvpEvent: this.pvpEvent(),
|
|
284
|
+
pvpParties: this.pvpParties(),
|
|
281
285
|
machines: this.#machinesSnapshot(derived.machines),
|
|
282
286
|
tables: includeTables ? this.tablesSnapshot() : derived.tableSummaries.slice()
|
|
283
287
|
};
|
|
@@ -331,6 +335,29 @@ export class ModelState {
|
|
|
331
335
|
return this.#derivedState().shipControls.slice();
|
|
332
336
|
}
|
|
333
337
|
|
|
338
|
+
pvpEvent() {
|
|
339
|
+
const entry = this.table(33).entries().next().value;
|
|
340
|
+
if (!entry) return null;
|
|
341
|
+
let shipsLeft = 0;
|
|
342
|
+
// The HUD excludes ships whose replicated exclusion flag is set.
|
|
343
|
+
for (const ship of this.table(20).values()) {
|
|
344
|
+
if (!ship.q153) shipsLeft += 1;
|
|
345
|
+
}
|
|
346
|
+
return summarizePvpEvent(entry[0], entry[1], shipsLeft);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
pvpParties() {
|
|
350
|
+
const config = this.table(34).entries().next().value;
|
|
351
|
+
const entries = this.table(35);
|
|
352
|
+
if (!config && entries.size === 0) return null;
|
|
353
|
+
return {
|
|
354
|
+
configEntity: config?.[0] ?? null,
|
|
355
|
+
maxShips: config ? config[1].q20 ?? 0 : 35,
|
|
356
|
+
entries: [...entries].map(([entity, record]) => summarizePvpPartyEntry(entity, record)),
|
|
357
|
+
configState: config ? cloneRecord(config[1]) : null
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
|
|
334
361
|
shipMetadata() {
|
|
335
362
|
if (this.isOverworld) return null;
|
|
336
363
|
const lockdownRecord = firstRecord(this.table(11));
|
package/src/state/world/state.js
CHANGED
|
@@ -266,6 +266,8 @@ export class WorldState {
|
|
|
266
266
|
balls: model.balls,
|
|
267
267
|
recyclers: model.recyclers,
|
|
268
268
|
shipControls: model.shipControls,
|
|
269
|
+
pvpEvent: model.pvpEvent,
|
|
270
|
+
pvpParties: model.pvpParties,
|
|
269
271
|
commsBubbles: this.commsBubbles.slice(),
|
|
270
272
|
tiles: includeTiles ? [...this.tiles.values()] : undefined
|
|
271
273
|
};
|