-
Notifications
You must be signed in to change notification settings - Fork 15
/
aimbot.py
173 lines (137 loc) · 4.62 KB
/
aimbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import warnings
warnings.filterwarnings("ignore")
import pyautogui
import pydirectinput
import keyboard as kb
import cv2
from sys import platform
from time import time, sleep
from threading import Thread, Lock
from gamecapture import GameCapture
from detection import Detection
from vision import Vision
from utilities import Utilities
class AimBot:
capture = None
detector = None
vision = None
is_running = False
is_active = False
is_single_thread = False
lock = None
state = None
frame = None
active_targets = None
action_history = None
mirror_ratio = 1
start_time = 0
def __init__(self, ist=True, mr=1):
self.lock = Lock()
self.active_targets = []
self.action_history = []
self.is_single_thread = ist
self.mirror_ratio = 1 / mr
self.capture = GameCapture()
self.detector = Detection()
self.vision = Vision()
def shoot(self, target):
try:
if (target[0] < self.capture.w - 20 and target[0] > 20) \
and (target[1] < self.capture.h - 20 and target[1] > 20):
gui.moveTo(target[0], target[1])
gui.click()
self.action_history.append((time() - self.start_time, target))
else:
raise Exception('Target out of screen bounds.')
except Exception as e:
gui.moveTo(self.capture.w/2, self.capture.h/2)
self.action_history.append((time() - self.start_time, ('OOB')))
def user_kill_signal(self):
if kb.is_pressed('-'):
self.toggle()
if kb.is_pressed('='):
self.stop()
return True
return False
def monitor_toggle_actions(self):
while self.is_running:
self.user_kill_signal()
def display(self, frame):
# TODO: write frames to video file if recording
cv2.imshow('MIRROR: ' + self.capture.windowname, cv2.resize(frame, (0,0), fx=self.mirror_ratio, fy=self.mirror_ratio))
if cv2.waitKey(1) & 0xFF == ord('='):
self.stop()
def run_single_thread(self):
while self.is_running:
try:
if self.user_kill_signal():
break
frame = self.capture.capture_frame()
if self.is_active:
predictions = self.detector.detect(frame)
target = self.vision.get_priority_target(predictions)
frame = self.vision.draw_bounding_boxes(frame, predictions)
frame = self.vision.draw_crosshair(frame, target)
if target is not None:
self.shoot(target)
self.display(frame)
except Exception as e:
print(e)
pass
#out.release()
cv2.destroyAllWindows()
with open('output/actions.txt', 'w') as f:
for action in self.action_history:
f.write(str(action))
def run(self):
while self.is_running:
# TODO: shoot active target
pass
def start(self):
if not self.is_running:
self.is_running = True
self.start_time = time()
#mt = Thread(target=self.monitor_toggle_actions)
#mt.start()
if self.is_single_thread:
t = Thread(target=self.run_single_thread)
t.start()
#self.run_single_thread()
else:
t = Thread(target=self.run)
t.start()
def stop(self):
self.lock.acquire()
self.is_running = False
self.is_active = False
self.lock.release()
def update(self, frame):
self.lock.acquire()
self.frame = frame
self.lock.release()
def toggle(self):
self.lock.acquire()
self.is_active = not self.is_active
self.lock.release()
def is_active(self):
active = 0
self.lock.acquire()
active = self.is_active
self.lock.release()
return active
def main():
aimbot = AimBot(mr=3, ist=True)
aimbot.start()
def usage():
print('\033[96m'+'======================= '+'\033[91m'+'U S A G E'+'\033[96m'+' =======================\n'+'\033[0m')
print('\033[92m'+"\t\tExit key: '=' \n\t\tToggle firing key: '-'"+'\033[0m')
print('\033[96m'+'\n=========================================================='+'\033[0m')
gui = None
if __name__ == '__main__':
if platform == "win32":
gui = pydirectinput
else:
gui = pyautogui
gui.PAUSE = 0
usage()
main()