Josiahiscool73

ai aimbots in python

Jul 18th, 2025
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.66 KB | None | 0 0
  1. # pip install tensorflow tensorflow-hub opencv-python numpy mss pydirectinput keyboard pywin32
  2.  
  3. import tensorflow as tf
  4. import tensorflow_hub as hub
  5. import cv2
  6. import numpy as np
  7. import mss
  8. import pydirectinput
  9. import keyboard
  10. import time
  11. import math
  12. import colorsys
  13.  
  14. # Windows-specific imports for the overlay
  15. import win32gui
  16. import win32con
  17. import win32api
  18.  
  19. # --- Configuration ---
  20. # You can change these values to tune the bot
  21. AIM_KEY = 'right' # The key to hold down to activate the aimbot (e.g., 'right' for right mouse button)
  22. 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'
  23. AIM_SPEED = 0.15 # How fast the mouse moves. Lower is slower/smoother. (0.1 - 1.0)
  24. CONFIDENCE_THRESHOLD = 0.25 # Minimum confidence for a detection to be considered (0.0 - 1.0)
  25. FOV_RADIUS = 250 # Field of View: The radius (in pixels) around the crosshair to lock onto targets.
  26. QUIT_KEY = 'end' # The key to press to stop the script.
  27.  
  28. # --- Advanced Configuration ---
  29. MONITOR_NUMBER = 1 # The monitor to capture. 1 is the primary monitor.
  30. MODEL_SELECTION = 'movenet_lightning' # Model variants: 'movenet_lightning', 'movenet_thunder'. Lightning is faster, Thunder is more accurate.
  31.  
  32. # --- Code ---
  33. # Do not change below this line unless you know what you are doing
  34.  
  35. # Dictionary to map body part names to their keypoint indices
  36. KEYPOINT_DICT = {
  37. 'nose': 0, 'left_eye': 1, 'right_eye': 2, 'left_ear': 3, 'right_ear': 4,
  38. 'left_shoulder': 5, 'right_shoulder': 6, 'left_elbow': 7, 'right_elbow': 8,
  39. 'left_wrist': 9, 'right_wrist': 10, 'left_hip': 11, 'right_hip': 12,
  40. 'left_knee': 13, 'right_knee': 14, 'left_ankle': 15, 'right_ankle': 16
  41. }
  42.  
  43. # Define skeleton connections
  44. SKELETON_CONNECTIONS = [
  45. (0, 1), (0, 2), (1, 3), (2, 4), (0, 5), (0, 6), (5, 7), (7, 9),
  46. (6, 8), (8, 10), (5, 6), (5, 11), (6, 12), (11, 12), (11, 13),
  47. (13, 15), (12, 14), (14, 16)
  48. ]
  49.  
  50. class ScreenOverlay:
  51. """A class to create a transparent, click-through overlay on the screen."""
  52. def __init__(self, width, height):
  53. self.width = width
  54. self.height = height
  55. self.hwnd = None
  56.  
  57. wc = win32gui.WNDCLASS()
  58. wc.hInstance = win32api.GetModuleHandle(None)
  59. wc.lpszClassName = "PythonOverlay"
  60. wc.lpfnWndProc = lambda hwnd, msg, wparam, lparam: 0
  61. class_atom = win32gui.RegisterClass(wc)
  62.  
  63. self.hwnd = win32gui.CreateWindowEx(
  64. win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT | win32con.WS_EX_LAYERED,
  65. class_atom, "PythonOverlayWindow", win32con.WS_POPUP,
  66. 0, 0, self.width, self.height, None, None, wc.hInstance, None
  67. )
  68. win32gui.SetLayeredWindowAttributes(self.hwnd, 0, 255, win32con.LWA_ALPHA)
  69. win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)
  70.  
  71. def update(self, frame_bgr):
  72. if not self.hwnd: return
  73. frame_bgra = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2BGRA)
  74. black_pixels_mask = np.all(frame_bgra == [0, 0, 0, 255], axis=-1)
  75. frame_bgra[black_pixels_mask] = [0, 0, 0, 0]
  76. hdc_screen = win32gui.GetDC(0)
  77. hdc_mem = win32gui.CreateCompatibleDC(hdc_screen)
  78. h_bitmap = win32gui.CreateCompatibleBitmap(hdc_screen, self.width, self.height)
  79. win32gui.SelectObject(hdc_mem, h_bitmap)
  80.  
  81. try:
  82. from win32ui import CreateBitmap
  83. bmp = CreateBitmap()
  84. bmp.CreateFromHandle(h_bitmap)
  85. bmp.SetBitmapBits(True, frame_bgra.tobytes())
  86. except ImportError:
  87. print("Please run `pip install pywin32-ctypes` if you have issues with bitmap creation.")
  88. return
  89.  
  90. blend = win32gui.BLENDFUNCTION(win32con.AC_SRC_OVER, 0, 255, win32con.AC_SRC_ALPHA)
  91. win32gui.UpdateLayeredWindow(self.hwnd, hdc_screen, (0, 0), (self.width, self.height),
  92. hdc_mem, (0, 0), 0, blend, win32con.ULW_ALPHA)
  93. win32gui.DeleteObject(h_bitmap)
  94. win32gui.DeleteDC(hdc_mem)
  95. win32gui.ReleaseDC(None, hdc_screen)
  96.  
  97. def cleanup(self):
  98. if self.hwnd:
  99. win32gui.DestroyWindow(self.hwnd)
  100. self.hwnd = None
  101.  
  102. def load_model(model_name):
  103. print(f"Loading model '{model_name}'...")
  104. if model_name == "movenet_lightning": module = hub.load("https://tfhub.dev/google/movenet/singlepose/lightning/4")
  105. elif model_name == "movenet_thunder": module = hub.load("https://tfhub.dev/google/movenet/singlepose/thunder/4")
  106. else: raise ValueError(f"Unknown model name: {model_name}")
  107. return module.signatures['serving_default']
  108.  
  109. def run_inference(model, image):
  110. if MODEL_SELECTION == 'movenet_lightning': input_size = 192
  111. else: input_size = 256
  112. image_tensor = tf.convert_to_tensor(image)
  113. image_tensor = tf.image.resize_with_pad(image_tensor, input_size, input_size)
  114. image_tensor = tf.expand_dims(image_tensor, axis=0)
  115. image_tensor = tf.cast(image_tensor, dtype=tf.int32)
  116. outputs = model(image_tensor)
  117. return outputs['output_0'].numpy()[0, 0, :, :]
  118.  
  119. def get_rainbow_color(hue):
  120. r, g, b = colorsys.hsv_to_rgb(hue, 1.0, 1.0)
  121. return (int(b * 255), int(g * 255), int(r * 255))
  122.  
  123. def draw_esp(frame, keypoints, color):
  124. h, w, _ = frame.shape
  125. for y, x, score in keypoints:
  126. if score > CONFIDENCE_THRESHOLD:
  127. cv2.circle(frame, (int(x * w), int(y * h)), 3, color, -1)
  128. for start_idx, end_idx in SKELETON_CONNECTIONS:
  129. start_kp, end_kp = keypoints[start_idx], keypoints[end_idx]
  130. if start_kp[2] > CONFIDENCE_THRESHOLD and end_kp[2] > CONFIDENCE_THRESHOLD:
  131. cv2.line(frame, (int(start_kp[1] * w), int(start_kp[0] * h)),
  132. (int(end_kp[1] * w), int(end_kp[0] * h)), color, 2)
  133. valid_kps = [kp for kp in keypoints if kp[2] > CONFIDENCE_THRESHOLD]
  134. if len(valid_kps) > 2:
  135. min_x = int(min(kp[1] for kp in valid_kps) * w)
  136. min_y = int(min(kp[0] for kp in valid_kps) * h)
  137. max_x = int(max(kp[1] for kp in valid_kps) * w)
  138. max_y = int(max(kp[0] for kp in valid_kps) * h)
  139. cv2.rectangle(frame, (min_x, min_y), (max_x, max_y), color, 2)
  140.  
  141. def main():
  142. pose_model = load_model(MODEL_SELECTION)
  143. try:
  144. target_bone_idx = KEYPOINT_DICT[AIM_BONE]
  145. except KeyError:
  146. print(f"Error: Invalid AIM_BONE '{AIM_BONE}'. Please choose from {list(KEYPOINT_DICT.keys())}")
  147. return
  148.  
  149. sct = mss.mss()
  150. monitor = sct.monitors[MONITOR_NUMBER]
  151. screen_width, screen_height = monitor["width"], monitor["height"]
  152. screen_center_x, screen_center_y = screen_width // 2, screen_height // 2
  153.  
  154. overlay = ScreenOverlay(screen_width, screen_height)
  155. print(f"Screen dimensions: {screen_width}x{screen_height}")
  156. print(f"Aimbot activated. Hold '{AIM_KEY}' to aim. Press '{QUIT_KEY}' to quit.")
  157.  
  158. hue = 0.0
  159. try:
  160. while not keyboard.is_pressed(QUIT_KEY):
  161. win32gui.PumpWaitingMessages()
  162.  
  163. sct_img = sct.grab(monitor)
  164. frame_rgba = np.array(sct_img)
  165. frame_rgb = cv2.cvtColor(frame_rgba, cv2.COLOR_BGRA2RGB)
  166.  
  167. keypoints = run_inference(pose_model, frame_rgb)
  168.  
  169. target_kp = keypoints[target_bone_idx]
  170. target_y, target_x, target_confidence = target_kp
  171. target_x_screen, target_y_screen = int(target_x * screen_width), int(target_y * screen_height)
  172.  
  173. if keyboard.is_pressed(AIM_KEY) and target_confidence > CONFIDENCE_THRESHOLD:
  174. dist = math.sqrt((target_x_screen - screen_center_x)**2 + (target_y_screen - screen_center_y)**2)
  175. if dist <= FOV_RADIUS:
  176. move_x = (target_x_screen - screen_center_x) * AIM_SPEED
  177. move_y = (target_y_screen - screen_center_y) * AIM_SPEED
  178. pydirectinput.move(int(move_x), int(move_y), relative=True)
  179.  
  180. esp_frame = np.zeros((screen_height, screen_width, 3), dtype=np.uint8)
  181.  
  182. hue = (hue + 0.005) % 1.0
  183. rainbow_color = get_rainbow_color(hue)
  184.  
  185. if keypoints[:, 2].max() > CONFIDENCE_THRESHOLD:
  186. draw_esp(esp_frame, keypoints, rainbow_color)
  187.  
  188. cv2.circle(esp_frame, (screen_center_x, screen_center_y), FOV_RADIUS, (255, 255, 0), 1)
  189.  
  190. overlay.update(esp_frame)
  191.  
  192. finally:
  193. print("Aimbot terminating.")
  194. overlay.cleanup()
  195. sct.close()
  196.  
  197. if __name__ == "__main__":
  198. main()
Advertisement
Add Comment
Please, Sign In to add comment