@@ -36,18 +36,20 @@ std::vector<PakIndex> g_pakIndexes;
3636static HANDLE g_hPipe;
3737
3838// WinAPI function hooks
39- auto orig_ReadFile = ReadFile;
4039auto orig_CreateProcessW = CreateProcessW;
40+ auto orig_ShellExecuteA = ShellExecuteA;
41+ auto orig_ShellExecuteW = ShellExecuteW;
42+ auto orig_ReadFile = ReadFile;
4143NTSTATUS (*orig_ZwSetInformationThread)(HANDLE , ULONG , PVOID , ULONG );
4244
4345// ----------------------------------------------------------------------------
44- static void SendPipeMessage (PipeMessage * msg)
46+ static void SendPipeMessage (PipeMessage& msg)
4547{
46- msg-> pid = GetCurrentProcessId ();
47- msg-> tid = GetCurrentThreadId ();
48+ msg. pid = GetCurrentProcessId ();
49+ msg. tid = GetCurrentThreadId ();
4850
4951 DWORD dummy;
50- if (WriteFile (g_hPipe, msg, sizeof (* msg), &dummy, NULL ))
52+ if (WriteFile (g_hPipe, & msg, sizeof (msg), &dummy, NULL ))
5153 {
5254 // wait for launcher to handle message
5355 SuspendThread (GetCurrentThread ());
@@ -65,7 +67,7 @@ static void SendStringMessage(const WCHAR *str, ...)
6567 _vsnwprintf_s (msg.msgString , sizeof (msg.msgString ) / sizeof (WCHAR ), str, va);
6668 va_end (va);
6769
68- SendPipeMessage (& msg);
70+ SendPipeMessage (msg);
6971}
7072
7173// ----------------------------------------------------------------------------
@@ -116,7 +118,7 @@ static BOOL WINAPI hook_CreateProcessW(LPCWSTR name, LPWSTR cmdLine, LPSECURITY_
116118
117119 msg.msgProcess .pid = pi->dwProcessId ;
118120 msg.msgProcess .flags = flags;
119- SendPipeMessage (& msg);
121+ SendPipeMessage (msg);
120122
121123 // if the process wasn't already supposed to be suspended, unsuspend it now
122124 if (!(flags & CREATE_SUSPENDED ))
@@ -130,6 +132,49 @@ static BOOL WINAPI hook_CreateProcessW(LPCWSTR name, LPWSTR cmdLine, LPSECURITY_
130132 return FALSE ;
131133}
132134
135+ // ----------------------------------------------------------------------------
136+ static void RunWithSteamAppID (UINT appID)
137+ {
138+ SendStringMessage (L" Tried to launch Steam w/ app ID %u" , appID);
139+
140+ PipeMessage msg;
141+ msg.msgType = SteamAppIDMessage;
142+ msg.msgUInt = appID;
143+ SendPipeMessage (msg);
144+ }
145+
146+ // ----------------------------------------------------------------------------
147+ static HINSTANCE WINAPI hook_ShellExecuteA (HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParams, LPCSTR lpDir, INT nShowCmd)
148+ {
149+ UINT appID;
150+
151+ if (lpOperation && lpFile
152+ && !strcmp (lpOperation, " open" )
153+ && sscanf_s (lpFile, " steam://run/%u" , &appID) == 1 )
154+ {
155+ RunWithSteamAppID (appID);
156+ return 0 ;
157+ }
158+
159+ return orig_ShellExecuteA (hwnd, lpOperation, lpFile, lpParams, lpDir, nShowCmd);
160+ }
161+
162+ // ----------------------------------------------------------------------------
163+ static HINSTANCE WINAPI hook_ShellExecuteW (HWND hwnd, LPCWSTR lpOperation, LPCWSTR lpFile, LPCWSTR lpParams, LPCWSTR lpDir, INT nShowCmd)
164+ {
165+ UINT appID;
166+
167+ if (lpFile && lpParams
168+ && wcsstr (lpFile, L" steam.exe" )
169+ && swscanf_s (lpParams, L" steam://run/%u" , &appID) == 1 )
170+ {
171+ RunWithSteamAppID (appID);
172+ return 0 ;
173+ }
174+
175+ return orig_ShellExecuteW (hwnd, lpOperation, lpFile, lpParams, lpDir, nShowCmd);
176+ }
177+
133178// ----------------------------------------------------------------------------
134179static BOOL WINAPI hook_ReadFile (HANDLE hFile, LPVOID lpBuffer, DWORD nSize, LPDWORD lpSize, LPOVERLAPPED lpOverlapped)
135180{
@@ -174,7 +219,7 @@ static BOOL WINAPI hook_ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nSize, LPD
174219 // SendStringMessage(L"Reading encrypted pak index to 0x%p for %ws", lpBuffer, msg.msgIndex.filePath);
175220 SendStringMessage (L" Reading encrypted pak index for %ws" , wcsrchr (msg.msgIndex .filePath , L' \\ ' ) + 1 );
176221 // SendStringMessage(L"Buffer size is 0x%x", nSize);
177- SendPipeMessage (& msg);
222+ SendPipeMessage (msg);
178223 }
179224 }
180225 }
@@ -214,6 +259,8 @@ static void Init()
214259 if (!hookStatus)
215260 {
216261 MH_CreateHook (CreateProcessW, hook_CreateProcessW, (LPVOID *)&orig_CreateProcessW);
262+ MH_CreateHook (ShellExecuteA, hook_ShellExecuteA, (LPVOID *)&orig_ShellExecuteA);
263+ MH_CreateHook (ShellExecuteW, hook_ShellExecuteW, (LPVOID *)&orig_ShellExecuteW);
217264 MH_CreateHook (ReadFile, hook_ReadFile, (LPVOID *)&orig_ReadFile);
218265 MH_CreateHook (GetProcAddress (GetModuleHandleA (" ntdll" ), " ZwSetInformationThread" ),
219266 hook_ZwSetInformationThread, (LPVOID *)&orig_ZwSetInformationThread);
@@ -225,12 +272,12 @@ static void Init()
225272 }
226273 else
227274 {
228- SendStringMessage (L" MinHook enable failed: %s " , MH_StatusToString (hookStatus));
275+ SendStringMessage (L" MinHook enable failed: %hs " , MH_StatusToString (hookStatus));
229276 }
230277 }
231278 else
232279 {
233- SendStringMessage (L" MinHook init failed: %s " , MH_StatusToString (hookStatus));
280+ SendStringMessage (L" MinHook init failed: %hs " , MH_StatusToString (hookStatus));
234281 }
235282}
236283
0 commit comments