Hello! I'm stupid man! [ Patched ]

just a funny script.. Sends a message when a player appears on the screen

  1. // ==UserScript==
  2. // @name Hello! I'm stupid man! [ Patched ]
  3. // @namespace -
  4. // @version 0.1
  5. // @description just a funny script.. Sends a message when a player appears on the screen
  6. // @author Devil D. Nudo#7346
  7. // @match *://*.moomoo.io/*
  8. // @match *://moomoo.io/*
  9. // @grant none
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. "use strict"
  15.  
  16. class MsgPack {
  17. static decodeData(data) {
  18. if (!data || typeof MsgPack.decode !== 'function') return
  19.  
  20. data = MsgPack.decode(new Uint8Array(data))
  21.  
  22. return data
  23. }
  24.  
  25. static encodeData(data) {
  26. if (!data || typeof MsgPack.encode !== 'function') return
  27.  
  28. data = new Uint8Array(Array.from(MsgPack.encode(data)))
  29.  
  30. return data
  31. }
  32.  
  33. static getFormatedData() {
  34. if (!arguments.length) return
  35.  
  36. const type = Array.prototype.slice.call(arguments, 0, 1)
  37. const content = Array.prototype.slice.call(arguments, 1)
  38.  
  39. if (!content.length) {
  40. console.warn(type[0], "A strange packet with no data being sent")
  41. }
  42.  
  43. const data = MsgPack.encode([type[0], [...content]])
  44.  
  45. return data
  46. }
  47. }
  48.  
  49. Function.prototype.call = new Proxy(Function.prototype.call, {
  50. apply(target, _this, args) {
  51. const data = target.apply(_this, args)
  52.  
  53. if (args[1] && args[1].i) {
  54. const index = args[1].i
  55.  
  56. if (index === 9) {
  57. MsgPack.encode = args[0].encode
  58. }
  59.  
  60. if (index === 15) {
  61. MsgPack.decode = args[0].decode
  62.  
  63. Function.prototype.call = target
  64. }
  65. }
  66.  
  67. return data
  68. }
  69. })
  70.  
  71. class Config {
  72. get stupidMessage() {
  73. return "Hello [name]! I'm stupid man!"
  74. }
  75. }
  76.  
  77. const config = new Config()
  78.  
  79. class Socket {
  80. constructor(websocket = null) {
  81. this.websocket = websocket
  82.  
  83. this.eventQueue = []
  84. }
  85.  
  86. addEvent(event, callback) {
  87. if (!this.websocket) {
  88. return this.eventQueue.push({
  89. event: event,
  90. callback: callback
  91. })
  92. }
  93.  
  94. this.websocket.addEventListener(event, callback)
  95. }
  96.  
  97. send() {
  98. const data = MsgPack.getFormatedData(...arguments)
  99.  
  100. this.websocket.send(data)
  101. }
  102.  
  103. init(sourceThis, callback) {
  104. this.websocket = sourceThis
  105.  
  106. for (const event of this.eventQueue) {
  107. this.addEvent(event.event, event.callback)
  108. }
  109.  
  110. callback.call(this, this.websocket)
  111. }
  112. }
  113.  
  114. class MyPlayer {
  115. constructor() {
  116. if (MyPlayer.instance) {
  117. return MyPlayer.instance
  118. }
  119.  
  120. this.sid = null
  121.  
  122. this.socket = new Socket()
  123.  
  124. MyPlayer.instance = this
  125. }
  126.  
  127. onSetupGame(content) {
  128. if (this.sid !== null) return
  129.  
  130. this.sid = content[0]
  131. }
  132.  
  133. onAddPlayer(content) {
  134. const info = [...content[0]]
  135.  
  136. if (info[1] === this.sid) return
  137.  
  138. const message = config.stupidMessage.replace(/\[\w+\]/, info[2])
  139.  
  140. this.socket.send("ch", message)
  141. }
  142.  
  143. onMessage(event) {
  144. const data = MsgPack.decodeData(event.data)
  145. const type = data[0]
  146. const content = [...data[1]]
  147.  
  148. switch (type) {
  149. case "1": this.onSetupGame(content)
  150. break
  151.  
  152. case "2": this.onAddPlayer(content)
  153. break
  154. }
  155. }
  156. }
  157.  
  158. const myPlayer = new MyPlayer()
  159.  
  160. window.WebSocket = class extends WebSocket {
  161. constructor(...args) {
  162. super(args)
  163.  
  164. myPlayer.socket.init(this, function() {
  165. this.addEvent("message", myPlayer.onMessage.bind(myPlayer))
  166. })
  167. }
  168. }
  169.  
  170. window.myPlayer = myPlayer
  171. })()