@@ -31,9 +31,9 @@ void print_usage() {
3131 << L" -A Enable ANSI hooks (e.g. RegisterClassA).\n "
3232 << L" -W Enable Unicode hooks (e.g. RegisterClassW).\n "
3333 << L" -Std Enable Standard hooks (e.g. RegisterClass).\n "
34- << L" -Ex Enable Extended hooks (e.g. RegisterClassEx).\n\n "
34+ << L" -Ex Enable Extended hooks (e.g. RegisterClassEx).\n "
3535 << L" -IgnoreWinClass <Name> Ignore specific Class Name (partial match).\n "
36- << L" -IgnoreWinName <Name> Ignore specific Window Name (partial match).\n "
36+ << L" -IgnoreWinName <Name> Ignore specific Window Name (partial match).\n\n "
3737 << L" (If no filters are provided, ALL are enabled by default.)\n\n " ;
3838}
3939
@@ -218,10 +218,7 @@ int wmain(int argc, wchar_t* argv[])
218218 WCHAR exePath[MAX_PATH ];
219219 GetModuleFileName (NULL , exePath, MAX_PATH );
220220 std::wstring exeDir = exePath;
221- size_t lastSlash = exeDir.find_last_of (L" \\ /" );
222- if (lastSlash != std::wstring::npos) {
223- exeDir = exeDir.substr (0 , lastSlash);
224- }
221+ exeDir = exeDir.substr (0 , exeDir.find_last_of (L" \\ /" ));
225222
226223 std::wstring coreDllName;
227224
@@ -244,96 +241,85 @@ int wmain(int argc, wchar_t* argv[])
244241
245242 // Plugin DLLs
246243 std::vector<std::wstring> pluginDlls;
247- std::wstring pluginsDir = exeDir + L" \\ plugins\\ " ;
248- std::wstring searchPath = pluginsDir + L" *.dll" ;
244+ std::wstring searchPath = exeDir + L" \\ plugins\\ *.dll" ;
249245 WIN32_FIND_DATA wfd;
250246 HANDLE hFind = FindFirstFile (searchPath.c_str (), &wfd);
251247
252248 if (hFind != INVALID_HANDLE_VALUE ) {
253249 do {
254250 std::wstring filename = wfd.cFileName ;
255251 std::wstring lowerName = to_lower (filename);
256- if (lowerName.length () >= 4 &&
257- lowerName.substr (lowerName.length () - 4 ) == L" .dll" )
258- {
259- pluginDlls.push_back (pluginsDir + filename);
260- }
261- else
262- {
263- // std::wcout << L"Skipping invalid match: " << filename << std::endl;
264- }
265-
252+ if (lowerName.length () >= 4 && lowerName.substr (lowerName.length () - 4 ) == L" .dll" )
253+ pluginDlls.push_back (exeDir + L" \\ plugins\\ " + filename);
266254 } while (FindNextFile (hFind, &wfd));
267255 FindClose (hFind);
268256 }
269- else {
270- std::wcout << L" No plugins found in " << pluginsDir << std::endl;
271- }
272257
273258 // Launch Process
274259 PROCESS_INFORMATION pi = {};
275260 STARTUPINFOW si = {};
276261 si.cb = sizeof (si);
277-
278262 std::wstring fullCommandLine = L" \" " + gamePath + L" \" " + gameArgs;
279263
280264 std::wcout << L" Launching game suspended: " << gamePath << std::endl;
281-
282- if (!CreateProcess (
283- NULL ,
284- const_cast <wchar_t *>(fullCommandLine.c_str ()), // Command line
285- NULL ,
286- NULL ,
287- FALSE ,
288- CREATE_SUSPENDED ,
289- NULL ,
290- NULL ,
291- &si, // StartupInfo
292- &pi // ProcessInfo
293- )) {
294- std::wcerr << L" Failed to create process: " << GetLastError () << std::endl;
295- Sleep (7000 );
265+ if (!CreateProcess (NULL , const_cast <wchar_t *>(fullCommandLine.c_str ()), NULL , NULL , FALSE , CREATE_SUSPENDED , NULL , NULL , &si, &pi)) {
266+ std::wcerr << L" Failed to create process." << std::endl;
296267 return 1 ;
297268 }
298269
299- DWORD processId = pi.dwProcessId ;
270+ std::wcout << L" Resuming process..." << std::endl;
271+ ResumeThread (pi.hThread );
300272
273+ std::wcout << L" Attempting to catch process..." << std::endl;
301274
302- std::wcout << L" Injecting Core DLL via EasyHook..." << std::endl;
303- NTSTATUS nt = RhInjectLibrary (
304- processId,
305- 0 ,
306- EASYHOOK_INJECT_DEFAULT ,
275+ NTSTATUS nt = -1 ;
276+ int attempts = 0 ;
277+ const int MAX_ATTEMPTS = 50 ;
278+
279+ while (attempts < MAX_ATTEMPTS ) {
280+ nt = RhInjectLibrary (
281+ pi.dwProcessId ,
282+ 0 ,
283+ EASYHOOK_INJECT_DEFAULT ,
307284#if defined(_WIN64)
308- NULL , const_cast <wchar_t *>(coreDllPath.c_str ()),
285+ NULL , const_cast <wchar_t *>(coreDllPath.c_str ()),
309286#else
310- const_cast <wchar_t *>(coreDllPath.c_str ()), NULL ,
287+ const_cast <wchar_t *>(coreDllPath.c_str ()), NULL ,
311288#endif
312- & injectionInfo, sizeof (InjectionInfo)
313- );
289+ & injectionInfo, sizeof (InjectionInfo)
290+ );
291+
292+ if (nt == 0 ) {
293+ std::wcout << L" Injection Successful on attempt " << (attempts + 1 ) << std::endl;
294+ break ;
295+ }
296+ else {
297+ attempts++;
298+ Sleep (10 );
299+ }
300+ }
314301
315302 if (nt != 0 ) {
316- std::wcerr << L" Failed to inject Core DLL: " << RtlGetLastErrorString () << std::endl;
317- std::wcerr << L" Terminating... " << std::endl;
318- TerminateProcess (pi.hProcess , 1 );
303+ std::wcerr << L" CRITICAL FAILURE: Could not inject after " << MAX_ATTEMPTS << " attempts. " << std::endl;
304+ std::wcerr << L" Last Error: " << RtlGetLastErrorString () << std::endl;
305+ // TerminateProcess(pi.hProcess, 1);
319306 return 1 ;
320307 }
321308
322- if (!pluginDlls.empty ())
323- {
324- std::wcout << L" Injecting " << pluginDlls.size () << L" plugins via LoadLibrary..." << std::endl;
309+ std::wcout << L" Waiting for hooks to settle..." << std::endl;
310+ Sleep (2000 );
311+
312+ if (!pluginDlls.empty ()) {
313+ std::wcout << L" Injecting plugins..." << std::endl;
325314 for (const auto & dllPath : pluginDlls) {
326315 InjectStandardDLL (pi.hProcess , dllPath);
316+ Sleep (200 );
327317 }
328318 }
329319
330- std::wcout << L" Resuming game process..." << std::endl;
331- ResumeThread (pi.hThread );
332-
333320 CloseHandle (pi.hProcess );
334321 CloseHandle (pi.hThread );
335322
336- std::wcout << L" Success. Launcher exiting." << std::endl;
337-
323+ std::wcout << L" Success." << std::endl;
338324 return 0 ;
339325}
0 commit comments