Skip to content

Commit

Permalink
Update hook debugger to pull from GameInteractor ptrs rather than clo…
Browse files Browse the repository at this point in the history
…ning the data every frame
  • Loading branch information
garrettjoecox committed Dec 3, 2024
1 parent bbe3bb7 commit b948f10
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
12 changes: 5 additions & 7 deletions soh/soh/Enhancements/debugger/hookDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
Expand Down Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions soh/soh/Enhancements/debugger/hookDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
};
4 changes: 2 additions & 2 deletions soh/soh/Enhancements/game-interactor/GameInteractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,8 @@ class GameInteractor {
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
Expand Down

0 comments on commit b948f10

Please sign in to comment.