Greasy Fork is available in English.

MooMoo.io Auto Heal

A simple MooMoo.io Auto Heal script for in-game auto-healing.

Från och med 2023-11-11. Se den senaste versionen.

  1. // ==UserScript==
  2. // @name MooMoo.io Auto Heal
  3. // @namespace https://greasyfork.org/users/1064285-vcrazy-gaming
  4. // @version 0.1
  5. // @description A simple MooMoo.io Auto Heal script for in-game auto-healing.
  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. (() => {
  15. // Constants and Variables
  16. window.onbeforeunload = null;
  17. let mouseX,
  18. mouseY,
  19. weapons = [],
  20. width,
  21. height;
  22. let coreURL = new URL(window.location.href);
  23. window.sessionStorage.force = coreURL.searchParams.get("fc");
  24. let ws,
  25. msgpack5 = window.msgpack,
  26. tmpHealth = 100,
  27. sCount = 0,
  28. sTime = 0;
  29. const inventory = {
  30. primary: null,
  31. secondary: null,
  32. food: null,
  33. wall: null,
  34. spike: null,
  35. mill: null,
  36. mine: null,
  37. boostPad: null,
  38. trap: null,
  39. turret: null,
  40. spawnpad: null
  41. };
  42. const myPlayer = {
  43. sid: null,
  44. x: null,
  45. y: null,
  46. dir: null,
  47. buildIndex: null,
  48. weaponIndex: null,
  49. weaponVariant: null,
  50. team: null,
  51. isLeader: null,
  52. skinIndex: null,
  53. tailIndex: null,
  54. iconIndex: null
  55. };
  56.  
  57. // Helper Functions
  58. /**
  59. * Utility function to join arrays
  60. * @param {Array} message - The array to join
  61. * @returns {Array} - Joined array
  62. */
  63. const join = message => Array.isArray(message) ? [...message] : [...message];
  64.  
  65. /**
  66. * Hook function for WebSocket
  67. * @param {object} data - WebSocket message
  68. */
  69. const hookWS = data => {
  70. // PARSE MESSAGE:
  71. let tmpData = msgpack5.decode(new Uint8Array(data.data));
  72. if ((data = undefined) || (tmpData = (data = tmpData.length > 1 ? [tmpData[0], ...join(tmpData[1])] : tmpData)[0]) || data) {
  73. let health = data[2];
  74. let addEventListener = {
  75. "setupGame": "C",
  76. "updateHealth": "O"
  77. };
  78.  
  79. // CALL EVENT:
  80. if ("io-init" == tmpData) {
  81. let gameCanvas = document.getElementById("gameCanvas");
  82. width = gameCanvas.clientWidth;
  83. height = gameCanvas.clientHeight;
  84. document.getElementById(window).resize(function () {
  85. width = gameCanvas.clientWidth;
  86. height = gameCanvas.clientHeight;
  87. });
  88. gameCanvas.addEventListener("mousemove", f => {
  89. mouseX = f.clientX;
  90. mouseY = f.clientY;
  91. });
  92. }
  93.  
  94. // SETUP GAME:
  95. if (addEventListener.setupGame == tmpData && null === myPlayer.sid) {
  96. myPlayer.sid = data[1];
  97. weapons = [0];
  98. }
  99.  
  100. // UPDATE HEALTH/AUTO HEAL CODES:
  101. if (addEventListener.updateHealth == tmpData && data[1] == myPlayer.sid) {
  102. if (health > 0 && tmpHealth !== health) {
  103. setTimeout(() => {
  104. place(inventory.food);
  105. place(inventory.food);
  106. }, Math.max(0, 175 - window.pingTime));
  107. }
  108. if (tmpHealth - health < 0) {
  109. if (sTime) {
  110. let timeHit = Date.now() - sTime;
  111. sTime = 0;
  112. if (timeHit <= 120) sCount++;else sCount = Math.max(0, sCount - 2);
  113. }
  114. } else {
  115. sTime = Date.now();
  116. }
  117. tmpHealth = health;
  118. }
  119. cacheItems();
  120. }
  121. };
  122.  
  123. /**
  124. * Function to send a packet
  125. * @param {string} event - Event type
  126. * @param {*} e - Parameter e
  127. */
  128. function sendPacket(e) {
  129. // EXTRACT DATA ARRAY:
  130. let t = Array.prototype.slice.call(arguments, 1);
  131. // SEND MESSAGE:
  132. ws.send(window.msgpack.encode([e, t]));
  133. }
  134.  
  135. // PLACE:
  136. /**
  137. * Function to place an item
  138. * @param {number} event - Event type
  139. * @param {number} ang - Angle
  140. */
  141. const place = (id, ang) => {
  142. sendPacket("G", id, false);
  143. sendPacket("d", 1, ang);
  144. sendPacket("d", 0, ang);
  145. sendPacket("G", 0, true);
  146. };
  147.  
  148. // ITEM GROUPS/WEAPONS:
  149. /**
  150. * Cache the player's items
  151. */
  152. const cacheItems = () => {
  153. const categories = [{
  154. category: 'primary',
  155. start: 0,
  156. end: 8
  157. }, {
  158. category: 'secondary',
  159. start: 9,
  160. end: 15
  161. }, {
  162. category: 'food',
  163. start: 16,
  164. end: 18
  165. }, {
  166. category: 'wall',
  167. start: 19,
  168. end: 21
  169. }, {
  170. category: 'spike',
  171. start: 22,
  172. end: 25
  173. }, {
  174. category: 'mill',
  175. start: 26,
  176. end: 28
  177. }, {
  178. category: 'mine',
  179. start: 29,
  180. end: 30
  181. }, {
  182. category: 'boostPad',
  183. start: 31,
  184. end: 32
  185. }, {
  186. category: 'trap',
  187. start: 31,
  188. end: 32
  189. }, {
  190. category: 'turret',
  191. start: 29,
  192. end: 30
  193. }, {
  194. category: 'spawnpad',
  195. start: 36,
  196. end: 36
  197. }];
  198. categories.forEach(category => {
  199. for (let i = category.start; i <= category.end; i++) {
  200. const element = document.getElementById(`actionBarItem${i}`);
  201. if (element !== null && element.offsetParent !== null) {
  202. inventory[category.category] = i - 16;
  203. }
  204. }
  205. });
  206. };
  207. // Override WebSocket's send method
  208. document.msgpack = window.msgpack;
  209. WebSocket.prototype.oldSend = WebSocket.prototype.send;
  210. WebSocket.prototype.send = function (event) {
  211. ws || (document.ws = this, ws = this, document.ws.addEventListener("message", hookWS));
  212. this.oldSend(event);
  213. };
  214. })();