2020-12-22 18:10:01 +01:00
|
|
|
#pragma once
|
|
|
|
|
2020-12-27 15:39:06 +01:00
|
|
|
#include <hex.hpp>
|
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/views/view.hpp>
|
|
|
|
#include <hex/providers/provider.hpp>
|
2021-02-19 13:22:12 +01:00
|
|
|
#include <hex/helpers/utils.hpp>
|
2020-12-22 18:10:01 +01:00
|
|
|
|
|
|
|
#include <string_view>
|
2021-02-19 13:22:12 +01:00
|
|
|
#include <dlfcn.h>
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-08-21 00:51:50 +02:00
|
|
|
struct ImGuiContext;
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
namespace hex {
|
|
|
|
|
|
|
|
class Plugin {
|
|
|
|
public:
|
|
|
|
Plugin(std::string_view path);
|
2021-02-07 14:57:13 +01:00
|
|
|
Plugin(const Plugin&) = delete;
|
2021-02-19 13:22:12 +01:00
|
|
|
Plugin(Plugin &&other) noexcept;
|
2020-12-22 18:10:01 +01:00
|
|
|
~Plugin();
|
|
|
|
|
2021-01-12 23:28:41 +01:00
|
|
|
void initializePlugin() const;
|
2021-02-19 13:22:12 +01:00
|
|
|
std::string getPluginName() const;
|
|
|
|
std::string getPluginAuthor() const;
|
|
|
|
std::string getPluginDescription() const;
|
2021-08-21 00:51:50 +02:00
|
|
|
void setImGuiContext(ImGuiContext *ctx) const;
|
2021-02-19 13:22:12 +01:00
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
|
|
|
|
private:
|
2021-02-19 13:22:12 +01:00
|
|
|
using InitializePluginFunc = void(*)();
|
|
|
|
using GetPluginNameFunc = const char*(*)();
|
|
|
|
using GetPluginAuthorFunc = const char*(*)();
|
|
|
|
using GetPluginDescriptionFunc = const char*(*)();
|
2021-08-21 00:51:50 +02:00
|
|
|
using SetImGuiContextFunc = void(*)(ImGuiContext*);
|
2020-12-22 18:10:01 +01:00
|
|
|
|
|
|
|
void *m_handle = nullptr;
|
|
|
|
|
2021-02-19 13:22:12 +01:00
|
|
|
InitializePluginFunc m_initializePluginFunction = nullptr;
|
|
|
|
GetPluginNameFunc m_getPluginNameFunction = nullptr;
|
|
|
|
GetPluginAuthorFunc m_getPluginAuthorFunction = nullptr;
|
|
|
|
GetPluginDescriptionFunc m_getPluginDescriptionFunction = nullptr;
|
2021-08-21 00:51:50 +02:00
|
|
|
SetImGuiContextFunc m_setImGuiContextFunction = nullptr;
|
2021-02-19 13:22:12 +01:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
auto getPluginFunction(std::string_view pluginName, std::string_view symbol) {
|
|
|
|
auto symbolName = hex::format(symbol.data(), pluginName.length(), pluginName.data());
|
|
|
|
return reinterpret_cast<T>(dlsym(this->m_handle, symbolName.c_str()));
|
|
|
|
};
|
2020-12-22 18:10:01 +01:00
|
|
|
};
|
|
|
|
|
2021-04-20 21:46:48 +02:00
|
|
|
class PluginManager {
|
2020-12-22 18:10:01 +01:00
|
|
|
public:
|
2021-04-20 21:46:48 +02:00
|
|
|
PluginManager() = delete;
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-04-20 21:46:48 +02:00
|
|
|
static bool load(std::string_view pluginFolder);
|
2020-12-22 18:10:01 +01:00
|
|
|
static void unload();
|
|
|
|
static void reload();
|
|
|
|
|
|
|
|
static const auto& getPlugins() {
|
2021-04-20 21:46:48 +02:00
|
|
|
return PluginManager::s_plugins;
|
2020-12-22 18:10:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static inline std::string s_pluginFolder;
|
2021-02-07 14:57:13 +01:00
|
|
|
static inline std::vector<Plugin> s_plugins;
|
2020-12-22 18:10:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|