Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
3,211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         KRUNKVILLAIN - Krunker.io HACK AIMBOT ESP BHOP
  3. // @namespace    Roogybot
  4. // @version      1.0.1
  5. // @description  Aimbot, Auto Reload, Auto BHop and Wall Hack for Krunker.io
  6. // @author       Roogybot
  7. // @include      https://krunker.io/
  8. // @include      https://krunker.io/?game=*
  9. // @grant        GM_xmlhttpRequest
  10. // @run-at       document-start
  11. // ==/UserScript==
  12.  
  13. var OnOffMode;
  14. (function (OnOffMode) {
  15.     OnOffMode["On"] = "On";
  16.     OnOffMode["Off"] = "Off";
  17. })(OnOffMode || (OnOffMode = {}));
  18. class Module {
  19.     constructor() {
  20.         this.allStates = this.getAllModes();
  21.         this.currentModeIndex = this.allStates.indexOf(this.getInitialMode());
  22.     }
  23.     onModeChanged() {
  24.         // Let implementations override this if needed
  25.     }
  26.     onTick() {
  27.         // Let implementations override this if needed
  28.     }
  29.     getInitialMode() {
  30.         return this.allStates[0];
  31.     }
  32.     onKeyPressed() {
  33.         this.currentModeIndex++;
  34.         if (this.currentModeIndex >= this.allStates.length) {
  35.             this.currentModeIndex = 0;
  36.         }
  37.         this.onModeChanged();
  38.     }
  39.     isEnabled() {
  40.         return this.currentModeIndex !== 0;
  41.     }
  42.     getStatus() {
  43.         return this.allStates[this.currentModeIndex].toString();
  44.     }
  45.     getCurrentMode() {
  46.         return this.allStates[this.currentModeIndex];
  47.     }
  48. }
  49.  
  50. var AimbotMode;
  51. (function (AimbotMode) {
  52.     AimbotMode["Off"] = "Off";
  53.     AimbotMode["Quickscoper"] = "Quickscoper";
  54.     AimbotMode["OnRMB"] = "On RMB";
  55. })(AimbotMode || (AimbotMode = {}));
  56. class Aimbot extends Module {
  57.     constructor() {
  58.         super(...arguments);
  59.         this.scopingOut = false;
  60.         this.canShoot = true;
  61.     }
  62.     getName() {
  63.         return 'Aimbot';
  64.     }
  65.     getKey() {
  66.         return 'I';
  67.     }
  68.     getAllModes() {
  69.         return [AimbotMode.Off, AimbotMode.Quickscoper, AimbotMode.OnRMB];
  70.     }
  71.     onTick() {
  72.         if (!this.players) {
  73.             return;
  74.         }
  75.         const possibleTargets = this.players
  76.             .filter(player => {
  77.             return player.active && player.inView && !player.isYou && (!player.team || player.team !== this.me.team);
  78.         })
  79.             .sort((p1, p2) => this.distance(this.me, p1) - this.distance(this.me, p2));
  80.         let isLockedOn = false;
  81.         if (possibleTargets.length > 0) {
  82.             const target = possibleTargets[0];
  83.             switch (this.getCurrentMode()) {
  84.                 case AimbotMode.Quickscoper:
  85.                     isLockedOn = this.runQuickscoper(target);
  86.                     break;
  87.                 case AimbotMode.OnRMB:
  88.                     isLockedOn = this.runOnRMB(target);
  89.                     break;
  90.             }
  91.         }
  92.         if (!isLockedOn) {
  93.             this.control.camLookAt(null);
  94.             this.control.target = null;
  95.             if (this.getCurrentMode() === AimbotMode.Quickscoper) {
  96.                 this.control.mouseDownL = 0;
  97.                 this.control.mouseDownR = 0;
  98.             }
  99.         }
  100.     }
  101.     runQuickscoper(target) {
  102.         if (this.me.didShoot) {
  103.             this.canShoot = false;
  104.             setTimeout(() => {
  105.                 this.canShoot = true;
  106.             }, this.me.weapon.rate);
  107.         }
  108.         if (this.control.mouseDownL === 1) {
  109.             this.control.mouseDownL = 0;
  110.             this.control.mouseDownR = 0;
  111.             this.scopingOut = true;
  112.         }
  113.         if (this.me.aimVal === 1) {
  114.             this.scopingOut = false;
  115.         }
  116.         if (this.scopingOut || !this.canShoot || this.me.recoilForce > 0.01) {
  117.             return false;
  118.         }
  119.         this.lookAt(target);
  120.         if (this.control.mouseDownR === 0) {
  121.             this.control.mouseDownR = 1;
  122.         }
  123.         else if (this.me.aimVal < 0.2) {
  124.             this.control.mouseDownL = 1 - this.control.mouseDownL;
  125.         }
  126.         return true;
  127.     }
  128.     runOnRMB(target) {
  129.         if (this.control.mouseDownR === 0) {
  130.             return false;
  131.         }
  132.         this.lookAt(target);
  133.         return true;
  134.     }
  135.     lookAt(target) {
  136.         this.control.camLookAt(target.x2, target.y2 + target.height - 1.5 - 2.5 * target.crouchVal - this.me.recoilAnimY * 0.3 * 25, target.z2);
  137.     }
  138.     distance(player1, player2) {
  139.         const dx = player1.x - player2.x;
  140.         const dy = player1.y - player2.y;
  141.         const dz = player1.z - player2.z;
  142.         return Math.sqrt(dx * dx + dy * dy + dz * dz);
  143.     }
  144. }
  145.  
  146. var BHopMode;
  147. (function (BHopMode) {
  148.     BHopMode["Off"] = "Off";
  149.     BHopMode["Jump"] = "Jump";
  150.     BHopMode["SlideJump"] = "Slide Jump";
  151. })(BHopMode || (BHopMode = {}));
  152. class AutoBHop extends Module {
  153.     constructor() {
  154.         super(...arguments);
  155.         this.isSliding = false;
  156.     }
  157.     getName() {
  158.         return 'Auto BHop';
  159.     }
  160.     getKey() {
  161.         return 'B';
  162.     }
  163.     getAllModes() {
  164.         return [BHopMode.Off, BHopMode.Jump, BHopMode.SlideJump];
  165.     }
  166.     onTick() {
  167.         this.control.keys[32] = !this.control.keys[32];
  168.         if (this.getCurrentMode() === BHopMode.SlideJump) {
  169.             if (this.isSliding) {
  170.                 this.inputs[8] = 1;
  171.                 return;
  172.             }
  173.             if (this.me.yVel < -0.04 && this.me.canSlide) {
  174.                 this.isSliding = true;
  175.                 setTimeout(() => {
  176.                     this.isSliding = false;
  177.                 }, 350);
  178.                 this.inputs[8] = 1;
  179.             }
  180.         }
  181.     }
  182. }
  183.  
  184. class AutoReload extends Module {
  185.     getName() {
  186.         return 'Auto Reload';
  187.     }
  188.     getKey() {
  189.         return 'J';
  190.     }
  191.     getAllModes() {
  192.         return [OnOffMode.Off, OnOffMode.On];
  193.     }
  194.     getInitialMode() {
  195.         return OnOffMode.On;
  196.     }
  197.     onTick() {
  198.         if (this.me.ammos[this.me.weaponIndex] === 0) {
  199.             this.inputs[9] = 1;
  200.         }
  201.     }
  202. }
  203.  
  204. class WallHack extends Module {
  205.     getName() {
  206.         return 'Wall Hack';
  207.     }
  208.     getKey() {
  209.         return 'O';
  210.     }
  211.     getAllModes() {
  212.         return [OnOffMode.Off, OnOffMode.On];
  213.     }
  214.     getInitialMode() {
  215.         unsafeWindow.wallHackEnabled = true;
  216.         return OnOffMode.On;
  217.     }
  218.     onModeChanged() {
  219.         unsafeWindow.wallHackEnabled = this.getCurrentMode() === OnOffMode.On;
  220.     }
  221. }
  222.  
  223. class Krunkbot {
  224.     constructor() {
  225.         this.modules = [];
  226.     }
  227.     init() {
  228.         this.modules.push(new Aimbot());
  229.         this.modules.push(new AutoReload());
  230.         this.modules.push(new WallHack());
  231.         this.modules.push(new AutoBHop());
  232.         const initInfoBoxInterval = setInterval(() => {
  233.             if (this.canInjectInfoBox()) {
  234.                 clearInterval(initInfoBoxInterval);
  235.                 this.injectInfoBox();
  236.                 this.updateInfoBox();
  237.             }
  238.         }, 100);
  239.     }
  240.     onTick(me, inputs) {
  241.         this.modules.forEach(module => {
  242.             if (module.isEnabled()) {
  243.                 module.me = me;
  244.                 module.inputs = inputs;
  245.                 module.control = unsafeWindow.control;
  246.                 module.players = unsafeWindow.players;
  247.                 module.onTick();
  248.             }
  249.         });
  250.     }
  251.     onKeyPressed(e) {
  252.         let shouldUpdateInfoBox = false;
  253.         this.modules.forEach(module => {
  254.             if (module.getKey().toUpperCase() === e.key.toUpperCase()) {
  255.                 module.onKeyPressed();
  256.                 shouldUpdateInfoBox = true;
  257.             }
  258.         });
  259.         if (shouldUpdateInfoBox) {
  260.             this.updateInfoBox();
  261.         }
  262.     }
  263.     updateInfoBox() {
  264.         const infoBox = unsafeWindow.document.querySelector('#krunkbotInfoBox');
  265.         if (infoBox === null) {
  266.             return;
  267.         }
  268.         const moduleLines = this.modules.map(module => {
  269.             return `
  270.         <div class="leaderItem">
  271.           <div class="leaderNameF">[${module.getKey().toUpperCase()}] ${module.getName()}</div>
  272.           <div class="leaderScore">${module.getStatus()}</div>
  273.         </div>
  274.       `;
  275.         });
  276.         infoBox.innerHTML = `
  277.       <div class="krunkbotTitle">Krunkbot</div>
  278.       ${moduleLines.join('')}
  279.     `.trim();
  280.     }
  281.     injectInfoBox() {
  282.         const infoBox = unsafeWindow.document.createElement('div');
  283.         infoBox.innerHTML = `
  284.       <div>
  285.         <style>
  286.           #krunkbotInfoBox {
  287.             text-align: left;
  288.             width: 310px;
  289.             z-index: 3;
  290.             padding: 10px;
  291.             padding-left: 20px;
  292.             padding-right: 20px;
  293.             color: rgba(255, 255, 255, 0.7);
  294.             line-height: 25px;
  295.             margin-top: 20px;
  296.             background-color: rgba(0, 0, 0, 0.2);
  297.           }
  298.          
  299.           #krunkbotInfoBox .krunkbotTitle {
  300.             font-size: 18px;
  301.             font-weight: bold;
  302.             text-align: center;
  303.             color: #fff;
  304.             margin-top: 5px;
  305.             margin-bottom: 5px;
  306.           }
  307.          
  308.           #krunkbotInfoBox .leaderItem {
  309.            font-size: 14px;
  310.           }
  311.         </style>
  312.  
  313.         <div id="krunkbotInfoBox"></div>      
  314.       </div>
  315.     `.trim();
  316.         const leaderDisplay = unsafeWindow.document.querySelector('#leaderDisplay');
  317.         leaderDisplay.parentNode.insertBefore(infoBox.firstChild, leaderDisplay.nextSibling);
  318.     }
  319.     canInjectInfoBox() {
  320.         return unsafeWindow.document.querySelector('#leaderDisplay') !== null;
  321.     }
  322. }
  323.  
  324. // tslint:disable no-console
  325. class Logger {
  326.     constructor(prefix) {
  327.         this.prefix = prefix;
  328.     }
  329.     log(...message) {
  330.         console.log(this.prefix, ...message);
  331.     }
  332.     error(...message) {
  333.         console.error(this.prefix, ...message);
  334.     }
  335.     crash(message) {
  336.         document.open();
  337.         document.write(`
  338.       <html lang="en">
  339.         <head>
  340.           <title>Krunkbot has crashed!</title>
  341.          
  342.           <style>
  343.             .container {
  344.               position: absolute;
  345.               top: 50%;
  346.               left: 50%;
  347.               -moz-transform: translateX(-50%) translateY(-50%);
  348.               -webkit-transform: translateX(-50%) translateY(-50%);
  349.               transform: translateX(-50%) translateY(-50%);
  350.               text-align: center;
  351.               font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
  352.             }
  353.            
  354.             .title {
  355.               font-size: 24px;
  356.               font-weight: bold;
  357.               margin-bottom: 5px;
  358.             }
  359.            
  360.             .message {
  361.               font-size: 20px;
  362.             }
  363.           </style>
  364.         </head>
  365.         <body>
  366.           <div class="container">
  367.             <div class="title">Krunkbot has crashed!</div>
  368.             <div class="message">Error message: ${message}</div>
  369.           </div>
  370.         </body>
  371.       </html>
  372.     `);
  373.         document.close();
  374.         throw new Error(`${this.prefix} ${message}`);
  375.     }
  376. }
  377. const logger = new Logger('[Krunkbot]');
  378.  
  379. function applyPatch(script, method, regex, replacer) {
  380.     const newScript = script.replace(regex, replacer);
  381.     if (script === newScript) {
  382.         logger.crash(`${method} was not successful`);
  383.     }
  384.     return newScript;
  385. }
  386. function patchControl(script) {
  387.     return applyPatch(script, 'patchControl', /var ([a-zA-Z0-9]+)=this,([a-zA-Z0-9]+)=([a-zA-Z0-9]+)\.renderer\.domElement/, ($0, $1, $2, $3) => {
  388.         return `var ${$1} = window.control = this, ${$2} = ${$3}.renderer.domElement;`;
  389.     });
  390. }
  391. function patchPlayers(script) {
  392.     return applyPatch(script, 'patchPlayers', /if\(this\.now/, 'window.players = this.players.list; if (this.now');
  393. }
  394. function patchOnTick(script) {
  395.     return applyPatch(script, 'patchOnTick', /,([a-zA-Z0-9]+)\.procInputs\(([a-zA-Z0-9]+)/, ($0, $1, $2) => {
  396.         return `, window.onTick(${$1}, ${$2}), ${$1}.procInputs(${$2}`;
  397.     });
  398. }
  399. function patchOnKeyPressed(script) {
  400.     return applyPatch(script, 'patchOnKeyPressed', /"keyup",function\(([a-zA-Z0-9]+)\){/, ($0, $1) => {
  401.         return `"keyup", function (${$1}) { if (document.activeElement !== chatInput) { window.onKeyPressed(${$1}); }`;
  402.     });
  403. }
  404. function patchForAimbot(script) {
  405.     return applyPatch(script, 'patchForAimbot', /{if\(this\.target\){(.+)}},this.camLookAt=/, ($0, $1) => {
  406.         return `
  407.       {
  408.         if (this.target) {
  409.           this.object.rotation.y = this.target.yD;
  410.           this.pitchObject.rotation.x = this.target.xD;
  411.          
  412.           const half = Math.PI / 2;
  413.           this.pitchObject.rotation.x = Math.max(-half, Math.min(half, this.pitchObject.rotation.x));
  414.          
  415.           this.yDr = this.pitchObject.rotation.x % Math.PI;
  416.           this.xDr = this.object.rotation.y % Math.PI;
  417.          
  418.           ${$1}
  419.         }
  420.       }, this.camLookAt =
  421.     `;
  422.     });
  423. }
  424. function patchForWallHack(script) {
  425.     return applyPatch(script, 'patchForWallHack', /if\(([a-zA-Z0-9]+)\.inView\){(.+)}else ([a-zA-Z0-9]+)\.style\.display="none"}var ([a-zA-Z0-9]+);/, ($0, $1, $2, $3, $4) => {
  426.         return `
  427.       if (${$1}.inView || window.wallHackEnabled) {
  428.         ${$2}
  429.       } else ${$3}.style.display = "none"
  430.       } var ${$4};
  431.     `;
  432.     });
  433. }
  434. function patchIsHacker(script) {
  435.     return applyPatch(script, 'patchIsHacker', /&&([a-zA-Z0-9]+)\.isHacker&&/, `&& 1 === 0 &&`);
  436. }
  437. function patchLastHack(script) {
  438.     return applyPatch(script, 'patchIsHacker', /&&([a-zA-Z0-9]+)\.lastHack&&/, `&& 1 === 0 &&`);
  439. }
  440. function patchServerSearch(script) {
  441.     return applyPatch(script, 'patchServerSearch', /([a-zA-Z0-9]+)\.data\.([a-zA-Z0-9]+)\.toLowerCase/, ($0, $1, $2) => {
  442.         return `(${$1}.data.${$2} || '').toLowerCase`;
  443.     });
  444. }
  445. function patchStyleErrors(script) {
  446.     return applyPatch(script, 'patchStyleErrors', /else document\.getElementById\("healthBarE"\+([a-zA-Z0-9]+)\)\.style\.width=([a-zA-Z0-9]+)\+"%"/, ($0, $1, $2) => {
  447.         return `else (document.getElementById("healthBarE" + ${$1}) || { style: {} }).style.width = ${$2} + "%"`;
  448.     });
  449. }
  450. function patchGameScript(script) {
  451.     logger.log('Patching the game script...');
  452.     script = patchControl(script);
  453.     script = patchPlayers(script);
  454.     script = patchOnTick(script);
  455.     script = patchOnKeyPressed(script);
  456.     script = patchForAimbot(script);
  457.     script = patchForWallHack(script);
  458.     script = patchIsHacker(script);
  459.     script = patchLastHack(script);
  460.     script = patchServerSearch(script);
  461.     script = patchStyleErrors(script);
  462.     logger.log('Successfully patched the game script!');
  463.     return script;
  464. }
  465.  
  466. function request(url) {
  467.     return new Promise(resolve => {
  468.         logger.log(`Retrieving ${url}`);
  469.         GM_xmlhttpRequest({
  470.             url,
  471.             method: 'GET',
  472.             onload: response => resolve(response.responseText),
  473.         });
  474.     });
  475. }
  476.  
  477. function replaceRemoteScriptWithInline(html, partialSrc, script) {
  478.     const inline = `<script type="text/javascript">${script}</script>`;
  479.     const regExp = new RegExp(`<script src="[^"]*${partialSrc}[^"]*"></script>`);
  480.     const withoutScriptTag = html.replace(regExp, '');
  481.     return withoutScriptTag + inline;
  482. }
  483. async function inlineRemoteScript(html, partialSrc) {
  484.     const regExp = new RegExp(`<script src="([^"]*)${partialSrc}([^"]*)"></script>`);
  485.     const [, prefix, suffix] = regExp.exec(html);
  486.     const script = await request(prefix + partialSrc + suffix);
  487.     return replaceRemoteScriptWithInline(html, partialSrc, script);
  488. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement