Skip to content

Commit

Permalink
Prevent module callbacks being ran for duplicate modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ASpoonPlaysGames committed Aug 26, 2024
1 parent 734ac49 commit 98aafc9
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions primedev/windows/libsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@ ILoadLibraryExW o_LoadLibraryExW = nullptr;
//-----------------------------------------------------------------------------
// Purpose: Run detour callbacks for given HMODULE
//-----------------------------------------------------------------------------
void LibSys_RunModuleCallbacks(HMODULE hModule, unsigned int iRecurse = 0)
void LibSys_RunModuleCallbacks(HMODULE hModule)
{
if (!hModule || iRecurse > 1)
// Modules that we have already ran callbacks for.
// Note: If we ever hook unloading modules, then this will need updating to handle removal etc.
static std::vector<HMODULE> vCalledModules;

if (!hModule)
{
return;
}

// FIXME [Fifty]: Instead of only recursing once we should store the modules we ran callbacks for
iRecurse++;
// If we have already ran callbacks for this module, don't run them again.
if (std::find(vCalledModules.begin(), vCalledModules.end(), hModule) != vCalledModules.end())
{
return;
}
vCalledModules.push_back(hModule);

// Get module base name in ASCII as noone wants to deal with unicode
CHAR szModuleName[MAX_PATH];
Expand All @@ -33,7 +41,7 @@ void LibSys_RunModuleCallbacks(HMODULE hModule, unsigned int iRecurse = 0)
// Run calllbacks for all imported modules
CModule cModule(hModule);
for (const std::string& svImport : cModule.GetImportedModules())
LibSys_RunModuleCallbacks(GetModuleHandleA(svImport.c_str()), iRecurse);
LibSys_RunModuleCallbacks(GetModuleHandleA(svImport.c_str()));

// DevMsg(eLog::NONE, "%s\n", szModuleName);

Expand Down

0 comments on commit 98aafc9

Please sign in to comment.