Skip to content

Commit 37c39e8

Browse files
committed
version 0.6.4
1 parent b32d433 commit 37c39e8

File tree

11 files changed

+399
-188
lines changed

11 files changed

+399
-188
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Before you get started, make sure you have the following prerequisites installed
4646
<thead><tr><th>Python:</th><td>3.11.6</td></tr></thead>
4747
<thead><tr><th>CUDA:</th><td>12.4</td></tr></thead>
4848
<thead><tr><th>TensorRT:</th><td>10.0.1</td></tr></thead>
49-
<thead><tr><th>Ultralytics:</th><td>8.2.42</td></tr></thead>
49+
<thead><tr><th>Ultralytics:</th><td>8.2.48</td></tr></thead>
5050
<thead><tr><th>GitHub AI Model:</th><td>0.4.1 (YOLOv8)</td></tr></thead>
5151
<thead><tr><th>Boosty AI Model:</th><td>0.5.7 (YOLOv10)</td></tr></thead>
5252
</table>
@@ -74,6 +74,7 @@ The behavior of the aimbot can be configured via the [`config.ini`](https://gith
7474
- hideout_targets `bool`: Allows shooting at targets on the range (for example in warface on the polygon or in aimlabs).
7575
- disable_headshot `bool`: Disable head targerting.
7676
- disable_prediction `bool`: Disable target position prediction.
77+
- third_person `bool`: Turn on the third-person game mode. (sunxds_0.5.7+)
7778

7879
### Hot keys:
7980
- The names of all the keys are [here](https://github.com/SunOner/sunone_aimbot/blob/main/logic/buttons.py). Type `None` is empty button.

config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ body_y_offset = 0.35
1616
hideout_targets = False
1717
disable_headshot = False
1818
disable_prediction = False
19+
third_person = False
1920

2021
[Hotkeys]
2122
hotkey_targeting = RightMouseButton

helper.py

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import subprocess
3+
import tempfile
34
import time
45
import re
56
import sys
@@ -32,7 +33,7 @@
3233

3334
def install_cuda():
3435
st.write("Cuda 12.4 is being downloaded, and installation will begin after downloading.")
35-
download_file("https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_551.61_windows.exe', './cuda_12.4.0_551.61_windows.exe")
36+
download_file("https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_551.61_windows.exe", "./cuda_12.4.0_551.61_windows.exe")
3637
subprocess.call(f'{os.path.join(os.path.dirname(os.path.abspath(__file__)), "cuda_12.4.0_551.61_windows.exe")}')
3738

3839
def delete_files_in_folder(folder):
@@ -128,7 +129,7 @@ def upgrade_ultralytics():
128129
if 'python_version' not in st.session_state:
129130
st.session_state.python_version = sys.version_info
130131

131-
HELPER, EXPORT, CONFIG = st.tabs(["HELPER", "EXPORT", "CONFIG"])
132+
HELPER, EXPORT, CONFIG, TRAIN = st.tabs(["HELPER", "EXPORT", "CONFIG", "TRAIN"])
132133

133134
with HELPER:
134135
st.title("Helper")
@@ -574,4 +575,103 @@ def save_config(config):
574575
config.set('Debug window', 'show_window', "False")
575576

576577
if st.button('Save Config'):
577-
save_config(config)
578+
save_config(config)
579+
580+
with TRAIN:
581+
st.title("Train model")
582+
resume = False
583+
584+
# model selection
585+
pretrained_models = ["yolov8n.pt", "yolov8s.pt", "yolov8m.pt", "yolov10n.pt", "yolov10s.pt", "yolov10m.pt"]
586+
587+
user_trained_models = st.toggle(label="Use user pretrained models", value=False)
588+
if user_trained_models:
589+
last_pt_files = []
590+
root_folder = r'runs\detect'
591+
592+
for root, dirs, files in os.walk(root_folder):
593+
for file in files:
594+
if file == 'last.pt':
595+
last_pt_files.append(os.path.join(root, file))
596+
597+
selected_model_path = st.selectbox(label="Select model", options=last_pt_files)
598+
resume = st.toggle(label="Resume training", value=False)
599+
else:
600+
selected_model_path = st.selectbox(label="Select model", options=pretrained_models)
601+
602+
if resume == False:
603+
604+
# data yaml
605+
data_yaml = st.text_input(label="Path to the dataset configuration file", value="logic/game.yaml")
606+
607+
# epochs
608+
epochs = st.number_input(label="Epochs", value=80, format="%u", min_value=10, step=10)
609+
610+
# image size
611+
img_size = st.number_input(label="Image size", value=640, format="%u", min_value=120, max_value=1280, step=10)
612+
613+
# device
614+
input_devices = ["cpu", "0", "1", "2", "3", "4", "5"]
615+
train_device = st.selectbox(label="Specifies the computational device for training",
616+
options=input_devices,
617+
index=1,
618+
help="cpu - Train on processor, 0-5 GPU ID for training.")
619+
if train_device != "cpu":
620+
train_device = int(train_device)
621+
622+
# cache
623+
use_cache = st.toggle(label="Enables caching of dataset images in memory",
624+
value=False)
625+
626+
# batch size
627+
batch_size_options = ["auto", "4", "8", "16", "32", "64", "128", "256"]
628+
batch_size = st.selectbox(label="Batch size",
629+
options=batch_size_options,
630+
index=0)
631+
if batch_size == "auto":
632+
batch_size = "-1"
633+
batch_size = int(batch_size)
634+
635+
augment = st.toggle(label="Use augmentation", value=True)
636+
637+
if augment: #TODO Add more settings
638+
augment_degrees = st.number_input(label="Degrees", format="%u", value=5, min_value=-180, max_value=180, step=5)
639+
augment_flipud = st.number_input(label="Flipud", format="%f", value=0.2, min_value=0.0, max_value=1.0, step=0.1)
640+
641+
# WANDB
642+
wandb = st.toggle(label="Force disable WANDB logger", value=True)
643+
if wandb:
644+
os.environ['WANDB_DISABLED'] = 'true'
645+
else:
646+
os.environ['WANDB_DISABLED'] = 'false'
647+
648+
# START TRAIN
649+
if st.button(label="Start"):
650+
with st.spinner("Train in process, check terminal window."):
651+
with tempfile.NamedTemporaryFile(delete=False, suffix=".py") as temp_script:
652+
# for multiprocessing "if __name__ == '__main__':" required
653+
temp_script.write(f"""
654+
if __name__ == '__main__':
655+
from ultralytics import YOLO
656+
yolo_model = YOLO('{selected_model_path}')
657+
yolo_model.train(
658+
data='{data_yaml}',
659+
epochs={epochs},
660+
imgsz={img_size},
661+
device={train_device},
662+
cache={use_cache},
663+
batch={batch_size},
664+
augment={augment},
665+
degrees={augment_degrees},
666+
flipud={augment_flipud},
667+
resume={resume}
668+
)
669+
""".encode('utf-8'))
670+
temp_script_path = temp_script.name
671+
672+
if os.name == 'nt':
673+
os.system(f'start cmd /k python {temp_script_path}')
674+
else:
675+
os.system(f'xterm -e python {temp_script_path}')
676+
677+
st.success("Training started in a new terminal window.")

logic/capture.py

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import cv2
22
import bettercam
33
from screeninfo import get_monitors
4+
import threading
5+
import queue
6+
import time
7+
48
from logic.config_watcher import cfg
59

6-
class Capture():
10+
class Capture(threading.Thread):
711
def __init__(self):
12+
super().__init__()
13+
self.daemon = True
14+
self.name = "Capture"
15+
816
self.Warnings()
917
self.print_startup_messages()
1018

@@ -19,43 +27,66 @@ def __init__(self):
1927
self.prev_detection_window_height = cfg.detection_window_height
2028
self.prev_bettercam_capture_fps = cfg.bettercam_capture_fps
2129

22-
if cfg.Bettercam_capture:
23-
self.bc = bettercam.create(device_idx=cfg.bettercam_monitor_id, output_idx=cfg.bettercam_gpu_id, output_color="BGR", max_buffer_len=64, region=self.Calculate_screen_offset())
24-
if self.bc.is_capturing == False:
25-
self.bc.start(region=self.Calculate_screen_offset(custom_region=[] if len(self._custom_region) <=0 else self._custom_region, x_offset=None if self._offset_x == None else self._offset_x, y_offset = None if self._offset_y == None else self._offset_y), target_fps=cfg.bettercam_capture_fps)
30+
self.frame_queue = queue.Queue(maxsize=5)
31+
self.running = True
2632

27-
if cfg.Obs_capture:
28-
if cfg.Obs_camera_id == 'auto':
29-
camera_id = self.find_obs_virtual_camera()
30-
if camera_id == -1:
31-
print('OBS Virtual Camera not found')
32-
exit(0)
33-
elif cfg.Obs_camera_id.isdigit:
34-
camera_id = int(cfg.Obs_camera_id)
35-
self.obs_camera = cv2.VideoCapture(camera_id)
36-
self.obs_camera.set(cv2.CAP_PROP_FRAME_WIDTH, cfg.detection_window_width)
37-
self.obs_camera.set(cv2.CAP_PROP_FRAME_HEIGHT, cfg.detection_window_height)
38-
self.obs_camera.set(cv2.CAP_PROP_FPS, cfg.Obs_capture_fps)
33+
if cfg.Bettercam_capture:
34+
self.setup_bettercam()
35+
elif cfg.Obs_capture:
36+
self.setup_obs()
37+
38+
def setup_bettercam(self):
39+
self.bc = bettercam.create(device_idx=cfg.bettercam_monitor_id, output_idx=cfg.bettercam_gpu_id, output_color="BGR", max_buffer_len=64, region=self.Calculate_screen_offset())
40+
if not self.bc.is_capturing:
41+
self.bc.start(region=self.Calculate_screen_offset(custom_region=[] if len(self._custom_region) <=0 else self._custom_region, x_offset=None if self._offset_x == None else self._offset_x, y_offset = None if self._offset_y == None else self._offset_y), target_fps=cfg.bettercam_capture_fps)
42+
43+
def setup_obs(self):
44+
if cfg.Obs_camera_id == 'auto':
45+
camera_id = self.find_obs_virtual_camera()
46+
if camera_id == -1:
47+
print('OBS Virtual Camera not found')
48+
exit(0)
49+
elif cfg.Obs_camera_id.isdigit:
50+
camera_id = int(cfg.Obs_camera_id)
51+
self.obs_camera = cv2.VideoCapture(camera_id)
52+
self.obs_camera.set(cv2.CAP_PROP_FRAME_WIDTH, cfg.detection_window_width)
53+
self.obs_camera.set(cv2.CAP_PROP_FRAME_HEIGHT, cfg.detection_window_height)
54+
self.obs_camera.set(cv2.CAP_PROP_FPS, cfg.Obs_capture_fps)
3955

40-
def get_new_frame(self):
56+
def run(self):
57+
while self.running:
58+
frame = self.capture_frame()
59+
if frame is not None:
60+
if self.frame_queue.full():
61+
self.frame_queue.get()
62+
self.frame_queue.put(frame)
63+
time.sleep(1 / cfg.bettercam_capture_fps)
64+
65+
def capture_frame(self):
4166
if cfg.Bettercam_capture:
4267
return self.bc.get_latest_frame()
43-
44-
if cfg.Obs_capture:
68+
elif cfg.Obs_capture:
4569
ret_val, img = self.obs_camera.read()
4670
if ret_val:
4771
return img
4872
else:
49-
print('OBS Virtual Camera not found')
50-
exit(0)
73+
print('Failed to capture frame from OBS Virtual Camera')
74+
return None
75+
76+
def get_new_frame(self):
77+
try:
78+
return self.frame_queue.get(timeout=1)
79+
except queue.Empty:
80+
print("No frame available")
81+
return None
5182

5283
def restart(self):
53-
if cfg.Bettercam_capture and self.prev_detection_window_height != cfg.detection_window_height or cfg.Bettercam_capture and self.prev_detection_window_width != cfg.detection_window_width or cfg.Bettercam_capture and self.prev_bettercam_capture_fps != cfg.bettercam_capture_fps:
84+
if cfg.Bettercam_capture and (self.prev_detection_window_height != cfg.detection_window_height or
85+
self.prev_detection_window_width != cfg.detection_window_width or
86+
self.prev_bettercam_capture_fps != cfg.bettercam_capture_fps):
5487
self.bc.stop()
5588
del self.bc
56-
57-
self.bc = bettercam.create(device_idx=cfg.bettercam_monitor_id, output_idx=cfg.bettercam_gpu_id, output_color="BGR", max_buffer_len=64)
58-
self.bc.start(self.Calculate_screen_offset(), target_fps=cfg.bettercam_capture_fps)
89+
self.setup_bettercam()
5990

6091
self.screen_x_center = cfg.detection_window_width / 2
6192
self.screen_y_center = cfg.detection_window_height / 2
@@ -152,7 +183,12 @@ def Warnings(self):
152183
print('WARNING: A small value of `AI_conf ` can lead to a large number of false positives.')
153184

154185
def Quit(self):
186+
self.running = False
155187
if cfg.Bettercam_capture and self.bc.is_capturing:
156188
self.bc.stop()
189+
if cfg.Obs_capture:
190+
self.obs_camera.release()
191+
self.join()
157192

158-
capture = Capture()
193+
capture = Capture()
194+
capture.start()

logic/config_watcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def Read(self, verbose=False, ):
3030
self.hideout_targets = self.config_Aim.getboolean('hideout_targets')
3131
self.disable_headshot = self.config_Aim.getboolean('disable_headshot')
3232
self.disable_prediction = self.config_Aim.getboolean('disable_prediction')
33+
self.third_person = self.config_Aim.getboolean('third_person')
3334
# Hotkeys
3435
self.config_Hotkeys_settings = self.config['Hotkeys']
3536
self.hotkey_targeting = str(self.config_Hotkeys_settings['hotkey_targeting'])

logic/frame_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from logic.capture import capture
66
from logic.visual import visuals
77
from logic.mouse import mouse
8+
from logic.shooting import shooting
89

910
class Target():
1011
def __init__(self, x, y, w, h, cls):
@@ -40,8 +41,7 @@ def parse(self, result):
4041
visuals.draw_predicted_position(target.x, target.y)
4142
else:
4243
if cfg.auto_shoot or cfg.triggerbot:
43-
mouse.shoot(False) # release shooting buttons
44-
pass
44+
shooting.shoot(False, False) # release shooting buttons
4545

4646
if cfg.show_window and cfg.show_detection_speed == True:
4747
visuals.draw_speed(frame.speed['preprocess'], frame.speed['inference'], frame.speed['postprocess'])

logic/ghub.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from ctypes import *
2+
from os import path
3+
4+
class GhubMouse:
5+
def __init__(self):
6+
self.basedir = path.dirname(path.abspath(__file__))
7+
self.dlldir = path.join(self.basedir, 'ghub_mouse.dll')
8+
self.gm = CDLL(self.dlldir)
9+
self.gmok = self.gm.mouse_open()
10+
11+
@staticmethod
12+
def _ghub_SendInput(*inputs):
13+
nInputs = len(inputs)
14+
LPINPUT = INPUT * nInputs
15+
pInputs = LPINPUT(*inputs)
16+
cbSize = c_int(sizeof(INPUT))
17+
return windll.user32.SendInput(nInputs, pInputs, cbSize)
18+
19+
@staticmethod
20+
def _ghub_Input(structure):
21+
return INPUT(0, _INPUTunion(mi=structure))
22+
23+
@staticmethod
24+
def _ghub_MouseInput(flags, x, y, data):
25+
return MOUSEINPUT(x, y, data, flags, 0, None)
26+
27+
@staticmethod
28+
def _ghub_Mouse(flags, x=0, y=0, data=0):
29+
return GhubMouse._ghub_Input(GhubMouse._ghub_MouseInput(flags, x, y, data))
30+
31+
def mouse_xy(self, x, y):
32+
if self.gmok:
33+
return self.gm.moveR(x, y)
34+
return self._ghub_SendInput(self._ghub_Mouse(0x0001, x, y))
35+
36+
def mouse_down(self, key=1):
37+
if self.gmok:
38+
return self.gm.press(key)
39+
if key == 1:
40+
return self._ghub_SendInput(self._ghub_Mouse(0x0002))
41+
elif key == 2:
42+
return self._ghub_SendInput(self._ghub_Mouse(0x0008))
43+
44+
def mouse_up(self, key=1):
45+
if self.gmok:
46+
return self.gm.release()
47+
if key == 1:
48+
return self._ghub_SendInput(self._ghub_Mouse(0x0004))
49+
elif key == 2:
50+
return self._ghub_SendInput(self._ghub_Mouse(0x0010))
51+
52+
def mouse_close(self):
53+
if self.gmok:
54+
return self.gm.mouse_close()
55+
56+
LONG = c_long
57+
DWORD = c_ulong
58+
ULONG_PTR = POINTER(DWORD)
59+
60+
class MOUSEINPUT(Structure):
61+
_fields_ = (('dx', LONG),
62+
('dy', LONG),
63+
('mouseData', DWORD),
64+
('dwFlags', DWORD),
65+
('time', DWORD),
66+
('dwExtraInfo', ULONG_PTR))
67+
68+
class _INPUTunion(Union):
69+
_fields_ = (('mi', MOUSEINPUT),)
70+
71+
class INPUT(Structure):
72+
_fields_ = (('type', DWORD),
73+
('union', _INPUTunion))
74+
75+
gHub = GhubMouse()

0 commit comments

Comments
 (0)