From a692adefd77a387c42895b955df99ceebc0ecb53 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 8 Jan 2021 18:36:12 +0100 Subject: [PATCH] Remove legacy patch support --- Utilities/bin_patch.cpp | 128 ++----------------------- Utilities/bin_patch.h | 7 +- rpcs3/rpcs3qt/patch_manager_dialog.cpp | 30 ++---- rpcs3/rpcs3qt/patch_manager_dialog.h | 2 - rpcs3/rpcs3qt/patch_manager_dialog.ui | 7 -- 5 files changed, 15 insertions(+), 159 deletions(-) diff --git a/Utilities/bin_patch.cpp b/Utilities/bin_patch.cpp index 41b7b66e66..c6a8ef068c 100644 --- a/Utilities/bin_patch.cpp +++ b/Utilities/bin_patch.cpp @@ -9,11 +9,6 @@ LOG_CHANNEL(patch_log, "PAT"); -namespace config_key -{ - static const std::string enable_legacy_patches = "Enable Legacy Patches"; -} - template <> void fmt_class_string::format(std::string& out, u64 arg) { @@ -128,16 +123,14 @@ bool patch_engine::load(patch_map& patches_map, const std::string& path, std::st } // Load patch config to determine which patches are enabled - bool enable_legacy_patches = false; patch_map patch_config; if (!importing) { - patch_config = load_config(enable_legacy_patches); + patch_config = load_config(); } std::string version; - bool is_legacy_patch = false; if (const auto version_node = root[patch_key::version]) { @@ -153,17 +146,12 @@ bool patch_engine::load(patch_map& patches_map, const std::string& path, std::st // We don't need the Version node in local memory anymore root.remove(patch_key::version); } - else if (importing) + else { append_log_message(log_messages, fmt::format("Error: No '%s' entry found. Patch engine version = %s (file: %s)", patch_key::version, patch_engine_version, path)); patch_log.error("No '%s' entry found. Patch engine version = %s (file: %s)", patch_key::version, patch_engine_version, path); return false; } - else - { - patch_log.warning("Patch engine version %s: Reading legacy patch file %s", patch_engine_version, path); - is_legacy_patch = true; - } bool is_valid = true; @@ -172,30 +160,6 @@ bool patch_engine::load(patch_map& patches_map, const std::string& path, std::st { const auto& main_key = pair.first.Scalar(); - // Use old logic and yaml layout if this is a legacy patch - if (is_legacy_patch) - { - struct patch_info info{}; - info.hash = main_key; - info.is_enabled = enable_legacy_patches; - info.is_legacy = true; - info.source_path = path; - - if (!read_patch_node(info, pair.second, root, log_messages)) - { - is_valid = false; - } - - // Find or create an entry matching the key/hash in our map - auto& container = patches_map[main_key]; - container.hash = main_key; - container.is_legacy = true; - container.patch_info_map["legacy"] = info; - continue; - } - - // Use new logic and yaml layout - if (const auto yml_type = pair.second.Type(); yml_type != YAML::NodeType::Map) { append_log_message(log_messages, fmt::format("Error: Skipping key %s: expected Map, found %s", main_key, yml_type)); @@ -212,7 +176,6 @@ bool patch_engine::load(patch_map& patches_map, const std::string& path, std::st // Find or create an entry matching the key/hash in our map auto& container = patches_map[main_key]; - container.is_legacy = false; container.hash = main_key; container.version = version; @@ -431,35 +394,6 @@ bool patch_engine::add_patch_data(YAML::Node node, patch_info& info, u32 modifie { // Special syntax: anchors (named sequence) - // Most legacy patches don't use the anchor syntax correctly, so try to sanitize it. - if (info.is_legacy) - { - if (const auto yml_type = addr_node.Type(); yml_type == YAML::NodeType::Scalar) - { - if (!root) - { - patch_log.fatal("Trying to parse legacy patch with invalid root."); // Sanity Check - return false; - } - - const auto anchor = addr_node.Scalar(); - const auto anchor_node = root[anchor]; - - if (anchor_node) - { - addr_node = anchor_node; - append_log_message(log_messages, fmt::format("Incorrect anchor syntax found in legacy patch: %s (key: %s)", anchor, info.hash)); - patch_log.warning("Incorrect anchor syntax found in legacy patch: %s (key: %s)", anchor, info.hash); - } - else - { - append_log_message(log_messages, fmt::format("Anchor not found in legacy patch: %s (key: %s)", anchor, info.hash)); - patch_log.error("Anchor not found in legacy patch: %s (key: %s)", anchor, info.hash); - return false; - } - } - } - // Check if the anchor was resolved. if (const auto yml_type = addr_node.Type(); yml_type != YAML::NodeType::Sequence) { @@ -553,10 +487,7 @@ bool patch_engine::read_patch_node(patch_info& info, YAML::Node node, const YAML void patch_engine::append_global_patches() { - // Legacy patch.yml - load(m_map, fs::get_config_dir() + "patch.yml"); - - // New patch.yml + // Regular patch.yml load(m_map, get_patches_path() + "patch.yml"); // Imported patch.yml @@ -570,10 +501,7 @@ void patch_engine::append_title_patches(const std::string& title_id) return; } - // Legacy patch.yml - load(m_map, fs::get_config_dir() + "data/" + title_id + "/patch.yml"); - - // New patch.yml + // Regular patch.yml load(m_map, get_patches_path() + title_id + "_patch.yml"); } @@ -694,7 +622,6 @@ usz patch_engine::apply_patch(const std::string& name, u8* dst, u32 filesz, u32 const auto app_version = Emu.GetAppVersion(); // Different containers in order to seperate the patches - std::vector legacy_patches; std::vector patches_for_this_serial_and_this_version; std::vector patches_for_this_serial_and_all_versions; std::vector patches_for_all_serials_and_this_version; @@ -703,17 +630,6 @@ usz patch_engine::apply_patch(const std::string& name, u8* dst, u32 filesz, u32 // Sort patches into different vectors based on their serial and version for (const auto& [description, patch] : container.patch_info_map) { - // Find out if this legacy patch is enabled - if (patch.is_legacy) - { - if (patch.is_enabled) - { - legacy_patches.push_back(patch); - } - - continue; - } - // Find out if this patch is enabled for (const auto& [title, serials] : patch.titles) { @@ -780,7 +696,6 @@ usz patch_engine::apply_patch(const std::string& name, u8* dst, u32 filesz, u32 // Sort specific patches in front of global patches std::vector sorted_patches; - sorted_patches.insert(sorted_patches.end(), legacy_patches.begin(), legacy_patches.end()); sorted_patches.insert(sorted_patches.end(), patches_for_this_serial_and_this_version.begin(), patches_for_this_serial_and_this_version.end()); sorted_patches.insert(sorted_patches.end(), patches_for_this_serial_and_all_versions.begin(), patches_for_this_serial_and_all_versions.end()); sorted_patches.insert(sorted_patches.end(), patches_for_all_serials_and_this_version.begin(), patches_for_all_serials_and_this_version.end()); @@ -802,20 +717,13 @@ usz patch_engine::apply_patch(const std::string& name, u8* dst, u32 filesz, u32 const usz applied = apply_modification(patch, dst, filesz, ls_addr); applied_total += applied; - if (patch.is_legacy) - { - patch_log.success("Applied legacy patch (hash='%s')(<- %d)", patch.hash, applied); - } - else - { - patch_log.success("Applied patch (hash='%s', description='%s', author='%s', patch_version='%s', file_version='%s') (<- %d)", patch.hash, patch.description, patch.author, patch.patch_version, patch.version, applied); - } + patch_log.success("Applied patch (hash='%s', description='%s', author='%s', patch_version='%s', file_version='%s') (<- %d)", patch.hash, patch.description, patch.author, patch.patch_version, patch.version, applied); } return applied_total; } -void patch_engine::save_config(const patch_map& patches_map, bool enable_legacy_patches) +void patch_engine::save_config(const patch_map& patches_map) { const std::string path = get_patch_config_path(); patch_log.notice("Saving patch config file %s", path); @@ -830,26 +738,13 @@ void patch_engine::save_config(const patch_map& patches_map, bool enable_legacy_ YAML::Emitter out; out << YAML::BeginMap; - // Save "Enable Legacy Patches" - out << config_key::enable_legacy_patches << enable_legacy_patches; - // Save 'enabled' state per hash, description, serial and app_version patch_map config_map; for (const auto& [hash, container] : patches_map) { - if (container.is_legacy) - { - continue; - } - for (const auto& [description, patch] : container.patch_info_map) { - if (patch.is_legacy) - { - continue; - } - for (const auto& [title, serials] : patch.titles) { for (const auto& [serial, app_versions] : serials) @@ -1092,10 +987,8 @@ bool patch_engine::remove_patch(const patch_info& info) return false; } -patch_engine::patch_map patch_engine::load_config(bool& enable_legacy_patches) +patch_engine::patch_map patch_engine::load_config() { - enable_legacy_patches = true; // Default to true - patch_map config_map; const std::string path = get_patch_config_path(); @@ -1111,13 +1004,6 @@ patch_engine::patch_map patch_engine::load_config(bool& enable_legacy_patches) return config_map; } - // Try to load "Enable Legacy Patches" (default to true) - if (auto enable_legacy_node = root[config_key::enable_legacy_patches]) - { - enable_legacy_patches = enable_legacy_node.as(true); - root.remove(config_key::enable_legacy_patches); // Remove the node in order to skip it in the next part - } - for (const auto pair : root) { const auto& hash = pair.first.Scalar(); diff --git a/Utilities/bin_patch.h b/Utilities/bin_patch.h index d7c2aa2abf..56e94e17d8 100644 --- a/Utilities/bin_patch.h +++ b/Utilities/bin_patch.h @@ -73,8 +73,6 @@ public: // Redundant information for accessibility (see patch_container) std::string hash; std::string version; - bool is_legacy = false; - bool is_enabled = false; // only for legacy patches }; struct patch_container @@ -82,7 +80,6 @@ public: std::unordered_map patch_info_map; std::string hash; std::string version; - bool is_legacy = false; }; using patch_map = std::unordered_map; @@ -111,7 +108,7 @@ public: static bool add_patch_data(YAML::Node node, patch_info& info, u32 modifier, const YAML::Node& root, std::stringstream* log_messages = nullptr); // Save to patch_config.yml - static void save_config(const patch_map& patches_map, bool enable_legacy_patches); + static void save_config(const patch_map& patches_map); // Save a patch file static bool save_patches(const patch_map& patches, const std::string& path, std::stringstream* log_messages = nullptr); @@ -123,7 +120,7 @@ public: static bool remove_patch(const patch_info& info); // Load patch_config.yml - static patch_map load_config(bool& enable_legacy_patches); + static patch_map load_config(); // Load from file and append to member patches map void append_global_patches(); diff --git a/rpcs3/rpcs3qt/patch_manager_dialog.cpp b/rpcs3/rpcs3qt/patch_manager_dialog.cpp index 446e95021e..2a24d45be8 100644 --- a/rpcs3/rpcs3qt/patch_manager_dialog.cpp +++ b/rpcs3/rpcs3qt/patch_manager_dialog.cpp @@ -62,14 +62,13 @@ patch_manager_dialog::patch_manager_dialog(std::shared_ptr gui_set setModal(true); // Load config for special settings - patch_engine::load_config(m_legacy_patches_enabled); + patch_engine::load_config(); // Load gui settings m_show_owned_games_only = m_gui_settings->GetValue(gui::pm_show_owned).toBool(); // Initialize gui controls ui->patch_filter->setText(QString::fromStdString(search_term)); - ui->cb_enable_legacy_patches->setChecked(m_legacy_patches_enabled); ui->cb_owned_games_only->setChecked(m_show_owned_games_only); ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)->setText(tr("Download latest patches")); @@ -81,7 +80,6 @@ patch_manager_dialog::patch_manager_dialog(std::shared_ptr gui_set connect(ui->patch_tree, &QTreeWidget::currentItemChanged, this, &patch_manager_dialog::handle_item_selected); connect(ui->patch_tree, &QTreeWidget::itemChanged, this, &patch_manager_dialog::handle_item_changed); connect(ui->patch_tree, &QTreeWidget::customContextMenuRequested, this, &patch_manager_dialog::handle_custom_context_menu_requested); - connect(ui->cb_enable_legacy_patches, &QCheckBox::stateChanged, this, &patch_manager_dialog::handle_legacy_patches_enabled); connect(ui->cb_owned_games_only, &QCheckBox::stateChanged, this, &patch_manager_dialog::handle_show_owned_games_only); connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QWidget::close); connect(ui->buttonBox, &QDialogButtonBox::clicked, [this](QAbstractButton* button) @@ -204,22 +202,11 @@ void patch_manager_dialog::populate_tree() for (const auto& [hash, container] : m_map) { - // Don't show legacy patches, because you can't configure them anyway - if (container.is_legacy) - { - continue; - } - const QString q_hash = QString::fromStdString(hash); // Add patch items for (const auto& [description, patch] : container.patch_info_map) { - if (patch.is_legacy) - { - continue; - } - const QString q_patch_group = QString::fromStdString(patch.patch_group); for (const auto& [title, serials] : patch.titles) @@ -374,7 +361,7 @@ void patch_manager_dialog::populate_tree() void patch_manager_dialog::save_config() { - patch_engine::save_config(m_map, m_legacy_patches_enabled); + patch_engine::save_config(m_map); } void patch_manager_dialog::filter_patches(const QString& term) @@ -475,7 +462,7 @@ void patch_manager_dialog::handle_item_selected(QTreeWidgetItem *current, QTreeW { const auto& container = m_map.at(hash); - if (!container.is_legacy && container.patch_info_map.find(description) != container.patch_info_map.end()) + if (container.patch_info_map.find(description) != container.patch_info_map.end()) { const auto& found_info = container.patch_info_map.at(description); info.author = QString::fromStdString(found_info.author); @@ -553,7 +540,7 @@ void patch_manager_dialog::handle_item_changed(QTreeWidgetItem *item, int /*colu { auto& container = m_map[hash]; - if (!container.is_legacy && container.patch_info_map.find(description) != container.patch_info_map.end()) + if (container.patch_info_map.find(description) != container.patch_info_map.end()) { m_map[hash].patch_info_map[description].titles[title][serial][app_version] = enabled; handle_item_selected(item, nullptr); @@ -585,9 +572,9 @@ void patch_manager_dialog::handle_custom_context_menu_requested(const QPoint &po { const auto& container = m_map.at(hash); - if (!container.is_legacy && container.patch_info_map.find(description) != container.patch_info_map.end()) + if (container.patch_info_map.find(description) != container.patch_info_map.end()) { - const auto info = container.patch_info_map.at(description); + const auto& info = container.patch_info_map.at(description); QAction* open_filepath = new QAction(tr("Show Patch File")); menu->addAction(open_filepath); @@ -798,11 +785,6 @@ void patch_manager_dialog::dropEvent(QDropEvent* event) } } -void patch_manager_dialog::handle_legacy_patches_enabled(int state) -{ - m_legacy_patches_enabled = state == Qt::CheckState::Checked; -} - void patch_manager_dialog::handle_show_owned_games_only(int state) { m_show_owned_games_only = state == Qt::CheckState::Checked; diff --git a/rpcs3/rpcs3qt/patch_manager_dialog.h b/rpcs3/rpcs3qt/patch_manager_dialog.h index 13a0bcb822..55af11199d 100644 --- a/rpcs3/rpcs3qt/patch_manager_dialog.h +++ b/rpcs3/rpcs3qt/patch_manager_dialog.h @@ -47,7 +47,6 @@ private Q_SLOTS: void handle_item_selected(QTreeWidgetItem *current, QTreeWidgetItem *previous); void handle_item_changed(QTreeWidgetItem *item, int column); void handle_custom_context_menu_requested(const QPoint& pos); - void handle_legacy_patches_enabled(int state); void handle_show_owned_games_only(int state); private: @@ -66,7 +65,6 @@ private: bool m_show_owned_games_only = false; patch_engine::patch_map m_map; - bool m_legacy_patches_enabled = false; downloader* m_downloader = nullptr; diff --git a/rpcs3/rpcs3qt/patch_manager_dialog.ui b/rpcs3/rpcs3qt/patch_manager_dialog.ui index ed170edd67..1eb8b75790 100644 --- a/rpcs3/rpcs3qt/patch_manager_dialog.ui +++ b/rpcs3/rpcs3qt/patch_manager_dialog.ui @@ -46,13 +46,6 @@ - - - - Enable Legacy Patches - - -