From 275dc71ef4154e8ceaf2b16ba54d7dd0eb8451e5 Mon Sep 17 00:00:00 2001 From: praydog Date: Sun, 22 Oct 2023 03:21:40 -0700 Subject: [PATCH] Move imgui logic into UEngine::Tick if possible --- src/Framework.cpp | 13 +++++++++++-- src/Framework.hpp | 5 +++++ src/mods/vr/FFakeStereoRenderingHook.cpp | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Framework.cpp b/src/Framework.cpp index 27576de1..1bca6b44 100644 --- a/src/Framework.cpp +++ b/src/Framework.cpp @@ -372,10 +372,15 @@ Framework::~Framework() { m_terminating = true; m_d3d_monitor_thread->request_stop(); + m_command_thread->request_stop(); if (m_d3d_monitor_thread->joinable()) { m_d3d_monitor_thread->join(); } + if (m_command_thread->joinable()) { + m_command_thread->join(); + } + if (m_is_d3d11) { deinit_d3d11(); } @@ -470,7 +475,9 @@ void Framework::on_frame_d3d11() { ImGui_ImplDX11_NewFrame(); // hooks don't run until after initialization, so we just render the imgui window while initalizing. - run_imgui_frame(false); + if (!m_has_engine_thread) { + run_imgui_frame(false); + } /* } else { return; } @@ -573,7 +580,9 @@ void Framework::on_frame_d3d12() { invalidate_device_objects(); ImGui_ImplDX12_NewFrame(); // hooks don't run until after initialization, so we just render the imgui window while initalizing. - run_imgui_frame(false); + if (!m_has_engine_thread) { + run_imgui_frame(false); + } /* } else { return; } diff --git a/src/Framework.hpp b/src/Framework.hpp index edcf5d1e..361ddf58 100644 --- a/src/Framework.hpp +++ b/src/Framework.hpp @@ -180,6 +180,10 @@ class Framework { return m_uevr_shared_memory; } + void enable_engine_thread() { + m_has_engine_thread = true; + } + private: void consume_input(); void update_fonts(); @@ -278,6 +282,7 @@ class Framework { bool m_sent_message{false}; bool m_message_hook_requested{false}; + bool m_has_engine_thread{false}; RendererType m_renderer_type{RendererType::D3D11}; diff --git a/src/mods/vr/FFakeStereoRenderingHook.cpp b/src/mods/vr/FFakeStereoRenderingHook.cpp index 09c8e755..85a60acc 100644 --- a/src/mods/vr/FFakeStereoRenderingHook.cpp +++ b/src/mods/vr/FFakeStereoRenderingHook.cpp @@ -236,6 +236,7 @@ void FFakeStereoRenderingHook::attempt_hook_game_engine_tick(uintptr_t return_ad } } + // TODO: move this to a better place m_tick_hook = safetyhook::create_inline((void*)*func, +[](sdk::UGameEngine* engine, float delta, bool idle) -> void* { ZoneScopedN("UGameEngine::Tick Hook"); FrameMarkStart("UGameEngine::Tick"); @@ -270,6 +271,9 @@ void FFakeStereoRenderingHook::attempt_hook_game_engine_tick(uintptr_t return_ad hook->m_ignore_next_engine_tick = false; return nullptr; } + + g_framework->enable_engine_thread(); + g_framework->run_imgui_frame(false); delta += hook->m_ignored_engine_delta; hook->m_ignored_engine_delta = 0.0f;