feat: restart bot process instead of killing D2R when stuck

When restart_d2r_when_stuck is enabled, spawn a fresh Python process
(same main.py) and exit immediately rather than killing and relaunching
D2R. The new bot detects D2R is already running and skips launching it,
preserving the game session. D2R is only killed on deliberate exits
(safe_exit) and the initial auto_login launch.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
alex
2026-06-07 16:13:18 +02:00
co-authored by Claude Sonnet 4.6
parent 5254b7ee75
commit fda747a1bf
2 changed files with 15 additions and 19 deletions
+6 -4
View File
@@ -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()
+9 -15
View File
@@ -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: