Skip to content

Commit

Permalink
FFakeStereoRenderingHook: Add alternate DrawWindow_RenderThread hook
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jan 23, 2025
1 parent d943422 commit 11548cf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dependencies/submodules/UESDK
Submodule UESDK updated from ad0773 to 39ec12
25 changes: 21 additions & 4 deletions src/mods/vr/FFakeStereoRenderingHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,12 @@ void FFakeStereoRenderingHook::attempt_hook_game_engine_tick(uintptr_t return_ad
namespace detail{
bool pre_find_slate_thread() {
sdk::slate::locate_draw_window_renderthread_fn(); // Can take a while to find
sdk::slate::locate_draw_window_renderthread_fn_alternate();
return true;
}
}

void FFakeStereoRenderingHook::attempt_hook_slate_thread(uintptr_t return_address) {
void FFakeStereoRenderingHook::attempt_hook_slate_thread(uintptr_t return_address, bool alternate) {
if (m_asynchronous_scan->value()) {
static std::future<bool> future = std::async(std::launch::async, detail::pre_find_slate_thread);

Expand All @@ -394,14 +395,22 @@ void FFakeStereoRenderingHook::attempt_hook_slate_thread(uintptr_t return_addres
return;
}

if (return_address == 0 && m_attempted_hook_slate_thread) {
const auto attempted = alternate ? m_attempted_hook_slate_thread_alternate : m_attempted_hook_slate_thread;

if (return_address == 0 && attempted) {
return;
}

SPDLOG_INFO("Attempting to hook FSlateRHIRenderer::DrawWindow_RenderThread!");
m_attempted_hook_slate_thread = true;

auto func = sdk::slate::locate_draw_window_renderthread_fn();
if (alternate) {
SPDLOG_INFO("Using alternate method to hook FSlateRHIRenderer::DrawWindow_RenderThread!");
m_attempted_hook_slate_thread_alternate = true;
} else {
m_attempted_hook_slate_thread = true;
}

auto func = alternate ? sdk::slate::locate_draw_window_renderthread_fn_alternate() : sdk::slate::locate_draw_window_renderthread_fn();

if (!func && return_address == 0) {
SPDLOG_ERROR("Cannot hook FSlateRHIRenderer::DrawWindow_RenderThread");
Expand Down Expand Up @@ -3026,6 +3035,14 @@ void FFakeStereoRenderingHook::pre_render_viewfamily_renderthread(ISceneViewExte
return;
}

static size_t execution_count{0};

if (g_hook->m_attempted_hook_slate_thread && !g_hook->m_slate_thread_hook && !g_hook->m_attempted_hook_slate_thread_alternate && execution_count++ >= 50) {
SPDLOG_INFO("DrawWindow_RenderThread was not hooked after {} render calls, trying alternative hook", execution_count);

g_hook->attempt_hook_slate_thread(0, true);
}

auto& vr = VR::get();

if (!vr->is_hmd_active()) {
Expand Down
3 changes: 2 additions & 1 deletion src/mods/vr/FFakeStereoRenderingHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class FFakeStereoRenderingHook : public ModComponent {

void attempt_hooking();
void attempt_hook_game_engine_tick(uintptr_t return_address = 0);
void attempt_hook_slate_thread(uintptr_t return_address = 0);
void attempt_hook_slate_thread(uintptr_t return_address = 0, bool alternate = false);
void attempt_hook_update_viewport_rhi(uintptr_t return_address);
void attempt_hook_fsceneview_constructor();

Expand Down Expand Up @@ -433,6 +433,7 @@ class FFakeStereoRenderingHook : public ModComponent {
bool m_hooked_slate_thread{false};
bool m_attempted_hook_game_engine_tick{false};
bool m_attempted_hook_slate_thread{false};
bool m_attempted_hook_slate_thread_alternate{false};
bool m_attempted_hook_update_viewport_rhi{false};
bool m_attempted_hook_fsceneview_constructor{false};
bool m_uses_old_rendertarget_manager{false};
Expand Down

0 comments on commit 11548cf

Please sign in to comment.