Kour.rip

Basic Kour.io cheats.

  1. // ==UserScript==
  2. // @name Kour.rip
  3. // @match *://kour.io/*
  4. // @version 1.0.0
  5. // @author dropout (https://github.com/dropout1337)
  6. // @description Basic Kour.io cheats.
  7. // @run-at document-start
  8. // @grant unsafeWindow
  9. // @namespace https://greasyfork.org/users/1369586
  10. // ==/UserScript==
  11.  
  12. const Signatures = {
  13. ping: "f3 07 01 00 00", // Filter
  14. pong: "f3 06 01 01 01", // Filter
  15. anotherPing: "f3 04 e2 03 e3", // Filter
  16.  
  17. createGame: "f3 02 e3 03 ff 07 06", // Create Game / Party (Can be used to change partyId)
  18. updateState: "f3 02 fd 02 f4 03 c8", // Insta-kill
  19. damageTaken: "f3 04 c8 02 f5 15 04", // Invisibility
  20.  
  21. connectStarts: "f3 02 e", // Connect (start)
  22. connectEnds: "f1 1c e8 1c bf 0b 23" // Connect (end)
  23. }
  24.  
  25. class Kour {
  26. constructor() {
  27. // sockets: list of WebSocket
  28. this.sockets = [];
  29.  
  30. // What features you want enabled
  31. this.config = {
  32. Invisible: true,
  33. InstantKill: false
  34. }
  35.  
  36. // Current packet count (not used, just visually)
  37. this.packets = 0;
  38.  
  39. // Hook window.WebSocket
  40. unsafeWindow.WebSocket = class extends WebSocket {
  41. constructor() {
  42. super(...arguments);
  43. this.addEventListener("open", event => {
  44. // Add to this.sockets list.
  45. kourInstance.sockets.push(this);
  46.  
  47. // Hook send/onmessage
  48. kourInstance.hook(this);
  49. });
  50. }
  51. }
  52. }
  53.  
  54. /**
  55. * Converts an array of hexadecimal strings to a human-readable string.
  56. *
  57. * @param {string[]} hexArray - An array of strings, where each string represents a hexadecimal number.
  58. * @returns {string} - A string where each character is derived from the corresponding hexadecimal value.
  59. */
  60. hexArrayToString(hexArray) {
  61. let str = '';
  62.  
  63. for (let i = 0; i < hexArray.length; i++) {
  64. let hex = hexArray[i];
  65. let decimalValue = parseInt(hex, 16);
  66.  
  67. str += String.fromCharCode(decimalValue);
  68. }
  69.  
  70. return str;
  71. }
  72.  
  73. /**
  74. * Hooks into the WebSocket instance to intercept and log WebSocket messages and sends.
  75. *
  76. * @param {WebSocket} socket - The WebSocket instance to hook into.
  77. */
  78. hook(socket) {
  79. console.debug("%c !! ", "background:#7aadff;color:#000", `Intercepted WebSocket (${socket.url})`);
  80.  
  81. const send = socket.send; // Original send function
  82. const onmessage = socket.onmessage; // Original onmessage function
  83.  
  84. socket.onmessage = (event) => {
  85. if (event.data == null) {
  86. return onmessage.call(socket, event);
  87. }
  88.  
  89. this.packets += 1;
  90.  
  91. let hexArray = Array.from(new Uint8Array(event.data)).map(byte => byte.toString(16).padStart(2, '0'));
  92. let uint8Array = new Uint8Array(event.data);
  93. let stringHexArray = hexArray.join(" ");
  94.  
  95. if (stringHexArray == "") return onmessage.call(socket, event);
  96. if (stringHexArray.startsWith(Signatures.ping)) return onmessage.call(socket, event);
  97. if (stringHexArray.startsWith(Signatures.anotherPing)) return onmessage.call(socket, event);
  98. // If the event is a Damage/Shoot event ignore it.
  99. if (stringHexArray.startsWith(Signatures.damageTaken) && this.config.Invisible) {
  100. return;
  101. }
  102.  
  103. console.debug("%c <= ", "background:#FF6A19;color:#000", JSON.stringify({
  104. "hex_array": stringHexArray,
  105. "array": uint8Array,
  106. "base64": btoa(String.fromCharCode.apply(null, new Uint8Array(hexArray.map(hex => parseInt(hex, 16))))),
  107. "string": this.hexArrayToString(hexArray)
  108. }));
  109.  
  110. return onmessage.call(socket, event);
  111. };
  112.  
  113. socket.send = (data) => {
  114. this.packets += 1;
  115.  
  116. let hexArray = Array.from(new Uint8Array(data)).map(byte => byte.toString(16).padStart(2, '0'));
  117. let uint8Array = new Uint8Array(data);
  118. let stringHexArray = hexArray.join(" ");
  119.  
  120. if (stringHexArray == "") return send.call(socket, data);
  121. if (stringHexArray.startsWith(Signatures.pong)) return send.call(socket, data);
  122.  
  123. if (stringHexArray.startsWith(Signatures.createGame)) {
  124. let partyId = this.hexArrayToString(hexArray.slice(7, 13));
  125. console.debug("%c => ", "background:#7F7;color:#000", "Creating game:", partyId);
  126. return send.call(socket, data);
  127. } else if (stringHexArray.startsWith(Signatures.updateState) && this.config.InstantKill) { // Repeat state packets (movement, crouch, jump, shoot, switch weapon), causes the game to send 40 of the same packet. So if we shoot we actually send 40 damage packets instead of 1.
  128. console.debug("%c => ", "background:#7F7;color:#000", "State repeated.");
  129.  
  130. for (let i = 0; i < 40; i++) {
  131. send.call(socket, data);
  132. }
  133.  
  134. return send.call(socket, data);
  135. } else if (stringHexArray.startsWith(Signatures.connectStarts) && stringHexArray.endsWith(Signatures.connectEnds)) {
  136. console.debug("%c => ", "background:#7F7;color:#000", "Connecting to game.", this.hexArrayToString(hexArray));
  137. return send.call(socket, data);
  138. }
  139.  
  140. console.debug("%c => ", "background:#7F7;color:#000", JSON.stringify({
  141. "hex_array": stringHexArray,
  142. "array": uint8Array,
  143. "base64": btoa(String.fromCharCode.apply(null, new Uint8Array(hexArray.map(hex => parseInt(hex, 16))))),
  144. "string": this.hexArrayToString(hexArray)
  145. }));
  146.  
  147. return send.call(socket, data);
  148. };
  149. }
  150.  
  151. /**
  152. * Draws the watermark onto the unity-canvas.
  153. */
  154. watermark() {
  155. let overlayCanvas = document.createElement("canvas");
  156. let unityContainer = document.getElementById("unity-container");
  157. overlayCanvas.width = unityContainer.clientWidth;
  158. overlayCanvas.height = unityContainer.clientHeight;
  159. overlayCanvas.style.position = "absolute";
  160. overlayCanvas.style.top = "50%";
  161. overlayCanvas.style.left = "50%";
  162. overlayCanvas.style.transform = "translate(-50%, -50%)";
  163. overlayCanvas.style.pointerEvents = "none";
  164. unityContainer.appendChild(overlayCanvas);
  165. let ctx = overlayCanvas.getContext("2d");
  166. ctx.font = "15px monospace";
  167. ctx.textAlign = "center";
  168. ctx.textBaseline = "middle";
  169. let opacity = 0;
  170. let delta = 0.03;
  171. function animate() {
  172. let lines = [`kour.rip (${kourInstance.packets})`];
  173.  
  174. if (kourInstance.config.Invisible) {
  175. lines.push("<c>✔ Invisible")
  176. } else {
  177. lines.push("<c>✖ Invisible")
  178. }
  179.  
  180. if (kourInstance.config.InstantKill) {
  181. lines.push("<c>✔ Instant-Kill")
  182. } else {
  183. lines.push("<c>✖ Instant-Kill")
  184. }
  185.  
  186. let lineHeight = 20;
  187. let startY = overlayCanvas.height / 2 - ((lines.length - 1) * lineHeight) / 2 + 60;
  188. let centerX = overlayCanvas.width / 2;
  189. ctx.clearRect(0, 0, overlayCanvas.width, overlayCanvas.height);
  190. opacity += delta;
  191. if (opacity > 1) {
  192. opacity = 1;
  193. delta = -delta;
  194. } else if (opacity < 0) {
  195. opacity = 0;
  196. delta = -delta;
  197. }
  198. ctx.globalAlpha = opacity;
  199. lines.forEach((line, index) => {
  200. if (line.includes("<c>")) {
  201. line = line.replace("<c>", "");
  202. ctx.fillStyle = "#F8CEFF";
  203. } else {
  204. ctx.fillStyle = "white";
  205. }
  206. ctx.fillText(line, centerX, startY + index * lineHeight);
  207. });
  208. ctx.globalAlpha = 1;
  209. requestAnimationFrame(animate);
  210. }
  211. animate();
  212. }
  213. }
  214.  
  215. class Message {
  216. constructor() {
  217. this.msgArray = [243, 2, 253, 3, 246, 3, 1, 244, 34, 245, 23, 1, 7];
  218. this.sockets = kourInstance.sockets;
  219. }
  220.  
  221. /**
  222. * Converts a given string into an array of decimal ASCII codes.
  223. *
  224. * @param {string} text - The input text to be encoded.
  225. * @returns {number[]} An array of decimal ASCII codes representing each character in the input text.
  226. */
  227. encodeDec(text) {
  228. const decArray = [];
  229.  
  230. for (let i = 0; i < text.length; i++) {
  231. decArray.push(text.charCodeAt(i));
  232. }
  233.  
  234. return decArray;
  235. }
  236.  
  237. /**
  238. * Sends a message through the last socket in the sockets array.
  239. *
  240. * @param {string} msg - The message to be sent.
  241. */
  242. send(msg) {
  243. let socket = this.sockets[this.sockets.length - 1];
  244.  
  245. let msgArray = [...this.msgArray];
  246.  
  247. let savedlength = msg.length;
  248. let amount = Math.floor(savedlength/128);
  249. let strLength = [];
  250. if (savedlength > 128) {
  251. strLength.push(128 + (savedlength % 128));
  252. strLength.push(amount);
  253. } else {
  254. strLength.push(savedlength);
  255. }
  256.  
  257. msgArray.push(...strLength);
  258. msgArray.push(...this.encodeDec(msg));
  259.  
  260. socket.send(new Uint8Array(msgArray));
  261. }
  262. }
  263.  
  264. const kourInstance = new Kour();
  265. const kourMessager = new Message();
  266.  
  267. unsafeWindow.kourInstance = kourInstance;
  268. unsafeWindow.kourMessager = kourMessager;
  269.  
  270. window.addEventListener("load", kourInstance.watermark);