Cheats: Strip whitespace from code names

This commit is contained in:
Stenzek 2024-11-29 12:48:52 +10:00
parent c4d4a7a774
commit 208e6c4b35
No known key found for this signature in database
1 changed files with 45 additions and 13 deletions

View File

@ -1246,11 +1246,17 @@ void Cheats::ParseFile(CheatCodeList* dst_list, const std::string_view file_cont
continue;
}
const std::string_view name = StringUtil::StripWhitespace(linev.substr(1, linev.length() - 2));
if (name.empty())
{
WARNING_LOG("Empty cheat code name at line {}: {}", reader.GetCurrentLineNumber(), line);
continue;
}
if (!next_code_metadata.name.empty())
finish_code();
// new code.
const std::string_view name = linev.substr(1, linev.length() - 2);
next_code_metadata.name =
next_code_group.empty() ? std::string(name) : fmt::format("{}\\{}", next_code_group, name);
continue;
@ -1514,12 +1520,26 @@ bool Cheats::ImportPCSXFile(CodeInfoList* dst, const std::string_view file_conte
continue;
}
std::string_view name_part = StringUtil::StripWhitespace(linev.substr(1, linev.length() - 2));
if (!name_part.empty() && name_part.front() == '*')
name_part = name_part.substr(1);
if (name_part.empty())
{
if (!reader.LogError(error, stop_on_error, "Empty code name at line {}: {}", reader.GetCurrentLineNumber(),
line))
{
return false;
}
continue;
}
// new code.
if (!current_code.name.empty() && !finish_code())
return false;
current_code = CodeInfo();
current_code.name = (linev[1] == '*') ? linev.substr(2, linev.length() - 3) : linev.substr(1, linev.length() - 2);
current_code.name = name_part;
current_code.file_offset_start = static_cast<u32>(reader.GetCurrentLineOffset());
current_code.file_offset_end = current_code.file_offset_start;
current_code.file_offset_body_start = current_code.file_offset_start;
@ -1683,12 +1703,24 @@ bool Cheats::ImportEPSXeFile(CodeInfoList* dst, const std::string_view file_cont
continue;
}
const std::string_view name_part = StringUtil::StripWhitespace(linev.substr(1));
if (name_part.empty())
{
if (!reader.LogError(error, stop_on_error, "Empty code name at line {}: {}", reader.GetCurrentLineNumber(),
line))
{
return false;
}
continue;
}
if (!current_code.name.empty() && !finish_code())
return false;
// new code.
current_code = CodeInfo();
current_code.name = linev.substr(1);
current_code.name = name_part;
current_code.file_offset_start = static_cast<u32>(reader.GetCurrentOffset());
current_code.file_offset_end = current_code.file_offset_start;
current_code.file_offset_body_start = current_code.file_offset_start;