yolkbot 0.1.0-alpha.9 → 0.1.0

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.
Files changed (45) hide show
  1. package/build/browser.js +6 -6
  2. package/package.json +17 -5
  3. package/src/api.js +97 -23
  4. package/src/bot/GamePlayer.js +2 -2
  5. package/src/bot.js +851 -484
  6. package/src/comm/Codes.js +73 -0
  7. package/src/constants/index.js +23 -1
  8. package/src/constants/items.js +663 -264
  9. package/src/constants/maps.js +57 -18
  10. package/src/dispatches/BootPlayerDispatch.js +1 -1
  11. package/src/dispatches/ChatDispatch.js +1 -1
  12. package/src/dispatches/GameOptionsDispatch.js +1 -1
  13. package/src/dispatches/GoToAmmoDispatch.js +44 -0
  14. package/src/dispatches/GoToCoopDispatch.js +44 -0
  15. package/src/dispatches/GoToGrenadeDispatch.js +44 -0
  16. package/src/dispatches/GoToPlayerDispatch.js +5 -1
  17. package/src/dispatches/GoToSpatulaDispatch.js +5 -1
  18. package/src/dispatches/MeleeDispatch.js +1 -1
  19. package/src/dispatches/PauseDispatch.js +1 -1
  20. package/src/dispatches/ReloadDispatch.js +14 -2
  21. package/src/dispatches/ReportPlayerDispatch.js +1 -1
  22. package/src/dispatches/SaveLoadoutDispatch.js +11 -34
  23. package/src/dispatches/SpawnDispatch.js +1 -1
  24. package/src/dispatches/SwapWeaponDispatch.js +1 -1
  25. package/src/dispatches/SwitchTeamDispatch.js +1 -1
  26. package/src/dispatches/ThrowGrenadeDispatch.js +1 -1
  27. package/src/dispatches/index.js +9 -0
  28. package/src/matchmaker.js +11 -2
  29. package/src/pathing/mapnode.js +83 -250
  30. package/src/socket.js +1 -1
  31. package/src/types/api.d.ts +2 -16
  32. package/src/types/bot/GamePlayer.d.ts +25 -21
  33. package/src/types/bot.d.ts +78 -54
  34. package/src/types/constants/guns.d.ts +240 -0
  35. package/src/types/constants/index.d.ts +100 -0
  36. package/src/types/constants/items.d.ts +21 -0
  37. package/src/types/constants/maps.d.ts +15 -0
  38. package/src/types/dispatches/GoToAmmoDispatch.d.ts +8 -0
  39. package/src/types/dispatches/GoToCoopDispatch.d.ts +8 -0
  40. package/src/types/dispatches/GoToGrenadeDispatch.d.ts +8 -0
  41. package/src/types/dispatches/MovementDispatch.d.ts +2 -0
  42. package/src/types/dispatches/index.d.ts +45 -1
  43. package/src/types/matchmaker.d.ts +19 -14
  44. package/src/types/socket.d.ts +7 -0
  45. package/src/types/gun.d.ts +0 -131
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-alpha.9",
4
+ "version": "0.1.0",
5
5
  "keywords": [
6
6
  "shell shockers",
7
7
  "shellshock.io",
@@ -46,9 +46,20 @@
46
46
  "types": "./src/types/matchmaker.d.ts"
47
47
  },
48
48
  "./packets": "./src/packet.js",
49
- "./constants": "./src/constants/index.js",
50
- "./constants/*": "./src/constants/*.js",
51
- "./constants/*.js": "./src/constants/*.js",
49
+ "./pathing/*": "./src/pathing/*.js",
50
+ "./pathing/*.js": "./src/pathing/*.js",
51
+ "./constants": {
52
+ "import": "./src/constants/index.js",
53
+ "types": "./src/types/constants/index.d.ts"
54
+ },
55
+ "./constants/*": {
56
+ "import": "./src/constants/*.js",
57
+ "types": "./src/types/constants/*.d.ts"
58
+ },
59
+ "./constants/*.js": {
60
+ "import": "./src/constants/*.js",
61
+ "types": "./src/types/constants/*.d.ts"
62
+ },
52
63
  "./dispatch": {
53
64
  "import": "./src/dispatches/index.js",
54
65
  "types": "./src/types/dispatches.d.ts"
@@ -63,7 +74,8 @@
63
74
  }
64
75
  },
65
76
  "dependencies": {
66
- "socks-proxy-agent": "^8.0.5",
77
+ "axios": "^1.8.3",
78
+ "smallsocks": "^1.0.0",
67
79
  "ws": "^8.18.0"
68
80
  },
69
81
  "devDependencies": {
package/src/api.js CHANGED
@@ -1,18 +1,34 @@
1
+ import axios from 'axios';
2
+
1
3
  import yolkws from './socket.js';
2
4
 
3
- import { FirebaseKey, UserAgent } from '#constants';
5
+ import { FirebaseKey, IsBrowser, UserAgent } from '#constants';
6
+
7
+ let SocksProxyAgent;
8
+ if (!IsBrowser) SocksProxyAgent = (await import('smallsocks')).SocksProxyAgent;
4
9
 
5
10
  const queryServices = async (request, proxy = '', instance = 'shellshock.io') => {
6
- return new Promise((resolve) => {
7
- const ws = new yolkws(`wss://${instance}/services/`, proxy);
11
+ let ws;
12
+
13
+ const attempt = async () => {
14
+ try {
15
+ ws = new yolkws(`wss://${instance}/services/`, proxy);
16
+ } catch {
17
+ await new Promise((resolve) => setTimeout(resolve, 100));
18
+ await attempt();
19
+ }
20
+ }
21
+
22
+ await attempt();
8
23
 
24
+ return new Promise((resolve) => {
9
25
  ws.onopen = () => {
10
26
  // console.log('opened')
11
27
  ws.send(JSON.stringify(request));
12
28
  }
13
-
29
+
14
30
  let resolved = false;
15
-
31
+
16
32
  ws.onmessage = (mes) => {
17
33
  try {
18
34
  const resp = JSON.parse(mes.data);
@@ -35,7 +51,11 @@ const queryServices = async (request, proxy = '', instance = 'shellshock.io') =>
35
51
  });
36
52
  }
37
53
 
38
- async function loginWithCredentials(email, password, prox = '', instance = 'shellshock.io') {
54
+ async function createAccount(email, password, prox = '', instance = 'shellshock.io') {
55
+ return await loginWithCredentials(email, password, prox, instance, true);
56
+ }
57
+
58
+ async function loginWithCredentials(email, password, prox = '', instance = 'shellshock.io', _useRegisterEndpoint) {
39
59
  if (!email || !password) return 'firebase_no_credentials';
40
60
 
41
61
  /*
@@ -54,25 +74,26 @@ async function loginWithCredentials(email, password, prox = '', instance = 'shel
54
74
  }
55
75
  */
56
76
 
77
+ const endpoint = _useRegisterEndpoint ? 'signUp' : 'signInWithPassword';
78
+
57
79
  let SUCCESS = false;
58
80
  let request, body, token;
59
81
  let k = 0;
60
82
 
61
83
  while (!SUCCESS) {
62
84
  try {
63
- request = await fetch('https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=' + FirebaseKey, {
64
- method: 'POST',
65
- body: JSON.stringify({
66
- email: email,
67
- password: password,
68
- returnSecureToken: true
69
- }),
85
+ request = await axios.post(`https://identitytoolkit.googleapis.com/v1/accounts:${endpoint}?key=${FirebaseKey}`, {
86
+ email: email,
87
+ password: password,
88
+ returnSecureToken: true
89
+ }, {
70
90
  headers: {
71
91
  'user-agent': UserAgent,
72
92
  'x-client-version': 'Chrome/JsCore/9.17.2/FirebaseCore-web'
73
- }
93
+ },
94
+ httpsAgent: (!IsBrowser && prox) ? new SocksProxyAgent(prox) : false
74
95
  })
75
- body = await request.json();
96
+ body = request.data
76
97
  token = body.idToken;
77
98
  SUCCESS = true;
78
99
  } catch (error) {
@@ -87,8 +108,7 @@ async function loginWithCredentials(email, password, prox = '', instance = 'shel
87
108
  }
88
109
 
89
110
  if (k > 5) return 'firebase_too_many_retries';
90
-
91
- await new Promise((resolve) => setTimeout(resolve, 100));
111
+ else await new Promise((resolve) => setTimeout(resolve, 100));
92
112
  }
93
113
  }
94
114
 
@@ -105,17 +125,69 @@ async function loginWithCredentials(email, password, prox = '', instance = 'shel
105
125
  return response;
106
126
  }
107
127
 
128
+ async function loginWithRefreshToken(refreshToken, prox = '', instance = 'shellshock.io') {
129
+ if (!refreshToken) return 'firebase_no_credentials';
130
+
131
+ const formData = new URLSearchParams();
132
+ formData.append('grant_type', 'refresh_token');
133
+ formData.append('refresh_token', refreshToken);
134
+
135
+ let SUCCESS = false;
136
+ let request, body, token;
137
+ let k = 0;
138
+
139
+ while (!SUCCESS) {
140
+ try {
141
+ request = await axios.post(`https://securetoken.googleapis.com/v1/token?key=${FirebaseKey}`, formData, {
142
+ headers: {
143
+ 'user-agent': UserAgent,
144
+ 'x-client-version': 'Chrome/JsCore/9.17.2/FirebaseCore-web'
145
+ },
146
+ httpsAgent: (!IsBrowser && prox) ? new SocksProxyAgent(prox) : false
147
+ })
148
+ body = request.data
149
+ token = body.id_token;
150
+ SUCCESS = true;
151
+ } catch (error) {
152
+ ++k;
153
+ if (error.code == 'auth/network-request-failed') {
154
+ console.error('loginWithRefreshToken: Network req failed (auth/network-request-failed), retrying, k =', k);
155
+ } else if (error.code == 'auth/missing-email') {
156
+ return 'firebase_no_credentials';
157
+ } else {
158
+ console.error('loginWithRefreshToken: Error:', refreshToken);
159
+ console.error('loginWithRefreshToken: Error:', error, 'k =', k);
160
+ }
161
+
162
+ if (k > 5) return 'firebase_too_many_retries';
163
+ else await new Promise((resolve) => setTimeout(resolve, 100));
164
+ }
165
+ }
166
+
167
+ if (!token) {
168
+ console.error('loginWithRefreshToken: the game sent no idToken', body);
169
+ return 'firebase_no_token';
170
+ }
171
+
172
+ const response = await queryServices({
173
+ cmd: 'auth',
174
+ firebaseToken: token
175
+ }, prox, instance);
176
+
177
+ return response;
178
+ }
179
+
108
180
  async function loginAnonymously(prox = '', instance = 'shellshock.io') {
109
- const request = await fetch('https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=' + FirebaseKey, {
110
- method: 'POST',
111
- body: JSON.stringify({ returnSecureToken: true }),
181
+ const { data: body } = await axios.post('https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=' + FirebaseKey, {
182
+ returnSecureToken: true
183
+ }, {
112
184
  headers: {
113
185
  'user-agent': UserAgent,
114
186
  'x-client-version': 'Chrome/JsCore/9.17.2/FirebaseCore-web'
115
- }
116
- })
187
+ },
188
+ httpsAgent: (!IsBrowser && prox) ? new SocksProxyAgent(prox) : false
189
+ });
117
190
 
118
- const body = await request.json();
119
191
  const token = body.idToken;
120
192
 
121
193
  if (!token) {
@@ -132,7 +204,9 @@ async function loginAnonymously(prox = '', instance = 'shellshock.io') {
132
204
  }
133
205
 
134
206
  export {
207
+ createAccount,
135
208
  loginAnonymously,
136
209
  loginWithCredentials,
210
+ loginWithRefreshToken,
137
211
  queryServices
138
212
  }
@@ -13,7 +13,7 @@ export class GamePlayer {
13
13
 
14
14
  this.playing = playerData.playing_;
15
15
 
16
- this.social = playerData.social && JSON.parse(playerData.social_);
16
+ this.social = playerData.social_ && JSON.parse(playerData.social_);
17
17
  this.showBadge = !playerData.hideBadge_ || false;
18
18
 
19
19
  this.position = {
@@ -52,7 +52,7 @@ export class GamePlayer {
52
52
  this.weapons[1] = new Cluck9mm();
53
53
  }
54
54
 
55
- this.grenades = 0;
55
+ this.grenades = 1;
56
56
 
57
57
  this.buffer = {
58
58
  0: {},