Skip to content

Commit

Permalink
UObjectHook: Fix crash in destructor hook
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Nov 9, 2023
1 parent 762d963 commit 7734c8f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/mods/UObjectHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,7 @@ void UObjectHook::ui_handle_scene_component(sdk::USceneComponent* comp) {

// Create a name based on the first and last part of the path
const auto name = path.front() + "_" + path.back() + "_mc_state.json";
const auto wanted_dir = Framework::get_persistent_dir() / "uobjecthook" / name;
const auto wanted_dir = UObjectHook::get_persistent_dir() / name;

// Create dir if necessary
std::filesystem::create_directories(wanted_dir.parent_path());
Expand Down Expand Up @@ -2194,8 +2194,16 @@ void* UObjectHook::destructor(sdk::UObjectBase* object, void* rdx, void* r8, voi
hook->m_overlap_detection_actor_left = nullptr;
}

for (auto super = (sdk::UStruct*)it->second->uclass; super != nullptr; super = super->get_super_struct()) {
for (auto super = (sdk::UStruct*)it->second->uclass; super != nullptr;) {
hook->m_objects_by_class[(sdk::UClass*)super].erase(object);

// Just make sure we don't do any operations on super because it might be invalid...
if (!hook->m_objects.contains(super)) {
//SPDLOG_ERROR("Super for {:x} is not valid", (uintptr_t)object);
break;
}

super = super->get_super_struct();
}

//hook->m_objects_by_class[it->second->uclass].erase(object);
Expand Down

0 comments on commit 7734c8f

Please sign in to comment.