impr: Make plugin features and subcommands work in statically linked builds
This commit is contained in:
parent
db1373d572
commit
d511080814
@ -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,9 +84,15 @@
|
|||||||
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 { \
|
||||||
initializePlugin, \
|
initializePlugin, \
|
||||||
nullptr, \
|
nullptr, \
|
||||||
getPluginName, \
|
getPluginName, \
|
||||||
@ -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()
|
||||||
@ -87,18 +117,26 @@
|
|||||||
*/
|
*/
|
||||||
#define IMHEX_PLUGIN_SUBCOMMANDS() IMHEX_PLUGIN_SUBCOMMANDS_IMPL()
|
#define IMHEX_PLUGIN_SUBCOMMANDS() IMHEX_PLUGIN_SUBCOMMANDS_IMPL()
|
||||||
|
|
||||||
#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<> \
|
||||||
return &g_subCommands; \
|
struct PluginSubCommandsFunctionHelper<PluginFunctionHelperInstantiation> { \
|
||||||
} \
|
static void* getSubCommands(); \
|
||||||
|
}; \
|
||||||
|
void* PluginSubCommandsFunctionHelper<PluginFunctionHelperInstantiation>::getSubCommands() { \
|
||||||
|
return &g_subCommands; \
|
||||||
|
} \
|
||||||
std::vector<hex::SubCommand> 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_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() 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<> \
|
||||||
return &g_features; \
|
struct PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation> { \
|
||||||
} \
|
static void* getFeatures(); \
|
||||||
|
}; \
|
||||||
|
void* PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation>::getFeatures() { \
|
||||||
|
return &g_features; \
|
||||||
|
} \
|
||||||
std::vector<hex::Feature> g_features
|
std::vector<hex::Feature> g_features
|
||||||
|
@ -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 {
|
||||||
|
@ -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();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user