Skip to content

Commit

Permalink
ObjectExplorer: Fix types/singletons showing up more than once
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Nov 1, 2024
1 parent 368bf84 commit 257bee3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
10 changes: 5 additions & 5 deletions shared/sdk/REGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ REGlobals::REGlobals() {
}

m_objects.insert(obj_ptr);
m_object_list.push_back(obj_ptr);
m_object_list.insert(obj_ptr);
} catch(...) {

}
Expand Down Expand Up @@ -111,21 +111,21 @@ REGlobals::REGlobals() {
spdlog::info("Finished REGlobals initialization");
}

std::vector<REManagedObject*> REGlobals::get_objects() {
std::vector<REManagedObject*> out{};
std::unordered_set<REManagedObject*> REGlobals::get_objects() {
std::unordered_set<REManagedObject*> out{};

if (!m_object_list.empty()) {
for (auto obj_ptr : m_object_list) {
if (*obj_ptr != nullptr && !IsBadReadPtr(*obj_ptr, sizeof(void*))) {
out.push_back(*obj_ptr);
out.insert(*obj_ptr);
}
}
} else {
for (auto getter : m_getters) {
auto result = getter.second();

if (result != nullptr) {
out.push_back(result);
out.insert(result);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions shared/sdk/REGlobals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class REGlobals {
return m_objects;
}

std::vector<REManagedObject*> get_objects();
std::unordered_set<REManagedObject*> get_objects();

REType* get_native(std::string_view name);
std::vector<::REType*>& get_native_singleton_types();
Expand All @@ -45,7 +45,7 @@ class REGlobals {

// Raw list of objects (for if the type hasn't been fully initialized, we need to refresh the map)
std::unordered_set<REManagedObject**> m_objects;
std::vector<REManagedObject**> m_object_list;
std::unordered_set<REManagedObject**> m_object_list;
std::unordered_map<std::string, std::function<REManagedObject* ()>> m_getters;

// List of objects we've already logged
Expand Down
13 changes: 10 additions & 3 deletions src/mods/tools/ObjectExplorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ void ObjectExplorer::on_draw_dev_ui() {
}

// make a copy, we want to sort by name
auto singletons = reframework::get_globals()->get_objects();
auto singletons_unordered = reframework::get_globals()->get_objects();
std::vector<REManagedObject*> singletons{ singletons_unordered.begin(), singletons_unordered.end() };

// first loop, sort
std::sort(singletons.begin(), singletons.end(), [](REManagedObject* a, REManagedObject* b) {
Expand Down Expand Up @@ -4253,6 +4254,8 @@ void ObjectExplorer::populate_classes() {
auto type_list = reframework::get_types()->get_raw_types();
spdlog::info("TypeList: {:x}", (uintptr_t)type_list);

std::unordered_set<REType*> seen{};

if (type_list != nullptr) try {
// I don't know why but it can extend past the size.
for (auto i = 0; i < type_list->numAllocated; ++i) {
Expand All @@ -4266,6 +4269,10 @@ void ObjectExplorer::populate_classes() {
continue;
}

if (seen.contains(t)) {
continue;
}

auto name = std::string{ t->name };

if (name.empty()) {
Expand All @@ -4275,6 +4282,8 @@ void ObjectExplorer::populate_classes() {
spdlog::info("{:s}", name);
m_sorted_types.push_back(name);
m_types[name] = t;

seen.insert(t);
}

std::sort(m_sorted_types.begin(), m_sorted_types.end());
Expand All @@ -4285,8 +4294,6 @@ void ObjectExplorer::populate_classes() {

auto tdb = sdk::RETypeDB::get();

std::unordered_set<REType*> seen{};

if (tdb != nullptr) {
for (auto i = 0; i < tdb->get_num_types(); ++i) {
const auto t = tdb->get_type(i);
Expand Down

0 comments on commit 257bee3

Please sign in to comment.