Base Zones

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

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

  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.6
  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. //set scale here
  16. const scales = 1
  17. function drawZones(scale, notFullScreen) {
  18. if (player.dead) return;
  19. ctx.save();
  20. ctx.globalAlpha = 0.08;
  21. let radius = 48;
  22. let width = 169;
  23. let compensation = notFullScreen * (width-2);
  24.  
  25. if (player.gamemode === '4teams') {
  26.  
  27. //blue
  28. ctx.fillStyle = '#006480';
  29. ctx.beginPath();
  30. ctx.arc(1920-(1920-1728)*scale, 1080-(1080-888)*scale-compensation, radius*scale, 0 * Math.PI, 1/2 * Math.PI);
  31. ctx.fill();
  32. ctx.beginPath();
  33. ctx.moveTo(1920-(1920-1728)*scale, 1080-(1080-888)*scale-compensation);
  34. ctx.lineTo(1920-(1920-1728)*scale+radius*scale, 1080-(1080-888)*scale-compensation);
  35. ctx.lineTo(1920-(1920-1728)*scale, 1080-(1080-888)*scale+radius*scale-compensation);
  36. ctx.fill();
  37.  
  38. //purple
  39. ctx.fillStyle = '#644280';
  40. ctx.beginPath();
  41. ctx.arc(1920-(1920-1728)*scale+width*scale, 1080-(1080-888)*scale-compensation, radius*scale, 1/2 * Math.PI, Math.PI);
  42. ctx.fill();
  43. ctx.beginPath();
  44. ctx.moveTo(1920-(1920-1728)*scale+width*scale, 1080-(1080-888)*scale-compensation);
  45. ctx.lineTo(1920-(1920-1728)*scale+radius*scale+width*scale-2*radius*scale, 1080-(1080-888)*scale-compensation);
  46. ctx.lineTo(1920-(1920-1728)*scale+width*scale, 1080-(1080-888)*scale+radius*scale-compensation);
  47. ctx.fill();
  48.  
  49. //green
  50. ctx.fillStyle = '#00803e';
  51. ctx.beginPath();
  52. ctx.arc(1920-(1920-1728)*scale, 1080-(1080-888)*scale+width*scale-compensation, radius*scale, 3/2 * Math.PI, 2 * Math.PI);
  53. ctx.fill()
  54. ctx.beginPath();
  55. ctx.moveTo(1920-(1920-1728)*scale, 1080-(1080-888)*scale+width*scale-compensation);
  56. ctx.lineTo(1920-(1920-1728)*scale+radius*scale, 1080-(1080-888)*scale+width*scale-compensation);
  57. ctx.lineTo(1920-(1920-1728)*scale, 1080-(1080-888)*scale+radius*scale+width*scale-2*radius*scale-compensation);
  58. ctx.fill();
  59.  
  60. //red
  61. ctx.fillStyle = '#963033';
  62. ctx.beginPath();
  63. ctx.arc(1920-(1920-1728)*scale+width*scale, 1080-(1080-888)*scale+width*scale-compensation, radius*scale, Math.PI, 3/2 * Math.PI);
  64. ctx.fill();
  65. ctx.beginPath();
  66. ctx.moveTo(1920-(1920-1728)*scale+width*scale, 1080-(1080-888)*scale+width*scale-compensation);
  67. ctx.lineTo(1920-(1920-1728)*scale+radius*scale+width*scale-2*radius*scale, 1080-(1080-888)*scale+width*scale-compensation);
  68. ctx.lineTo(1920-(1920-1728)*scale+width*scale, 1080-(1080-888)*scale+radius*scale+width*scale-2*radius*scale-compensation);
  69. ctx.fill();
  70.  
  71. } else if (player.gamemode === 'teams') {
  72. let radius2 = 40;
  73. //blue
  74. ctx.fillStyle = '#006480';
  75. ctx.fillRect(1920-(1920-1728)*scale, 1080-(1080-890)*scale-compensation, radius2*scale, 170*scale);
  76.  
  77. //red
  78. ctx.fillStyle = '#963033';
  79. ctx.fillRect(1920-(1920-1728)*scale+124*scale, 1080-(1080-890)*scale-compensation, radius2*scale, 170*scale);
  80. }
  81. ctx.restore();
  82. }
  83. class Gui {
  84. constructor(title) {
  85. this._buttons = [];
  86. this._init();
  87. }
  88. _init() {
  89. const nonce = `a${Math.floor(Math.random() * 1e5)}`;
  90. GM_addStyle(
  91. `.${nonce} button{display:none;font-family:Ubuntu;color:#fff;text-shadow:-.1em -.1em 0 #000,0 -.1em 0 #000,.1em -.1em 0 #000,.1em 0 0 #000,.1em .1em 0 #000,0 .1em 0 #000,-.1em .1em 0 #000,-.1em 0 0 #000;opacity:.8;border:0;padding:.3em .5em;width:100%;transition:all .15s}.${nonce}{top:0;left:0;position:absolute}.${nonce} button:active:not([disabled]){filter:brightness(.9)}.${nonce} button:hover:not([disabled]):not(:active){filter:brightness(1.1)}`
  92. );
  93. }
  94. }
  95. class Minimap {
  96. constructor() {
  97. this._minimapWidth;
  98. this._minimapHeight;
  99. this._x00;
  100. this._y00;
  101. this._pointX;
  102. this._pointY;
  103. this._pointX_previous;
  104. this._pointY_previous;
  105. this._viewportWidth;
  106. this._viewportHeight;
  107. this._fov;
  108.  
  109. this._minimapHook();
  110. this._arrowHook();
  111. this._viewportHook();
  112. this._fovHook(); }
  113. get x() {
  114. return this._pointX ? (this._pointX - this._x00) / this._minimapWidth : 0;
  115. }
  116. get y() {
  117. return this._pointY ? (this._pointY - this._y00) / this._minimapHeight : 0;
  118. }
  119. get x_previous() {
  120. return this._pointX_previous ? (this._pointX_previous - this._x00) / this._minimapWidth : 0;
  121. }
  122. get y_previous() {
  123. return this._pointY_previous ? (this._pointY_previous - this._y00) / this._minimapHeight : 0;
  124. }
  125. get scale() {
  126. return {
  127. x: this._viewportWidth / this._minimapWidth,
  128. y: this._viewportHeight / this._minimapHeight,
  129. };
  130. }
  131. get fov() {
  132. return this._fov;
  133. }
  134.  
  135. _minimapHook() {
  136. let setTransformArgs;
  137.  
  138. const onsetTransform = (args) => {
  139. if (args[0] === args[3]) setTransformArgs = args;
  140. };
  141. const onstrokeRect = () => {
  142. if (setTransformArgs) {
  143. this._minimapWidth = setTransformArgs[0];
  144. this._minimapHeight = setTransformArgs[3];
  145. this._x00 = setTransformArgs[4];
  146. this._y00 = setTransformArgs[5];
  147. setTransformArgs = undefined;
  148. }
  149. };
  150. this._ctxHook('setTransform', onsetTransform);
  151. this._ctxHook('strokeRect', onstrokeRect);
  152. }
  153. _arrowHook() {
  154. let index = 0;
  155. const stack = Array(4);
  156.  
  157. let pointA;
  158. let pointB;
  159. let pointC;
  160.  
  161. const calculatePos = () => {
  162. const side1 = Math.floor(
  163. Math.sqrt(Math.pow(pointA[0] - pointB[0], 2) + Math.pow(pointA[1] - pointB[1], 2))
  164. );
  165. const side2 = Math.floor(
  166. Math.sqrt(Math.pow(pointA[0] - pointC[0], 2) + Math.pow(pointA[1] - pointC[1], 2))
  167. );
  168. const side3 = Math.floor(
  169. Math.sqrt(Math.pow(pointB[0] - pointC[0], 2) + Math.pow(pointB[1] - pointC[1], 2))
  170. );
  171. if (side1 == side2 && side2 == side3) return;
  172.  
  173. this._pointX_previous = this._pointX;
  174. this._pointY_previous = this._pointY;
  175.  
  176. this._pointX = (pointA[0] + pointB[0] + pointC[0]) / 3;
  177. this._pointY = (pointA[1] + pointB[1] + pointC[1]) / 3;
  178. };
  179. const onbeginPath = () => {
  180. index = 0;
  181. stack[index++] = 0;
  182. };
  183. const onmoveTo = (args) => {
  184. if (index === 1 && stack[index - 1] === 0) {
  185. stack[index++] = 1;
  186. pointA = args;
  187. return;
  188. }
  189. index = 0;
  190. };
  191. const onlineTo = (args) => {
  192. if (index === 2 && stack[index - 1] === 1) {
  193. stack[index++] = 2;
  194. pointB = args;
  195. return;
  196. }
  197. if (index === 3 && stack[index - 1] === 2) {
  198. stack[index++] = 2;
  199. pointC = args;
  200. return;
  201. }
  202. index = 0;
  203. };
  204. const onfill = () => {
  205. if (index === 4 && stack[index - 1] === 2) {
  206. calculatePos();
  207. return;
  208. }
  209. index = 0;
  210. };
  211.  
  212. this._ctxHook('beginPath', onbeginPath);
  213. this._ctxHook('moveTo', onmoveTo);
  214. this._ctxHook('lineTo', onlineTo);
  215. this._ctxHook('fill', onfill);
  216. }
  217. _viewportHook() {
  218. let setTransformArgs;
  219.  
  220. const onsetTransform = (args) => {
  221. if ((args[0] / args[3]).toFixed(4) !== (unsafeWindow.innerWidth / unsafeWindow.innerHeight).toFixed(4))
  222. return;
  223. if (args[0] >= unsafeWindow.innerWidth && args[3] >= unsafeWindow.innerHeight) return;
  224.  
  225. setTransformArgs = args;
  226. };
  227. const onfillRect = () => {
  228. if (setTransformArgs) {
  229. unsafeWindow.input.set_convar('ren_minimap_viewport', false);
  230. this._viewportWidth = setTransformArgs[0];
  231. this._viewportHeight = setTransformArgs[3];
  232. setTransformArgs = undefined;
  233. }
  234. };
  235.  
  236. this._ctxHook('setTransform', onsetTransform);
  237. this._ctxHook('fillRect', onfillRect);
  238.  
  239. setTimeout(() => unsafeWindow.input.set_convar('ren_minimap_viewport', true), 1000);
  240. setInterval(() => {
  241. unsafeWindow.input.set_convar('ren_minimap_viewport', true);
  242. }, 1000);
  243. }
  244. _fovHook() {
  245. let solid_background = false;
  246. setTimeout(() => {
  247. solid_background = unsafeWindow.input.get_convar('ren_solid_background') === 'true' ? true : false;
  248. }, 400);
  249.  
  250. const calculateFov = (fov) => {
  251. this._fov = fov * 10;
  252. };
  253. function onstroke() {
  254. if (this.fillStyle === '#cdcdcd') {
  255. if (solid_background) unsafeWindow.input.set_convar('ren_solid_background', true);
  256. calculateFov(this.globalAlpha);
  257. }
  258. }
  259.  
  260. this._ctxHook('stroke', onstroke);
  261.  
  262. setInterval(() => {
  263. if (solid_background) unsafeWindow.input.set_convar('ren_solid_background', false);
  264. }, 10000);
  265. }
  266. _ctxHook(method, hook) {
  267. const target = window.CanvasRenderingContext2D.prototype;
  268. target[method] = new Proxy(target[method], {
  269. apply(target, thisArg, args) {
  270. args = hook.call(thisArg, args) || args;
  271. return target.apply(thisArg, args);
  272. },
  273. });
  274. }
  275. }
  276.  
  277. class Vector {
  278.  
  279. }
  280. class Arena {
  281. static get BLOCKSIZE() {
  282. return 50;
  283. }
  284. static scale(x, y) {
  285. return {
  286. x: Math.floor(22300 * (x - 0.5) + 0.5),
  287. y: Math.floor(22300 * (y - 0.5) + 0.5),
  288. };
  289. }
  290. static unscale(x, y) {
  291. return {
  292. x: x / 22300 + 0.5,
  293. y: y / 22300 + 0.5,
  294. };
  295. }
  296. }
  297. class Player {
  298. constructor() {
  299. this._minimap = new Minimap();
  300.  
  301. this._mouse = {
  302. x: 0,
  303. y: 0,
  304. };
  305. this._inputs = {
  306. left: false,
  307. down: false,
  308. up: false,
  309. right: false,
  310. };
  311. this._dead = true;
  312.  
  313. //Dead Listener
  314. new MutationObserver((args) => {
  315. this._dead = args[0].target.style.display === 'block';
  316. if (this.ondead && this._dead) this.ondead();
  317. }).observe(document.getElementById('a'), { attributes: true });
  318. //Message Listener
  319. const notify = (text) => {
  320. if (this.onmessage) this.onmessage(text);
  321. };
  322. CanvasRenderingContext2D.prototype.fillText = new Proxy(CanvasRenderingContext2D.prototype.fillText, {
  323. apply(target, thisArg, args) {
  324. if (args[0].startsWith("You've killed ")) {
  325. notify(args[0]);
  326. }
  327. return Reflect.apply(target, thisArg, args);
  328. },
  329. });
  330. }
  331.  
  332. set useGamepad(value) {
  333. this._gamepad.connected = value;
  334. }
  335.  
  336. get position() {
  337. const position = Arena.scale(this._minimap.x, this._minimap.y);
  338. const previous = Arena.scale(this._minimap.x_previous, this._minimap.y_previous);
  339. return {
  340. x: position.x,
  341. y: position.y,
  342. x_previous: previous.x,
  343. y_previous: previous.y,
  344. };
  345. }
  346. get dead() {
  347. return this._dead;
  348. }
  349.  
  350. get gamemode() {
  351. return unsafeWindow.localStorage.gamemode;
  352. }
  353. }
  354.  
  355. /**
  356. *this code is useless, but do not delete as that messes up something
  357. */
  358. class Chat {
  359. constructor(player) {
  360. this._player = player;
  361. this._inputBox = document.body.appendChild(document.createElement('div'));
  362. this._hookonkeydown();
  363. this._hookAnimationFrame();
  364. }
  365. _onkeydown(e) {
  366. let preventDefault = false;
  367.  
  368. if (player.dead) return;
  369.  
  370. return preventDefault;
  371. }
  372. _hookonkeydown() {
  373. const _this = this;
  374. unsafeWindow.onkeydown = new Proxy(unsafeWindow.onkeydown, {
  375. });
  376. }
  377. _hookAnimationFrame() {
  378. const _this = this;
  379. unsafeWindow.requestAnimationFrame = new Proxy(unsafeWindow.requestAnimationFrame, {
  380. });
  381. }
  382. }
  383.  
  384. const player = new Player();
  385. const chat = new Chat(player);
  386. const minimap = new Minimap();
  387. var a = 0
  388. var d = minimap._minimapWidth;
  389. //setup canvas
  390. const ctx = document.getElementById('canvas').getContext('2d');
  391.  
  392. // run main Loop
  393. unsafeWindow.requestAnimationFrame = new Proxy(unsafeWindow.requestAnimationFrame, {
  394. apply: function (target, thisArg, args) {
  395. setInterval(() => {
  396. if(window.innerHeight == screen.height) {
  397. a = 0;} else {a = 1;}}, 500);
  398. setInterval(() => {d = minimap._minimapWidth}, 100);
  399. drawZones(d / 175, a);
  400.  
  401. setTimeout(() => Reflect.apply(target, thisArg, args), 0);
  402. },
  403. });