mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
NN_UTIL_RETURN_IF_FAILEDをCOMMON_LOGGER_RETURN_IF_FAILEDに置換 CmacAdderが出力先ディレクトリ初期化時にエラーで止まっていたので修正 git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@631 385bec56-5757-e545-9c3a-d8741f4650f1
154 lines
4.2 KiB
C++
154 lines
4.2 KiB
C++
/*---------------------------------------------------------------------------*
|
||
Project: Horizon
|
||
File: RegionIdModifier.cpp
|
||
|
||
Copyright (C)2011 Nintendo Co., Ltd. All rights reserved.
|
||
|
||
These coded instructions, statements, and computer programs contain
|
||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||
Company Ltd., and are protected by Federal copyright law. They may
|
||
not be disclosed to third parties or copied or duplicated in any form,
|
||
in whole or in part, without the prior written consent of Nintendo.
|
||
|
||
$Rev:$
|
||
*---------------------------------------------------------------------------*/
|
||
#include "RegionIdModifier.h"
|
||
#include <cwchar>
|
||
#include <cstring>
|
||
|
||
struct CountryData
|
||
{
|
||
u32 id; // 上記定数にあるように、国IDと地域IDを組み合わせたID
|
||
u16 regionName[nn::cfg::CTR::CFG_SIMPLE_ADDRESS_NUM_LANGUAGES][nn::cfg::CTR::CFG_SIMPLE_ADDRESS_NAME_LENGTH]; // NULL終端込み
|
||
u8 order[nn::cfg::CTR::CFG_SIMPLE_ADDRESS_NUM_LANGUAGES]; // 言語ごとの地域名並び順(「未設定」が0になるので、最初の地域は1)
|
||
u16 latitude; // リストの値を 65536/360 倍して格納して下さい
|
||
u16 longitude; // リストの値を 65536/360 倍して格納して下さい
|
||
};
|
||
|
||
const size_t NUP_VERSION_TO_REGIONNUM[] =
|
||
{
|
||
1, // ローンチ(0)
|
||
1, // 0thNUP(1)
|
||
2, // 1stNUP(2)
|
||
2, // 1.05NUP(3)
|
||
2, // 1.1NUP(4)
|
||
3, // 2ndNUP(5)
|
||
3, // 2.1NUP(6)
|
||
};
|
||
|
||
const wchar_t* DIR_PATH[] =
|
||
{
|
||
L"0/JP/",
|
||
L"0/US/",
|
||
L"0/EU/",
|
||
L"2/JP/",
|
||
L"2/US/",
|
||
L"2/EU/",
|
||
L"5/JP/",
|
||
L"5/US/",
|
||
L"5/EU/"
|
||
};
|
||
|
||
RegionIdModifier::RegionIdModifier(u16 id, u8 nupVersion, u8 regionCode, const wchar_t* regionName)
|
||
{
|
||
m_Id = id;
|
||
m_NupVersion = nupVersion;
|
||
m_RegionCode = regionCode;
|
||
if (regionName != NULL)
|
||
{
|
||
std::wcsncpy(m_RegionName, regionName, sizeof(m_RegionName) / sizeof(wchar_t));
|
||
}
|
||
}
|
||
|
||
bool RegionIdModifier::IsValid()
|
||
{
|
||
return (m_Id & 0x00ff) != 0x01;
|
||
}
|
||
|
||
const PathList* RegionIdModifier::GetDirectoryPath()
|
||
{
|
||
// 範囲外のリージョン
|
||
if (nn::cfg::CTR::CFG_REGION_EUROPE < m_RegionCode)
|
||
{
|
||
return NULL;
|
||
}
|
||
|
||
for (u8 i = 0; i < nn::cfg::CTR::CFG_REGION_EUROPE + 1; i++)
|
||
{
|
||
std::wcsncpy(m_DirectoryPathBuf[i].path, DIR_PATH[m_RegionCode + i * (nn::cfg::CTR::CFG_REGION_EUROPE + 1)],
|
||
PATHLIST_LENGTH);
|
||
}
|
||
|
||
return m_DirectoryPathBuf;
|
||
}
|
||
|
||
size_t RegionIdModifier::GetDirectoryPathNum()
|
||
{
|
||
// 範囲外のリージョン
|
||
if (nn::cfg::CTR::CFG_REGION_EUROPE < m_RegionCode)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
const size_t countryNum = sizeof(NUP_VERSION_TO_REGIONNUM) / sizeof(NUP_VERSION_TO_REGIONNUM[0]);
|
||
if (m_NupVersion > countryNum - 1)
|
||
{
|
||
return NUP_VERSION_TO_REGIONNUM[countryNum - 1];
|
||
}
|
||
else
|
||
{
|
||
return NUP_VERSION_TO_REGIONNUM[m_NupVersion];
|
||
}
|
||
}
|
||
|
||
const wchar_t* RegionIdModifier::GetFileName()
|
||
{
|
||
std::swprintf(m_FileNameBuf, sizeof(m_FileNameBuf), L"%d_LZ.bin", m_Id >> 8);
|
||
return m_FileNameBuf;
|
||
}
|
||
|
||
const PathList* RegionIdModifier::GetFilePath()
|
||
{
|
||
std::memset(m_FilePathBuf, 0, sizeof(m_FilePathBuf));
|
||
GetDirectoryPath();
|
||
for (u8 i = 0; i < GetDirectoryPathNum(); i++)
|
||
{
|
||
size_t writeSize = std::wcslen(m_DirectoryPathBuf[i].path);
|
||
std::wcsncpy(m_FilePathBuf[i].path, m_DirectoryPathBuf[i].path, writeSize);
|
||
std::wcsncat(m_FilePathBuf[i].path, GetFileName(), PATHLIST_LENGTH - writeSize);
|
||
}
|
||
|
||
return m_FilePathBuf;
|
||
}
|
||
|
||
size_t RegionIdModifier::GetFilePathNum()
|
||
{
|
||
return GetDirectoryPathNum();
|
||
}
|
||
|
||
bool RegionIdModifier::GetValidRegionId(void* buf, size_t size, u8* id)
|
||
{
|
||
if (buf == NULL || size == 0)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
u32 numRegion; // その国に含まれる地域の数
|
||
numRegion = *reinterpret_cast<u32*>(buf);
|
||
|
||
CountryData* pCountry;
|
||
pCountry = reinterpret_cast<CountryData*>(&reinterpret_cast<u32*>(buf)[1]);
|
||
|
||
for (u32 i = 0; i < numRegion + 1; i++)
|
||
{
|
||
if (std::wcscmp(m_RegionName, reinterpret_cast<wchar_t*>(pCountry->regionName[0])) == 0)
|
||
{
|
||
*id = (pCountry->id >> 16) & 0x00ff;
|
||
return true;
|
||
}
|
||
pCountry++;
|
||
}
|
||
|
||
return false;
|
||
}
|