2021-01-11 20:31:40 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
2021-08-29 22:15:18 +02:00
|
|
|
#include <hex/helpers/concepts.hpp>
|
2021-09-21 21:29:18 +02:00
|
|
|
#include <hex/pattern_language/token.hpp>
|
2021-01-13 17:41:16 +01:00
|
|
|
|
2021-01-11 20:31:40 +01:00
|
|
|
#include <functional>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
#include <nlohmann/json_fwd.hpp>
|
2021-01-11 20:31:40 +01:00
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
2021-01-12 16:50:15 +01:00
|
|
|
class View;
|
2021-09-08 15:18:24 +02:00
|
|
|
class LanguageDefinition;
|
2021-09-21 21:29:18 +02:00
|
|
|
namespace pl { class Evaluator; }
|
2021-01-30 22:39:06 +01:00
|
|
|
namespace dp { class Node; }
|
2021-01-11 23:54:12 +01:00
|
|
|
|
2021-01-12 16:50:15 +01:00
|
|
|
/*
|
|
|
|
The Content Registry is the heart of all features in ImHex that are in some way extendable by Plugins.
|
|
|
|
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.
|
|
|
|
*/
|
2021-01-20 20:16:24 +01:00
|
|
|
struct ContentRegistry {
|
2021-01-11 20:31:40 +01:00
|
|
|
ContentRegistry() = delete;
|
|
|
|
|
2021-01-12 16:50:15 +01:00
|
|
|
/* Settings Registry. Allows adding of new entries into the ImHex preferences window. */
|
2021-01-11 20:31:40 +01:00
|
|
|
struct Settings {
|
|
|
|
Settings() = delete;
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
using Callback = std::function<bool(const std::string&, nlohmann::json&)>;
|
|
|
|
|
2021-01-11 20:31:40 +01:00
|
|
|
struct Entry {
|
|
|
|
std::string name;
|
2021-09-08 15:18:24 +02:00
|
|
|
Callback callback;
|
2021-01-11 20:31:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void load();
|
|
|
|
static void store();
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
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);
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
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);
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
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 = { });
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2021-01-11 20:31:40 +01:00
|
|
|
static std::map<std::string, std::vector<Entry>>& getEntries();
|
2021-09-08 15:18:24 +02:00
|
|
|
static nlohmann::json getSetting(const std::string &unlocalizedCategory, const std::string &unlocalizedName);
|
2021-01-11 20:31:40 +01:00
|
|
|
static nlohmann::json& getSettingsData();
|
|
|
|
};
|
2021-01-11 21:11:03 +01:00
|
|
|
|
2021-01-12 16:50:15 +01:00
|
|
|
/* Command Palette Command Registry. Allows adding of new commands to the command palette */
|
2021-01-11 23:02:55 +01:00
|
|
|
struct CommandPaletteCommands {
|
|
|
|
CommandPaletteCommands() = delete;
|
|
|
|
|
|
|
|
enum class Type : u32 {
|
|
|
|
SymbolCommand,
|
|
|
|
KeywordCommand
|
|
|
|
};
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
using DisplayCallback = std::function<std::string(std::string)>;
|
|
|
|
using ExecuteCallback = std::function<void(std::string)>;
|
|
|
|
|
2021-01-11 23:02:55 +01:00
|
|
|
struct Entry {
|
|
|
|
Type type;
|
|
|
|
std::string command;
|
2021-02-13 15:15:32 +01:00
|
|
|
std::string unlocalizedDescription;
|
2021-09-08 15:18:24 +02:00
|
|
|
DisplayCallback displayCallback;
|
|
|
|
ExecuteCallback executeCallback;
|
2021-01-11 23:02:55 +01:00
|
|
|
};
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
static void add(Type type, const std::string &command, const std::string &unlocalizedDescription, const DisplayCallback &displayCallback, const ExecuteCallback &executeCallback = [](auto){});
|
2021-01-12 16:50:15 +01:00
|
|
|
static std::vector<Entry>& getEntries();
|
2021-01-11 23:02:55 +01:00
|
|
|
};
|
2021-01-11 23:54:12 +01:00
|
|
|
|
2021-01-12 16:50:15 +01:00
|
|
|
/* Pattern Language Function Registry. Allows adding of new functions that may be used inside the pattern language */
|
2021-01-11 23:54:12 +01:00
|
|
|
struct PatternLanguageFunctions {
|
|
|
|
PatternLanguageFunctions() = delete;
|
|
|
|
|
|
|
|
constexpr static u32 UnlimitedParameters = 0xFFFF'FFFF;
|
|
|
|
constexpr static u32 MoreParametersThan = 0x8000'0000;
|
|
|
|
constexpr static u32 LessParametersThan = 0x4000'0000;
|
|
|
|
constexpr static u32 NoParameters = 0x0000'0000;
|
|
|
|
|
2021-08-27 09:56:20 +02:00
|
|
|
using Namespace = std::vector<std::string>;
|
2021-09-21 21:29:18 +02:00
|
|
|
using Callback = std::function<std::optional<hex::pl::Token::Literal>(hex::pl::Evaluator*, const std::vector<hex::pl::Token::Literal>&)>;
|
2021-08-27 09:56:20 +02:00
|
|
|
|
2021-01-11 23:54:12 +01:00
|
|
|
struct Function {
|
|
|
|
u32 parameterCount;
|
2021-09-08 15:18:24 +02:00
|
|
|
Callback func;
|
2021-01-11 23:54:12 +01:00
|
|
|
};
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
static void add(const Namespace &ns, const std::string &name, u32 parameterCount, const Callback &func);
|
2021-01-12 16:50:15 +01:00
|
|
|
static std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function>& getEntries();
|
|
|
|
};
|
|
|
|
|
|
|
|
/* View Registry. Allows adding of new windows */
|
|
|
|
struct Views {
|
|
|
|
Views() = delete;
|
|
|
|
|
2021-01-13 17:41:16 +01:00
|
|
|
template<hex::derived_from<View> T, typename ... Args>
|
2021-02-03 00:56:33 +01:00
|
|
|
static void add(Args&& ... args) {
|
2021-03-16 22:44:37 +01:00
|
|
|
return add(new T(std::forward<Args>(args)...));
|
2021-01-12 16:50:15 +01:00
|
|
|
}
|
|
|
|
|
2021-03-16 22:44:37 +01:00
|
|
|
static std::vector<View*>& getEntries();
|
2021-01-12 16:50:15 +01:00
|
|
|
|
|
|
|
private:
|
2021-03-16 22:44:37 +01:00
|
|
|
static void add(View *view);
|
2021-01-12 16:50:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Tools Registry. Allows adding new entries to the tools window */
|
|
|
|
struct Tools {
|
2021-01-13 01:24:27 +01:00
|
|
|
Tools() = delete;
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
using Callback = std::function<void()>;
|
|
|
|
|
2021-01-13 13:18:03 +01:00
|
|
|
struct Entry {
|
|
|
|
std::string name;
|
2021-09-08 15:18:24 +02:00
|
|
|
Callback function;
|
2021-01-13 13:18:03 +01:00
|
|
|
};
|
2021-01-12 16:50:15 +01:00
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
static void add(const std::string &unlocalizedName, const Callback &function);
|
2021-01-13 13:18:03 +01:00
|
|
|
|
|
|
|
static std::vector<Entry>& getEntries();
|
2021-01-11 23:54:12 +01:00
|
|
|
};
|
2021-01-13 01:24:27 +01:00
|
|
|
|
|
|
|
/* Data Inspector Registry. Allows adding of new types to the data inspector */
|
|
|
|
struct DataInspector {
|
|
|
|
DataInspector() = delete;
|
|
|
|
|
|
|
|
enum class NumberDisplayStyle {
|
|
|
|
Decimal,
|
|
|
|
Hexadecimal,
|
|
|
|
Octal
|
|
|
|
};
|
|
|
|
|
2021-03-02 22:09:38 +01:00
|
|
|
using DisplayFunction = std::function<std::string()>;
|
2021-01-13 01:24:27 +01:00
|
|
|
using GeneratorFunction = std::function<DisplayFunction(const std::vector<u8>&, std::endian, NumberDisplayStyle)>;
|
|
|
|
|
|
|
|
struct Entry {
|
2021-02-13 15:15:32 +01:00
|
|
|
std::string unlocalizedName;
|
2021-01-13 01:24:27 +01:00
|
|
|
size_t requiredSize;
|
|
|
|
GeneratorFunction generatorFunction;
|
|
|
|
};
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
static void add(const std::string &unlocalizedName, size_t requiredSize, GeneratorFunction function);
|
2021-01-13 01:24:27 +01:00
|
|
|
|
|
|
|
static std::vector<Entry>& getEntries();
|
|
|
|
};
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-02-19 17:36:10 +01:00
|
|
|
/* Data Processor Node Registry. Allows adding new processor nodes to be used in the data processor */
|
2021-01-30 22:39:06 +01:00
|
|
|
struct DataProcessorNode {
|
|
|
|
using CreatorFunction = std::function<dp::Node*()>;
|
|
|
|
struct Entry {
|
|
|
|
std::string category;
|
|
|
|
std::string name;
|
|
|
|
CreatorFunction creatorFunction;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<hex::derived_from<dp::Node> T, typename ... Args>
|
2021-09-08 15:18:24 +02:00
|
|
|
static void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, Args&& ... args) {
|
|
|
|
add(Entry{ unlocalizedCategory.c_str(), unlocalizedName.c_str(),
|
|
|
|
[=]{
|
2021-05-17 23:17:58 +02:00
|
|
|
auto node = new T(std::forward<Args>(args)...);
|
2021-09-08 15:18:24 +02:00
|
|
|
node->setUnlocalizedName(unlocalizedName);
|
2021-05-17 23:17:58 +02:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
});
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void addSeparator();
|
|
|
|
|
|
|
|
static std::vector<Entry>& getEntries();
|
|
|
|
private:
|
|
|
|
static void add(const Entry &entry);
|
|
|
|
};
|
2021-02-11 00:35:30 +01:00
|
|
|
|
2021-02-19 17:36:10 +01:00
|
|
|
/* Language Registry. Allows together with the LangEntry class and the _lang user defined literal to add new languages */
|
2021-02-11 00:35:30 +01:00
|
|
|
struct Language {
|
2021-09-08 15:18:24 +02:00
|
|
|
static void registerLanguage(const std::string &name, const std::string &languageCode);
|
|
|
|
static void addLocalizations(const std::string &languageCode, const LanguageDefinition &definition);
|
2021-02-11 00:35:30 +01:00
|
|
|
|
|
|
|
static std::map<std::string, std::string>& getLanguages();
|
|
|
|
static std::map<std::string, std::vector<LanguageDefinition>>& getLanguageDefinitions();
|
|
|
|
};
|
2021-02-18 12:09:19 +01:00
|
|
|
|
2021-02-19 17:36:10 +01:00
|
|
|
/* Interface Registry. Allows adding new items to various interfaces */
|
2021-02-18 12:09:19 +01:00
|
|
|
struct Interface {
|
|
|
|
using DrawCallback = std::function<void()>;
|
|
|
|
|
|
|
|
static void addWelcomeScreenEntry(const DrawCallback &function);
|
|
|
|
static void addFooterItem(const DrawCallback &function);
|
2021-08-21 00:52:11 +02:00
|
|
|
static void addToolbarItem(const DrawCallback &function);
|
2021-02-18 12:09:19 +01:00
|
|
|
|
|
|
|
static std::vector<DrawCallback>& getWelcomeScreenEntries();
|
|
|
|
static std::vector<DrawCallback>& getFooterItems();
|
2021-08-21 00:52:11 +02:00
|
|
|
static std::vector<DrawCallback>& getToolbarItems();
|
2021-02-18 12:09:19 +01:00
|
|
|
};
|
2021-01-11 20:31:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|