yolkbot 0.1.2-alpha.1 → 0.1.2-alpha.11
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/browser/build/global.js +1 -1
- package/browser/build/module.js +1 -1
- package/package.json +3 -1
- package/src/api.js +3 -3
- package/src/bot.js +94 -110
- package/src/dispatches/SaveLoadoutDispatch.js +4 -2
- package/src/types/bot.d.ts +3 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yolkbot",
|
|
3
3
|
"description": "create a shell shockers bot in under 10 lines.",
|
|
4
|
-
"version": "0.1.2-alpha.
|
|
4
|
+
"version": "0.1.2-alpha.11",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shell shockers",
|
|
7
7
|
"shellshock.io",
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
"types": "./src/types/api.d.ts"
|
|
35
35
|
},
|
|
36
36
|
"./browser": "./browser/build/module.js",
|
|
37
|
+
"./browser/*": "./browser/build/*.js",
|
|
38
|
+
"./browser/*.js": "./browser/build/*.js",
|
|
37
39
|
"./comm": "./src/comm/index.js",
|
|
38
40
|
"./matchmaker": {
|
|
39
41
|
"import": "./src/matchmaker.js",
|
package/src/api.js
CHANGED
|
@@ -97,7 +97,7 @@ async function loginWithCredentials(email, password, proxy = '', instance = 'she
|
|
|
97
97
|
'x-client-version': 'Chrome/JsCore/9.17.2/FirebaseCore-web',
|
|
98
98
|
'x-firebase-locale': 'en'
|
|
99
99
|
},
|
|
100
|
-
dispatcher: proxy ? new globals.ProxyAgent(proxy) : undefined
|
|
100
|
+
dispatcher: proxy ? new globals.ProxyAgent(proxy.replace(/socks([4|5|4a|5h]+)/g, 'https')) : undefined
|
|
101
101
|
});
|
|
102
102
|
|
|
103
103
|
body = await request.json();
|
|
@@ -158,7 +158,7 @@ async function loginWithRefreshToken(refreshToken, proxy = '', instance = 'shell
|
|
|
158
158
|
'x-client-version': 'Chrome/JsCore/9.17.2/FirebaseCore-web',
|
|
159
159
|
'x-firebase-locale': 'en'
|
|
160
160
|
},
|
|
161
|
-
dispatcher: proxy ? new globals.ProxyAgent(proxy) : undefined
|
|
161
|
+
dispatcher: proxy ? new globals.ProxyAgent(proxy.replace(/socks([4|5|4a|5h]+)/g, 'https')) : undefined
|
|
162
162
|
});
|
|
163
163
|
|
|
164
164
|
body = await request.json();
|
|
@@ -206,7 +206,7 @@ async function loginAnonymously(proxy = '', instance = 'shellshock.io') {
|
|
|
206
206
|
'x-client-version': 'Chrome/JsCore/9.17.2/FirebaseCore-web',
|
|
207
207
|
'x-firebase-locale': 'en'
|
|
208
208
|
},
|
|
209
|
-
dispatcher: proxy ? new globals.ProxyAgent(proxy) : undefined
|
|
209
|
+
dispatcher: proxy ? new globals.ProxyAgent(proxy.replace(/socks([4|5|4a|5h]+)/g, 'https')) : undefined
|
|
210
210
|
});
|
|
211
211
|
|
|
212
212
|
const body = await req.json();
|
package/src/bot.js
CHANGED
|
@@ -43,7 +43,8 @@ const intents = {
|
|
|
43
43
|
PING: 5,
|
|
44
44
|
COSMETIC_DATA: 6,
|
|
45
45
|
PLAYER_HEALTH: 7,
|
|
46
|
-
PACKET_HOOK: 8
|
|
46
|
+
PACKET_HOOK: 8,
|
|
47
|
+
MONITOR: 9
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
export class Bot {
|
|
@@ -68,8 +69,9 @@ export class Bot {
|
|
|
68
69
|
|
|
69
70
|
// private information NOT FOR OTHER PLAYERS!!
|
|
70
71
|
this.state = {
|
|
71
|
-
// kept for specifying
|
|
72
|
+
// kept for specifying various params
|
|
72
73
|
name: '',
|
|
74
|
+
weaponIdx: 0,
|
|
73
75
|
|
|
74
76
|
// tracking for dispatch checks
|
|
75
77
|
reloading: false,
|
|
@@ -387,97 +389,6 @@ export class Bot {
|
|
|
387
389
|
});
|
|
388
390
|
}
|
|
389
391
|
|
|
390
|
-
async #onGameMesssage(msg) {
|
|
391
|
-
CommIn.init(msg.data);
|
|
392
|
-
|
|
393
|
-
let out;
|
|
394
|
-
const cmd = CommIn.unPackInt8U();
|
|
395
|
-
|
|
396
|
-
switch (cmd) {
|
|
397
|
-
case CommCode.socketReady:
|
|
398
|
-
out = CommOut.getBuffer();
|
|
399
|
-
out.packInt8(CommCode.joinGame);
|
|
400
|
-
|
|
401
|
-
out.packString(this.state.name); // name
|
|
402
|
-
out.packString(this.game.raw.uuid); // game id
|
|
403
|
-
|
|
404
|
-
out.packInt8(0); // hidebadge
|
|
405
|
-
out.packInt8(0); // weapon choice
|
|
406
|
-
|
|
407
|
-
out.packInt32(this.account.session); // session int
|
|
408
|
-
out.packString(this.account.firebaseId); // firebase id
|
|
409
|
-
out.packString(this.account.sessionId); // session id
|
|
410
|
-
|
|
411
|
-
out.send(this.game.socket);
|
|
412
|
-
break;
|
|
413
|
-
|
|
414
|
-
case CommCode.gameJoined: {
|
|
415
|
-
this.me.id = CommIn.unPackInt8U();
|
|
416
|
-
// console.log("My id is:", this.me.id);
|
|
417
|
-
this.me.team = CommIn.unPackInt8U();
|
|
418
|
-
// console.log("My team is:", this.me.team);
|
|
419
|
-
this.game.gameModeId = CommIn.unPackInt8U(); // aka gameType
|
|
420
|
-
this.game.gameMode = GameModesById[this.game.gameModeId];
|
|
421
|
-
// console.log("Gametype:", this.game.gameMode, this.game.gameModeId);
|
|
422
|
-
this.game.mapIdx = CommIn.unPackInt8U();
|
|
423
|
-
this.game.map = Maps[this.game.mapIdx];
|
|
424
|
-
if (this.intents.includes(this.Intents.PATHFINDING)) {
|
|
425
|
-
this.game.map.raw = await this.#fetchMap(this.game.map.filename, this.game.map.hash);
|
|
426
|
-
this.pathing.nodeList = new NodeList(this.game.map.raw);
|
|
427
|
-
if (this.game.gameModeId === GameModes.kotc) this.#initKotcZones();
|
|
428
|
-
}
|
|
429
|
-
// console.log("Map:", this.game.map);
|
|
430
|
-
this.game.playerLimit = CommIn.unPackInt8U();
|
|
431
|
-
// console.log("Player limit:", this.game.playerLimit);
|
|
432
|
-
this.game.isGameOwner = CommIn.unPackInt8U() == 1;
|
|
433
|
-
// console.log("Is game owner:", this.game.isGameOwner);
|
|
434
|
-
this.game.isPrivate = CommIn.unPackInt8U() == 1;
|
|
435
|
-
// console.log("Is private game:", this.game.isPrivate);
|
|
436
|
-
|
|
437
|
-
// console.log('Successfully joined game.');
|
|
438
|
-
this.state.joinedGame = true;
|
|
439
|
-
this.lastDeathTime = Date.now();
|
|
440
|
-
|
|
441
|
-
const out = CommOut.getBuffer();
|
|
442
|
-
out.packInt8(CommCode.clientReady);
|
|
443
|
-
out.send(this.game.socket);
|
|
444
|
-
|
|
445
|
-
this.game.socket.onmessage = (msg) => this._packetQueue.push(msg.data);
|
|
446
|
-
|
|
447
|
-
if (this.autoUpdate)
|
|
448
|
-
this.updateIntervalId = setInterval(() => this.update(), this.updateInterval);
|
|
449
|
-
|
|
450
|
-
if (this.intents.includes(this.Intents.PING)) {
|
|
451
|
-
const out = CommOut.getBuffer();
|
|
452
|
-
out.packInt8(CommCode.ping);
|
|
453
|
-
out.send(this.game.socket);
|
|
454
|
-
this.lastPingTime = Date.now();
|
|
455
|
-
}
|
|
456
|
-
break;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
case CommCode.eventModifier:
|
|
460
|
-
// console.log("Echoed eventModifier"); // why the fuck do you need to do this
|
|
461
|
-
out = CommOut.getBuffer();
|
|
462
|
-
out.packInt8(CommCode.eventModifier);
|
|
463
|
-
out.send(this.game.socket);
|
|
464
|
-
break;
|
|
465
|
-
|
|
466
|
-
case CommCode.requestGameOptions:
|
|
467
|
-
this.#processGameRequestOptionsPacket();
|
|
468
|
-
break;
|
|
469
|
-
|
|
470
|
-
default:
|
|
471
|
-
try {
|
|
472
|
-
const inferredCode = Object.entries(CommCode).filter(([, v]) => v == cmd)[0][0];
|
|
473
|
-
console.error('onGameMessage: Received but did not handle a:', inferredCode);
|
|
474
|
-
// packet could potentially not exist, then [0][0] will error
|
|
475
|
-
} catch {
|
|
476
|
-
console.error('onGameMessage: Unexpected packet received during startup: ' + cmd);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
392
|
// region - a region id ('useast', 'germany', etc)
|
|
482
393
|
// mode - a mode name that corresponds to a GameMode id
|
|
483
394
|
// map - the name of a map
|
|
@@ -571,7 +482,7 @@ export class Bot {
|
|
|
571
482
|
this.game.socket.onerror = null;
|
|
572
483
|
}
|
|
573
484
|
|
|
574
|
-
this.game.socket.onmessage = this
|
|
485
|
+
this.game.socket.onmessage = (msg) => this.processPacket(msg.data);
|
|
575
486
|
|
|
576
487
|
this.game.socket.onclose = (e) => {
|
|
577
488
|
// console.log('Game socket closed:', e.code, Object.entries(CloseCode).filter(([, v]) => v == e.code));
|
|
@@ -665,19 +576,20 @@ export class Bot {
|
|
|
665
576
|
if (now - this.lastUpdateTime >= 50) {
|
|
666
577
|
this.emit('tick');
|
|
667
578
|
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
579
|
+
if (!this.intents.includes(this.Intents.MONITOR)) {
|
|
580
|
+
const out = CommOut.getBuffer();
|
|
581
|
+
out.packInt8(CommCode.syncMe);
|
|
582
|
+
out.packInt8(Math.random() * 128 | 0); // stateIdx
|
|
583
|
+
out.packInt8(this.me.serverStateIdx); // serverStateIdx
|
|
584
|
+
for (let i = 0; i < 3; i++) {
|
|
585
|
+
out.packInt8(this.controlKeys); // controlkeys
|
|
586
|
+
out.packInt8(this.state.shotsFired); // shots fired
|
|
587
|
+
out.packRadU(this.me.view.yaw); // yaw
|
|
588
|
+
out.packRad(this.me.view.pitch); // pitch
|
|
589
|
+
out.packInt8(100); // fixes commcode issues, does nothing
|
|
590
|
+
}
|
|
591
|
+
out.send(this.game.socket);
|
|
679
592
|
}
|
|
680
|
-
out.send(this.game.socket);
|
|
681
593
|
|
|
682
594
|
this.lastUpdateTime = now;
|
|
683
595
|
this.state.shotsFired = 0;
|
|
@@ -1114,9 +1026,11 @@ export class Bot {
|
|
|
1114
1026
|
}
|
|
1115
1027
|
|
|
1116
1028
|
#processEventModifierPacket() {
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1029
|
+
if (!this.intents.includes(this.Intents.MONITOR)) {
|
|
1030
|
+
const out = CommOut.getBuffer();
|
|
1031
|
+
out.packInt8(CommCode.eventModifier);
|
|
1032
|
+
out.send(this.game.socket);
|
|
1033
|
+
}
|
|
1120
1034
|
}
|
|
1121
1035
|
|
|
1122
1036
|
#processRemovePlayerPacket() {
|
|
@@ -1350,7 +1264,7 @@ export class Bot {
|
|
|
1350
1264
|
|
|
1351
1265
|
this.emit('pingUpdate', oldPing, this.ping);
|
|
1352
1266
|
|
|
1353
|
-
setTimeout(() => {
|
|
1267
|
+
if (!this.intents.includes(this.Intents.MONITOR)) setTimeout(() => {
|
|
1354
1268
|
const out = CommOut.getBuffer();
|
|
1355
1269
|
out.packInt8(CommCode.ping);
|
|
1356
1270
|
out.send(this.game.socket);
|
|
@@ -1547,6 +1461,68 @@ export class Bot {
|
|
|
1547
1461
|
}
|
|
1548
1462
|
}
|
|
1549
1463
|
|
|
1464
|
+
#processSocketReadyPacket() {
|
|
1465
|
+
if (!this.intents.includes(this.Intents.MONITOR)) {
|
|
1466
|
+
const out = CommOut.getBuffer();
|
|
1467
|
+
out.packInt8(CommCode.joinGame);
|
|
1468
|
+
|
|
1469
|
+
out.packString(this.state.name);
|
|
1470
|
+
out.packString(this.game.raw.uuid);
|
|
1471
|
+
|
|
1472
|
+
out.packInt8(0); // hidebadge
|
|
1473
|
+
out.packInt8(this.state.weaponIdx || 0); // weapon idx
|
|
1474
|
+
|
|
1475
|
+
out.packInt32(this.account.session);
|
|
1476
|
+
out.packString(this.account.firebaseId);
|
|
1477
|
+
out.packString(this.account.sessionId);
|
|
1478
|
+
|
|
1479
|
+
out.send(this.game.socket);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
async #processGameJoinedPacket() {
|
|
1484
|
+
this.me.id = CommIn.unPackInt8U();
|
|
1485
|
+
this.me.team = CommIn.unPackInt8U();
|
|
1486
|
+
this.game.gameModeId = CommIn.unPackInt8U(); // aka gameType
|
|
1487
|
+
this.game.gameMode = GameModesById[this.game.gameModeId];
|
|
1488
|
+
this.game.mapIdx = CommIn.unPackInt8U();
|
|
1489
|
+
this.game.map = Maps[this.game.mapIdx];
|
|
1490
|
+
if (this.intents.includes(this.Intents.PATHFINDING)) {
|
|
1491
|
+
this.game.map.raw = await this.#fetchMap(this.game.map.filename, this.game.map.hash);
|
|
1492
|
+
this.pathing.nodeList = new NodeList(this.game.map.raw);
|
|
1493
|
+
if (this.game.gameModeId === GameModes.kotc) this.#initKotcZones();
|
|
1494
|
+
}
|
|
1495
|
+
this.game.playerLimit = CommIn.unPackInt8U();
|
|
1496
|
+
this.game.isGameOwner = CommIn.unPackInt8U() == 1;
|
|
1497
|
+
this.game.isPrivate = CommIn.unPackInt8U() == 1;
|
|
1498
|
+
|
|
1499
|
+
// console.log('Successfully joined game.');
|
|
1500
|
+
|
|
1501
|
+
this.state.joinedGame = true;
|
|
1502
|
+
this.lastDeathTime = Date.now();
|
|
1503
|
+
|
|
1504
|
+
if (!this.intents.includes(this.Intents.MONITOR)) {
|
|
1505
|
+
const out = CommOut.getBuffer();
|
|
1506
|
+
out.packInt8(CommCode.clientReady);
|
|
1507
|
+
out.send(this.game.socket);
|
|
1508
|
+
|
|
1509
|
+
this.game.socket.onmessage = (msg) => this._packetQueue.push(msg.data);
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
if (this.autoUpdate)
|
|
1513
|
+
this.updateIntervalId = setInterval(() => this.update(), this.updateInterval);
|
|
1514
|
+
|
|
1515
|
+
if (this.intents.includes(this.Intents.PING)) {
|
|
1516
|
+
this.lastPingTime = Date.now();
|
|
1517
|
+
|
|
1518
|
+
if (!this.intents.includes(this.Intents.MONITOR)) {
|
|
1519
|
+
const out = CommOut.getBuffer();
|
|
1520
|
+
out.packInt8(CommCode.ping);
|
|
1521
|
+
out.send(this.game.socket);
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1550
1526
|
processPacket(packet) {
|
|
1551
1527
|
CommIn.init(packet);
|
|
1552
1528
|
|
|
@@ -1682,6 +1658,14 @@ export class Bot {
|
|
|
1682
1658
|
this.#processChallengeCompletePacket();
|
|
1683
1659
|
break;
|
|
1684
1660
|
|
|
1661
|
+
case CommCode.socketReady:
|
|
1662
|
+
this.#processSocketReadyPacket();
|
|
1663
|
+
break;
|
|
1664
|
+
|
|
1665
|
+
case CommCode.gameJoined:
|
|
1666
|
+
this.#processGameJoinedPacket();
|
|
1667
|
+
break;
|
|
1668
|
+
|
|
1685
1669
|
case CommCode.gameAction:
|
|
1686
1670
|
this.#processGameActionPacket();
|
|
1687
1671
|
break;
|
|
@@ -70,10 +70,12 @@ export class SaveLoadoutDispatch {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
execute(bot) {
|
|
73
|
-
if (this.changes.classIdx && this.changes.classIdx !== bot.me.selectedGun) {
|
|
73
|
+
if (bot.me && this.changes.classIdx && this.changes.classIdx !== bot.me.selectedGun) {
|
|
74
74
|
bot.me.weapons[0] = new GunList[this.changes.classIdx]();
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
bot.state.weaponIdx = this.changes.classIdx || bot.state.weaponIdx;
|
|
78
|
+
|
|
77
79
|
const loadout = {
|
|
78
80
|
...bot.account.loadout,
|
|
79
81
|
...this.changes
|
|
@@ -89,7 +91,7 @@ export class SaveLoadoutDispatch {
|
|
|
89
91
|
|
|
90
92
|
bot.account.loadout = loadout;
|
|
91
93
|
|
|
92
|
-
saveLoadout.then(() => {
|
|
94
|
+
if (bot.me) saveLoadout.then(() => {
|
|
93
95
|
if (bot.state.joinedGame) {
|
|
94
96
|
const out = CommOut.getBuffer();
|
|
95
97
|
out.packInt8(CommCode.changeCharacter);
|
package/src/types/bot.d.ts
CHANGED
|
@@ -170,6 +170,7 @@ export interface Pathing {
|
|
|
170
170
|
|
|
171
171
|
export interface BotState {
|
|
172
172
|
name: string;
|
|
173
|
+
weaponIdx: number;
|
|
173
174
|
reloading: boolean;
|
|
174
175
|
swappingGun: boolean;
|
|
175
176
|
usingMelee: boolean;
|
|
@@ -190,7 +191,8 @@ type intents = {
|
|
|
190
191
|
PING: 5,
|
|
191
192
|
COSMETIC_DATA: 6,
|
|
192
193
|
PLAYER_HEALTH: 7,
|
|
193
|
-
PACKET_HOOK: 8
|
|
194
|
+
PACKET_HOOK: 8,
|
|
195
|
+
MONITOR: 9
|
|
194
196
|
}
|
|
195
197
|
|
|
196
198
|
export class Bot {
|