From 537bdaa52aeaf2c449eda0904bbffdd965a483d8 Mon Sep 17 00:00:00 2001 From: Renee Koecher Date: Wed, 31 Aug 2022 10:53:23 +0200 Subject: [PATCH] Ashita: v4 - add /pivot d[ump] command --- .../polplugin/AshitaInterface.cpp | 2 +- XIPivot.Ashita_v4/polplugin/UserInterface.cpp | 69 ++++++++++++++++++- XIPivot.Ashita_v4/polplugin/UserInterface.h | 2 +- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/XIPivot.Ashita_v4/polplugin/AshitaInterface.cpp b/XIPivot.Ashita_v4/polplugin/AshitaInterface.cpp index a20f7b5..5116818 100644 --- a/XIPivot.Ashita_v4/polplugin/AshitaInterface.cpp +++ b/XIPivot.Ashita_v4/polplugin/AshitaInterface.cpp @@ -126,7 +126,7 @@ namespace XiPivot HANDLECOMMAND("/pivot") { args.erase(args.begin()); - return m_ui.HandleCommand(m_ashitaCore->GetChatManager(), args); + return m_ui.HandleCommand(m_ashitaCore, args); } return false; } diff --git a/XIPivot.Ashita_v4/polplugin/UserInterface.cpp b/XIPivot.Ashita_v4/polplugin/UserInterface.cpp index bdb98cb..ae6b7c1 100644 --- a/XIPivot.Ashita_v4/polplugin/UserInterface.cpp +++ b/XIPivot.Ashita_v4/polplugin/UserInterface.cpp @@ -31,6 +31,8 @@ #include "AshitaInterface.h" #include "Redirector.h" +#include + #define IS_PARAM(arg, abbr, full) if((arg) == (abbr) || (arg) == (full)) namespace XiPivot @@ -54,8 +56,10 @@ namespace XiPivot m_cacheNextPurge = time(nullptr) + m_cachePurgeDelay; } - bool UserInterface::HandleCommand(IChatManager* const chat, std::vector& args) + bool UserInterface::HandleCommand(IAshitaCore* const core, std::vector& args) { + const auto chat = core->GetChatManager(); + switch (args.size()) { case 0: @@ -94,6 +98,62 @@ namespace XiPivot m_guiState.state.showCacheOverlay = !m_guiState.state.showCacheOverlay; } } + + IS_PARAM(args.at(0), "d", "dump") + { + std::ostringstream msg; + std::string dumpPath = std::string(core->GetInstallPath()) + "\\logs\\pivot-dump.txt"; + std::fstream dumpFile; + + dumpFile.open(dumpPath, std::ios_base::out | std::ios_base::trunc); + if (dumpFile.is_open()) + { + const auto stats = m_guiState.values.cacheStats; + + dumpFile << "-- pivot memory stats --" << std::endl; + if (Core::MemCache::instance().hooksActive()) + { + + dumpFile << "memCache: enabled" << std::endl + << "max size : " << (stats.allocation / 1048576.0f) << std::endl + << "used size : " << (stats.used / 1048576.0f) << std::endl + << "objects : " << stats.activeObjects << std::endl + << "ignored : " << stats.cacheIgnored << std::endl; + + } + else + { + dumpFile << "memcache: disabled" << std::endl; + } + dumpFile << std::endl; + + dumpFile << "-- pivot overlay stats --" << std::endl; + if (Core::Redirector::instance().hooksActive()) + { + auto overlayList = XiPivot::Core::Redirector::instance().overlayList(); + dumpFile << "redirector: enabled" << std::endl + << "active overlays: " << overlayList.size() << std::endl; + + for (const auto& overlay : overlayList) + { + dumpFile << "- '" << overlay << "'" << std::endl; + } + } + else + { + dumpFile << "redirector: disabled"; + } + + dumpFile.close(); + + msg << Ashita::Chat::Header(PluginCommand) << Ashita::Chat::Message("Dumped statistics to ") << Ashita::Chat::Message(dumpPath); + } + else + { + msg << Ashita::Chat::Header(PluginCommand) << Ashita::Chat::Error("Unable to write to ") << Ashita::Chat::Error(dumpPath); + } + chat->AddChatMessage(1, false, msg.str().c_str()); + } break; case 2: @@ -319,9 +379,14 @@ namespace XiPivot chat->AddChatMessage(1, false, msg.str().c_str()); msg.str(""); - msg << Ashita::Chat::Header(PluginCommand) << Ashita::Chat::Color1(0x3, "c") << "ache - open the cache stats overlay"; + msg << Ashita::Chat::Header(PluginCommand) << Ashita::Chat::Color1(0x3, "c") << "ache - open the cache stats overlay."; chat->AddChatMessage(1, false, msg.str().c_str()); + msg.str(""); + msg << Ashita::Chat::Header(PluginCommand) << Ashita::Chat::Color1(0x3, "d") << "ump - dump overlay and cache statistics to logs\\pivot-dump.txt."; + chat->AddChatMessage(1, false, msg.str().c_str()); + + msg.str(""); msg << Ashita::Chat::Header(PluginCommand) << Ashita::Chat::Color1(0x3, "") << " - open the configuration UI."; chat->AddChatMessage(1, false, msg.str().c_str()); diff --git a/XIPivot.Ashita_v4/polplugin/UserInterface.h b/XIPivot.Ashita_v4/polplugin/UserInterface.h index 406123d..4baed19 100644 --- a/XIPivot.Ashita_v4/polplugin/UserInterface.h +++ b/XIPivot.Ashita_v4/polplugin/UserInterface.h @@ -48,7 +48,7 @@ namespace XiPivot void setCachePurgeDelay(time_t maxAge); time_t getCachePurgeDelay(void) const { return m_cachePurgeDelay; } - bool HandleCommand(IChatManager* chat, std::vector& args); + bool HandleCommand(IAshitaCore* const core, std::vector& args); void ProcessUI(bool &settingsChanged); void RenderUI(IGuiManager* const imgui);