diff --git a/primedev/windows/libsys.cpp b/primedev/windows/libsys.cpp index 0a3195dd3b..0aff820b72 100644 --- a/primedev/windows/libsys.cpp +++ b/primedev/windows/libsys.cpp @@ -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 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]; @@ -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);