krunker tips

Krunker Source code for Aimbot, Auto Reload, Auto BHop and Wall Hack

Krunker Source code for Aimbot, Auto Reload, Auto BHop and Wall Hack

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