mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 13:37:42 -05:00
build/plugins: Added initial support for Rust plugins (#327)
* build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
This commit is contained in:
@@ -24,13 +24,10 @@ namespace hex {
|
||||
It allows you to add/register new content that will be picked up and used by the ImHex core or by other
|
||||
plugins when needed.
|
||||
*/
|
||||
struct ContentRegistry {
|
||||
ContentRegistry() = delete;
|
||||
namespace ContentRegistry {
|
||||
|
||||
/* Settings Registry. Allows adding of new entries into the ImHex preferences window. */
|
||||
struct Settings {
|
||||
Settings() = delete;
|
||||
|
||||
namespace Settings {
|
||||
using Callback = std::function<bool(const std::string&, nlohmann::json&)>;
|
||||
|
||||
struct Entry {
|
||||
@@ -38,28 +35,27 @@ namespace hex {
|
||||
Callback callback;
|
||||
};
|
||||
|
||||
static void load();
|
||||
static void store();
|
||||
void load();
|
||||
void store();
|
||||
|
||||
static void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, s64 defaultValue, const Callback &callback);
|
||||
static void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &defaultValue, const Callback &callback);
|
||||
void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, s64 defaultValue, const Callback &callback);
|
||||
void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &defaultValue, const Callback &callback);
|
||||
|
||||
static void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, s64 value);
|
||||
static void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &value);
|
||||
static void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector<std::string>& value);
|
||||
void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, s64 value);
|
||||
void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &value);
|
||||
void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector<std::string>& value);
|
||||
|
||||
static s64 read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, s64 defaultValue);
|
||||
static std::string read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &defaultValue);
|
||||
static std::vector<std::string> read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector<std::string>& defaultValue = { });
|
||||
s64 read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, s64 defaultValue);
|
||||
std::string read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &defaultValue);
|
||||
std::vector<std::string> read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector<std::string>& defaultValue = { });
|
||||
|
||||
static std::map<std::string, std::vector<Entry>>& getEntries();
|
||||
static nlohmann::json getSetting(const std::string &unlocalizedCategory, const std::string &unlocalizedName);
|
||||
static nlohmann::json& getSettingsData();
|
||||
std::map<std::string, std::vector<Entry>>& getEntries();
|
||||
nlohmann::json getSetting(const std::string &unlocalizedCategory, const std::string &unlocalizedName);
|
||||
nlohmann::json& getSettingsData();
|
||||
};
|
||||
|
||||
/* Command Palette Command Registry. Allows adding of new commands to the command palette */
|
||||
struct CommandPaletteCommands {
|
||||
CommandPaletteCommands() = delete;
|
||||
namespace CommandPaletteCommands {
|
||||
|
||||
enum class Type : u32 {
|
||||
SymbolCommand,
|
||||
@@ -77,13 +73,12 @@ namespace hex {
|
||||
ExecuteCallback executeCallback;
|
||||
};
|
||||
|
||||
static void add(Type type, const std::string &command, const std::string &unlocalizedDescription, const DisplayCallback &displayCallback, const ExecuteCallback &executeCallback = [](auto){});
|
||||
static std::vector<Entry>& getEntries();
|
||||
void add(Type type, const std::string &command, const std::string &unlocalizedDescription, const DisplayCallback &displayCallback, const ExecuteCallback &executeCallback = [](auto){});
|
||||
std::vector<Entry>& getEntries();
|
||||
};
|
||||
|
||||
/* Pattern Language Function Registry. Allows adding of new functions that may be used inside the pattern language */
|
||||
struct PatternLanguageFunctions {
|
||||
PatternLanguageFunctions() = delete;
|
||||
namespace PatternLanguageFunctions {
|
||||
|
||||
constexpr static u32 UnlimitedParameters = 0xFFFF'FFFF;
|
||||
constexpr static u32 MoreParametersThan = 0x8000'0000;
|
||||
@@ -98,31 +93,25 @@ namespace hex {
|
||||
Callback func;
|
||||
};
|
||||
|
||||
static void add(const Namespace &ns, const std::string &name, u32 parameterCount, const Callback &func);
|
||||
static std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function>& getEntries();
|
||||
void add(const Namespace &ns, const std::string &name, u32 parameterCount, const Callback &func);
|
||||
std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function>& getEntries();
|
||||
};
|
||||
|
||||
/* View Registry. Allows adding of new windows */
|
||||
struct Views {
|
||||
Views() = delete;
|
||||
namespace Views {
|
||||
void add(View *view);
|
||||
|
||||
template<hex::derived_from<View> T, typename ... Args>
|
||||
static void add(Args&& ... args) {
|
||||
void add(Args&& ... args) {
|
||||
return add(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
static std::vector<View*>& getEntries();
|
||||
|
||||
private:
|
||||
static void add(View *view);
|
||||
|
||||
std::vector<View*>& getEntries();
|
||||
|
||||
};
|
||||
|
||||
/* Tools Registry. Allows adding new entries to the tools window */
|
||||
struct Tools {
|
||||
Tools() = delete;
|
||||
|
||||
namespace Tools {
|
||||
using Callback = std::function<void()>;
|
||||
|
||||
struct Entry {
|
||||
@@ -130,14 +119,13 @@ namespace hex {
|
||||
Callback function;
|
||||
};
|
||||
|
||||
static void add(const std::string &unlocalizedName, const Callback &function);
|
||||
void add(const std::string &unlocalizedName, const Callback &function);
|
||||
|
||||
static std::vector<Entry>& getEntries();
|
||||
std::vector<Entry>& getEntries();
|
||||
};
|
||||
|
||||
/* Data Inspector Registry. Allows adding of new types to the data inspector */
|
||||
struct DataInspector {
|
||||
DataInspector() = delete;
|
||||
namespace DataInspector {
|
||||
|
||||
enum class NumberDisplayStyle {
|
||||
Decimal,
|
||||
@@ -154,13 +142,14 @@ namespace hex {
|
||||
GeneratorFunction generatorFunction;
|
||||
};
|
||||
|
||||
static void add(const std::string &unlocalizedName, size_t requiredSize, GeneratorFunction function);
|
||||
void add(const std::string &unlocalizedName, size_t requiredSize, GeneratorFunction function);
|
||||
|
||||
static std::vector<Entry>& getEntries();
|
||||
std::vector<Entry>& getEntries();
|
||||
};
|
||||
|
||||
/* Data Processor Node Registry. Allows adding new processor nodes to be used in the data processor */
|
||||
struct DataProcessorNode {
|
||||
namespace DataProcessorNode {
|
||||
|
||||
using CreatorFunction = std::function<dp::Node*()>;
|
||||
struct Entry {
|
||||
std::string category;
|
||||
@@ -168,8 +157,10 @@ namespace hex {
|
||||
CreatorFunction creatorFunction;
|
||||
};
|
||||
|
||||
void add(const Entry &entry);
|
||||
|
||||
template<hex::derived_from<dp::Node> T, typename ... Args>
|
||||
static void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, Args&& ... args) {
|
||||
void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, Args&& ... args) {
|
||||
add(Entry{ unlocalizedCategory.c_str(), unlocalizedName.c_str(),
|
||||
[=]{
|
||||
auto node = new T(std::forward<Args>(args)...);
|
||||
@@ -179,33 +170,32 @@ namespace hex {
|
||||
});
|
||||
}
|
||||
|
||||
static void addSeparator();
|
||||
void addSeparator();
|
||||
|
||||
std::vector<Entry>& getEntries();
|
||||
|
||||
static std::vector<Entry>& getEntries();
|
||||
private:
|
||||
static void add(const Entry &entry);
|
||||
};
|
||||
|
||||
/* Language Registry. Allows together with the LangEntry class and the _lang user defined literal to add new languages */
|
||||
struct Language {
|
||||
static void registerLanguage(const std::string &name, const std::string &languageCode);
|
||||
static void addLocalizations(const std::string &languageCode, const LanguageDefinition &definition);
|
||||
namespace Language {
|
||||
void registerLanguage(const std::string &name, const std::string &languageCode);
|
||||
void addLocalizations(const std::string &languageCode, const LanguageDefinition &definition);
|
||||
|
||||
static std::map<std::string, std::string>& getLanguages();
|
||||
static std::map<std::string, std::vector<LanguageDefinition>>& getLanguageDefinitions();
|
||||
std::map<std::string, std::string>& getLanguages();
|
||||
std::map<std::string, std::vector<LanguageDefinition>>& getLanguageDefinitions();
|
||||
};
|
||||
|
||||
/* Interface Registry. Allows adding new items to various interfaces */
|
||||
struct Interface {
|
||||
namespace Interface {
|
||||
using DrawCallback = std::function<void()>;
|
||||
|
||||
static void addWelcomeScreenEntry(const DrawCallback &function);
|
||||
static void addFooterItem(const DrawCallback &function);
|
||||
static void addToolbarItem(const DrawCallback &function);
|
||||
void addWelcomeScreenEntry(const DrawCallback &function);
|
||||
void addFooterItem(const DrawCallback &function);
|
||||
void addToolbarItem(const DrawCallback &function);
|
||||
|
||||
static std::vector<DrawCallback>& getWelcomeScreenEntries();
|
||||
static std::vector<DrawCallback>& getFooterItems();
|
||||
static std::vector<DrawCallback>& getToolbarItems();
|
||||
std::vector<DrawCallback>& getWelcomeScreenEntries();
|
||||
std::vector<DrawCallback>& getFooterItems();
|
||||
std::vector<DrawCallback>& getToolbarItems();
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -12,19 +12,16 @@ namespace hex {
|
||||
|
||||
namespace prv { class Provider; }
|
||||
|
||||
struct ImHexApi {
|
||||
ImHexApi() = delete;
|
||||
namespace ImHexApi {
|
||||
namespace Common {
|
||||
|
||||
struct Common {
|
||||
|
||||
static void closeImHex(bool noQuestions = false);
|
||||
static void restartImHex();
|
||||
void sayHello();
|
||||
void closeImHex(bool noQuestions = false);
|
||||
void restartImHex();
|
||||
|
||||
};
|
||||
|
||||
struct Bookmarks {
|
||||
Bookmarks() = delete;
|
||||
|
||||
namespace Bookmarks {
|
||||
struct Entry {
|
||||
Region region;
|
||||
|
||||
@@ -34,28 +31,28 @@ namespace hex {
|
||||
bool locked;
|
||||
};
|
||||
|
||||
static void add(Region region, const std::string &name, const std::string &comment, u32 color = 0x00000000);
|
||||
static void add(u64 addr, size_t size, const std::string &name, const std::string &comment, u32 color = 0x00000000);
|
||||
void add(Region region, const std::string &name, const std::string &comment, u32 color = 0x00000000);
|
||||
void add(u64 addr, size_t size, const std::string &name, const std::string &comment, u32 color = 0x00000000);
|
||||
|
||||
static std::list<Entry>& getEntries();
|
||||
std::list<Entry>& getEntries();
|
||||
};
|
||||
|
||||
struct Provider {
|
||||
namespace Provider {
|
||||
|
||||
static prv::Provider* get();
|
||||
static const std::vector<prv::Provider*>& getProviders();
|
||||
prv::Provider* get();
|
||||
const std::vector<prv::Provider*>& getProviders();
|
||||
|
||||
static bool isValid();
|
||||
bool isValid();
|
||||
|
||||
void add(prv::Provider *provider);
|
||||
|
||||
template<hex::derived_from<prv::Provider> T>
|
||||
static void add(auto&& ... args) {
|
||||
void add(auto&& ... args) {
|
||||
add(new T(std::forward<decltype(args)>(args)...));
|
||||
}
|
||||
|
||||
static void remove(prv::Provider *provider);
|
||||
void remove(prv::Provider *provider);
|
||||
|
||||
private:
|
||||
static void add(prv::Provider *provider);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user