From b20858adb355523e07a4d5053c11920733355763 Mon Sep 17 00:00:00 2001 From: LPFaint99 Date: Thu, 16 Dec 2010 07:36:26 +0000 Subject: [PATCH] System Menu Region is now detected based on the Title Version in tmd Title Version and region char of currently installed system menu are now listed in the menu as well Which means disc channel will only show pal discs if it is a pal nand dump; ntsc nand dump will show ntsc discs, ntsc-j nand dump will show ntsc-j discs git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6591 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/DiscIO/Src/NANDContentLoader.cpp | 16 +++++++------ Source/Core/DiscIO/Src/NANDContentLoader.h | 1 + Source/Core/DiscIO/Src/Volume.h | 1 + Source/Core/DiscIO/Src/VolumeCommon.cpp | 25 ++++++++++++++++++++ Source/Core/DiscIO/Src/VolumeWad.cpp | 19 ++++++++------- Source/Core/DiscIO/Src/VolumeWad.h | 1 + Source/Core/DolphinWX/Src/FrameTools.cpp | 5 +++- 7 files changed, 52 insertions(+), 16 deletions(-) diff --git a/Source/Core/DiscIO/Src/NANDContentLoader.cpp b/Source/Core/DiscIO/Src/NANDContentLoader.cpp index 9d0f2e432c..52489351bc 100644 --- a/Source/Core/DiscIO/Src/NANDContentLoader.cpp +++ b/Source/Core/DiscIO/Src/NANDContentLoader.cpp @@ -122,6 +122,7 @@ public: u16 GetTitleVersion() const {return m_TileVersion;} u16 GetNumEntries() const {return m_numEntries;} DiscIO::IVolume::ECountry GetCountry() const; + u8 GetCountryChar() const {return m_Country; } private: @@ -133,6 +134,7 @@ private: u16 m_TileVersion; u8 m_TicketView[TICKET_VIEW_SIZE]; u8 m_TmdHeader[TMD_HEADER_SIZE]; + u8 m_Country; std::vector m_Content; @@ -223,6 +225,9 @@ bool CNANDContentLoader::CreateFromDirectory(const std::string& _rPath) m_BootIndex = Common::swap16(pTMD + 0x01e0); m_TitleID = Common::swap64(pTMD + 0x018c); m_IosVersion = Common::swap16(pTMD + 0x018a); + m_Country = *(u8*)&m_TitleID; + if (m_Country == 2) // SYSMENU + m_Country = DiscIO::GetSysMenuRegion(m_TileVersion); m_Content.resize(m_numEntries); @@ -307,6 +312,9 @@ bool CNANDContentLoader::ParseTMD(u8* pDataApp, u32 pDataAppSize, u8* pTicket, u m_BootIndex = Common::swap16(pTMD + 0x01e0); m_TitleID = Common::swap64(pTMD + 0x018c); m_IosVersion = Common::swap16(pTMD + 0x018a); + m_Country = *(u8*)&m_TitleID; + if (m_Country == 2) // SYSMENU + m_Country = DiscIO::GetSysMenuRegion(m_TileVersion); u8* p = pDataApp; @@ -341,16 +349,10 @@ DiscIO::IVolume::ECountry CNANDContentLoader::GetCountry() const if (!IsValid()) return DiscIO::IVolume::COUNTRY_UNKNOWN; - u64 TitleID = GetTitleID(); - char* pTitleID = (char*)&TitleID; - - return CountrySwitch((u8)pTitleID[0]); - - + return CountrySwitch(m_Country); } - CNANDContentManager CNANDContentManager::m_Instance; diff --git a/Source/Core/DiscIO/Src/NANDContentLoader.h b/Source/Core/DiscIO/Src/NANDContentLoader.h index 45bd07717a..85402cbfd3 100644 --- a/Source/Core/DiscIO/Src/NANDContentLoader.h +++ b/Source/Core/DiscIO/Src/NANDContentLoader.h @@ -63,6 +63,7 @@ public: virtual u16 GetTitleVersion() const = 0; virtual u16 GetNumEntries() const = 0; virtual DiscIO::IVolume::ECountry GetCountry() const = 0; + virtual u8 GetCountryChar() const = 0; enum { diff --git a/Source/Core/DiscIO/Src/Volume.h b/Source/Core/DiscIO/Src/Volume.h index 1eef45611f..f1bb5d3773 100644 --- a/Source/Core/DiscIO/Src/Volume.h +++ b/Source/Core/DiscIO/Src/Volume.h @@ -62,6 +62,7 @@ public: // Generic Switch function for all volumes IVolume::ECountry CountrySwitch(u8 CountryCode); +u8 GetSysMenuRegion(u16 _TitleVersion); } // namespace diff --git a/Source/Core/DiscIO/Src/VolumeCommon.cpp b/Source/Core/DiscIO/Src/VolumeCommon.cpp index 3f62495251..c10c8cad80 100644 --- a/Source/Core/DiscIO/Src/VolumeCommon.cpp +++ b/Source/Core/DiscIO/Src/VolumeCommon.cpp @@ -81,5 +81,30 @@ IVolume::ECountry CountrySwitch(u8 CountryCode) break; } } + +u8 GetSysMenuRegion(u16 _TitleVersion) +{ + switch(_TitleVersion) + { + case 128: case 192: case 224: case 256: + case 288: case 352: case 384: case 416: + case 448: case 480: case 512: + return 'J'; + case 97: case 193: case 225: case 257: + case 289: case 353: case 385: case 417: + case 449: case 481: case 513: + return 'E'; + case 130: case 162: case 194: case 226: + case 258: case 290: case 354: case 386: + case 418: case 450: case 482: case 514: + return 'P'; + case 326: case 390: case 454: case 486: + case 518: + return 'K'; + default: + return 'A'; + } +} + }; diff --git a/Source/Core/DiscIO/Src/VolumeWad.cpp b/Source/Core/DiscIO/Src/VolumeWad.cpp index 1777fd009b..0bd76f19fb 100644 --- a/Source/Core/DiscIO/Src/VolumeWad.cpp +++ b/Source/Core/DiscIO/Src/VolumeWad.cpp @@ -35,7 +35,16 @@ CVolumeWAD::CVolumeWAD(IBlobReader* _pReader) Read(0x14, 4, (u8*)&tmd_size); Read(0x18, 4, (u8*)&data_size); - OpeningBnrOffset = ALIGN_40(hdr_size) + ALIGN_40(cert_size) + ALIGN_40(tick_size) + ALIGN_40(tmd_size) + ALIGN_40(data_size); + u32 TmdOffset = ALIGN_40(hdr_size) + ALIGN_40(cert_size) + ALIGN_40(tick_size); + OpeningBnrOffset = TmdOffset + ALIGN_40(tmd_size) + ALIGN_40(data_size); + // read the last digit of the titleID in the ticket + Read(TmdOffset + 0x0193, 1, &m_Country); + if (m_Country == 2) // SYSMENU + { + u16 titlever = 0; + Read(TmdOffset + 0x01dc, 2, (u8*)&titlever); + m_Country = DiscIO::GetSysMenuRegion(Common::swap16(titlever)); + } } CVolumeWAD::~CVolumeWAD() @@ -56,13 +65,7 @@ IVolume::ECountry CVolumeWAD::GetCountry() const if (!m_pReader) return COUNTRY_UNKNOWN; - u8 CountryCode; - u32 Offset = ALIGN_40(hdr_size) + ALIGN_40(cert_size); - - // read the last digit of the titleID in the ticket - Read(Offset + 0x01E3, 1, &CountryCode); - - return CountrySwitch(CountryCode); + return CountrySwitch(m_Country); } std::string CVolumeWAD::GetUniqueID() const diff --git a/Source/Core/DiscIO/Src/VolumeWad.h b/Source/Core/DiscIO/Src/VolumeWad.h index c7760a7f46..06bd772699 100644 --- a/Source/Core/DiscIO/Src/VolumeWad.h +++ b/Source/Core/DiscIO/Src/VolumeWad.h @@ -48,6 +48,7 @@ private: IBlobReader* m_pReader; u64 m_titleID; u32 OpeningBnrOffset, hdr_size, cert_size, tick_size, tmd_size, data_size; + u8 m_Country; }; } // namespace diff --git a/Source/Core/DolphinWX/Src/FrameTools.cpp b/Source/Core/DolphinWX/Src/FrameTools.cpp index da724bb492..7d90bfbe9e 100644 --- a/Source/Core/DolphinWX/Src/FrameTools.cpp +++ b/Source/Core/DolphinWX/Src/FrameTools.cpp @@ -202,7 +202,10 @@ void CFrame::CreateMenu() if (DiscIO::CNANDContentManager::Access().GetNANDLoader(TITLEID_SYSMENU).IsValid()) { - toolsMenu->Append(IDM_LOAD_WII_MENU, _T("Load Wii Menu")); + int sysmenuVersion = DiscIO::CNANDContentManager::Access().GetNANDLoader(TITLEID_SYSMENU).GetTitleVersion(); + char sysmenuRegion = DiscIO::CNANDContentManager::Access().GetNANDLoader(TITLEID_SYSMENU).GetCountryChar(); + + toolsMenu->Append(IDM_LOAD_WII_MENU, wxString::Format(_T("Load Wii System Menu (%d %c)"), sysmenuVersion, sysmenuRegion)); } else {