1
0
mirror of synced 2024-12-01 02:37:18 +01:00

fix: Make sure library plugins are always initialized

This commit is contained in:
WerWolv 2023-12-28 14:59:23 +01:00
parent f44b44a881
commit 5adeac6bbc
2 changed files with 46 additions and 42 deletions

View File

@ -2,6 +2,7 @@
#include <hex.hpp>
#include <hex/api/plugin_manager.hpp>
#include <hex/helpers/logger.hpp>
#include <string>
@ -26,6 +27,11 @@
#define IMHEX_LIBRARY_SETUP_IMPL() \
IMHEX_PLUGIN_VISIBILITY_PREFIX void initializeLibrary(); \
static auto WOLV_TOKEN_CONCAT(libraryInitializer_, IMHEX_PLUGIN_NAME) = [] { \
initializeLibrary(); \
hex::log::info("Library plugin '{}' initialized successfully", WOLV_STRINGIFY(IMHEX_PLUGIN_NAME)); \
return 0; \
}(); \
extern "C" [[gnu::visibility("default")]] void WOLV_TOKEN_CONCAT(forceLinkPlugin_, IMHEX_PLUGIN_NAME)() { \
hex::PluginManager::addPlugin(hex::PluginFunctions { \
nullptr, \

View File

@ -17,6 +17,8 @@
namespace hex {
Plugin::Plugin(const std::fs::path &path) : m_path(path) {
log::info("Loading plugin '{}'", wolv::util::toUTF8String(path.filename()));
#if defined(OS_WINDOWS)
m_handle = uintptr_t(LoadLibraryW(path.c_str()));
@ -33,8 +35,6 @@ namespace hex {
}
#endif
log::info("Loaded plugin '{}'", wolv::util::toUTF8String(path.filename()));
m_functions.initializePluginFunction = getPluginFunction<PluginFunctions::InitializePluginFunc>("initializePlugin");
m_functions.initializeLibraryFunction = getPluginFunction<PluginFunctions::InitializePluginFunc>("initializeLibrary");
m_functions.getPluginNameFunction = getPluginFunction<PluginFunctions::GetPluginNameFunc>("getPluginName");
@ -88,8 +88,6 @@ namespace hex {
const auto pluginName = wolv::util::toUTF8String(m_path.filename());
if (this->isLibraryPlugin()) {
m_functions.initializeLibraryFunction();
log::info("Library plugin '{}' initialized successfully", pluginName);
return true;
}