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