1
0
mirror of synced 2025-02-06 22:24:24 +01:00

fix: Subcommands not working at all on Linux

This commit is contained in:
WerWolv 2023-07-21 14:12:08 +02:00
parent 3149183450
commit e5a793e8de
3 changed files with 4 additions and 12 deletions

View File

@ -24,11 +24,6 @@ namespace hex {
std::function<void(const std::vector<std::string>&)> callback; std::function<void(const std::vector<std::string>&)> callback;
}; };
struct SubCommandList {
hex::SubCommand *subCommands;
size_t size;
};
class Plugin { class Plugin {
public: public:
explicit Plugin(const std::fs::path &path); explicit Plugin(const std::fs::path &path);
@ -58,7 +53,7 @@ namespace hex {
using GetCompatibleVersionFunc = const char *(*)(); using GetCompatibleVersionFunc = const char *(*)();
using SetImGuiContextFunc = void (*)(ImGuiContext *); using SetImGuiContextFunc = void (*)(ImGuiContext *);
using IsBuiltinPluginFunc = bool (*)(); using IsBuiltinPluginFunc = bool (*)();
using GetSubCommandsFunc = SubCommandList* (*)(); using GetSubCommandsFunc = void* (*)();
#if defined(OS_WINDOWS) #if defined(OS_WINDOWS)
HMODULE m_handle = nullptr; HMODULE m_handle = nullptr;

View File

@ -39,10 +39,7 @@
#define IMHEX_PLUGIN_SUBCOMMANDS_IMPL() \ #define IMHEX_PLUGIN_SUBCOMMANDS_IMPL() \
extern std::vector<hex::SubCommand> g_subCommands; \ extern std::vector<hex::SubCommand> g_subCommands; \
extern "C" [[gnu::visibility("default")]] hex::SubCommandList getSubCommands() { \ extern "C" [[gnu::visibility("default")]] void* getSubCommands() { \
return hex::SubCommandList { \ return &g_subCommands; \
g_subCommands.data(), \
g_subCommands.size() \
}; \
} \ } \
std::vector<hex::SubCommand> g_subCommands std::vector<hex::SubCommand> g_subCommands

View File

@ -155,7 +155,7 @@ namespace hex {
std::span<SubCommand> Plugin::getSubCommands() const { std::span<SubCommand> Plugin::getSubCommands() const {
if (this->m_getSubCommandsFunction != nullptr) { if (this->m_getSubCommandsFunction != nullptr) {
auto result = this->m_getSubCommandsFunction(); auto result = this->m_getSubCommandsFunction();
return { result->subCommands, result->size }; return *reinterpret_cast<std::vector<SubCommand>*>(result);
} else } else
return { }; return { };
} }