diff --git a/Source/Process/AuProcess.cpp b/Source/Process/AuProcess.cpp index 176f9c6e..bc1148f1 100644 --- a/Source/Process/AuProcess.cpp +++ b/Source/Process/AuProcess.cpp @@ -145,6 +145,24 @@ namespace Aurora::Process return dllSuffixString; } + static AuString GetModuleNameFromFileName(const AuString &filename) + { + static const auto &kStringSuffixA = ConstructAuDllSuffix(); + static const auto kStringSuffixB = GetPlatformExt(Build::kCurrentPlatform); + + if (filename.ends_with(kStringSuffixA)) + { + return filename.substr(0, filename.size() - kStringSuffixA.size()); + } + + if (filename.ends_with(kStringSuffixB)) + { + return filename.substr(0, filename.size() - strlen(kStringSuffixB)); + } + + return filename; + } + #if defined(AURORA_PLATFORM_WIN32) bool VerifyEmbeddedSignature(const wchar_t *path, HANDLE handle) { @@ -276,6 +294,12 @@ namespace Aurora::Process static void *LoadModule(const AuString &name, const AuString &path) { + auto itr = gModuleHandles.find(path); + if (itr != gModuleHandles.end()) + { + return itr->second; + } + #if defined(AURORA_IS_MODERNNT_DERIVED) if (!pLoadLibraryW) { @@ -299,6 +323,7 @@ namespace Aurora::Process auto pRet = (void *)handle; gModuleHandles.insert(AuMakePair(name, pRet)); + gModuleHandles.insert(AuMakePair(path, pRet)); return pRet; } @@ -706,16 +731,27 @@ namespace Aurora::Process { auto &sharedDLL = *itr; - AuLogDbg("[attempt] Loading shared object: {}", sharedDLL); - AuString a = dir + "/" + sharedDLL; #if defined(AURORA_IS_MODERNNT_DERIVED) AuString aAbs = dir + "/" + sharedDLL + "."; #endif + #if defined(AURORA_IS_MODERNNT_DERIVED) + if (GetProcHandle(aAbs)) + #else + if (GetProcHandle(a)) + #endif + { + itr++; + continue; + } + + auto modName = GetModuleNameFromFileName(sharedDLL); + AuLogDbg("[attempt] Loading shared object: {} (path: {})", modName, sharedDLL); + bool fail {}; - ModuleLoadRequest request { AuList{ dir }, sharedDLL }; + ModuleLoadRequest request { AuList{ dir }, modName }; if (TryLoadModule(a, #if defined(AURORA_IS_MODERNNT_DERIVED) @@ -727,7 +763,7 @@ namespace Aurora::Process { if (!fail) { - AuLogDbg("[attempt] Loaded shared object: {}!", sharedDLL); + AuLogDbg("[attempt] Loaded shared object: {} (path: {})", modName, sharedDLL); uSuccess++; itr = sharedObjects.erase(itr); }