Base Zones

diep.io base zone script

安装此脚本
作者推荐脚本

您可能也喜欢Diep.io Grayscale Theme

安装此脚本
  1. // ==UserScript==
  2. // @name Base Zones
  3. // @description diep.io base zone script
  4. // @version 1.4
  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. // @license none
  13. // @namespace https://greasyfork.org/users/790354
  14. // @run-at document-end
  15. // ==/UserScript==
  16. 'use strict';
  17. function drawZones(x, y) {
  18. if (player.dead) return;
  19. let corner = 11.5/27*arenaDim;
  20. let arenaCorner = arenaDim/2;
  21. if (player.gamemode === 'teams') {
  22. ctx.fillStyle = '#00B1DE14';
  23. ctx.beginPath();
  24. ctx.fillRect(-arenaCorner-x, -arenaDim/2-y, arenaDim/4.05, arenaDim);
  25. ctx.fillStyle = '#F14E5414';
  26. ctx.beginPath();
  27. ctx.fillRect(arenaCorner-x, -arenaDim/2-y, -arenaDim/4.05, arenaDim);
  28. ctx.fillStyle = '#00B1DE24';
  29. ctx.beginPath();
  30. ctx.fillRect(-arenaCorner-x, -arenaDim/2-y, arenaDim/5.51, arenaDim);
  31. ctx.fillStyle = '#F14E5424';
  32. ctx.beginPath();
  33. ctx.fillRect(arenaCorner-x, -arenaDim/2-y, -arenaDim/5.51, arenaDim);
  34. }
  35. if (player.gamemode === '4teams') {
  36. ctx.lineWidth = 20;
  37. //Calibration (change corner 1 so that the circles align with base center)
  38. //Blue
  39. ctx.fillStyle = '#00000011';
  40. ctx.beginPath();
  41. ctx.ellipse(-corner-x, -corner-y, 100,100,0, 0, 2*Math.PI);
  42. ctx.fill();
  43. //Purple
  44. ctx.fillStyle = '#00000011';
  45. ctx.beginPath();
  46. ctx.ellipse(corner-x, -corner-y, 100,100,0, 0, 2*Math.PI);
  47. ctx.fill();
  48. //Green
  49. ctx.fillStyle = '#00000011';
  50. ctx.beginPath();
  51. ctx.ellipse(-corner-x, corner-y, 100,100,0, 0, 2*Math.PI);
  52. ctx.fill();
  53. //Red
  54. ctx.fillStyle = '#00000011';
  55. ctx.beginPath();
  56. ctx.ellipse(corner-x, corner-y, 100,100,0, 0, 2*Math.PI);
  57. ctx.fill();
  58. //Zone Rendering Outer
  59. //Blue
  60. ctx.fillStyle = '#00B1DE18';
  61. ctx.beginPath();
  62. ctx.ellipse(-corner-x, -corner-y, arenaDim/4.25,arenaDim/4.25,0, 0, 2*Math.PI);
  63. ctx.fill();
  64. //Purple
  65. ctx.fillStyle = '#BF7FF518';
  66. ctx.beginPath();
  67. ctx.ellipse(corner-x, -corner-y, arenaDim/4.25,arenaDim/4.25,0, 0, 2*Math.PI);
  68. ctx.fill();
  69. //Green
  70. ctx.fillStyle = '#00E16E18';
  71. ctx.beginPath();
  72. ctx.ellipse(-corner-x, corner-y, arenaDim/4.25,arenaDim/4.25,0, 0, 2*Math.PI);
  73. ctx.fill();
  74. //Red
  75. ctx.fillStyle = '#F14E5418';
  76. ctx.beginPath();
  77. ctx.ellipse(corner-x, corner-y, arenaDim/4.25,arenaDim/4.25,0, 0, 2*Math.PI);
  78. ctx.fill();
  79. //Zone Rendering Inner
  80. //Blue
  81. ctx.fillStyle = '#00B1DE26';
  82. ctx.beginPath();
  83. ctx.ellipse(-corner-x, -corner-y, arenaDim/5.75,arenaDim/5.75,0, 0, 2*Math.PI);
  84. ctx.fill();
  85. //Purple
  86. ctx.fillStyle = '#BF7FF526';
  87. ctx.beginPath();
  88. ctx.ellipse(corner-x, -corner-y, arenaDim/5.75,arenaDim/5.75,0, 0, 2*Math.PI);
  89. ctx.fill();
  90. //Green
  91. ctx.fillStyle = '#00E16E26';
  92. ctx.beginPath();
  93. ctx.ellipse(-corner-x, corner-y,arenaDim/5.75,arenaDim/5.75,0, 0, 2*Math.PI);
  94. ctx.fill();
  95. //Red
  96. ctx.fillStyle = '#F14E5426';
  97. ctx.beginPath();
  98. ctx.ellipse(corner-x, corner-y, arenaDim/5.75,arenaDim/5.75,0, 0, 2*Math.PI);
  99. ctx.fill();
  100. }
  101. }
  102. class Minimap {
  103. constructor() {
  104. this._minimapWidth;
  105. this._minimapHeight;
  106. this._x00;
  107. this._y00;
  108. this._pointX;
  109. this._pointY;
  110. this._pointX_previous;
  111. this._pointY_previous;
  112. this._viewportX;
  113. this._viewportY;
  114. this._fov;
  115.  
  116. this._minimapHook();
  117. this._viewportHook();
  118. this._fovHook();}
  119. get fov() {
  120. return this._fov;
  121. }
  122. _minimapHook() {
  123. let setTransformArgs;
  124. const onsetTransform = (args) => {
  125. if (args[0] === args[3]) setTransformArgs = args;
  126. };
  127. const onstrokeRect = () => {
  128. if (setTransformArgs) {
  129. this._minimapWidth = setTransformArgs[0];
  130. this._minimapHeight = setTransformArgs[3];
  131. this._x00 = setTransformArgs[4] + setTransformArgs[0]/2;
  132. this._y00 = setTransformArgs[5] + setTransformArgs[3]/2;
  133. setTransformArgs = undefined;
  134. }
  135. };
  136. this._ctxHook('setTransform', onsetTransform);
  137. this._ctxHook('strokeRect', onstrokeRect);
  138. }
  139. _viewportHook() {
  140. let setTransformArgs;
  141. const onsetTransform = (args) => {
  142. if ((args[0] / args[3]).toFixed(2) !== (unsafeWindow.innerWidth / unsafeWindow.innerHeight).toFixed(2)) return;
  143. if (args[0] >= unsafeWindow.innerWidth && args[3] >= unsafeWindow.innerHeight) return;
  144. setTransformArgs = args;
  145. };
  146. const onfillRect = () => {
  147. if (setTransformArgs) {
  148. unsafeWindow.input.set_convar('ren_minimap_viewport', true);
  149. this._viewPortX = setTransformArgs[4] + 0*setTransformArgs[0]/2;
  150. this._viewPortY = setTransformArgs[5] + 0*setTransformArgs[3]/2;
  151. setTransformArgs = undefined;
  152. }
  153. };
  154. console.log(setTransformArgs);
  155. this._ctxHook('setTransform', onsetTransform);
  156. this._ctxHook('fillRect', onfillRect);
  157. setInterval(() => {
  158. unsafeWindow.input.set_convar('ren_minimap_viewport', true);
  159. }, 1000);
  160. }
  161. _fovHook() {
  162. let solid_background = false;
  163. setTimeout(() => {
  164. solid_background = unsafeWindow.input.get_convar('ren_solid_background') === 'true' ? true : false;
  165. }, 1000);
  166. const calculateFov = (fov) => {
  167. this._fov = fov * 10;
  168. };
  169. function onstroke() {
  170. if (this.fillStyle === '#cdcdcd') {
  171. if (solid_background) unsafeWindow.input.set_convar('ren_solid_background', true);
  172. calculateFov(this.globalAlpha);
  173. }
  174. }
  175. this._ctxHook('stroke', onstroke);
  176.  
  177. setInterval(() => {
  178. if (solid_background) unsafeWindow.input.set_convar('ren_solid_background', false);
  179. }, 10000);
  180. }
  181. _ctxHook(method, hook) {
  182. const target = window.CanvasRenderingContext2D.prototype;
  183. target[method] = new Proxy(target[method], {
  184. apply(target, thisArg, args) {
  185. args = hook.call(thisArg, args) || args;
  186. return target.apply(thisArg, args);
  187. },
  188. });
  189. }
  190. }
  191. class Player {
  192. constructor() {
  193. this._minimap = new Minimap();
  194. this._dead = true;
  195. }
  196. get dead() {
  197. return !(score >=0);
  198. }
  199. get gamemode() {
  200. return unsafeWindow.localStorage.gamemode;
  201. }
  202. }
  203.  
  204. const player = new Player();
  205. const minimap = new Minimap();
  206. var arenaDim;
  207. var score = NaN;
  208. var fov;
  209. var isAfk = 0;
  210. //setup canvas
  211. const canvas = document.getElementById('canvas');
  212. const ctx = document.getElementById('canvas').getContext('2d');
  213. // run main Loop
  214. unsafeWindow.requestAnimationFrame = new Proxy(unsafeWindow.requestAnimationFrame, {
  215. apply: function (target, thisArg, args) {
  216. fov = player._minimap.fov / 0.55;
  217. arenaDim = 11150*1.1*fov;
  218. //Helpers
  219. let scaleX = (minimap._viewPortX - minimap._x00) / minimap._minimapWidth;
  220. let scaleY = (minimap._viewPortY - minimap._y00) / minimap._minimapWidth;
  221. let posX = scaleX * arenaDim;
  222. let posY = scaleY * arenaDim;
  223. drawZones(posX, posY);
  224. setTimeout(() => Reflect.apply(target, thisArg, args), 0);
  225. },
  226. });
  227. CanvasRenderingContext2D.prototype.fillText = new Proxy(CanvasRenderingContext2D.prototype.fillText, {
  228. apply(fillRect, ctx, [text, x, y, ...blah]) {
  229. if (text.startsWith("Score:")) {
  230. score = parseFloat(text.slice(7).replace(',', ''));
  231. }
  232. fillRect.call(ctx, text, x, y, ...blah);
  233. }
  234. });