code for diep.io

script

  1. // ==UserScript==
  2. // @name code for diep.io
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1.3.7
  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: "GunnerTrapper2",cycleRate: 0.001, maxAngle: Math.PI, NCANNON: 2},
  59. {name: "Octo", cycleRate: 0.003095, maxAngle: Math.PI * 45 / 180, NCANNON: 2},
  60. {name: "Streamliner", cycleRate: 0.0625, maxAngle: Math.PI * 15 / 180, NCANNON: 3},
  61. {name: "triplet", cycleRate: 0.0625, maxAngle: Math.PI * 15 / 180, NCANNON: 3},
  62. ];
  63. var tankIndex = 0;
  64.  
  65. var measuring = false;
  66.  
  67. var effective = false;
  68. var frameRequest;
  69.  
  70. var canvas = window.document.getElementById("canvas");
  71.  
  72. var mouseX;
  73. var mouseY;
  74. var a = 0;
  75. var startA = 0;
  76. var artificialMouseMove = false;
  77.  
  78. var disabled = false;
  79.  
  80. function onMouseDown(e){
  81. if(e.button == 2){
  82. if(!effective){
  83. startA = a - 50;
  84. mouseX = e.clientX;
  85. mouseY = e.clientY;
  86. canvas.dispatchEvent(new MouseEvent("mousedown", {clientX: mouseX, clientY: mouseY}));
  87. }
  88. effective = true;
  89. }
  90. }
  91.  
  92. function onMouseUp(e){
  93. if(e.button == 2){
  94. if(effective){
  95. canvas.dispatchEvent(new MouseEvent("mouseup", {clientX: mouseX, clientY: mouseY}));
  96. }
  97. effective = false;
  98. }
  99. }
  100.  
  101. function onMouseMove(e){
  102. if(effective){
  103. if(!artificialMouseMove){
  104. e.stopPropagation();
  105. mouseX = e.clientX;
  106. mouseY = e.clientY;
  107. }
  108. }else{
  109. mouseX = e.clientX;
  110. mouseY = e.clientY;
  111. }
  112. }
  113.  
  114. function update(_a){
  115. frameRequest = window.requestAnimationFrame(update);
  116. a = _a;
  117.  
  118. if(effective){
  119. var da = a - startA;
  120. var state = Math.floor(cycleRate * da * NCANNON) % (NCANNON * 2);
  121. var state1 = state % NCANNON;
  122. var state2 = Math.floor(state / NCANNON);
  123. var angle = angleUnit * state1 * (state1 % 2 == state2 ? 1 : -1);
  124.  
  125. var cx = window.innerWidth / 2;
  126. var cy = window.innerHeight / 2;
  127. var sin = Math.sin(angle);
  128. var cos = Math.cos(angle);
  129.  
  130. var x = mouseX - cx;
  131. var y = mouseY - cy;
  132. var _x = cos * x - sin * y;
  133. var _y = sin * x + cos * y;
  134. x = _x + cx;
  135. y = _y + cy;
  136.  
  137. artificialMouseMove = true;
  138. canvas.dispatchEvent(new MouseEvent("mousemove", {clientX: x, clientY: y}));
  139. artificialMouseMove = false;
  140. }
  141. }
  142.  
  143. function onKeyUp(e){
  144. if(e.key == "Q"){
  145. disabled = !disabled;
  146. if(disabled){
  147. if(measuring){
  148. cycleRate = 1 / measure.terminate();
  149. measuring = false;
  150. } else stop();
  151. }else start();
  152. window.updateInfo && window.updateInfo("off", disabled ? "Disabled." : null);
  153. return;
  154. }
  155.  
  156. if(disabled) return;
  157.  
  158. if(e.key == "R"){
  159. changeTank((tankIndex + 1) % tankData.length);
  160. }
  161. }
  162.  
  163. function changeTank(index){
  164. var data = tankData[index];
  165. tankIndex = index;
  166.  
  167. cycleRate = data.cycleRate; // ms^-1
  168. maxAngle = data.maxAngle;
  169. NCANNON = data.NCANNON;
  170. angleUnit = maxAngle / (NCANNON - 1);
  171. window.updateInfo && window.updateInfo("changeTank", "Tank: " + data.name);
  172. }
  173.  
  174. function init(){
  175. window.addEventListener("keyup", onKeyUp);
  176. start();
  177. changeTank(0);
  178. }
  179.  
  180. function start(){
  181. canvas.addEventListener("mousedown", onMouseDown);
  182. canvas.addEventListener("mouseup", onMouseUp);
  183. window.addEventListener("mousemove", onMouseMove, true);
  184. frameRequest = window.requestAnimationFrame(update);
  185. }
  186.  
  187. function stop(){
  188. canvas.removeEventListener("mousedown", onMouseDown);
  189. canvas.removeEventListener("mouseup", onMouseUp);
  190. window.removeEventListener("mousemove", onMouseMove, true);
  191. window.cancelAnimationFrame(frameRequest);
  192. effective = false;
  193. }
  194.  
  195.  
  196. init();
  197.  
  198. })();
  199.  
  200.