From 9066891ce269bd6beacda07a67dbe3a15699a19a Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 24 Dec 2023 12:20:51 +0100 Subject: [PATCH] fix: ImHex not starting on some platforms --- .../include/hex/api/plugin_manager.hpp | 7 +++---- lib/libimhex/source/api/plugin_manager.cpp | 21 +++++++++++-------- plugins/hashes/CMakeLists.txt | 1 + 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/libimhex/include/hex/api/plugin_manager.hpp b/lib/libimhex/include/hex/api/plugin_manager.hpp index 20a390156..df819b489 100644 --- a/lib/libimhex/include/hex/api/plugin_manager.hpp +++ b/lib/libimhex/include/hex/api/plugin_manager.hpp @@ -41,8 +41,8 @@ namespace hex { class Plugin { public: - explicit Plugin(const std::fs::path &path, bool libraryPlugin); - explicit Plugin(PluginFunctions functions, bool libraryPlugin); + explicit Plugin(const std::fs::path &path); + explicit Plugin(PluginFunctions functions); Plugin(const Plugin &) = delete; Plugin(Plugin &&other) noexcept; @@ -66,12 +66,11 @@ namespace hex { [[nodiscard]] std::span getSubCommands() const; - [[nodiscard]] bool isLibraryPlugin() const { return m_libraryPlugin; } + [[nodiscard]] bool isLibraryPlugin() const; private: uintptr_t m_handle = 0; std::fs::path m_path; - bool m_libraryPlugin; mutable bool m_initialized = false; diff --git a/lib/libimhex/source/api/plugin_manager.cpp b/lib/libimhex/source/api/plugin_manager.cpp index fb915f195..b1f81b2ae 100644 --- a/lib/libimhex/source/api/plugin_manager.cpp +++ b/lib/libimhex/source/api/plugin_manager.cpp @@ -16,7 +16,7 @@ namespace hex { - Plugin::Plugin(const std::fs::path &path, bool libraryPlugin) : m_path(path), m_libraryPlugin(libraryPlugin) { + Plugin::Plugin(const std::fs::path &path) : m_path(path) { #if defined(OS_WINDOWS) m_handle = uintptr_t(LoadLibraryW(path.c_str())); @@ -46,10 +46,9 @@ namespace hex { m_functions.getSubCommandsFunction = getPluginFunction("getSubCommands"); } - Plugin::Plugin(hex::PluginFunctions functions, bool libraryPlugin) { + Plugin::Plugin(hex::PluginFunctions functions) { m_handle = 0; m_functions = functions; - m_libraryPlugin = libraryPlugin; } @@ -57,7 +56,6 @@ namespace hex { m_handle = other.m_handle; other.m_handle = 0; - m_libraryPlugin = other.m_libraryPlugin; m_path = std::move(other.m_path); m_functions = other.m_functions; @@ -68,7 +66,6 @@ namespace hex { m_handle = other.m_handle; other.m_handle = 0; - m_libraryPlugin = other.m_libraryPlugin; m_path = std::move(other.m_path); m_functions = other.m_functions; @@ -90,7 +87,7 @@ namespace hex { bool Plugin::initializePlugin() const { const auto pluginName = wolv::util::toUTF8String(m_path.filename()); - if (m_functions.initializeLibraryFunction != nullptr) { + if (this->isLibraryPlugin()) { m_functions.initializeLibraryFunction(); log::info("Library plugin '{}' initialized successfully", pluginName); return true; @@ -192,6 +189,12 @@ namespace hex { return { }; } + bool Plugin::isLibraryPlugin() const { + return m_functions.initializeLibraryFunction != nullptr && + m_functions.initializePluginFunction == nullptr; + } + + void *Plugin::getPluginFunction(const std::string &symbol) const { #if defined(OS_WINDOWS) @@ -210,13 +213,13 @@ namespace hex { // Load library plugins first for (auto &pluginPath : std::fs::directory_iterator(pluginFolder)) { if (pluginPath.is_regular_file() && pluginPath.path().extension() == ".hexpluglib") - getPlugins().emplace_back(pluginPath.path(), true); + getPlugins().emplace_back(pluginPath.path()); } // Load regular plugins afterwards for (auto &pluginPath : std::fs::directory_iterator(pluginFolder)) { if (pluginPath.is_regular_file() && pluginPath.path().extension() == ".hexplug") - getPlugins().emplace_back(pluginPath.path(), false); + getPlugins().emplace_back(pluginPath.path()); } std::erase_if(getPlugins(), [](const Plugin &plugin) { @@ -243,7 +246,7 @@ namespace hex { } void PluginManager::addPlugin(hex::PluginFunctions functions) { - getPlugins().emplace_back(functions, false); + getPlugins().emplace_back(functions); } std::vector &PluginManager::getPlugins() { diff --git a/plugins/hashes/CMakeLists.txt b/plugins/hashes/CMakeLists.txt index 173b2ada3..d4044a0f5 100644 --- a/plugins/hashes/CMakeLists.txt +++ b/plugins/hashes/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.16) include(ImHexPlugin) add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/HashLibPlus ${CMAKE_CURRENT_BINARY_DIR}/HashLibPlus) +set_target_properties(hashplus PROPERTIES POSITION_INDEPENDENT_CODE ON) add_imhex_plugin( NAME