Controllerを手直し

IVSのダウンロード、Unregister、Shop::Connectを行えるように


git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@207 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
N2614 2011-04-20 08:19:08 +00:00
parent 8dcb999097
commit 2551da56f7
13 changed files with 1277 additions and 329 deletions

View File

@ -321,7 +321,6 @@ extern "C" void nnMain(void)
bool flip = false;
bool continueRestore = false;
for(;;)
{
@ -383,7 +382,7 @@ extern "C" void nnMain(void)
// 進捗確認メッセージを兼ねる?
::std::vector<std::string> operationMessage;
ControlState(operationMessage, nextStep, continueRestore);
ControlState(operationMessage, nextStep);
nn::util::FloatColor titleColor;

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,7 @@ typedef enum RestoreMode
const u32 RETRY_MAX = 3;
void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep, bool& continueRestore);
void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep);
bool InProgress();
bool IsRestoreSucceeded();
bool IsRestoreFailed();

View File

@ -264,24 +264,34 @@ nn::Result EqualsDeviceIdFileandDeviceId()
bit32 sdDeviceId;
common::SdReaderWriter sdReader;
size_t totalSize;
result = sdReader.ReadBufWithCmac(common::DEVICE_ID_PATHNAME, &sdDeviceId, sizeof(sdDeviceId), &totalSize);
s_CheckedEqualsDeviceIdFileandDeviceId = true;
if(result.IsSuccess())
size_t bufSize = common::HeapManager::GetHeap()->GetAllocatableSize();
void* buf = common::HeapManager::GetHeap()->Allocate(bufSize);
if (buf != NULL)
{
if(GetDeviceId() == sdDeviceId)
result = sdReader.ReadBufWithCmac(common::DEVICE_ID_PATHNAME, buf, bufSize, &totalSize);
if (result.IsSuccess())
{
result = nn::ResultSuccess();
s_CheckedEqualsDeviceIdFileandDeviceId = true;
std::memcpy(&sdDeviceId, buf, sizeof(sdDeviceId));
if (GetDeviceId() == sdDeviceId)
{
result = nn::ResultSuccess();
}
result = nn::Result(nn::Result::LEVEL_STATUS, nn::Result::SUMMARY_INVALID_RESULT_VALUE,
nn::Result::MODULE_COMMON, nn::Result::DESCRIPTION_INVALID_RESULT_VALUE);
return result;
}
result = nn::Result(nn::Result::LEVEL_STATUS, nn::Result::SUMMARY_INVALID_RESULT_VALUE, nn::Result::MODULE_COMMON,
nn::Result::DESCRIPTION_INVALID_RESULT_VALUE);
return result;
common::HeapManager::GetHeap()->Free(buf);
}
else
{
return result;
result = nn::Result(nn::Result::LEVEL_FATAL, nn::Result::SUMMARY_OUT_OF_RESOURCE, nn::Result::MODULE_COMMON,
nn::Result::DESCRIPTION_OUT_OF_MEMORY);
}
return result;
}
nn::Result EqualsRegionDataandRegion()
@ -879,6 +889,16 @@ void CreateRtcSyncFinishedFile()
CreateEmptyFile(common::RTC_SYNC_CHECK_PATHNAME);
}
void CreateDownloadIvsFinishedFile()
{
CreateEmptyFile(common::DOWNLOAD_IVS_CHECK_PATHNAME);
}
void CreateDeleteAccountFinishedFile()
{
CreateEmptyFile(common::DELETE_ACCOUNT_CHECK_PATHNAME);
}
u32 GetImportProgress()
{
return common::GetProgress();

View File

@ -38,6 +38,8 @@ void CreateWriteFinishedFile();
void CreateUpdateFinishedFile();
void CreateConsoleInitializedFile();
void CreateRtcSyncFinishedFile();
void CreateDownloadIvsFinishedFile();
void CreateDeleteAccountFinishedFile();
u32 GetImportProgress();
// NANDのごみを削除する

View File

@ -31,6 +31,8 @@ SOURCES[] =
Importer.cpp
Updater.cpp
Ntpclient.cpp
TitleDownloader.cpp
Shop.cpp
../common/HardwareInfo.cpp
../common/DrawSystemState.cpp
../common/FileTransfer.cpp

View File

@ -0,0 +1,321 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: Shop.cpp
Copyright 2009 Nintendo. 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 <nn/os.h>
#include <nn/Handle.h>
#include <nn/dbg.h>
#include <nn/nim.h>
#include <nn/ac/private/ac.h>
#include <nn/ac/CTR/private/ac_InternalApi.h>
#include <nn/nim/CTR/private/nim_ShopPrivateApi.h>
#include "Shop.h"
#include "CommonLogger.h"
using namespace ES_NAMESPACE;
using namespace EC_NAMESPACE;
#define NIM_UNREGISTER_RESULT_CHECK(result) \
do { \
if (result.IsFailure()) \
{ \
ECCustomerSupportCode csc; \
NN_UTIL_PANIC_IF_FAILED( \
nn::nim::Shop::GetCustomerSupportCode(&csc)); \
COMMON_LOGGER("CSCode: %d\n", csc); \
nn::dbg::PrintResult(result); \
s_Result = result; \
goto LABEL_FINALIZE; \
} \
} while(0)
namespace
{
nn::Result s_Result = nn::ResultSuccess();
const size_t UNREGISTER_THREAD_STACK_SIZE = 0x1000;
nn::os::Thread s_UnregisterThread;
nn::os::StackBuffer<UNREGISTER_THREAD_STACK_SIZE> s_UnregisterThreadStack;
static const size_t ecBufferSize = 128 * 1024;
static u8 ecBufffer[ecBufferSize];
#ifndef NN_SWITCH_DISABLE_DEBUG_PRINT
// 空文字列と NULL ポインタをそれぞれ <empty> と NULL として返す
const char* Cstr(const char* p)
{
return p ? (p[0] ? p : "<empty>") : "NULL";
}
// ECTicketVersions を出力
void PrintECTicketVersions(const ECTicketVersions& ticketVersions)
{
if (ticketVersions.nTicketVersions == 0)
{
NN_LOG("No TicketVersions\n");
return;
}
NN_LOG("----- ECTicketVersions -----\n");
for (u32 i = 0; i < ticketVersions.nTicketVersions; i++)
{
ECTicketVersion version = ticketVersions.ticketVersions[i];
NN_LOG("%03d: 0x%016llx v%d\n", i, version.ticketId, version.version);
}
NN_LOG("---------------------------\n");
}
// ECAccountInfo の情報を出力
void PrintECAccountInfo(const ECAccountInfo& accountInfo)
{
NN_LOG("========== ECAccountInfo ==========\n");
NN_LOG("accountId\n %s\n", Cstr(accountInfo.accountId));
NN_LOG("accountStatus\n %s\n", Cstr(accountInfo.accountStatus));
if (accountInfo.accountBalance == NULL)
{
NN_LOG("accountBalance\n NULL\n");
}
else
{
NN_LOG("accountBalance->amount\n %s\n",
Cstr(accountInfo.accountBalance->amount));
NN_LOG("accountBalance->currency\n %s\n",
Cstr(accountInfo.accountBalance->currency));
}
if (accountInfo.agreedEULAVersion == NULL)
{
NN_LOG("agreedEULAVersion\n NULL\n");
}
else
{
NN_LOG("agreedEULAVersion\n %lld\n",
*accountInfo.agreedEULAVersion);
}
if (accountInfo.latestEULAVersion == NULL)
{
NN_LOG("latestEULAVersion\n NULL\n");
}
else
{
NN_LOG("latestEULAVersion\n %lld\n",
*accountInfo.latestEULAVersion);
}
NN_LOG("country\n %s\n", Cstr(accountInfo.country));
NN_LOG("extAccountId\n %s\n", Cstr(accountInfo.extAccountId));
NN_LOG("deviceToken\n %s\n", Cstr(accountInfo.deviceToken));
NN_LOG("weakToken\n %s\n", Cstr(accountInfo.weakToken));
NN_LOG("isStandbyMode\n %d\n", accountInfo.isStandbyMode);
if (accountInfo.owned == NULL)
{
NN_LOG("owned\n NULL\n");
}
else
{
PrintECTicketVersions(*(accountInfo.owned));
}
}
#endif //NN_SWITCH_DISABLE_DEBUG_PRINT
nn::Result PrintNetworkSetting()
{
nn::ac::NetworkSetting networkSetting;
NN_UTIL_RETURN_IF_FAILED(nn::ac::LoadNetworkSetting(0, networkSetting));
COMMON_LOGGER("SSID: %s\n", networkSetting.wireless.essidSecurity.ssid);
COMMON_LOGGER("DNS : %d.%d.%d.%d\n",
networkSetting.ip.dns[0][0], networkSetting.ip.dns[0][1],
networkSetting.ip.dns[0][2], networkSetting.ip.dns[0][3]);
return nn::ResultSuccess();
}
nn::Result ConnectNetwork()
{
nn::Result result = nn::ResultSuccess();
nn::ac::Config config;
result = nn::ac::CreateDefaultConfig(&config);
NN_UTIL_RETURN_IF_FAILED(result);
result = nn::ac::ConnectWithoutEula(config);
NN_UTIL_RETURN_IF_FAILED(result);
NN_LOG("Success nn::ac::ConnectWithoutEula\n");
NN_UTIL_RETURN_IF_FAILED(PrintNetworkSetting());
return nn::ResultSuccess();
}
nn::Result InitializeInternal()
{
nn::Result result = nn::ResultSuccess();
result = nn::ac::InitializeInternal();
NN_UTIL_RETURN_IF_FAILED(result);
result = ConnectNetwork();
NN_UTIL_RETURN_IF_FAILED(result);
return nn::ResultSuccess();
}
nn::Result FinalizeInternal()
{
nn::Result result = nn::ResultSuccess();
nn::ac::CloseAll();
result = nn::ac::FinalizeInternal();
NN_UTIL_RETURN_IF_FAILED(result);
return nn::ResultSuccess();
}
}
namespace ConsoleRestore{
// メイン関数
void ShopOperationSingleThreadFunc(ShopOperation op)
{
nn::Result result = nn::ResultSuccess();
NN_LOG("util::ac::Initialize\n");
InitializeInternal();
/* -------------------------------------------------------------------
Initialize
-------------------------------------------------------------------- */
NN_LOG("nim::InitializeForShop\n");
result = nn::nim::InitializeForShop();
NIM_UNREGISTER_RESULT_CHECK(result);
/* -------------------------------------------------------------------
SetParameter
-------------------------------------------------------------------- */
NN_LOG("nim::Shop::SetTIN\n");
result = nn::nim::Shop::SetTin(NIM_TIN);
NIM_UNREGISTER_RESULT_CHECK(result);
switch(op)
{
case SHOP_OPERATION_CONNECT_ONLY:
{
// Connectするのみ
/* -------------------------------------------------------------------
Connect
-------------------------------------------------------------------- */
NN_LOG("nim::Shop::Connect\n");
ECAccountInfo* pAccountInfo;
result = nn::nim::Shop::Connect(&pAccountInfo, ecBufffer, ecBufferSize);
NIM_UNREGISTER_RESULT_CHECK(result);
#ifndef NN_SWITCH_DISABLE_DEBUG_PRINT
PrintECAccountInfo(*pAccountInfo);
NN_LOG("\n");
#endif //NN_SWITCH_DISABLE_DEBUG_PRINT
}
break;
case SHOP_OPERATION_GET_IVS:
{
// IVSを取得する
result = nn::nim::Shop::ImportIvsFromInfrastructure();
NIM_UNREGISTER_RESULT_CHECK(result);
}
break;
case SHOP_OPERATION_UNREGISTER:
{
/* -------------------------------------------------------------------
Connect
-------------------------------------------------------------------- */
NN_LOG("nim::Shop::Connect\n");
ECAccountInfo* pAccountInfo;
result = nn::nim::Shop::Connect(&pAccountInfo, ecBufffer, ecBufferSize);
NIM_UNREGISTER_RESULT_CHECK(result);
#ifndef NN_SWITCH_DISABLE_DEBUG_PRINT
PrintECAccountInfo(*pAccountInfo);
NN_LOG("\n");
#endif //NN_SWITCH_DISABLE_DEBUG_PRINT
if (pAccountInfo->accountStatus && pAccountInfo->accountStatus[0] == 'R')
{
/* ---------------------------------------------------------------
Unregister
---------------------------------------------------------------- */
NN_LOG("nim::Shop::Unregister\n");
result = nn::nim::Shop::Unregister();
NIM_UNREGISTER_RESULT_CHECK(result);
}
else
{
NN_LOG("Not registered.\n");
}
}
break;
}
LABEL_FINALIZE:
/* -------------------------------------------------------------------
Finalize
-------------------------------------------------------------------- */
NN_LOG("nim::FinalizeForShop\n");
result = nn::nim::FinalizeForShop();
NIM_UNREGISTER_RESULT_CHECK(result);
NN_LOG("util::ac::Initialize\n");
FinalizeInternal();
}
void StartShopOperationSingle(ShopOperation op)
{
NN_LOG("Start ShopOperationSingle");
s_Result = nn::ResultSuccess();
s_UnregisterThread.Start(ShopOperationSingleThreadFunc, op, s_UnregisterThreadStack);
}
void FinishShopOperationSingle()
{
NN_LOG("Finalize ShopOperationSingle\n");
s_UnregisterThread.Join();
s_UnregisterThread.Finalize();
}
bool IsShopOperationSingleFinished()
{
return s_UnregisterThread.IsValid() && !s_UnregisterThread.IsAlive();
}
nn::Result GetShopOperationSingleResult()
{
return s_Result;
}
}

View File

@ -0,0 +1,40 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: Shop.h
Copyright 2009 Nintendo. 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$
*---------------------------------------------------------------------------*/
#ifndef SHOP_H_
#define SHOP_H_
#include <nn.h>
#define NIM_TIN "56789"
namespace ConsoleRestore
{
typedef enum SHOP_OPERATION
{
SHOP_OPERATION_CONNECT_ONLY,
SHOP_OPERATION_GET_IVS,
SHOP_OPERATION_UNREGISTER
} ShopOperation;
void StartShopOperationSingle(ShopOperation op);
void FinishShopOperationSingle();
bool IsShopOperationSingleFinished();
nn::Result GetShopOperationSingleResult();
}
#endif /* SHOP_H_ */

View File

@ -0,0 +1,59 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: TitleDownloader.cpp
Copyright 2009 Nintendo. 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 "TitleDownloader.h"
#include <nn/am.h>
namespace ConsoleRestore
{
TitleDownloader::TitleDownloader() : m_Executing(false)
{
// TODO 自動生成されたコンストラクター・スタブ
}
TitleDownloader::~TitleDownloader()
{
// TODO Auto-generated destructor stub
}
void TitleDownloader::Start(nn::ProgramID* programIdList, size_t listNum)
{
if(m_Executing)
{
return;
}
m_Executing = true;
}
bool TitleDownloader::Succeeded()
{
return true;
}
bool TitleDownloader::Finished()
{
return true;
}
}

View File

@ -0,0 +1,42 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: TitleDownloader.h
Copyright 2009 Nintendo. 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$
*---------------------------------------------------------------------------*/
#ifndef TITLEDOWNLOADER_H_
#define TITLEDOWNLOADER_H_
#include <nn.h>
namespace ConsoleRestore
{
class TitleDownloader
{
public:
TitleDownloader();
virtual ~TitleDownloader();
void Start(nn::ProgramID* programIdList, size_t listNum);
static bool Succeeded();
static bool Finished();
private:
bool m_Executing;
};
}
#endif /* TITLEDOWNLOADER_H_ */

View File

@ -82,7 +82,6 @@ bool ExistsIVSFile()
bool ExistsConsoleInitializedFile()
{
// どちらかのファイルがあれば初期化済み
return ExistsFile(EXISTS_CONSOLE_INTIALIZED);
}
@ -116,6 +115,16 @@ bool ExistsRegionData()
return ExistsFile(EXISTS_REGION_DATA);
}
bool ExistsDeleteAccountChecked()
{
return ExistsFile(EXISTS_DELETE_ACCOUNT);
}
bool ExistsDownloadIvsCheckedFile()
{
return ExistsFile(EXISTS_DOWNLOAD_IVS);
}
void InitializeFileCheck()
{
for(u32 i = 0; i < EXISTS_MAX; i++)

View File

@ -33,6 +33,8 @@ typedef enum FILE_EXISTS_CHECK
EXISTS_COUNTRY_LANGUAGE,
EXISTS_VERSION_DATA,
EXISTS_REGION_DATA,
EXISTS_DELETE_ACCOUNT,
EXISTS_DOWNLOAD_IVS,
EXISTS_MAX
} FileExistsCheck;
@ -47,7 +49,9 @@ const wchar_t* const FILENAME_TABLE[EXISTS_MAX] =
common::RTC_SYNC_CHECK_PATHNAME,
common::COUNTRY_SETTING_PATHNAME,
common::VERSION_DATA_PATHNAME,
common::REGION_DATA_PATHNAME
common::REGION_DATA_PATHNAME,
common::DELETE_ACCOUNT_CHECK_PATHNAME,
common::DOWNLOAD_IVS_CHECK_PATHNAME
};
bool CheckFileExists(const wchar_t* path);
@ -61,6 +65,8 @@ bool ExistsRtcSyncFinishedFile();
bool ExistsCountryLanguageFile();
bool ExistsVersionData();
bool ExistsRegionData();
bool ExistsDeleteAccountChecked();
bool ExistsDownloadIvsCheckedFile();
void InitializeFileCheck();

View File

@ -50,6 +50,8 @@ const wchar_t* const NAND_TWL_DATA_ROOT_PATHNAME_WITHOUT_SLASH = L"twln:/title";
const wchar_t* const SDMC_ROOT_DIRECTORY_PATH = L"sdmc:/";
const wchar_t* const WRITE_FINISHED_CHECK_PATHNAME = L"sdmc:/CTR_Console_Repair/WriteFinished";
const wchar_t* const UPDATE_CHECK_PATHNAME = L"sdmc:/CTR_Console_Repair/UpdateFinished";
const wchar_t* const DELETE_ACCOUNT_CHECK_PATHNAME = L"sdmc:/CTR_Console_Repair/AccountDeletedChecked";
const wchar_t* const DOWNLOAD_IVS_CHECK_PATHNAME = L"sdmc:/CTR_Console_Repair/DownloadIvsFinished";
const wchar_t* const INITIALIZED_CHECK_PATHNAME = L"sdmc:/CTR_Console_Repair/ConsoleInitialized";
const wchar_t* const RTC_SYNC_CHECK_PATHNAME = L"sdmc:/CTR_Console_Repair/RtcSyncFinished";
const wchar_t* const PLAYHISTORY_PATHNAME = L"sdmc:/CTR_Console_Repair/playhistory.bin";