13 static bool show_export_dialog =
false;
14 static int patch_format = 0;
15 static char filename[256] =
"my_hack";
18 if (ImGui::MenuItem(
"Export Patch...",
nullptr,
nullptr, rom->
is_loaded())) {
19 show_export_dialog =
true;
23 if (show_export_dialog) {
24 ImGui::OpenPopup(
"Export Patch");
27 if (ImGui::BeginPopupModal(
"Export Patch", &show_export_dialog)) {
29 const auto& original_data = rom->original_data();
30 const auto& modified_data = rom->
data();
34 original_data, modified_data);
36 ImGui::Text(
"Patch Summary:");
38 ImGui::Text(
"Total changed bytes: %zu", patch_info.changed_bytes);
39 ImGui::Text(
"Number of regions: %zu", patch_info.num_regions);
41 if (patch_info.changed_bytes == 0) {
42 ImGui::TextColored(ImVec4(1, 1, 0, 1),
"No changes detected!");
46 if (!patch_info.changed_regions.empty()) {
48 ImGui::Text(
"Changed Regions:");
50 for (
const auto& region : patch_info.changed_regions) {
51 if (region_count >= 10) {
52 ImGui::Text(
"... and %zu more regions",
53 patch_info.changed_regions.size() - 10);
56 ImGui::Text(
" Offset: 0x%06X, Size: %zu bytes",
57 static_cast<unsigned>(region.first), region.second);
65 ImGui::Text(
"Patch Format:");
66 ImGui::RadioButton(
"BPS (Beat)", &patch_format, 0);
68 ImGui::RadioButton(
"IPS", &patch_format, 1);
71 ImGui::Text(
"Filename:");
72 ImGui::InputText(
"##filename", filename,
sizeof(filename));
76 if (ImGui::Button(
"Export", ImVec2(120, 0))) {
77 if (patch_info.changed_bytes > 0) {
79 std::string full_filename = std::string(filename);
81 if (patch_format == 0) {
83 if (full_filename.find(
".bps") == std::string::npos) {
84 full_filename +=
".bps";
87 original_data, modified_data, full_filename);
90 if (full_filename.find(
".ips") == std::string::npos) {
91 full_filename +=
".ips";
94 original_data, modified_data, full_filename);
98 ImGui::CloseCurrentPopup();
99 show_export_dialog =
false;
103 ImGui::OpenPopup(
"Export Error");
109 if (ImGui::Button(
"Cancel", ImVec2(120, 0))) {
110 ImGui::CloseCurrentPopup();
111 show_export_dialog =
false;
115 if (ImGui::BeginPopupModal(
"Export Error")) {
116 ImGui::Text(
"Failed to export patch!");
117 if (ImGui::Button(
"OK", ImVec2(120, 0))) {
118 ImGui::CloseCurrentPopup();
132 const auto& original = rom->original_data();
133 const auto& modified = rom->
data();
136 std::string filename = rom->
filename();
137 size_t dot_pos = filename.find_last_of(
'.');
138 if (dot_pos != std::string::npos) {
139 filename = filename.substr(0, dot_pos);
144 original, modified, filename);
156 const auto& original = rom->original_data();
157 const auto& modified = rom->
data();
160 if (modified.size() > 0xFFFFFF) {
165 std::string filename = rom->
filename();
166 size_t dot_pos = filename.find_last_of(
'.');
167 if (dot_pos != std::string::npos) {
168 filename = filename.substr(0, dot_pos);
173 original, modified, filename);