From de6bc9127a0dd007a837a18c6a1035775ea534a7 Mon Sep 17 00:00:00 2001 From: Julian Xhokaxhiu Date: Thu, 12 Dec 2024 23:28:18 +0100 Subject: [PATCH] AppUI: Fix launching Chocobo World on FF8 2000 --- AppUI/Classes/GameLauncher.cs | 43 +++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/AppUI/Classes/GameLauncher.cs b/AppUI/Classes/GameLauncher.cs index 21e6e9b..fd984dd 100644 --- a/AppUI/Classes/GameLauncher.cs +++ b/AppUI/Classes/GameLauncher.cs @@ -867,7 +867,11 @@ internal static async Task LaunchChocoboExe() Process.Start(startInfo); // Wait for game process - await waitForProcess(Path.GetFileNameWithoutExtension(chocoboExe)); + Process game = await waitForProcess(Path.GetFileNameWithoutExtension(chocoboExe)); + if (game != null) + { + ff8Proc = game; + } // Delete signal file File.Delete(ticket); @@ -882,9 +886,29 @@ internal static async Task LaunchChocoboExe() WorkingDirectory = Path.GetDirectoryName(chocoboExe), UseShellExecute = true, }; - Process.Start(startInfo); + ff8Proc = Process.Start(startInfo); } + ff8Proc.EnableRaisingEvents = true; + ff8Proc.Exited += (o, e) => + { + try + { + if (!IsChocoboRunning() && Instance._controllerInterceptor != null) + { + // stop polling for input once all ff8 procs are closed (could be multiple instances open) + Instance._controllerInterceptor.PollingInput = false; + } + + // cleanup + DeleteJ8WrapperDlls(); + } + catch (Exception ex) + { + Logger.Error(ex); + } + }; + return true; } catch (Exception ex) @@ -1334,6 +1358,21 @@ public static bool IsFF8Running() return ret; } + public static bool IsChocoboRunning() + { + bool ret = false; + + string fileName = Sys.Settings.FF8InstalledVersion == FF8Version.Steam ? "chocobo_en" : "chocobo"; + ret = Process.GetProcessesByName(fileName).Length > 0; + + if (!ret && Sys.Settings.FF8InstalledVersion == FF8Version.Steam) + { + ret = Process.GetProcessesByName("FF8_Launcher").Length > 0; + } + + return ret; + } + private static bool ForceKillFF8() { string fileName = Path.GetFileNameWithoutExtension(Sys.Settings.FF8Exe);