Skip to content

Commit

Permalink
Added loaded ASI and CLEO plugins list to log. (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC authored Nov 27, 2024
1 parent de687b2 commit d423584
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cleo_sdk/CLEO_Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,23 @@ namespace CLEO
}
}

static bool StringEndsWith(const std::string_view str, const std::string_view suffix, bool caseSensitive = true)
{
if (str.length() < suffix.length())
{
return false;
}

if (caseSensitive)
{
return strncmp(&str.back() + 1 - suffix.length(), suffix.data(), suffix.length()) == 0;
}
else
{
return _strnicmp(&str.back() + 1 - suffix.length(), suffix.data(), suffix.length()) == 0;
}
}

static std::string ScriptInfoStr(CLEO::CRunningScript* thread)
{
std::string info(1024, '\0');
Expand Down
42 changes: 42 additions & 0 deletions source/CPluginSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "stdafx.h"
#include "CPluginSystem.h"
#include "CleoBase.h"
#include <psapi.h>


using namespace CLEO;
Expand Down Expand Up @@ -117,3 +118,44 @@ size_t CPluginSystem::GetNumPlugins() const
return plugins.size();
}

void CLEO::CPluginSystem::LogLoadedPlugins() const
{
auto process = GetCurrentProcess();

DWORD buffSize = 0;
if (!EnumProcessModules(process, nullptr, 0, &buffSize) || buffSize < sizeof(HMODULE))
{
return;
}

std::vector<HMODULE> modules(buffSize / sizeof(HMODULE));
if (!EnumProcessModules(process, modules.data(), buffSize, &buffSize))
{
return;
}

TRACE(""); // separator
TRACE("Loaded plugins summary:");

for (const auto& m : modules)
{
std::string filename(512, '\0');
if (GetModuleFileName(m, filename.data(), filename.size()))
{
filename.resize(strlen(filename.data()));

if (StringEndsWith(filename, ".asi", false) || StringEndsWith(filename, ".cleo", false))
{
std::error_code err;
auto fileSize = (size_t)FS::file_size(filename, err);

FilepathRemoveParent(filename, Filepath_Game);

TRACE(" %s (%zu bytes)", filename.c_str(), fileSize);
}
}
}

TRACE(""); // separator
}

2 changes: 2 additions & 0 deletions source/CPluginSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ namespace CLEO
void LoadPlugins();
void UnloadPlugins();
size_t GetNumPlugins() const;

void LogLoadedPlugins() const;
};
}
2 changes: 2 additions & 0 deletions source/CleoBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ namespace CLEO
TRACE("CLEO initialization: Phase 2");

CodeInjector.ReplaceJump(OnDebugDisplayTextBuffer, VersionManager.TranslateMemoryAddress(MA_DEBUG_DISPLAY_TEXT_BUFFER), &DebugDisplayTextBuffer);

PluginSystem.LogLoadedPlugins();
}

m_initStage = stage;
Expand Down

0 comments on commit d423584

Please sign in to comment.