@@ -433,17 +433,6 @@ DWORD GetCurrentProcessMainThreadId()
433433
434434DWORD WINAPI StartProxy (LPVOID lpParam) {
435435 HINSTANCE hinstDLL = (HINSTANCE)lpParam;
436-
437- // Setup logging layer
438- remove (" 7thWrapperLoader.log" );
439- plog::init<plog::_7thFormatter>(plog::verbose, " 7thWrapperLoader.log" );
440- PLOGI << " 7thWrapperLoader init log" ;
441-
442- // Log unhandled exceptions
443- SetUnhandledExceptionFilter (ExceptionHandler);
444-
445- // Save current main thread if for FF7.exe
446- currentMainThreadId = GetCurrentProcessMainThreadId ();
447436
448437 // Begin the detouring
449438 static auto target = &GetCommandLineA;
@@ -526,7 +515,35 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
526515 if (fdwReason != DLL_PROCESS_ATTACH) return TRUE ;
527516 if (DetourIsHelperProcess ()) return TRUE ;
528517
529- CreateThread (NULL , 0 , StartProxy, hinstDLL, 0 , NULL );
518+ // Setup logging layer
519+ remove (" 7thWrapperLoader.log" );
520+ plog::init<plog::_7thFormatter>(plog::verbose, " 7thWrapperLoader.log" );
521+ PLOGI << " 7thWrapperLoader init log" ;
522+
523+ // Log unhandled exceptions
524+ SetUnhandledExceptionFilter (ExceptionHandler);
525+
526+ // Save current main thread if for FF7.exe
527+ currentMainThreadId = GetCurrentProcessMainThreadId ();
528+
529+ // Get current process name
530+ CHAR parentName[1024 ];
531+ GetModuleFileNameA (NULL , parentName, sizeof (parentName));
532+ _strlwr (parentName);
533+
534+ // Use the create thread approach for the Steam exe, otherwise run directly the code for 1998 edition
535+ if (strstr (parentName, " ff7_en.exe" ) != NULL )
536+ {
537+ PLOGI << " Detected Steam edition. Using CreateThread approach..." ;
538+
539+ CreateThread (NULL , 0 , StartProxy, hinstDLL, 0 , NULL );
540+ }
541+ else
542+ {
543+ PLOGI << " Detected 1998 edition. Using direct call approach..." ;
544+
545+ StartProxy ((LPVOID)hinstDLL);
546+ }
530547
531548 return TRUE ;
532549}
0 commit comments