diff --git a/src/bot.py b/src/bot.py index 193962f..782e27b 100644 --- a/src/bot.py +++ b/src/bot.py @@ -3,6 +3,7 @@ import time from input_layer import keyboard import time import os +import sys import random import cv2 import math @@ -14,7 +15,7 @@ from health_manager import set_pause_state from transmute import Transmute from utils.misc import wait, hms from utils.log_rotation import safe_imwrite -from utils.restart import safe_exit, restart_game +from utils.restart import safe_exit from game_stats import GameStats from logger import Logger from config import Config @@ -239,9 +240,10 @@ class Bot: if not self._game_stats.get_failure_reason(): self._game_stats.set_failure_reason(message) if Config().general["restart_d2r_when_stuck"]: - Logger.info("Restart botty") - restart_game(Config().general["d2r_path"], Config().advanced_options["launch_options"]) - self.stop() + Logger.info("Restarting bot — game kept running") + import subprocess + subprocess.Popen([sys.executable, os.path.abspath(sys.argv[0])]) + os._exit(0) else: Logger.info("Shut down botty") safe_exit() diff --git a/src/game_controller.py b/src/game_controller.py index 4ffb4d2..15fdcd5 100644 --- a/src/game_controller.py +++ b/src/game_controller.py @@ -14,7 +14,7 @@ from health_manager import HealthManager from logger import Logger from messages import Messenger from screen import grab, get_offset_state -from utils.restart import restart_game, safe_exit +from utils.restart import safe_exit from utils.misc import cooperative_shutdown, set_d2r_always_on_top, restore_d2r_window_visibility, wait @@ -114,21 +114,15 @@ class GameController: if Config().general["info_screenshots"]: safe_imwrite("./log/screenshots/info/info_could_not_recover_" + time.strftime("%Y%m%d_%H%M%S") + ".png", grab()) if Config().general['restart_d2r_when_stuck']: - Logger.error("Could not recover from a max game length violation. Restarting the Game.") + Logger.error("Could not recover. Restarting the bot — game kept running.") if messenger.enabled: - messenger.send_message("Got stuck and will now restart D2R") - if restart_game(Config().general["d2r_path"], Config().advanced_options["launch_options"]): - if max_game_length_reached and not self.game_stats.get_failure_reason(): - self.game_stats.set_failure_reason("Max game length reached (stuck)") - self.game_stats.log_end_game(failed=max_game_length_reached) - if self.setup_screen(): - self.start_health_manager_thread() - self.start_death_manager_thread() - self.game_recovery = GameRecovery(self.death_manager) - return self.run_bot() - Logger.error("Could not restart the game. Quitting.") - if messenger.enabled: - messenger.send_message("Got stuck and could not restart the game. Quitting.") + messenger.send_message("Got stuck, restarting bot (game kept running)") + if max_game_length_reached and not self.game_stats.get_failure_reason(): + self.game_stats.set_failure_reason("Max game length reached (stuck)") + self.game_stats.log_end_game(failed=max_game_length_reached) + import subprocess, sys, os as _os + subprocess.Popen([sys.executable, _os.path.abspath(sys.argv[0])]) + _os._exit(0) else: Logger.error("Could not recover from a max game length violation. Quitting botty.") if messenger.enabled: