Skip to content

Commit

Permalink
Lua/UObjectHook: Add support for InterfaceProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Oct 10, 2024
1 parent 8878b2e commit a178738
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lua-api/lib/src/ScriptUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ sol::object prop_to_object(sol::this_state s, void* self, uevr::API::FProperty*
}
case L"NameProperty"_fnv:
return sol::make_object(s, *(uevr::API::FName*)((uintptr_t)self + offset));
case L"InterfaceProperty"_fnv:
case L"ObjectProperty"_fnv:
if (*(uevr::API::UObject**)((uintptr_t)self + offset) == nullptr) {
return sol::make_object(s, sol::lua_nil);
Expand Down Expand Up @@ -192,6 +193,7 @@ sol::object prop_to_object(sol::this_state s, void* self, uevr::API::FProperty*
const auto inner_name_hash = ::utility::hash(inner_c->get_fname()->to_string());

switch (inner_name_hash) {
case L"InterfaceProperty"_fnv:
case L"ObjectProperty"_fnv:
{
const auto& arr = *(uevr::API::TArray<uevr::API::UObject*>*)((uintptr_t)self + offset);
Expand Down Expand Up @@ -371,6 +373,7 @@ void set_property(sol::this_state s, void* self, uevr::API::UStruct* owner_c, ue
}

return;
case L"InterfaceProperty"_fnv:
case L"ObjectProperty"_fnv:
*(uevr::API::UObject**)((uintptr_t)self + offset) = value.as<uevr::API::UObject*>();
return;
Expand Down Expand Up @@ -544,6 +547,7 @@ sol::object call_function(sol::this_state s, uevr::API::UObject* self, uevr::API
const auto inner_name_hash = ::utility::hash(inner_c->get_fname()->to_string());

switch (inner_name_hash) {
case L"InterfaceProperty"_fnv:
case L"ObjectProperty"_fnv:
{
const auto arg_obj = args[args_index++];
Expand Down Expand Up @@ -614,7 +618,7 @@ sol::object call_function(sol::this_state s, uevr::API::UObject* self, uevr::API
auto tbl = args[arg_index].as<sol::lua_table>();
if (prop_name_hash == L"ClassProperty"_fnv) {
tbl["result"] = (uevr::API::UClass*)*(uevr::API::UClass**)((uintptr_t)params.data() + prop->get_offset());
} else if (prop_name_hash == L"ObjectProperty"_fnv) {
} else if (prop_name_hash == L"ObjectProperty"_fnv || prop_name_hash == L"InterfaceProperty"_fnv) {
tbl["result"] = (uevr::API::UObject*)*(uevr::API::UObject**)((uintptr_t)params.data() + prop->get_offset());
} else if (prop_name_hash == L"ArrayProperty"_fnv) {
const auto tbl_was_empty = tbl.empty();
Expand All @@ -635,7 +639,7 @@ sol::object call_function(sol::this_state s, uevr::API::UObject* self, uevr::API

const auto inner_name_hash = ::utility::hash(inner_c->get_fname()->to_string());

if (inner_name_hash == L"ObjectProperty"_fnv) {
if (inner_name_hash == L"ObjectProperty"_fnv || inner_name_hash == L"InterfaceProperty"_fnv) {
for (size_t i = 0; i < arr.count; ++i) {
tbl[i + 1] = arr.data[i];
}
Expand Down Expand Up @@ -687,6 +691,7 @@ sol::object call_function(sol::this_state s, uevr::API::UObject* self, uevr::API
const auto inner_name_hash = ::utility::hash(inner_c->get_fname()->to_string());

switch (inner_name_hash) {
case L"InterfaceProperty"_fnv:
case L"ObjectProperty"_fnv:
{
//printf("ArrayProperty<ObjectProperty> cleanup\n");
Expand Down
5 changes: 4 additions & 1 deletion src/mods/UObjectHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,7 @@ UObjectHook::ResolvedObject UObjectHook::StatePath::resolve() const {

const auto prop_t_name = prop_t->get_name().to_string();
switch (utility::hash(utility::narrow(prop_t_name))) {
case "InterfaceProperty"_fnv:
case "ObjectProperty"_fnv:
{
const auto obj_ptr = prop_desc->get_data<sdk::UObject*>(previous_data);
Expand Down Expand Up @@ -1699,7 +1700,7 @@ UObjectHook::ResolvedObject UObjectHook::StatePath::resolve() const {
const auto inner_c_type = utility::narrow(inner_c->get_name().to_string());

// only support ObjectProperty for now
if (inner_c_type != "ObjectProperty") {
if (inner_c_type != "ObjectProperty" && inner_c_type != "InterfaceProperty") {
return nullptr;
}

Expand Down Expand Up @@ -3376,6 +3377,7 @@ void UObjectHook::ui_handle_properties(void* object, sdk::UStruct* uclass) {
display_context(value);
}
break;
case "InterfaceProperty"_fnv:
case "ObjectProperty"_fnv:
{
auto& value = *(sdk::UObject**)((uintptr_t)object + ((sdk::FProperty*)prop)->get_offset());
Expand Down Expand Up @@ -3479,6 +3481,7 @@ void UObjectHook::ui_handle_array_property(void* addr, sdk::FArrayProperty* prop
const auto inner_c_type = utility::narrow(inner_c->get_name().to_string());

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

0 comments on commit a178738

Please sign in to comment.