Skip to content

Commit

Permalink
SDK: Fix Vector/Matrix names on really old UE (< 4.8)
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Aug 23, 2023
1 parent fc891be commit 95e0287
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ list(APPEND sdk_SOURCES
"shared/sdk/FSceneView.cpp"
"shared/sdk/FViewportInfo.cpp"
"shared/sdk/Globals.cpp"
"shared/sdk/ScriptMatrix.cpp"
"shared/sdk/ScriptVector.cpp"
"shared/sdk/Slate.cpp"
"shared/sdk/StereoStuff.cpp"
"shared/sdk/UClass.cpp"
Expand Down Expand Up @@ -358,6 +360,8 @@ list(APPEND sdk_SOURCES
"shared/sdk/Globals.hpp"
"shared/sdk/Math.hpp"
"shared/sdk/RHICommandList.hpp"
"shared/sdk/ScriptMatrix.hpp"
"shared/sdk/ScriptVector.hpp"
"shared/sdk/Slate.hpp"
"shared/sdk/StereoStuff.hpp"
"shared/sdk/TArray.hpp"
Expand Down Expand Up @@ -437,6 +441,8 @@ list(APPEND sdk-nolog_SOURCES
"shared/sdk/FSceneView.cpp"
"shared/sdk/FViewportInfo.cpp"
"shared/sdk/Globals.cpp"
"shared/sdk/ScriptMatrix.cpp"
"shared/sdk/ScriptVector.cpp"
"shared/sdk/Slate.cpp"
"shared/sdk/StereoStuff.cpp"
"shared/sdk/UClass.cpp"
Expand Down Expand Up @@ -467,6 +473,8 @@ list(APPEND sdk-nolog_SOURCES
"shared/sdk/Globals.hpp"
"shared/sdk/Math.hpp"
"shared/sdk/RHICommandList.hpp"
"shared/sdk/ScriptMatrix.hpp"
"shared/sdk/ScriptVector.hpp"
"shared/sdk/Slate.hpp"
"shared/sdk/StereoStuff.hpp"
"shared/sdk/TArray.hpp"
Expand Down
5 changes: 3 additions & 2 deletions shared/sdk/AActor.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <vector>
#include "UObjectArray.hpp"
#include "ScriptVector.hpp"

#include "AActor.hpp"

Expand All @@ -11,7 +12,7 @@ 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 fvector = sdk::ScriptVector::static_struct();

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

Expand Down Expand Up @@ -45,7 +46,7 @@ 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 fvector = sdk::ScriptVector::static_struct();

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

Expand Down
12 changes: 12 additions & 0 deletions shared/sdk/ScriptMatrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "UObjectArray.hpp"

#include "ScriptMatrix.hpp"

namespace sdk {
UScriptStruct* ScriptMatrix::static_struct() {
static auto modern_class = sdk::find_uobject<UScriptStruct>(L"ScriptStruct /Script/CoreUObject.Matrix");
static auto old_class = sdk::find_uobject<UScriptStruct>(L"ScriptStruct /Script/CoreUObject.Object.Matrix");

return modern_class != nullptr ? modern_class : old_class;
}
}
12 changes: 12 additions & 0 deletions shared/sdk/ScriptMatrix.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "UClass.hpp"

namespace sdk {
class ScriptMatrix : public UObject {
public:
static UScriptStruct* static_struct();

protected:
};
}
12 changes: 12 additions & 0 deletions shared/sdk/ScriptVector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "UObjectArray.hpp"

#include "ScriptVector.hpp"

namespace sdk {
UScriptStruct* ScriptVector::static_struct() {
static auto modern_class = sdk::find_uobject<UScriptStruct>(L"ScriptStruct /Script/CoreUObject.Vector");
static auto old_class = sdk::find_uobject<UScriptStruct>(L"ScriptStruct /Script/CoreUObject.Object.Vector");

return modern_class != nullptr ? modern_class : old_class;
}
}
12 changes: 12 additions & 0 deletions shared/sdk/ScriptVector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "UClass.hpp"

namespace sdk {
class ScriptVector : public UObject {
public:
static UScriptStruct* static_struct();

protected:
};
}
10 changes: 6 additions & 4 deletions shared/sdk/UClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "FProperty.hpp"
#include "FField.hpp"
#include "FProperty.hpp"
#include "ScriptVector.hpp"
#include "ScriptMatrix.hpp"

#include "UClass.hpp"

Expand Down Expand Up @@ -43,8 +45,8 @@ void UField::update_offsets() {
}

void UStruct::resolve_field_offsets(uint32_t child_search_start) {
const auto matrix_scriptstruct = sdk::find_uobject(L"ScriptStruct /Script/CoreUObject.Matrix");
const auto vector_scriptstruct = sdk::find_uobject(L"ScriptStruct /Script/CoreUObject.Vector");
const auto matrix_scriptstruct = sdk::ScriptMatrix::static_struct();
const auto vector_scriptstruct = sdk::ScriptVector::static_struct();
const auto float_property = sdk::find_uobject(L"Class /Script/CoreUObject.FloatProperty");
const auto double_property = sdk::find_uobject(L"Class /Script/CoreUObject.DoubleProperty");

Expand Down Expand Up @@ -511,8 +513,8 @@ void UScriptStruct::update_offsets() {

SPDLOG_INFO("[UScriptStruct] Bruteforcing offsets...");

const auto matrix_scriptstruct = sdk::find_uobject(L"ScriptStruct /Script/CoreUObject.Matrix");
const auto vector_scriptstruct = sdk::find_uobject(L"ScriptStruct /Script/CoreUObject.Vector");
const auto matrix_scriptstruct = sdk::ScriptMatrix::static_struct();
const auto vector_scriptstruct = sdk::ScriptVector::static_struct();

if (matrix_scriptstruct == nullptr || vector_scriptstruct == nullptr) {
SPDLOG_ERROR("[UScriptStruct] Failed to find Matrix/Vector!");
Expand Down

0 comments on commit 95e0287

Please sign in to comment.