3131#include " AshitaInterface.h"
3232#include " Redirector.h"
3333
34+ #include < fstream>
35+
3436#define IS_PARAM (arg, abbr, full ) if ((arg) == (abbr) || (arg) == (full))
3537
3638namespace XiPivot
@@ -54,8 +56,10 @@ namespace XiPivot
5456 m_cacheNextPurge = time (nullptr ) + m_cachePurgeDelay;
5557 }
5658
57- bool UserInterface::HandleCommand (IChatManager * const chat , std::vector<std::string>& args)
59+ bool UserInterface::HandleCommand (IAshitaCore * const core , std::vector<std::string>& args)
5860 {
61+ const auto chat = core->GetChatManager ();
62+
5963 switch (args.size ())
6064 {
6165 case 0 :
@@ -94,6 +98,62 @@ namespace XiPivot
9498 m_guiState.state .showCacheOverlay = !m_guiState.state .showCacheOverlay ;
9599 }
96100 }
101+
102+ IS_PARAM (args.at (0 ), " d" , " dump" )
103+ {
104+ std::ostringstream msg;
105+ std::string dumpPath = std::string (core->GetInstallPath ()) + " \\ logs\\ pivot-dump.txt" ;
106+ std::fstream dumpFile;
107+
108+ dumpFile.open (dumpPath, std::ios_base::out | std::ios_base::trunc);
109+ if (dumpFile.is_open ())
110+ {
111+ const auto stats = m_guiState.values .cacheStats ;
112+
113+ dumpFile << " -- pivot memory stats --" << std::endl;
114+ if (Core::MemCache::instance ().hooksActive ())
115+ {
116+
117+ dumpFile << " memCache: enabled" << std::endl
118+ << " max size : " << (stats.allocation / 1048576 .0f ) << std::endl
119+ << " used size : " << (stats.used / 1048576 .0f ) << std::endl
120+ << " objects : " << stats.activeObjects << std::endl
121+ << " ignored : " << stats.cacheIgnored << std::endl;
122+
123+ }
124+ else
125+ {
126+ dumpFile << " memcache: disabled" << std::endl;
127+ }
128+ dumpFile << std::endl;
129+
130+ dumpFile << " -- pivot overlay stats --" << std::endl;
131+ if (Core::Redirector::instance ().hooksActive ())
132+ {
133+ auto overlayList = XiPivot::Core::Redirector::instance ().overlayList ();
134+ dumpFile << " redirector: enabled" << std::endl
135+ << " active overlays: " << overlayList.size () << std::endl;
136+
137+ for (const auto & overlay : overlayList)
138+ {
139+ dumpFile << " - '" << overlay << " '" << std::endl;
140+ }
141+ }
142+ else
143+ {
144+ dumpFile << " redirector: disabled" ;
145+ }
146+
147+ dumpFile.close ();
148+
149+ msg << Ashita::Chat::Header (PluginCommand) << Ashita::Chat::Message (" Dumped statistics to " ) << Ashita::Chat::Message (dumpPath);
150+ }
151+ else
152+ {
153+ msg << Ashita::Chat::Header (PluginCommand) << Ashita::Chat::Error (" Unable to write to " ) << Ashita::Chat::Error (dumpPath);
154+ }
155+ chat->AddChatMessage (1 , false , msg.str ().c_str ());
156+ }
97157 break ;
98158
99159 case 2 :
@@ -319,9 +379,14 @@ namespace XiPivot
319379 chat->AddChatMessage (1 , false , msg.str ().c_str ());
320380
321381 msg.str (" " );
322- msg << Ashita::Chat::Header (PluginCommand) << Ashita::Chat::Color1 (0x3 , " c" ) << " ache - open the cache stats overlay" ;
382+ msg << Ashita::Chat::Header (PluginCommand) << Ashita::Chat::Color1 (0x3 , " c" ) << " ache - open the cache stats overlay. " ;
323383 chat->AddChatMessage (1 , false , msg.str ().c_str ());
324384
385+ msg.str (" " );
386+ msg << Ashita::Chat::Header (PluginCommand) << Ashita::Chat::Color1 (0x3 , " d" ) << " ump - dump overlay and cache statistics to logs\\ pivot-dump.txt." ;
387+ chat->AddChatMessage (1 , false , msg.str ().c_str ());
388+
389+
325390 msg.str (" " );
326391 msg << Ashita::Chat::Header (PluginCommand) << Ashita::Chat::Color1 (0x3 , " <no args>" ) << " - open the configuration UI." ;
327392 chat->AddChatMessage (1 , false , msg.str ().c_str ());
0 commit comments