Skip to content

Commit

Permalink
D3D12Hook: Hook streamline as soon as DLSS DLL is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jun 3, 2024
1 parent d59bd9c commit 445e521
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/D3D12Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ void* D3D12Hook::Streamline::link_swapchain_to_cmd_queue(void* rcx, void* rdx, v
return result;
}

void D3D12Hook::hook_streamline() {
void D3D12Hook::hook_streamline(HMODULE dlssg_module) try {
if (D3D12Hook::s_streamline.setup) {
return;
}

std::scoped_lock _{g_framework->get_hook_monitor_mutex()};

spdlog::info("[Streamline] Hooking Streamline");

const auto dlssg_module = GetModuleHandleW(L"sl.dlss_g.dll");
if (dlssg_module == nullptr) {
dlssg_module = GetModuleHandleW(L"sl.dlss_g.dll");
}

if (dlssg_module == nullptr) {
spdlog::error("[Streamline] Failed to get sl.dlss_g.dll module handle");
Expand Down Expand Up @@ -89,6 +93,8 @@ void D3D12Hook::hook_streamline() {
}

D3D12Hook::s_streamline.setup = true;
} catch(...) {
spdlog::error("[Streamline] Failed to hook Streamline");
}

bool D3D12Hook::hook() {
Expand Down
2 changes: 1 addition & 1 deletion src/D3D12Hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class D3D12Hook
m_ignore_next_present = true;
}

void hook_streamline();
static void hook_streamline(HMODULE dlssg_module = nullptr);

protected:
ID3D12Device4* m_device{ nullptr };
Expand Down
6 changes: 6 additions & 0 deletions src/REFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ try {
if (NotificationData->Loaded.BaseDllName != nullptr && NotificationData->Loaded.BaseDllName->Buffer != nullptr) {
std::wstring base_dll_name = NotificationData->Loaded.BaseDllName->Buffer;
spdlog::info("LdrRegisterDllNotification: Loaded: {}", utility::narrow(base_dll_name));

if (std::wstring_view{base_dll_name}.find(L"sl.dlss_g.dll") != std::wstring_view::npos) {
spdlog::info("LdrRegisterDllNotification: Detected DLSS DLL loaded");

D3D12Hook::hook_streamline((HMODULE)NotificationData->Loaded.DllBase);
}
}

if (g_current_game_path && NotificationData->Loaded.FullDllName != nullptr && NotificationData->Loaded.FullDllName->Buffer != nullptr) {
Expand Down

0 comments on commit 445e521

Please sign in to comment.