Base Zones

diep.io base drone script

当前为 2021-10-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Base Zones
  3. // @description diep.io base drone script
  4. // @version 1.2.0
  5. // @author none
  6. // @match *://diep.io/*
  7. // @grant GM_addStyle
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM_addValueChangeListener
  11. // @grant GM_removeValueChangeListener
  12. // @namespace https://greasyfork.org/users/790354
  13. // ==/UserScript==
  14. 'use strict';
  15. function drawZones(x, y, a, b, c, d, scale) {
  16. if (player.dead) return;
  17. if (player.gamemode === '4teams') {
  18. if (player.dead) return;
  19. let r = 44;
  20. let positioning = 600;
  21. let arenaDim = 10000;
  22. ctx.save();
  23. ctx.globalAlpha = 0.12;
  24. //Blue
  25. ctx.fillStyle = '#006480';
  26. ctx.beginPath();
  27. ctx.arc(400+positioning-x, positioning-y, 65*r*scale, 0, 2*Math.PI);
  28. ctx.fill();
  29. ctx.fillStyle = '#1E86E0';
  30. ctx.beginPath();
  31. ctx.arc(400+positioning-x, positioning-y, 45*r*scale, 0, 2*Math.PI);
  32. ctx.fill();
  33. //Purple
  34. ctx.fillStyle = '#644280';
  35. ctx.beginPath();
  36. ctx.arc(arenaDim+1040-positioning-x, positioning-y, 65*r*scale, 0, 2*Math.PI);
  37. ctx.fill();
  38. ctx.fillStyle = '#B11EEF';
  39. ctx.beginPath();
  40. ctx.arc(arenaDim+1040-positioning-x, positioning-y, 45*r*scale, 0, 2*Math.PI);
  41. ctx.fill();
  42. //Green
  43. ctx.fillStyle = '#00803e';
  44. ctx.beginPath;
  45. ctx.arc(400+positioning-x, arenaDim+600-positioning-y, 65*r*scale, 0, 2*Math.PI);
  46. ctx.fill();
  47. ctx.fillStyle = '#11D84B';
  48. ctx.beginPath();
  49. ctx.arc(400+positioning-x, arenaDim+600-positioning-y, 45*r*scale, 0, 2*Math.PI);
  50. ctx.fill();
  51. //Red
  52. ctx.fillStyle = '#963033';
  53. ctx.beginPath();
  54. ctx.arc(1040+arenaDim-positioning-x, arenaDim+600-positioning-y, 65*r*scale, 0, 2*Math.PI);
  55. ctx.fill();
  56. ctx.fillStyle = '#ff3033';
  57. ctx.beginPath();
  58. ctx.arc(1040+arenaDim-positioning-x, arenaDim+600-positioning-y, 45*r*scale, 0, 2*Math.PI);
  59. ctx.fill();
  60. }
  61. ctx.restore();
  62. }
  63. class Gui {
  64. constructor(title) {
  65. this._buttons = [];
  66. }
  67. }
  68. class Minimap {
  69. constructor() {
  70. this._minimapWidth;
  71. this._minimapHeight;
  72. this._x00;
  73. this._y00;
  74. this._pointX;
  75. this._pointY;
  76. this._pointX_previous;
  77. this._pointY_previous;
  78. this._viewportWidth;
  79. this._viewportHeight;
  80. this._fov;
  81.  
  82. this._minimapHook();
  83. this._arrowHook();
  84. this._viewportHook();
  85. this._fovHook();}
  86. get x() {
  87. return this._pointX ? (this._pointX - this._x00) / this._minimapWidth : 0;
  88. }
  89. get y() {
  90. return this._pointY ? (this._pointY - this._y00) / this._minimapHeight : 0;
  91. }
  92. get x_previous() {
  93. return this._pointX_previous ? (this._pointX_previous - this._x00) / this._minimapWidth : 0;
  94. }
  95. get y_previous() {
  96. return this._pointY_previous ? (this._pointY_previous - this._y00) / this._minimapHeight : 0;
  97. }
  98. get fov() {
  99. return this._fov;
  100. }
  101.  
  102. _minimapHook() {
  103. let setTransformArgs;
  104.  
  105. const onsetTransform = (args) => {
  106. if (args[0] === args[3]) setTransformArgs = args;
  107. };
  108. const onstrokeRect = () => {
  109. if (setTransformArgs) {
  110. this._minimapWidth = setTransformArgs[0];
  111. this._minimapHeight = setTransformArgs[3];
  112. this._x00 = setTransformArgs[4];
  113. this._y00 = setTransformArgs[5];
  114. setTransformArgs = undefined;
  115. }
  116. };
  117. this._ctxHook('setTransform', onsetTransform);
  118. this._ctxHook('strokeRect', onstrokeRect);
  119. }
  120. _arrowHook() {
  121. let index = 0;
  122. const stack = Array(4);
  123.  
  124. let pointA;
  125. let pointB;
  126. let pointC;
  127.  
  128. const calculatePos = () => {
  129. const side1 = Math.floor(
  130. Math.sqrt(Math.pow(pointA[0] - pointB[0], 2) + Math.pow(pointA[1] - pointB[1], 2))
  131. );
  132. const side2 = Math.floor(
  133. Math.sqrt(Math.pow(pointA[0] - pointC[0], 2) + Math.pow(pointA[1] - pointC[1], 2))
  134. );
  135. const side3 = Math.floor(
  136. Math.sqrt(Math.pow(pointB[0] - pointC[0], 2) + Math.pow(pointB[1] - pointC[1], 2))
  137. );
  138. if (side1 == side2 && side2 == side3) return;
  139.  
  140. this._pointX_previous = this._pointX;
  141. this._pointY_previous = this._pointY;
  142.  
  143. this._pointX = (pointA[0] + pointB[0] + pointC[0]) / 3;
  144. this._pointY = (pointA[1] + pointB[1] + pointC[1]) / 3;
  145. };
  146. const onbeginPath = () => {
  147. index = 0;
  148. stack[index++] = 0;
  149. };
  150. const onmoveTo = (args) => {
  151. if (index === 1 && stack[index - 1] === 0) {
  152. stack[index++] = 1;
  153. pointA = args;
  154. return;
  155. }
  156. index = 0;
  157. };
  158. const onlineTo = (args) => {
  159. if (index === 2 && stack[index - 1] === 1) {
  160. stack[index++] = 2;
  161. pointB = args;
  162. return;
  163. }
  164. if (index === 3 && stack[index - 1] === 2) {
  165. stack[index++] = 2;
  166. pointC = args;
  167. return;
  168. }
  169. index = 0;
  170. };
  171. const onfill = () => {
  172. if (index === 4 && stack[index - 1] === 2) {
  173. calculatePos();
  174. return;
  175. }
  176. index = 0;
  177. };
  178.  
  179. this._ctxHook('beginPath', onbeginPath);
  180. this._ctxHook('moveTo', onmoveTo);
  181. this._ctxHook('lineTo', onlineTo);
  182. this._ctxHook('fill', onfill);
  183. }
  184. _viewportHook() {
  185. let setTransformArgs;
  186.  
  187. const onsetTransform = (args) => {
  188. if ((args[0] / args[3]).toFixed(4) !== (unsafeWindow.innerWidth / unsafeWindow.innerHeight).toFixed(4)) return;
  189. if (args[0] >= unsafeWindow.innerWidth && args[3] >= unsafeWindow.innerHeight) return;
  190. setTransformArgs = args;
  191. };
  192. const onfillRect = () => {
  193. if (setTransformArgs) {
  194. unsafeWindow.input.set_convar('ren_minimap_viewport', true);
  195. this._viewportWidth = setTransformArgs[0];
  196. this._viewportHeight = setTransformArgs[3];
  197. setTransformArgs = undefined;
  198. }
  199. };
  200.  
  201. this._ctxHook('setTransform', onsetTransform);
  202. this._ctxHook('fillRect', onfillRect);
  203.  
  204. setInterval(() => {
  205. unsafeWindow.input.set_convar('ren_minimap_viewport', true);
  206. }, 1000);
  207. }
  208. _fovHook() {
  209. let solid_background = false;
  210. setTimeout(() => {
  211. solid_background = unsafeWindow.input.get_convar('ren_solid_background') === 'true' ? true : false;
  212. }, 1000);
  213.  
  214. const calculateFov = (fov) => {
  215. this._fov = fov * 10;
  216. };
  217. function onstroke() {
  218. if (this.fillStyle === '#cdcdcd') {
  219. if (solid_background) unsafeWindow.input.set_convar('ren_solid_background', true);
  220. calculateFov(this.globalAlpha);
  221. }
  222. }
  223.  
  224. this._ctxHook('stroke', onstroke);
  225.  
  226. setInterval(() => {
  227. if (solid_background) unsafeWindow.input.set_convar('ren_solid_background', false);
  228. }, 10000);
  229. }
  230. _ctxHook(method, hook) {
  231. const target = window.CanvasRenderingContext2D.prototype;
  232. target[method] = new Proxy(target[method], {
  233. apply(target, thisArg, args) {
  234. args = hook.call(thisArg, args) || args;
  235. return target.apply(thisArg, args);
  236. },
  237. });
  238. }
  239. }
  240.  
  241. class Vector {}
  242.  
  243. class Arena {}
  244. class Player {
  245. constructor() {
  246. this._minimap = new Minimap();
  247. this._dead = true;
  248.  
  249. //Dead Listener
  250. new MutationObserver((args) => {
  251. this._dead = args[0].target.style.display === 'block';
  252. if (this.ondead && this._dead) this.ondead();
  253. }).observe(document.getElementById('a'), { attributes: true });
  254. }
  255.  
  256. get dead() {
  257. return this._dead;
  258. }
  259.  
  260. get gamemode() {
  261. return unsafeWindow.localStorage.gamemode;
  262. }
  263.  
  264. }
  265.  
  266. class Chat {
  267. constructor(player) {
  268. this._player = player;
  269. this._hookonkeydown();
  270. this._hookAnimationFrame();
  271. }
  272.  
  273. _hookonkeydown() {
  274. const _this = this;
  275. unsafeWindow.onkeydown = new Proxy(unsafeWindow.onkeydown, {
  276. });
  277. }
  278. _hookAnimationFrame() {
  279. const _this = this;
  280. unsafeWindow.requestAnimationFrame = new Proxy(unsafeWindow.requestAnimationFrame, {
  281. });
  282. }
  283. }
  284.  
  285. const player = new Player();
  286. const arena = new Arena();
  287. const chat = new Chat(player);
  288. const minimap = new Minimap();
  289. const radius = 44;
  290. const width = 149;
  291. const arenaScaling = 22300 / 175;
  292. var ack = 0.75;
  293. var a,fj,fk,fl,fm,tj,tk,c1,c2,c3,c4,c5,c6,scale,x,y,d,compensation = 0;
  294. var blue = 1;
  295. var purple = 1;
  296. var green = 1;
  297. var red = 1;
  298. var interX, interY, posX, posY;
  299. //setup canvas
  300. const ctx = document.getElementById('canvas').getContext('2d');
  301. // run main Loop
  302. document.body.onkeydown = function(e) {
  303. if (e.keyCode === 70) {
  304. blue = 1 - blue
  305. }
  306. if (e.keyCode === 71) {
  307. purple = 1 - purple
  308. }
  309. if (e.keyCode === 86) {
  310. green = 1 - green
  311. }
  312. if (e.keyCode === 66) {
  313. red = 1 - red
  314. }
  315. }
  316.  
  317. unsafeWindow.requestAnimationFrame = new Proxy(unsafeWindow.requestAnimationFrame, {
  318. apply: function (target, thisArg, args) {
  319. x = minimap._pointX;
  320. scale = d / 175;
  321. y = minimap._pointY;
  322. compensation = a * (width+18);
  323. //Helpers
  324. if(window.innerHeight == screen.height) {
  325. a = 0;} else {a = 1;}
  326. d = minimap._minimapWidth;
  327. //corner of minimap = (1920-(1920-1738)*scale, 920-(920-898)*scale+compensation/2)
  328. interX = x - (1920-(1920-1738)*scale);
  329. posX = interX * 11150 / d;
  330. interY = y - (920-(920-898)*scale-compensation);
  331. posY = interY * 11150 / d;
  332. drawZones(posX, posY, blue, purple, green, red, scale);
  333. setTimeout(() => Reflect.apply(target, thisArg, args), 0);
  334. },
  335. });