bruh

practice with websocket

  1. // ==UserScript==
  2. // @name bruh
  3. // @namespace Simple Mod
  4. // @match *://*/*
  5. // @grant none
  6. // @version 1.0
  7. // @author keypressed & z-r
  8. // @description practice with websocket
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12.  
  13. var killCount = 0;
  14. var lastSpawnTime = Date.now();
  15. var spawnChat = false;
  16. var killChat = false;
  17. var autoRespawn = false;
  18. var spawnContent = "spawn↠[player]";
  19. var killChatTextValue = "kill↠[playerkilled] ([kills])";
  20. var showID = false;
  21. var nick = document.getElementById("nickname");
  22. const play = document.getElementById("play");
  23. var autoSelect = false;
  24. var buildingInfo = false;
  25. var logItem = false;
  26. var logData = false;
  27. var autoheal = false;
  28. var millWarning = false;
  29. var maxMills = false;
  30. let millMessage = "replace your mill(s)!";
  31. //automatically set nickname
  32. nick.value = "sploop.io";
  33.  
  34. const menu = document.createElement("div");
  35. document.body.appendChild(menu);
  36. menu.style.position = "absolute";
  37. menu.style.top = "10px";
  38. menu.style.left = "10px";
  39. menu.style.width = "400px";
  40. menu.style.height = "auto";
  41. menu.style.border = "2px solid black";
  42. menu.style.borderRadius = "10px";
  43. menu.style.backgroundColor = "lightpink";
  44. menu.style.opacity = "0.9";
  45. menu.style.padding = "8px";
  46.  
  47. function toggleMenu() {
  48. if (menu.style.display === 'none') {
  49. menu.style.display = 'block';
  50. } else {
  51. menu.style.display = 'none';
  52. }
  53. }
  54.  
  55. document.addEventListener('keydown', function (event) {
  56. if (event.key === 'Escape') {
  57. toggleMenu();
  58. }
  59. });
  60. const header = document.createElement("h1");
  61. header.textContent = "Simple Mod v1.0.1";
  62. menu.appendChild(header);
  63. header.style.margin = "5px";
  64.  
  65. const division = document.createElement("hr");
  66. menu.appendChild(division);
  67.  
  68. const label = document.createElement("label");
  69. label.textContent = "Send chat on players spawning";
  70. menu.appendChild(label);
  71. label.style.margin = "5px";
  72.  
  73. const checkbox = document.createElement("input");
  74. checkbox.type = "checkbox";
  75. menu.appendChild(checkbox);
  76. checkbox.checked = false;
  77.  
  78. const lineBreak = document.createElement("br");
  79. menu.appendChild(lineBreak);
  80.  
  81.  
  82. const spawnChatInputLabel = document.createElement("label");
  83. spawnChatInputLabel.textContent = "What text to say when player spawns: ";
  84. menu.appendChild(spawnChatInputLabel);
  85. spawnChatInputLabel.style.margin = "5px";
  86.  
  87.  
  88. const lineBreak2 = document.createElement("br");
  89. menu.appendChild(lineBreak2);
  90.  
  91. const spawnChatInputText = document.createElement("input");
  92. spawnChatInputText.value = spawnContent;
  93. menu.appendChild(spawnChatInputText);
  94. spawnChatInputText.style.margin = "5px";
  95. spawnChatInputText.style.width = "350px";
  96.  
  97. const lineBreak3 = document.createElement("br");
  98. menu.appendChild(lineBreak3);
  99.  
  100. const showIDSLabel = document.createElement("label");
  101. showIDSLabel.textContent = "Show IDS in the spawn text";
  102. showIDSLabel.style.margin = "5px";
  103. menu.appendChild(showIDSLabel);
  104.  
  105. const IDCheckbox = document.createElement("input");
  106. IDCheckbox.type = "checkbox";
  107. IDCheckbox.checked = false;
  108. menu.appendChild(IDCheckbox);
  109.  
  110. const firstHR = document.createElement("hr");
  111. menu.appendChild(firstHR);
  112.  
  113. const killChatToggleLabel = document.createElement("label");
  114. killChatToggleLabel.textContent = "Send killchat";
  115. killChatToggleLabel.style.margin = "5px";
  116. menu.appendChild(killChatToggleLabel);
  117.  
  118. const killChatToggle = document.createElement("input");
  119. killChatToggle.type = "checkbox";
  120. killChatToggle.checked = false;
  121. menu.appendChild(killChatToggle);
  122.  
  123. const lineBreak4 = document.createElement("br");
  124. menu.appendChild(lineBreak4);
  125.  
  126. const killChatLabel = document.createElement("label");
  127. killChatLabel.textContent = "Text sent on a kill";
  128. menu.appendChild(killChatLabel);
  129. killChatLabel.style.margin = "5px";
  130.  
  131. const killChatText = document.createElement("input");
  132. killChatText.type = "text";
  133. killChatText.value = killChatTextValue;
  134. menu.appendChild(killChatText);
  135.  
  136. const secondHR = document.createElement("hr");
  137. menu.appendChild(secondHR);
  138.  
  139. const autoRespawnLabel = document.createElement("label");
  140. autoRespawnLabel.textContent = "Auto-respawn";
  141. menu.appendChild(autoRespawnLabel);
  142. autoRespawnLabel.style.margin = "5px";
  143.  
  144. const autoRespawnToggle = document.createElement("input");
  145. autoRespawnToggle.type = "checkbox";
  146. autoRespawnToggle.checked = false;
  147. menu.appendChild(autoRespawnToggle);
  148.  
  149. const lineBreak5 = document.createElement("br");
  150. menu.appendChild(lineBreak5);
  151.  
  152. const autoRespawnNameLabel = document.createElement("label");
  153. autoRespawnNameLabel.textContent = "Auto-respawn name: ";
  154. menu.appendChild(autoRespawnNameLabel);
  155. autoRespawnNameLabel.style.margin = "5px";
  156.  
  157. const autoRespawnName = document.createElement("input");
  158. autoRespawnName.type = "text";
  159. autoRespawnName.value = nick.value;
  160. menu.appendChild(autoRespawnName);
  161.  
  162. const thirdHR = document.createElement("hr");
  163. menu.appendChild(thirdHR);
  164.  
  165. const autoSelectLabel = document.createElement("label");
  166. autoSelectLabel.textContent = "Auto Select KTH";
  167. menu.appendChild(autoSelectLabel);
  168. autoSelectLabel.style.margin = "5px";
  169.  
  170. const sendWeapons = document.createElement("input");
  171. sendWeapons.type = "checkbox";
  172. sendWeapons.checked = false;
  173. menu.appendChild(sendWeapons);
  174.  
  175. const fourthHR = document.createElement("hr");
  176. menu.appendChild(fourthHR);
  177.  
  178. const buildingInfoLabel = document.createElement("label");
  179. buildingInfoLabel.textContent = "Show number of buildings";
  180. menu.appendChild(buildingInfoLabel);
  181. buildingInfoLabel.style.margin = "5px";
  182.  
  183. const buildingInfoToggle = document.createElement("input");
  184. buildingInfoToggle.type = "checkbox";
  185. buildingInfoToggle.checked = false;
  186. menu.appendChild(buildingInfoToggle);
  187.  
  188.  
  189.  
  190. const buildInfoContainer = document.createElement("div");
  191. buildInfoContainer.style.width = "auto";
  192. buildInfoContainer.style.height = "auto";
  193. buildInfoContainer.style.border = "2px solid black";
  194. buildInfoContainer.style.borderRadius = "10px";
  195. buildInfoContainer.style.backgroundColor = "salmon";
  196. buildInfoContainer.style.opacity = "0.8";
  197. buildInfoContainer.style.padding = "8px";
  198. buildInfoContainer.style.display = "none";
  199. menu.appendChild(buildInfoContainer);
  200.  
  201. const walls = document.createElement("label");
  202. walls.textContent = "Walls: 0/100";
  203. const line = document.createElement("br");
  204. const mills = document.createElement("label");
  205. mills.textContent = "Mills: 0/8";
  206. const line2 = document.createElement("br");
  207. const spikes = document.createElement("label");
  208. spikes.textContent = "Spikes: 0/30";
  209. const line3 = document.createElement("br");
  210. const platforms = document.createElement("label");
  211. platforms.textContent = "Platforms: 0/32";
  212. const line4 = document.createElement("br");
  213. const cosy = document.createElement("label");
  214. cosy.textContent = "Cosy bed: 0/1";
  215. const line5 = document.createElement("br");
  216. const trap = document.createElement("label");
  217. trap.textContent = "Trap/boosts: 0/12";
  218. buildInfoContainer.append(walls, line, mills, line2, spikes, line3, platforms, line4, cosy, line5, trap);
  219.  
  220. const lineBreak6 = document.createElement("br");
  221. menu.appendChild(lineBreak6);
  222.  
  223. const warnLabel = document.createElement("label");
  224. warnLabel.textContent = "Send warning on mills being broken";
  225. menu.appendChild(warnLabel);
  226. warnLabel.style.margin = "5px";
  227.  
  228. const warnToggle = document.createElement("input");
  229. warnToggle.type = "checkbox";
  230. warnToggle.checked = false;
  231. menu.appendChild(warnToggle);
  232.  
  233. const fifthHR = document.createElement("hr");
  234. menu.appendChild(fifthHR);
  235. const lineBreak7 = document.createElement("br");
  236. menu.appendChild(lineBreak7);
  237.  
  238. const autohealLabel = document.createElement("label");
  239. autohealLabel.textContent = "Autoheal";
  240. menu.appendChild(autohealLabel);
  241. autohealLabel.style.margin = "5px";
  242.  
  243. const autohealToggle = document.createElement("input");
  244. autohealToggle.type = "checkbox";
  245. autohealToggle.checked = false;
  246. menu.appendChild(autohealToggle);
  247.  
  248. const lineBreak8 = document.createElement("br");
  249. menu.appendChild(lineBreak8);
  250.  
  251. const healthLabel = document.createElement("label");
  252. healthLabel.textContent = "Health: none";
  253. menu.appendChild(healthLabel);
  254. healthLabel.style.margin = "5px";
  255.  
  256. const ninthHR = document.createElement("hr");
  257. menu.appendChild(ninthHR);
  258.  
  259. const mainDebugToggle = document.createElement("label");
  260. mainDebugToggle.textContent = "Show debug options";
  261. menu.appendChild(mainDebugToggle);
  262. mainDebugToggle.style.margin = "5px";
  263.  
  264. const mainDebugCB = document.createElement("input");
  265. mainDebugCB.type = "checkbox";
  266. mainDebugCB.checked = false;
  267. menu.appendChild(mainDebugCB);
  268.  
  269. const debugDiv = document.createElement("div");
  270. menu.appendChild(debugDiv);
  271. debugDiv.style.margin = "5px";
  272. debugDiv.style.display = "none";
  273.  
  274. const lineBreak10 = document.createElement("br");
  275. debugDiv.appendChild(lineBreak10);
  276.  
  277. const debugInfo = document.createElement("label");
  278. debugInfo.textContent = "Log item to custom console";
  279. debugDiv.appendChild(debugInfo);
  280. debugInfo.style.margin = "5px";
  281.  
  282. const debugItem = document.createElement("input");
  283. debugItem.type = "checkbox";
  284. debugItem.checked = false;
  285. debugDiv.appendChild(debugItem);
  286.  
  287.  
  288. const lineBreak12 = document.createElement("br");
  289. debugDiv.appendChild(lineBreak12);
  290.  
  291. const debugData = document.createElement("label");
  292. debugData.textContent = "Log data to custom console";
  293. debugDiv.appendChild(debugData);
  294. debugData.style.margin = "5px";
  295.  
  296. const debug2Toggle = document.createElement("input");
  297. debug2Toggle.type = "checkbox";
  298. debug2Toggle.checked = false;
  299. debugDiv.appendChild(debug2Toggle);
  300.  
  301. IDCheckbox.addEventListener('change', function () {
  302. if (this.checked) {
  303. showID = true;
  304. } else {
  305. showID = false;
  306. }
  307. });
  308.  
  309. checkbox.addEventListener('change', function () {
  310. if (this.checked) {
  311. spawnChat = true;
  312. } else {
  313. spawnChat = false;
  314. }
  315. });
  316.  
  317. killChatToggle.addEventListener('change', function () {
  318. if (this.checked) {
  319. killChat = true;
  320. } else {
  321. killChat = false;
  322. }
  323. });
  324.  
  325. autoRespawnToggle.addEventListener('change', function () {
  326. if (this.checked) {
  327. autoRespawn = true;
  328. } else {
  329. autoRespawn = false;
  330. }
  331. });
  332.  
  333. sendWeapons.addEventListener('change', function () {
  334. if (this.checked) {
  335. autoSelect = true;
  336. } else {
  337. autoSelect = false;
  338. }
  339. });
  340.  
  341. debugItem.addEventListener('change', function () {
  342. if (this.checked) {
  343. logItem = true;
  344. } else {
  345. logItem = false;
  346. }
  347. });
  348.  
  349. debug2Toggle.addEventListener('change', function () {
  350. if (this.checked) {
  351. logData = true;
  352. } else {
  353. logData = false;
  354. }
  355. });
  356.  
  357. mainDebugCB.addEventListener('change', function () {
  358. if (this.checked) {
  359. debugDiv.style.display = "block";
  360. } else {
  361. debugDiv.style.display = "none";
  362. }
  363. });
  364.  
  365. autohealToggle.addEventListener('change', function () {
  366. if (this.checked) {
  367. autoheal = true;
  368. } else {
  369. autoheal = false;
  370. }
  371. });
  372.  
  373. warnToggle.addEventListener('change', function () {
  374. if (this.checked) {
  375. millWarning = true;
  376. } else {
  377. millWarning = false;
  378. }
  379. });
  380.  
  381. buildingInfoToggle.addEventListener('change', function () {
  382. if (this.checked) {
  383. buildingInfo = true;
  384. buildInfoContainer.style.display = "block";
  385. } else {
  386. buildingInfo = false;
  387. buildInfoContainer.style.display = "none";
  388. }
  389. });
  390. function logToCustomConsole(message) {
  391. var customConsole = document.getElementById('custom-console');
  392. var newLine = document.createElement('div');
  393. newLine.textContent = message;
  394. customConsole.appendChild(newLine);
  395.  
  396. if (customConsole.scrollTop + customConsole.clientHeight >= customConsole.scrollHeight - 20) {
  397. customConsole.scrollTop = customConsole.scrollHeight;
  398. }
  399. }
  400.  
  401. var millWarningDiv = document.createElement("div");
  402. document.body.appendChild(millWarningDiv);
  403. millWarningDiv.style.position = "absolute";
  404. millWarningDiv.style.top = "10px";
  405. millWarningDiv.style.left = "900px";
  406. millWarningDiv.style.height = "50px";
  407. millWarningDiv.style.position = "auto";
  408. millWarningDiv.style.border = "2px solid black";
  409. millWarningDiv.style.textAlign = "center";
  410. millWarningDiv.style.borderRadius = "5px";
  411. millWarningDiv.style.backgroundColor = "salmon";
  412. millWarningDiv.style.opacity = "0.9";
  413. millWarningDiv.textContent = "Replace your mills!";
  414. millWarningDiv.style.display = "none";
  415.  
  416.  
  417.  
  418. var customConsoleElement = document.createElement('div');
  419. customConsoleElement.id = 'custom-console';
  420. debugDiv.appendChild(customConsoleElement);
  421. customConsoleElement.style.width = "auto";
  422. customConsoleElement.style.height = "150px";
  423. customConsoleElement.style.border = "2px solid black";
  424. /*customConsoleElement.style.position = "absolute";
  425. customConsoleElement.style.top = "10px";
  426. customConsoleElement.style.left = "500px";*/
  427. customConsoleElement.style.overflow = "auto";
  428. let lastPacket = 0;
  429.  
  430. WebSocket.prototype.lastSend = WebSocket.prototype.send;
  431. WebSocket.prototype.send = function (a) {
  432. this.lastSend(a);
  433. this.addEventListener("message", (msg) => {
  434. try {
  435. const data = typeof msg.data == "string" ? JSON.parse(msg.data) : new Uint8Array(msg.data);
  436. const item = data[0];
  437.  
  438. let wallAmt = data[4];
  439. let spikeAmt = data[5];
  440. let millAmt = data[6];
  441. let trapAmt = data[8];
  442. let platformAmt = data[9];
  443. let bedAmt = data[10];
  444. if (item == 20 && autoheal) {
  445. healthLabel.textContent = "Health: " + data[13] / 255 * 100;
  446. }
  447. if (item != 20 && item != lastPacket && logItem) {
  448. logToCustomConsole(item);
  449. lastPacket = item;
  450. }
  451. if (item != 20 && item != lastPacket && logData) {
  452. logToCustomConsole(data);
  453. lastPacket = item;
  454. }
  455. if (item == 36 && (Date.now() - lastSpawnTime > 50)){
  456. if(millAmt === 8){
  457. maxMills = true;
  458. millWarningDiv.style.display = "none";
  459. }
  460. if(maxMills && millWarning && millAmt<8){
  461. millWarningDiv.style.display = "block";
  462. logToCustomConsole(millMessage);
  463. }
  464. lastSpawnTime = Date.now();
  465. }
  466. if (item == 36 && (Date.now() - lastSpawnTime > 50)) {
  467. walls.textContent = "Walls: " + wallAmt + "/100";
  468. spikes.textContent = "Spikes: " + spikeAmt + "/30";
  469. mills.textContent = "Mills: " + millAmt + "/8";
  470. platforms.textContent = "Platforms/roof: " + platformAmt + "/32";
  471. trap.textContent = "Trap/boosts: " + trapAmt + "/12";
  472. cosy.textContent = "Cosy bed: " + bedAmt + "/1";
  473. lastSpawnTime = Date.now();
  474. //index 0 = packet type
  475. //index 1 = unknown
  476. //index 2 = unknown
  477. //index 3 = unknown
  478. //index 4 = wall
  479. //index 5 = spike
  480. //index 6 = mill
  481. //index 7 = bush/sapling/stone
  482. //index 8 = trap/boost
  483. //index 9 = roof/platform
  484. //index 10 = cosy bed
  485. //index 11 = unknown
  486. }
  487. if (item == 14 && autoSelect && (Date.now() - lastSpawnTime > 50)) {
  488. const encodedData = new Uint8Array([14, 1]);//sword
  489. const encodedData2 = new Uint8Array([14, 12]);//cookie
  490. const encodedData3 = new Uint8Array([14, 9]);//trap
  491. const encodedData4 = new Uint8Array([14, 19]);//powermill
  492. const encodedData5 = new Uint8Array([14, 20]);//spike
  493. const encodedData6 = new Uint8Array([14, 15]);//hammer
  494. const encodedData7 = new Uint8Array([14, 8]);//platform
  495.  
  496. const encodedData9 = new Uint8Array([14, 17]);//katana
  497. const encodedData10 = new Uint8Array([14, 16]);//bed
  498. this.send(encodedData);
  499. this.send(encodedData2);
  500. this.send(encodedData3);
  501. this.send(encodedData4);
  502. this.send(encodedData5);
  503. this.send(encodedData6);
  504. this.send(encodedData7);
  505. this.send(encodedData9);
  506. this.send(encodedData10);
  507. lastSpawnTime = Date.now();
  508. }
  509. if (item == 19 && autoRespawn && (Date.now() - lastSpawnTime > 50)) {
  510. nick.value = autoRespawnName.value;
  511. play.click();
  512. lastSpawnTime = Date.now();
  513. }
  514.  
  515. if (item == 35) { killCount = 0 };
  516. if (item == 28 && (Date.now() - lastSpawnTime > 50)) {
  517. killCount++;
  518. if (killChat) {
  519. //const playerkilled = data[1].split(' ')[1];
  520. const playerkilled = data[1].substring(6);
  521. logToCustomConsole(playerkilled);
  522. killChatTextValue = killChatText.value;
  523. this.send(new Uint8Array([7, ...new TextEncoder().encode(killChatTextValue.replace('[kills]', killCount).replace('[playerkilled]', playerkilled))]));
  524. }
  525. lastSpawnTime = Date.now();
  526. }
  527.  
  528. if (item == 32 && (Date.now() - lastSpawnTime > 700)) {
  529. const playerName = data[2];
  530. const playerId = data[1];
  531. if (spawnChat) {
  532. spawnContent = spawnChatInputText.value;
  533. if (showID) {
  534. this.send(new Uint8Array([7, ...new TextEncoder().encode(`${spawnContent.replace('[player]', playerName)} ID: ${playerId}`)]));
  535. } else {
  536. this.send(new Uint8Array([7, ...new TextEncoder().encode(spawnContent.replace('[player]', playerName))]));
  537. }
  538. }
  539. lastSpawnTime = Date.now();
  540. }
  541. } catch (error) {
  542. console.error('Error processing message:', error);
  543. }
  544. });
  545. };