aboutsummaryrefslogtreecommitdiff
path: root/primedev/windows/libsys.cpp
diff options
context:
space:
mode:
authorJack <66967891+ASpoonPlaysGames@users.noreply.github.com>2024-08-27 07:48:33 +0100
committerGitHub <noreply@github.com>2024-08-27 08:48:33 +0200
commitf1288350c729d63aeeb0a6bdab0746b865131668 (patch)
treebcad7f52872c962b47969df3a2f07ee3fec90ef2 /primedev/windows/libsys.cpp
parent932735e0500f6fc4d43ee949754c6a6a7c48d3e2 (diff)
downloadNorthstarLauncher-f1288350c729d63aeeb0a6bdab0746b865131668.tar.gz
NorthstarLauncher-f1288350c729d63aeeb0a6bdab0746b865131668.zip
hooking: run callbacks for imported modules (#780)v1.27.3-rc6v1.27.3
Previously we only ran callbacks for modules loaded using WinAPI. This now also runs callbacks for modules imported by those loaded by WinAPI. This fixes callbacks for miles and bink dlls.
Diffstat (limited to 'primedev/windows/libsys.cpp')
-rw-r--r--primedev/windows/libsys.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/primedev/windows/libsys.cpp b/primedev/windows/libsys.cpp
index 501eae68..0aff820b 100644
--- a/primedev/windows/libsys.cpp
+++ b/primedev/windows/libsys.cpp
@@ -18,15 +18,31 @@ ILoadLibraryExW o_LoadLibraryExW = nullptr;
//-----------------------------------------------------------------------------
void LibSys_RunModuleCallbacks(HMODULE hModule)
{
+ // 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;
}
+ // 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];
GetModuleBaseNameA(GetCurrentProcess(), hModule, szModuleName, MAX_PATH);
+ // Run calllbacks for all imported modules
+ CModule cModule(hModule);
+ for (const std::string& svImport : cModule.GetImportedModules())
+ LibSys_RunModuleCallbacks(GetModuleHandleA(svImport.c_str()));
+
// DevMsg(eLog::NONE, "%s\n", szModuleName);
// Call callbacks