feat: Allow plugins to be dynamically turned on and off

This commit is contained in:
WerWolv
2025-08-05 22:16:39 +02:00
parent 95465e2fc3
commit 5b06702dee
6 changed files with 81 additions and 3 deletions

View File

@@ -46,6 +46,7 @@ EXPORT_MODULE namespace hex {
using SetImGuiContextFunc = void (*)(ImGuiContext *);
using GetSubCommandsFunc = void* (*)();
using GetFeaturesFunc = void* (*)();
using IsBuiltinPluginFunc = bool (*)();
InitializePluginFunc initializePluginFunction = nullptr;
InitializeLibraryFunc initializeLibraryFunction = nullptr;
@@ -58,6 +59,7 @@ EXPORT_MODULE namespace hex {
SetImGuiContextFunc setImGuiContextLibraryFunction = nullptr;
GetSubCommandsFunc getSubCommandsFunction = nullptr;
GetFeaturesFunc getFeaturesFunction = nullptr;
IsBuiltinPluginFunc isBuiltinPluginFunction = nullptr;
};
class Plugin {
@@ -84,6 +86,7 @@ EXPORT_MODULE namespace hex {
[[nodiscard]] bool isLoaded() const;
[[nodiscard]] bool isValid() const;
[[nodiscard]] bool isInitialized() const;
[[nodiscard]] bool isBuiltinPlugin() const;
[[nodiscard]] std::span<SubCommand> getSubCommands() const;
[[nodiscard]] std::span<Feature> getFeatures() const;
@@ -92,12 +95,15 @@ EXPORT_MODULE namespace hex {
[[nodiscard]] bool wasAddedManually() const;
void setEnabled(bool enabled);
private:
uintptr_t m_handle = 0;
std::fs::path m_path;
mutable bool m_initialized = false;
bool m_addedManually = false;
bool m_enabled = true;
PluginFunctions m_functions = {};
@@ -133,6 +139,8 @@ EXPORT_MODULE namespace hex {
static bool isPluginLoaded(const std::fs::path &path);
static void setPluginEnabled(const Plugin &plugin, bool enabled);
private:
static std::list<Plugin>& getPluginsMutable();

View File

@@ -80,6 +80,10 @@ void* PluginSubCommandsFunctionHelper<T>::getSubCommands() {
#define IMHEX_PLUGIN_SETUP(name, author, description) IMHEX_PLUGIN_SETUP_IMPL(name, author, description)
#define IMHEX_LIBRARY_SETUP(name) IMHEX_LIBRARY_SETUP_IMPL(name)
#define IMHEX_PLUGIN_SETUP_BUILTIN(name, author, description) \
IMHEX_PLUGIN_VISIBILITY_PREFIX bool isBuiltinPlugin() { return true; } \
IMHEX_PLUGIN_SETUP_IMPL(name, author, description)
#define IMHEX_LIBRARY_SETUP_IMPL(name) \
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; } \