1
0
mirror of synced 2025-01-29 19:17:28 +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/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)
#define IMHEX_PLUGIN_VISIBILITY_PREFIX static
#else
@ -60,9 +84,15 @@
ImGui::SetCurrentContext(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(); \
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 { \
initializePlugin, \
nullptr, \
getPluginName, \
@ -71,8 +101,8 @@
getPluginDescription, \
getCompatibleVersion, \
setImGuiContext, \
nullptr, \
nullptr \
getSubCommands, \
getFeatures \
}); \
} \
IMHEX_PLUGIN_VISIBILITY_PREFIX void initializePlugin()
@ -87,18 +117,26 @@
*/
#define IMHEX_PLUGIN_SUBCOMMANDS() IMHEX_PLUGIN_SUBCOMMANDS_IMPL()
#define IMHEX_PLUGIN_SUBCOMMANDS_IMPL() \
extern std::vector<hex::SubCommand> g_subCommands; \
extern "C" [[gnu::visibility("default")]] void* getSubCommands() { \
return &g_subCommands; \
} \
#define IMHEX_PLUGIN_SUBCOMMANDS_IMPL() \
extern std::vector<hex::SubCommand> g_subCommands; \
template<> \
struct PluginSubCommandsFunctionHelper<PluginFunctionHelperInstantiation> { \
static void* getSubCommands(); \
}; \
void* PluginSubCommandsFunctionHelper<PluginFunctionHelperInstantiation>::getSubCommands() { \
return &g_subCommands; \
} \
std::vector<hex::SubCommand> g_subCommands
#define IMHEX_FEATURE_ENABLED(feature) WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(IMHEX_PLUGIN_, IMHEX_PLUGIN_NAME), _FEATURE_), feature)
#define IMHEX_PLUGIN_FEATURES() IMHEX_PLUGIN_FEATURES_IMPL()
#define IMHEX_PLUGIN_FEATURES_IMPL() \
extern std::vector<hex::Feature> g_features; \
extern "C" [[gnu::visibility("default")]] void* getFeatures() { \
return &g_features; \
} \
#define IMHEX_PLUGIN_FEATURES_IMPL() \
extern std::vector<hex::Feature> g_features; \
template<> \
struct PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation> { \
static void* getFeatures(); \
}; \
void* PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation>::getFeatures() { \
return &g_features; \
} \
std::vector<hex::Feature> g_features

View File

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

View File

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