MooMoo.io Items Marker

Draws markers on items

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         MooMoo.io Items Marker
// @description  Draws markers on items
// @author       KOOKY WARRIOR
// @match        *://*.moomoo.io/*
// @icon         https://moomoo.io/img/favicon.png?v=1
// @require      https://cdnjs.cloudflare.com/ajax/libs/msgpack-lite/0.1.26/msgpack.min.js
// @require 	 https://greatest.deepsurf.us/scripts/478839-moomoo-io-packet-code/code/MooMooio%20Packet%20Code.js
// @run-at       document-start
// @grant		 unsafeWindow
// @license      MIT
// @version      0.4.1
// @namespace    https://greatest.deepsurf.us/users/999838
// ==/UserScript==

// This script was originally made by Murka007
// https://greatest.deepsurf.us/en/scripts/447475
/*
	Original Author: Murka
    Github: https://github.com/Murka007
    Discord: https://discord.gg/sG9cyfGPj5
    Greasyfork: https://greatest.deepsurf.us/en/users/919633
    MooMooForge: https://github.com/MooMooForge
*/

;(async () => {
	const MARKER_COLOUR = {
		MY_PLAYER: {
			render: true,
			colour: "#a7f060"
		},
		TEAMMATE: {
			render: true,
			colour: "#fceb65"
		},
		ENEMY: {
			render: true,
			colour: "#f76363"
		}
	}
	const MARKER_SIZE = 10

	function getItemColour(sid) {
		if (sid === myPlayerSID) return MARKER_COLOUR.MY_PLAYER
		if (teammates.includes(sid)) return MARKER_COLOUR.TEAMMATE
		return MARKER_COLOUR.ENEMY
	}

	var myPlayerSID = null
	var teammates = []

	let init = false
	await new Promise(async (resolve) => {
		let { send } = WebSocket.prototype

		WebSocket.prototype.send = function (...x) {
			send.apply(this, x)
			this.send = send
			if (!init) {
				init = true
				this.addEventListener("message", (e) => {
					if (!e.origin.includes("moomoo.io") && !unsafeWindow.privateServer) return
					const [packet, data] = msgpack.decode(new Uint8Array(e.data))
					switch (packet) {
						case PACKETCODE.RECEIVE.setupGame:
							myPlayerSID = data[0]
							break
						case PACKETCODE.RECEIVE.setPlayerTeam:
							if (data[0] == null) {
								teammates = []
							}
							break
						case PACKETCODE.RECEIVE.setAlliancePlayers:
							teammates = []
							for (let i = 0; i < data[0].length; i += 2) {
								const [sid, name] = data[0].slice(i, i + 2)
								teammates.push(sid)
							}
							break
					}
				})
			}
			resolve(this)
		}
	})

	let item = null
	const symbol = Symbol("isItem")
	Object.defineProperty(Object.prototype, "isItem", {
		get() {
			if (this[symbol] === true) {
				item = this
			}
			return this[symbol]
		},
		set(value) {
			this[symbol] = value
		},
		configurable: true
	})

	function drawMarker(ctx) {
		if (!item || !item.owner || myPlayerSID === null) return
		const type = getItemColour(item.owner.sid)

		if (!type.render) return

		ctx.fillStyle = type.colour
		ctx.beginPath()
		ctx.arc(0, 0, MARKER_SIZE, 0, 2 * Math.PI)
		ctx.fill()
		item = null
	}

	// This method is called when item was drawn
	CanvasRenderingContext2D.prototype.restore = new Proxy(CanvasRenderingContext2D.prototype.restore, {
		apply(target, _this, args) {
			drawMarker(_this)
			return target.apply(_this, args)
		}
	})
})()