From ab955876f16906a5b8ed8eb0c5ca97788152df80 Mon Sep 17 00:00:00 2001 From: praydog Date: Fri, 28 Jun 2024 07:26:38 -0700 Subject: [PATCH] Lua: Pass correct pos/rot structs through stereo callbacks --- lua-api/lib/src/ScriptContext.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lua-api/lib/src/ScriptContext.cpp b/lua-api/lib/src/ScriptContext.cpp index e6a1e15e..2b8e6beb 100644 --- a/lua-api/lib/src/ScriptContext.cpp +++ b/lua-api/lib/src/ScriptContext.cpp @@ -665,11 +665,21 @@ void ScriptContext::on_post_slate_draw_window_render_thread(UEVR_FSlateRHIRender } void ScriptContext::on_pre_calculate_stereo_view_offset(UEVR_StereoRenderingDeviceHandle device, int view_index, float world_to_meters, UEVR_Vector3f* position, UEVR_Rotatorf* rotation, bool is_double) { + const auto ue5_position = (lua::datatypes::Vector3d*)position; + const auto ue4_position = (lua::datatypes::Vector3f*)position; + const auto ue5_rotation = (lua::datatypes::Vector3d*)rotation; + const auto ue4_rotation = (lua::datatypes::Vector3f*)rotation; + const auto is_ue5 = lua::utility::is_ue5(); + g_contexts.for_each([=](auto ctx) { std::scoped_lock _{ ctx->m_mtx }; for (auto& fn : ctx->m_on_pre_calculate_stereo_view_offset_callbacks) try { - ctx->handle_protected_result(fn(device, view_index, world_to_meters, position, rotation, is_double)); + if (is_ue5) { + ctx->handle_protected_result(fn(device, view_index, world_to_meters, ue5_position, ue5_rotation, is_double)); + } else { + ctx->handle_protected_result(fn(device, view_index, world_to_meters, ue4_position, ue4_rotation, is_double)); + } } catch (const std::exception& e) { ScriptContext::log("Exception in on_pre_calculate_stereo_view_offset: " + std::string(e.what())); } catch (...) { @@ -679,11 +689,21 @@ void ScriptContext::on_pre_calculate_stereo_view_offset(UEVR_StereoRenderingDevi } void ScriptContext::on_post_calculate_stereo_view_offset(UEVR_StereoRenderingDeviceHandle device, int view_index, float world_to_meters, UEVR_Vector3f* position, UEVR_Rotatorf* rotation, bool is_double) { + const auto ue5_position = (lua::datatypes::Vector3d*)position; + const auto ue4_position = (lua::datatypes::Vector3f*)position; + const auto ue5_rotation = (lua::datatypes::Vector3d*)rotation; + const auto ue4_rotation = (lua::datatypes::Vector3f*)rotation; + const auto is_ue5 = lua::utility::is_ue5(); + g_contexts.for_each([=](auto ctx) { std::scoped_lock _{ ctx->m_mtx }; for (auto& fn : ctx->m_on_post_calculate_stereo_view_offset_callbacks) try { - ctx->handle_protected_result(fn(device, view_index, world_to_meters, position, rotation, is_double)); + if (is_ue5) { + ctx->handle_protected_result(fn(device, view_index, world_to_meters, ue5_position, ue5_rotation, is_double)); + } else { + ctx->handle_protected_result(fn(device, view_index, world_to_meters, ue4_position, ue4_rotation, is_double)); + } } catch (const std::exception& e) { ScriptContext::log("Exception in on_post_calculate_stereo_view_offset: " + std::string(e.what())); } catch (...) {