Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.61 KB | None | 0 0
  1. // ==UserScript==
  2. // @name KC - Aimbot, Wallhack, Auto-Reload, Fast/slow speedhack, Time stop, Bhop, Auto Weapon-Swap
  3. // @namespace Meemsouprice
  4. // @version 1.2.5
  5. // @description AIMBOT, ESP, AUTO-RELOAD, FAST/SLOW SPEEDHACK, TIME STOP, BHOP, AUTO WEAPON-SWAP
  6. // @author Meemsouprice and Anohaxer
  7. // @include https://krunker.io/
  8. // @include https://krunker.io/?game=*
  9. // @grant GM_xmlhttpRequest
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13.  
  14. var OnOffMode;
  15. (function (OnOffMode) {
  16. OnOffMode["On"] = "On";
  17. OnOffMode["Off"] = "Off";
  18. })(OnOffMode || (OnOffMode = {}));
  19. class Module {
  20. constructor() {
  21. this.allStates = this.getAllModes();
  22. this.currentModeIndex = this.allStates.indexOf(this.getInitialMode());
  23. }
  24. onModeChanged() {
  25. }
  26. onTick() {
  27. }
  28. getInitialMode() {
  29. return this.allStates[0];
  30. }
  31. onKeyPressed() {
  32. this.currentModeIndex++;
  33. if (this.currentModeIndex >= this.allStates.length) {
  34. this.currentModeIndex = 0;
  35. }
  36. this.onModeChanged();
  37. }
  38. isEnabled() {
  39. return this.currentModeIndex !== 0;
  40. }
  41. getStatus() {
  42. return this.allStates[this.currentModeIndex].toString();
  43. }
  44. getCurrentMode() {
  45. return this.allStates[this.currentModeIndex];
  46. }
  47. }
  48.  
  49. var AimbotMode;
  50. (function (AimbotMode) {
  51. AimbotMode["Off"] = "Off";
  52. AimbotMode["Quickscoper"] = "Quickscoper";
  53. AimbotMode["OnRMB"] = "On RMB";
  54. })(AimbotMode || (AimbotMode = {}));
  55. class Aimbot extends Module {
  56. constructor() {
  57. super(...arguments);
  58. this.scopingOut = false;
  59. this.canShoot = true;
  60. }
  61. getName() {
  62. return 'Aimbot';
  63. }
  64. getKey() {
  65. return 'T';
  66. }
  67. getAllModes() {
  68. return [AimbotMode.Off, AimbotMode.Quickscoper, AimbotMode.OnRMB, AimbotMode.AutoShoot];
  69. }
  70. onTick() {
  71. if (!this.players) {
  72. return;
  73. }
  74. const possibleTargets = this.players
  75. .filter(player => {
  76. return player.active && player.inView && !player.isYou && (!player.team || player.team !== this.me.team);
  77. })
  78. .sort((p1, p2) => this.distance(this.me, p1) - this.distance(this.me, p2));
  79. let isLockedOn = false;
  80. if (possibleTargets.length > 0) {
  81. const target = possibleTargets[0];
  82. switch (this.getCurrentMode()) {
  83. case AimbotMode.Quickscoper:
  84. isLockedOn = this.runQuickscoper(target);
  85. break;
  86. case AimbotMode.OnRMB:
  87. isLockedOn = this.runOnRMB(target);
  88. break;
  89. }
  90. }
  91. if (!isLockedOn) {
  92. this.control.camLookAt(null);
  93. this.control.target = null;
  94. if (this.getCurrentMode() === AimbotMode.Quickscoper) {
  95. this.control.mouseDownL = 0;
  96. this.control.mouseDownR = 0;
  97. }
  98. }
  99. }
  100. runQuickscoper(target) {
  101. if (this.me.didShoot) {
  102. this.canShoot = false;
  103. setTimeout(() => {
  104. this.canShoot = true;
  105. }, this.me.weapon.rate);
  106. }
  107. if (this.control.mouseDownL === 1) {
  108. this.control.mouseDownL = 0;
  109. this.control.mouseDownR = 0;
  110. this.scopingOut = true;
  111. }
  112. if (this.me.aimVal === 1) {
  113. this.scopingOut = false;
  114. }
  115. if (this.scopingOut || !this.canShoot || this.me.recoilForce > 0.01) {
  116. return false;
  117. }
  118. this.lookAt(target);
  119. if (this.control.mouseDownR === 0) {
  120. this.control.mouseDownR = 1;
  121. }
  122. else if (this.me.aimVal < 0.2) {
  123. this.control.mouseDownL = 1 - this.control.mouseDownL;
  124. }
  125. return true;
  126. }
  127. runOnRMB(target) {
  128. if (this.control.mouseDownR === 0) {
  129. return false;
  130. }
  131. this.lookAt(target);
  132. return true;
  133. }
  134. lookAt(target) {
  135. this.control.camLookAt(target.x2, target.y2 + target.height - 1.5 - 2.5 * target.crouchVal - this.me.recoilAnimY * 0.3 * 25, target.z2);
  136. }
  137. distance(player1, player2) {
  138. const dx = player1.x - player2.x;
  139. const dy = player1.y - player2.y;
  140. const dz = player1.z - player2.z;
  141. return Math.sqrt(dx * dx + dy * dy + dz * dz);
  142. }
  143. }
  144.  
  145. var Bhop;
  146. (function (Bhop) {
  147. Bhop["Off"] = "Off";
  148. Bhop["Jump"] = "Jump";
  149. Bhop["SlideJump"] = "Slide Jump";
  150. })(Bhop || (Bhop = {}));
  151. class AutoBHop extends Module {
  152. constructor() {
  153. super(...arguments);
  154. this.isSliding = false;
  155. }
  156. getName() {
  157. return 'Bhop';
  158. }
  159. getKey() {
  160. return 'B';
  161. }
  162. getAllModes() {
  163. return [Bhop.Off, Bhop.Jump, Bhop.SlideJump, Bhop.SlideAnti];
  164. }
  165. onTick() {
  166. this.control.keys[32] = !this.control.keys[32];
  167. if (this.getCurrentMode() === Bhop.SlideJump) {
  168. if (this.isSliding) {
  169. this.inputs[8] = 1;
  170. return;
  171. }
  172. if (this.me.yVel < -0.04 && this.me.canSlide) {
  173. this.isSliding = true;
  174. setTimeout(() => {
  175. this.isSliding = false;
  176. }, 350);
  177. this.inputs[8] = 1;
  178. }
  179. }
  180. }
  181. }
  182.  
  183. class AutoWeaponSwap extends Module {
  184. getName() {
  185. return 'Auto-WS';
  186. }
  187. getKey() {
  188. return 'G';
  189. }
  190. getAllModes() {
  191. return [OnOffMode.Off, OnOffMode.On];
  192. }
  193. getInitialMode() {
  194. return OnOffMode.Off;
  195. }
  196. onTick() {
  197. if (this.me.ammos[this.me.weaponIndex] === 0 && this.me.ammos[0] != this.me.ammos[1]) {
  198. this.inputs[10] = -1
  199. }
  200. }
  201. }
  202.  
  203. class AutoReload extends Module {
  204. getName() {
  205. return 'Auto-Reload';
  206. }
  207. getKey() {
  208. return 'H';
  209. }
  210. getAllModes() {
  211. return [OnOffMode.Off, OnOffMode.On];
  212. }
  213. getInitialMode() {
  214. return OnOffMode.On;
  215. }
  216. onTick() {
  217. if (this.me.ammos[this.me.weaponIndex] === 0) {
  218. this.inputs[9] = 1;
  219. }
  220. }
  221. }
  222.  
  223.  
  224. class FasterSpeedHack extends Module {
  225. getName() {
  226. return 'Faster Speedhack';
  227. }
  228. getKey() {
  229. return 'M';
  230. }
  231. getAllModes() {
  232. return [OnOffMode.Off, OnOffMode.On];
  233. }
  234. getInitialMode() {
  235. return OnOffMode.Off;
  236. }
  237. onTick() {
  238. this.inputs[1] *= 2.000;
  239. }
  240. }
  241.  
  242. class FastSpeedHack extends Module {
  243. getName() {
  244. return 'Fast Speedhack';
  245. }
  246. getKey() {
  247. return 'U';
  248. }
  249. getAllModes() {
  250. return [OnOffMode.Off, OnOffMode.On];
  251. }
  252. getInitialMode() {
  253. return OnOffMode.Off;
  254. }
  255. onTick() {
  256. this.inputs[1] *= 1.275;
  257. }
  258. }
  259.  
  260. class SlowSpeedHack extends Module {
  261. getName() {
  262. return 'SlowSpeedhack';
  263. }
  264. getKey() {
  265. return 'I';
  266. }
  267. getAllModes() {
  268. return [OnOffMode.Off, OnOffMode.On];
  269. }
  270. getInitialMode() {
  271. return OnOffMode.Off;
  272. }
  273. onTick() {
  274. this.inputs[1] *= 1.133;
  275. }
  276. }
  277.  
  278. class Timestop extends Module {
  279. getName() {
  280. return 'ZA WARUDO';
  281. }
  282. getKey() {
  283. return 'N';
  284. }
  285. getAllModes() {
  286. return [OnOffMode.Off, OnOffMode.On];
  287. }
  288. getInitialMode() {
  289. return OnOffMode.Off;
  290. }
  291. onTick() {
  292. this.inputs[1] *= 0;
  293. }
  294.  
  295.  
  296. //epic sound effect copyrkt by Anoh4xer https://www.youtube.com/channel/UC0-d0_6kPIKjJwJOQlaRZ7w
  297. onModeChanged() {
  298. if (this.getCurrentMode() === OnOffMode.On) {
  299. new Audio("https://www.myinstants.com/media/sounds/za-warudo-stop-time-sound.mp3").play();
  300.  
  301. }
  302. }
  303. }
  304.  
  305. class WallHack extends Module {
  306. getName() {
  307. return 'Wallhack';
  308. }
  309. getKey() {
  310. return 'L';
  311. }
  312. getAllModes() {
  313. return [OnOffMode.Off, OnOffMode.On];
  314. }
  315. getInitialMode() {
  316. unsafeWindow.wallHackEnabled = true;
  317. return OnOffMode.On;
  318. }
  319. onModeChanged() {
  320. unsafeWindow.wallHackEnabled = this.getCurrentMode() === OnOffMode.On;
  321. }
  322. }
  323.  
  324. class KC {
  325. constructor() {
  326. this.modules = [];
  327. }
  328. init() {
  329. this.modules.push(new Aimbot());
  330. this.modules.push(new AutoReload());
  331. this.modules.push(new AutoWeaponSwap());
  332. this.modules.push(new FasterSpeedHack());
  333. this.modules.push(new FastSpeedHack());
  334. this.modules.push(new SlowSpeedHack());
  335. this.modules.push(new Timestop());
  336. this.modules.push(new WallHack());
  337. this.modules.push(new AutoBHop());
  338. const initInfoBoxInterval = setInterval(() => {
  339. if (this.canInjectInfoBox()) {
  340. clearInterval(initInfoBoxInterval);
  341. this.injectInfoBox();
  342. this.updateInfoBox();
  343. }
  344. }, 100);
  345. }
  346. onTick(me, inputs) {
  347. this.modules.forEach(module => {
  348. if (module.isEnabled()) {
  349. module.me = me;
  350. module.inputs = inputs;
  351. module.control = unsafeWindow.control;
  352. module.players = unsafeWindow.players;
  353. module.onTick();
  354. }
  355. });
  356. }
  357. onKeyPressed(e) {
  358. let shouldUpdateInfoBox = false;
  359. this.modules.forEach(module => {
  360. if (module.getKey().toUpperCase() === e.key.toUpperCase()) {
  361. module.onKeyPressed();
  362. shouldUpdateInfoBox = true;
  363. }
  364. });
  365. if (shouldUpdateInfoBox) {
  366. this.updateInfoBox();
  367. }
  368. }
  369. updateInfoBox() {
  370. const infoBox = unsafeWindow.document.querySelector('#KCInfoBox');
  371. if (infoBox === null) {
  372. return;
  373. }
  374. const moduleLines = this.modules.map(module => {
  375. return `
  376. <div class="leaderItem">
  377. <div class="leaderNameF">[${module.getKey().toUpperCase()}] ${module.getName()}</div>
  378. <div class="leaderScore">${module.getStatus()}</div>
  379. </div>
  380. `;
  381. });
  382. infoBox.innerHTML = `
  383. <div class="KCTitle">KC</div>
  384. ${moduleLines.join('')}
  385. `.trim();
  386. }
  387. injectInfoBox() {
  388. const infoBox = unsafeWindow.document.createElement('div');
  389. infoBox.innerHTML = `
  390. <div>
  391. <style>
  392. #KCInfoBox {
  393. text-align: center;
  394. width: 220px;
  395. z-index: 3;
  396. padding: 10px;
  397. padding-left: 20px;
  398. padding-right: 20px;
  399. color: rgba(255, 255, 255, 0.7);
  400. line-height: 25px;
  401. margin-top: 20px;
  402. background-color: rgba(255, 10, 10, 0.80);
  403. }
  404.  
  405. #KCInfoBox .KCTitle {
  406. font-size: 19px;
  407. font-weight: bold;
  408. text-align: center;
  409. color: #fff;
  410. margin-top: 5px;
  411. margin-bottom: 5px;
  412. }
  413.  
  414. #KCInfoBox .leaderItem {
  415. font-size: 14px;
  416. }
  417. </style>
  418.  
  419. <div id="KCInfoBox"></div>
  420. </div>
  421. `.trim();
  422. const leaderDisplay = unsafeWindow.document.querySelector('#leaderDisplay');
  423. leaderDisplay.parentNode.insertBefore(infoBox.firstChild, leaderDisplay.nextSibling);
  424. }
  425. canInjectInfoBox() {
  426. return unsafeWindow.document.querySelector('#leaderDisplay') !== null;
  427. }
  428. }
  429.  
  430. // tslint:disable no-console
  431. class Logger {
  432. constructor(prefix) {
  433. this.prefix = prefix;
  434. }
  435. log(...message) {
  436. console.log(this.prefix, ...message);
  437. }
  438. error(...message) {
  439. console.error(this.prefix, ...message);
  440. }
  441. crash(message) {
  442. document.open();
  443. document.write(`
  444. <html lang="en">
  445. <head>
  446. <title>KC has crashed!</title>
  447.  
  448. <style>
  449. .container {
  450. position: absolute;
  451. top: 50%;
  452. left: 50%;
  453. -moz-transform: translateX(-50%) translateY(-50%);
  454. -webkit-transform: translateX(-50%) translateY(-50%);
  455. transform: translateX(-50%) translateY(-50%);
  456. text-align: center;
  457. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
  458. }
  459.  
  460. .title {
  461. font-size: 24px;
  462. font-weight: bold;
  463. margin-bottom: 5px;
  464. }
  465.  
  466. .message {
  467. font-size: 20px;
  468. }
  469. </style>
  470. </head>
  471. <body>
  472. <div class="container">
  473. <div class="title">KC has crashed!</div>
  474. <div class="message">Error message: ${message}</div>
  475. </div>
  476. </body>
  477. </html>
  478. `);
  479. document.close();
  480. throw new Error(`${this.prefix} ${message}`);
  481. }
  482. }
  483. const logger = new Logger('[KC]');
  484.  
  485. function applyPatch(script, method, regex, replacer) {
  486. const newScript = script.replace(regex, replacer);
  487. if (script === newScript) {
  488. logger.crash(`${method} was not successful`);
  489. }
  490. return newScript;
  491. }
  492. function patchControl(script) {
  493. return applyPatch(script, 'patchControl', /var ([a-zA-Z0-9]+)=this,([a-zA-Z0-9]+)=([a-zA-Z0-9]+)\.renderer\.domElement/, ($0, $1, $2, $3) => {
  494. return `var ${$1} = window.control = this, ${$2} = ${$3}.renderer.domElement;`;
  495. });
  496. }
  497. function patchPlayers(script) {
  498. return applyPatch(script, 'patchPlayers', /if\(this\.now/, 'window.players = this.players.list; if (this.now');
  499. }
  500. function patchOnTick(script) {
  501. return applyPatch(script, 'patchOnTick', /,([a-zA-Z0-9]+)\.procInputs\(([a-zA-Z0-9]+)/, ($0, $1, $2) => {
  502. return `, window.onTick(${$1}, ${$2}), ${$1}.procInputs(${$2}`;
  503. });
  504. }
  505. function patchOnKeyPressed(script) {
  506. return applyPatch(script, 'patchOnKeyPressed', /"keyup",function\(([a-zA-Z0-9]+)\){/, ($0, $1) => {
  507. return `"keyup", function (${$1}) { if (document.activeElement !== chatInput) { window.onKeyPressed(${$1}); }`;
  508. });
  509. }
  510. function patchForAimbot(script) {
  511. return applyPatch(script, 'patchForAimbot', /{if\(this\.target\){(.+)}},this.camLookAt=/, ($0, $1) => {
  512. return `
  513. {
  514. if (this.target) {
  515. this.object.rotation.y = this.target.yD;
  516. this.pitchObject.rotation.x = this.target.xD;
  517.  
  518. const half = Math.PI / 2;
  519. this.pitchObject.rotation.x = Math.max(-half, Math.min(half, this.pitchObject.rotation.x));
  520.  
  521. this.yDr = this.pitchObject.rotation.x % Math.PI;
  522. this.xDr = this.object.rotation.y % Math.PI;
  523.  
  524. ${$1}
  525. }
  526. }, this.camLookAt =
  527. `;
  528. });
  529. }
  530. function patchForWallHack(script) {
  531. 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) => {
  532. return `
  533. if (${$1}.inView || window.wallHackEnabled) {
  534. ${$2}
  535. } else ${$3}.style.display = "none"
  536. } var ${$4};
  537. `;
  538. });
  539. }
  540. function patchIsHacker(script) {
  541. return applyPatch(script, 'patchIsHacker', /&&([a-zA-Z0-9]+)\.isHacker&&/, `&& 1 === 0 &&`);
  542. }
  543. function patchLastHack(script) {
  544. return applyPatch(script, 'patchIsHacker', /&&([a-zA-Z0-9]+)\.lastHack&&/, `&& 1 === 0 &&`);
  545. }
  546. /*
  547. function patchServerSearch(script) {
  548. return applyPatch(script, 'patchServerSearch', /([a-zA-Z0-9]+)\.data\.([a-zA-Z0-9]+)\.toLowerCase/, ($0, $1, $2) => {
  549. return `(${$1}.data.${$2} || '').toLowerCase`;
  550. });
  551. }
  552. */
  553. function patchStyleErrors(script) {
  554. return applyPatch(script, 'patchStyleErrors', /else document\.getElementById\("healthBarE"\+([a-zA-Z0-9]+)\)\.style\.width=([a-zA-Z0-9]+)\+"%"/, ($0, $1, $2) => {
  555. return `else (document.getElementById("healthBarE" + ${$1}) || { style: {} }).style.width = ${$2} + "%"`;
  556. });
  557. }
  558. function patchGameScript(script) {
  559. logger.log('Patching the game script...');
  560. script = patchControl(script);
  561. script = patchPlayers(script);
  562. script = patchOnTick(script);
  563. script = patchOnKeyPressed(script);
  564. script = patchForAimbot(script);
  565. script = patchForWallHack(script);
  566. script = patchIsHacker(script);
  567. script = patchLastHack(script);
  568. // script = patchServerSearch(script);
  569. script = patchStyleErrors(script);
  570. logger.log('Successfully patched the game script!');
  571. return script;
  572. }
  573.  
  574. function request(url) {
  575. return new Promise(resolve => {
  576. logger.log(`Retrieving ${url}`);
  577. GM_xmlhttpRequest({
  578. url,
  579. method: 'GET',
  580. onload: response => resolve(response.responseText),
  581. });
  582. });
  583. }
  584.  
  585. function replaceRemoteScriptWithInline(html, partialSrc, script) {
  586. const inline = `<script type="text/javascript">${script}</script>`;
  587. const regExp = new RegExp(`<script src="[^"]*${partialSrc}[^"]*"></script>`);
  588. const withoutScriptTag = html.replace(regExp, '');
  589. return withoutScriptTag + inline;
  590. }
  591. async function inlineRemoteScript(html, partialSrc) {
  592. const regExp = new RegExp(`<script src="([^"]*)${partialSrc}([^"]*)"></script>`);
  593. const [, prefix, suffix] = regExp.exec(html);
  594. const script = await request(prefix + partialSrc + suffix);
  595. return replaceRemoteScriptWithInline(html, partialSrc, script);
  596. }
  597. (async () => {
  598. if (unsafeWindow.navigator.userAgent.includes('Firefox')) {
  599. alert('KC does not work on Firefox.');
  600. return;
  601. }
  602. window.stop();
  603. logger.log('Loading KC...');
  604. let newHtml = await request(document.location.href);
  605. const gameScriptHash = /game\.([^\.]+)\.js/.exec(newHtml)[1];
  606. const gameScript = await request(`https://krunker.io/js/game.${gameScriptHash}.js`);
  607. newHtml = await inlineRemoteScript(newHtml, 'libs/zip.js');
  608. newHtml = await inlineRemoteScript(newHtml, 'libs/zip-ext.js');
  609. newHtml = replaceRemoteScriptWithInline(newHtml, 'js/game', patchGameScript(gameScript));
  610. const bot = new KC();
  611. bot.init();
  612. unsafeWindow.onTick = (me, inputs) => bot.onTick(me, inputs);
  613. unsafeWindow.onKeyPressed = (e) => bot.onKeyPressed(e);
  614. document.open();
  615. document.write(newHtml);
  616. document.close();
  617. logger.log('Successfully loaded KC!');
  618. })();
  619.  
  620. var checkgameloaded;
  621.  
  622. window.WebSocket.prototype.oldSend = WebSocket.prototype.send;
  623. window.WebSocket.prototype.send = function(m){
  624. if (!checkgameloaded){
  625. activatehack(this);
  626. }
  627. this.oldSend(m);
  628. }
  629.  
  630. window.stop();
  631. document.innerHTML = ``;
  632.  
  633. window.gameCode = "";
  634. window.zip = "";
  635. window.zipExt = "";
  636.  
  637.  
  638. window.chatmessage = window.Ze = (t, e, i) => {
  639. for (chatList.innerHTML += i ? "<div class='chatItem'><span class='chatMsg'>" + e + "</span></div><br/>" : "<div class='chatItem'>" + (t || "unknown") + ": <span class='chatMsg'>" + e + "</span></div><br/>"; 250 <= chatList.scrollHeight;) chatList.removeChild(chatList.childNodes[0])
  640. }
  641.  
  642. function activatehack(socket){
  643. window.socket = socket;
  644. checkgameloaded = socket;
  645.  
  646. }
  647.  
  648. setTimeout( () => {
  649. pending = true;
  650. }, 5000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement