diff --git a/shared/sdk/APlayerController.cpp b/shared/sdk/APlayerController.cpp index 01944a5c..e805e4e1 100644 --- a/shared/sdk/APlayerController.cpp +++ b/shared/sdk/APlayerController.cpp @@ -1,7 +1,85 @@ +#include + +#include +#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(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 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 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(L"Class /Script/Engine.PlayerController"); +} + APawn* APlayerController::get_acknowledged_pawn() const { return get_property(L"AcknowledgedPawn"); } -} \ No newline at end of file + +APlayerCameraManager* APlayerController::get_player_camera_manager() const { + return get_property(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; + } +} +} diff --git a/shared/sdk/APlayerController.hpp b/shared/sdk/APlayerController.hpp index 2dd4a5fd..d871ccc3 100644 --- a/shared/sdk/APlayerController.hpp +++ b/shared/sdk/APlayerController.hpp @@ -1,13 +1,30 @@ #pragma once +#include + #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: }; diff --git a/src/mods/UObjectHook.cpp b/src/mods/UObjectHook.cpp index d458384e..15ee9efe 100644 --- a/src/mods/UObjectHook.cpp +++ b/src/mods/UObjectHook.cpp @@ -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();