Skip to content

Commit

Permalink
SDK: Forgot to add UCamera/SceneComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Oct 22, 2023
1 parent 9c482b1 commit 383450b
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions shared/sdk/UCameraComponent.cpp
Original file line number Diff line number Diff line change
@@ -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<UClass>(L"Class /Script/Engine.CameraComponent");
}
};
12 changes: 12 additions & 0 deletions shared/sdk/UCameraComponent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "UObject.hpp"

#include "USceneComponent.hpp"

namespace sdk {
class UCameraComponent : public USceneComponent {
public:
static UClass* static_class();
};
}
83 changes: 83 additions & 0 deletions shared/sdk/USceneComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <sdk/Math.hpp>

#include <vector>
#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<UClass>(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<UScriptStruct>(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<uint8_t> 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<UScriptStruct>(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<uint8_t> 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());
}
}
16 changes: 16 additions & 0 deletions shared/sdk/USceneComponent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <sdk/Math.hpp>

#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);
};
}

0 comments on commit 383450b

Please sign in to comment.