yolkbot 0.1.0 → 0.1.1-alpha.3

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 (self) bot in under 10 lines.",
4
- "version": "0.1.0",
4
+ "version": "0.1.1-alpha.3",
5
5
  "keywords": [
6
6
  "shell shockers",
7
7
  "shellshock.io",
package/src/bot.js CHANGED
@@ -41,7 +41,8 @@ const intents = {
41
41
  BUFFERS: 4,
42
42
  PING: 5,
43
43
  COSMETIC_DATA: 6,
44
- PLAYER_HEALTH: 7
44
+ PLAYER_HEALTH: 7,
45
+ PACKET_HOOK: 8
45
46
  }
46
47
 
47
48
  export class Bot {
@@ -249,7 +250,7 @@ export class Bot {
249
250
  this.account.password = pass;
250
251
 
251
252
  const loginData = await createAccount(email, pass, this.proxy, this.instance);
252
- return this.#processLoginData(loginData);
253
+ return await this.#processLoginData(loginData);
253
254
  }
254
255
 
255
256
  async login(email, pass) {
@@ -257,12 +258,12 @@ export class Bot {
257
258
  this.account.password = pass;
258
259
 
259
260
  const loginData = await loginWithCredentials(email, pass, this.proxy, this.instance);
260
- return this.#processLoginData(loginData);
261
+ return await this.#processLoginData(loginData);
261
262
  }
262
263
 
263
264
  async loginWithRefreshToken(refreshToken) {
264
265
  const loginData = await loginWithRefreshToken(refreshToken, this.proxy, this.instance);
265
- return this.#processLoginData(loginData);
266
+ return await this.#processLoginData(loginData);
266
267
  }
267
268
 
268
269
  async loginAnonymously() {
@@ -270,10 +271,10 @@ export class Bot {
270
271
  delete this.account.password;
271
272
 
272
273
  const loginData = await loginAnonymously(this.proxy, this.instance);
273
- return this.#processLoginData(loginData);
274
+ return await this.#processLoginData(loginData);
274
275
  }
275
276
 
276
- #processLoginData(loginData) {
277
+ async #processLoginData(loginData) {
277
278
  if (typeof loginData == 'string') {
278
279
  this.emit('authFail', loginData);
279
280
  return false;
@@ -297,6 +298,29 @@ export class Bot {
297
298
  this.account.sessionId = loginData.sessionId;
298
299
  this.account.vip = loginData.upgradeProductId && !loginData.upgradeIsExpired;
299
300
 
301
+ if (this.intents.includes(this.Intents.STATS)) this.account.stats = {
302
+ lifetime: loginData.statsLifetime,
303
+ monthly: loginData.statsCurrent
304
+ };
305
+
306
+ if (this.intents.includes(this.Intents.CHALLENGES)) {
307
+ this.account.challenges = [];
308
+
309
+ const { Challenges } = await import('./constants/challenges.js');
310
+
311
+ for (const challenge of loginData.challenges) {
312
+ const challengeData = Challenges.find(c => c.id == challenge.challengeId);
313
+ if (!challengeData) continue;
314
+
315
+ delete challenge.playerId;
316
+
317
+ this.account.challenges.push({
318
+ ...challengeData,
319
+ ...challenge
320
+ });
321
+ }
322
+ }
323
+
300
324
  return this.account;
301
325
  }
302
326
 
@@ -875,7 +899,15 @@ export class Bot {
875
899
  const climbing = CommIn.unPackInt8U();
876
900
 
877
901
  const player = this.players[id];
878
- if (!player) return;
902
+ if (!player || player.id == this.me.id) {
903
+ for (let i2 = 0; i2 < 3 /* FramesBetweenSyncs */; i2++) {
904
+ CommIn.unPackInt8U();
905
+ CommIn.unPackRadU();
906
+ CommIn.unPackRad();
907
+ CommIn.unPackInt8U();
908
+ }
909
+ return;
910
+ }
879
911
 
880
912
  if (player.position.x !== x) player.position.x = x;
881
913
  if (player.position.z !== z) player.position.z = z;
@@ -888,24 +920,13 @@ export class Bot {
888
920
  if (this.intents.includes(this.Intents.BUFFERS)) {
889
921
  if (!player.buffer) return;
890
922
 
891
- if (player.id == this.me.id) {
892
- for (let i2 = 0; i2 < 3 /* FramesBetweenSyncs */; i2++) {
893
- CommIn.unPackInt8U();
894
- CommIn.unPackRadU();
895
- CommIn.unPackRad();
896
- CommIn.unPackInt8U();
897
- }
898
- return;
899
- }
900
-
901
- let yaw, pitch;
902
923
  for (let i2 = 0; i2 < 3; i2++) {
903
924
  player.buffer[i2].controlKeys = CommIn.unPackInt8U();
904
925
 
905
- yaw = CommIn.unPackRadU();
926
+ const yaw = CommIn.unPackRadU();
906
927
  if (!isNaN(yaw)) player.buffer[i2].yaw_ = yaw
907
928
 
908
- pitch = CommIn.unPackRad();
929
+ const pitch = CommIn.unPackRad();
909
930
  if (!isNaN(pitch)) player.buffer[i2].pitch_ = pitch
910
931
 
911
932
  CommIn.unPackInt8U();
@@ -1476,9 +1497,28 @@ export class Bot {
1476
1497
  }
1477
1498
  }
1478
1499
 
1500
+ #processChallengeCompletePacket() {
1501
+ const id = CommIn.unPackInt8U();
1502
+ const challengeId = CommIn.unPackInt8U();
1503
+
1504
+ const player = this.players[id];
1505
+ if (!player) return;
1506
+
1507
+ if (!this.intents.includes(this.Intents.CHALLENGES))
1508
+ return this.emit('challengeComplete', player, challengeId);
1509
+
1510
+ const challenge = this.account.challenges.find(c => c.id == challengeId);
1511
+ this.emit('challengeComplete', player, challenge);
1512
+
1513
+ if (player.id == this.me.id) this.refreshChallenges();
1514
+ }
1515
+
1479
1516
  #handlePacket(packet) {
1480
1517
  CommIn.init(packet);
1481
1518
 
1519
+ if (this.intents.includes(this.Intents.PACKET_HOOK))
1520
+ this.emit('packet', packet);
1521
+
1482
1522
  let lastCommand = 0;
1483
1523
  let abort = false;
1484
1524
 
@@ -1487,91 +1527,91 @@ export class Bot {
1487
1527
 
1488
1528
  switch (cmd) {
1489
1529
  case CommCode.syncThem:
1490
- this.#processSyncThemPacket(packet);
1530
+ this.#processSyncThemPacket();
1491
1531
  break;
1492
1532
 
1493
1533
  case CommCode.fire:
1494
- this.#processFirePacket(packet);
1534
+ this.#processFirePacket();
1495
1535
  break;
1496
1536
 
1497
1537
  case CommCode.hitThem:
1498
- this.#processHitThemPacket(packet);
1538
+ this.#processHitThemPacket();
1499
1539
  break;
1500
1540
 
1501
1541
  case CommCode.syncMe:
1502
- this.#processSyncMePacket(packet);
1542
+ this.#processSyncMePacket();
1503
1543
  break;
1504
1544
 
1505
1545
  case CommCode.hitMe:
1506
- this.#processHitMePacket(packet);
1546
+ this.#processHitMePacket();
1507
1547
  break;
1508
1548
 
1509
1549
  case CommCode.swapWeapon:
1510
- this.#processSwapWeaponPacket(packet);
1550
+ this.#processSwapWeaponPacket();
1511
1551
  break;
1512
1552
 
1513
1553
  case CommCode.collectItem:
1514
- this.#processCollectPacket(packet);
1554
+ this.#processCollectPacket();
1515
1555
  break;
1516
1556
 
1517
1557
  case CommCode.respawn:
1518
- this.#processRespawnPacket(packet);
1558
+ this.#processRespawnPacket();
1519
1559
  break;
1520
1560
 
1521
1561
  case CommCode.die:
1522
- this.#processDeathPacket(packet);
1562
+ this.#processDeathPacket();
1523
1563
  break;
1524
1564
 
1525
1565
  case CommCode.pause:
1526
- this.#processPausePacket(packet);
1566
+ this.#processPausePacket();
1527
1567
  break;
1528
1568
 
1529
1569
  case CommCode.chat:
1530
- this.#processChatPacket(packet);
1570
+ this.#processChatPacket();
1531
1571
  break;
1532
1572
 
1533
1573
  case CommCode.addPlayer:
1534
- this.#processAddPlayerPacket(packet);
1574
+ this.#processAddPlayerPacket();
1535
1575
  break;
1536
1576
 
1537
1577
  case CommCode.removePlayer:
1538
- this.#processRemovePlayerPacket(packet);
1578
+ this.#processRemovePlayerPacket();
1539
1579
  break;
1540
1580
 
1541
1581
  case CommCode.eventModifier:
1542
- this.#processEventModifierPacket(packet);
1582
+ this.#processEventModifierPacket();
1543
1583
  break;
1544
1584
 
1545
1585
  case CommCode.metaGameState:
1546
- this.#processGameStatePacket(packet);
1586
+ this.#processGameStatePacket();
1547
1587
  break;
1548
1588
 
1549
1589
  case CommCode.beginShellStreak:
1550
- this.#processBeginStreakPacket(packet);
1590
+ this.#processBeginStreakPacket();
1551
1591
  break;
1552
1592
 
1553
1593
  case CommCode.endShellStreak:
1554
- this.#processEndStreakPacket(packet);
1594
+ this.#processEndStreakPacket();
1555
1595
  break;
1556
1596
 
1557
1597
  case CommCode.hitMeHardBoiled:
1558
- this.#processHitShieldPacket(packet);
1598
+ this.#processHitShieldPacket();
1559
1599
  break;
1560
1600
 
1561
1601
  case CommCode.gameOptions:
1562
- this.#processGameOptionsPacket(packet);
1602
+ this.#processGameOptionsPacket();
1563
1603
  break;
1564
1604
 
1565
1605
  case CommCode.ping:
1566
- this.#processPingPacket(packet);
1606
+ this.#processPingPacket();
1567
1607
  break;
1568
1608
 
1569
1609
  case CommCode.switchTeam:
1570
- this.#processSwitchTeamPacket(packet);
1610
+ this.#processSwitchTeamPacket();
1571
1611
  break;
1572
1612
 
1573
1613
  case CommCode.changeCharacter:
1574
- this.#processChangeCharacterPacket(packet);
1614
+ this.#processChangeCharacterPacket();
1575
1615
  break;
1576
1616
 
1577
1617
  case CommCode.reload:
@@ -1595,11 +1635,15 @@ export class Bot {
1595
1635
  break;
1596
1636
 
1597
1637
  case CommCode.updateBalance:
1598
- this.#processUpdateBalancePacket(packet);
1638
+ this.#processUpdateBalancePacket();
1639
+ break;
1640
+
1641
+ case CommCode.challengeCompleted:
1642
+ this.#processChallengeCompletePacket();
1599
1643
  break;
1600
1644
 
1601
1645
  case CommCode.gameAction:
1602
- this.#processGameActionPacket(packet);
1646
+ this.#processGameActionPacket();
1603
1647
  break;
1604
1648
 
1605
1649
  case CommCode.requestGameOptions:
@@ -1607,7 +1651,7 @@ export class Bot {
1607
1651
  break;
1608
1652
 
1609
1653
  case CommCode.respawnDenied:
1610
- this.#processRespawnDeniedPacket(packet);
1654
+ this.#processRespawnDeniedPacket();
1611
1655
  break;
1612
1656
 
1613
1657
  // we do not plan to implement these
@@ -1620,11 +1664,6 @@ export class Bot {
1620
1664
  CommIn.unPackLongString();
1621
1665
  break;
1622
1666
 
1623
- case CommCode.challengeCompleted:
1624
- CommIn.unPackInt8U();
1625
- CommIn.unPackInt8U();
1626
- break;
1627
-
1628
1667
  default:
1629
1668
  console.error(`handlePacket: I got but did not handle a: ${Object.keys(CommCode).find(k => CommCode[k] === cmd)}`);
1630
1669
  if (lastCommand) console.error(`handlePacket: It may be a result of the ${lastCommand} command.`);