Kill d2r when botty cannot recover and shuts down (#511)
This commit is contained in:
@@ -14,7 +14,7 @@ from health_manager import HealthManager
|
||||
from logger import Logger
|
||||
from messages import Messenger
|
||||
from screen import Screen
|
||||
from utils.restart import restart_game
|
||||
from utils.restart import restart_game, kill_game
|
||||
from utils.misc import kill_thread, set_d2r_always_on_top, restore_d2r_window_visibility
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class GameController:
|
||||
Logger.error(msg)
|
||||
if self._config.general["custom_message_hook"]:
|
||||
messenger.send_message(msg)
|
||||
os._exit(1)
|
||||
self.safe_exit(1)
|
||||
else:
|
||||
do_restart = self.game_recovery.go_to_hero_selection()
|
||||
break
|
||||
@@ -101,7 +101,7 @@ class GameController:
|
||||
Logger.error("Could not recover from a max game length violation. Quitting botty.")
|
||||
if self._config.general["custom_message_hook"]:
|
||||
messenger.send_message("Got stuck and will now quit botty")
|
||||
os._exit(1)
|
||||
self.safe_exit(1)
|
||||
|
||||
def start(self):
|
||||
# Check if we user should update the d2r settings
|
||||
@@ -156,3 +156,7 @@ class GameController:
|
||||
def toggle_pause_bot(self):
|
||||
if self.bot:
|
||||
self.bot.toggle_pause()
|
||||
|
||||
def safe_exit(self, error_code=0):
|
||||
kill_game()
|
||||
os._exit(error_code)
|
||||
|
||||
@@ -15,13 +15,17 @@ def process_exists(process_name):
|
||||
# because Fail message could be translated
|
||||
return last_line.lower().startswith(process_name.lower())
|
||||
|
||||
def kill_game():
|
||||
while process_exists("D2R.exe"):
|
||||
os.system("taskkill /f /im D2R.exe")
|
||||
wait(1.0, 1.5)
|
||||
|
||||
def restart_game(d2_path = None):
|
||||
if not d2_path:
|
||||
path = "C:\Program Files (x86)\Diablo II Resurrected\D2R.exe"
|
||||
else:
|
||||
path = d2_path
|
||||
if process_exists("D2R.exe"):
|
||||
os.system("taskkill /f /im D2R.exe")
|
||||
kill_game()
|
||||
wait(1.0, 1.5)
|
||||
# This method should function similar to opening the exe via double-click
|
||||
os.startfile(path)
|
||||
|
||||
Reference in New Issue
Block a user