From a9da3093f7695fda2b4cbac8d4c77d062e46fdf0 Mon Sep 17 00:00:00 2001 From: j-lin-lmg <167900848+j-lin-lmg@users.noreply.github.com> Date: Fri, 3 Oct 2025 10:24:59 -0700 Subject: [PATCH] user failsafe false (#168) user failsafe false for all games that use pydirectinput --- alanwake2/alanwake2.py | 5 ++- counterstrike2/cs2.py | 40 ++++++++++++----- cyberpunk2077/cyberpunk2077.py | 2 + doomdarkages/doomdarkages.py | 2 + dota2/dota2.py | 1 + farcry6/farcry6.py | 43 ++++++++++++------- forza5/forza5.py | 1 + grid_legends/grid_legends.py | 2 + harness_utils/misc.py | 1 + marvelrivals/marvelrivals.py | 2 + reddeadredemption2/reddeadredemption2.py | 1 + .../shadowofthetombraider.py | 1 + tinytinaswonderland/tinytinaswonderland.py | 2 + 13 files changed, 75 insertions(+), 28 deletions(-) diff --git a/alanwake2/alanwake2.py b/alanwake2/alanwake2.py index fbfbeae..303f196 100644 --- a/alanwake2/alanwake2.py +++ b/alanwake2/alanwake2.py @@ -24,8 +24,9 @@ LOG_DIRECTORY = SCRIPT_DIRECTORY.joinpath("run") PROCESS_NAME = "alanwake2.exe" EXECUTABLE_PATH = find_epic_executable() GAME_ID = "c4763f236d08423eb47b4c3008779c84%3A93f2a8c3547846eda966cb3c152a026e%3Adc9d2e595d0e4650b35d659f90d41059?action=launch&silent=true" -gamefoldername = "AlanWake2" +GAMEFOLDERNAME = "AlanWake2" +user.FAILSAFE = False def setup_logging(): """default logging config""" @@ -169,7 +170,7 @@ try: "resolution": f"{width}x{height}", "start_time": round((start_time * 1000)), "end_time": round((end_time * 1000)), - "game_version": find_eg_game_version(gamefoldername) + "game_version": find_eg_game_version(GAMEFOLDERNAME) } am.create_manifest() diff --git a/counterstrike2/cs2.py b/counterstrike2/cs2.py index e28f02e..e9f63c7 100644 --- a/counterstrike2/cs2.py +++ b/counterstrike2/cs2.py @@ -29,7 +29,14 @@ PROCESS_NAME = "cs2.exe" STEAM_GAME_ID = 730 STEAM_USER_ID = get_registry_active_user() -cfg = Path(get_steam_folder_path(), "userdata", str(STEAM_USER_ID), str(STEAM_GAME_ID), "local", "cfg", "cs2_video.txt") +cfg = Path( + get_steam_folder_path(), + "userdata", str(STEAM_USER_ID), + str(STEAM_GAME_ID), + "local", "cfg", "cs2_video.txt") + +user.FAILSAFE = False + def setup_logging(): """default logging config""" @@ -74,17 +81,24 @@ def run_benchmark(keras_service): # We check the resolution so we know which screenshot to use for the locate on screen function match width: case "1920": - location = gui.locateOnScreen(f"{SCRIPT_DIR}\\screenshots\\settings_1080.png", minSearchTime=5, confidence=0.6) + location = gui.locateOnScreen( + f"{SCRIPT_DIR}\\screenshots\\settings_1080.png", minSearchTime=5, confidence=0.6) case "2560": - location = gui.locateOnScreen(f"{SCRIPT_DIR}\\screenshots\\settings_1440.png", minSearchTime=5, confidence=0.6) + location = gui.locateOnScreen( + f"{SCRIPT_DIR}\\screenshots\\settings_1440.png", minSearchTime=5, confidence=0.6) case "3840": - location = gui.locateOnScreen(f"{SCRIPT_DIR}\\screenshots\\settings_2160.png", minSearchTime=5, confidence=0.6) + location = gui.locateOnScreen( + f"{SCRIPT_DIR}\\screenshots\\settings_2160.png", minSearchTime=5, confidence=0.6) case _: - logging.error("Could not find the settings cog. The game resolution is currently %s, %s. Are you using a standard resolution?", height, width) + logging.error( + "Could not find the settings cog. The game resolution is currently %s, %s. Are you using a standard resolution?", + height, width) raise RuntimeError if location is None: - logging.error("Could not find the settings cog. The game resolution is currently %s, %s. Are you using a standard resolution?", height, width) + logging.error( + "Could not find the settings cog. The game resolution is currently %s, %s. Are you using a standard resolution?", + height, width) raise RuntimeError click_me = gui.center(location) @@ -122,11 +136,13 @@ def run_benchmark(keras_service): gui.mouseUp() time.sleep(0.2) - am.take_screenshot("advanced_video_1.png", ArtifactType.CONFIG_IMAGE, "first picture of advanced video settings") + am.take_screenshot("advanced_video_1.png", ArtifactType.CONFIG_IMAGE, + "first picture of advanced video settings") result = keras_service.look_for_word(word="boost", attempts=10, interval=1) if not result: - logging.info("Did not find the keyword 'Boost' in the advanced video menu. Did Keras click correctly?") + logging.info( + "Did not find the keyword 'Boost' in the advanced video menu. Did Keras click correctly?") raise RuntimeError gui.moveTo(result["x"], result["y"]) @@ -135,9 +151,11 @@ def run_benchmark(keras_service): time.sleep(1) if keras_service.wait_for_word(word="particle", timeout=30, interval=1) is None: - logging.info("Did not find the keyword 'Particle' in advanced video menu. Did Keras scroll correctly?") + logging.info( + "Did not find the keyword 'Particle' in advanced video menu. Did Keras scroll correctly?") raise RuntimeError - am.take_screenshot("advanced_video_2.png", ArtifactType.CONFIG_IMAGE, "second picture of advanced video settings") + am.take_screenshot("advanced_video_2.png", ArtifactType.CONFIG_IMAGE, + "second picture of advanced video settings") logging.info('Starting benchmark') user.press("`") @@ -170,7 +188,7 @@ def run_benchmark(keras_service): test_start_time = int(time.time()) logging.info("Saw \'lets roll\'! Marking the time.") - time.sleep(112) # sleep duration during gameplay + time.sleep(112) # sleep duration during gameplay # Default fallback end time test_end_time = int(time.time()) diff --git a/cyberpunk2077/cyberpunk2077.py b/cyberpunk2077/cyberpunk2077.py index 135d23e..87369a6 100644 --- a/cyberpunk2077/cyberpunk2077.py +++ b/cyberpunk2077/cyberpunk2077.py @@ -27,6 +27,8 @@ LOG_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "run") PROCESS_NAME = "cyberpunk2077.exe" +user.FAILSAFE = False + def start_game(): """Launch the game with no launcher or start screen""" return exec_steam_game(STEAM_GAME_ID, game_params=["--launcher-skip", "-skipStartScreen"]) diff --git a/doomdarkages/doomdarkages.py b/doomdarkages/doomdarkages.py index fcb4276..54da02b 100644 --- a/doomdarkages/doomdarkages.py +++ b/doomdarkages/doomdarkages.py @@ -34,6 +34,8 @@ STEAM_GAME_ID = 3017860 username = os.getlogin() BENCHMARK_RESULTS_PATH = f"C:\\Users\\{username}\\Saved Games\\id Software\\DOOMTheDarkAges\\base\\benchmark" +user.FAILSAFE = False + def start_game(): """Launch the game with no launcher or start screen""" copy_launcher_config() diff --git a/dota2/dota2.py b/dota2/dota2.py index 2ff14d8..ec6ed78 100644 --- a/dota2/dota2.py +++ b/dota2/dota2.py @@ -40,6 +40,7 @@ logging.getLogger('').addHandler(console) args = get_args() kerasService = KerasService(args.keras_host, args.keras_port) +user.FAILSAFE = False def start_game(): """Launch the game with console enabled and FPS unlocked""" diff --git a/farcry6/farcry6.py b/farcry6/farcry6.py index c128e13..61dd49b 100644 --- a/farcry6/farcry6.py +++ b/farcry6/farcry6.py @@ -1,4 +1,6 @@ """Far Cry 6 test script""" + +# pylint: disable = C0116, W0621 import os import logging import time @@ -30,25 +32,31 @@ LOG_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "run") PROCESS_NAME = "FarCry6.exe" GAME_ID = 5266 username = os.getlogin() -xml_file = rf"C:\Users\{username}\Documents\My Games\Far Cry 6\gamerprofile.xml" +XML_FILE = rf"C:\Users\{username}\Documents\My Games\Far Cry 6\gamerprofile.xml" + + +user.FAILSAFE = False + def start_game(): - subprocess.run(f'start uplay://launch/{GAME_ID}/0', shell=True) + subprocess.run(f'start uplay://launch/{GAME_ID}/0', shell=True, check=True) + def skip_logo_screens() -> None: """Simulate input to skip logo screens""" logging.info("Skipping logo screens") - #skipping the logo screens + # skipping the logo screens press_n_times("escape", 8, 1) + def run_benchmark(): am = ArtifactManager(LOG_DIRECTORY) start_game() setup_start_time = int(time.time()) time.sleep(25) - #skipping game intros + # skipping game intros result = kerasService.look_for_word("warning", attempts=20, interval=1) if not result: logging.info("Did not see warnings. Did the game start?") @@ -66,7 +74,7 @@ def run_benchmark(): time.sleep(2) - #navigating the menus to get to the video settings + # navigating the menus to get to the video settings result = kerasService.look_for_word("later", attempts=5, interval=1) if result: user.press("escape") @@ -95,10 +103,11 @@ def run_benchmark(): gui.mouseUp() time.sleep(2) - #grabbing screenshots of all the video settings + # grabbing screenshots of all the video settings result = kerasService.look_for_word("adapter", attempts=10, interval=1) if not result: - logging.info("Did not find the Video Adapter setting in the monitor options. Did keras navigate wrong?") + logging.info( + "Did not find the Video Adapter setting in the monitor options. Did keras navigate wrong?") sys.exit(1) am.take_screenshot("video.png", ArtifactType.CONFIG_IMAGE, "picture of video settings") @@ -109,18 +118,20 @@ def run_benchmark(): result = kerasService.look_for_word("filtering", attempts=10, interval=1) if not result: - logging.info("Did not find the Texture Filtering setting in the quality options. Did keras navigate wrong?") + logging.info( + "Did not find the Texture Filtering setting in the quality options. Did keras navigate wrong?") sys.exit(1) am.take_screenshot("quality1.png", ArtifactType.CONFIG_IMAGE, "1st picture of quality settings") time.sleep(2) - mouse_scroll_n_times(8, -800, 0.2) + mouse_scroll_n_times(8, -800, 0.2) result = kerasService.look_for_word("shading", attempts=10, interval=1) if not result: - logging.info("Did not find the FidelityFX Variable Shading setting in the quality options. Did keras navigate wrong?") + logging.info( + "Did not find the FidelityFX Variable Shading setting in the quality options. Did keras navigate wrong?") sys.exit(1) am.take_screenshot("quality2.png", ArtifactType.CONFIG_IMAGE, "2nd picture of quality settings") @@ -131,12 +142,13 @@ def run_benchmark(): result = kerasService.look_for_word("lock", attempts=10, interval=1) if not result: - logging.info("Did not find the Enable Framerate Lock setting in the advanced options. Did keras navigate wrong?") + logging.info( + "Did not find the Enable Framerate Lock setting in the advanced options. Did keras navigate wrong?") sys.exit(1) am.take_screenshot("advanced.png", ArtifactType.CONFIG_IMAGE, "picture of advanced settings") - #starting the benchmark + # starting the benchmark time.sleep(2) user.press("f5") elapsed_setup_time = round(int(time.time()) - setup_start_time, 2) @@ -148,7 +160,7 @@ def run_benchmark(): sys.exit(1) test_start_time = int(time.time()) - time.sleep(60) # wait for benchmark to complete + time.sleep(60) # wait for benchmark to complete result = kerasService.wait_for_word("results", interval=0.5, timeout=100) if not result: @@ -165,11 +177,12 @@ def run_benchmark(): # Exit terminate_processes(PROCESS_NAME) - am.copy_file(xml_file, ArtifactType.CONFIG_TEXT, "config file") + am.copy_file(XML_FILE, ArtifactType.CONFIG_TEXT, "config file") am.create_manifest() return test_start_time, test_end_time + setup_log_directory(LOG_DIRECTORY) logging.basicConfig(filename=f'{LOG_DIRECTORY}/harness.log', @@ -204,4 +217,4 @@ except Exception as e: logging.error("Something went wrong running the benchmark!") logging.exception(e) terminate_processes(PROCESS_NAME) - sys.exit(1) \ No newline at end of file + sys.exit(1) diff --git a/forza5/forza5.py b/forza5/forza5.py index 3d8943f..cb62db7 100644 --- a/forza5/forza5.py +++ b/forza5/forza5.py @@ -34,6 +34,7 @@ CONFIG_LOCATION = ( CONFIG_FILENAME = "UserConfigSelections" PROCESSES = ["ForzaHorizon5.exe", "RTSS.exe"] +user.FAILSAFE = False def start_rtss(): """Sets up the RTSS process""" diff --git a/grid_legends/grid_legends.py b/grid_legends/grid_legends.py index c8d4b73..558cf7b 100644 --- a/grid_legends/grid_legends.py +++ b/grid_legends/grid_legends.py @@ -33,6 +33,8 @@ CONFIG_PATH = f"C:\\Users\\{username}\\Documents\\My Games\\GRID Legends\\hardwa CONFIG_FILENAME = "hardware_settings_config.xml" CONFIG_FULL_PATH = f"{CONFIG_PATH}\\{CONFIG_FILENAME}" +user.FAILSAFE = False + def get_resolution() -> tuple[int]: """Gets resolution width and height from local xml file created by game.""" resolution = re.compile(r"