feat: Add more debug logging (#503)

This commit is contained in:
Yimura 2022-10-23 20:48:51 +02:00 committed by GitHub
parent a00e9e34f3
commit 5212fb701a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 67 additions and 27 deletions

View File

@ -21,7 +21,15 @@ namespace big
{ {
bool metric_logs{}; bool metric_logs{};
bool script_event_logs = false; bool script_hook_logs{};
struct
{
bool logs = false;
bool filter_player = true;
std::int8_t player_id = -1;
} script_event{};
} logs{}; } logs{};
}; };
@ -395,7 +403,7 @@ namespace big
void from_json(const nlohmann::json& j) void from_json(const nlohmann::json& j)
{ {
this->debug.logs.metric_logs = j["debug"]["logs"]["metric_logs"]; this->debug.logs.metric_logs = j["debug"]["logs"]["metric_logs"];
this->debug.logs.script_event_logs = j["debug"]["logs"]["script_event_logs"]; this->debug.logs.script_hook_logs = j["debug"]["logs"]["script_hook_logs"];
g->notifications.gta_thread_kill.log = j["notifications"]["gta_thread_kill"]["log"]; g->notifications.gta_thread_kill.log = j["notifications"]["gta_thread_kill"]["log"];
g->notifications.gta_thread_kill.notify = j["notifications"]["gta_thread_kill"]["notify"]; g->notifications.gta_thread_kill.notify = j["notifications"]["gta_thread_kill"]["notify"];
@ -688,7 +696,7 @@ namespace big
"logs", "logs",
{ {
{ "metric_logs", this->debug.logs.metric_logs }, { "metric_logs", this->debug.logs.metric_logs },
{ "script_event_logs", this->debug.logs.script_event_logs } { "script_hook_logs", this->debug.logs.script_hook_logs }
} }
} }
} }

View File

@ -323,16 +323,21 @@ namespace big
} }
if (g->debug.logs.script_event_logs) if (g->debug.logs.script_event.logs && (!g->debug.logs.script_event.filter_player || g->debug.logs.script_event.player_id == player->m_player_id))
{ {
LOG(INFO) << "== Begin of Script Event =="; std::string script_args = "{ ";
LOG(INFO) << "Player: " << player->get_name(); for (std::size_t i = 0; i < scripted_game_event->m_args_size; i++)
LOG(INFO) << "Hash/Arg #0: " << (int)hash; {
if (i)
script_args += ", ";
for (std::size_t i = 1; i < sizeof(args); i++) script_args += std::to_string(args[i]);
LOG(INFO) << "Arg #" << i << ": " << args[i]; }
script_args += " };";
LOG(INFO) << "== End of Script Event =="; LOG(G3LOG_DEBUG) << "Script Event:\n"
<< "\tPlayer: " << player->get_name() << "\n"
<< "\tArgs: " << script_args;
} }
return false; return false;

View File

@ -68,7 +68,7 @@ namespace big
if (m_script_hooks.find(gta_thread->m_script_hash) != m_script_hooks.end()) if (m_script_hooks.find(gta_thread->m_script_hash) != m_script_hooks.end())
{ {
// this should never happen but if it does we catch it // this should never happen but if it does we catch it
LOG(INFO) << "Dynamic native script hook still active for script, cleaning up..."; LOG_IF(G3LOG_DEBUG, g->debug.logs.script_hook_logs) << "Dynamic native script hook still active for script, cleaning up...";
m_script_hooks.erase(gta_thread->m_script_hash); m_script_hooks.erase(gta_thread->m_script_hash);
} }
@ -87,7 +87,7 @@ namespace big
{ {
if (m_script_hooks.erase(gta_thread->m_script_hash)) if (m_script_hooks.erase(gta_thread->m_script_hash))
{ {
LOG(INFO) << gta_thread->m_name << " script terminated, cleaning up native hooks"; LOG_IF(G3LOG_DEBUG, g->debug.logs.script_hook_logs) << gta_thread->m_name << " script terminated, cleaning up native hooks";
} }
} }
} }

View File

@ -58,7 +58,7 @@ namespace big
if (program->is_valid()) if (program->is_valid())
{ {
hook_instance(program); hook_instance(program);
LOG(INFO) << "Hooked " << program->m_name << " script (" << HEX_TO_UPPER(static_cast<void*>(program)) << ")"; LOG_IF(G3LOG_DEBUG, g->debug.logs.script_hook_logs) << "Hooked " << program->m_name << " script (" << HEX_TO_UPPER(static_cast<void*>(program)) << ")";
} }
} }
} }

View File

@ -1,14 +0,0 @@
#include "view_debug.hpp"
namespace big
{
void debug::logs()
{
if (ImGui::BeginTabItem("Logs"))
{
ImGui::Checkbox("Log Metrics", &g->debug.logs.metric_logs);
ImGui::EndTabItem();
}
}
}

View File

@ -0,0 +1,41 @@
#include "gui/components/components.hpp"
#include "services/players/player_service.hpp"
#include "view_debug.hpp"
namespace big
{
void debug::logs()
{
if (ImGui::BeginTabItem("Logs"))
{
ImGui::Checkbox("Log Metrics", &g->debug.logs.metric_logs);
ImGui::Checkbox("Native Script Hooks", &g->debug.logs.script_hook_logs);
if (ImGui::TreeNode("Script Event Logging"))
{
ImGui::Checkbox("Enable Script Event Logging", &g->debug.logs.script_event.logs);
ImGui::Separator();
ImGui::Checkbox("Filter by Player", &g->debug.logs.script_event.filter_player);
if (g->debug.logs.script_event.filter_player)
{
ImGui::ListBoxHeader("##filter_player");
for (const auto& [_, player] : g_player_service->players())
{
if (components::selectable(player->get_name(), g->debug.logs.script_event.player_id == player->id()))
{
g->debug.logs.script_event.player_id = player->id();
}
}
ImGui::EndListBox();
}
ImGui::TreePop();
}
ImGui::EndTabItem();
}
}
}