Skip to content

Instantly share code, notes, and snippets.

@Sam-Belliveau
Last active August 27, 2021 03:36
Show Gist options
  • Save Sam-Belliveau/7028918a13ce96417c4bc95ee92ea2e7 to your computer and use it in GitHub Desktop.
Save Sam-Belliveau/7028918a13ce96417c4bc95ee92ea2e7 to your computer and use it in GitHub Desktop.
[CDLLBOSS DID HELP MAKE THIS] This is just an experiment for using the radar to make an aimbot. Its not amazing, but its impossible to detect as it just looks at the screen. It takes some configuring, like getting the radar perfectly in view and making binds, but it shouldnt be too hard.
# INSTALL PYTHON FROM THE WINDOWS STORE THAN DOUBLE CLICK THE PYTHON FILES
# ALL DEPENDANCIES WILL INSTALL AUTOMATICALLY
from subprocess import call
# GUI
from tkinter import *
import tkinter.font as tkFont
# Timing Functions
import sys
import time
import timeit
# Recording Screen
try:
import win32api, win32ui, win32gui, win32con
except Exception:
call(['pip', 'install', 'pywin32'])
import win32api, win32ui, win32gui, win32con
# CV
try:
import numpy as np
except Exception:
call(['pip', 'install', 'numpy'])
import numpy as np
try:
import cv2
except Exception:
call(['pip', 'install', 'opencv-python'])
import cv2
# Misc Math
from math import hypot, atan2, degrees
# User IO
try:
import pyautogui as mouse
except Exception:
call(['pip', 'install', 'pyautogui'])
import pyautogui as mouse
try:
import keyboard
except Exception:
call(['pip', 'install', 'keyboard'])
import keyboard
# Print Things to Console Fast
def fast_print(text):
sys.stdout.write(text)
sys.stdout.flush
#################################
### ENTRY CLASS FOR CONSTANTS ###
#################################
# GUI CONFIG
FONT_NAME = "Helvetica"
FONT_SIZE = 14
row = 0
column = 0
config_window = Tk()
config_window.title("S1mple Aimbot")
# Class lets you make variables appear in gui
class ConfigEntry:
def __init__(self, name, value):
global row
global column
global config_window
self.name = name
font = tkFont.Font(family=FONT_NAME, size=FONT_SIZE)
Label(config_window, text=name, font=font).grid(row=row, column=column)
self.entry = Entry(config_window, font=font)
self.entry.grid(row=row, column=column + 1)
self.entry.insert(0, value)
row += 1
def get_str(self):
try:
return self.entry.get()
except Exception as e:
fast_print("\n[ERROR] Error Reading Entry \"{}\"".format(self.name))
return "Error"
def get_num(self):
try:
return float(self.get_str())
except Exception as e:
fast_print("\n[ERROR] Invalid Value for \"{}\"".format(self.name))
return 0.0
def get_bool(self):
return self.get_str().lower().strip() in ['true', 'on', '1', 'yes', 'y']
#################
### CONSTANTS ###
#################
def indent():
global row
global column
row = 0
column += 2
def add_title(name):
global row
font = tkFont.Font(family=FONT_NAME, size=FONT_SIZE + 2)
Label(config_window, text=name, font=font).grid(row=row, column=column)
row += 1
# Name of game to record
add_title("Game Config")
APP_NAME = ConfigEntry("App Name", 'Counter-Strike: Global Offensive')
# size of windows title bar in pixels
add_title("")
add_title("Window Config")
WINDOWS_TITLE_SIZE = ConfigEntry("Window Title Bar Size", 31)
WINDOWS_BORDER_THICKNESS = ConfigEntry("Window Border Size", 1)
# Radar coords as a ratio of the screen
# NOTE: CONFIG IS FOR 1080p WITH MAX RADAR SIZE
add_title("")
add_title("Radar Config")
X_START_RADAR_RATIO = ConfigEntry("Radar X Pos", 0.0168)
X_TOTAL_RADAR_RATIO = ConfigEntry("Radar X Size", 0.171)
Y_START_RADAR_RATIO = ConfigEntry("Radar Y Pos", 0.08)
Y_TOTAL_RADAR_RATIO = ConfigEntry("Radar Y Size", 0.3045)
# Button pressed to enable aimbot
indent()
add_title("Aimbot Config")
AIMBOT_BUTTON = ConfigEntry("Aimbot Button", 'Alt')
USE_MOUSE_VAL = ConfigEntry("Aimbot on Click", 'False')
PIXELS_PER_ANGLE = ConfigEntry("Aimbot Speed", 15)
# Range that a pixel can be for it to be an enemy
RADAR_RED_LOWER_MASK = np.array([0, 0, 200])
RADAR_RED_UPPER_MASK = np.array([64, 64, 255])
GREY_THRESHOLD = 32
# Sorting Values
add_title("")
add_title("Aimbot Priorities")
MAX_ANGLE = ConfigEntry("Max Aimbot Angle", 90)
DIST_VAL = ConfigEntry("Distance Importance", 1)
ANG_VAL = ConfigEntry("Angle Importance", 1)
SOLIDITY_VAL = ConfigEntry("Solidity Importance", 1)
MIN_SOLIDITY = ConfigEntry("Min Solidity [0 - 1]", 0.2)
# Auto Shoot
add_title("")
add_title("Autoshoot Config")
ENABLE_AUTO_SHOOT = ConfigEntry("Enable Autoshoot", 'True')
MAX_ANG_SHOOT = ConfigEntry("Max Autoshoot Angle", 1)
TIME_BETWEEN_SHOTS = ConfigEntry("Time Between Shots", 0.2)
RECOIL_CONTROL_PER_SHOT = ConfigEntry("Recoil Compensation", 0.1)
# MISC
DEFAULT_ANGLE = "Nothing Detected"
############
### CODE ###
############
# Code to get the part of the screen
# that displays the radar
def get_radar_pos():
pos = { 'x': 0, 'y': 0, 'w': 0, 'h': 0, }
def callback(hwnd, extra):
rect = win32gui.GetWindowRect(hwnd)
if win32gui.GetWindowText(hwnd) == APP_NAME.get_str():
pos['x'] = rect[0] + WINDOWS_BORDER_THICKNESS.get_num()
pos['y'] = rect[1] + WINDOWS_TITLE_SIZE.get_num() + WINDOWS_BORDER_THICKNESS.get_num()
pos['w'] = rect[2] - pos['x'] - WINDOWS_BORDER_THICKNESS.get_num()
pos['h'] = rect[3] - pos['y'] - WINDOWS_BORDER_THICKNESS.get_num()
win32gui.EnumWindows(callback, None)
x = pos['x']; y = pos['y'];
w = pos['w']; h = pos['h'];
x1 = int(x + w * X_START_RADAR_RATIO.get_num())
y1 = int(y + h * Y_START_RADAR_RATIO.get_num())
x2 = int(x1 + w * X_TOTAL_RADAR_RATIO.get_num())
y2 = int(y1 + h * Y_TOTAL_RADAR_RATIO.get_num())
return (x1, y1, x2, y2)
# Grab a region of the screen and feed it into an opencv image
def capture_screen(box):
try:
hwin = win32gui.GetDesktopWindow()
left, top, x2, y2 = box
width = x2 - left + 1
height = y2 - top + 1
hwindc = win32gui.GetWindowDC(hwin)
srcdc = win32ui.CreateDCFromHandle(hwindc)
memdc = srcdc.CreateCompatibleDC()
bmp = win32ui.CreateBitmap()
bmp.CreateCompatibleBitmap(srcdc, width, height)
memdc.SelectObject(bmp)
memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), win32con.SRCCOPY)
signedIntsArray = bmp.GetBitmapBits(True)
img = np.fromstring(signedIntsArray, dtype='uint8')
img.shape = (height, width, 4)
srcdc.DeleteDC()
memdc.DeleteDC()
win32gui.ReleaseDC(hwin, hwindc)
win32gui.DeleteObject(bmp.GetHandle())
return cv2.cvtColor(img, cv2.COLOR_RGBA2RGB)
except Exception as e:
frame = np.zeros((1, 1, 3), np.uint8)
return cv2.cvtColor(frame, cv2.COLOR_RGBA2BGR)
# Filter out the red on the radar
def filter_radar_red(img):
result = img.copy()
# Mask Red Pixels
mask = cv2.inRange(img, RADAR_RED_LOWER_MASK, RADAR_RED_UPPER_MASK)
# Apply Mask
result = cv2.bitwise_and(img, img, mask=mask)
# Make pixlels on or off
result = cv2.cvtColor(result, cv2.COLOR_BGR2GRAY)
ret, result = cv2.threshold(result, GREY_THRESHOLD, 255, 0)
return result
# Get the closest player, then get the angle to him
def get_best_ang(img):
# Get contours from radar
def get_contours(img):
contours, hierarchy = cv2.findContours(img, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
return contours
# Takes angle and distance and sees how worthwhile he is to lock onto
def get_worth(x, y, solidity):
ang = abs(atan2(x, y)) ** ANG_VAL.get_num()
dist = hypot(x, y) ** DIST_VAL.get_num()
sinv = (1 / max(solidity, 1 / 65536)) ** SOLIDITY_VAL.get_num()
return dist * ang * sinv
# Get what percentage of the contour is taken up This helps avoid x's and ?'s
def get_solidity(contour):
area = cv2.contourArea(contour)
x,y,w,h = cv2.boundingRect(contour)
rectArea = w * h
return area / rectArea
# Where the best ang is stored
target_ang = DEFAULT_ANGLE
target_worth = -1
# Go through contours
for c in get_contours(img):
# Get x, y pixel values
x, y, w, h = cv2.boundingRect(c)
x += w / 2
y += h / 2
# Shape values around center
x = x - img.shape[1] / 2
y = img.shape[0] / 2 - y
# Get Angle of Target
ang = degrees(atan2(x, y))
# If to far away, aim else where
if abs(ang) > MAX_ANGLE.get_num():
continue
solidity = get_solidity(c)
if solidity < MIN_SOLIDITY.get_num():
continue
cv2.drawContours(img, [c], -1, [255, 255, 0], 3)
worth = get_worth(x, y, solidity)
if worth < target_worth or target_worth < 0:
target_ang = ang
target_worth = worth
return target_ang
# Move mouse by angle
def move_mouse(ang_horiz, ang_vert):
MOUSEEVENT_MOVE = 0x01
scale = PIXELS_PER_ANGLE.get_num()
x = ang_horiz * scale
y = ang_vert * scale
win32api.mouse_event(MOUSEEVENT_MOVE, int(x), int(y))
# Stop it from clicking too fast
last_shot = timeit.default_timer()
# If angle is lower than threshold, shoot
def auto_shoot(ang):
global last_shot
elapsed = timeit.default_timer() - last_shot
if(TIME_BETWEEN_SHOTS.get_num() < elapsed and abs(ang) < MAX_ANG_SHOOT.get_num() and ENABLE_AUTO_SHOOT.get_bool()):
mouse.click()
move_mouse(0, RECOIL_CONTROL_PER_SHOT.get_num())
last_shot = timeit.default_timer()
# If Aimbot Key Is Pressed
def get_key():
try:
if keyboard.is_pressed(AIMBOT_BUTTON.get_str()):
return True
except Exception as e:
pass
if USE_MOUSE_VAL.get_bool():
MOUSE_KEY = 0x01
state = win32api.GetKeyState(MOUSE_KEY)
if(state == -127 or state == -128):
return True
return False
# Check if window is in focus
def game_is_focused():
is_focused = APP_NAME.get_str() == win32gui.GetWindowText(win32gui.GetForegroundWindow())
return is_focused
# FPS tracker
last_update = timeit.default_timer()
while True:
# Debug info
debug_fps = "ERR"
debug_ang = DEFAULT_ANGLE
# Find radar scaling
radar_pos = get_radar_pos()
# Capture radar
radar = capture_screen(radar_pos)
# Aimbot
if get_key() and game_is_focused():
radar = filter_radar_red(radar)
ang = get_best_ang(radar)
debug_ang = ang
if(ang != DEFAULT_ANGLE):
move_mouse(ang, 0)
auto_shoot(ang)
# Display Images
cv2.imshow("S1mple Aimbot Radar", radar)
# Calculate Elapsed Time
old_update = last_update
last_update = timeit.default_timer()
elapsed = last_update - old_update
# Calculate FPS
debug_fps = 1 / elapsed
# Print Debug Info
fast_print("\rS1mple Aimbot [FPS: {}, ANG: {}]\t\t\t".format(debug_fps, debug_ang))
# Update TK Window
config_window.update()
cv2.destroyAllWindows()
@CDLLBOSS
Copy link

I helped you make this

@CDLLBOSS
Copy link

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment