Enhanced Krunker.IO Aimbot, ESP, and Recoil Control (Improved)

Aimbot, ESP, recoil control system with keybindings, dynamic GUI, and settings save/load.

目前為 2024-12-18 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Enhanced Krunker.IO Aimbot, ESP, and Recoil Control (Improved)
// @namespace    http://tampermonkey.net/
// @version      2.0.0
// @description  Aimbot, ESP, recoil control system with keybindings, dynamic GUI, and settings save/load.
// @author       Loki Enhanced
// @match        *://krunker.io/*
// @exclude      *://krunker.io/social*
// @exclude      *://krunker.io/editor*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(() => {
    const config = {
        aimbot: { enabled: true, mode: 'snap' },
        esp: { enabled: true, color: 'red' },
        recoilControl: { enabled: true, intensity: 0.8 },
        keybindings: { toggleAimbot: 'F1', toggleESP: 'F2', toggleRecoil: 'F3' },
    };

    const state = { scene: null, players: [], myPlayer: null };
    const canvasID = 'espCanvas';

    /** Hook into the game scene */
    const hookScene = () => {
        const originalAdd = Object.prototype.add;
        Object.prototype.add = function (obj) {
            if (obj?.type === 'Scene' && obj.name === 'Main') {
                state.scene = obj;
                console.log('Scene hooked successfully!');
            }
            return originalAdd?.call(this, obj);
        };
    };

    /** Find players and my player */
    const findPlayers = () => {
        const { scene } = state;
        if (!scene) return { players: [], myPlayer: null };

        const players = [];
        let myPlayer = null;

        scene.children.forEach((child) => {
            if (child.type !== 'Object3D') return;

            const camera = child.children[0]?.children[0];
            if (camera?.type === 'PerspectiveCamera') {
                myPlayer = child;
            } else if (child.children[0]) {
                players.push(child);
            }
        });

        return { players, myPlayer };
    };

    /** Aimbot logic */
    const aimbotLogic = (targetPlayer, myPlayer) => {
        if (!config.aimbot.enabled || !targetPlayer || !myPlayer) return;
        const targetPos = targetPlayer.children[0]?.children[0]?.getWorldPosition(new THREE.Vector3());
        if (!targetPos) return;

        if (config.aimbot.mode === 'snap') {
            myPlayer.lookAt(targetPos);
        } else {
            const factor = config.aimbot.mode === 'soft' ? 0.1 : 0.05;
            myPlayer.rotation.x = THREE.MathUtils.lerp(myPlayer.rotation.x, targetPos.x, factor);
            myPlayer.rotation.y = THREE.MathUtils.lerp(myPlayer.rotation.y, targetPos.y, factor);
        }
    };

    /** ESP logic */
    const renderESP = (players) => {
        if (!config.esp.enabled) return;

        const canvas = document.getElementById(canvasID) || createCanvas();
        const ctx = canvas.getContext('2d');
        ctx.clearRect(0, 0, canvas.width, canvas.height);

        players.forEach((player) => {
            const screenPos = toScreenPosition(player.position, state.myPlayer.children[0]?.children[0]);
            if (!screenPos) return;

            ctx.fillStyle = config.esp.color;
            ctx.beginPath();
            ctx.arc(screenPos.x, screenPos.y, 5, 0, Math.PI * 2);
            ctx.fill();
        });
    };

    const createCanvas = () => {
        const canvas = document.createElement('canvas');
        canvas.id = canvasID;
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        canvas.style.position = 'absolute';
        canvas.style.top = '0';
        canvas.style.left = '0';
        canvas.style.pointerEvents = 'none';
        document.body.appendChild(canvas);

        window.addEventListener('resize', () => {
            canvas.width = window.innerWidth;
            canvas.height = window.innerHeight;
        });

        return canvas;
    };

    const toScreenPosition = (position, camera) => {
        if (!camera) return null;
        const vector = position.clone().project(camera);
        return {
            x: (vector.x + 1) * window.innerWidth / 2,
            y: (-vector.y + 1) * window.innerHeight / 2,
        };
    };

    /** Recoil Control System */
    const controlRecoil = (myPlayer) => {
        if (!config.recoilControl.enabled || !myPlayer) return;

        const recoilIntensity = config.recoilControl.intensity;
        myPlayer.rotation.x -= Math.random() * 0.005 * recoilIntensity;
        myPlayer.rotation.y -= Math.random() * 0.005 * recoilIntensity;
    };

    /** GUI Creation */
    const createGUI = () => {
        const button = document.createElement('button');
        button.innerHTML = 'Toggle Hacks';
        button.style.position = 'absolute';
        button.style.top = '10px';
        button.style.left = '10px';
        button.style.zIndex = '10000';
        button.onclick = toggleGUI;

        const gui = document.createElement('div');
        gui.id = 'hacksGUI';
        gui.style.display = 'none';
        gui.style.position = 'absolute';
        gui.style.top = '50px';
        gui.style.left = '10px';
        gui.style.padding = '10px';
        gui.style.backgroundColor = '#222';
        gui.style.color = '#fff';
        gui.style.border = '1px solid #444';
        gui.style.zIndex = '10000';

        const toggles = [
            { label: 'Enable Aimbot', obj: config.aimbot, key: 'enabled' },
            { label: 'Enable ESP', obj: config.esp, key: 'enabled' },
            { label: 'Recoil Control', obj: config.recoilControl, key: 'enabled' },
        ];

        toggles.forEach(({ label, obj, key }) => {
            const toggle = createToggle(label, obj, key);
            gui.appendChild(toggle);
        });

        document.body.appendChild(button);
        document.body.appendChild(gui);
    };

    const createToggle = (label, obj, key) => {
        const container = document.createElement('div');
        const checkbox = document.createElement('input');
        checkbox.type = 'checkbox';
        checkbox.checked = obj[key];
        checkbox.onchange = () => {
            obj[key] = checkbox.checked;
            alert(`${label}: ${obj[key]}`);
        };

        const labelElem = document.createElement('label');
        labelElem.innerText = label;
        labelElem.style.marginLeft = '5px';

        container.appendChild(checkbox);
        container.appendChild(labelElem);
        return container;
    };

    const toggleGUI = () => {
        const gui = document.getElementById('hacksGUI');
        gui.style.display = gui.style.display === 'none' ? 'block' : 'none';
    };

    /** Add Keybindings */
    const setupKeybindings = () => {
        window.addEventListener('keydown', (e) => {
            switch (e.key.toUpperCase()) {
                case config.keybindings.toggleAimbot:
                    config.aimbot.enabled = !config.aimbot.enabled;
                    alert(`Aimbot: ${config.aimbot.enabled}`);
                    break;
                case config.keybindings.toggleESP:
                    config.esp.enabled = !config.esp.enabled;
                    alert(`ESP: ${config.esp.enabled}`);
                    break;
                case config.keybindings.toggleRecoil:
                    config.recoilControl.enabled = !config.recoilControl.enabled;
                    alert(`Recoil Control: ${config.recoilControl.enabled}`);
                    break;
            }
        });
    };

    /** Game loop */
    const gameLoop = () => {
        requestAnimationFrame(gameLoop);

        const { players, myPlayer } = findPlayers();
        state.players = players;
        state.myPlayer = myPlayer;

        if (!players.length || !myPlayer) return;

        let closestPlayer = null;
        let minDist = Infinity;

        players.forEach((player) => {
            const dist = player.position.distanceTo(myPlayer.position);
            if (dist < minDist) {
                minDist = dist;
                closestPlayer = player;
            }
        });

        aimbotLogic(closestPlayer, myPlayer);
        renderESP(players);
        controlRecoil(myPlayer);
    };

    hookScene();
    createGUI();
    setupKeybindings();
    gameLoop();
})();