diff --git a/src/core/cheats.cpp b/src/core/cheats.cpp index 0caa0b04a..6f5078a6a 100644 --- a/src/core/cheats.cpp +++ b/src/core/cheats.cpp @@ -1077,10 +1077,11 @@ bool Cheats::ExtractCodeInfo(CodeInfoList* dst, std::string_view file_data, bool std::optional legacy_group; std::optional legacy_type; std::optional legacy_activation; + bool ignore_this_code = false; CheatFileReader reader(file_data); - const auto finish_code = [&dst, &file_data, &stop_on_error, &error, ¤t_code, &reader]() { + const auto finish_code = [&dst, &file_data, &stop_on_error, &error, ¤t_code, &ignore_this_code, &reader]() { if (current_code.file_offset_end > current_code.file_offset_body_start) { current_code.body = file_data.substr(current_code.file_offset_body_start, @@ -1092,7 +1093,9 @@ bool Cheats::ExtractCodeInfo(CodeInfoList* dst, std::string_view file_data, bool return false; } - AppendCheatToList(dst, std::move(current_code)); + if (!ignore_this_code) + AppendCheatToList(dst, std::move(current_code)); + return true; }; @@ -1167,6 +1170,7 @@ bool Cheats::ExtractCodeInfo(CodeInfoList* dst, std::string_view file_data, bool // overwrite existing codes with the same name. finish_code(); current_code = CodeInfo(); + ignore_this_code = false; } current_code.name = @@ -1223,7 +1227,9 @@ bool Cheats::ExtractCodeInfo(CodeInfoList* dst, std::string_view file_data, bool { if (!reader.LogError(error, stop_on_error, "Unknown code type at line {}: {}", reader.GetCurrentLineNumber(), line)) + { return false; + } } } else if (key == "Activation") @@ -1268,6 +1274,10 @@ bool Cheats::ExtractCodeInfo(CodeInfoList* dst, std::string_view file_data, bool } } } + else if (key == "Ignore") + { + ignore_this_code = StringUtil::FromChars(value).value_or(false); + } // ignore other keys when we're only grabbing info continue; @@ -1314,10 +1324,11 @@ void Cheats::ParseFile(CheatCodeList* dst_list, const std::string_view file_cont std::string_view next_code_group; CheatCode::Metadata next_code_metadata; + bool next_code_ignored = false; std::optional code_body_start; const auto finish_code = [&dst_list, &file_contents, &reader, &next_code_group, &next_code_metadata, - &code_body_start]() { + &next_code_ignored, &code_body_start]() { if (!code_body_start.has_value()) { WARNING_LOG("Empty cheat body at line {}", reader.GetCurrentLineNumber()); @@ -1349,6 +1360,8 @@ void Cheats::ParseFile(CheatCodeList* dst_list, const std::string_view file_cont next_code_group = {}; next_code_metadata = CheatCode::Metadata(); code_body_start.reset(); + if (std::exchange(next_code_ignored, false)) + return; // overwrite existing codes with the same name. const auto iter = std::find_if(dst_list->begin(), dst_list->end(), [&code](const std::unique_ptr& rhs) { @@ -1492,6 +1505,10 @@ void Cheats::ParseFile(CheatCodeList* dst_list, const std::string_view file_cont { // ignored when loading } + else if (key == "Ignore") + { + next_code_ignored = StringUtil::FromChars(value).value_or(false); + } else { WARNING_LOG("Unknown parameter {} at line {}", key, reader.GetCurrentLineNumber());