Загрузка данных


window.MC_CHEAT = window.MC_CHEAT || {
    modules: {
        fly: false, glide: false, nofall: false, speed: false, spider: false,
        killaura: false, targetstrafe: false, esp: false, chinahat: false,
        chams: false, firefly: false, targetesp: false, autosprint: false,
        blockesp: false, xray: false, fog: false, jumpcircle: false,
        aimassist: false, triggerbot: false, hitparticles: false, autotranslate: false,
    },
    speedMode: 'legit', speedMultiplier: 1.5, flySpeed: 0.3,
    killauraRange: 4.5, killauraDelay: 50, killauraAttackRange: 4, killauraAimRange: 8,
    targetstrafeRange: 3, targetstrafeSpeed: 0.3, targetstrafeMode: 'normal',
    espOpacity: 0.5, espMode: 'box', spiderSpeed: 0.2,
    xrayMode: 'box', fogOpacity: 0.1, fogDistance: 100,
    intervals: {}, chinaHats: [], chinaHatMesh: null, espMeshes: [], espFrameId: null,
    fireflies: [], targetSprite: null, blockESPMeshes: [], xrayMeshes: [],
    jumpCircles: [], hitParticlesMeshes: [],
    binds: {},
    lastY: null, lastAttack: 0, guiVisible: false, currentTheme: 'green',
    translateTo: 'ru',
};

const THEMES = {
    green: { main: '#0f0', border: 'rgba(0,255,0,0.4)' },
    red: { main: '#f00', border: 'rgba(255,0,0,0.4)' },
    blue: { main: '#0af', border: 'rgba(0,170,255,0.4)' },
    purple: { main: '#a0f', border: 'rgba(170,0,255,0.4)' },
    cyan: { main: '#0ff', border: 'rgba(0,255,255,0.4)' },
    yellow: { main: '#ff0', border: 'rgba(255,255,0,0.4)' },
    orange: { main: '#fa0', border: 'rgba(255,170,0,0.4)' },
    pink: { main: '#f0f', border: 'rgba(255,0,255,0.4)' },
    white: { main: '#fff', border: 'rgba(255,255,255,0.4)' },
};

function createChinaHat() {
    const cheat = window.MC_CHEAT;
    const worldRenderer = window.appViewer?.backend?.soundSystem?.worldRenderer;
    if (!worldRenderer) return;
    const scene = worldRenderer.scene;
    const theme = THEMES[cheat.currentTheme] || THEMES.green;
    const color = theme.main;
    const perspective = window.appViewer?.playerState?.reactive?.perspective;
    
    if (perspective === 0 || perspective === undefined) {
        if (cheat.chinaHatMesh) { scene.remove(cheat.chinaHatMesh); cheat.chinaHatMesh = null; }
        return;
    }
    if (cheat.chinaHatMesh) scene.remove(cheat.chinaHatMesh);
    
    const segments = 64;
    const vertices = [];
    const indices = [];
    const baseY = 0.3, tipY = 0.6, radius = 0.6;
    vertices.push(0, baseY, 0);
    for (let i = 0; i < segments; i++) {
        const angle = (i / segments) * Math.PI * 2;
        vertices.push(Math.cos(angle) * radius, baseY, Math.sin(angle) * radius);
    }
    vertices.push(0, tipY, 0);
    for (let i = 1; i <= segments; i++) {
        const next = i === segments ? 1 : i + 1;
        indices.push(0, i, next);
    }
    for (let i = 1; i <= segments; i++) {
        const next = i === segments ? 1 : i + 1;
        indices.push(i, next, segments + 1);
    }
    
    const geometry = new THREE.BufferGeometry();
    geometry.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3));
    geometry.setIndex(indices);
    geometry.computeVertexNormals();
    
    const material = new THREE.MeshBasicMaterial({ 
        color: new THREE.Color(color), transparent: true, opacity: 0.3,
        side: THREE.DoubleSide, depthWrite: false
    });
    const chinaHat = new THREE.Mesh(geometry, material);
    scene.add(chinaHat);
    cheat.chinaHatMesh = chinaHat;
}

function createESP() {
    const cheat = window.MC_CHEAT;
    const worldRenderer = window.appViewer?.backend?.soundSystem?.worldRenderer;
    if (!worldRenderer) return;
    const scene = worldRenderer.scene;
    const me = window.bot.entity;
    const theme = THEMES[cheat.currentTheme] || THEMES.green;
    const color = theme.main;
    
    cheat.espMeshes.forEach(mesh => scene.remove(mesh));
    cheat.espMeshes = [];
    
    if (cheat.espMode === 'chams') {
        const entities = worldRenderer.entities;
        const allEntities = Object.values(entities.entities || {});
        allEntities.forEach(entity => {
            if (entity === entities.playerEntity) return;
            entity.traverse(child => {
                if (child.isMesh) {
                    if (!child.userData.originalMaterial) child.userData.originalMaterial = child.material;
                    child.material = new THREE.MeshBasicMaterial({
                        color: new THREE.Color(color), depthTest: false,
                        depthWrite: false, transparent: true, opacity: cheat.espOpacity
                    });
                }
            });
        });
    } else {
        const players = Object.values(window.bot.players || {});
        players.forEach(player => {
            if (!player.entity || player.entity === me) return;
            const pos = player.entity.position;
            const boxGeometry = new THREE.BoxGeometry(1, 2, 1);
            const boxMaterial = new THREE.MeshBasicMaterial({ 
                color: new THREE.Color(color), transparent: true, 
                opacity: cheat.espOpacity, depthTest: false, depthWrite: false
            });
            const box = new THREE.Mesh(boxGeometry, boxMaterial);
            box.position.set(pos.x - me.position.x, pos.y - me.position.y - 0.5, pos.z - me.position.z);
            scene.add(box);
            cheat.espMeshes.push(box);
        });
    }
}

function setupChams() {
    const cheat = window.MC_CHEAT;
    const worldRenderer = window.appViewer?.backend?.soundSystem?.worldRenderer;
    if (!worldRenderer) return;
    const entities = worldRenderer.entities;
    const allEntities = Object.values(entities.entities || {});
    allEntities.forEach(entity => {
        if (entity === entities.playerEntity) return;
        entity.traverse(child => {
            if (child.isMesh) {
                if (!child.userData.originalMaterial) child.userData.originalMaterial = child.material;
                child.material = new THREE.MeshBasicMaterial({
                    map: child.material.map || null, depthTest: false,
                    depthWrite: false, transparent: true, opacity: 0.7
                });
            }
        });
    });
}

function removeChams() {
    const worldRenderer = window.appViewer?.backend?.soundSystem?.worldRenderer;
    if (!worldRenderer) return;
    const entities = worldRenderer.entities;
    const allEntities = Object.values(entities.entities || {});
    allEntities.forEach(entity => {
        if (entity === entities.playerEntity) return;
        entity.traverse(child => {
            if (child.isMesh && child.userData.originalMaterial) {
                child.material = child.userData.originalMaterial;
            }
        });
    });
}

function createFireFly() {
    const cheat = window.MC_CHEAT;
    const worldRenderer = window.appViewer?.backend?.soundSystem?.worldRenderer;
    if (!worldRenderer) return;
    const scene = worldRenderer.scene;
    const theme = THEMES[cheat.currentTheme] || THEMES.green;
    const color = theme.main;
    
    const canvas = document.createElement('canvas');
    canvas.width = 64; canvas.height = 64;
    const ctx = canvas.getContext('2d');
    const rgb = new THREE.Color(color);
    const r = Math.floor(rgb.r * 255), g = Math.floor(rgb.g * 255), b = Math.floor(rgb.b * 255);
    const gradient = ctx.createRadialGradient(32, 32, 0, 32, 32, 32);
    gradient.addColorStop(0, `rgba(${r},${g},${b},1)`);
    gradient.addColorStop(0.5, `rgba(${r},${g},${b},0.5)`);
    gradient.addColorStop(1, `rgba(${r},${g},${b},0)`);
    ctx.fillStyle = gradient;
    ctx.fillRect(0, 0, 64, 64);
    const texture = new THREE.CanvasTexture(canvas);
    
    function spawnFirefly() {
        if (cheat.fireflies.length >= 50) return;
        const material = new THREE.SpriteMaterial({ map: texture, transparent: true, depthTest: false, opacity: 0 });
        const sprite = new THREE.Sprite(material);
        const angle = Math.random() * Math.PI * 2;
        const radius = 2 + Math.random() * 10;
        const height = Math.random() * 6;
        sprite.position.set(Math.cos(angle) * radius, height, Math.sin(angle) * radius);
        sprite.scale.set(0.5, 0.5, 1);
        sprite.userData = { createdAt: Date.now(), lifespan: 5000, fadeIn: 1000, fadeOut: 1000, baseY: sprite.position.y };
        scene.add(sprite);
        cheat.fireflies.push(sprite);
        if (cheat.fireflies.length > 50) {
            const oldest = cheat.fireflies.shift();
            scene.remove(oldest);
        }
    }
    
    function updateFireflies() {
        const now = Date.now();
        for (let i = cheat.fireflies.length - 1; i >= 0; i--) {
            const ff = cheat.fireflies[i];
            const age = now - ff.userData.createdAt;
            const life = ff.userData.lifespan;
            if (age < ff.userData.fadeIn) ff.material.opacity = age / ff.userData.fadeIn;
            else if (age < life - ff.userData.fadeOut) ff.material.opacity = 1;
            else if (age < life) ff.material.opacity = (life - age) / ff.userData.fadeOut;
            else { scene.remove(ff); cheat.fireflies.splice(i, 1); continue; }
            ff.position.y = ff.userData.baseY + Math.sin(now / 500 + i) * 0.3;
        }
    }
    
    cheat.intervals.fireflySpawn = setInterval(spawnFirefly, 200);
    function updateLoop() {
        updateFireflies();
        requestAnimationFrame(updateLoop);
    }
    updateLoop();
}
function createTargetESP() {
    const cheat = window.MC_CHEAT;
    const worldRenderer = window.appViewer?.backend?.soundSystem?.worldRenderer;
    if (!worldRenderer) return;
    const scene = worldRenderer.scene;
    const me = window.bot.entity;
    
    const loader = new THREE.TextureLoader();
    loader.load('https://i.ibb.co/m5p3cD87/target.png', function(texture) {
        const material = new THREE.SpriteMaterial({ 
            map: texture, 
            transparent: true, 
            depthTest: false, 
            opacity: 0 
        });
        cheat.targetSprite = new THREE.Sprite(material);
        cheat.targetSprite.scale.set(1, 1, 1);
        cheat.targetSprite.visible = false;
        scene.add(cheat.targetSprite);
        
        let rotationAngle = 0;
        
        function updateTargetESP() {
            if (!cheat.targetSprite) return;
            
            const shouldShow = cheat.modules.targetesp && (cheat.modules.killaura || cheat.modules.targetstrafe || cheat.modules.triggerbot);
            
            let nearest = null, nearestDist = Infinity;
            const players = Object.values(window.bot.players || {});
            players.forEach(player => {
                if (player.entity && player.entity !== me) {
                    const dist = me.position.distanceTo(player.entity.position);
                    if (dist < nearestDist) { nearest = player; nearestDist = dist; }
                }
            });
            
            if (shouldShow && nearest?.entity) {
                const target = nearest.entity;
                cheat.targetSprite.position.set(
                    target.position.x - me.position.x,
                    target.position.y - me.position.y,
                    target.position.z - me.position.z
                );
                cheat.targetSprite.visible = true;
                
                if (cheat.targetSprite.material.opacity < 0.8) {
                    cheat.targetSprite.material.opacity += 0.05;
                }
                
                rotationAngle += 0.01;
                cheat.targetSprite.material.rotation = rotationAngle;
            } else {
                if (cheat.targetSprite.material.opacity > 0) {
                    cheat.targetSprite.material.opacity -= 0.05;
                }
                if (cheat.targetSprite.material.opacity <= 0) {
                    cheat.targetSprite.visible = false;
                }
            }
        }
        
        function updateLoop() {
            updateTargetESP();
            requestAnimationFrame(updateLoop);
        }
        updateLoop();
    });
}

function createBlockESP() {
    const cheat = window.MC_CHEAT;
    const worldRenderer = window.appViewer?.backend?.soundSystem?.worldRenderer;
    if (!worldRenderer) return;
    const scene = worldRenderer.scene;
    const me = window.bot.entity;
    
    const blockColors = {
        'chest': 0xff8800,
        'trapped_chest': 0xff8800,
        'ender_chest': 0x8800ff,
        'spawner': 0x888888,
        'barrel': 0xff8800,
        'shulker_box': 0xff8800,
    };
    
    function updateBlockESP() {
        cheat.blockESPMeshes.forEach(mesh => scene.remove(mesh));
        cheat.blockESPMeshes = [];
        
        const radius = 20;
        
        for (let x = -radius; x <= radius; x++) {
            for (let y = -radius; y <= radius; y++) {
                for (let z = -radius; z <= radius; z++) {
                    const pos = me.position.offset(x, y, z);
                    const block = window.bot.blockAt(pos);
                    
                    if (block && block.name && blockColors[block.name]) {
                        const color = blockColors[block.name];
                        
                        const boxGeometry = new THREE.BoxGeometry(1.01, 1.01, 1.01);
                        const boxMaterial = new THREE.MeshBasicMaterial({ 
                            color: color, 
                            transparent: true, 
                            opacity: 0.5,
                            depthTest: false,
                            depthWrite: false
                        });
                        const mesh = new THREE.Mesh(boxGeometry, boxMaterial);
                        
                        mesh.position.set(
                            block.position.x - me.position.x + 0.5,
                            block.position.y - me.position.y - 1.13,
                            block.position.z - me.position.z + 0.5
                        );
                        
                        scene.add(mesh);
                        cheat.blockESPMeshes.push(mesh);
                    }
                }
            }
        }
    }
    
    cheat.intervals.blockesp = setInterval(updateBlockESP, 250);
    updateBlockESP();
}

function createXRay() {
    const cheat = window.MC_CHEAT;
    const worldRenderer = window.appViewer?.backend?.soundSystem?.worldRenderer;
    if (!worldRenderer) return;
    const scene = worldRenderer.scene;
    const me = window.bot.entity;
    
    const oreColors = {
        'diamond_ore': 0x00ffff, 'deepslate_diamond_ore': 0x00ffff,
        'emerald_ore': 0x00ff00, 'deepslate_emerald_ore': 0x00ff00,
        'gold_ore': 0xffff00, 'nether_gold_ore': 0xffff00,
        'iron_ore': 0xff8888, 'deepslate_iron_ore': 0xff8888,
        'coal_ore': 0x444444, 'deepslate_coal_ore': 0x444444,
        'redstone_ore': 0xff0000, 'deepslate_redstone_ore': 0xff0000,
        'lapis_ore': 0x0000ff, 'deepslate_lapis_ore': 0x0000ff,
        'copper_ore': 0xff8800, 'deepslate_copper_ore': 0xff8800,
        'nether_quartz_ore': 0xffffff, 'ancient_debris': 0x8b0000,
    };
    
    function updateXRay() {
        cheat.xrayMeshes.forEach(mesh => scene.remove(mesh));
        cheat.xrayMeshes = [];
        
        const radius = 20;
        
        for (let x = -radius; x <= radius; x++) {
            for (let y = -radius; y <= radius; y++) {
                for (let z = -radius; z <= radius; z++) {
                    const pos = me.position.offset(x, y, z);
                    const block = window.bot.blockAt(pos);
                    
                    if (block && block.name && oreColors[block.name]) {
                        const color = oreColors[block.name];
                        
                        const boxGeometry = new THREE.BoxGeometry(1, 1, 1);
                        const boxMaterial = new THREE.MeshBasicMaterial({ 
                            color: color, 
                            transparent: true, 
                            opacity: cheat.xrayMode === 'chams' ? 0.8 : 0.6,
                            depthTest: false,
                            depthWrite: false
                        });
                        const mesh = new THREE.Mesh(boxGeometry, boxMaterial);
                        
                        mesh.position.set(
                            block.position.x - me.position.x + 0.5,
                            block.position.y - me.position.y - 1.13,
                            block.position.z - me.position.z + 0.5
                        );
                        
                        scene.add(mesh);
                        cheat.xrayMeshes.push(mesh);
                    }
                }
            }
        }
    }
    
    cheat.intervals.xray = setInterval(updateXRay, 250);
    updateXRay();
}

function createFog() {
    const cheat = window.MC_CHEAT;
    const worldRenderer = window.appViewer?.backend?.soundSystem?.worldRenderer;
    if (!worldRenderer) return;
    const scene = worldRenderer.scene;
    
    const theme = THEMES[cheat.currentTheme] || THEMES.green;
    const color = theme.main;
    
    const fogGeometry = new THREE.BoxGeometry(cheat.fogDistance, cheat.fogDistance, cheat.fogDistance);
    const fogMaterial = new THREE.MeshBasicMaterial({
        color: new THREE.Color(color),
        transparent: true,
        opacity: cheat.fogOpacity,
        depthWrite: false,
        side: THREE.BackSide
    });
    cheat.fogMesh = new THREE.Mesh(fogGeometry, fogMaterial);
    cheat.fogMesh.position.set(0, 0, 0);
    scene.add(cheat.fogMesh);
}

function createJumpCircle() {
    const cheat = window.MC_CHEAT;
    const worldRenderer = window.appViewer?.backend?.soundSystem?.worldRenderer;
    if (!worldRenderer) return;
    const scene = worldRenderer.scene;
    const me = window.bot.entity;
    
    const theme = THEMES[cheat.currentTheme] || THEMES.green;
    const color = theme.main;
    
    const canvas = document.createElement('canvas');
    canvas.width = 128;
    canvas.height = 128;
    const ctx = canvas.getContext('2d');
    
    ctx.beginPath();
    ctx.arc(64, 64, 60, 0, Math.PI * 2);
    ctx.strokeStyle = color;
    ctx.lineWidth = 4;
    ctx.stroke();
    
    ctx.beginPath();
    ctx.arc(64, 64, 60, 0, Math.PI * 2);
    ctx.fillStyle = color + '33';
    ctx.fill();
    
    const texture = new THREE.CanvasTexture(canvas);
    
    let wasOnGround = me.onGround;
    let jumpCircleActive = true;
    
    function spawnCircle() {
        const circleGeometry = new THREE.CircleGeometry(1, 32);
        const circleMaterial = new THREE.MeshBasicMaterial({ 
            map: texture,
            transparent: true, 
            depthTest: false,
            depthWrite: false,
            opacity: 0.7
        });
        const circle = new THREE.Mesh(circleGeometry, circleMaterial);
        circle.rotation.x = -Math.PI / 2;
        circle.position.set(0, -2.1, 0);
        circle.scale.set(0.1, 0.1, 1);
        circle.userData = {
            createdAt: Date.now(),
            lifespan: 1500,
            worldX: me.position.x,
            worldZ: me.position.z
        };
        scene.add(circle);
        cheat.jumpCircles.push(circle);
    }
    
    function updateJumpCircle() {
        if (!jumpCircleActive) return;
        
        if (wasOnGround && !me.onGround) {
            spawnCircle();
        }
        wasOnGround = me.onGround;
        
        for (let i = cheat.jumpCircles.length - 1; i >= 0; i--) {
            const circle = cheat.jumpCircles[i];
            const age = Date.now() - circle.userData.createdAt;
            
            if (age > circle.userData.lifespan) {
                scene.remove(circle);
                cheat.jumpCircles.splice(i, 1);
                continue;
            }
            
            const progress = age / circle.userData.lifespan;
            const scale = 0.1 + progress * 1.9;
            circle.scale.set(scale, scale, 1);
            
            circle.position.x = circle.userData.worldX - me.position.x;
            circle.position.z = circle.userData.worldZ - me.position.z;
            
            circle.material.opacity = 0.7 * (1 - progress);
        }
    }
    
    function updateLoop() {
        updateJumpCircle();
        requestAnimationFrame(updateLoop);
    }
    updateLoop();
    
    return {
        disable: function() {
            jumpCircleActive = false;
            cheat.jumpCircles.forEach(circle => scene.remove(circle));
            cheat.jumpCircles = [];
        }
    };
}

function createAimAssist() {
    const cheat = window.MC_CHEAT;
    if (!window.bot?.entity) return;
    
    const me = window.bot.entity;
    let aimAssistActive = true;
    
    function aimAssistTick() {
        if (!aimAssistActive || !cheat.modules.aimassist) return;
        
        let nearest = null;
        let nearestDist = Infinity;
        
        const players = Object.values(window.bot.players || {});
        players.forEach(player => {
            if (player.entity && player.entity !== me) {
                const dist = me.position.distanceTo(player.entity.position);
                if (dist < 10 && dist < nearestDist) {
                    nearest = player;
                    nearestDist = dist;
                }
            }
        });
        
        if (nearest?.entity) {
            const target = nearest.entity;
            window.bot.lookAt(target.position.offset(0, 1.6, 0), true);
        }
    }
    
    // Один цикл (исправлено с 100 циклов)
    function updateLoop() {
        if (!aimAssistActive || !cheat.modules.aimassist) return;
        aimAssistTick();
        requestAnimationFrame(updateLoop);
    }
    updateLoop();
    
    return {
        disable: function() {
            aimAssistActive = false;
        }
    };
}
function setupAutoTranslate() {
    const cheat = window.MC_CHEAT;
    if (!window.bot?._client) return;
    
    if (window._oldChatListener) {
        window.bot._client.removeListener('chat', window._oldChatListener);
    }
    
    window._oldChatListener = function(packet) {
        if (!cheat.modules.autotranslate) return;
        
        try {
            const parsed = JSON.parse(packet.message);
            let text = '';
            
            if (parsed.with && Array.isArray(parsed.with)) {
                const textPart = parsed.with.find(item => typeof item === 'object' && item.text && item.text !== parsed.with[0]?.text);
                text = textPart?.text || parsed.with[parsed.with.length - 1]?.text || '';
            } else {
                text = parsed.text || '';
            }
            
            if (!text) return;
            
            const targetLang = cheat.translateTo;
            
            fetch(`https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=${targetLang}&dt=t&q=${encodeURIComponent(text)}`)
                .then(r => r.json())
                .then(data => {
                    const translated = data[0]?.map(item => item[0]).join('') || text;
                    
                    const chatContainer = document.querySelector('.chat.opened') || document.querySelector('.chat-messages-wrapper');
                    if (chatContainer) {
                        const msgLi = document.createElement('li');
                        msgLi.className = 'chat-message';
                        msgLi.style.color = '#aaa';
                        msgLi.style.fontSize = '12px';
                        msgLi.style.fontStyle = 'italic';
                        msgLi.textContent = `[Перевод] ${translated}`;
                        chatContainer.appendChild(msgLi);
                        chatContainer.scrollTop = chatContainer.scrollHeight;
                        
                        setTimeout(() => {
                            if (msgLi.parentNode) msgLi.remove();
                        }, 5000);
                    }
                    
                    console.log(`[ПЕРЕВОД] ${translated}`);
                })
                .catch(err => console.log('Ошибка перевода:', err));
        } catch(e) {
            console.log('Ошибка парсинга:', e);
        }
    };
    
    window.bot._client.on('chat', window._oldChatListener);
    
    return {
        disable: function() {
            if (window._oldChatListener) {
                window.bot._client.removeListener('chat', window._oldChatListener);
                window._oldChatListener = null;
            }
        }
    };
}

function createHitParticles() {
    const cheat = window.MC_CHEAT;
    const worldRenderer = window.appViewer?.backend?.soundSystem?.worldRenderer;
    if (!worldRenderer) return;
    
    const scene = worldRenderer.scene;
    const me = window.bot.entity;
    
    const canvas = document.createElement('canvas');
    canvas.width = 64;
    canvas.height = 64;
    const ctx = canvas.getContext('2d');
    const gradient = ctx.createRadialGradient(32, 32, 0, 32, 32, 32);
    gradient.addColorStop(0, 'rgba(255,0,0,1)');
    gradient.addColorStop(0.5, 'rgba(255,0,0,0.5)');
    gradient.addColorStop(1, 'rgba(255,0,0,0)');
    ctx.fillStyle = gradient;
    ctx.fillRect(0, 0, 64, 64);
    const texture = new THREE.CanvasTexture(canvas);
    
    if (window._hitParticlesInstalled) return { disable: function() {} };
    window._hitParticlesInstalled = true;
    
    const originalWrite = window.bot._client.write.bind(window.bot._client);
    
    window.bot._client.write = function(name, params) {
        if (name === 'arm_animation' && cheat.modules.hitparticles) {
            let target = null;
            let nearestDist = Infinity;
            
            const players = Object.values(window.bot.players || {});
            players.forEach(player => {
                if (player.entity && player.entity !== me) {
                    const dist = me.position.distanceTo(player.entity.position);
                    if (dist < 5 && dist < nearestDist) {
                        target = player.entity;
                        nearestDist = dist;
                    }
                }
            });
            
            if (target) {
                const targetX = target.position.x - me.position.x;
                const targetY = target.position.y - me.position.y;
                const targetZ = target.position.z - me.position.z;
                
                for (let i = 0; i < 10; i++) {
                    const material = new THREE.SpriteMaterial({ 
                        map: texture, 
                        transparent: true, 
                        depthTest: false,
                        opacity: 1
                    });
                    const sprite = new THREE.Sprite(material);
                    sprite.scale.set(0.5, 0.5, 1);
                    
                    sprite.position.set(targetX, targetY, targetZ);
                    
                    const angle = (i / 10) * Math.PI * 2;
                    const speed = 0.07;
                    sprite.userData = {
                        vx: Math.cos(angle) * speed,
                        vy: Math.random() * 0.1,
                        vz: Math.sin(angle) * speed,
                        createdAt: Date.now(),
                        lifespan: 800
                    };
                    
                    scene.add(sprite);
                    cheat.hitParticlesMeshes.push(sprite);
                    
                    function animateParticle() {
                        const age = Date.now() - sprite.userData.createdAt;
                        if (age > sprite.userData.lifespan) {
                            scene.remove(sprite);
                            const index = cheat.hitParticlesMeshes.indexOf(sprite);
                            if (index > -1) cheat.hitParticlesMeshes.splice(index, 1);
                            return;
                        }
                        
                        sprite.position.x += sprite.userData.vx;
                        sprite.position.y += sprite.userData.vy;
                        sprite.position.z += sprite.userData.vz;
                        sprite.userData.vy -= 0.002;
                        sprite.material.opacity = 1 - (age / sprite.userData.lifespan);
                        
                        requestAnimationFrame(animateParticle);
                    }
                    animateParticle();
                }
            }
        }
        
        return originalWrite(name, params);
    };
    
    return {
        disable: function() {
            window.bot._client.write = originalWrite;
            window._hitParticlesInstalled = false;
            cheat.hitParticlesMeshes.forEach(sprite => scene.remove(sprite));
            cheat.hitParticlesMeshes = [];
        }
    };
}

function createTriggerBot() {
    const cheat = window.MC_CHEAT;
    if (!window.bot?.entity) return;
    
    const me = window.bot.entity;
    
    function triggerBotTick() {
        if (!cheat.modules.triggerbot) return;
        
        let nearest = null;
        let nearestDist = Infinity;
        
        const players = Object.values(window.bot.players || {});
        players.forEach(player => {
            if (player.entity && player.entity !== me) {
                const dist = me.position.distanceTo(player.entity.position);
                if (dist < 4 && dist < nearestDist) {
                    nearest = player;
                    nearestDist = dist;
                }
            }
        });
        
        if (nearest?.entity) {
            const target = nearest.entity;
            
            const dx = target.position.x - me.position.x;
            const dz = target.position.z - me.position.z;
            const targetYaw = Math.atan2(-dx, dz) * 180 / Math.PI;
            
            let yawDiff = Math.abs(targetYaw - me.yaw);
            while (yawDiff > 180) yawDiff -= 360;
            yawDiff = Math.abs(yawDiff);
            
            if (yawDiff < 15) {
                try {
                    window.bot.attack(target);
                } catch (e) {}
            }
        }
    }
    
    const interval = setInterval(triggerBotTick, 100);
    
    return {
        disable: function() {
            clearInterval(interval);
        }
    };
}

function killauraTick() {
    const cheat = window.MC_CHEAT;
    if (!cheat.modules.killaura || !window.bot?.entity) return;
    const me = window.bot.entity;
    let nearest = null, nearestDist = Infinity;
    
    const players = Object.values(window.bot.players || {});
    players.forEach(player => {
        if (player.entity && player.entity !== me) {
            const dist = me.position.distanceTo(player.entity.position);
            if (dist < cheat.killauraAimRange && dist < nearestDist) {
                nearest = player;
                nearestDist = dist;
            }
        }
    });
    
    if (!nearest?.entity) return;
    const target = nearest.entity;
    
    const dx = target.position.x - me.position.x;
    const dy = (target.position.y + 1.6) - (me.position.y + me.eyeHeight);
    const dz = target.position.z - me.position.z;
    
    const yaw = Math.atan2(-dx, dz) * 180 / Math.PI;
    const groundDist = Math.sqrt(dx * dx + dz * dz);
    const pitch = -Math.atan2(dy, groundDist) * 180 / Math.PI;
    
    window.bot._client.write('look', { yaw: yaw, pitch: pitch, onGround: me.onGround ?? true });
    
    const now = Date.now();
    if (nearestDist <= cheat.killauraAttackRange && (!cheat.lastAttack || now - cheat.lastAttack > 500)) {
        try { window.bot.attack(target); cheat.lastAttack = now; } catch (e) {}
    }
}

function targetStrafeTick() {
    const cheat = window.MC_CHEAT;
    if (!cheat.modules.targetstrafe || !window.bot?.entity) return;
    const me = window.bot.entity;
    
    let nearest = null, nearestDist = Infinity;
    const players = Object.values(window.bot.players || {});
    players.forEach(player => {
        if (player.entity && player.entity !== me) {
            const dist = me.position.distanceTo(player.entity.position);
            if (dist < cheat.killauraAimRange && dist < nearestDist) {
                nearest = player;
                nearestDist = dist;
            }
        }
    });
    
    if (!nearest?.entity) return;
    const target = nearest.entity;
    
    let targetLookingAtMe = false;
    const targetYaw = target.yaw || 0;
    const dxToMe = me.position.x - target.position.x;
    const dzToMe = me.position.z - target.position.z;
    const angleToMe = Math.atan2(-dxToMe, dzToMe) * 180 / Math.PI;
    let yawDiff = Math.abs(targetYaw - angleToMe);
    while (yawDiff > 180) yawDiff -= 360;
    yawDiff = Math.abs(yawDiff);
    if (yawDiff < 30) targetLookingAtMe = true;
    
    const speedMultiplier = targetLookingAtMe ? 1.5 : 1;
    
    if (cheat.targetstrafeMode === 'safe') {
        const behindX = target.position.x - Math.sin(targetYaw * Math.PI / 180) * cheat.targetstrafeRange;
        const behindZ = target.position.z - Math.cos(targetYaw * Math.PI / 180) * cheat.targetstrafeRange;
        me.velocity.x += (behindX - me.position.x) * cheat.targetstrafeSpeed * speedMultiplier;
        me.velocity.z += (behindZ - me.position.z) * cheat.targetstrafeSpeed * speedMultiplier;
        if (!me.onGround) { me.velocity.x *= 0.5; me.velocity.z *= 0.5; }
    } else {
        const dx = target.position.x - me.position.x;
        const dz = target.position.z - me.position.z;
        const dist = Math.sqrt(dx * dx + dz * dz);
        if (dist > 0 && dist < cheat.targetstrafeRange + 2) {
            me.velocity.x += (dx / dist) * cheat.targetstrafeSpeed * speedMultiplier;
            me.velocity.z += (dz / dist) * cheat.targetstrafeSpeed * speedMultiplier;
            me.velocity.x *= cheat.speedMultiplier;
            me.velocity.z *= cheat.speedMultiplier;
            if (!me.onGround) { me.velocity.x *= 0.3; me.velocity.z *= 0.3; }
        }
    }
}

function spiderTick() {
    const cheat = window.MC_CHEAT;
    if (!cheat.modules.spider || !window.bot?.entity) return;
    const me = window.bot.entity;
    if (me.isCollidedHorizontally && !me.onGround) {
        me.velocity.y = cheat.spiderSpeed;
    }
}

function autoSprintTick() {
    const cheat = window.MC_CHEAT;
    if (!cheat.modules.autosprint || !window.bot?.entity) return;
    if (window.bot.controlState) {
        window.bot.controlState.sprint = true;
    }
}
function toggleModule(name) {
    const cheat = window.MC_CHEAT;
    cheat.modules[name] = !cheat.modules[name];
    
    if (cheat.intervals[name]) {
        clearInterval(cheat.intervals[name]);
        cheat.intervals[name] = null;
    }
    
    if (name === 'fly' && cheat.modules.fly) {
        cheat.intervals.fly = setInterval(() => {
            if (window.bot?.entity) window.bot.entity.velocity.y = cheat.flySpeed;
        }, 50);
    }
    if (name === 'glide' && cheat.modules.glide) {
        cheat.intervals.glide = setInterval(() => {
            if (window.bot?.entity) {
                const e = window.bot.entity;
                if (e.velocity.y < -0.1) { e.velocity.y = -0.01; e.position.y += 0.05; }
            }
        }, 50);
    }
    if (name === 'nofall' && cheat.modules.nofall) {
        cheat.lastY = window.bot?.entity?.position.y ?? null;
        cheat.intervals.nofall = setInterval(() => {
            if (window.bot?.entity) {
                const e = window.bot.entity;
                if (e.velocity.y < -0.5 && cheat.lastY !== null && e.position.y < cheat.lastY - 0.1) {
                    e.position.y += 0.5;
                    e.velocity.y = 0;
                }
                cheat.lastY = e.position.y;
            }
        }, 100);
    }
    if (name === 'speed' && cheat.modules.speed) {
        cheat.intervals.speed = setInterval(() => {
            if (window.bot?.entity) {
                const e = window.bot.entity;
                const v = e.velocity;
                if (Math.abs(v.x) > 0.01 || Math.abs(v.z) > 0.01) {
                    const m = cheat.speedMultiplier;
                    if (cheat.speedMode === 'legit' && e.onGround) { v.x *= m; v.z *= m; }
                    if (cheat.speedMode === 'bunnyhop' && !e.onGround) { v.x *= 1+(m-1)*0.2; v.z *= 1+(m-1)*0.2; }
                    if (cheat.speedMode === 'fly' && e.onGround) { v.y = 0.05; v.x *= 1+(m-1)*0.1; v.z *= 1+(m-1)*0.1; }
                    if (cheat.speedMode === 'lowhop' && e.onGround) { v.y = 0.2; v.x *= m; v.z *= m; }
                }
            }
        }, 50);
    }
    if (name === 'killaura' && cheat.modules.killaura) {
        cheat.intervals.killaura = setInterval(killauraTick, cheat.killauraDelay);
    }
    if (name === 'targetstrafe' && cheat.modules.targetstrafe) {
        cheat.intervals.targetstrafe = setInterval(targetStrafeTick, 50);
    }
    if (name === 'spider' && cheat.modules.spider) {
        cheat.intervals.spider = setInterval(spiderTick, 50);
    }
    if (name === 'autosprint' && cheat.modules.autosprint) {
        cheat.intervals.autosprint = setInterval(autoSprintTick, 50);
    }
    if (name === 'aimassist') {
        if (cheat.modules.aimassist) {
            if (cheat.aimAssistInstance && cheat.aimAssistInstance.disable) {
                cheat.aimAssistInstance.disable();
            }
            cheat.aimAssistInstance = createAimAssist();
        } else {
            if (cheat.aimAssistInstance && cheat.aimAssistInstance.disable) {
                cheat.aimAssistInstance.disable();
                cheat.aimAssistInstance = null;
            }
        }
    }
    if (name === 'triggerbot') {
        if (cheat.modules.triggerbot) {
            if (cheat.triggerBotInstance && cheat.triggerBotInstance.disable) {
                cheat.triggerBotInstance.disable();
            }
            cheat.triggerBotInstance = createTriggerBot();
        } else {
            if (cheat.triggerBotInstance && cheat.triggerBotInstance.disable) {
                cheat.triggerBotInstance.disable();
                cheat.triggerBotInstance = null;
            }
        }
    }
    if (name === 'hitparticles') {
        if (cheat.modules.hitparticles) {
            if (cheat.hitParticlesInstance && cheat.hitParticlesInstance.disable) {
                cheat.hitParticlesInstance.disable();
            }
            cheat.hitParticlesInstance = createHitParticles();
        } else {
            if (cheat.hitParticlesInstance && cheat.hitParticlesInstance.disable) {
                cheat.hitParticlesInstance.disable();
                cheat.hitParticlesInstance = null;
            }
        }
    }
    if (name === 'autotranslate') {
        if (cheat.modules.autotranslate) {
            if (cheat.autoTranslateInstance && cheat.autoTranslateInstance.disable) {
                cheat.autoTranslateInstance.disable();
            }
            cheat.autoTranslateInstance = setupAutoTranslate();
        } else {
            if (cheat.autoTranslateInstance && cheat.autoTranslateInstance.disable) {
                cheat.autoTranslateInstance.disable();
                cheat.autoTranslateInstance = null;
            }
        }
    }
    if (name === 'chinahat') {
        if (cheat.modules.chinahat) {
            createChinaHat();
            cheat.intervals.chinahat = setInterval(() => { if (cheat.modules.chinahat) createChinaHat(); }, 500);
        } else {
            if (cheat.intervals.chinahat) { clearInterval(cheat.intervals.chinahat); cheat.intervals.chinahat = null; }
            if (cheat.chinaHatMesh) {
                const scene = window.appViewer.backend.soundSystem.worldRenderer.scene;
                scene.remove(cheat.chinaHatMesh);
                cheat.chinaHatMesh = null;
            }
        }
    }
    if (name === 'esp') {
        if (cheat.modules.esp) {
            function updateESP() {
                if (!cheat.modules.esp) return;
                createESP();
                cheat.espFrameId = requestAnimationFrame(updateESP);
            }
            updateESP();
        } else {
            if (cheat.espFrameId) { cancelAnimationFrame(cheat.espFrameId); cheat.espFrameId = null; }
            const scene = window.appViewer.backend.soundSystem.worldRenderer.scene;
            cheat.espMeshes.forEach(mesh => scene.remove(mesh));
            cheat.espMeshes = [];
            removeChams();
        }
    }
    if (name === 'chams') {
        if (cheat.modules.chams) {
            setupChams();
            cheat.intervals.chams = setInterval(setupChams, 500);
        } else {
            if (cheat.intervals.chams) { clearInterval(cheat.intervals.chams); cheat.intervals.chams = null; }
            removeChams();
        }
    }
    if (name === 'firefly') {
        if (cheat.modules.firefly) {
            if (cheat.intervals.fireflySpawn) {
                clearInterval(cheat.intervals.fireflySpawn);
            }
            createFireFly();
        } else {
            if (cheat.intervals.fireflySpawn) {
                clearInterval(cheat.intervals.fireflySpawn);
                cheat.intervals.fireflySpawn = null;
            }
            const scene = window.appViewer.backend.soundSystem.worldRenderer.scene;
            cheat.fireflies.forEach(ff => scene.remove(ff));
            cheat.fireflies = [];
        }
    }
    if (name === 'targetesp') {
        if (cheat.modules.targetesp) {
            createTargetESP();
        } else {
            if (cheat.targetSprite) {
                const scene = window.appViewer.backend.soundSystem.worldRenderer.scene;
                scene.remove(cheat.targetSprite);
                cheat.targetSprite = null;
            }
        }
    }
    if (name === 'blockesp') {
        if (cheat.modules.blockesp) {
            createBlockESP();
        } else {
            if (cheat.intervals.blockesp) { clearInterval(cheat.intervals.blockesp); cheat.intervals.blockesp = null; }
            const scene = window.appViewer.backend.soundSystem.worldRenderer.scene;
            cheat.blockESPMeshes.forEach(mesh => scene.remove(mesh));
            cheat.blockESPMeshes = [];
        }
    }
    if (name === 'xray') {
        if (cheat.modules.xray) {
            createXRay();
        } else {
            if (cheat.intervals.xray) { clearInterval(cheat.intervals.xray); cheat.intervals.xray = null; }
            const scene = window.appViewer.backend.soundSystem.worldRenderer.scene;
            cheat.xrayMeshes.forEach(mesh => scene.remove(mesh));
            cheat.xrayMeshes = [];
        }
    }
    if (name === 'fog') {
        if (cheat.modules.fog) {
            createFog();
        } else {
            if (cheat.fogMesh) {
                const scene = window.appViewer.backend.soundSystem.worldRenderer.scene;
                scene.remove(cheat.fogMesh);
                cheat.fogMesh = null;
            }
        }
    }
    if (name === 'jumpcircle') {
        if (cheat.modules.jumpcircle) {
            if (cheat.jumpCircleInstance && cheat.jumpCircleInstance.disable) {
                cheat.jumpCircleInstance.disable();
            }
            cheat.jumpCircleInstance = createJumpCircle();
        } else {
            if (cheat.jumpCircleInstance && cheat.jumpCircleInstance.disable) {
                cheat.jumpCircleInstance.disable();
                cheat.jumpCircleInstance = null;
            }
            const scene = window.appViewer.backend.soundSystem.worldRenderer.scene;
            cheat.jumpCircles.forEach(circle => scene.remove(circle));
            cheat.jumpCircles = [];
        }
    }
}

function getModulesForCategory(category) {
    const map = {
        combat: ['killaura', 'targetstrafe', 'targetesp', 'aimassist', 'triggerbot', 'hitparticles'],
        movement: ['fly', 'glide', 'nofall', 'speed', 'spider', 'autosprint'],
        visual: ['esp', 'chinahat', 'chams', 'firefly', 'blockesp', 'xray', 'fog', 'jumpcircle'],
        macros: ['autotranslate'],
        theme: Object.keys(THEMES),
    };
    return map[category] || [];
}

function createRelayHUD() {
    const theme = THEMES[window.MC_CHEAT.currentTheme] || THEMES.green;
    let relayDiv = document.getElementById('relay-hud');
    if (!relayDiv) {
        relayDiv = document.createElement('div');
        relayDiv.id = 'relay-hud';
        relayDiv.style.cssText = 'position:fixed;top:10px;left:10px;z-index:9998;background:rgba(0,0,0,0.5);backdrop-filter:blur(10px);padding:10px 15px;border-radius:8px;font-family:monospace;font-size:13px;pointer-events:none;';
        document.body.appendChild(relayDiv);
    }
    const ping = window.bot?.player?.ping || 0;
    relayDiv.innerHTML = `<span style="color:${theme.main}">Relay</span> <span style="color:#fff">|</span> <span style="color:#fff">${ping}ms</span> <span style="color:#fff">|</span> <span style="color:#aaa">${window.bot?.username || ''}</span>`;
}

function createCoordsHUD() {
    const theme = THEMES[window.MC_CHEAT.currentTheme] || THEMES.green;
    let coordsDiv = document.getElementById('coords-hud');
    if (!coordsDiv) {
        coordsDiv = document.createElement('div');
        coordsDiv.id = 'coords-hud';
        coordsDiv.style.cssText = 'position:fixed;bottom:10px;left:10px;z-index:9998;font-family:monospace;font-size:13px;pointer-events:none;';
        document.body.appendChild(coordsDiv);
    }
    const me = window.bot?.entity;
    if (me) {
        coordsDiv.textContent = `${Math.round(me.position.x)} ${Math.round(me.position.y)} ${Math.round(me.position.z)}`;
        coordsDiv.style.color = theme.main;
    }
}

function createKeyBindsHUD() {
    const cheat = window.MC_CHEAT;
    const theme = THEMES[cheat.currentTheme] || THEMES.green;
    let bindsDiv = document.getElementById('binds-hud');
    
    const bindEntries = Object.entries(cheat.binds);
    
    if (bindEntries.length === 0) {
        if (bindsDiv) bindsDiv.remove();
        return;
    }
    
    if (!bindsDiv) {
        bindsDiv = document.createElement('div');
        bindsDiv.id = 'binds-hud';
        bindsDiv.style.cssText = 'position:fixed;top:60px;left:10px;z-index:9998;background:rgba(0,0,0,0.5);backdrop-filter:blur(10px);padding:10px;border-radius:8px;font-family:monospace;font-size:12px;cursor:move;user-select:none;';
        document.body.appendChild(bindsDiv);
        
        let isDragging = false;
        let dragOffsetX = 0, dragOffsetY = 0;
        
        bindsDiv.addEventListener('mousedown', function(e) {
            isDragging = true;
            dragOffsetX = e.clientX - bindsDiv.getBoundingClientRect().left;
            dragOffsetY = e.clientY - bindsDiv.getBoundingClientRect().top;
            e.preventDefault();
        });
        
        document.addEventListener('mousemove', function(e) {
            if (isDragging) {
                bindsDiv.style.left = (e.clientX - dragOffsetX) + 'px';
                bindsDiv.style.top = (e.clientY - dragOffsetY) + 'px';
            }
        });
        
        document.addEventListener('mouseup', function() {
            isDragging = false;
        });
    }
    
    let html = `<div style="color:${theme.main};margin-bottom:5px;font-size:13px;font-weight:bold;">KeyBinds</div>`;
    bindEntries.forEach(([key, mods]) => {
        const modList = Array.isArray(mods) ? mods : [mods];
        modList.forEach(mod => {
            const active = cheat.modules[mod];
            const color = active ? '#0f0' : '#fff';
            html += `<div style="color:${color}">${mod.toUpperCase()} - ${key}</div>`;
        });
    });
    bindsDiv.innerHTML = html;
}

function createAllPanels() {
    ['combat', 'movement', 'visual', 'macros', 'theme'].forEach(cat => {
        const old = document.getElementById(`category-${cat}`);
        if (old) old.remove();
    });
    
    const categories = ['combat', 'movement', 'visual', 'macros', 'theme'];
    const panelWidth = 180;
    const panelHeight = 400;
    const gap = 15;
    const totalWidth = categories.length * panelWidth + (categories.length - 1) * gap;
    const startX = Math.max(10, (window.innerWidth - totalWidth) / 2);
    const startY = Math.max(10, (window.innerHeight - panelHeight) / 2);
    const theme = THEMES[window.MC_CHEAT.currentTheme] || THEMES.green;
    
    categories.forEach((cat, i) => {
        const panel = document.createElement('div');
        panel.id = `category-${cat}`;
        panel.style.position = 'fixed';
        panel.style.top = startY + 'px';
        panel.style.left = (startX + i * (panelWidth + gap)) + 'px';
        panel.style.zIndex = '10000';
        panel.style.background = 'rgba(10,10,10,0.8)';
        panel.style.backdropFilter = 'blur(15px)';
        panel.style.webkitBackdropFilter = 'blur(15px)';
        panel.style.color = 'white';
        panel.style.padding = '15px';
        panel.style.borderRadius = '10px';
        panel.style.fontFamily = 'monospace';
        panel.style.fontSize = '13px';
        panel.style.width = panelWidth + 'px';
        panel.style.height = panelHeight + 'px';
        panel.style.border = '2px solid ' + theme.border;
        panel.style.overflowY = 'auto';
        
        const header = document.createElement('div');
        header.textContent = cat.toUpperCase();
        header.style.textAlign = 'center';
        header.style.fontWeight = 'bold';
        header.style.fontSize = '15px';
        header.style.color = theme.main;
        header.style.marginBottom = '10px';
        header.style.borderBottom = '1px solid ' + theme.border;
        header.style.paddingBottom = '8px';
        panel.appendChild(header);
        
        const modules = getModulesForCategory(cat);
        if (modules.length === 0) {
            const empty = document.createElement('div');
            empty.textContent = 'Пусто';
            empty.style.textAlign = 'center';
            empty.style.color = '#666';
            empty.style.padding = '30px';
            panel.appendChild(empty);
        } else {
            modules.forEach(mod => {
                const btn = document.createElement('button');
                const isTheme = cat === 'theme';
                const active = isTheme ? (window.MC_CHEAT.currentTheme === mod) : window.MC_CHEAT.modules[mod];
                
                let color = 'white';
                let border = active ? '#0f0' : '#555';
                if (isTheme && THEMES[mod]) {
                    color = THEMES[mod].main;
                    border = active ? THEMES[mod].main : '#555';
                }
                
                const bind = Object.keys(window.MC_CHEAT.binds).find(key => {
                    const mods = window.MC_CHEAT.binds[key];
                    return Array.isArray(mods) ? mods.includes(mod) : mods === mod;
                });
                btn.textContent = mod.toUpperCase() + (bind ? ` [${bind}]` : '');
                btn.style.background = active ? 'rgba(255,255,255,0.2)' : 'rgba(255,255,255,0.1)';
                btn.style.color = color;
                btn.style.border = '1px solid ' + border;
                btn.style.padding = '10px';
                btn.style.cursor = 'pointer';
                btn.style.borderRadius = '8px';
                btn.style.fontFamily = 'inherit';
                btn.style.fontSize = '12px';
                btn.style.textAlign = 'center';
                btn.style.width = '100%';
                btn.style.marginBottom = '5px';
                
                btn.onclick = () => {
                    if (isTheme) {
                        window.MC_CHEAT.currentTheme = mod;
                        // Перезапуск всех активных визуальных модулей
                        const activeModules = Object.keys(window.MC_CHEAT.modules).filter(m => window.MC_CHEAT.modules[m]);
                        activeModules.forEach(moduleName => {
                            if (['chinahat', 'esp', 'chams', 'firefly', 'fog', 'jumpcircle'].includes(moduleName)) {
                                toggleModule(moduleName); // Выключить
                                toggleModule(moduleName); // Включить с новой темой
                            }
                        });
                        createAllPanels();
                    } else {
                        toggleModule(mod);
                        createAllPanels();
                    }
                };
                
                btn.oncontextmenu = (e) => {
                    e.preventDefault();
                    if (isTheme) return;
                    if (['speed', 'killaura', 'targetstrafe', 'esp', 'spider', 'fog'].includes(mod)) {
                        openSettingsModal(mod);
                    }
                };
                
                btn.addEventListener('mousedown', (e) => {
                    if (e.button === 1) {
                        e.preventDefault();
                        if (isTheme) return;
                        
                        btn.textContent = 'НАЖМИ КЛАВИШУ...';
                        btn.style.border = '2px solid #ff0';
                        
                        const keyHandler = (ev) => {
                            ev.preventDefault();
                            ev.stopPropagation();
                            
                            if (ev.button === 2) {
                                Object.keys(window.MC_CHEAT.binds).forEach(key => {
                                    const mods = window.MC_CHEAT.binds[key];
                                    if (Array.isArray(mods)) {
                                        window.MC_CHEAT.binds[key] = mods.filter(m => m !== mod);
                                        if (window.MC_CHEAT.binds[key].length === 0) delete window.MC_CHEAT.binds[key];
                                    } else if (mods === mod) {
                                        delete window.MC_CHEAT.binds[key];
                                    }
                                });
                                document.removeEventListener('keydown', keyHandler);
                                createAllPanels();
                                return;
                            }
                            
                            const key = ev.key.toUpperCase();
                            if (!window.MC_CHEAT.binds[key]) {
                                window.MC_CHEAT.binds[key] = [];
                            }
                            if (!Array.isArray(window.MC_CHEAT.binds[key])) {
                                window.MC_CHEAT.binds[key] = [window.MC_CHEAT.binds[key]];
                            }
                            if (!window.MC_CHEAT.binds[key].includes(mod)) {
                                window.MC_CHEAT.binds[key].push(mod);
                            }
                            
                            document.removeEventListener('keydown', keyHandler);
                            createAllPanels();
                        };
                        
                        document.addEventListener('keydown', keyHandler);
                    }
                });
                
                panel.appendChild(btn);
            });
        }
        
        document.body.appendChild(panel);
    });
    
    window.MC_CHEAT.guiVisible = true;
    document.body.style.cursor = 'default';
    if (document.pointerLockElement) document.exitPointerLock();
}

function openSettingsModal(mod) {
    const theme = THEMES[window.MC_CHEAT.currentTheme] || THEMES.green;
    const modal = document.createElement('div');
    modal.id = 'settings-modal';
    modal.style.position = 'fixed';
    modal.style.top = '50%';
    modal.style.left = '50%';
    modal.style.transform = 'translate(-50%, -50%)';
    modal.style.zIndex = '10001';
    modal.style.background = 'rgba(10,10,10,0.95)';
    modal.style.color = 'white';
    modal.style.padding = '20px';
    modal.style.borderRadius = '10px';
    modal.style.fontFamily = 'monospace';
    modal.style.width = '300px';
    modal.style.border = '2px solid ' + theme.border;
    
    const title = document.createElement('div');
    title.textContent = 'Настройки: ' + mod.toUpperCase();
    title.style.fontWeight = 'bold';
    title.style.fontSize = '15px';
    title.style.color = theme.main;
    title.style.marginBottom = '15px';
    title.style.textAlign = 'center';
    modal.appendChild(title);
    
    if (mod === 'speed') {
        const label = document.createElement('div');
        label.textContent = 'Режим:';
        label.style.color = '#aaa';
        label.style.marginTop = '10px';
        modal.appendChild(label);
        const select = document.createElement('select');
        select.style.background = '#333';
        select.style.color = 'white';
        select.style.border = '1px solid #555';
        select.style.padding = '8px';
        select.style.borderRadius = '5px';
        select.style.width = '100%';
        select.style.fontFamily = 'inherit';
        ['legit', 'bunnyhop', 'fly', 'lowhop'].forEach(mode => {
            const opt = document.createElement('option');
            opt.value = mode;
            opt.textContent = mode;
            select.appendChild(opt);
        });
        select.value = window.MC_CHEAT.speedMode;
        select.onchange = () => { window.MC_CHEAT.speedMode = select.value; };
        modal.appendChild(select);
    }
    
    if (mod === 'killaura') {
        const atkLabel = document.createElement('div');
        atkLabel.textContent = 'Дистанция атаки: ' + window.MC_CHEAT.killauraAttackRange;
        atkLabel.style.color = '#aaa';
        atkLabel.style.marginTop = '10px';
        modal.appendChild(atkLabel);
        const atkSlider = document.createElement('input');
        atkSlider.type = 'range';
        atkSlider.min = '1';
        atkSlider.max = '6';
        atkSlider.step = '0.5';
        atkSlider.value = window.MC_CHEAT.killauraAttackRange;
        atkSlider.style.width = '100%';
        atkSlider.oninput = () => {
            window.MC_CHEAT.killauraAttackRange = parseFloat(atkSlider.value);
            atkLabel.textContent = 'Дистанция атаки: ' + atkSlider.value;
        };
        modal.appendChild(atkSlider);
        
        const aimLabel = document.createElement('div');
        aimLabel.textContent = 'Дистанция наводки: ' + window.MC_CHEAT.killauraAimRange;
        aimLabel.style.color = '#aaa';
        aimLabel.style.marginTop = '15px';
        modal.appendChild(aimLabel);
        const aimSlider = document.createElement('input');
        aimSlider.type = 'range';
        aimSlider.min = '6';
        aimSlider.max = '12';
        aimSlider.step = '0.5';
        aimSlider.value = window.MC_CHEAT.killauraAimRange;
        aimSlider.style.width = '100%';
        aimSlider.oninput = () => {
            window.MC_CHEAT.killauraAimRange = parseFloat(aimSlider.value);
            aimLabel.textContent = 'Дистанция наводки: ' + aimSlider.value;
        };
        modal.appendChild(aimSlider);
    }
    
    if (mod === 'targetstrafe') {
        const modeLabel = document.createElement('div');
        modeLabel.textContent = 'Режим:';
        modeLabel.style.color = '#aaa';
        modeLabel.style.marginTop = '10px';
        modal.appendChild(modeLabel);
        const modeSelect = document.createElement('select');
        modeSelect.style.background = '#333';
        modeSelect.style.color = 'white';
        modeSelect.style.border = '1px solid #555';
        modeSelect.style.padding = '8px';
        modeSelect.style.borderRadius = '5px';
        modeSelect.style.width = '100%';
        modeSelect.style.fontFamily = 'inherit';
        [['normal', 'Обычный'], ['safe', 'Безопасный']].forEach(([val, label]) => {
            const opt = document.createElement('option');
            opt.value = val;
            opt.textContent = label;
            modeSelect.appendChild(opt);
        });
        modeSelect.value = window.MC_CHEAT.targetstrafeMode;
        modeSelect.onchange = () => { window.MC_CHEAT.targetstrafeMode = modeSelect.value; };
        modal.appendChild(modeSelect);
        
        const rangeLabel = document.createElement('div');
        rangeLabel.textContent = 'Радиус: ' + window.MC_CHEAT.targetstrafeRange;
        rangeLabel.style.color = '#aaa';
        rangeLabel.style.marginTop = '15px';
        modal.appendChild(rangeLabel);
        const rangeSlider = document.createElement('input');
        rangeSlider.type = 'range';
        rangeSlider.min = '1';
        rangeSlider.max = '6';
        rangeSlider.step = '0.5';
        rangeSlider.value = window.MC_CHEAT.targetstrafeRange;
        rangeSlider.style.width = '100%';
        rangeSlider.oninput = () => {
            window.MC_CHEAT.targetstrafeRange = parseFloat(rangeSlider.value);
            rangeLabel.textContent = 'Радиус: ' + rangeSlider.value;
        };
        modal.appendChild(rangeSlider);
        
        const speedLabel = document.createElement('div');
        speedLabel.textContent = 'Скорость: ' + window.MC_CHEAT.targetstrafeSpeed;
        speedLabel.style.color = '#aaa';
        speedLabel.style.marginTop = '15px';
        modal.appendChild(speedLabel);
        const speedSlider = document.createElement('input');
        speedSlider.type = 'range';
        speedSlider.min = '0.1';
        speedSlider.max = '1';
        speedSlider.step = '0.05';
        speedSlider.value = window.MC_CHEAT.targetstrafeSpeed;
        speedSlider.style.width = '100%';
        speedSlider.oninput = () => {
            window.MC_CHEAT.targetstrafeSpeed = parseFloat(speedSlider.value);
            speedLabel.textContent = 'Скорость: ' + speedSlider.value;
        };
        modal.appendChild(speedSlider);
    }
    
    if (mod === 'esp') {
        const modeLabel = document.createElement('div');
        modeLabel.textContent = 'Режим:';
        modeLabel.style.color = '#aaa';
        modeLabel.style.marginTop = '10px';
        modal.appendChild(modeLabel);
        const modeSelect = document.createElement('select');
        modeSelect.style.background = '#333';
        modeSelect.style.color = 'white';
        modeSelect.style.border = '1px solid #555';
        modeSelect.style.padding = '8px';
        modeSelect.style.borderRadius = '5px';
        modeSelect.style.width = '100%';
        modeSelect.style.fontFamily = 'inherit';
        [['box', 'Куб'], ['chams', 'Chams']].forEach(([val, label]) => {
            const opt = document.createElement('option');
            opt.value = val;
            opt.textContent = label;
            modeSelect.appendChild(opt);
        });
        modeSelect.value = window.MC_CHEAT.espMode;
        modeSelect.onchange = () => {
            window.MC_CHEAT.espMode = modeSelect.value;
            if (window.MC_CHEAT.modules.esp) createESP();
        };
        modal.appendChild(modeSelect);
        
        const opacityLabel = document.createElement('div');
        opacityLabel.textContent = 'Насыщенность: ' + window.MC_CHEAT.espOpacity;
        opacityLabel.style.color = '#aaa';
        opacityLabel.style.marginTop = '15px';
        modal.appendChild(opacityLabel);
        const opacitySlider = document.createElement('input');
        opacitySlider.type = 'range';
        opacitySlider.min = '0.1';
        opacitySlider.max = '1.0';
        opacitySlider.step = '0.05';
        opacitySlider.value = window.MC_CHEAT.espOpacity;
        opacitySlider.style.width = '100%';
        opacitySlider.oninput = () => {
            window.MC_CHEAT.espOpacity = parseFloat(opacitySlider.value);
            opacityLabel.textContent = 'Насыщенность: ' + opacitySlider.value;
            if (window.MC_CHEAT.modules.esp) createESP();
        };
        modal.appendChild(opacitySlider);
    }
    
    if (mod === 'spider') {
        const speedLabel = document.createElement('div');
        speedLabel.textContent = 'Скорость: ' + window.MC_CHEAT.spiderSpeed;
        speedLabel.style.color = '#aaa';
        speedLabel.style.marginTop = '10px';
        modal.appendChild(speedLabel);
        const speedSlider = document.createElement('input');
        speedSlider.type = 'range';
        speedSlider.min = '0.05';
        speedSlider.max = '0.5';
        speedSlider.step = '0.05';
        speedSlider.value = window.MC_CHEAT.spiderSpeed;
        speedSlider.style.width = '100%';
        speedSlider.oninput = () => {
            window.MC_CHEAT.spiderSpeed = parseFloat(speedSlider.value);
            speedLabel.textContent = 'Скорость: ' + speedSlider.value;
        };
        modal.appendChild(speedSlider);
    }
    
    if (mod === 'fog') {
        const opacityLabel = document.createElement('div');
        opacityLabel.textContent = 'Насыщенность: ' + window.MC_CHEAT.fogOpacity;
        opacityLabel.style.color = '#aaa';
        opacityLabel.style.marginTop = '10px';
        modal.appendChild(opacityLabel);
        const opacitySlider = document.createElement('input');
        opacitySlider.type = 'range';
        opacitySlider.min = '0.01';
        opacitySlider.max = '0.5';
        opacitySlider.step = '0.01';
        opacitySlider.value = window.MC_CHEAT.fogOpacity;
        opacitySlider.style.width = '100%';
        opacitySlider.oninput = () => {
            window.MC_CHEAT.fogOpacity = parseFloat(opacitySlider.value);
            opacityLabel.textContent = 'Насыщенность: ' + opacitySlider.value;
            if (window.MC_CHEAT.fogMesh) {
                window.MC_CHEAT.fogMesh.material.opacity = window.MC_CHEAT.fogOpacity;
            }
        };
        modal.appendChild(opacitySlider);
        
        const distanceLabel = document.createElement('div');
        distanceLabel.textContent = 'Дальность: ' + window.MC_CHEAT.fogDistance;
        distanceLabel.style.color = '#aaa';
        distanceLabel.style.marginTop = '15px';
        modal.appendChild(distanceLabel);
        const distanceSlider = document.createElement('input');
        distanceSlider.type = 'range';
        distanceSlider.min = '10';
        distanceSlider.max = '300';
        distanceSlider.step = '10';
        distanceSlider.value = window.MC_CHEAT.fogDistance;
        distanceSlider.style.width = '100%';
        distanceSlider.oninput = () => {
            window.MC_CHEAT.fogDistance = parseInt(distanceSlider.value);
            distanceLabel.textContent = 'Дальность: ' + distanceSlider.value;
            if (window.MC_CHEAT.fogMesh) {
                window.MC_CHEAT.fogMesh.geometry.dispose();
                window.MC_CHEAT.fogMesh.geometry = new THREE.BoxGeometry(
                    window.MC_CHEAT.fogDistance,
                    window.MC_CHEAT.fogDistance,
                    window.MC_CHEAT.fogDistance
                );
            }
        };
        modal.appendChild(distanceSlider);
    }
    
    const hint = document.createElement('div');
    hint.textContent = 'ESC - назад';
    hint.style.color = '#666';
    hint.style.marginTop = '20px';
    hint.style.textAlign = 'center';
    modal.appendChild(hint);
    
    document.body.appendChild(modal);
}

function closeGUI() {
    ['combat', 'movement', 'visual', 'macros', 'theme'].forEach(cat => {
        const panel = document.getElementById(`category-${cat}`);
        if (panel) panel.remove();
    });
    const modal = document.getElementById('settings-modal');
    if (modal) modal.remove();
    window.MC_CHEAT.guiVisible = false;
}

setInterval(() => {
    createRelayHUD();
    createCoordsHUD();
    createKeyBindsHUD();
}, 100);

document.addEventListener('keydown', (e) => {
    if (e.code === 'ShiftRight') {
        e.preventDefault();
        if (window.MC_CHEAT.guiVisible) {
            closeGUI();
        } else {
            createAllPanels();
        }
    }
    if (e.code === 'Escape' && window.MC_CHEAT.guiVisible) {
        e.preventDefault();
        e.stopPropagation();
        const modal = document.getElementById('settings-modal');
        if (modal) {
            modal.remove();
        } else {
            closeGUI();
        }
    }
    
    if (!window.MC_CHEAT.guiVisible) {
        const key = e.key.toUpperCase();
        if (window.MC_CHEAT.binds[key]) {
            const mods = window.MC_CHEAT.binds[key];
            if (Array.isArray(mods)) {
                mods.forEach(mod => toggleModule(mod));
            } else {
                toggleModule(mods);
            }
            createKeyBindsHUD();
        }
    }
}, true);

console.log('%c[CHEAT] v17.0 загружен! Правый Shift - GUI', 'background: green; color: white; font-size: 16px');