mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 13:37:42 -05:00
feat: Allow plugins to be dynamically turned on and off
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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; } \
|
||||
|
||||
Reference in New Issue
Block a user