oliverbabish

better slitherio hack

Dec 23rd, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.44 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Slither.io Invincible HackBot (Best Slither Bot and working 2020)
  3. // @namespace http://slither.io/
  4. // @description Slither.io Invincible HackBot by CTHack and Fixed by Jaime Argila
  5. // @include http://slither.io/
  6. // @version 1.0.2
  7. // @grant none
  8. // ==/UserScript==
  9. window.log = function() {
  10. if (window.logDebugging) {
  11. console.log.apply(console, arguments);
  12. }
  13. };
  14. // Appends divs to the page - used to display things on the screen
  15. window.appendDiv = function(id, className, style) {
  16. // Create a div
  17. var div = document.createElement('div');
  18. // Check for id
  19. if (id) {
  20. // Set the id
  21. div.id = id;
  22. }
  23. // Check for class name
  24. if (className) {
  25. // Set the class name
  26. div.className = className;
  27. }
  28. // Check for css styles
  29. if (style) {
  30. // Set the css styles
  31. div.style = style;
  32. }
  33. // Append the div to the page
  34. document.body.appendChild(div);
  35. };
  36.  
  37. // Saves username when you click on "Play" button
  38. window.play_btn.btnf.addEventListener('click', function() {
  39. window.saveNick(window.nick.value);
  40. });
  41. // Save nickname when you press "Enter"
  42. window.nick_holder.addEventListener('keypress', function(e) {
  43. if (e.keyCode == 13) {
  44. window.saveNick(window.nick.value);
  45. }
  46. });
  47. // Save nickname
  48. window.saveNick = function(nick) {
  49. window.savePreference('savedNick', nick);
  50. };
  51. //Easy get mouseCoords
  52. document.addEventListener("mousemove", function(e){
  53. window.mouseCoords = {
  54. x: e.clientX,
  55. y: e.clientY
  56. }
  57. })
  58. // Set fake mouse coordinates
  59. window.setMouseCoordinates = function(x, y) {
  60. window.xm = x;
  61. window.ym = y;
  62. };
  63. // Coordinates relative to the center (snake position).
  64. window.mouseRelativeToCenter = function(x, y) {
  65. var mapX = x - window.getWidth() / 2;
  66. var mapY = y - window.getHeight() / 2;
  67. return [mapX, mapY];
  68. };
  69. // Mouse coordinates to screen coordinates
  70. window.mouseToScreen = function(x, y) {
  71. var screenX = x + (window.getWidth() / 2);
  72. var screenY = y + (window.getHeight() / 2);
  73. return [screenX, screenY];
  74. };
  75. // Screen to canvas coordinates
  76. window.screenToCanvas = function(x, y) {
  77. var canvasX = window.csc * (x * window.canvasRatio[0]) - parseInt(window.mc.style.left);
  78. var canvasY = window.csc * (y * window.canvasRatio[1]) - parseInt(window.mc.style.top);
  79. return [canvasX, canvasY];
  80. };
  81. // Map to mouse coordinates
  82. window.mapToMouse = function(x, y) {
  83. var mouseX = (x - window.getX()) * window.gsc;
  84. var mouseY = (y - window.getY()) * window.gsc;
  85. return [mouseX, mouseY];
  86. };
  87. // Canvas width
  88. window.getWidth = function() {
  89. return window.ww;
  90. };
  91. // Canvas height
  92. window.getHeight = function() {
  93. return window.hh;
  94. };
  95. // X coordinates on the screen
  96. window.getX = function() {
  97. return window.snake.xx;
  98. };
  99. // Y coordinates on the screen
  100. window.getY = function() {
  101. return window.snake.yy;
  102. };
  103. // Updates the relation between the screen and the canvas
  104. window.onresize = function() {
  105. window.resize();
  106. // Canvas different size from the screen (often bigger). Gives a ratio so we can convert
  107. window.canvasRatio = [window.mc.width / window.getWidth(), window.mc.height / window.getHeight()];
  108. };
  109. // Lets you zoom in and out using the mouse wheel
  110. window.setZoom = function(e) {
  111. // Scaling ratio
  112. if (window.gsc) {
  113. window.gsc *= Math.pow(0.9, e.wheelDelta / -120 || e.detail / 2 || 0);
  114. }
  115. };
  116. // FPS counter
  117. window.framesPerSecond = {
  118. startTime: 0,
  119. frameNumber: 0,
  120. filterStrength: 40,
  121. lastLoop: 0,
  122. frameTime: 0,
  123. getFPS: function() {
  124. var thisLoop = performance.now();
  125. var thisFrameTime = thisLoop - this.lastLoop;
  126. this.frameTime += (thisFrameTime - this.frameTime) / this.filterStrength;
  127. this.lastLoop = thisLoop;
  128. return (1000 / this.frameTime).toFixed(0);
  129. }
  130. };
  131.  
  132. // Set background - default is slither.io's own background
  133. function setBackground(url = '/s/bg45.jpg') {
  134. window.ii.src = url;
  135. }
  136. // Reset zoom
  137. window.resetZoom = function() {
  138. window.gsc = 0.9;
  139. }
  140. // Get scaling ratio
  141. window.getScale = function() {
  142. return window.gsc;
  143. };
  144. // Snake length
  145. window.getSnakeLength = function() {
  146. return (Math.floor(150 * (window.fpsls[window.snake.sct] + window.snake.fam / window.fmlts[window.snake.sct] - 1) - 50) / 10);
  147. };
  148. // Save the original slither.io onmousemove function so we can re enable it back later
  149. window.mousemovelistener = window.onmousemove;
  150.  
  151. // Starts the bot
  152. window.launchBot = function() {
  153. window.log('Starting Bot.');
  154. window.isBotRunning = true;
  155. // Removed the onmousemove listener so we can move the snake manually by setting coordinates
  156. window.onmousemove = function() {};
  157. };
  158. // Stops the bot
  159. window.stopBot = function() {
  160. window.log('Stopping Bot.');
  161. // Re enable the original onmousemove function
  162. window.onmousemove = window.mousemovelistener;
  163. window.isBotRunning = false;
  164. // Clear the interval which starts the bot
  165. };
  166.  
  167. // Connects the bot
  168. window.connectBot = function() {
  169. if (!window.autoRespawn) return;
  170. // Stop the bot
  171. window.stopBot();
  172. window.log('Connecting...');
  173. // Connect the bot
  174. window.connect();
  175. // Check if bot can start
  176. window.botCanStart = setInterval(function() {
  177. if (window.playing) {
  178. window.launchBot();
  179. clearInterval(window.botCanStart);
  180. }
  181. }, 100);
  182. };
  183.  
  184. // Save variable to local storage
  185. window.savePreference = function(item, value) {
  186. window.localStorage.setItem(item, value);
  187. };
  188.  
  189. // Load a variable from local storage
  190. window.loadPreference = function(preference, defaultVar) {
  191. var savedItem = window.localStorage.getItem(preference);
  192. if (savedItem !== null) {
  193. if (savedItem == 'true') {
  194. window[preference] = true;
  195. } else if (savedItem == 'false') {
  196. window[preference] = false;
  197. } else {
  198. window[preference] = savedItem;
  199. }
  200. window.log('Setting found for ' + preference + ': ' + window[preference]);
  201. } else {
  202. window[preference] = defaultVar;
  203. window.log('No setting found for ' + preference + '. Used default: ' + window[preference]);
  204. }
  205. return window[preference];
  206. };
  207.  
  208. // Save the original slither.io onkeydown function so we can add stuff to it
  209. document.oldKeyDown = document.onkeydown;
  210. // Re write the function with our function
  211. document.onkeydown = function(e) {
  212. // Original slither.io onkeydown function + whatever is under it
  213. document.oldKeyDown(e);
  214. if (document.activeElement.parentElement !== window.nick_holder) {
  215. // Letter `T` to toggle bot
  216. if (e.keyCode === 84) {
  217. if (window.isBotRunning) {
  218. window.stopBot();
  219. window.isBotEnabled = false;
  220. } else {
  221. window.launchBot(5);
  222. window.isBotEnabled = true;
  223. }
  224. }
  225. // Letter 'U' to toggle debugging (console)
  226. if (e.keyCode === 85) {
  227. window.logDebugging = !window.logDebugging;
  228. console.log('Log debugging set to: ' + window.logDebugging);
  229. window.savePreference('logDebugging', window.logDebugging);
  230. }
  231. // Letter 'Y' to toggle debugging (visual)
  232. if (e.keyCode === 89) {
  233. window.visualDebugging = !window.visualDebugging;
  234. console.log('Visual debugging set to: ' + window.visualDebugging);
  235. window.savePreference('visualDebugging', window.visualDebugging);
  236. }
  237. // Letter 'I' to toggle autorespawn
  238. if (e.keyCode === 73) {
  239. window.autoRespawn = !window.autoRespawn;
  240. console.log('Automatic Respawning set to: ' + window.autoRespawn);
  241. window.savePreference('autoRespawn', window.autoRespawn);
  242. }
  243. // Letter 'O' to change rendermode (visual)
  244. if (e.keyCode === 79) {
  245. window.mobileRender = !window.mobileRender;
  246. console.log('Mobile rendering set to: ' + window.mobileRender);
  247. window.savePreference('mobileRender', window.mobileRender);
  248. // Set render mode
  249. if (window.mobileRender) {
  250. setBackground('data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs');
  251. window.render_mode = 1;
  252. } else {
  253. setBackground();
  254. window.render_mode = 2;
  255. }
  256. }
  257. // Letter 'P' to toggle hunting Prey
  258. if (e.keyCode === 80) {
  259. window.huntPrey = !window.huntPrey;
  260. console.log('Prey hunting set to: ' + window.huntPrey);
  261. window.savePreference('huntPrey', window.huntPrey);
  262. }
  263.  
  264. // Letter 'C' to toggle Collision detection / enemy avoidance
  265. if (e.keyCode === 67) {
  266. window.collisionDetection = !window.collisionDetection;
  267. console.log('collisionDetection set to: ' + window.collisionDetection);
  268. window.savePreference('collisionDetection', window.collisionDetection);
  269. }
  270.  
  271. // Letter 'A' to increase collision detection radius
  272. if (e.keyCode === 65) {
  273. window.collisionRadiusMultiplier++;
  274. console.log('collisionRadiusMultiplier set to: ' + window.collisionRadiusMultiplier);
  275. window.savePreference('collisionRadiusMultiplier', window.collisionRadiusMultiplier);
  276. }
  277.  
  278. // Letter 'S' to decrease collision detection radius
  279. if (e.keyCode === 83) {
  280. if (window.collisionRadiusMultiplier > 1) {
  281. window.collisionRadiusMultiplier--;
  282. console.log('collisionRadiusMultiplier set to: ' + window.collisionRadiusMultiplier);
  283. window.savePreference('collisionRadiusMultiplier', window.collisionRadiusMultiplier);
  284. }
  285. }
  286.  
  287. // Letter 'D' to toggle defence mode
  288. if (e.keyCode === 68) {
  289. window.defence = !window.defence;
  290. console.log('Defence set to: ' + window.defence);
  291. window.savePreference('defence', window.defence);
  292. }
  293. // Letter 'Z' to reset zoom
  294. if (e.keyCode === 90) {
  295. window.resetZoom();
  296. }
  297. }
  298. };
  299. // Snake width
  300. window.getSnakeWidth = function() {
  301. return window.snake.sc * 15 * window.getScale();
  302. };
  303. // Sorting function for food, from property 'distance'
  304. window.sortFood = function(a, b) {
  305. // a.sz & b.sz - size
  306. // Divide distance by size so bigger food is prioritised over smaller food
  307. return a.distance / a.sz - b.distance / b.sz;
  308. };
  309. // Sorting function for prey, from property 'distance'
  310. window.sortPrey = function(a, b) {
  311. return a.distance - b.distance;
  312. };
  313.  
  314. // Convert object coordinates to radians
  315. window.getAngleFromObject = function(object) {
  316. var x = object.xx - window.getX();
  317. var y = object.yy - window.getY();
  318. return Math.atan2(x, y);
  319. };
  320.  
  321. // Polar angle to Cartesian angles
  322. window.getCoordsFromAngle = function(angle) {
  323. var x = Math.cos(angle) * 100;
  324. var y = Math.sin(angle) * 100;
  325. return [x, y];
  326. };
  327.  
  328. // Given an object (of which properties xx and yy are not null), return the object with an additional property 'distance'
  329. window.getDistanceFromMe = function(point) {
  330. if (point === null) return null;
  331. point.distance = window.getDistance(window.getX(), window.getY(), point.xx, point.yy);
  332. return point;
  333. };
  334. // Get a distance from point (x1; y1) to point (x2; y2).
  335. window.getDistance = function(x1, y1, x2, y2) {
  336. // Calculate the vector coordinates.
  337. var xDistance = (x1 - x2);
  338. var yDistance = (y1 - y2);
  339. // Get the absolute value of each coordinate
  340. xDistance = xDistance < 0 ? xDistance * -1 : xDistance;
  341. yDistance = yDistance < 0 ? yDistance * -1 : yDistance;
  342. //Add the coordinates of the vector to get a distance. Not the real distance, but reliable for distance comparison.
  343. var distance = xDistance + yDistance;
  344. // Real distance but not needed. Here for reference -
  345. // var distance = Math.sqrt(Math.pow(xDistance, 2) + Math.pow(yDistance, 2));
  346. return distance;
  347. };
  348. // Checks to see if you are going to collide with anything in the collision detection radius
  349. window.checkCollision = function(x, y, r) {
  350. var circle1 = collisionScreenToCanvas({
  351. x: x,
  352. y: y,
  353. radius: r
  354. });
  355. if (window.visualDebugging) {
  356. window.drawDot(circle1.x, circle1.y, circle1.radius, 'blue', false);
  357. }
  358. var avoid = false;
  359. var circle2;
  360.  
  361. for (var snake in window.snakes) {
  362. if (window.snakes[snake].nk != window.snake.nk) {
  363. for (var y = window.snakes[snake].pts.length - 1; 0 <= y; y--) {
  364. if (!window.snakes[snake].pts[y].dying) {
  365. circle2 = {
  366. x: window.snakes[snake].pts[y].xx + window.snakes[snake].fx,
  367. y: window.snakes[snake].pts[y].yy + window.snakes[snake].fy,
  368. radius: 15 * window.snakes[snake].sc * window.getScale()
  369. };
  370. if (window.circleIntersect(circle1, collisionScreenToCanvas(circle2))) {
  371. window.changeGoalCoords(circle2);
  372. avoid = true;
  373. }
  374. }
  375. }
  376. }
  377. }
  378.  
  379. return avoid;
  380. };
  381. // Screen to Canvas coordinate conversion - used for collision detection
  382. window.collisionScreenToCanvas = function(circle) {
  383. var newCircle = window.mapToMouse(circle.x, circle.y);
  384. newCircle = window.mouseToScreen(newCircle[0], newCircle[1]);
  385. newCircle = window.screenToCanvas(newCircle[0], newCircle[1]);
  386.  
  387. return {
  388. x: newCircle[0],
  389. y: newCircle[1],
  390. radius: circle.radius
  391. };
  392. };
  393. // Change direction
  394. window.changeGoalCoords = function(circle1) {
  395. if ((circle1.x != window.collisionPoint.x && circle1.y != window.collisionPoint.y)) {
  396. window.collisionPoint = circle1;
  397. window.goalCoordinates = window.mapToMouse(window.snake.xx + (window.snake.xx - window.collisionPoint.x), window.snake.yy + (window.snake.yy - window.collisionPoint.y));
  398. window.setAcceleration(0);
  399. window.setMouseCoordinates(goalCoordinates[0], goalCoordinates[1]);
  400. }
  401. };
  402. // Check if circles intersect
  403. window.circleIntersect = function(circle1, circle2) {
  404. if (quickCollisionCheck(circle1, circle2)) {
  405. if (collisionCheck(circle1, circle2)) {
  406. return true;
  407. } else {
  408. return false;
  409. }
  410. } else {
  411. return false;
  412. }
  413. };
  414. // Quickly check if we are going to collide with anything
  415. window.quickCollisionCheck = function(circle1, circle2) {
  416. return (circle1.x + circle1.radius + circle2.radius > circle2.x &&
  417. circle1.x < circle2.x + circle1.radius + circle2.radius &&
  418. circle1.y + circle1.radius + circle2.radius > circle2.y &&
  419. circle1.y < circle2.y + circle1.radius + circle2.radius);
  420. };
  421. // Collision check
  422. window.collisionCheck = function(circle1, circle2) {
  423. distance = Math.sqrt(((circle1.x - circle2.x) * (circle1.x - circle2.x)) + ((circle1.y - circle2.y) * (circle1.y - circle2.y)));
  424.  
  425. if (distance < circle1.radius + circle2.radius) {
  426. collisionPointX = ((circle1.x * circle2.radius) + (circle2.x * circle1.radius)) / (circle1.radius + circle2.radius);
  427. collisionPointY = ((circle1.y * circle2.radius) + (circle2.y * circle1.radius)) / (circle1.radius + circle2.radius);
  428.  
  429. if (window.visualDebugging) {
  430. window.drawDot(collisionPointX, collisionPointY, circle2.radius, 'cyan', true);
  431. window.drawDot(circle2.x, circle2.y, circle2.radius, 'red', true);
  432. }
  433. return true;
  434. } else {
  435. return false;
  436. }
  437. };
  438.  
  439. // Sort food based on distance
  440. window.getSortedFood = function() {
  441. // Filters the nearest food by getting the distance
  442. return window.foods.filter(function(val) {
  443. return val !== null;
  444. }).map(window.getDistanceFromMe).sort(window.sortFood);
  445. };
  446. // Sort prey based on distance
  447. window.getSortedPrey = function() {
  448. // Filters the nearest food by getting the distance
  449. return window.preys.filter(function(val) {
  450. return val !== null;
  451. }).map(window.getDistanceFromMe).sort(window.sortPrey);
  452. };
  453. // Draw dots on the canvas
  454. window.drawDot = function(x, y, radius, colour, fill) {
  455. var context = window.mc.getContext('2d');
  456. context.beginPath();
  457. context.strokeStyle = '#00FF00';
  458. context.arc(x, y, radius * window.getScale(), 0, Math.PI * 2);
  459. context.closePath();
  460. if (fill) {
  461. context.fillStyle = ('green red white yellow black cyan blue'.indexOf(colour) < 0) ? 'white' : colour;
  462. context.fill();
  463. context.fillStyle = 'black';
  464. }
  465. };
  466.  
  467. // Draw lines on the canvas
  468. window.drawLine = function(x2, y2, colour) {
  469. var context = window.mc.getContext('2d');
  470. var center = [window.mc.height / 2, window.mc.width / 2];
  471. context.lineWidth = 5 * window.getScale();
  472. context.strokeStyle = (colour === 'green') ? '#00FF00' : '#FF0000';
  473. context.moveTo(center[1], center[0]);
  474. context.lineTo(x2, y2);
  475. context.stroke();
  476. context.strokeStyle = '#000000';
  477. };
  478. // Save the original slither.io oef function so we can add things to it later
  479. window.oldOef = window.oef;
  480. window.oef = function() {
  481. // Original slither.io oef function + whatever is under it
  482. // requestAnimationFrame(window.loop);
  483. window.oldOef();
  484. if (window.isBotRunning) window.loop();
  485. window.onFrameUpdate();
  486. };
  487. window.handleTextColor = function(enabled) {
  488. return '<span style=\"opacity: 0.8; color:' + (enabled ? 'green;\">enabled' : 'red;\">disabled') + '</span>';
  489. };
  490. window.onFrameUpdate = function() {
  491. // Botstatus overlay
  492. var generalStyle = '<span style = "opacity: 0.35";>';
  493. window.botstatus_overlay.innerHTML = generalStyle + '(T) Bot: </span>' + window.handleTextColor(window.isBotRunning);
  494. window.visualdebugging_overlay.innerHTML = generalStyle + '(Y) Visual debugging: </span>' + window.handleTextColor(window.visualDebugging);
  495. window.logdebugging_overlay.innerHTML = generalStyle + '(U) Log debugging: </span>' + window.handleTextColor(window.logDebugging);
  496. window.autorespawn_overlay.innerHTML = generalStyle + '(I) Auto respawning: </span>' + window.handleTextColor(window.autoRespawn);
  497. window.rendermode_overlay.innerHTML = generalStyle + '(O) Mobile rendering: </span>' + window.handleTextColor(window.mobileRender);
  498. window.huntprey_overlay.innerHTML = generalStyle + '(P) Prey hunting: </span>' + window.handleTextColor(window.huntPrey);
  499. window.collision_detection_overlay.innerHTML = generalStyle + '(C) Collision detection: </span>' + window.handleTextColor(window.collisionDetection);
  500. window.collision_radius_multiplier_overlay.innerHTML = generalStyle + '(A/S) Collision radius multiplier: ' + window.collisionRadiusMultiplier + ' </span>';
  501. window.defence_overlay.innerHTML = generalStyle + '(D) Defence: </span>' + window.handleTextColor(window.defence);
  502. window.resetzoom_overlay.innerHTML = generalStyle + '(Z) Reset zoom </span>';
  503. window.fps_overlay.innerHTML = generalStyle + 'FPS: ' + window.framesPerSecond.getFPS() + '</span>';
  504.  
  505. // If playing
  506. if (window.playing && window.visualDebugging) {
  507. if (window.isBotRunning) {
  508. // Check to see if there is a position overlay
  509. if (window.position_overlay) {
  510. // Display the X and Y of the snake
  511. window.position_overlay.innerHTML = generalStyle + 'X: ' + (Math.round(window.snake.xx) || 0) + ' Y: ' + (Math.round(window.snake.yy) || 0) + '</span>';
  512. }
  513. drawGoalCoordinates = window.mouseToScreen(window.goalCoordinates[0], window.goalCoordinates[1]);
  514. drawGoalCoordinates = window.screenToCanvas(drawGoalCoordinates[0], drawGoalCoordinates[1]);
  515. window.drawLine(drawGoalCoordinates[0], drawGoalCoordinates[1], 'green');
  516. window.drawDot(drawGoalCoordinates[0], drawGoalCoordinates[1], 5, 'red', true);
  517. }
  518. }
  519. };
  520. // Defense mode - bot turns around in a circle
  521. window.playDefence = function(dir) {
  522. window.kd_l = (dir === "l");
  523. window.kd_r = (dir === "r");
  524. window.setMouseCoordinates(window.getWidth() / 2, window.getHeight() / 2);
  525. };
  526. // Actual bot code
  527.  
  528. // Loop for running the bot
  529. window.loop = function() {
  530. // If the game and the bot are running
  531. if (window.playing && window.isBotEnabled) {
  532. window.ranOnce = true;
  533. // TODO: Check some condition to see if we should play defence
  534. // Right now this just uses the manual toggle
  535. if (window.defence) {
  536. window.playDefence("l");
  537. return;
  538. }
  539.  
  540. // If no enemies or obstacles, go after what you are going after
  541. if ((!window.checkCollision(window.getX(), window.getY(), window.getSnakeWidth()*window.collisionRadiusMultiplier)) && window.huntPrey) {
  542. // Sort the food based on their distance relative to player's snake
  543. window.sortedFood = window.getSortedFood();
  544. // Current food
  545. window.currentFood = window.sortedFood[0];
  546. // Convert coordinates of the closest food using mapToMouse
  547. var coordinatesOfClosestFood = window.mapToMouse(window.currentFood.xx, window.currentFood.yy);
  548. window.goalCoordinates = coordinatesOfClosestFood;
  549. // Disable Sprint
  550. window.setAcceleration(0);
  551. // Check for preys, enough "length"
  552. if (window.preys.length > 0) {
  553. // Sort preys based on their distance relative to player's snake
  554. window.sortedPrey = window.getSortedPrey();
  555. // Current prey
  556. window.currentPrey = window.sortedPrey[0];
  557. // Convert coordinates of the closest prey using mapToMouse
  558. var coordinatesOfClosestPrey = window.mapToMouse(window.currentPrey.xx, window.currentPrey.yy);
  559. // Check for the distance
  560. if (window.currentPrey.distance <= Math.pow(window.getSnakeLength(), 2) / 2) {
  561. // Set the mouse coordinates to the coordinates of the closest prey
  562. window.goalCoordinates = coordinatesOfClosestPrey;
  563. // "Sprint" enabled
  564. window.setAcceleration(1);
  565. }
  566. }
  567. window.kd_l = false;
  568. window.kd_r = false;
  569. window.setMouseCoordinates(window.goalCoordinates[0], window.goalCoordinates[1]);
  570. }
  571. if (!window.defence && !window.huntPrey){
  572. //continue what is being done
  573. window.setMouseCoordinates(mouseCoords.x - (innerWidth / 2), mouseCoords.y - (innerHeight / 2));
  574. }
  575. } else {
  576. if (window.ranOnce) {
  577. //window.startInterval = setInterval(window.startBot, 1000);
  578. window.stopBot();
  579. }
  580. }
  581. };
  582.  
  583. // Target the user's browser.
  584. (function() {
  585. var requestAnimationFrame = window.requestAnimationFrame ||
  586. window.mozRequestAnimationFrame ||
  587. window.webkitRequestAnimationFrame ||
  588. window.msRequestAnimationFrame;
  589.  
  590. window.requestAnimationFrame = requestAnimationFrame;
  591. })();
  592.  
  593. // Starts bot
  594. window.startBot = function() {
  595. if (window.autoRespawn && !window.playing && window.isBotEnabled && window.ranOnce && !window.isBotRunning) {
  596. window.connectBot();
  597. //clearInterval(window.startInterval);
  598. }
  599. };
  600. // Initialises the bot
  601. window.initBot = function() {
  602. window.ranOnce = false;
  603. window.isBotRunning = false;
  604. window.isBotEnabled = true;
  605. window.collisionPoint = {
  606. x: 0,
  607. y: 0,
  608. radius: 0
  609. };
  610. // Load preferences
  611. window.loadPreference('logDebugging', false);
  612. window.loadPreference('visualDebugging', false);
  613. window.loadPreference('autoRespawn', false);
  614. window.loadPreference('mobileRender', false);
  615. window.loadPreference('huntPrey', true);
  616. window.loadPreference('collisionDetection', true);
  617. window.loadPreference('collisionRadiusMultiplier', 8);
  618. window.loadPreference('defence', false);
  619. window.nick.value = window.loadPreference('savedNick', '');
  620. // Overlays
  621. // Top left
  622. window.generalstyle = 'color: #FFF; font-family: Arial, \'Helvetica Neue\', Helvetica, sans-serif; font-size: 14px; position: fixed; z-index: 7;';
  623. window.appendDiv('botstatus_overlay', 'nsi', window.generalstyle + 'left: 30; top: 30px;');
  624. window.appendDiv('visualdebugging_overlay', 'nsi', window.generalstyle + 'left: 30; top: 45px;');
  625. window.appendDiv('logdebugging_overlay', 'nsi', window.generalstyle + 'left: 30; top: 60px;');
  626. window.appendDiv('autorespawn_overlay', 'nsi', window.generalstyle + 'left: 30; top: 75px;');
  627. window.appendDiv('rendermode_overlay', 'nsi', window.generalstyle + 'left: 30; top: 90px;');
  628. window.appendDiv('huntprey_overlay', 'nsi', window.generalstyle + 'left: 30; top: 105px;');
  629. window.appendDiv('collision_detection_overlay', 'nsi', window.generalstyle + 'left: 30; top: 120px;');
  630. window.appendDiv('collision_radius_multiplier_overlay', 'nsi', window.generalstyle + 'left: 30; top: 135px;');
  631. window.appendDiv('defence_overlay', 'nsi', window.generalstyle + 'left: 30; top: 150px;');
  632. window.appendDiv('resetzoom_overlay', 'nsi', window.generalstyle + 'left: 30; top: 165px;');
  633. // Bottom right
  634. window.appendDiv('position_overlay', 'nsi', window.generalstyle + 'right: 30; bottom: 120px;');
  635. window.appendDiv('fps_overlay', 'nsi', window.generalstyle + 'right: 30; bottom: 170px;');
  636. // Listener for mouse wheel scroll - used for setZoom function
  637. document.body.addEventListener('mousewheel', window.setZoom);
  638. document.body.addEventListener('DOMMouseScroll', window.setZoom);
  639. // Set render mode
  640. if (window.mobileRender) {
  641. setBackground('data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs');
  642. window.render_mode = 1;
  643. } else {
  644. setBackground();
  645. window.render_mode = 2;
  646. }
  647. // Canvas Ratio
  648. window.canvasRatio = [window.mc.width / window.getWidth(), window.mc.height / window.getHeight()];
  649. // Unblocks all skins without the need for FB sharing.
  650. window.localStorage.setItem('edttsg', '1');
  651. // Remove social
  652. window.social.remove();
  653. // Start!
  654. window.launchBot(50);
  655. window.startInterval = setInterval(window.startBot, 1000);//possible will remove because this could cause great lag
  656. };
  657. window.initBot();
  658.  
Add Comment
Please, Sign In to add comment