Skip to content

Commit

Permalink
Ashita: v4 - add /pivot d[ump] command
Browse files Browse the repository at this point in the history
  • Loading branch information
Renee Koecher committed Aug 31, 2022
1 parent 47fbdaf commit 537bdaa
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
2 changes: 1 addition & 1 deletion XIPivot.Ashita_v4/polplugin/AshitaInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
69 changes: 67 additions & 2 deletions XIPivot.Ashita_v4/polplugin/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "AshitaInterface.h"
#include "Redirector.h"

#include <fstream>

#define IS_PARAM(arg, abbr, full) if((arg) == (abbr) || (arg) == (full))

namespace XiPivot
Expand All @@ -54,8 +56,10 @@ namespace XiPivot
m_cacheNextPurge = time(nullptr) + m_cachePurgeDelay;
}

bool UserInterface::HandleCommand(IChatManager* const chat, std::vector<std::string>& args)
bool UserInterface::HandleCommand(IAshitaCore* const core, std::vector<std::string>& args)
{
const auto chat = core->GetChatManager();

switch (args.size())
{
case 0:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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, "<no args>") << " - open the configuration UI.";
chat->AddChatMessage(1, false, msg.str().c_str());
Expand Down
2 changes: 1 addition & 1 deletion XIPivot.Ashita_v4/polplugin/UserInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>& args);
bool HandleCommand(IAshitaCore* const core, std::vector<std::string>& args);

void ProcessUI(bool &settingsChanged);
void RenderUI(IGuiManager* const imgui);
Expand Down

0 comments on commit 537bdaa

Please sign in to comment.