mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
@@ -26,22 +26,22 @@ namespace hex {
|
||||
using InitializePluginFunc = void (*)();
|
||||
using InitializeLibraryFunc = void (*)();
|
||||
using GetPluginNameFunc = const char *(*)();
|
||||
using GetLibraryNameFunc = const char *(*)();
|
||||
using GetPluginAuthorFunc = const char *(*)();
|
||||
using GetPluginDescriptionFunc = const char *(*)();
|
||||
using GetCompatibleVersionFunc = const char *(*)();
|
||||
using SetImGuiContextFunc = void (*)(ImGuiContext *);
|
||||
using IsBuiltinPluginFunc = bool (*)();
|
||||
using GetSubCommandsFunc = void* (*)();
|
||||
using GetFeaturesFunc = void* (*)();
|
||||
|
||||
InitializePluginFunc initializePluginFunction = nullptr;
|
||||
InitializeLibraryFunc initializeLibraryFunction = nullptr;
|
||||
GetPluginNameFunc getPluginNameFunction = nullptr;
|
||||
GetLibraryNameFunc getLibraryNameFunction = nullptr;
|
||||
GetPluginAuthorFunc getPluginAuthorFunction = nullptr;
|
||||
GetPluginDescriptionFunc getPluginDescriptionFunction = nullptr;
|
||||
GetCompatibleVersionFunc getCompatibleVersionFunction = nullptr;
|
||||
SetImGuiContextFunc setImGuiContextFunction = nullptr;
|
||||
IsBuiltinPluginFunc isBuiltinPluginFunction = nullptr;
|
||||
GetSubCommandsFunc getSubCommandsFunction = nullptr;
|
||||
GetFeaturesFunc getFeaturesFunction = nullptr;
|
||||
};
|
||||
@@ -49,7 +49,7 @@ namespace hex {
|
||||
class Plugin {
|
||||
public:
|
||||
explicit Plugin(const std::fs::path &path);
|
||||
explicit Plugin(const PluginFunctions &functions);
|
||||
explicit Plugin(const std::string &name, const PluginFunctions &functions);
|
||||
|
||||
Plugin(const Plugin &) = delete;
|
||||
Plugin(Plugin &&other) noexcept;
|
||||
@@ -64,7 +64,6 @@ namespace hex {
|
||||
[[nodiscard]] std::string getPluginDescription() const;
|
||||
[[nodiscard]] std::string getCompatibleVersion() const;
|
||||
void setImGuiContext(ImGuiContext *ctx) const;
|
||||
[[nodiscard]] bool isBuiltinPlugin() const;
|
||||
|
||||
[[nodiscard]] const std::fs::path &getPath() const;
|
||||
|
||||
@@ -100,7 +99,7 @@ namespace hex {
|
||||
static void unload();
|
||||
static void reload();
|
||||
|
||||
static void addPlugin(PluginFunctions functions);
|
||||
static void addPlugin(const std::string &name, PluginFunctions functions);
|
||||
|
||||
static std::vector<Plugin> &getPlugins();
|
||||
static std::vector<std::fs::path> &getPluginPaths();
|
||||
|
||||
@@ -29,15 +29,17 @@
|
||||
#define IMHEX_LIBRARY_SETUP_IMPL(name) \
|
||||
namespace { static struct EXIT_HANDLER { ~EXIT_HANDLER() { hex::log::info("Unloaded library '{}'", name); } } HANDLER; } \
|
||||
IMHEX_PLUGIN_VISIBILITY_PREFIX void initializeLibrary(); \
|
||||
IMHEX_PLUGIN_VISIBILITY_PREFIX const char *getLibraryName() { return name; } \
|
||||
IMHEX_PLUGIN_VISIBILITY_PREFIX void setImGuiContext(ImGuiContext *ctx) { \
|
||||
ImGui::SetCurrentContext(ctx); \
|
||||
GImGui = ctx; \
|
||||
} \
|
||||
extern "C" [[gnu::visibility("default")]] void WOLV_TOKEN_CONCAT(forceLinkPlugin_, IMHEX_PLUGIN_NAME)() { \
|
||||
hex::PluginManager::addPlugin(hex::PluginFunctions { \
|
||||
hex::PluginManager::addPlugin(name, hex::PluginFunctions { \
|
||||
nullptr, \
|
||||
initializeLibrary, \
|
||||
nullptr, \
|
||||
getLibraryName, \
|
||||
nullptr, \
|
||||
nullptr, \
|
||||
nullptr, \
|
||||
@@ -60,10 +62,11 @@
|
||||
} \
|
||||
IMHEX_PLUGIN_VISIBILITY_PREFIX void initializePlugin(); \
|
||||
extern "C" [[gnu::visibility("default")]] void WOLV_TOKEN_CONCAT(forceLinkPlugin_, IMHEX_PLUGIN_NAME)() { \
|
||||
hex::PluginManager::addPlugin(hex::PluginFunctions { \
|
||||
hex::PluginManager::addPlugin(name, hex::PluginFunctions { \
|
||||
initializePlugin, \
|
||||
nullptr, \
|
||||
getPluginName, \
|
||||
nullptr, \
|
||||
getPluginAuthor, \
|
||||
getPluginDescription, \
|
||||
getCompatibleVersion, \
|
||||
|
||||
@@ -39,18 +39,19 @@ namespace hex {
|
||||
m_functions.initializePluginFunction = getPluginFunction<PluginFunctions::InitializePluginFunc>("initializePlugin");
|
||||
m_functions.initializeLibraryFunction = getPluginFunction<PluginFunctions::InitializePluginFunc>("initializeLibrary");
|
||||
m_functions.getPluginNameFunction = getPluginFunction<PluginFunctions::GetPluginNameFunc>("getPluginName");
|
||||
m_functions.getLibraryNameFunction = getPluginFunction<PluginFunctions::GetLibraryNameFunc>("getLibraryName");
|
||||
m_functions.getPluginAuthorFunction = getPluginFunction<PluginFunctions::GetPluginAuthorFunc>("getPluginAuthor");
|
||||
m_functions.getPluginDescriptionFunction = getPluginFunction<PluginFunctions::GetPluginDescriptionFunc>("getPluginDescription");
|
||||
m_functions.getCompatibleVersionFunction = getPluginFunction<PluginFunctions::GetCompatibleVersionFunc>("getCompatibleVersion");
|
||||
m_functions.setImGuiContextFunction = getPluginFunction<PluginFunctions::SetImGuiContextFunc>("setImGuiContext");
|
||||
m_functions.isBuiltinPluginFunction = getPluginFunction<PluginFunctions::IsBuiltinPluginFunc>("isBuiltinPlugin");
|
||||
m_functions.getSubCommandsFunction = getPluginFunction<PluginFunctions::GetSubCommandsFunc>("getSubCommands");
|
||||
m_functions.getFeaturesFunction = getPluginFunction<PluginFunctions::GetSubCommandsFunc>("getFeatures");
|
||||
}
|
||||
|
||||
Plugin::Plugin(const hex::PluginFunctions &functions) {
|
||||
Plugin::Plugin(const std::string &name, const hex::PluginFunctions &functions) {
|
||||
m_handle = 0;
|
||||
m_functions = functions;
|
||||
m_path = name;
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +138,7 @@ namespace hex {
|
||||
return m_functions.getPluginNameFunction();
|
||||
} else {
|
||||
if (this->isLibraryPlugin())
|
||||
return "Library Plugin";
|
||||
return m_functions.getLibraryNameFunction();
|
||||
else
|
||||
return hex::format("Unknown Plugin @ 0x{0:016X}", m_handle);
|
||||
}
|
||||
@@ -170,13 +171,6 @@ namespace hex {
|
||||
m_functions.setImGuiContextFunction(ctx);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool Plugin::isBuiltinPlugin() const {
|
||||
if (m_functions.isBuiltinPluginFunction != nullptr)
|
||||
return m_functions.isBuiltinPluginFunction();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::fs::path &Plugin::getPath() const {
|
||||
return m_path;
|
||||
}
|
||||
@@ -191,7 +185,8 @@ namespace hex {
|
||||
|
||||
std::span<SubCommand> Plugin::getSubCommands() const {
|
||||
if (m_functions.getSubCommandsFunction != nullptr) {
|
||||
auto result = m_functions.getSubCommandsFunction();
|
||||
const auto result = m_functions.getSubCommandsFunction();
|
||||
|
||||
return *static_cast<std::vector<SubCommand>*>(result);
|
||||
} else {
|
||||
return { };
|
||||
@@ -200,7 +195,8 @@ namespace hex {
|
||||
|
||||
std::span<Feature> Plugin::getFeatures() const {
|
||||
if (m_functions.getFeaturesFunction != nullptr) {
|
||||
auto result = m_functions.getFeaturesFunction();
|
||||
const auto result = m_functions.getFeaturesFunction();
|
||||
|
||||
return *static_cast<std::vector<Feature>*>(result);
|
||||
} else {
|
||||
return { };
|
||||
@@ -274,16 +270,8 @@ namespace hex {
|
||||
}
|
||||
}
|
||||
|
||||
void PluginManager::reload() {
|
||||
auto paths = getPluginPaths();
|
||||
|
||||
PluginManager::unload();
|
||||
for (const auto &path : paths)
|
||||
PluginManager::load(path);
|
||||
}
|
||||
|
||||
void PluginManager::addPlugin(hex::PluginFunctions functions) {
|
||||
getPlugins().emplace_back(functions);
|
||||
void PluginManager::addPlugin(const std::string &name, hex::PluginFunctions functions) {
|
||||
getPlugins().emplace_back(name, functions);
|
||||
}
|
||||
|
||||
std::vector<Plugin> &PluginManager::getPlugins() {
|
||||
|
||||
Reference in New Issue
Block a user