Advertisement
MekhiMaraghYT

Improved Bullet stacking diep.io!

Aug 11th, 2020 (edited)
7,493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.18 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Improved Bullet Stacking By Mekhi Maragh
  3. // @include *://diep.io/*
  4. // @author Mekhi MAragh
  5. // @description Makes some tanks more powerful (Tri-angle branch, spread shot, penta shot, octo tank, gunner trapper, streamliner).
  6. // @connect diep.io
  7. // @namespace aaa
  8. // @version 69
  9. // ==/UserScript==
  10.  
  11. /*
  12. How to Use:
  13. Press Shift+R to cycle through the tanks.
  14. Press Shift+Q to disable/enable the script.
  15. Press I to hide the dialog. (The script remains functional, though).
  16. Hold rightclick to activate . For best results, leave autofire off for a bit before doing so.
  17. If necessary, press Shift+M to re-calibrate the script. Wait for the ms to stabilise.
  18. Note: This calibration may break for Triple Twin, and is unnecessary for Streamliner.
  19. */
  20. (function(){//info
  21. if(window.updateInfo) return;
  22.  
  23.  
  24. var info = {};
  25. var info_container = document.createElement("div");
  26. info_container.style.position = "fixed";
  27. info_container.style.color = "blue";
  28. info_container.style["pointer-events"] = "none";
  29. document.body.appendChild(info_container);
  30.  
  31. function toggle_info_container(e){
  32. if(e.key == "i"){
  33. info_container.style.display = info_container.style.display=="block" ? "none" : "block";
  34. }
  35. }
  36. window.addEventListener("keyup", toggle_info_container);
  37.  
  38. window.updateInfo = function(key, value){
  39. if(!value) delete info[key];
  40. else info[key] = value;
  41. var s = "";
  42. for(var _key in info){
  43. s += info[_key] + "\n";
  44. }
  45. info_container.innerText = s;
  46. };
  47. })();
  48.  
  49. function MeasureCycle(){
  50. var canvas = document.getElementById("canvas");
  51. var ctx = canvas.getContext("2d");
  52. var real_arc = ctx.arc;
  53. var real_setTransform = ctx.setTransform;
  54.  
  55. var a;
  56. var tx = 0, ty = 0;
  57. var a11 = 1;
  58.  
  59. var state = false;
  60. var found = false;
  61. var inA = null;
  62. var direction = 1;
  63.  
  64. var frameRequest;
  65. var intervalEMA = null; // ms
  66.  
  67. function arc(){
  68. real_arc.apply(ctx, arguments);
  69.  
  70. if(!found){
  71. var aimX = window.innerWidth / 2 + 50 * direction;
  72. var aimY = window.innerHeight / 2;
  73. found = (tx - a11 < aimX) && (tx + a11 > aimX) && (ty - a11 < aimY) && (ty + a11 > aimY);
  74. }
  75. }
  76.  
  77. function setTransform(b11, b12, b21, b22, bx, by){
  78. real_setTransform.apply(ctx, arguments);
  79. tx = bx, ty = by, a11 = b11;
  80. }
  81.  
  82. function onFrame(_a){
  83. frameRequest = window.requestAnimationFrame(onFrame);
  84. a = _a;
  85. if(!state && found){
  86. if(inA){
  87. var da = a - inA;
  88. inA = a;
  89. intervalEMA = intervalEMA ? 0.8 * intervalEMA + 0.2 * da : da;
  90. window.updateInfo && window.updateInfo(
  91. "intervalEMA",
  92. "Fire Period: " + intervalEMA.toString().substr(0, 5) + "ms"
  93. );
  94.  
  95. }else{
  96. inA = a;
  97. }
  98. }
  99. state = found;
  100. found = false;
  101. }
  102.  
  103. function onMouseEvent(e){
  104. e.stopPropagation();
  105. }
  106.  
  107. this.start = function(_direction){
  108. _direction = _direction || 1;
  109. direction = _direction > 0 ? 1 : -1;
  110. inA = null;
  111. intervalEMA = null;
  112. state = found = false;
  113.  
  114. ctx.setTransform = setTransform;
  115. ctx.arc = arc;
  116.  
  117. var aimX = window.innerWidth / 2 + 50 * direction;
  118. var aimY = window.innerHeight / 2;
  119. canvas.dispatchEvent(new MouseEvent("mousemove", {clientX: aimX, clientY: aimY}));
  120. canvas.dispatchEvent(new MouseEvent("mousedown", {clientX: aimX, clientY: aimY}));
  121.  
  122. window.addEventListener("mousemove", onMouseEvent, true);
  123. window.addEventListener("mouseup", onMouseEvent, true);
  124. window.addEventListener("mousedown", onMouseEvent, true);
  125. frameRequest = window.requestAnimationFrame(onFrame);
  126.  
  127. window.updateInfo && window.updateInfo("measuring", "Measuring...");
  128. }
  129.  
  130. this.terminate = function(){
  131. ctx.setTransform = real_setTransform;
  132. ctx.arc = real_arc;
  133.  
  134. window.removeEventListener("mousemove", onMouseEvent, true);
  135. window.removeEventListener("mousedown", onMouseEvent, true);
  136. window.removeEventListener("mouseup", onMouseEvent, true);
  137. window.cancelAnimationFrame(frameRequest);
  138.  
  139. canvas.dispatchEvent(new MouseEvent("mouseup", {clientX: 10, clientY: 10}));
  140.  
  141. window.updateInfo && window.updateInfo("measuring", null);
  142. return intervalEMA;
  143. }
  144. };
  145.  
  146. (function(){
  147. var cycleRate = 0.003125; // ms^-1
  148. var maxAngle = Math.PI * 45 / 180;
  149. var secAngle = 0;
  150. var cycleCounter = 1;
  151. var NCANNON = 3;
  152. var angleUnit = maxAngle / (NCANNON - 1);
  153. var secUnit = secAngle;
  154. var ax30945=1;
  155. var sec=false;
  156. var tankData = [
  157. {name: "Tri-angle Stack", cycleRate: 0.003125, maxAngle: Math.PI * 150 / 180, secondaryAngle: Math.PI * 150 / 180, NCANNON: 2},
  158. {name: "Fighter Stack", cycleRate: 0.003135, maxAngle: Math.PI * 90 / 175, secondaryAngle: Math.PI/2, NCANNON: 2},
  159. {name: "bycycle's retarded script", cycleRate: 0.003125, maxAngle: Math.PI, secondaryAngle: Math.PI, NCANNON: 2},
  160. {name: "Penta Stack broken", cycleRate: 0.003125, maxAngle: Math.PI/4, secondaryAngle: Math.PI/4, NCANNON: 3},
  161. {name: "Spread Stack boken", cycleRate: 0.001555, maxAngle: Math.PI * 75 / 180, secondaryAngle: Math.PI * 75 / 180, NCANNON: 6},
  162. {name: "Octo Stack", cycleRate: 0.003125, maxAngle: Math.PI/4, secondaryAngle: Math.PI/4, NCANNON: 2},
  163. {name: "GunnerTrapper",cycleRate: 0.0125, maxAngle: Math.PI, secondaryAngle: Math.PI, NCANNON: 2},
  164. {name: "Streamliner Spread", cycleRate: 0.0625, maxAngle: Math.PI * 15 / 180, secondaryAngle: Math.PI * 15 / 180, NCANNON: 3},
  165. {name: "random spinny flick shit idk", cycleRate: 0.001, maxAngle: 0, secondaryAngle: 0, NCANNON: 2},
  166. ];
  167. var tankIndex = 0;
  168.  
  169. var measure = new MeasureCycle();
  170. var measuring = false;
  171.  
  172. var effective = false;
  173. var frameRequest;
  174. var toggle1 = true;
  175. var toggle2 = false;
  176. var canvas = window.document.getElementById("canvas");
  177.  
  178. var mouseX;
  179. var mouseY;
  180. var a = 0;
  181. var startA = 0;
  182. var artificialMouseMove = false;
  183.  
  184. var disabled = false;
  185. function onMouseDown(e){
  186. if(e.button == 2){
  187. sec=false;
  188. if(!effective){
  189. startA = a - 25;
  190. mouseX = e.clientX;
  191. mouseY = e.clientY;
  192. canvas.dispatchEvent(new MouseEvent("mousedown", {clientX: mouseX, clientY: mouseY}));
  193. }
  194. effective = true;
  195. cycleCounter=0;
  196. }
  197. }
  198.  
  199. function onMouseUp(e){
  200. if(e.button == 2){
  201. if(effective){
  202. canvas.dispatchEvent(new MouseEvent("mouseup", {clientX: mouseX, clientY: mouseY}));
  203. }
  204. effective = false;
  205. }
  206. }
  207.  
  208. function onMouseMove(e){
  209. if(effective){
  210. if(!artificialMouseMove){
  211. e.stopPropagation();
  212. mouseX = e.clientX;
  213. mouseY = e.clientY;
  214. }
  215. }else{
  216. mouseX = e.clientX;
  217. mouseY = e.clientY;
  218. }
  219. }
  220.  
  221. function update(_a){
  222. frameRequest = window.requestAnimationFrame(update);
  223. a = _a;
  224.  
  225. if(effective){
  226. var da = a - startA;
  227. var state = Math.floor(cycleRate * da * NCANNON) % (NCANNON * 2);
  228. var state1 = state % NCANNON;
  229. var state2 = Math.floor(state / NCANNON);
  230. var remainder=cycleRate*da*NCANNON-Math.floor(cycleRate*da*NCANNON);
  231. var angle = angleUnit * state1 * ax30945;
  232. var angle2 = secUnit * state1 * ax30945;
  233. var cx = window.innerWidth / 2;
  234. var cy = window.innerHeight / 2;
  235. window.updateInfo && window.updateInfo("reeeee", remainder);
  236.  
  237. if (toggle2 && state1==0) {
  238. toggle2=false;
  239. cycleCounter++;
  240. }
  241. if (state1!=0) toggle2=true;
  242. if (cycleCounter%3==2) angle=angle2;
  243. //if (remainder>0.5) angle=0;
  244. //if (cycleCounter%2==1) angle=-angle;
  245. var sin = Math.sin(angle);
  246. var cos = Math.cos(angle);
  247.  
  248. var x = mouseX - cx;
  249. var y = mouseY - cy;
  250. var _x = cos * x - sin * y;
  251. var _y = sin * x + cos * y;
  252. x = _x + cx;
  253. y = _y + cy;
  254.  
  255. artificialMouseMove = true;
  256. canvas.dispatchEvent(new MouseEvent("mousemove", {clientX: x, clientY: y}));
  257. artificialMouseMove = false;
  258. } else {
  259. var data = tankData[tankIndex];
  260. if (data.name=="random spinny flick shit idk") {
  261. da = a - startA;
  262. state = Math.floor(0.01 * da * 4) % (4 * 2);
  263. state1 = state % 4;
  264. state2 = Math.floor(state / 4);
  265. angle = Math.PI/3 * state1;
  266.  
  267. cx = window.innerWidth / 2;
  268. cy = window.innerHeight / 2;
  269. sin = Math.sin(angle);
  270. cos = Math.cos(angle);
  271.  
  272. x = mouseX - cx;
  273. y = mouseY - cy;
  274. _x = cos * x - sin * y;
  275. _y = sin * x + cos * y;
  276. x = _x + cx;
  277. y = _y + cy;
  278.  
  279. artificialMouseMove = true;
  280. canvas.dispatchEvent(new MouseEvent("mousemove", {clientX: x, clientY: y}));
  281. artificialMouseMove = false;
  282. }
  283. }
  284. }
  285.  
  286. function onKeyUp(e){
  287. if(e.key == "Z") {
  288. ax30945=1;
  289. }
  290. if(e.key == "Q"){
  291. disabled = !disabled;
  292. if(disabled){
  293. if(measuring){
  294. cycleRate = 1 / measure.terminate();
  295. measuring = false;
  296. } else stop();
  297. }else start();
  298. window.updateInfo && window.updateInfo("off", disabled ? "Disabled." : null);
  299. return;
  300. }
  301.  
  302. if(disabled) return;
  303.  
  304. if(e.key == "N"){
  305. if(measuring){
  306. cycleRate = 1 / measure.terminate();
  307. start();
  308. measuring = false;
  309. }else{
  310. stop();
  311. measure.start(mouseX - window.innerWidth / 2);
  312. measuring = true;
  313. }
  314. }else if(e.key == "R"){
  315. changeTank((tankIndex + 1) % tankData.length);
  316. }
  317. }
  318.  
  319. function changeTank(index){
  320. var data = tankData[index];
  321. tankIndex = index;
  322.  
  323. cycleRate = data.cycleRate; // ms^-1
  324. maxAngle = data.maxAngle;
  325. secAngle = data.secondaryAngle;
  326. NCANNON = data.NCANNON;
  327. angleUnit = maxAngle / (NCANNON - 1);
  328. secUnit = secAngle / (NCANNON - 1);
  329.  
  330. window.updateInfo && window.updateInfo("changeTank", "Tank: " + data.name);
  331. }
  332.  
  333. function init(){
  334. window.addEventListener("keyup", onKeyUp);
  335. start();
  336. changeTank(0);
  337. }
  338.  
  339. function start(){
  340. canvas.addEventListener("mousedown", onMouseDown);
  341. canvas.addEventListener("mouseup", onMouseUp);
  342. window.addEventListener("mousemove", onMouseMove, true);
  343. frameRequest = window.requestAnimationFrame(update);
  344. }
  345.  
  346. function stop(){
  347. canvas.removeEventListener("mousedown", onMouseDown);
  348. canvas.removeEventListener("mouseup", onMouseUp);
  349. window.removeEventListener("mousemove", onMouseMove, true);
  350. window.cancelAnimationFrame(frameRequest);
  351. effective = false;
  352. }
  353.  
  354.  
  355. init();
  356.  
  357. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement