From ffb9a8b7ed191110116c8d952c5b1307d604886a Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 27 May 2022 20:46:16 +0200 Subject: [PATCH] feature: Added Invert option to data inspector --- .../content/views/view_data_inspector.hpp | 1 + .../source/content/views/view_data_inspector.cpp | 16 ++++++++++++++++ plugins/builtin/source/lang/de_DE.cpp | 1 + plugins/builtin/source/lang/en_US.cpp | 3 ++- plugins/builtin/source/lang/it_IT.cpp | 2 +- plugins/builtin/source/lang/ja_JP.cpp | 1 + plugins/builtin/source/lang/zh_CN.cpp | 1 + 7 files changed, 23 insertions(+), 2 deletions(-) diff --git a/plugins/builtin/include/content/views/view_data_inspector.hpp b/plugins/builtin/include/content/views/view_data_inspector.hpp index 8f43d296c..9638bfa83 100644 --- a/plugins/builtin/include/content/views/view_data_inspector.hpp +++ b/plugins/builtin/include/content/views/view_data_inspector.hpp @@ -29,6 +29,7 @@ namespace hex::plugin::builtin { std::endian m_endian = std::endian::native; ContentRegistry::DataInspector::NumberDisplayStyle m_numberDisplayStyle = ContentRegistry::DataInspector::NumberDisplayStyle::Decimal; + bool m_invert = false; u64 m_startAddress = 0; size_t m_validBytes = 0; diff --git a/plugins/builtin/source/content/views/view_data_inspector.cpp b/plugins/builtin/source/content/views/view_data_inspector.cpp index 7efc9c8c4..76e64e3c0 100644 --- a/plugins/builtin/source/content/views/view_data_inspector.cpp +++ b/plugins/builtin/source/content/views/view_data_inspector.cpp @@ -42,6 +42,11 @@ namespace hex::plugin::builtin { std::vector buffer(entry.requiredSize); provider->read(this->m_startAddress, buffer.data(), buffer.size()); + if (this->m_invert) { + for (auto &byte : buffer) + byte ^= 0xFF; + } + this->m_cachedData.push_back({ entry.unlocalizedName, entry.generatorFunction(buffer, this->m_endian, this->m_numberDisplayStyle), entry.editingFunction, false }); } } @@ -154,6 +159,17 @@ namespace hex::plugin::builtin { } } } + + { + int selection = this->m_invert ? 1 : 0; + std::array options = { "hex.builtin.common.no"_lang, "hex.builtin.common.yes"_lang }; + + if (ImGui::SliderInt("hex.builtin.view.data_inspector.invert"_lang, &selection, 0, options.size() - 1, options[selection], ImGuiSliderFlags_NoInput)) { + this->m_shouldInvalidate = true; + + this->m_invert = selection == 1; + } + } } else { std::string text = "hex.builtin.view.data_inspector.no_data"_lang; auto textSize = ImGui::CalcTextSize(text.c_str()); diff --git a/plugins/builtin/source/lang/de_DE.cpp b/plugins/builtin/source/lang/de_DE.cpp index 10c1da763..c611b0008 100644 --- a/plugins/builtin/source/lang/de_DE.cpp +++ b/plugins/builtin/source/lang/de_DE.cpp @@ -137,6 +137,7 @@ namespace hex::plugin::builtin { { "hex.builtin.view.data_inspector.table.name", "Name" }, { "hex.builtin.view.data_inspector.table.value", "Wert" }, { "hex.builtin.view.data_inspector.no_data", "Keine bytes angewählt"}, + { "hex.builtin.view.data_inspector.invert", "Invertieren" }, { "hex.builtin.view.data_processor.name", "Datenprozessor" }, { "hex.builtin.view.data_processor.help_text", "Rechtsklicken um neuen Knoten zu erstellen" }, diff --git a/plugins/builtin/source/lang/en_US.cpp b/plugins/builtin/source/lang/en_US.cpp index b13c75405..bc5d7b592 100644 --- a/plugins/builtin/source/lang/en_US.cpp +++ b/plugins/builtin/source/lang/en_US.cpp @@ -138,7 +138,8 @@ namespace hex::plugin::builtin { { "hex.builtin.view.data_inspector.name", "Data Inspector" }, { "hex.builtin.view.data_inspector.table.name", "Name" }, { "hex.builtin.view.data_inspector.table.value", "Value" }, - { "hex.builtin.view.data_inspector.no_data", "No bytes selected"}, + { "hex.builtin.view.data_inspector.no_data", "No bytes selected" }, + { "hex.builtin.view.data_inspector.invert", "Invert" }, { "hex.builtin.view.data_processor.name", "Data Processor" }, { "hex.builtin.view.data_processor.help_text", "Right click to add a new node" }, diff --git a/plugins/builtin/source/lang/it_IT.cpp b/plugins/builtin/source/lang/it_IT.cpp index 26b39083b..87e879236 100644 --- a/plugins/builtin/source/lang/it_IT.cpp +++ b/plugins/builtin/source/lang/it_IT.cpp @@ -139,7 +139,7 @@ namespace hex::plugin::builtin { { "hex.builtin.view.data_inspector.table.name", "Nome" }, { "hex.builtin.view.data_inspector.table.value", "Valore" }, { "hex.builtin.view.data_inspector.no_data", "Nessun byte selezionato"}, - + //{ "hex.builtin.view.data_inspector.invert", "Invert" }, { "hex.builtin.view.data_processor.name", "Processa Dati" }, //{ "hex.builtin.view.data_processor.help_text", "Right click to add a new node" }, diff --git a/plugins/builtin/source/lang/ja_JP.cpp b/plugins/builtin/source/lang/ja_JP.cpp index d07862534..207d74f28 100644 --- a/plugins/builtin/source/lang/ja_JP.cpp +++ b/plugins/builtin/source/lang/ja_JP.cpp @@ -139,6 +139,7 @@ namespace hex::plugin::builtin { { "hex.builtin.view.data_inspector.table.name", "名前" }, { "hex.builtin.view.data_inspector.table.value", "値" }, { "hex.builtin.view.data_inspector.no_data", "範囲が選択されていません"}, + //{ "hex.builtin.view.data_inspector.invert", "Invert" }, { "hex.builtin.view.data_processor.name", "データプロセッサ" }, //{ "hex.builtin.view.data_processor.help_text", "Right click to add a new node" }, diff --git a/plugins/builtin/source/lang/zh_CN.cpp b/plugins/builtin/source/lang/zh_CN.cpp index 2ac78a8d5..f128e1a3a 100644 --- a/plugins/builtin/source/lang/zh_CN.cpp +++ b/plugins/builtin/source/lang/zh_CN.cpp @@ -138,6 +138,7 @@ namespace hex::plugin::builtin { { "hex.builtin.view.data_inspector.table.name", "名称" }, { "hex.builtin.view.data_inspector.table.value", "值" }, { "hex.builtin.view.data_inspector.no_data", "没有选中字节"}, + //{ "hex.builtin.view.data_inspector.invert", "Invert" }, { "hex.builtin.view.data_processor.name", "数据处理器" }, { "hex.builtin.view.data_processor.help_text", "右键以添加新的节点" },