From 6c122e5fbe777377ffcf695c5d723bbd524656fc Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 18 Apr 2023 10:06:47 +0200 Subject: [PATCH] patterns: Updated to new API --- lib/external/libromfs | 2 +- lib/external/pattern_language | 2 +- .../include/hex/api/content_registry.hpp | 2 +- lib/libimhex/include/hex/helpers/concepts.hpp | 2 +- lib/libimhex/include/hex/plugin.hpp | 4 ++++ plugins/builtin/include/ui/pattern_drawer.hpp | 6 +++--- .../builtin/source/content/pl_visualizers.cpp | 16 ++++++++-------- .../source/content/views/view_data_inspector.cpp | 2 +- .../source/content/views/view_pattern_data.cpp | 2 +- .../source/content/views/view_pattern_editor.cpp | 2 +- plugins/builtin/source/ui/pattern_drawer.cpp | 12 ++++++------ 11 files changed, 28 insertions(+), 24 deletions(-) diff --git a/lib/external/libromfs b/lib/external/libromfs index 40cd303e9..80b9adea2 160000 --- a/lib/external/libromfs +++ b/lib/external/libromfs @@ -1 +1 @@ -Subproject commit 40cd303e9213e544a3ff21562b16406140f254ec +Subproject commit 80b9adea2003eb01fa4cf2ecb0d77f2d9c0dd32a diff --git a/lib/external/pattern_language b/lib/external/pattern_language index a918d6f3a..6fc521084 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit a918d6f3a76fd199af146e1045aafe637245361e +Subproject commit 6fc5210840edf1b3eecd9b06c07066155366b04b diff --git a/lib/libimhex/include/hex/api/content_registry.hpp b/lib/libimhex/include/hex/api/content_registry.hpp index 9c1e9df2f..8c580ffa9 100644 --- a/lib/libimhex/include/hex/api/content_registry.hpp +++ b/lib/libimhex/include/hex/api/content_registry.hpp @@ -239,7 +239,7 @@ namespace hex { namespace impl { - using VisualizerFunctionCallback = std::function)>; + using VisualizerFunctionCallback = std::function)>; struct FunctionDefinition { pl::api::Namespace ns; diff --git a/lib/libimhex/include/hex/helpers/concepts.hpp b/lib/libimhex/include/hex/helpers/concepts.hpp index 9e3f57106..dac4924a6 100644 --- a/lib/libimhex/include/hex/helpers/concepts.hpp +++ b/lib/libimhex/include/hex/helpers/concepts.hpp @@ -16,7 +16,7 @@ namespace hex { concept has_size = sizeof(T) == Size; template - class Cloneable { + class ICloneable { public: [[nodiscard]] virtual std::unique_ptr clone() const = 0; }; diff --git a/lib/libimhex/include/hex/plugin.hpp b/lib/libimhex/include/hex/plugin.hpp index d850f916d..4479abecf 100644 --- a/lib/libimhex/include/hex/plugin.hpp +++ b/lib/libimhex/include/hex/plugin.hpp @@ -6,6 +6,10 @@ #include +/** + * This macro is used to define all the required entry points for a plugin. + * Name, Author and Description will be displayed in the in the plugin list on the Welcome screen. + */ #define IMHEX_PLUGIN_SETUP(name, author, description) IMHEX_PLUGIN_SETUP_IMPL(name, author, description) #define IMHEX_PLUGIN_SETUP_IMPL(name, author, description) \ diff --git a/plugins/builtin/include/ui/pattern_drawer.hpp b/plugins/builtin/include/ui/pattern_drawer.hpp index 8b3dfa779..24b3f5a7e 100644 --- a/plugins/builtin/include/ui/pattern_drawer.hpp +++ b/plugins/builtin/include/ui/pattern_drawer.hpp @@ -49,12 +49,12 @@ namespace hex::plugin::builtin::ui { constexpr static auto ChunkSize = 512; constexpr static auto DisplayEndStep = 64; - void drawArray(pl::ptrn::Pattern& pattern, pl::ptrn::Iteratable &iteratable, bool isInlined); + void drawArray(pl::ptrn::Pattern& pattern, pl::ptrn::IIterable &iteratable, bool isInlined); u64& getDisplayEnd(const pl::ptrn::Pattern& pattern); void makeSelectable(const pl::ptrn::Pattern &pattern); - void drawVisualizerButton(pl::ptrn::Pattern& pattern, pl::ptrn::Iteratable &iteratable); - void drawVisualizer(const std::vector &arguments, pl::ptrn::Pattern &pattern, pl::ptrn::Iteratable &iteratable, bool reset); + void drawVisualizerButton(pl::ptrn::Pattern& pattern, pl::ptrn::IIterable &iteratable); + void drawVisualizer(const std::vector &arguments, pl::ptrn::Pattern &pattern, pl::ptrn::IIterable &iteratable, bool reset); void createLeafNode(const pl::ptrn::Pattern& pattern); bool createTreeNode(const pl::ptrn::Pattern& pattern); diff --git a/plugins/builtin/source/content/pl_visualizers.cpp b/plugins/builtin/source/content/pl_visualizers.cpp index 26466a253..d47374e6b 100644 --- a/plugins/builtin/source/content/pl_visualizers.cpp +++ b/plugins/builtin/source/content/pl_visualizers.cpp @@ -42,7 +42,7 @@ namespace hex::plugin::builtin { namespace { - void drawLinePlotVisualizer(pl::ptrn::Pattern &, pl::ptrn::Iteratable &, bool shouldReset, std::span arguments) { + void drawLinePlotVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { static std::vector values; auto dataPattern = arguments[0].toPattern(); @@ -61,7 +61,7 @@ namespace hex::plugin::builtin { } } - void drawScatterPlotVisualizer(pl::ptrn::Pattern &, pl::ptrn::Iteratable &, bool shouldReset, std::span arguments) { + void drawScatterPlotVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { static std::vector xValues, yValues; auto xPattern = arguments[0].toPattern(); @@ -83,7 +83,7 @@ namespace hex::plugin::builtin { } } - void drawImageVisualizer(pl::ptrn::Pattern &, pl::ptrn::Iteratable &, bool shouldReset, std::span arguments) { + void drawImageVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { static ImGui::Texture texture; if (shouldReset) { auto pattern = arguments[0].toPattern(); @@ -96,7 +96,7 @@ namespace hex::plugin::builtin { ImGui::Image(texture, texture.getSize()); } - void drawBitmapVisualizer(pl::ptrn::Pattern &, pl::ptrn::Iteratable &, bool shouldReset, std::span arguments) { + void drawBitmapVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { static ImGui::Texture texture; if (shouldReset) { auto pattern = arguments[0].toPattern(); @@ -111,7 +111,7 @@ namespace hex::plugin::builtin { ImGui::Image(texture, texture.getSize()); } - void drawDisassemblyVisualizer(pl::ptrn::Pattern &, pl::ptrn::Iteratable &, bool shouldReset, std::span arguments) { + void drawDisassemblyVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { struct Disassembly { u64 address; std::vector bytes; @@ -167,7 +167,7 @@ namespace hex::plugin::builtin { } } - void draw3DVisualizer(pl::ptrn::Pattern &, pl::ptrn::Iteratable &, bool shouldReset, std::span arguments) { + void draw3DVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { auto verticesPattern = arguments[0].toPattern(); auto indicesPattern = arguments[1].toPattern(); @@ -339,7 +339,7 @@ namespace hex::plugin::builtin { } - void drawSoundVisualizer(pl::ptrn::Pattern &, pl::ptrn::Iteratable &, bool shouldReset, std::span arguments) { + void drawSoundVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { auto wavePattern = arguments[0].toPattern(); auto channels = arguments[1].toUnsigned(); auto sampleRate = arguments[2].toUnsigned(); @@ -443,7 +443,7 @@ namespace hex::plugin::builtin { (waveData.size() / sampleRate) / 60, (waveData.size() / sampleRate) % 60); } - void drawChunkBasedEntropyVisualizer(pl::ptrn::Pattern &, pl::ptrn::Iteratable &, bool shouldReset, std::span arguments) { + void drawChunkBasedEntropyVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { // variable used to store the result to avoid having to recalculate the result at each frame static DiagramChunkBasedEntropyAnalysis analyzer; diff --git a/plugins/builtin/source/content/views/view_data_inspector.cpp b/plugins/builtin/source/content/views/view_data_inspector.cpp index 714b76d1b..319b8289b 100644 --- a/plugins/builtin/source/content/views/view_data_inspector.cpp +++ b/plugins/builtin/source/content/views/view_data_inspector.cpp @@ -112,7 +112,7 @@ namespace hex::plugin::builtin { if (!inspectorCode.empty()) { if (this->m_runtime.executeString(inspectorCode, {}, inVariables, true)) { - const auto &patterns = this->m_runtime.getAllPatterns(); + const auto &patterns = this->m_runtime.getPatterns(); for (const auto &pattern : patterns) { if (pattern->getVisibility() == pl::ptrn::Visibility::Hidden) diff --git a/plugins/builtin/source/content/views/view_pattern_data.cpp b/plugins/builtin/source/content/views/view_pattern_data.cpp index 405c77b08..5c3821107 100644 --- a/plugins/builtin/source/content/views/view_pattern_data.cpp +++ b/plugins/builtin/source/content/views/view_pattern_data.cpp @@ -44,7 +44,7 @@ namespace hex::plugin::builtin { this->m_shouldReset = false; } - this->m_patternDrawer.draw(runtime.getAllPatterns()); + this->m_patternDrawer.draw(runtime.getPatterns()); } } } diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 9211665ab..2a0934d25 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -471,7 +471,7 @@ namespace hex::plugin::builtin { const auto &patterns = [&, this] -> const auto& { if (patternProvider->isReadable() && *this->m_executionDone) - return runtime.getAllPatterns(id); + return runtime.getPatterns(id); else { static const std::vector> empty; return empty; diff --git a/plugins/builtin/source/ui/pattern_drawer.cpp b/plugins/builtin/source/ui/pattern_drawer.cpp index 500e6af6f..7e9e857af 100644 --- a/plugins/builtin/source/ui/pattern_drawer.cpp +++ b/plugins/builtin/source/ui/pattern_drawer.cpp @@ -144,7 +144,7 @@ namespace hex::plugin::builtin::ui { this->m_editingPatternOffset = 0x00; } - void PatternDrawer::drawVisualizer(const std::vector &arguments, pl::ptrn::Pattern &pattern, pl::ptrn::Iteratable &iteratable, bool reset) { + void PatternDrawer::drawVisualizer(const std::vector &arguments, pl::ptrn::Pattern &pattern, pl::ptrn::IIterable &iteratable, bool reset) { auto visualizerName = arguments.front().toString(true); const auto &visualizers = ContentRegistry::PatternLanguage::impl::getVisualizers(); @@ -169,7 +169,7 @@ namespace hex::plugin::builtin::ui { ImGui::TextUnformatted(this->m_lastVisualizerError.c_str()); } - void PatternDrawer::drawVisualizerButton(pl::ptrn::Pattern& pattern, pl::ptrn::Iteratable &iteratable) { + void PatternDrawer::drawVisualizerButton(pl::ptrn::Pattern& pattern, pl::ptrn::IIterable &iteratable) { if (const auto &arguments = pattern.getAttributeArguments("hex::visualize"); !arguments.empty()) { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); if (ImGui::IconButton(ICON_VS_EYE, ImGui::GetStyleColorVec4(ImGuiCol_Text), ImVec2(ImGui::GetTextLineHeightWithSpacing(), ImGui::GetTextLineHeight()))) { @@ -316,7 +316,7 @@ namespace hex::plugin::builtin::ui { drawSizeColumn(pattern); drawTypenameColumn(pattern, "bitfield"); - drawVisualizerButton(pattern, static_cast(pattern)); + drawVisualizerButton(pattern, static_cast(pattern)); ImGui::TextFormatted("{}", pattern.getFormattedValue()); } @@ -553,7 +553,7 @@ namespace hex::plugin::builtin::ui { ImGui::PopStyleVar(); } } else { - drawVisualizerButton(pattern, static_cast(pattern)); + drawVisualizerButton(pattern, static_cast(pattern)); ImGui::TextFormatted("{}", pattern.getFormattedValue()); } @@ -606,7 +606,7 @@ namespace hex::plugin::builtin::ui { ImGui::PopStyleVar(); } } else { - drawVisualizerButton(pattern, static_cast(pattern)); + drawVisualizerButton(pattern, static_cast(pattern)); ImGui::TextFormatted("{}", pattern.getFormattedValue()); } } @@ -666,7 +666,7 @@ namespace hex::plugin::builtin::ui { pattern.accept(*this); } - void PatternDrawer::drawArray(pl::ptrn::Pattern& pattern, pl::ptrn::Iteratable &iteratable, bool isInlined) { + void PatternDrawer::drawArray(pl::ptrn::Pattern& pattern, pl::ptrn::IIterable &iteratable, bool isInlined) { if (iteratable.getEntryCount() == 0) return;