Update hook debugger to pull from GameInteractor ptrs rather than cloning the data every frame (#4609)

This commit is contained in:
Garrett Cox 2024-12-03 10:44:18 -06:00 committed by GitHub
parent 82d70a2029
commit 291561667b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 11 deletions

View File

@ -4,14 +4,14 @@
#include <string>
#include <version>
static std::unordered_map<const char*, std::unordered_map<HOOK_ID, HookInfo>> hookData;
static std::unordered_map<const char*, std::unordered_map<HOOK_ID, HookInfo>*> hookData;
const ImVec4 grey = ImVec4(0.75, 0.75, 0.75, 1);
const ImVec4 yellow = ImVec4(1, 1, 0, 1);
const ImVec4 red = ImVec4(1, 0, 0, 1);
void DrawHookRegisteringInfos(const char* hookName) {
if (hookData[hookName].size() == 0) {
if ((*hookData[hookName]).size() == 0) {
ImGui::TextColored(grey, "No hooks found");
return;
}
@ -27,7 +27,7 @@ void DrawHookRegisteringInfos(const char* hookName) {
//ImGui::TableSetupColumn("Stub");
ImGui::TableSetupColumn("Number of Calls");
ImGui::TableHeadersRow();
for (auto& [id, hookInfo] : hookData[hookName]) {
for (auto& [id, hookInfo] : (*hookData[hookName])) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
@ -100,12 +100,10 @@ void HookDebuggerWindow::DrawElement() {
}
}
void HookDebuggerWindow::UpdateElement() {
hookData.clear();
void HookDebuggerWindow::InitElement() {
#define DEFINE_HOOK(name, _) hookData.insert({#name, GameInteractor::Instance->GetHookData<GameInteractor::name>()});
#include "../game-interactor/GameInteractor_HookTable.h"
#undef DEFINE_HOOK
}
}

View File

@ -4,7 +4,7 @@ class HookDebuggerWindow : public Ship::GuiWindow {
public:
using GuiWindow::GuiWindow;
void InitElement() override {};
void InitElement() override;
void DrawElement() override;
void UpdateElement() override;
void UpdateElement() override {};
};

View File

@ -641,8 +641,8 @@ public:
inline static std::vector<HOOK_ID> hooksForFilter;
};
template <typename H> std::unordered_map<uint32_t, HookInfo> GetHookData() {
return RegisteredGameHooks<H>::hookData;
template <typename H> std::unordered_map<uint32_t, HookInfo>* GetHookData() {
return &RegisteredGameHooks<H>::hookData;
}
// General Hooks