Advertisement
Guest User

Untitled

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