Advertisement
okbrainlet

Krunker Cheat discord.gg/4yegWMt

Nov 15th, 2019
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Krunker WheelChair
  3. // @namespace    https://github.com/hrt
  4. // @version      1.8.9
  5. // @description  WheelChair
  6. // @author       hrt x ttap
  7. // @match        *://krunker.io/*
  8. // @run-at       document-start
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13.     const replace = String.prototype.replace;
  14.     const original_call = Function.prototype.call;
  15.  
  16.     let anti_map = [];
  17.  
  18.     // hook toString to conceal all hooks
  19.     const original_toString = Function.prototype.toString;
  20.     let hook_toString = new Proxy(original_toString, {
  21.         apply: function(target, _this, _arguments) {
  22.             for (var i = 0; i < anti_map.length; i++) {
  23.                 if (anti_map[i].from === _this) {
  24.                     return target.apply(anti_map[i].to, _arguments);
  25.                 }
  26.             }
  27.             return target.apply(_this, _arguments);
  28.         }
  29.     });
  30.     // hide toString hook itself
  31.     anti_map.push({from: hook_toString, to: original_toString});
  32.     Function.prototype.toString = hook_toString;
  33.  
  34.     let conceal_function = function(original_Function, hook_Function) {
  35.         anti_map.push({from: hook_Function, to: original_Function});
  36.     };
  37.  
  38.     // hook Object.getOwnPropertyDescriptors to hide variables from window
  39.     let hidden_globals = [];
  40.     const original_getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors;
  41.     let hook_getOwnPropertyDescriptors = new Proxy(original_getOwnPropertyDescriptors, {
  42.         apply: function(target, _this, _arguments) {
  43.             let descriptors = target.apply(_this, _arguments);
  44.             for (var i = 0; i < hidden_globals.length; i++) {
  45.                 delete descriptors[hidden_globals[i]];
  46.             }
  47.             return descriptors;
  48.         }
  49.     });
  50.     Object.getOwnPropertyDescriptors = hook_getOwnPropertyDescriptors;
  51.     conceal_function(original_getOwnPropertyDescriptors, hook_getOwnPropertyDescriptors);
  52.  
  53.     let invisible_define = function(obj, key, value) {
  54.         hidden_globals.push(key);
  55.         Object.defineProperty(obj, key, {
  56.             enumberable: false,
  57.             configurable: false,
  58.             writable: true,
  59.             value: value
  60.         });
  61.     };
  62.  
  63.     let global_invisible_define = function(key, value) {
  64.         invisible_define(window, key, value);
  65.     };
  66.  
  67.     // we generate random keys for global variables and make it almost impossible(?)
  68.     // for outsiders to find programatically
  69.     let keyMap = {};
  70.     let genKey = function() {
  71.         // https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
  72.         let a = new Uint8Array(20);
  73.         crypto.getRandomValues(a);
  74.         return 'hrt'+Array.from(a,x=>('0'+x.toString(16)).substr(-2)).join('');
  75.     }
  76.  
  77.     keyMap['init'] = genKey();
  78.     global_invisible_define(keyMap['init'], false);
  79.  
  80.     // drawVisuals gets overwritten later - place hook before anti cheat loads
  81.     let drawVisuals = function() {};
  82.     const original_clearRect = CanvasRenderingContext2D.prototype.clearRect;
  83.     let hook_clearRect = new Proxy(original_clearRect, {
  84.         apply: function(target, _this, _arguments) {
  85.             target.apply(_this, _arguments);
  86.             drawVisuals(_this);
  87.         }
  88.     });
  89.     conceal_function(original_clearRect, hook_clearRect);
  90.     CanvasRenderingContext2D.prototype.clearRect = hook_clearRect;
  91.  
  92.     // me, inputs, world, consts, math are objects the rest are key strings
  93.     let hrtCheat = function(me, inputs, world, consts, math, canSee, pchObjc, objInstances, isYou, recoilAnimY, mouseDownL, mouseDownR) {
  94.         /* re implements code that we overwrote to place hook */
  95.         let controls = world.controls;
  96.         if (controls.scrollDelta) {
  97.             controls.skipScroll = controls.scrollToSwap;
  98.             if (!controls.scrollToSwap) {
  99.                 controls.fakeKey(0x4e20,0x1);
  100.             }
  101.         }
  102.         controls.scrollDelta = 0;
  103.         controls.wSwap = 0;
  104.         /******************************************************/
  105.  
  106.         const playerHeight = 11;
  107.         const crouchDst = 3;
  108.         const headScale = 2;
  109.         const hitBoxPad = 1;
  110.         const armScale = 1.3;
  111.         const chestWidth = 2.6;
  112.         const armInset = -.1;
  113.         const playerScale = (2 * armScale + chestWidth + armInset) / 2;
  114.         const SHOOT = 5, SCOPE = 6, xDr = 3, yDr = 2, JUMP = 7, CROUCH = 8;
  115.         let isEnemy = function(player) {return !me.team || player.team != me.team};
  116.         let canHit = function(player) {return null == world[canSee](me, player.x3, player.y3 - player.crouchVal * crouchDst, player.z3)};
  117.         let normaliseYaw = function(yaw) {return (yaw % Math.PI2 + Math.PI2) % Math.PI2;};
  118.         let getDir = function(a, b, c, d) {
  119.             return Math.atan2(b - d, a - c);
  120.         };
  121.         let getD3D = function(a, b, c, d, e, f) {
  122.             let g = a - d, h = b - e, i = c - f;
  123.             return Math.sqrt(g * g + h * h + i * i);
  124.         };
  125.         let getXDire = function(a, b, c, d, e, f) {
  126.             let g = Math.abs(b - e), h = getD3D(a, b, c, d, e, f);
  127.             return Math.asin(g / h) * (b > e ? -1 : 1);
  128.         };
  129.  
  130.         let dAngleTo = function(x, y, z) {
  131.             let ty = normaliseYaw(getDir(controls.object.position.z, controls.object.position.x, z, x));
  132.             let tx = getXDire(controls.object.position.x, controls.object.position.y, controls.object.position.z, x, y, z);
  133.             let oy = normaliseYaw(controls.object.rotation.y);
  134.             let ox = controls[pchObjc].rotation.x;
  135.             let dYaw = Math.min(Math.abs(ty - oy), Math.abs(ty - oy - Math.PI2), Math.abs(ty - oy + Math.PI2));
  136.             let dPitch = tx - ox;
  137.             return Math.hypot(dYaw, dPitch);
  138.         };
  139.         let calcAngleTo = function(player) {return dAngleTo(player.x3, player.y3 + playerHeight - (headScale + hitBoxPad) / 2 - player.crouchVal * crouchDst, player.z3);};
  140.         let calcDistanceTo = function(player) {return getD3D(player.x3, player.y3, player.z3, me.x, me.y, me.z)};
  141.         let isCloseEnough = function(player) {let distance = calcDistanceTo(player); return me.weapon.range >= distance && ("Shotgun" != me.weapon.name || distance < 70) && ("Akimbo Uzi" != me.weapon.name || distance < 100);};
  142.         let haveAmmo = function() {return !(me.ammos[me.weaponIndex] !== undefined && me.ammos[me.weaponIndex] == 0);};
  143.  
  144.         // target selector - based on closest to aim
  145.         let closest = null, closestAngle = Infinity;
  146.         let players = world.players.list;
  147.         for (var i = 0; me.active && i < players.length; i++) {
  148.             let e = players[i];
  149.             if (e[isYou] || !e.active || !e[objInstances] || !isEnemy(e)) {
  150.                 continue;
  151.             }
  152.  
  153.             // experimental prediction removed
  154.             e.x3 = e.x;
  155.             e.y3 = e.y;
  156.             e.z3 = e.z;
  157.  
  158.             if (!isCloseEnough(e) || !canHit(e)) {
  159.                 continue;
  160.             }
  161.  
  162.             let angle = calcAngleTo(e);
  163.             if (angle < closestAngle) {
  164.                 closestAngle = angle;
  165.                 closest = e;
  166.             }
  167.         }
  168.         // aimbot
  169.         let ty = controls.object.rotation.y, tx = controls[pchObjc].rotation.x;
  170.         if (closest) {
  171.             let target = closest;
  172.             let y = target.y3 + playerHeight - (headScale/* + hitBoxPad*/) / 2 - target.crouchVal * crouchDst;
  173.             if (me.weapon.nAuto && me.didShoot) {
  174.                 inputs[SHOOT] = 0;
  175.             } else if (!me.aimVal) {
  176.                 inputs[SHOOT] = 1;
  177.                 inputs[SCOPE] = 1;
  178.             } else {
  179.                 inputs[SCOPE] = 1;
  180.             }
  181.  
  182.             ty = getDir(controls.object.position.z, controls.object.position.x, target.z3, target.x3);
  183.             tx = getXDire(controls.object.position.x, controls.object.position.y, controls.object.position.z, target.x3, y, target.z3);
  184.  
  185.             // perfect recoil control
  186.             tx -= .3 * me[recoilAnimY];
  187.         } else {
  188.             inputs[SHOOT] = controls[mouseDownL];
  189.             inputs[SCOPE] = controls[mouseDownR];
  190.         }
  191.  
  192.         // silent aim
  193.         inputs[xDr] = (tx % Math.PI2).round(3);
  194.         inputs[yDr] = (ty % Math.PI2).round(3);
  195.  
  196.         // auto reload
  197.         controls.keys[controls.reloadKey] = !haveAmmo() * 1;
  198.  
  199.         // bhop
  200.         inputs[JUMP] = (controls.keys[controls.jumpKey] && !me.didJump) * 1;
  201.  
  202.         // runs once to set up renders
  203.         if (!window[keyMap['init']]) {
  204.             window[keyMap['init']] = true;
  205.  
  206.             drawVisuals = function(c) {
  207.                 let scalingFactor = arguments.callee.caller.caller.arguments[0];
  208.                 let perspective = arguments.callee.caller.caller.arguments[2];
  209.                 let scaledWidth = c.canvas.width / scalingFactor;
  210.                 let scaledHeight = c.canvas.height / scalingFactor;
  211.                 let worldPosition = perspective.camera.getWorldPosition();
  212.                 for (var i = 0; i < world.players.list.length; i++) {
  213.                     let player = world.players.list[i];
  214.                     let e = players[i];
  215.                     if (e[isYou] || !e.active || !e[objInstances] || !isEnemy(e)) {
  216.                         continue;
  217.                     }
  218.  
  219.                     // the below variables correspond to the 2d box esps corners
  220.                     // note: we can already tell what ymin ymax is
  221.                     let xmin = Infinity;
  222.                     let xmax = -Infinity;
  223.                     let ymin = Infinity;
  224.                     let ymax = -Infinity;
  225.                     let br = false;
  226.                     for (var j = -1; !br && j < 2; j+=2) {
  227.                         for (var k = -1; !br && k < 2; k+=2) {
  228.                             for (var l = 0; !br && l < 2; l++) {
  229.                                 let position = e[objInstances].position.clone();
  230.                                 position.x += j * playerScale;
  231.                                 position.z += k * playerScale;
  232.                                 position.y += l * (playerHeight - e.crouchVal * crouchDst);
  233.                                 if (!perspective.frustum.containsPoint(position)) {
  234.                                     br = true;
  235.                                     break;
  236.                                 }
  237.                                 position.project(perspective.camera);
  238.                                 xmin = Math.min(xmin, position.x);
  239.                                 xmax = Math.max(xmax, position.x);
  240.                                 ymin = Math.min(ymin, position.y);
  241.                                 ymax = Math.max(ymax, position.y);
  242.                             }
  243.                         }
  244.                     }
  245.  
  246.                     if (br) {
  247.                         continue;
  248.                     }
  249.  
  250.                     xmin = (xmin + 1) / 2;
  251.                     ymin = (ymin + 1) / 2;
  252.                     xmax = (xmax + 1) / 2;
  253.                     ymax = (ymax + 1) / 2;
  254.  
  255.  
  256.                     c.save();
  257.                     // save and restore these variables later so they got nothing on us
  258.                     const original_strokeStyle = c.strokeStyle;
  259.                     const original_lineWidth = c.lineWidth;
  260.                     const original_font = c.font;
  261.                     const original_fillStyle = c.fillStyle;
  262.  
  263.                     // perfect box esp
  264.                     c.lineWidth = 5;
  265.                     c.strokeStyle = 'rgba(255,50,50,1)';
  266.  
  267.                     let distanceScale = Math.max(.3, 1 - getD3D(worldPosition.x, worldPosition.y, worldPosition.z, e.x, e.y, e.z) / 600);
  268.                     c.scale(distanceScale, distanceScale);
  269.                     let xScale = scaledWidth / distanceScale;
  270.                     let yScale = scaledHeight / distanceScale;
  271.  
  272.                     c.beginPath();
  273.                     ymin = yScale * (1 - ymin);
  274.                     ymax = yScale * (1 - ymax);
  275.                     xmin = xScale * xmin;
  276.                     xmax = xScale * xmax;
  277.                     c.moveTo(xmin, ymin);
  278.                     c.lineTo(xmin, ymax);
  279.                     c.lineTo(xmax, ymax);
  280.                     c.lineTo(xmax, ymin);
  281.                     c.lineTo(xmin, ymin);
  282.                     c.stroke();
  283.  
  284.                     // health bar
  285.                     c.fillStyle = "rgba(255,50,50,1)";
  286.                     let barMaxHeight = ymax - ymin;
  287.                     c.fillRect(xmin - 7, ymin, -10, barMaxHeight);
  288.                     c.fillStyle = "#00FFFF";
  289.                     c.fillRect(xmin - 7, ymin, -10, barMaxHeight * (e.health / e.maxHealth));
  290.  
  291.                     // info
  292.                     c.font = "60px Sans-serif";
  293.                     c.fillStyle = "white";
  294.                     c.strokeStyle='black';
  295.                     c.lineWidth = 1;
  296.                     let x = xmax + 7;
  297.                     let y = ymax;
  298.                     c.fillText(e.name, x, y);
  299.                     c.strokeText(e.name, x, y);
  300.                     c.font = "30px Sans-serif";
  301.                     y += 35;
  302.                     c.fillText(e.weapon.name, x, y);
  303.                     c.strokeText(e.weapon.name, x, y);
  304.                     y += 35;
  305.                     c.fillText(e.health + ' HP', x, y);
  306.                     c.strokeText(e.health + ' HP', x, y);
  307.  
  308.                     c.strokeStyle = original_strokeStyle;
  309.                     c.lineWidth = original_lineWidth;
  310.                     c.font = original_font;
  311.                     c.fillStyle = original_fillStyle;
  312.                     c.restore();
  313.  
  314.                     // skelly chams
  315.                     // note: this can be done better
  316.                     if (e.legMeshes[0]) {
  317.                         let material = e.legMeshes[0].material;
  318.                         material.alphaTest = 1;
  319.                         material.depthTest = false;
  320.                         material.fog = false;
  321.                         material.emissive.r = 1;
  322.                         material.emissive.g = 1;
  323.                         material.emissive.b = 1;
  324.                         material.wireframe = true;
  325.                     }
  326.  
  327.                 }
  328.             };
  329.         };
  330.     };
  331.     keyMap['hrtCheat'] = genKey();
  332.     global_invisible_define(keyMap['hrtCheat'], hrtCheat);
  333.  
  334.     const handler = {
  335.       construct(target, args) {
  336.         // ttap#4547
  337.         if (args.length == 2 && args[1].length > 1337) {
  338.             let script = args[1];
  339.  
  340.             // anti anti chet & anti skid
  341.             const version = script.match(/\w+\['exports'\]=(0[xX][0-9a-fA-F]+);/)[1];
  342.             if (version !== "0x597b") {
  343.                 window[atob('ZG9jdW1lbnQ=')][atob('d3JpdGU=')](atob('VmVyc2lvbiBtaXNzbWF0Y2gg') + version);
  344.                 window[atob('bG9jYX'+'Rpb24'+'=')][atob('aHJ'+'lZg='+'=')] = atob('aHR0cHM6'+'Ly9naXRodWIuY2'+'9tL2hydC93aGVlb'+'GNoYWly');
  345.             }
  346.  
  347.             var canSee = "'"+script.match(/,this\['(\w+)'\]=function\(\w+,\w+,\w+,\w+,\w+\){if\(!\w+\)return!\w+;/)[1]+"'";
  348.             var pchObjc = "'"+script.match(/\(\w+,\w+,\w+\),this\['(\w+)'\]=new \w+\['\w+'\]\(\)/)[1]+"'";
  349.             var objInstances = "'"+script.match(/\[\w+\]\['\w+'\]=!\w+,this\['\w+'\]\[\w+\]\['\w+'\]&&\(this\['\w+'\]\[\w+\]\['(\w+)'\]\['\w+'\]=!\w+/)[1]+"'";
  350.             var isYou = "'"+script.match(/,this\['\w+'\]=!\w+,this\['\w+'\]=!\w+,this\['(\w+)'\]=\w+,this\['\w+'\]\['length'\]=\w+,this\[/)[1]+"'";
  351.             var recoilAnimY = "'"+script.match(/\w*1,this\['\w+'\]=\w*0,this\['\w+'\]=\w*0,this\['\w+'\]=\w*1,this\['\w+'\]=\w*1,this\['\w+'\]=\w*0,this\['\w+'\]=\w*0,this\['(\w+)'\]=\w*0,this\['\w+'\]=\w*0,this\['\w+'\]=\w*0,this\['\w+'\]=\w*0,/)[1]+"'";
  352.             var mouseDownL = "'"+script.match(/this\['\w+'\]=function\(\){this\['(\w+)'\]=\w*0,this\['(\w+)'\]=\w*0,this\['\w+'\]={}/)[1]+"'";
  353.             var mouseDownR = "'"+script.match(/this\['\w+'\]=function\(\){this\['(\w+)'\]=\w*0,this\['(\w+)'\]=\w*0,this\['\w+'\]={}/)[2]+"'";
  354.  
  355.             var inputs = script.match(/\(\w+,\w*1\)\),\w+\['\w+'\]=\w*0,\w+\['\w+'\]=\w*0,!(\w+)\['\w+'\]&&\w+\['\w+'\]\['push'\]\((\w+)\),(\w+)\['\w+'\]/)[2];
  356.             var world = script.match(/\(\w+,\w*1\)\),\w+\['\w+'\]=\w*0,\w+\['\w+'\]=\w*0,!(\w+)\['\w+'\]&&\w+\['\w+'\]\['push'\]\((\w+)\),(\w+)\['\w+'\]/)[1];
  357.             var consts = script.match(/\w+\['\w+'\]\),\w+\['\w+'\]\(\w+\['\w+'\],\w+\['\w+'\]\+\w+\['\w+'\]\*(\w+)/)[1];
  358.             var me = script.match(/\(\w+,\w*1\)\),\w+\['\w+'\]=\w*0,\w+\['\w+'\]=\w*0,!(\w+)\['\w+'\]&&\w+\['\w+'\]\['push'\]\((\w+)\),(\w+)\['\w+'\]/)[3];
  359.             var math = script.match(/\\x20\-50\%\)\\x20rotate\('\+\((\w+)\['\w+'\]\(\w+\[\w+\]\['\w+'\]/)[1];
  360.  
  361.  
  362.             const code_to_overwrite = script.match(/(\w+\['\w+'\]&&\(\w+\['\w+'\]=\w+\['\w+'\],!\w+\['\w+'\]&&\w+\['\w+'\]\(\w+,\w*1\)\),\w+\['\w+'\]=\w*0,\w+\['\w+'\]=\w*0),!\w+\['\w+'\]&&\w+\['\w+'\]\['push'\]\(\w+\),\w+\['\w+'\]\(\w+,\w+,!\w*1,\w+\['\w+'\]\)/)[1];
  363.             const ttapParams = [me, inputs, world, consts, math, canSee, pchObjc, objInstances, isYou, recoilAnimY, mouseDownL, mouseDownR].toString();
  364.             let call_hrt = `window['` + keyMap['hrtCheat'] + `'](` + ttapParams + `)`;
  365.  
  366.             /*
  367.                 pad to avoid stack trace line number detections
  368.                 the script will have the same length as it originally had
  369.             */
  370.             while (call_hrt.length < code_to_overwrite.length) {
  371.                 call_hrt += ' ';
  372.             }
  373.  
  374.             const hooked_call = Function.prototype.call;
  375.             Function.prototype.call = original_call;
  376.             /* the bIg mod */
  377.             script = replace.call(script, code_to_overwrite, call_hrt);
  378.  
  379.             /* Below are some misc features which I wouldn't consider bannable, third party clients could be using them */
  380.             // all weapons trails on
  381.             script = replace.call(script, /\w+\['weapon'\]&&\w+\['weapon'\]\['trail'\]/g, "true")
  382.  
  383.             // color blind mode
  384.             script = replace.call(script, /#9eeb56/g, '#00FFFF');
  385.  
  386.             // no zoom
  387.             script = replace.call(script, /,'zoom':.+?(?=,)/g, ",'zoom':1");
  388.  
  389.             // script = replace.call(script, /(void this\['sendQueue'\]\['push'\]\(\[(\w+),(\w+)\]\);)/, '$1_[$2]=$3;');
  390.             Function.prototype.call = hooked_call;
  391.             /***********************************************************************************************************/
  392.  
  393.             // bypass modification check of returned function
  394.             const original_script = args[1];
  395.             args[1] = script;
  396.             let mod_fn = new target(...args);
  397.             args[1] = original_script;
  398.             let original_fn = new target(...args);
  399.             conceal_function(original_fn, mod_fn);
  400.             return mod_fn;
  401.         }
  402.         return new target(...args);
  403.       }
  404.     };
  405.  
  406.     // we intercept game.js at the `Function` generation level
  407.     const original_Function = Function;
  408.     let hook_Function = new Proxy(Function, handler);
  409.     conceal_function(original_Function, hook_Function);
  410.     Function = hook_Function;
  411. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement