Skip to content

Commit

Permalink
UObjectHook: Add APlayerCameraManager to commmon objects
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Oct 26, 2023
1 parent c52d818 commit 77c8d90
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 2 deletions.
80 changes: 79 additions & 1 deletion shared/sdk/APlayerController.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,85 @@
#include <sdk/Math.hpp>

#include <vector>
#include "UObjectArray.hpp"
#include "ScriptVector.hpp"
#include "ScriptRotator.hpp"
#include "FProperty.hpp"

#include "APlayerController.hpp"

namespace sdk {
UClass* AController::static_class() {
return sdk::find_uobject<UClass>(L"Class /Script/Engine.Controller");
}

void AController::set_control_rotation(const glm::vec3& newrotation) {
static const auto func = static_class()->find_function(L"SetControlRotation");
const auto frotator = sdk::ScriptRotator::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*)&newrotation, (uint8_t*)&newrotation + sizeof(glm::vec3));
} else {
glm::vec<3, double> rot = newrotation;
params.insert(params.end(), (uint8_t*)&rot, (uint8_t*)&rot + sizeof(glm::vec<3, double>));
}

this->process_event(func, params.data());
}

glm::vec3 AController::get_control_rotation() {
static const auto func = static_class()->find_function(L"GetControlRotation");
const auto frotator = sdk::ScriptVector::static_struct();

const auto is_ue5 = frotator->get_struct_size() == sizeof(glm::vec<3, double>);
std::vector<uint8_t> 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.data());

if (!is_ue5) {
return *(glm::vec3*)params.data();
}
return *(glm::vec<3, double>*)params.data();
}

UClass* APlayerController::static_class() {
return sdk::find_uobject<UClass>(L"Class /Script/Engine.PlayerController");
}

APawn* APlayerController::get_acknowledged_pawn() const {
return get_property<APawn*>(L"AcknowledgedPawn");
}
}

APlayerCameraManager* APlayerController::get_player_camera_manager() const {
return get_property<APlayerCameraManager*>(L"PlayerCameraManager");
}

void APlayerController::add_rotation_input(const glm::vec3& rotation) {
//static const auto field = static_class()->find_property(L"RotationInput");
const auto frotator = sdk::ScriptRotator::static_struct();
const auto is_ue5 = frotator->get_struct_size() == sizeof(glm::vec<3, double>);

//if (field == nullptr) {
//return;
//}

static const auto nc_field = static_class()->find_property(L"NetConnection");

if (is_ue5) {
*(glm::vec<3, double>*)((uintptr_t)this + nc_field->get_offset() + sizeof(void*)) += glm::vec<3, double>{rotation};
} else {
*(glm::vec3*)((uintptr_t)this + nc_field->get_offset() + sizeof(void*)) += rotation;
}
}
}
19 changes: 18 additions & 1 deletion shared/sdk/APlayerController.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
#pragma once

#include <sdk/Math.hpp>

#include "UObject.hpp"

namespace sdk {
class APawn;
class APlayerCameraManager;

class AController : public UObject {
public:
static UClass* static_class();

void set_control_rotation(const glm::vec3& newrotation);
glm::vec3 get_control_rotation();

class APlayerController : public UObject {
protected:
};

class APlayerController : public AController {
public:
static UClass* static_class();

APawn* get_acknowledged_pawn() const;
APlayerCameraManager* get_player_camera_manager() const;
void add_rotation_input(const glm::vec3& rotation);

protected:
};
Expand Down
20 changes: 20 additions & 0 deletions src/mods/UObjectHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,26 @@ void UObjectHook::on_draw_ui() {
} else {
ImGui::Text("No pawn");
}
} else {
ImGui::Text("No player controller");
}

ImGui::TreePop();
}

if (ImGui::TreeNode("Camera Manager")) {
auto player_controller = sdk::UGameplayStatics::get()->get_player_controller(world, 0);

if (player_controller != nullptr) {
auto camera_manager = player_controller->get_player_camera_manager();

if (camera_manager != nullptr) {
ui_handle_object((sdk::UObject*)camera_manager);
} else {
ImGui::Text("No camera manager");
}
} else {
ImGui::Text("No player controller");
}

ImGui::TreePop();
Expand Down

0 comments on commit 77c8d90

Please sign in to comment.