mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
インターネット設定をバックアップメモリに保存、バックアップメモリからの書き出しする機能を追加
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@756 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
parent
0884e17a8e
commit
5d8ac9e88a
205
trunk/Initializer2ndNUP/AcChanger.cpp
Normal file
205
trunk/Initializer2ndNUP/AcChanger.cpp
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Project: Horizon
|
||||||
|
File: AcChanger.cpp
|
||||||
|
|
||||||
|
Copyright 2009-2011 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 "AcChanger.h"
|
||||||
|
#include <nn/cfg.h>
|
||||||
|
#include <nn/cfg/CTR/cfg_ApiSys.h>
|
||||||
|
#include <nn/cfg/CTR/detail/cfg_Keys.h>
|
||||||
|
#include <nn/cfg/CTR/detail/cfg_DataStructures.h>
|
||||||
|
#include <nn/cfg/CTR/cfg_NtrSettings.h>
|
||||||
|
#include <nn/cfg/CTR/cfg_ApiNor.h>
|
||||||
|
#include <nn/ac/CTR/private/ac_InternalApi.h>
|
||||||
|
#include <nn/ac/CTR/private/ac_NetworkSetting.h>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
struct SaveData
|
||||||
|
{
|
||||||
|
// インターネット接続設定
|
||||||
|
nn::ac::CTR::NetworkSetting m_NetworkSetting[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
SaveData s_SaveData;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
AcChanger::AcChanger()
|
||||||
|
{
|
||||||
|
// TODO 自動生成されたコンストラクター・スタブ
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
AcChanger::~AcChanger()
|
||||||
|
{
|
||||||
|
// TODO Auto-generated destructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
nn::Result AcChanger::RestoreFromBackup()
|
||||||
|
{
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
nn::fs::MountSaveData("data:")
|
||||||
|
);
|
||||||
|
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
CheckBackupFormat()
|
||||||
|
);
|
||||||
|
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
RestoreAcDataFromBackup()
|
||||||
|
);
|
||||||
|
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
nn::fs::Unmount("data:")
|
||||||
|
);
|
||||||
|
|
||||||
|
return nn::ResultSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
nn::Result AcChanger::CheckBackupFormat()
|
||||||
|
{
|
||||||
|
size_t maxFiles;
|
||||||
|
size_t maxDirectories;
|
||||||
|
bool isDuplicateAll;
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
nn::fs::GetSaveDataFormatInfo(&maxFiles, &maxDirectories, &isDuplicateAll)
|
||||||
|
);
|
||||||
|
|
||||||
|
NN_LOG("MaxFile = %d, MaxDirectory = %d, Duplicate = %d\n", maxFiles, maxDirectories, isDuplicateAll);
|
||||||
|
|
||||||
|
if(maxFiles != FILE_NUM ||
|
||||||
|
maxDirectories != DIR_NUM ||
|
||||||
|
isDuplicateAll != DUPLICATE
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return nn::MakePermanentResult(nn::Result::SUMMARY_INVALID_STATE, nn::Result::MODULE_APPLICATION,
|
||||||
|
nn::Result::DESCRIPTION_INVALID_RESULT_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nn::ResultSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
nn::Result AcChanger::ImportToBackup()
|
||||||
|
{
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
GetAcData()
|
||||||
|
);
|
||||||
|
|
||||||
|
// バックアップメモリをフォーマットします
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
nn::fs::FormatSaveData(FILE_NUM, DIR_NUM, DUPLICATE)
|
||||||
|
);
|
||||||
|
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
ImportAcDatatoBackup()
|
||||||
|
);
|
||||||
|
|
||||||
|
return nn::ResultSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
nn::Result AcChanger::GetAcData()
|
||||||
|
{
|
||||||
|
nn::Result result;
|
||||||
|
|
||||||
|
// インターネット接続設定取得
|
||||||
|
result = nn::ac::CTR::InitializeInternal();
|
||||||
|
if (result.IsSuccess())
|
||||||
|
{
|
||||||
|
for(s32 i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
result = nn::ac::CTR::LoadNetworkSetting(i, s_SaveData.m_NetworkSetting[i]);
|
||||||
|
if(result.IsFailure())
|
||||||
|
{
|
||||||
|
std::memset(&s_SaveData.m_NetworkSetting[i], 0 , sizeof(s_SaveData.m_NetworkSetting[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
nn::ac::CTR::FinalizeInternal()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::memset(s_SaveData.m_NetworkSetting, 0, sizeof(s_SaveData.m_NetworkSetting));
|
||||||
|
}
|
||||||
|
|
||||||
|
return nn::ResultSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
nn::Result AcChanger::ImportAcDatatoBackup()
|
||||||
|
{
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
nn::fs::MountSaveData("data:")
|
||||||
|
);
|
||||||
|
|
||||||
|
nn::fs::FileOutputStream file;
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
file.TryInitialize(L"data:/savedata.bin", true)
|
||||||
|
);
|
||||||
|
|
||||||
|
s32 writeSize;
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
file.TryWrite(&writeSize, &s_SaveData, sizeof(s_SaveData), true)
|
||||||
|
);
|
||||||
|
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
nn::fs::CommitSaveData("data:")
|
||||||
|
);
|
||||||
|
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
nn::fs::Unmount("data:")
|
||||||
|
);
|
||||||
|
|
||||||
|
return nn::ResultSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
nn::Result AcChanger::RestoreAcDataFromBackup()
|
||||||
|
{
|
||||||
|
nn::fs::FileInputStream file;
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
file.TryInitialize(L"data:/savedata.bin")
|
||||||
|
);
|
||||||
|
|
||||||
|
s32 readSize;
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
file.TryRead(&readSize, &s_SaveData, sizeof(s_SaveData))
|
||||||
|
);
|
||||||
|
|
||||||
|
// インターネット接続設定
|
||||||
|
nn::Result result = nn::ac::CTR::InitializeInternal();
|
||||||
|
if (result.IsSuccess())
|
||||||
|
{
|
||||||
|
for(s32 i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
result = nn::ac::CTR::UpdateNetworkSetting(i, s_SaveData.m_NetworkSetting[i]);
|
||||||
|
if(result.IsFailure())
|
||||||
|
{
|
||||||
|
std::memset(&s_SaveData.m_NetworkSetting[i], 0 , sizeof(s_SaveData.m_NetworkSetting[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
nn::ac::CTR::FlushNetworkSetting()
|
||||||
|
);
|
||||||
|
|
||||||
|
NN_UTIL_RETURN_IF_FAILED(
|
||||||
|
nn::ac::CTR::FinalizeInternal()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::memset(s_SaveData.m_NetworkSetting, 0, sizeof(s_SaveData.m_NetworkSetting));
|
||||||
|
}
|
||||||
|
|
||||||
|
return nn::ResultSuccess();
|
||||||
|
}
|
||||||
52
trunk/Initializer2ndNUP/AcChanger.h
Normal file
52
trunk/Initializer2ndNUP/AcChanger.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Project: Horizon
|
||||||
|
File: AcChanger.h
|
||||||
|
|
||||||
|
Copyright 2009-2011 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 ACCHANGER_H_
|
||||||
|
#define ACCHANGER_H_
|
||||||
|
|
||||||
|
#include <nn.h>
|
||||||
|
|
||||||
|
class AcChanger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AcChanger();
|
||||||
|
virtual ~AcChanger();
|
||||||
|
|
||||||
|
// バックアップメモリからデータを読み取ってacに反映します
|
||||||
|
nn::Result RestoreFromBackup();
|
||||||
|
|
||||||
|
// 現在のacの値をバックアップメモリに取り込みます。
|
||||||
|
// バックアップメモリは初期化されます
|
||||||
|
nn::Result ImportToBackup();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// バックアップメモリのフォーマットをチェックします
|
||||||
|
nn::Result CheckBackupFormat();
|
||||||
|
|
||||||
|
// acデータを読み込みます
|
||||||
|
nn::Result GetAcData();
|
||||||
|
|
||||||
|
// 読み込んだacデータをバックアップメモリに書き込みます
|
||||||
|
nn::Result ImportAcDatatoBackup();
|
||||||
|
|
||||||
|
// acのデータをバックアップメモリから書き込みます
|
||||||
|
nn::Result RestoreAcDataFromBackup();
|
||||||
|
|
||||||
|
static const size_t FILE_NUM = 1;
|
||||||
|
static const size_t DIR_NUM = 1;
|
||||||
|
static const bool DUPLICATE = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* ACCHANGER_H_ */
|
||||||
@ -13,6 +13,8 @@ Rom:
|
|||||||
# ROMに含めるファイルのルートを記述します。
|
# ROMに含めるファイルのルートを記述します。
|
||||||
# このパス以下のファイルは、ROMに含まれファイルシステムから読み込めます。
|
# このパス以下のファイルは、ROMに含まれファイルシステムから読み込めます。
|
||||||
HostRoot : "$(ROMFS_ROOT)"
|
HostRoot : "$(ROMFS_ROOT)"
|
||||||
|
SaveDataSize : 512KB
|
||||||
|
|
||||||
CardInfo:
|
CardInfo:
|
||||||
CardDevice: None
|
CardDevice : NorFlash
|
||||||
|
MediaType : Card1
|
||||||
@ -18,6 +18,7 @@ CTR_APPTYPE = CARD
|
|||||||
|
|
||||||
TARGET_PROGRAM = ConsoleInitializer
|
TARGET_PROGRAM = ConsoleInitializer
|
||||||
ROM_SPEC_FILE = $(TARGET_PROGRAM).rsf
|
ROM_SPEC_FILE = $(TARGET_PROGRAM).rsf
|
||||||
|
DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/private/InitializeTool.desc
|
||||||
|
|
||||||
ROMFS_ROOT = romfiles
|
ROMFS_ROOT = romfiles
|
||||||
CTR_BANNER_SPEC = AutoBoot.bsf
|
CTR_BANNER_SPEC = AutoBoot.bsf
|
||||||
@ -28,6 +29,7 @@ INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) \
|
|||||||
|
|
||||||
SOURCES[] =
|
SOURCES[] =
|
||||||
main.cpp
|
main.cpp
|
||||||
|
AcChanger.cpp
|
||||||
|
|
||||||
LIBS += lib_demo
|
LIBS += lib_demo
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
【ビルド環境】
|
【ビルド環境】
|
||||||
|
|
||||||
・SDK
|
・SDK
|
||||||
CTR_SDK-3_3 branch r45337
|
CTR_SDK-3_3 branch r54451
|
||||||
|
|||||||
@ -22,13 +22,21 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "demo.h"
|
#include "demo.h"
|
||||||
|
#include "AcChanger.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
demo::RenderSystemDrawing s_RenderSystem;
|
demo::RenderSystemDrawing s_RenderSystem;
|
||||||
nn::os::StackBuffer<1024> s_StackBuffer;
|
|
||||||
std::vector<std::string> s_DispMessage;
|
std::vector<std::string> s_DispMessage;
|
||||||
|
|
||||||
|
AcChanger s_AcChanger;
|
||||||
|
|
||||||
|
enum Mode
|
||||||
|
{
|
||||||
|
MODE_IMPORT,
|
||||||
|
MODE_JUMP_TO_INITIALIZE
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define HANDLE_RESULT(result) \
|
#define HANDLE_RESULT(result) \
|
||||||
@ -80,11 +88,12 @@ nn::ProgramId GetProgramIdMsetWithRegion_()
|
|||||||
void DrawResult(nn::Result result)
|
void DrawResult(nn::Result result)
|
||||||
{
|
{
|
||||||
char buf[16];
|
char buf[16];
|
||||||
nn::nstd::TSNPrintf(buf, sizeof(buf), "%08X", result.GetPrintableBits());
|
NN_LOG("%08X\n", result.GetPrintableBits());
|
||||||
|
nn::nstd::TSNPrintf(buf, sizeof(buf), "Error: %08X", result.GetPrintableBits());
|
||||||
s_DispMessage.push_back(std::string(buf));
|
s_DispMessage.push_back(std::string(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
void JumpThreadFunc()
|
void Jump()
|
||||||
{
|
{
|
||||||
nn::Result result;
|
nn::Result result;
|
||||||
|
|
||||||
@ -106,16 +115,109 @@ void JumpThreadFunc()
|
|||||||
HANDLE_RESULT(result);
|
HANDLE_RESULT(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsImportMode()
|
||||||
|
{
|
||||||
|
// 入力チェック
|
||||||
|
nn::hid::PadStatus pad;
|
||||||
|
nn::hid::PadReader padReader;
|
||||||
|
while( !padReader.ReadLatest(&pad) )
|
||||||
|
{
|
||||||
|
nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMilliSeconds(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
if((pad.hold & nn::hid::BUTTON_A) &&
|
||||||
|
(pad.hold & nn::hid::BUTTON_B) &&
|
||||||
|
(pad.hold & nn::hid::BUTTON_X) &&
|
||||||
|
(pad.hold & nn::hid::BUTTON_Y))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Import()
|
||||||
|
{
|
||||||
|
s_DispMessage.push_back(std::string("Import to Backup Memory"));
|
||||||
|
// 設定読み込み
|
||||||
|
nn::Result result = s_AcChanger.ImportToBackup();
|
||||||
|
if (result.IsSuccess())
|
||||||
|
{
|
||||||
|
s_DispMessage.push_back(std::string("Press Power Button to Shutdown"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HANDLE_RESULT(result);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Restore()
|
||||||
|
{
|
||||||
|
s_DispMessage.push_back(std::string("Restore from Backup Memory"));
|
||||||
|
// 設定反映
|
||||||
|
nn::Result result = s_AcChanger.RestoreFromBackup();
|
||||||
|
if (result.IsSuccess())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HANDLE_RESULT(result);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ManageBackupMemory(Mode mode)
|
||||||
|
{
|
||||||
|
if(mode == MODE_IMPORT)
|
||||||
|
{
|
||||||
|
return Import();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Restore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" void nnMain()
|
extern "C" void nnMain()
|
||||||
{
|
{
|
||||||
nn::applet::Enable();
|
nn::applet::Enable();
|
||||||
|
|
||||||
|
nn::fs::Initialize();
|
||||||
nn::cfg::Initialize();
|
nn::cfg::Initialize();
|
||||||
|
|
||||||
|
HANDLE_RESULT(
|
||||||
|
nn::hid::Initialize()
|
||||||
|
);
|
||||||
|
|
||||||
s_DispMessage.clear();
|
s_DispMessage.clear();
|
||||||
// ジャンプ用スレッドの生成
|
|
||||||
nn::os::Thread drawThread;
|
Mode mode;
|
||||||
drawThread.Start(JumpThreadFunc, s_StackBuffer, nn::os::DEFAULT_THREAD_PRIORITY + 1);
|
if(IsImportMode())
|
||||||
|
{
|
||||||
|
mode = MODE_IMPORT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mode = MODE_JUMP_TO_INITIALIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool backupMemoryOperationSuccess;
|
||||||
|
backupMemoryOperationSuccess = ManageBackupMemory(mode);
|
||||||
|
|
||||||
|
if(mode == MODE_JUMP_TO_INITIALIZE && backupMemoryOperationSuccess)
|
||||||
|
{
|
||||||
|
Jump();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// ここから先はImportモードか、Jumpに失敗した時のみ
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// RenderSystem の準備
|
// RenderSystem の準備
|
||||||
nn::fnd::ExpHeap appHeap;
|
nn::fnd::ExpHeap appHeap;
|
||||||
@ -124,7 +226,15 @@ extern "C" void nnMain()
|
|||||||
uptr heapForGx = reinterpret_cast<uptr>(appHeap.Allocate(s_GxHeapSize));
|
uptr heapForGx = reinterpret_cast<uptr>(appHeap.Allocate(s_GxHeapSize));
|
||||||
s_RenderSystem.Initialize(heapForGx, s_GxHeapSize);
|
s_RenderSystem.Initialize(heapForGx, s_GxHeapSize);
|
||||||
|
|
||||||
s_RenderSystem.SetClearColor(NN_GX_DISPLAY_BOTH, 0, 0, 0, 1);
|
if(mode == MODE_IMPORT && backupMemoryOperationSuccess)
|
||||||
|
{
|
||||||
|
s_RenderSystem.SetClearColor(NN_GX_DISPLAY_BOTH, 0, 1, 0, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s_RenderSystem.SetClearColor(NN_GX_DISPLAY_BOTH, 0, 0, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
s_RenderSystem.SetColor(1, 1, 1);
|
s_RenderSystem.SetColor(1, 1, 1);
|
||||||
|
|
||||||
u32 counter = 0;
|
u32 counter = 0;
|
||||||
@ -137,7 +247,7 @@ extern "C" void nnMain()
|
|||||||
s32 i = 0;
|
s32 i = 0;
|
||||||
for(std::vector<std::string>::iterator it = s_DispMessage.begin(); it != s_DispMessage.end(); it++)
|
for(std::vector<std::string>::iterator it = s_DispMessage.begin(); it != s_DispMessage.end(); it++)
|
||||||
{
|
{
|
||||||
s_RenderSystem.DrawText(0, (i + 1) * 10, "%s", it->c_str());
|
s_RenderSystem.DrawText(0, ++i * 10, "%s", it->c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
s_RenderSystem.SwapBuffers();
|
s_RenderSystem.SwapBuffers();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user