From 0d02af3cf048f747405937fdf749ff397d0bf261 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 12 Jan 2022 12:51:29 +0100 Subject: [PATCH] patterns: Fixed arrays overriding the color of all its entries --- .../include/hex/pattern_language/ast_node.hpp | 1 - .../include/hex/pattern_language/pattern_data.hpp | 13 +++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/libimhex/include/hex/pattern_language/ast_node.hpp b/plugins/libimhex/include/hex/pattern_language/ast_node.hpp index 78f025841..504250a76 100644 --- a/plugins/libimhex/include/hex/pattern_language/ast_node.hpp +++ b/plugins/libimhex/include/hex/pattern_language/ast_node.hpp @@ -966,7 +966,6 @@ namespace hex::pl { auto addEntry = [&](PatternData *pattern) { pattern->setVariableName(hex::format("[{}]", entryIndex)); pattern->setEndian(arrayPattern->getEndian()); - pattern->setColor(arrayPattern->getColor()); entries.push_back(pattern); size += pattern->getSize(); diff --git a/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp b/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp index 884379f27..1bb2e308f 100644 --- a/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp +++ b/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp @@ -88,6 +88,7 @@ namespace hex::pl { return; this->m_color = Palette[SharedData::patternPaletteOffset++]; + this->m_manualColor = false; if (SharedData::patternPaletteOffset >= (sizeof(Palette) / sizeof(u32))) SharedData::patternPaletteOffset = 0; @@ -115,7 +116,8 @@ namespace hex::pl { void setTypeName(std::string name) { this->m_typeName = std::move(name); } [[nodiscard]] u32 getColor() const { return this->m_color; } - virtual void setColor(u32 color) { this->m_color = color; } + virtual void setColor(u32 color) { this->m_color = color; this->m_manualColor = true; } + [[nodiscard]] bool hasOverriddenColor() const { return this->m_manualColor; } [[nodiscard]] std::endian getEndian() const { return this->m_endian; } void setEndian(std::endian endian) { this->m_endian = endian; } @@ -314,6 +316,7 @@ namespace hex::pl { std::optional m_transformFunction; bool m_local = false; + bool m_manualColor = false; }; class PatternDataPadding : public PatternData { @@ -825,8 +828,10 @@ namespace hex::pl { void setEntries(const std::vector &entries) { this->m_entries = entries; - for (auto &entry : this->m_entries) { - entry->setColor(this->getColor()); + if (this->hasOverriddenColor()) { + for (auto &entry : this->m_entries) { + entry->setColor(this->getColor()); + } } } @@ -966,7 +971,7 @@ namespace hex::pl { this->m_template = templ; this->m_entryCount = count; - this->setColor(this->m_template->getColor()); + if (this->hasOverriddenColor()) this->setColor(this->m_template->getColor()); this->m_template->setEndian(templ->getEndian()); }