Document

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 18

// ==UserScript==

// @name Krunker Hero Utilities Cheat ✔Working on == UPDATE 1.6.3 ==

// @namespace SkidLamer

// @version 1.1.7

// @description A Krunker.io Cheat

// @author SkidLamer

// @match *://krunker.io/*

// @grant none

// @run-at document-start

// ==/UserScript==

const cStruct = (...keys) => ((...v) => keys.reduce((o, k, i) => {o[k] = v[i];return o}, {}))

class Utilities {

constructor() {

this.inputs;

this.exports;

this.control;

this.functions;

this.wpnClasses;

this.self;

this.settings = {

scopingOut: false,

canShoot: true,

targetCoolDown: 600,

weaponIndex: 0,
isSliding: false,

};

this.spinTimer = 1800;

this.features = [];

this.onLoad();

onLoad() {

this.newFeature('AutoAim', "1", ['Off', 'Aim Assist', 'Aim Bot', 'Trigger Bot']);

this.newFeature('AutoBhop', "2", ['Off', 'Auto Jump', 'Auto SlideJump']);

this.newFeature('AutoReload', "3", []);

this.newFeature('NoRecoil', "4", []);

this.newFeature('AimDelta', "5", ['Off', 'Slow', 'Medium', 'Fast', 'MethHead']);

this.newFeature('BurstShot', "6", []);

this.newFeature('ForceScope', "7", []);

this.newFeature('NoDeathDelay', "8", []);

this.newFeature('SuperGun', '9', []);

this.newFeature('SpinBot', '0', []);

window.addEventListener("keydown", event => this.onKeyDown(event));

const interval = setInterval(() => {

if (document.querySelector('#leaderDisplay') !== null) {

clearInterval(interval);

this.createInfoBox();

}, 100);
}

onTick() {

for (var i = 0, sz = this.features.length; i < sz; i++) {

const feature = this.features[i];

switch (feature.name) {

case 'AutoAim':

if (feature.value) this.AutoAim(feature.value);

break;

case 'AutoReload':

if (feature.value) this.wpnReload();

break;

case 'NoRecoil':

if (feature.value) this.self.recoilTweenY = this.self.recoilForce = 0;

break;

case 'AimDelta':

this.world.config.deltaMlt = this.control.mouseDownR === 0 || feature.value === 0 ?


1 : feature.value === 1 ? .5 : feature.value === 2 ? .75 : feature.value === 3 ? 1.5 : feature.value
=== 4 ? 2 : 1;

break;

case 'SuperGun':

if (feature.value) {

this.settings.weaponIndex += this.control.mouseDownL == 1;

if (this.settings.weaponIndex > this.world.weapons.length - 3)


this.settings.weaponIndex = 0;

this.self.weapon = this.world.weapons[this.settings.weaponIndex];

}
break;

case 'BurstShot':

if (feature.value) this.self.weapon.shots = this.self.weapon.ammo;

break;

case 'AutoBhop':

if (feature.value) this.AutoBhop(feature.value);

break;

case 'NoDeathDelay':

if (feature.value && this.self && this.self.health === 0) {

this.server.deathDelay = 0;

this.world.players.forcePos();

//this.world.players.resetAim();

//this.world.updateUI();

break;

this.server.viewDist = 5000; // 2000 default

this.world.config.impulseMlt = 3; //1 default / max 3

for (i = 0, sz = this.wpnClasses.length; i < sz; i++) {

this.wpnClasses[i].speed = 1.05; // 1.05 max

onUpdated(feature) {
if (feature.container.length) {

feature.value += 1;

if (feature.value > feature.container.length - 1) {

feature.value = 0;

feature.valueStr = feature.container[feature.value];

else

feature.value ^= 1;

feature.valueStr = feature.value ? "true" : "false";

switch (feature.name) {

case 'ForceScope':

feature.value || this.self.weapon.name === "Sniper Rifle" || this.self.weapon.name ===


"Semi Auto" ? this.self.weapon.scope = 1 : delete this.self.weapon.scope;

break;

window.saveVal(`utilities_${feature.name}`, feature.value);

this.updateInfoBox();

getStatic(s, d) {

if(typeof s == 'undefined') {

return d;

}
return s;

newFeature(name, key, array) {

const feature = cStruct('name', 'hotkey', 'value', 'valueStr', 'container')

const value = parseInt(window.getSavedVal(`utilities_${name}`) || 0);

this.features.push(feature(name, key, value, array.length ? array[value] : value ? "true" :


"false", array));

getFeature(name) {

for (const feature of this.features) {

if (feature.name.toLowerCase() === name.toLowerCase()) {

return feature;

return cStruct('name', 'hotkey', 'value', 'valueStr', 'container');

createInfoBox() {

const leaderDisplay = document.querySelector('#leaderDisplay');

if (leaderDisplay) {

var infoBox = document.createElement('div');

if (infoBox) infoBox.innerHTML = '<div> <style> #InfoBox { text-align: left; width: 310px; z-


index: 3; padding: 10px; padding-left: 20px; padding-right: 20px; color: rgba(255, 255, 255, 0.7);
line-height: 25px; margin-top: 0px; background-color: rgba(0, 0, 0, 0.3); } #InfoBox .utilitiesTitle
{ font-size: 16px; font-weight: bold; text-align: center; color: #1A72B8; margin-top: 5px; margin-
bottom: 5px; } #InfoBox .leaderItem { font-size: 14px; } </style> <div id="InfoBox"></div>
</div>'.trim();

leaderDisplay.parentNode.insertBefore(infoBox.firstChild, leaderDisplay.nextSibling);

this.updateInfoBox();

upperCase(str) {

return str.toUpperCase();

toProperCase(str) {

str = str.replace(/([a-z\xE0-\xFF])([A-Z\xC0\xDF])/g, '$1 $2');

str = str.replace(/\s[a-z]/g, this.upperCase)

return str;

updateInfoBox() {

const infoBox = document.querySelector('#InfoBox');

if (infoBox) {

const lines = this.features.map(feature => {

return '<div class="leaderItem"> <div class="leaderNameF">[' +


feature.hotkey.toUpperCase() + '] ' + this.toProperCase(feature.name) + '</div> <div
class="leaderScore">' + feature.valueStr + '</div> </div>';

});

infoBox.innerHTML = '<div class="utilitiesTitle">Krunker Hero</div>' + lines.join('').trim();

}
}

onKeyDown(event) {

if (document.activeElement.tagName === "INPUT") return;

const key = event.key.toUpperCase();

switch (key) {

case 'M': {

const infoBox = document.querySelector('#InfoBox');

if (infoBox) infoBox.style.display = !infoBox.style.display || infoBox.style.display ===


"inline-block" ? "none" : "inline-block";

break;

case 'DELETE':

this.resetSettings();

break;

default:

for (const feature of this.features) {

if (feature.hotkey.toUpperCase() === key) {

this.onUpdated(feature);

break;

getDistance3D(fromX, fromY, fromZ, toX, toY, toZ) {


var distX = fromX - toX,

distY = fromY - toY,

distZ = fromZ - toZ;

return Math.sqrt(distX * distX + distY * distY + distZ * distZ)

getDistance(player1, player2) {

return this.getDistance3D(player1.x, player1.y, player1.z, player2.x, player2.y, player2.z);

getDirection(fromZ, fromX, toZ, toX) {

return Math.atan2(fromX - toX, fromZ - toZ)

getXDir(fromX, fromY, fromZ, toX, toY, toZ) {

var dirY = Math.abs(fromY - toY),

dist = this.getDistance3D(fromX, fromY, fromZ, toX, toY, toZ);

return Math.asin(dirY / dist) * (fromY > toY ? -1 : 1)

getAngleDist(start, end) {

return Math.atan2(Math.sin(end - start), Math.cos(start - end));

camLookAt(X, Y, Z) {
var xdir = this.getXDir(this.control.object.position.x, this.control.object.position.y,
this.control.object.position.z, X, Y, Z),

ydir = this.getDirection(this.control.object.position.z, this.control.object.position.x, Z, X),

camChaseDst = this.server.camChaseDst;

this.control.target = {

xD: xdir,

yD: ydir,

x: X + this.server.camChaseDst * Math.sin(ydir) * Math.cos(xdir),

y: Y - this.server.camChaseDst * Math.sin(xdir),

z: Z + this.server.camChaseDst * Math.cos(ydir) * Math.cos(xdir)

AutoAim(value) {

if (this.self.didShoot) {

setTimeout(() => {

this.self.aimVal = 1;

this.world.players.resetAim();

this.settings.forceScope || this.self.weapon.name === "Sniper Rifle" ||


this.self.weapon.name === "Semi Auto" ? this.self.weapon.scope = 1 : delete
this.self.weapon.scope;

this.settings.canShoot = true;

}, this.self.weapon.rate );

const target = this.getTarget();

if (target) {

switch (value) {
case 1:

/*Aim Assist*/

if (this.control.mouseDownR === 1) {

this.lookAtHead(target);

break;

case 2:

/*Aim Bot*/

this.lookAtHead(target);

if (this.control.mouseDownR === 0) {

this.control.mouseDownR = 1;

break;

case 3:

/*Trigger Bot*/

if (this.control.mouseDownL === 1) {

this.control.mouseDownL = 0;

this.control.mouseDownR = 0;

this.settings.scopingOut = true;

if (this.self.aimVal !== 1 || !this.settings.canShoot || this.self.recoilForce > 0.01 ||


this.control.mouseDownR === 1) {

if (this.control.mouseDownL === 1) {

this.control.mouseDownL =

this.control.mouseDownR = 0;

}
this.control.target = null;

this.lookAtHead(target);

if (this.control.mouseDownR === 0) {

this.control.mouseDownR = 2;

} else if (this.self.aimVal === 0 && this.settings.canShoot) {

this.control.mouseDownL ^= 1;

break;

else {

this.wpnReload(this.getFeature('AutoReload').value &&
this.self.ammos[this.self.weaponIndex] < ((this.self.weapon.ammo / 2) + 1));

this.control.target = null;

if (this.control.mouseDownR === 2) {

setTimeout(() => {

this.control.mouseDownR = 0;

this.settings.canShoot = true;

this.self.aimVal = 1;

}, this.settings.targetCoolDown);

AutoBhop(value) {
if (value) {

this.control.keys[this.control.jumpKey] = this.self.onGround;

if (value === 2) {

if (this.settings.isSliding) {

this.inputs[8] = 1;

return;

if (this.self.yVel < -0.04 && this.self.canSlide) {

this.settings.isSliding = true;

setTimeout(() => {

this.settings.isSliding = false;

}, this.self.slideTimer);

this.inputs[8] = 1;

wpnReload(force = false) {

const ammoLeft = this.self.ammos[this.self.weaponIndex];

if (force || ammoLeft === 0) this.world.players.reload(this.self);

resetSettings() {

if (confirm("Are you sure you want to reset all your hero settings? This will also refresh the
page")) {
Object.keys(window.localStorage).filter(x=>x.includes("utilities_")).forEach(x =>
window.localStorage.removeItem(x));

location.reload();

getTarget() {

const enemies = this.world.players.list

.filter(player => {return player.active && (player.inView || this.self.dmgReceived[player.id])


&& !player.isYou && (!player.team || player.team !== this.self.team);})

.sort((p1, p2) => this.getDistance(this.self, p1) - this.getDistance(this.self, p2));

return enemies.length ? enemies[0] : null;

lookAtHead(target) {

if (this.getFeature("SpinBot").value) this.spinTick();

this.camLookAt(target.x2, target.y2 + target.height - 1.5 - 2.5 * target.crouchVal -


this.self.recoilAnimY * 0.3 * this.getDistance(this.self, target) * 0.6, target.z2);

spinTick() {

//this.world.players.getSpin(this.self);

//this.world.players.saveSpin(this.self, angle);

const last = this.inputs[2];

const angle = this.getAngleDist(this.inputs[2], this.self.xDire);

this.spins = this.getStatic(this.spins, new Array());

this.spinTimer= this.getStatic(this.spinTimer, this.server.spinTimer);


this.serverTickRate = this.getStatic(this.serverTickRate, this.server.serverTickRate);

(this.spins.unshift(angle), this.spins.length > this.spinTimer / this.serverTickRate &&


(this.spins.length = Math.round(this.spinTimer / this.serverTickRate)))

for (var e = 0, i = 0; i < this.spins.length; ++i) e += this.spins[i];

const count = Math.abs(e * (180 / Math.PI));

if (count < 360) { this.inputs[2] = this.self.xDire + Math.PI; }

else console.log('count', count);

inputsTick(self, inputs, world) {

//Hooked

if (this.control && this.exports && self && inputs && world) {

this.inputs = inputs;

this.world = world;

this.self = self;

this.server = this.exports.c[7].exports;

this.functions = this.exports.c[8].exports;

this.wpnClasses = this.exports.c[69].exports;

this.onTick();

controlTick(control) {

//Hooked

if (control) {

this.control = control;
const half = Math.PI / 2;

if (control.target) {

control.object.rotation.y = control.target.yD;

control.pitchObject.rotation.x = control.target.xD;

control.pitchObject.rotation.x = Math.max(-half, Math.min(half,


control.pitchObject.rotation.x));

control.yDr = control.pitchObject.rotation.x % Math.PI;

control.xDr = control.object.rotation.y % Math.PI;

function read(url) {

return new Promise(resolve => {

fetch(url).then(res => res.text()).then(res => {

return resolve(res);

});

});

function patch(source, method, regex, replacer) {

const patched = source.replace(regex, replacer);

if (source === patched) {

alert(`Failed to patch ${method}`);

} else console.log("Successfully patched ", method);


return patched;

function patchedIndex(html) {

html = patch(html, "html_scriptBlock", /(<script src=".*?game.*?")(><\/script>)/, '$1


type="javascript/blocked" $2');

html = patch(html, "html_payPal", /<script src=".*?paypal.*?"><\/script>/, '');

return html;

function patchedScript(script) {

script = patch(script, "IsHacker", /&&(\w+)\['isHacker']&&/, `&&!1&&`);

script = patch(script, "LastHack", /&&(\w+)\['lastHack']&&/, `&&!1&&`);

script = patch(script, 'WallHack', /if\(!tmpObj\['inView']\)continue;/, ``);

script = patch(script, 'Socket', /('connect':function\((\w+),(\w+),(\w+)\){if\(!this\['(\w+)']\){)/,


`$1 window.utilities.socket=this;`);

script = patch(script, "Exports", /(\['__CANCEL__']=!(\w+),(\w+)\['exports']=(\w+);},function\


((\w+),(\w+),(\w+)\){)(let)/, `$1window.utilities = new Utilities();window.utilities.exports=$7;$8`);

script = patch(script, 'ControlTick', /{if\(this\['target']\){(.+?)}},this\['(\w+)']=/,


`{window.utilities.controlTick(this);},this['$2']=`);

script = patch(script, 'ControlFix', /&&\((\w+)\[('\w+')]\((\w+)\['x'],(\w+)\['y']\+(\w+)\['height']-


(\w+)\['cameraHeight'],(\w+)\['z']\)/, `&&(utilities.camLookAt($3.x,$3.y+$3.height-
$6.cameraHeight,$3.z)`);

script = patch(script, "HasServer", /(this\['hasServer']=)(\w+)\?(\w+):(\w+)/, `$1 $2 =


utilities.socket`);

script = patch(script, 'ProcInput', /this\['procInputs']=function\((\w+),(\w+),(\w+)\){/,


`this['procInputs']=function($1,$2,$3){window.utilities.inputsTick(this,$1,$2);`);

return script;

}
(async function () {

const index = await read(document.location.href);

const build = index.match(/(?<=build=)[^"]+/)[0];

const patch = index.match(/"SOUND.play\(.+\)">v(.+)</)[1];

const script = await read(`/js/game.${build}.js`);

console.log('Loading Krunker Hero ...');

window.stop();

document.open();

document.write(patchedIndex(index));

document.close();

try {

eval(patchedScript(script));

} catch (err) {

alert("Failed Injecting Script.'OK' to ReLoad.");

location.reload();

console.log('Successfully loaded Krunker Hero!');

})();

You might also like