diff --git a/plugins/builtin/include/content/views/view_hexeditor.hpp b/plugins/builtin/include/content/views/view_hexeditor.hpp index e8f51aca9..ba0b056f9 100644 --- a/plugins/builtin/include/content/views/view_hexeditor.hpp +++ b/plugins/builtin/include/content/views/view_hexeditor.hpp @@ -54,6 +54,7 @@ namespace hex::plugin::builtin { u8 m_highlightAlpha = 0x80; bool m_processingImportExport = false; + bool m_advancedDecodingEnabled = false; void drawSearchPopup(); void drawGotoPopup(); diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index e820623d7..9a740ecc0 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -177,7 +177,7 @@ namespace hex::plugin::builtin { return false; }); - ContentRegistry::Settings::add("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.advanced_decoding", 0, [](auto name, nlohmann::json &setting) { + ContentRegistry::Settings::add("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.advanced_decoding", 1, [](auto name, nlohmann::json &setting) { static bool advancedDecoding = static_cast(setting); if (ImGui::Checkbox(name.data(), &advancedDecoding)) { diff --git a/plugins/builtin/source/content/views/view_hexeditor.cpp b/plugins/builtin/source/content/views/view_hexeditor.cpp index c8536ca74..fadd32303 100644 --- a/plugins/builtin/source/content/views/view_hexeditor.cpp +++ b/plugins/builtin/source/content/views/view_hexeditor.cpp @@ -179,6 +179,8 @@ namespace hex::plugin::builtin { this->m_memoryEditor.DrawWindow(View::toWindowName("hex.builtin.view.hexeditor.name").c_str(), &this->getWindowOpenState(), this, dataSize, dataSize == 0 ? 0x00 : provider->getBaseAddress() + provider->getCurrentPageAddress()); if (dataSize != 0x00) { + this->m_memoryEditor.OptShowAdvancedDecoding = this->m_advancedDecodingEnabled && this->m_currEncodingFile.valid(); + if (ImGui::Begin(View::toWindowName("hex.builtin.view.hexeditor.name").c_str())) { if (ImGui::IsMouseReleased(ImGuiMouseButton_Right) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows)) @@ -421,7 +423,7 @@ namespace hex::plugin::builtin { } if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.load_encoding_file"_lang)) { - hex::openFileBrowser("hex.builtin.view.hexeditor.load_enconding_file"_lang, DialogMode::Open, { }, [this](auto path) { + hex::openFileBrowser("hex.builtin.view.hexeditor.load_enconding_file"_lang, DialogMode::Open, { { "Thingy Table File", "tbl" } }, [this](auto path) { this->m_currEncodingFile = EncodingFile(EncodingFile::Type::Thingy, path); }); } @@ -1133,7 +1135,7 @@ namespace hex::plugin::builtin { auto advancedDecoding = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.advanced_decoding"); if (advancedDecoding.is_number()) - this->m_memoryEditor.OptShowAdvancedDecoding = static_cast(advancedDecoding); + this->m_advancedDecodingEnabled = static_cast(advancedDecoding); } { diff --git a/plugins/libimhex/include/hex/helpers/encoding_file.hpp b/plugins/libimhex/include/hex/helpers/encoding_file.hpp index 2bfb23cef..af008cf68 100644 --- a/plugins/libimhex/include/hex/helpers/encoding_file.hpp +++ b/plugins/libimhex/include/hex/helpers/encoding_file.hpp @@ -28,9 +28,15 @@ namespace hex { [[nodiscard]] std::pair getEncodingFor(const std::vector &buffer) const; [[nodiscard]] size_t getLongestSequence() const { return this->m_longestSequence; } + bool valid() const { + return this->m_valid; + } + private: void parseThingyFile(std::ifstream &content); + bool m_valid = false; + std::map, std::string>> m_mapping; size_t m_longestSequence = 0; }; diff --git a/plugins/libimhex/source/helpers/encoding_file.cpp b/plugins/libimhex/source/helpers/encoding_file.cpp index 581cb936b..c77eb0339 100644 --- a/plugins/libimhex/source/helpers/encoding_file.cpp +++ b/plugins/libimhex/source/helpers/encoding_file.cpp @@ -13,6 +13,8 @@ namespace hex { case Type::Thingy: parseThingyFile(encodingFile); break; default: throw std::runtime_error("Invalid encoding file type"); } + + this->m_valid = true; } std::pair EncodingFile::getEncodingFor(const std::vector &buffer) const {