Skip to content

Commit 4b3f109

Browse files
committed
Fix LoadGameOverlay: module name check + robust Steam path + PATH fallback
1 parent 5320aa8 commit 4b3f109

1 file changed

Lines changed: 63 additions & 11 deletions

File tree

dllmain.cpp

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -502,34 +502,86 @@ static void LoadGameOverlay()
502502
{
503503
forcedAppId = g_ForcedAppId;
504504
}
505-
505+
506+
// Check if overlay is already loaded by module name (not hardcoded path)
506507
#if defined(_M_IX86)
507-
HMODULE hOverlay = GetModuleHandleW(L"C:\\Program Files (x86)\\Steam\\GameOverlayRenderer.dll");
508+
const char* overlayName = "GameOverlayRenderer.dll";
508509
#elif defined(_M_AMD64)
509-
HMODULE hOverlay = GetModuleHandleW(L"C:\\Program Files (x86)\\Steam\\GameOverlayRenderer64.dll");
510+
const char* overlayName = "GameOverlayRenderer64.dll";
510511
#endif
512+
HMODULE hOverlay = GetModuleHandleA(overlayName);
511513

512514
if (forcedAppId != 769 && !hOverlay)
513515
{
514-
const char* installPath = SteamAPI_GetSteamInstallPath();
515-
if (_stricmp(installPath, "UCOnline2_InvalidPath") != 0)
516+
// Use the same path resolution logic as InitSteamClient
517+
char steamPath[MAX_PATH] = {0};
518+
bool found = false;
519+
520+
if (GetSteamPathFromRegistry(steamPath, MAX_PATH))
521+
{
522+
found = true;
523+
}
524+
else
525+
{
526+
const char* commonPaths[] = {
527+
"C:\\Program Files (x86)\\Steam",
528+
"C:\\Steam"
529+
};
530+
for (int i = 0; i < _countof(commonPaths); i++)
531+
{
532+
DWORD attrs = GetFileAttributesA(commonPaths[i]);
533+
if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY))
534+
{
535+
strcpy_s(steamPath, MAX_PATH, commonPaths[i]);
536+
found = true;
537+
break;
538+
}
539+
}
540+
if (!found)
541+
{
542+
const char* cachedPath = SteamAPI_GetSteamInstallPath();
543+
if (cachedPath && strcmp(cachedPath, "UCOnline2_InvalidPath") != 0)
544+
{
545+
strcpy_s(steamPath, MAX_PATH, cachedPath);
546+
found = true;
547+
}
548+
}
549+
}
550+
551+
if (found)
516552
{
517553
char overlayPath[MAX_PATH] = { 0 };
518-
#if defined(_M_IX86)
519-
_snprintf_s(overlayPath, MAX_PATH, _TRUNCATE, "%s\\GameOverlayRenderer.dll", installPath);
520-
#elif defined(_M_AMD64)
521-
_snprintf_s(overlayPath, MAX_PATH, _TRUNCATE, "%s\\GameOverlayRenderer64.dll", installPath);
522-
#endif
554+
_snprintf_s(overlayPath, MAX_PATH, _TRUNCATE, "%s\\%s", steamPath, overlayName);
555+
556+
UCOLOG("[UCOnline2] Loading game overlay from: %s", overlayPath);
523557
HMODULE hLoaded = LoadLibraryExA(overlayPath, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH);
524558
if (hLoaded)
525559
{
526560
UCOLOG("[UCOnline2] Loaded game overlay: %s", overlayPath);
527561
}
528562
else
529563
{
530-
UCOLOG("[UCOnline2] Failed to load game overlay: %s (error %lu)", overlayPath, GetLastError());
564+
UCOLOG("[UCOnline2] Failed to load game overlay from Steam dir (error %lu), trying PATH...", GetLastError());
565+
// Fallback: let Windows search PATH
566+
hLoaded = LoadLibraryExA(overlayName, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH);
567+
if (hLoaded)
568+
{
569+
UCOLOG("[UCOnline2] Loaded game overlay from PATH");
570+
}
571+
else
572+
{
573+
UCOLOG("[UCOnline2] Failed to load game overlay: %s (error %lu)", overlayName, GetLastError());
574+
}
531575
}
532576
}
577+
else
578+
{
579+
UCOLOG("[UCOnline2] Could not determine Steam path, skipping overlay load");
580+
}
581+
}
582+
else if (hOverlay)
583+
{
584+
UCOLOG("[UCOnline2] Game overlay already loaded, skipping");
533585
}
534586
#endif
535587
}

0 commit comments

Comments
 (0)