Base Zones REAL

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

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

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