Skip to content

Commit

Permalink
ObjectExplorer: Add "DUPLICATE" method tag (do not hook these funcs)
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Aug 17, 2022
1 parent 5eff4e7 commit 7145dbd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
16 changes: 16 additions & 0 deletions shared/sdk/RETypeDB.hpp
Expand Up @@ -743,6 +743,22 @@ struct RETypeDB : public sdk::RETypeDB_ {
sdk::REField* get_field(uint32_t index) const;
sdk::REProperty* get_property(uint32_t index) const;

uint32_t get_num_types() const {
return numTypes;
}

uint32_t get_num_methods() const {
return numMethods;
}

uint32_t get_num_fields() const {
return numFields;
}

uint32_t get_num_properties() const {
return numProperties;
}

const char* get_string(uint32_t offset) const;
uint8_t* get_bytes(uint32_t offset) const;

Expand Down
41 changes: 39 additions & 2 deletions src/mods/tools/ObjectExplorer.cpp
Expand Up @@ -336,8 +336,7 @@ void ObjectExplorer::on_draw_dev_ui() {
ImGui::SetNextTreeNodeOpen(false, ImGuiCond_::ImGuiCond_Once);

if (m_do_init) {
populate_classes();
populate_enums();
init();
}

if (!m_do_init && !ImGui::CollapsingHeader(get_name().data())) {
Expand Down Expand Up @@ -2031,6 +2030,12 @@ void ObjectExplorer::report_sdk_dump_progress(float progress) {
}

void ObjectExplorer::handle_address(Address address, int32_t offset, Address parent, Address real_address) {
// Because this can be called from Lua.
if (m_do_init) {
init();
m_do_init = false;
}

if (!is_managed_object(address)) {
return;
}
Expand Down Expand Up @@ -2969,6 +2974,13 @@ void ObjectExplorer::display_native_methods(REManagedObject* obj, sdk::RETypeDef
ImGui::TextColored(ImVec4{ 1.0f, 0.0f, 0.0f, 1.0f }, "STUB");
}

bool is_duplicate = m_function_occurrences[method_ptr] > 5;

if (is_duplicate) {
ImGui::SameLine();
ImGui::TextColored(ImVec4{ 1.0f, 0.0f, 0.0f, 1.0f }, "DUPLICATE");
}

// draw the method data
if (made_node) {
if (ImGui::BeginTable("##method", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable)) {
Expand Down Expand Up @@ -3897,6 +3909,31 @@ void ObjectExplorer::populate_enums() {
#endif
}

void ObjectExplorer::init() {
populate_classes();
populate_enums();

if (m_function_occurrences.empty()) {
const auto tdb = sdk::RETypeDB::get();

for (auto i = 0; i < tdb->get_num_methods(); ++i) {
const auto method = tdb->get_method(i);

if (method == nullptr) {
continue;
}

const auto func = method->get_function();

if (func == nullptr) {
continue;
}

m_function_occurrences[func]++;
}
}
}

std::string ObjectExplorer::get_full_enum_value_name(std::string_view enum_name, int64_t value) {
std::string out{};

Expand Down
2 changes: 2 additions & 0 deletions src/mods/tools/ObjectExplorer.hpp
Expand Up @@ -185,6 +185,7 @@ class ObjectExplorer : public Tool {

void populate_classes();
void populate_enums();
void init();

std::string get_full_enum_value_name(std::string_view enum_name, int64_t value);
std::string get_enum_value_name(std::string_view enum_name, int64_t value);
Expand Down Expand Up @@ -267,6 +268,7 @@ class ObjectExplorer : public Tool {

std::unordered_set<void*> m_known_stub_methods{};
std::unordered_set<void*> m_ok_methods{};
std::unordered_map<void*, uint32_t> m_function_occurrences{}; // occurrences of re-uses of the function address in other methods
std::unordered_multimap<std::string, EnumDescriptor> m_enums;
std::unordered_map<std::string, REType*> m_types;
std::vector<std::string> m_sorted_types;
Expand Down

0 comments on commit 7145dbd

Please sign in to comment.