Skip to content

Commit ea25a25

Browse files
committed
fix(Fornite): Fix SoundSwitch compatibility with Fornite
And surely other games with anti-cheats. Fixes #1588 Fixes #1553
1 parent 01625c3 commit ea25a25

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

SoundSwitch.Audio.Manager/WindowMonitor.cs

+14-5
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,18 @@ public WindowMonitor()
8282
Log.Information("Foreground = SoundSwitch, don't save.");
8383
return;
8484
}
85+
8586
var process = Process.GetProcessById((int)processId);
86-
var processName = process.MainModule?.FileName ?? "N/A";
87+
var processName = "N/A";
88+
try
89+
{
90+
processName = process.MainModule?.FileName ?? "N/A";
91+
}
92+
catch (Exception)
93+
{
94+
// ignored
95+
}
96+
8797
ForegroundChanged?.Invoke(this, new Event(processId, processName, windowText, windowClass, hwnd));
8898
}
8999
catch (Exception)
@@ -118,7 +128,7 @@ public static (uint ProcessId, string WindowText, string WindowClass) ProcessWin
118128
var wndClass = "";
119129
try
120130
{
121-
wndText = User32.GetWindowText(hwnd);
131+
User32.NativeMethods.GetWindowThreadProcessId(hwnd, out processId);
122132
}
123133
catch (Exception)
124134
{
@@ -127,7 +137,7 @@ public static (uint ProcessId, string WindowText, string WindowClass) ProcessWin
127137

128138
try
129139
{
130-
wndClass = User32.GetWindowClass(hwnd);
140+
wndText = User32.GetWindowText(hwnd);
131141
}
132142
catch (Exception)
133143
{
@@ -136,14 +146,13 @@ public static (uint ProcessId, string WindowText, string WindowClass) ProcessWin
136146

137147
try
138148
{
139-
User32.NativeMethods.GetWindowThreadProcessId(hwnd, out processId);
149+
wndClass = User32.GetWindowClass(hwnd);
140150
}
141151
catch (Exception)
142152
{
143153
// ignored
144154
}
145155

146-
147156
return (processId, wndText, wndClass);
148157
}
149158
}

0 commit comments

Comments
 (0)