Untitled

 avatar
unknown
plain_text
a year ago
4.4 kB
14
Indexable
import time
from pynput.keyboard import Listener
from pynput.mouse import Controller
from termcolor import colored  
from ultralytics import YOLO
import mss  
import numpy as np
import cv2
        
class Aimbot:
    def __init__(self, box_constant=350, collect_data=False, mouse_delay=0.0006):
        self.box_constant = box_constant  # Detection box size (width/height)
        self.conf = 0.45  # Confidence threshold
        self.collect_data = collect_data
        self.mouse_delay = mouse_delay
        
        # Model Path: Update with your correct YOLO model
        self.model = YOLO('/Users/chocolatu/Downloads/Users/chocolatu/Desktop/AI-Aimbot-main 2/lib/yolov11.p)')

        # Mouse and Keyboard Setup
        self.mouse_controller = Controller()
        self.keyboard_listener = Listener(on_press=self.on_press)
        self.keyboard_listener.start()
                
        # Screen Setup (via mss)
        self.screen = mss.mss()
        self.screen_width, self.screen_height = self.get_screen_resolution()
                    
        # Aimbot Status
        self.aimbot_enabled = False
        
        # Welcome Messages
        print("[INFO] Aimbot initialized")
        print("[INFO] PRESS 'C' to toggle AIMBOT")
        print("[INFO] PRESS 'V' to quit") 
        
    def get_screen_resolution(self):
        """Get the current screen resolution."""
        monitor = self.screen.monitors[0]
        return monitor["width"], monitor["height"]
        
    def on_press(self, key):
        """Handle keyboard input."""
        try:
            if hasattr(key, 'char'):
                pressed_key = key.char.lower()
                if pressed_key == 'c':
                    self.toggle_aimbot()
                elif pressed_key == 'v':
                    print("[INFO] Quitting script...")
   self.keyboard_listener.stop()
                    exit(0)
        except AttributeError:
            pass
        
    def toggle_aimbot(self):
        """Toggle the aimbot on or off."""
        self.aimbot_enabled = not self.aimbot_enabled
        status = "ENABLED" if self.aimbot_enabled else "DISABLED"
        print(f"[INFO] Aimbot is {status}")
    
    def move_mouse(self, dx, dy):   
        """Move the mouse by a given offset.""" 
        current_position = self.mouse_controller.position
        new_position = (current_position[0] + dx, current_position[1] + dy)
        self.mouse_controller.position = new_position
    
    def start(self):
        """Start the aimbot loop."""
        print("[INFO] Starting screen capture...")
                
        while True:
            if self.aimbot_enabled:
                frame = self.capture_screen()
                detections = self.detect_objects(frame)
                    
                if detections:
                    # Target the first detection
                    x, y, w, h = detections[0]  # Bounding box of the target
                    
                    target_x = x + w // 2
                    target_y = y + h // 3  # Adjust to aim at the "head"
        
                    dx = target_x - self.screen_width // 2
                    dy = target_y - self.screen_height // 2
                    
                    self.move_mouse(dx, dy)
        
                print("[INFO] Aiming at target...")
        
            time.sleep(self.mouse_delay)
    
    def capture_screen(self):
        """Capture the screen as a NumPy array."""
        monitor = self.screen.monitors[0]
        frame = np.array(self.screen.grab(monitor))
        return cv2.cvtColor(frame, cv2.COLOR_BGRA2RGB)
            
    def detect_objects(self, frame):
     """Capture the screen as a NumPy array."""
        monitor = self.screen.monitors[0]
        frame = np.array(self.screen.grab(monitor))
        return cv2.cvtColor(frame, cv2.COLOR_BGRA2RGB)
            
    def detect_objects(self, frame):
        """Detect objects in the frame using YOLO."""  
        results = self.model(frame, conf=self.conf, device="cpu")
                
        detections = []
        for result in results.xyxy[0]:  # Iterate over detected objects
            x1, y1, x2, y2, conf, cls = result
            if conf >= self.conf:
                detections.append((int(x1), int(y1), int(x2 - x1), int(y2 - y1)))
        
        return detections
                    
# Main Script       
if __name__ == "__main__":
    aimbot = Aimbot()
    aimbot.start()
Editor is loading...
Leave a Comment