-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathgameSelection.py
79 lines (70 loc) · 3.07 KB
/
gameSelection.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
import pygetwindow
import time
import bettercam
from typing import Union
# Could be do with
# from config import *
# But we are writing it out for clarity for new devs
from config import screenShotHeight, screenShotWidth
def gameSelection() -> (bettercam.BetterCam, int, Union[int, None]):
# Selecting the correct game window
try:
videoGameWindows = pygetwindow.getAllWindows()
print("=== All Windows ===")
for index, window in enumerate(videoGameWindows):
# only output the window if it has a meaningful title
if window.title != "":
print("[{}]: {}".format(index, window.title))
# have the user select the window they want
try:
userInput = int(input(
"Please enter the number corresponding to the window you'd like to select: "))
except ValueError:
print("You didn't enter a valid number. Please try again.")
return
# "save" that window as the chosen window for the rest of the script
videoGameWindow = videoGameWindows[userInput]
except Exception as e:
print("Failed to select game window: {}".format(e))
return None
# Activate that Window
activationRetries = 30
activationSuccess = False
while (activationRetries > 0):
try:
videoGameWindow.activate()
activationSuccess = True
break
except pygetwindow.PyGetWindowException as we:
print("Failed to activate game window: {}".format(str(we)))
print("Trying again... (you should switch to the game now)")
except Exception as e:
print("Failed to activate game window: {}".format(str(e)))
print("Read the relevant restrictions here: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setforegroundwindow")
activationSuccess = False
activationRetries = 0
break
# wait a little bit before the next try
time.sleep(3.0)
activationRetries = activationRetries - 1
# if we failed to activate the window then we'll be unable to send input to it
# so just exit the script now
if activationSuccess == False:
return None
print("Successfully activated the game window...")
# Starting screenshoting engine
left = ((videoGameWindow.left + videoGameWindow.right) // 2) - (screenShotWidth // 2)
top = videoGameWindow.top + \
(videoGameWindow.height - screenShotHeight) // 2
right, bottom = left + screenShotWidth, top + screenShotHeight
region: tuple = (left, top, right, bottom)
# Calculating the center Autoaim box
cWidth: int = screenShotWidth // 2
cHeight: int = screenShotHeight // 2
print(region)
camera = bettercam.create(region=region, output_color="BGRA", max_buffer_len=512)
if camera is None:
print("Your Camera Failed! Ask @Wonder for help in our Discord in the #ai-aimbot channel ONLY: https://discord.gg/rootkitorg")
return
camera.start(target_fps=120, video_mode=True)
return camera, cWidth, cHeight