2021-01-11 20:31:40 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
2023-12-19 12:22:28 +01:00
|
|
|
#include <hex/api/localization_manager.hpp>
|
2021-08-29 22:15:18 +02:00
|
|
|
#include <hex/helpers/concepts.hpp>
|
2022-01-13 14:33:30 +01:00
|
|
|
|
2021-01-11 20:31:40 +01:00
|
|
|
#include <functional>
|
|
|
|
#include <map>
|
2024-05-18 11:10:55 +02:00
|
|
|
#include <mutex>
|
2023-02-07 14:18:59 +01:00
|
|
|
#include <span>
|
2021-01-11 20:31:40 +01:00
|
|
|
#include <string>
|
2023-10-21 23:07:33 +02:00
|
|
|
#include <utility>
|
2021-01-11 20:31:40 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2023-12-22 23:39:38 +01:00
|
|
|
#include <pl/pattern_language.hpp>
|
2023-10-21 23:07:33 +02:00
|
|
|
#include <nlohmann/json.hpp>
|
2023-12-22 23:39:38 +01:00
|
|
|
#include <wolv/io/fs.hpp>
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2022-05-27 20:42:07 +02:00
|
|
|
using ImGuiDataType = int;
|
|
|
|
using ImGuiInputTextFlags = int;
|
2023-10-21 23:07:33 +02:00
|
|
|
struct ImColor;
|
2024-01-21 18:39:32 +01:00
|
|
|
enum ImGuiCustomCol : int;
|
2022-05-27 20:42:07 +02:00
|
|
|
|
2021-01-11 20:31:40 +01:00
|
|
|
namespace hex {
|
|
|
|
|
2021-01-12 16:50:15 +01:00
|
|
|
class View;
|
2023-11-18 14:34:33 +01:00
|
|
|
class Shortcut;
|
2024-02-21 00:06:52 +01:00
|
|
|
class Task;
|
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
|
|
|
|
2023-11-21 14:38:01 +01:00
|
|
|
namespace LocalizationManager {
|
|
|
|
class LanguageDefinition;
|
|
|
|
}
|
|
|
|
|
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 {
|
2021-09-08 15:18:24 +02:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
namespace Widgets {
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
class Widget {
|
|
|
|
public:
|
|
|
|
virtual ~Widget() = default;
|
2022-02-21 21:46:25 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
virtual bool draw(const std::string &name) = 0;
|
|
|
|
|
|
|
|
virtual void load(const nlohmann::json &data) = 0;
|
|
|
|
virtual nlohmann::json store() = 0;
|
|
|
|
|
|
|
|
class Interface {
|
|
|
|
public:
|
|
|
|
friend class Widget;
|
|
|
|
|
|
|
|
Interface& requiresRestart() {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_requiresRestart = true;
|
2023-10-21 23:07:33 +02:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Interface& setEnabledCallback(std::function<bool()> callback) {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_enabledCallback = std::move(callback);
|
2023-10-21 23:07:33 +02:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Interface& setChangedCallback(std::function<void(Widget&)> callback) {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_changedCallback = std::move(callback);
|
2023-10-21 23:07:33 +02:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Interface& setTooltip(const std::string &tooltip) {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_tooltip = tooltip;
|
2023-10-21 23:07:33 +02:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
Widget& getWidget() const {
|
2023-12-19 13:10:25 +01:00
|
|
|
return *m_widget;
|
2023-10-21 23:07:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit Interface(Widget *widget) : m_widget(widget) {}
|
|
|
|
Widget *m_widget;
|
|
|
|
|
|
|
|
bool m_requiresRestart = false;
|
|
|
|
std::function<bool()> m_enabledCallback;
|
|
|
|
std::function<void(Widget&)> m_changedCallback;
|
2024-05-19 15:10:22 +02:00
|
|
|
std::optional<UnlocalizedString> m_tooltip;
|
2023-10-21 23:07:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
bool doesRequireRestart() const {
|
2023-12-19 13:10:25 +01:00
|
|
|
return m_interface.m_requiresRestart;
|
2023-10-21 23:07:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
bool isEnabled() const {
|
2023-12-19 13:10:25 +01:00
|
|
|
return !m_interface.m_enabledCallback || m_interface.m_enabledCallback();
|
2023-10-21 23:07:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]]
|
2024-05-19 15:10:22 +02:00
|
|
|
const std::optional<UnlocalizedString>& getTooltip() const {
|
2023-12-19 13:10:25 +01:00
|
|
|
return m_interface.m_tooltip;
|
2023-10-21 23:07:33 +02:00
|
|
|
}
|
2022-02-18 22:34:54 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
void onChanged() {
|
2023-12-19 13:10:25 +01:00
|
|
|
if (m_interface.m_changedCallback)
|
|
|
|
m_interface.m_changedCallback(*this);
|
2023-03-21 15:33:43 +01:00
|
|
|
}
|
2022-02-18 22:34:54 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
[[nodiscard]]
|
|
|
|
Interface& getInterface() {
|
2023-12-19 13:10:25 +01:00
|
|
|
return m_interface;
|
2023-03-21 15:33:43 +01:00
|
|
|
}
|
2023-10-21 23:07:33 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
Interface m_interface = Interface(this);
|
|
|
|
};
|
|
|
|
|
2023-12-09 12:14:45 +01:00
|
|
|
class Checkbox : public Widget {
|
2023-10-21 23:07:33 +02:00
|
|
|
public:
|
|
|
|
explicit Checkbox(bool defaultValue) : m_value(defaultValue) { }
|
|
|
|
|
|
|
|
bool draw(const std::string &name) override;
|
|
|
|
|
|
|
|
void load(const nlohmann::json &data) override;
|
|
|
|
nlohmann::json store() override;
|
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
[[nodiscard]] bool isChecked() const { return m_value; }
|
2023-10-21 23:07:33 +02:00
|
|
|
|
2024-02-24 22:46:52 +01:00
|
|
|
protected:
|
2023-10-21 23:07:33 +02:00
|
|
|
bool m_value;
|
|
|
|
};
|
2023-12-09 12:14:45 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
class SliderInteger : public Widget {
|
|
|
|
public:
|
|
|
|
SliderInteger(i32 defaultValue, i32 min, i32 max) : m_value(defaultValue), m_min(min), m_max(max) { }
|
|
|
|
bool draw(const std::string &name) override;
|
|
|
|
|
|
|
|
void load(const nlohmann::json &data) override;
|
|
|
|
nlohmann::json store() override;
|
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
[[nodiscard]] i32 getValue() const { return m_value; }
|
2023-10-21 23:07:33 +02:00
|
|
|
|
2024-02-24 22:46:52 +01:00
|
|
|
protected:
|
2023-10-21 23:07:33 +02:00
|
|
|
int m_value;
|
|
|
|
i32 m_min, m_max;
|
|
|
|
};
|
2023-12-09 12:14:45 +01:00
|
|
|
|
|
|
|
class SliderFloat : public Widget {
|
2023-10-21 23:07:33 +02:00
|
|
|
public:
|
|
|
|
SliderFloat(float defaultValue, float min, float max) : m_value(defaultValue), m_min(min), m_max(max) { }
|
|
|
|
bool draw(const std::string &name) override;
|
|
|
|
|
|
|
|
void load(const nlohmann::json &data) override;
|
|
|
|
nlohmann::json store() override;
|
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
[[nodiscard]] float getValue() const { return m_value; }
|
2023-10-21 23:07:33 +02:00
|
|
|
|
2024-02-24 22:46:52 +01:00
|
|
|
protected:
|
2023-10-21 23:07:33 +02:00
|
|
|
float m_value;
|
|
|
|
float m_min, m_max;
|
|
|
|
};
|
2023-12-09 12:14:45 +01:00
|
|
|
|
2024-05-19 15:10:22 +02:00
|
|
|
class SliderDataSize : public Widget {
|
|
|
|
public:
|
|
|
|
SliderDataSize(u64 defaultValue, u64 min, u64 max) : m_value(defaultValue), m_min(min), m_max(max) { }
|
|
|
|
bool draw(const std::string &name) override;
|
|
|
|
|
|
|
|
void load(const nlohmann::json &data) override;
|
|
|
|
nlohmann::json store() override;
|
|
|
|
|
|
|
|
[[nodiscard]] i32 getValue() const { return m_value; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
u64 m_value;
|
|
|
|
u64 m_min, m_max;
|
|
|
|
};
|
|
|
|
|
2023-12-09 12:14:45 +01:00
|
|
|
class ColorPicker : public Widget {
|
2023-10-21 23:07:33 +02:00
|
|
|
public:
|
|
|
|
explicit ColorPicker(ImColor defaultColor);
|
|
|
|
|
|
|
|
bool draw(const std::string &name) override;
|
|
|
|
|
|
|
|
void load(const nlohmann::json &data) override;
|
|
|
|
nlohmann::json store() override;
|
|
|
|
|
|
|
|
[[nodiscard]] ImColor getColor() const;
|
|
|
|
|
2024-02-24 22:46:52 +01:00
|
|
|
protected:
|
2023-11-10 14:48:26 +01:00
|
|
|
std::array<float, 4> m_value{};
|
2023-10-21 23:07:33 +02:00
|
|
|
};
|
2023-12-09 12:14:45 +01:00
|
|
|
|
|
|
|
class DropDown : public Widget {
|
2023-10-21 23:07:33 +02:00
|
|
|
public:
|
2023-10-22 17:31:53 +02:00
|
|
|
explicit DropDown(const std::vector<std::string> &items, const std::vector<nlohmann::json> &settingsValues, const nlohmann::json &defaultItem) : m_items(items), m_settingsValues(settingsValues), m_defaultItem(defaultItem) { }
|
2023-10-21 23:07:33 +02:00
|
|
|
|
|
|
|
bool draw(const std::string &name) override;
|
|
|
|
|
|
|
|
void load(const nlohmann::json &data) override;
|
|
|
|
nlohmann::json store() override;
|
|
|
|
|
|
|
|
[[nodiscard]]
|
|
|
|
const nlohmann::json& getValue() const;
|
|
|
|
|
2024-02-24 22:46:52 +01:00
|
|
|
protected:
|
2023-10-21 23:07:33 +02:00
|
|
|
std::vector<std::string> m_items;
|
|
|
|
std::vector<nlohmann::json> m_settingsValues;
|
2023-10-22 17:31:53 +02:00
|
|
|
nlohmann::json m_defaultItem;
|
|
|
|
|
2023-10-22 17:51:00 +02:00
|
|
|
int m_value = -1;
|
2023-10-21 23:07:33 +02:00
|
|
|
};
|
2023-12-09 12:14:45 +01:00
|
|
|
|
|
|
|
class TextBox : public Widget {
|
2023-10-21 23:07:33 +02:00
|
|
|
public:
|
|
|
|
explicit TextBox(std::string defaultValue) : m_value(std::move(defaultValue)) { }
|
|
|
|
|
|
|
|
bool draw(const std::string &name) override;
|
|
|
|
|
|
|
|
void load(const nlohmann::json &data) override;
|
|
|
|
nlohmann::json store() override;
|
|
|
|
|
|
|
|
[[nodiscard]]
|
2023-12-19 13:10:25 +01:00
|
|
|
const std::string& getValue() const { return m_value; }
|
2023-10-21 23:07:33 +02:00
|
|
|
|
2024-02-24 22:46:52 +01:00
|
|
|
protected:
|
2023-10-21 23:07:33 +02:00
|
|
|
std::string m_value;
|
|
|
|
};
|
2023-12-09 12:14:45 +01:00
|
|
|
|
|
|
|
class FilePicker : public Widget {
|
2023-10-21 23:07:33 +02:00
|
|
|
public:
|
|
|
|
bool draw(const std::string &name) override;
|
|
|
|
|
|
|
|
void load(const nlohmann::json &data) override;
|
|
|
|
nlohmann::json store() override;
|
|
|
|
|
2024-02-24 22:46:52 +01:00
|
|
|
[[nodiscard]] const std::fs::path& getPath() const {
|
|
|
|
return m_path;
|
2023-12-09 12:14:45 +01:00
|
|
|
}
|
2023-10-21 23:07:33 +02:00
|
|
|
|
2024-02-24 22:46:52 +01:00
|
|
|
protected:
|
|
|
|
std::fs::path m_path;
|
2023-10-21 23:07:33 +02:00
|
|
|
};
|
|
|
|
|
2023-12-09 12:14:45 +01:00
|
|
|
class Label : public Widget {
|
|
|
|
public:
|
|
|
|
bool draw(const std::string &name) override;
|
|
|
|
|
|
|
|
void load(const nlohmann::json &) override {}
|
|
|
|
nlohmann::json store() override { return {}; }
|
|
|
|
};
|
2023-10-21 23:07:33 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
struct Entry {
|
2023-12-19 12:22:28 +01:00
|
|
|
UnlocalizedString unlocalizedName;
|
2023-10-21 23:07:33 +02:00
|
|
|
std::unique_ptr<Widgets::Widget> widget;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SubCategory {
|
2023-12-19 12:22:28 +01:00
|
|
|
UnlocalizedString unlocalizedName;
|
2023-10-21 23:07:33 +02:00
|
|
|
std::vector<Entry> entries;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Category {
|
2023-12-19 12:22:28 +01:00
|
|
|
UnlocalizedString unlocalizedName;
|
|
|
|
UnlocalizedString unlocalizedDescription;
|
2023-10-21 23:07:33 +02:00
|
|
|
std::vector<SubCategory> subCategories;
|
2023-03-21 15:33:43 +01:00
|
|
|
};
|
2021-01-11 20:31:40 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
void load();
|
|
|
|
void store();
|
|
|
|
void clear();
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::vector<Category>& getSettings();
|
2023-12-19 12:22:28 +01:00
|
|
|
nlohmann::json& getSetting(const UnlocalizedString &unlocalizedCategory, const UnlocalizedString &unlocalizedName, const nlohmann::json &defaultValue);
|
2024-02-10 23:31:05 +01:00
|
|
|
const nlohmann::json& getSettingsData();
|
2023-10-21 23:07:33 +02:00
|
|
|
|
2023-12-19 12:22:28 +01:00
|
|
|
Widgets::Widget* add(const UnlocalizedString &unlocalizedCategory, const UnlocalizedString &unlocalizedSubCategory, const UnlocalizedString &unlocalizedName, std::unique_ptr<Widgets::Widget> &&widget);
|
2024-02-03 12:16:36 +01:00
|
|
|
|
|
|
|
void printSettingReadError(const UnlocalizedString &unlocalizedCategory, const UnlocalizedString &unlocalizedName, const nlohmann::json::exception &e);
|
2024-02-18 11:29:18 +01:00
|
|
|
|
|
|
|
void runOnChangeHandlers(const UnlocalizedString &unlocalizedCategory, const UnlocalizedString &unlocalizedName, const nlohmann::json &value);
|
2023-03-21 15:33:43 +01:00
|
|
|
}
|
2022-02-18 22:34:54 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
template<std::derived_from<Widgets::Widget> T>
|
2023-12-19 12:22:28 +01:00
|
|
|
Widgets::Widget::Interface& add(const UnlocalizedString &unlocalizedCategory, const UnlocalizedString &unlocalizedSubCategory, const UnlocalizedString &unlocalizedName, auto && ... args) {
|
2023-10-21 23:07:33 +02:00
|
|
|
return impl::add(
|
|
|
|
unlocalizedCategory,
|
|
|
|
unlocalizedSubCategory,
|
|
|
|
unlocalizedName,
|
|
|
|
std::make_unique<T>(std::forward<decltype(args)>(args)...)
|
|
|
|
)->getInterface();
|
|
|
|
}
|
2023-03-21 15:33:43 +01:00
|
|
|
|
2023-12-19 12:22:28 +01:00
|
|
|
void setCategoryDescription(const UnlocalizedString &unlocalizedCategory, const UnlocalizedString &unlocalizedDescription);
|
2021-02-01 19:03:28 +01:00
|
|
|
|
2024-02-18 11:29:18 +01:00
|
|
|
class SettingsValue {
|
|
|
|
public:
|
|
|
|
SettingsValue(nlohmann::json value) : m_value(std::move(value)) {}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
T get(std::common_type_t<T> defaultValue) const {
|
|
|
|
try {
|
|
|
|
auto result = m_value;
|
|
|
|
if (result.is_number() && std::same_as<T, bool>)
|
|
|
|
result = m_value.get<int>() != 0;
|
|
|
|
if (m_value.is_null())
|
|
|
|
result = defaultValue;
|
|
|
|
|
|
|
|
return result.get<T>();
|
|
|
|
} catch (const nlohmann::json::exception &e) {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nlohmann::json m_value;
|
|
|
|
};
|
|
|
|
|
2024-02-03 12:16:36 +01:00
|
|
|
template<typename T>
|
|
|
|
[[nodiscard]] T read(const UnlocalizedString &unlocalizedCategory, const UnlocalizedString &unlocalizedName, const std::common_type_t<T> &defaultValue) {
|
|
|
|
auto setting = impl::getSetting(unlocalizedCategory, unlocalizedName, defaultValue);
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (setting.is_number() && std::same_as<T, bool>)
|
|
|
|
setting = setting.template get<int>() != 0;
|
|
|
|
if (setting.is_null())
|
|
|
|
setting = defaultValue;
|
|
|
|
|
|
|
|
return setting.template get<T>();
|
|
|
|
} catch (const nlohmann::json::exception &e) {
|
|
|
|
impl::printSettingReadError(unlocalizedCategory, unlocalizedName, e);
|
|
|
|
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void write(const UnlocalizedString &unlocalizedCategory, const UnlocalizedString &unlocalizedName, const std::common_type_t<T> &value) {
|
|
|
|
impl::getSetting(unlocalizedCategory, unlocalizedName, value) = value;
|
2024-02-18 11:29:18 +01:00
|
|
|
impl::runOnChangeHandlers(unlocalizedCategory, unlocalizedName, value);
|
2024-05-15 18:25:33 +02:00
|
|
|
|
|
|
|
impl::store();
|
2024-02-03 12:16:36 +01:00
|
|
|
}
|
|
|
|
|
2024-02-18 11:29:18 +01:00
|
|
|
using OnChangeCallback = std::function<void(const SettingsValue &)>;
|
|
|
|
u64 onChange(const UnlocalizedString &unlocalizedCategory, const UnlocalizedString &unlocalizedName, const OnChangeCallback &callback);
|
|
|
|
|
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
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
enum class Type : u32 {
|
2021-01-11 23:02:55 +01:00
|
|
|
SymbolCommand,
|
|
|
|
KeywordCommand
|
|
|
|
};
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
namespace impl {
|
2023-03-20 14:11:43 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
struct QueryResult {
|
|
|
|
std::string name;
|
|
|
|
std::function<void(std::string)> callback;
|
|
|
|
};
|
2021-09-08 15:18:24 +02:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
using DisplayCallback = std::function<std::string(std::string)>;
|
|
|
|
using ExecuteCallback = std::function<void(std::string)>;
|
|
|
|
using QueryCallback = std::function<std::vector<QueryResult>(std::string)>;
|
2021-01-11 23:02:55 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
struct Entry {
|
|
|
|
Type type;
|
|
|
|
std::string command;
|
2023-12-19 12:22:28 +01:00
|
|
|
UnlocalizedString unlocalizedDescription;
|
2023-03-21 15:33:43 +01:00
|
|
|
DisplayCallback displayCallback;
|
|
|
|
ExecuteCallback executeCallback;
|
|
|
|
};
|
2023-03-20 14:11:43 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
struct Handler {
|
|
|
|
Type type;
|
|
|
|
std::string command;
|
|
|
|
QueryCallback queryCallback;
|
|
|
|
DisplayCallback displayCallback;
|
|
|
|
};
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::vector<Entry>& getEntries();
|
|
|
|
const std::vector<Handler>& getHandlers();
|
2023-03-21 15:33:43 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adds a new command to the command palette
|
|
|
|
* @param type The type of the command
|
|
|
|
* @param command The command to add
|
|
|
|
* @param unlocalizedDescription The description of the command
|
|
|
|
* @param displayCallback The callback that will be called when the command is displayed in the command palette
|
|
|
|
* @param executeCallback The callback that will be called when the command is executed
|
|
|
|
*/
|
2022-01-24 20:53:17 +01:00
|
|
|
void add(
|
2022-02-01 22:09:44 +01:00
|
|
|
Type type,
|
|
|
|
const std::string &command,
|
2023-12-19 12:22:28 +01:00
|
|
|
const UnlocalizedString &unlocalizedDescription,
|
2023-03-21 15:33:43 +01:00
|
|
|
const impl::DisplayCallback &displayCallback,
|
|
|
|
const impl::ExecuteCallback &executeCallback = [](auto) {});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adds a new command handler to the command palette
|
|
|
|
* @param type The type of the command
|
|
|
|
* @param command The command to add
|
|
|
|
* @param queryCallback The callback that will be called when the command palette wants to load the name and callback items
|
|
|
|
* @param displayCallback The callback that will be called when the command is displayed in the command palette
|
|
|
|
*/
|
2023-03-20 14:11:43 +01:00
|
|
|
void addHandler(
|
|
|
|
Type type,
|
|
|
|
const std::string &command,
|
2023-03-21 15:33:43 +01:00
|
|
|
const impl::QueryCallback &queryCallback,
|
|
|
|
const impl::DisplayCallback &displayCallback);
|
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 {
|
|
|
|
|
2023-04-18 10:06:47 +02:00
|
|
|
using VisualizerFunctionCallback = std::function<void(pl::ptrn::Pattern&, pl::ptrn::IIterable&, bool, std::span<const pl::core::Token::Literal>)>;
|
2023-03-21 15:33:43 +01:00
|
|
|
|
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
|
|
|
|
2023-01-20 21:16:28 +01:00
|
|
|
struct Visualizer {
|
2023-10-31 10:56:20 +01:00
|
|
|
pl::api::FunctionParameterCount parameterCount;
|
2023-01-20 21:16:28 +01:00
|
|
|
VisualizerFunctionCallback callback;
|
|
|
|
};
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::map<std::string, Visualizer>& getVisualizers();
|
|
|
|
const std::map<std::string, Visualizer>& getInlineVisualizers();
|
|
|
|
const std::map<std::string, pl::api::PragmaHandler>& getPragmas();
|
|
|
|
const std::vector<FunctionDefinition>& getFunctions();
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2022-04-17 16:57:30 +02:00
|
|
|
}
|
2022-03-24 20:31:45 +01:00
|
|
|
|
2023-04-17 16:18:48 +02:00
|
|
|
/**
|
|
|
|
* @brief Provides access to the current provider's pattern language runtime
|
|
|
|
* @return Runtime
|
|
|
|
*/
|
|
|
|
pl::PatternLanguage& getRuntime();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Provides access to the current provider's pattern language runtime's lock
|
|
|
|
* @return Lock
|
|
|
|
*/
|
2023-05-12 15:46:13 +02:00
|
|
|
std::mutex& getRuntimeLock();
|
2023-04-17 16:18:48 +02:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Configures the pattern language runtime using ImHex's default settings
|
|
|
|
* @param runtime The pattern language runtime to configure
|
|
|
|
* @param provider The provider to use for data access
|
|
|
|
*/
|
2022-09-15 09:34:40 +02:00
|
|
|
void configureRuntime(pl::PatternLanguage &runtime, prv::Provider *provider);
|
2021-01-11 23:54:12 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new pragma to the pattern language
|
|
|
|
* @param name The name of the pragma
|
|
|
|
* @param handler The handler that will be called when the pragma is encountered
|
|
|
|
*/
|
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
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new function to the pattern language
|
|
|
|
* @param ns The namespace of the function
|
|
|
|
* @param name The name of the function
|
|
|
|
* @param parameterCount The amount of parameters the function takes
|
|
|
|
* @param func The function callback
|
|
|
|
*/
|
2024-01-15 20:52:08 +01:00
|
|
|
void addFunction(
|
|
|
|
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
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new dangerous function to the pattern language
|
|
|
|
* @note Dangerous functions are functions that require the user to explicitly allow them to be used
|
|
|
|
* @param ns The namespace of the function
|
|
|
|
* @param name The name of the function
|
|
|
|
* @param parameterCount The amount of parameters the function takes
|
|
|
|
* @param func The function callback
|
|
|
|
*/
|
2024-01-15 20:52:08 +01:00
|
|
|
void addDangerousFunction(
|
|
|
|
const pl::api::Namespace &ns,
|
|
|
|
const std::string &name,
|
|
|
|
pl::api::FunctionParameterCount parameterCount,
|
|
|
|
const pl::api::FunctionCallback &func
|
|
|
|
);
|
2023-01-20 21:16:28 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new visualizer to the pattern language
|
|
|
|
* @note Visualizers are extensions to the [[hex::visualize]] attribute, used to visualize data
|
|
|
|
* @param name The name of the visualizer
|
2023-11-10 14:48:26 +01:00
|
|
|
* @param function The function callback
|
2023-03-21 15:33:43 +01:00
|
|
|
* @param parameterCount The amount of parameters the function takes
|
|
|
|
*/
|
2024-01-15 20:52:08 +01:00
|
|
|
void addVisualizer(
|
|
|
|
const std::string &name,
|
|
|
|
const impl::VisualizerFunctionCallback &function,
|
|
|
|
pl::api::FunctionParameterCount parameterCount
|
|
|
|
);
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2023-07-04 22:18:06 +02:00
|
|
|
/**
|
|
|
|
* @brief Adds a new inline visualizer to the pattern language
|
|
|
|
* @note Inline visualizers are extensions to the [[hex::inline_visualize]] attribute, used to visualize data
|
|
|
|
* @param name The name of the visualizer
|
2023-11-10 14:48:26 +01:00
|
|
|
* @param function The function callback
|
2023-07-04 22:18:06 +02:00
|
|
|
* @param parameterCount The amount of parameters the function takes
|
|
|
|
*/
|
2024-01-15 20:52:08 +01:00
|
|
|
void addInlineVisualizer(
|
|
|
|
const std::string &name,
|
|
|
|
const impl::VisualizerFunctionCallback &function,
|
|
|
|
pl::api::FunctionParameterCount parameterCount
|
|
|
|
);
|
2023-07-04 22:18:06 +02: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 {
|
|
|
|
|
2023-04-08 12:08:45 +02:00
|
|
|
void add(std::unique_ptr<View> &&view);
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::map<std::string, std::unique_ptr<View>>& getEntries();
|
2021-12-12 11:52:58 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new view to ImHex
|
|
|
|
* @tparam T The custom view class that extends View
|
|
|
|
* @tparam Args Arguments types
|
|
|
|
* @param args Arguments passed to the constructor of the 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) {
|
2023-04-08 12:08:45 +02:00
|
|
|
return impl::add(std::make_unique<T>(std::forward<Args>(args)...));
|
2021-01-12 16:50:15 +01:00
|
|
|
}
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Gets a view by its unlocalized name
|
|
|
|
* @param unlocalizedName The unlocalized name of the view
|
|
|
|
* @return The view if it exists, nullptr otherwise
|
|
|
|
*/
|
2023-12-19 12:22:28 +01:00
|
|
|
View* getViewByName(const UnlocalizedString &unlocalizedName);
|
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 {
|
2024-02-10 23:31:05 +01:00
|
|
|
UnlocalizedString unlocalizedName;
|
2021-12-12 11:52:58 +01:00
|
|
|
Callback function;
|
|
|
|
};
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::vector<Entry>& getEntries();
|
2023-03-21 15:33:43 +01:00
|
|
|
|
2021-12-12 11:52:58 +01:00
|
|
|
}
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new tool to the tools window
|
|
|
|
* @param unlocalizedName The unlocalized name of the tool
|
|
|
|
* @param function The function that will be called to draw the tool
|
|
|
|
*/
|
2023-12-19 12:22:28 +01:00
|
|
|
void add(const UnlocalizedString &unlocalizedName, const impl::Callback &function);
|
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 {
|
2023-12-19 12:22:28 +01:00
|
|
|
UnlocalizedString unlocalizedName;
|
2021-12-12 11:52:58 +01:00
|
|
|
size_t requiredSize;
|
2022-08-01 13:20:20 +02:00
|
|
|
size_t maxSize;
|
2023-11-10 14:48:26 +01:00
|
|
|
GeneratorFunction generatorFunction;
|
|
|
|
std::optional<EditingFunction> editingFunction;
|
2021-12-12 11:52:58 +01:00
|
|
|
};
|
2021-01-13 01:24:27 +01:00
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::vector<Entry>& getEntries();
|
2023-03-21 15:33:43 +01:00
|
|
|
|
2021-12-12 11:52:58 +01:00
|
|
|
}
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new entry to the data inspector
|
|
|
|
* @param unlocalizedName The unlocalized name of the entry
|
|
|
|
* @param requiredSize The minimum required number of bytes available for the entry to appear
|
|
|
|
* @param displayGeneratorFunction The function that will be called to generate the display function
|
|
|
|
* @param editingFunction The function that will be called to edit the data
|
|
|
|
*/
|
2024-01-15 20:52:08 +01:00
|
|
|
void add(
|
|
|
|
const UnlocalizedString &unlocalizedName,
|
|
|
|
size_t requiredSize,
|
|
|
|
impl::GeneratorFunction displayGeneratorFunction,
|
|
|
|
std::optional<impl::EditingFunction> editingFunction = std::nullopt
|
|
|
|
);
|
2021-12-12 11:52:58 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new entry to the data inspector
|
|
|
|
* @param unlocalizedName The unlocalized name of the entry
|
|
|
|
* @param requiredSize The minimum required number of bytes available for the entry to appear
|
|
|
|
* @param maxSize The maximum number of bytes to read from the data
|
|
|
|
* @param displayGeneratorFunction The function that will be called to generate the display function
|
|
|
|
* @param editingFunction The function that will be called to edit the data
|
|
|
|
*/
|
2024-01-15 20:52:08 +01:00
|
|
|
void add(
|
|
|
|
const UnlocalizedString &unlocalizedName,
|
|
|
|
size_t requiredSize,
|
|
|
|
size_t maxSize,
|
|
|
|
impl::GeneratorFunction displayGeneratorFunction,
|
|
|
|
std::optional<impl::EditingFunction> editingFunction = std::nullopt
|
|
|
|
);
|
|
|
|
|
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 {
|
2023-12-19 12:22:28 +01:00
|
|
|
UnlocalizedString unlocalizedCategory;
|
|
|
|
UnlocalizedString unlocalizedName;
|
2021-12-12 11:52:58 +01:00
|
|
|
CreatorFunction creatorFunction;
|
|
|
|
};
|
|
|
|
|
|
|
|
void add(const Entry &entry);
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::vector<Entry>& getEntries();
|
2021-12-12 11:52:58 +01:00
|
|
|
}
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-10-16 11:37:29 +02:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new node to the data processor
|
|
|
|
* @tparam T The custom node class that extends dp::Node
|
|
|
|
* @tparam Args Arguments types
|
|
|
|
* @param unlocalizedCategory The unlocalized category name of the node
|
|
|
|
* @param unlocalizedName The unlocalized name of the node
|
|
|
|
* @param args Arguments passed to the constructor of the node
|
|
|
|
*/
|
2022-06-25 12:19:59 +02:00
|
|
|
template<std::derived_from<dp::Node> T, typename... Args>
|
2023-12-19 12:22:28 +01:00
|
|
|
void add(const UnlocalizedString &unlocalizedCategory, const UnlocalizedString &unlocalizedName, Args &&...args) {
|
2022-08-08 21:23:52 +02:00
|
|
|
add(impl::Entry {
|
2023-12-19 12:22:28 +01:00
|
|
|
unlocalizedCategory,
|
|
|
|
unlocalizedName,
|
2023-04-17 16:18:48 +02:00
|
|
|
[=, ...args = std::forward<Args>(args)] mutable {
|
2022-08-08 21:23:52 +02:00
|
|
|
auto node = std::make_unique<T>(std::forward<Args>(args)...);
|
|
|
|
node->setUnlocalizedName(unlocalizedName);
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
});
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a separator to the data processor right click menu
|
|
|
|
*/
|
2021-10-16 11:37:29 +02:00
|
|
|
void addSeparator();
|
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
}
|
2021-02-11 00:35:30 +01:00
|
|
|
|
2023-11-21 14:38:01 +01:00
|
|
|
/* Language Registry. Allows together with the Lang class and the _lang user defined literal to add new languages */
|
2021-10-16 11:37:29 +02:00
|
|
|
namespace Language {
|
2023-03-21 15:33:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Loads localization information from json data
|
|
|
|
* @param data The language data
|
|
|
|
*/
|
2022-12-02 12:00:04 +01:00
|
|
|
void addLocalization(const nlohmann::json &data);
|
2021-02-11 00:35:30 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
namespace impl {
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::map<std::string, std::string>& getLanguages();
|
|
|
|
const std::map<std::string, std::vector<LocalizationManager::LanguageDefinition>>& getLanguageDefinitions();
|
2023-03-21 15:33:43 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2024-01-21 18:39:32 +01:00
|
|
|
struct Icon {
|
|
|
|
Icon(const char *glyph, ImGuiCustomCol color = ImGuiCustomCol(0x00)) : glyph(glyph), color(color) {}
|
|
|
|
|
|
|
|
std::string glyph;
|
|
|
|
ImGuiCustomCol color;
|
|
|
|
};
|
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
namespace impl {
|
|
|
|
|
2023-03-20 13:11:43 +01:00
|
|
|
using DrawCallback = std::function<void()>;
|
|
|
|
using MenuCallback = std::function<void()>;
|
|
|
|
using EnabledCallback = std::function<bool()>;
|
2024-01-15 20:52:08 +01:00
|
|
|
using SelectedCallback = std::function<bool()>;
|
2023-03-20 13:11:43 +01:00
|
|
|
using ClickCallback = std::function<void()>;
|
2022-01-18 00:10:10 +01:00
|
|
|
|
|
|
|
struct MainMenuItem {
|
2023-12-19 12:22:28 +01:00
|
|
|
UnlocalizedString unlocalizedName;
|
2022-01-18 00:10:10 +01:00
|
|
|
};
|
|
|
|
|
2022-01-23 02:28:38 +01:00
|
|
|
struct MenuItem {
|
2023-12-19 12:22:28 +01:00
|
|
|
std::vector<UnlocalizedString> unlocalizedNames;
|
2024-01-21 18:39:32 +01:00
|
|
|
Icon icon;
|
2023-11-18 14:34:33 +01:00
|
|
|
std::unique_ptr<Shortcut> shortcut;
|
|
|
|
View *view;
|
2023-03-20 13:11:43 +01:00
|
|
|
MenuCallback callback;
|
|
|
|
EnabledCallback enabledCallback;
|
2024-01-15 20:52:08 +01:00
|
|
|
SelectedCallback selectedCallback;
|
2024-01-21 18:39:32 +01:00
|
|
|
i32 toolbarIndex;
|
2022-01-23 02:28:38 +01:00
|
|
|
};
|
|
|
|
|
2022-01-22 22:03:19 +01:00
|
|
|
struct SidebarItem {
|
|
|
|
std::string icon;
|
|
|
|
DrawCallback callback;
|
2023-11-14 15:55:25 +01:00
|
|
|
EnabledCallback enabledCallback;
|
2022-01-22 22:03:19 +01:00
|
|
|
};
|
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
struct TitleBarButton {
|
|
|
|
std::string icon;
|
2023-12-19 12:22:28 +01:00
|
|
|
UnlocalizedString unlocalizedTooltip;
|
2022-02-02 00:36:09 +01:00
|
|
|
ClickCallback callback;
|
|
|
|
};
|
|
|
|
|
2023-03-20 13:11:43 +01:00
|
|
|
constexpr static auto SeparatorValue = "$SEPARATOR$";
|
|
|
|
constexpr static auto SubMenuValue = "$SUBMENU$";
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::multimap<u32, MainMenuItem>& getMainMenuItems();
|
|
|
|
|
|
|
|
const std::multimap<u32, MenuItem>& getMenuItems();
|
|
|
|
std::multimap<u32, MenuItem>& getMenuItemsMutable();
|
2023-03-21 15:33:43 +01:00
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::vector<DrawCallback>& getWelcomeScreenEntries();
|
|
|
|
const std::vector<DrawCallback>& getFooterItems();
|
|
|
|
const std::vector<DrawCallback>& getToolbarItems();
|
|
|
|
const std::vector<SidebarItem>& getSidebarItems();
|
|
|
|
const std::vector<TitleBarButton>& getTitlebarButtons();
|
2023-03-21 15:33:43 +01:00
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
}
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new top-level main menu entry
|
|
|
|
* @param unlocalizedName The unlocalized name of the entry
|
|
|
|
* @param priority The priority of the entry. Lower values are displayed first
|
|
|
|
*/
|
2023-12-19 12:22:28 +01:00
|
|
|
void registerMainMenuItem(const UnlocalizedString &unlocalizedName, u32 priority);
|
2023-03-21 15:33:43 +01:00
|
|
|
|
2024-01-08 21:51:48 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new main menu entry
|
|
|
|
* @param unlocalizedMainMenuNames The unlocalized names of the main menu entries
|
|
|
|
* @param icon The icon to use for the entry
|
|
|
|
* @param priority The priority of the entry. Lower values are displayed first
|
|
|
|
* @param shortcut The shortcut to use for the entry
|
|
|
|
* @param function The function to call when the entry is clicked
|
|
|
|
* @param enabledCallback The function to call to determine if the entry is enabled
|
|
|
|
* @param view The view to use for the entry. If nullptr, the shortcut will work globally
|
|
|
|
*/
|
2024-01-15 20:52:08 +01:00
|
|
|
void addMenuItem(
|
|
|
|
const std::vector<UnlocalizedString> &unlocalizedMainMenuNames,
|
2024-01-21 18:39:32 +01:00
|
|
|
const Icon &icon,
|
2024-01-15 20:52:08 +01:00
|
|
|
u32 priority,
|
|
|
|
const Shortcut &shortcut,
|
|
|
|
const impl::MenuCallback &function,
|
|
|
|
const impl::EnabledCallback& enabledCallback, View *view
|
|
|
|
);
|
2024-01-08 21:51:48 +01:00
|
|
|
|
2024-01-15 20:52:08 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new main menu entry
|
|
|
|
* @param unlocalizedMainMenuNames The unlocalized names of the main menu entries
|
|
|
|
* @param icon The icon to use for the entry
|
|
|
|
* @param priority The priority of the entry. Lower values are displayed first
|
|
|
|
* @param shortcut The shortcut to use for the entry
|
|
|
|
* @param function The function to call when the entry is clicked
|
|
|
|
* @param enabledCallback The function to call to determine if the entry is enabled
|
|
|
|
* @param selectedCallback The function to call to determine if the entry is selected
|
|
|
|
* @param view The view to use for the entry. If nullptr, the shortcut will work globally
|
|
|
|
*/
|
|
|
|
void addMenuItem(
|
|
|
|
const std::vector<UnlocalizedString> &unlocalizedMainMenuNames,
|
2024-01-21 18:39:32 +01:00
|
|
|
const Icon &icon,
|
2024-01-15 20:52:08 +01:00
|
|
|
u32 priority,
|
|
|
|
const Shortcut &shortcut,
|
|
|
|
const impl::MenuCallback &function,
|
|
|
|
const impl::EnabledCallback& enabledCallback = []{ return true; },
|
|
|
|
const impl::SelectedCallback &selectedCallback = []{ return false; },
|
|
|
|
View *view = nullptr
|
|
|
|
);
|
2024-01-08 21:51:48 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new main menu entry
|
|
|
|
* @param unlocalizedMainMenuNames The unlocalized names of the main menu entries
|
|
|
|
* @param priority The priority of the entry. Lower values are displayed first
|
|
|
|
* @param shortcut The shortcut to use for the entry
|
|
|
|
* @param function The function to call when the entry is clicked
|
|
|
|
* @param enabledCallback The function to call to determine if the entry is enabled
|
2024-01-15 20:52:08 +01:00
|
|
|
* @param selectedCallback The function to call to determine if the entry is selected
|
2023-03-21 15:33:43 +01:00
|
|
|
* @param view The view to use for the entry. If nullptr, the shortcut will work globally
|
|
|
|
*/
|
2024-01-15 20:52:08 +01:00
|
|
|
void addMenuItem(
|
|
|
|
const std::vector<UnlocalizedString> &unlocalizedMainMenuNames,
|
|
|
|
u32 priority,
|
|
|
|
const Shortcut &shortcut,
|
|
|
|
const impl::MenuCallback &function,
|
|
|
|
const impl::EnabledCallback& enabledCallback = []{ return true; },
|
|
|
|
const impl::SelectedCallback &selectedCallback = []{ return false; },
|
|
|
|
View *view = nullptr
|
|
|
|
);
|
2023-03-21 15:33:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adds a new main menu sub-menu entry
|
|
|
|
* @param unlocalizedMainMenuNames The unlocalized names of the main menu entries
|
|
|
|
* @param priority The priority of the entry. Lower values are displayed first
|
|
|
|
* @param function The function to call when the entry is clicked
|
|
|
|
* @param enabledCallback The function to call to determine if the entry is enabled
|
|
|
|
*/
|
2024-01-15 20:52:08 +01:00
|
|
|
void addMenuItemSubMenu(
|
|
|
|
std::vector<UnlocalizedString> unlocalizedMainMenuNames,
|
|
|
|
u32 priority,
|
|
|
|
const impl::MenuCallback &function,
|
|
|
|
const impl::EnabledCallback& enabledCallback = []{ return true; }
|
|
|
|
);
|
2023-03-21 15:33:43 +01:00
|
|
|
|
2024-01-08 21:51:48 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new main menu sub-menu entry
|
|
|
|
* @param unlocalizedMainMenuNames The unlocalized names of the main menu entries
|
|
|
|
* @param icon The icon to use for the entry
|
|
|
|
* @param priority The priority of the entry. Lower values are displayed first
|
|
|
|
* @param function The function to call when the entry is clicked
|
|
|
|
* @param enabledCallback The function to call to determine if the entry is enabled
|
|
|
|
*/
|
2024-01-15 20:52:08 +01:00
|
|
|
void addMenuItemSubMenu(
|
|
|
|
std::vector<UnlocalizedString> unlocalizedMainMenuNames,
|
|
|
|
const char *icon,
|
|
|
|
u32 priority,
|
|
|
|
const impl::MenuCallback &function,
|
|
|
|
const impl::EnabledCallback& enabledCallback = []{ return true; }
|
|
|
|
);
|
2024-01-08 21:51:48 +01:00
|
|
|
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new main menu separator
|
|
|
|
* @param unlocalizedMainMenuNames The unlocalized names of the main menu entries
|
|
|
|
* @param priority The priority of the entry. Lower values are displayed first
|
|
|
|
*/
|
2023-12-19 12:22:28 +01:00
|
|
|
void addMenuItemSeparator(std::vector<UnlocalizedString> unlocalizedMainMenuNames, u32 priority);
|
2022-01-23 02:28:38 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adds a new welcome screen entry
|
|
|
|
* @param function The function to call to draw the entry
|
|
|
|
*/
|
2022-01-18 00:10:10 +01:00
|
|
|
void addWelcomeScreenEntry(const impl::DrawCallback &function);
|
2023-03-21 15:33:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adds a new footer item
|
|
|
|
* @param function The function to call to draw the item
|
|
|
|
*/
|
2022-01-18 00:10:10 +01:00
|
|
|
void addFooterItem(const impl::DrawCallback &function);
|
2023-03-21 15:33:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adds a new toolbar item
|
|
|
|
* @param function The function to call to draw the item
|
|
|
|
*/
|
2022-01-18 00:10:10 +01:00
|
|
|
void addToolbarItem(const impl::DrawCallback &function);
|
2023-03-21 15:33:43 +01:00
|
|
|
|
2024-01-21 18:39:32 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a menu item to the toolbar
|
|
|
|
* @param unlocalizedName Unlocalized name of the menu item
|
|
|
|
* @param color Color of the toolbar icon
|
|
|
|
*/
|
|
|
|
void addMenuItemToToolbar(const UnlocalizedString &unlocalizedName, ImGuiCustomCol color);
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new sidebar item
|
|
|
|
* @param icon The icon to use for the item
|
|
|
|
* @param function The function to call to draw the item
|
2023-11-14 15:55:25 +01:00
|
|
|
* @param enabledCallback The function
|
2023-03-21 15:33:43 +01:00
|
|
|
*/
|
2024-01-15 20:52:08 +01:00
|
|
|
void addSidebarItem(
|
|
|
|
const std::string &icon,
|
|
|
|
const impl::DrawCallback &function,
|
|
|
|
const impl::EnabledCallback &enabledCallback = []{ return true; }
|
|
|
|
);
|
2022-01-18 00:10:10 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new title bar button
|
|
|
|
* @param icon The icon to use for the button
|
|
|
|
* @param unlocalizedTooltip The unlocalized tooltip to use for the button
|
|
|
|
* @param function The function to call when the button is clicked
|
|
|
|
*/
|
2024-01-15 20:52:08 +01:00
|
|
|
void addTitleBarButton(
|
|
|
|
const std::string &icon,
|
|
|
|
const UnlocalizedString &unlocalizedTooltip,
|
|
|
|
const impl::ClickCallback &function
|
|
|
|
);
|
2022-01-18 00:10:10 +01:00
|
|
|
|
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 {
|
|
|
|
|
2023-12-19 12:22:28 +01:00
|
|
|
void addProviderName(const UnlocalizedString &unlocalizedName);
|
2021-12-12 11:52:58 +01:00
|
|
|
|
2024-03-10 22:05:26 +01:00
|
|
|
using ProviderCreationFunction = std::function<std::unique_ptr<prv::Provider>()>;
|
2023-11-18 14:34:33 +01:00
|
|
|
void add(const std::string &typeName, ProviderCreationFunction creationFunction);
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::vector<std::string>& getEntries();
|
2023-03-21 15:33:43 +01:00
|
|
|
|
2021-12-12 11:52:58 +01:00
|
|
|
}
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new provider to the list of providers
|
|
|
|
* @tparam T The provider type that extends hex::prv::Provider
|
|
|
|
* @param addToList Whether to display the provider in the Other Providers list in the welcome screen and File menu
|
|
|
|
*/
|
2023-11-10 14:48:26 +01:00
|
|
|
template<std::derived_from<prv::Provider> T>
|
2022-08-08 21:23:52 +02:00
|
|
|
void add(bool addToList = true) {
|
|
|
|
auto typeName = T().getTypeName();
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
impl::add(typeName, [] -> std::unique_ptr<prv::Provider> {
|
|
|
|
return std::make_unique<T>();
|
2021-12-12 11:52:58 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
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-01-13 00:27:31 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/* Data Formatter Registry. Allows adding formatters that are used in the Copy-As menu for example */
|
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)>;
|
2024-06-18 22:57:55 +02:00
|
|
|
struct ExportMenuEntry {
|
2023-12-19 12:22:28 +01:00
|
|
|
UnlocalizedString unlocalizedName;
|
2022-01-13 00:27:31 +01:00
|
|
|
Callback callback;
|
|
|
|
};
|
|
|
|
|
2024-06-18 22:57:55 +02:00
|
|
|
struct FindOccurrence {
|
|
|
|
Region region;
|
|
|
|
enum class DecodeType { ASCII, Binary, UTF16, Unsigned, Signed, Float, Double } decodeType;
|
|
|
|
std::endian endian = std::endian::native;
|
|
|
|
bool selected;
|
|
|
|
};
|
|
|
|
|
|
|
|
using FindExporterCallback = std::function<std::vector<u8>(const std::vector<FindOccurrence>&, std::function<std::string(FindOccurrence)>)>;
|
|
|
|
struct FindExporterEntry {
|
|
|
|
UnlocalizedString unlocalizedName;
|
|
|
|
std::string fileExtension;
|
|
|
|
FindExporterCallback callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Retrieves a list of all registered data formatters used by the 'File -> Export' menu
|
|
|
|
*/
|
|
|
|
const std::vector<ExportMenuEntry>& getExportMenuEntries();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Retrieves a list of all registered data formatters used in the Results section of the 'Find' view
|
|
|
|
*/
|
|
|
|
const std::vector<FindExporterEntry>& getFindExporterEntries();
|
2023-03-21 15:33:43 +01:00
|
|
|
|
2022-01-13 00:27:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new data formatter
|
|
|
|
* @param unlocalizedName The unlocalized name of the formatter
|
|
|
|
* @param callback The function to call to format the data
|
|
|
|
*/
|
2024-06-18 22:57:55 +02:00
|
|
|
void addExportMenuEntry(const UnlocalizedString &unlocalizedName, const impl::Callback &callback);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adds a new data exporter for Find results
|
|
|
|
* @param unlocalizedName The unlocalized name of the formatter
|
|
|
|
* @param callback The function to call to format the data
|
|
|
|
*/
|
|
|
|
void addFindExportFormatter(const UnlocalizedString &unlocalizedName, const std::string fileExtension, const impl::FindExporterCallback &callback);
|
2022-01-13 00:27:31 +01:00
|
|
|
|
|
|
|
}
|
2022-01-13 14:34:19 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/* File Handler Registry. Allows adding handlers for opening files specific file types */
|
2022-01-13 14:34:19 +01:00
|
|
|
namespace FileHandler {
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
2023-03-17 11:43:50 +01:00
|
|
|
using Callback = std::function<bool(std::fs::path)>;
|
2022-01-13 14:34:19 +01:00
|
|
|
struct Entry {
|
|
|
|
std::vector<std::string> extensions;
|
|
|
|
Callback callback;
|
|
|
|
};
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::vector<Entry>& getEntries();
|
2023-03-21 15:33:43 +01:00
|
|
|
|
2022-01-13 14:34:19 +01:00
|
|
|
}
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new file handler
|
|
|
|
* @param extensions The file extensions to handle
|
|
|
|
* @param callback The function to call to handle the file
|
|
|
|
*/
|
2022-01-13 14:34:19 +01:00
|
|
|
void add(const std::vector<std::string> &extensions, const impl::Callback &callback);
|
|
|
|
|
|
|
|
}
|
2022-05-27 20:42:07 +02:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/* Hex Editor Registry. Allows adding new functionality to the hex editor */
|
2022-05-27 20:42:07 +02:00
|
|
|
namespace HexEditor {
|
|
|
|
|
|
|
|
class DataVisualizer {
|
|
|
|
public:
|
2023-12-19 12:22:28 +01:00
|
|
|
DataVisualizer(UnlocalizedString unlocalizedName, u16 bytesPerCell, u16 maxCharsPerCell)
|
2023-06-05 09:07:58 +02:00
|
|
|
: m_unlocalizedName(std::move(unlocalizedName)),
|
|
|
|
m_bytesPerCell(bytesPerCell),
|
|
|
|
m_maxCharsPerCell(maxCharsPerCell) { }
|
2022-05-27 20:42:07 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
[[nodiscard]] u16 getBytesPerCell() const { return m_bytesPerCell; }
|
|
|
|
[[nodiscard]] u16 getMaxCharsPerCell() const { return m_maxCharsPerCell; }
|
2022-05-27 20:42:07 +02:00
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
[[nodiscard]] const UnlocalizedString& getUnlocalizedName() const { return m_unlocalizedName; }
|
2023-06-05 09:07:58 +02:00
|
|
|
|
2022-05-27 20:42:07 +02:00
|
|
|
protected:
|
|
|
|
const static int TextInputFlags;
|
|
|
|
|
2023-02-18 22:20:02 +01:00
|
|
|
bool drawDefaultScalarEditingTextBox(u64 address, const char *format, ImGuiDataType dataType, u8 *data, ImGuiInputTextFlags flags) const;
|
|
|
|
bool drawDefaultTextEditingTextBox(u64 address, std::string &data, ImGuiInputTextFlags flags) const;
|
2023-06-05 09:07:58 +02:00
|
|
|
|
2022-05-27 20:42:07 +02:00
|
|
|
private:
|
2023-12-19 12:22:28 +01:00
|
|
|
UnlocalizedString m_unlocalizedName;
|
2022-05-27 20:42:07 +02:00
|
|
|
u16 m_bytesPerCell;
|
|
|
|
u16 m_maxCharsPerCell;
|
|
|
|
};
|
|
|
|
|
2024-01-28 15:28:55 +01:00
|
|
|
struct MiniMapVisualizer {
|
2024-06-20 11:21:20 +02:00
|
|
|
using Callback = std::function<void(u64, std::span<const u8>, std::vector<ImColor>&)>;
|
2024-01-28 15:28:55 +01:00
|
|
|
|
|
|
|
UnlocalizedString unlocalizedName;
|
|
|
|
Callback callback;
|
|
|
|
};
|
|
|
|
|
2022-05-27 20:42:07 +02:00
|
|
|
namespace impl {
|
|
|
|
|
2023-06-21 17:48:51 +02:00
|
|
|
void addDataVisualizer(std::shared_ptr<DataVisualizer> &&visualizer);
|
2022-05-27 20:42:07 +02:00
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::vector<std::shared_ptr<DataVisualizer>>& getVisualizers();
|
|
|
|
const std::vector<std::shared_ptr<MiniMapVisualizer>>& getMiniMapVisualizers();
|
2022-05-27 20:42:07 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new cell data visualizer
|
|
|
|
* @tparam T The data visualizer type that extends hex::DataVisualizer
|
|
|
|
* @param args The arguments to pass to the constructor of the data visualizer
|
|
|
|
*/
|
2022-06-25 12:19:59 +02:00
|
|
|
template<std::derived_from<DataVisualizer> T, typename... Args>
|
2023-06-05 09:07:58 +02:00
|
|
|
void addDataVisualizer(Args &&...args) {
|
2023-06-21 17:48:51 +02:00
|
|
|
return impl::addDataVisualizer(std::make_shared<T>(std::forward<Args>(args)...));
|
2022-05-27 20:42:07 +02:00
|
|
|
}
|
|
|
|
|
2023-06-21 17:48:51 +02:00
|
|
|
/**
|
2023-06-21 23:59:40 +02:00
|
|
|
* @brief Gets a data visualizer by its unlocalized name
|
2023-06-21 17:48:51 +02:00
|
|
|
* @param unlocalizedName Unlocalized name of the data visualizer
|
|
|
|
* @return The data visualizer, or nullptr if it doesn't exist
|
|
|
|
*/
|
2023-12-19 12:22:28 +01:00
|
|
|
std::shared_ptr<DataVisualizer> getVisualizerByName(const UnlocalizedString &unlocalizedName);
|
2023-06-21 17:48:51 +02:00
|
|
|
|
2024-01-28 15:28:55 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a new minimap visualizer
|
|
|
|
* @param unlocalizedName Unlocalized name of the minimap visualizer
|
|
|
|
* @param callback The callback that will be called to get the color of a line
|
|
|
|
*/
|
|
|
|
void addMiniMapVisualizer(UnlocalizedString unlocalizedName, MiniMapVisualizer::Callback callback);
|
|
|
|
|
2022-05-27 20:42:07 +02:00
|
|
|
}
|
2022-05-30 16:36:46 +02:00
|
|
|
|
2024-01-21 18:39:13 +01:00
|
|
|
/* Diffing Registry. Allows adding new diffing algorithms */
|
|
|
|
namespace Diffing {
|
|
|
|
|
|
|
|
enum class DifferenceType : u8 {
|
|
|
|
Match = 0,
|
|
|
|
Insertion = 1,
|
|
|
|
Deletion = 2,
|
|
|
|
Mismatch = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
using DiffTree = wolv::container::IntervalTree<DifferenceType>;
|
|
|
|
|
|
|
|
class Algorithm {
|
|
|
|
public:
|
|
|
|
explicit Algorithm(UnlocalizedString unlocalizedName, UnlocalizedString unlocalizedDescription)
|
|
|
|
: m_unlocalizedName(std::move(unlocalizedName)),
|
|
|
|
m_unlocalizedDescription(std::move(unlocalizedDescription)) { }
|
|
|
|
|
|
|
|
virtual ~Algorithm() = default;
|
|
|
|
|
|
|
|
virtual std::vector<DiffTree> analyze(prv::Provider *providerA, prv::Provider *providerB) const = 0;
|
|
|
|
virtual void drawSettings() { }
|
|
|
|
|
|
|
|
const UnlocalizedString& getUnlocalizedName() const { return m_unlocalizedName; }
|
|
|
|
const UnlocalizedString& getUnlocalizedDescription() const { return m_unlocalizedDescription; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
UnlocalizedString m_unlocalizedName, m_unlocalizedDescription;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::vector<std::unique_ptr<Algorithm>>& getAlgorithms();
|
2024-01-21 18:39:13 +01:00
|
|
|
|
|
|
|
void addAlgorithm(std::unique_ptr<Algorithm> &&hash);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adds a new hash
|
|
|
|
* @tparam T The hash type that extends hex::Hash
|
|
|
|
* @param args The arguments to pass to the constructor of the hash
|
|
|
|
*/
|
|
|
|
template<typename T, typename ... Args>
|
|
|
|
void addAlgorithm(Args && ... args) {
|
|
|
|
impl::addAlgorithm(std::make_unique<T>(std::forward<Args>(args)...));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/* Hash Registry. Allows adding new hashes to the Hash view */
|
2022-05-30 16:36:46 +02:00
|
|
|
namespace Hashes {
|
|
|
|
|
|
|
|
class Hash {
|
|
|
|
public:
|
2023-12-19 12:22:28 +01:00
|
|
|
explicit Hash(UnlocalizedString unlocalizedName) : m_unlocalizedName(std::move(unlocalizedName)) {}
|
2023-06-11 10:47:17 +02:00
|
|
|
virtual ~Hash() = default;
|
2022-05-30 16:36:46 +02:00
|
|
|
|
|
|
|
class Function {
|
|
|
|
public:
|
|
|
|
using Callback = std::function<std::vector<u8>(const Region&, prv::Provider *)>;
|
|
|
|
|
2023-01-18 14:30:56 +01:00
|
|
|
Function(Hash *type, std::string name, Callback callback)
|
2022-05-30 16:36:46 +02:00
|
|
|
: m_type(type), m_name(std::move(name)), m_callback(std::move(callback)) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
[[nodiscard]] Hash *getType() { return m_type; }
|
|
|
|
[[nodiscard]] const Hash *getType() const { return m_type; }
|
2024-02-10 23:31:05 +01:00
|
|
|
[[nodiscard]] const std::string& getName() const { return m_name; }
|
2022-05-30 16:36:46 +02:00
|
|
|
|
|
|
|
const std::vector<u8>& get(const Region& region, prv::Provider *provider) {
|
2023-12-19 13:10:25 +01:00
|
|
|
if (m_cache.empty()) {
|
|
|
|
m_cache = m_callback(region, provider);
|
2022-05-30 16:36:46 +02:00
|
|
|
}
|
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
return m_cache;
|
2022-05-30 16:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_cache.clear();
|
2022-05-30 16:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2023-01-18 14:30:56 +01:00
|
|
|
Hash *m_type;
|
2022-05-30 16:36:46 +02:00
|
|
|
std::string m_name;
|
|
|
|
Callback m_callback;
|
|
|
|
|
|
|
|
std::vector<u8> m_cache;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual void draw() { }
|
|
|
|
[[nodiscard]] virtual Function create(std::string name) = 0;
|
|
|
|
|
2023-01-18 14:30:56 +01:00
|
|
|
[[nodiscard]] virtual nlohmann::json store() const = 0;
|
|
|
|
virtual void load(const nlohmann::json &json) = 0;
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
[[nodiscard]] const UnlocalizedString& getUnlocalizedName() const {
|
2023-12-19 13:10:25 +01:00
|
|
|
return m_unlocalizedName;
|
2022-05-30 16:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2023-01-18 14:30:56 +01:00
|
|
|
[[nodiscard]] Function create(const std::string &name, const Function::Callback &callback) {
|
2022-05-30 16:36:46 +02:00
|
|
|
return { this, name, callback };
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2023-12-19 12:22:28 +01:00
|
|
|
UnlocalizedString m_unlocalizedName;
|
2022-05-30 16:36:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::vector<std::unique_ptr<Hash>>& getHashes();
|
2022-05-30 16:36:46 +02:00
|
|
|
|
2023-06-11 10:47:17 +02:00
|
|
|
void add(std::unique_ptr<Hash> &&hash);
|
2024-01-21 18:39:13 +01:00
|
|
|
|
2022-05-30 16:36:46 +02:00
|
|
|
}
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adds a new hash
|
|
|
|
* @tparam T The hash type that extends hex::Hash
|
|
|
|
* @param args The arguments to pass to the constructor of the hash
|
|
|
|
*/
|
2022-05-30 16:36:46 +02:00
|
|
|
template<typename T, typename ... Args>
|
|
|
|
void add(Args && ... args) {
|
2023-06-11 10:47:17 +02:00
|
|
|
impl::add(std::make_unique<T>(std::forward<Args>(args)...));
|
2022-05-30 16:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-05-15 11:30:24 +02:00
|
|
|
|
2023-11-10 14:48:26 +01:00
|
|
|
/* Background Service Registry. Allows adding new background services */
|
2023-05-15 11:30:24 +02:00
|
|
|
namespace BackgroundServices {
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
using Callback = std::function<void()>;
|
|
|
|
|
|
|
|
void stopServices();
|
|
|
|
}
|
|
|
|
|
2023-12-19 12:22:28 +01:00
|
|
|
void registerService(const UnlocalizedString &unlocalizedName, const impl::Callback &callback);
|
2023-05-15 11:30:24 +02:00
|
|
|
}
|
|
|
|
|
2023-11-10 14:48:26 +01:00
|
|
|
/* Network Communication Interface Registry. Allows adding new communication interface endpoints */
|
2023-05-15 11:30:24 +02:00
|
|
|
namespace CommunicationInterface {
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
using NetworkCallback = std::function<nlohmann::json(const nlohmann::json &)>;
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::map<std::string, NetworkCallback>& getNetworkEndpoints();
|
2023-05-15 11:30:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void registerNetworkEndpoint(const std::string &endpoint, const impl::NetworkCallback &callback);
|
|
|
|
|
|
|
|
}
|
2023-11-10 14:48:26 +01:00
|
|
|
|
|
|
|
/* Experiments Registry. Allows adding new experiments */
|
|
|
|
namespace Experiments {
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
struct Experiment {
|
2023-12-19 12:22:28 +01:00
|
|
|
UnlocalizedString unlocalizedName, unlocalizedDescription;
|
2023-11-10 14:48:26 +01:00
|
|
|
bool enabled;
|
|
|
|
};
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::map<std::string, Experiment>& getExperiments();
|
2023-11-10 14:48:26 +01:00
|
|
|
}
|
|
|
|
|
2024-01-15 20:52:08 +01:00
|
|
|
void addExperiment(
|
|
|
|
const std::string &experimentName,
|
|
|
|
const UnlocalizedString &unlocalizedName,
|
|
|
|
const UnlocalizedString &unlocalizedDescription = ""
|
|
|
|
);
|
|
|
|
|
2023-11-10 14:48:26 +01:00
|
|
|
void enableExperiement(const std::string &experimentName, bool enabled);
|
|
|
|
|
|
|
|
[[nodiscard]] bool isExperimentEnabled(const std::string &experimentName);
|
|
|
|
}
|
2023-11-22 08:26:31 +01:00
|
|
|
|
2024-02-21 00:06:52 +01:00
|
|
|
/* Reports Registry. Allows adding new sections to exported reports */
|
2023-11-22 08:26:31 +01:00
|
|
|
namespace Reports {
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
using Callback = std::function<std::string(prv::Provider*)>;
|
|
|
|
|
|
|
|
struct ReportGenerator {
|
|
|
|
Callback callback;
|
|
|
|
};
|
|
|
|
|
2024-02-10 23:31:05 +01:00
|
|
|
const std::vector<ReportGenerator>& getGenerators();
|
2023-11-22 08:26:31 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void addReportProvider(impl::Callback callback);
|
|
|
|
|
|
|
|
}
|
2024-02-21 00:06:52 +01:00
|
|
|
|
|
|
|
namespace DataInformation {
|
|
|
|
|
|
|
|
class InformationSection {
|
|
|
|
public:
|
|
|
|
InformationSection(const UnlocalizedString &unlocalizedName, const UnlocalizedString &unlocalizedDescription = "", bool hasSettings = false)
|
|
|
|
: m_unlocalizedName(unlocalizedName), m_unlocalizedDescription(unlocalizedDescription),
|
|
|
|
m_hasSettings(hasSettings) { }
|
|
|
|
virtual ~InformationSection() = default;
|
|
|
|
|
|
|
|
[[nodiscard]] const UnlocalizedString& getUnlocalizedName() const { return m_unlocalizedName; }
|
|
|
|
[[nodiscard]] const UnlocalizedString& getUnlocalizedDescription() const { return m_unlocalizedDescription; }
|
|
|
|
|
|
|
|
virtual void process(Task &task, prv::Provider *provider, Region region) = 0;
|
|
|
|
virtual void reset() = 0;
|
|
|
|
|
|
|
|
virtual void drawSettings() { }
|
|
|
|
virtual void drawContent() = 0;
|
|
|
|
|
|
|
|
[[nodiscard]] bool isValid() const { return m_valid; }
|
|
|
|
void markValid(bool valid = true) { m_valid = valid; }
|
|
|
|
|
|
|
|
[[nodiscard]] bool isEnabled() const { return m_enabled; }
|
|
|
|
void setEnabled(bool enabled) { m_enabled = enabled; }
|
|
|
|
|
|
|
|
[[nodiscard]] bool isAnalyzing() const { return m_analyzing; }
|
|
|
|
void setAnalyzing(bool analyzing) { m_analyzing = analyzing; }
|
|
|
|
|
|
|
|
virtual void load(const nlohmann::json &data) {
|
|
|
|
m_enabled = data.value<bool>("enabled", true);
|
|
|
|
}
|
|
|
|
[[nodiscard]] virtual nlohmann::json store() {
|
|
|
|
nlohmann::json data;
|
|
|
|
data["enabled"] = m_enabled.load();
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] bool hasSettings() const { return m_hasSettings; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
UnlocalizedString m_unlocalizedName, m_unlocalizedDescription;
|
|
|
|
bool m_hasSettings;
|
|
|
|
|
|
|
|
std::atomic<bool> m_analyzing = false;
|
|
|
|
std::atomic<bool> m_valid = false;
|
|
|
|
std::atomic<bool> m_enabled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
using CreateCallback = std::function<std::unique_ptr<InformationSection>()>;
|
|
|
|
|
|
|
|
const std::vector<CreateCallback>& getInformationSectionConstructors();
|
|
|
|
void addInformationSectionCreator(const CreateCallback &callback);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void addInformationSection(auto && ...args) {
|
|
|
|
impl::addInformationSectionCreator([args...] {
|
|
|
|
return std::make_unique<T>(std::forward<decltype(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
|
|
|
}
|