Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # pip install tensorflow tensorflow-hub opencv-python numpy mss pydirectinput keyboard pywin32
- import tensorflow as tf
- import tensorflow_hub as hub
- import cv2
- import numpy as np
- import mss
- import pydirectinput
- import keyboard
- import time
- import math
- import colorsys
- # Windows-specific imports for the overlay
- import win32gui
- import win32con
- import win32api
- # --- Configuration ---
- # You can change these values to tune the bot
- AIM_KEY = 'right' # The key to hold down to activate the aimbot (e.g., 'right' for right mouse button)
- AIM_BONE = 'nose' # The body part to aim at. Options: 'nose', 'left_eye', 'right_eye', 'left_ear', 'right_ear', 'left_shoulder', 'right_shoulder', 'left_elbow', 'right_elbow', 'left_wrist', 'right_wrist', 'left_hip', 'right_hip', 'left_knee', 'right_knee', 'left_ankle', 'right_ankle'
- AIM_SPEED = 0.15 # How fast the mouse moves. Lower is slower/smoother. (0.1 - 1.0)
- CONFIDENCE_THRESHOLD = 0.25 # Minimum confidence for a detection to be considered (0.0 - 1.0)
- FOV_RADIUS = 250 # Field of View: The radius (in pixels) around the crosshair to lock onto targets.
- QUIT_KEY = 'end' # The key to press to stop the script.
- # --- Advanced Configuration ---
- MONITOR_NUMBER = 1 # The monitor to capture. 1 is the primary monitor.
- MODEL_SELECTION = 'movenet_lightning' # Model variants: 'movenet_lightning', 'movenet_thunder'. Lightning is faster, Thunder is more accurate.
- # --- Code ---
- # Do not change below this line unless you know what you are doing
- # Dictionary to map body part names to their keypoint indices
- KEYPOINT_DICT = {
- 'nose': 0, 'left_eye': 1, 'right_eye': 2, 'left_ear': 3, 'right_ear': 4,
- 'left_shoulder': 5, 'right_shoulder': 6, 'left_elbow': 7, 'right_elbow': 8,
- 'left_wrist': 9, 'right_wrist': 10, 'left_hip': 11, 'right_hip': 12,
- 'left_knee': 13, 'right_knee': 14, 'left_ankle': 15, 'right_ankle': 16
- }
- # Define skeleton connections
- SKELETON_CONNECTIONS = [
- (0, 1), (0, 2), (1, 3), (2, 4), (0, 5), (0, 6), (5, 7), (7, 9),
- (6, 8), (8, 10), (5, 6), (5, 11), (6, 12), (11, 12), (11, 13),
- (13, 15), (12, 14), (14, 16)
- ]
- class ScreenOverlay:
- """A class to create a transparent, click-through overlay on the screen."""
- def __init__(self, width, height):
- self.width = width
- self.height = height
- self.hwnd = None
- wc = win32gui.WNDCLASS()
- wc.hInstance = win32api.GetModuleHandle(None)
- wc.lpszClassName = "PythonOverlay"
- wc.lpfnWndProc = lambda hwnd, msg, wparam, lparam: 0
- class_atom = win32gui.RegisterClass(wc)
- self.hwnd = win32gui.CreateWindowEx(
- win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT | win32con.WS_EX_LAYERED,
- class_atom, "PythonOverlayWindow", win32con.WS_POPUP,
- 0, 0, self.width, self.height, None, None, wc.hInstance, None
- )
- win32gui.SetLayeredWindowAttributes(self.hwnd, 0, 255, win32con.LWA_ALPHA)
- win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)
- def update(self, frame_bgr):
- if not self.hwnd: return
- frame_bgra = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2BGRA)
- black_pixels_mask = np.all(frame_bgra == [0, 0, 0, 255], axis=-1)
- frame_bgra[black_pixels_mask] = [0, 0, 0, 0]
- hdc_screen = win32gui.GetDC(0)
- hdc_mem = win32gui.CreateCompatibleDC(hdc_screen)
- h_bitmap = win32gui.CreateCompatibleBitmap(hdc_screen, self.width, self.height)
- win32gui.SelectObject(hdc_mem, h_bitmap)
- try:
- from win32ui import CreateBitmap
- bmp = CreateBitmap()
- bmp.CreateFromHandle(h_bitmap)
- bmp.SetBitmapBits(True, frame_bgra.tobytes())
- except ImportError:
- print("Please run `pip install pywin32-ctypes` if you have issues with bitmap creation.")
- return
- blend = win32gui.BLENDFUNCTION(win32con.AC_SRC_OVER, 0, 255, win32con.AC_SRC_ALPHA)
- win32gui.UpdateLayeredWindow(self.hwnd, hdc_screen, (0, 0), (self.width, self.height),
- hdc_mem, (0, 0), 0, blend, win32con.ULW_ALPHA)
- win32gui.DeleteObject(h_bitmap)
- win32gui.DeleteDC(hdc_mem)
- win32gui.ReleaseDC(None, hdc_screen)
- def cleanup(self):
- if self.hwnd:
- win32gui.DestroyWindow(self.hwnd)
- self.hwnd = None
- def load_model(model_name):
- print(f"Loading model '{model_name}'...")
- if model_name == "movenet_lightning": module = hub.load("https://tfhub.dev/google/movenet/singlepose/lightning/4")
- elif model_name == "movenet_thunder": module = hub.load("https://tfhub.dev/google/movenet/singlepose/thunder/4")
- else: raise ValueError(f"Unknown model name: {model_name}")
- return module.signatures['serving_default']
- def run_inference(model, image):
- if MODEL_SELECTION == 'movenet_lightning': input_size = 192
- else: input_size = 256
- image_tensor = tf.convert_to_tensor(image)
- image_tensor = tf.image.resize_with_pad(image_tensor, input_size, input_size)
- image_tensor = tf.expand_dims(image_tensor, axis=0)
- image_tensor = tf.cast(image_tensor, dtype=tf.int32)
- outputs = model(image_tensor)
- return outputs['output_0'].numpy()[0, 0, :, :]
- def get_rainbow_color(hue):
- r, g, b = colorsys.hsv_to_rgb(hue, 1.0, 1.0)
- return (int(b * 255), int(g * 255), int(r * 255))
- def draw_esp(frame, keypoints, color):
- h, w, _ = frame.shape
- for y, x, score in keypoints:
- if score > CONFIDENCE_THRESHOLD:
- cv2.circle(frame, (int(x * w), int(y * h)), 3, color, -1)
- for start_idx, end_idx in SKELETON_CONNECTIONS:
- start_kp, end_kp = keypoints[start_idx], keypoints[end_idx]
- if start_kp[2] > CONFIDENCE_THRESHOLD and end_kp[2] > CONFIDENCE_THRESHOLD:
- cv2.line(frame, (int(start_kp[1] * w), int(start_kp[0] * h)),
- (int(end_kp[1] * w), int(end_kp[0] * h)), color, 2)
- valid_kps = [kp for kp in keypoints if kp[2] > CONFIDENCE_THRESHOLD]
- if len(valid_kps) > 2:
- min_x = int(min(kp[1] for kp in valid_kps) * w)
- min_y = int(min(kp[0] for kp in valid_kps) * h)
- max_x = int(max(kp[1] for kp in valid_kps) * w)
- max_y = int(max(kp[0] for kp in valid_kps) * h)
- cv2.rectangle(frame, (min_x, min_y), (max_x, max_y), color, 2)
- def main():
- pose_model = load_model(MODEL_SELECTION)
- try:
- target_bone_idx = KEYPOINT_DICT[AIM_BONE]
- except KeyError:
- print(f"Error: Invalid AIM_BONE '{AIM_BONE}'. Please choose from {list(KEYPOINT_DICT.keys())}")
- return
- sct = mss.mss()
- monitor = sct.monitors[MONITOR_NUMBER]
- screen_width, screen_height = monitor["width"], monitor["height"]
- screen_center_x, screen_center_y = screen_width // 2, screen_height // 2
- overlay = ScreenOverlay(screen_width, screen_height)
- print(f"Screen dimensions: {screen_width}x{screen_height}")
- print(f"Aimbot activated. Hold '{AIM_KEY}' to aim. Press '{QUIT_KEY}' to quit.")
- hue = 0.0
- try:
- while not keyboard.is_pressed(QUIT_KEY):
- win32gui.PumpWaitingMessages()
- sct_img = sct.grab(monitor)
- frame_rgba = np.array(sct_img)
- frame_rgb = cv2.cvtColor(frame_rgba, cv2.COLOR_BGRA2RGB)
- keypoints = run_inference(pose_model, frame_rgb)
- target_kp = keypoints[target_bone_idx]
- target_y, target_x, target_confidence = target_kp
- target_x_screen, target_y_screen = int(target_x * screen_width), int(target_y * screen_height)
- if keyboard.is_pressed(AIM_KEY) and target_confidence > CONFIDENCE_THRESHOLD:
- dist = math.sqrt((target_x_screen - screen_center_x)**2 + (target_y_screen - screen_center_y)**2)
- if dist <= FOV_RADIUS:
- move_x = (target_x_screen - screen_center_x) * AIM_SPEED
- move_y = (target_y_screen - screen_center_y) * AIM_SPEED
- pydirectinput.move(int(move_x), int(move_y), relative=True)
- esp_frame = np.zeros((screen_height, screen_width, 3), dtype=np.uint8)
- hue = (hue + 0.005) % 1.0
- rainbow_color = get_rainbow_color(hue)
- if keypoints[:, 2].max() > CONFIDENCE_THRESHOLD:
- draw_esp(esp_frame, keypoints, rainbow_color)
- cv2.circle(esp_frame, (screen_center_x, screen_center_y), FOV_RADIUS, (255, 255, 0), 1)
- overlay.update(esp_frame)
- finally:
- print("Aimbot terminating.")
- overlay.cleanup()
- sct.close()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment