Cheats: Add 'Ignore' field to file format

Codes with Ignore set to true will not be listed/loaded.
pull/3364/head
Stenzek 3 weeks ago
parent 4236beabaf
commit 8132c51a12
No known key found for this signature in database

@ -1077,10 +1077,11 @@ bool Cheats::ExtractCodeInfo(CodeInfoList* dst, std::string_view file_data, bool
std::optional<std::string> legacy_group; std::optional<std::string> legacy_group;
std::optional<CodeType> legacy_type; std::optional<CodeType> legacy_type;
std::optional<CodeActivation> legacy_activation; std::optional<CodeActivation> legacy_activation;
bool ignore_this_code = false;
CheatFileReader reader(file_data); CheatFileReader reader(file_data);
const auto finish_code = [&dst, &file_data, &stop_on_error, &error, &current_code, &reader]() { const auto finish_code = [&dst, &file_data, &stop_on_error, &error, &current_code, &ignore_this_code, &reader]() {
if (current_code.file_offset_end > current_code.file_offset_body_start) if (current_code.file_offset_end > current_code.file_offset_body_start)
{ {
current_code.body = file_data.substr(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; return false;
} }
AppendCheatToList(dst, std::move(current_code)); if (!ignore_this_code)
AppendCheatToList(dst, std::move(current_code));
return true; return true;
}; };
@ -1167,6 +1170,7 @@ bool Cheats::ExtractCodeInfo(CodeInfoList* dst, std::string_view file_data, bool
// overwrite existing codes with the same name. // overwrite existing codes with the same name.
finish_code(); finish_code();
current_code = CodeInfo(); current_code = CodeInfo();
ignore_this_code = false;
} }
current_code.name = 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(), if (!reader.LogError(error, stop_on_error, "Unknown code type at line {}: {}", reader.GetCurrentLineNumber(),
line)) line))
{
return false; return false;
}
} }
} }
else if (key == "Activation") 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<bool>(value).value_or(false);
}
// ignore other keys when we're only grabbing info // ignore other keys when we're only grabbing info
continue; continue;
@ -1314,10 +1324,11 @@ void Cheats::ParseFile(CheatCodeList* dst_list, const std::string_view file_cont
std::string_view next_code_group; std::string_view next_code_group;
CheatCode::Metadata next_code_metadata; CheatCode::Metadata next_code_metadata;
bool next_code_ignored = false;
std::optional<size_t> code_body_start; std::optional<size_t> code_body_start;
const auto finish_code = [&dst_list, &file_contents, &reader, &next_code_group, &next_code_metadata, 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()) if (!code_body_start.has_value())
{ {
WARNING_LOG("Empty cheat body at line {}", reader.GetCurrentLineNumber()); 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_group = {};
next_code_metadata = CheatCode::Metadata(); next_code_metadata = CheatCode::Metadata();
code_body_start.reset(); code_body_start.reset();
if (std::exchange(next_code_ignored, false))
return;
// overwrite existing codes with the same name. // overwrite existing codes with the same name.
const auto iter = std::find_if(dst_list->begin(), dst_list->end(), [&code](const std::unique_ptr<CheatCode>& rhs) { const auto iter = std::find_if(dst_list->begin(), dst_list->end(), [&code](const std::unique_ptr<CheatCode>& rhs) {
@ -1492,6 +1505,10 @@ void Cheats::ParseFile(CheatCodeList* dst_list, const std::string_view file_cont
{ {
// ignored when loading // ignored when loading
} }
else if (key == "Ignore")
{
next_code_ignored = StringUtil::FromChars<bool>(value).value_or(false);
}
else else
{ {
WARNING_LOG("Unknown parameter {} at line {}", key, reader.GetCurrentLineNumber()); WARNING_LOG("Unknown parameter {} at line {}", key, reader.GetCurrentLineNumber());

Loading…
Cancel
Save