From fd2d4c7f9a141c4bc2ecb0222b156b990b571127 Mon Sep 17 00:00:00 2001 From: praydog Date: Mon, 10 Jul 2023 11:13:40 -0700 Subject: [PATCH] Fix roomscale movement on UE5 --- shared/sdk/AActor.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/shared/sdk/AActor.cpp b/shared/sdk/AActor.cpp index f02fe9b6..41771f49 100644 --- a/shared/sdk/AActor.cpp +++ b/shared/sdk/AActor.cpp @@ -11,12 +11,20 @@ UClass* AActor::static_class() { bool AActor::set_actor_location(const glm::vec3& location, bool sweep, bool teleport) { static const auto func = static_class()->find_function(L"K2_SetActorLocation"); static const auto fhitresult = sdk::find_uobject(L"ScriptStruct /Script/Engine.HitResult"); + static const auto fvector = sdk::find_uobject(L"ScriptStruct /Script/CoreUObject.Vector"); + + const auto is_ue5 = fvector->get_struct_size() == sizeof(glm::vec<3, double>); // Need to dynamically allocate the params because of unknown FHitResult size std::vector params{}; // add a vec3 - params.insert(params.end(), (uint8_t*)&location, (uint8_t*)&location + sizeof(glm::vec3)); + if (!is_ue5) { + params.insert(params.end(), (uint8_t*)&location, (uint8_t*)&location + sizeof(glm::vec3)); + } else { + glm::vec<3, double> loc = location; + params.insert(params.end(), (uint8_t*)&loc, (uint8_t*)&loc + sizeof(glm::vec<3, double>)); + } // add a bool params.insert(params.end(), (uint8_t*)&sweep, (uint8_t*)&sweep + sizeof(bool)); // align @@ -37,13 +45,25 @@ bool AActor::set_actor_location(const glm::vec3& location, bool sweep, bool tele glm::vec3 AActor::get_actor_location() { static const auto func = static_class()->find_function(L"K2_GetActorLocation"); + static const auto fvector = sdk::find_uobject(L"ScriptStruct /Script/CoreUObject.Vector"); + + const auto is_ue5 = fvector->get_struct_size() == sizeof(glm::vec<3, double>); + + std::vector params{}; - struct { - glm::vec3 result{}; - } params; + // add a vec3 + if (!is_ue5) { + params.insert(params.end(), sizeof(glm::vec3), 0); + } else { + params.insert(params.end(), sizeof(glm::vec<3, double>), 0); + } - this->process_event(func, ¶ms); + this->process_event(func, params.data()); - return params.result; + if (!is_ue5) { + return *(glm::vec3*)params.data(); + } + + return *(glm::vec<3, double>*)params.data(); }; } \ No newline at end of file