From aedf0cc701e207a8f4ffd15c7de061eac2f4f158 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 28 Apr 2021 11:59:10 +0100 Subject: [PATCH] Handle D3D12 hooked libraries on replay moving in memory on reload --- renderdoc/driver/d3d12/d3d12_sdk_select.cpp | 18 +++++++++++++++++- renderdoc/os/win32/win32_hook.cpp | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/renderdoc/driver/d3d12/d3d12_sdk_select.cpp b/renderdoc/driver/d3d12/d3d12_sdk_select.cpp index c90332108..cdfca03b2 100644 --- a/renderdoc/driver/d3d12/d3d12_sdk_select.cpp +++ b/renderdoc/driver/d3d12/d3d12_sdk_select.cpp @@ -104,7 +104,21 @@ HMODULE Hooked_D3D12LoadLibrary(const rdcstr &filename, HANDLE h, DWORD flags) // if we detect the intercepted call to D3D12Core.dll and we have a redirect path, load that // redirect path instead if(strlower(filename).contains("d3d12core.dll") && !D3D12Core_Override_Path.empty()) - return LoadLibraryExW(StringFormat::UTF82Wide(D3D12Core_Override_Path).c_str(), NULL, flags); + { + HMODULE ret = + LoadLibraryExW(StringFormat::UTF82Wide(D3D12Core_Override_Path).c_str(), NULL, flags); + + if(ret) + { + Win32_ManualHookModule("d3d12core.dll", ret); + } + else + { + RDCERR("Error loading D3D12Core.dll from %s", D3D12Core_Override_Path.c_str()); + } + + return ret; + } return NULL; } @@ -207,6 +221,8 @@ void D3D12_PrepareReplaySDKVersion(UINT SDKVersion, bytebuf d3d12core_file, HMOD if(!hooks_applied) { + hooks_applied = true; + Win32_RegisterManualModuleHooking(); D3D12GetInterface_hook.Register("d3d12core.dll", "D3D12GetInterface", Hooked_D3D12GetInterface); diff --git a/renderdoc/os/win32/win32_hook.cpp b/renderdoc/os/win32/win32_hook.cpp index b0ce83013..9184d3b4e 100644 --- a/renderdoc/os/win32/win32_hook.cpp +++ b/renderdoc/os/win32/win32_hook.cpp @@ -999,6 +999,12 @@ void Win32_ManualHookModule(rdcstr modName, HMODULE module) s_HookData->DllHooks[modName].module = module; + for(FunctionHook &hook : s_HookData->DllHooks[modName].FunctionHooks) + { + if(hook.orig) + *hook.orig = GetProcAddress(module, hook.function.c_str()); + } + s_HookData->ApplyHooks(modName.c_str(), module); }