From a43e16432c53a91c39408848f34d553f00a9400b Mon Sep 17 00:00:00 2001 From: Elijah Harmon Date: Sun, 26 Nov 2023 16:31:45 -0800 Subject: [PATCH] masking update --- config.py | 7 ++++--- gameSelection.py | 20 ++++++-------------- main.py | 7 +++++-- main_onnx.py | 7 +++++-- main_tensorrt.py | 8 ++++++-- 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/config.py b/config.py index 0f1f1a3..7b6543a 100644 --- a/config.py +++ b/config.py @@ -3,11 +3,12 @@ screenShotHeight = 320 screenShotWidth = 320 # For use in games that are 3rd person and character model interferes with the autoaim -# EXAMPLE: Fortnite and New World -aaRightShift = 0 +useMask = False +maskWidth = 80 +maskHeight = 200 # Autoaim mouse movement amplifier -aaMovementAmp = .4 +aaMovementAmp = .1 # Person Class Confidence confidence = 0.4 diff --git a/gameSelection.py b/gameSelection.py index 39ac920..bc95062 100644 --- a/gameSelection.py +++ b/gameSelection.py @@ -5,7 +5,7 @@ import bettercam # Could be do with # from config import * # But we are writing it out for clarity for new devs -from config import aaRightShift, screenShotHeight, screenShotWidth +from config import screenShotHeight, screenShotWidth def gameSelection() -> (bettercam.BetterCam, int, int | None): # Selecting the correct game window @@ -55,18 +55,8 @@ def gameSelection() -> (bettercam.BetterCam, int, int | None): return None print("Successfully activated the game window...") - # Setting up the screen shots - sctArea: dict[str, int] = {"mon": 1, "top": videoGameWindow.top + (videoGameWindow.height - screenShotHeight) // 2, - "left": aaRightShift + ((videoGameWindow.left + videoGameWindow.right) // 2) - (screenShotWidth // 2), - "width": screenShotWidth, - "height": screenShotHeight} - - #! Uncomment if you want to view the entire screen - # sctArea = {"mon": 1, "top": 0, "left": 0, "width": 1920, "height": 1080} - # Starting screenshoting engine - left = aaRightShift + \ - ((videoGameWindow.left + videoGameWindow.right) // 2) - (screenShotWidth // 2) + left = ((videoGameWindow.left + videoGameWindow.right) // 2) - (screenShotWidth // 2) top = videoGameWindow.top + \ (videoGameWindow.height - screenShotHeight) // 2 right, bottom = left + screenShotWidth, top + screenShotHeight @@ -74,8 +64,10 @@ def gameSelection() -> (bettercam.BetterCam, int, int | None): region: tuple = (left, top, right, bottom) # Calculating the center Autoaim box - cWidth: int = sctArea["width"] / 2 - cHeight: int = sctArea["height"] / 2 + 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: diff --git a/main.py b/main.py index 43fe21c..10d414c 100644 --- a/main.py +++ b/main.py @@ -11,7 +11,7 @@ from utils.general import (cv2, non_max_suppression, xyxy2xywh) # Could be do with # from config import * # But we are writing it out for clarity for new devs -from config import aaMovementAmp, aaRightShift, aaQuitKey, screenShotHeight, confidence, headshot_mode, cpsDisplay, visuals, centerOfScreen +from config import aaMovementAmp, useMask, maskWidth, maskHeight, aaQuitKey, screenShotHeight, confidence, headshot_mode, cpsDisplay, visuals, centerOfScreen import gameSelection def main(): @@ -41,6 +41,9 @@ def main(): # Getting Frame npImg = np.array(camera.get_latest_frame()) + if useMask: + npImg[-maskHeight:, :maskWidth, :] = 0 + # Normalizing Data im = torch.from_numpy(npImg) if im.shape[2] == 4: @@ -99,7 +102,7 @@ def main(): targets.sort_values(by="dist", ascending=False) # Take the first person that shows up in the dataframe (Recall that we sort based on Euclidean distance) - xMid = targets.iloc[0].current_mid_x + aaRightShift + xMid = targets.iloc[0].current_mid_x yMid = targets.iloc[0].current_mid_y box_height = targets.iloc[0].height diff --git a/main_onnx.py b/main_onnx.py index 61106bb..e53d701 100644 --- a/main_onnx.py +++ b/main_onnx.py @@ -13,7 +13,7 @@ import torch # Could be do with # from config import * # But we are writing it out for clarity for new devs -from config import aaMovementAmp, aaRightShift, aaQuitKey, confidence, headshot_mode, cpsDisplay, visuals, onnxChoice, centerOfScreen +from config import aaMovementAmp, useMask, maskHeight, maskWidth, aaQuitKey, confidence, headshot_mode, cpsDisplay, visuals, onnxChoice, centerOfScreen import gameSelection def main(): @@ -49,6 +49,9 @@ def main(): # Getting Frame npImg = np.array(camera.get_latest_frame()) + if useMask: + npImg[-maskHeight:, :maskWidth, :] = 0 + # If Nvidia, do this if onnxChoice == 3: # Normalizing Data @@ -122,7 +125,7 @@ def main(): targets.sort_values(by="dist", ascending=False) # Take the first person that shows up in the dataframe (Recall that we sort based on Euclidean distance) - xMid = targets.iloc[0].current_mid_x + aaRightShift + xMid = targets.iloc[0].current_mid_x yMid = targets.iloc[0].current_mid_y box_height = targets.iloc[0].height diff --git a/main_tensorrt.py b/main_tensorrt.py index 7f1c207..4edbd20 100644 --- a/main_tensorrt.py +++ b/main_tensorrt.py @@ -13,7 +13,7 @@ import cupy as cp # Could be do with # from config import * # But we are writing it out for clarity for new devs -from config import aaMovementAmp, aaRightShift, aaQuitKey, confidence, headshot_mode, cpsDisplay, visuals, centerOfScreen +from config import aaMovementAmp, useMask, maskHeight, maskWidth, aaQuitKey, confidence, headshot_mode, cpsDisplay, visuals, centerOfScreen import gameSelection def main(): @@ -41,6 +41,10 @@ def main(): if npImg.shape[3] == 4: # If the image has an alpha channel, remove it npImg = npImg[:, :, :, :3] + + if useMask: + npImg[:, -maskHeight:, :maskWidth, :] = 0 + im = npImg / 255 im = im.astype(cp.half) @@ -90,7 +94,7 @@ def main(): targets.sort_values(by="dist", ascending=False) # Take the first person that shows up in the dataframe (Recall that we sort based on Euclidean distance) - xMid = targets.iloc[0].current_mid_x + aaRightShift + xMid = targets.iloc[0].current_mid_x yMid = targets.iloc[0].current_mid_y box_height = targets.iloc[0].height