Skip to content

Commit

Permalink
Fix roomscale movement on UE5
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jul 10, 2023
1 parent da4c2dd commit fd2d4c7
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions shared/sdk/AActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UScriptStruct>(L"ScriptStruct /Script/Engine.HitResult");
static const auto fvector = sdk::find_uobject<UScriptStruct>(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<uint8_t> 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
Expand All @@ -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<UScriptStruct>(L"ScriptStruct /Script/CoreUObject.Vector");

const auto is_ue5 = fvector->get_struct_size() == sizeof(glm::vec<3, double>);

std::vector<uint8_t> 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, &params);
this->process_event(func, params.data());

return params.result;
if (!is_ue5) {
return *(glm::vec3*)params.data();
}

return *(glm::vec<3, double>*)params.data();
};
}

0 comments on commit fd2d4c7

Please sign in to comment.