1
0
mirror of synced 2025-02-06 14:14:22 +01:00

impr: Make plugin features and subcommands work in statically linked builds

This commit is contained in:
WerWolv 2024-01-13 00:34:13 +01:00
parent db1373d572
commit d511080814
3 changed files with 60 additions and 20 deletions

View File

@ -13,6 +13,30 @@
#include <wolv/utils/preproc.hpp> #include <wolv/utils/preproc.hpp>
#include <wolv/utils/guards.hpp> #include <wolv/utils/guards.hpp>
namespace {
struct PluginFunctionHelperInstantiation {};
}
template<typename T>
struct PluginFeatureFunctionHelper {
static void* getFeatures();
};
template<typename T>
struct PluginSubCommandsFunctionHelper {
static void* getSubCommands();
};
template<typename T>
void* PluginFeatureFunctionHelper<T>::getFeatures() {
return nullptr;
}
template<typename T>
void* PluginSubCommandsFunctionHelper<T>::getSubCommands() {
return nullptr;
}
#if defined (IMHEX_STATIC_LINK_PLUGINS) #if defined (IMHEX_STATIC_LINK_PLUGINS)
#define IMHEX_PLUGIN_VISIBILITY_PREFIX static #define IMHEX_PLUGIN_VISIBILITY_PREFIX static
#else #else
@ -60,6 +84,12 @@
ImGui::SetCurrentContext(ctx); \ ImGui::SetCurrentContext(ctx); \
GImGui = ctx; \ GImGui = ctx; \
} \ } \
IMHEX_PLUGIN_VISIBILITY_PREFIX void* getFeatures() { \
return PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation>::getFeatures(); \
} \
IMHEX_PLUGIN_VISIBILITY_PREFIX void* getSubCommands() { \
return PluginSubCommandsFunctionHelper<PluginFunctionHelperInstantiation>::getSubCommands(); \
} \
IMHEX_PLUGIN_VISIBILITY_PREFIX void initializePlugin(); \ IMHEX_PLUGIN_VISIBILITY_PREFIX void initializePlugin(); \
extern "C" [[gnu::visibility("default")]] void WOLV_TOKEN_CONCAT(forceLinkPlugin_, IMHEX_PLUGIN_NAME)() { \ extern "C" [[gnu::visibility("default")]] void WOLV_TOKEN_CONCAT(forceLinkPlugin_, IMHEX_PLUGIN_NAME)() { \
hex::PluginManager::addPlugin(name, hex::PluginFunctions { \ hex::PluginManager::addPlugin(name, hex::PluginFunctions { \
@ -71,8 +101,8 @@
getPluginDescription, \ getPluginDescription, \
getCompatibleVersion, \ getCompatibleVersion, \
setImGuiContext, \ setImGuiContext, \
nullptr, \ getSubCommands, \
nullptr \ getFeatures \
}); \ }); \
} \ } \
IMHEX_PLUGIN_VISIBILITY_PREFIX void initializePlugin() IMHEX_PLUGIN_VISIBILITY_PREFIX void initializePlugin()
@ -89,7 +119,11 @@
#define IMHEX_PLUGIN_SUBCOMMANDS_IMPL() \ #define IMHEX_PLUGIN_SUBCOMMANDS_IMPL() \
extern std::vector<hex::SubCommand> g_subCommands; \ extern std::vector<hex::SubCommand> g_subCommands; \
extern "C" [[gnu::visibility("default")]] void* getSubCommands() { \ template<> \
struct PluginSubCommandsFunctionHelper<PluginFunctionHelperInstantiation> { \
static void* getSubCommands(); \
}; \
void* PluginSubCommandsFunctionHelper<PluginFunctionHelperInstantiation>::getSubCommands() { \
return &g_subCommands; \ return &g_subCommands; \
} \ } \
std::vector<hex::SubCommand> g_subCommands std::vector<hex::SubCommand> g_subCommands
@ -98,7 +132,11 @@
#define IMHEX_PLUGIN_FEATURES() IMHEX_PLUGIN_FEATURES_IMPL() #define IMHEX_PLUGIN_FEATURES() IMHEX_PLUGIN_FEATURES_IMPL()
#define IMHEX_PLUGIN_FEATURES_IMPL() \ #define IMHEX_PLUGIN_FEATURES_IMPL() \
extern std::vector<hex::Feature> g_features; \ extern std::vector<hex::Feature> g_features; \
extern "C" [[gnu::visibility("default")]] void* getFeatures() { \ template<> \
struct PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation> { \
static void* getFeatures(); \
}; \
void* PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation>::getFeatures() { \
return &g_features; \ return &g_features; \
} \ } \
std::vector<hex::Feature> g_features std::vector<hex::Feature> g_features

View File

@ -196,6 +196,8 @@ namespace hex {
std::span<Feature> Plugin::getFeatures() const { std::span<Feature> Plugin::getFeatures() const {
if (m_functions.getFeaturesFunction != nullptr) { if (m_functions.getFeaturesFunction != nullptr) {
const auto result = m_functions.getFeaturesFunction(); const auto result = m_functions.getFeaturesFunction();
if (result == nullptr)
return { };
return *static_cast<std::vector<Feature>*>(result); return *static_cast<std::vector<Feature>*>(result);
} else { } else {

View File

@ -14,15 +14,15 @@ namespace hex::plugin::decompress {
using namespace hex; using namespace hex;
using namespace hex::plugin::decompress; using namespace hex::plugin::decompress;
IMHEX_PLUGIN_SETUP("Decompressing", "WerWolv", "Support for decompressing data") {
hex::log::debug("Using romfs: '{}'", romfs::name());
registerPatternLanguageFunctions();
}
IMHEX_PLUGIN_FEATURES() { IMHEX_PLUGIN_FEATURES() {
{ "bzip2 Support", IMHEX_FEATURE_ENABLED(BZIP2) }, { "bzip2 Support", IMHEX_FEATURE_ENABLED(BZIP2) },
{ "zlib Support", IMHEX_FEATURE_ENABLED(ZLIB) }, { "zlib Support", IMHEX_FEATURE_ENABLED(ZLIB) },
{ "LZMA Support", IMHEX_FEATURE_ENABLED(LIBLZMA) }, { "LZMA Support", IMHEX_FEATURE_ENABLED(LIBLZMA) },
{ "zstd Support", IMHEX_FEATURE_ENABLED(ZSTD) }, { "zstd Support", IMHEX_FEATURE_ENABLED(ZSTD) },
}; };
IMHEX_PLUGIN_SETUP("Decompressing", "WerWolv", "Support for decompressing data") {
hex::log::debug("Using romfs: '{}'", romfs::name());
registerPatternLanguageFunctions();
}