mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-04 05:51:19 +12:00
Track online-enable and network-service settings per-account instead of globally
This commit is contained in:
parent
065fb7eb58
commit
3f8722f0a6
8 changed files with 164 additions and 102 deletions
|
@ -131,7 +131,12 @@ uint32 ActiveSettings::GetPersistentId()
|
|||
|
||||
bool ActiveSettings::IsOnlineEnabled()
|
||||
{
|
||||
return GetConfig().account.online_enabled && Account::GetAccount(GetPersistentId()).IsValidOnlineAccount() && HasRequiredOnlineFiles();
|
||||
if(!Account::GetAccount(GetPersistentId()).IsValidOnlineAccount())
|
||||
return false;
|
||||
if(!HasRequiredOnlineFiles())
|
||||
return false;
|
||||
NetworkService networkService = static_cast<NetworkService>(GetConfig().GetAccountNetworkService(GetPersistentId()));
|
||||
return networkService == NetworkService::Nintendo || networkService == NetworkService::Pretendo || networkService == NetworkService::Custom;
|
||||
}
|
||||
|
||||
bool ActiveSettings::HasRequiredOnlineFiles()
|
||||
|
@ -139,8 +144,9 @@ bool ActiveSettings::HasRequiredOnlineFiles()
|
|||
return s_has_required_online_files;
|
||||
}
|
||||
|
||||
NetworkService ActiveSettings::GetNetworkService() {
|
||||
return static_cast<NetworkService>(GetConfig().account.active_service.GetValue());
|
||||
NetworkService ActiveSettings::GetNetworkService()
|
||||
{
|
||||
return GetConfig().GetAccountNetworkService(GetPersistentId());
|
||||
}
|
||||
|
||||
bool ActiveSettings::DumpShadersEnabled()
|
||||
|
|
|
@ -328,8 +328,22 @@ void CemuConfig::Load(XMLConfigParser& parser)
|
|||
// account
|
||||
auto acc = parser.get("Account");
|
||||
account.m_persistent_id = acc.get("PersistentId", account.m_persistent_id);
|
||||
account.online_enabled = acc.get("OnlineEnabled", account.online_enabled);
|
||||
account.active_service = acc.get("ActiveService",account.active_service);
|
||||
// legacy online settings, we only parse these for upgrading purposes
|
||||
account.legacy_online_enabled = acc.get("OnlineEnabled", account.legacy_online_enabled);
|
||||
account.legacy_active_service = acc.get("ActiveService",account.legacy_active_service);
|
||||
// per-account online setting
|
||||
auto accService = parser.get("AccountService");
|
||||
account.service_select.clear();
|
||||
for (auto element = accService.get("SelectedService"); element.valid(); element = accService.get("SelectedService", element))
|
||||
{
|
||||
uint32 persistentId = element.get_attribute<uint32>("PersistentId", 0);
|
||||
sint32 serviceIndex = element.get_attribute<sint32>("Service", 0);
|
||||
NetworkService networkService = static_cast<NetworkService>(serviceIndex);
|
||||
if (persistentId < Account::kMinPersistendId)
|
||||
continue;
|
||||
if(networkService == NetworkService::Offline || networkService == NetworkService::Nintendo || networkService == NetworkService::Pretendo || networkService == NetworkService::Custom)
|
||||
account.service_select.emplace(persistentId, networkService);
|
||||
}
|
||||
// debug
|
||||
auto debug = parser.get("Debug");
|
||||
#if BOOST_OS_WINDOWS
|
||||
|
@ -512,8 +526,17 @@ void CemuConfig::Save(XMLConfigParser& parser)
|
|||
// account
|
||||
auto acc = config.set("Account");
|
||||
acc.set("PersistentId", account.m_persistent_id.GetValue());
|
||||
acc.set("OnlineEnabled", account.online_enabled.GetValue());
|
||||
acc.set("ActiveService",account.active_service.GetValue());
|
||||
// legacy online mode setting
|
||||
acc.set("OnlineEnabled", account.legacy_online_enabled.GetValue());
|
||||
acc.set("ActiveService",account.legacy_active_service.GetValue());
|
||||
// per-account online setting
|
||||
auto accService = config.set("AccountService");
|
||||
for(auto& it : account.service_select)
|
||||
{
|
||||
auto entry = accService.set("SelectedService");
|
||||
entry.set_attribute("PersistentId", it.first);
|
||||
entry.set_attribute("Service", static_cast<sint32>(it.second));
|
||||
}
|
||||
// debug
|
||||
auto debug = config.set("Debug");
|
||||
#if BOOST_OS_WINDOWS
|
||||
|
@ -609,3 +632,30 @@ void CemuConfig::AddRecentNfcFile(std::string_view file)
|
|||
while (recent_nfc_files.size() > kMaxRecentEntries)
|
||||
recent_nfc_files.pop_back();
|
||||
}
|
||||
|
||||
NetworkService CemuConfig::GetAccountNetworkService(uint32 persistentId)
|
||||
{
|
||||
auto it = account.service_select.find(persistentId);
|
||||
if (it != account.service_select.end())
|
||||
{
|
||||
NetworkService serviceIndex = it->second;
|
||||
// make sure the returned service is valid
|
||||
if (serviceIndex != NetworkService::Offline &&
|
||||
serviceIndex != NetworkService::Nintendo &&
|
||||
serviceIndex != NetworkService::Pretendo &&
|
||||
serviceIndex != NetworkService::Custom)
|
||||
return NetworkService::Offline;
|
||||
if( static_cast<NetworkService>(serviceIndex) == NetworkService::Custom && !NetworkConfig::XMLExists() )
|
||||
return NetworkService::Offline; // custom is selected but no custom config exists
|
||||
return serviceIndex;
|
||||
}
|
||||
// if not found, return the legacy value
|
||||
if(!account.legacy_online_enabled)
|
||||
return NetworkService::Offline;
|
||||
return static_cast<NetworkService>(account.legacy_active_service.GetValue() + 1); // +1 because "Offline" now takes index 0
|
||||
}
|
||||
|
||||
void CemuConfig::SetAccountSelectedService(uint32 persistentId, NetworkService serviceIndex)
|
||||
{
|
||||
account.service_select[persistentId] = serviceIndex;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <wx/language.h>
|
||||
#include <wx/intl.h>
|
||||
|
||||
enum class NetworkService;
|
||||
|
||||
struct GameEntry
|
||||
{
|
||||
GameEntry() = default;
|
||||
|
@ -483,8 +485,9 @@ struct CemuConfig
|
|||
struct
|
||||
{
|
||||
ConfigValueBounds<uint32> m_persistent_id{ Account::kMinPersistendId, Account::kMinPersistendId, 0xFFFFFFFF };
|
||||
ConfigValue<bool> online_enabled{false};
|
||||
ConfigValue<int> active_service{0};
|
||||
ConfigValue<bool> legacy_online_enabled{false};
|
||||
ConfigValue<int> legacy_active_service{0};
|
||||
std::unordered_map<uint32, NetworkService> service_select; // per-account service index. Key is persistentId
|
||||
}account{};
|
||||
|
||||
// input
|
||||
|
@ -509,6 +512,9 @@ struct CemuConfig
|
|||
bool GetGameListCustomName(uint64 titleId, std::string& customName);
|
||||
void SetGameListCustomName(uint64 titleId, std::string customName);
|
||||
|
||||
NetworkService GetAccountNetworkService(uint32 persistentId);
|
||||
void SetAccountSelectedService(uint32 persistentId, NetworkService serviceIndex);
|
||||
|
||||
private:
|
||||
GameEntry* GetGameEntryByTitleId(uint64 titleId);
|
||||
GameEntry* CreateGameEntry(uint64 titleId);
|
||||
|
|
|
@ -34,14 +34,15 @@ void NetworkConfig::Load(XMLConfigParser& parser)
|
|||
|
||||
bool NetworkConfig::XMLExists()
|
||||
{
|
||||
static std::optional<bool> s_exists; // caches result of fs::exists
|
||||
if(s_exists.has_value())
|
||||
return *s_exists;
|
||||
std::error_code ec;
|
||||
if (!fs::exists(ActiveSettings::GetConfigPath("network_services.xml"), ec))
|
||||
{
|
||||
if (static_cast<NetworkService>(GetConfig().account.active_service.GetValue()) == NetworkService::Custom)
|
||||
{
|
||||
GetConfig().account.active_service = 0;
|
||||
}
|
||||
s_exists = false;
|
||||
return false;
|
||||
}
|
||||
s_exists = true;
|
||||
return true;
|
||||
}
|
|
@ -5,9 +5,11 @@
|
|||
|
||||
enum class NetworkService
|
||||
{
|
||||
Offline,
|
||||
Nintendo,
|
||||
Pretendo,
|
||||
Custom
|
||||
Custom,
|
||||
COUNT = Custom
|
||||
};
|
||||
|
||||
struct NetworkConfig
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue