Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
TheLazySquid
GitHub Repository: TheLazySquid/GimkitCheat
Path: blob/main/src/network/blueboat.js
8160 views
1
// this code was stolen from the original Gimkit Util extension
2
function n(t, e, n) {
3
for (var i = 0, s = 0, o = n.length; s < o; s++)(i = n.charCodeAt(s)) < 128 ? t.setUint8(e++, i) : (i < 2048 ? t.setUint8(e++, 192 | i >> 6) : (i < 55296 || 57344 <= i ? t.setUint8(e++, 224 | i >> 12) : (s++, i = 65536 + ((1023 & i) << 10 | 1023 & n.charCodeAt(s)), t.setUint8(e++, 240 | i >> 18), t.setUint8(e++, 128 | i >> 12 & 63)), t.setUint8(e++, 128 | i >> 6 & 63)), t.setUint8(e++, 128 | 63 & i))
4
}
5
6
function encode(t, e, s) {
7
let o;
8
9
if(Array.isArray(t)) {
10
o = {
11
type: 2,
12
data: t,
13
options: {
14
compress: !0
15
},
16
nsp: "/"
17
};
18
} else {
19
o = {
20
type: 2,
21
data: ["blueboat_SEND_MESSAGE", {
22
room: s,
23
key: t,
24
data: e
25
}],
26
options: {
27
compress: !0
28
},
29
nsp: "/"
30
};
31
}
32
33
return function(t) {
34
var e = [],
35
i = [],
36
s = function t(e, n, i) {
37
var s = typeof i,
38
o = 0,
39
r = 0,
40
a = 0,
41
c = 0,
42
l = 0,
43
u = 0;
44
if ("string" === s) {
45
if ((l = function(t) {
46
for (var e = 0, n = 0, i = 0, s = t.length; i < s; i++)(e = t.charCodeAt(i)) < 128 ? n += 1 : e < 2048 ? n += 2 : e < 55296 || 57344 <= e ? n += 3 : (i++, n += 4);
47
return n
48
}(i)) < 32) e.push(160 | l), u = 1;
49
else if (l < 256) e.push(217, l), u = 2;
50
else if (l < 65536) e.push(218, l >> 8, l), u = 3;
51
else {
52
if (!(l < 4294967296)) throw new Error("String too long");
53
e.push(219, l >> 24, l >> 16, l >> 8, l), u = 5
54
}
55
return n.push({
56
h: i,
57
u: l,
58
t: e.length
59
}), u + l
60
}
61
if ("number" === s) return Math.floor(i) === i && isFinite(i) ? 0 <= i ? i < 128 ? (e.push(i), 1) : i < 256 ? (e.push(204, i), 2) : i < 65536 ? (e.push(205, i >> 8, i), 3) : i < 4294967296 ? (e.push(206, i >> 24, i >> 16, i >> 8, i), 5) : (a = i / Math.pow(2, 32) >> 0, c = i >>> 0, e.push(207, a >> 24, a >> 16, a >> 8, a, c >> 24, c >> 16, c >> 8, c), 9) : -32 <= i ? (e.push(i), 1) : -128 <= i ? (e.push(208, i), 2) : -32768 <= i ? (e.push(209, i >> 8, i), 3) : -2147483648 <= i ? (e.push(210, i >> 24, i >> 16, i >> 8, i), 5) : (a = Math.floor(i / Math.pow(2, 32)), c = i >>> 0, e.push(211, a >> 24, a >> 16, a >> 8, a, c >> 24, c >> 16, c >> 8, c), 9) : (e.push(203), n.push({
62
o: i,
63
u: 8,
64
t: e.length
65
}), 9);
66
if ("object" === s) {
67
if (null === i) return e.push(192), 1;
68
if (Array.isArray(i)) {
69
if ((l = i.length) < 16) e.push(144 | l), u = 1;
70
else if (l < 65536) e.push(220, l >> 8, l), u = 3;
71
else {
72
if (!(l < 4294967296)) throw new Error("Array too large");
73
e.push(221, l >> 24, l >> 16, l >> 8, l), u = 5
74
}
75
for (o = 0; o < l; o++) u += t(e, n, i[o]);
76
return u
77
}
78
if (i instanceof Date) {
79
var h = i.getTime();
80
return a = Math.floor(h / Math.pow(2, 32)), c = h >>> 0, e.push(215, 0, a >> 24, a >> 16, a >> 8, a, c >> 24, c >> 16, c >> 8, c), 10
81
}
82
if (i instanceof ArrayBuffer) {
83
if ((l = i.byteLength) < 256) e.push(196, l), u = 2;
84
else if (l < 65536) e.push(197, l >> 8, l), u = 3;
85
else {
86
if (!(l < 4294967296)) throw new Error("Buffer too large");
87
e.push(198, l >> 24, l >> 16, l >> 8, l), u = 5
88
}
89
return n.push({
90
l: i,
91
u: l,
92
t: e.length
93
}), u + l
94
}
95
if ("function" == typeof i.toJSON) return t(e, n, i.toJSON());
96
var d = [],
97
f = "",
98
p = Object.keys(i);
99
for (o = 0, r = p.length; o < r; o++) "function" != typeof i[f = p[o]] && d.push(f);
100
if ((l = d.length) < 16) e.push(128 | l), u = 1;
101
else if (l < 65536) e.push(222, l >> 8, l), u = 3;
102
else {
103
if (!(l < 4294967296)) throw new Error("Object too large");
104
e.push(223, l >> 24, l >> 16, l >> 8, l), u = 5
105
}
106
for (o = 0; o < l; o++) u += t(e, n, f = d[o]), u += t(e, n, i[f]);
107
return u
108
}
109
if ("boolean" === s) return e.push(i ? 195 : 194), 1;
110
if ("undefined" === s) return e.push(212, 0, 0), 3;
111
throw new Error("Could not encode")
112
}(e, i, t),
113
o = new ArrayBuffer(s),
114
r = new DataView(o),
115
a = 0,
116
c = 0,
117
l = -1;
118
0 < i.length && (l = i[0].t);
119
for (var u, h = 0, d = 0, f = 0, p = e.length; f < p; f++)
120
if (r.setUint8(c + f, e[f]), f + 1 === l) {
121
if (h = (u = i[a]).u, d = c + l, u.l)
122
for (var g = new Uint8Array(u.l), E = 0; E < h; E++) r.setUint8(d + E, g[E]);
123
else u.h ? n(r, d, u.h) : void 0 !== u.o && r.setFloat64(d, u.o);
124
c += h, i[++a] && (l = i[a].t)
125
} let y = Array.from(new Uint8Array(o));
126
y.unshift(4)
127
return new Uint8Array(y).buffer
128
}(o)
129
}
130
131
function decode(packet) {
132
function e(t) {
133
if (this.t = 0, t instanceof ArrayBuffer) this.i = t, this.s = new DataView(this.i);
134
else {
135
if (!ArrayBuffer.isView(t)) return null;
136
this.i = t.buffer, this.s = new DataView(this.i, t.byteOffset, t.byteLength)
137
}
138
}
139
140
e.prototype.g = function(t) {
141
for (var e = new Array(t), n = 0; n < t; n++) e[n] = this.v();
142
return e
143
}, e.prototype.M = function(t) {
144
for (var e = {}, n = 0; n < t; n++) e[this.v()] = this.v();
145
return e
146
}, e.prototype.h = function(t) {
147
var e = function(t, e, n) {
148
for (var i = "", s = 0, o = e, r = e + n; o < r; o++) {
149
var a = t.getUint8(o);
150
if (0 != (128 & a))
151
if (192 != (224 & a))
152
if (224 != (240 & a)) {
153
if (240 != (248 & a)) throw new Error("Invalid byte " + a.toString(16));
154
65536 <= (s = (7 & a) << 18 | (63 & t.getUint8(++o)) << 12 | (63 & t.getUint8(++o)) << 6 | (63 & t.getUint8(++o)) << 0) ? (s -= 65536, i += String.fromCharCode(55296 + (s >>> 10), 56320 + (1023 & s))) : i += String.fromCharCode(s)
155
} else i += String.fromCharCode((15 & a) << 12 | (63 & t.getUint8(++o)) << 6 | (63 & t.getUint8(++o)) << 0);
156
else i += String.fromCharCode((31 & a) << 6 | 63 & t.getUint8(++o));
157
else i += String.fromCharCode(a)
158
}
159
return i
160
}(this.s, this.t, t);
161
return this.t += t, e
162
}, e.prototype.l = function(t) {
163
var e = this.i.slice(this.t, this.t + t);
164
return this.t += t, e
165
}, e.prototype.v = function() {
166
if(!this.s) return null;
167
var t, e = this.s.getUint8(this.t++),
168
n = 0,
169
i = 0,
170
s = 0,
171
o = 0;
172
if (e < 192) return e < 128 ? e : e < 144 ? this.M(15 & e) : e < 160 ? this.g(15 & e) : this.h(31 & e);
173
if (223 < e) return -1 * (255 - e + 1);
174
switch (e) {
175
case 192:
176
return null;
177
case 194:
178
return !1;
179
case 195:
180
return !0;
181
case 196:
182
return n = this.s.getUint8(this.t), this.t += 1, this.l(n);
183
case 197:
184
return n = this.s.getUint16(this.t), this.t += 2, this.l(n);
185
case 198:
186
return n = this.s.getUint32(this.t), this.t += 4, this.l(n);
187
case 199:
188
return n = this.s.getUint8(this.t), i = this.s.getInt8(this.t + 1), this.t += 2, [i, this.l(n)];
189
case 200:
190
return n = this.s.getUint16(this.t), i = this.s.getInt8(this.t + 2), this.t += 3, [i, this.l(n)];
191
case 201:
192
return n = this.s.getUint32(this.t), i = this.s.getInt8(this.t + 4), this.t += 5, [i, this.l(n)];
193
case 202:
194
return t = this.s.getFloat32(this.t), this.t += 4, t;
195
case 203:
196
return t = this.s.getFloat64(this.t), this.t += 8, t;
197
case 204:
198
return t = this.s.getUint8(this.t), this.t += 1, t;
199
case 205:
200
return t = this.s.getUint16(this.t), this.t += 2, t;
201
case 206:
202
return t = this.s.getUint32(this.t), this.t += 4, t;
203
case 207:
204
return s = this.s.getUint32(this.t) * Math.pow(2, 32), o = this.s.getUint32(this.t + 4), this.t += 8, s + o;
205
case 208:
206
return t = this.s.getInt8(this.t), this.t += 1, t;
207
case 209:
208
return t = this.s.getInt16(this.t), this.t += 2, t;
209
case 210:
210
return t = this.s.getInt32(this.t), this.t += 4, t;
211
case 211:
212
return s = this.s.getInt32(this.t) * Math.pow(2, 32), o = this.s.getUint32(this.t + 4), this.t += 8, s + o;
213
case 212:
214
return i = this.s.getInt8(this.t), this.t += 1, 0 === i ? void(this.t += 1) : [i, this.l(1)];
215
case 213:
216
return i = this.s.getInt8(this.t), this.t += 1, [i, this.l(2)];
217
case 214:
218
return i = this.s.getInt8(this.t), this.t += 1, [i, this.l(4)];
219
case 215:
220
return i = this.s.getInt8(this.t), this.t += 1, 0 === i ? (s = this.s.getInt32(this.t) * Math.pow(2, 32), o = this.s.getUint32(this.t + 4), this.t += 8, new Date(s + o)) : [i, this.l(8)];
221
case 216:
222
return i = this.s.getInt8(this.t), this.t += 1, [i, this.l(16)];
223
case 217:
224
return n = this.s.getUint8(this.t), this.t += 1, this.h(n);
225
case 218:
226
return n = this.s.getUint16(this.t), this.t += 2, this.h(n);
227
case 219:
228
return n = this.s.getUint32(this.t), this.t += 4, this.h(n);
229
case 220:
230
return n = this.s.getUint16(this.t), this.t += 2, this.g(n);
231
case 221:
232
return n = this.s.getUint32(this.t), this.t += 4, this.g(n);
233
case 222:
234
return n = this.s.getUint16(this.t), this.t += 2, this.M(n);
235
case 223:
236
return n = this.s.getUint32(this.t), this.t += 4, this.M(n)
237
}
238
throw new Error("Could not parse")
239
};
240
241
const q = function(t) {
242
var n = new e(t = t.slice(1)),
243
i = n.v();
244
if (n.t === t.byteLength) return i;
245
return null
246
}(packet);
247
248
return q?.data?.[1];
249
}
250
251
export default {
252
encode,
253
decode
254
}
255