From 36c92294dfcb2605b29bcc12e69526e904887818 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 16 Mar 2020 15:19:08 +0100 Subject: [PATCH] Boot: Preserve CODE value in setting.txt if it already matches the region This is a part of fixing https://bugs.dolphin-emu.org/issues/11930. --- Source/Core/Core/Boot/Boot_BS2Emu.cpp | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Source/Core/Core/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Boot/Boot_BS2Emu.cpp index a85a939e79..8f8f630e80 100644 --- a/Source/Core/Core/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Boot/Boot_BS2Emu.cpp @@ -242,6 +242,30 @@ bool CBoot::EmulatedBS2_GC(const DiscIO::VolumeDisc& volume) return RunApploader(/*is_wii*/ false, volume); } +static DiscIO::Region CodeRegion(char c) +{ + switch (c) + { + case 'J': // Japan + case 'T': // Taiwan + return DiscIO::Region::NTSC_J; + case 'B': // Brazil + case 'M': // Middle East + case 'R': // Argentina + case 'S': // ??? + case 'U': // USA + case 'W': // ??? + return DiscIO::Region::NTSC_U; + case 'A': // Australia + case 'E': // Europe + return DiscIO::Region::PAL; + case 'K': // Korea + return DiscIO::Region::NTSC_K; + default: + return DiscIO::Region::Unknown; + } +} + bool CBoot::SetupWiiMemory(IOS::HLE::IOSC::ConsoleType console_type) { static const std::map region_settings = { @@ -267,11 +291,25 @@ bool CBoot::SetupWiiMemory(IOS::HLE::IOSC::ConsoleType console_type) { gen.SetBytes(std::move(data)); serno = gen.GetValue("SERNO"); + + bool region_matches = false; if (SConfig::GetInstance().bOverrideRegionSettings) + { + region_matches = true; + } + else + { + const std::string code = gen.GetValue("CODE"); + if (code.size() >= 2 && CodeRegion(code[1]) == SConfig::GetInstance().m_region) + region_matches = true; + } + + if (region_matches) { region_setting = RegionSetting{gen.GetValue("AREA"), gen.GetValue("VIDEO"), gen.GetValue("GAME"), gen.GetValue("CODE")}; } + gen.Reset(); } }