Fix fatal error caused by auto-detect region
Some checks are pending
citra-build / source (push) Waiting to run
citra-build / linux (appimage) (push) Waiting to run
citra-build / linux (fresh) (push) Waiting to run
citra-build / macos (arm64) (push) Waiting to run
citra-format / clang-format (push) Waiting to run
citra-transifex / transifex (push) Waiting to run
citra-build / macos (x86_64) (push) Waiting to run
citra-build / macos-universal (push) Blocked by required conditions
citra-build / windows (msvc) (push) Waiting to run
citra-build / windows (msys2) (push) Waiting to run
citra-build / android (push) Waiting to run
citra-build / ios (push) Waiting to run

This commit is contained in:
PabloMK7 2025-03-24 18:21:36 +01:00 committed by OpenSauce
parent 9203b23868
commit d8077fdea6
6 changed files with 85 additions and 13 deletions

View file

@ -108,5 +108,53 @@ HackManager hack_manager = {
},
}},
{HackType::REGION_FROM_SECURE,
HackEntry{
.mode = HackAllowMode::FORCE,
.affected_title_ids =
{
// eShop
0x0004001000020900, // JPN
0x0004001000021900, // USA
0x0004001000022900, // EUR
0x0004001000027900, // KOR
0x0004001000028900, // TWN
// System Settings
0x0004001000020000, // JPN
0x0004001000021000, // USA
0x0004001000022000, // EUR
0x0004001000026000, // CHN
0x0004001000027000, // KOR
0x0004001000028000, // TWN
// Nintendo Network ID Settings
0x000400100002BF00, // JPN
0x000400100002C000, // USA
0x000400100002C100, // EUR
// System Settings
0x0004003000008202, // JPN
0x0004003000008F02, // USA
0x0004003000009802, // EUR
0x000400300000A102, // CHN
0x000400300000A902, // KOR
0x000400300000B102, // TWN
// NIM
0x0004013000002C02, // Normal
0x0004013000002C03, // Safe mode
0x0004013020002C03, // New 3DS safe mode
// ACT
0x0004013000003802, // Normal
// FRD
0x0004013000003202, // Normal
0x0004013000003203, // Safe mode
0x0004013020003203, // New 3DS safe mode
},
}},
}};
}

View file

@ -13,6 +13,7 @@ enum class HackType : int {
ACCURATE_MULTIPLICATION,
DECRYPTION_AUTHORIZED,
ONLINE_LLE_REQUIRED,
REGION_FROM_SECURE,
};
class UserHackData {};

View file

@ -1,4 +1,4 @@
// Copyright 2018 Citra Emulator Project
// Copyright Citra Emulator Project / Azahar Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
@ -573,9 +573,11 @@ Result AppletManager::PrepareToStartLibraryApplet(AppletId applet_id) {
capture_buffer_info.reset();
if (Settings::values.lle_applets) {
bool is_setup = system.GetAppLoader().DoingInitialSetup();
auto cfg = Service::CFG::GetModule(system);
auto process = NS::LaunchTitle(system, FS::MediaType::NAND,
GetTitleIdForApplet(applet_id, cfg->GetRegionValue()));
auto process =
NS::LaunchTitle(system, FS::MediaType::NAND,
GetTitleIdForApplet(applet_id, cfg->GetRegionValue(is_setup)));
if (process) {
return ResultSuccess;
}
@ -602,9 +604,11 @@ Result AppletManager::PreloadLibraryApplet(AppletId applet_id) {
last_prepared_library_applet = applet_id;
if (Settings::values.lle_applets) {
bool is_setup = system.GetAppLoader().DoingInitialSetup();
auto cfg = Service::CFG::GetModule(system);
auto process = NS::LaunchTitle(system, FS::MediaType::NAND,
GetTitleIdForApplet(applet_id, cfg->GetRegionValue()));
auto process =
NS::LaunchTitle(system, FS::MediaType::NAND,
GetTitleIdForApplet(applet_id, cfg->GetRegionValue(is_setup)));
if (process) {
return ResultSuccess;
}
@ -814,9 +818,11 @@ Result AppletManager::StartSystemApplet(AppletId applet_id, std::shared_ptr<Kern
const auto slot_id =
applet_id == AppletId::HomeMenu ? AppletSlot::HomeMenu : AppletSlot::SystemApplet;
if (!GetAppletSlot(slot_id)->registered) {
bool is_setup = system.GetAppLoader().DoingInitialSetup();
auto cfg = Service::CFG::GetModule(system);
auto process = NS::LaunchTitle(system, FS::MediaType::NAND,
GetTitleIdForApplet(applet_id, cfg->GetRegionValue()));
auto process =
NS::LaunchTitle(system, FS::MediaType::NAND,
GetTitleIdForApplet(applet_id, cfg->GetRegionValue(is_setup)));
if (!process) {
// TODO: Find the right error code.
return {ErrorDescription::NotFound, ErrorModule::Applet, ErrorSummary::NotSupported,
@ -1422,7 +1428,7 @@ void AppletManager::EnsureHomeMenuLoaded() {
}
auto cfg = Service::CFG::GetModule(system);
auto menu_title_id = GetTitleIdForApplet(AppletId::HomeMenu, cfg->GetRegionValue());
auto menu_title_id = GetTitleIdForApplet(AppletId::HomeMenu, cfg->GetRegionValue(false));
auto process = NS::LaunchTitle(system, FS::MediaType::NAND, menu_title_id);
if (!process) {
LOG_WARNING(Service_APT,

View file

@ -196,7 +196,7 @@ static u32 DecompressLZ11(const u8* in, u8* out) {
bool Module::LoadSharedFont() {
auto cfg = Service::CFG::GetModule(system);
u8 font_region_code;
switch (cfg->GetRegionValue()) {
switch (cfg->GetRegionValue(false)) {
case 4: // CHN
font_region_code = 2;
break;

View file

@ -12,6 +12,7 @@
#include <fmt/ranges.h>
#include "common/archives.h"
#include "common/file_util.h"
#include "common/hacks/hack_manager.h"
#include "common/logging/log.h"
#include "common/settings.h"
#include "common/string_util.h"
@ -21,6 +22,7 @@
#include "core/file_sys/errors.h"
#include "core/file_sys/file_backend.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/process.h"
#include "core/hle/result.h"
#include "core/hle/service/cfg/cfg.h"
#include "core/hle/service/cfg/cfg_defaults.h"
@ -200,7 +202,14 @@ void Module::Interface::GetCountryCodeID(Kernel::HLERequestContext& ctx) {
rb.Push<u16>(country_code_id);
}
u32 Module::GetRegionValue() {
u32 Module::GetRegionValue(bool from_secure_info) {
if (from_secure_info) {
auto& sec_info = HW::UniqueData::GetSecureInfoA();
if (sec_info.IsValid()) {
return sec_info.body.region;
}
}
if (Settings::values.region_value.GetValue() == Settings::REGION_VALUE_AUTO_SELECT) {
UpdatePreferredRegionCode();
return preferred_region_code;
@ -212,9 +221,13 @@ u32 Module::GetRegionValue() {
void Module::Interface::GetRegion(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
u64 caller_tid = ctx.ClientThread()->owner_process.lock()->codeset->program_id;
bool from_secure_info = Common::Hacks::hack_manager.OverrideBooleanSetting(
Common::Hacks::HackType::REGION_FROM_SECURE, caller_tid, false);
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(ResultSuccess);
rb.Push<u8>(static_cast<u8>(cfg->GetRegionValue()));
rb.Push<u8>(static_cast<u8>(cfg->GetRegionValue(from_secure_info)));
}
void Module::Interface::SecureInfoGetByte101(Kernel::HLERequestContext& ctx) {
@ -319,8 +332,12 @@ void Module::Interface::IsCoppacsSupported(Kernel::HLERequestContext& ctx) {
rb.Push(ResultSuccess);
u64 caller_tid = ctx.ClientThread()->owner_process.lock()->codeset->program_id;
bool from_secure_info = Common::Hacks::hack_manager.OverrideBooleanSetting(
Common::Hacks::HackType::REGION_FROM_SECURE, caller_tid, false);
u8 canada_or_usa = 1;
if (canada_or_usa == cfg->GetRegionValue()) {
if (canada_or_usa == cfg->GetRegionValue(from_secure_info)) {
rb.Push(true);
} else {
rb.Push(false);

View file

@ -484,7 +484,7 @@ private:
void LoadMCUConfig();
public:
u32 GetRegionValue();
u32 GetRegionValue(bool from_secure_info);
// Utilities for frontend to set config data.
// Note: UpdateConfigNANDSavegame should be called after making changes to config data.