Greasy Fork

Aim Assist for cloud gaming

Aim assist script with typing "bet" to toggle

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

// ==UserScript==
// @name         Aim Assist for cloud gaming
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Aim assist script with typing "bet" to toggle
// @author       You
// @match        *://*.xbox.com/*
// @grant        none
// ==/UserScript==

// Set the aim assist strength (0-1)
const AIM_ASSIST_STRENGTH = 0.8;

// Set the player detection radius (in pixels)
const PLAYER_DETECTION_RADIUS = 150;

// Set the aim assist speed (in pixels per frame)
const AIM_ASSIST_SPEED = 5;

// Create a variable to store the aim assist state
let aimAssistEnabled = false;

// Create a variable to store the aim assist target
let aimAssistTarget = null;

// Create a function to detect players
function detectPlayers() {
  // Get the game canvas element
  const canvas = document.querySelector('canvas');

  // Get the 2D drawing context
  const ctx = canvas.getContext('2d');

  // Get the player's crosshair position
  const crosshairX = canvas.width / 2;
  const crosshairY = canvas.height / 2;

  // Loop through all pixels in the canvas
  for (let x = 0; x < canvas.width; x++) {
    for (let y = 0; y < canvas.height; y++) {
      // Calculate the distance between the crosshair and the current pixel
      const distance = Math.sqrt((x - crosshairX) ** 2 + (y - crosshairY) ** 2);

      // Check if the pixel is within the player detection radius
      if (distance < PLAYER_DETECTION_RADIUS) {
        // Get the pixel color
        const pixelColor = ctx.getImageData(x, y, 1, 1).data;

        // Check if the pixel color matches the player's color (you may need to adjust this)
        if (pixelColor[0] > 100 && pixelColor[1] > 100 && pixelColor[2] > 100) {
          // Set the aim assist target to the player's position
          aimAssistTarget = { x, y };

          // Break out of the loop
          break;
        }
      }
    }
  }
}

// Create a function to apply the aim assist
function applyAimAssist() {
  // Get the game canvas element
  const canvas = document.querySelector('canvas');

  // Get the player's crosshair position
  const crosshairX = canvas.width / 2;
  const crosshairY = canvas.height / 2;

  // Calculate the aim assist direction
  const aimAssistDirectionX = aimAssistTarget.x - crosshairX;
  const aimAssistDirectionY = aimAssistTarget.y - crosshairY;

  // Calculate the aim assist distance
  const aimAssistDistance = Math.sqrt(aimAssistDirectionX ** 2 + aimAssistDirectionY ** 2);

  // Calculate the aim assist speed
  const aimAssistSpeedX = aimAssistDirectionX / aimAssistDistance * AIM_ASSIST_SPEED;
  const aimAssistSpeedY = aimAssistDirectionY / aimAssistDistance * AIM_ASSIST_SPEED;

  // Apply the aim assist
  if (aimAssistEnabled) {
    const aimAssistX = crosshairX + aimAssistSpeedX;
    const aimAssistY = crosshairY + aimAssistSpeedY;
    canvas.dispatchEvent(new MouseEvent('mousemove', { clientX: aimAssistX, clientY: aimAssistY }));
  }
}

// Create a function to toggle the aim assist
function toggleAimAssist() {
  aimAssistEnabled = !aimAssistEnabled;
  console.log(`Aim assist ${aimAssistEnabled ? 'enabled' : 'disabled'}`);
}

// Add an event listener to the document to detect keyboard input
document.addEventListener('keydown', (event) => {
  const input = document.querySelector('input[type="text"]');
  if (input && input.value.toLowerCase() === 'bet') {
    toggleAimAssist();
    input.value = '';
  }
});

// Add an event listener to the game canvas to detect mouse movements
canvas.addEventListener('mousemove', detectPlayers);

// Add an event listener to the game canvas to apply the aim assist
setInterval(applyAimAssist, 16); // 16ms = 60fps