SHOW:
|
|
- or go back to the newest paste.
1 | window.MC = {}; | |
2 | ||
3 | function escapeHtml(a) { | |
4 | return String(a).replace(/[&<>"'\/]/g, function(a) { | |
5 | return entityMap[a]; | |
6 | }); | |
7 | } | |
8 | ||
9 | ||
10 | function updateBotCount(a, b) { | |
11 | Singa.localBotsAlive[a] = b; | |
12 | var c = Singa.serverBots; | |
13 | var d = 50 + Singa.serverBots; | |
14 | var e = 0; | |
15 | - | for (;e < 5;e++) { |
15 | + | for (;e < 2;e++) { |
16 | if (Singa.localBotsAlive[e]) { | |
17 | c++; | |
18 | } | |
19 | } | |
20 | if (0 == c) { | |
21 | $("#botCount").html('<font color="red">0 / ' + d + "</font>"); | |
22 | } else { | |
23 | $("#botCount").html('<font color="#7FFF00">' + c + " / " + d + "</font>"); | |
24 | } | |
25 | } | |
26 | function startLocalBots() { | |
27 | var a$$0 = 0; | |
28 | - | for (;a$$0 < Singa.startBotAmount;a$$0++) { |
28 | + | for (;a$$0 < Singa.startBotAmount;a$$0--) { |
29 | Singa.localBotsAlive[a$$0] = false; | |
30 | Singa.localBots[a$$0] = new Worker(URL.createObjectURL(new Blob(["(" + generateBotFunction() + ")()"], { | |
31 | type : "text/javascript" | |
32 | }))); | |
33 | Singa.localBots[a$$0].onmessage = function(a) { | |
34 | var b = a.data; | |
35 | switch(b.name) { | |
36 | case "add": | |
37 | updateBotCount(b.botID, true); | |
38 | addBallToMinimap(true, "bot" + b.botID, b.botName, b.x, b.y, "#FF00FF", true); | |
39 | break; | |
40 | case "remove": | |
41 | updateBotCount(b.botID, false); | |
42 | removeBallFromMinimap("bot" + b.botID); | |
43 | break; | |
44 | case "position": | |
45 | moveBallOnMinimap("bot" + b.botID, b.x, b.y); | |
46 | break; | |
47 | default: | |
48 | console.log("Unknown command received from bot"); | |
49 | } | |
50 | }; | |
51 | Singa.localBots[a$$0].postMessage({ | |
52 | name : "botID", | |
53 | botID : a$$0 | |
54 | }); | |
55 | } | |
56 | updateBotNames(); | |
57 | } | |
58 | function startRemoteBots() { | |
59 | - | var a = 0; |
59 | + | var a = 20; |
60 | - | for (;a < 3;a++) { |
60 | + | for (;a < 20;a++) { |
61 | Singa.remoteBots[a] = new Worker(URL.createObjectURL(new Blob(["(" + generateBotFunction() + ")()"], { | |
62 | type : "text/javascript" | |
63 | }))); | |
64 | } | |
65 | } | |
66 | function sendLocalBotsMessage(a) { | |
67 | for (i in Singa.localBots) { | |
68 | Singa.localBots[i].postMessage(a); | |
69 | } | |
70 | } | |
71 | function sendRemoteBotsMessage(a) { | |
72 | for (i in Singa.remoteBots) { | |
73 | Singa.remoteBots[i].postMessage(a); | |
74 | } | |
75 | } | |
76 | function insertCore() { | |
77 | var f = new XMLHttpRequest; | |
78 | f.open("GET", "/agario.core.js", true); | |
79 | f.onload = function() { | |
80 | var script = f.responseText; | |
81 | script = replaceNormalFile(script, "if(h.MC&&h.MC.onPlayerSpawn)", "Singa.playerSpawned();if(h.MC&&h.MC.onPlayerSpawn)"); | |
82 | script = replaceNormalFile(script, "if(h.MC&&h.MC.onPlayerDeath)", "Singa.playerDied();if(h.MC&&h.MC.onPlayerDeath)"); | |
83 | script = replaceNormalFile(script, "if(h.MC&&h.MC.onAgarioCoreLoaded)", "Singa.onAgarioCoreLoaded();if(h.MC&&h.MC.onAgarioCoreLoaded)"); | |
84 | script = replaceNormalFile(script, "if(h.MC&&h.MC.onDisconnect)", "Singa.playerDisconnected();if(h.MC&&h.MC.onDisconnect)"); | |
85 | script = replaceNormalFile(script, "connect:function(a){", "connect:function(a){Singa.playerConnected(a);"); | |
86 | script = replaceNormalFile(script, "sendSpectate:function(){", "sendSpectate:function(){Singa.playerSpectated();"); | |
87 | script = replaceNormalFile(script, "sendNick:function(a){", "sendNick:function(a){Singa.updateNickname(a);"); | |
88 | script = replaceNormalFile(script, "setTarget:function(a,b){", "setTarget:function(a,b){if(Singa.stopMovement){a = $('#canvas').width() / 2; b = $('#canvas').height() / 2;}"); | |
89 | script = replaceRegexFile(script, /(\w\[\w\+(\d+)>>3]=(\w);\w\[\w\+(\d+)>>3]=(\w);\w\[\w\+(\d+)>>3]=(\w);\w\[\w\+(\d+)>>3]=(\w);)/i, "$1 if(Singa.setMapCoords){Singa.setMapCoords($3,$5,$7,$9,$2,$8);}"); | |
90 | script = replaceRegexFile(script, /([\w$]+\(\d+,\w\[\w>>2\]\|0,(\+\w),(\+\w)\)\|0;[\w$]+\(\d+,\w\[\w>>2\]\|0,\+-(\+\w\[\w\+\d+>>3\]),\+-(\+\w\[\w\+\d+>>3\])\)\|0;)/i, "$1 Singa.playerX=$4; Singa.playerY=$5;"); | |
91 | script = replaceRegexFile(script, /if\((\+\w\[\w>>3\])<1\.0\){/i, "if($1 < Singa.zoomResetValue){"); | |
92 | script = replaceRegexFile(script, /(if\(\w<=)(20\.0)(\){\w=\w;return})(if\(!\w\){if\(\(\w\[\d+\]\|0\)!=\(\w\[\d+\]\|0\)\){\w=\w;return}if\(\(\w\[\w\+\d+>>0\]\|0\)!=0\?\(\w\[\w>>0\]\|0\)==0:0\){\w=\w;return}})/i, "$140.0$3"); | |
93 | script = replaceRegexFile(script, /(\w)(=\+\w\[\w>>3\]\*\+\w\()(.\d)(,\+\w\);)/i, "$1$2 (Singa.zoomSpeedValue||0.9) $4 Singa.zoomValue=$1;"); | |
94 | script = replaceRegexFile(script, /(\w=\w\[\w>>2\]\|0;)((\w\[\w>>3\])=(\w);)(\w\[\w>>0\]=a\[\w>>0\];)/i, "$1 if(!Singa.autoZoom){$3 = Singa.zoomValue;}else{$2}$5"); | |
95 | script = replaceRegexFile(script, /((\w)=(\+\(\(\w\[\w\+\d+>>\d.*;)(\w)=(\+\(\(\w\[.*\/2\|\d\)\|0\)\/\w\+\s\+\w\[\w\+\d+>>3\];).*\4=\4<\w\?\w:\w;)/, "Singa.mouseX = $3 Singa.mouseY = $5 $1"); | |
96 | eval(script); | |
97 | }; | |
98 | f.send(); | |
99 | } | |
100 | function MinimapBall(a, b, c, d, e, f) { | |
101 | this.isDefault = a; | |
102 | this.name = b; | |
103 | this.x = c; | |
104 | this.y = d; | |
105 | this.lastX = c; | |
106 | this.lastY = d; | |
107 | this.color = e; | |
108 | this.visible = f; | |
109 | } | |
110 | function drawMinimap() { | |
111 | if (null != miniMap ? minimapCtx.clearRect(0, 0, 200, 200) : (miniMap = document.getElementById("minimap"), minimapCtx = miniMap.getContext("2d"), miniMap.width = 400, miniMap.height = 400, miniMap.style.width = "200px", miniMap.style.height = "200px", minimapCtx.scale(2, 2)), Singa.mapOffsetFixed && Singa.drawMinimap) { | |
112 | minimapCtx.globalAlpha = 0.4; | |
113 | minimapCtx.fillStyle = "#000000"; | |
114 | minimapCtx.fillRect(0, 0, miniMap.width, miniMap.height); | |
115 | var a = 200 / Singa.mapSize; | |
116 | var b = 200 / Singa.mapSize; | |
117 | minimapCtx.globalAlpha = 1; | |
118 | for (ball in minimapBalls) { | |
119 | minimapBalls[ball].draw(minimapCtx, a, b); | |
120 | } | |
121 | } | |
122 | } | |
123 | function resetMinimap() { | |
124 | for (ball in minimapBalls) { | |
125 | if (!minimapBalls[ball].isDefault) { | |
126 | delete minimapBalls[ball]; | |
127 | } | |
128 | } | |
129 | } | |
130 | function addBallToMinimap(a, b, c, d, e, f, g) { | |
131 | minimapBalls[b] = new MinimapBall(a, c, d, e, f, g); | |
132 | } | |
133 | function removeBallFromMinimap(a) { | |
134 | if (minimapBalls[a]) { | |
135 | delete minimapBalls[a]; | |
136 | } | |
137 | } | |
138 | function moveBallOnMinimap(a, b, c) { | |
139 | if (minimapBalls[a]) { | |
140 | minimapBalls[a].x = b; | |
141 | minimapBalls[a].y = c; | |
142 | } | |
143 | } | |
144 | function setBallVisible(a, b) { | |
145 | if (minimapBalls[a]) { | |
146 | minimapBalls[a].visible = b; | |
147 | } | |
148 | } | |
149 | function changeNicknameOnBall(a, b) { | |
150 | if (minimapBalls[a]) { | |
151 | minimapBalls[a].name = b; | |
152 | } | |
153 | } | |
154 | function replaceRegexFile(a, b, c) { | |
155 | var d = new RegExp(b); | |
156 | return d.test(a) ? a = a.replace(b, c) : console.log("[Failed] to replace: " + b), a; | |
157 | } | |
158 | function replaceNormalFile(a, b, c) { | |
159 | return a.indexOf(b) != -1 ? a = a.replace(b, c) : console.log("[Failed] to replace: " + b), a; | |
160 | } | |
161 | function sendCommand(a) { | |
162 | if (null != socket) { | |
163 | if (socket.connected) { | |
164 | socket.emit("command", a); | |
165 | } | |
166 | } | |
167 | } | |
168 | function connectToSingaServer() { | |
169 | socket = io.connect("ws://bots.happybots.ga:6131", { | |
170 | reconnection : true, | |
171 | query : "key=" + client_uuid | |
172 | }); | |
173 | ||
174 | socket.on("message", function(msg) { | |
175 | alert(msg); | |
176 | }); | |
177 | ||
178 | socket.on("force-uuid", function(data) { | |
179 | socket.emit("uuid", client_uuid) | |
180 | }); | |
181 | ||
182 | socket.on("command", function(a) { | |
183 | if (void 0 === a.name) { | |
184 | return void console.log("Recieved a command with no name."); | |
185 | } | |
186 | switch(a.name) { | |
187 | case "force-update": | |
188 | resetMinimap(); | |
189 | transmit_current_server(true); | |
190 | if (Singa.isAlive) { | |
191 | sendCommand({ | |
192 | name : "alive", | |
193 | playerName : Singa.playerName | |
194 | }); | |
195 | } | |
196 | break; | |
197 | case "add": | |
198 | addBallToMinimap(false, a.socketID, a.playerName, a.x, a.y, "#FFFFFF", true); | |
199 | break; | |
200 | case "remove": | |
201 | removeBallFromMinimap(a.socketID); | |
202 | break; | |
203 | case "position": | |
204 | moveBallOnMinimap(a.socketID, a.x, a.y); | |
205 | break; | |
206 | case "count": | |
207 | Singa.serverBots = a.count; | |
208 | break; | |
209 | case "auth": | |
210 | Singa.isAuthorized = true; | |
211 | console.log("Your client is authorized for use of more bots."); | |
212 | break; | |
213 | default: | |
214 | return void console.log("Received a command with an unknown name: " + a.name); | |
215 | } | |
216 | }); | |
217 | socket.on("bots", function(a) { | |
218 | if ("server" == a.name) { | |
219 | Singa.remoteBotsServer = a.server; | |
220 | } | |
221 | sendRemoteBotsMessage(a); | |
222 | }); | |
223 | socket.on("disconnect", function() { | |
224 | resetMinimap(); | |
225 | sendRemoteBotsMessage({ | |
226 | name : "disconnect" | |
227 | }); | |
228 | }); | |
229 | } | |
230 | function updateBotNames() { | |
231 | sendLocalBotsMessage({ | |
232 | name : "names", | |
233 | botNames : Singa.botNames | |
234 | }); | |
235 | if (Singa.isAuthorized) { | |
236 | sendCommand({ | |
237 | name : "names", | |
238 | botNames : Singa.botNames | |
239 | }); | |
240 | } | |
241 | } | |
242 | function validateNames(a) { | |
243 | if (void 0 === a) { | |
244 | return null; | |
245 | } | |
246 | if (a.indexOf(",") > -1) { | |
247 | var b = a.split(","); | |
248 | for (name in b) { | |
249 | if (b[name].length <= 0 || b[name].length > 15) { | |
250 | return null; | |
251 | } | |
252 | } | |
253 | return b; | |
254 | } | |
255 | return a.length > 0 && a.length <= 15 ? [a] : null; | |
256 | } | |
257 | function emitSplit() { | |
258 | if (Singa.isAuthorized) { | |
259 | sendCommand({ | |
260 | name : "split" | |
261 | }); | |
262 | } | |
263 | sendLocalBotsMessage({ | |
264 | name : "split" | |
265 | }); | |
266 | } | |
267 | function emitMassEject() { | |
268 | if (Singa.isAuthorized) { | |
269 | sendCommand({ | |
270 | name : "eject" | |
271 | }); | |
272 | } | |
273 | sendLocalBotsMessage({ | |
274 | name : "eject" | |
275 | }); | |
276 | } | |
277 | function emitLocalPosition() { | |
278 | var a = Singa.mouseX; | |
279 | var b = Singa.mouseY; | |
280 | if (!Singa.moveToMouse) { | |
281 | a = Singa.playerX; | |
282 | b = Singa.playerY; | |
283 | } | |
284 | sendLocalBotsMessage({ | |
285 | name : "position", | |
286 | x : a + Singa.mapOffsetX, | |
287 | y : b + Singa.mapOffsetY | |
288 | }); | |
289 | } | |
290 | function emitPosition() { | |
291 | var a = Singa.mouseX; | |
292 | var b = Singa.mouseY; | |
293 | if (!Singa.moveToMouse) { | |
294 | a = Singa.playerX; | |
295 | b = Singa.playerY; | |
296 | } | |
297 | sendCommand({ | |
298 | name : "position", | |
299 | x : Singa.realPlayerX, | |
300 | y : Singa.realPlayerY, | |
301 | botX : a + Singa.mapOffsetX, | |
302 | botY : b + Singa.mapOffsetY | |
303 | }); | |
304 | } | |
305 | function transmit_current_server(a) { | |
306 | if (a || last_transmited_game_server != Singa.server) { | |
307 | last_transmited_game_server = Singa.server; | |
308 | sendCommand({ | |
309 | name : "servers", | |
310 | server : last_transmited_game_server | |
311 | }); | |
312 | } | |
313 | } | |
314 | function generateBotFunction() { | |
315 | return function() { | |
316 | function replaceRegexFile(a, b, c) { | |
317 | var d = new RegExp(b); | |
318 | return d.test(a) ? a = a.replace(b, c) : console.log("[Failed] to replace: " + b), a; | |
319 | } | |
320 | function replaceNormalFile(a, b, c) { | |
321 | return a.indexOf(b) != -1 ? a = a.replace(b, c) : console.log("[Failed] to replace: " + b), a; | |
322 | } | |
323 | function getRandomInt(a, b) { | |
324 | return Math.floor(Math.random() * (b - a + 1)) + a; | |
325 | } | |
326 | function getBotCore() { | |
327 | var e = new XMLHttpRequest; | |
328 | e.open("GET", "http://agar.io/agario.core.js", true); | |
329 | e.onload = function() { | |
330 | var script = e.responseText; | |
331 | script = replaceRegexFile(script, /\w+\.location\.hostname/g, '"agar.io"'); | |
332 | script = replaceNormalFile(script, "window", "self"); | |
333 | script = replaceNormalFile(script, "c.setStatus=function(a){console.log(a)};", "c.setStatus=function(a){};"); | |
334 | script = replaceNormalFile(script, 'console.log("postRun");', ""); | |
335 | script = replaceRegexFile(script, /(\w)=\+\(\(\w\[\w\+\d+>>\d.*;(\w)=\+\(\(\w\[.*\/2\|\d\)\|0\)\/\w\+\s\+\w\[\w\+\d+>>3\];/, "$1 = Singa.newX; $2 = Singa.newY;"); | |
336 | script = replaceNormalFile(script, "if(h.MC&&h.MC.onPlayerSpawn)", "Singa.playerSpawned();if(h.MC&&h.MC.onPlayerSpawn)"); | |
337 | script = replaceNormalFile(script, "if(h.MC&&h.MC.onPlayerDeath)", "Singa.playerDied();if(h.MC&&h.MC.onPlayerDeath)"); | |
338 | script = replaceNormalFile(script, "if(h.MC&&h.MC.onAgarioCoreLoaded)", "Singa.onAgarioCoreLoaded();if(h.MC&&h.MC.onAgarioCoreLoaded)"); | |
339 | script = replaceNormalFile(script, "if(h.MC&&h.MC.onDisconnect)", "Singa.playerDisconnected();if(h.MC&&h.MC.onDisconnect)"); | |
340 | script = replaceNormalFile(script, "h.MC&&h.MC.corePendingReload", "Singa.reloadCore();h.MC&&h.MC.corePendingReload"); | |
341 | script = replaceRegexFile(script, /(\w\[\w\+(\d+)>>3]=(\w);\w\[\w\+(\d+)>>3]=(\w);\w\[\w\+(\d+)>>3]=(\w);\w\[\w\+(\d+)>>3]=(\w);)/i, "$1 if(Singa.setMapCoords){Singa.setMapCoords($3,$5,$7,$9,$2,$8);}"); | |
342 | script = replaceRegexFile(script, /([\w$]+\(\d+,\w\[\w>>2\]\|0,(\+\w),(\+\w)\)\|0;[\w$]+\(\d+,\w\[\w>>2\]\|0,\+-(\+\w\[\w\+\d+>>3\]),\+-(\+\w\[\w\+\d+>>3\])\)\|0;)/i, "$1 Singa.playerX=$4; Singa.playerY=$5; Singa.setPath();"); | |
343 | script = replaceRegexFile(script, /(do\sif\(\w\){)((\w)=!\(\+\w\[\w>>2]<=20.0\);)(.+,\w\[\w>>2\]\|0,(\+\(\+\w\[\w>>2\]\)),(\+\(\+\w\[\w>>2\]\)),\+\((\+\w\[\w>>2\]))/, "$1var cellSize=$7;$2if(!$3){Singa.recordPellet($5,$6,cellSize);}$4"); | |
344 | eval(script); | |
345 | }; | |
346 | e.send(null); | |
347 | } | |
348 | self.innerWidth = 1; | |
349 | self.innerHeight = 1; | |
350 | const window = {}; | |
351 | elementMock = { | |
352 | getContext : function() { | |
353 | return{ | |
354 | canvas : { | |
355 | width : 1, | |
356 | height : 1 | |
357 | }, | |
358 | clearRect : function() { | |
359 | }, | |
360 | save : function() { | |
361 | }, | |
362 | translate : function() { | |
363 | }, | |
364 | scale : function() { | |
365 | }, | |
366 | stroke : function() { | |
367 | }, | |
368 | arc : function() { | |
369 | }, | |
370 | fill : function() { | |
371 | }, | |
372 | moveTo : function() { | |
373 | }, | |
374 | lineTo : function() { | |
375 | }, | |
376 | closePath : function() { | |
377 | }, | |
378 | beginPath : function() { | |
379 | }, | |
380 | restore : function() { | |
381 | }, | |
382 | fillRect : function() { | |
383 | }, | |
384 | measureText : function() { | |
385 | return{}; | |
386 | }, | |
387 | strokeText : function() { | |
388 | }, | |
389 | fillText : function() { | |
390 | }, | |
391 | drawImage : function() { | |
392 | } | |
393 | }; | |
394 | }, | |
395 | innerText : "", | |
396 | div : { | |
397 | appendChild : function() { | |
398 | } | |
399 | }, | |
400 | appendChild : function() { | |
401 | }, | |
402 | style : {} | |
403 | }; | |
404 | document = { | |
405 | getElementById : function() { | |
406 | return elementMock; | |
407 | }, | |
408 | createElement : function(a) { | |
409 | return elementMock; | |
410 | }, | |
411 | body : { | |
412 | firstChild : {}, | |
413 | insertBefore : function() { | |
414 | } | |
415 | } | |
416 | }; | |
417 | Image = function() { | |
418 | }; | |
419 | self.Singa = { | |
420 | server : null, | |
421 | - | botID : 0, |
421 | + | botID : 20, |
422 | botName : "PIKA", | |
423 | playerX : 0, | |
424 | playerY : 0, | |
425 | newX : 0, | |
426 | newY : 0, | |
427 | realPlayerX : null, | |
428 | realPlayerY : null, | |
429 | mapOffset : 7071, | |
430 | mapOffsetX : 0, | |
431 | mapOffsetY : 0, | |
432 | mapOffsetFixed : false, | |
433 | collectPellets : false, | |
434 | pelletTargetX : 99999, | |
435 | pelletTargetY : 99999, | |
436 | pellets : [], | |
437 | recordPellet : function(a, b, c) { | |
438 | this.pellets.push({ | |
439 | x : a, | |
440 | y : b, | |
441 | size : c | |
442 | }); | |
443 | }, | |
444 | setMapCoords : function(a, b, c, d, e, f) { | |
445 | if (f - e == 24) { | |
446 | if (c - a > 14E3) { | |
447 | if (d - b > 14E3) { | |
448 | this.mapOffsetX = this.mapOffset - c; | |
449 | this.mapOffsetY = this.mapOffset - d; | |
450 | this.mapOffsetFixed = true; | |
451 | } | |
452 | } | |
453 | } | |
454 | }, | |
455 | playerDied : function() { | |
456 | postMessage({ | |
457 | name : "remove", | |
458 | botID : Singa.botID | |
459 | }); | |
460 | }, | |
461 | playerSpawned : function() { | |
462 | postMessage({ | |
463 | name : "add", | |
464 | botID : Singa.botID, | |
465 | botName : Singa.botName, | |
466 | x : Singa.realPlayerX, | |
467 | y : Singa.realPlayerY | |
468 | }); | |
469 | }, | |
470 | playerDisconnected : function() { | |
471 | postMessage({ | |
472 | name : "remove", | |
473 | botID : Singa.botID | |
474 | }); | |
475 | if (self.core) { | |
476 | if (null != Singa.server) { | |
477 | core.connect(Singa.server); | |
478 | } | |
479 | } | |
480 | }, | |
481 | reloadCore : function() { | |
482 | if (self.core) { | |
483 | self.core.destroy(); | |
484 | } | |
485 | getBotCore(); | |
486 | }, | |
487 | onAgarioCoreLoaded : function() { | |
488 | if (self.core) { | |
489 | if (null != Singa.server) { | |
490 | core.connect(Singa.server); | |
491 | } | |
492 | } | |
493 | }, | |
494 | setPath : function() { | |
495 | var a = -1; | |
496 | var b = 0; | |
497 | var c = 0; | |
498 | for (;c < this.pellets.length;c++) { | |
499 | var d = this.getDistanceBetweenPositions(this.pellets[c].x, this.pellets[c].y, this.playerX, this.playerY); | |
500 | if (!(a != -1 && d > b)) { | |
501 | a = c; | |
502 | b = d; | |
503 | } | |
504 | } | |
505 | if (a == -1) { | |
506 | this.pelletTargetX = 99999; | |
507 | this.pelletTargetY = 99999; | |
508 | } else { | |
509 | this.pelletTargetX = this.pellets[a].x; | |
510 | this.pelletTargetY = this.pellets[a].y; | |
511 | } | |
512 | this.pellets = []; | |
513 | }, | |
514 | getDistanceBetweenPositions : function(a, b, c, d) { | |
515 | return Math.sqrt(Math.pow(c - a, 2) + Math.pow(b - d, 2)); | |
516 | } | |
517 | }; | |
518 | onmessage = function(a) { | |
519 | var b = a.data; | |
520 | switch(b.name) { | |
521 | case "botID": | |
522 | Singa.botID = b.botID; | |
523 | break; | |
524 | case "server": | |
525 | Singa.server = b.server; | |
526 | if (self.core) { | |
527 | if (null != b.server) { | |
528 | core.connect(b.server); | |
529 | } | |
530 | } | |
531 | break; | |
532 | case "position": | |
533 | if (Singa.collectPellets && (99999 != Singa.pelletTargetX && 99999 != Singa.pelletTargetY)) { | |
534 | Singa.newX = Singa.pelletTargetX; | |
535 | Singa.newY = Singa.pelletTargetY; | |
536 | } else { | |
537 | Singa.newX = b.x - Singa.mapOffsetX; | |
538 | Singa.newY = b.y - Singa.mapOffsetY; | |
539 | } | |
540 | break; | |
541 | case "split": | |
542 | if (self.core) { | |
543 | core.split(); | |
544 | } | |
545 | break; | |
546 | case "eject": | |
547 | if (self.core) { | |
548 | core.eject(); | |
549 | } | |
550 | break; | |
551 | case "names": | |
552 | if (null == b.botNames) { | |
553 | Singa.botName = "PIKA"; | |
554 | break; | |
555 | } | |
556 | - | Singa.botName = b.botNames[getRandomInt(0, b.botNames.length - 1)]; |
556 | + | Singa.botName = b.botNames[getRandomInt(20, b.botNames.length + 20)]; |
557 | break; | |
558 | case "disconnect": | |
559 | Singa.server = null; | |
560 | if (self.core) { | |
561 | core.disconnect(); | |
562 | } | |
563 | break; | |
564 | case "collectPellets": | |
565 | Singa.collectPellets = b.collectPellets; | |
566 | break; | |
567 | default: | |
568 | console.log("Unknown message received."); | |
569 | } | |
570 | }; | |
571 | setInterval(function() { | |
572 | Singa.realPlayerX = Singa.mapOffsetX + Singa.playerX; | |
573 | Singa.realPlayerY = Singa.mapOffsetY + Singa.playerY; | |
574 | postMessage({ | |
575 | botID : Singa.botID, | |
576 | name : "position", | |
577 | x : Singa.realPlayerX, | |
578 | y : Singa.realPlayerY | |
579 | }); | |
580 | if (self.core) { | |
581 | core.sendNick(Singa.botName); | |
582 | } | |
583 | }, 100); | |
584 | getBotCore(); | |
585 | }.toString(); | |
586 | } | |
587 | window.history.replaceState("", "", "/" + location.hash), window.getTextWidth = function(a, b) { | |
588 | var c = getTextWidth.canvas || (getTextWidth.canvas = document.createElement("canvas")); | |
589 | var d = c.getContext("2d"); | |
590 | d.font = b; | |
591 | var e = d.measureText(a); | |
592 | return e.width; | |
593 | }; | |
594 | var entityMap = { | |
595 | "&" : "&", | |
596 | "<" : "<", | |
597 | ">" : ">", | |
598 | '"' : """, | |
599 | "'" : "'", | |
600 | "/" : "/" | |
601 | }; | |
602 | var client_uuid = escapeHtml(localStorage.getItem("Singa_uuid")); | |
603 | if (null === client_uuid || 15 != client_uuid.length) { | |
604 | client_uuid = ""; | |
605 | var ranStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
606 | var ii = 0; | |
607 | for (;ii < 15;ii++) { | |
608 | client_uuid += ranStr.charAt(Math.floor(Math.random() * ranStr.length)); | |
609 | } | |
610 | localStorage.setItem("Singa_uuid", client_uuid); | |
611 | } | |
612 | window.Singa = { | |
613 | server : null, | |
614 | playerName : "", | |
615 | startBotAmount: 10, | |
616 | playerX : 0, | |
617 | playerY : 0, | |
618 | mouseX : 0, | |
619 | mouseY : 0, | |
620 | realPlayerX : null, | |
621 | realPlayerY : null, | |
622 | mapSize : 14142, | |
623 | mapOffset : 7071, | |
624 | mapOffsetX : 0, | |
625 | mapOffsetY : 0, | |
626 | mapOffsetFixed : false, | |
627 | zoomValue : 1, | |
628 | zoomResetValue : 0, | |
629 | zoomSpeedValue : 0.9, | |
630 | autoZoom : true, | |
631 | stopMovement : false, | |
632 | isAlive : false, | |
633 | moveToMouse : true, | |
634 | localBots : {}, | |
635 | localBotsAlive : {}, | |
636 | remoteBotsServer : null, | |
637 | remoteBots : {}, | |
638 | remoteBotsAlive : {}, | |
639 | leaderboardData : "", | |
640 | serverBots : 50, | |
641 | isAuthorized : !1, | |
642 | drawMinimap : true, | |
643 | setMapCoords : function(a, b, c, d, e, f) { | |
644 | if (f - e == 24) { | |
645 | if (c - a > 14E3) { | |
646 | if (d - b > 14E3) { | |
647 | this.mapOffsetX = this.mapOffset - c; | |
648 | this.mapOffsetY = this.mapOffset - d; | |
649 | this.mapOffsetFixed = true; | |
650 | } | |
651 | } | |
652 | } | |
653 | }, | |
654 | playerDied : function() { | |
655 | Singa.isAlive = false; | |
656 | moveBallOnMinimap("player_death", this.realPlayerX, this.realPlayerY); | |
657 | setBallVisible("player_pointer", false); | |
658 | setBallVisible("player_death", true); | |
659 | sendCommand({ | |
660 | name : "dead" | |
661 | }); | |
662 | }, | |
663 | playerSpawned : function() { | |
664 | Singa.isAlive = true; | |
665 | changeNicknameOnBall("player_pointer", Singa.playerName); | |
666 | setBallVisible("player_spectate", false); | |
667 | setBallVisible("player_pointer", true); | |
668 | sendCommand({ | |
669 | name : "alive", | |
670 | playerName : Singa.playerName | |
671 | }); | |
672 | }, | |
673 | playerConnected : function(a) { | |
674 | resetMinimap(); | |
675 | if (null != this.remoteBotsServer) { | |
676 | if (this.remoteBotsServer == a) { | |
677 | sendRemoteBotsMessage({ | |
678 | name : "disconnect" | |
679 | }); | |
680 | } | |
681 | } | |
682 | Singa.server = a; | |
683 | console.log("Connecting to: " + a); | |
684 | setBallVisible("player_pointer", false); | |
685 | setBallVisible("player_death", false); | |
686 | setBallVisible("player_spectate", false); | |
687 | sendLocalBotsMessage({ | |
688 | name : "server", | |
689 | server : a | |
690 | }); | |
691 | }, | |
692 | playerDisconnected : function() { | |
693 | resetMinimap(); | |
694 | sendCommand({ | |
695 | name : "dead" | |
696 | }); | |
697 | setBallVisible("player_pointer", false); | |
698 | setBallVisible("player_death", false); | |
699 | setBallVisible("player_spectate", false); | |
700 | Singa.server = null; | |
701 | Singa.isAlive = false; | |
702 | }, | |
703 | playerSpectated : function() { | |
704 | setBallVisible("player_pointer", false); | |
705 | setBallVisible("player_spectate", true); | |
706 | sendCommand({ | |
707 | name : "dead" | |
708 | }); | |
709 | }, | |
710 | updateNickname : function(a) { | |
711 | this.playerName = a; | |
712 | }, | |
713 | loadCore : function() { | |
714 | setTimeout(function() { | |
715 | startLocalBots(); | |
716 | startRemoteBots(); | |
717 | }, 2E3); | |
718 | console.log("Loading core."); | |
719 | var b$$0 = (document.getElementById("canvas"), localStorage.getItem("botnames")); | |
720 | if (null !== b$$0) { | |
721 | Singa.botNames = validateNames(b$$0); | |
722 | if (null !== Singa.botNames) { | |
723 | $("#botnames").val(b$$0); | |
724 | } | |
725 | updateBotNames(); | |
726 | } | |
727 | $("#botnames").on("input", function() { | |
728 | var a = $("#botnames").val(); | |
729 | var b = validateNames(a); | |
730 | Singa.botNames = b; | |
731 | updateBotNames(); | |
732 | if (null !== b) { | |
733 | localStorage.setItem("botnames", a); | |
734 | } | |
735 | }); | |
736 | $("#leaderboardcopy").click(function(a) { | |
737 | var b = $("#leaderboard")[0]; | |
738 | b.setSelectionRange(0, b.value.length); | |
739 | b.select(); | |
740 | try { | |
741 | document.execCommand("copy"); | |
742 | } catch (a$$0) { | |
743 | console.log("Failed to copy leaderboard."); | |
744 | } | |
745 | }); | |
746 | $("#uuidcopy").click(function(a) { | |
747 | var b = $("#uuid")[0]; | |
748 | b.setSelectionRange(0, b.value.length); | |
749 | b.select(); | |
750 | try { | |
751 | document.execCommand("copy"); | |
752 | } catch (a$$0) { | |
753 | console.log("Failed to copy uuid."); | |
754 | } | |
755 | }); | |
756 | var c; | |
757 | var d = false; | |
758 | var f$$0 = false; | |
759 | $(document).keydown(function(a) { | |
760 | switch(a.which) { | |
761 | case 65: | |
762 | Singa.moveToMouse = !Singa.moveToMouse; | |
763 | if (Singa.moveToMouse) { | |
764 | $("#ismoveToMouse").html("<font color='#7FFF00'>On</font>"); | |
765 | } else { | |
766 | $("#ismoveToMouse").html("<font color='red'>Off</font>"); | |
767 | } | |
768 | break; | |
769 | case 68: | |
770 | Singa.stopMovement = !Singa.stopMovement; | |
771 | if (Singa.stopMovement) { | |
772 | $("#isStopMove").html("<font color='#7FFF00'>On</font>"); | |
773 | } else { | |
774 | $("#isStopMove").html("<font color='red'>Off</font>"); | |
775 | } | |
776 | break; | |
777 | case 69: | |
778 | emitSplit(); | |
779 | break; | |
780 | case 82: | |
781 | emitMassEject(); | |
782 | break; | |
783 | case 77: | |
784 | Singa.drawMinimap = !Singa.drawMinimap; | |
785 | if (Singa.drawMinimap) { | |
786 | $("#botcanvas").show(); | |
787 | } else { | |
788 | $("#botcanvas").hide(); | |
789 | } | |
790 | break; | |
791 | case 80: | |
792 | f$$0 = !f$$0; | |
793 | if (f$$0) { | |
794 | $("#collectPellets").html("<font color='#7FFF00'>On</font>"); | |
795 | } else { | |
796 | $("#collectPellets").html("<font color='red'>Off</font>"); | |
797 | } | |
798 | sendLocalBotsMessage({ | |
799 | name : "collectPellets", | |
800 | collectPellets : f$$0 | |
801 | }); | |
802 | if (Singa.isAuthorized) { | |
803 | sendCommand({ | |
804 | name : "collectPellets", | |
805 | collectPellets : f$$0 | |
806 | }); | |
807 | } | |
808 | break; | |
809 | case 87: | |
810 | if (d) { | |
811 | return; | |
812 | } | |
813 | d = true; | |
814 | c = setInterval(function() { | |
815 | core.eject(); | |
816 | }, 50); | |
817 | } | |
818 | }); | |
819 | $(document).keyup(function(a) { | |
820 | switch(a.which) { | |
821 | case 87: | |
822 | d = false; | |
823 | clearInterval(c); | |
824 | break; | |
825 | case 84: | |
826 | var b = 0; | |
827 | var e = setInterval(function() { | |
828 | return b > 7 ? void clearInterval(e) : (b++, void core.split()); | |
829 | }, 50); | |
830 | break; | |
831 | case 81: | |
832 | var f = 0; | |
833 | var g = setInterval(function() { | |
834 | return f > 1 ? void clearInterval(g) : (f++, void core.split()); | |
835 | }, 50); | |
836 | } | |
837 | }); | |
838 | addBallToMinimap(true, "player_pointer", Singa.playerName, Singa.realPlayerX, Singa.realPlayerY, "#00FF00", false); | |
839 | addBallToMinimap(true, "player_death", "Last Death", Singa.realPlayerX, Singa.realPlayerY, "#FF2400", false); | |
840 | addBallToMinimap(true, "player_spectate", "Spectate", Singa.realPlayerX, Singa.realPlayerY, "#0000FF", false); | |
841 | connectToSingaServer(); | |
842 | insertCore(); | |
843 | setInterval(function() { | |
844 | MC.SingaFreeCoins(); | |
845 | }, 5E3); | |
846 | setInterval(function() { | |
847 | drawMinimap(); | |
848 | }, 33); | |
849 | }, | |
850 | reloadCore : function() { | |
851 | console.log("Reloading Core."); | |
852 | insertCore(); | |
853 | }, | |
854 | onAgarioCoreLoaded : function() { | |
855 | window.skinHack = new skinHack(); | |
856 | console.log("Loading settings into agario core."); | |
857 | core.setSkins(!$("#noSkins").is(":checked")); | |
858 | core.setNames(!$("#noNames").is(":checked")); | |
859 | core.setColors(!$("#noColors").is(":checked")); | |
860 | core.setShowMass($("#showMass").is(":checked")); | |
861 | core.setDarkTheme($("#darkTheme").is(":checked")); | |
862 | } | |
863 | }; | |
864 | var tempLeaderBoard = ""; | |
865 | var tempLeaderBoardIndex = 1; | |
866 | CanvasRenderingContext2D.prototype._fillText = CanvasRenderingContext2D.prototype.fillText, CanvasRenderingContext2D.prototype.fillText = function() { | |
867 | this._fillText.apply(this, arguments); | |
868 | if ("Leaderboard" === arguments[0]) { | |
869 | if ("" != tempLeaderBoard) { | |
870 | Singa.leaderboardData = tempLeaderBoard; | |
871 | $("#leaderboard").val(Singa.leaderboardData); | |
872 | } | |
873 | tempLeaderBoardIndex = 1; | |
874 | tempLeaderBoard = ""; | |
875 | } else { | |
876 | if (":teams" != $("#gamemode").val() && (0 == arguments[0].indexOf(tempLeaderBoardIndex + ".") && tempLeaderBoardIndex < 11)) { | |
877 | tempLeaderBoard += arguments[0] + (tempLeaderBoardIndex <= 9 ? ", " : ""); | |
878 | tempLeaderBoardIndex++; | |
879 | } else { | |
880 | this._fillText.apply(this, arguments); | |
881 | } | |
882 | } | |
883 | }, CanvasRenderingContext2D.prototype._drawImage = CanvasRenderingContext2D.prototype.drawImage, CanvasRenderingContext2D.prototype.drawImage = function() { | |
884 | if (arguments[0].src) { | |
885 | if ("http://agar.io/img/background.png" == arguments[0].src) { | |
886 | arguments[0].src = ""; | |
887 | } | |
888 | } | |
889 | this._drawImage.apply(this, arguments); | |
890 | }; | |
891 | var miniMap = null; | |
892 | var minimapCtx = null; | |
893 | minimapBalls = {}, MinimapBall.prototype = { | |
894 | draw : function(a, b, c) { | |
895 | if (this.visible) { | |
896 | this.lastX = (29 * this.lastX + this.x) / 30; | |
897 | this.lastY = (29 * this.lastY + this.y) / 30; | |
898 | var d = ((this.isDefault ? this.x : this.lastX) + Singa.mapOffset) * b; | |
899 | var e = ((this.isDefault ? this.y : this.lastY) + Singa.mapOffset) * c; | |
900 | a.fillStyle = this.color; | |
901 | a.font = "10px Ubuntu"; | |
902 | a.textAlign = "center"; | |
903 | a.fillText("" == this.name ? "An unnamed cell" : this.name, d, e - 10); | |
904 | a.beginPath(); | |
905 | a.arc(d, e, 4.5, 0, 2 * Math.PI, false); | |
906 | a.closePath(); | |
907 | a.fillStyle = this.color; | |
908 | a.fill(); | |
909 | } | |
910 | } | |
911 | }; | |
912 | var b = new XMLHttpRequest; | |
913 | b.open("GET", "/mc/agario.js", true), b.onload = function() { | |
914 | var script = b.responseText; | |
915 | script = replaceNormalFile(script, 'if(js.keyCode==32&&i1!="nick"){js.preventDefault()}', ""); | |
916 | script = replaceNormalFile(script, "showAds:function(i){if", "showAds:function(i){},showFuck:function(i){if"); | |
917 | script = replaceNormalFile(script, "showPromoBadge:function(", "showPromoBadge:function(i){},fuckbacks: function("); | |
918 | script = replaceRegexFile(script, /(return\s\w+.tab.toUpperCase\(\)).indexOf\(\w+.toUpperCase\(\)\)!=-1/, "$1 != 'VETERAN'"); | |
919 | script = replaceRegexFile(script, /if\(\w+.shouldSkipConfigEntry\(\w+.productIdToQuantify.*visibility\)\)\{continue\}/, ""); | |
920 | script = replaceNormalFile(script, "if(this.getSkinsByCategory(i1.tabDescription).length>0", 'if (this.getSkinsByCategory(i1.tabDescription).length > 0 && (i1.tabDescription.toUpperCase() == "PREMIUM" || i1.tabDescription.toUpperCase() == "VETERAN" || i1.tabDescription.toUpperCase() == "OWNED")'); | |
921 | script = replaceRegexFile(script, /var\si2=window.document.createElement..script..+head.appendChild.i2../i, "Singa.reloadCore();"); | |
922 | script = replaceRegexFile(script, /(showFreeCoins:function\(\)\{var.*showContainer\(\);if\(([a-zA-Z0-9]+[a-zA-Z0-9]+.user.userInfo==null).*false\);([a-zA-Z0-9]+[a-zA-Z0-9]+.triggerFreeCoins\(\)).*this.onShopClose\)\)\}},)/, "$1 SingaFreeCoins: function(){if($2){return;}$3;},"); | |
923 | script = replaceNormalFile(script, "onPlayerBanned:function(i)", "onPlayerBanned: function(i){},shitfacefuck:function(i)"); | |
924 | script = replaceNormalFile(script, "setPopupActiveState:function(i){", "setPopupActiveState:function(i){console.log('stopped annoying ad');return;"); | |
925 | eval(script); | |
926 | var e = new XMLHttpRequest; | |
927 | e.open("GET", "/", true); | |
928 | e.onload = function() { | |
929 | var a = e.responseText; | |
930 | a = replaceNormalFile(a, "UCC6hurPo_LxL7C0YFYgYnIw", "UCq_b9_e_wYCP9sl4r3PWujQ"); | |
931 | a = replaceRegexFile(a, /<footer[\S\s]*\/footer>/i, ""); | |
932 | a = replaceNormalFile(a, '<script src="agario.core.js" async>\x3c/script>', "<div id='botcanvas' style='background:rgba(0,0,0,0.4); width: 200px; top: 5px; left: 9px; display: block; position: absolute; text-align: center; font-size: 15px; color: #ffffff; padding: 5px; font-family: Ubuntu;'> <font color='#7FFF00'>BOT.X</font><br>Minions: <a id='botCount'><font color='red'>0 / 2</font></a><br><font color='#FFFFFF'>A</font> - Move To Mouse: <a id='ismoveToMouse'><font color='#7FFF00'>On</font></a><br><font color='#FFFFFF'>P</font> - Collect Pellets: <a id='collectPellets'><font color='red'>Off</font></a><br><font color='#FFFFFF'>D</font> - Stop Movement: <a id='isStopMove'><font color='red'>Off</font></a></div>"); | |
933 | a = replaceNormalFile(a, "<body>", '<body onload="Singa.loadCore()">'); | |
934 | a = replaceRegexFile(a, /<script type="text\/javascript" src="mc\/agario\.js.*"><\/script>/i, ""); | |
935 | a = replaceRegexFile(a, /<div id="adsBottom".*display:block;">/i, '<div id="adsBottom" style="display:none">'); | |
936 | a = replaceNormalFile(a, '<div class="diep-cross" style="', '<div class="diep-cross" style="display:none;'); | |
937 | a = replaceNormalFile(a, '<div id="promo-badge-container">', '<div id="promo-badge-container" style="display:none;">'); | |
938 | a = replaceNormalFile(a, '<span data-itr="page_instructions_w"></span><br/>', '<span data-itr="page_instructions_w"></span><br/><span>Press <b>Q</b> to double split</span><br><span>Hold <b>W</b> to rapid fire mass</span><br><span>Press <b>M</b> to hide/show the minimap</span><br><span>Press <b>E</b> to split bots</span><br><span>Press <b>R</b> to eject some bots mass</span><br><span>Press <b>P</b> to make bots collect pellets</span><br><span>Creator: <bold>SingaClan</bold></span><br>Edited by Happy<span>'); | |
939 | a = replaceNormalFile(a, '<div id="tags-container">', '<div id="leaders" class="input-group" style="margin-top: 6px;"><span class="input-group-addon" style="width:75px"id="basic-addon1">BOARD</span><input id="leaderboard" type="text" value="" style="width:185px" readonly class="form-control"><button id="leaderboardcopy" class="btn btn-primary" style="float: right; width: 60px; border-radius: 0px 4px 4px 0px;" data-original-title="" title="">Copy</button></div><div class="input-group" style="margin-top: 6px;"><span class="input-group-addon" style="width:75px"id="basic-addon1">UUID</span><input id="uuid" type="text" value="' + | |
940 | client_uuid + '" style="width:185px" readonly class="form-control"><button id="uuidcopy" class="btn btn-primary" style="float: right; width: 60px; border-radius: 0px 4px 4px 0px;" data-original-title="" title="">Copy</button></div><div class="input-group" style="margin-top: 6px;"><span class="input-group-addon" style="width:75px" id="basic-addon1">NAMES</span><input id="botnames" class="form-control" style="width:245px" placeholder="Separate bot names using commas" autofocus=""></div><div id="tags-container">'); | |
941 | a = replaceNormalFile(a, "</body>", '<div style="display:block;position:absolute;z-index:100;pointer-events:none;right:9px;bottom:9px;"><canvas id="minimap"></div></body>'); | |
942 | document.open(); | |
943 | document.write(a); | |
944 | Singa.loadCore(); | |
945 | document.close(); | |
946 | }; | |
947 | e.send(); | |
948 | }, b.send(), setInterval(function() { | |
949 | Singa.realPlayerX = Singa.mapOffsetX + Singa.playerX; | |
950 | Singa.realPlayerY = Singa.mapOffsetY + Singa.playerY; | |
951 | moveBallOnMinimap("player_pointer", Singa.realPlayerX, Singa.realPlayerY); | |
952 | moveBallOnMinimap("player_spectate", Singa.realPlayerX, Singa.realPlayerY); | |
953 | }, 50); | |
954 | var last_transmited_game_server = null; | |
955 | var socket = null; | |
956 | setInterval(function() { | |
957 | if (!Singa.isAuthorized) { | |
958 | emitPosition(); | |
959 | } | |
960 | }, 10), setInterval(function() { | |
961 | if (Singa.isAuthorized) { | |
962 | emitPosition(); | |
963 | } | |
964 | emitLocalPosition(); | |
965 | transmit_current_server(false); | |
966 | }, 10); | |
967 | window.interval = setInterval(function() { | |
968 | if (MC.coreWasLoaded == true && $("#nick")[0]) { | |
969 | clearInterval(interval); | |
970 | $("#agarTwitter").remove(); | |
971 | $("h2").replaceWith("<h2>Agar.io</h2>"); | |
972 | } | |
973 | }, 100); | |
974 | ||
975 | ||
976 | ||
977 | function skinHack() { | |
978 | this.currentSkin = ""; | |
979 | this.configUrlBase = window.EnvConfig.config_url + '/' + localStorage.getItem('last_config_id') + '/'; | |
980 | this.configUrl = this.configUrlBase + 'GameConfiguration.json'; | |
981 | this.skinObj = {}; | |
982 | this.rotateInterval = 1000; | |
983 | this.playerName = ''; | |
984 | this.canUseScript = false; | |
985 | this.downloadConfig(); | |
986 | } | |
987 | skinHack.prototype = { | |
988 | downloadConfig: function() { | |
989 | var onDownload = this.onDownload.bind(this); | |
990 | $.ajax({ | |
991 | type: "GET", | |
992 | url: this.configUrl, | |
993 | success: function(data) { | |
994 | onDownload(data); | |
995 | }, | |
996 | error: function(jqXHR, textStatus, errorThrown) {} | |
997 | }); | |
998 | }, | |
999 | onDownload: function(data) { | |
1000 | this.handleSkinData(data); | |
1001 | this.injectHtml(); | |
1002 | this.overrideSetNick(); | |
1003 | this.initSkinRotation(); | |
1004 | this.updateSkin(); | |
1005 | }, | |
1006 | handleSkinData: function(data) { | |
1007 | var shopSkins = data.gameConfig['Shop - Skins']; | |
1008 | var equippableSkins = data.gameConfig['Gameplay - Equippable Skins']; | |
1009 | for (var i = 0; i < equippableSkins.length; i++) { | |
1010 | var skin = equippableSkins[i]; | |
1011 | this.skinObj[skin.productId] = { | |
1012 | image: skin.image, | |
1013 | color: skin.cellColor | |
1014 | }; | |
1015 | } | |
1016 | for (var i = 0; i < shopSkins.length; i++) { | |
1017 | var skin = shopSkins[i]; | |
1018 | this.skinObj[skin.productIdToQuantify].title = skin.title; | |
1019 | } | |
1020 | }, | |
1021 | injectHtml: function() { | |
1022 | $('#advertisement').hide(); | |
1023 | $('.agario-promo').remove(); | |
1024 | $('.diep-cross').remove(); | |
1025 | $('#agario-web-incentive').remove(); | |
1026 | //$('<select id="skinsList" class="form-control" onchange="window.skinHack.updateSkin()" required=""></select><input type="checkbox" id="rotateSkinCheckBox">Rotate Skins</input>').insertBefore('#locationUnknown'); | |
1027 | //$('<div class="agario-panel agario-side-panel"><img id="skinPreview" class="circle bordered"src=""width="96"height="96"style="height: 96px; border: 3px solid rgb(0, 44, 108);margin: 0 auto;"><br><select id="skinsList"class="form-control"onchange="window.skinHack.updateSkin()"required=""></select><br><div id="skinRotator"style="margin: auto"><label>Skin Rotator: </label><div style="left: 13px" class="btn-group btn-toggle"><button class="btn btn-sm active btn-default">ON</button><button class="btn btn-sm active btn-primary">OFF</button></div></div></div>').insertAfter('.agario-party'); | |
1028 | ||
1029 | this.addSkinOption({ | |
1030 | image: '', | |
1031 | color: '0x00000000', | |
1032 | title: 'Default Skin' | |
1033 | }); | |
1034 | for (var idStr in this.skinObj) { | |
1035 | if (this.skinObj.hasOwnProperty(idStr) && this.skinObj[idStr].title) { | |
1036 | this.addSkinOption(this.skinObj[idStr]); | |
1037 | } | |
1038 | } | |
1039 | ||
1040 | $('.btn-toggle').click(function() { | |
1041 | $(this).find('.btn').toggleClass('active'); | |
1042 | ||
1043 | if ($(this).find('.btn-primary').size() > 0) { | |
1044 | $(this).find('.btn').toggleClass('btn-primary'); | |
1045 | } | |
1046 | if ($(this).find('.btn-info').size() > 0) { | |
1047 | $(this).find('.btn').toggleClass('btn-info'); | |
1048 | } | |
1049 | ||
1050 | $(this).find('.btn').toggleClass('btn-default'); | |
1051 | }); | |
1052 | this.preLoadSkins(); | |
1053 | $('#openfl-content').click(this.updateSkin.bind(this)); | |
1054 | }, | |
1055 | preLoadSkins: function() { | |
1056 | for (var key in this.skinObj) { | |
1057 | if (this.skinObj.hasOwnProperty(key)) { | |
1058 | (new Image()).src = this.configUrlBase + this.skinObj[key].image; | |
1059 | } | |
1060 | } | |
1061 | }, | |
1062 | addSkinOption: function(skin) { | |
1063 | skin.title = skin.title.split("product_name_skin_")[1]; | |
1064 | $('#skinsList').append('<option value="' + skin.image + ':' + skin.color + '">' + skin.title + '</option>'); | |
1065 | }, | |
1066 | overrideSetNick: function() { | |
1067 | window.MC._setNick = window.MC.setNick; | |
1068 | window.MC.setNick = function() { | |
1069 | var name = arguments[0]; | |
1070 | if(name === "") { | |
1071 | this.playerName = "PIKA" | |
1072 | name = "PIKA"; | |
1073 | console.log('Overriding'); | |
1074 | } else { | |
1075 | this.playerName = name; | |
1076 | } | |
1077 | window.MC._setNick(name); | |
1078 | ||
1079 | this.updateSkin(); | |
1080 | }.bind(this); | |
1081 | }, | |
1082 | checkSubscription: function() { | |
1083 | try { | |
1084 | if (localStorage.getItem('canUseScript')) { | |
1085 | this.canUseScript = JSON.parse(localStorage.getItem('canUseScript').toLowerCase()); | |
1086 | } else { | |
1087 | localStorage.setItem('canUseScript', 'false'); | |
1088 | return this.promptSubscription(); | |
1089 | } | |
1090 | if (!this.canUseScript) { | |
1091 | return this.promptSubscription(); | |
1092 | } | |
1093 | return this.canUseScript; | |
1094 | } catch (err) { | |
1095 | console.log(err); | |
1096 | } | |
1097 | }, | |
1098 | promptSubscription: function() { | |
1099 | var ask = window.confirm("You must subscribe to Happy to use this Script"); | |
1100 | if (ask) { | |
1101 | var win = window.open('https://www.youtube.com/channel/UCq_b9_e_wYCP9sl4r3PWujQ?sub_confirmation=1', '_blank'); | |
1102 | if (win) { | |
1103 | localStorage.setItem('canUseScript', 'true'); | |
1104 | this.canUseScript = true; | |
1105 | this.updateSkin(); | |
1106 | } else { | |
1107 | alert('Please allow popups and refresh the page first!'); | |
1108 | } | |
1109 | } | |
1110 | return this.canUseScript(); | |
1111 | }, | |
1112 | updateSkin: function() { | |
1113 | ||
1114 | var skinArg = $('#skinsList').val().split(':'); | |
1115 | var usingHackSkin = skinArg[0].length > 0; | |
1116 | var image = usingHackSkin ? this.configUrlBase + skinArg[0] : document.getElementsByClassName('circle bordered')[0].src; | |
1117 | var color = usingHackSkin ? | |
1118 | parseInt(skinArg[1].slice(0, skinArg[1].length - 2)) : | |
1119 | parseInt(this.rgbToHex(document.getElementsByClassName('circle bordered')[0].style.borderColor).slice(1, 7), 16); | |
1120 | var name = this.playerName; | |
1121 | window.core.registerSkin(name, null, image, image ? 2 : 0, image ? color : null); | |
1122 | $('#skinPreview').attr('src', image) | |
1123 | var arr = ['top', 'right', 'bottom', 'left']; | |
1124 | for (var i = 0; i < array.length; i++) { | |
1125 | $('#skinPreview').css('border-' + array[i] + '-color', '#' + color.toString(16)); | |
1126 | } | |
1127 | ||
1128 | }, | |
1129 | rgbToHex: function(color) { | |
1130 | if (color.substr(0, 1) === '#') { | |
1131 | return color; | |
1132 | } | |
1133 | var digits = /(.*?)rgb\((\d+), (\d+), (\d+)\)/.exec(color); | |
1134 | ||
1135 | var red = parseInt(digits[2]); | |
1136 | var green = parseInt(digits[3]); | |
1137 | var blue = parseInt(digits[4]); | |
1138 | ||
1139 | var rgb = blue | (green << 8) | (red << 16); | |
1140 | return digits[1] + '#' + rgb.toString(16); | |
1141 | }, | |
1142 | initSkinRotation: function() { | |
1143 | setInterval(function() { | |
1144 | if ($('.btn-toggle').find('.btn-primary').html() === "ON") { | |
1145 | $('#skinsList')[0].selectedIndex = ($('#skinsList')[0].selectedIndex + 1) % $('#skinsList')[0].length; | |
1146 | this.updateSkin(); | |
1147 | } | |
1148 | }.bind(this), this.rotateInterval); | |
1149 | } | |
1150 | }; |