2020-12-22 17:10:01 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-12-27 14:39:06 +00:00
|
|
|
#include <hex.hpp>
|
|
|
|
|
2021-08-29 20:15:18 +00:00
|
|
|
#include <hex/helpers/fmt.hpp>
|
2022-01-13 13:33:30 +00:00
|
|
|
#include <hex/helpers/paths.hpp>
|
2020-12-22 17:10:01 +00:00
|
|
|
|
2022-01-17 23:10:10 +00:00
|
|
|
#include <string>
|
2020-12-22 17:10:01 +00:00
|
|
|
|
2021-08-20 22:51:50 +00:00
|
|
|
struct ImGuiContext;
|
|
|
|
|
2020-12-22 17:10:01 +00:00
|
|
|
namespace hex {
|
|
|
|
|
|
|
|
class Plugin {
|
|
|
|
public:
|
2022-01-17 19:06:00 +00:00
|
|
|
explicit Plugin(const fs::path &path);
|
2021-02-07 13:57:13 +00:00
|
|
|
Plugin(const Plugin&) = delete;
|
2021-02-19 12:22:12 +00:00
|
|
|
Plugin(Plugin &&other) noexcept;
|
2020-12-22 17:10:01 +00:00
|
|
|
~Plugin();
|
|
|
|
|
2022-01-17 19:06:00 +00:00
|
|
|
[[nodiscard]] bool initializePlugin() const;
|
2021-09-08 13:18:24 +00:00
|
|
|
[[nodiscard]] std::string getPluginName() const;
|
|
|
|
[[nodiscard]] std::string getPluginAuthor() const;
|
|
|
|
[[nodiscard]] std::string getPluginDescription() const;
|
2022-01-23 22:28:56 +00:00
|
|
|
[[nodiscard]] std::string getCompatibleVersion() const;
|
2021-08-20 22:51:50 +00:00
|
|
|
void setImGuiContext(ImGuiContext *ctx) const;
|
2021-02-19 12:22:12 +00:00
|
|
|
|
2022-01-17 19:06:00 +00:00
|
|
|
[[nodiscard]] const fs::path& getPath() const;
|
2020-12-22 17:10:01 +00:00
|
|
|
|
2022-01-23 22:28:56 +00:00
|
|
|
[[nodiscard]] bool isLoaded() const;
|
2020-12-22 17:10:01 +00:00
|
|
|
private:
|
2021-02-19 12:22:12 +00:00
|
|
|
using InitializePluginFunc = void(*)();
|
|
|
|
using GetPluginNameFunc = const char*(*)();
|
|
|
|
using GetPluginAuthorFunc = const char*(*)();
|
|
|
|
using GetPluginDescriptionFunc = const char*(*)();
|
2022-01-23 22:28:56 +00:00
|
|
|
using GetCompatibleVersionFunc = const char*(*)();
|
2021-08-20 22:51:50 +00:00
|
|
|
using SetImGuiContextFunc = void(*)(ImGuiContext*);
|
2020-12-22 17:10:01 +00:00
|
|
|
|
|
|
|
void *m_handle = nullptr;
|
2022-01-17 19:06:00 +00:00
|
|
|
fs::path m_path;
|
2020-12-22 17:10:01 +00:00
|
|
|
|
2022-01-23 22:28:56 +00:00
|
|
|
mutable bool m_initialized = false;
|
|
|
|
|
2022-01-17 23:10:10 +00:00
|
|
|
InitializePluginFunc m_initializePluginFunction = nullptr;
|
|
|
|
GetPluginNameFunc m_getPluginNameFunction = nullptr;
|
|
|
|
GetPluginAuthorFunc m_getPluginAuthorFunction = nullptr;
|
|
|
|
GetPluginDescriptionFunc m_getPluginDescriptionFunction = nullptr;
|
2022-01-23 22:28:56 +00:00
|
|
|
GetCompatibleVersionFunc m_getCompatibleVersionFunction = nullptr;
|
2022-01-17 23:10:10 +00:00
|
|
|
SetImGuiContextFunc m_setImGuiContextFunction = nullptr;
|
2021-02-19 12:22:12 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2022-01-23 22:28:56 +00:00
|
|
|
[[nodiscard]] auto getPluginFunction(const std::string &symbol) {
|
|
|
|
return reinterpret_cast<T>(this->getPluginFunction(symbol));
|
2022-01-17 23:10:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-01-23 22:28:56 +00:00
|
|
|
[[nodiscard]] void* getPluginFunction(const std::string &symbol);
|
2020-12-22 17:10:01 +00:00
|
|
|
};
|
|
|
|
|
2021-04-20 19:46:48 +00:00
|
|
|
class PluginManager {
|
2020-12-22 17:10:01 +00:00
|
|
|
public:
|
2021-04-20 19:46:48 +00:00
|
|
|
PluginManager() = delete;
|
2020-12-22 17:10:01 +00:00
|
|
|
|
2022-01-13 13:33:30 +00:00
|
|
|
static bool load(const fs::path &pluginFolder);
|
2020-12-22 17:10:01 +00:00
|
|
|
static void unload();
|
|
|
|
static void reload();
|
|
|
|
|
|
|
|
static const auto& getPlugins() {
|
2021-04-20 19:46:48 +00:00
|
|
|
return PluginManager::s_plugins;
|
2020-12-22 17:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-01-13 13:33:30 +00:00
|
|
|
static inline fs::path s_pluginFolder;
|
2021-02-07 13:57:13 +00:00
|
|
|
static inline std::vector<Plugin> s_plugins;
|
2020-12-22 17:10:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|