code for diep.io

script

As of 2021-12-12. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

  1. // ==UserScript==
  2. // @name code for diep.io
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1.2
  5. // @description script
  6. // @author delta-1
  7. // @match https://diep.io/
  8. // @license MIT
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12.  
  13.  
  14.  
  15.  
  16. (function(){//info
  17. if(window.updateInfo) return;
  18.  
  19.  
  20. var info = {};
  21. var info_container = document.createElement("div");
  22. info_container.style.position = "fixed";
  23. info_container.style.color = "#29FCCC";
  24. info_container.style["pointer-events"] = "none";
  25. document.body.appendChild(info_container);
  26.  
  27. function toggle_info_container(e){
  28. if(e.key == "i"){
  29. info_container.style.display = info_container.style.display=="block" ? "none" : "block";
  30. }
  31. }
  32. window.addEventListener("keyup", toggle_info_container);
  33.  
  34. window.updateInfo = function(key, value){
  35. if(!value) delete info[key];
  36. else info[key] = value;
  37. var s = "";
  38. for(var _key in info){
  39. s += info[_key] + "\n";
  40. }
  41. info_container.innerText = s;
  42. };
  43. })();
  44.  
  45.  
  46. (function(){
  47. var cycleRate = 0.003125; // ms^-1
  48. var maxAngle = Math.PI * 45 / 180;
  49. var NCANNON = 3;
  50. var angleUnit = maxAngle / (NCANNON - 1);
  51.  
  52. var tankData = [
  53. {name: "Tri-angle1", cycleRate: 0.003095, maxAngle: Math.PI * 135 / 180, NCANNON: 2},
  54. {name: "Tri-angle2",cycleRate: 0.003095, maxAngle: Math.PI, NCANNON: 2},
  55. {name: "TripleTwin", cycleRate: 0.003125, maxAngle: Math.PI * 180 / 180, NCANNON: 2},
  56. {name: "fighter?", cycleRate: 0.003095, maxAngle: Math.PI * 90 / 180, NCANNON: 2},
  57. {name: "GunnerTrapper",cycleRate: 0.015, maxAngle: Math.PI, NCANNON: 2},
  58. {name: "Octo", cycleRate: 0.003095, maxAngle: Math.PI * 45 / 180, NCANNON: 2},
  59. {name: "Streamliner", cycleRate: 0.0625, maxAngle: Math.PI * 15 / 180, NCANNON: 3},
  60. ];
  61. var tankIndex = 0;
  62.  
  63. var measuring = false;
  64.  
  65. var effective = false;
  66. var frameRequest;
  67.  
  68. var canvas = window.document.getElementById("canvas");
  69.  
  70. var mouseX;
  71. var mouseY;
  72. var a = 0;
  73. var startA = 0;
  74. var artificialMouseMove = false;
  75.  
  76. var disabled = false;
  77.  
  78. function onMouseDown(e){
  79. if(e.button == 2){
  80. if(!effective){
  81. startA = a - 50;
  82. mouseX = e.clientX;
  83. mouseY = e.clientY;
  84. canvas.dispatchEvent(new MouseEvent("mousedown", {clientX: mouseX, clientY: mouseY}));
  85. }
  86. effective = true;
  87. }
  88. }
  89.  
  90. function onMouseUp(e){
  91. if(e.button == 2){
  92. if(effective){
  93. canvas.dispatchEvent(new MouseEvent("mouseup", {clientX: mouseX, clientY: mouseY}));
  94. }
  95. effective = false;
  96. }
  97. }
  98.  
  99. function onMouseMove(e){
  100. if(effective){
  101. if(!artificialMouseMove){
  102. e.stopPropagation();
  103. mouseX = e.clientX;
  104. mouseY = e.clientY;
  105. }
  106. }else{
  107. mouseX = e.clientX;
  108. mouseY = e.clientY;
  109. }
  110. }
  111.  
  112. function update(_a){
  113. frameRequest = window.requestAnimationFrame(update);
  114. a = _a;
  115.  
  116. if(effective){
  117. var da = a - startA;
  118. var state = Math.floor(cycleRate * da * NCANNON) % (NCANNON * 2);
  119. var state1 = state % NCANNON;
  120. var state2 = Math.floor(state / NCANNON);
  121. var angle = angleUnit * state1 * (state1 % 2 == state2 ? 1 : -1);
  122.  
  123. var cx = window.innerWidth / 2;
  124. var cy = window.innerHeight / 2;
  125. var sin = Math.sin(angle);
  126. var cos = Math.cos(angle);
  127.  
  128. var x = mouseX - cx;
  129. var y = mouseY - cy;
  130. var _x = cos * x - sin * y;
  131. var _y = sin * x + cos * y;
  132. x = _x + cx;
  133. y = _y + cy;
  134.  
  135. artificialMouseMove = true;
  136. canvas.dispatchEvent(new MouseEvent("mousemove", {clientX: x, clientY: y}));
  137. artificialMouseMove = false;
  138. }
  139. }
  140.  
  141. function onKeyUp(e){
  142. if(e.key == "Q"){
  143. disabled = !disabled;
  144. if(disabled){
  145. if(measuring){
  146. cycleRate = 1 / measure.terminate();
  147. measuring = false;
  148. } else stop();
  149. }else start();
  150. window.updateInfo && window.updateInfo("off", disabled ? "Disabled." : null);
  151. return;
  152. }
  153.  
  154. if(disabled) return;
  155.  
  156. if(e.key == "R"){
  157. changeTank((tankIndex + 1) % tankData.length);
  158. }
  159. }
  160.  
  161. function changeTank(index){
  162. var data = tankData[index];
  163. tankIndex = index;
  164.  
  165. cycleRate = data.cycleRate; // ms^-1
  166. maxAngle = data.maxAngle;
  167. NCANNON = data.NCANNON;
  168. angleUnit = maxAngle / (NCANNON - 1);
  169. window.updateInfo && window.updateInfo("changeTank", "Tank: " + data.name);
  170. }
  171.  
  172. function init(){
  173. window.addEventListener("keyup", onKeyUp);
  174. start();
  175. changeTank(0);
  176. }
  177.  
  178. function start(){
  179. canvas.addEventListener("mousedown", onMouseDown);
  180. canvas.addEventListener("mouseup", onMouseUp);
  181. window.addEventListener("mousemove", onMouseMove, true);
  182. frameRequest = window.requestAnimationFrame(update);
  183. }
  184.  
  185. function stop(){
  186. canvas.removeEventListener("mousedown", onMouseDown);
  187. canvas.removeEventListener("mouseup", onMouseUp);
  188. window.removeEventListener("mousemove", onMouseMove, true);
  189. window.cancelAnimationFrame(frameRequest);
  190. effective = false;
  191. }
  192.  
  193.  
  194. init();
  195.  
  196. })();
  197.  
  198.