|
|
@@ -109,6 +109,7 @@ namespace TBMM |
|
|
|
|
|
|
|
private void HandleGameExit(object sender, EventArgs e) |
|
|
|
{ |
|
|
|
Debug.WriteLine("Handling game exit"); |
|
|
|
_gameProcess = (null, false); |
|
|
|
if (InvokeMethod(CheckIfPatched) != GameState.Patched || Configuration.KeepPatched) |
|
|
|
return; |
|
|
@@ -128,27 +129,37 @@ namespace TBMM |
|
|
|
|
|
|
|
private bool CheckIfGameIsRunning() |
|
|
|
{ |
|
|
|
Debug.WriteLine($"Check if game is running: {_gameProcess}"); |
|
|
|
switch (_gameProcess.Process) |
|
|
|
{ |
|
|
|
case { HasExited: false }: |
|
|
|
Debug.WriteLine("Game has not exited"); |
|
|
|
return true; |
|
|
|
case { HasExited: true }: |
|
|
|
Debug.WriteLine("Game has exited, dialog shown"); |
|
|
|
MessageBox.Show("Game has exited without handling... Please report."); |
|
|
|
HandleGameExit(null, EventArgs.Empty); |
|
|
|
return false; |
|
|
|
default: |
|
|
|
Debug.WriteLine($"Process seems to be null: {_gameProcess}"); |
|
|
|
if (_gameProcess.Process?.HasExited ?? true) |
|
|
|
{ |
|
|
|
_gameProcess = (Process.GetProcessesByName(GetExe(withExtension: false)).FirstOrDefault(), false); |
|
|
|
Debug.WriteLine($"Game process exited already, got new process object: {_gameProcess}"); |
|
|
|
} |
|
|
|
|
|
|
|
if (_gameProcess.Process == null) return false; |
|
|
|
if (_gameProcess.Process.HasExited) |
|
|
|
{ |
|
|
|
Debug.WriteLine($"Game has exited already: {_gameProcess}"); |
|
|
|
HandleGameExit(null, EventArgs.Empty); |
|
|
|
return false; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Debug.WriteLine($"Game is still running"); |
|
|
|
if (_gameProcess.ExitHandlerAdded) return true; |
|
|
|
Debug.WriteLine("Game running and no exit handler yet, adding it"); |
|
|
|
_gameProcess.Process.Exited += HandleGameExit; |
|
|
|
_gameProcess.Process.EnableRaisingEvents = true; |
|
|
|
_gameProcess.ExitHandlerAdded = true; |
|
|
|