Greasy Fork

Greasy Fork is available in English.

Enhanced Aim Assist with Bounding Box

Aims at detected players with bounding boxes around them (for educational use only)

当前为 2024-12-25 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Enhanced Aim Assist with Bounding Box
// @namespace    ViolentMonkey Scripts
// @version      1.1
// @description  Aims at detected players with bounding boxes around them (for educational use only)
// @author       You
// @match        https://www.xbox.com/en-US/play/launch/fortnite/BT5P2X999VH2
// @grant        none
// ==/UserScript==

(async function() {
    'use strict';

    // Include TensorFlow.js and Coco-SSD model
    const scriptTensorFlow = document.createElement('script');
    scriptTensorFlow.src = 'https://cdn.jsdelivr.net/npm/@tensorflow/tfjs';
    document.head.appendChild(scriptTensorFlow);

    const scriptCocoSSD = document.createElement('script');
    scriptCocoSSD.src = 'https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/coco-ssd';
    document.head.appendChild(scriptCocoSSD);

    // Wait for TensorFlow.js and Coco-SSD to load
    await new Promise(resolve => {
        scriptTensorFlow.onload = scriptCocoSSD.onload = resolve;
    });

    // Configuration Settings
    const aimAssistConfig = {
        sensitivity: 0.5,       // Sensitivity: Higher values = slower aim movement
        assistEnabled: false,   // Whether aim assist is on or off
        toggleKeys: ['4', 't'], // Keys to toggle the assist on/off
        detectionInterval: 100, // Milliseconds between detections
        boxColor: 'rgba(0, 255, 0, 0.6)', // Color for the bounding box
    };

    // Track key presses for toggling aim assist
    let keySequence = [];
    document.addEventListener("keydown", (e) => {
        keySequence.push(e.key.toLowerCase());
        if (keySequence.slice(-2).join('') === aimAssistConfig.toggleKeys.join('')) {
            aimAssistConfig.assistEnabled = !aimAssistConfig.assistEnabled;
            console.log(`Aim assist ${aimAssistConfig.assistEnabled ? 'enabled' : 'disabled'}`);
            keySequence = [];
        }
    });

    // Capture the game feed (assuming video element or canvas)
    const videoElement = document.querySelector('video');  // Modify if game uses a different element
    if (!videoElement) {
        console.error("Game video feed not found.");
        return;
    }

    // Initialize the canvas for object detection
    const canvas = document.createElement('canvas');
    const context = canvas.getContext('2d');
    document.body.appendChild(canvas);  // Optional: to debug by showing canvas

    // Load the Coco-SSD model
    let model;
    try {
        model = await cocoSsd.load();
        console.log("Coco-SSD model loaded.");
    } catch (error) {
        console.error("Error loading model: ", error);
        return;
    }

    // Object detection and aim assist loop
    async function aimAssistLoop() {
        if (aimAssistConfig.assistEnabled) {
            // Draw the video frame to the canvas
            canvas.width = videoElement.videoWidth;
            canvas.height = videoElement.videoHeight;
            context.drawImage(videoElement, 0, 0, canvas.width, canvas.height);

            // Detect objects in the frame
            const predictions = await model.detect(canvas);
            if (predictions.length > 0) {
                // Prioritize targets (e.g., prioritize persons/players)
                const target = prioritizeTargets(predictions);
                if (target) {
                    // Draw bounding box around the detected player
                    drawBoundingBox(target);

                    // Simulate aiming at the target
                    adjustAimToTarget(target);
                }
            }
        }
        setTimeout(aimAssistLoop, aimAssistConfig.detectionInterval);
    }

    // Prioritize the best target (filter relevant objects)
    function prioritizeTargets(predictions) {
        // Filter to get the player/people with high confidence score
        const target = predictions.find(pred => pred.class === 'person' && pred.score > 0.5);
        if (target) {
            return target;
        }
        return null;
    }

    // Draw a bounding box around the detected player
    function drawBoundingBox(target) {
        const [x, y, width, height] = target.bbox;
        context.strokeStyle = aimAssistConfig.boxColor;
        context.lineWidth = 3;
        context.beginPath();
        context.rect(x, y, width, height);
        context.stroke();
    }

    // Adjust aim by simulating mouse movement
    function adjustAimToTarget(target) {
        const [x, y, width, height] = target.bbox;
        const targetCenterX = x + width / 2;
        const targetCenterY = y + height / 2;

        // Calculate the adjustment needed to center the aim on the target
        const deltaX = targetCenterX - canvas.width / 2;
        const deltaY = targetCenterY - canvas.height / 2;

        // Apply sensitivity to the movement
        const newX = canvas.width / 2 + deltaX * aimAssistConfig.sensitivity;
        const newY = canvas.height / 2 + deltaY * aimAssistConfig.sensitivity;

        // Simulate the mouse movement to adjust the aim
        const mouseEvent = new MouseEvent('mousemove', {
            clientX: newX,
            clientY: newY,
        });
        document.dispatchEvent(mouseEvent);
        console.log(`Aiming at target: (${newX}, ${newY})`);
    }

    // Start the detection loop
    aimAssistLoop();
})();