Skip to content

Commit

Permalink
D3D12Hook: More frame generation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jun 2, 2024
1 parent c07073b commit 5cf9a17
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
20 changes: 14 additions & 6 deletions src/D3D12Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,24 @@ void* D3D12Hook::Streamline::link_swapchain_to_cmd_queue(void* rcx, void* rdx, v
spdlog::info("[Streamline] linkSwapchainToCmdQueue: {:x}", (uintptr_t)_ReturnAddress());

g_framework->on_reset(); // Needed to prevent a crash due to resources hanging around
g_d3d12_hook->unhook(); // Removes all vtable hooks

auto& hook = g_d3d12_hook->m_streamline.link_swapchain_to_cmd_queue_hook;
if (g_d3d12_hook != nullptr) {
g_d3d12_hook->unhook(); // Removes all vtable hooks
}

auto& hook = D3D12Hook::s_streamline.link_swapchain_to_cmd_queue_hook;
const auto result = hook->get_original<decltype(link_swapchain_to_cmd_queue)>()(rcx, rdx, r8, r9);

// Re-hooks present after the above function creates the swapchain
// This allows the hook to immediately still function
// rather than waiting on the hook monitor to notice the hook isn't working
g_framework->hook_d3d12();

return result;
}

void D3D12Hook::hook_streamline() {
if (m_streamline.setup) {
if (D3D12Hook::s_streamline.setup) {
return;
}

Expand Down Expand Up @@ -72,15 +80,15 @@ void D3D12Hook::hook_streamline() {
return;
}

m_streamline.link_swapchain_to_cmd_queue_hook = std::make_unique<FunctionHook>(*fn, (uintptr_t)&Streamline::link_swapchain_to_cmd_queue);
D3D12Hook::s_streamline.link_swapchain_to_cmd_queue_hook = std::make_unique<FunctionHook>(*fn, (uintptr_t)&Streamline::link_swapchain_to_cmd_queue);

if (m_streamline.link_swapchain_to_cmd_queue_hook->create()) {
if (D3D12Hook::s_streamline.link_swapchain_to_cmd_queue_hook->create()) {
spdlog::info("[Streamline] Hooked linkSwapchainToCmdQueue");
} else {
spdlog::error("[Streamline] Failed to hook linkSwapchainToCmdQueue");
}

m_streamline.setup = true;
D3D12Hook::s_streamline.setup = true;
}

bool D3D12Hook::hook() {
Expand Down
4 changes: 3 additions & 1 deletion src/D3D12Hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ class D3D12Hook

std::unique_ptr<FunctionHook> link_swapchain_to_cmd_queue_hook{};
bool setup{ false };
} m_streamline{};
};

static inline Streamline s_streamline{};

OnPresentFn m_on_present{ nullptr };
OnPresentFn m_on_post_present{ nullptr };
Expand Down
2 changes: 2 additions & 0 deletions src/REFramework.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ class REFramework {
void draw_ui();
void draw_about();

public:
bool hook_d3d11();
bool hook_d3d12();

private:
bool initialize();
bool initialize_game_data();
bool initialize_windows_message_hook();
Expand Down

0 comments on commit 5cf9a17

Please sign in to comment.