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