Skip to content

Commit

Permalink
fix(Fornite): Fix SoundSwitch compatibility with Fornite
Browse files Browse the repository at this point in the history
And surely other games with anti-cheats.

Fixes #1588
Fixes #1553
  • Loading branch information
Belphemur committed Feb 5, 2025
1 parent 01625c3 commit ea25a25
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions SoundSwitch.Audio.Manager/WindowMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,18 @@ public WindowMonitor()
Log.Information("Foreground = SoundSwitch, don't save.");
return;
}

var process = Process.GetProcessById((int)processId);
var processName = process.MainModule?.FileName ?? "N/A";
var processName = "N/A";
try
{
processName = process.MainModule?.FileName ?? "N/A";
}
catch (Exception)
{
// ignored
}

ForegroundChanged?.Invoke(this, new Event(processId, processName, windowText, windowClass, hwnd));
}
catch (Exception)
Expand Down Expand Up @@ -118,7 +128,7 @@ public static (uint ProcessId, string WindowText, string WindowClass) ProcessWin
var wndClass = "";
try
{
wndText = User32.GetWindowText(hwnd);
User32.NativeMethods.GetWindowThreadProcessId(hwnd, out processId);
}
catch (Exception)
{
Expand All @@ -127,7 +137,7 @@ public static (uint ProcessId, string WindowText, string WindowClass) ProcessWin

try
{
wndClass = User32.GetWindowClass(hwnd);
wndText = User32.GetWindowText(hwnd);
}
catch (Exception)
{
Expand All @@ -136,14 +146,13 @@ public static (uint ProcessId, string WindowText, string WindowClass) ProcessWin

try
{
User32.NativeMethods.GetWindowThreadProcessId(hwnd, out processId);
wndClass = User32.GetWindowClass(hwnd);
}
catch (Exception)
{
// ignored
}


return (processId, wndText, wndClass);
}
}
Expand Down

0 comments on commit ea25a25

Please sign in to comment.