Kour.io Vortex Menu

Invisibility, ESP, Aimbot

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Kour.io Vortex Menu
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB...
// @match        *://kour.io/*
// @author       Vortex
// @description  Invisibility, ESP, Aimbot
// @run-at       document-start
// @grant        unsafeWindow
// @version 1.0
// @namespace https://greasyfork.org/users/1572944
// ==/UserScript==

(function () {
    ("use strict");

    /***************************************
     * Performance.now Wrapper (Speedhack deaktiviert)
     ***************************************/
    const originalPerfNow = performance.now.bind(performance);
    function updatePerformanceNow() {
        performance.now = originalPerfNow;
    }
    updatePerformanceNow();

    /***************************************
     * Invisibility + Instakill
     ***************************************/
    const Signatures = {
        damageTaken: "f3 04 c8 02 f5 15 04",
        updateState: "f3 02 fd 02 f4 03 c8",
    };

    function hexOf(buf) {
        return Array.from(new Uint8Array(buf))
            .map((b) => b.toString(16).padStart(2, "0"))
            .join(" ");
    }

    function shouldBlockDamage(ev) {
        return (
            ev.data instanceof ArrayBuffer &&
            hexOf(ev.data).startsWith(Signatures.damageTaken) &&
            kourInstance.config.Invisible
        );
    }

    /***************************************
     * AntiAim
     ***************************************/
    const HEADER_SIG = [0xf3, 0x02, 0xfd, 0x02, 0xf4, 0x03];
    const SAFE_MIN_LENGTH = 70;

    function arrayStartsWith(arr, prefix) {
        if (arr.length < prefix.length) return false;
        for (let i = 0; i < prefix.length; i++) {
            if (arr[i] !== prefix[i]) return false;
        }
        return true;
    }

    function isSafeToModify(packet) {
        return packet.byteLength >= SAFE_MIN_LENGTH && !kourInstance.config.Invisible && kourInstance.config.AntiAim;
    }

    function modifyPacket(packet) {
        const view = new DataView(packet.buffer, packet.byteOffset, packet.byteLength);

        let x = view.getFloat32(28, true);
        const xDelta = Math.random() < 0.5 ? -0.2 : 0.2;
        x += xDelta;
        view.setFloat32(28, x, true);

        let z = view.getFloat32(36, true);
        const zDelta = Math.random() < 0.5 ? -0.2 : 0.2;
        z += zDelta;
        view.setFloat32(36, z, true);

        return packet;
    }

    /***************************************
     * Spinbot Angle Modifier
     ***************************************/
    const crazyNumbers = [
        3822588238527201280.00, -1857736430059520.00, 0.00, -0.00, -1.4284511533486216e+24,
        -0.00, 0.00, 0.12, -1.8763868419170566e+22, 0.00, 556457979374085341184.00, 0.00,
        -228963383699832832.00, -0.00, 478289722746077184.00, 0.00, -1707527.88, 0.00,
        2.0849836473005435e+26, -0.00, 343366451878428672.00, -0.00, 0.00, -0.00, -398.99,
        -7.327271464138011e+37, -0.00, 7.479676797675635e+34, 6077727.50, -112678365030856523776.00,
        64406255347955662848.00, -0.00, 3.9367609144474995e+28, -0.68, -4.1272324222675643e+34,
        0.00, -34401746419712.00, 256284.98, -0.00, -992099.94, -46124.25, -0.00, -0.23,
        3573135.75, -0.00, 3.4937574108676156e+24, 31446140.00, -0.00, 0.00,
        -2.633920784508417e+22, 1.5002101046880594e+23, -662611.81, 0.00, -7.82,
        2.1554711763577515e+33, -4781238408011841536.00, -8.267893275317273e+33, -0.00, 0.00,
        -4.7050078084659084e+24, 63447551577279168512.00, 0.00, 5.614778816753592e+36, 5183327.50,
    ];

    let currentIndex = 0;
    const ANGLE_OFFSET = 0x38;

    /***************************************
     * WebSocket Hooking
     ***************************************/
    (function hookWS() {
        const OrigWS = unsafeWindow.WebSocket;
        unsafeWindow.WebSocket = function (...args) {
            const ws = new OrigWS(...args);

            const { addEventListener } = ws;
            ws.addEventListener = (type, fn, opts) =>
                addEventListener.call(
                    ws,
                    type,
                    type === "message" ? (ev) => shouldBlockDamage(ev) || fn(ev) : fn,
                    opts
                );

            const protoDesc = Object.getOwnPropertyDescriptor(OrigWS.prototype, "onmessage");
            Object.defineProperty(ws, "onmessage", {
                set(fn) {
                    protoDesc.set.call(this, (ev) => shouldBlockDamage(ev) || fn(ev));
                },
                get() {
                    return protoDesc.get.call(this);
                },
            });

            const originalSend = ws.send;
            ws.send = function (data) {
                if (data instanceof ArrayBuffer || data instanceof Uint8Array) {
                    let packet = data instanceof Uint8Array ? data : new Uint8Array(data);

                    const hex = hexOf(packet);

                    if (hex.startsWith(Signatures.updateState) && kourInstance.config.Instakill) {
                        for (let i = 0; i < 41; i++) originalSend.call(ws, data);
                        return;
                    }

                    if (arrayStartsWith(packet, HEADER_SIG)) {
                        if (isSafeToModify(packet)) {
                            packet = modifyPacket(packet);
                            data = packet.buffer;
                        }

                        if (kourInstance.config.SpinBot && packet.byteLength >= ANGLE_OFFSET + 4 && !kourInstance.config.Invisible) {
                            const view = new DataView(data);
                            const num = crazyNumbers[currentIndex];

                            view.setFloat32(ANGLE_OFFSET, num, true);

                            currentIndex++;
                            if (currentIndex >= crazyNumbers.length) currentIndex = 0;
                        }
                    }
                }

                return originalSend.call(this, data);
            };

            return ws;
        };

        unsafeWindow.WebSocket.prototype = OrigWS.prototype;
    })();

    /***************************************
     * Config Object
     ***************************************/
    class Kour {
        constructor() {
            this.config = {
                Invisible: true,
                Instakill: false,
                AntiAim: false,
                SpinBot: false,
                airStrafing: true,
            };
        }
    }

    const kourInstance = new Kour();
    unsafeWindow.kourInstance = kourInstance;

    /***************************************
     * Skin Changer (Lobby Only!)
     ***************************************/
    const skins = [
        { name: "KBI Agent", id: "12" },
        { name: "James Kour", id: "13" },
        { name: "President", id: "14" },
        { name: "Doctor", id: "15" },
        { name: "Trickster", id: "16" },
        { name: "Royal Guard", id: "17" },
        { name: "Xmas", id: "18" },
        { name: "Kelvis", id: "19" },
        { name: "Princess Pink", id: "20" },
        { name: "Princess White", id: "21" },
        { name: "Princess Bee", id: "22" },
        { name: "Princess Leaf", id: "23" },
        { name: "Koura Kraft", id: "24" },
        { name: "Green Hologram", id: "25" },
        { name: "Hologrape", id: "26" },
        { name: "Peter", id: "27" },
        { name: "Chicken", id: "28" },
        { name: "Chickoletta", id: "29" },
        { name: "Kyle", id: "30" },
        { name: "Shadowgram", id: "32" },
        { name: "IceBunny", id: "33" },
        { name: "CocoBunny", id: "34" },
        { name: "Kourean", id: "35" },
        { name: "KourG", id: "36" },
        { name: "Hackour", id: "37" },
        { name: "Golden Hackour", id: "38" },
        { name: "Gas Man", id: "39" },
        { name: "Terrorist", id: "40" },
        { name: "Counter Terrorist", id: "41" },
        { name: "Ambush", id: "42" },
        { name: "Baby Kour", id: "43" },
        { name: "Poacher", id: "44" },
        { name: "Astronaut", id: "45" },
        { name: "Kour Parrot", id: "46" },
        { name: "Kour Pirate", id: "47" },
        { name: "Legionaut", id: "48" },
        { name: "Blue Hologram", id: "49" },
        { name: "Mr Wireframe", id: "50" },
        { name: "Mythian", id: "51" },
        { name: "Kour Trooper", id: "52" },
        { name: "Kour Craft", id: "53" },
        { name: "Kour Green Soldier", id: "54" },
        { name: "Yellow Astronaut", id: "55" },
        { name: "Orange Astronaut", id: "56" },
        { name: "Red Astronaut", id: "57" },
        { name: "Blue Astronaut", id: "58" },
        { name: "Kour Banana", id: "59" },
        { name: "Mrs Kour", id: "60" },
        { name: "Investor Inverted", id: "61" },
        { name: "Kour Jungler", id: "62" },
        { name: "Skinny Baby", id: "63" },
        { name: "KourTuber", id: "64" },
        { name: "Red Hologram", id: "65" },
        { name: "White Hologram", id: "66" },
        { name: "Orange Hologram", id: "67" },
        { name: "Dark Blue Hologram", id: "68" },
        { name: "Brown Hologram", id: "69" },
        { name: "Yellow Hologram", id: "70" },
        { name: "Dark Red Hologram", id: "71" },
        { name: "Kourist", id: "72" },
        { name: "Firefighter", id: "73" },
        { name: "FireKour", id: "74" },
        { name: "Kour Thief", id: "75" },
        { name: "Kour Burger", id: "76" },
        { name: "Kour Fan", id: "77" },
        { name: "Kour Brady", id: "78" },
        { name: "LeKour James", id: "79" },
        { name: "Uncle Kour", id: "80" },
        { name: "Chef", id: "81" },
        { name: "KourObby", id: "82" },
        { name: "Legionary", id: "83" },
        { name: "Kitty Kour One", id: "84" },
        { name: "Kitty Kour Two", id: "85" },
        { name: "Kitty Kour Three", id: "86" },
        { name: "Kour Crafter", id: "87" },
        { name: "RTX", id: "88" },
        { name: "Loony Kour", id: "89" },
        { name: "Kour Shocker", id: "90" },
        { name: "Kourkin", id: "91" },
        { name: "Forest Kour", id: "92" },
        { name: "Slender Kour", id: "93" },
        { name: "Drakour", id: "94" },
        { name: "Christmas2024", id: "95" },
        { name: "Deer2024", id: "96" }
    ];

    function setSkin(skinID) {
        firebase
            .database()
            .ref("users/" + firebase.auth().currentUser.uid)
            .child("skin")
            .set(skinID);
        showUserDetails(
            firebase.auth().currentUser.email,
            firebase.auth().currentUser
        );
    }

    /***************************************
     * Profile Stats
     ***************************************/
    function setStat(stat, value) {
        const parsedValue = parseInt(value, 10);
        const finalValue = isNaN(parsedValue) ? value : parsedValue;
        firebase
            .database()
            .ref("users/" + firebase.auth().currentUser.uid + "/public")
            .child(stat)
            .set(finalValue);
        showUserDetails(
            firebase.auth().currentUser.email,
            firebase.auth().currentUser
        );
    }

    /***************************************
     * Clan Editing
     ***************************************/
    function overrideCreateClan() {
        if (typeof createClan === 'function') {
            createClan = function (clanName, leaderUserId, clanColor, reqID) {
                unityInstanceWrapper.sendMessage(firebaseObjName, 'OnSetDataNew', clanName + "&" + reqID);
            };
        } else {
            setTimeout(overrideCreateClan, 500);
        }
    }
    overrideCreateClan();

    /***************************************
     * Class Kills
     ***************************************/
    const classMapKills = {
        Soldier: "class0kills",
        Hitman: "class1kills",
        Gunner: "class2kills",
        Heavy: "class3kills",
        Rocketeer: "class4kills",
        Agent: "class5kills",
        Brawler: "class6kills",
        Investor: "class7kills",
        Assassin: "class8kills",
        Juggernaut: "class9kills",
        Recon: "class10kills",
        Pyro: "class11kills",
        Rayblader: "class15kills",
    };

    function setClassKills() {
        const existingDialog = document.getElementById("classSelectionDialog");
        if (existingDialog) existingDialog.remove();

        const dlg = document.createElement("div");
        dlg.id = "classSelectionDialog";
        Object.assign(dlg.style, {
            position: "fixed",
            top: "50%",
            left: "50%",
            transform: "translate(-50%, -50%)",
            background: "radial-gradient(circle at top, #13152a 0%, #050712 70%)",
            color: "#f3f3ff",
            padding: "18px",
            zIndex: "10002",
            fontFamily: "Segoe UI, Arial, sans-serif",
            fontSize: "13px",
            borderRadius: "12px",
            boxShadow: "0 0 20px rgba(0,0,0,0.75)",
            width: "320px",
            maxHeight: "420px",
            overflowY: "auto",
            border: "1px solid rgba(0,255,200,0.45)",
        });

        const title = document.createElement("div");
        title.textContent = "Class Kills bearbeiten";
        Object.assign(title.style, {
            fontWeight: "bold",
            fontSize: "16px",
            marginBottom: "10px",
            textAlign: "center",
            color: "#00ffd5",
        });
        dlg.appendChild(title);

        const grid = document.createElement("div");
        Object.assign(grid.style, {
            display: "grid",
            gridTemplateColumns: "repeat(2, minmax(0, 1fr))",
            gap: "6px",
        });

        Object.keys(classMapKills).forEach((className) => {
            const btn = document.createElement("button");
            btn.textContent = className;
            Object.assign(btn.style, {
                padding: "7px 6px",
                cursor: "pointer",
                background: "linear-gradient(135deg, #15172b, #1f2240)",
                border: "1px solid rgba(0,255,200,0.3)",
                borderRadius: "6px",
                fontSize: "12px",
                color: "#e9e9ff",
                transition: "all 0.18s",
                textAlign: "center",
            });

            btn.addEventListener("mouseover", () => {
                btn.style.background = "linear-gradient(135deg, #202542, #2c3253)";
                btn.style.boxShadow = "0 0 6px rgba(0,255,200,0.35)";
                btn.style.transform = "translateY(-1px)";
            });
            btn.addEventListener("mouseout", () => {
                btn.style.background = "linear-gradient(135deg, #15172b, #1f2240)";
                btn.style.boxShadow = "none";
                btn.style.transform = "translateY(0)";
            });

            btn.addEventListener("click", () => {
                const killsValue = prompt(
                    `Neue Kill-Anzahl für ${className} eingeben:`,
                    "10000"
                );
                if (killsValue === null) return;
                const numKills = Number(killsValue);
                if (isNaN(numKills)) {
                    alert("Bitte eine gültige Zahl eingeben!");
                    return;
                }
                const dbField = classMapKills[className];
                updateClassKills(dbField, numKills);
                dlg.remove();
            });

            grid.appendChild(btn);
        });

        dlg.appendChild(grid);

        const closeBtn = document.createElement("button");
        closeBtn.textContent = "Schließen";
        Object.assign(closeBtn.style, {
            width: "100%",
            marginTop: "12px",
            padding: "7px",
            cursor: "pointer",
            background: "linear-gradient(135deg, #3b1f32, #52213d)",
            border: "1px solid rgba(255,80,120,0.5)",
            borderRadius: "6px",
            color: "#ffe6f0",
            transition: "all 0.18s",
        });
        closeBtn.addEventListener("mouseover", () => {
            closeBtn.style.background = "linear-gradient(135deg, #5a2544, #7a294f)";
        });
        closeBtn.addEventListener("mouseout", () => {
            closeBtn.style.background = "linear-gradient(135deg, #3b1f32, #52213d)";
        });
        closeBtn.addEventListener("click", () => dlg.remove());
        dlg.appendChild(closeBtn);

        document.body.appendChild(dlg);
    }

    function updateClassKills(classField, killCount) {
        if (!firebase.auth().currentUser) {
            console.log("[Vortex Menu] User ist nicht eingeloggt");
            return;
        }

        const updateData = {};
        updateData[classField] = killCount;

        firebase
            .database()
            .ref(`users/${firebase.auth().currentUser.uid}`)
            .update(updateData)
            .then(() => {
                showUserDetails(
                    firebase.auth().currentUser.email,
                    firebase.auth().currentUser
                );
                console.log(
                    `[Vortex Menu] ${classField} erfolgreich auf ${killCount} gesetzt`
                );
            })
            .catch((err) => {
                console.error(`[Vortex Menu] Fehler beim Updaten von ${classField}:`, err);
            });
    }

    /***************************************
     * Stats Changer
     ***************************************/
    function updateKDStats(kills) {
        if (!firebase.auth().currentUser) {
            console.log("[Vortex Menu] User ist nicht eingeloggt");
            alert("Bitte zuerst einloggen!");
            return;
        }

        const updateData = { totalKills: kills };

        firebase
            .database()
            .ref(`users/${firebase.auth().currentUser.uid}`)
            .update(updateData)
            .then(() => {
                showUserDetails(
                    firebase.auth().currentUser.email,
                    firebase.auth().currentUser
                );
                console.log(
                    `[Vortex Menu] Stats aktualisiert: Kills=${kills}`
                );
            })
            .catch((err) => {
                console.error("[Vortex Menu] Fehler beim Stats-Update:", err);
            });
    }

    function setKDStats() {
        const kills = prompt("Neue Total Kills eingeben:", "1337");
        if (kills === null) return;
        const parsedKills = Number(kills);

        if (isNaN(parsedKills)) {
            alert("Bitte eine gültige Zahl für Kills eingeben.");
            return;
        }

        updateKDStats(parsedKills);
    }

    /***************************************
     * Air strafing
     ***************************************/
    let spaceHeld = false;
    let turningLeft = false;
    let turningRight = false;

    let lastMoveTime = 0;
    const activeTimeout = 150;

    document.addEventListener('mousemove', e => {
        if (e.movementX < 0) {
            turningLeft = true;
            turningRight = false;
        } else if (e.movementX > 0) {
            turningRight = true;
            turningLeft = false;
        }
        lastMoveTime = Date.now();
    });

    document.addEventListener('keydown', e => {
        if (e.code === 'Space') spaceHeld = true;
    });

    document.addEventListener('keyup', e => {
        if (e.code === 'Space') spaceHeld = false;
    });

    function simulateKey(code, down = true) {
        const event = new KeyboardEvent(down ? 'keydown' : 'keyup', {
            code: code,
            key: code.replace('Key', ''),
            keyCode: code === 'KeyA' ? 65 : 68,
            which: code === 'KeyA' ? 65 : 68,
            bubbles: true,
            cancelable: true,
        });
        document.dispatchEvent(event);
    }

    let aHeld = false;
    let dHeld = false;

    function loop() {
        const now = Date.now();
        const mouseActive = (now - lastMoveTime) < activeTimeout;
        if (kourInstance.config.airStrafing) {
            if (spaceHeld && mouseActive) {
                if (turningLeft && !aHeld) {
                    simulateKey('KeyA', true);
                    aHeld = true;
                } else if (!turningLeft && aHeld) {
                    simulateKey('KeyA', false);
                    aHeld = false;
                }

                if (turningRight && !dHeld) {
                    simulateKey('KeyD', true);
                    dHeld = true;
                } else if (!turningRight && dHeld) {
                    simulateKey('KeyD', false);
                    dHeld = false;
                }
            } else {
                if (aHeld) {
                    simulateKey('KeyA', false);
                    aHeld = false;
                }
                if (dHeld) {
                    simulateKey('KeyD', false);
                    dHeld = false;
                }
            }

            requestAnimationFrame(loop);
        }
    }
    loop();

    /***************************************
     * ESP
     ***************************************/
    let gl = null;
    const filters = [
        { min: 1481, max: 1483 },
        { min: 1553, max: 1555 },
        { min: 5615, max: 5617 },
        { min: 3875, max: 3877 },
    ];

    window.espEnabled = true;

    window.addEventListener("keydown", (e) => {
        if (e.key.toLowerCase() === "p") {
            window.espEnabled = !window.espEnabled;
            console.log(`[Vortex ESP] Toggled ${window.espEnabled ? "ON" : "OFF"}`);
        }
    });

    const WebGL = WebGL2RenderingContext.prototype;

    HTMLCanvasElement.prototype.getContext = new Proxy(
        HTMLCanvasElement.prototype.getContext,
        {
            apply(target, thisArgs, args) {
                if (args[1]) {
                    args[1].preserveDrawingBuffer = true;
                }
                return Reflect.apply(...arguments);
            },
        }
    );

    try {
        window.espColor = JSON.parse(localStorage.getItem("espColorRGB")) || { r: 0, g: 0, b: 0 };
    } catch {
        window.espColor = { r: 0, g: 0, b: 0 };
    }

    const drawHandler = {
        apply(target, thisArgs, args) {
            const count = args[1];
            const blockarms = document.getElementById("blockarms");
            if (count === 24 && settings.damagenumbersoff) return;
            if (blockarms && blockarms.checked && count === 1098) return;

            const program = thisArgs.getParameter(thisArgs.CURRENT_PROGRAM);
            if (!program.uniforms) {
                program.uniforms = {
                    vertexCount: thisArgs.getUniformLocation(program, "vertexCount"),
                    espToggle: thisArgs.getUniformLocation(program, "espToggle"),
                    gnilgnim: thisArgs.getUniformLocation(program, "gnilgnim"),
                    espColor: thisArgs.getUniformLocation(program, "espColor"),
                };
            }

            if (program.uniforms.vertexCount) {
                thisArgs.uniform1f(program.uniforms.vertexCount, count);
            }
            if (program.uniforms.espToggle) {
                thisArgs.uniform1f(program.uniforms.espToggle, window.espEnabled ? 1.0 : 0.0);
            }
            if (program.uniforms.gnilgnim) {
                thisArgs.uniform1f(program.uniforms.gnilgnim, 13371337.0);
            }
            if (program.uniforms.espColor && window.espColor) {
                const { r, g, b } = window.espColor;
                thisArgs.uniform3f(program.uniforms.espColor, r / 255, g / 255, b / 255);
            }

            gl = thisArgs;
            return Reflect.apply(...arguments);
        },
    };

    WebGL.drawElements = new Proxy(WebGL.drawElements, drawHandler);
    WebGL.drawElementsInstanced = new Proxy(WebGL.drawElementsInstanced, drawHandler);

    function generateRangeConditions(varName) {
        return filters
            .map(({ min, max }) => `(${varName} >= ${min}.0 && ${varName} <= ${max}.0)`)
            .join(" || ");
    }

    WebGL.shaderSource = new Proxy(WebGL.shaderSource, {
        apply(target, thisArgs, args) {
            let [shader, src] = args;

            if (src.includes("gl_Position")) {
                const conditions = generateRangeConditions("vertexCount");
                src = src.replace(
                    /void\s+main\s*\(\s*\)\s*\{/,
                    `uniform float vertexCount;\nuniform float espToggle;\nuniform float gnilgnim;\nout float vVertexCount;\nuniform vec3 espColor;\nvoid main() {\nvVertexCount = vertexCount;\n`
                );
                src = src.replace(
                    /(gl_Position\s*=.+;)/,
                    `$1\nif (espToggle > 0.5 && (${conditions})) {\n  gl_Position.z = 0.01 + gl_Position.z * 0.1;\n}\nif (espToggle > 0.5 && gnilgnim == 13371337.0) {\n  gl_Position.z *= 1.0;\n}`
                );
            }

            if (src.includes("SV_Target0")) {
                const conditions = generateRangeConditions("vVertexCount");
                src = src
                    .replace(
                        /void\s+main\s*\(\s*\)\s*\{/,
                        `uniform float espToggle;\nuniform float gnilgnim;\nin float vVertexCount;\nuniform vec3 espColor;\nvoid main() {`
                    )
                    .replace(
                        /return;/,
                        `if (espToggle > 0.5 && (${conditions}) && SV_Target0.a > 0.5) {\n  SV_Target0 = vec4(espColor, 1.0);\n}\nif (gnilgnim == 13371337.0) {\n  SV_Target0.rgb *= 1.0;\n}\nreturn;`
                    );
            }

            args[1] = src;
            return Reflect.apply(...arguments);
        },
    });

    /***************************************
     * Color Aimbot
     ***************************************/
    let fovCircleEnabled = true;

    const fovCanvas = document.createElement('canvas');
    Object.assign(fovCanvas.style, {
        position: 'fixed',
        top: '0',
        left: '0',
        pointerEvents: 'none',
        zIndex: '9999',
    });
    document.body.appendChild(fovCanvas);

    const fovCtx = fovCanvas.getContext('2d');

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

    const fovRadius = 80;

    function drawFOVCircle() {
        fovCtx.clearRect(0, 0, fovCanvas.width, fovCanvas.height);
        if (!fovCircleEnabled) return;
        const centerX = fovCanvas.width / 2;
        const centerY = fovCanvas.height / 2;

        fovCtx.beginPath();
        fovCtx.arc(centerX, centerY, fovRadius, 0, Math.PI * 2);
        fovCtx.strokeStyle = 'rgba(0, 255, 180, 0.8)';
        fovCtx.lineWidth = 2;
        fovCtx.setLineDash([4, 4]);
        fovCtx.stroke();
        fovCtx.setLineDash([]);
    }

    const settings = {
        aimbotEnabled: true,
        aimbotSpeed: 1.2,
        aimbotTriggerButton: ['left', 'right'],
        crosshairEnabled: false,
        triggerbotEnabled: true,
        damagenumbersoff: false,
    };

    let mouseButtons = { left: false, right: false };

    document.addEventListener("mousedown", (e) => {
        if (e.button === 0) mouseButtons.left = true;
        if (e.button === 2) mouseButtons.right = true;
    });
    document.addEventListener("mouseup", (e) => {
        if (e.button === 0) mouseButtons.left = false;
        if (e.button === 2) mouseButtons.right = false;
    });

    function isTriggerPressed() {
        return settings.aimbotTriggerButton.some(btn => mouseButtons[btn]);
    }

    function isTargetPixel(r, g, b, a, t, c) {
        if (a === 0) return false;
        const dr = r - c.r;
        const dg = g - c.g;
        const db = b - c.b;
        return (dr * dr + dg * dg + db * db) <= (t * t);
    }

    function updateAimbot() {
        drawFOVCircle();
        if (!settings.aimbotEnabled || !gl || !gl.canvas || !gl.readPixels || !isTriggerPressed()) return;

        const width = Math.min(150, gl.canvas?.width || 0);
        const height = Math.min(150, gl.canvas?.height || 0);
        if (width < 10 || height < 10) return;

        const t = 20;
        const c = window.espColor;

        const centerX = gl.canvas.width / 2;
        const centerY = gl.canvas.height / 2;
        const startX = Math.floor(centerX - width / 2);
        const startY = Math.floor(centerY - height / 2);
        const pixels = new Uint8Array(width * height * 4);

        gl.readPixels(startX, startY, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);

        let closestDist = Infinity;
        let bestDX = 0;
        let bestDY = 0;

        for (let i = 0; i < pixels.length; i += 4) {
            const r = pixels[i], g = pixels[i + 1], b = pixels[i + 2], a = pixels[i + 3];
            if (isTargetPixel(r, g, b, a, t, c)) {
                const index = i / 4;
                const x = index % width;
                const y = Math.floor(index / width);
                const dx = startX + x - centerX;
                const dy = -(startY + y - centerY);
                const dist = Math.hypot(dx, dy);
                if (fovCircleEnabled && dist > fovRadius) continue;
                if (dist < closestDist) {
                    closestDist = dist;
                    bestDX = dx;
                    bestDY = dy;
                }
            }
        }

        if (closestDist < Infinity) {
            const factor = settings.aimbotSpeed;
            gl.canvas.dispatchEvent(new MouseEvent("mousemove", {
                movementX: bestDX * factor,
                movementY: bestDY * factor,
                bubbles: true,
                cancelable: true,
                composed: true,
            }));
        }
    }

    setInterval(updateAimbot, 0);

    /***************************************
     * Neues UI: Floating Panel mit Tabs (Main / Visuals / Profile)
     ***************************************/
    let keybinds = {
        toggleMenu: "o",
    };

    const savedKeybinds = localStorage.getItem("zephKeybinds");
    if (savedKeybinds) {
        try {
            keybinds = JSON.parse(savedKeybinds);
        } catch { }
    }

    function createUI() {
        const panel = document.createElement("div");
        panel.id = "vortexPanel";
        Object.assign(panel.style, {
            position: "fixed",
            top: "15px",
            left: "15px",
            width: "320px",
            maxHeight: "80vh",
            background: "radial-gradient(circle at top left, #161930 0%, #060712 60%)",
            color: "#f3f3ff",
            padding: "10px 10px 12px 10px",
            zIndex: "10000",
            fontFamily: "Segoe UI, Arial, sans-serif",
            fontSize: "13px",
            borderRadius: "12px",
            boxShadow: "0 0 22px rgba(0,0,0,0.9)",
            border: "1px solid rgba(0,255,200,0.5)",
            backdropFilter: "blur(8px)",
            display: "none",
        });

        // Draggable Bar
        const dragBar = document.createElement("div");
        Object.assign(dragBar.style, {
            height: "18px",
            marginBottom: "4px",
            display: "flex",
            alignItems: "center",
            justifyContent: "space-between",
            cursor: "move",
        });

        const title = document.createElement("div");
                title.textContent = "Vortex Menu";
        Object.assign(title.style, {
            fontSize: "13px",
            fontWeight: "600",
            letterSpacing: "0.8px",
            textTransform: "uppercase",
            color: "#a8ffe9",
        });

        const by = document.createElement("div");
        by.textContent = "By Vortex";
        Object.assign(by.style, {
            fontSize: "11px",
            opacity: "0.8",
            marginLeft: "6px",
        });

        const leftGroup = document.createElement("div");
        Object.assign(leftGroup.style, {
            display: "flex",
            alignItems: "center",
            gap: "6px",
        });
        leftGroup.appendChild(title);
        leftGroup.appendChild(by);

        const closeBtn = document.createElement("div");
        closeBtn.textContent = "×";
        Object.assign(closeBtn.style, {
            fontSize: "15px",
            cursor: "pointer",
            color: "#ff6f8a",
            padding: "0 4px",
        });
        closeBtn.onclick = () => {
            panel.style.display = "none";
        };

        dragBar.appendChild(leftGroup);
        dragBar.appendChild(closeBtn);
        panel.appendChild(dragBar);

        // Drag Handling
        (function makeDraggable(el, handle) {
            let offsetX = 0, offsetY = 0, startX = 0, startY = 0, dragging = false;
            handle.addEventListener("mousedown", (e) => {
                if (e.target === closeBtn) return;
                dragging = true;
                startX = e.clientX;
                startY = e.clientY;
                const rect = el.getBoundingClientRect();
                offsetX = startX - rect.left;
                offsetY = startY - rect.top;
                document.addEventListener("mousemove", onMove);
                document.addEventListener("mouseup", onUp);
            });

            function onMove(e) {
                if (!dragging) return;
                const x = e.clientX - offsetX;
                const y = e.clientY - offsetY;
                el.style.left = Math.max(0, Math.min(window.innerWidth - el.offsetWidth, x)) + "px";
                el.style.top = Math.max(0, Math.min(window.innerHeight - el.offsetHeight, y)) + "px";
            }

            function onUp() {
                dragging = false;
                document.removeEventListener("mousemove", onMove);
                document.removeEventListener("mouseup", onUp);
            }
        })(panel, dragBar);

        // Tab-Leiste
        const tabBar = document.createElement("div");
        Object.assign(tabBar.style, {
            display: "grid",
            gridTemplateColumns: "repeat(3, 1fr)",
            gap: "4px",
            marginBottom: "8px",
        });

        function createTabButton(label, key) {
            const btn = document.createElement("button");
            btn.textContent = label;
            Object.assign(btn.style, {
                padding: "4px 0",
                background: "rgba(12,14,28,0.9)",
                border: "1px solid rgba(0,255,200,0.35)",
                borderRadius: "10px",
                fontSize: "12px",
                color: "#d9e5ff",
                cursor: "pointer",
                transition: "all 0.15s",
            });
            btn.dataset.tabKey = key;
            return btn;
        }

        const tabMain = createTabButton("Main", "main");
        const tabVisuals = createTabButton("Visuals", "visuals");
        const tabProfile = createTabButton("Profile", "profile");

        tabBar.appendChild(tabMain);
        tabBar.appendChild(tabVisuals);
        tabBar.appendChild(tabProfile);
        panel.appendChild(tabBar);

        // Panel-Container
        const content = document.createElement("div");
        Object.assign(content.style, {
            maxHeight: "calc(80vh - 60px)",
            overflowY: "auto",
        });
        panel.appendChild(content);

        const panelMain = document.createElement("div");
        const panelVisuals = document.createElement("div");
        const panelProfile = document.createElement("div");

        [panelMain, panelVisuals, panelProfile].forEach(p => {
            p.style.display = "none";
        });

        /********** MAIN TAB – Hauptfunktionen (Cards mit Switch) **********/
        (function buildMainTab() {
            const grid = document.createElement("div");
            Object.assign(grid.style, {
                display: "grid",
                gridTemplateColumns: "repeat(2, minmax(0, 1fr))",
                gap: "8px",
            });

            function createMainCard(title, desc, icon, initial, onToggle) {
                const card = document.createElement("div");
                Object.assign(card.style, {
                    borderRadius: "10px",
                    background: "linear-gradient(135deg, #181b36, #15172a)",
                    border: "1px solid rgba(0,255,200,0.35)",
                    padding: "8px 8px 6px 8px",
                    display: "flex",
                    flexDirection: "column",
                    justifyContent: "space-between",
                    minHeight: "72px",
                    transition: "all 0.18s",
                });

                const topRow = document.createElement("div");
                Object.assign(topRow.style, {
                    display: "flex",
                    alignItems: "center",
                    justifyContent: "space-between",
                });

                const left = document.createElement("div");
                const iconSpan = document.createElement("span");
                iconSpan.textContent = icon;
                Object.assign(iconSpan.style, {
                    fontSize: "16px",
                    marginRight: "4px",
                });

                const titleSpan = document.createElement("span");
                titleSpan.textContent = title;
                Object.assign(titleSpan.style, {
                    fontSize: "12px",
                    fontWeight: "600",
                });

                const leftRow = document.createElement("div");
                Object.assign(leftRow.style, {
                    display: "flex",
                    alignItems: "center",
                });
                leftRow.appendChild(iconSpan);
                leftRow.appendChild(titleSpan);
                left.appendChild(leftRow);

                const toggle = document.createElement("input");
                toggle.type = "checkbox";
                toggle.checked = initial;
                Object.assign(toggle.style, {
                    width: "14px",
                    height: "14px",
                    cursor: "pointer",
                });

                topRow.appendChild(left);
                topRow.appendChild(toggle);

                const descEl = document.createElement("div");
                descEl.textContent = desc;
                Object.assign(descEl.style, {
                    fontSize: "11px",
                    color: "#9aa7d5",
                    marginTop: "3px",
                });

                card.appendChild(topRow);
                card.appendChild(descEl);

                function applyState(on) {
                    card.style.boxShadow = on ? "0 0 8px rgba(0,255,200,0.3)" : "none";
                    card.style.borderColor = on ? "rgba(0,255,200,0.6)" : "rgba(0,255,200,0.35)";
                }
                applyState(initial);

                toggle.addEventListener("change", () => {
                    applyState(toggle.checked);
                    onToggle(toggle.checked);
                });

                card.addEventListener("mouseenter", () => {
                    card.style.transform = "translateY(-1px)";
                });
                card.addEventListener("mouseleave", () => {
                    card.style.transform = "translateY(0)";
                });

                return card;
            }

            grid.appendChild(
                createMainCard(
                    "Invisibility",
                    "Blockt Damage-Pakete -> unsichtbar.",
                    "👻",
                    kourInstance.config.Invisible,
                    v => { kourInstance.config.Invisible = v; }
                )
            );

            grid.appendChild(
                createMainCard(
                    "Aimbot",
                    "Color-basiertes Aiming auf ESP-Farbe.",
                    "🎯",
                    settings.aimbotEnabled,
                    v => { settings.aimbotEnabled = v; }
                )
            );

            grid.appendChild(
                createMainCard(
                    "AntiPlayer",
                    "Random Movement (AntiAim).",
                    "🌀",
                    kourInstance.config.AntiAim,
                    v => { kourInstance.config.AntiAim = v; }
                )
            );

            grid.appendChild(
                createMainCard(
                    "Air Strafing",
                    "Automatisches A/D in der Luft.",
                    "💨",
                    kourInstance.config.airStrafing,
                    v => { kourInstance.config.airStrafing = v; }
                )
            );

            grid.appendChild(
                createMainCard(
                    "Hide Arms",
                    "Versteckt die eigenen Arme.",
                    "✋",
                    true,
                    v => {
                        const blockarms = document.getElementById("blockarms");
                        if (blockarms) blockarms.checked = v;
                    }
                )
            );

            panelMain.appendChild(grid);

            // versteckte Checkbox für Logic (wird vom Card-Button gesteuert)
            const hiddenBlockarms = document.createElement("input");
            hiddenBlockarms.type = "checkbox";
            hiddenBlockarms.id = "blockarms";
            hiddenBlockarms.checked = true;
            hiddenBlockarms.style.display = "none";
            panelMain.appendChild(hiddenBlockarms);
        })();

        /********** VISUALS TAB – ESP, FOV, Farbe **********/
        (function buildVisualsTab() {
            const container = document.createElement("div");
            container.style.display = "flex";
            container.style.flexDirection = "column";
            container.style.gap = "8px";

            function createLineToggle(label, desc, initial, onChange) {
                const row = document.createElement("div");
                Object.assign(row.style, {
                    display: "flex",
                    justifyContent: "space-between",
                    alignItems: "center",
                    background: "linear-gradient(135deg, #15172a, #15162a)",
                    borderRadius: "8px",
                    border: "1px solid rgba(0,255,200,0.25)",
                    padding: "6px 8px",
                });

                const textBox = document.createElement("div");
                const titleEl = document.createElement("div");
                titleEl.textContent = label;
                titleEl.style.fontSize = "12px";
                titleEl.style.fontWeight = "600";

                const descEl = document.createElement("div");
                descEl.textContent = desc;
                descEl.style.fontSize = "11px";
                descEl.style.color = "#9aa7d5";

                textBox.appendChild(titleEl);
                textBox.appendChild(descEl);

                const chk = document.createElement("input");
                chk.type = "checkbox";
                chk.checked = initial;
                chk.style.cursor = "pointer";

                chk.addEventListener("change", () => onChange(chk.checked));

                row.appendChild(textBox);
                row.appendChild(chk);

                return row;
            }

            container.appendChild(
                createLineToggle(
                    "ESP",
                    "Visual Outline & Wallhack.",
                    window.espEnabled,
                    v => { window.espEnabled = v; }
                )
            );

            container.appendChild(
                createLineToggle(
                    "FOV Circle",
                    "Zeigt die Aimbot-Reichweite.",
                    fovCircleEnabled,
                    v => { fovCircleEnabled = v; }
                )
            );

            // ESP-Farbe
            const colorRow = document.createElement("div");
            Object.assign(colorRow.style, {
                display: "flex",
                alignItems: "center",
                justifyContent: "space-between",
                background: "linear-gradient(135deg, #15172a, #15162a)",
                borderRadius: "8px",
                border: "1px solid rgba(0,255,200,0.25)",
                padding: "6px 8px",
            });

            const labelBox = document.createElement("div");
            const l1 = document.createElement("div");
            l1.textContent = "ESP Color";
            Object.assign(l1.style, {
                fontSize: "12px",
                fontWeight: "600",
            });
            const l2 = document.createElement("div");
            l2.textContent = "Farbe der ESP-Treffer.";
            Object.assign(l2.style, {
                fontSize: "11px",
                color: "#9aa7d5",
            });

            labelBox.appendChild(l1);
            labelBox.appendChild(l2);

            function hexToRgb(hex) {
                const bigint = parseInt(hex.slice(1), 16);
                return {
                    r: (bigint >> 16) & 255,
                    g: (bigint >> 8) & 255,
                    b: bigint & 255
                };
            }

            let savedRgb = localStorage.getItem("espColorRGB");
            if (savedRgb) {
                try {
                    window.espColor = JSON.parse(savedRgb);
                } catch {
                    window.espColor = { r: 0, g: 0, b: 0 };
                }
            } else {
                window.espColor = { r: 0, g: 0, b: 0 };
            }

            const colorInput = document.createElement("input");
            colorInput.type = "color";
            colorInput.value = `#${((1 << 24) + (window.espColor.r << 16) + (window.espColor.g << 8) + window.espColor.b).toString(16).slice(1)}`;
            Object.assign(colorInput.style, {
                width: "40px",
                height: "22px",
                borderRadius: "4px",
                border: "1px solid rgba(0,255,200,0.4)",
                background: "transparent",
                cursor: "pointer",
                padding: "0",
            });

            colorInput.addEventListener("input", (e) => {
                const rgb = hexToRgb(e.target.value);
                window.espColor = rgb;
                localStorage.setItem("espColorRGB", JSON.stringify(rgb));
            });

            colorRow.appendChild(labelBox);
            colorRow.appendChild(colorInput);

            container.appendChild(colorRow);

            panelVisuals.appendChild(container);
        })();

    /********** PROFILE TAB – Name, Class, Skins, Profile Modder **********/
        (function buildProfileTab() {
            const col = document.createElement("div");
            col.style.display = "flex";
            col.style.flexDirection = "column";
            col.style.gap = "6px";

            function createProfileButton(text, onClick) {
                const btn = document.createElement("button");
                btn.textContent = text;
                Object.assign(btn.style, {
                    width: "100%",
                    padding: "7px 8px",
                    background: "linear-gradient(135deg, #13162a, #171a34)",
                    borderRadius: "8px",
                    border: "1px solid rgba(0,255,200,0.35)",
                    color: "#e5eeff",
                    cursor: "pointer",
                    textAlign: "left",
                    fontSize: "12px",
                    transition: "all 0.18s",
                });
                btn.addEventListener("click", onClick);
                btn.addEventListener("mouseover", () => {
                    btn.style.background = "linear-gradient(135deg, #1f2340, #252a4c)";
                    btn.style.boxShadow = "0 0 8px rgba(0,255,200,0.3)";
                });
                btn.addEventListener("mouseout", () => {
                    btn.style.background = "linear-gradient(135deg, #13162a, #171a34)";
                    btn.style.boxShadow = "none";
                });
                return btn;
            }

            // Name
            col.appendChild(
                createProfileButton("Edit Name", () => {
                    const savedName = localStorage.getItem("playerNickname") || "";
                    const newName = prompt("Enter your nickname:", savedName);
                    if (newName !== null && newName.trim() !== "") {
                        localStorage.setItem("playerNickname", newName.trim());
                        if (window.location.href.includes("#")) {
                            unityInstance.SendMessage("MapScripts", "SetNickname", newName.trim());
                        }
                    }
                })
            );

            // Class Auswahl (öffnet kleines Dropdown Overlay)
            col.appendChild(
                createProfileButton("Select Class (V Key im Match)", () => {
                    // Re-use setClassKills Map zum Anzeigen? – hier simpler Prompt:
                    const classMapSelect = {
                        "0": "Soldier",
                        "1": "Hitman",
                        "2": "Gunner",
                        "3": "Heavy",
                        "4": "Rocketeer",
                        "5": "Agent",
                        "6": "Brawler",
                        "7": "Investor",
                        "8": "Assassin",
                        "9": "Juggernaut",
                        "10": "Recon",
                        "11": "Pyro",
                        "12": "Rayblader"
                    };
                    const id = prompt(
                        "Class ID wählen:\n" +
                        Object.entries(classMapSelect).map(([id, name]) => `${id} = ${name}`).join("\n"),
                        localStorage.getItem("selectedClass") || "0"
                    );
                    if (id === null) return;
                    if (!classMapSelect[id]) {
                        alert("Ungültige Class ID");
                        return;
                    }
                    localStorage.setItem("selectedClass", parseInt(id));
                    if (window.location.href.includes("#")) {
                        unityInstance.SendMessage("MapScripts", "ChangeClassTo", parseInt(id));
                    }
                })
            );

            // Skin Picker (extra kleines Panel)
            col.appendChild(
                createProfileButton("Skins öffnen", () => {
                    const skinMenu = document.getElementById("vortexSkinMenu");
                    if (skinMenu) {
                        skinMenu.style.display = skinMenu.style.display === "none" ? "block" : "none";
                    }
                })
            );

            // Profile Modder (Stats / Kills)
            col.appendChild(
                createProfileButton("Profile Modder (Stats/Kills)", () => {
                    const dlgId = "vortexProfileModder";
                    let dlg = document.getElementById(dlgId);
                    if (!dlg) {
                        dlg = document.createElement("div");
                        dlg.id = dlgId;
                        Object.assign(dlg.style, {
                            position: "fixed",
                            top: "50%",
                            left: "50%",
                            transform: "translate(-50%, -50%)",
                            background: "radial-gradient(circle at top, #13152a 0%, #050712 70%)",
                            color: "#f3f3ff",
                            padding: "18px",
                            zIndex: "10002",
                            fontFamily: "Segoe UI, Arial, sans-serif",
                            fontSize: "12px",
                            borderRadius: "12px",
                            boxShadow: "0 0 20px rgba(0,0,0,0.8)",
                            width: "300px",
                            maxHeight: "420px",
                            overflowY: "auto",
                            border: "1px solid rgba(0,255,200,0.45)",
                        });

                        const title = document.createElement("div");
                        title.textContent = "Profile Modder";
                        title.style.fontWeight = "bold";
                        title.style.textAlign = "center";
                        title.style.marginBottom = "10px";
                        title.style.color = "#00ffd5";
                        dlg.appendChild(title);

                        function addButton(label, cb) {
                            const b = document.createElement("button");
                            b.textContent = label;
                            Object.assign(b.style, {
                                width: "100%",
                                padding: "6px 8px",
                                margin: "3px 0",
                                background: "linear-gradient(135deg, #15172b, #1e2138)",
                                borderRadius: "6px",
                                border: "1px solid rgba(0,255,200,0.35)",
                                color: "#e5eeff",
                                cursor: "pointer",
                                textAlign: "left",
                                fontSize: "12px",
                                transition: "all 0.18s",
                            });
                            b.addEventListener("click", cb);
                            b.addEventListener("mouseover", () => {
                                b.style.background = "linear-gradient(135deg, #202542, #2c3253)";
                            });
                            b.addEventListener("mouseout", () => {
                                b.style.background = "linear-gradient(135deg, #15172b, #1e2138)";
                            });
                            dlg.appendChild(b);
                        }

                        addButton("Set Class Kills", setClassKills);
                        addButton("Change Total Kills", setKDStats);

                        const statMappings = [
                            { label: "ELO", key: "elo" },
                            { label: "Chickalettas Killed", key: "chickalettasKilled" },
                            { label: "Games Played", key: "gamesPlayed" },
                            { label: "Games Won", key: "gamesWon" },
                            { label: "Knife Kills", key: "knifeKills" },
                            { label: "Assists", key: "assists" },
                            { label: "Highest Kill Streak", key: "maxKillStreak" },
                            { label: "Barrels Shot", key: "barrels" },
                            { label: "Kyles Killed", key: "kylesKilled" },
                        ];
                        statMappings.forEach(({ label, key }) => {
                            addButton(`Change ${label}`, () => {
                                const v = prompt(`Neuen Wert für ${label} eingeben:`);
                                if (v !== null) setStat(key, v);
                            });
                        });

                        const close = document.createElement("button");
                        close.textContent = "Schließen";
                        Object.assign(close.style, {
                            width: "100%",
                            marginTop: "8px",
                            padding: "6px",
                            background: "linear-gradient(135deg, #3b1f32, #52213d)",
                            borderRadius: "6px",
                            border: "1px solid rgba(255,80,120,0.5)",
                            color: "#ffe6f0",
                            cursor: "pointer",
                        });
                        close.onclick = () => dlg.remove();
                        dlg.appendChild(close);

                        document.body.appendChild(dlg);
                    } else {
                        dlg.style.display = "block";
                    }
                })
            );

            panelProfile.appendChild(col);

            // Skin-Menü separat
            const skinMenu = document.createElement("div");
            skinMenu.id = "vortexSkinMenu";
            Object.assign(skinMenu.style, {
                position: "fixed",
                top: "20%",
                left: "50%",
                transform: "translateX(-50%)",
                background: "radial-gradient(circle at top, #111327 0%, #050612 70%)",
                color: "#f3f3ff",
                padding: "14px",
                zIndex: "10002",
                borderRadius: "12px",
                border: "1px solid rgba(0,255,200,0.5)",
                boxShadow: "0 0 20px rgba(0,0,0,0.8)",
                width: "260px",
                maxHeight: "420px",
                overflowY: "auto",
                display: "none",
            });

            const skinTitle = document.createElement("div");
            skinTitle.textContent = "Skins";
            skinTitle.style.textAlign = "center";
            skinTitle.style.fontWeight = "bold";
            skinTitle.style.marginBottom = "8px";
            skinTitle.style.color = "#00ffd5";
            skinMenu.appendChild(skinTitle);

            skins.forEach(s => {
                const b = document.createElement("button");
                b.textContent = `${s.name} (${s.id})`;
                Object.assign(b.style, {
                    width: "100%",
                    padding: "5px",
                    margin: "3px 0",
                    background: "linear-gradient(135deg, #15172b, #1e2138)",
                    borderRadius: "6px",
                    border: "1px solid rgba(0,255,200,0.3)",
                    color: "#e5eeff",
                    cursor: "pointer",
                    fontSize: "12px",
                    textAlign: "left",
                });
                b.addEventListener("click", () => {
                    setSkin(s.id);
                    skinMenu.style.display = "none";
                });
                skinMenu.appendChild(b);
            });

            const closeSkin = document.createElement("button");
            closeSkin.textContent = "Schließen";
            Object.assign(closeSkin.style, {
                width: "100%",
                padding: "5px",
                marginTop: "6px",
                background: "linear-gradient(135deg, #3b1f32, #52213d)",
                borderRadius: "6px",
                border: "1px solid rgba(255,80,120,0.5)",
                color: "#ffe6f0",
                cursor: "pointer",
            });
            closeSkin.onclick = () => skinMenu.style.display = "none";
            skinMenu.appendChild(closeSkin);

            document.body.appendChild(skinMenu);
        })();

        // Panels registrieren
        content.appendChild(panelMain);
        content.appendChild(panelVisuals);
        content.appendChild(panelProfile);

        function activateTab(key) {
            // Buttons
            [tabMain, tabVisuals, tabProfile].forEach(btn => {
                const active = btn.dataset.tabKey === key;
                btn.style.background = active
                    ? "linear-gradient(135deg, #10bbaa, #63f2ff)"
                    : "rgba(12,14,28,0.9)";
                btn.style.color = active ? "#041015" : "#d9e5ff";
            });

            // Panels
            panelMain.style.display = key === "main" ? "block" : "none";
            panelVisuals.style.display = key === "visuals" ? "block" : "none";
            panelProfile.style.display = key === "profile" ? "block" : "none";
        }

        tabMain.onclick = () => activateTab("main");
        tabVisuals.onclick = () => activateTab("visuals");
        tabProfile.onclick = () => activateTab("profile");

        activateTab("main");
        document.body.appendChild(panel);
    }

    /***************************************
     * Hotkey V (Class) & Nick‑Sync
     ***************************************/
    window.addEventListener("keydown", (e) => {
        if (e.key.toLowerCase() === "v") {
            const savedClassID = localStorage.getItem("selectedClass");
            if (
                savedClassID !== null &&
                window.location.href.includes("#")
            ) {
                unityInstance.SendMessage("MapScripts", "ChangeClassTo", parseInt(savedClassID));
            }
        }
    });

    let lastHash = window.location.hash;

    setInterval(() => {
        const currentHash = window.location.hash;
        if (currentHash !== lastHash && currentHash.includes("#")) {
            lastHash = currentHash;

            const storedName = localStorage.getItem("playerNickname");
            if (storedName) {
                unityInstance.SendMessage("MapScripts", "SetNickname", storedName);
            }
        }
    }, 500);

    /***************************************
     * Menü‑Toggle (Keybind)
     ***************************************/
    document.addEventListener("keydown", function (e) {
        if (e.key === keybinds.toggleMenu && !e.target.matches("input, textarea")) {
            const panel = document.getElementById("vortexPanel");
            if (panel) {
                panel.style.display = panel.style.display === "none" ? "block" : "none";
            }
        }
    });

    window.addEventListener("load", createUI);
})();