GameDatabase: Fix incorrect multitap key parsing

This commit is contained in:
Stenzek 2025-03-21 19:11:50 +10:00
parent de6a8fba51
commit 346f0f945d
No known key found for this signature in database

View File

@ -40,7 +40,7 @@ namespace GameDatabase {
enum : u32 enum : u32
{ {
GAME_DATABASE_CACHE_SIGNATURE = 0x45434C48, GAME_DATABASE_CACHE_SIGNATURE = 0x45434C48,
GAME_DATABASE_CACHE_VERSION = 21, GAME_DATABASE_CACHE_VERSION = 22,
}; };
static const Entry* GetEntryForId(std::string_view code); static const Entry* GetEntryForId(std::string_view code);
@ -1172,6 +1172,38 @@ bool GameDatabase::ParseYamlEntry(Entry* entry, const ryml::ConstNodeRef& value)
{ {
GetStringFromObject(value, "name", &entry->title); GetStringFromObject(value, "name", &entry->title);
entry->supported_controllers = static_cast<u16>(~0u);
if (const ryml::ConstNodeRef controllers = value.find_child(to_csubstr("controllers"));
controllers.valid() && controllers.has_children())
{
bool first = true;
for (const ryml::ConstNodeRef& controller : controllers.cchildren())
{
const std::string_view controller_str = to_stringview(controller.val());
if (controller_str.empty())
{
WARNING_LOG("controller is not a string in {}", entry->serial);
return false;
}
const Controller::ControllerInfo* cinfo = Controller::GetControllerInfo(controller_str);
if (!cinfo)
{
WARNING_LOG("Invalid controller type {} in {}", controller_str, entry->serial);
continue;
}
if (first)
{
entry->supported_controllers = 0;
first = false;
}
entry->supported_controllers |= (1u << static_cast<u16>(cinfo->type));
}
}
if (const ryml::ConstNodeRef metadata = value.find_child(to_csubstr("metadata")); metadata.valid()) if (const ryml::ConstNodeRef metadata = value.find_child(to_csubstr("metadata")); metadata.valid())
{ {
GetStringFromObject(metadata, "genre", &entry->genre); GetStringFromObject(metadata, "genre", &entry->genre);
@ -1214,37 +1246,19 @@ bool GameDatabase::ParseYamlEntry(Entry* entry, const ryml::ConstNodeRef& value)
} }
} }
} }
}
entry->supported_controllers = static_cast<u16>(~0u); if (const ryml::ConstNodeRef& multitap = metadata.find_child(to_csubstr("multitap")); multitap.valid())
if (const ryml::ConstNodeRef controllers = value.find_child(to_csubstr("controllers"));
controllers.valid() && controllers.has_children())
{
bool first = true;
for (const ryml::ConstNodeRef& controller : controllers.cchildren())
{ {
const std::string_view controller_str = to_stringview(controller.val()); if (const std::optional multitap_val = StringUtil::FromChars<bool>(to_stringview(multitap.val()));
if (controller_str.empty()) multitap_val.has_value())
{ {
WARNING_LOG("controller is not a string in {}", entry->serial); if (multitap_val.value())
return false; entry->supported_controllers |= Entry::SUPPORTS_MULTITAP_BIT;
} }
else
const Controller::ControllerInfo* cinfo = Controller::GetControllerInfo(controller_str);
if (!cinfo)
{ {
WARNING_LOG("Invalid controller type {} in {}", controller_str, entry->serial); WARNING_LOG("Invalid multitap value in {}", entry->serial);
continue;
} }
if (first)
{
entry->supported_controllers = 0;
first = false;
}
entry->supported_controllers |= (1u << static_cast<u16>(cinfo->type));
} }
} }
@ -1310,20 +1324,6 @@ bool GameDatabase::ParseYamlEntry(Entry* entry, const ryml::ConstNodeRef& value)
} }
} }
if (const ryml::ConstNodeRef& multitap = value.find_child(to_csubstr("multitap")); multitap.valid())
{
if (const std::optional multitap_val = StringUtil::FromChars<bool>(to_stringview(multitap.val()));
multitap_val.has_value())
{
if (multitap_val.value())
entry->supported_controllers |= Entry::SUPPORTS_MULTITAP_BIT;
}
else
{
WARNING_LOG("Invalid multitap value in {}", entry->serial);
}
}
if (const ryml::ConstNodeRef settings = value.find_child(to_csubstr("settings")); if (const ryml::ConstNodeRef settings = value.find_child(to_csubstr("settings"));
settings.valid() && settings.has_children()) settings.valid() && settings.has_children())
{ {