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

View File

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

View File

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