Skip to content

Commit

Permalink
UObjectHook: Fallback method of resolving paths from invalid base
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Nov 29, 2023
1 parent 4e98f6a commit 221a73d
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/mods/UObjectHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,73 @@ void UObjectHook::ui_handle_scene_component(sdk::USceneComponent* comp) {
}
}

// Try to look through the objects' properties instead now.
if (!found_any) {
for (const auto& allowed_base : s_allowed_bases) {
const auto base_obj = StatePath{{allowed_base}}.resolve_base_object();

if (base_obj == nullptr) {
continue;
}

for (auto field = base_obj->get_class()->get_child_properties(); field != nullptr; field = field->get_next()) {
if (field->get_class()->get_name().to_string() != L"ObjectProperty") {
continue;
}

const auto prop = (sdk::FObjectProperty*)field;
const auto obj_ptr = prop->get_data<sdk::UObject*>(base_obj);

if (obj_ptr == nullptr || *obj_ptr == nullptr) {
continue;
}

const auto obj = *obj_ptr;

if (obj == comp) {
const auto possible_path = std::vector<std::string>{allowed_base, "Properties", utility::narrow(field->get_field_name().to_string())};
const auto path = StatePath{possible_path};
const auto resolved = path.resolve();

if (resolved == comp) {
if (ImGui::Button("Save state")) {
save_state_logic(path.path());
}

found_any = true;
break;
}

break;
}

// Traverse that object's components now and see if we can find it there.
if (obj->get_class()->is_a(sdk::AActor::static_class())) {
const auto actor = (sdk::AActor*)*obj_ptr;

for (auto actor_comp : actor->get_all_components()) {
if (actor_comp != comp) {
continue;
}

const auto possible_path = std::vector<std::string>{allowed_base, "Properties", utility::narrow(field->get_field_name().to_string()), "Components", component_name};
const auto path = StatePath{possible_path};
const auto resolved = path.resolve();

if (resolved == comp) {
if (ImGui::Button("Save state")) {
save_state_logic(path.path());
}

found_any = true;
break;
}
}
}
}
}
}

if (!found_any) {
ImGui::Text("Can't save, did not start from a valid base or none of the allowed bases can reach this component");
}
Expand Down

0 comments on commit 221a73d

Please sign in to comment.