Skip to content

Commit

Permalink
UObjectHook: Add ArrayProperty support (ObjectProperty only)
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Oct 28, 2023
1 parent 5c65ef9 commit 226b798
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
8 changes: 8 additions & 0 deletions shared/sdk/TArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ struct TArray {
return data + count;
}

T* begin() const {
return data;
}

T* end() const {
return data + count;
}

// operator[]
T& operator[](int32_t index) {
return data[index];
Expand Down
57 changes: 57 additions & 0 deletions src/mods/UObjectHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <sdk/APawn.hpp>
#include <sdk/ScriptVector.hpp>
#include <sdk/FBoolProperty.hpp>
#include <sdk/FObjectProperty.hpp>
#include <sdk/FArrayProperty.hpp>

#include "VR.hpp"

Expand Down Expand Up @@ -1393,6 +1395,13 @@ void UObjectHook::ui_handle_properties(void* object, sdk::UStruct* uclass) {
}
break;
case "Function"_fnv:
break;
case "ArrayProperty"_fnv:
if (ImGui::TreeNode(utility::narrow(prop->get_field_name().to_string()).data())) {
ui_handle_array_property(object, (sdk::FArrayProperty*)prop);
ImGui::TreePop();
}

break;
default:
{
Expand All @@ -1405,6 +1414,54 @@ void UObjectHook::ui_handle_properties(void* object, sdk::UStruct* uclass) {
}
}

void UObjectHook::ui_handle_array_property(void* addr, sdk::FArrayProperty* prop) {
if (addr == nullptr || prop == nullptr) {
return;
}

const auto& array_generic = *(sdk::TArray<void*>*)((uintptr_t)addr + prop->get_offset());

if (array_generic.data == nullptr || array_generic.count == 0) {
return;
}

const auto inner = prop->get_inner();

if (inner == nullptr) {
return;
}

const auto inner_c = inner->get_class();

if (inner_c == nullptr) {
return;
}

const auto inner_c_type = utility::narrow(inner_c->get_name().to_string());

switch (utility::hash(inner_c_type)) {
case "ObjectProperty"_fnv:
{
const auto& array_obj = *(sdk::TArray<sdk::UObject*>*)((uintptr_t)addr + prop->get_offset());

for (auto obj : array_obj) {
std::wstring name = obj->get_class()->get_fname().to_string() + L" " + obj->get_fname().to_string();

if (ImGui::TreeNode(utility::narrow(name).data())) {
ui_handle_object(obj);
ImGui::TreePop();
}
}

break;
}

default:
ImGui::Text("Array of %s (unsupported)", inner_c_type.data());
break;
};
}

void UObjectHook::ui_handle_struct(void* addr, sdk::UStruct* uclass) {
if (uclass == nullptr) {
return;
Expand Down
2 changes: 2 additions & 0 deletions src/mods/UObjectHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class UScriptStruct;
class USceneComponent;
class UActorComponent;
class AActor;
class FArrayProperty;
}

class UObjectHook : public Mod {
Expand Down Expand Up @@ -60,6 +61,7 @@ class UObjectHook : public Mod {

void ui_handle_object(sdk::UObject* object);
void ui_handle_properties(void* object, sdk::UStruct* definition);
void ui_handle_array_property(void* object, sdk::FArrayProperty* definition);
void ui_handle_functions(void* object, sdk::UStruct* definition);
void ui_handle_struct(void* addr, sdk::UStruct* definition);

Expand Down

0 comments on commit 226b798

Please sign in to comment.