diff --git a/CMakeLists.txt b/CMakeLists.txt index 57e181e5..e6796a4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -335,6 +335,7 @@ list(APPEND sdk_SOURCES "shared/sdk/ScriptVector.cpp" "shared/sdk/Slate.cpp" "shared/sdk/StereoStuff.cpp" + "shared/sdk/UCameraComponent.cpp" "shared/sdk/UClass.cpp" "shared/sdk/UEngine.cpp" "shared/sdk/UEnum.cpp" @@ -346,6 +347,7 @@ list(APPEND sdk_SOURCES "shared/sdk/UObjectArray.cpp" "shared/sdk/UObjectBase.cpp" "shared/sdk/UProperty.cpp" + "shared/sdk/USceneComponent.cpp" "shared/sdk/Utility.cpp" "shared/sdk/AActor.hpp" "shared/sdk/APawn.hpp" @@ -371,6 +373,7 @@ list(APPEND sdk_SOURCES "shared/sdk/Slate.hpp" "shared/sdk/StereoStuff.hpp" "shared/sdk/TArray.hpp" + "shared/sdk/UCameraComponent.hpp" "shared/sdk/UClass.hpp" "shared/sdk/UEngine.hpp" "shared/sdk/UEnum.hpp" @@ -382,6 +385,7 @@ list(APPEND sdk_SOURCES "shared/sdk/UObjectArray.hpp" "shared/sdk/UObjectBase.hpp" "shared/sdk/UProperty.hpp" + "shared/sdk/USceneComponent.hpp" "shared/sdk/UWorld.hpp" "shared/sdk/Utility.hpp" "shared/sdk/threading/GameThreadWorker.hpp" @@ -455,6 +459,7 @@ list(APPEND sdk-nolog_SOURCES "shared/sdk/ScriptVector.cpp" "shared/sdk/Slate.cpp" "shared/sdk/StereoStuff.cpp" + "shared/sdk/UCameraComponent.cpp" "shared/sdk/UClass.cpp" "shared/sdk/UEngine.cpp" "shared/sdk/UEnum.cpp" @@ -466,6 +471,7 @@ list(APPEND sdk-nolog_SOURCES "shared/sdk/UObjectArray.cpp" "shared/sdk/UObjectBase.cpp" "shared/sdk/UProperty.cpp" + "shared/sdk/USceneComponent.cpp" "shared/sdk/Utility.cpp" "shared/sdk/AActor.hpp" "shared/sdk/APawn.hpp" @@ -491,6 +497,7 @@ list(APPEND sdk-nolog_SOURCES "shared/sdk/Slate.hpp" "shared/sdk/StereoStuff.hpp" "shared/sdk/TArray.hpp" + "shared/sdk/UCameraComponent.hpp" "shared/sdk/UClass.hpp" "shared/sdk/UEngine.hpp" "shared/sdk/UEnum.hpp" @@ -502,6 +509,7 @@ list(APPEND sdk-nolog_SOURCES "shared/sdk/UObjectArray.hpp" "shared/sdk/UObjectBase.hpp" "shared/sdk/UProperty.hpp" + "shared/sdk/USceneComponent.hpp" "shared/sdk/UWorld.hpp" "shared/sdk/Utility.hpp" "shared/sdk/threading/GameThreadWorker.hpp" diff --git a/shared/sdk/UCameraComponent.cpp b/shared/sdk/UCameraComponent.cpp new file mode 100644 index 00000000..eba81089 --- /dev/null +++ b/shared/sdk/UCameraComponent.cpp @@ -0,0 +1,12 @@ +#include "UObjectArray.hpp" +#include "ScriptVector.hpp" +#include "ScriptRotator.hpp" +#include "FProperty.hpp" + +#include "UCameraComponent.hpp" + +namespace sdk { +UClass* UCameraComponent::static_class() { + return sdk::find_uobject(L"Class /Script/Engine.CameraComponent"); +} +}; \ No newline at end of file diff --git a/shared/sdk/UCameraComponent.hpp b/shared/sdk/UCameraComponent.hpp new file mode 100644 index 00000000..941cf72d --- /dev/null +++ b/shared/sdk/UCameraComponent.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "UObject.hpp" + +#include "USceneComponent.hpp" + +namespace sdk { +class UCameraComponent : public USceneComponent { +public: + static UClass* static_class(); +}; +} \ No newline at end of file diff --git a/shared/sdk/USceneComponent.cpp b/shared/sdk/USceneComponent.cpp new file mode 100644 index 00000000..dada7a40 --- /dev/null +++ b/shared/sdk/USceneComponent.cpp @@ -0,0 +1,83 @@ +#include + +#include +#include "UObjectArray.hpp" +#include "ScriptVector.hpp" +#include "ScriptRotator.hpp" +#include "FProperty.hpp" + +#include "USceneComponent.hpp" + +namespace sdk { +UClass* USceneComponent::static_class() { + return sdk::find_uobject(L"Class /Script/Engine.SceneComponent"); +} + +void USceneComponent::set_world_rotation(const glm::vec3& rotation, bool sweep, bool teleport) { + static auto fn = static_class()->find_function(L"K2_SetWorldRotation"); + static const auto fhitresult = sdk::find_uobject(L"ScriptStruct /Script/Engine.HitResult"); + + if (fn == nullptr) { + return; + } + + const auto frotator = sdk::ScriptVector::static_struct(); + const auto is_ue5 = frotator->get_struct_size() == sizeof(glm::vec<3, double>); + + // Need to dynamically allocate the params because of unknown FRotator size + std::vector params{}; + + // add a vec3 + if (!is_ue5) { + params.insert(params.end(), (uint8_t*)&rotation, (uint8_t*)&rotation + sizeof(glm::vec3)); + } else { + glm::vec<3, double> rot = rotation; + params.insert(params.end(), (uint8_t*)&rot, (uint8_t*)&rot + sizeof(glm::vec<3, double>)); + } + + // add a bool + params.insert(params.end(), (uint8_t*)&teleport, (uint8_t*)&sweep + sizeof(bool)); + // align + params.insert(params.end(), 3, 0); + // add a FHitResult + params.insert(params.end(), fhitresult->get_struct_size(), 0); + // add a bool + params.insert(params.end(), (uint8_t*)&teleport, (uint8_t*)&teleport + sizeof(bool)); + + this->process_event(fn, params.data()); +} + +void USceneComponent::add_world_rotation(const glm::vec3& rotation, bool sweep, bool teleport) { + static auto fn = static_class()->find_function(L"K2_AddWorldRotation"); + static const auto fhitresult = sdk::find_uobject(L"ScriptStruct /Script/Engine.HitResult"); + + if (fn == nullptr) { + return; + } + + const auto frotator = sdk::ScriptVector::static_struct(); + const auto is_ue5 = frotator->get_struct_size() == sizeof(glm::vec<3, double>); + + // Need to dynamically allocate the params because of unknown FRotator size + std::vector params{}; + + // add a vec3 + if (!is_ue5) { + params.insert(params.end(), (uint8_t*)&rotation, (uint8_t*)&rotation + sizeof(glm::vec3)); + } else { + glm::vec<3, double> rot = rotation; + params.insert(params.end(), (uint8_t*)&rot, (uint8_t*)&rot + sizeof(glm::vec<3, double>)); + } + + // add a bool + params.insert(params.end(), (uint8_t*)&teleport, (uint8_t*)&sweep + sizeof(bool)); + // align + params.insert(params.end(), 3, 0); + // add a FHitResult + params.insert(params.end(), fhitresult->get_struct_size(), 0); + // add a bool + params.insert(params.end(), (uint8_t*)&teleport, (uint8_t*)&teleport + sizeof(bool)); + + this->process_event(fn, params.data()); +} +} \ No newline at end of file diff --git a/shared/sdk/USceneComponent.hpp b/shared/sdk/USceneComponent.hpp new file mode 100644 index 00000000..2f057f3d --- /dev/null +++ b/shared/sdk/USceneComponent.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include + +#include "UObject.hpp" + +namespace sdk { +class USceneComponent : public UObject { +public: + static UClass* static_class(); + +public: + void set_world_rotation(const glm::vec3& rotation, bool sweep = false, bool teleport = false); + void add_world_rotation(const glm::vec3& rotation, bool sweep = false, bool teleport = false); +}; +} \ No newline at end of file