Enhanced Krunker.IO Aimbot & ESP with Modes and Team Check

High-performance aimbot and ESP for Krunker.io with modes and team-based filtering

目前为 2024-12-05 提交的版本。查看 最新版本

// ==UserScript==
// @name         Enhanced Krunker.IO Aimbot & ESP with Modes and Team Check
// @namespace    http://tampermonkey.net/
// @version      1.1.0
// @description  High-performance aimbot and ESP for Krunker.io with modes and team-based filtering
// @author       Loki
// @match        *://krunker.io/*
// @exclude      *://krunker.io/social*
// @exclude      *://krunker.io/editor*
// @grant        none
// @run-at       document-start
// ==/UserScript==

const settings = {
    aimbotEnabled: true,
    aimbotMode: 'snap', // Modes: 'snap', 'soft', 'assist'
    espEnabled: true,
    espLines: true,
    wireframe: false,
};

const keyBindings = {
    KeyB: 'aimbotEnabled', // Toggle aimbot
    KeyT: 'toggleMode', // Toggle between aimbot modes
    KeyM: 'espEnabled', // Toggle ESP
    KeyN: 'espLines', // Toggle ESP lines
};

const AIMBOT_MODES = ['snap', 'soft', 'assist'];
let scene = null;
let myPlayer = null;

// Hook into scene safely
const originalAdd = Object.prototype.add;
Object.prototype.add = function(value) {
    if (value?.type === 'Scene' && value.name === 'Main') {
        scene = value;
        console.log('Scene injected!');
    }
    return originalAdd ? originalAdd.call(this, value) : value;
};

// Find players and current user
function findPlayers() {
    if (!scene) return { players: [], myPlayer: null };

    const players = [];
    let myPlayer = null;

    for (const child of scene.children) {
        if (child.type !== 'Object3D') continue;

        try {
            const camera = child.children[0]?.children[0];
            if (camera?.type === 'PerspectiveCamera') {
                myPlayer = child;
            } else if (child.children[0]) {
                players.push(child);
            }
        } catch (e) {
            console.warn('Error processing player object:', e);
        }
    }

    return { players, myPlayer };
}

// Aimbot logic
function aimbot(targetPlayer, myPlayer) {
    if (!settings.aimbotEnabled || !targetPlayer || !myPlayer) return;

    if (isTeammate(targetPlayer)) return;

    const targetPosition = targetPlayer.children[0]?.children[0]?.getWorldPosition(new THREE.Vector3());
    const direction = targetPosition.sub(myPlayer.position).normalize();

    if (settings.aimbotMode === 'snap') {
        myPlayer.lookAt(targetPosition);

    } else if (settings.aimbotMode === 'soft') {
        myPlayer.rotation.x = THREE.MathUtils.lerp(myPlayer.rotation.x, direction.x, 0.1);
        myPlayer.rotation.y = THREE.MathUtils.lerp(myPlayer.rotation.y, direction.y, 0.1);

    } else if (settings.aimbotMode === 'assist') {
        myPlayer.rotation.x = THREE.MathUtils.lerp(myPlayer.rotation.x, direction.x, 0.05);
        myPlayer.rotation.y = THREE.MathUtils.lerp(myPlayer.rotation.y, direction.y, 0.05);
    }
}

// Check if a player is on the same team
function isTeammate(player) {
    try {
        const playerTeam = player.team || player.playerTeam || 0;
        const myTeam = myPlayer.team || myPlayer.playerTeam || 0;
        return playerTeam === myTeam;
    } catch (e) {
        console.warn('Error checking teammate:', e);
        return false;
    }
}

// Render ESP
function renderESP(players) {
    if (!settings.espEnabled) return;

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

    for (const player of players) {
        const screenPos = toScreenPosition(player.position, myPlayer.children[0]?.children[0]);
        if (!screenPos) continue;

        ctx.beginPath();
        ctx.moveTo(screenPos.x, screenPos.y);
        ctx.lineTo(window.innerWidth / 2, window.innerHeight); // Example: line to bottom center
        ctx.strokeStyle = 'red';
        ctx.stroke();
    }
}

function createCanvas() {
    const canvas = document.createElement('canvas');
    canvas.id = 'espCanvas';
    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);
    return canvas;
}

function 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,
    };
}

// Game loop
function gameLoop() {
    requestAnimationFrame(gameLoop);

    const { players, myPlayer: player } = findPlayers();
    myPlayer = player; // Update myPlayer reference
    if (!players.length || !myPlayer) return;

    let targetPlayer = null;
    let minDist = Infinity;

    for (const player of players) {
        if (isTeammate(player)) continue;
        const dist = player.position.distanceTo(myPlayer.position);
        if (dist < minDist) {
            minDist = dist;
            targetPlayer = player;
        }
    }

    aimbot(targetPlayer, myPlayer);
    renderESP(players);
}

// Event listeners
window.addEventListener('keyup', (e) => {
    if (document.activeElement?.tagName === 'INPUT') return;

    const setting = keyBindings[e.code];
    if (setting === 'toggleMode') {
        const currentIndex = AIMBOT_MODES.indexOf(settings.aimbotMode);
        settings.aimbotMode = AIMBOT_MODES[(currentIndex + 1) % AIMBOT_MODES.length];
        console.log(`Aimbot mode: ${settings.aimbotMode}`);
    } else if (setting) {
        settings[setting] = !settings[setting];
        console.log(`${setting} set to ${settings[setting]}`);
    }
});

// Start the game loop
gameLoop();