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>
|
2022-01-13 14:33:30 +01:00
|
|
|
|
2022-04-17 16:57:30 +02:00
|
|
|
#include <pl/pattern_language.hpp>
|
2021-12-12 11:52:58 +01:00
|
|
|
#include <hex/api/imhex_api.hpp>
|
|
|
|
#include <hex/api/event.hpp>
|
2021-01-13 17:41:16 +01:00
|
|
|
|
2021-01-11 20:31:40 +01:00
|
|
|
#include <functional>
|
|
|
|
#include <map>
|
2022-05-27 20:42:07 +02:00
|
|
|
#include <unordered_map>
|
2021-01-11 20:31:40 +01:00
|
|
|
#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
|
|
|
|
2022-05-27 20:42:07 +02:00
|
|
|
using ImGuiDataType = int;
|
|
|
|
using ImGuiInputTextFlags = int;
|
|
|
|
|
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;
|
2022-04-17 16:57:30 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
namespace dp {
|
|
|
|
class Node;
|
|
|
|
}
|
|
|
|
namespace prv {
|
|
|
|
class Provider;
|
|
|
|
}
|
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-10-16 11:37:29 +02:00
|
|
|
namespace ContentRegistry {
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2021-01-12 16:50:15 +01:00
|
|
|
/* Settings Registry. Allows adding of new entries into the ImHex preferences window. */
|
2021-10-16 11:37:29 +02:00
|
|
|
namespace Settings {
|
2022-01-24 20:53:17 +01:00
|
|
|
using Callback = std::function<bool(const std::string &, nlohmann::json &)>;
|
2021-09-08 15:18:24 +02:00
|
|
|
|
2021-01-11 20:31:40 +01:00
|
|
|
struct Entry {
|
|
|
|
std::string name;
|
2022-02-21 21:46:25 +01:00
|
|
|
bool requiresRestart;
|
2021-09-08 15:18:24 +02:00
|
|
|
Callback callback;
|
2021-01-11 20:31:40 +01:00
|
|
|
};
|
|
|
|
|
2022-02-18 22:34:54 +01:00
|
|
|
struct Category {
|
|
|
|
std::string name;
|
|
|
|
size_t slot = 0;
|
2022-02-21 21:46:25 +01:00
|
|
|
|
2022-02-18 22:34:54 +01:00
|
|
|
bool operator<(const Category &other) const {
|
|
|
|
return name < other.name;
|
|
|
|
}
|
|
|
|
|
2022-10-02 17:30:26 +02:00
|
|
|
explicit operator const std::string &() const {
|
2022-02-18 22:34:54 +01:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-10-16 11:37:29 +02:00
|
|
|
void load();
|
|
|
|
void store();
|
2022-07-30 11:19:56 +02:00
|
|
|
void clear();
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2022-02-21 21:46:25 +01:00
|
|
|
void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, i64 defaultValue, const Callback &callback, bool requiresRestart = false);
|
|
|
|
void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &defaultValue, const Callback &callback, bool requiresRestart = false);
|
|
|
|
void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector<std::string> &defaultValue, const Callback &callback, bool requiresRestart = false);
|
2022-02-18 22:34:54 +01:00
|
|
|
|
2022-02-21 21:46:25 +01:00
|
|
|
void addCategoryDescription(const std::string &unlocalizedCategory, const std::string &unlocalizedCategoryDescription);
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2022-01-22 22:37:52 +01:00
|
|
|
void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, i64 value);
|
2021-10-16 11:37:29 +02:00
|
|
|
void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &value);
|
2022-01-24 20:53:17 +01:00
|
|
|
void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector<std::string> &value);
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2022-01-22 22:37:52 +01:00
|
|
|
i64 read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, i64 defaultValue);
|
2021-10-16 11:37:29 +02:00
|
|
|
std::string read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &defaultValue);
|
2022-01-24 20:53:17 +01:00
|
|
|
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
|
|
|
|
2022-02-18 22:34:54 +01:00
|
|
|
std::map<Category, std::vector<Entry>> &getEntries();
|
|
|
|
std::map<std::string, std::string> &getCategoryDescriptions();
|
2021-10-16 11:37:29 +02:00
|
|
|
nlohmann::json getSetting(const std::string &unlocalizedCategory, const std::string &unlocalizedName);
|
2022-01-24 20:53:17 +01:00
|
|
|
nlohmann::json &getSettingsData();
|
2021-12-07 22:47:41 +01:00
|
|
|
}
|
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-10-16 11:37:29 +02:00
|
|
|
namespace CommandPaletteCommands {
|
2021-01-11 23:02:55 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
enum class Type : u32
|
|
|
|
{
|
2021-01-11 23:02:55 +01:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
void add(
|
2022-02-01 22:09:44 +01:00
|
|
|
Type type,
|
|
|
|
const std::string &command,
|
|
|
|
const std::string &unlocalizedDescription,
|
|
|
|
const DisplayCallback &displayCallback,
|
|
|
|
const ExecuteCallback &executeCallback = [](auto) {});
|
2022-01-24 20:53:17 +01:00
|
|
|
std::vector<Entry> &getEntries();
|
2021-12-07 22:47:41 +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-12-20 20:40:28 +01:00
|
|
|
namespace PatternLanguage {
|
2021-01-11 23:54:12 +01:00
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
namespace impl {
|
|
|
|
|
2022-04-17 16:57:30 +02:00
|
|
|
struct FunctionDefinition {
|
|
|
|
pl::api::Namespace ns;
|
2022-02-01 18:09:40 +01:00
|
|
|
std::string name;
|
2022-03-24 20:31:45 +01:00
|
|
|
|
2022-04-17 16:57:30 +02:00
|
|
|
pl::api::FunctionParameterCount parameterCount;
|
|
|
|
pl::api::FunctionCallback callback;
|
2022-03-24 20:31:45 +01:00
|
|
|
|
2022-04-17 16:57:30 +02:00
|
|
|
bool dangerous;
|
|
|
|
};
|
2022-03-24 20:31:45 +01:00
|
|
|
|
2022-04-17 16:57:30 +02:00
|
|
|
}
|
2022-03-24 20:31:45 +01:00
|
|
|
|
2022-09-15 09:34:40 +02:00
|
|
|
void configureRuntime(pl::PatternLanguage &runtime, prv::Provider *provider);
|
2021-01-11 23:54:12 +01:00
|
|
|
|
2022-04-17 16:57:30 +02:00
|
|
|
void addPragma(const std::string &name, const pl::api::PragmaHandler &handler);
|
2021-08-27 09:56:20 +02:00
|
|
|
|
2022-04-17 16:57:30 +02:00
|
|
|
void addFunction(const pl::api::Namespace &ns, const std::string &name, pl::api::FunctionParameterCount parameterCount, const pl::api::FunctionCallback &func);
|
|
|
|
void addDangerousFunction(const pl::api::Namespace &ns, const std::string &name, pl::api::FunctionParameterCount parameterCount, const pl::api::FunctionCallback &func);
|
2021-01-11 23:54:12 +01:00
|
|
|
|
2022-04-17 16:57:30 +02:00
|
|
|
std::map<std::string, pl::api::PragmaHandler> &getPragmas();
|
|
|
|
std::vector<impl::FunctionDefinition> &getFunctions();
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
}
|
2021-01-12 16:50:15 +01:00
|
|
|
|
|
|
|
/* View Registry. Allows adding of new windows */
|
2021-10-16 11:37:29 +02:00
|
|
|
namespace Views {
|
2021-12-12 11:52:58 +01:00
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
void add(View *view);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-06-25 12:19:59 +02:00
|
|
|
template<std::derived_from<View> T, typename... Args>
|
2022-01-24 20:53:17 +01:00
|
|
|
void add(Args &&...args) {
|
2021-12-12 11:52:58 +01:00
|
|
|
return impl::add(new T(std::forward<Args>(args)...));
|
2021-01-12 16:50:15 +01:00
|
|
|
}
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
std::map<std::string, View *> &getEntries();
|
2022-01-18 00:10:10 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
View *getViewByName(const std::string &unlocalizedName);
|
2021-01-12 16:50:15 +01:00
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
}
|
2021-01-12 16:50:15 +01:00
|
|
|
|
|
|
|
/* Tools Registry. Allows adding new entries to the tools window */
|
2021-10-16 11:37:29 +02:00
|
|
|
namespace Tools {
|
2021-09-08 15:18:24 +02:00
|
|
|
|
2021-12-12 11:52:58 +01:00
|
|
|
namespace impl {
|
2021-01-12 16:50:15 +01:00
|
|
|
|
2021-12-12 11:52:58 +01:00
|
|
|
using Callback = std::function<void()>;
|
2021-01-13 13:18:03 +01:00
|
|
|
|
2021-12-12 11:52:58 +01:00
|
|
|
struct Entry {
|
|
|
|
std::string name;
|
|
|
|
Callback function;
|
2022-10-13 10:47:35 +02:00
|
|
|
bool detached;
|
2021-12-12 11:52:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void add(const std::string &unlocalizedName, const impl::Callback &function);
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
std::vector<impl::Entry> &getEntries();
|
2021-12-07 22:47:41 +01:00
|
|
|
}
|
2021-01-13 01:24:27 +01:00
|
|
|
|
|
|
|
/* Data Inspector Registry. Allows adding of new types to the data inspector */
|
2021-10-16 11:37:29 +02:00
|
|
|
namespace DataInspector {
|
2021-01-13 01:24:27 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
enum class NumberDisplayStyle
|
|
|
|
{
|
2021-01-13 01:24:27 +01:00
|
|
|
Decimal,
|
|
|
|
Hexadecimal,
|
|
|
|
Octal
|
|
|
|
};
|
|
|
|
|
2021-12-12 11:52:58 +01:00
|
|
|
namespace impl {
|
2021-01-13 01:24:27 +01:00
|
|
|
|
2022-02-01 22:09:44 +01:00
|
|
|
using DisplayFunction = std::function<std::string()>;
|
2022-02-15 21:50:27 +01:00
|
|
|
using EditingFunction = std::function<std::vector<u8>(std::string, std::endian)>;
|
2022-01-24 20:53:17 +01:00
|
|
|
using GeneratorFunction = std::function<DisplayFunction(const std::vector<u8> &, std::endian, NumberDisplayStyle)>;
|
2021-01-13 01:24:27 +01:00
|
|
|
|
2021-12-12 11:52:58 +01:00
|
|
|
struct Entry {
|
|
|
|
std::string unlocalizedName;
|
|
|
|
size_t requiredSize;
|
2022-08-01 13:20:20 +02:00
|
|
|
size_t maxSize;
|
2021-12-12 11:52:58 +01:00
|
|
|
impl::GeneratorFunction generatorFunction;
|
2022-02-15 21:50:27 +01:00
|
|
|
std::optional<impl::EditingFunction> editingFunction;
|
2021-12-12 11:52:58 +01:00
|
|
|
};
|
2021-01-13 01:24:27 +01:00
|
|
|
|
2021-12-12 11:52:58 +01:00
|
|
|
}
|
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
void add(const std::string &unlocalizedName, size_t requiredSize, impl::GeneratorFunction displayGeneratorFunction, std::optional<impl::EditingFunction> editingFunction = std::nullopt);
|
2022-08-01 13:20:20 +02:00
|
|
|
void add(const std::string &unlocalizedName, size_t requiredSize, size_t maxSize, impl::GeneratorFunction displayGeneratorFunction, std::optional<impl::EditingFunction> editingFunction = std::nullopt);
|
2021-12-12 11:52:58 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
std::vector<impl::Entry> &getEntries();
|
2021-12-07 22:47:41 +01:00
|
|
|
}
|
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-10-16 11:37:29 +02:00
|
|
|
namespace DataProcessorNode {
|
|
|
|
|
2021-12-12 11:52:58 +01:00
|
|
|
namespace impl {
|
|
|
|
|
2022-08-08 21:23:52 +02:00
|
|
|
using CreatorFunction = std::function<std::unique_ptr<dp::Node>()>;
|
2021-12-12 11:52:58 +01:00
|
|
|
|
|
|
|
struct Entry {
|
|
|
|
std::string category;
|
|
|
|
std::string name;
|
|
|
|
CreatorFunction creatorFunction;
|
|
|
|
};
|
|
|
|
|
|
|
|
void add(const Entry &entry);
|
|
|
|
|
|
|
|
}
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-10-16 11:37:29 +02:00
|
|
|
|
2022-06-25 12:19:59 +02:00
|
|
|
template<std::derived_from<dp::Node> T, typename... Args>
|
2022-01-24 20:53:17 +01:00
|
|
|
void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, Args &&...args) {
|
2022-08-08 21:23:52 +02:00
|
|
|
add(impl::Entry {
|
|
|
|
unlocalizedCategory.c_str(),
|
|
|
|
unlocalizedName.c_str(),
|
|
|
|
[=] {
|
|
|
|
auto node = std::make_unique<T>(std::forward<Args>(args)...);
|
|
|
|
node->setUnlocalizedName(unlocalizedName);
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
});
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
2021-10-16 11:37:29 +02:00
|
|
|
void addSeparator();
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
std::vector<impl::Entry> &getEntries();
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
}
|
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-10-16 11:37:29 +02:00
|
|
|
namespace Language {
|
2022-12-02 12:00:04 +01:00
|
|
|
void addLocalization(const nlohmann::json &data);
|
2021-02-11 00:35:30 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
std::map<std::string, std::string> &getLanguages();
|
|
|
|
std::map<std::string, std::vector<LanguageDefinition>> &getLanguageDefinitions();
|
2021-12-07 22:47:41 +01:00
|
|
|
}
|
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-10-16 11:37:29 +02:00
|
|
|
namespace Interface {
|
2021-02-18 12:09:19 +01:00
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
namespace impl {
|
|
|
|
|
2022-02-01 22:09:44 +01:00
|
|
|
using DrawCallback = std::function<void()>;
|
2022-01-18 00:10:10 +01:00
|
|
|
using LayoutFunction = std::function<void(u32)>;
|
2022-02-02 00:36:09 +01:00
|
|
|
using ClickCallback = std::function<void()>;
|
2022-01-18 00:10:10 +01:00
|
|
|
|
|
|
|
struct Layout {
|
|
|
|
std::string unlocalizedName;
|
|
|
|
LayoutFunction callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MainMenuItem {
|
|
|
|
std::string unlocalizedName;
|
|
|
|
};
|
|
|
|
|
2022-01-23 02:28:38 +01:00
|
|
|
struct MenuItem {
|
|
|
|
std::string unlocalizedName;
|
|
|
|
DrawCallback callback;
|
|
|
|
};
|
|
|
|
|
2022-01-22 22:03:19 +01:00
|
|
|
struct SidebarItem {
|
|
|
|
std::string icon;
|
|
|
|
DrawCallback callback;
|
|
|
|
};
|
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
struct TitleBarButton {
|
|
|
|
std::string icon;
|
|
|
|
std::string unlocalizedTooltip;
|
|
|
|
ClickCallback callback;
|
|
|
|
};
|
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
}
|
|
|
|
|
2022-01-23 20:45:51 +01:00
|
|
|
void registerMainMenuItem(const std::string &unlocalizedName, u32 priority);
|
2022-01-23 02:28:38 +01:00
|
|
|
void addMenuItem(const std::string &unlocalizedMainMenuName, u32 priority, const impl::DrawCallback &function);
|
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
void addWelcomeScreenEntry(const impl::DrawCallback &function);
|
|
|
|
void addFooterItem(const impl::DrawCallback &function);
|
|
|
|
void addToolbarItem(const impl::DrawCallback &function);
|
2022-01-22 22:03:19 +01:00
|
|
|
void addSidebarItem(const std::string &icon, const impl::DrawCallback &function);
|
2022-02-02 00:36:09 +01:00
|
|
|
void addTitleBarButton(const std::string &icon, const std::string &unlocalizedTooltip, const impl::ClickCallback &function);
|
2022-01-18 00:10:10 +01:00
|
|
|
|
|
|
|
void addLayout(const std::string &unlocalizedName, const impl::LayoutFunction &function);
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
std::multimap<u32, impl::MainMenuItem> &getMainMenuItems();
|
|
|
|
std::multimap<u32, impl::MenuItem> &getMenuItems();
|
2022-01-23 02:28:38 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
std::vector<impl::DrawCallback> &getWelcomeScreenEntries();
|
|
|
|
std::vector<impl::DrawCallback> &getFooterItems();
|
|
|
|
std::vector<impl::DrawCallback> &getToolbarItems();
|
|
|
|
std::vector<impl::SidebarItem> &getSidebarItems();
|
2022-02-02 00:36:09 +01:00
|
|
|
std::vector<impl::TitleBarButton> &getTitleBarButtons();
|
2021-02-18 12:09:19 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
std::vector<impl::Layout> &getLayouts();
|
2021-12-07 22:47:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Provider Registry. Allows adding new data providers to be created from the UI */
|
|
|
|
namespace Provider {
|
|
|
|
|
2021-12-12 11:52:58 +01:00
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
void addProviderName(const std::string &unlocalizedName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-06-25 12:19:59 +02:00
|
|
|
template<std::derived_from<hex::prv::Provider> T>
|
2022-08-08 21:23:52 +02:00
|
|
|
void add(bool addToList = true) {
|
|
|
|
auto typeName = T().getTypeName();
|
|
|
|
|
2022-08-14 10:07:45 +02:00
|
|
|
(void)EventManager::subscribe<RequestCreateProvider>([expectedName = typeName](const std::string &name, bool skipLoadInterface, hex::prv::Provider **provider) {
|
2021-12-12 11:52:58 +01:00
|
|
|
if (name != expectedName) return;
|
|
|
|
|
2022-08-14 10:07:45 +02:00
|
|
|
prv::Provider *newProvider = new T();
|
2021-12-12 11:52:58 +01:00
|
|
|
|
2022-08-14 10:07:45 +02:00
|
|
|
hex::ImHexApi::Provider::add(newProvider, skipLoadInterface);
|
2021-12-12 11:52:58 +01:00
|
|
|
|
|
|
|
if (provider != nullptr)
|
|
|
|
*provider = newProvider;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (addToList)
|
2022-08-08 21:23:52 +02:00
|
|
|
impl::addProviderName(typeName);
|
2021-12-12 11:52:58 +01:00
|
|
|
}
|
2021-12-07 22:47:41 +01:00
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
std::vector<std::string> &getEntries();
|
2021-12-07 22:47:41 +01:00
|
|
|
|
|
|
|
}
|
2022-01-13 00:27:31 +01:00
|
|
|
|
|
|
|
namespace DataFormatter {
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
using Callback = std::function<std::string(prv::Provider *provider, u64 address, size_t size)>;
|
|
|
|
struct Entry {
|
|
|
|
std::string unlocalizedName;
|
|
|
|
Callback callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void add(const std::string &unlocalizedName, const impl::Callback &callback);
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
std::vector<impl::Entry> &getEntries();
|
2022-01-13 00:27:31 +01:00
|
|
|
|
|
|
|
}
|
2022-01-13 14:34:19 +01:00
|
|
|
|
|
|
|
namespace FileHandler {
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
2022-10-21 14:55:01 +02:00
|
|
|
using Callback = std::function<bool(std::filesystem::path)>;
|
2022-01-13 14:34:19 +01:00
|
|
|
struct Entry {
|
|
|
|
std::vector<std::string> extensions;
|
|
|
|
Callback callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void add(const std::vector<std::string> &extensions, const impl::Callback &callback);
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
std::vector<impl::Entry> &getEntries();
|
2022-01-13 14:34:19 +01:00
|
|
|
|
|
|
|
}
|
2022-05-27 20:42:07 +02:00
|
|
|
|
|
|
|
namespace HexEditor {
|
|
|
|
|
|
|
|
class DataVisualizer {
|
|
|
|
public:
|
|
|
|
DataVisualizer(u16 bytesPerCell, u16 maxCharsPerCell)
|
|
|
|
: m_bytesPerCell(bytesPerCell), m_maxCharsPerCell(maxCharsPerCell) {}
|
|
|
|
|
|
|
|
virtual ~DataVisualizer() = default;
|
|
|
|
|
|
|
|
virtual void draw(u64 address, const u8 *data, size_t size, bool upperCase) = 0;
|
|
|
|
virtual bool drawEditing(u64 address, u8 *data, size_t size, bool upperCase, bool startedEditing) = 0;
|
|
|
|
|
|
|
|
[[nodiscard]] u16 getBytesPerCell() const { return this->m_bytesPerCell; }
|
|
|
|
[[nodiscard]] u16 getMaxCharsPerCell() const { return this->m_maxCharsPerCell; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const static int TextInputFlags;
|
|
|
|
|
|
|
|
bool drawDefaultEditingTextBox(u64 address, const char *format, ImGuiDataType dataType, u8 *data, ImGuiInputTextFlags flags) const;
|
|
|
|
private:
|
|
|
|
u16 m_bytesPerCell;
|
|
|
|
u16 m_maxCharsPerCell;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
void addDataVisualizer(const std::string &unlocalizedName, DataVisualizer *visualizer);
|
|
|
|
|
|
|
|
std::map<std::string, DataVisualizer*> &getVisualizers();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-06-25 12:19:59 +02:00
|
|
|
template<std::derived_from<DataVisualizer> T, typename... Args>
|
2022-05-27 20:42:07 +02:00
|
|
|
void addDataVisualizer(const std::string &unlocalizedName, Args &&...args) {
|
|
|
|
return impl::addDataVisualizer(unlocalizedName, new T(std::forward<Args>(args)...));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-05-30 16:36:46 +02:00
|
|
|
|
|
|
|
namespace Hashes {
|
|
|
|
|
|
|
|
class Hash {
|
|
|
|
public:
|
2022-10-02 17:30:26 +02:00
|
|
|
explicit Hash(std::string unlocalizedName) : m_unlocalizedName(std::move(unlocalizedName)) {}
|
2022-05-30 16:36:46 +02:00
|
|
|
|
|
|
|
class Function {
|
|
|
|
public:
|
|
|
|
using Callback = std::function<std::vector<u8>(const Region&, prv::Provider *)>;
|
|
|
|
|
|
|
|
Function(const Hash *type, std::string name, Callback callback)
|
|
|
|
: m_type(type), m_name(std::move(name)), m_callback(std::move(callback)) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] const Hash *getType() const { return this->m_type; }
|
|
|
|
[[nodiscard]] const std::string &getName() const { return this->m_name; }
|
|
|
|
|
|
|
|
const std::vector<u8>& get(const Region& region, prv::Provider *provider) {
|
|
|
|
if (this->m_cache.empty()) {
|
|
|
|
this->m_cache = this->m_callback(region, provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this->m_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
this->m_cache.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Hash *m_type;
|
|
|
|
std::string m_name;
|
|
|
|
Callback m_callback;
|
|
|
|
|
|
|
|
std::vector<u8> m_cache;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual void draw() { }
|
|
|
|
[[nodiscard]] virtual Function create(std::string name) = 0;
|
|
|
|
|
2022-06-14 11:54:34 +02:00
|
|
|
[[nodiscard]] const std::string &getUnlocalizedName() const {
|
|
|
|
return this->m_unlocalizedName;
|
2022-05-30 16:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
[[nodiscard]] Function create(const std::string &name, const Function::Callback &callback) const {
|
|
|
|
return { this, name, callback };
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-06-14 11:54:34 +02:00
|
|
|
std::string m_unlocalizedName;
|
2022-05-30 16:36:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
std::vector<Hash*> &getHashes();
|
|
|
|
|
|
|
|
void add(Hash* hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, typename ... Args>
|
|
|
|
void add(Args && ... args) {
|
|
|
|
impl::add(new T(std::forward<Args>(args)...));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-10-02 17:30:26 +02:00
|
|
|
}
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2022-02-18 22:34:54 +01:00
|
|
|
}
|