Afk Script

Press f to set the afk location and j to afk boom

当前为 2023-09-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Afk Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 1
  5. // @description Press f to set the afk location and j to afk boom
  6. // @author Mi300
  7. // @match https://diep.io/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @license dont copy my script thx
  10. // @grant none
  11. // ==/UserScript==
  12. setTimeout (function() {
  13. function hookContext(method, callback, target = CanvasRenderingContext2D) {
  14. target.prototype[method] = new Proxy(target.prototype[method], {
  15. apply(method, context, args) {
  16. callback(context, args);
  17. method.apply(context, args);
  18. }
  19. });
  20. };
  21. const canvas = document.getElementById('canvas');
  22. const ctx = canvas.getContext('2d');
  23. let distance = [0, 0];
  24. let isActive = false;
  25. let storedPos = [0, 0];
  26. let arrowPos = [0, 0];
  27. let minimapPos = [0, 0];
  28. let minimapDim = [0, 0];
  29. let worldPosition = [0, 0];
  30.  
  31. let teamSnapshot = false;
  32. let team = '#f14e54';
  33. function hookMinimapArrow() {
  34. let drawInstructions = 0;
  35. let vertices = new Array(0);
  36.  
  37. hookContext('beginPath', function(context, args) {
  38. drawInstructions = 1;
  39. vertices = new Array(0);
  40. });
  41. hookContext('moveTo', function(context, args) {
  42. drawInstructions = 2;
  43. vertices.push(args);
  44. });
  45. hookContext('lineTo', function(context, args) {
  46. if (drawInstructions >= 2 && drawInstructions <= 5) {
  47. drawInstructions++;
  48. vertices.push(args);
  49. return;
  50. }
  51. drawInstructions = 0;
  52. });
  53. hookContext('fill', function(context, args) {
  54. if (context.globalAlpha != 1 || context.fillStyle != '#000000') {
  55. return;
  56. }
  57. if (drawInstructions === 4) {
  58. const pos = getAverage (vertices);
  59. arrowPos = pos;
  60. }
  61. });
  62. }
  63. function hookMinimap() {
  64. hookContext('strokeRect', function(context, args) {
  65. const t = context.getTransform();
  66. minimapPos = [t.e, t.f];
  67. minimapDim = [t.a, t.d];
  68. });
  69. hookContext('rect', function(context, args) {// purple: #bf7ff5, red: #f14e54, blue: #00b2e1, green: #00e16e
  70. const c = context.fillStyle;
  71. if (teamSnapshot) {
  72. if (c == '#f14e54') {
  73. team = c;
  74. }
  75. if (c == '#00b2e1') {
  76. team = c;
  77. }
  78. if (c == '#bf7ff5') {
  79. team = c;
  80. }
  81. if (c == '#00e16e') {
  82. team = c;
  83. }
  84. }
  85. });
  86. }
  87. hookMinimap();
  88. hookMinimapArrow();
  89. function getAverage(points) {
  90. let ret = [0, 0];
  91. points.forEach (point => {
  92. ret[0] += point[0];
  93. ret[1] += point[1];
  94. });
  95. ret[0] /= points.length;
  96. ret[1] /= points.length;
  97. return ret;
  98. }
  99. function getWorldPos () {
  100. const ret = [
  101. parseFloat((((arrowPos[0] - minimapPos[0] - minimapDim[0] / 2) / minimapDim[0] * 100) * 460).toFixed (3)),
  102. parseFloat((((arrowPos[1] - minimapPos[1] - minimapDim[1] / 2) / minimapDim[1] * 100) * 460).toFixed (3)),
  103. ]
  104. return ret;
  105. }
  106. let lineWidth = 0;
  107. let cameraZoom = 0;
  108. CanvasRenderingContext2D.prototype.stroke = new Proxy(CanvasRenderingContext2D.prototype.stroke, {
  109. apply(method, self, args) {
  110. lineWidth = self.lineWidth;
  111. return Reflect.apply(method, self, args);
  112. }
  113. });
  114. CanvasRenderingContext2D.prototype.createPattern = new Proxy(CanvasRenderingContext2D.prototype.createPattern, {
  115. apply(method, self, args) {
  116. cameraZoom = 1 / lineWidth;
  117. return Reflect.apply(method, self, args);
  118. }
  119. });
  120. input.try_spawn = new Proxy(input.try_spawn, {
  121. apply(method, self, args) {
  122. teamSnapshot = true;
  123. setTimeout(function() {
  124. teamSnapshot = false;
  125. console.log (team)
  126. },1000);
  127. return Reflect.apply(method, self, args);
  128. }
  129. });
  130. function tick() {
  131. window.requestAnimationFrame(tick);
  132. worldPosition = getWorldPos();
  133. distance = getDist(
  134. worldPosition,
  135. storedPos,
  136. )
  137. if (isActive) {
  138. move();
  139. }
  140. drawAfkPos();
  141. }
  142. tick();
  143. function toGrid(dist) {
  144. return [
  145. dist[0] / ((1 - cameraZoom) * 8),
  146. dist[1] / ((1 - cameraZoom) * 8),
  147. dist[2] / ((1 - cameraZoom) * 8),
  148. ]
  149. }
  150. function drawAfkPos() {
  151. //distance
  152. const width = canvas.width;
  153. const height = canvas.height;
  154.  
  155. const grid = toGrid(distance);
  156. const size = 50;
  157. let toDraw = [
  158. width / 2 - grid[1],
  159. height / 2 - grid[2],
  160. ]
  161. ctx.beginPath();
  162. ctx.globalAlpha = 0.5;
  163. ctx.fillStyle = team
  164. ctx.arc(...toDraw, size, 0, Math.PI * 2, false);
  165. ctx.fill();
  166. ctx.stroke();
  167. ctx.globalAlpha = 1;
  168.  
  169. ctx.beginPath();
  170. ctx.lineWidth = 4;
  171. ctx.font = "23px bold arial"
  172. ctx.fillStyle = 'white';
  173. ctx.strokeStyle = 'black';
  174. if (isActive) {
  175. ctx.strokeText('[J] Locked', toDraw[0] - 50, toDraw[1] + 25);
  176. ctx.fillText('[J] Locked', toDraw[0] - 50, toDraw[1] + 25);
  177. } else {
  178. ctx.strokeText('[J] Unlocked', toDraw[0] - 50, toDraw[1] + 25);
  179. ctx.fillText('[J] Unlocked', toDraw[0] - 50, toDraw[1] + 25);
  180. }
  181.  
  182. }
  183. document.addEventListener('keydown', e => {
  184. if(e.key === 'j') {
  185. isActive = !isActive;
  186. input.key_up (83);
  187. input.key_up (87);
  188. input.key_up (68);
  189. input.key_up (65);
  190. }
  191. if(e.key === 'f') {
  192. storedPos = worldPosition;
  193. }
  194. });
  195. function getDist(t1, t2) {
  196. const distX = t1[0] - t2[0];
  197. const distY = t1[1] - t2[1];
  198. return [Math.hypot(distX, distY), distX, distY];
  199. };
  200. function move() {
  201. if (distance[1] < 0.1) {
  202. input.key_up (65);
  203. input.key_down (68);
  204. } else if (distance[1] > -0.1) {
  205. input.key_up (68);
  206. input.key_down (65);
  207. } else {
  208. input.key_up (68);
  209. input.key_up (65);
  210. }
  211.  
  212. if (distance[2] < 0.1) {
  213. input.key_up (87);
  214. input.key_down (83);
  215. } else if (distance[2] > 0.1) {
  216. input.key_up (83);
  217. input.key_down (87);
  218. } else {
  219. input.key_up (83);
  220. input.key_up (87);
  221. }
  222. }
  223. },2500);