Voice Mod Beta

In order for everything to work correctly, you need to play on the HTTPS protocol. Allow access to the microphone! This is a beta version, so there are probably bugs here. See the commands in greasyfork description!

  1. // ==UserScript==
  2. // @name Voice Mod Beta
  3. // @namespace -
  4. // @version 1.0
  5. // @description In order for everything to work correctly, you need to play on the HTTPS protocol. Allow access to the microphone! This is a beta version, so there are probably bugs here. See the commands in greasyfork description!
  6. // @author Nudo#3310
  7. // @match *://moomoo.io/*
  8. // @match *://*.moomoo.io/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=moomoo.io
  10. // @require https://greasyfork.org/scripts/423602-msgpack/code/msgpack.js
  11. // @grant none
  12. // ==/UserScript==
  13. (function() {
  14. const Client = {}
  15.  
  16. class Socket {
  17. constructor(socket) {
  18. this.source = socket
  19. }
  20.  
  21. isOpen() {
  22. if (this.source.readyState !== 1) {
  23. return false
  24. }
  25.  
  26. return true
  27. }
  28.  
  29. send(data) {
  30. if (!this.isOpen()) {
  31. return void 0
  32. }
  33.  
  34. const item = Array.prototype.slice.call(arguments, 0, 1)
  35. const action = Array.prototype.slice.call(arguments, 1)
  36.  
  37. data = new Uint8Array(Array.from(msgpack.encode([item[0], action])))
  38.  
  39. this.source.send(data)
  40. }
  41. }
  42.  
  43. // just beta version sorry xD I was too lazy to do it normally >
  44. let primary = 0
  45. let secondary = 0
  46. let foodType = 0
  47. let spikeType = 0
  48. // <
  49.  
  50. // just beta version sorry xD I was too lazy to do it normally >
  51. function isVisible(element) {
  52. if (!element) {
  53. return void 0
  54. }
  55.  
  56. return element.offsetParent !== null
  57. }
  58. // <
  59.  
  60. WebSocket.prototype.oldSend = WebSocket.prototype.send
  61. WebSocket.prototype.send = function() {
  62. if (typeof Client.socket === 'undefined') {
  63. if (!this) {
  64. return void 0
  65. }
  66.  
  67. Client.socket = new Socket(this)
  68. }
  69.  
  70. // just beta version sorry xD I was too lazy to do it normally >
  71. for (let i = 0; i < 9; i++)
  72. if (isVisible(document.getElementById("actionBarItem" + i.toString()))) primary = i
  73. for (let i = 9; i < 16; i++)
  74. if (isVisible(document.getElementById("actionBarItem" + i.toString()))) secondary = i
  75. for (let i = 16; i < 19; i++)
  76. if (isVisible(document.getElementById("actionBarItem" + i.toString()))) foodType = i - 16
  77. for (let i = 22; i < 26; i++)
  78. if (isVisible(document.getElementById("actionBarItem" + i.toString()))) spikeType = i - 16
  79. // <
  80.  
  81. this.oldSend.apply(this, arguments)
  82. }
  83.  
  84. const Utils = {}
  85.  
  86. Utils.toRaq = function(angle) {
  87. return angle * 0.01745329251
  88. }
  89.  
  90. const Game = {}
  91.  
  92. Game.move = function(angle, raq = true) {
  93. Client.socket.send("33", raq ? Utils.toRaq(angle) : angle)
  94. }
  95.  
  96. Game.hit = function(type, angle) {
  97. Client.socket.send("c", type, angle)
  98. }
  99.  
  100. Game.take = function(id, type = true) {
  101. Client.socket.send("5", id, type)
  102. }
  103.  
  104. Game.place = function(id, angle) {
  105. this.take(id, null)
  106. this.hit(true)
  107. this.hit(false)
  108. this.take(primary)
  109. }
  110.  
  111. Game.equip = function(id) {
  112. Client.socket.send("13c", 0, id, 0)
  113. }
  114.  
  115. Game.chat = function(string) {
  116. Client.socket.send("ch", string)
  117. }
  118.  
  119. Game.voiceChat = false
  120.  
  121. const recognizer = new window.webkitSpeechRecognition()
  122.  
  123. recognizer.executeCommands = {
  124. "left": () => {
  125. Game.move(180)
  126. },
  127. "right": () => {
  128. Game.move(0)
  129. },
  130. "up": () => {
  131. Game.move(270)
  132. },
  133. "down": () => {
  134. Game.move(90)
  135. },
  136. "stop": () => {
  137. Game.move(null, false)
  138. },
  139. "attack": () => {
  140. Game.hit(true)
  141. Game.hit(false)
  142. },
  143. "heal": () => {
  144. Game.place(foodType)
  145. },
  146. "place spike": () => {
  147. console.log(spikeType)
  148. Game.place(spikeType)
  149. },
  150. "equip apple cap": () => {
  151. Game.equip(50)
  152. },
  153. "voice chat": () => {
  154. Game.voiceChat = !Game.voiceChat
  155. }
  156. }
  157.  
  158. function fixedCommand(command) {
  159. if (command === "play spike") {
  160. command = "place spike"
  161. } else if (command === "top") {
  162. command = "up"
  163. } else if (command === "bottom") {
  164. command = "down"
  165. } else if (command === "equip apple cab") {
  166. command = "equip apple cap"
  167. }
  168.  
  169. return command
  170. }
  171.  
  172.  
  173. function onRecognizerResult(received, _this) {
  174. if (typeof Client.socket === 'undefined') {
  175. return void 0
  176. }
  177.  
  178. received = received.toLowerCase()
  179.  
  180. received = fixedCommand(received)
  181.  
  182. if (!_this.executeCommands[received] && !Game.voiceChat) {
  183. Game.chat(`NotFound: ${received}`)
  184.  
  185. return void 0
  186. }
  187.  
  188. if (Game.voiceChat) {
  189. if (received === "voice chat") {
  190. Game.chat(`VoiceCmd: ${received}`)
  191.  
  192. _this.executeCommands["voice chat"]()
  193. } else {
  194. Game.chat(received)
  195. }
  196. } else {
  197. Game.chat(`VoiceCmd: ${received}`)
  198.  
  199. _this.executeCommands[received](_this)
  200. }
  201. }
  202.  
  203. recognizer.setup = function() {
  204. this.interimResults = true
  205. this.lang = "en-EN"
  206.  
  207. this.reset = function() {
  208. this.stop()
  209.  
  210. setTimeout(() => {
  211. this.start()
  212. }, 750)
  213. }
  214.  
  215. this.onresult = function() {
  216. const result = event.results[event.resultIndex]
  217.  
  218. if (result.isFinal) {
  219. const words = result[0].transcript
  220.  
  221. onRecognizerResult(words, this)
  222. }
  223. }
  224.  
  225. this.onend = function() {
  226. this.reset()
  227. }
  228.  
  229. this.start()
  230. }
  231.  
  232. window.addEventListener("load", () => {
  233. recognizer.setup()
  234. })
  235. })()