Add a system region setting

Needed for games such as AC:NH.
The `Auto` option automatically selects a region based on the currently selected system language.

Co-Authored-By: Timotej Leginus <35149140+timleg002@users.noreply.github.com>
This commit is contained in:
lynxnb 2022-10-14 14:33:15 +02:00 committed by Billy Laws
parent d4800d13b8
commit 782f9e37ee
10 changed files with 114 additions and 18 deletions

View File

@ -34,6 +34,7 @@ namespace skyline {
isDocked = ktSettings.GetBool("isDocked");
usernameValue = std::move(ktSettings.GetString("usernameValue"));
systemLanguage = ktSettings.GetInt<skyline::language::SystemLanguage>("systemLanguage");
systemRegion = ktSettings.GetInt<skyline::region::RegionCode>("systemRegion");
forceTripleBuffering = ktSettings.GetBool("forceTripleBuffering");
disableFrameThrottling = ktSettings.GetBool("disableFrameThrottling");
gpuDriver = ktSettings.GetString("gpuDriver");

View File

@ -106,4 +106,53 @@ namespace skyline {
#undef LANGUAGES
}
namespace region {
/**
* @brief The list of all regions
* @url https://switchbrew.org/wiki/Settings_services#RegionCode_2
*/
enum class RegionCode : i32 {
Auto = -1, // Automatically determine region based on the selected language
Japan = 0,
Usa = 1,
Europe = 2,
Australia = 3,
HongKongTaiwanKorea = 4,
China = 5,
};
/**
* @brief Returns the region code for the given system language
*/
constexpr region::RegionCode GetRegionCodeForSystemLanguage(language::SystemLanguage systemLanguage) {
switch (systemLanguage) {
case language::SystemLanguage::Japanese:
return region::RegionCode::Japan;
case language::SystemLanguage::AmericanEnglish:
case language::SystemLanguage::CanadianFrench:
case language::SystemLanguage::LatinAmericanSpanish:
case language::SystemLanguage::BrazilianPortuguese:
return region::RegionCode::Usa;
case language::SystemLanguage::French:
case language::SystemLanguage::German:
case language::SystemLanguage::Italian:
case language::SystemLanguage::Spanish:
case language::SystemLanguage::Dutch:
case language::SystemLanguage::Portuguese:
case language::SystemLanguage::Russian:
case language::SystemLanguage::BritishEnglish:
return region::RegionCode::Europe;
case language::SystemLanguage::Chinese:
case language::SystemLanguage::SimplifiedChinese:
case language::SystemLanguage::TraditionalChinese:
return region::RegionCode::China;
case language::SystemLanguage::Taiwanese:
case language::SystemLanguage::Korean:
return region::RegionCode::HongKongTaiwanKorea;
default:
throw exception("Invalid system language: {}", systemLanguage);
}
}
}
}

View File

@ -62,6 +62,7 @@ namespace skyline {
Setting<bool> isDocked; //!< If the emulated Switch should be handheld or docked
Setting<std::string> usernameValue; //!< The user name to be supplied to the guest
Setting<language::SystemLanguage> systemLanguage; //!< The system language
Setting<region::RegionCode> systemRegion; //!< The system region
// Display
Setting<bool> forceTripleBuffering; //!< If the presentation engine should always triple buffer even if the swapchain supports double buffering

View File

@ -3,6 +3,7 @@
#include <common/language.h>
#include "ISettingsServer.h"
#include <common/settings.h>
namespace skyline::service::settings {
ISettingsServer::ISettingsServer(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager) {}
@ -23,4 +24,14 @@ namespace skyline::service::settings {
response.Push<i32>(constant::NewLanguageCodeListSize);
return {};
}
Result ISettingsServer::GetRegionCode(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
region::RegionCode regionCode{*state.settings->systemRegion};
if (regionCode == region::RegionCode::Auto)
regionCode = region::GetRegionCodeForSystemLanguage(*state.settings->systemLanguage);
response.Push(regionCode);
return {};
}
}

View File

@ -24,6 +24,11 @@ namespace skyline::service::settings {
*/
Result MakeLanguageCode(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
/**
* @brief Returns the user-selected region's code
*/
Result GetRegionCode(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
/**
* @brief Reads the available language codes that an application can use (post 4.0.0)
*/
@ -32,6 +37,7 @@ namespace skyline::service::settings {
SERVICE_DECL(
SFUNC(0x1, ISettingsServer, GetAvailableLanguageCodes),
SFUNC(0x2, ISettingsServer, MakeLanguageCode),
SFUNC(0x4, ISettingsServer, GetRegionCode),
SFUNC(0x5, ISettingsServer, GetAvailableLanguageCodes2)
)
};

View File

@ -16,6 +16,7 @@ class NativeSettings(context : Context, pref : PreferenceSettings) {
var isDocked : Boolean = pref.isDocked
var usernameValue : String = pref.usernameValue
var systemLanguage : Int = pref.systemLanguage
var systemRegion : Int = pref.systemRegion
// Display
var forceTripleBuffering : Boolean = pref.forceTripleBuffering

View File

@ -26,6 +26,7 @@ class PreferenceSettings @Inject constructor(@ApplicationContext private val con
var isDocked by sharedPreferences(context, true)
var usernameValue by sharedPreferences(context, context.getString(R.string.username_default))
var systemLanguage by sharedPreferences(context, 1)
var systemRegion by sharedPreferences(context, -1)
// Display
var forceTripleBuffering by sharedPreferences(context, true)

View File

@ -38,24 +38,42 @@
<item>臺語 (Taiwanese)</item>
</string-array>
<integer-array name="system_languages_val">
<item>1</item>
<item>12</item>
<item>2</item>
<item>13</item>
<item>3</item>
<item>5</item>
<item>14</item>
<item>4</item>
<item>8</item>
<item>9</item>
<item>17</item>
<item>10</item>
<item>0</item>
<item>6</item>
<item>16</item>
<item>15</item>
<item>7</item>
<item>11</item>
<item>1</item> <!-- American English -->
<item>12</item> <!-- British English -->
<item>2</item> <!-- French -->
<item>13</item> <!-- Canadian French -->
<item>3</item> <!-- German -->
<item>5</item> <!-- Spanish -->
<item>14</item> <!-- Latin American Spanish -->
<item>4</item> <!-- Italian -->
<item>8</item> <!-- Dutch -->
<item>9</item> <!-- Portuguese -->
<item>17</item> <!-- Brazilian Portuguese -->
<item>10</item> <!-- Russian -->
<item>0</item> <!-- Japanese -->
<item>6</item> <!-- Chinese -->
<item>16</item> <!-- Traditional Chinese -->
<item>15</item> <!-- Simplified Chinese -->
<item>7</item> <!-- Korean -->
<item>11</item> <!-- Taiwanese -->
</integer-array>
<string-array name="system_region">
<item>Auto</item>
<item>Japan</item>
<item>The Americas</item>
<item>Europe</item>
<item>Australia / New Zealand</item>
<item>Hong Kong / Taiwan / South Korea</item>
<item>China</item>
</string-array>
<integer-array name="system_region_val">
<item>-1</item> <!-- Auto -->
<item>0</item> <!-- Japan -->
<item>1</item> <!-- The Americas -->
<item>2</item> <!-- Europe -->
<item>3</item> <!-- Australia / New Zealand -->
<item>4</item> <!-- Hong Kong / Taiwan / South Korea -->
<item>5</item> <!-- China -->
</integer-array>
<string-array name="aspect_ratios">
<item>16:9 (Switch, Recommended)</item>

View File

@ -47,6 +47,7 @@
<string name="username">Username</string>
<string name="username_default">@string/app_name</string>
<string name="system_language">System language</string>
<string name="system_region">System region</string>
<!-- Settings - Keys -->
<string name="keys">Keys</string>
<string name="prod_keys">Production Keys</string>

View File

@ -78,6 +78,13 @@
app:refreshRequired="true"
app:title="@string/system_language"
app:useSimpleSummaryProvider="true" />
<emu.skyline.preference.IntegerListPreference
android:defaultValue="-1"
android:entries="@array/system_region"
android:entryValues="@array/system_region_val"
app:key="system_region"
app:title="@string/system_region"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory
android:key="category_presentation"