diff --git a/UXAssist/Common/WinApi.cs b/UXAssist/Common/WinApi.cs index 5cc4150..e2543c5 100644 --- a/UXAssist/Common/WinApi.cs +++ b/UXAssist/Common/WinApi.cs @@ -136,6 +136,9 @@ public static class WinApi [DllImport("kernel32", ExactSpelling = true)] public static extern int GetCurrentProcessId(); + + [DllImport("kernel32", ExactSpelling = true)] + public static extern IntPtr GetConsoleWindow(); [DllImport("kernel32", ExactSpelling = true, SetLastError = true)] public static extern bool SetProcessAffinityMask(IntPtr hProcess, ulong dwProcessAffinityMask); diff --git a/UXAssist/Functions/WindowFunctions.cs b/UXAssist/Functions/WindowFunctions.cs index 47da706..1e120f6 100644 --- a/UXAssist/Functions/WindowFunctions.cs +++ b/UXAssist/Functions/WindowFunctions.cs @@ -240,13 +240,17 @@ public static class WindowFunctions if (_gameWindowHandle != IntPtr.Zero) return _gameWindowHandle; var wnd = IntPtr.Zero; + var consoleWnd = WinApi.GetConsoleWindow(); + var currentProcessId = WinApi.GetCurrentProcessId(); while (true) { wnd = WinApi.FindWindowEx(IntPtr.Zero, wnd, GameWindowClass, _gameWindowTitle); if (wnd == IntPtr.Zero) return IntPtr.Zero; + if (wnd == consoleWnd) + continue; WinApi.GetWindowThreadProcessId(wnd, out var pid); - if (pid == WinApi.GetCurrentProcessId()) + if (pid == currentProcessId) break; } _gameWindowHandle = wnd;