Josiahiscool73

ai aimbot in python pre trained models tensorflow hub

Jun 29th, 2025
216
0
Never
6
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.98 KB | None | 0 0
  1. pip install tensorflow tensorflow-hub numpy pyautogui opencv-python pywin32
  2.  
  3. import tensorflow as tf
  4. import tensorflow_hub as hub
  5. import numpy as np
  6. import pyautogui
  7. import win32api, win32con, win32gui
  8. import cv2
  9. import math
  10. import time
  11.  
  12. # --- Aimbot Configuration ---
  13. # Load Detection model from TensorFlow Hub. [1]
  14. # The specific model used is 'centernet/resnet50v1_fpn_512x512/1' which is an image object detection model. [1]
  15. detector = hub.load("https://tfhub.dev/tensorflow/centernet/resnet50v1_fpn_512x512/1")
  16. # This scale factor is used to resize the screenshot for faster processing on less powerful hardware. [1]
  17. # The video indicates a size_scale of 3 was used to resize to 1/3 of the original image. [1]
  18. size_scale = 3
  19.  
  20. # Main loop for the aimbot to continuously run
  21. while True:
  22. # 1. Get rect of Window
  23. # Find the game window by its title. [1]
  24. # Changed to target "Google Chrome" as requested.
  25. hwnd = win32gui.FindWindow(None, 'Google Chrome')
  26.  
  27. # If the game window is not found, print a message and continue to the next iteration.
  28. if hwnd == 0:
  29. print("Google Chrome window not found. Make sure Chrome is running and the window title is correct.")
  30. time.sleep(1) # Wait a bit before retrying
  31. continue
  32.  
  33. # Get the bounding box coordinates (left, top, right, bottom) of the game window. [1]
  34. rect = win32gui.GetWindowRect(hwnd)
  35. # Convert the rectangle to (x, y, width, height) format for pyautogui.screenshot. [1]
  36. region = rect[0], rect[1], rect[2] - rect[0], rect[3] - rect[1]
  37.  
  38. # 2. Get a screen and pre-process
  39. # Take a screenshot of the specified game window region. [1]
  40. # The output is a NumPy array representing the image. [1]
  41. ori_img = np.array(pyautogui.screenshot(region=region))
  42.  
  43. # Resize the image to match the `size_scale` for faster processing. [1]
  44. # The model expects specific input dimensions. [1]
  45. ori_img = cv2.resize(ori_img, (ori_img.shape[1] // size_scale, ori_img.shape[0] // size_scale))
  46.  
  47. # Add a batch dimension to the image, as the TensorFlow model expects input shape (1, H, W, 3). [1]
  48. image = np.expand_dims(ori_img, 0)
  49.  
  50. # Store the width and height of the processed image for later calculations. [1]
  51. img_w, img_h = image.shape[2], image.shape[1]
  52.  
  53. # 3. Detection and calculate distance
  54. # Pass the image to the loaded detection model. [1]
  55. result = detector(image)
  56. # Convert TensorFlow tensors in the result to NumPy arrays. [1]
  57. result = {key:value.numpy() for key,value in result.items()}
  58.  
  59. # Extract detection boxes, scores, and classes. [1]
  60. boxes = result['detection_boxes'][0]
  61. scores = result['detection_scores'][0]
  62. classes = result['detection_classes'][0]
  63.  
  64. detected_boxes = []
  65. # Iterate through each detected object. [1]
  66. for i, box in enumerate(boxes):
  67. # The COCO dataset, which this model is trained on, labels 'person' as class 1. [1]
  68. # Filter detections to only include 'persons' with a confidence score of 0.5 or higher. [1]
  69. if classes[i] == 1 and scores[i] >= 0.5:
  70. ymin, xmin, ymax, xmax = tuple(box)
  71.  
  72. # Custom condition to ignore detections in the bottom part of the screen. [1]
  73. # This is to prevent detecting the player's own weapon as a human. [1]
  74. # These values (0.5 and 0.8) are specific to CS:GO in the video and may need adjustment. [1]
  75. if ymin > 0.5 and ymax > 0.8:
  76. continue
  77.  
  78. # Convert normalized bounding box coordinates to pixel coordinates relative to the image. [1]
  79. # The result is the portion of the image. So you need to multiply width and height. [1]
  80. left = int(xmin * img_w)
  81. right = int(xmax * img_w)
  82. top = int(ymin * img_h)
  83. bottom = int(ymax * img_h)
  84. detected_boxes.append((left, right, top, bottom))
  85.  
  86. # Optional: Draw rectangles on the image for debugging and visualization.
  87. # cv2.rectangle(ori_img, (left, top), (right, bottom), (255, 255, 0), 2)
  88.  
  89. # Check if any objects were detected. [1]
  90. if len(detected_boxes) >= 1:
  91. min_dist = 99999 # Initialize minimum distance to a very high value. [1]
  92. closest_idx = 0 # Index of the closest detected object. [1]
  93. centers = [] # To store the center coordinates of detected boxes. [1]
  94.  
  95. # Calculate the center of each detected bounding box and its distance from the screen's crosshair (center). [1]
  96. for i, box in enumerate(detected_boxes):
  97. x1, y1, x2, y2 = box
  98. c_x = ((x2 - x1) / 2) + x1 # Center X coordinate
  99. c_y = ((y2 - y1) / 2) + y1 # Center Y coordinate
  100. centers.append((c_x, c_y))
  101.  
  102. # Calculate the Euclidean distance from the image center (crosshair) to the object's center. [1]
  103. dist = math.sqrt(math.pow(img_w/2 - c_x, 2) + math.pow(img_h/2 - c_y, 2))
  104.  
  105. # Update the closest object if a closer one is found. [1]
  106. if dist < min_dist:
  107. min_dist = dist
  108. closest_idx = i
  109.  
  110. # 4. Move mouse and shoot
  111. # Calculate the pixel difference in X and Y from the crosshair to the target's center. [1]
  112. x_diff = centers[closest_idx][0] - img_w/2
  113. # For Y, an offset (0.45 of box height) is added to aim for the head. This value is empirical. [1]
  114. y_diff = centers[closest_idx][1] - img_h/2 - (detected_boxes[closest_idx][3] - detected_boxes[closest_idx][2]) * 0.45
  115.  
  116. # Scale the pixel difference to match in-game mouse sensitivity. [1]
  117. # This '1.7' value is derived from trial and error in the video for the specific game/setup. [1]
  118. # It's multiplied by 'size_scale' because the image was downscaled, and we need to compensate. [1]
  119. mouse_scale = 1.7 * size_scale
  120. scaled_x = int(x_diff * mouse_scale)
  121. scaled_y = int(y_diff * mouse_scale)
  122.  
  123. # Use win32api to move the mouse relative to its current position. [1]
  124. # MOUSEEVENTF_MOVE is used for movement. [1]
  125. win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, scaled_x, scaled_y, 0, 0)
  126. time.sleep(0.05) # Short delay after moving the mouse. [1]
  127.  
  128. # Simulate a left mouse button press (shoot). [1]
  129. win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, scaled_x, scaled_y, 0, 0)
  130. time.sleep(0.1) # Hold the mouse button down for a brief moment. [1]
  131. win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, scaled_x, scaled_y, 0, 0) # Release the mouse button. [1]
  132.  
  133. # Optional: Display the processed image with detections (uncomment if you want to see the visual output)
  134. # This requires an OpenCV window to be set up, which might interfere with game performance.
  135. # cv2.imshow("Detection Output", cv2.cvtColor(ori_img, cv2.COLOR_BGR2RGB))
  136. # cv2.waitKey(1) # Wait for 1ms for a key event (keeps the window responsive)
  137.  
  138. time.sleep(0.1) # General delay for the loop to prevent excessive CPU usage. [1]
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment