yolkbot 0.1.2-alpha.16 → 0.1.2-alpha.2

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/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.16",
4
+ "version": "0.1.2-alpha.2",
5
5
  "keywords": [
6
6
  "shell shockers",
7
7
  "shellshock.io",
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.replace(/socks([4|5|4a|5h]+)/g, 'https')) : undefined
100
+ dispatcher: proxy ? new globals.ProxyAgent(proxy) : 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.replace(/socks([4|5|4a|5h]+)/g, 'https')) : undefined
161
+ dispatcher: proxy ? new globals.ProxyAgent(proxy) : 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.replace(/socks([4|5|4a|5h]+)/g, 'https')) : undefined
209
+ dispatcher: proxy ? new globals.ProxyAgent(proxy) : undefined
210
210
  });
211
211
 
212
212
  const body = await req.json();
package/src/bot.js CHANGED
@@ -43,8 +43,7 @@ const intents = {
43
43
  PING: 5,
44
44
  COSMETIC_DATA: 6,
45
45
  PLAYER_HEALTH: 7,
46
- PACKET_HOOK: 8,
47
- MONITOR: 9
46
+ PACKET_HOOK: 8
48
47
  }
49
48
 
50
49
  export class Bot {
@@ -69,9 +68,8 @@ export class Bot {
69
68
 
70
69
  // private information NOT FOR OTHER PLAYERS!!
71
70
  this.state = {
72
- // kept for specifying various params
71
+ // kept for specifying socket open sequence
73
72
  name: '',
74
- weaponIdx: 0,
75
73
 
76
74
  // tracking for dispatch checks
77
75
  reloading: false,
@@ -389,6 +387,97 @@ export class Bot {
389
387
  });
390
388
  }
391
389
 
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
+
392
481
  // region - a region id ('useast', 'germany', etc)
393
482
  // mode - a mode name that corresponds to a GameMode id
394
483
  // map - the name of a map
@@ -482,7 +571,7 @@ export class Bot {
482
571
  this.game.socket.onerror = null;
483
572
  }
484
573
 
485
- this.game.socket.onmessage = (msg) => this.processPacket(msg.data);
574
+ this.game.socket.onmessage = this.#onGameMesssage.bind(this);
486
575
 
487
576
  this.game.socket.onclose = (e) => {
488
577
  // console.log('Game socket closed:', e.code, Object.entries(CloseCode).filter(([, v]) => v == e.code));
@@ -576,20 +665,19 @@ export class Bot {
576
665
  if (now - this.lastUpdateTime >= 50) {
577
666
  this.emit('tick');
578
667
 
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);
668
+ // Send out update packet
669
+ const out = CommOut.getBuffer();
670
+ out.packInt8(CommCode.syncMe);
671
+ out.packInt8(Math.random() * 128 | 0); // stateIdx
672
+ out.packInt8(this.me.serverStateIdx); // serverStateIdx
673
+ for (let i = 0; i < 3; i++) {
674
+ out.packInt8(this.controlKeys); // controlkeys
675
+ out.packInt8(this.state.shotsFired); // shots fired
676
+ out.packRadU(this.me.view.yaw); // yaw
677
+ out.packRad(this.me.view.pitch); // pitch
678
+ out.packInt8(100); // fixes commcode issues, does nothing
592
679
  }
680
+ out.send(this.game.socket);
593
681
 
594
682
  this.lastUpdateTime = now;
595
683
  this.state.shotsFired = 0;
@@ -1026,11 +1114,9 @@ export class Bot {
1026
1114
  }
1027
1115
 
1028
1116
  #processEventModifierPacket() {
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
- }
1117
+ const out = CommOut.getBuffer();
1118
+ out.packInt8(CommCode.eventModifier);
1119
+ out.send(this.game.socket);
1034
1120
  }
1035
1121
 
1036
1122
  #processRemovePlayerPacket() {
@@ -1264,7 +1350,7 @@ export class Bot {
1264
1350
 
1265
1351
  this.emit('pingUpdate', oldPing, this.ping);
1266
1352
 
1267
- if (!this.intents.includes(this.Intents.MONITOR)) setTimeout(() => {
1353
+ setTimeout(() => {
1268
1354
  const out = CommOut.getBuffer();
1269
1355
  out.packInt8(CommCode.ping);
1270
1356
  out.send(this.game.socket);
@@ -1374,26 +1460,22 @@ export class Bot {
1374
1460
  }
1375
1461
 
1376
1462
  #processGameRequestOptionsPacket() {
1377
- if (!this.intents.includes(this.Intents.MONITOR)) {
1378
- const out = CommOut.getBuffer();
1379
- out.packInt8(CommCode.gameOptions);
1380
- out.packInt8(this.game.options.gravity * 4);
1381
- out.packInt8(this.game.options.damage * 4);
1382
- out.packInt8(this.game.options.healthRegen * 4);
1383
-
1384
- const flags =
1385
- (this.game.options.locked ? 1 : 0) |
1386
- (this.game.options.noTeamChange ? 2 : 0) |
1387
- (this.game.options.noTeamShuffle ? 4 : 0);
1463
+ const out = CommOut.getBuffer();
1464
+ out.packInt8(CommCode.gameOptions);
1465
+ out.packInt8(this.game.options.gravity * 4);
1466
+ out.packInt8(this.game.options.damage * 4);
1467
+ out.packInt8(this.game.options.healthRegen * 4);
1388
1468
 
1389
- out.packInt8(flags);
1469
+ const flags =
1470
+ (this.game.options.locked ? 1 : 0) |
1471
+ (this.game.options.noTeamChange ? 2 : 0) |
1472
+ (this.game.options.noTeamShuffle ? 4 : 0);
1390
1473
 
1391
- this.game.options.weaponsDisabled.forEach((v) => {
1392
- out.packInt8(v ? 1 : 0);
1393
- });
1474
+ out.packInt8(flags);
1394
1475
 
1395
- out.send(this.game.socket);
1396
- }
1476
+ this.game.options.weaponsDisabled.forEach((v) => {
1477
+ out.packInt8(v ? 1 : 0);
1478
+ });
1397
1479
  }
1398
1480
 
1399
1481
  #processExplodePacket() {
@@ -1465,68 +1547,6 @@ export class Bot {
1465
1547
  }
1466
1548
  }
1467
1549
 
1468
- #processSocketReadyPacket() {
1469
- if (!this.intents.includes(this.Intents.MONITOR)) {
1470
- const out = CommOut.getBuffer();
1471
- out.packInt8(CommCode.joinGame);
1472
-
1473
- out.packString(this.state.name);
1474
- out.packString(this.game.raw.uuid);
1475
-
1476
- out.packInt8(0); // hidebadge
1477
- out.packInt8(this.state.weaponIdx || 0); // weapon idx
1478
-
1479
- out.packInt32(this.account.session);
1480
- out.packString(this.account.firebaseId);
1481
- out.packString(this.account.sessionId);
1482
-
1483
- out.send(this.game.socket);
1484
- }
1485
- }
1486
-
1487
- async #processGameJoinedPacket() {
1488
- this.me.id = CommIn.unPackInt8U();
1489
- this.me.team = CommIn.unPackInt8U();
1490
- this.game.gameModeId = CommIn.unPackInt8U(); // aka gameType
1491
- this.game.gameMode = GameModesById[this.game.gameModeId];
1492
- this.game.mapIdx = CommIn.unPackInt8U();
1493
- this.game.map = Maps[this.game.mapIdx];
1494
- if (this.intents.includes(this.Intents.PATHFINDING)) {
1495
- this.game.map.raw = await this.#fetchMap(this.game.map.filename, this.game.map.hash);
1496
- this.pathing.nodeList = new NodeList(this.game.map.raw);
1497
- if (this.game.gameModeId === GameModes.kotc) this.#initKotcZones();
1498
- }
1499
- this.game.playerLimit = CommIn.unPackInt8U();
1500
- this.game.isGameOwner = CommIn.unPackInt8U() == 1;
1501
- this.game.isPrivate = CommIn.unPackInt8U() == 1;
1502
-
1503
- // console.log('Successfully joined game.');
1504
-
1505
- this.state.joinedGame = true;
1506
- this.lastDeathTime = Date.now();
1507
-
1508
- if (!this.intents.includes(this.Intents.MONITOR)) {
1509
- const out = CommOut.getBuffer();
1510
- out.packInt8(CommCode.clientReady);
1511
- out.send(this.game.socket);
1512
-
1513
- this.game.socket.onmessage = (msg) => this._packetQueue.push(msg.data);
1514
- }
1515
-
1516
- if (this.autoUpdate)
1517
- this.updateIntervalId = setInterval(() => this.update(), this.updateInterval);
1518
-
1519
- if (this.intents.includes(this.Intents.PING)) {
1520
- this.lastPingTime = Date.now();
1521
-
1522
- if (!this.intents.includes(this.Intents.MONITOR)) {
1523
- const out = CommOut.getBuffer();
1524
- out.packInt8(CommCode.ping);
1525
- out.send(this.game.socket);
1526
- }
1527
- }
1528
- }
1529
-
1530
1550
  processPacket(packet) {
1531
1551
  CommIn.init(packet);
1532
1552
 
@@ -1662,14 +1682,6 @@ export class Bot {
1662
1682
  this.#processChallengeCompletePacket();
1663
1683
  break;
1664
1684
 
1665
- case CommCode.socketReady:
1666
- this.#processSocketReadyPacket();
1667
- break;
1668
-
1669
- case CommCode.gameJoined:
1670
- this.#processGameJoinedPacket();
1671
- break;
1672
-
1673
1685
  case CommCode.gameAction:
1674
1686
  this.#processGameActionPacket();
1675
1687
  break;
@@ -1743,7 +1755,7 @@ export class Bot {
1743
1755
  if (typeof response === 'string') return response;
1744
1756
 
1745
1757
  if (response.error) {
1746
- if (response.error == 'RATELIMITED' || response.error == 'RATELMITED') {
1758
+ if (response.error == 'RATELIMITED') {
1747
1759
  await this.checkChiknWinner();
1748
1760
  return 'on_cooldown';
1749
1761
  } else if (response.error == 'SESSION_EXPIRED') {
@@ -70,12 +70,10 @@ export class SaveLoadoutDispatch {
70
70
  }
71
71
 
72
72
  execute(bot) {
73
- if (bot.me && this.changes.classIdx && this.changes.classIdx !== bot.me.selectedGun) {
73
+ if (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
-
79
77
  const loadout = {
80
78
  ...bot.account.loadout,
81
79
  ...this.changes
@@ -91,7 +89,7 @@ export class SaveLoadoutDispatch {
91
89
 
92
90
  bot.account.loadout = loadout;
93
91
 
94
- if (bot.me) saveLoadout.then(() => {
92
+ saveLoadout.then(() => {
95
93
  if (bot.state.joinedGame) {
96
94
  const out = CommOut.getBuffer();
97
95
  out.packInt8(CommCode.changeCharacter);
@@ -66,8 +66,6 @@ export interface Account {
66
66
  firebaseId: string;
67
67
  sessionId: string;
68
68
  session: string;
69
- email: string;
70
- password: string;
71
69
  cw: ChiknWinnerStatus;
72
70
  loadout: {
73
71
  hatId: number | null;
@@ -172,7 +170,6 @@ export interface Pathing {
172
170
 
173
171
  export interface BotState {
174
172
  name: string;
175
- weaponIdx: number;
176
173
  reloading: boolean;
177
174
  swappingGun: boolean;
178
175
  usingMelee: boolean;
@@ -193,8 +190,7 @@ type intents = {
193
190
  PING: 5,
194
191
  COSMETIC_DATA: 6,
195
192
  PLAYER_HEALTH: 7,
196
- PACKET_HOOK: 8,
197
- MONITOR: 9
193
+ PACKET_HOOK: 8
198
194
  }
199
195
 
200
196
  export class Bot {
@@ -235,7 +231,7 @@ export class Bot {
235
231
  update(): void;
236
232
 
237
233
  canSee(player: GamePlayer): boolean;
238
- getBestTarget(customFilter?: (player: GamePlayer) => boolean): GamePlayer | undefined;
234
+ getBestTarget(customFilter: (player: GamePlayer) => boolean): GamePlayer | undefined;
239
235
 
240
236
  onAny(cb: Function): void;
241
237