Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.01 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Stone & Water
  3. // @description A Krunker.io Hack Script (Aimbot, ESP, And More!)
  4. // @version 2.2
  5. // @author hacker
  6. // @include /^(https?:\/\/)?(www\.)?(.+)krunker\.io(|\/|\/\?.+)$/
  7. // @grant none
  8. // @run-at document-start
  9. // ==/UserScript==
  10.  
  11. const Struct = (...keys) => ((...v) => keys.reduce((o, k, i) => {
  12. o[k] = v[i];
  13. return o
  14. }, {}))
  15. const feature = Struct('name', 'hotkey', 'value', 'valueStr', 'container', 'updated')
  16. class Utilities {
  17. constructor() {
  18. this.inputs;
  19. this.exports;
  20. this.control;
  21. this.functions
  22. this.self;
  23. this.settings = {
  24. scopingOut: false,
  25. canShoot: true,
  26. targetCoolDown: 500,
  27. weaponIndex: 0,
  28. };
  29. this.features = [];
  30. this.onLoad();
  31. }
  32.  
  33. onLoad() {
  34. this.createInfoBox();
  35. this.features.push(feature('Aimbot', "1", -1, null, ['Off', 'On'], true));
  36. this.features.push(feature('AutoBhop', "2", -1, null, ['Off', 'Auto Jump', 'Auto SlideJump'], true));
  37. this.features.push(feature('NoRecoil', "3", -1, null, [], true));
  38. window.addEventListener("keydown", event => this.onKeyDown(event));
  39. }
  40.  
  41. onTick() {
  42. this.features.forEach((feature, index, array) => {
  43. // On Updated State
  44. if (feature.updated) {
  45. feature.updated = false;
  46. if (feature.container.length !== 0) {
  47. if (feature.value == -1) {
  48. feature.value = parseInt(window.getSavedVal(`utilities_${feature.name}`) || 0);
  49. console.log(`${feature.name} set from saved value ${feature.value}`);
  50. }
  51. else {
  52. feature.value += 1;
  53. if (feature.value > feature.container.length - 1)
  54. feature.value = 0;
  55. }
  56. feature.valueStr = feature.container[feature.value];
  57. } else {
  58. if (feature.value == -1) {
  59. feature.value = parseInt(window.getSavedVal(`utilities_${feature.name}`) || 0);
  60. console.log(`${feature.name} set from saved value ${feature.value}`);
  61. }
  62. else
  63. feature.value ^= 1;
  64. feature.valueStr = feature.value ? "true" : "false";
  65. }
  66. this.onUpdated(feature);
  67. }
  68. // OnTick State
  69. switch (feature.name) {
  70. case 'Aimbot':this.Aimbot(feature.value);break;
  71. case 'NoRecoil':if (feature.value)this.self.recoilTweenY = 0;break;
  72. case 'AutoBhop': this.AutoBhop(feature.value);break;
  73. }
  74. });
  75. }
  76.  
  77. onUpdated(feature) {
  78. window.saveVal(`utilities_${feature.name}`, feature.value);
  79. this.updateInfoBox();
  80. }
  81.  
  82. getName(str) {
  83. return str.replace(/([A-Z])/g, (match) => match).replace(/^./, (match) => match.toUpperCase());
  84. }
  85.  
  86. createInfoBox() {
  87. const infoBox = document.createElement('div');
  88. infoBox.innerHTML = '<div> </div>'.trim();
  89. const leaderDisplay = document.querySelector('#leaderDisplay');
  90. leaderDisplay.parentNode.insertBefore(infoBox.firstChild, leaderDisplay.nextSibling);
  91. }
  92.  
  93. updateInfoBox() {
  94. const infoBox = document.querySelector('#InfoBox');
  95. if (infoBox === null) {
  96. return;
  97. }
  98. const lines = this.features.map(feature => {
  99. return '<div class="leaderItem"> <div class="leaderNameF">[' + feature.hotkey.toUpperCase() + ']' + this.getName(feature.name) + '</div> <div class="leaderScore">' + feature.valueStr + '</div> </div>';
  100. });
  101. infoBox.innerHTML = '<div class="utilitiesTitle">axthny</div>' + lines.join('').trim();
  102. }
  103.  
  104. onKeyDown(event) {
  105. const key = event.key.toUpperCase();
  106. if (document.activeElement.tagName !== "INPUT") {
  107. if ('0' === key) {
  108. const menu = document.getElementById("InfoBox");
  109. if (menu) {
  110. menu.style.display = !menu.style.display || menu.style.display === "inline-block" ? "none" : "inline-block";
  111. }
  112. }
  113. else if ('DELETE' === key) {
  114. this.resetSettings();
  115. }
  116. else {
  117. this.features.forEach((feature, index, array) => {
  118. feature.updated = feature.hotkey.toUpperCase() === key;
  119. });
  120. }
  121. }
  122. }
  123.  
  124. getDistance3D(fromX, fromY, fromZ, toX, toY, toZ) {
  125. var distX = fromX - toX,
  126. distY = fromY - toY,
  127. distZ = fromZ - toZ;
  128. return Math.sqrt(distX * distX + distY * distY + distZ * distZ)
  129. }
  130.  
  131. getDistance(player1, player2) {
  132. return this.getDistance3D(player1.x, player1.y, player1.z, player2.x, player2.y, player2.z);
  133. }
  134.  
  135. getDirection(fromZ, fromX, toZ, toX) {
  136. return Math.atan2(fromX - toX, fromZ - toZ)
  137. }
  138.  
  139. getXDir(fromX, fromY, fromZ, toX, toY, toZ) {
  140. var dirY = Math.abs(fromY - toY),
  141. dist = this.getDistance3D(fromX, fromY, fromZ, toX, toY, toZ);
  142. return Math.asin(dirY / dist) * (fromY > toY ? -1 : 1)
  143. }
  144.  
  145. camLookAt(X, Y, Z) {
  146. var xdir = this.getXDir(this.control.object.position.x, this.control.object.position.y, this.control.object.position.z, X, Y, Z),
  147. ydir = this.getDirection(this.control.object.position.z, this.control.object.position.x, Z, X),
  148. camChaseDst = this.server.camChaseDst;
  149. this.control.target = {
  150. xD: xdir,
  151. yD: ydir,
  152. x: X + this.server.camChaseDst * Math.sin(ydir) * Math.cos(xdir),
  153. y: Y - this.server.camChaseDst * Math.sin(xdir),
  154. z: Z + this.server.camChaseDst * Math.cos(ydir) * Math.cos(xdir)
  155. }
  156. }
  157.  
  158. Aimbot(value) {
  159. if (value == 0) return;
  160. let isLockedOn = false;
  161. const target = this.getTarget();
  162. if (target) {
  163. switch (value) {
  164. case 1:
  165. if (this.control.mouseDownR === 1) {
  166. this.lookAtHead(target);
  167. isLockedOn = true;
  168. }
  169. break;
  170. }
  171. }
  172. if (!isLockedOn) {
  173. this.control.target = null;
  174. if (value !== 1 && this.control.mouseDownR === 1)
  175. this.timeoutHandle = setTimeout(() => {
  176. clearTimeout(this.timeoutHandle);
  177. this.timeoutHandle = null;
  178. this.control.mouseDownR = 0;
  179. }, this.settings.targetCoolDown);
  180. }
  181. }
  182.  
  183. AutoBhop(value) {
  184. if (value == 0) return;
  185. if (value === 2) {
  186. if (this.self.yVel < -0.04 && this.self.canSlide) {
  187. this.inputs[8] = 1;
  188. setTimeout(() => {
  189. this.control.keys[this.control.jumpKey] = 1;
  190. }, 350);
  191. } else
  192. this.control.keys[this.control.jumpKey] = this.self.onGround;
  193. } else if (value === 1)
  194. this.control.keys[this.control.jumpKey] = this.self.onGround;
  195. }
  196.  
  197. resetSettings() {
  198. if (confirm("Are you sure you want to reset all your hero settings? This will also refresh the page")) {
  199. Object.keys(window.localStorage).filter(x=>x.includes("utilities_")).forEach(x => window.localStorage.removeItem(x));
  200. location.reload();
  201. }
  202. }
  203.  
  204. getTarget() {
  205. const enemies = this.world.players.list.filter(x => !x.isYou).filter(x => x.inView && x.objInstances && x.objInstances.visible).filter(x => (!x.team || (x.team !== this.self.team))).filter(x => x.active).sort(this.functions.orderByDst);
  206. for (const cunt of enemies) {
  207. if (this.self.dmgReceived[cunt.id]) return cunt;
  208. }
  209. return enemies[0];
  210. }
  211.  
  212. lookAtHead(target) {
  213. this.camLookAt(target.x2, target.y2 + target.height - 1.5 - 2.5 * target.crouchVal - this.self.recoilAnimY * 0.3 * this.getDistance(this.self, target) / 10, target.z2);
  214. }
  215.  
  216. inputsTick(self, inputs, world) {
  217. //Hooked
  218. if (this.control && this.exports && self && inputs && world) {
  219. this.inputs = inputs;
  220. this.world = world;
  221. this.self = self;
  222. this.server = this.exports.c[7].exports;
  223. this.functions = this.exports.c[8].exports;
  224. this.onTick();
  225. }
  226. }
  227.  
  228. controlTick(control) {
  229. //Hooked
  230. if (control) {
  231. this.control = control;
  232. const half = Math.PI / 2;
  233. if (control.target) {
  234. control.yDr = control.target.xD % Math.PI;
  235. control.xDr = control.target.yD % Math.PI;
  236. }
  237. }
  238. }
  239. }
  240. function read(url) {
  241. return new Promise(resolve => {
  242. fetch(url).then(res => res.text()).then(res => {
  243. return resolve(res);
  244. });
  245. });
  246. }
  247.  
  248. function patch(source, method, regex, replacer) {
  249. const patched = source.replace(regex, replacer);
  250. if (source === patched) {
  251. alert(`Failed to patch ${method}`);
  252. } else console.log("Successfully patched ", method);
  253. return patched;
  254. }
  255.  
  256. function patchedIndex(html) {
  257. html = patch(html, "html_scriptBlock", /(<script src=".*?game.*?")(><\/script>)/, '$1 type="javascript/blocked" $2');
  258. html = patch(html, "html_payPal", /<script src=".*?paypal.*?"><\/script>/, '');
  259. return html;
  260. }
  261.  
  262. function patchedScript(script) {
  263. script = patch(script, 'WallHack', /if\(!tmpObj\['inView']\)continue;/, ``);
  264. script = patch(script, "Exports", /\['__CANCEL__']=!(\w+),(\w+)\['exports']=(\w+);},function\((\w+),(\w+),(\w+)\){let/, `['__CANCEL__']=!$1,$2['exports']=$3;},function($4,$5,$6){window.utilities=new Utilities();window.utilities.exports=$6;let`);
  265. script = patch(script, 'ProcInput', /this\['procInputs']=function\((\w+),(\w+),(\w+)\){/, `this['procInputs']=function($1,$2,$3){window.utilities.inputsTick(this,$1,$2);`);
  266. script = patch(script, 'ControlTick', /{if\(this\['target']\){(.+?)}},this\['(\w+)']=/, `{window.utilities.controlTick(this);},this['$2']=`);
  267. 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'])`);
  268. return script;
  269. }
  270.  
  271. (async function () {
  272. const index = await read(document.location.href);
  273. const build = index.match(/(?<=build=)[^"]+/)[0];
  274. const patch = index.match(/"SOUND.play\(.+\)">v(.+)</)[1];
  275. const script = await read(`/js/game.${build}.js`);
  276. //window.stop();
  277. document.open();
  278. document.write(patchedIndex(index));
  279. document.close();
  280. try {
  281. eval(patchedScript(script));
  282. } catch (err) {
  283. location.reload();
  284. }
  285. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement