diff --git a/lib/libimhex/include/hex/plugin.hpp b/lib/libimhex/include/hex/plugin.hpp index d09d72fc0..3b2bfcc60 100644 --- a/lib/libimhex/include/hex/plugin.hpp +++ b/lib/libimhex/include/hex/plugin.hpp @@ -11,6 +11,7 @@ #include #include +#include #if defined (IMHEX_STATIC_LINK_PLUGINS) #define IMHEX_PLUGIN_VISIBILITY_PREFIX static @@ -23,57 +24,59 @@ * Name, Author and Description will be displayed in the in the plugin list on the Welcome screen. */ #define IMHEX_PLUGIN_SETUP(name, author, description) IMHEX_PLUGIN_SETUP_IMPL(name, author, description) -#define IMHEX_LIBRARY_SETUP() IMHEX_LIBRARY_SETUP_IMPL() +#define IMHEX_LIBRARY_SETUP(name) IMHEX_LIBRARY_SETUP_IMPL(name) -#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; \ - }(); \ - IMHEX_PLUGIN_VISIBILITY_PREFIX void setImGuiContext(ImGuiContext *ctx) { \ - ImGui::SetCurrentContext(ctx); \ - GImGui = ctx; \ - } \ - extern "C" [[gnu::visibility("default")]] void WOLV_TOKEN_CONCAT(forceLinkPlugin_, IMHEX_PLUGIN_NAME)() { \ - hex::PluginManager::addPlugin(hex::PluginFunctions { \ - nullptr, \ - initializeLibrary, \ - nullptr, \ - nullptr, \ - nullptr, \ - nullptr, \ - setImGuiContext, \ - nullptr, \ - nullptr \ - }); \ - } \ +#define IMHEX_LIBRARY_SETUP_IMPL(name) \ + namespace { static struct EXIT_HANDLER { ~EXIT_HANDLER() { hex::log::info("Unloading library '{}'", name); } } HANDLER; } \ + 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; \ + }(); \ + IMHEX_PLUGIN_VISIBILITY_PREFIX void setImGuiContext(ImGuiContext *ctx) { \ + ImGui::SetCurrentContext(ctx); \ + GImGui = ctx; \ + } \ + extern "C" [[gnu::visibility("default")]] void WOLV_TOKEN_CONCAT(forceLinkPlugin_, IMHEX_PLUGIN_NAME)() { \ + hex::PluginManager::addPlugin(hex::PluginFunctions { \ + nullptr, \ + initializeLibrary, \ + nullptr, \ + nullptr, \ + nullptr, \ + nullptr, \ + setImGuiContext, \ + nullptr, \ + nullptr \ + }); \ + } \ IMHEX_PLUGIN_VISIBILITY_PREFIX void initializeLibrary() -#define IMHEX_PLUGIN_SETUP_IMPL(name, author, description) \ - IMHEX_PLUGIN_VISIBILITY_PREFIX const char *getPluginName() { return name; } \ - IMHEX_PLUGIN_VISIBILITY_PREFIX const char *getPluginAuthor() { return author; } \ - IMHEX_PLUGIN_VISIBILITY_PREFIX const char *getPluginDescription() { return description; } \ - IMHEX_PLUGIN_VISIBILITY_PREFIX const char *getCompatibleVersion() { return IMHEX_VERSION; } \ - IMHEX_PLUGIN_VISIBILITY_PREFIX void setImGuiContext(ImGuiContext *ctx) { \ - ImGui::SetCurrentContext(ctx); \ - GImGui = ctx; \ - } \ - IMHEX_PLUGIN_VISIBILITY_PREFIX void initializePlugin(); \ - extern "C" [[gnu::visibility("default")]] void WOLV_TOKEN_CONCAT(forceLinkPlugin_, IMHEX_PLUGIN_NAME)() { \ - hex::PluginManager::addPlugin(hex::PluginFunctions { \ - initializePlugin, \ - nullptr, \ - getPluginName, \ - getPluginAuthor, \ - getPluginDescription, \ - getCompatibleVersion, \ - setImGuiContext, \ - nullptr, \ - nullptr \ - }); \ - } \ +#define IMHEX_PLUGIN_SETUP_IMPL(name, author, description) \ + namespace { static struct EXIT_HANDLER { ~EXIT_HANDLER() { hex::log::info("Unloading plugin '{}'", name); } } HANDLER; } \ + IMHEX_PLUGIN_VISIBILITY_PREFIX const char *getPluginName() { return name; } \ + IMHEX_PLUGIN_VISIBILITY_PREFIX const char *getPluginAuthor() { return author; } \ + IMHEX_PLUGIN_VISIBILITY_PREFIX const char *getPluginDescription() { return description; } \ + IMHEX_PLUGIN_VISIBILITY_PREFIX const char *getCompatibleVersion() { return IMHEX_VERSION; } \ + IMHEX_PLUGIN_VISIBILITY_PREFIX void setImGuiContext(ImGuiContext *ctx) { \ + ImGui::SetCurrentContext(ctx); \ + GImGui = ctx; \ + } \ + IMHEX_PLUGIN_VISIBILITY_PREFIX void initializePlugin(); \ + extern "C" [[gnu::visibility("default")]] void WOLV_TOKEN_CONCAT(forceLinkPlugin_, IMHEX_PLUGIN_NAME)() { \ + hex::PluginManager::addPlugin(hex::PluginFunctions { \ + initializePlugin, \ + nullptr, \ + getPluginName, \ + getPluginAuthor, \ + getPluginDescription, \ + getCompatibleVersion, \ + setImGuiContext, \ + nullptr, \ + nullptr \ + }); \ + } \ IMHEX_PLUGIN_VISIBILITY_PREFIX void initializePlugin() /** diff --git a/lib/libimhex/source/api/plugin_manager.cpp b/lib/libimhex/source/api/plugin_manager.cpp index 6a7bd76bc..2f23286ba 100644 --- a/lib/libimhex/source/api/plugin_manager.cpp +++ b/lib/libimhex/source/api/plugin_manager.cpp @@ -260,11 +260,6 @@ namespace hex { auto &plugins = getPlugins(); const auto pluginCount = plugins.size(); for (size_t i = 0; i < pluginCount; i++) { - auto &plugin = plugins[pluginCount - 1 - i]; - if (plugin.isLoaded()) { - log::info("Unloading plugin '{}'", plugin.getPluginName()); - } - plugins.pop_back(); } } diff --git a/plugins/ui/source/library_ui.cpp b/plugins/ui/source/library_ui.cpp index 5e78f7366..a32472dcf 100644 --- a/plugins/ui/source/library_ui.cpp +++ b/plugins/ui/source/library_ui.cpp @@ -9,7 +9,7 @@ #include #include -IMHEX_LIBRARY_SETUP() { +IMHEX_LIBRARY_SETUP("UI") { hex::log::debug("Using romfs: '{}'", romfs::name()); for (auto &path : romfs::list("lang")) hex::ContentRegistry::Language::addLocalization(nlohmann::json::parse(romfs::get(path).string()));