diff options
| -rw-r--r-- | src/citra/config.cpp | 3 | ||||
| -rw-r--r-- | src/citra/default_ini.h | 2 | ||||
| -rw-r--r-- | src/citra_qt/config.cpp | 3 | ||||
| -rw-r--r-- | src/citra_qt/configure_general.cpp | 6 | ||||
| -rw-r--r-- | src/citra_qt/configure_general.ui | 5 | ||||
| -rw-r--r-- | src/citra_qt/configure_system.ui | 3 | ||||
| -rw-r--r-- | src/core/hle/service/cfg/cfg.cpp | 57 | ||||
| -rw-r--r-- | src/core/hle/service/cfg/cfg.h | 7 | ||||
| -rw-r--r-- | src/core/loader/ncch.cpp | 22 | ||||
| -rw-r--r-- | src/core/loader/ncch.h | 3 | ||||
| -rw-r--r-- | src/core/settings.h | 4 |
11 files changed, 108 insertions, 7 deletions
diff --git a/src/citra/config.cpp b/src/citra/config.cpp index 29462c982..98f093258 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp | |||
| @@ -89,7 +89,8 @@ void Config::ReadValues() { | |||
| 89 | 89 | ||
| 90 | // System | 90 | // System |
| 91 | Settings::values.is_new_3ds = sdl2_config->GetBoolean("System", "is_new_3ds", false); | 91 | Settings::values.is_new_3ds = sdl2_config->GetBoolean("System", "is_new_3ds", false); |
| 92 | Settings::values.region_value = sdl2_config->GetInteger("System", "region_value", 1); | 92 | Settings::values.region_value = |
| 93 | sdl2_config->GetInteger("System", "region_value", Settings::REGION_VALUE_AUTO_SELECT); | ||
| 93 | 94 | ||
| 94 | // Miscellaneous | 95 | // Miscellaneous |
| 95 | Settings::values.log_filter = sdl2_config->Get("Miscellaneous", "log_filter", "*:Info"); | 96 | Settings::values.log_filter = sdl2_config->Get("Miscellaneous", "log_filter", "*:Info"); |
diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h index 001b18ac2..50c4a2812 100644 --- a/src/citra/default_ini.h +++ b/src/citra/default_ini.h | |||
| @@ -101,7 +101,7 @@ use_virtual_sd = | |||
| 101 | is_new_3ds = | 101 | is_new_3ds = |
| 102 | 102 | ||
| 103 | # The system region that Citra will use during emulation | 103 | # The system region that Citra will use during emulation |
| 104 | # 0: Japan, 1: USA (default), 2: Europe, 3: Australia, 4: China, 5: Korea, 6: Taiwan | 104 | # -1: Auto-select (default), 0: Japan, 1: USA, 2: Europe, 3: Australia, 4: China, 5: Korea, 6: Taiwan |
| 105 | region_value = | 105 | region_value = |
| 106 | 106 | ||
| 107 | [Miscellaneous] | 107 | [Miscellaneous] |
diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index 06a4e9d25..c904c4b00 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp | |||
| @@ -72,7 +72,8 @@ void Config::ReadValues() { | |||
| 72 | 72 | ||
| 73 | qt_config->beginGroup("System"); | 73 | qt_config->beginGroup("System"); |
| 74 | Settings::values.is_new_3ds = qt_config->value("is_new_3ds", false).toBool(); | 74 | Settings::values.is_new_3ds = qt_config->value("is_new_3ds", false).toBool(); |
| 75 | Settings::values.region_value = qt_config->value("region_value", 1).toInt(); | 75 | Settings::values.region_value = |
| 76 | qt_config->value("region_value", Settings::REGION_VALUE_AUTO_SELECT).toInt(); | ||
| 76 | qt_config->endGroup(); | 77 | qt_config->endGroup(); |
| 77 | 78 | ||
| 78 | qt_config->beginGroup("Miscellaneous"); | 79 | qt_config->beginGroup("Miscellaneous"); |
diff --git a/src/citra_qt/configure_general.cpp b/src/citra_qt/configure_general.cpp index 27139fb30..0b802d081 100644 --- a/src/citra_qt/configure_general.cpp +++ b/src/citra_qt/configure_general.cpp | |||
| @@ -23,13 +23,15 @@ void ConfigureGeneral::setConfiguration() { | |||
| 23 | ui->toggle_deepscan->setChecked(UISettings::values.gamedir_deepscan); | 23 | ui->toggle_deepscan->setChecked(UISettings::values.gamedir_deepscan); |
| 24 | ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing); | 24 | ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing); |
| 25 | ui->toggle_cpu_jit->setChecked(Settings::values.use_cpu_jit); | 25 | ui->toggle_cpu_jit->setChecked(Settings::values.use_cpu_jit); |
| 26 | ui->region_combobox->setCurrentIndex(Settings::values.region_value); | 26 | |
| 27 | // The first item is "auto-select" with actual value -1, so plus one here will do the trick | ||
| 28 | ui->region_combobox->setCurrentIndex(Settings::values.region_value + 1); | ||
| 27 | } | 29 | } |
| 28 | 30 | ||
| 29 | void ConfigureGeneral::applyConfiguration() { | 31 | void ConfigureGeneral::applyConfiguration() { |
| 30 | UISettings::values.gamedir_deepscan = ui->toggle_deepscan->isChecked(); | 32 | UISettings::values.gamedir_deepscan = ui->toggle_deepscan->isChecked(); |
| 31 | UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked(); | 33 | UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked(); |
| 32 | Settings::values.region_value = ui->region_combobox->currentIndex(); | 34 | Settings::values.region_value = ui->region_combobox->currentIndex() - 1; |
| 33 | Settings::values.use_cpu_jit = ui->toggle_cpu_jit->isChecked(); | 35 | Settings::values.use_cpu_jit = ui->toggle_cpu_jit->isChecked(); |
| 34 | Settings::Apply(); | 36 | Settings::Apply(); |
| 35 | } | 37 | } |
diff --git a/src/citra_qt/configure_general.ui b/src/citra_qt/configure_general.ui index 81688113f..342954e41 100644 --- a/src/citra_qt/configure_general.ui +++ b/src/citra_qt/configure_general.ui | |||
| @@ -84,6 +84,11 @@ | |||
| 84 | <widget class="QComboBox" name="region_combobox"> | 84 | <widget class="QComboBox" name="region_combobox"> |
| 85 | <item> | 85 | <item> |
| 86 | <property name="text"> | 86 | <property name="text"> |
| 87 | <string>Auto-select</string> | ||
| 88 | </property> | ||
| 89 | </item> | ||
| 90 | <item> | ||
| 91 | <property name="text"> | ||
| 87 | <string notr="true">JPN</string> | 92 | <string notr="true">JPN</string> |
| 88 | </property> | 93 | </property> |
| 89 | </item> | 94 | </item> |
diff --git a/src/citra_qt/configure_system.ui b/src/citra_qt/configure_system.ui index 6a906b61b..cc54fa37f 100644 --- a/src/citra_qt/configure_system.ui +++ b/src/citra_qt/configure_system.ui | |||
| @@ -129,6 +129,9 @@ | |||
| 129 | </item> | 129 | </item> |
| 130 | <item row="2" column="1"> | 130 | <item row="2" column="1"> |
| 131 | <widget class="QComboBox" name="combo_language"> | 131 | <widget class="QComboBox" name="combo_language"> |
| 132 | <property name="toolTip"> | ||
| 133 | <string>Note: this can be overridden when region setting is auto-select</string> | ||
| 134 | </property> | ||
| 132 | <item> | 135 | <item> |
| 133 | <property name="text"> | 136 | <property name="text"> |
| 134 | <string>Japanese (日本語)</string> | 137 | <string>Japanese (日本語)</string> |
diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index d554c3f54..5e340f4c8 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp | |||
| @@ -114,6 +114,8 @@ static const std::vector<u8> cfg_system_savedata_id = { | |||
| 114 | 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x01, 0x00, | 114 | 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x01, 0x00, |
| 115 | }; | 115 | }; |
| 116 | 116 | ||
| 117 | static u32 preferred_region_code = 0; | ||
| 118 | |||
| 117 | void GetCountryCodeString(Service::Interface* self) { | 119 | void GetCountryCodeString(Service::Interface* self) { |
| 118 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 120 | u32* cmd_buff = Kernel::GetCommandBuffer(); |
| 119 | u32 country_code_id = cmd_buff[1]; | 121 | u32 country_code_id = cmd_buff[1]; |
| @@ -159,11 +161,18 @@ void GetCountryCodeID(Service::Interface* self) { | |||
| 159 | cmd_buff[2] = country_code_id; | 161 | cmd_buff[2] = country_code_id; |
| 160 | } | 162 | } |
| 161 | 163 | ||
| 164 | static u32 GetRegionValue() { | ||
| 165 | if (Settings::values.region_value == Settings::REGION_VALUE_AUTO_SELECT) | ||
| 166 | return preferred_region_code; | ||
| 167 | |||
| 168 | return Settings::values.region_value; | ||
| 169 | } | ||
| 170 | |||
| 162 | void SecureInfoGetRegion(Service::Interface* self) { | 171 | void SecureInfoGetRegion(Service::Interface* self) { |
| 163 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 172 | u32* cmd_buff = Kernel::GetCommandBuffer(); |
| 164 | 173 | ||
| 165 | cmd_buff[1] = RESULT_SUCCESS.raw; | 174 | cmd_buff[1] = RESULT_SUCCESS.raw; |
| 166 | cmd_buff[2] = Settings::values.region_value; | 175 | cmd_buff[2] = GetRegionValue(); |
| 167 | } | 176 | } |
| 168 | 177 | ||
| 169 | void GenHashConsoleUnique(Service::Interface* self) { | 178 | void GenHashConsoleUnique(Service::Interface* self) { |
| @@ -183,7 +192,7 @@ void GetRegionCanadaUSA(Service::Interface* self) { | |||
| 183 | cmd_buff[1] = RESULT_SUCCESS.raw; | 192 | cmd_buff[1] = RESULT_SUCCESS.raw; |
| 184 | 193 | ||
| 185 | u8 canada_or_usa = 1; | 194 | u8 canada_or_usa = 1; |
| 186 | if (canada_or_usa == Settings::values.region_value) { | 195 | if (canada_or_usa == GetRegionValue()) { |
| 187 | cmd_buff[2] = 1; | 196 | cmd_buff[2] = 1; |
| 188 | } else { | 197 | } else { |
| 189 | cmd_buff[2] = 0; | 198 | cmd_buff[2] = 0; |
| @@ -313,10 +322,47 @@ static ResultVal<void*> GetConfigInfoBlockPointer(u32 block_id, u32 size, u32 fl | |||
| 313 | return MakeResult<void*>(pointer); | 322 | return MakeResult<void*>(pointer); |
| 314 | } | 323 | } |
| 315 | 324 | ||
| 325 | /// Checks if the language is available in the chosen region, and returns a proper one | ||
| 326 | static u8 AdjustLanguageInfoBlock(u32 region, u8 language) { | ||
| 327 | static const std::array<std::vector<u8>, 7> region_languages{{ | ||
| 328 | // JPN | ||
| 329 | {LANGUAGE_JP}, | ||
| 330 | // USA | ||
| 331 | {LANGUAGE_EN, LANGUAGE_FR, LANGUAGE_ES, LANGUAGE_PT}, | ||
| 332 | // EUR | ||
| 333 | {LANGUAGE_EN, LANGUAGE_FR, LANGUAGE_DE, LANGUAGE_IT, LANGUAGE_ES, LANGUAGE_NL, LANGUAGE_PT, | ||
| 334 | LANGUAGE_RU}, | ||
| 335 | // AUS | ||
| 336 | {LANGUAGE_EN, LANGUAGE_FR, LANGUAGE_DE, LANGUAGE_IT, LANGUAGE_ES, LANGUAGE_NL, LANGUAGE_PT, | ||
| 337 | LANGUAGE_RU}, | ||
| 338 | // CHN | ||
| 339 | {LANGUAGE_ZH}, | ||
| 340 | // KOR | ||
| 341 | {LANGUAGE_KO}, | ||
| 342 | // TWN | ||
| 343 | {LANGUAGE_TW}, | ||
| 344 | }}; | ||
| 345 | const auto& available = region_languages[region]; | ||
| 346 | if (std::find(available.begin(), available.end(), language) == available.end()) { | ||
| 347 | return available[0]; | ||
| 348 | } | ||
| 349 | return language; | ||
| 350 | } | ||
| 351 | |||
| 316 | ResultCode GetConfigInfoBlock(u32 block_id, u32 size, u32 flag, void* output) { | 352 | ResultCode GetConfigInfoBlock(u32 block_id, u32 size, u32 flag, void* output) { |
| 317 | void* pointer; | 353 | void* pointer; |
| 318 | CASCADE_RESULT(pointer, GetConfigInfoBlockPointer(block_id, size, flag)); | 354 | CASCADE_RESULT(pointer, GetConfigInfoBlockPointer(block_id, size, flag)); |
| 319 | memcpy(output, pointer, size); | 355 | memcpy(output, pointer, size); |
| 356 | |||
| 357 | // override the language setting if the region setting is auto | ||
| 358 | if (block_id == LanguageBlockID && | ||
| 359 | Settings::values.region_value == Settings::REGION_VALUE_AUTO_SELECT) { | ||
| 360 | u8 language; | ||
| 361 | memcpy(&language, output, sizeof(u8)); | ||
| 362 | language = AdjustLanguageInfoBlock(preferred_region_code, language); | ||
| 363 | memcpy(output, &language, sizeof(u8)); | ||
| 364 | } | ||
| 365 | |||
| 320 | return RESULT_SUCCESS; | 366 | return RESULT_SUCCESS; |
| 321 | } | 367 | } |
| 322 | 368 | ||
| @@ -533,10 +579,17 @@ void Init() { | |||
| 533 | AddService(new CFG_U_Interface); | 579 | AddService(new CFG_U_Interface); |
| 534 | 580 | ||
| 535 | LoadConfigNANDSaveFile(); | 581 | LoadConfigNANDSaveFile(); |
| 582 | |||
| 583 | preferred_region_code = 0; | ||
| 536 | } | 584 | } |
| 537 | 585 | ||
| 538 | void Shutdown() {} | 586 | void Shutdown() {} |
| 539 | 587 | ||
| 588 | void SetPreferredRegionCode(u32 region_code) { | ||
| 589 | preferred_region_code = region_code; | ||
| 590 | LOG_INFO(Service_CFG, "Preferred region code set to %u", preferred_region_code); | ||
| 591 | } | ||
| 592 | |||
| 540 | void SetUsername(const std::u16string& name) { | 593 | void SetUsername(const std::u16string& name) { |
| 541 | ASSERT(name.size() <= 10); | 594 | ASSERT(name.size() <= 10); |
| 542 | UsernameBlock block{}; | 595 | UsernameBlock block{}; |
diff --git a/src/core/hle/service/cfg/cfg.h b/src/core/hle/service/cfg/cfg.h index fb47c2aa5..618c9647e 100644 --- a/src/core/hle/service/cfg/cfg.h +++ b/src/core/hle/service/cfg/cfg.h | |||
| @@ -282,6 +282,13 @@ void Init(); | |||
| 282 | /// Shutdown the config service | 282 | /// Shutdown the config service |
| 283 | void Shutdown(); | 283 | void Shutdown(); |
| 284 | 284 | ||
| 285 | /** | ||
| 286 | * Set the region code preferred by the game so that CFG will adjust to it when the region setting | ||
| 287 | * is auto. | ||
| 288 | * @param region_code the preferred region code to set | ||
| 289 | */ | ||
| 290 | void SetPreferredRegionCode(u32 region_code); | ||
| 291 | |||
| 285 | // Utilities for frontend to set config data. | 292 | // Utilities for frontend to set config data. |
| 286 | // Note: before calling these functions, LoadConfigNANDSaveFile should be called, | 293 | // Note: before calling these functions, LoadConfigNANDSaveFile should be called, |
| 287 | // and UpdateConfigNANDSavegame should be called after making changes to config data. | 294 | // and UpdateConfigNANDSavegame should be called after making changes to config data. |
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index d4be61e0e..dce7f50f9 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp | |||
| @@ -11,8 +11,10 @@ | |||
| 11 | #include "core/file_sys/archive_romfs.h" | 11 | #include "core/file_sys/archive_romfs.h" |
| 12 | #include "core/hle/kernel/process.h" | 12 | #include "core/hle/kernel/process.h" |
| 13 | #include "core/hle/kernel/resource_limit.h" | 13 | #include "core/hle/kernel/resource_limit.h" |
| 14 | #include "core/hle/service/cfg/cfg.h" | ||
| 14 | #include "core/hle/service/fs/archive.h" | 15 | #include "core/hle/service/fs/archive.h" |
| 15 | #include "core/loader/ncch.h" | 16 | #include "core/loader/ncch.h" |
| 17 | #include "core/loader/smdh.h" | ||
| 16 | #include "core/memory.h" | 18 | #include "core/memory.h" |
| 17 | 19 | ||
| 18 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 20 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| @@ -309,6 +311,23 @@ ResultStatus AppLoader_NCCH::LoadExeFS() { | |||
| 309 | return ResultStatus::Success; | 311 | return ResultStatus::Success; |
| 310 | } | 312 | } |
| 311 | 313 | ||
| 314 | void AppLoader_NCCH::ParseRegionLockoutInfo() { | ||
| 315 | std::vector<u8> smdh_buffer; | ||
| 316 | if (ReadIcon(smdh_buffer) == ResultStatus::Success && smdh_buffer.size() >= sizeof(SMDH)) { | ||
| 317 | SMDH smdh; | ||
| 318 | memcpy(&smdh, smdh_buffer.data(), sizeof(SMDH)); | ||
| 319 | u32 region_lockout = smdh.region_lockout; | ||
| 320 | constexpr u32 REGION_COUNT = 7; | ||
| 321 | for (u32 region = 0; region < REGION_COUNT; ++region) { | ||
| 322 | if (region_lockout & 1) { | ||
| 323 | Service::CFG::SetPreferredRegionCode(region); | ||
| 324 | break; | ||
| 325 | } | ||
| 326 | region_lockout >>= 1; | ||
| 327 | } | ||
| 328 | } | ||
| 329 | } | ||
| 330 | |||
| 312 | ResultStatus AppLoader_NCCH::Load() { | 331 | ResultStatus AppLoader_NCCH::Load() { |
| 313 | if (is_loaded) | 332 | if (is_loaded) |
| 314 | return ResultStatus::ErrorAlreadyLoaded; | 333 | return ResultStatus::ErrorAlreadyLoaded; |
| @@ -325,6 +344,9 @@ ResultStatus AppLoader_NCCH::Load() { | |||
| 325 | 344 | ||
| 326 | Service::FS::RegisterArchiveType(std::make_unique<FileSys::ArchiveFactory_RomFS>(*this), | 345 | Service::FS::RegisterArchiveType(std::make_unique<FileSys::ArchiveFactory_RomFS>(*this), |
| 327 | Service::FS::ArchiveIdCode::RomFS); | 346 | Service::FS::ArchiveIdCode::RomFS); |
| 347 | |||
| 348 | ParseRegionLockoutInfo(); | ||
| 349 | |||
| 328 | return ResultStatus::Success; | 350 | return ResultStatus::Success; |
| 329 | } | 351 | } |
| 330 | 352 | ||
diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index bcf3ae6e3..e9e11727b 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h | |||
| @@ -250,6 +250,9 @@ private: | |||
| 250 | */ | 250 | */ |
| 251 | ResultStatus LoadExeFS(); | 251 | ResultStatus LoadExeFS(); |
| 252 | 252 | ||
| 253 | /// Reads the region lockout info in the SMDH and send it to CFG service | ||
| 254 | void ParseRegionLockoutInfo(); | ||
| 255 | |||
| 253 | bool is_exefs_loaded = false; | 256 | bool is_exefs_loaded = false; |
| 254 | bool is_compressed = false; | 257 | bool is_compressed = false; |
| 255 | 258 | ||
diff --git a/src/core/settings.h b/src/core/settings.h index db4c8fada..4e7a4b1be 100644 --- a/src/core/settings.h +++ b/src/core/settings.h | |||
| @@ -110,5 +110,9 @@ struct Values { | |||
| 110 | u16 gdbstub_port; | 110 | u16 gdbstub_port; |
| 111 | } extern values; | 111 | } extern values; |
| 112 | 112 | ||
| 113 | // a special value for Values::region_value indicating that citra will automatically select a region | ||
| 114 | // value to fit the region lockout info of the game | ||
| 115 | static constexpr int REGION_VALUE_AUTO_SELECT = -1; | ||
| 116 | |||
| 113 | void Apply(); | 117 | void Apply(); |
| 114 | } | 118 | } |