Skip to content

Commit

Permalink
Added UI Message log
Browse files Browse the repository at this point in the history
  • Loading branch information
3vcloud committed Nov 15, 2023
1 parent bedeac2 commit 0824268
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions GWToolboxdll/Windows/InfoWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,35 @@ namespace {
typedef uint32_t*(__cdecl* CreateTexture_pt)(wchar_t* file_name, uint32_t flags);
CreateTexture_pt CreateTexture_Func = nullptr;
CreateTexture_pt CreateTexture_Ret = nullptr;

// Why reinvent the wheel?
typedef void(__cdecl* GWCA_SendUIMessage_pt)(GW::UI::UIMessage msgid, void* wParam, void* lParam);
GWCA_SendUIMessage_pt GWCA_SendUIMessage_Func = nullptr;
GWCA_SendUIMessage_pt GWCA_SendUIMessage_Ret = nullptr;

struct UIMessagePacket {
GW::UI::UIMessage msgid;
void* wParam;
void* lParam;
};

std::vector<UIMessagePacket*> ui_message_packets_recorded;
bool record_ui_messages = false;

void OnGWCASendUIMessage(GW::UI::UIMessage msgid, void* wParam, void* lParam) {
GW::Hook::EnterHook();
GWCA_SendUIMessage_Ret(msgid, wParam, lParam);
if(record_ui_messages)
ui_message_packets_recorded.push_back(new UIMessagePacket({ msgid,wParam,lParam }));
GW::Hook::LeaveHook();
}
void ClearUIMessagesRecorded() {
for (auto p : ui_message_packets_recorded) {
delete p;
}
ui_message_packets_recorded.clear();
}

std::map<uint32_t,IDirect3DTexture9**> textures_created;

bool record_textures = false;
Expand Down Expand Up @@ -689,6 +718,17 @@ namespace {
ImGui::PopStyleVar();
ImGui::PopStyleVar();
}
record_ui_messages = ImGui::CollapsingHeader("UI Message Log");
if (record_ui_messages) {
if (ImGui::SmallButton("Reset")) {
ClearUIMessagesRecorded();
}
for (auto it : ui_message_packets_recorded) {
ImGui::PushID(it);
ImGui::Text("0x%08x 0x%08x 0x%08x", it->msgid, it->wParam, it->lParam);
ImGui::PopID();
}
}


// For debugging changes to flags/arrays etc
Expand Down Expand Up @@ -718,6 +758,11 @@ void InfoWindow::Terminate()
GW::HookBase::RemoveHook(CreateTexture_Func);
CreateTexture_Func = nullptr;
}
if (GWCA_SendUIMessage_Func) {
GW::HookBase::RemoveHook(GWCA_SendUIMessage_Func);
GWCA_SendUIMessage_Func = nullptr;
}
ClearUIMessagesRecorded();
}

void InfoWindow::Initialize()
Expand All @@ -739,13 +784,18 @@ void InfoWindow::Initialize()
GW::HookBase::EnableHooks(CreateTexture_Func);
}



GWCA_SendUIMessage_Func = (GWCA_SendUIMessage_pt)GW::UI::SendUIMessage;
if (GWCA_SendUIMessage_Func) {
GW::HookBase::CreateHook(GWCA_SendUIMessage_Func, OnGWCASendUIMessage, (void**)&GWCA_SendUIMessage_Ret);
GW::HookBase::EnableHooks(GWCA_SendUIMessage_Func);
}
}

void InfoWindow::Draw(IDirect3DDevice9*)
{
if (!visible) {
record_ui_messages = false;
record_textures = false;
return;
}
ImGui::SetNextWindowCenter(ImGuiCond_FirstUseEver);
Expand Down

0 comments on commit 0824268

Please sign in to comment.