Greasy Fork

Greasy Fork is available in English.

MooMoo.io Mod (Hat Macros & Trap Indicator)

Adds hat macros and a line connecting player to trapped enemies

当前为 2025-01-29 提交的版本,查看 最新版本

// ==UserScript==
// @name         MooMoo.io Mod (Hat Macros & Trap Indicator)
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Adds hat macros and a line connecting player to trapped enemies
// @author     II
// @match        *://moomoo.io/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    console.log("MooMoo.io Mod Loaded!");

    // Keybinds for Hat Macros
    const KEY_TANK_HAT = 'F';   // Tank Hat Macro
    const KEY_TURRET_HAT = 'G'; // Turret Hat Macro
    const KEY_SOLDIER_HAT = 'H'; // Soldier Hat Macro

    let player = { x: 0, y: 0 }; // Player position
    let enemies = {}; // Track enemy positions
    let spikes = []; // Track spike positions

    // Create a canvas for drawing lines
    let canvas = document.createElement("canvas");
    document.body.appendChild(canvas);
    canvas.style.position = "absolute";
    canvas.style.top = "0";
    canvas.style.left = "0";
    canvas.style.pointerEvents = "none";
    let ctx = canvas.getContext("2d");

    function resizeCanvas() {
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
    }
    window.addEventListener("resize", resizeCanvas);
    resizeCanvas();

    // Intercept WebSocket messages
    const oldSend = WebSocket.prototype.send;
    WebSocket.prototype.send = function(data) {
        try {
            let msg = new Uint8Array(data);

            // Detect player movements
            if (msg.length > 3 && msg[0] === 255 && msg[1] === 2) {
                player.x = msg[2]; // Extract player X coordinate
                player.y = msg[3]; // Extract player Y coordinate
            }

            // Detect hat changes
            document.addEventListener("keydown", function(event) {
                let key = event.key.toUpperCase();
                if (key === KEY_TANK_HAT) {
                    console.log("Switching to Tank Hat...");
                    selectHat(7);
                }
                if (key === KEY_TURRET_HAT) {
                    console.log("Switching to Turret Hat...");
                    selectHat(18);
                }
                if (key === KEY_SOLDIER_HAT) {
                    console.log("Switching to Soldier Hat...");
                    selectHat(15);
                }
            });

            // Detect enemy getting trapped
            if (msg.length > 4 && msg[0] === 255 && msg[1] === 3) {
                let enemyID = msg[2]; // Enemy ID
                let trapX = msg[3]; // Trap X position
                let trapY = msg[4]; // Trap Y position
                if (enemies[enemyID]) {
                    let enemyPos = enemies[enemyID];
                    drawLine(player.x, player.y, enemyPos.x, enemyPos.y, trapX, trapY);
                }
            }

        } catch (error) {
            console.error("Error processing WebSocket data:", error);
        }
        return oldSend.apply(this, arguments);
    };

    // Function to draw a line from Player → Enemy → Trap
    function drawLine(px, py, ex, ey, sx, sy) {
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        ctx.beginPath();
        ctx.moveTo(px, py);
        ctx.lineTo(ex, ey);
        ctx.lineTo(sx, sy);
        ctx.strokeStyle = "red";
        ctx.lineWidth = 3;
        ctx.stroke();

        // Remove the line after 3 seconds
        setTimeout(() => {
            ctx.clearRect(0, 0, canvas.width, canvas.height);
        }, 3000);
    }

    // Function to select a hat
    function selectHat(hatID) {
        window.gameSocket.send(new Uint8Array([255, 6, hatID])); // Send hat selection packet
    }

})();