Skip to content

Commit 353f904

Browse files
Improved process detection for hidden windows
1 parent 413eef6 commit 353f904

2 files changed

Lines changed: 30 additions & 11 deletions

File tree

Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
* e32b5b5 (HEAD -> staging, origin/staging, origin/master, origin/HEAD, master) Unit tests for BitmaskExtensions and bug fixes
1+
* 413eef6 (HEAD -> staging, origin/staging) Implemented SkipLauncher option and GameArgs for URI mode
2+
* e32b5b5 (origin/master, origin/HEAD, master) Unit tests for BitmaskExtensions and bug fixes
23
* 928f8de Some more unit tests for Program class
34
* 2df305e Just list our options to be validated cleanly for readability
45
* 67f72bd Remove a typo in validated INI options

OriginSteamOverlayLauncher/ProcessTracking.cs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,15 @@ public static int ValidateProcTree(Process[] procTree, int timeout)
123123
if (procChildren == 1 && !procTree[0].HasExited
124124
&& procTree[0].MainWindowHandle != IntPtr.Zero && procTree[0].MainWindowTitle.Length > 0)
125125
{
126+
procTree[0].Refresh();
126127
return procTree[0].Id; // just return the PID of the parent
127128
}
128129
else if (procChildren > 1)
129130
{// our parent is likely a caller or proxy
130131
for (int i = 0; i < procChildren; i++)
131132
{// iterate through each process in the tree and determine which process we should bind to
132133
var proc = procTree[i];
134+
proc.Refresh();
133135

134136
if (proc.Id > 0 && !proc.HasExited)
135137
{
@@ -143,6 +145,13 @@ public static int ValidateProcTree(Process[] procTree, int timeout)
143145
}
144146
}
145147
}
148+
149+
for (int j = 0; j < procChildren; j++)
150+
{// fall back to finding the ModuleHandle (breaks window messages)
151+
var proc = procTree[j];
152+
if (proc.Id > 0 && proc.MainWindowHandle == IntPtr.Zero && proc.MainModule != null && (long)proc.Handle > 0)
153+
return proc.Id;
154+
}
146155
}
147156

148157
return 0;
@@ -190,6 +199,10 @@ public static Process GetProcessTreeHandle(Settings setHnd, String procName, ref
190199
_retProc = Program.RebindProcessByID(_result);
191200
processType = DetectWindowType(_retProc); // pass our process type out by ref
192201
Program.Logger("OSOL", String.Format("Bound to a valid process at PID: {0} [{1}] in {2} seconds", _result, String.Format("{0}.exe", procName), sanity_counter));
202+
203+
if (processType == -1)
204+
Program.Logger("WARNING", String.Format("Could not find MainWindowHandle of PID [{0}], fell back to ModuleHandle instead...", _retProc.Id));
205+
193206
break;
194207
}
195208
}
@@ -288,16 +301,19 @@ public void ProcessLauncher(Settings setHnd, IniFile iniHnd)
288301
launcherProc = GetProcessTreeHandle(setHnd, launcherName, ref launcherType);
289302
launcherPID = launcherProc != null ? launcherProc.Id : 0;
290303

291-
if (launcherPID > 0 && launcherType > -1)
304+
if (launcherPID > 0)
292305
{
293306
// do some waiting based on user tuneables to avoid BPM weirdness
294307
Program.Logger("OSOL", String.Format("Waiting {0}s for launcher process to load...", setHnd.PreGameLauncherWaitTime));
295308
Thread.Sleep(setHnd.PreGameLauncherWaitTime * 1000);
296-
Program.BringToFront(launcherProc.MainWindowHandle);
297309

298-
// if the user requests it minimize our launcher after detecting it
299-
if (setHnd.MinimizeLauncher)
300-
Program.MinimizeWindow(launcherProc.MainWindowHandle);
310+
if (launcherType > -1)
311+
{// we can only send window messages if we have a window handle
312+
Program.BringToFront(launcherProc.MainWindowHandle);
313+
if (setHnd.MinimizeLauncher)
314+
Program.MinimizeWindow(launcherProc.MainWindowHandle);
315+
}
316+
301317
}
302318
}
303319
#endregion
@@ -355,16 +371,18 @@ public void ProcessLauncher(Settings setHnd, IniFile iniHnd)
355371
launcherProc = GetProcessTreeHandle(setHnd, launcherName, ref launcherType);
356372
launcherPID = launcherProc != null ? launcherProc.Id : 0;
357373

358-
if (launcherPID > 0 && launcherType > -1)
374+
if (launcherPID > 0)
359375
{
360376
// do some waiting based on user tuneables to avoid BPM weirdness
361377
Program.Logger("OSOL", String.Format("Waiting {0}s for launcher process to load...", setHnd.PreGameLauncherWaitTime));
362378
Thread.Sleep(setHnd.PreGameLauncherWaitTime * 1000);
363-
Program.BringToFront(launcherProc.MainWindowHandle);
364379

365-
// if the user requests it minimize our launcher after detecting it
366-
if (setHnd.MinimizeLauncher)
367-
Program.MinimizeWindow(launcherProc.MainWindowHandle);
380+
if (launcherType > -1)
381+
{// we can only send window messages if we have a window handle
382+
Program.BringToFront(launcherProc.MainWindowHandle);
383+
if (setHnd.MinimizeLauncher)
384+
Program.MinimizeWindow(launcherProc.MainWindowHandle);
385+
}
368386
}
369387
}
370388
}

0 commit comments

Comments
 (0)