yolkbot 1.4.8 → 1.5.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/README.md +1 -1
- package/browser/build/global.js +1 -1
- package/browser/build/module.js +1 -1
- package/dist/api.d.ts +34 -16
- package/dist/api.js +164 -121
- package/dist/bot/GamePlayer.d.ts +2 -2
- package/dist/bot/GamePlayer.js +15 -5
- package/dist/bot.d.ts +121 -83
- package/dist/bot.js +624 -1077
- package/dist/comm/CommIn.js +14 -17
- package/dist/comm/CommOut.js +15 -15
- package/dist/constants/CommCode.js +1 -1
- package/dist/constants/findItemById.js +2 -1
- package/dist/constants/guns.d.ts +16 -41
- package/dist/constants/guns.js +137 -259
- package/dist/constants/index.d.ts +7 -9
- package/dist/constants/index.js +15 -13
- package/dist/dispatches/BanPlayerDispatch.d.ts +3 -1
- package/dist/dispatches/BootPlayerDispatch.d.ts +3 -1
- package/dist/dispatches/ChatDispatch.d.ts +3 -1
- package/dist/dispatches/ChatDispatch.js +3 -3
- package/dist/dispatches/FireDispatch.d.ts +3 -1
- package/dist/dispatches/GameOptionsDispatch.d.ts +3 -1
- package/dist/dispatches/GoToAmmoDispatch.d.ts +2 -0
- package/dist/dispatches/GoToAmmoDispatch.js +15 -16
- package/dist/dispatches/GoToCoopDispatch.d.ts +2 -0
- package/dist/dispatches/GoToCoopDispatch.js +19 -20
- package/dist/dispatches/GoToGrenadeDispatch.d.ts +2 -0
- package/dist/dispatches/GoToGrenadeDispatch.js +15 -16
- package/dist/dispatches/GoToPlayerDispatch.d.ts +3 -1
- package/dist/dispatches/GoToPlayerDispatch.js +16 -21
- package/dist/dispatches/GoToSpatulaDispatch.d.ts +2 -0
- package/dist/dispatches/GoToSpatulaDispatch.js +11 -14
- package/dist/dispatches/LookAtDispatch.d.ts +3 -1
- package/dist/dispatches/LookAtDispatch.js +8 -6
- package/dist/dispatches/LookAtPosDispatch.d.ts +3 -1
- package/dist/dispatches/LookAtPosDispatch.js +1 -1
- package/dist/dispatches/MeleeDispatch.d.ts +2 -0
- package/dist/dispatches/MeleeDispatch.js +4 -4
- package/dist/dispatches/MovementDispatch.d.ts +3 -1
- package/dist/dispatches/MovementDispatch.js +1 -1
- package/dist/dispatches/PauseDispatch.d.ts +2 -0
- package/dist/dispatches/ReloadDispatch.d.ts +2 -0
- package/dist/dispatches/ReloadDispatch.js +17 -10
- package/dist/dispatches/ReportPlayerDispatch.d.ts +4 -2
- package/dist/dispatches/ReportPlayerDispatch.js +8 -6
- package/dist/dispatches/ResetGameDispatch.d.ts +2 -0
- package/dist/dispatches/SaveLoadoutDispatch.d.ts +4 -2
- package/dist/dispatches/SaveLoadoutDispatch.js +9 -8
- package/dist/dispatches/SpawnDispatch.d.ts +2 -0
- package/dist/dispatches/SpawnDispatch.js +5 -1
- package/dist/dispatches/SwapWeaponDispatch.d.ts +3 -1
- package/dist/dispatches/SwapWeaponDispatch.js +1 -1
- package/dist/dispatches/SwitchTeamDispatch.d.ts +2 -0
- package/dist/dispatches/SwitchTeamDispatch.js +2 -1
- package/dist/dispatches/ThrowGrenadeDispatch.d.ts +3 -1
- package/dist/dispatches/index.d.ts +105 -182
- package/dist/dispatches/index.js +24 -25
- package/dist/enums.d.ts +154 -0
- package/dist/enums.js +114 -0
- package/dist/env/fetch.d.ts +15 -0
- package/dist/env/fetch.js +113 -79
- package/dist/env/globals.d.ts +9 -0
- package/dist/env/globals.js +11 -9
- package/dist/index.d.ts +31 -0
- package/dist/index.js +24 -14
- package/dist/packets/addPlayer.js +63 -0
- package/dist/packets/beginShellStreak.js +44 -0
- package/dist/packets/challengeCompleted.js +16 -0
- package/dist/packets/changeCharacter.js +46 -0
- package/dist/packets/chat.js +10 -0
- package/dist/packets/collectItem.js +26 -0
- package/dist/packets/die.js +40 -0
- package/dist/packets/endShellStreak.js +21 -0
- package/dist/packets/eventModifier.js +8 -0
- package/dist/packets/explode.js +19 -0
- package/dist/packets/fire.js +21 -0
- package/dist/packets/gameAction.js +33 -0
- package/dist/packets/gameJoined.js +64 -0
- package/dist/packets/gameOptions.js +27 -0
- package/dist/packets/hitMe.js +12 -0
- package/dist/packets/hitMeHardBoiled.js +18 -0
- package/dist/packets/hitThem.js +12 -0
- package/dist/packets/melee.js +8 -0
- package/dist/packets/metaGameState.js +62 -0
- package/dist/packets/pause.js +17 -0
- package/dist/packets/ping.js +19 -0
- package/dist/packets/playerInfo.js +15 -0
- package/dist/packets/reload.js +17 -0
- package/dist/packets/removePlayer.js +10 -0
- package/dist/packets/respawn.js +31 -0
- package/dist/packets/socketReady.js +16 -0
- package/dist/packets/spawnItem.js +11 -0
- package/dist/packets/swapWeapon.js +11 -0
- package/dist/packets/switchTeam.js +13 -0
- package/dist/packets/syncMe.js +25 -0
- package/dist/packets/syncThem.js +63 -0
- package/dist/packets/throwGrenade.js +17 -0
- package/dist/packets/updateBalance.js +8 -0
- package/dist/pathing/astar.js +33 -20
- package/dist/pathing/mapnode.d.ts +3 -1
- package/dist/pathing/mapnode.js +170 -65
- package/dist/socket.d.ts +21 -6
- package/dist/socket.js +48 -38
- package/dist/util.d.ts +4 -1
- package/dist/util.js +102 -44
- package/dist/wasm/bytes.d.ts +1 -1
- package/dist/wasm/bytes.js +1 -1
- package/dist/wasm/direct.d.ts +1 -1
- package/dist/wasm/direct.js +13 -13
- package/dist/wasm/legacy.d.ts +7 -6
- package/dist/wasm/legacy.js +14 -8
- package/package.json +43 -30
- package/dist/comm/index.d.ts +0 -12
- package/dist/comm/index.js +0 -11
- package/dist/constants/changelog.d.ts +0 -7
- package/dist/constants/housePromo.d.ts +0 -40
- package/dist/constants/language.d.ts +0 -3
- package/dist/constants/notices.d.ts +0 -4
- package/dist/constants/shellNews.d.ts +0 -12
- package/dist/constants/shellYoutube.d.ts +0 -12
- package/dist/constants/shopItems.d.ts +0 -15
- package/dist/constants/sounds.d.ts +0 -10
- package/dist/matchmaker.d.ts +0 -50
- package/dist/matchmaker.js +0 -141
- package/dist/pathing/binaryheap.d.ts +0 -18
- package/dist/pathing/binaryheap.js +0 -79
- package/dist/wasm/util.d.ts +0 -9
- package/dist/wasm/util.js +0 -19
package/dist/socket.js
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
import globals from "./env/globals.js";
|
|
2
2
|
import { UserAgent } from "./constants/index.js";
|
|
3
3
|
|
|
4
|
-
class yolkws {
|
|
4
|
+
export class yolkws {
|
|
5
|
+
connected = false;
|
|
6
|
+
autoReconnect = false;
|
|
5
7
|
url = "";
|
|
6
8
|
proxy = "";
|
|
7
9
|
binaryType = "";
|
|
8
|
-
maxRetries = 5;
|
|
9
10
|
connectionTimeout = 5000;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
errorLogger = (...args) => console.error(...args);
|
|
12
|
+
onopen = () => {};
|
|
13
|
+
onmessage = () => {};
|
|
14
|
+
onclose = () => {};
|
|
15
|
+
onerror = () => {};
|
|
16
|
+
constructor(url, params = {}) {
|
|
17
|
+
if (typeof params !== "object")
|
|
18
|
+
params = {};
|
|
19
|
+
if (typeof process === "undefined" && params.proxy)
|
|
20
|
+
throw new Error("You cannot pass a proxy to a WebSocket in this environment.");
|
|
13
21
|
this.url = url;
|
|
14
|
-
this.proxy = proxy;
|
|
22
|
+
this.proxy = params.proxy;
|
|
23
|
+
if (typeof params.errorLogger === "function")
|
|
24
|
+
this.errorLogger = params.errorLogger;
|
|
15
25
|
}
|
|
16
26
|
async tryConnect(tries = 1) {
|
|
17
27
|
const url = new URL(this.url);
|
|
@@ -21,7 +31,7 @@ class yolkws {
|
|
|
21
31
|
return await this.tryConnect(tries + 1);
|
|
22
32
|
};
|
|
23
33
|
try {
|
|
24
|
-
this.socket =
|
|
34
|
+
this.socket = typeof process === "undefined" ? new globals.WebSocket(this.url) : new globals.WebSocket(this.url, {
|
|
25
35
|
proxy: this.proxy || null,
|
|
26
36
|
headers: {
|
|
27
37
|
"accept-encoding": "gzip, deflate, br, zstd",
|
|
@@ -30,14 +40,13 @@ class yolkws {
|
|
|
30
40
|
connection: "Upgrade",
|
|
31
41
|
origin: url.origin.replace("ws", "http"),
|
|
32
42
|
pragma: "no-cache",
|
|
33
|
-
"sec-websocket-extensions": "permessage-deflate; client_max_window_bits",
|
|
34
43
|
"user-agent": UserAgent
|
|
35
44
|
}
|
|
36
45
|
});
|
|
37
46
|
if (this.binaryType)
|
|
38
47
|
this.socket.binaryType = this.binaryType;
|
|
39
48
|
} catch (e) {
|
|
40
|
-
|
|
49
|
+
this.errorLogger(`Failed to connect on try ${tries}, trying again...`, e);
|
|
41
50
|
return await retryOrQuit();
|
|
42
51
|
}
|
|
43
52
|
if (this.onBeforeConnect)
|
|
@@ -49,49 +58,50 @@ class yolkws {
|
|
|
49
58
|
}, this.connectionTimeout);
|
|
50
59
|
const errorListener = async (e) => {
|
|
51
60
|
clearTimeout(timeout);
|
|
52
|
-
|
|
61
|
+
this.errorLogger("WebSocket error", e);
|
|
53
62
|
resolve(await retryOrQuit());
|
|
54
63
|
};
|
|
55
64
|
this.socket.addEventListener("open", async () => {
|
|
56
65
|
clearTimeout(timeout);
|
|
66
|
+
this.connected = true;
|
|
67
|
+
this.onopen();
|
|
57
68
|
this.socket.removeEventListener("error", errorListener);
|
|
69
|
+
this.socket.addEventListener("message", (messageEvent) => this.onmessage(messageEvent));
|
|
70
|
+
this.socket.addEventListener("close", (closeEvent) => !this.autoReconnect && this.onclose(closeEvent));
|
|
71
|
+
this.socket.addEventListener("error", (event) => this.onerror(event));
|
|
58
72
|
resolve(true);
|
|
59
73
|
});
|
|
60
74
|
this.socket.addEventListener("error", errorListener);
|
|
75
|
+
this.socket.addEventListener("close", () => {
|
|
76
|
+
if (this.connected) {
|
|
77
|
+
this.connected = false;
|
|
78
|
+
if (this.autoReconnect)
|
|
79
|
+
setTimeout(async () => {
|
|
80
|
+
const didConnect = await this.tryConnect();
|
|
81
|
+
if (!didConnect) {
|
|
82
|
+
if (this.onclose)
|
|
83
|
+
this.onclose();
|
|
84
|
+
this.errorLogger("tryConnect: failed to reconnect to", this.url, "after 5 attempts.");
|
|
85
|
+
this.errorLogger("tryConnect: please check your internet connection & ensure your IP isn't blocked.");
|
|
86
|
+
}
|
|
87
|
+
}, 250);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
61
90
|
});
|
|
62
91
|
}
|
|
63
|
-
get onmessage() {
|
|
64
|
-
return this.socket?.onmessage;
|
|
65
|
-
}
|
|
66
|
-
set onmessage(handler) {
|
|
67
|
-
if (this.socket)
|
|
68
|
-
this.socket.onmessage = handler;
|
|
69
|
-
else
|
|
70
|
-
console.error("set onmessage before socket existed");
|
|
71
|
-
}
|
|
72
|
-
get onclose() {
|
|
73
|
-
return this.socket?.onclose;
|
|
74
|
-
}
|
|
75
|
-
set onclose(handler) {
|
|
76
|
-
if (this.socket)
|
|
77
|
-
this.socket.onclose = handler;
|
|
78
|
-
else
|
|
79
|
-
console.error("set onclose before socket existed");
|
|
80
|
-
}
|
|
81
|
-
get onerror() {
|
|
82
|
-
return this.socket?.onerror;
|
|
83
|
-
}
|
|
84
|
-
set onerror(handler) {
|
|
85
|
-
if (this.socket)
|
|
86
|
-
this.socket.onerror = handler;
|
|
87
|
-
else
|
|
88
|
-
console.error("set onclose before socket existed");
|
|
89
|
-
}
|
|
90
92
|
send(data) {
|
|
91
93
|
return this.socket?.send(data);
|
|
92
94
|
}
|
|
93
95
|
close(data) {
|
|
94
|
-
|
|
96
|
+
if (!this.socket)
|
|
97
|
+
return;
|
|
98
|
+
this.autoReconnect = false;
|
|
99
|
+
if (this.socket.terminate) {
|
|
100
|
+
try {
|
|
101
|
+
this.socket.terminate();
|
|
102
|
+
} catch {}
|
|
103
|
+
} else
|
|
104
|
+
this.socket.close(data);
|
|
95
105
|
}
|
|
96
106
|
}
|
|
97
107
|
export default yolkws;
|
package/dist/util.d.ts
CHANGED
|
@@ -2,5 +2,8 @@ import { Zone } from './bot';
|
|
|
2
2
|
import { Position } from './bot/GamePlayer';
|
|
3
3
|
import { MapJSON } from './constants/maps';
|
|
4
4
|
|
|
5
|
+
export declare function createGun<T extends { ammo: { capacity: number; store: number } }>(baseGun: T): T;
|
|
6
|
+
export declare function createError<T = string>(message: T): { ok: false; error: T };
|
|
5
7
|
export declare function fetchMap(name: string, hash: string): Promise<MapJSON>;
|
|
6
|
-
export declare function initKotcZones(meshData: Array<Position>): Array<Array<Zone>>;
|
|
8
|
+
export declare function initKotcZones(meshData: Array<Position>): Array<Array<Zone>>;
|
|
9
|
+
export declare function isDoubleEggWeeknd(): boolean;
|
package/dist/util.js
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
export const createGun = (baseGun) => {
|
|
2
|
+
const gun = structuredClone(baseGun);
|
|
3
|
+
gun.ammo.rounds = gun.ammo.capacity;
|
|
4
|
+
gun.ammo.storeMax = gun.ammo.store;
|
|
5
|
+
return gun;
|
|
6
|
+
};
|
|
7
|
+
export const createError = (errorEnum) => ({ ok: false, error: errorEnum });
|
|
8
|
+
const attemptFetch = async (url, options = {}, retries = 3, backoff = 300) => {
|
|
9
|
+
try {
|
|
10
|
+
const response = await fetch(url, options);
|
|
11
|
+
if (!response.ok)
|
|
12
|
+
throw new Error(`failed to fetch map; status: ${response.status}`);
|
|
13
|
+
return response;
|
|
14
|
+
} catch (error) {
|
|
15
|
+
if (retries > 0) {
|
|
16
|
+
await new Promise((res) => setTimeout(res, backoff));
|
|
17
|
+
return attemptFetch(url, options, retries - 1, backoff * 2);
|
|
18
|
+
} else
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
2
22
|
export const fetchMap = async (name, hash) => {
|
|
3
|
-
if (
|
|
23
|
+
if (typeof process !== "undefined") {
|
|
4
24
|
const { existsSync, mkdirSync, readFileSync, writeFileSync } = process.getBuiltinModule("node:fs");
|
|
5
25
|
const { join } = process.getBuiltinModule("node:path");
|
|
6
26
|
const { homedir } = process.getBuiltinModule("node:os");
|
|
@@ -15,56 +35,94 @@ export const fetchMap = async (name, hash) => {
|
|
|
15
35
|
const mapFile = join(mapCache, `${safeName}-${safeHash}.json`);
|
|
16
36
|
if (existsSync(mapFile))
|
|
17
37
|
return JSON.parse(readFileSync(mapFile, "utf-8"));
|
|
18
|
-
const data = await (await
|
|
38
|
+
const data = await (await attemptFetch(`https://x.yolkbot.xyz/data/maps/full/${name}.json?${hash}`)).json();
|
|
19
39
|
writeFileSync(mapFile, JSON.stringify(data, null, 4), { flag: "w+" });
|
|
20
40
|
return data;
|
|
21
41
|
}
|
|
22
|
-
const data = await (await
|
|
42
|
+
const data = await (await attemptFetch(`https://x.yolkbot.xyz/data/maps/full/${name}.json?${hash}`)).json();
|
|
23
43
|
return data;
|
|
24
44
|
};
|
|
25
45
|
export const initKotcZones = (meshData) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
46
|
+
const len = meshData.length;
|
|
47
|
+
if (!len)
|
|
48
|
+
return [];
|
|
49
|
+
let minX = 1 / 0, minY = 1 / 0, minZ = 1 / 0;
|
|
50
|
+
let maxX = -1 / 0, maxY = -1 / 0, maxZ = -1 / 0;
|
|
51
|
+
for (let i = 0;i < len; i++) {
|
|
52
|
+
const { x, y, z } = meshData[i];
|
|
53
|
+
if (x < minX)
|
|
54
|
+
minX = x;
|
|
55
|
+
if (x > maxX)
|
|
56
|
+
maxX = x;
|
|
57
|
+
if (y < minY)
|
|
58
|
+
minY = y;
|
|
59
|
+
if (y > maxY)
|
|
60
|
+
maxY = y;
|
|
61
|
+
if (z < minZ)
|
|
62
|
+
minZ = z;
|
|
63
|
+
if (z > maxZ)
|
|
64
|
+
maxZ = z;
|
|
35
65
|
}
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
const sizeX = maxX - minX + 1 | 0;
|
|
67
|
+
const sizeY = maxY - minY + 1 | 0;
|
|
68
|
+
const sizeZ = maxZ - minZ + 1 | 0;
|
|
69
|
+
const strideY = sizeX;
|
|
70
|
+
const strideZ = sizeX * sizeY;
|
|
71
|
+
const cellIndex = new Int32Array(sizeX * sizeY * sizeZ).fill(-1);
|
|
72
|
+
const zoneIds = new Uint16Array(len);
|
|
73
|
+
const queue = new Uint32Array(len);
|
|
74
|
+
for (let i = 0;i < len; i++) {
|
|
75
|
+
const { x, y, z } = meshData[i];
|
|
76
|
+
cellIndex[(x - minX | 0) + (y - minY | 0) * strideY + (z - minZ | 0) * strideZ] = i;
|
|
77
|
+
}
|
|
78
|
+
const zones = [];
|
|
79
|
+
let zoneId = 0;
|
|
80
|
+
for (let i = 0;i < len; i++) {
|
|
81
|
+
if (zoneIds[i])
|
|
82
|
+
continue;
|
|
83
|
+
const zone = ++zoneId;
|
|
84
|
+
const activeZone = [];
|
|
85
|
+
let head = 0, tail = 0;
|
|
86
|
+
queue[tail++] = i;
|
|
87
|
+
zoneIds[i] = zone;
|
|
88
|
+
while (head < tail) {
|
|
89
|
+
const idx = queue[head++];
|
|
90
|
+
const cell = meshData[idx];
|
|
91
|
+
cell.zone = zone;
|
|
92
|
+
activeZone[activeZone.length] = cell;
|
|
93
|
+
const { x, y, z } = cell;
|
|
94
|
+
const flatIdx = (x - minX | 0) + (y - minY | 0) * strideY + (z - minZ | 0) * strideZ;
|
|
95
|
+
let nIdx;
|
|
96
|
+
if (x > minX && (nIdx = cellIndex[flatIdx - 1]) !== -1 && !zoneIds[nIdx]) {
|
|
97
|
+
zoneIds[nIdx] = zone;
|
|
98
|
+
queue[tail++] = nIdx;
|
|
99
|
+
}
|
|
100
|
+
if (x < maxX && (nIdx = cellIndex[flatIdx + 1]) !== -1 && !zoneIds[nIdx]) {
|
|
101
|
+
zoneIds[nIdx] = zone;
|
|
102
|
+
queue[tail++] = nIdx;
|
|
103
|
+
}
|
|
104
|
+
if (y > minY && (nIdx = cellIndex[flatIdx - strideY]) !== -1 && !zoneIds[nIdx]) {
|
|
105
|
+
zoneIds[nIdx] = zone;
|
|
106
|
+
queue[tail++] = nIdx;
|
|
107
|
+
}
|
|
108
|
+
if (y < maxY && (nIdx = cellIndex[flatIdx + strideY]) !== -1 && !zoneIds[nIdx]) {
|
|
109
|
+
zoneIds[nIdx] = zone;
|
|
110
|
+
queue[tail++] = nIdx;
|
|
111
|
+
}
|
|
112
|
+
if (z > minZ && (nIdx = cellIndex[flatIdx - strideZ]) !== -1 && !zoneIds[nIdx]) {
|
|
113
|
+
zoneIds[nIdx] = zone;
|
|
114
|
+
queue[tail++] = nIdx;
|
|
115
|
+
}
|
|
116
|
+
if (z < maxZ && (nIdx = cellIndex[flatIdx + strideZ]) !== -1 && !zoneIds[nIdx]) {
|
|
117
|
+
zoneIds[nIdx] = zone;
|
|
118
|
+
queue[tail++] = nIdx;
|
|
119
|
+
}
|
|
67
120
|
}
|
|
121
|
+
zones[zones.length] = activeZone;
|
|
68
122
|
}
|
|
69
123
|
return zones;
|
|
70
124
|
};
|
|
125
|
+
export const isDoubleEggWeeknd = () => {
|
|
126
|
+
const day = new Date().getUTCDay();
|
|
127
|
+
return day >= 5 && new Date().getUTCHours() >= 20 || day === 6 || day === 0;
|
|
128
|
+
};
|
package/dist/wasm/bytes.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const wasmBytes:
|
|
1
|
+
export declare const wasmBytes: Uint8Array;
|