2020-12-27 15:39:06 +01:00
|
|
|
#pragma once
|
|
|
|
|
2023-11-18 14:34:33 +01:00
|
|
|
#include <hex.hpp>
|
|
|
|
#include <hex/api/plugin_manager.hpp>
|
2023-12-28 14:59:23 +01:00
|
|
|
#include <hex/helpers/logger.hpp>
|
2023-11-18 14:34:33 +01:00
|
|
|
|
2023-07-13 14:08:23 +02:00
|
|
|
#include <string>
|
|
|
|
|
2020-12-27 15:39:06 +01:00
|
|
|
#include <imgui.h>
|
2021-08-21 00:52:11 +02:00
|
|
|
#include <imgui_internal.h>
|
2020-12-27 15:39:06 +01:00
|
|
|
|
2023-07-13 14:08:23 +02:00
|
|
|
#include <wolv/utils/string.hpp>
|
2023-10-04 12:00:32 +02:00
|
|
|
#include <wolv/utils/preproc.hpp>
|
2024-01-09 10:53:50 +01:00
|
|
|
#include <wolv/utils/guards.hpp>
|
2023-10-04 12:00:32 +02:00
|
|
|
|
2024-01-13 00:34:13 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-07-08 21:34:47 +02:00
|
|
|
[[maybe_unused]] static auto& getFeaturesImpl() {
|
|
|
|
static std::vector<hex::Feature> features;
|
|
|
|
return features;
|
|
|
|
}
|
2024-07-08 18:12:46 +02:00
|
|
|
|
2023-10-04 12:00:32 +02:00
|
|
|
#if defined (IMHEX_STATIC_LINK_PLUGINS)
|
|
|
|
#define IMHEX_PLUGIN_VISIBILITY_PREFIX static
|
|
|
|
#else
|
|
|
|
#define IMHEX_PLUGIN_VISIBILITY_PREFIX extern "C" [[gnu::visibility("default")]]
|
|
|
|
#endif
|
2020-12-27 15:39:06 +01:00
|
|
|
|
2024-07-08 18:12:46 +02:00
|
|
|
#define IMHEX_FEATURE_ENABLED(feature) WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(IMHEX_PLUGIN_, IMHEX_PLUGIN_NAME), _FEATURE_), feature)
|
|
|
|
#define IMHEX_DEFINE_PLUGIN_FEATURES() IMHEX_DEFINE_PLUGIN_FEATURES_IMPL()
|
|
|
|
#define IMHEX_DEFINE_PLUGIN_FEATURES_IMPL() \
|
|
|
|
template<> \
|
|
|
|
struct PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation> { \
|
|
|
|
static void* getFeatures(); \
|
|
|
|
}; \
|
|
|
|
void* PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation>::getFeatures() { \
|
2024-07-08 21:34:47 +02:00
|
|
|
return &getFeaturesImpl(); \
|
2024-07-08 18:12:46 +02:00
|
|
|
} \
|
2024-07-08 21:34:47 +02:00
|
|
|
static auto initFeatures = [] { getFeaturesImpl() = std::vector<hex::Feature>({ IMHEX_PLUGIN_FEATURES_CONTENT }); return 0; }()
|
2024-07-08 18:12:46 +02:00
|
|
|
|
2024-07-08 21:34:47 +02:00
|
|
|
#define IMHEX_PLUGIN_FEATURES ::getFeaturesImpl()
|
2024-07-08 18:12:46 +02:00
|
|
|
|
2023-04-18 10:06:47 +02:00
|
|
|
/**
|
|
|
|
* This macro is used to define all the required entry points for a plugin.
|
2024-07-08 21:34:47 +02:00
|
|
|
* Name, Author and Description will be displayed in the plugin list on the Welcome screen.
|
2023-04-18 10:06:47 +02:00
|
|
|
*/
|
2022-02-02 17:19:50 +01:00
|
|
|
#define IMHEX_PLUGIN_SETUP(name, author, description) IMHEX_PLUGIN_SETUP_IMPL(name, author, description)
|
2024-01-09 10:53:50 +01:00
|
|
|
#define IMHEX_LIBRARY_SETUP(name) IMHEX_LIBRARY_SETUP_IMPL(name)
|
2023-12-23 21:09:41 +01:00
|
|
|
|
2024-01-09 10:53:50 +01:00
|
|
|
#define IMHEX_LIBRARY_SETUP_IMPL(name) \
|
2024-01-22 12:53:07 +01:00
|
|
|
namespace { static struct EXIT_HANDLER { ~EXIT_HANDLER() { hex::log::debug("Unloaded library '{}'", name); } } HANDLER; } \
|
2024-01-29 15:44:18 +01:00
|
|
|
IMHEX_PLUGIN_VISIBILITY_PREFIX void WOLV_TOKEN_CONCAT(initializeLibrary_, IMHEX_PLUGIN_NAME)(); \
|
|
|
|
IMHEX_PLUGIN_VISIBILITY_PREFIX const char *WOLV_TOKEN_CONCAT(getLibraryName_, IMHEX_PLUGIN_NAME)() { return name; } \
|
|
|
|
IMHEX_PLUGIN_VISIBILITY_PREFIX void WOLV_TOKEN_CONCAT(setImGuiContext_, IMHEX_PLUGIN_NAME)(ImGuiContext *ctx) { \
|
2024-01-09 10:53:50 +01:00
|
|
|
ImGui::SetCurrentContext(ctx); \
|
|
|
|
GImGui = ctx; \
|
|
|
|
} \
|
|
|
|
extern "C" [[gnu::visibility("default")]] void WOLV_TOKEN_CONCAT(forceLinkPlugin_, IMHEX_PLUGIN_NAME)() { \
|
2024-01-22 12:53:07 +01:00
|
|
|
hex::PluginManager::addPlugin(name, hex::PluginFunctions { \
|
2024-01-09 10:53:50 +01:00
|
|
|
nullptr, \
|
2024-01-29 15:44:18 +01:00
|
|
|
WOLV_TOKEN_CONCAT(initializeLibrary_, IMHEX_PLUGIN_NAME), \
|
2024-01-09 10:53:50 +01:00
|
|
|
nullptr, \
|
2024-01-29 15:44:18 +01:00
|
|
|
WOLV_TOKEN_CONCAT(getLibraryName_, IMHEX_PLUGIN_NAME), \
|
2024-01-09 10:53:50 +01:00
|
|
|
nullptr, \
|
|
|
|
nullptr, \
|
|
|
|
nullptr, \
|
2024-01-29 15:44:18 +01:00
|
|
|
WOLV_TOKEN_CONCAT(setImGuiContext_, IMHEX_PLUGIN_NAME), \
|
|
|
|
nullptr, \
|
2024-01-09 10:53:50 +01:00
|
|
|
nullptr, \
|
|
|
|
nullptr \
|
|
|
|
}); \
|
|
|
|
} \
|
2024-01-29 15:44:18 +01:00
|
|
|
IMHEX_PLUGIN_VISIBILITY_PREFIX void WOLV_TOKEN_CONCAT(initializeLibrary_, IMHEX_PLUGIN_NAME)()
|
2021-02-07 13:40:47 +01:00
|
|
|
|
2024-01-09 10:53:50 +01:00
|
|
|
#define IMHEX_PLUGIN_SETUP_IMPL(name, author, description) \
|
2024-01-22 12:53:07 +01:00
|
|
|
namespace { static struct EXIT_HANDLER { ~EXIT_HANDLER() { hex::log::debug("Unloaded plugin '{}'", name); } } HANDLER; } \
|
2024-01-09 10:53:50 +01:00
|
|
|
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; \
|
|
|
|
} \
|
2024-07-08 18:12:46 +02:00
|
|
|
IMHEX_DEFINE_PLUGIN_FEATURES(); \
|
2024-01-13 00:34:13 +01:00
|
|
|
IMHEX_PLUGIN_VISIBILITY_PREFIX void* getFeatures() { \
|
|
|
|
return PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation>::getFeatures(); \
|
|
|
|
} \
|
|
|
|
IMHEX_PLUGIN_VISIBILITY_PREFIX void* getSubCommands() { \
|
|
|
|
return PluginSubCommandsFunctionHelper<PluginFunctionHelperInstantiation>::getSubCommands(); \
|
|
|
|
} \
|
2024-01-09 10:53:50 +01:00
|
|
|
IMHEX_PLUGIN_VISIBILITY_PREFIX void initializePlugin(); \
|
|
|
|
extern "C" [[gnu::visibility("default")]] void WOLV_TOKEN_CONCAT(forceLinkPlugin_, IMHEX_PLUGIN_NAME)() { \
|
2024-01-13 00:34:13 +01:00
|
|
|
hex::PluginManager::addPlugin(name, hex::PluginFunctions { \
|
2024-01-09 10:53:50 +01:00
|
|
|
initializePlugin, \
|
|
|
|
nullptr, \
|
|
|
|
getPluginName, \
|
2024-01-12 23:03:13 +01:00
|
|
|
nullptr, \
|
2024-01-09 10:53:50 +01:00
|
|
|
getPluginAuthor, \
|
|
|
|
getPluginDescription, \
|
|
|
|
getCompatibleVersion, \
|
|
|
|
setImGuiContext, \
|
2024-01-29 15:44:18 +01:00
|
|
|
nullptr, \
|
2024-01-13 00:34:13 +01:00
|
|
|
getSubCommands, \
|
|
|
|
getFeatures \
|
2024-01-09 10:53:50 +01:00
|
|
|
}); \
|
|
|
|
} \
|
2023-10-04 12:00:32 +02:00
|
|
|
IMHEX_PLUGIN_VISIBILITY_PREFIX void initializePlugin()
|
2023-07-13 14:08:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This macro is used to define subcommands defined by the plugin
|
|
|
|
* A subcommand consists of a key, a description, and a callback
|
|
|
|
* The key is what the first argument to ImHex should be, prefixed by `--`
|
|
|
|
* For example, if the key if `help`, ImHex should be started with `--help` as its first argument to trigger the subcommand
|
|
|
|
* when the subcommand is triggerred, it's callback will be executed. The callback is executed BEFORE most of ImHex initialization
|
|
|
|
* so to do anything meaningful, you should subscribe to an event (like EventImHexStartupFinished) and run your code there.
|
|
|
|
*/
|
|
|
|
#define IMHEX_PLUGIN_SUBCOMMANDS() IMHEX_PLUGIN_SUBCOMMANDS_IMPL()
|
|
|
|
|
2024-01-13 00:34:13 +01:00
|
|
|
#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; \
|
|
|
|
} \
|
2023-07-13 14:08:23 +02:00
|
|
|
std::vector<hex::SubCommand> g_subCommands
|