From d423584829c902d326cfc8297e95dfe84efdc8de Mon Sep 17 00:00:00 2001 From: MiranDMC Date: Wed, 27 Nov 2024 16:40:20 +0100 Subject: [PATCH] Added loaded ASI and CLEO plugins list to log. (#239) --- cleo_sdk/CLEO_Utils.h | 17 ++++++++++++++++ source/CPluginSystem.cpp | 42 ++++++++++++++++++++++++++++++++++++++++ source/CPluginSystem.h | 2 ++ source/CleoBase.cpp | 2 ++ 4 files changed, 63 insertions(+) diff --git a/cleo_sdk/CLEO_Utils.h b/cleo_sdk/CLEO_Utils.h index 3555d8e6..5abf00ff 100644 --- a/cleo_sdk/CLEO_Utils.h +++ b/cleo_sdk/CLEO_Utils.h @@ -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'); diff --git a/source/CPluginSystem.cpp b/source/CPluginSystem.cpp index 5a59e1e9..f33fbc97 100644 --- a/source/CPluginSystem.cpp +++ b/source/CPluginSystem.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "CPluginSystem.h" #include "CleoBase.h" +#include using namespace CLEO; @@ -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 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 +} + diff --git a/source/CPluginSystem.h b/source/CPluginSystem.h index 7b99d4a5..63afa1be 100644 --- a/source/CPluginSystem.h +++ b/source/CPluginSystem.h @@ -30,5 +30,7 @@ namespace CLEO void LoadPlugins(); void UnloadPlugins(); size_t GetNumPlugins() const; + + void LogLoadedPlugins() const; }; } diff --git a/source/CleoBase.cpp b/source/CleoBase.cpp index fefc469a..cb9079e2 100644 --- a/source/CleoBase.cpp +++ b/source/CleoBase.cpp @@ -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;