Base Zones

credits to cazka for basically 99% of this script, no this is not a multiboxing script

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

  1. // ==UserScript==
  2. // @name Base Zones
  3. // @description credits to cazka for basically 99% of this script, no this is not a multiboxing script
  4. // @version 1.0.11
  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. const refreshRate = 2000;
  16.  
  17. function fillBlue2(flag) {
  18. if (flag > 0) {
  19. if (player.dead) return;
  20. ctx.save();
  21. ctx.globalAlpha = 0.20;
  22. if (player.gamemode === 'teams') {
  23. ctx.fillStyle = '#006480';
  24. ctx.beginPath();
  25. ctx.arc(960,540-compensation/2,80,0,2*Math.PI);
  26. ctx.fill();
  27. ctx.restore();
  28. }
  29. }
  30. }
  31. function fillRed2(flag) {
  32. if (flag > 0) {
  33. if (player.dead) return;
  34. ctx.save();
  35. ctx.globalAlpha = 0.20;
  36. if (player.gamemode === 'teams') {
  37. ctx.fillStyle = '#963033';
  38. ctx.beginPath();
  39. ctx.arc(960,540-compensation/2,80,0,2*Math.PI);
  40. ctx.fill();
  41. ctx.restore();
  42. }
  43. }
  44. }
  45. function fillBlue(flag) {
  46. if (flag > 0) {
  47.  
  48. if (player.dead) return;
  49. ctx.save();
  50. ctx.globalAlpha = 0.20*flag;
  51. let length = 160;
  52. let width = 9/16*length;
  53. if (player.gamemode === '4teams') {
  54. ctx.fillStyle = '#006480';
  55. ctx.beginPath();
  56. ctx.arc(960,540-compensation/2,80,0,2*Math.PI);
  57. ctx.fill();
  58. ctx.restore();
  59. }
  60. }
  61. }
  62. function fillRed(flag) {
  63. if (flag > 0) {
  64. if (player.dead) return;
  65. ctx.save();
  66. ctx.globalAlpha = 0.20*flag;
  67. let length = 160;
  68. let width = 9/16*length;
  69. if (player.gamemode === '4teams') {
  70. ctx.fillStyle = '#963033';
  71. ctx.beginPath();
  72. ctx.arc(960,540-compensation/2,80,0,2*Math.PI);
  73. ctx.fill();
  74. ctx.restore();
  75. }
  76. }
  77. }
  78. function fillGreen(flag) {
  79. if (flag > 0) {
  80. if (player.dead) return;
  81. ctx.save();
  82. ctx.globalAlpha = 0.20*flag;
  83. let length = 160;
  84. let width = 9/16*length;
  85. if (player.gamemode === '4teams') {
  86. ctx.fillStyle = '#00803e';
  87. ctx.beginPath();
  88. ctx.arc(960,540-compensation/2,80,0,2*Math.PI);
  89. ctx.fill();
  90. }
  91. ctx.restore();
  92. }
  93. }
  94. function fillPurple(flag) {
  95. if (flag > 0) {
  96. if (player.dead) return;
  97. ctx.save();
  98. ctx.globalAlpha = 0.20*flag;
  99. let length = 160;
  100. let width = 9/16*length;
  101. if (player.gamemode === '4teams') {
  102. ctx.fillStyle = '#644280';
  103. ctx.beginPath();
  104. ctx.arc(960,540-compensation/2,80,0,2*Math.PI);
  105. ctx.fill();
  106. ctx.restore();
  107. }
  108. }
  109. }
  110. class Gui {
  111. constructor(title) {
  112. this._buttons = [];
  113. }
  114. }
  115. class Minimap {
  116. constructor() {
  117. this._minimapWidth;
  118. this._minimapHeight;
  119. this._x00;
  120. this._y00;
  121. this._pointX;
  122. this._pointY;
  123. this._pointX_previous;
  124. this._pointY_previous;
  125. this._viewportWidth;
  126. this._viewportHeight;
  127. this._fov;
  128.  
  129. this._minimapHook();
  130. this._arrowHook();
  131. this._viewportHook();
  132. this._fovHook();}
  133. get x() {
  134. return this._pointX ? (this._pointX - this._x00) / this._minimapWidth : 0;
  135. }
  136. get y() {
  137. return this._pointY ? (this._pointY - this._y00) / this._minimapHeight : 0;
  138. }
  139. get x_previous() {
  140. return this._pointX_previous ? (this._pointX_previous - this._x00) / this._minimapWidth : 0;
  141. }
  142. get y_previous() {
  143. return this._pointY_previous ? (this._pointY_previous - this._y00) / this._minimapHeight : 0;
  144. }
  145. get fov() {
  146. return this._fov;
  147. }
  148.  
  149. _minimapHook() {
  150. let setTransformArgs;
  151.  
  152. const onsetTransform = (args) => {
  153. if (args[0] === args[3]) setTransformArgs = args;
  154. };
  155. const onstrokeRect = () => {
  156. if (setTransformArgs) {
  157. this._minimapWidth = setTransformArgs[0];
  158. this._minimapHeight = setTransformArgs[3];
  159. this._x00 = setTransformArgs[4];
  160. this._y00 = setTransformArgs[5];
  161. setTransformArgs = undefined;
  162. }
  163. };
  164. this._ctxHook('setTransform', onsetTransform);
  165. this._ctxHook('strokeRect', onstrokeRect);
  166. }
  167. _arrowHook() {
  168. let index = 0;
  169. const stack = Array(4);
  170.  
  171. let pointA;
  172. let pointB;
  173. let pointC;
  174.  
  175. const calculatePos = () => {
  176. const side1 = Math.floor(
  177. Math.sqrt(Math.pow(pointA[0] - pointB[0], 2) + Math.pow(pointA[1] - pointB[1], 2))
  178. );
  179. const side2 = Math.floor(
  180. Math.sqrt(Math.pow(pointA[0] - pointC[0], 2) + Math.pow(pointA[1] - pointC[1], 2))
  181. );
  182. const side3 = Math.floor(
  183. Math.sqrt(Math.pow(pointB[0] - pointC[0], 2) + Math.pow(pointB[1] - pointC[1], 2))
  184. );
  185. if (side1 == side2 && side2 == side3) return;
  186.  
  187. this._pointX_previous = this._pointX;
  188. this._pointY_previous = this._pointY;
  189.  
  190. this._pointX = (pointA[0] + pointB[0] + pointC[0]) / 3;
  191. this._pointY = (pointA[1] + pointB[1] + pointC[1]) / 3;
  192. };
  193. const onbeginPath = () => {
  194. index = 0;
  195. stack[index++] = 0;
  196. };
  197. const onmoveTo = (args) => {
  198. if (index === 1 && stack[index - 1] === 0) {
  199. stack[index++] = 1;
  200. pointA = args;
  201. return;
  202. }
  203. index = 0;
  204. };
  205. const onlineTo = (args) => {
  206. if (index === 2 && stack[index - 1] === 1) {
  207. stack[index++] = 2;
  208. pointB = args;
  209. return;
  210. }
  211. if (index === 3 && stack[index - 1] === 2) {
  212. stack[index++] = 2;
  213. pointC = args;
  214. return;
  215. }
  216. index = 0;
  217. };
  218. const onfill = () => {
  219. if (index === 4 && stack[index - 1] === 2) {
  220. calculatePos();
  221. return;
  222. }
  223. index = 0;
  224. };
  225.  
  226. this._ctxHook('beginPath', onbeginPath);
  227. this._ctxHook('moveTo', onmoveTo);
  228. this._ctxHook('lineTo', onlineTo);
  229. this._ctxHook('fill', onfill);
  230. }
  231. _viewportHook() {
  232. let setTransformArgs;
  233.  
  234. const onsetTransform = (args) => {
  235. if ((args[0] / args[3]).toFixed(4) !== (unsafeWindow.innerWidth / unsafeWindow.innerHeight).toFixed(4)) return;
  236. if (args[0] >= unsafeWindow.innerWidth && args[3] >= unsafeWindow.innerHeight) return;
  237. setTransformArgs = args;
  238. };
  239. const onfillRect = () => {
  240. if (setTransformArgs) {
  241. unsafeWindow.input.set_convar('ren_minimap_viewport', true);
  242. this._viewportWidth = setTransformArgs[0];
  243. this._viewportHeight = setTransformArgs[3];
  244. setTransformArgs = undefined;
  245. }
  246. };
  247.  
  248. this._ctxHook('setTransform', onsetTransform);
  249. this._ctxHook('fillRect', onfillRect);
  250.  
  251. setInterval(() => {
  252. unsafeWindow.input.set_convar('ren_minimap_viewport', true);
  253. }, 1000);
  254. }
  255. _fovHook() {
  256. let solid_background = false;
  257. setTimeout(() => {
  258. solid_background = unsafeWindow.input.get_convar('ren_solid_background') === 'true' ? true : false;
  259. }, 1000);
  260.  
  261. const calculateFov = (fov) => {
  262. this._fov = fov * 10;
  263. };
  264. function onstroke() {
  265. if (this.fillStyle === '#cdcdcd') {
  266. if (solid_background) unsafeWindow.input.set_convar('ren_solid_background', true);
  267. calculateFov(this.globalAlpha);
  268. }
  269. }
  270.  
  271. this._ctxHook('stroke', onstroke);
  272.  
  273. setInterval(() => {
  274. if (solid_background) unsafeWindow.input.set_convar('ren_solid_background', false);
  275. }, 10000);
  276. }
  277. _ctxHook(method, hook) {
  278. const target = window.CanvasRenderingContext2D.prototype;
  279. target[method] = new Proxy(target[method], {
  280. apply(target, thisArg, args) {
  281. args = hook.call(thisArg, args) || args;
  282. return target.apply(thisArg, args);
  283. },
  284. });
  285. }
  286. }
  287.  
  288. class Vector {}
  289.  
  290. class Arena {
  291. static get BLOCKSIZE() {
  292. return 50;
  293. }
  294. }
  295. class Player {
  296. constructor() {
  297. this._minimap = new Minimap();
  298. this._dead = true;
  299.  
  300. //Dead Listener
  301. new MutationObserver((args) => {
  302. this._dead = args[0].target.style.display === 'block';
  303. if (this.ondead && this._dead) this.ondead();
  304. }).observe(document.getElementById('a'), { attributes: true });
  305. }
  306.  
  307. get dead() {
  308. return this._dead;
  309. }
  310.  
  311. get gamemode() {
  312. return unsafeWindow.localStorage.gamemode;
  313. }
  314.  
  315. }
  316.  
  317.  
  318. class Chat {
  319. constructor(player) {
  320. this._player = player;
  321. this._hookonkeydown();
  322. this._hookAnimationFrame();
  323. }
  324.  
  325. _hookonkeydown() {
  326. const _this = this;
  327. unsafeWindow.onkeydown = new Proxy(unsafeWindow.onkeydown, {
  328. });
  329. }
  330. _hookAnimationFrame() {
  331. const _this = this;
  332. unsafeWindow.requestAnimationFrame = new Proxy(unsafeWindow.requestAnimationFrame, {
  333. });
  334. }
  335. }
  336.  
  337. const player = new Player();
  338. const arena = new Arena();
  339. const chat = new Chat(player);
  340. const minimap = new Minimap();
  341. const radius = 44;
  342. const width = 149;
  343.  
  344. var ack = 0.75;
  345. var a,fj,fk,fl,fm,tj,tk,c1,c2,c3,c4,c5,c6 = 0;
  346. var yes = 1
  347. var scale = d/175;
  348. var x = minimap._pointX;
  349. var y = minimap._pointY;
  350. var d = minimap._minimapWidth;
  351. var compensation = a * (width+18);
  352.  
  353. //setup canvas
  354. const ctx = document.getElementById('canvas').getContext('2d');
  355. // run main Loop
  356. document.body.onkeydown = function(e) {
  357. if (e.keyCode === 32) {
  358. if (yes == 1) {
  359. yes = 0;
  360. } else {
  361. yes = 1;
  362. }
  363. }
  364. }
  365. unsafeWindow.requestAnimationFrame = new Proxy(unsafeWindow.requestAnimationFrame, {
  366. apply: function (target, thisArg, args) {
  367. if (yes == 1){
  368.  
  369.  
  370. x = minimap._pointX;
  371. scale = d / 175;
  372. y = minimap._pointY;
  373. compensation = a * (width+18);
  374. if (player.gamemode === '4teams') {
  375. //4 teams
  376. //Blue
  377. setInterval(() => {
  378. c1 = Math.pow(1920-(1920-1738)*scale-x,2) + Math.pow(1080-(1080-898)*scale-compensation-y,2)
  379. ack = Math.pow(c1/Math.pow(radius*scale, 2), 0.5)
  380. fj = 5.5-5*ack;
  381.  
  382. }, refreshRate);
  383. //Purple
  384. setInterval(() => {
  385. c2 = Math.pow(1920-(1920-1738)*scale+width*scale-x,2) + Math.pow(1080-(1080-898)*scale-compensation-y,2)
  386. ack = Math.pow(c2/Math.pow(radius*scale, 2), 0.5)
  387. fk = 5.5-5*ack;
  388.  
  389. }, refreshRate);
  390. //Green
  391. setInterval(() => {
  392. c3 = Math.pow(1920-(1920-1738)*scale-x,2) + Math.pow(1080-(1080-898)*scale+width*scale-compensation-y,2)
  393. ack = Math.pow(c3/Math.pow(radius*scale, 2), 0.5)
  394. fl = 5.5-5*ack;
  395.  
  396. }, refreshRate);
  397. //Red
  398. setInterval(() => {
  399. c4 = Math.pow(1920-(1920-1738)*scale+width*scale-x,2) + Math.pow(1080-(1080-898)*scale+width*scale-compensation-y,2)
  400. ack = Math.pow(c4/Math.pow(radius*scale, 2), 0.5)
  401. fm = 5.5-5*ack;
  402.  
  403. }, refreshRate);
  404. }
  405. else if (player.gamemode === 'teams') {
  406. //2 teams
  407. //Blue
  408. setInterval(() => {
  409. if(1920-(1920-1728)*scale+40*scale>x) {
  410. tj = 1;}
  411. else {tj = 0;}
  412.  
  413. }, refreshRate);
  414. //Red
  415. setInterval(() => {
  416. if(1920-(1920-1728)*scale+124*scale<x) {
  417. tk = 1;}
  418. else {tk = 0;}
  419.  
  420. }, refreshRate);
  421. }
  422. //Helpers
  423. setInterval(() => {
  424. if(window.innerHeight == screen.height) {
  425. a = 0;} else {a = 1;}}, refreshRate);
  426. setInterval(() => {d = minimap._minimapWidth}, refreshRate);
  427.  
  428. fillBlue(fj);
  429. fillPurple(fk);
  430. fillGreen(fl);
  431. fillRed(fm);
  432. fillBlue2(tj);
  433. fillRed2(tk);
  434. }
  435.  
  436. setTimeout(() => Reflect.apply(target, thisArg, args), 0);
  437. },
  438. });