From e43db24b2c2302518207f922f8659415e3fbadb7 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 27 Jun 2020 10:32:00 +0200 Subject: [PATCH] patch_manager: add All override All can now be used as a key for title, serial and/or app version. If you check a patch for all ... then the patch will be applied regardless of what's checked for the game specifically, because we do not save 'Unchecked' patches. --- Utilities/bin_patch.cpp | 34 ++++++++++++++++++++------ Utilities/bin_patch.h | 18 ++++---------- rpcs3/rpcs3qt/patch_manager_dialog.cpp | 21 ++++++++++++---- rpcs3/rpcs3qt/patch_manager_dialog.h | 4 +++ 4 files changed, 52 insertions(+), 25 deletions(-) diff --git a/Utilities/bin_patch.cpp b/Utilities/bin_patch.cpp index 7ff4ab7766..16d317c0f3 100644 --- a/Utilities/bin_patch.cpp +++ b/Utilities/bin_patch.cpp @@ -563,15 +563,35 @@ std::size_t patch_engine::apply_patch(const std::string& name, u8* dst, u32 file for (const auto& [title, serials] : patch.titles) { - if (serials.find(serial) != serials.end()) + std::string found_serial; + + if (serials.find(patch_key::all) != serials.end()) { - if (const auto& app_versions = serials.at(serial); app_versions.find(app_version) != app_versions.end()) + found_serial = patch_key::all; + } + else if (serials.find(serial) != serials.end()) + { + found_serial = serial; + } + + if (!found_serial.empty()) + { + const auto& app_versions = serials.at(found_serial); + std::string found_app_version; + + if (app_versions.find(patch_key::all) != app_versions.end()) { - if (app_versions.at(app_version)) - { - enabled = true; - break; - } + found_app_version = patch_key::all; + } + else if (app_versions.find(app_version) != app_versions.end()) + { + found_app_version = app_version; + } + + if (!found_app_version.empty() && app_versions.at(found_app_version)) + { + enabled = true; + break; } } } diff --git a/Utilities/bin_patch.h b/Utilities/bin_patch.h index 0c13c0cd9f..42c6a6da77 100644 --- a/Utilities/bin_patch.h +++ b/Utilities/bin_patch.h @@ -7,6 +7,11 @@ #include "util/yaml.hpp" +namespace patch_key +{ + static const std::string all = "All"; +} + enum class patch_type { invalid, @@ -81,19 +86,6 @@ public: static std::string get_imported_patch_path(); // Load from file and append to specified patches map - // Example entry: - // - // PPU-8007056e52279bea26c15669d1ee08c2df321d00: - // Patches: - // 60fps: - // Game Title: Fancy Game - // Serials: ABCD12345, SUPA13337 v.1.3 - // Author: Batman bin Suparman - // Notes: This is super - // Patch Version: 1.3 - // Patch: - // - [ be32, 0x000e522c, 0x995d0072 ] - // - [ be32, 0x000e5234, 0x995d0074 ] static bool load(patch_map& patches, const std::string& path, bool importing = false, std::stringstream* log_messages = nullptr); // Read and add a patch node to the patch info diff --git a/rpcs3/rpcs3qt/patch_manager_dialog.cpp b/rpcs3/rpcs3qt/patch_manager_dialog.cpp index 6bb27cf301..ddef7651d2 100644 --- a/rpcs3/rpcs3qt/patch_manager_dialog.cpp +++ b/rpcs3/rpcs3qt/patch_manager_dialog.cpp @@ -194,7 +194,7 @@ void patch_manager_dialog::populate_tree() if (!title_level_item) { title_level_item = new QTreeWidgetItem(); - title_level_item->setText(0, q_title); + title_level_item->setText(0, title == patch_key::all ? tr_all_titles : q_title); title_level_item->setData(0, title_role, q_title); title_level_item->setData(0, node_level_role, node_level::title_level); title_level_item->setData(0, persistance_role, true); @@ -211,11 +211,13 @@ void patch_manager_dialog::populate_tree() } const QString q_serial = QString::fromStdString(serial); + const QString visible_serial = serial == patch_key::all ? tr_all_serials : q_serial; for (const auto& [app_version, enabled] : app_versions) { const QString q_app_version = QString::fromStdString(app_version); - const QString q_serial_and_version = q_serial + QStringLiteral(" v.") + q_app_version; + const QString q_version_suffix = app_version == patch_key::all ? (QStringLiteral(" - ") + tr_all_versions) : (QStringLiteral(" v.") + q_app_version); + const QString q_serial_and_version = visible_serial + q_version_suffix; // Find out if there is a node item for this serial QTreeWidgetItem* serial_level_item = gui::utils::find_child(title_level_item, q_serial_and_version); @@ -404,14 +406,23 @@ void patch_manager_dialog::on_item_selected(QTreeWidgetItem *current, QTreeWidge } case node_level::serial_level: { - info.serial = current->data(0, serial_role).toString(); - info.app_version = current->data(0, app_version_role).toString(); + const QString serial = current->data(0, serial_role).toString(); + info.serial = serial.toStdString() == patch_key::all ? tr_all_serials : serial; + + const QString app_version = current->data(0, app_version_role).toString(); + info.app_version = app_version.toStdString() == patch_key::all ? tr_all_versions : app_version; + [[fallthrough]]; } case node_level::title_level: + { + const QString title = current->data(0, title_role).toString(); + info.title = title.toStdString() == patch_key::all ? tr_all_titles : title; + + [[fallthrough]]; + } default: { - info.title = current->data(0, title_role).toString(); break; } } diff --git a/rpcs3/rpcs3qt/patch_manager_dialog.h b/rpcs3/rpcs3qt/patch_manager_dialog.h index 10265d8bb7..d56726b25e 100644 --- a/rpcs3/rpcs3qt/patch_manager_dialog.h +++ b/rpcs3/rpcs3qt/patch_manager_dialog.h @@ -30,6 +30,10 @@ class patch_manager_dialog : public QDialog QString patch_version; }; + const QString tr_all_titles = tr("All titles"); + const QString tr_all_serials = tr("All serials"); + const QString tr_all_versions = tr("All versions"); + public: explicit patch_manager_dialog(std::shared_ptr gui_settings, std::unordered_map> games, QWidget* parent = nullptr); ~patch_manager_dialog();