3333#include " IconsFontAwesome6.h"
3434#include " IconsPromptFont.h"
3535
36+ #include < limits>
3637#include < mutex>
3738
3839LOG_CHANNEL (FullscreenUI);
@@ -186,14 +187,11 @@ static constexpr std::string_view ACHIEVEMENTS_LOGIN_DIALOG_NAME = "##achievemen
186187static constexpr std::string_view COVER_DOWNLOADER_DIALOG_NAME = " ##cover_downloader" ;
187188
188189namespace {
189- struct ALIGN_TO_CACHE_LINE SettingsLocals
190+ struct SettingsLocals
190191{
191192 float settings_last_bg_alpha = 1 .0f ;
192193 SettingsPage settings_page = SettingsPage::Interface;
193194 std::unique_ptr<INISettingsInterface> game_settings_interface;
194- std::string game_settings_serial;
195- GameHash game_settings_hash = 0 ;
196- const GameDatabase::Entry* game_settings_db_entry;
197195 std::unique_ptr<GameList::Entry> game_settings_entry;
198196 std::vector<std::pair<std::string, bool >> game_list_directories_cache;
199197 GPUDevice::AdapterInfoList graphics_adapter_list_cache;
@@ -213,7 +211,7 @@ struct ALIGN_TO_CACHE_LINE SettingsLocals
213211
214212} // namespace
215213
216- static SettingsLocals s_settings_locals;
214+ ALIGN_TO_CACHE_LINE static SettingsLocals s_settings_locals;
217215
218216} // namespace FullscreenUI
219217
@@ -1564,10 +1562,7 @@ void FullscreenUI::ClearSettingsState()
15641562 s_settings_locals.input_binding_dialog .ClearState ();
15651563 std::memset (s_settings_locals.controller_macro_expanded , 0 , sizeof (s_settings_locals.controller_macro_expanded ));
15661564 s_settings_locals.game_list_directories_cache = {};
1567- s_settings_locals.game_settings_db_entry = nullptr ;
15681565 s_settings_locals.game_settings_entry .reset ();
1569- s_settings_locals.game_settings_hash = 0 ;
1570- s_settings_locals.game_settings_serial = {};
15711566 s_settings_locals.game_settings_interface .reset ();
15721567 s_settings_locals.game_settings_changed = false ;
15731568 s_settings_locals.game_patch_list = {};
@@ -1585,9 +1580,6 @@ void FullscreenUI::SwitchToSettings()
15851580{
15861581 s_settings_locals.game_settings_entry .reset ();
15871582 s_settings_locals.game_settings_interface .reset ();
1588- s_settings_locals.game_settings_serial = {};
1589- s_settings_locals.game_settings_hash = 0 ;
1590- s_settings_locals.game_settings_db_entry = nullptr ;
15911583 s_settings_locals.game_patch_list = {};
15921584 s_settings_locals.enabled_game_patch_cache = {};
15931585 s_settings_locals.game_cheats_list = {};
@@ -1609,54 +1601,33 @@ void FullscreenUI::SwitchToSettings()
16091601 s_settings_locals.settings_last_bg_alpha = GetBackgroundAlpha ();
16101602}
16111603
1612- void FullscreenUI::SwitchToGameSettingsForSerial (std::string_view serial, GameHash hash, SettingsPage page)
1613- {
1614- s_settings_locals.game_settings_serial = serial;
1615- s_settings_locals.game_settings_hash = hash;
1616- s_settings_locals.game_settings_entry .reset ();
1617- s_settings_locals.game_settings_db_entry = GameDatabase::GetEntryForSerial (serial);
1618- s_settings_locals.game_settings_interface =
1619- System::GetGameSettingsInterface (s_settings_locals.game_settings_db_entry , serial, true , false );
1620- PopulatePatchesAndCheatsList ();
1621- s_settings_locals.settings_page = page;
1622- SwitchToMainWindow (MainWindowType::Settings);
1623- }
1624-
16251604bool FullscreenUI::SwitchToGameSettings (SettingsPage page)
16261605{
1627- const std::string& serial = GPUThread::GetGameSerial ();
1628- if (serial.empty ())
1629- return false ;
1630-
1631- auto lock = GameList::GetLock ();
1632- const GameList::Entry* entry = GameList::GetEntryForPath (GPUThread::GetGamePath ());
1633- if (!entry)
1634- {
1635- SwitchToGameSettingsForSerial (serial, GPUThread::GetGameHash (), page);
1636- return true ;
1637- }
1638- else
1639- {
1640- SwitchToGameSettings (entry, page);
1641- return true ;
1642- }
1606+ return SwitchToGameSettingsForPath (GPUThread::GetGamePath ());
16431607}
16441608
16451609bool FullscreenUI::SwitchToGameSettingsForPath (const std::string& path, SettingsPage page)
16461610{
16471611 auto lock = GameList::GetLock ();
1648- const GameList::Entry* entry = GameList::GetEntryForPath (path);
1649- if (!entry)
1612+ const GameList::Entry* entry = !path.empty () ? GameList::GetEntryForPath (path) : nullptr ;
1613+ if (!entry || entry->serial .empty ())
1614+ {
1615+ ShowToast ({}, FSUI_STR (" Game properties is only available for scanned games." ));
16501616 return false ;
1617+ }
16511618
16521619 SwitchToGameSettings (entry, page);
16531620 return true ;
16541621}
16551622
16561623void FullscreenUI::SwitchToGameSettings (const GameList::Entry* entry, SettingsPage page)
16571624{
1658- SwitchToGameSettingsForSerial (entry->serial , entry->hash , page);
16591625 s_settings_locals.game_settings_entry = std::make_unique<GameList::Entry>(*entry);
1626+ s_settings_locals.game_settings_interface = System::GetGameSettingsInterface (
1627+ s_settings_locals.game_settings_entry ->dbentry , s_settings_locals.game_settings_entry ->serial , true , false );
1628+ PopulatePatchesAndCheatsList ();
1629+ s_settings_locals.settings_page = page;
1630+ SwitchToMainWindow (MainWindowType::Settings);
16601631}
16611632
16621633void FullscreenUI::PopulateGraphicsAdapterList ()
@@ -1683,10 +1654,10 @@ void FullscreenUI::PopulateGameListDirectoryCache(SettingsInterface* si)
16831654
16841655void FullscreenUI::PopulatePatchesAndCheatsList ()
16851656{
1686- s_settings_locals.game_patch_list = Cheats::GetCodeInfoList (s_settings_locals. game_settings_serial ,
1687- s_settings_locals.game_settings_hash , false , true , true );
1657+ s_settings_locals.game_patch_list = Cheats::GetCodeInfoList (
1658+ s_settings_locals. game_settings_entry -> serial , s_settings_locals.game_settings_entry -> hash , false , true , true );
16881659 s_settings_locals.game_cheats_list = Cheats::GetCodeInfoList (
1689- s_settings_locals.game_settings_serial , s_settings_locals.game_settings_hash , true ,
1660+ s_settings_locals.game_settings_entry -> serial , s_settings_locals.game_settings_entry -> hash , true ,
16901661 s_settings_locals.game_settings_interface ->GetBoolValue (" Cheats" , " LoadCheatsFromDatabase" , true ),
16911662 s_settings_locals.game_settings_interface ->GetBoolValue (" Cheats" , " SortList" , false ));
16921663 s_settings_locals.game_cheat_groups = Cheats::GetCodeListUniquePrefixes (s_settings_locals.game_cheats_list , true );
@@ -2064,11 +2035,12 @@ void FullscreenUI::DrawSummarySettingsPage(bool show_localized_titles)
20642035
20652036 MenuHeading (FSUI_VSTR (" Options" ));
20662037
2067- if (s_settings_locals.game_settings_db_entry && s_settings_locals.game_settings_db_entry ->disc_set )
2038+ DebugAssert (s_settings_locals.game_settings_entry );
2039+ if (s_settings_locals.game_settings_entry ->dbentry && s_settings_locals.game_settings_entry ->dbentry ->disc_set )
20682040 {
20692041 // only enable for first disc
2070- const bool is_first_disc = (s_settings_locals.game_settings_db_entry ->serial ==
2071- s_settings_locals.game_settings_db_entry ->disc_set ->serials .front ());
2042+ const bool is_first_disc = (s_settings_locals.game_settings_entry -> dbentry ->serial ==
2043+ s_settings_locals.game_settings_entry -> dbentry ->disc_set ->serials .front ());
20722044 DrawToggleSetting (
20732045 GetEditingSettingsInterface (), FSUI_ICONVSTR (ICON_FA_COMPACT_DISC, " Use Separate Disc Settings" ),
20742046 FSUI_VSTR (
@@ -5180,8 +5152,8 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats)
51805152 bsi->SetBoolValue (" Cheats" , " SortList" , true );
51815153 SetSettingsChanged (bsi);
51825154 s_settings_locals.game_cheats_list =
5183- Cheats::GetCodeInfoList (s_settings_locals.game_settings_serial , s_settings_locals. game_settings_hash , true ,
5184- load_database_cheats, sort_list);
5155+ Cheats::GetCodeInfoList (s_settings_locals.game_settings_entry -> serial ,
5156+ s_settings_locals. game_settings_entry -> hash , true , load_database_cheats, sort_list);
51855157 }
51865158
51875159 if (code_list.empty ())
0 commit comments