Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.98 KB | None | 0 0
  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. // silent aim
  169. inputs[xDr] = (tx % Math.PI2).round(3);
  170. inputs[yDr] = (ty % Math.PI2).round(3);
  171.  
  172. // auto reload
  173. controls.keys[controls.reloadKey] = !haveAmmo() * 1;
  174.  
  175. // bhop
  176. inputs[JUMP] = (controls.keys[controls.jumpKey] && !me.didJump) * 1;
  177.  
  178. // runs once to set up renders
  179. if (!window[keyMap['init']]) {
  180. window[keyMap['init']] = true;
  181.  
  182. drawVisuals = function(c) {
  183. let scalingFactor = arguments.callee.caller.caller.arguments[0];
  184. let perspective = arguments.callee.caller.caller.arguments[2];
  185. let scaledWidth = c.canvas.width / scalingFactor;
  186. let scaledHeight = c.canvas.height / scalingFactor;
  187. let worldPosition = perspective.camera.getWorldPosition();
  188. for (var i = 0; i < world.players.list.length; i++) {
  189. let player = world.players.list[i];
  190. let e = players[i];
  191. if (e[isYou] || !e.active || !e[objInstances] || !isEnemy(e)) {
  192. continue;
  193. }
  194.  
  195. // the below variables correspond to the 2d box esps corners
  196. // note: we can already tell what ymin ymax is
  197. let xmin = Infinity;
  198. let xmax = -Infinity;
  199. let ymin = Infinity;
  200. let ymax = -Infinity;
  201. let br = false;
  202. for (var j = -1; !br && j < 2; j+=2) {
  203. for (var k = -1; !br && k < 2; k+=2) {
  204. for (var l = 0; !br && l < 2; l++) {
  205. let position = e[objInstances].position.clone();
  206. position.x += j * playerScale;
  207. position.z += k * playerScale;
  208. position.y += l * (playerHeight - e.crouchVal * crouchDst);
  209. if (!perspective.frustum.containsPoint(position)) {
  210. br = true;
  211. break;
  212. }
  213. position.project(perspective.camera);
  214. xmin = Math.min(xmin, position.x);
  215. xmax = Math.max(xmax, position.x);
  216. ymin = Math.min(ymin, position.y);
  217. ymax = Math.max(ymax, position.y);
  218. }
  219. }
  220. }
  221.  
  222. if (br) {
  223. continue;
  224. }
  225.  
  226. xmin = (xmin + 1) / 2;
  227. ymin = (ymin + 1) / 2;
  228. xmax = (xmax + 1) / 2;
  229. ymax = (ymax + 1) / 2;
  230.  
  231.  
  232. c.save();
  233. // save and restore these variables later so they got nothing on us
  234. const original_strokeStyle = c.strokeStyle;
  235. const original_lineWidth = c.lineWidth;
  236. const original_font = c.font;
  237. const original_fillStyle = c.fillStyle;
  238.  
  239. // perfect box esp
  240. c.lineWidth = 5;
  241. c.strokeStyle = 'rgba(255,50,50,1)';
  242.  
  243. let distanceScale = Math.max(.3, 1 - getD3D(worldPosition.x, worldPosition.y, worldPosition.z, e.x, e.y, e.z) / 600);
  244. c.scale(distanceScale, distanceScale);
  245. let xScale = scaledWidth / distanceScale;
  246. let yScale = scaledHeight / distanceScale;
  247.  
  248. c.beginPath();
  249. ymin = yScale * (1 - ymin);
  250. ymax = yScale * (1 - ymax);
  251. xmin = xScale * xmin;
  252. xmax = xScale * xmax;
  253. c.moveTo(xmin, ymin);
  254. c.lineTo(xmin, ymax);
  255. c.lineTo(xmax, ymax);
  256. c.lineTo(xmax, ymin);
  257. c.lineTo(xmin, ymin);
  258. c.stroke();
  259.  
  260. // health bar
  261. c.fillStyle = "rgba(255,50,50,1)";
  262. let barMaxHeight = ymax - ymin;
  263. c.fillRect(xmin - 7, ymin, -10, barMaxHeight);
  264. c.fillStyle = "#00FFFF";
  265. c.fillRect(xmin - 7, ymin, -10, barMaxHeight * (e.health / e.maxHealth));
  266.  
  267. // info
  268. c.font = "60px Sans-serif";
  269. c.fillStyle = "white";
  270. c.strokeStyle='black';
  271. c.lineWidth = 1;
  272. let x = xmax + 7;
  273. let y = ymax;
  274. c.fillText(e.name, x, y);
  275. c.strokeText(e.name, x, y);
  276. c.font = "30px Sans-serif";
  277. y += 35;
  278. c.fillText(e.weapon.name, x, y);
  279. c.strokeText(e.weapon.name, x, y);
  280. y += 35;
  281. c.fillText(e.health + ' HP', x, y);
  282. c.strokeText(e.health + ' HP', x, y);
  283.  
  284. c.strokeStyle = original_strokeStyle;
  285. c.lineWidth = original_lineWidth;
  286. c.font = original_font;
  287. c.fillStyle = original_fillStyle;
  288. c.restore();
  289.  
  290. // skelly chams
  291. // note: this can be done better
  292. if (e.legMeshes[0]) {
  293. let material = e.legMeshes[0].material;
  294. material.alphaTest = 1;
  295. material.depthTest = false;
  296. material.fog = false;
  297. material.emissive.r = 1;
  298. material.emissive.g = 1;
  299. material.emissive.b = 1;
  300. material.wireframe = true;
  301. }
  302.  
  303. }
  304. };
  305. };
  306. };
  307. keyMap['hrtCheat'] = genKey();
  308. global_invisible_define(keyMap['hrtCheat'], hrtCheat);
  309.  
  310. const handler = {
  311. construct(target, args) {
  312. // ttap#4547
  313. if (args.length == 2 && args[1].length > 1337) {
  314. let script = args[1];
  315.  
  316. // anti anti chet & anti skid
  317. const version = script.match(/\w+\['exports'\]=(0[xX][0-9a-fA-F]+);/)[1];
  318. if (version !== "0x597b") {
  319. window[atob('ZG9jdW1lbnQ=')][atob('d3JpdGU=')](atob('VmVyc2lvbiBtaXNzbWF0Y2gg') + version);
  320. window[atob('bG9jYX'+'Rpb24'+'=')][atob('aHJ'+'lZg='+'=')] = atob('aHR0cHM6'+'Ly9naXRodWIuY2'+'9tL2hydC93aGVlb'+'GNoYWly');
  321. }
  322.  
  323. var canSee = "'"+script.match(/,this\['(\w+)'\]=function\(\w+,\w+,\w+,\w+,\w+\){if\(!\w+\)return!\w+;/)[1]+"'";
  324. var pchObjc = "'"+script.match(/\(\w+,\w+,\w+\),this\['(\w+)'\]=new \w+\['\w+'\]\(\)/)[1]+"'";
  325. var objInstances = "'"+script.match(/\[\w+\]\['\w+'\]=!\w+,this\['\w+'\]\[\w+\]\['\w+'\]&&\(this\['\w+'\]\[\w+\]\['(\w+)'\]\['\w+'\]=!\w+/)[1]+"'";
  326. var isYou = "'"+script.match(/,this\['\w+'\]=!\w+,this\['\w+'\]=!\w+,this\['(\w+)'\]=\w+,this\['\w+'\]\['length'\]=\w+,this\[/)[1]+"'";
  327. 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]+"'";
  328. var mouseDownL = "'"+script.match(/this\['\w+'\]=function\(\){this\['(\w+)'\]=\w*0,this\['(\w+)'\]=\w*0,this\['\w+'\]={}/)[1]+"'";
  329. var mouseDownR = "'"+script.match(/this\['\w+'\]=function\(\){this\['(\w+)'\]=\w*0,this\['(\w+)'\]=\w*0,this\['\w+'\]={}/)[2]+"'";
  330.  
  331. var inputs = script.match(/\(\w+,\w*1\)\),\w+\['\w+'\]=\w*0,\w+\['\w+'\]=\w*0,!(\w+)\['\w+'\]&&\w+\['\w+'\]\['push'\]\((\w+)\),(\w+)\['\w+'\]/)[2];
  332. var world = script.match(/\(\w+,\w*1\)\),\w+\['\w+'\]=\w*0,\w+\['\w+'\]=\w*0,!(\w+)\['\w+'\]&&\w+\['\w+'\]\['push'\]\((\w+)\),(\w+)\['\w+'\]/)[1];
  333. var consts = script.match(/\w+\['\w+'\]\),\w+\['\w+'\]\(\w+\['\w+'\],\w+\['\w+'\]\+\w+\['\w+'\]\*(\w+)/)[1];
  334. var me = script.match(/\(\w+,\w*1\)\),\w+\['\w+'\]=\w*0,\w+\['\w+'\]=\w*0,!(\w+)\['\w+'\]&&\w+\['\w+'\]\['push'\]\((\w+)\),(\w+)\['\w+'\]/)[3];
  335. var math = script.match(/\\x20\-50\%\)\\x20rotate\('\+\((\w+)\['\w+'\]\(\w+\[\w+\]\['\w+'\]/)[1];
  336.  
  337.  
  338. 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];
  339. const ttapParams = [me, inputs, world, consts, math, canSee, pchObjc, objInstances, isYou, recoilAnimY, mouseDownL, mouseDownR].toString();
  340. let call_hrt = `window['` + keyMap['hrtCheat'] + `'](` + ttapParams + `)`;
  341.  
  342. /*
  343. pad to avoid stack trace line number detections
  344. the script will have the same length as it originally had
  345. */
  346. while (call_hrt.length < code_to_overwrite.length) {
  347. call_hrt += ' ';
  348. }
  349.  
  350. const hooked_call = Function.prototype.call;
  351. Function.prototype.call = original_call;
  352. /* the bIg mod */
  353. script = replace.call(script, code_to_overwrite, call_hrt);
  354.  
  355. /* Below are some misc features which I wouldn't consider bannable, third party clients could be using them */
  356. // all weapons trails on
  357. script = replace.call(script, /\w+\['weapon'\]&&\w+\['weapon'\]\['trail'\]/g, "true")
  358.  
  359. // color blind mode
  360. script = replace.call(script, /#9eeb56/g, '#00FFFF');
  361.  
  362. // no zoom
  363. script = replace.call(script, /,'zoom':.+?(?=,)/g, ",'zoom':1");
  364.  
  365. // script = replace.call(script, /(void this\['sendQueue'\]\['push'\]\(\[(\w+),(\w+)\]\);)/, '$1_[$2]=$3;');
  366. Function.prototype.call = hooked_call;
  367. /***********************************************************************************************************/
  368.  
  369. // bypass modification check of returned function
  370. const original_script = args[1];
  371. args[1] = script;
  372. let mod_fn = new target(...args);
  373. args[1] = original_script;
  374. let original_fn = new target(...args);
  375. conceal_function(original_fn, mod_fn);
  376. return mod_fn;
  377. }
  378. return new target(...args);
  379. }
  380. };
  381.  
  382. // we intercept game.js at the `Function` generation level
  383. const original_Function = Function;
  384. let hook_Function = new Proxy(Function, handler);
  385. conceal_function(original_Function, hook_Function);
  386. Function = hook_Function;
  387. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement