mirror of
https://github.com/HarbourMasters/Shipwright
synced 2026-07-09 23:02:15 -04:00
Hook unregister fixes and hook debugger tweaks (#5139)
* clang-format before * Hook unregister fixes and hook debugger tweaks
This commit is contained in:
@@ -4,28 +4,29 @@
|
||||
#include <string>
|
||||
#include <version>
|
||||
|
||||
static std::unordered_map<const char*, std::unordered_map<HOOK_ID, HookInfo>*> hookData;
|
||||
static std::map<const char*, std::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) {
|
||||
size_t numHooks = (*hookData[hookName]).size();
|
||||
|
||||
if (numHooks == 0) {
|
||||
ImGui::TextColored(grey, "No hooks found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ImGui::BeginTable(
|
||||
("Table##" + std::string(hookName)).c_str(),
|
||||
4,
|
||||
ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit
|
||||
)) {
|
||||
ImGui::TableSetupColumn("Id");
|
||||
ImGui::TableSetupColumn("Type");
|
||||
ImGui::TableSetupColumn("Registration Info");
|
||||
//ImGui::TableSetupColumn("Stub");
|
||||
ImGui::TableSetupColumn("Number of Calls");
|
||||
ImGui::Text("Total Registered: %d", numHooks);
|
||||
|
||||
if (ImGui::BeginTable(("Table##" + std::string(hookName)).c_str(), 4,
|
||||
ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable |
|
||||
ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit)) {
|
||||
ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_WidthFixed);
|
||||
ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_WidthFixed);
|
||||
ImGui::TableSetupColumn("Registration Info", ImGuiTableColumnFlags_WidthStretch);
|
||||
ImGui::TableSetupColumn("# Calls", ImGuiTableColumnFlags_WidthFixed);
|
||||
ImGui::TableHeadersRow();
|
||||
for (auto& [id, hookInfo] : (*hookData[hookName])) {
|
||||
ImGui::TableNextRow();
|
||||
@@ -39,7 +40,7 @@ void DrawHookRegisteringInfos(const char* hookName) {
|
||||
ImGui::Text("Normal");
|
||||
break;
|
||||
case HOOK_TYPE_ID:
|
||||
ImGui::Text("Id");
|
||||
ImGui::Text("ID");
|
||||
break;
|
||||
case HOOK_TYPE_PTR:
|
||||
ImGui::Text("Ptr");
|
||||
@@ -54,27 +55,19 @@ void DrawHookRegisteringInfos(const char* hookName) {
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
if (hookInfo.registering.valid) {
|
||||
ImGui::Text("%s(%d:%d) %s", hookInfo.registering.file, hookInfo.registering.line, hookInfo.registering.column, hookInfo.registering.function);
|
||||
// Replace the space after the return type of the parent function with a non-breaking space
|
||||
std::string parentFunction = std::string(hookInfo.registering.function);
|
||||
size_t pos = parentFunction.find_first_of(" ");
|
||||
if (pos != std::string::npos) {
|
||||
parentFunction.replace(pos, 1, "\u00A0");
|
||||
}
|
||||
// Non breaking space to keep the arrow with the parent function
|
||||
ImGui::TextWrapped("%s(%d:%d) <-\u00A0%s", hookInfo.registering.file, hookInfo.registering.line,
|
||||
hookInfo.registering.column, parentFunction.c_str());
|
||||
} else {
|
||||
ImGui::TextColored(yellow, "[Unavaliable]");
|
||||
ImGui::TextColored(yellow, "[Unavailable]");
|
||||
}
|
||||
|
||||
//TODO: not currently possible
|
||||
/*
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::BeginDisabled();
|
||||
|
||||
bool stubButtonPressed = ImGui::Button(("Stub##" + std::to_string(id)).c_str());
|
||||
UIWidgets::SetLastItemHoverText("Stub this hook.\nThis is not possible to automatically undo.");
|
||||
|
||||
if (stubButtonPressed) {
|
||||
//stub
|
||||
}
|
||||
|
||||
ImGui::EndDisabled();
|
||||
*/
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%d", hookInfo.calls);
|
||||
}
|
||||
@@ -84,12 +77,9 @@ void DrawHookRegisteringInfos(const char* hookName) {
|
||||
|
||||
void HookDebuggerWindow::DrawElement() {
|
||||
#ifndef __cpp_lib_source_location
|
||||
ImGui::TextColored(
|
||||
yellow,
|
||||
"Some features of the Hook Debugger are unavaliable because SoH was compiled "
|
||||
"without \"<source_location>\" support "
|
||||
"(\"__cpp_lib_source_location\" not defined in \"<version>\")."
|
||||
);
|
||||
ImGui::TextColored(yellow, "Some features of the Hook Debugger are unavailable because SoH was compiled "
|
||||
"without \"<source_location>\" support "
|
||||
"(\"__cpp_lib_source_location\" not defined in \"<version>\").");
|
||||
#endif
|
||||
|
||||
for (auto& [hookName, _] : hookData) {
|
||||
@@ -101,9 +91,9 @@ void HookDebuggerWindow::DrawElement() {
|
||||
}
|
||||
|
||||
void HookDebuggerWindow::InitElement() {
|
||||
#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"
|
||||
|
||||
#undef DEFINE_HOOK
|
||||
#undef DEFINE_HOOK
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user