Multibox script Working December 2023

multibox

当前为 2023-12-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Multibox script Working December 2023
  3. // @namespace http://tampermonkey.net/
  4. // @version 2023
  5. // @description multibox
  6. // @author Mi300#4401
  7. // @match https://diep.io/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @license dont copy thx
  12. // ==/UserScript==
  13.  
  14.  
  15. let WTF = setInterval (function() {
  16. if (!document.querySelector('d-base').shadowRoot.children[0].shadowRoot.getElementById('username-input')) {
  17. return;
  18. }
  19. clearInterval (WTF)
  20.  
  21. let canRespawn = false;
  22. let worldPosition = [0, 0];
  23. let overlay;
  24. let mouseOffset = [0, 0];
  25. let gui = true;
  26. let moveKeys = new Array(4)
  27. let tabId = Math.round(Math.random()*10000)
  28. GM_setValue('multiboxEnabled', false)
  29.  
  30. setInterval(function(){
  31. document.title = 'diep.io tab #' + tabId
  32. }, 1000)
  33.  
  34. const canvas = document.getElementById ('canvas');
  35.  
  36. function hook(target, callback){
  37.  
  38. const check = () => {
  39. window.requestAnimationFrame(check)
  40. const func = CanvasRenderingContext2D.prototype[target]
  41.  
  42. if(func.toString().includes(target)){
  43.  
  44. CanvasRenderingContext2D.prototype[target] = new Proxy (func, {
  45. apply (method, thisArg, args) {
  46. callback(method, thisArg, args)
  47.  
  48. return Reflect.apply (method, thisArg, args)
  49. }
  50. });
  51. }
  52. }
  53. check()
  54. }
  55. let dgg = 'i';
  56.  
  57. function hookMinimapArrow () {
  58.  
  59. let drawInstructions = 0;
  60. let minimapArrowVertex = [];
  61. hook ('beginPath', (method, thisArg, args) => {
  62. //console.log('beginPath', args)
  63. drawInstructions = 1;
  64. minimapArrowVertex = [];
  65. });
  66. hook ('moveTo', (method, thisArg, args) => {
  67. //console.log('moveTo', args)
  68. drawInstructions = 2;
  69. minimapArrowVertex.push ( args );
  70. });
  71. hook ('lineTo', (method, thisArg, args) => {
  72. //console.log('lineTo', args)
  73. if (drawInstructions >= 2 && drawInstructions <= 5) {
  74. drawInstructions ++;
  75. minimapArrowVertex.push ( args );
  76.  
  77. } else {
  78. drawInstructions = 0;
  79. }
  80. });
  81. hook ('fill', (method, thisArg, args) => {
  82. //console.log('fill', args)
  83. if (thisArg.fillStyle != '#000000' || thisArg.globalAlpha < 1) {
  84. return;
  85. }
  86. if (drawInstructions === 4) {
  87. const pos = getAverage (minimapArrowVertex);
  88. //console.log(pos)
  89. worldPosition = getWorldPosition (pos);
  90. }
  91. });
  92. }
  93. let minimapPosition = [0, 0];
  94. let minimapDim = [0, 0];
  95.  
  96. function hookMinimap () {
  97. hook ('strokeRect', (method, thisArg, args) => {
  98. const transform = thisArg.getTransform ();
  99. minimapPosition = [transform.e, transform.f];
  100. minimapDim = [transform.a, transform.d];
  101. });
  102. }
  103.  
  104. function getWorldPosition (position) {
  105. const ret = [
  106. parseFloat((((position[0] - minimapPosition[0] - minimapDim[0] / 2) / minimapDim[0] * 100) * 460).toFixed (3)),
  107. parseFloat((((position[1] - minimapPosition[1] - minimapDim[1] / 2) / minimapDim[1] * 100) * 460).toFixed (3)),
  108. ]
  109. return ret;
  110. }
  111. const Mi = '';
  112.  
  113. function getAverage (points) {
  114. let ret = [0, 0];
  115. points.forEach (point => {
  116. ret[0] += point[0];
  117. ret[1] += point[1];
  118. });
  119. ret[0] /= points.length;
  120. ret[1] /= points.length;
  121.  
  122. return ret;
  123. }
  124. let dgh = 'M';
  125.  
  126.  
  127. const getDist = (t1, t2) => {
  128. const distX = t1[0] - t2[0];
  129. const distY = t1[1] - t2[1];
  130.  
  131. return [Math.hypot(distX, distY), distX, distY];
  132. };
  133.  
  134. function moveBot () {
  135. if (GM_getValue('autoRespawn')) {
  136. if (canRespawn) {
  137. input.trySpawn && input.trySpawn (GM_getValue('name'))
  138. }
  139. }
  140. if (input.should_prevent_unload()) {
  141. canRespawn = true;
  142. }
  143. let masterMouse = GM_getValue('multiboxMouse');
  144. let masterMove = GM_getValue ('multiboxWorld');
  145.  
  146. console.log(masterMove, worldPosition)
  147. const distanceMove = getDist (masterMove, worldPosition);
  148. if (!masterMouse[0] || !masterMouse[1] || !masterMove[0] || !masterMove[1]) {
  149. return;
  150. }
  151.  
  152.  
  153.  
  154. if (GM_getValue('copyMovement')) {
  155. //console.log(distanceMove[0])
  156. if (distanceMove[0] > 400) {
  157. angleMove(distanceMove[1], distanceMove[2])
  158. } else {
  159. copyMove(GM_getValue('keys'))
  160. }
  161. }
  162. if (GM_getValue('copyMouse')) {
  163. angleShoot(...masterMouse)
  164. }
  165. }
  166.  
  167.  
  168.  
  169. function angleMove(dX, dY){
  170. if (dX > 0) {
  171. input.key_up (65);
  172. input.key_down (68);
  173. } else if (dX < 0) {
  174. input.key_up (68);
  175. input.key_down (65);
  176. } else {
  177. input.key_up (68);
  178. input.key_up (65);
  179. }
  180.  
  181. if (dY > 0) {
  182. input.key_up (87);
  183. input.key_down (83);
  184. } else if (dY < 0) {
  185. input.key_up (83);
  186. input.key_down (87);
  187. } else {
  188. input.key_up (83);
  189. input.key_up (87);
  190. }
  191. }
  192. function angleShoot(stepX, stepY){
  193. const x = stepX * canvas.width * window.devicePixelRatio;
  194. const y = stepY * canvas.height * window.devicePixelRatio;
  195.  
  196. input.mouse(x, y)
  197. }
  198. function copyMove(keys){
  199. if(keys[0]){
  200. input.key_down(87)
  201. }
  202. else{
  203. input.key_up(87)
  204. }
  205. if(keys[1]){
  206. input.key_down(65)
  207. }
  208. else {
  209. input.key_up(65)
  210. }
  211. if(keys[2]){
  212. input.key_down(83)
  213. }
  214. else {
  215. input.key_up(83)
  216. }
  217. if(keys[3]){
  218. input.key_down(68)
  219. }
  220. else {
  221. input.key_up(68)
  222. }
  223. }
  224.  
  225.  
  226.  
  227. function frame () {
  228. overlay.innerHTML = `
  229. <h1>MULTIBOX</h1>
  230. <br> <br>
  231. World position: <br> ${Math.round(worldPosition[0]) || 0} ${Math.round(worldPosition[1]) || 0}
  232. <br> <br>
  233. Master Tab: #${GM_getValue('master') || 0}
  234. <br> <br>
  235. [F] Multibox Enabled: ${GM_getValue('multiboxEnabled') || false}
  236. <br> <br>
  237. [G] Copy Movement: ${GM_getValue('copyMovement') || false}
  238. <br> <br>
  239. [J] Copy Mouse: ${GM_getValue('copyMouse') || false}
  240. <br> <br>
  241. [Q] Toggle Gui: true
  242. <br> <br>
  243. [Z] Auto Respawn: ${GM_getValue('autoRespawn') || false}
  244. <br> <br>
  245. [,] Always Shoot: ${GM_getValue('autoShoot') || false}
  246. <br> <br>
  247. `
  248. if(GM_getValue('autoShoot')){
  249. input.key_down(1)
  250. }
  251. else{
  252. input.key_up(1)
  253. }
  254. if (GM_getValue('master') == tabId){
  255. GM_setValue('multiboxWorld', worldPosition)
  256. GM_setValue('multiboxMouse', mouseOffset)
  257. GM_setValue('keys', moveKeys)
  258.  
  259. } else if (GM_getValue('multiboxEnabled')) {
  260. moveBot ();
  261. }
  262. window.requestAnimationFrame (frame);
  263. }
  264.  
  265.  
  266. document.addEventListener ('keydown', e => {
  267. if (e.key === 'f') {
  268. GM_setValue('multiboxEnabled', !GM_getValue('multiboxEnabled'))
  269. if(GM_getValue('multiboxEnabled')){
  270. GM_setValue('master', tabId)
  271. }
  272. }
  273. if (e.key === 'g') {
  274. GM_setValue('copyMovement', !GM_getValue('copyMovement'))
  275. }
  276. if (e.key === 'j') {
  277. GM_setValue('copyMouse', !GM_getValue('copyMouse'))
  278. }
  279. if (e.key === 'q') {
  280. gui = !gui;
  281. overlay.style.display = gui ? 'block' : 'none'
  282. }
  283. if (e.key === ',') {
  284. GM_setValue('autoShoot', !GM_getValue('autoShoot'))
  285. }
  286. if (e.key === 'z') {
  287. GM_setValue('autoRespawn', !GM_getValue('autoRespawn'))
  288. }
  289. if(e.key === 'p'){
  290. GM_setValue('master', tabId)
  291. }
  292.  
  293. if(e.key === 'w'){
  294. moveKeys[0] = true;
  295. }
  296. if(e.key === 'a') {
  297. moveKeys[1] = true;
  298. }
  299. if(e.key === 's') {
  300. moveKeys[2] = true;
  301. }
  302. if(e.key === 'd') {
  303. moveKeys[3] = true;
  304. }
  305. })
  306. document.addEventListener('keyup', e => {
  307. if(e.key === 'w'){
  308. moveKeys[0] = false;
  309. }
  310. if(e.key === 'a') {
  311. moveKeys[1] = false;
  312. }
  313. if(e.key === 's') {
  314. moveKeys[2] = false;
  315. }
  316. if(e.key === 'd') {
  317. moveKeys[3] = false;
  318. }
  319. });
  320.  
  321. document.addEventListener ('mousemove', e => {
  322. mouseOffset = [
  323. e.x / canvas.width,
  324. e.y / canvas.height,
  325. ]
  326. });
  327. function terminate () {
  328. overlay = document.createElement('div');
  329. overlay.style.position = 'fixed';
  330. overlay.style.top = '1px';
  331. overlay.style.left = '1px';
  332. overlay.style.fontFamily = 'Lucida Console, Courier, monospace';
  333. overlay.style.fontSize = '12px';
  334. overlay.style.color = '#ffffff';
  335. overlay.style.pointerEvents = 'none';
  336. overlay.style.userSelect = 'none';
  337. overlay.style.fontSize = '14px';
  338. overlay.style.backgroundColor = 'gray';
  339. overlay.style.height = '450px';
  340. overlay.style.width = '250px';
  341. overlay.style.borderRadius = '1px'
  342. overlay.style.borderStyle = 'solid'
  343. overlay.style.borderColor = '#404040'
  344. overlay.style.borderWidth = '5px'
  345. overlay.style.textAlign = 'center';
  346. document.body.appendChild(overlay);
  347.  
  348. frame ();
  349. hookMinimapArrow ();
  350. hookMinimap ();
  351.  
  352.  
  353.  
  354. }
  355. terminate ();
  356. },400);