Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.81 KB | None | 0 0
  1. // Bot Client Class
  2. class Client {
  3. constructor(botServerIP) {
  4. this.botServerIP = botServerIP;
  5. this._ws = null;
  6. this.moveInterval = 0;
  7. this.clientX = 0;
  8. this.clientY = 0;
  9. this.currentServer = '';
  10. this.botMode = 'FEEDER';
  11. this.token = '';
  12. this.serverReady = false;
  13. this.serverInUse = false;
  14. this.validated = false;
  15. this.extraZoom = false;
  16. this.connect();
  17. this.addListener();
  18. }
  19.  
  20. connect() { // Connect
  21. this._ws = new WebSocket(this.botServerIP);
  22. this._ws.binaryType = 'arraybuffer';
  23. this._ws.onopen = this.onopen.bind(this);
  24. this._ws.onmessage = this.onmessage.bind(this);
  25. this._ws.onclose = this.onclose.bind(this);
  26. this._ws.onerror = this.onerror.bind(this);
  27. console.log('Client: Connecting to bot server....');
  28. }
  29.  
  30. onopen() {
  31. console.log('Client: Connected to bot server.');
  32. $('#botServer').removeClass('label-default');
  33. $('#botServer').removeClass('label-danger');
  34. $('#botServer').addClass('label-success');
  35. $('#botServer').html('Connected');
  36. this.sendToken();
  37. this.startMoveInterval();
  38. }
  39.  
  40. sendToken() {
  41. let buf = this.createBuffer(2 + this.token.length);
  42. buf.setUint8(0, 4);
  43. for (let i = 0; i < this.token.length; i++) buf.setUint8(1 + i, this.token.charCodeAt(i));
  44. this.send(buf);
  45. }
  46.  
  47. onmessage(msg) {
  48. let buf = new DataView(msg.data);
  49. let offset = 0;
  50. let opcode = buf.getUint8(offset++);
  51. switch (opcode) {
  52. case 0:
  53. let spawnedAmount = buf.getUint16(offset, true);
  54. offset += 2;
  55. let connectedAmount = buf.getUint16(offset, true);
  56. offset += 2;
  57. let maxBots = buf.getUint16(offset, true);
  58. $('#botCount').html(`${connectedAmount}/${spawnedAmount}/${maxBots}`);
  59. if (connectedAmount >= 1) {
  60. $('#botCount').removeClass('label-default');
  61. $('#botCount').addClass('label-success');
  62. } else if (connectedAmount < 1) {
  63. $('#botCount').addClass('label-default');
  64. $('#botCount').removeClass('label-success');
  65. }
  66. break;
  67. case 1:
  68. let serverStatus = buf.getUint8(offset++);
  69. let classes = 'label-';
  70. let message = 'Failed to read message';
  71. switch (serverStatus) {
  72. case 0:
  73. this.serverReady = false;
  74. classes += 'warning';
  75. message = 'Phantom loading';
  76. break;
  77. case 1:
  78. this.serverReady = true;
  79. classes += 'success';
  80. message = 'Ready';
  81. break;
  82. case 2:
  83. this.serverReady = false;
  84. this.serverInUse = true;
  85. classes += 'danger';
  86. message = 'In use';
  87. break;
  88. case 3:
  89. let stat = buf.getUint8(offset++);
  90. switch (stat) {
  91. case 0:
  92. this.serverReady = false;
  93. classes += 'warning';
  94. message = 'Getting proxies (0)';
  95. break;
  96. case 1:
  97. this.serverReady = true;
  98. classes += 'success';
  99. message = 'Ready';
  100. break;
  101. case 2:
  102. classes += 'warning';
  103. message = `Getting proxies (${buf.getUint16(offset, true)})`;
  104. break;
  105. }
  106. break;
  107. case 4:
  108. let isValid = buf.getUint8(offset++);
  109. if (isValid) {
  110. classes += 'success';
  111. message = 'Validated/Ready';
  112. this.validated = true;
  113. } else {
  114. classes += 'danger';
  115. message = 'Not validated';
  116. this.serverInUse = true;
  117. }
  118. break;
  119. case 5:
  120. classes += 'warning';
  121. message = 'Waiting for validation';
  122. break;
  123. default:
  124. alert(`Warning: Received unknown server status from bot server: ${serverStatus}`);
  125. break;
  126. }
  127. switch (classes) {
  128. case 'label-danger':
  129. $('#serverStatus').removeClass('label-success');
  130. $('#serverStatus').removeClass('label-warning');
  131. break;
  132. case 'label-success':
  133. $('#serverStatus').removeClass('label-danger')
  134. $('#serverStatus').removeClass('label-warning');
  135. break;
  136. case 'label-warning':
  137. $('#serverStatus').removeClass('label-success');
  138. $('#serverStatus').removeClass('label-danger');
  139. break;
  140. }
  141. $('#serverStatus').addClass(classes);
  142. $('#serverStatus').html(message);
  143. break;
  144. case 16:
  145. if (window.sniffer) {
  146. buf = this.getRealData(new Buffer(buf.buffer));
  147. let output = new Buffer(LZ4.encodeBound(buf.byteLength));
  148. const compressedSize = LZ4.encodeBlock(buf, output);
  149. output = output.slice(0, compressedSize);
  150. let packet = new Buffer(5);
  151. packet.writeUInt8(255, 0);
  152. packet.writeUInt32LE(compressedSize, 1);
  153. sniffer.fakeReceiveData(Buffer.concat([packet, output]));
  154. }
  155. break;
  156. default:
  157. console.log('Got invalid data from bot server');
  158. break;
  159. }
  160. }
  161.  
  162. getRealData(buf) {
  163. let offset = 1;
  164. let eatQueueLength = buf.readUInt16LE(offset); // Number of eat events
  165. offset += eatQueueLength * 8 + 2;
  166.  
  167. while (true) {
  168. if (buf.readUInt32LE(offset) === 0) break; // End of cell queue.
  169. offset += 4;
  170. let x = buf.readInt32LE(offset); // Cell X position.
  171. buf.writeInt32LE(x + window.offsetX, offset);
  172. offset += 4;
  173. let y = buf.readInt32LE(offset); // Cell Y position.
  174. buf.writeInt32LE(y + window.offsetY, offset);
  175. offset += 6;
  176. let flags = buf.readUInt8(offset++); // Cell flags
  177.  
  178. if (flags & 2) { // Cell color in RGB
  179. offset += 3;
  180. }
  181.  
  182. if (flags & 128) { // Added in protocol v11.
  183. offset++;
  184. }
  185.  
  186. if (flags & 4) { // Cell skin
  187. let char = 0;
  188. while ((char = buf.readUInt8(offset++)) !== 0) {}
  189. }
  190.  
  191. if (flags & 8) { // Cell name
  192. let char = 0;
  193. while ((char = buf.readUInt8(offset++)) !== 0) {}
  194. }
  195. }
  196. return buf;
  197. }
  198.  
  199. onclose() {
  200. console.log('Client: Connection to bot server closed.');
  201. $('#botServer').addClass('label-danger');
  202. $('#botServer').removeClass('label-success');
  203. $('#botCount').addClass('label-default');
  204. $('#botCount').removeClass('label-success');
  205. $('#serverStatus').addClass('label-default');
  206. $('#serverStatus').removeClass('label-success');
  207. $('#serverStatus').removeClass('label-warning');
  208. $('#serverStatus').removeClass('label-danger');
  209. if (!this.serverInUse) $('#serverStatus').html('Waiting...');
  210. $('#botCount').html('0/0/0');
  211. $('#botServer').html('Closed');
  212. $('#toggleButton').replaceWith(`<button id='toggleButton' onclick='window.client.startBots();' class='btn btn-success'>Start Bots</button>`);
  213. clearInterval(this.moveInterval);
  214. this.serverReady = false;
  215. this.validated = false;
  216. if (!this.serverInUse) setTimeout(this.connect.bind(this), 500);
  217. }
  218.  
  219. onerror() {
  220. console.log('Client: Connection to bot server errored.');
  221. }
  222.  
  223. startBots() { //Send startBots
  224. if (!this.serverReady || !this.validated) return alert('Bot server is not ready for bots to be started yet!');
  225. this.changeBotMode(this.botMode);
  226. let botNick = $('#botNick').val();
  227. let botAmount = $('#botAmount').val();
  228. let currentServer = this.currentServer;
  229. console.log(botNick, currentServer);
  230. let buf = this.createBuffer(9 + 2 * botNick.length + 2 * currentServer.length);
  231. let offset = 0;
  232. buf.setUint8(offset++, 0);
  233. for (let i = 0; i < botNick.length; i++) {
  234. buf.setUint16(offset, botNick.charCodeAt(i), true);
  235. offset += 2;
  236. }
  237. buf.setUint16(offset, 0, true);
  238. offset += 2;
  239. for (let i = 0; i < currentServer.length; i++) {
  240. buf.setUint16(offset, currentServer.charCodeAt(i), true);
  241. offset += 2;
  242. }
  243. buf.setUint16(offset, 0, true);
  244. offset += 2;
  245. buf.setUint32(offset, botAmount, true);
  246. this.send(buf);
  247. $('#toggleButton').replaceWith(`<button id='toggleButton' onclick='window.client.stopBots();' class='btn btn-danger'>Stop Bots</button>`);
  248. }
  249.  
  250. sendGetProxies() {
  251. let buf = this.createBuffer(3);
  252. buf.setUint8(0, 3);
  253. buf.setUint16(1, $('#proxyTimeout').val(), true);
  254. this.send(buf);
  255. }
  256.  
  257. changeBotMode(newMode) {
  258. let buf = this.createBuffer(3 + newMode.length * 2);
  259. buf.setUint8(0, 2);
  260. for (let i = 0; i < newMode.length; i++) buf.setUint16(1 + 2 * i, newMode.charCodeAt(i), true);
  261. this.send(buf);
  262. }
  263.  
  264. stopBots() { //Send stopBots
  265. let buf = this.createBuffer(1);
  266. buf.setUint8(0, 1);
  267. this.send(buf);
  268. $('#toggleButton').replaceWith(`<button id='toggleButton' onclick='window.client.startBots();' class='btn btn-success'>Start Bots</button>`);
  269. }
  270.  
  271. toggleMove() {
  272. if ($('#botStopped').html() == 'ON') {
  273. $('#botStopped').html('OFF');
  274. $('#botStopped').removeClass('label-success');
  275. $('#botStopped').addClass('label-danger');
  276. this.changeBotMode(this.botMode);
  277. } else {
  278. $('#botStopped').html('ON');
  279. $('#botStopped').removeClass('label-danger');
  280. $('#botStopped').addClass('label-success');
  281. this.changeBotMode('STOPPED');
  282. $('#botAI').html('OFF');
  283. $('#botAI').removeClass('label-success');
  284. $('#botAI').addClass('label-danger');
  285. }
  286. }
  287.  
  288. toggleAI() {
  289. if ($('#botAI').html() == 'ON') {
  290. $('#botAI').html('OFF');
  291. $('#botAI').removeClass('label-success');
  292. $('#botAI').addClass('label-danger');
  293. this.changeBotMode(this.botMode);
  294. } else {
  295. $('#botAI').html('ON');
  296. $('#botAI').removeClass('label-danger');
  297. $('#botAI').addClass('label-success');
  298. this.changeBotMode('BOTAI');
  299. $('#botStopped').html('OFF');
  300. $('#botStopped').removeClass('label-success');
  301. $('#botStopped').addClass('label-danger');
  302. }
  303. }
  304.  
  305. sendMove(xPos, yPos) { //Send xPos and yPos
  306. let buf = this.createBuffer(9);
  307. buf.setUint8(0, 16);
  308. buf.setInt32(1, xPos, true);
  309. buf.setInt32(5, yPos, true);
  310. this.send(buf);
  311. }
  312.  
  313. split() {
  314. let buf = this.createBuffer(1);
  315. buf.setUint8(0, 17);
  316. this.send(buf);
  317. }
  318.  
  319. eject() {
  320. let buf = this.createBuffer(1);
  321. buf.setUint8(0, 21);
  322. this.send(buf);
  323. }
  324.  
  325. startMoveInterval() {
  326. this.moveInterval = setInterval(() => {
  327. if (window.playerX && window.playerX && window.coordOffsetFixed && this.clientX && this.clientY) this.sendMove(((this.clientX - window.innerWidth / 2) / window.viewScale) + window.playerX, ((this.clientY - window.innerHeight / 2) / window.viewScale) + window.playerY);
  328. }, 200);
  329. }
  330.  
  331. createBuffer(len) {
  332. return new DataView(new ArrayBuffer(len));
  333. }
  334.  
  335. send(data) { //Send the data to the BotServer if the WebSocket is connected.
  336. if (this._ws.readyState !== 1) return;
  337. this._ws.send(data, {
  338. binary: true
  339. });
  340. }
  341.  
  342. addListener() {
  343. document.addEventListener('mousemove', event => {
  344. this.clientX = event.clientX;
  345. this.clientY = event.clientY;
  346. });
  347. }
  348.  
  349. genToken() {
  350. const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  351. let token = '';
  352. for (let i = 0; i < 3; i++) {
  353. for (let a = 0; a < 7; a++) token += possible.charAt(Math.floor(Math.random() * possible.length));
  354. token += '-';
  355. }
  356. token = token.substring(0, token.length - 1);
  357. localStorage.setItem('agarUnlimitedToken', token);
  358. return token;
  359. }
  360. }
  361.  
  362. class GUITweaker {
  363. constructor() {
  364. this.removeStartupBackground();
  365. this.removeElements();
  366. this.addBotGUI();
  367. this.addGUI();
  368. this.loadCustomCSS();
  369. }
  370.  
  371. removeStartupBackground() {
  372. const oldEvt = CanvasRenderingContext2D.prototype.drawImage;
  373. CanvasRenderingContext2D.prototype.drawImage = function (a) {
  374. if (a.src && a.src == 'http://agar.io/img/background.png') return;
  375. oldEvt.apply(this, arguments);
  376. };
  377. }
  378.  
  379. removeElements() {
  380. $('#advertisement').remove();
  381. $('#bannerCarousel').remove();
  382. }
  383.  
  384. addBotGUI() {
  385. const botNick = localStorage.getItem('botNick') || 'MrSonicMaster';
  386. const proxyTimeout = localStorage.getItem('proxyTimeout') || 15000;
  387. const botAmount = localStorage.getItem('botAmount') || 500;
  388. const botMode = localStorage.getItem('botMode');
  389. $('.agario-promo-container').replaceWith(`
  390. <div class="agario-panel">
  391. <center><h3>Agar Unlimited</h3></center>
  392. <div style="margin-top: 6px;" class="input-group">
  393. <span style="width:75px;" class="input-group-addon" id="basic-addon1">Token/UID</span>
  394. <input style="width:230px" disabled id="agarUnlimitedToken" class="form-control" placeholder="Agar Unlimited Token/UID" value="Loading client..."></input>
  395. </div>
  396. <br>
  397. <input onchange="localStorage.setItem('botNick', this.value);" id="botNick" maxlength="15" class="form-control" placeholder="Bot Name" value="${botNick}"></input>
  398. <br>
  399. <input onkeypress="return event.charCode >= 48 && event.charCode <= 57" onchange="localStorage.setItem('botAmount', this.value);" id="botAmount" maxlength="4" class="form-control" placeholder="Bot Amount" value="${botAmount}"></input>
  400. <br>
  401. <select onchange="window.client.botMode=this.value;localStorage.setItem('botMode', this.value);" class="form-control">
  402. <option ${botMode == "FEEDER" ? "selected" : ""} value="FEEDER">Feeder Bots</option>
  403. <option ${botMode == "CRASHER" ? "selected" : ""} value="CRASHER">Crasher Bots</option>
  404. <option ${botMode == "AGARVIEW" ? "selected" : ""} value="AGARVIEW">AgarView BETA Bots</option>
  405. </select>
  406. <br>
  407. <button id="toggleButton" onclick="window.client.startBots();" class="btn btn-success">Start Bots</button>
  408. <br><br>
  409. <input onkeypress="return event.charCode >= 48 &amp;&amp; event.charCode <= 57" onchange="localStorage.setItem('proxyTimeout', this.value);" id="proxyTimeout" class="form-control" placeholder="Checking Timeout" value="${proxyTimeout}">
  410. <br>
  411. <button id="getProxies" onclick="window.client.sendGetProxies();" class="btn btn-success">Get new proxies</button>
  412. </div>`);
  413. }
  414.  
  415. addGUI() {
  416. $('body').append(`
  417. <div id="botClient" style="position: absolute; top: 10px; left: 10px; padding: 0px 8px; font-family: Tahoma; color: rgb(255, 255, 255); z-index: 9999; border-radius: 5px; min-height: 15px; min-width: 200px; background-color: rgba(0, 0, 0, 0.6);">
  418. <div id="counter"><center><b>Agar Unlimited</b></center></div>
  419. <br>
  420. <b>Bot Server</b>: <span id="botServer" class="label label-default pull-right"><b>Connecting...</b></span>
  421. <br>
  422. <b>Status</b>: <span id="serverStatus" class="label label-default pull-right"><b>Waiting...</b></span>
  423. <br>
  424. <div id="important"><center><b>Bot Info</b></center></div>
  425. <div><b>Bot Count</b>: <span id="botCount" class="label label-default pull-right">0/0/0</span></div>
  426. <div id="divBotAI"><b>Bot AI</b>: <span id="botAI" class="label label-danger pull-right">OFF</span></div>
  427. <div id="dibBotStopped"><b>Bots Stopped</b>: <span id="botStopped" class="label label-danger pull-right">OFF</span></div>
  428. <br>
  429. </div>`);
  430. $('#options').append(`
  431. <label>
  432. <input ${(JSON.parse(localStorage.getItem('extraZoom'))) ? 'checked' : ''} onclick="localStorage.setItem('extraZoom', this.checked);client.extraZoom=this.checked;" type="checkbox" id="extraZoom" style="margin-top: 1px">
  433. <span data-itr="Extra Zoom">Extra Zoom</span>
  434. </label>`);
  435. }
  436.  
  437. loadCustomCSS() {
  438. $('head').append(`<style type="text/css">.agario-panel, .shop-blocker {background-color:rgba(23,23,23,0.73)!important;color:#fff!important}</style>`);
  439. }
  440. }
  441.  
  442. let check = setInterval(() => {
  443. if (document.readyState == "complete") {
  444. clearInterval(check);
  445. setTimeout(() => {
  446. new GUITweaker();
  447. $('#agarUnlimitedToken').val(client.token);
  448. }, 1500);
  449. }
  450. }, 100);
  451.  
  452. class Macro {
  453. constructor() {
  454. this.ejectDown = false;
  455. this.stopped = false;
  456. this.speed = 15;
  457. this.addMoveHook();
  458. this.addKeyHooks();
  459. }
  460.  
  461. addKeyHooks() {
  462. window.addEventListener('keydown', this.onkeydown.bind(this));
  463. window.addEventListener('keyup', this.onkeyup.bind(this));
  464. }
  465.  
  466. onkeydown(event) {
  467. if (!window.MC || !MC.isInGame()) return;
  468. switch (event.key.toUpperCase()) {
  469. case 'W':
  470. this.ejectDown = true;
  471. setTimeout(this.eject.bind(this), this.speed);
  472. break;
  473. case 'P':
  474. this.stopped = !this.stopped;
  475. break;
  476. case 'E':
  477. client.split();
  478. break;
  479. case 'R':
  480. client.eject();
  481. break;
  482. case 'T':
  483. client.toggleAI();
  484. break;
  485. case 'O':
  486. client.toggleMove();
  487. break;
  488. }
  489. if (event.keyCode == 16) {
  490. for (let i = 0; i < 11; i++) setTimeout(window.core.split, this.speed * i);
  491. }
  492. }
  493.  
  494. onkeyup(event) {
  495. switch (String.fromCharCode(event.keyCode).toUpperCase()) {
  496. case 'W':
  497. this.ejectDown = false;
  498. break;
  499. }
  500. }
  501.  
  502. eject() {
  503. if (this.ejectDown) {
  504. window.core.eject();
  505. setTimeout(this.eject.bind(this), this.speed);
  506. }
  507. }
  508.  
  509. addMoveHook() {
  510. window.core._setTarget = window.core.setTarget;
  511. window.core.setTarget = function () {
  512. if (!this.stopped) window.core._setTarget.apply(this, arguments);
  513. else window.core._setTarget(window.innerWidth / 2, window.innerHeight / 2);
  514. }.bind(this);
  515. }
  516. }
  517.  
  518. window.onload = () => {
  519. new Macro();
  520. }
  521.  
  522. //Load custom core.
  523. $.ajax('http://agar.io/agario.core.js', {
  524. success: core => {
  525. core = core.replace(/([\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 window.viewScale=$2; if (window.coordOffsetFixed) { window.playerX=$4+window.offsetX; window.playerY=$5+window.offsetY;}');
  526. core = core.replace(/(\w\[\w\+(\d+)>>3]=(\w);\w\[\w\+(\d+)>>3]=(\w);\w\[\w\+(\d+)>>3]=(\w);\w\[\w\+(\d+)>>3]=(\w);)/i, '$1 function setMapCoords(_0x7e8bx1, _0x7e8bx2, _0x7e8bx3, _0x7e8bx4, _0x7e8bx5, _0x7e8bx6) { if (_0x7e8bx6 - _0x7e8bx5 == 24) { if (_0x7e8bx3 - _0x7e8bx1 > 14E3) { if (_0x7e8bx4 - _0x7e8bx2 > 14E3) { window.offsetX = 7071.067811865476 - _0x7e8bx3; window.offsetY = 7071.067811865476 - _0x7e8bx4; window.coordOffsetFixed = true; } } } } setMapCoords($3,$5,$7,$9,$2,$8);');
  527. core = core.replace(/var (\w)=new WebSocket\((\w\(\w\))\);/, 'window.client.currentServer=$2;var $1=new WebSocket(window.client.currentServer);');
  528. core = core.replace(/if\((\+\w\[\w>>3\])<1\.0\){/i, 'if($1<!client.extraZoom){');
  529. core = core.replace(/(if\([\w$]+\[[\w$]+\+\d+\>\>0\]\|0\)\{[\w$]+\=[\w$]+;return\})(if\(\![\w$]+\))/, '$1if(false)$2');
  530. eval(core);
  531. },
  532. dataType: 'text',
  533. method: 'GET',
  534. cache: false,
  535. crossDomain: true
  536. });
  537.  
  538. function isInIncognito(callback) {
  539. var fs = window.RequestFileSystem || window.webkitRequestFileSystem;
  540. if (!fs) return callback(false);
  541. fs(window.TEMPORARY, 100, () => callback(false), () => callback(true));
  542. }
  543. isInIncognito(incognito => {
  544. if (incognito) alert('This script will not work fully in incognito, settings won\'t save, and your UID would be forcefully changed. Please exit incognito mode and try again.');
  545. else runClientLoad();
  546. });
  547.  
  548. function runClientLoad() {
  549. //window.client = new Client('ws://144.217.95.240:8001'); // Bot Server IP.
  550. window.client = new Client('ws://94.177.189.246:4569'); // Bot Server IP.
  551. //window.client = new Client('ws://127.0.0.1:8080'); // Bot Server IP.
  552. client.botMode = localStorage.getItem('botMode') || 'FEEDER'; // Set the bot mode to the stored bot mode.
  553. client.extraZoom = JSON.parse(localStorage.getItem('extraZoom'));
  554. client.token = localStorage.getItem('agarUnlimitedToken') || client.genToken();
  555. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement