2020-11-29 01:06:41 +00:00
|
|
|
#include "views/view_patches.hpp"
|
|
|
|
|
2021-01-13 16:28:27 +00:00
|
|
|
#include <hex/providers/provider.hpp>
|
2020-11-29 01:06:41 +00:00
|
|
|
|
2021-01-13 16:28:27 +00:00
|
|
|
#include <hex/helpers/utils.hpp>
|
2020-11-29 23:03:12 +00:00
|
|
|
#include "helpers/project_file_handler.hpp"
|
2020-11-29 01:06:41 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace std::literals::string_literals;
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
2021-03-03 21:26:17 +00:00
|
|
|
ViewPatches::ViewPatches() : View("hex.view.patches.name") {
|
2021-03-27 10:36:36 +00:00
|
|
|
EventManager::subscribe<EventProjectFileStore>(this, []{
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 14:39:06 +00:00
|
|
|
if (provider != nullptr)
|
|
|
|
ProjectFile::setPatches(provider->getPatches());
|
2020-11-29 23:03:12 +00:00
|
|
|
});
|
|
|
|
|
2021-03-27 10:36:36 +00:00
|
|
|
EventManager::subscribe<EventProjectFileLoad>(this, []{
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 14:39:06 +00:00
|
|
|
if (provider != nullptr)
|
|
|
|
provider->getPatches() = ProjectFile::getPatches();
|
2020-11-29 23:03:12 +00:00
|
|
|
});
|
2020-11-29 01:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewPatches::~ViewPatches() {
|
2021-03-27 10:36:36 +00:00
|
|
|
EventManager::unsubscribe<EventProjectFileStore>(this);
|
|
|
|
EventManager::unsubscribe<EventProjectFileLoad>(this);
|
2020-11-29 01:06:41 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 17:10:01 +00:00
|
|
|
void ViewPatches::drawContent() {
|
2021-03-03 21:26:17 +00:00
|
|
|
if (ImGui::Begin(View::toWindowName("hex.view.patches.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-11-29 01:06:41 +00:00
|
|
|
|
2020-12-27 14:39:06 +00:00
|
|
|
if (provider != nullptr && provider->isReadable()) {
|
2020-11-29 01:06:41 +00:00
|
|
|
|
|
|
|
if (ImGui::BeginTable("##patchesTable", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable |
|
|
|
|
ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY)) {
|
|
|
|
ImGui::TableSetupScrollFreeze(0, 1);
|
2021-02-11 22:09:45 +00:00
|
|
|
ImGui::TableSetupColumn("hex.view.patches.offset"_lang);
|
|
|
|
ImGui::TableSetupColumn("hex.view.patches.orig"_lang);
|
|
|
|
ImGui::TableSetupColumn("hex.view.patches.patch"_lang);
|
2020-11-29 01:06:41 +00:00
|
|
|
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
2020-12-27 14:39:06 +00:00
|
|
|
auto& patches = provider->getPatches();
|
2020-11-29 01:06:41 +00:00
|
|
|
u32 index = 0;
|
|
|
|
for (const auto &[address, patch] : patches) {
|
|
|
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
if (ImGui::Selectable(("##patchLine" + std::to_string(index)).c_str(), false, ImGuiSelectableFlags_SpanAllColumns)) {
|
2021-03-27 10:36:36 +00:00
|
|
|
EventManager::post<RequestSelectionChange>(Region { address, 1 });
|
2020-11-29 01:06:41 +00:00
|
|
|
}
|
|
|
|
if (ImGui::IsMouseReleased(1) && ImGui::IsItemHovered()) {
|
|
|
|
ImGui::OpenPopup("PatchContextMenu");
|
|
|
|
this->m_selectedPatch = address;
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::Text("0x%08lX", address);
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
u8 previousValue = 0x00;
|
2020-12-27 14:39:06 +00:00
|
|
|
provider->readRaw(address, &previousValue, sizeof(u8));
|
2020-11-29 01:06:41 +00:00
|
|
|
ImGui::Text("0x%02X", previousValue);
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::Text("0x%02X", patch);
|
|
|
|
index += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::BeginPopup("PatchContextMenu")) {
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.patches.remove"_lang)) {
|
2020-11-29 01:06:41 +00:00
|
|
|
patches.erase(this->m_selectedPatch);
|
2020-11-29 23:03:12 +00:00
|
|
|
ProjectFile::markDirty();
|
2020-11-29 01:06:41 +00:00
|
|
|
}
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2020-12-22 17:10:01 +00:00
|
|
|
void ViewPatches::drawMenu() {
|
2020-11-29 01:06:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|