MooMoo.io Auto Heal

Simple auto-healing script for MooMoo.io.

  1. // ==UserScript==
  2. // @name MooMoo.io Auto Heal
  3. // @namespace https://greasyfork.org/users/1064285-vcrazy-gaming
  4. // @version 0.3
  5. // @description Simple auto-healing script for MooMoo.io.
  6. // @match *://moomoo.io/*
  7. // @match *://*.moomoo.io/*
  8. // @author _VcrazY_
  9. // @require https://greasyfork.org/scripts/423602-msgpack/code/msgpack.js
  10. // @grant none
  11. // @icon https://moomoo.io/img/favicon.png?v=1
  12. // @license MIT
  13. // ==/UserScript==
  14. (function () {
  15. // Variables
  16. let AUTO_HEAL_SPEED = 120;
  17. let AUTO_HEAL_ENABLED = true;
  18. let items = [];
  19. let weapons = [];
  20. let inGame = false;
  21. let tmpHealth = 100;
  22. let sTime = 0;
  23. let sCount = 0;
  24. let msgpack = window.msgpack;
  25. let ws;
  26. // WebSocket setup
  27. ws = new Promise(function (resolve) {
  28. let {
  29. send
  30. } = WebSocket.prototype;
  31. WebSocket.prototype.send = function (...x) {
  32. send.apply(this, x);
  33. this.send = send;
  34. this.io = function (...datas) {
  35. const [packet, ...data] = datas;
  36. this.send(new Uint8Array(Array.from(msgpack.encode([packet, data]))));
  37. };
  38. this.addEventListener("message", function (e) {
  39. const [packet, data] = msgpack.decode(new Uint8Array(e.data));
  40. let sid = data[0];
  41. let health = data[1];
  42. let inventory = {
  43. food: items[0],
  44. walls: items[1],
  45. spikes: items[2],
  46. mill: items[3],
  47. mine: items[4],
  48. trap: items[5],
  49. booster: items[6],
  50. turret: items[7],
  51. watchtower: items[8],
  52. buff: items[9],
  53. spawn: items[10],
  54. sapling: items[11],
  55. blocker: items[12],
  56. teleporter: items[13]
  57. };
  58. let addEventListener = {
  59. setupGame: "C",
  60. updateHealth: "O",
  61. killPlayer: "P",
  62. updateItems: "V"
  63. };
  64. switch (packet) {
  65. case addEventListener.setupGame:
  66. inGame = true;
  67. items = [0, 3, 6, 10];
  68. weapons = [0];
  69. break;
  70. case addEventListener.updateHealth:
  71. if (sid) {
  72. const AUTOHEAL_SPEED = parseInt(document.getElementById('speedInput').value);
  73. if (inGame && AUTO_HEAL_ENABLED) {
  74. if (health < 100 && health > 0) {
  75. setTimeout(function () {
  76. place(inventory.food);
  77. place(inventory.food);
  78. place(inventory.food);
  79. place(inventory.food);
  80. }, AUTOHEAL_SPEED);
  81. }
  82. }
  83. if (tmpHealth - health < 0) {
  84. if (sTime) {
  85. let timeHit = Date.now() - sTime;
  86. sTime = 0;
  87. sCount = timeHit <= 120 ? sCount + 1 : Math.max(0, sCount - 2);
  88. }
  89. } else {
  90. sTime = Date.now();
  91. }
  92. tmpHealth = health;
  93. }
  94. break;
  95. case addEventListener.killPlayer:
  96. inGame = false;
  97. break;
  98. case addEventListener.updateItems:
  99. if (sid) {
  100. if (health) {
  101. weapons = sid;
  102. } else {
  103. items = sid;
  104. }
  105. }
  106. break;
  107. }
  108. });
  109. resolve(this);
  110. };
  111. });
  112.  
  113. // Functions
  114. const sendPacket = function (...datas) {
  115. const [type, ...data] = datas;
  116. var binary = msgpack.encode([type, data]);
  117. ws.then(function (wsInstance) {
  118. wsInstance.send(new Uint8Array(Array.from(binary)));
  119. });
  120. };
  121.  
  122. // PLACE
  123. const place = function (id, ang) {
  124. if (inGame) {
  125. sendPacket("G", id, false);
  126. hit(ang);
  127. selectWeapon();
  128. }
  129. };
  130.  
  131. // SELECT WEAPON
  132. const selectWeapon = function () {
  133. if (inGame) {
  134. sendPacket("G", weapons[0], true);
  135. }
  136. };
  137.  
  138. // HIT
  139. const hit = function (id, ang) {
  140. if (inGame) {
  141. sendPacket("d", 1, ang);
  142. sendPacket("d", 0, ang);
  143. }
  144. };
  145. // CHAT
  146. const chat = function (e) {
  147. if (inGame) {
  148. sendPacket("6", e);
  149. }
  150. };
  151.  
  152. // SCRIPT MENU:
  153. let modMenus = document.createElement("div");
  154. modMenus.id = "modMenus";
  155. document.body.append(modMenus);
  156. modMenus.style.display = "block";
  157. modMenus.style.padding = "10px";
  158. modMenus.style.backgroundColor = "rgba(0, 0, 0, 0.25)";
  159. modMenus.style.borderRadius = "4px";
  160. modMenus.style.position = "absolute";
  161. modMenus.style.left = "20px";
  162. modMenus.style.top = "20px";
  163. modMenus.style.minWidth = "300px";
  164. modMenus.style.maxWidth = "290px";
  165. modMenus.style.minHeight = "400";
  166. modMenus.style.maxHeight = "700";
  167. function updateInnerHTML() {
  168. modMenus.innerHTML = `<h2 style="text-align: center; font-size: 28px;">Auto Heal <span ></span></h2>
  169. <hr>
  170. <label for="speedInput">Speed</label>
  171. <input type="number" id="speedInput" oninput="this.value = this.value.slice(0, 4)" value=${AUTO_HEAL_SPEED}>
  172. <span id="speedValue"></span>
  173. <hr>
  174. <input type="checkbox" checked id="AUTO_HEAL">
  175. Auto Heal
  176. <br>`;
  177. }
  178. updateInnerHTML();
  179. // THIS IS HOW SCRIPT MENU IS ON/OFF:
  180. function getEl(id) {
  181. return document.getElementById(id);
  182. }
  183.  
  184. // PART OF SCRIPT MENU:
  185. getEl("AUTO_HEAL").onclick = function () {
  186. AUTO_HEAL_ENABLED = !AUTO_HEAL_ENABLED;
  187. chat(`Auto Heal : ${AUTO_HEAL_ENABLED ? 'enabled' : 'disabled'}`);
  188. };
  189. getEl("speedInput").oninput = function () {
  190. chat(`Auto Heal Speed : ${getEl("speedInput").value}`);
  191. };
  192. })();