Advertisement
Guest User

// ==UserScript== // @name Agar.io API feeder bots /

a guest
Dec 11th, 2016
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.54 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Agar.io API feeder bots
  3. // @namespace http://github.com/nuclearc/
  4. // @version 0.8
  5. // @description Agar.io bots
  6. // @author NuclearC & AgarThix
  7. // @license MIT
  8. // @match *://72.k.vu/*
  9. // @match http://soapplus.tk/sgar/*
  10. // @match http://mgar.io/mgar/
  11. // @match http://soapplus.tk/sgar/?ip=
  12. // @grant none
  13. // @run-at document-start
  14. // ==/UserScript==
  15.  
  16. var ip = "ws://127.0.0.1:8081";
  17. var ws = null;
  18. var mapOffsetX = 0;
  19. var mapOffsetY = 0;
  20. var mapSizeX = 0;
  21. var mapSizeY = 0;
  22. var playerX = 0;
  23. var playerY = 0;
  24. var canSendPosition = true;
  25. var movetoMouse = true;
  26. var collectingPallets = false;
  27.  
  28. setTimeout(function () {
  29. $("#canvas").after("<div style='background-color: #000000; border: 0px; border-radius: 5px; -moz-opacity: 0.8; -khtml-opacity: 0.8; opacity: 0.8; filter: alpha(opacity=80); zoom: 1; width: 205px; top: 10px; left: 10px; display: block; position: fixed; text-align: center; font-size: 21px; color: #0091FF; padding: 5px; font-family: Arial;'> <div style='color:#0091FF; display: inline; -moz-opacity:1; -khtml-opacity: 1; opacity:1; filter:alpha(opacity=100); padding: 20px;'><a>IMBots</a></div> <div style='color:0091FF; display: inline; -moz-opacity:1; -khtml-opacity: 1; opacity:1; filter:alpha(opacity=100); padding: 10px;'><br>Bots : <a id='minionCount' >Offline</a><br>Collect Food: <a id='iscollectfood' >Off</a>");
  30. $("#helloContainer").after("<div style='background-color: #fff; border: 5px solid rgba(123, 121, 121, 1); border-radius: 5px; -moz-opacity: 1.0; -khtml-opacity: 1.0; opacity: 1.0; width: 355px; height: 175px; top: 41%; left: 59.5%; display: block; position: fixed; text-align: center; font-size: 15px; color: #000000; font-family: Arial;'><h4>Input Method</h4><div style='margin-top: 6px;' class='input-group'><span style='width:75px;' class='input-group-addon' id='basic-addon1'>Amount</span><input id='bot-amount' type='text' value='100' maxlength='4' style='width:245px' placeholder='Bot amount (max 5000)' autofocus='' class='form-control'></div><div style='margin-top: 6px;' class='input-group'><span style='width:75px; margin: 10px;' class='input-group-addon' id='basic-addon1'>Name</span><input id='bot-name' type='text' value='IMBots' maxlength='15' style='width:245px' placeholder='Bots name (max length 15)' autofocus='' class='form-control'></div><div><br>Position: <a id='posXY'>0, 0</a> </div>");
  31. $("h2").replaceWith("<h2>AgarAPI</h2>");
  32. $('#options').after("<center><button id='stop-bots' style='margin: 2px; width: 100px;' class='btn btn-needs-server btn btn-danger'><b>Stop Bots</b></button></center>");
  33. $('#options').after("<center><button id='start-bots' style='margin: 0px; width: 100px;' class='btn btn-needs-server btn-success'><b>Start Bots</b></button></center>");
  34.  
  35. ws = new WebSocket(ip);
  36. ws.binaryType = 'arraybuffer';
  37. ws.onopen = function () {
  38. document.getElementById('minionCount').innerHTML = "Waiting...";
  39. }
  40.  
  41. ws.onclose = function () {
  42. document.getElementById('minionCount').innerHTML = "OFFLINE";
  43. canSendPosition = true;
  44. }
  45.  
  46. ws.onerror = function () {
  47. document.getElementById('minionCount').innerHTML = "OFFLINE";
  48. canSendPosition = true;
  49. }
  50.  
  51. ws.onmessage = function (e) {
  52. var data = event.data;
  53. var dv = new DataView(data);
  54. var packetID = dv.getUint8(0);
  55.  
  56. switch (packetID) {
  57. case 0x10:
  58. {
  59. // got connection!
  60. canSendPosition = true;
  61.  
  62. setInterval(function () {
  63. emitPosition()
  64. }, 100);
  65. } break;
  66. case 0x70:
  67. {
  68. // max bots and current bots
  69. var maxBots = dv.getUint32(1, true);
  70. var currentBots = dv.getUint32(5, true);
  71.  
  72. document.getElementById('minionCount').innerHTML = currentBots + "/" + maxBots;
  73. } break;
  74. }
  75. }
  76.  
  77. var client_uuid = localStorage.getItem('client_uuid');
  78. if (client_uuid == null) {
  79. console.log("generating a uuid for this user");
  80. client_uuid = ""; var ranStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  81. for (var ii = 0; ii < 15; ii++) client_uuid += ranStr.charAt(Math.floor(Math.random() * ranStr.length));
  82. localStorage.setItem('client_uuid', client_uuid);
  83. }
  84.  
  85. $("#options").after('<br><br><br><div style="margin-top: 6px;" class="input-group"><span style="width:75px;" class="input-group-addon" id="basic-addon1">UUID</span><input id="bot-uuid" type="text" value="' + client_uuid + '" style="width:245px" readonly class="form-control"</div>');
  86.  
  87. window.v72.hooks.dimensionsUpdated = function (minx, miny, maxx, maxy) {
  88. mapSizeX = maxx - minx;
  89. mapSizeY = maxy - miny;
  90.  
  91.  
  92. mapOffsetX = minx +
  93. mapSizeX / 2;
  94. mapOffsetY = miny +
  95. mapSizeY / 2;
  96. };
  97.  
  98. var mouseX = 0;
  99. var mouseY = 0;
  100.  
  101. document.getElementById("start-bots").onclick = function () {
  102. emitServer()
  103. };
  104.  
  105.  
  106. document.getElementById("stop-bots").onclick = function () {
  107. emitStop()
  108. };
  109.  
  110. $("body").mousemove(function (event) {
  111. mouseX = event.clientX;
  112. mouseY = event.clientY;
  113.  
  114. document.getElementById('posXY').innerHTML = playerX + ", " + playerY;
  115. });
  116.  
  117. function isMe(cell) {
  118. for (var i = 0; i < window.v72.myCells.length; i++) {
  119. if (window.v72.myCells[i] == cell.id) {
  120. return true
  121. }
  122. }
  123. return true
  124. }
  125.  
  126. function getCell() {
  127. var me = [];
  128. for (var key in window.v72.allCells) {
  129. var cell = window.v72.allCells[key];
  130. if (isMe(cell)) {
  131. me.push(cell)
  132. }
  133. }
  134. return me[0];
  135. }
  136.  
  137. function emitPosition() {
  138. var mycell = getCell();
  139. if (window.v72.myCells.length > 0 && mycell != undefined) {
  140. playerX = mycell.x;
  141. playerY = mycell.y;
  142. }
  143.  
  144.  
  145. var x = 0;
  146. var y = 0;
  147.  
  148. if (movetoMouse) {
  149. x = (mouseX - window.innerWidth / 2) / window.v72.drawScale + window.v72.rawViewport.x;
  150. y = (mouseY - window.innerHeight / 2) / window.v72.drawScale + window.v72.rawViewport.y;
  151. }
  152. else {
  153. x = playerX;
  154. y = playerY;
  155. }
  156.  
  157. var buffer = new ArrayBuffer(9);
  158. var dv = new DataView(buffer);
  159. dv.setUint8(0, 0x10);
  160. dv.setInt32(1, x - mapOffsetX, true);
  161. dv.setInt32(5, y - mapOffsetY, true);
  162. if (canSendPosition) {
  163. ws.send(buffer);
  164. }
  165. }
  166.  
  167. function emitStop() {
  168. var buffer = new Uint8Array(1);
  169. buffer[0] = 240;
  170.  
  171. if (canSendPosition) {
  172. ws.send(buffer);
  173. }
  174. }
  175.  
  176. function emitServer() {
  177.  
  178. var a = '0' + client_uuid + ',' + 'ws://' + window.location.search.substring(4) + ',' + $('#bot-name').val() + ',' + $('#bot-amount').val() + ';';
  179.  
  180. ws.send(a);
  181. }
  182.  
  183. document.addEventListener('keydown', function (event) {
  184. switch (event.keyCode) {
  185. case 0x58:
  186. {
  187. var buffer = new Uint8Array(1);
  188. buffer[0] = 230;
  189.  
  190. if (canSendPosition) {
  191. ws.send(buffer);
  192. }
  193. } break;
  194. case 0x43: {
  195. var buffer = new Uint8Array(1);
  196. buffer[0] = 231;
  197.  
  198. if (canSendPosition) {
  199. ws.send(buffer);
  200. }
  201. } break;
  202. case 65:
  203. movetoMouse = !movetoMouse;
  204. if (movetoMouse) { document.getElementById('ismoveToMouse').innerHTML = "On"; } else { document.getElementById('ismoveToMouse').innerHTML = "Off"; }
  205. break;
  206. case 0x50:
  207. collectingPallets = !collectingPallets;
  208. if (collectingPallets) { document.getElementById('iscollectfood').innerHTML = "On"; } else { document.getElementById('iscollectfood').innerHTML = "Off"; }
  209. var buffer = new Uint8Array(1);
  210. buffer[0] = 232;
  211.  
  212. if (canSendPosition) {
  213. ws.send(buffer);
  214. }
  215. break;
  216. }
  217. });
  218. }, 50);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement