diff --git a/Utilities/cheat_info.cpp b/Utilities/cheat_info.cpp index cc8934f15a..7745d26732 100644 --- a/Utilities/cheat_info.cpp +++ b/Utilities/cheat_info.cpp @@ -34,7 +34,7 @@ bool cheat_info::from_str(std::string_view cheat_line) s64 val64 = 0; if (cheat_vec.size() != 5 || !try_to_int64(&val64, cheat_vec[2], 0, cheat_type_max - 1)) { - log_cheat.fatal("Failed to parse cheat line"); + log_cheat.error("Failed to parse cheat line: '%s'", cheat_line); return false; } diff --git a/rpcs3/rpcs3qt/cheat_manager.cpp b/rpcs3/rpcs3qt/cheat_manager.cpp index a24a2cd5fc..fa8d0b4d58 100644 --- a/rpcs3/rpcs3qt/cheat_manager.cpp +++ b/rpcs3/rpcs3qt/cheat_manager.cpp @@ -129,16 +129,27 @@ void cheat_engine::save() const cheat_file.write(out.c_str(), out.size()); } -void cheat_engine::import_cheats_from_str(std::string_view str_cheats) +bool cheat_engine::import_cheats_from_str(std::string_view str_cheats) { const auto cheats_vec = fmt::split_sv(str_cheats, {"^^^"}); + std::vector valid_cheats; + for (const auto& cheat_line : cheats_vec) { cheat_info new_cheat; - if (new_cheat.from_str(cheat_line)) - cheats[new_cheat.game][new_cheat.offset] = new_cheat; + if (!new_cheat.from_str(cheat_line)) + return false; + + valid_cheats.push_back(std::move(new_cheat)); } + + for (const cheat_info& new_cheat : valid_cheats) + { + cheats[new_cheat.game][new_cheat.offset] = new_cheat; + } + + return true; } std::string cheat_engine::export_cheats_to_str() const @@ -677,7 +688,7 @@ cheat_manager_dialog::cheat_manager_dialog(QWidget* parent) { const int row = sel->row(); - if (rows.count(row)) + if (rows.contains(row)) continue; g_cheat.erase(tbl_cheats->item(row, cheat_table_columns::title)->text().toStdString(), tbl_cheats->item(row, cheat_table_columns::offset)->data(Qt::UserRole).toUInt()); @@ -690,7 +701,11 @@ cheat_manager_dialog::cheat_manager_dialog(QWidget* parent) connect(import_cheats, &QAction::triggered, [this]() { QClipboard* clipboard = QGuiApplication::clipboard(); - g_cheat.import_cheats_from_str(clipboard->text().toStdString()); + if (!g_cheat.import_cheats_from_str(clipboard->text().toStdString())) + { + QMessageBox::warning(this, tr("Failure"), tr("Failed to import cheats.")); + return; + } update_cheat_list(); }); diff --git a/rpcs3/rpcs3qt/cheat_manager.h b/rpcs3/rpcs3qt/cheat_manager.h index b915faa8a2..c09f47428f 100644 --- a/rpcs3/rpcs3qt/cheat_manager.h +++ b/rpcs3/rpcs3qt/cheat_manager.h @@ -25,7 +25,7 @@ public: cheat_info* get(const std::string& game, const u32 offset); bool erase(const std::string& game, const u32 offset); - void import_cheats_from_str(std::string_view str_cheats); + bool import_cheats_from_str(std::string_view str_cheats); std::string export_cheats_to_str() const; void save() const;