feat: Added support for changing the page size

This commit is contained in:
WerWolv
2023-05-23 11:34:30 +02:00
parent 28778eaf8c
commit 0e3da22c76
7 changed files with 84 additions and 14 deletions

View File

@@ -759,6 +759,7 @@
"hex.builtin.view.hex_editor.menu.edit.resize": "Resize...",
"hex.builtin.view.hex_editor.menu.edit.select_all": "Select all",
"hex.builtin.view.hex_editor.menu.edit.set_base": "Set base address",
"hex.builtin.view.hex_editor.menu.edit.set_page_size": "Set page size",
"hex.builtin.view.hex_editor.menu.file.goto": "Goto",
"hex.builtin.view.hex_editor.menu.file.load_encoding_file": "Load custom encoding...",
"hex.builtin.view.hex_editor.menu.file.save": "Save",

View File

@@ -186,7 +186,7 @@ namespace hex::plugin::builtin {
if (overlays) {
for (u64 i = 0; i < size; i++)
if (getPatches().contains(offset + i))
reinterpret_cast<u8 *>(buffer)[i] = getPatches()[offset + PageSize * this->m_currPage + i];
reinterpret_cast<u8 *>(buffer)[i] = getPatches()[offset + this->getPageSize() * this->m_currPage + i];
this->applyOverlays(offset, buffer, size);
}

View File

@@ -341,7 +341,7 @@ namespace hex::plugin::builtin {
ImGui::TextUnformatted("hex.builtin.view.hex_editor.menu.edit.set_base"_lang);
ImGui::InputHexadecimal("##base_address", &this->m_baseAddress);
if (ImGui::IsItemFocused() && (ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_Enter))) {
if (ImGui::IsItemFocused() && (ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_KeypadEnter))) {
setBaseAddress(this->m_baseAddress);
editor->closePopup();
}
@@ -353,7 +353,8 @@ namespace hex::plugin::builtin {
},
[&]{
editor->closePopup();
});
}
);
}
private:
@@ -366,6 +367,44 @@ namespace hex::plugin::builtin {
u64 m_baseAddress;
};
class PopupPageSize : public ViewHexEditor::Popup {
public:
explicit PopupPageSize(u64 pageSize) : m_pageSize(pageSize) { }
void draw(ViewHexEditor *editor) override {
ImGui::TextUnformatted("hex.builtin.view.hex_editor.menu.edit.set_page_size"_lang);
ImGui::InputHexadecimal("##page_size", &this->m_pageSize);
if (ImGui::IsItemFocused() && (ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_KeypadEnter))) {
setPageSize(this->m_pageSize);
editor->closePopup();
}
View::confirmButtons("hex.builtin.common.set"_lang, "hex.builtin.common.cancel"_lang,
[&, this]{
setPageSize(this->m_pageSize);
editor->closePopup();
},
[&]{
editor->closePopup();
}
);
}
private:
static void setPageSize(u64 pageSize) {
if (ImHexApi::Provider::isValid()) {
auto provider = ImHexApi::Provider::get();
provider->setPageSize(pageSize);
provider->setCurrentPage(0);
}
}
private:
u64 m_pageSize;
};
class PopupResize : public ViewHexEditor::Popup {
public:
explicit PopupResize(u64 currSize) : m_size(currSize) {}
@@ -374,7 +413,7 @@ namespace hex::plugin::builtin {
ImGui::TextUnformatted("hex.builtin.view.hex_editor.menu.edit.resize"_lang);
ImGui::InputHexadecimal("##resize", &this->m_size);
if (ImGui::IsItemFocused() && (ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_Enter))) {
if (ImGui::IsItemFocused() && (ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_KeypadEnter))) {
resize(static_cast<size_t>(this->m_size));
editor->closePopup();
}
@@ -1151,7 +1190,14 @@ namespace hex::plugin::builtin {
}
},
[] { return ImHexApi::Provider::isValid() && ImHexApi::HexEditor::isSelectionValid() && ImHexApi::HexEditor::getSelection()->getSize() <= sizeof(u64); });
// Popups
/* Set Page Size */
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.edit", "hex.builtin.view.hex_editor.menu.edit.set_page_size" }, 1860, Shortcut::None,
[this] {
auto provider = ImHexApi::Provider::get();
this->openPopup<PopupPageSize>(provider->getPageSize());
},
[] { return ImHexApi::Provider::isValid() && ImHexApi::Provider::get()->isReadable(); });
ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.edit" }, 1900);

View File

@@ -693,7 +693,8 @@ namespace hex::plugin::builtin::ui {
// Page Address
ImGui::TableNextColumn();
{
ImGui::TextFormatted("{0}: 0x{1:08X} - 0x{2:08X} ({1} - {2})", "hex.builtin.hex_editor.region"_lang, this->m_provider->getCurrentPageAddress(), this->m_provider->getSize());
auto pageAddress = this->m_provider->getCurrentPageAddress();
ImGui::TextFormatted("{0}: 0x{1:08X} - 0x{2:08X} ({1} - {2})", "hex.builtin.hex_editor.region"_lang, pageAddress, pageAddress + this->m_provider->getSize() - 1);
}
ImGui::TableNextRow();