Diep.io+ (added Level seeker)

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-06 提交的版本,查看 最新版本

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