mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-25 15:15:40 +00:00
Cheats: Fix detection of ungrouped cheat import
This commit is contained in:
parent
f4e8470502
commit
9d5a84541f
|
@ -206,6 +206,15 @@ inline std::string ToChars(bool value, int base)
|
|||
std::optional<std::vector<u8>> DecodeHex(const std::string_view str);
|
||||
std::string EncodeHex(const u8* data, int length);
|
||||
|
||||
/// Returns true if the character is a hexadecimal digit.
|
||||
template<typename T>
|
||||
ALWAYS_INLINE static bool IsHexDigit(T ch)
|
||||
{
|
||||
return ((ch >= static_cast<T>('a') && ch <= static_cast<T>('a')) ||
|
||||
(ch >= static_cast<T>('A') && ch <= static_cast<T>('Z')) ||
|
||||
(ch >= static_cast<T>('0') && ch <= static_cast<T>('9')));
|
||||
}
|
||||
|
||||
/// StartsWith/EndsWith variants which aren't case sensitive.
|
||||
ALWAYS_INLINE static bool StartsWithNoCase(const std::string_view str, const std::string_view prefix)
|
||||
{
|
||||
|
|
|
@ -171,11 +171,6 @@ CheatList::CheatList() = default;
|
|||
|
||||
CheatList::~CheatList() = default;
|
||||
|
||||
static bool IsHexCharacter(char c)
|
||||
{
|
||||
return (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
static int SignedCharToInt(char ch)
|
||||
{
|
||||
return static_cast<int>(static_cast<unsigned char>(ch));
|
||||
|
@ -285,7 +280,7 @@ bool CheatList::LoadFromPCSXRString(const std::string& str)
|
|||
continue;
|
||||
}
|
||||
|
||||
while (!IsHexCharacter(*start) && start != end)
|
||||
while (!StringUtil::IsHexDigit(*start) && start != end)
|
||||
start++;
|
||||
if (start == end)
|
||||
continue;
|
||||
|
@ -296,7 +291,7 @@ bool CheatList::LoadFromPCSXRString(const std::string& str)
|
|||
inst.second = 0;
|
||||
if (end_ptr)
|
||||
{
|
||||
while (!IsHexCharacter(*end_ptr) && end_ptr != end)
|
||||
while (!StringUtil::IsHexDigit(*end_ptr) && end_ptr != end)
|
||||
end_ptr++;
|
||||
if (end_ptr != end)
|
||||
inst.second = static_cast<u32>(std::strtoul(end_ptr, nullptr, 16));
|
||||
|
@ -480,7 +475,7 @@ bool CheatList::LoadFromEPSXeString(const std::string& str)
|
|||
continue;
|
||||
}
|
||||
|
||||
while (!IsHexCharacter(*start) && start != end)
|
||||
while (!StringUtil::IsHexDigit(*start) && start != end)
|
||||
start++;
|
||||
if (start == end)
|
||||
continue;
|
||||
|
@ -491,7 +486,7 @@ bool CheatList::LoadFromEPSXeString(const std::string& str)
|
|||
inst.second = 0;
|
||||
if (end_ptr)
|
||||
{
|
||||
while (!IsHexCharacter(*end_ptr) && end_ptr != end)
|
||||
while (!StringUtil::IsHexDigit(*end_ptr) && end_ptr != end)
|
||||
end_ptr++;
|
||||
if (end_ptr != end)
|
||||
inst.second = static_cast<u32>(std::strtoul(end_ptr, nullptr, 16));
|
||||
|
@ -622,7 +617,7 @@ CheatList::Format CheatList::DetectFileFormat(const std::string& str)
|
|||
if (start[0] == '#' || start[0] == ';')
|
||||
continue;
|
||||
|
||||
if (std::strncmp(line.data(), "cheats", 6) == 0)
|
||||
if (line.starts_with("cheats"))
|
||||
return Format::Libretro;
|
||||
|
||||
// pcsxr if we see brackets
|
||||
|
@ -630,7 +625,7 @@ CheatList::Format CheatList::DetectFileFormat(const std::string& str)
|
|||
return Format::PCSXR;
|
||||
|
||||
// otherwise if it's a code, it's probably epsxe
|
||||
if (std::isdigit(start[0]))
|
||||
if (StringUtil::IsHexDigit(start[0]))
|
||||
return Format::EPSXe;
|
||||
}
|
||||
|
||||
|
@ -772,7 +767,7 @@ bool CheatList::LoadFromPackage(const std::string& serial)
|
|||
continue;
|
||||
}
|
||||
|
||||
while (!IsHexCharacter(*start) && start != end)
|
||||
while (!StringUtil::IsHexDigit(*start) && start != end)
|
||||
start++;
|
||||
if (start == end)
|
||||
continue;
|
||||
|
@ -783,7 +778,7 @@ bool CheatList::LoadFromPackage(const std::string& serial)
|
|||
inst.second = 0;
|
||||
if (end_ptr)
|
||||
{
|
||||
while (!IsHexCharacter(*end_ptr) && end_ptr != end)
|
||||
while (!StringUtil::IsHexDigit(*end_ptr) && end_ptr != end)
|
||||
end_ptr++;
|
||||
if (end_ptr != end)
|
||||
inst.second = static_cast<u32>(std::strtoul(end_ptr, nullptr, 16));
|
||||
|
@ -928,7 +923,7 @@ bool CheatCode::SetInstructionsFromString(const std::string& str)
|
|||
if (*start == '#' || *start == ';' || *start == '/' || *start == '\"')
|
||||
continue;
|
||||
|
||||
while (!IsHexCharacter(*start) && start != end)
|
||||
while (!StringUtil::IsHexDigit(*start) && start != end)
|
||||
start++;
|
||||
if (start == end)
|
||||
continue;
|
||||
|
@ -939,7 +934,7 @@ bool CheatCode::SetInstructionsFromString(const std::string& str)
|
|||
inst.second = 0;
|
||||
if (end_ptr)
|
||||
{
|
||||
while (!IsHexCharacter(*end_ptr) && end_ptr != end)
|
||||
while (!StringUtil::IsHexDigit(*end_ptr) && end_ptr != end)
|
||||
end_ptr++;
|
||||
if (end_ptr != end)
|
||||
inst.second = static_cast<u32>(std::strtoul(end_ptr, nullptr, 16));
|
||||
|
|
Loading…
Reference in a new issue