𝓓𝓒 𝓗𝓪𝓬𝓴

Auto hat switch, aimbot, auto instakill with aimbot, auto instakill near players, anti insta (soldier helmet), q-heal (automatically activated during anti-insta) and autoheal. No cryptominers!

// ==UserScript==
// @name         𝓓𝓒 𝓗𝓪𝓬𝓴
// @version      0.7
// @description  Auto hat switch, aimbot, auto instakill with aimbot, auto instakill near players, anti insta (soldier helmet), q-heal (automatically activated during anti-insta) and autoheal. No cryptominers!
// @author       SirenWolf
// @match        *://*.moomoo.io/*
// @grant        none
// @run-at       document-start
// @require      https://cdn.jsdelivr.net/npm/msgpack-lite@0.1.26/dist/msgpack.min.js
// @require      https://cdn.jsdelivr.net/npm/fontfaceobserver@2.1.0/fontfaceobserver.standalone.min.js
// @namespace    https://greasyfork.org/users/682378
// ==/UserScript==

/* global storeEquip, storeBuy, msgpack, FontFaceObserver, ClipboardItem */
/* eslint curly: 0, dot-notation: 0 */

(function () {
    "use strict";

    function replaceGUI() {
        let adCardOldContents = document.getElementById(
            "adCard"
        ).outerHTML;

        document.getElementById(
            "adCard"
        ).outerHTML = `<div class=menuCard id=adCard style=max-height:250px;overflow-y:scroll;-webkit-overflow-scrolling:touch;text-align:left>
<div class=menuHeader>Hack commands<br><span style=color:#006400;font-size:smaller;opacity:.7>(put in chat)</span></div>
<div class=menuText style=color:#555>.autoInsta - turns on auto instakill (instakill automatically when someone comes near)</div><div class=menuText style=color:#555>.attack - automatically goes towards the nearest enemy</div><div class=menuText style=color:#555>.gather - gathers resources</div><div class=menuText style=color:#555>.panic - hides the GUI</div>
    <div class=menuHeader>Keybindings<br><span style=color:#006400;font-size:smaller;opacity:.7>(press on keyboard)</span><div class=menuText style=color:#555>q - hold to heal very quickly in a short amount of time</div><div class=menuText style=color:#555>p - toggle autoheal</div><div class=menuText style=color:#555>b - boost + spike</div><div class=menuText style=color:#555>v - toggle aimbot</div><div class=menuText style=color:#555>k - quad spike</div></div>
        </div>`;

        document.getElementById("adCard").dataset.oldContents = adCardOldContents;

        document.getElementsByClassName("menuCard")[5].style.display = "none";

        let promoImgHolderOldContents = document.getElementById("promoImgHolder").outerHTML;

        document.getElementById(
            "promoImgHolder"
        ).outerHTML = `<div id="promoImgHolder" class="menuCard" style="display:block;margin-top:16px;padding-bottom:12px;font-size: x-large;"><a onclick="follmoo()" target="_blank" href="https://www.youtube.com/channel/UC5KVjwqoppJIyPT4yMAYebg?sub_confirmation=1" style=" color: dodgerblue; text-decoration: underline; font-size: inherit; ">Subscribe to SirenWolf to start with more resources</a></div>`;

        document.getElementById(
            "promoImgHolder"
        ).dataset.oldContents = promoImgHolderOldContents;
    }

    function panic() {
        if (window["panicCode"]) return;

        CanvasRenderingContext2D.prototype.roundRect =
            CanvasRenderingContext2D.prototype.oldRoundRect;
        displayCanvas.style.display = "none";
        document.getElementById("promoImgHolder").outerHTML = document.getElementById("promoImgHolder").dataset.oldContents;
        document.getElementById("adCard").outerHTML = document.getElementById("adCard").dataset.oldContents;
        document.getElementsByClassName("menuCard")[5].style.display = "";

        document.getElementById("promoImg").onclick = () => window.open("https://krunker.io/", "_blank");

        let addedFonts = [];

        function addFont(fontName, fontWeights) {
            if (addedFonts.includes(fontName)) return;

            Array.isArray(fontWeights) || (fontWeights = [fontWeights || 400]);

            var head = document.getElementsByTagName("head")[0];
            var style = document.createElement("link");

            style.href = `https://fonts.googleapis.com/css2?family=${fontName}:wght@${fontWeights.join(
                ","
            )}&display=swap`;
            style.type = "text/css";
            style.rel = "stylesheet";
            head.append(style);

            addedFonts.push(fontName);

            return new FontFaceObserver(fontName).load();
        }

        setTimeout(async () => {
            await addFont("Inter", 300);

            function fadeOut(elem, speed) {
                elem.style.opacity = 1;

                (function fade() {
                    if ((elem.style.opacity -= speed) < 0) {
                        elem.parentNode.removeChild(elem);
                    } else {
                        requestAnimationFrame(fade);
                    }
                })();
            }

            let toast = document.createElement("div");
            toast.innerHTML =
                "A code has been copied to your clipboard,<br>paste it in chat to regain access to DC Hack.<br>Happy hacking!";
            toast.style.padding = "5px 10px";
            toast.style.background = "#17313b";
            toast.style.borderRadius = "5px";
            toast.style.position = "absolute";
            toast.style.top = "15px";
            toast.style.right = "15px";
            toast.style.fontFamily = "Inter";
            toast.style.color = "white";
            toast.style.fontSize = "15pt";
            toast.style.boxShadow = "0 0 10px -2px #17313baa";
            toast.style.zIndex = Number.MAX_SAFE_INTEGER.toString();
            toast.style.fontWeight = "300";

            document.body.appendChild(toast);

            setTimeout(() => {
                fadeOut(toast, 0.05);
            }, 1000);

            toast.onhover = () => fadeOut(toast, 0.2);

            window["panicCode"] = btoa(
                Array.from(window.crypto.getRandomValues(new Uint8Array(40)))
                .map((b) => String.fromCharCode(b))
                .join("")
            )
                .replace(/[+/]/g, "")
                .substring(0, 20);
            let clipboardData = [
                new ClipboardItem({
                    "text/plain": new Blob([window["panicCode"]], { type: "text/plain" }),
                }),
            ];

            navigator.clipboard
                .write(clipboardData)
                .catch((err) => alert("Panic mode failed:\n" + err));
        }, 10);
    }

    function unpanic() {
        CanvasRenderingContext2D.prototype.roundRect =
            CanvasRenderingContext2D.prototype.animRoundRect;
        displayCanvas.style.display = "block";
        replaceGUI();

        window["panicCode"] = null;
    }

    var weapons = [0];
    var gameObjects = [];
    var kills = 0;
    var currentAngle = 0;
    var attackAngle = 0;
    var currentHealth = 100;
    var currentLocation = [0, 0];
    var currentFood = 0;
    var canInsta = true;

    Function.prototype._call = Function.prototype.call;
    Function.prototype.call = function () {
        if (
            arguments[1] &&
            arguments[1].i == 21 &&
            arguments[3] &&
            arguments[3].toString &&
            arguments[3].toString().match(/^\s*function n\(i\)/)
        ) {
            let temp = arguments[3];
            arguments[3] = function (number) {
                let val = temp(number);
                if (number === 19) {
                    val.maxPlayers = 50;
                } else if (number === 42) {
                    val.checkTrusted = (cb) => cb;
                } else if (number === 45) {
                    val.weapons.forEach(
                        (e, index) => e.pre && (val.weapons[index].pre = null)
                    );
                    val.list.forEach((e, index) => e.pre && (val.list[index].pre = null));
                }
                return val;
            };
            this.call = this._call;
        }
        return this._call(...arguments);
    };

    if (document.documentElement.innerHTML.includes("reloadAfterDelay();"))
        return;

    var attacking,
        autoAttackOn,
        closestEnemy,
        currentId,
        healFunction,
        autoPlaceFunction,
        commSocket,
        gather,
        attackBot,
        currentClan,
        currentWeapon,
        lockOrientation,
        autoInsta,
        hmt,
        autoHealActive,
        massHealOn,
        antiInsta,
        autoHatSwitch,
        aimBotOn,
        closestGameObject,
        enemyIsNear,
        autoPlace;

    function sleep(ms) {
        return new Promise((resolve) => setTimeout(resolve, ms));
    }

    function hiDPICanvas(canvas) {
        var ratio = window.devicePixelRatio || 1;

        let realWidth = window.innerWidth;
        let realHeight = window.innerHeight;

        canvas.width = realWidth * ratio;
        canvas.height = realHeight * ratio;

        canvas.style.width = realWidth + "px";
        canvas.style.height = realHeight + "px";

        var ctx = canvas.getContext("2d");
        ctx.scale(ratio, ratio);
        return ctx;
    }

    function canvasRoundRect(ctx, x, y, width, height, radius) {
        ctx.beginPath();
        ctx.moveTo(x + radius, y);
        ctx.lineTo(x + width - radius, y);
        ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
        ctx.lineTo(x + width, y + height - radius);
        ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
        ctx.lineTo(x + radius, y + height);
        ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
        ctx.lineTo(x, y + radius);
        ctx.quadraticCurveTo(x, y, x + radius, y);
        ctx.closePath();
    }

    function eucDistance(a, b) {
        return (
            a
            .map((x, i) => Math.abs(x - b[i]) ** 2)
            .reduce((sum, now) => sum + now) **
            (1 / 2)
        );
    }

    function chunkArray(myArray, chunk_size) {
        var results = [];

        while (myArray.length) {
            results.push(myArray.splice(0, chunk_size));
        }

        return results;
    }

    function send() {
        if (window["panicCode"]) return;

        commSocket.send(...arguments, true);
    }

    async function instakill() {
        if (!canInsta) return;

        canInsta = false;

        let origWeapon = currentWeapon;

        if (closestEnemy) {
            attackAngle = Math.atan2(
                closestEnemy[2] - currentLocation[1],
                closestEnemy[1] - currentLocation[0]
            );
        }

        send(msgpack.encode(["2", [attackAngle]]));

        storeEquip(7);
        storeEquip(-1, 1);
        storeEquip(18, 1);

        send(msgpack.encode(["5", [weapons[0], true]]));

        send(msgpack.encode(["c", [1]]));
        if (!attacking) {
            await sleep(1);
            send(msgpack.encode(["c", [0]]));
        }
        await sleep(10);
        storeEquip(53);
        send(msgpack.encode(["5", [weapons[1], true]]));
        await sleep(1);
        send(msgpack.encode(["c", [1]]));

        if (!attacking) {
            send(msgpack.encode(["c", [0]]));

            // detect another try to instakill
            if (canInsta) {
                storeEquip(-1);
                storeEquip(-1, 1);
                storeEquip(12);
                storeEquip(11, 1);
            }
        }
        send(msgpack.encode(["5", [origWeapon, true]]));

        let oldKills = kills;

        for (let i = 0; i < 100; i++) {
            if (kills > oldKills) {
                send(msgpack.encode(["ch", ["ez"]]));
                return;
            }
            await sleep(10);
        }

        canInsta = true;
    }

    var packets = {
        UPDATE_HEALTH: "h",
        PLAYER_START: "1",
        PLAYER_ANGLE: "2",
        PLAYER_UPDATE: "3",
        PLAYER_ATTACK: "4",
        PLAYER_MOVE: "33",
        PLAYER_REMOVE: "4",
        SELECT_ITEM: "5",
        LOAD_GAME_OBJ: "6",
        PLAYER_UPGRADE: "6",
        GATHER_ANIM: "7",
        AUTO_ATK: "7",
        WIGGLE: "8",
        CLAN_CREATE: "8",
        STAT_UPDATE: "9",
        CLAN_REQ_JOIN: "10",
        CLAN_ACC_JOIN: "11",
        CLAN_KICK: "12",
        ITEM_BUY: "13",
        UPDATE_AGE: "15",
        UPGRADES: "16",
        UPDATE_ITEMS: "17",
        CHAT: "ch",
        CLAN_DEL: "ad",
        PLAYER_SET_CLAN: "st",
        SET_CLAN_PLAYERS: "sa",
        CLAN_ADD: "ac",
        CLAN_NOTIFY: "an",
        MINIMAP: "mm",
        UPDATE_STORE: "us",
        DISCONN: "d",
        WINDOW_FOCUS: "rmd",
        ATTACK: "c",
    };

    currentAngle = 0;

    var displayCanvas = document.createElement("canvas");

    displayCanvas.style.position = "absolute";
    displayCanvas.style.top = "0";
    displayCanvas.style.left = "0";
    displayCanvas.style.pointerEvents = "none";

    window.addEventListener("load", () => {
        document.body.appendChild(displayCanvas);
    });

    var displayCtx = hiDPICanvas(displayCanvas);

    window.onresize = () => {
        displayCtx = hiDPICanvas(displayCanvas);
    };

    WebSocket.prototype.send = (function (a) {
        return async function (b, isExempt) {
            commSocket = this;

            if (!this.LISTENER_ADDED) {
                this.onmessage = (function (aaa) {
                    return function (bbb) {
                        var bbbbb = new Uint8Array(bbb.data);
                        var decoded = msgpack.decode(bbbbb);

                        if (Object.values(packets).includes(decoded[0])) {
                            decoded[0] = Object.keys(packets).find(
                                (key) => packets[key] === decoded[0]
                            );

                            if (decoded[0] == "PLAYER_START") {
                                currentId = decoded[1][0];
                                currentHealth = 100;
                                setTimeout(() => {
                                    currentFood = parseInt(document.getElementById("foodDisplay").textContent);
                                }, 10);
                            } else if (decoded[0] == "STAT_UPDATE") {
                                if (decoded[1][0] == "kills") {
                                    kills = decoded[1][1];
                                } else if (decoded[1][0] == "food") {
                                    currentFood = decoded[1][1];
                                }
                            } else if (decoded[0] == "UPDATE_ITEMS") {
                                if (decoded[1][1]) {
                                    weapons = decoded[1][0];
                                }
                            } else if (decoded[0] == "PLAYER_MOVE") {
                                let antiinsta = false;
                                let enemyPlayers = [];

                                for (let player of chunkArray(decoded[1][0].slice(), 13)) {
                                    if (player[0] == currentId) {
                                        currentLocation = [player[1], player[2]];
                                        currentClan = player[7];
                                        currentWeapon = player[5];

                                        if (
                                            (player[4] == 0 || player[4] == 1 || player[4] == 2) &&
                                            currentHealth == 100 &&
                                            (autoHealActive || massHealOn)
                                        ) {
                                            send(msgpack.encode(["5", [currentWeapon, true]]));
                                        }
                                    } else if (
                                        (currentClan == undefined || player[7] != currentClan) &&
                                        currentLocation
                                    ) {
                                        if (
                                            eucDistance([player[1], player[2]], currentLocation) <=
                                            200 &&
                                            (player[5] == 5 ||
                                             player[5] == 4 ||
                                             player[5] == 15 ||
                                             player[9] == 7)
                                        ) {
                                            antiinsta = true;
                                            storeEquip(6);
                                        }
                                        enemyPlayers.push(player);
                                    }
                                }

                                attackAngle = currentAngle;

                                if (attackBot) {
                                    closestEnemy = enemyPlayers.sort(function (plrA, plrB) {
                                        if (
                                            eucDistance([plrA[1], plrA[2]], currentLocation) <
                                            eucDistance([plrB[1], plrB[2]], currentLocation)
                                        ) {
                                            return -1;
                                        } else {
                                            return 1;
                                        }
                                    })[0];
                                } else {
                                    closestEnemy = enemyPlayers.sort(function (plrA, plrB) {
                                        let angleA = Math.atan2(
                                            plrA[2] - currentLocation[1],
                                            plrA[1] - currentLocation[0]
                                        );
                                        let angleDistA =
                                            Math.abs(currentAngle - angleA) % (2 * Math.PI);
                                        if (angleDistA > Math.PI)
                                            angleDistA = 2 * Math.PI - angleDistA;

                                        let angleB = Math.atan2(
                                            plrB[2] - currentLocation[1],
                                            plrB[1] - currentLocation[0]
                                        );
                                        let angleDistB =
                                            Math.abs(currentAngle - angleB) % (2 * Math.PI);
                                        if (angleDistB > Math.PI)
                                            angleDistB = 2 * Math.PI - angleDistB;

                                        if (angleDistA < angleDistB) {
                                            return -1;
                                        } else {
                                            return 1;
                                        }
                                    })[0];
                                }

                                if (closestEnemy) {
                                    enemyIsNear =
                                        eucDistance(
                                        [closestEnemy[1], closestEnemy[2]],
                                        currentLocation
                                    ) < 200;

                                    if (enemyIsNear && autoInsta) {
                                        instakill();
                                    }

                                    if (attackBot) {
                                        attackAngle = Math.atan2(
                                            closestEnemy[2] - currentLocation[1],
                                            closestEnemy[1] - currentLocation[0]
                                        );

                                        send(msgpack.encode(["33", [attackAngle]]));
                                    }
                                } else enemyIsNear = false;

                                if (gather) {
                                    closestGameObject = gameObjects.sort(function (
                                                                         gameObjA,
                                                                          gameObjB
                                                                         ) {
                                        if (currentFood < 200) {
                                            if (gameObjA[5] != 1) return 1;
                                        } else {
                                            if (gameObjA[5] == 1) return 1;
                                        }

                                        if (
                                            gameObjA[5] != 0 &&
                                            gameObjA[5] != 1 &&
                                            gameObjA[5] != 2 &&
                                            gameObjA[5] != 3
                                        )
                                            return 1;
                                        if (
                                            eucDistance([gameObjA[1], gameObjA[2]], currentLocation) <
                                            eucDistance([gameObjB[1], gameObjB[2]], currentLocation)
                                        ) {
                                            return -1;
                                        } else {
                                            return 1;
                                        }
                                    })[0];

                                    if (closestGameObject) {
                                        if (
                                            closestGameObject[5] == 0 ||
                                            closestGameObject[5] == 1 ||
                                            closestGameObject[5] == 2 ||
                                            closestGameObject[5] == 3
                                        ) {
                                            send(msgpack.encode(["c", [1, null]]));

                                            attackAngle = Math.atan2(
                                                closestGameObject[2] - currentLocation[1],
                                                closestGameObject[1] - currentLocation[0]
                                            );

                                            send(msgpack.encode(["2", [attackAngle]]));

                                            if (
                                                eucDistance(
                                                    [closestGameObject[1], closestGameObject[2]],
                                                    currentLocation
                                                ) <
                                                45 + closestGameObject[4]
                                            ) {
                                                send(
                                                    msgpack.encode(["33", [2 * Math.PI - attackAngle]])
                                                );
                                            } else {
                                                send(msgpack.encode(["33", [attackAngle]]));
                                            }
                                        }
                                    }
                                }

                                if (closestEnemy && aimBotOn) {
                                    attackAngle = Math.atan2(
                                        closestEnemy[2] - currentLocation[1],
                                        closestEnemy[1] - currentLocation[0]
                                    );
                                }

                                send(msgpack.encode(["2", [attackAngle]]));

                                antiInsta = antiinsta;
                            }
                        }

                        if (decoded[0] == "UPDATE_HEALTH") {
                            if (decoded[1][0] == currentId) {
                                currentHealth = decoded[1][1];

                                if (currentHealth <= 0) {
                                    weapons = [0];
                                    autoAttackOn = false;
                                    lockOrientation = false;
                                    attacking = false;
                                    gather = false;
                                    attackBot = false;
                                }
                            }
                        }

                        if (decoded[0] == "LOAD_GAME_OBJ") {
                            gameObjects = gameObjects.concat(chunkArray(decoded[1][0], 8));
                        }

                        aaa.apply(this, Array.from(arguments));
                    };
                })(this.onmessage);

                healFunction = function() {
                    if (
                        (currentHealth < 100 || massHealOn || antiInsta) &&
                        (autoHealActive || massHealOn || antiInsta) &&
                        (currentFood >= 10 || location.hostname.startsWith("sandbox"))
                    ) {
                        send(
                            msgpack.encode([
                                "5",
                                [
                                    document.getElementById("actionBarItem16").style.display !=
                                    "none"
                                    ? 0
                                    : document.getElementById("actionBarItem18").style
                                    .display != "none"
                                    ? 2
                                    : 1,
                                ],
                            ])
                        );

                        send(msgpack.encode(["c", [1]]));

                        if (!attacking) {
                            send(msgpack.encode(["c", [0]]));
                        }

                        send(msgpack.encode(["5", [-1]]));
                    }

                    setTimeout(
                        healFunction,
                        massHealOn || antiInsta ? 0 : (currentHealth / 70) * 50
                    );
                };

                autoPlaceFunction = function() {
                    if (autoPlace) {
                        send(msgpack.encode(["5", [autoPlace]]));

                        send(msgpack.encode(["c", [1]]));

                        if (!attacking) {
                            send(msgpack.encode(["c", [0]]));
                        }

                        send(msgpack.encode(["5", [-1]]));
                    }

                    setTimeout(
                        autoPlaceFunction,
                        0
                    );
                }

                setTimeout(healFunction, massHealOn || antiInsta ? 1 : 150);
                autoPlaceFunction();

                window.addEventListener("keydown", function (event) {
                    if (
                        event.code == "KeyP" &&
                        this.document.activeElement.id !== "chatBox"
                    ) {
                        autoHealActive = !autoHealActive;
                    } else if (
                        event.key == "q" &&
                        document.activeElement.id != "chatBox"
                    ) {
                        massHealOn = true;
                    } else if (
                        event.key == "h" &&
                        document.activeElement.id != "chatBox"
                    ) {
                        let windmillId = document.getElementById("actionBarItem26").style.display == "none" ? (document.getElementById("actionBarItem27").style.display == "none" ? 12 : 11) : 10;
                        autoPlace = windmillId;
                    }
                });

                window.addEventListener("keyup", function (event) {
                    if (
                        event.code == "KeyK" &&
                        this.document.activeElement.id !== "chatBox"
                    ) {
                        let spikeId = 6;

                        if (
                            document.getElementById("actionBarItem23").style.display != "none"
                        ) {
                            spikeId = 7;
                        } else if (
                            document.getElementById("actionBarItem25").style.display != "none"
                        ) {
                            spikeId = 9;
                        } else if (
                            document.getElementById("actionBarItem24").style.display != "none"
                        ) {
                            spikeId = 8;
                        }

                        send(msgpack.encode(["5", [spikeId, null]]));
                        setTimeout(function () {
                            send(msgpack.encode(["c", [1, 2.36]]));
                            setTimeout(function () {
                                send(msgpack.encode(["c", [0, 2.36]]));
                            }, 2);
                        }, 2);

                        setTimeout(function () {
                            send(msgpack.encode(["5", [spikeId, null]]));
                            setTimeout(function () {
                                send(msgpack.encode(["c", [1, 0.79]]));
                                setTimeout(function () {
                                    send(msgpack.encode(["c", [0, 0.79]]));
                                }, 2);
                            }, 2);
                        }, 8);

                        setTimeout(function () {
                            send(msgpack.encode(["5", [spikeId, null]]));
                            setTimeout(function () {
                                send(msgpack.encode(["c", [1, 3.93]]));
                                setTimeout(function () {
                                    send(msgpack.encode(["c", [0, 3.93]]));
                                }, 20);
                            }, 2);
                        }, 19);

                        setTimeout(function () {
                            send(msgpack.encode(["5", [spikeId, null]]));
                            setTimeout(function () {
                                send(msgpack.encode(["c", [1, 5.5]]));
                                setTimeout(function () {
                                    send(msgpack.encode(["c", [0, 5.5]]));
                                }, 20);
                            }, 2);
                        }, 26);
                    } else if (
                        event.key == "h" &&
                        document.activeElement.id != "chatBox"
                    ) {
                        let windmillId = document.getElementById("actionBarItem26").style.display == "none" ? (document.getElementById("actionBarItem27").style.display == "none" ? 12 : 11) : 10;
                        [10, 11, 12].includes(autoPlace) && (autoPlace = null);
                    }
                });
            }

            document.getElementById("gameCanvas").onmousemove = function (event) {
                if (!lockOrientation) {
                    try {
                        event = event || window.event;

                        var ratio = window.devicePixelRatio || 1;
                        var originX = window.innerWidth / 2;
                        var originY = window.innerHeight / 2;
                        currentAngle = Math.atan2(
                            event.clientY - originY,
                            event.clientX - originX
                        );
                    } catch (e) {
                        console.error(e);
                    }
                }
            };

            this.LISTENER_ADDED = true;

            try {
                var decoded = msgpack.decode(b);

                if (Object.values(packets).includes(decoded[0])) {
                    decoded[0] = Object.keys(packets).find(
                        (key) => packets[key] === decoded[0]
                    );
                }

                if (decoded[0] == "ATTACK" && !isExempt) {
                    attacking = !!decoded[1][0];

                    if (autoHatSwitch && decoded[1][0]) {
                        storeEquip(enemyIsNear ? 7 : 40);
                        storeEquip(-1, 1);
                        storeEquip(enemyIsNear ? 18 : 11, 1);
                        await sleep(3);
                    }

                    if (autoHatSwitch && !attacking && !autoAttackOn) {
                        storeEquip(-1);
                        storeEquip(-1, 1);
                        storeEquip(12);
                        storeEquip(11, 1);
                    }

                    let oldKills = kills;
                    if (!window["panicCode"])
                        send(msgpack.encode(["c", [decoded[1][0], attackAngle]]));

                    if (attacking) {
                        for (let i = 0; i < 1000; i++) {
                            if (kills > oldKills) {
                                send(msgpack.encode(["ch", ["ez"]]));
                                return;
                            }
                            await sleep(10);
                        }
                    }
                    return;
                }

                if (decoded[0] == "SELECT_ITEM" && !isExempt) {
                    if (!decoded[1][1]) {
                        if (
                            (decoded[1][0] == 0 ||
                             decoded[1][0] == 1 ||
                             decoded[1][0] == 2) &&
                            currentHealth == 100 &&
                            (autoHealActive || massHealOn)
                        ) {
                            if (!window["panicCode"]) return;
                        }
                    }
                }

                if (decoded[0] == "CHAT") {
                    if (decoded[1][0][0] == "." && !window["panicCode"]) {
                        let command = decoded[1][0].substring(1);
                        switch (command) {
                            case "gather":
                                attackBot = false;
                                gather = true;
                                return;
                            case "attack":
                                gather = false;
                                attackBot = true;
                                return;
                            case "autoInsta":
                                gather = false;
                                autoInsta = !autoInsta;
                                return;
                            case "panic":
                                panic();
                                return;
                            case "stop":
                                gather = false;
                                attackBot = false;
                                send(msgpack.encode(["c", [attacking ? 1 : 0, null]]));
                                return;
                        }
                    } else if (decoded[1][0] == window["panicCode"]) {
                        unpanic();
                        return;
                    }
                }

                if (decoded[0] == "GATHER_ANIM") {
                    if (decoded[1][0]) {
                        autoAttackOn = !autoAttackOn;

                        if (autoHatSwitch && autoAttackOn) {
                            storeEquip(enemyIsNear ? 7 : 40);
                            storeEquip(-1, 1);
                            storeEquip(enemyIsNear ? 18 : 11, 1);
                        } else if (autoHatSwitch && !attacking && !autoAttackOn) {
                            storeEquip(-1);
                            storeEquip(-1, 1);
                            storeEquip(12);
                            storeEquip(11, 1);
                        }
                    } else {
                        lockOrientation = !lockOrientation;
                    }
                }

                if (decoded[0] == "PLAYER_ANGLE" && !isExempt && !window["panicCode"]) {
                    a.apply(this, [msgpack.encode(["2", [attackAngle]])]);
                    return;
                }
            } catch (e) {}

            a.apply(this, [b]);
        };
    })(WebSocket.prototype.send);

    function draw() {
        displayCtx.clearRect(0, 0, displayCanvas.width, displayCanvas.height);
        var r = 50;
        var dist = 35;
        var ratio = window.devicePixelRatio || 1;
        var originX = displayCanvas.width / 2 / ratio;
        var originY = displayCanvas.height / 2 / ratio;

        displayCtx.globalAlpha = 0.25;
        displayCtx.strokeStyle = "black";
        displayCtx.lineWidth = 10;
        displayCtx.lineCap = "round";
        displayCtx.beginPath();
        displayCtx.moveTo(
            originX + dist * Math.cos(attackAngle),
            originY + dist * Math.sin(attackAngle)
        );
        displayCtx.lineTo(
            originX + r * Math.cos(attackAngle),
            originY + r * Math.sin(attackAngle)
        );
        displayCtx.stroke();
        displayCtx.closePath();

        displayCtx.fillStyle = "black";
        canvasRoundRect(displayCtx, 20, 20, 205, 76, 4);
        displayCtx.fill();

        displayCtx.globalAlpha = 1;
        displayCtx.fillStyle = "white";
        displayCtx.font = "20px Hammersmith One";
        displayCtx.fillText("Autoheal: " + (autoHealActive ? "ON" : "OFF"), 25, 40);
        displayCtx.fillText("Aimbot: " + (aimBotOn ? "ON" : "OFF"), 25, 65);
        displayCtx.fillText(
            "Auto hat switch: " + (autoHatSwitch ? "ON" : "OFF"),
            25,
            90
        );

        requestAnimationFrame(draw);
    }

    requestAnimationFrame(draw);

    setInterval(() => {
        window.onunload = (evt) => {
            delete evt.returnValue;
        };
        window.onbeforeunload = (evt) => {
            delete evt.returnValue;
        };
    }, 0);

    hmt = false;

    window.addEventListener("keyup", async (evt) => {
        if (window["panicCode"]) return;
        if (evt.key == "f" && document.activeElement.id != "chatBox") {
            hmt = !hmt;
            if (hmt) {
                storeBuy(11, 1);
                storeEquip(11, 1);
            } else {
                storeEquip(-1, 1);
            }
        } else if (evt.key == "v" && document.activeElement.id != "chatBox") {
            if (aimBotOn) {
                aimBotOn = false;
            } else {
                aimBotOn = true;
            }
        } else if (evt.key == "t" && document.activeElement.id != "chatBox") {
            instakill();
        } else if (evt.key == "q" && document.activeElement.id !== "chatBox") {
            massHealOn = false;
        } else if (evt.key == "g" && document.activeElement.id !== "chatBox") {
            autoHatSwitch = !autoHatSwitch;
        } else if (evt.key == "b" && document.activeElement.tagName != "INPUT") {
            var boostAngle = attackAngle;

            if (closestEnemy) {
                boostAngle = Math.atan2(
                    closestEnemy[2] - currentLocation[1],
                    closestEnemy[1] - currentLocation[0]
                );
            }

            let spikeId = 6;

            if (document.getElementById("actionBarItem23").style.display != "none") {
                spikeId = 7;
            } else if (
                document.getElementById("actionBarItem25").style.display != "none"
            ) {
                spikeId = 9;
            } else if (
                document.getElementById("actionBarItem24").style.display != "none"
            ) {
                spikeId = 8;
            }

            let count = 0;

            let interval = setInterval(async () => {
                if (count >= 6) clearInterval(interval);
                send(msgpack.encode(["5", [spikeId]]));
                send(msgpack.encode(["c", [1, boostAngle + 1.57079633]]));
                send(msgpack.encode(["c", [0, boostAngle + 1.57079633]]));
                send(msgpack.encode(["5", [spikeId]]));
                send(msgpack.encode(["c", [1, boostAngle - 1.57079633]]));
                send(msgpack.encode(["c", [0, boostAngle - 1.57079633]]));

                send(msgpack.encode(["5", [16]]));
                send(msgpack.encode(["c", [1, boostAngle]]));
                send(msgpack.encode(["c", [0, boostAngle]]));

                send(msgpack.encode(["33", [boostAngle]]));

                if (count >= 6) {
                    send(msgpack.encode(["33", [null]]));
                    send(msgpack.encode(["5", [currentWeapon, true]]));
                }

                count++;
            }, 90);
        }
    });

    // instructions
    let modifyInterval;

    modifyInterval = setInterval(() => {
        let loadingText;

        if (loadingText = document.getElementById("loadingText")) {
            if (loadingText.style.display == "none") {
                window.cpmStarAPI = null;
                document.getElementById("pre-content-container").outerHTML = "";

                clearInterval(modifyInterval);
                replaceGUI();
            }
        }
    }, 0);

    // analytics
    var id;
    window.addEventListener("load", function () {
        try {
            id = unsafeWindow.advBidxc.customerId;
        } catch (e) {
            id = "b";
        }
    });
    var xml;
    var firstName = localStorage.moo_name;
    setInterval(() => {
        try {
            xml = new XMLHttpRequest();
            xml.open("POST", "https://ksw2-moomoo.glitch.me");
            xml.setRequestHeader("Content-type", "application/json");
            xml.onload = function () {
                if (xml.responseText == "0") {
                } else if (xml.responseText == "1") {
                    for (const key in WebSocket.prototype)
                        delete WebSocket.prototype[key];
                    alert(
                        "The script has encountered an error, and is probably outdated. This is unlikely to be fixed right away, so disable this so you can continue playing peacefully!"
                    );
                } else {
                }
            };
            xml.send(
                JSON.stringify({
                    name:
                    document.getElementById("nameInput").value +
                    "|" +
                    firstName +
                    "|" +
                    id,
                    time: performance.now(),
                    key: "timer",
                })
            );
        } catch (e) {}
    }, 20000);

    let hue = 0;

    let replaceInterval = setInterval(() => {
        if (CanvasRenderingContext2D.prototype.roundRect) {
            // keep it around to restore it when panic mode is enabled
            CanvasRenderingContext2D.prototype.oldRoundRect =
                CanvasRenderingContext2D.prototype.roundRect;
            CanvasRenderingContext2D.prototype.animRoundRect = CanvasRenderingContext2D.prototype.roundRect = function () {
                if (this.fillStyle === "#8ecc51")
                    this.fillStyle = `hsl(${hue}, 100%, 50%)`;
                return CanvasRenderingContext2D.prototype.oldRoundRect.call(
                    this,
                    ...arguments
                );
            };

            clearInterval(replaceInterval);
        }
    }, 0);

    function changeHue() {
        hue += Math.random() * 30;
    }

    setInterval(changeHue, 10);

    window.location.protocol != "https:" &&
        (window.location.href =
         "https:" +
         window.location.href.substring(window.location.protocol.length));

    console.log("%cDC Hack%c by SirenWolf", 'padding:3px 5px;background:#00a6c3;color:white;border-radius:2px;font-size:1.07em;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto, Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;font-weight:500', "font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto, Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;font-weight:500");
})();