Diep.io+ (added copy Info & base zones)

autorespawn(auto ad watcher with 2min timer), leader arrow + minimap arrow, FOV & diepUnits & windowScaling() calculator, Factory controls overlay, bullet distance (FOR EVERY BULLET SPEED BUILD) of 75% tanks, copy party link, leave game, no privacy settings button, no apes.io advertisment, net_predict_movement false

目前为 2024-09-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Diep.io+ (added copy Info & base zones)
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.0.4.2
  5. // @description autorespawn(auto ad watcher with 2min timer), leader arrow + minimap arrow, FOV & diepUnits & windowScaling() calculator, Factory controls overlay, bullet distance (FOR EVERY BULLET SPEED BUILD) of 75% tanks, copy party link, leave game, no privacy settings button, no apes.io advertisment, net_predict_movement false
  6. // @author r!PsAw
  7. // @match https://diep.io/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=diep.io
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. //!!!WARNING!!! Ui scale has to be at 0.9x for this script to work//
  14. let ingamescreen = document.getElementById("in-game-screen");
  15. let your_name = document.getElementById('spawn-nickname').value;
  16.  
  17. //GUI
  18. const container = document.createElement('div');
  19. container.style.position = 'fixed';
  20. container.style.top = '10px';
  21. container.style.left = '75px';
  22. container.style.padding = '15px';
  23. container.style.backgroundImage = 'linear-gradient(#ffffff, #79c7ff)';
  24. container.style.color = 'white';
  25. container.style.borderRadius = '10px';
  26. container.style.boxShadow = '0 0 10px rgba(0,0,0,0.5)';
  27. container.style.minWidth = '200px';
  28. container.style.zIndex = '10';
  29.  
  30. container.addEventListener('mouseover', () => {
  31. input.execute('ren_upgrades false');
  32. });
  33.  
  34. container.addEventListener('mouseout', () => {
  35. input.execute('ren_upgrades true');
  36. });
  37.  
  38. const title = document.createElement('h1');
  39. title.textContent = 'Diep.io+ (hide with J)';
  40. title.style.margin = '0 0 5px 0';
  41. title.style.fontSize = '24px';
  42. title.style.textAlign = 'center';
  43. title.style.color = '#fb2a7b';
  44. title.style.zIndex = '11';
  45. container.appendChild(title);
  46.  
  47. const subtitle = document.createElement('h3');
  48. subtitle.textContent = 'made by r!PsAw';
  49. subtitle.style.margin = '0 0 15px 0';
  50. subtitle.style.fontSize = '14px';
  51. subtitle.style.textAlign = 'center';
  52. subtitle.style.color = '#6fa8dc';
  53. subtitle.style.zIndex = '11';
  54. container.appendChild(subtitle);
  55.  
  56. const categories = ['Debug', 'Visual', 'Functional', 'Addons'];
  57. const categoryButtons = {};
  58. const categoryContainer = document.createElement('div');
  59. categoryContainer.style.display = 'flex';
  60. categoryContainer.style.justifyContent = 'space-between';
  61. categoryContainer.style.marginBottom = '15px';
  62. categoryContainer.style.zIndex = '12';
  63.  
  64. categories.forEach(category => {
  65. const button = document.createElement('button');
  66. button.textContent = category;
  67. button.style.flex = '1';
  68. button.style.padding = '8px';
  69. button.style.margin = '0 5px';
  70. button.style.cursor = 'pointer';
  71. button.style.border = 'none';
  72. button.style.borderRadius = '5px';
  73. button.style.backgroundColor = '#fb2a7b';
  74. button.style.color = 'white';
  75. button.style.transition = 'background-color 0.3s';
  76. button.style.zIndex = '13';
  77.  
  78. button.addEventListener('mouseover', () => {
  79. button.style.backgroundColor = '#0000ff';
  80. });
  81. button.addEventListener('mouseout', () => {
  82. button.style.backgroundColor = '#fb2a7b';
  83. });
  84.  
  85. categoryContainer.appendChild(button);
  86. categoryButtons[category] = button;
  87. });
  88.  
  89. container.appendChild(categoryContainer);
  90.  
  91. const contentArea = document.createElement('div');
  92. contentArea.style.marginTop = '15px';
  93. contentArea.style.zIndex = '12';
  94. container.appendChild(contentArea);
  95.  
  96. const toggleButtons = {
  97. Debug: {
  98. 'Toggle Text': false,
  99. 'Toggle Middle Circle': false,
  100. 'Toggle Upgrades': false,
  101. 'Toggle Arrow pos': false
  102. },
  103. Visual: {
  104. 'Toggle Aim Lines': false,
  105. 'Toggle Bullet Distance': false,
  106. 'Toggle Minimap': false,
  107. 'Highlight Leader Score': false
  108. },
  109. Functional: {
  110. 'Auto Respawn': false,
  111. 'Auto Bonus Level': false,
  112. 'Toggle Leave Button': false,
  113. 'Toggle Level Seeker': false
  114. },
  115. Addons: {
  116. 'Change Leader Arrow Color': '#000000',
  117. 'Toggle Leader Angle': false,
  118. 'Toggle Base Zones': false
  119. }
  120. };
  121.  
  122. function createToggleButton(text, initialState) {
  123. const button = document.createElement('button');
  124. button.textContent = text;
  125. button.style.display = 'block';
  126. button.style.width = '100%';
  127. button.style.marginBottom = '10px';
  128. button.style.padding = '8px';
  129. button.style.cursor = 'pointer';
  130. button.style.border = 'none';
  131. button.style.borderRadius = '5px';
  132. button.style.transition = 'background-color 0.3s';
  133. button.style.zIndex = '13';
  134.  
  135. if (text === 'Change Leader Arrow Color') {
  136. updateButtonColor(button, initialState);
  137. button.addEventListener('click', () => {
  138. const colorPicker = document.createElement('input');
  139. colorPicker.type = 'color';
  140. colorPicker.value = toggleButtons[currentCategory][text];
  141. colorPicker.style.display = 'none';
  142. document.body.appendChild(colorPicker);
  143.  
  144. colorPicker.addEventListener('change', (event) => {
  145. const newColor = event.target.value;
  146. toggleButtons[currentCategory][text] = newColor;
  147. updateButtonColor(button, newColor);
  148. document.body.removeChild(colorPicker);
  149. });
  150.  
  151. colorPicker.click();
  152. });
  153. } else {
  154. updateButtonColor(button, initialState);
  155. button.addEventListener('click', () => {
  156. toggleButtons[currentCategory][text] = !toggleButtons[currentCategory][text];
  157. updateButtonColor(button, toggleButtons[currentCategory][text]);
  158. });
  159. }
  160.  
  161. return button;
  162. }
  163.  
  164. function updateButtonColor(button, state) {
  165. if (typeof state === 'string') {
  166. // For color picker button
  167. button.style.backgroundColor = state;
  168. window.choose_color = state;
  169. button.style.color = 'white';
  170. } else {
  171. // For toggle buttons
  172. if (state) {
  173. button.style.backgroundColor = '#63a5d4';
  174. button.style.color = 'white';
  175. } else {
  176. button.style.backgroundColor = '#a11a4e';
  177. button.style.color = 'white';
  178. }
  179. }
  180. }
  181.  
  182. let currentCategory = '';
  183.  
  184. function showCategory(category) {
  185. contentArea.innerHTML = '';
  186. currentCategory = category;
  187.  
  188. Object.keys(categoryButtons).forEach(cat => {
  189. if (cat === category) {
  190. categoryButtons[cat].style.backgroundColor = '#0000ff';
  191. } else {
  192. categoryButtons[cat].style.backgroundColor = '#fb2a7b';
  193. }
  194. });
  195.  
  196. if (category === 'Functional') {
  197. const copyLinkButton = document.createElement('button');
  198. copyLinkButton.textContent = 'Copy Party Link';
  199. copyLinkButton.style.display = 'block';
  200. copyLinkButton.style.width = '100%';
  201. copyLinkButton.style.marginBottom = '10px';
  202. copyLinkButton.style.padding = '8px';
  203. copyLinkButton.style.cursor = 'pointer';
  204. copyLinkButton.style.border = 'none';
  205. copyLinkButton.style.borderRadius = '5px';
  206. copyLinkButton.style.backgroundColor = '#2196F3';
  207. copyLinkButton.style.color = 'white';
  208. copyLinkButton.style.transition = 'background-color 0.3s';
  209. copyLinkButton.style.zIndex = '13';
  210.  
  211. copyLinkButton.addEventListener('mouseover', () => {
  212. copyLinkButton.style.backgroundColor = '#1E88E5';
  213. });
  214. copyLinkButton.addEventListener('mouseout', () => {
  215. copyLinkButton.style.backgroundColor = '#2196F3';
  216. });
  217.  
  218. copyLinkButton.addEventListener('click', () => {
  219. document.getElementById("copy-party-link").click();
  220. });
  221. const copyInfoButton = document.createElement('button');
  222. copyInfoButton.textContent = 'Copy Info';
  223. copyInfoButton.style.display = 'block';
  224. copyInfoButton.style.width = '100%';
  225. copyInfoButton.style.marginBottom = '10px';
  226. copyInfoButton.style.padding = '8px';
  227. copyInfoButton.style.cursor = 'pointer';
  228. copyInfoButton.style.border = 'none';
  229. copyInfoButton.style.borderRadius = '5px';
  230. copyInfoButton.style.backgroundColor = '#2196F3';
  231. copyInfoButton.style.color = 'white';
  232. copyInfoButton.style.transition = 'background-color 0.3s';
  233. copyInfoButton.style.zIndex = '13';
  234.  
  235. copyInfoButton.addEventListener('mouseover', () => {
  236. copyLinkButton.style.backgroundColor = '#1E88E5';
  237. });
  238. copyInfoButton.addEventListener('mouseout', () => {
  239. copyLinkButton.style.backgroundColor = '#2196F3';
  240. });
  241.  
  242. copyInfoButton.addEventListener('click', () => {
  243. get_info();
  244. });
  245. contentArea.appendChild(copyLinkButton);
  246. contentArea.appendChild(copyInfoButton);
  247. }
  248.  
  249. Object.keys(toggleButtons[category]).forEach(text => {
  250. const button = createToggleButton(text, toggleButtons[category][text]);
  251. contentArea.appendChild(button);
  252. });
  253. }
  254.  
  255. Object.keys(categoryButtons).forEach(category => {
  256. categoryButtons[category].addEventListener('click', () => showCategory(category));
  257. });
  258.  
  259. document.body.appendChild(container);
  260.  
  261. //visibility of gui
  262. let visibility_gui = true;
  263.  
  264. function change_visibility() {
  265. visibility_gui = !visibility_gui;
  266. if (visibility_gui) {
  267. container.style.display = 'block';
  268. } else {
  269. container.style.display = 'none';
  270. }
  271. }
  272.  
  273. //ui scale
  274.  
  275. let ui_scale = document.querySelector("#settings-modal > div > div:nth-child(1) > div > div:nth-child(1) > label > span")
  276.  
  277. function ui_scale_check() {
  278. if (ui_scale.innerHTML != "-" && ui_scale.innerHTML != null && ingamescreen.classList.contains("screen") && ingamescreen.classList.contains("active")) {
  279. if (ui_scale.innerHTML != "0.9x") {
  280. input.inGameNotification("please change your ui_scale to 0.9x in Menu -> Settings");
  281. console.log(ui_scale.innerHTML);
  282. } else {
  283. console.log("no alert");
  284. }
  285. clearInterval(interval_for_ui_scale);
  286. }
  287. }
  288. let interval_for_ui_scale = setInterval(ui_scale_check, 0);
  289.  
  290. //check scripts
  291. let script_list = {
  292. minimap_leader_v1: null,
  293. minimap_leader_v2: null,
  294. fov: null,
  295. set_transform_debug: null,
  296. moveToLineTo_debug: null,
  297. gamemode_detect: null
  298. };
  299.  
  300. function check_ripsaw_scripts() {
  301. if (ingamescreen.classList.contains("screen") && ingamescreen.classList.contains("active")) {
  302. script_list.minimap_leader_v1 = !!window.m_arrow;
  303. script_list.minimap_leader_v2 = !!window.M_X;
  304. script_list.fov = !!window.HEAPF32;
  305. script_list.set_transform_debug = !!window.crx_container;
  306. script_list.moveToLineTo_debug = !!window.y_and_x;
  307. script_list.gamemode_detect = !!window.gm;
  308. }
  309. }
  310. setInterval(check_ripsaw_scripts, 500);
  311.  
  312. //detect gamemode
  313. let gamemode;
  314.  
  315. function check_gamemode() {
  316. if (script_list.gamemode_detect) {
  317. gamemode = window.gm;
  318. } else {
  319. gamemode = document.querySelector("#gamemode-selector > div > div.selected > div.dropdown-label").innerHTML;
  320. console.log(gamemode);
  321. }
  322. }
  323.  
  324. setInterval(check_gamemode, 100);
  325.  
  326. //check region
  327. let region;
  328. function check_region(){
  329. region = document.querySelector("#region-selector > div > div.selected > div.dropdown-label").innerHTML;
  330. console.log(region);
  331. }
  332.  
  333. setInterval(check_region, 100);
  334.  
  335. //detect if dead or alive
  336. let state = "idk yet";
  337.  
  338. function check_state() {
  339. switch (input.doesHaveTank()) {
  340. case 0:
  341. state = "in menu";
  342. break
  343. case 1:
  344. state = "in game";
  345. break
  346. }
  347. }
  348.  
  349. setInterval(check_state, 100);
  350. //config
  351. var two = canvas.width / window.innerWidth;
  352. var debugboolean = false;
  353. var script_boolean = true;
  354.  
  355. // Mouse coordinates
  356. var uwuX = '0';
  357. var uwuY = '0';
  358. document.addEventListener('mousemove', function(e) {
  359. uwuX = e.clientX;
  360. uwuY = e.clientY;
  361. });
  362.  
  363. //net_predict_movement false
  364. (function() {
  365. function applySettings() {
  366. input.execute("net_predict_movement false");
  367. }
  368.  
  369. function waitForGame() {
  370. if (window.input && input.execute) {
  371. applySettings();
  372. } else {
  373. setTimeout(waitForGame, 100);
  374. }
  375. }
  376. waitForGame();
  377. })();
  378.  
  379. //annoying html elements
  380. let ads_removed = false;
  381.  
  382. function instant_remove() {
  383. let privacy_btn = document.getElementById("cmpPersistentLink");
  384. let apes_btn = document.getElementById("apes-io-promo");
  385. let discord_ad = document.querySelector("#apes-io-promo > img");
  386. let annoying = document.querySelector("#last-updated");
  387. if (privacy_btn) {
  388. privacy_btn.remove();
  389. }
  390.  
  391. if (annoying) {
  392. annoying.remove();
  393. }
  394.  
  395. if (apes_btn) {
  396. apes_btn.remove();
  397. }
  398.  
  399. if (discord_ad) {
  400. discord_ad.remove();
  401. }
  402.  
  403. if (!privacy_btn && !apes_btn && !discord_ad && !annoying) {
  404. console.log("removed buttons, quitting...");
  405. clearInterval(interval);
  406. }
  407. };
  408.  
  409. let interval = setInterval(instant_remove, 100);
  410.  
  411. //timer for bonus reward
  412. const gameOverScreen = document.getElementById('game-over-screen');
  413. const ad_btn = document.getElementById("game-over-video-ad");
  414. var ad_btn_free = true;
  415.  
  416. const timerDisplay = document.createElement('h1');
  417. timerDisplay.textContent = "Time left to collect next bonus levels: 02:00";
  418. gameOverScreen.appendChild(timerDisplay);
  419.  
  420. let timer;
  421. let totalTime = 120; // 2 minutes in seconds
  422.  
  423. function startTimer() {
  424. clearInterval(timer);
  425. timer = setInterval(function() {
  426. if (totalTime <= 0) {
  427. clearInterval(timer);
  428. timerDisplay.textContent = "00:00";
  429. } else {
  430. totalTime--;
  431. let minutes = Math.floor(totalTime / 60);
  432. let seconds = totalTime % 60;
  433. timerDisplay.textContent =
  434. `Time left to collect next bonus levels: ${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
  435. }
  436. }, 1000);
  437. }
  438.  
  439. function resetTimer() {
  440. if (totalTime === 0) {
  441. clearInterval(timer);
  442. totalTime = 120; // Reset to 2 minutes
  443. timerDisplay.textContent = "02:00";
  444. }
  445. }
  446.  
  447. ad_btn.addEventListener('click', check_ad_state);
  448.  
  449. function check_ad_state() {
  450. if (totalTime === 0) {
  451. resetTimer();
  452. } else if (totalTime === 120) {
  453. ad_btn_free = true;
  454. startTimer();
  455. } else {
  456. ad_btn_free = false;
  457. }
  458. }
  459.  
  460. //autorespawn old method
  461.  
  462. let autorespawn = false;
  463.  
  464. function respawn() {
  465. if (toggleButtons.Functional['Auto Respawn']) {
  466. if (state === "in game") {
  467. return;
  468. } else {
  469. if ((totalTime === 120 || totalTime === 0) && toggleButtons.Functional['Auto Bonus Level']) {
  470. ad_btn.click();
  471. } else {
  472. let spawnbtn = document.getElementById("spawn-button");
  473. spawnbtn.click();
  474. }
  475. }
  476. }
  477. }
  478.  
  479. setInterval(respawn, 1000);
  480.  
  481. /*
  482. //autorespawn new method (no bonus level)
  483. function respawn(){
  484. if(toggleButtons.Functional['Auto Respawn']){
  485. if(state === "in menu"){
  486. let spawnbtn = document.getElementById("spawn-button");
  487. spawnbtn.click();
  488. }
  489. }
  490. }
  491.  
  492. setInterval(respawn, 1000);
  493. */
  494. //toggle leave game
  495. let ingame_quit_btn = document.getElementById("quick-exit-game");
  496.  
  497. function check_class() {
  498. if (toggleButtons.Functional['Toggle Leave Button']) {
  499. ingame_quit_btn.classList.remove("hidden");
  500. ingame_quit_btn.classList.add("shown");
  501. } else {
  502. ingame_quit_btn.classList.remove("shown");
  503. ingame_quit_btn.classList.add("hidden");
  504. }
  505. }
  506.  
  507. setInterval(check_class, 300);
  508.  
  509. //score logic
  510. let your_nameFont;
  511. let scoreBoardFont;
  512. let highest_score;
  513. let highest_score_addon;
  514. let highest_score_string;
  515. let is_highest_score_alive;
  516. let scores = {
  517. millions: 0,
  518. thousands: 0,
  519. lessThan1k: 0
  520. };
  521.  
  522. function get_highest_score() {
  523. if (scores.millions > 0) {
  524. highest_score = scores.millions;
  525. highest_score_addon = "m";
  526. } else if (scores.thousands > 0) {
  527. highest_score = scores.thousands;
  528. highest_score_addon = "k";
  529. } else if (scores.lessThan1k > 0) {
  530. highest_score = scores.lessThan1k;
  531. }
  532. }
  533. //getting text information (credits to abc)
  534. CanvasRenderingContext2D.prototype.fillText = new Proxy(CanvasRenderingContext2D.prototype.fillText, {
  535. apply(fillRect, ctx, [text, x, y, ...blah]) {
  536. const isNumeric = (string) => /^[+-]?\d+(\.\d+)?$/.test(string)
  537. if (text.startsWith('Lvl ')) {
  538. currentLevel = text.split(' ')[1];
  539. if (text.split(' ')[3] != undefined) {
  540. tanky = text.split(' ')[2] + text.split(' ')[3];
  541. } else {
  542. tanky = text.split(' ')[2]
  543. }
  544. } else if (text === your_name) {
  545. your_nameFont = ctx.font;
  546. } else if (text === " - ") {
  547. scoreBoardFont = ctx.font
  548. } else if (isNumeric(text) && ctx.font === scoreBoardFont) {
  549. scores.lessThan1k = parseFloat(text);
  550. } else if (text.includes('.') && text.includes('k') && ctx.font === scoreBoardFont) {
  551. if (parseFloat(text.split('k')[0]) > scores.thousands) {
  552. scores.thousands = parseFloat(text.split('k')[0]);
  553. }
  554. } else if (text.includes('.') && text.includes('m') && ctx.font === scoreBoardFont) {
  555. if (parseFloat(text.split('m')[0]) > scores.millions) {
  556. scores.millions = parseFloat(text.split('m')[0]);
  557. }
  558. }
  559.  
  560. get_highest_score();
  561. if (highest_score != null) {
  562. if (highest_score_addon != null) {
  563. highest_score_string = `${highest_score}${highest_score_addon}`;
  564. } else {
  565. highest_score_string = `${highest_score}`;
  566. }
  567. if (text === highest_score_string && toggleButtons.Visual['Highlight Leader Score']) {
  568. ctx.fillStyle = "orange";
  569. }
  570. }
  571. fillRect.call(ctx, text, x, y, ...blah);
  572. }
  573. });
  574.  
  575. //getting Info
  576. function get_info(){
  577. if(region != null && gamemode != null && highest_score != null){
  578. navigator.clipboard.writeText(`🌐Region: ${region}
  579. 🎮Mode: ${gamemode}
  580. 👑Leader: ${highest_score}${highest_score_addon}`);
  581. }
  582. }
  583. //display level
  584. const pointsNeeded = [
  585. 0, 4, 13, 28, 50, 78, 113, 157, 211, 275,
  586. 350, 437, 538, 655, 787, 938, 1109, 1301,
  587. 1516, 1757, 2026, 2325, 2658, 3026, 3433,
  588. 3883, 4379, 4925, 5525, 6184, 6907, 7698,
  589. 8537, 9426, 10368, 11367, 12426, 13549,
  590. 14739, 16000, 17337, 18754, 20256, 21849,
  591. 23536, 999999 //this one is not lvl 46, just a value to make my code work
  592. ];
  593.  
  594. const crx = CanvasRenderingContext2D.prototype;
  595. crx.fillText = new Proxy(crx.fillText, {
  596. apply: function(f, _this, args) {
  597. if (scoreBoardFont != null && toggleButtons.Functional['Toggle Level Seeker']) {
  598. const isNumeric = (string) => /^[+-]?\d+(\.\d+)?$/.test(string);
  599. if (_this.font != scoreBoardFont) {
  600. if (isNumeric(args[0])) {
  601. for (let i = 0; i < 16; i++) {
  602. if (parseFloat(args[0]) < pointsNeeded[i]) {
  603. args[0] = `L: ${i}`;
  604. }
  605. }
  606. } else if (args[0].includes('.')) {
  607. if (args[0].includes('k')) {
  608. for (let i = 16; i < pointsNeeded.length; i++) {
  609. if (parseFloat(args[0].split('k')[0]) * 1000 < pointsNeeded[i]) {
  610. args[0] = `L: ${i}`;
  611. }
  612. }
  613. } else if (args[0].includes('m')) {
  614. args[0] = `L: 45}`;
  615. }
  616. }
  617. }
  618. }
  619. f.apply(_this, args);
  620. }
  621. });
  622. crx.strokeText = new Proxy(crx.strokeText, {
  623. apply: function(f, _this, args) {
  624. if (scoreBoardFont != null && toggleButtons.Functional['Toggle Level Seeker']) {
  625. const isNumeric = (string) => /^[+-]?\d+(\.\d+)?$/.test(string);
  626. if (_this.font != scoreBoardFont) {
  627. if (isNumeric(args[0])) {
  628. for (let i = 0; i < 16; i++) {
  629. if (parseFloat(args[0]) < pointsNeeded[i]) {
  630. args[0] = `L: ${i}`;
  631. console.log(args[0]);
  632. }
  633. }
  634. } else if (args[0].includes('.')) {
  635. if (args[0].includes('k')) {
  636. for (let i = 16; i < pointsNeeded.length; i++) {
  637. if (parseFloat(args[0].split('k')[0]) * 1000 < pointsNeeded[i]) {
  638. args[0] = `L: ${i}`;
  639. console.log(args[0]);
  640. }
  641. }
  642. } else if (args[0].includes('m')) {
  643. args[0] = `L: 45`;
  644. console.log(args[0]);
  645. }
  646. }
  647. }
  648. }
  649. f.apply(_this, args);
  650. }
  651. });
  652.  
  653. //Detect AutoFire/AutoSpin
  654. let auto_fire = false;
  655. let auto_spin = false;
  656.  
  657. function f_s(f_or_s) {
  658. switch (f_or_s) {
  659. case "fire":
  660. auto_fire = !auto_fire;
  661. break
  662. case "spin":
  663. auto_spin = !auto_spin;
  664. break
  665. }
  666. }
  667. //Diep Units & fov calculator
  668. //NOTE: I removed spaces between tank names for this script only. Also since glider came out and diepindepth was unupdated it didn't update correctly, I fixed that.
  669.  
  670. /*
  671. =============================================================================
  672. Skid & Noob friendly calculation explained:
  673.  
  674. Read this in order to understand, how the position calculation works.
  675.  
  676. 1. Canvas/window coords
  677. When you load diep.io in a browser window, it also loads a canvas where the game is drawn.
  678. Imagine a piece of paper where you draw things, this is canvas. If you place a pen on that piece of paper, this is html element.
  679. Diep.io uses canvas mainly. Your window and the canvas use different coordinate systems, even tho they appear the same at first:
  680.  
  681. start->x
  682. |
  683. \/
  684. y
  685.  
  686. if x is for example 3 and y is 5, you find the point of your mouse.
  687.  
  688. start->x...
  689. |_________|
  690. \/________|
  691. y_________|
  692. ._________|
  693. ._________|
  694. ._________|
  695. ._________|
  696. ._________HERE
  697.  
  698. the right upper corner of your window is the x limit, called window.innerWidth
  699. the left bottom corner of your window is the y limit, called window.innerHeight
  700.  
  701. canvas is the same, but multiplied by 2. So for x, it's canvas.height = window.innerHeight * 2
  702. same goes for y, canvas.width = window.innerWidth * 2
  703.  
  704. This can work the other way around too. canvas.height/2 = window.innerHeight
  705. and canvas.width/2 = window.innerWidth
  706.  
  707. NOTE: when you use input.mouse(x, y) you're using the canvas coordinate system.
  708.  
  709. 2. DiepUnits
  710. Read this first: https://github.com/ABCxFF/diepindepth/blob/main/canvas/scaling.md
  711. if you're curious about what l and Fv means, like I was I can tell you now.
  712.  
  713. L stands for your Tank level, that you currently have.
  714. Fv is the fieldFactor. You can find them here for each tank: https://github.com/ABCxFF/diepindepth/blob/main/extras/tankdefs.json
  715. (The formula from the picture as code: const FOV = (level, fieldFactor) => (.55*fieldFactor)/Math.pow(1.01, (level-1)/2); )
  716.  
  717. Additions:
  718. DiepUnits are used, to draw all entities in game in the right size. For example when you go Ranger, they appear smaller
  719. because your entire ingame map shrinks down, so you see more without changing the size of the canvas or the window.
  720. So if a square is 55 diepunits big and it gets visually smaller, it's still 55 diepunits big.
  721.  
  722. Coordinate system: x*scalingFactor, y*scalingFactor
  723.  
  724. IMPORTANT!!! Note that your Tank is getting additional DiepUnits with every level it grows.
  725. This formula descritbes it's growth
  726. 53 * (1.01 ** (currentLevel - 1));
  727.  
  728. 3. WindowScaling
  729. Read this first: https://github.com/ABCxFF/diepindepth/blob/main/canvas/scaling.md
  730. (you can use the function given in there, if you don't want to make your own)
  731.  
  732. it's used for all ui elements, like scoreboard, minimap or stats upgrades.
  733. NOTE: It's not used for html Elements, only canvas. So the starting menu or gameover screen aren't part of it.
  734.  
  735. Coordinate system: x*windowScaling(), y*windowScaling()
  736.  
  737. 4. Converting coordinate systems into each other
  738. canvas -> window = a/(canvas.width/window.innerWidth) -> b
  739. window -> canvas = a*(canvas.width/window.innerWidth) -> b
  740. windowScaling -> window = ( a*windowScaling() )/(canvas.width/window.innerWidth) -> b
  741. windowScaling -> canvas = a*windowScaling() - > b
  742. diepUnits -> canvas = a/scalingFactor -> b
  743. diepUnits -> window = ( a/scalingFactor )/(canvas.width/window.innerWidth) -> b
  744. window -> diepUnits = ( a*scalingFactor )*(canvas.width/window.innerWidth) -> b
  745. canvas -> diepUnits = a*scalingFactor -> b
  746. window -> windowScaling() = ( a*windowScaling() )*(canvas.width/window.innerWidth) -> b
  747. canvas -> windowScaling() = a*windowScaling() - > b
  748. diepUnits -> windowScaling() = ( a/scalingFactor ) * fieldFactor -> b
  749. windowScaling()-> diepUnits = ( a/fieldFactor ) * scalingFactor -> b
  750.  
  751. =============================================================================
  752.  
  753. My todo list or fix:
  754.  
  755. - simulate diep.io moving and knockback physics
  756.  
  757. - simulate diep.io bullets
  758.  
  759. - figure out how to simulate mouse click events
  760.  
  761. - Finish bullet speed hybrid tanks
  762.  
  763. - Figure out physics for sniper, Ranger etc.
  764.  
  765. =============================================================================
  766.  
  767. Useful info:
  768.  
  769. -shape sizes:
  770.  
  771. tank lvl 1 size = 53 diep units
  772.  
  773. grid square side length = 50 diep units
  774. square, triangle = 55 diep units
  775. pentagon = 75 diep units
  776. small crasher = 35 diep units
  777. big crasher = 55 diep units
  778. alpha pentagon = 200 diep units
  779.  
  780. =============================================================================
  781. */
  782. var currentLevel = 0;
  783. var lastLevel = 0;
  784. var tanky = "";
  785. let ripsaw_radius;
  786. let fieldFactor = 1.0;
  787. let found = false;
  788. let loltank;
  789. let lolztank;
  790. let diepUnits = 53 * (1.01 ** (currentLevel - 1));
  791. let FOV = (0.55 * fieldFactor) / Math.pow(1.01, (currentLevel - 1) / 2);
  792. let scalingFactor = FOV * windowScaling();
  793. const fieldFactors = [
  794. {
  795. tank: "Sniper",
  796. factor: 0.899
  797. },
  798. {
  799. tank: "Overseer",
  800. factor: 0.899
  801. },
  802. {
  803. tank: "Overlord",
  804. factor: 0.899
  805. },
  806. {
  807. tank: "Assassin",
  808. factor: 0.8
  809. },
  810. {
  811. tank: "Necromancer",
  812. factor: 0.899
  813. },
  814. {
  815. tank: "Hunter",
  816. factor: 0.85
  817. },
  818. {
  819. tank: "Stalker",
  820. factor: 0.8
  821. },
  822. {
  823. tank: "Ranger",
  824. factor: 0.699
  825. },
  826. {
  827. tank: "Manager",
  828. factor: 0.899
  829. },
  830. {
  831. tank: "Predator",
  832. factor: 0.85
  833. },
  834. {
  835. tank: "Trapper",
  836. factor: 0.899
  837. },
  838. {
  839. tank: "GunnerTrapper",
  840. factor: 0.899
  841. },
  842. {
  843. tank: "Overtrapper",
  844. factor: 0.899
  845. },
  846. {
  847. tank: "MegaTrapper",
  848. factor: 0.899
  849. },
  850. {
  851. tank: "Tri-Trapper",
  852. factor: 0.899
  853. },
  854. {
  855. tank: "Smasher",
  856. factor: 0.899
  857. },
  858. {
  859. tank: "Landmine",
  860. factor: 0.899
  861. },
  862. {
  863. tank: "Streamliner",
  864. factor: 0.85
  865. },
  866. {
  867. tank: "AutoTrapper",
  868. factor: 0.899
  869. },
  870. {
  871. tank: "Battleship",
  872. factor: 0.899
  873. },
  874. {
  875. tank: "AutoSmasher",
  876. factor: 0.899
  877. },
  878. {
  879. tank: "Spike",
  880. factor: 0.899
  881. },
  882. {
  883. tank: "Factory",
  884. factor: 0.899
  885. },
  886. {
  887. tank: "Skimmer",
  888. factor: 0.899
  889. },
  890. {
  891. tank: "Glider",
  892. factor: 0.899
  893. },
  894. {
  895. tank: "Rocketeer",
  896. factor: 0.899
  897. },
  898. ]
  899.  
  900. function windowScaling() {
  901. const a = canvas.height / 1080;
  902. const b = canvas.width / 1920;
  903. return b < a ? a : b;
  904. }
  905.  
  906. function calculateFOV(Fv, l) {
  907. const numerator = 0.55 * Fv;
  908. const denominator = Math.pow(1.01, (l - 1) / 2);
  909. if (typeof window.HEAPF32 !== 'undefined' && typeof window.fov !== 'undefined' && window.fov.length > 0) {
  910. //use this part, if you have a fov script that can share it's fov value with you
  911. FOV = HEAPF32[fov[0]];
  912. } else {
  913. //use this part if you have no fov script
  914. FOV = numerator / denominator;
  915. }
  916. return FOV;
  917. }
  918.  
  919. function apply_values(FF) {
  920. calculateFOV(FF, currentLevel);
  921. scalingFactor = FOV * windowScaling();
  922. ripsaw_radius = diepUnits * scalingFactor;
  923. diepUnits = 53 * (1.01 ** (currentLevel - 1));
  924. }
  925.  
  926. function apply_changes(value) {
  927. if (found) {
  928. fieldFactor = fieldFactors[value].factor;
  929. loltank = tanky;
  930. lastLevel = currentLevel;
  931. apply_values(fieldFactor);
  932. } else {
  933. if (value === null) {
  934. fieldFactor = 1.0;
  935. loltank = "default";
  936. lolztank = tanky;
  937. lastLevel = currentLevel;
  938. apply_values(fieldFactor);
  939. }
  940. }
  941. }
  942.  
  943. function bruteforce_tanks() {
  944. for (let i = 0; i < fieldFactors.length; i++) {
  945. if (tanky.includes(fieldFactors[i].tank)) {
  946. found = true;
  947. console.log("FOUND TANK " + fieldFactors[i].tank);
  948. apply_changes(i);
  949. break;
  950. } else {
  951. found = false;
  952. if (i < fieldFactors.length - 1) {
  953. console.log(`checking tank ${i}`);
  954. } else {
  955. console.log("No Tank was found, resetting to default")
  956. apply_changes(null);
  957. }
  958. }
  959. }
  960. }
  961.  
  962. window.addEventListener("resize", bruteforce_tanks);
  963.  
  964. function check_lvl_change() {
  965. if (lastLevel === currentLevel) {
  966. //console.log("level wasn't changed");
  967. } else {
  968. console.log("changed level, bruteforcing");
  969. bruteforce_tanks();
  970. }
  971. }
  972.  
  973. function check_change() {
  974. //console.log("lastLevel: " + lastLevel + " currentLevel: " + currentLevel);
  975. check_lvl_change();
  976. if (loltank != tanky) {
  977. if (loltank === "default") {
  978. if (lolztank != tanky) {
  979. bruteforce_tanks();
  980. } else {
  981. return;
  982. }
  983. } else {
  984. bruteforce_tanks();
  985. }
  986. }
  987. }
  988.  
  989. setInterval(check_change, 250);
  990.  
  991. //canvas gui
  992. let offsetX = 0;
  993. let offsetY = 0;
  994. //for canvas text height and space between it
  995. let text_startingY = 450 * windowScaling();
  996. let textAdd = 25 * windowScaling();
  997. let selected_box = null;
  998. const boxes = [
  999. {
  1000. color: "lightblue",
  1001. LUcornerX: 47,
  1002. LUcornerY: 67
  1003. },
  1004. {
  1005. color: "green",
  1006. LUcornerX: 47 + 90 + 13,
  1007. LUcornerY: 67
  1008. },
  1009. {
  1010. color: "red",
  1011. LUcornerX: 47,
  1012. LUcornerY: 67 + 90 + 9
  1013. },
  1014. {
  1015. color: "yellow",
  1016. LUcornerX: 47 + 90 + 13,
  1017. LUcornerY: 67 + 90 + 9
  1018. },
  1019. {
  1020. color: "blue",
  1021. LUcornerX: 47,
  1022. LUcornerY: 67 + ((90 + 9) * 2)
  1023. },
  1024. {
  1025. color: "rainbow",
  1026. LUcornerX: 47 + 90 + 13,
  1027. LUcornerY: 67 + ((90 + 9) * 2)
  1028. }
  1029. ]
  1030.  
  1031. const ctx = canvas.getContext('2d');
  1032.  
  1033. function ctx_text(fcolor, scolor, lineWidth, font, text, textX, textY) {
  1034. ctx.fillStyle = fcolor;
  1035. ctx.lineWidth = lineWidth;
  1036. ctx.font = font;
  1037. ctx.strokeStyle = scolor;
  1038. ctx.strokeText(`${text}`, textX, textY)
  1039. ctx.fillText(`${text}`, textX, textY)
  1040. }
  1041.  
  1042. function ctx_arc(x, y, r, sAngle, eAngle, counterclockwise, c) {
  1043. ctx.beginPath();
  1044. ctx.arc(x, y, r, sAngle, eAngle, counterclockwise);
  1045. ctx.fillStyle = c;
  1046. ctx.fill();
  1047. }
  1048.  
  1049. function ctx_rect(x, y, a, b, c) {
  1050. ctx.beginPath();
  1051. ctx.strokeStyle = c;
  1052. ctx.strokeRect(x, y, a, b);
  1053. }
  1054.  
  1055. //use this for game entities
  1056. function dot_in_diepunits(diepunits_X, diepunits_Y) {
  1057. ctx_arc(diepunits_X * scalingFactor, diepunits_Y * scalingFactor, 5, 0, 2 * Math.PI, false, "lightblue");
  1058. }
  1059.  
  1060. function circle_in_diepunits(diepunits_X, diepunits_Y, diepunits_R, c) {
  1061. ctx.beginPath();
  1062. ctx.arc(diepunits_X * scalingFactor, diepunits_Y * scalingFactor, diepunits_R * scalingFactor, 0, 2 * Math.PI, false);
  1063. ctx.strokeStyle = c;
  1064. ctx.stroke();
  1065. }
  1066.  
  1067. //use this for ui elements like upgrades or scoreboard
  1068. function dot_in_diepunits_FOVless(diepunits_X, diepunits_Y) {
  1069. ctx_arc(diepunits_X * windowScaling(), diepunits_Y * windowScaling(), 5, 0, 2 * Math.PI, false, "lightblue");
  1070. }
  1071.  
  1072. function square_for_grid(x, y, a, b, color) {
  1073. ctx.beginPath();
  1074. ctx.rect(x * windowScaling(), y * windowScaling(), a * windowScaling(), b * windowScaling());
  1075. ctx.strokeStyle = color;
  1076. ctx.stroke();
  1077. }
  1078.  
  1079. function draw_upgrade_grid() {
  1080. for (let i = 0; i < boxes.length; i++) {
  1081. let start_x = (boxes[i].LUcornerX * windowScaling()) / two;
  1082. let start_y = (boxes[i].LUcornerY * windowScaling()) / two;
  1083. let end_x = ((boxes[i].LUcornerX + 43 * 2) * windowScaling()) / two;
  1084. let end_y = ((boxes[i].LUcornerY + 43 * 2) * windowScaling()) / two;
  1085. let temp_color = "black";
  1086. if (uwuX > start_x && uwuY > start_y && uwuX < end_x && uwuY < end_y) {
  1087. temp_color = "red";
  1088. selected_box = i;
  1089. } else {
  1090. temp_color = "black";
  1091. selected_box = null;
  1092. }
  1093. square_for_grid(boxes[i].LUcornerX, boxes[i].LUcornerY, 86, 86, temp_color);
  1094. }
  1095. for (let i = 0; i < boxes.length; i++) {
  1096. dot_in_diepunits_FOVless(boxes[i].LUcornerX, boxes[i].LUcornerY);
  1097. dot_in_diepunits_FOVless(boxes[i].LUcornerX + 43, boxes[i].LUcornerY);
  1098. dot_in_diepunits_FOVless(boxes[i].LUcornerX + 43 * 2, boxes[i].LUcornerY);
  1099. dot_in_diepunits_FOVless(boxes[i].LUcornerX + 43 * 2, boxes[i].LUcornerY + 43);
  1100. dot_in_diepunits_FOVless(boxes[i].LUcornerX + 43 * 2, boxes[i].LUcornerY + 43 * 2);
  1101. dot_in_diepunits_FOVless(boxes[i].LUcornerX, boxes[i].LUcornerY + 43);
  1102. dot_in_diepunits_FOVless(boxes[i].LUcornerX, boxes[i].LUcornerY + 43 * 2);
  1103. dot_in_diepunits_FOVless(boxes[i].LUcornerX + 43, boxes[i].LUcornerY + 43);
  1104. }
  1105. }
  1106.  
  1107. const gradients = ["#94b3d0", "#96b0c7", "#778daa", "#4c7299", "#52596c", "#19254e", "#2d445f", "#172631"];
  1108. const tank_group1 = ["Trapper", "Overtrapper", "MegaTrapper", "Tri-Trapper"]; //Traps only
  1109. const tank_group2 = ["Tank", "Twin", "TripleShot", "SpreadShot", "PentaShot", "TwinFlank", "TripleTwin", "QuadTank", "OctoTank", "MachineGun", "Sprayer", "Triplet", "FlankGuard"]; //constant bullets [initial speed = 0.699]
  1110. //const tank_group3 = ["GunnerTrapper", "AutoTrapper"]; //Traps AND constant bullets (UNFINISHED)
  1111. //const tank_group4 = []; //mix of bullets (UNFINISHED)
  1112. //const tank_group5 = ["Sniper", "Assassin", "Stalker", "Ranger"]; //sniper+ bullets (UNFINISHED)
  1113. const tank_group6 = ["Destroyer", "Hybrid", "Annihilator"]; //slower bullets [intitial speed = 0.699]
  1114. //const tank_group7 = ["Overseer", "Overlord", "Manager", "Necromancer"]; //infinite bullets(drones) (UNFINISHED)
  1115. const tank_group8 = ["Factory"]; //drones with spreading abilities
  1116. const tank_group9 = ["Battleship"]; //special case
  1117.  
  1118. function draw_cirle_radius_for_tank() {
  1119. if (tank_group1.includes(tanky)) {
  1120. for (let i = 0; i < gradients.length; i++) {
  1121. circle_in_diepunits(canvas.width / 2 / scalingFactor, canvas.height / 2 / scalingFactor, 485 + (52.5 * i), gradients[i]);
  1122. }
  1123. } else if (tank_group2.includes(tanky)) {
  1124. for (let i = 0; i < gradients.length; i++) {
  1125. circle_in_diepunits(canvas.width / 2 / scalingFactor, canvas.height / 2 / scalingFactor, 1850 + (210 * i), gradients[i]);
  1126. }
  1127. /*
  1128. }else if(tank_group5.includes(tanky)){
  1129. for(let i = 0; i < gradients.length; i++){
  1130. circle_in_diepunits(canvas.width/2/scalingFactor, canvas.height/2/scalingFactor, 2703 + (420*i), gradients[i]);
  1131. }*/
  1132. } else if (tank_group6.includes(tanky)) {
  1133. for (let i = 0; i < gradients.length; i++) {
  1134. circle_in_diepunits(canvas.width / 2 / scalingFactor, canvas.height / 2 / scalingFactor, 1443.21 + (146.79 * i), gradients[i]);
  1135. }
  1136. /*
  1137. }else if(tank_group7.includes(tanky)){
  1138. for(let i = 0; i < gradients.length; i++){
  1139. circle_in_diepunits( canvas.width/2/scalingFactor , canvas.height/2/scalingFactor, 1607 + (145*i), gradients[i]);
  1140. circle_in_diepunits( uwuX*2/scalingFactor , uwuY*2/scalingFactor, 1607 + (145*i), gradients[i]);
  1141. }*/
  1142. } else if (tank_group8.includes(tanky)) {
  1143. if(!auto_fire){
  1144. circle_in_diepunits(canvas.width/2 / scalingFactor, canvas.height/2 / scalingFactor, 200, gradients[0]);
  1145. }else{
  1146. circle_in_diepunits(uwuX * two / scalingFactor, uwuY * two / scalingFactor, 800, gradients[1]);
  1147. circle_in_diepunits(uwuX * two / scalingFactor, uwuY * two / scalingFactor, 900, gradients[2]);
  1148. }
  1149. } else if (tank_group9.includes(tanky)) {
  1150. for (let i = 0; i < gradients.length; i++) {
  1151. circle_in_diepunits(canvas.width / 2 / scalingFactor, canvas.height / 2 / scalingFactor, 1640 + (210 * i), gradients[i]);
  1152. }
  1153. } else {
  1154. return;
  1155. }
  1156.  
  1157. }
  1158.  
  1159. //let's calculate the angle
  1160. var vector_l = [null, null];
  1161. var angle_l = 0;
  1162.  
  1163. function calc_leader() {
  1164. if (script_list.minimap_leader_v1) {
  1165. let xc = canvas.width / 2;
  1166. let yc = canvas.height / 2;
  1167. vector_l[0] = window.l_arrow.xl - xc;
  1168. vector_l[1] = window.l_arrow.yl - yc;
  1169. angle_l = Math.atan2(vector_l[1], vector_l[0]) * (180 / Math.PI);
  1170. } else if (script_list.minimap_leader_v2) {
  1171. let xc = canvas.width / 2;
  1172. let yc = canvas.height / 2;
  1173. vector_l[0] = window.L_X - xc;
  1174. vector_l[1] = window.L_Y - yc;
  1175. angle_l = Math.atan2(vector_l[1], vector_l[0]) * (180 / Math.PI);
  1176. } else {
  1177. console.log("waiting for leader script to give us values");
  1178. }
  1179. }
  1180.  
  1181. //setInterval(calc_l, 0);
  1182.  
  1183. // Minimap logic
  1184. var minimap_elements = [
  1185. {
  1186. name: "minimap",
  1187. x: 177.5,
  1188. y: 177.5,
  1189. width: 162.5,
  1190. height: 162.5,
  1191. color: "purple"
  1192. },
  1193. {
  1194. name: "2 Teams Blue Team",
  1195. x: 177.5,
  1196. y: 177.5,
  1197. width: 17.5,
  1198. height: 162.5,
  1199. color: "blue"
  1200. },
  1201. {
  1202. name: "2 Teams Blue Team zone",
  1203. x: 160.0,
  1204. y: 177.5,
  1205. width: 17.5,
  1206. height: 162.5,
  1207. color: "SlateBlue"
  1208. },
  1209. {
  1210. name: "2 Teams Red Team",
  1211. x: 32.5,
  1212. y: 177.5,
  1213. width: 17.5,
  1214. height: 162.5,
  1215. color: "red"
  1216. },
  1217. {
  1218. name: "2 Teams Red Team zone",
  1219. x: 50,
  1220. y: 177.5,
  1221. width: 17.5,
  1222. height: 162.5,
  1223. color: "orangeRed"
  1224. },
  1225. {
  1226. name: "4 Teams Blue Team",
  1227. x: 177.5,
  1228. y: 177.5,
  1229. width: 25,
  1230. height: 25,
  1231. color: "blue"
  1232. },
  1233. {
  1234. name: "4 Teams Blue zone",
  1235. x: 177.5,
  1236. y: 177.5,
  1237. width: 40,
  1238. height: 40,
  1239. color: "SlateBlue"
  1240. },
  1241. {
  1242. name: "4 Teams Purple Team",
  1243. x: 40,
  1244. y: 177.5,
  1245. width: 25,
  1246. height: 25,
  1247. color: "purple"
  1248. },
  1249. {
  1250. name: "4 Teams Purple zone",
  1251. x: 55,
  1252. y: 177.5,
  1253. width: 40,
  1254. height: 40,
  1255. color: "Violet"
  1256. },
  1257. {
  1258. name: "4 Teams Green Team",
  1259. x: 177.5,
  1260. y: 40,
  1261. width: 25,
  1262. height: 25,
  1263. color: "green"
  1264. },
  1265. {
  1266. name: "4 Teams Green zone",
  1267. x: 177.5,
  1268. y: 55,
  1269. width: 40,
  1270. height: 40,
  1271. color: "LimeGreen"
  1272. },
  1273. {
  1274. name: "4 Teams Red Team",
  1275. x: 40,
  1276. y: 40,
  1277. width: 25,
  1278. height: 25,
  1279. color: "orangeRed"
  1280. },
  1281. {
  1282. name: "4 Teams Red zone",
  1283. x: 55,
  1284. y: 55,
  1285. width: 40,
  1286. height: 40,
  1287. color: "red"
  1288. },
  1289. ];
  1290.  
  1291. var m_e_ctx_coords = [
  1292. {
  1293. name: "minimap",
  1294. startx: null,
  1295. stary: null,
  1296. endx: null,
  1297. endy: null
  1298. },
  1299. {
  1300. name: "2 Teams Blue Team",
  1301. startx: null,
  1302. stary: null,
  1303. endx: null,
  1304. endy: null
  1305. },
  1306. {
  1307. name: "2 Teams Blue Team Zone",
  1308. startx: null,
  1309. stary: null,
  1310. endx: null,
  1311. endy: null
  1312. },
  1313. {
  1314. name: "2 Teams Red Team",
  1315. startx: null,
  1316. stary: null,
  1317. endx: null,
  1318. endy: null
  1319. },
  1320. {
  1321. name: "2 Teams Red Team Zone",
  1322. startx: null,
  1323. stary: null,
  1324. endx: null,
  1325. endy: null
  1326. },
  1327. {
  1328. name: "4 Teams Blue Team",
  1329. startx: null,
  1330. stary: null,
  1331. endx: null,
  1332. endy: null
  1333. },
  1334. {
  1335. name: "4 Teams Blue zone",
  1336. startx: null,
  1337. stary: null,
  1338. endx: null,
  1339. endy: null
  1340. },
  1341. {
  1342. name: "4 Teams Purple Team",
  1343. startx: null,
  1344. stary: null,
  1345. endx: null,
  1346. endy: null
  1347. },
  1348. {
  1349. name: "4 Teams Purple zone",
  1350. startx: null,
  1351. stary: null,
  1352. endx: null,
  1353. endy: null
  1354. },
  1355. {
  1356. name: "4 Teams Green Team",
  1357. startx: null,
  1358. stary: null,
  1359. endx: null,
  1360. endy: null
  1361. },
  1362. {
  1363. name: "4 Teams Green zone",
  1364. startx: null,
  1365. stary: null,
  1366. endx: null,
  1367. endy: null
  1368. },
  1369. {
  1370. name: "4 Teams Red Team",
  1371. startx: null,
  1372. stary: null,
  1373. endx: null,
  1374. endy: null
  1375. },
  1376. {
  1377. name: "4 Teams Red zone",
  1378. startx: null,
  1379. stary: null,
  1380. endx: null,
  1381. endy: null
  1382. }
  1383. ]
  1384.  
  1385. function draw_minimap() {
  1386. switch (gamemode) {
  1387. case "2 Teams":
  1388. for (let i = 0; i < 5; i++) {
  1389. if(i === 2 || i === 4){
  1390. if (toggleButtons.Addons['Toggle Base Zones']){
  1391. updateAndDrawElement(i);
  1392. }
  1393. }else{
  1394. updateAndDrawElement(i);
  1395. }
  1396. }
  1397. break;
  1398. case "4 Teams":
  1399. updateAndDrawElement(0);
  1400. for (let i = 5; i < minimap_elements.length; i++) {
  1401. if(i === 6 || i === 8 || i === 10 || i === 12){
  1402. if (toggleButtons.Addons['Toggle Base Zones']){
  1403. updateAndDrawElement(i);
  1404. }
  1405. }else{
  1406. updateAndDrawElement(i);
  1407. }
  1408. }
  1409. break;
  1410. }
  1411. if (script_list.minimap_leader_v1 || script_list.minimap_leader_v2) {
  1412. minimap_collision_check();
  1413. }
  1414. }
  1415.  
  1416. function updateAndDrawElement(index) {
  1417. // Update their real-time position
  1418. m_e_ctx_coords[index].startx = canvas.width - (minimap_elements[index].x * windowScaling());
  1419. m_e_ctx_coords[index].starty = canvas.height - (minimap_elements[index].y * windowScaling());
  1420. m_e_ctx_coords[index].endx = m_e_ctx_coords[index].startx + minimap_elements[index].width * windowScaling();
  1421. m_e_ctx_coords[index].endy = m_e_ctx_coords[index].starty + minimap_elements[index].height * windowScaling();
  1422.  
  1423. // Draw the element
  1424. ctx.beginPath();
  1425. ctx.rect(m_e_ctx_coords[index].startx, m_e_ctx_coords[index].starty, minimap_elements[index].width * windowScaling(), minimap_elements[index].height * windowScaling());
  1426. ctx.lineWidth = "1";
  1427. ctx.strokeStyle = minimap_elements[index].color;
  1428. ctx.stroke();
  1429. }
  1430.  
  1431. let position_on_minimap;
  1432.  
  1433. function minimap_collision_check() {
  1434. if (script_list.minimap_leader_v1 || script_list.minimap_leader_v2) {
  1435. let x = script_list.minimap_leader_v1 ? window.m_arrow.xl : window.M_X;
  1436. let y = script_list.minimap_leader_v1 ? window.m_arrow.yl : window.M_Y;
  1437.  
  1438. if (m_e_ctx_coords[0].startx < x &&
  1439. m_e_ctx_coords[0].starty < y &&
  1440. m_e_ctx_coords[0].endx > x &&
  1441. m_e_ctx_coords[0].endy > y) {
  1442.  
  1443. if (gamemode === "2 Teams") {
  1444. if (checkWithinBase(1, x, y)) position_on_minimap = "blue base";
  1445. else if (checkWithinBase(2, x, y)) position_on_minimap = "blue drones";
  1446. else if (checkWithinBase(3, x, y)) position_on_minimap = "red base";
  1447. else if (checkWithinBase(4, x, y)) position_on_minimap = "red base drones";
  1448. else position_on_minimap = "not in the base";
  1449. } else if (gamemode === "4 Teams") {
  1450. if (checkWithinBase(6, x, y)){
  1451. if (checkWithinBase(5, x, y)){
  1452. position_on_minimap = "blue base"
  1453. }else{
  1454. position_on_minimap = "blue drones";
  1455. }
  1456. }else if (checkWithinBase(8, x, y)){
  1457. if (checkWithinBase(7, x, y)){
  1458. position_on_minimap = "purple base"
  1459. }else{
  1460. position_on_minimap = "purple drones";
  1461. }
  1462. }else if (checkWithinBase(10, x, y)){
  1463. if (checkWithinBase(9, x, y)){
  1464. position_on_minimap = "green base"
  1465. }else{
  1466. position_on_minimap = "green drones";
  1467. }
  1468. }else if (checkWithinBase(12, x, y)){
  1469. if (checkWithinBase(11, x, y)){
  1470. position_on_minimap = "red base"
  1471. }else{
  1472. position_on_minimap = "red drones";
  1473. }
  1474. }else{
  1475. position_on_minimap = "not in the base";
  1476. }
  1477. } else {
  1478. position_on_minimap = "Warning! not on minimap";
  1479. }
  1480. }
  1481. }
  1482. }
  1483.  
  1484. function checkWithinBase(baseIndex, x, y) {
  1485. return m_e_ctx_coords[baseIndex].startx < x &&
  1486. m_e_ctx_coords[baseIndex].starty < y &&
  1487. m_e_ctx_coords[baseIndex].endx > x &&
  1488. m_e_ctx_coords[baseIndex].endy > y;
  1489. }
  1490.  
  1491. //notify player about entering base zones
  1492. let alerted = false;
  1493. function alert_about_drones(){
  1494. if(position_on_minimap.includes('drones')){
  1495. if(!alerted){
  1496. input.inGameNotification("Warning drones!");
  1497. alerted = true;
  1498. }
  1499. }else{
  1500. alerted = false;
  1501. }
  1502. }
  1503.  
  1504. //let's try drawing a line to the leader
  1505.  
  1506. function apply_vector_on_minimap() {
  1507. if (script_list.minimap_leader_v1) {
  1508. let x = window.m_arrow.xl;
  1509. let y = window.m_arrow.yl;
  1510. let thetaRadians = angle_l * (Math.PI / 180);
  1511. let r = m_e_ctx_coords[0].endx - m_e_ctx_coords[0].startx;
  1512. let x2 = x + r * Math.cos(thetaRadians);
  1513. let y2 = y + r * Math.sin(thetaRadians);
  1514. ctx.beginPath();
  1515. ctx.moveTo(x, y);
  1516. ctx.lineTo(x2, y2);
  1517. ctx.stroke();
  1518. } else if (script_list.minimap_leader_v2) {
  1519. let x = window.M_X;
  1520. let y = window.M_Y;
  1521. let thetaRadians = angle_l * (Math.PI / 180);
  1522. let r = m_e_ctx_coords[0].endx - m_e_ctx_coords[0].startx;
  1523. let x2 = x + r * Math.cos(thetaRadians);
  1524. let y2 = y + r * Math.sin(thetaRadians);
  1525. ctx.beginPath();
  1526. ctx.moveTo(x, y);
  1527. ctx.lineTo(x2, y2);
  1528. ctx.stroke();
  1529. }
  1530. }
  1531.  
  1532.  
  1533. //drawing the limit of the server (needs rework)
  1534. function draw_server_border(a, b) {
  1535. ctx.beginPath();
  1536. ctx.rect(canvas.width / 2 - (a / 2 * scalingFactor), canvas.height / 2 - (b / 2 * scalingFactor), a * scalingFactor, b * scalingFactor);
  1537. ctx.strokeStyle = "red";
  1538. ctx.stroke();
  1539. }
  1540.  
  1541. const circle_gradients = [
  1542. "#FF0000", // Red
  1543. "#FF4D00", // Orange Red
  1544. "#FF8000", // Orange
  1545. "#FFB300", // Dark Goldenrod
  1546. "#FFD700", // Gold
  1547. "#FFEA00", // Yellow
  1548. "#D6FF00", // Light Yellow Green
  1549. "#A3FF00", // Yellow Green
  1550. "#6CFF00", // Lime Green
  1551. "#00FF4C", // Medium Spring Green
  1552. "#00FF9D", // Turquoise
  1553. "#00D6FF", // Sky Blue
  1554. "#006CFF", // Blue
  1555. "#0000FF" // Dark Blue
  1556. ];
  1557.  
  1558. function draw_crx_events() {
  1559. //you need either leader arrow or moveTo/lineTo script from h3llside for this part
  1560. if (script_list.moveToLineTo_debug) {
  1561. for (let i = 0; i < window.y_and_x.length; i++) {
  1562. ctx_arc(window.y_and_x[i][0], window.y_and_x[i][1], 10, 0, 2 * Math.PI, false, circle_gradients[i]);
  1563. ctx_text("white", "DarkRed", 6, 1.5 + "em Ubuntu", i, window.y_and_x[i][0], window.y_and_x[i][1]);
  1564. }
  1565. } else if (script_list.minimap_leader_v1) {
  1566. //ctx_arc(window.l_arrow.xm, window.l_arrow.ym, 15, 0, 2 * Math.PI, false, window.l_arrow.color);
  1567. //ctx_arc(window.m_arrow.xm, window.m_arrow.ym, 1, 0, 2 * Math.PI, false, "yellow");
  1568. ctx_arc(window.l_arrow.xl, window.l_arrow.yl, 5, 0, 2 * Math.PI, false, window.l_arrow.color);
  1569. ctx_arc(window.m_arrow.xl, window.m_arrow.yl, 1, 0, 2 * Math.PI, false, "yellow");
  1570. }
  1571. }
  1572.  
  1573. //tank aim lines
  1574. let TurretRatios = [
  1575. {
  1576. name: "Destroyer",
  1577. ratio: 95 / 71.4,
  1578. color: "red"
  1579. },
  1580. {
  1581. name: "Anni",
  1582. ratio: 95 / 96.6,
  1583. color: "darkred"
  1584. },
  1585. {
  1586. name: "Fighter",
  1587. ratio: 80 / 42,
  1588. color: "orange"
  1589. },
  1590. {
  1591. name: "Booster",
  1592. ratio: 70 / 42,
  1593. color: "green"
  1594. },
  1595. {
  1596. name: "Tank",
  1597. ratio: 95 / 42,
  1598. color: "yellow"
  1599. },
  1600. {
  1601. name: "Sniper",
  1602. ratio: 110 / 42,
  1603. color: "yellow"
  1604. },
  1605. {
  1606. name: "Ranger",
  1607. ratio: 120 / 42,
  1608. color: "orange"
  1609. },
  1610. {
  1611. name: "Hunter",
  1612. ratio: 95 / 56.7,
  1613. color: "orange"
  1614. },
  1615. {
  1616. name: "Predator",
  1617. ratio: 80 / 71.4,
  1618. color: "darkorange"
  1619. },
  1620. {
  1621. name: "Mega Trapper",
  1622. ratio: 60 / 54.6,
  1623. color: "red"
  1624. },
  1625. {
  1626. name: "Trapper",
  1627. ratio: 60 / 42,
  1628. color: "orange"
  1629. },
  1630. {
  1631. name: "Gunner Trapper",
  1632. ratio: 95 / 26.6,
  1633. color: "yellow"
  1634. },
  1635. {
  1636. name: "Predator",
  1637. ratio: 95 / 84.8,
  1638. color: "red"
  1639. },
  1640. {
  1641. name: "Gunner(small)",
  1642. ratio: 65 / 25.2,
  1643. color: "lightgreen"
  1644. },
  1645. {
  1646. name: "Gunner(big)",
  1647. ratio: 85 / 25.2,
  1648. color: "green"
  1649. },
  1650. {
  1651. name: "Spread1",
  1652. ratio: 89 / 29.4,
  1653. color: "orange"
  1654. },
  1655. {
  1656. name: "Spread2",
  1657. ratio: 83 / 29.4,
  1658. color: "orange"
  1659. },
  1660. {
  1661. name: "Spread3",
  1662. ratio: 71 / 29.4,
  1663. color: "orange"
  1664. },
  1665. {
  1666. name: "Spread4",
  1667. ratio: 65 / 29.4,
  1668. color: "orange"
  1669. },
  1670. //{name: "bullet", ratio: 1, color: "pink"},
  1671. ];
  1672.  
  1673. function drawTheThing(x, y, r, index) {
  1674. if (toggleButtons.Visual['Toggle Aim Lines']) {
  1675. if (TurretRatios[index].name != "bullet") {
  1676. ctx.strokeStyle = TurretRatios[index].color;
  1677. ctx.lineWidth = 5;
  1678.  
  1679. let extendedR = 300 * scalingFactor;
  1680.  
  1681. // Reverse the angle to switch the direction
  1682. const reversedAngle = -angle;
  1683.  
  1684. // Calculate the end point of the line
  1685. const endX = x + extendedR * Math.cos(reversedAngle);
  1686. const endY = y + extendedR * Math.sin(reversedAngle);
  1687.  
  1688. // Draw the line
  1689. ctx.beginPath();
  1690. ctx.moveTo(x, y);
  1691. ctx.lineTo(endX, endY);
  1692. ctx.stroke();
  1693.  
  1694. // Draw text at the end of the line
  1695. ctx.font = "20px Arial";
  1696. ctx.fillStyle = TurretRatios[index].color;
  1697. ctx.strokeStyle = "black";
  1698. ctx.strokeText(TurretRatios[index].name, endX, endY);
  1699. ctx.fillText(TurretRatios[index].name, endX, endY);
  1700. ctx.beginPath();
  1701. } else {
  1702. ctx.strokeStyle = TurretRatios[index].color;
  1703. ctx.lineWidth = 5;
  1704.  
  1705. // Draw text at the end of the line
  1706. ctx.font = "15px Arial";
  1707. ctx.fillStyle = TurretRatios[index].color;
  1708. ctx.strokeStyle = "black";
  1709. let tankRadiusesTrans = [];
  1710. for (let i = 1; i <= 45; i++) {
  1711. let value = Math.abs((48.589 * (1.01 ** (i - 1))) * Math.abs(scalingFactor).toFixed(4)).toFixed(3);
  1712. tankRadiusesTrans.push(value);
  1713. }
  1714.  
  1715. let r_abs = Math.abs(r).toFixed(3);
  1716. if (r_abs < tankRadiusesTrans[0]) {
  1717. ctx.beginPath();
  1718. ctx.strokeStyle = TurretRatios[index].color;
  1719. ctx.arc(x, y - r / 2, r * 2, 0, 2 * Math.PI);
  1720. ctx.stroke();
  1721. ctx.beginPath();
  1722. } else {
  1723.  
  1724. // Find the closest value in the array
  1725. let closestValue = tankRadiusesTrans.reduce((prev, curr) => {
  1726. return (Math.abs(curr - r_abs) < Math.abs(prev - r_abs) ? curr : prev);
  1727. });
  1728.  
  1729. // Find the index of the closest value
  1730. let closestIndex = tankRadiusesTrans.indexOf(closestValue);
  1731.  
  1732. if (closestIndex !== -1) {
  1733. let r_name = `Level ${closestIndex + 1}`;
  1734. ctx.strokeText(r_name, x, y + 50 * scalingFactor);
  1735. ctx.fillText(r_name, x, y + 50 * scalingFactor);
  1736. ctx.beginPath();
  1737. } else {
  1738.  
  1739. let r_name = `radius: ${Math.abs(r).toFixed(4)} 1: ${tankRadiusesTrans[0]} 2: ${tankRadiusesTrans[1]} 3: ${tankRadiusesTrans[2]}`;
  1740. ctx.strokeText(r_name, x, y);
  1741. ctx.fillText(r_name, x, y);
  1742. ctx.beginPath();
  1743. }
  1744. /*
  1745. ctx.strokeText(TurretRatios[index].name, x, y);
  1746. ctx.fillText(TurretRatios[index].name, x, y);
  1747. */
  1748. }
  1749. }
  1750. }
  1751. }
  1752.  
  1753. var angle, a, b, width;
  1754. let perm_cont = [];
  1755.  
  1756. CanvasRenderingContext2D.prototype.setTransform = new Proxy(CanvasRenderingContext2D.prototype.setTransform, {
  1757. apply(target, thisArgs, args) {
  1758. // Check if the ratio matches the specified conditions
  1759. for (let i = 0; i < TurretRatios.length; i++) {
  1760. if (Math.abs(args[0] / args[3]).toFixed(3) == (TurretRatios[i].ratio).toFixed(3)) {
  1761. if (TurretRatios[i].name === "bullet") {
  1762. if (args[0] != 1 && args[0] > 10 && args[0] < 100 && args[4] > 1 && args[5] > 1 && args[4] != args[5] &&
  1763. thisArgs.globalAlpha != 0.10000000149011612 && thisArgs.globalAlpha != 0.3499999940395355) {
  1764. if (!perm_cont.includes(thisArgs)) {
  1765. perm_cont.push(thisArgs);
  1766. //console.log(perm_cont);
  1767. }
  1768. angle = Math.atan2(args[2], args[3]) || 0;
  1769. width = Math.hypot(args[3], args[2]);
  1770. a = args[4] - Math.cos(angle + Math.PI / 2) * width / 2;
  1771. b = args[5] + Math.sin(angle + Math.PI / 2) * width / 2;
  1772. //console.log(b);
  1773. if (a > 0 && b > 0 && thisArgs.fillStyle != "#1B1B1B") { //OUTLINE COLOR
  1774. drawTheThing(a, b, Math.hypot(args[3], args[2]), i);
  1775. }
  1776. }
  1777. } else {
  1778. angle = Math.atan2(args[2], args[3]) || 0;
  1779. width = Math.hypot(args[3], args[2]);
  1780. a = args[4] - Math.cos(angle + Math.PI / 2) * width / 2;
  1781. b = args[5] + Math.sin(angle + Math.PI / 2) * width / 2;
  1782. drawTheThing(a, b, Math.hypot(args[3], args[2]), i);
  1783. }
  1784. }
  1785. }
  1786. return Reflect.apply(target, thisArgs, args);
  1787. }
  1788. });
  1789.  
  1790. setTimeout(() => {
  1791. let gui = () => {
  1792. if (state === "in game") {
  1793. if (toggleButtons.Visual['Toggle Minimap']) {
  1794. draw_minimap();
  1795. }
  1796. if (toggleButtons.Addons['Toggle Base Zones']){
  1797. toggleButtons.Visual['Toggle Minimap'] = true;
  1798. alert_about_drones();
  1799. }
  1800. if (script_list.minimap_leader_v2) {
  1801. if (toggleButtons.Addons['Toggle Leader Angle']) {
  1802. if (!script_list.minimap_leader_v2) {
  1803. input.inGameNotification("missing Leader & Minimap Arrow(Mi300)");
  1804. }
  1805. if (!toggleButtons.Visual['Toggle Minimap']) {
  1806. input.inGameNotification("Enabled Minimap for it to work properly. To turn it off, go to Visual -> Minimap");
  1807. toggleButtons.Visual['Toggle Minimap'] = true;
  1808. } else {
  1809. calc_leader();
  1810. apply_vector_on_minimap();
  1811. }
  1812. }
  1813. }
  1814. if(toggleButtons.Debug['Toggle Arrow pos']){
  1815. window.arrowv2_debug = true;
  1816. }else{
  1817. window.arrowv2_debug = false;
  1818. }
  1819. if (script_list.set_transform_debug) {
  1820. ctx_arc(window.crx_container[2], window.crx_container[3], 50, 0, 2 * Math.PI, false, "yellow");
  1821. }
  1822. if (toggleButtons.Debug['Toggle Text']) {
  1823. ctx_text("white", "DarkRed", 3, 1 + "em Ubuntu", "canvas Lvl:" + currentLevel, canvas.width / 20 + 10, text_startingY + (textAdd * 0));
  1824. ctx_text("white", "DarkRed", 3, 1 + "em Ubuntu", "canvas tank: " + tanky, canvas.width / 20 + 10, text_startingY + (textAdd * 1));
  1825. ctx_text("white", "DarkRed", 3, 1 + "em Ubuntu", "radius: " + ripsaw_radius, canvas.width / 20 + 10, text_startingY + (textAdd * 2));
  1826. ctx_text("white", "DarkRed", 3, 1 + "em Ubuntu", "scaling Factor: " + scalingFactor, canvas.width / 20 + 10, text_startingY + (textAdd * 3));
  1827. ctx_text("white", "DarkRed", 3, 1 + "em Ubuntu", "diep Units: " + diepUnits, canvas.width / 20 + 10, text_startingY + (textAdd * 4));
  1828. ctx_text("white", "DarkRed", 3, 1 + "em Ubuntu", "Fov: " + FOV, canvas.width / 20 + 10, text_startingY + (textAdd * 5));
  1829. ctx_text("white", "DarkRed", 3, 1 + "em Ubuntu", "current Tick: " + currentTick, canvas.width / 20 + 10, text_startingY + (textAdd * 6));
  1830. ctx_text("white", "DarkRed", 3, 1 + "em Ubuntu", "vector: " + Math.floor(vector_l[0]) + ", " + Math.floor(vector_l[1]) + "angle: " + Math.floor(angle_l), canvas.width / 20 + 10, text_startingY + (textAdd * 7));
  1831. //ctx_text("white", "DarkRed", 6, 1.5 + "em Ubuntu", "realX: " + uwuX + "realY: " + uwuY + "newX: " + uwuX*windowScaling() + "newY: " + uwuY*windowScaling(), uwuX*2, uwuY*2);
  1832.  
  1833. //points at mouse
  1834. ctx_arc(uwuX * two, uwuY * two, 5, 0, 2 * Math.PI, false, "purple");
  1835. /*
  1836. circle_in_diepunits(uwuX*2/scalingFactor, uwuY*2/scalingFactor, 35, "pink");
  1837. circle_in_diepunits(uwuX*2/scalingFactor, uwuY*2/scalingFactor, 55, "yellow");
  1838. circle_in_diepunits(uwuX*2/scalingFactor, uwuY*2/scalingFactor, 75, "purple");
  1839. circle_in_diepunits(uwuX*2/scalingFactor, uwuY*2/scalingFactor, 200, "blue");
  1840. */
  1841.  
  1842. //coords at mouse
  1843. ctx_text("white", "DarkRed", 6, 1.5 + "em Ubuntu", "realX: " + uwuX * two + "realY: " + uwuY * two, uwuX * two, uwuY * two);
  1844. }
  1845.  
  1846. if (currentLevel != null && tanky != null) {
  1847. if (toggleButtons.Debug['Toggle Middle Circle']) {
  1848. ctx.beginPath();
  1849. ctx.moveTo(canvas.width / 2 + offsetX, canvas.height / 2 + offsetY);
  1850. ctx.lineTo(uwuX * two, uwuY * two);
  1851. ctx.stroke();
  1852. ctx_arc(canvas.width / 2 + offsetX, canvas.height / 2 + offsetY, ripsaw_radius, 0, 2 * Math.PI, false, "darkblue");
  1853. ctx_arc(canvas.width / 2 + offsetX, canvas.height / 2 + offsetY, ripsaw_radius * 0.9, 0, 2 * Math.PI, false, "lightblue");
  1854. }
  1855. if (toggleButtons.Debug['Toggle Upgrades']) {
  1856. draw_upgrade_grid();
  1857. }
  1858. //draw_server_border(4000, 2250);
  1859. draw_crx_events();
  1860. if (toggleButtons.Visual['Toggle Bullet Distance']) {
  1861. draw_cirle_radius_for_tank();
  1862. }
  1863. };
  1864. }
  1865. window.requestAnimationFrame(gui);
  1866. }
  1867. gui();
  1868. setTimeout(() => {
  1869. gui();
  1870. }, 5000);
  1871. }, 1000);
  1872.  
  1873. //game ticks finder
  1874. let clearRect_count = 0;
  1875. let fps;
  1876. CanvasRenderingContext2D.prototype.fillText = new Proxy(CanvasRenderingContext2D.prototype.fillText, {
  1877. apply(fillRect, ctx, [text, x, y, ...blah]) {
  1878. if (text.endsWith('FPS')) {
  1879. fps = text.split(' ')[0];
  1880. }
  1881. fillRect.call(ctx, text, x, y, ...blah);
  1882. }
  1883. });
  1884.  
  1885. // Tick tracking
  1886. let currentTick = 0;
  1887. const tickQueue = [];
  1888. const everyTickFunctions = [];
  1889.  
  1890. function runEveryTick(callback) {
  1891. everyTickFunctions.push(callback);
  1892. }
  1893.  
  1894. CanvasRenderingContext2D.prototype.clearRect = new Proxy(CanvasRenderingContext2D.prototype.clearRect, {
  1895. apply(target, thisArg, argumentsList) {
  1896. clearRect_count += 1;
  1897. currentTick = Math.floor(clearRect_count / 6);
  1898. processTickQueue();
  1899. everyTickFunctions.forEach(func => func(currentTick));
  1900. return target.apply(thisArg, argumentsList);
  1901. }
  1902. });
  1903.  
  1904. function scheduleAfterTicks(callback, ticksToWait) {
  1905. const executionTick = currentTick + ticksToWait;
  1906. tickQueue.push({
  1907. callback,
  1908. executionTick
  1909. });
  1910. }
  1911.  
  1912. function processTickQueue() {
  1913. while (tickQueue.length > 0 && tickQueue[0].executionTick <= currentTick) {
  1914. const item = tickQueue.shift();
  1915. item.callback();
  1916. }
  1917. }
  1918.  
  1919. // Function to run code for a specified number of ticks
  1920. function runForTicks(callback, totalTicks) {
  1921. const startingTick = currentTick;
  1922. let ticksPassed = 0;
  1923.  
  1924. function tickHandler() {
  1925. if (ticksPassed < totalTicks) {
  1926. callback(ticksPassed, currentTick);
  1927. ticksPassed++;
  1928. scheduleAfterTicks(tickHandler, 1);
  1929. }
  1930. }
  1931.  
  1932. tickHandler(); // Start the process
  1933. }
  1934.  
  1935. // Example usage:
  1936. function test() {
  1937. console.log("Starting test at tick:", currentTick);
  1938.  
  1939. scheduleAfterTicks(() => {
  1940. console.log("150 ticks have passed, current tick:", currentTick);
  1941. // Add your code here
  1942. }, 150);
  1943. }
  1944.  
  1945. function testLoop() {
  1946. console.log("Starting testLoop at tick:", currentTick);
  1947. runForTicks((ticksPassed, currentTick) => {
  1948. console.log(`Tick passed: ${ticksPassed}, Current tick: ${currentTick}`);
  1949. // Add any other code you want to run each tick
  1950. }, 50);
  1951. }
  1952.  
  1953. //cooldowns (unfinished)
  1954. let c_cd = "red";
  1955. let c_r = "green";
  1956. const cooldowns = [
  1957. {
  1958. Tank: "Destroyer",
  1959. cooldown0: 109,
  1960. cooldown1: 94,
  1961. cooldown2: 81,
  1962. cooldown3: 86
  1963. },
  1964. ]
  1965.  
  1966. //detect which slot was clicked
  1967. document.addEventListener('mousedown', checkPos)
  1968.  
  1969. function checkPos(e) {
  1970. console.log(currentTick);
  1971. console.log(boxes[selected_box]);
  1972. }
  1973.  
  1974.  
  1975. //warns you about annis, destroyers
  1976. /*
  1977. function drawTheThing(x,y,r) {
  1978. if(script_boolean){
  1979. let a = ctx.fillStyle;
  1980. ctx.fillStyle = "#FF000044";
  1981. ctx.beginPath();
  1982. ctx.arc(x,y,4*r,0,2*Math.PI);
  1983. ctx.fill();
  1984. ctx.fillStyle = "#FF000066";
  1985. ctx.beginPath();
  1986. ctx.arc(x,y,2*r,0,2*Math.PI);
  1987. ctx.fill();
  1988. ctx.beginPath();
  1989. }
  1990. }
  1991. var angle,a,b,width;
  1992. CanvasRenderingContext2D.prototype.setTransform = new Proxy(CanvasRenderingContext2D.prototype.setTransform, {
  1993. apply(target, thisArgs, args) {
  1994. //console.log(thisArgs)
  1995. if (Math.abs(args[0]/args[3]).toFixed(3) == (95/71.4).toFixed(3) || Math.abs(args[0]/args[3]).toFixed(3) == (95/96.6).toFixed(3)) {
  1996. angle = Math.atan2(args[2],args[3]) || 0;
  1997. width = Math.hypot(args[3], args[2]);
  1998. a = args[4]-Math.cos(angle+Math.PI/2)*width/2;
  1999. b = args[5]+Math.sin(angle+Math.PI/2)*width/2;
  2000. drawTheThing(a,b, Math.hypot(args[3],args[2]));
  2001. }
  2002. return Reflect.apply(target, thisArgs, args);
  2003. }
  2004. });
  2005. */
  2006.  
  2007. //physics for movement (UNFINISHED)
  2008. /*
  2009. //movement speed ingame stat
  2010. let m_s = [0, 1, 2, 3, 4, 5, 6, 7];
  2011.  
  2012. function accelarate(A_o){
  2013. //Accelaration
  2014. let sum = 0;
  2015. runForTicks((ticksPassed, currentTick) => {
  2016. console.log("sum is being calculated...");
  2017. sum += A_o * Math.pow(0.9, ticksPassed - 1);
  2018. offsetX = Math.floor(sum * scalingFactor);
  2019. console.log(offsetX);
  2020. }, 50);
  2021. //decelerate(sum);
  2022. }
  2023.  
  2024. function decelerate(sum){
  2025. //deceleration
  2026. let res = 0;
  2027. runForTicks((ticksPassed, currentTick) => {
  2028. console.log("res is being calculated...");
  2029. res = sum * Math.pow(0.9, ticksPassed);
  2030. offsetX = Math.floor(res * scalingFactor);
  2031. console.log(offsetX);
  2032. }, 50);
  2033. }
  2034. function calculate_speed(movement_speed_stat){
  2035. console.log("calculate_speed function called");
  2036. //use Accelaration for first 50 ticks, then deceleration until ticks hit 100, then stop moving
  2037.  
  2038. //calculating base value, we'll need this later
  2039. let a = (1.07**movement_speed_stat);
  2040. let b = (1.015**(currentLevel - 1));
  2041. let A_o = 2.55*(a/b);
  2042. accelarate(A_o);
  2043. }
  2044. */
  2045.  
  2046. //handle Key presses
  2047. let key_storage = [];
  2048.  
  2049. document.onkeydown = function(e) {
  2050. if (!key_storage.includes(e.key)) {
  2051. key_storage.push(e.key);
  2052. }
  2053. console.log(key_storage);
  2054. analyse_keys();
  2055. }
  2056.  
  2057. document.onkeyup = function(e) {
  2058. if (key_storage.includes(e.key)) {
  2059. key_storage.splice(key_storage.indexOf(e.key), 1);
  2060. }
  2061. console.log(key_storage);
  2062. analyse_keys();
  2063. }
  2064.  
  2065. function analyse_keys() {
  2066. if (key_storage.includes("j")) { //J
  2067. change_visibility();
  2068. } else if (key_storage.includes("e")) { //E
  2069. if (ingamescreen.classList.contains("screen") && ingamescreen.classList.contains("active")) {
  2070. f_s("fire");
  2071. } else {
  2072. auto_fire = false;
  2073. }
  2074. console.log(auto_fire);
  2075. } else if (key_storage.includes("c")) {
  2076. console.log(auto_spin);
  2077. if (ingamescreen.classList.contains("screen") && ingamescreen.classList.contains("active")) {
  2078. f_s("spin");
  2079. } else {
  2080. auto_spin = false;
  2081. }
  2082. console.log(auto_spin);
  2083. }
  2084. }
  2085. // Handle key presses for moving the center (UNFINISHED)
  2086.  
  2087. /*
  2088. function return_to_center(XorY, posOrNeg){
  2089. console.log("function called with: " + XorY + posOrNeg);
  2090. if(XorY === "x"){
  2091. if(posOrNeg === "pos"){
  2092. while(offsetX < 0){
  2093. offsetX += 0.5*scalingFactor;
  2094. }
  2095. }else if(posOrNeg === "neg"){
  2096. while(offsetX > 0){
  2097. offsetX -= 0.5*scalingFactor;
  2098. }
  2099. }else{
  2100. console.log("invalid posOrNeg at return_to_center();")
  2101. }
  2102. }else if(XorY === "y"){
  2103. if(posOrNeg === "pos"){
  2104. while(offsetY < 0){
  2105. offsetY += 0.5*scalingFactor;
  2106. }
  2107. }else if(posOrNeg === "neg"){
  2108. while(offsetY > 0){
  2109. offsetY -= 0.5*scalingFactor;
  2110. }
  2111. }else{
  2112. console.log("invalid posOrNeg at return_to_center();")
  2113. }
  2114. }else{
  2115. console.log("invalid XorY at return_to_center();");
  2116. }
  2117. }
  2118.  
  2119. document.onkeydown = function(e) {
  2120. switch (e.keyCode) {
  2121. case 87: // 'W' key
  2122. console.log("W");
  2123. if(offsetY >= -87.5*scalingFactor){
  2124. offsetY -= 12.5*scalingFactor;
  2125. }
  2126. break
  2127. case 83: // 'S' key
  2128. console.log("S");
  2129. if(offsetY <= 87.5*scalingFactor){
  2130. offsetY += 12.5*scalingFactor;
  2131. }
  2132. break;
  2133. case 68: // 'D' key
  2134. console.log("D");
  2135. if(offsetX <= 87.5*scalingFactor){
  2136. offsetX += 12.5*scalingFactor;
  2137. }
  2138. break
  2139. case 65: // 'A' key
  2140. console.log("A");
  2141. if(offsetX >= -87.5*scalingFactor){
  2142. offsetX -= 12.5*scalingFactor;
  2143. }
  2144. break
  2145. }
  2146. }
  2147.  
  2148. document.onkeyup = function(e) {
  2149. switch (e.keyCode) {
  2150. case 87: // 'W' key
  2151. console.log("W unpressed");
  2152. return_to_center("y", "pos");
  2153. break
  2154. case 83: // 'S' key
  2155. console.log("S unpressed");
  2156. return_to_center("y", "neg");
  2157. break;
  2158. case 68: // 'D' key
  2159. console.log("D unpressed");
  2160. return_to_center("x", "neg");
  2161. break
  2162. case 65:
  2163. console.log("A unpressed");
  2164. return_to_center("x", "pos");
  2165. }
  2166. }
  2167. */