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@305 385bec56-5757-e545-9c3a-d8741f4650f1
225 lines
6.8 KiB
C++
225 lines
6.8 KiB
C++
/*---------------------------------------------------------------------------*
|
|
Project: Horizon
|
|
File: PlayHistoryManager.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/pl.h>
|
|
#include <nn/pl/CTR/pl_PlayHistoryApiSysmenu.h>
|
|
|
|
#include "PlayHistoryManager.h"
|
|
#include "HeapManager.h"
|
|
#include "SdMountManager.h"
|
|
#include "SdReaderWriter.h"
|
|
#include "CommonLogger.h"
|
|
#include "FileName.h"
|
|
#include "ProgramId.h"
|
|
|
|
namespace common
|
|
{
|
|
|
|
PlayHistoryManager::PlayHistoryManager()
|
|
{
|
|
// TODO 自動生成されたコンストラクター・スタブ
|
|
|
|
}
|
|
|
|
PlayHistoryManager::~PlayHistoryManager()
|
|
{
|
|
// TODO Auto-generated destructor stub
|
|
}
|
|
|
|
void PlayHistoryManager::Export()
|
|
{
|
|
nn::Result result;
|
|
SdMountManager::Mount();
|
|
SdReaderWriter sd;
|
|
|
|
size_t historyNum = nn::pl::CTR::GetPlayHistoryLength();
|
|
if ( historyNum == 0)
|
|
{
|
|
NN_LOG("No Play Event\n");
|
|
return;
|
|
}
|
|
|
|
// SDに書き込む
|
|
result = sd.WriteBufWithCmac(common::PLAYHISTORY_COUNT_PATHNAME, reinterpret_cast<void*>(&historyNum),
|
|
sizeof(historyNum));
|
|
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
|
|
|
nn::pl::CTR::PlayEvent* pEvent;
|
|
pEvent = reinterpret_cast<nn::pl::CTR::PlayEvent*> (HeapManager::GetHeap()->Allocate(
|
|
sizeof(nn::pl::CTR::PlayEvent) * historyNum));
|
|
if ( pEvent == NULL )
|
|
{
|
|
NN_LOG("Failed to Allocate Heap\n");
|
|
return;
|
|
}
|
|
|
|
// 一番古いデータから素直に全部読み込む
|
|
nn::pl::CTR::GetPlayHistory(pEvent, 0, historyNum);
|
|
|
|
// SDに書き込む
|
|
result = sd.WriteBufWithCmac(common::PLAYHISTORY_PATHNAME, reinterpret_cast<void*>(pEvent),
|
|
sizeof(nn::pl::CTR::PlayEvent) * historyNum);
|
|
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
|
|
|
HeapManager::GetHeap()->Free(pEvent);
|
|
|
|
SdMountManager::Unmount();
|
|
}
|
|
|
|
nn::Result PlayHistoryManager::GetPlayHistoryNums(size_t* nums)
|
|
{
|
|
nn::Result result = nn::ResultSuccess();
|
|
|
|
size_t bufSize = common::HeapManager::GetHeap()->GetAllocatableSize();
|
|
void* buf = common::HeapManager::GetHeap()->Allocate(bufSize);
|
|
if (buf != NULL)
|
|
{
|
|
common::SdReaderWriter sdReader;
|
|
|
|
size_t readSize;
|
|
result = sdReader.ReadBufWithCmac(common::PLAYHISTORY_COUNT_PATHNAME, buf, bufSize, &readSize);
|
|
if (result.IsSuccess())
|
|
{
|
|
*nums = *reinterpret_cast<size_t*> (buf);
|
|
}
|
|
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
|
|
|
HeapManager::GetHeap()->Free(buf);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
nn::Result PlayHistoryManager::Import()
|
|
{
|
|
nn::Result result = nn::ResultSuccess();
|
|
SdMountManager::Mount();
|
|
SdReaderWriter sd;
|
|
|
|
SdMountManager::Mount();
|
|
|
|
// プレイ履歴の件数を取得する
|
|
size_t historyNum = 0;
|
|
|
|
GetPlayHistoryNums(&historyNum);
|
|
|
|
if(historyNum == 0)
|
|
{
|
|
NN_LOG("No PlayHistory found\n");
|
|
return nn::Result(nn::Result::LEVEL_PERMANENT, nn::Result::SUMMARY_NOT_FOUND, nn::Result::MODULE_COMMON,
|
|
nn::Result::DESCRIPTION_NOT_FOUND);
|
|
}
|
|
|
|
size_t bufSize = common::HeapManager::GetHeap()->GetAllocatableSize();
|
|
void* buf = common::HeapManager::GetHeap()->Allocate(bufSize);
|
|
if (buf != NULL)
|
|
{
|
|
common::SdReaderWriter sdReader;
|
|
|
|
size_t readSize;
|
|
result = sdReader.ReadBufWithCmac(common::PLAYHISTORY_PATHNAME, buf, bufSize, &readSize);
|
|
if(result.IsSuccess())
|
|
{
|
|
nn::pl::CTR::PlayEvent* pEvent = reinterpret_cast<nn::pl::CTR::PlayEvent*>(buf);
|
|
NN_LOG("history num = %d\n", historyNum);
|
|
|
|
// プレイ履歴を無効化する
|
|
nn::pl::CTR::ClearPlayHistory();
|
|
|
|
// データ移行ツールを無視して書き込む
|
|
for(u32 i = 0; i < historyNum; i++)
|
|
{
|
|
COMMON_LOGGER("Importing PlayHistory %d/%d", i, historyNum);
|
|
if ((pEvent[i].GetProgramId() & WITHOUT_VALIATION_MASK) != CONSOLE_BACKUP_PROGRAM_ID
|
|
&& (pEvent[i].GetProgramId() & WITHOUT_VALIATION_MASK) != CONSOLE_RESTORE_PROGRAM_ID)
|
|
{
|
|
NN_LOG("%05d 0x%16llx : %X : %d\n", i, pEvent[i].GetProgramId(), pEvent[i].GetEventType(),
|
|
pEvent[i].minutes);
|
|
|
|
nn::pl::CTR::NotifyPlayEvent(pEvent[i].GetEventType(), pEvent[i].GetProgramId(),
|
|
pEvent[i].GetEventTime());
|
|
}
|
|
else
|
|
{
|
|
NN_LOG("Skipped\n");
|
|
}
|
|
}
|
|
|
|
}
|
|
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
|
|
|
common::HeapManager::GetHeap()->Free(buf);
|
|
}
|
|
else
|
|
{
|
|
NN_LOG("Failed Allocate Heap!! %s, %d", __FILE__, __LINE__);
|
|
return result;
|
|
}
|
|
|
|
SdMountManager::Unmount();
|
|
|
|
return result;
|
|
}
|
|
|
|
void PlayHistoryManager::Dump()
|
|
{
|
|
nn::Result result;
|
|
|
|
s32 playEventLength = nn::pl::CTR::GetPlayHistoryLength();
|
|
if ( playEventLength == 0 )
|
|
{
|
|
NN_LOG("No Play Event\n");
|
|
return;
|
|
}
|
|
|
|
nn::pl::CTR::PlayEvent* playEvent = reinterpret_cast<nn::pl::CTR::PlayEvent*> (HeapManager::GetHeap()->Allocate(
|
|
sizeof(nn::pl::CTR::PlayEvent) * playEventLength));
|
|
if ( playEvent == NULL )
|
|
{
|
|
NN_LOG("Failed to Allocate Heap\n");
|
|
return;
|
|
}
|
|
|
|
// 一番古いデータから素直に全部読み込む
|
|
(void)nn::pl::CTR::GetPlayHistory(playEvent, 0, playEventLength);
|
|
|
|
// 取得したデータを順番にすべて表示していく
|
|
s32 restPlayEventLength = playEventLength;
|
|
s32 displayCount = 0;
|
|
|
|
nn::pl::CTR::PlayEvent* pEvent;
|
|
while ( restPlayEventLength > 0 )
|
|
{
|
|
// 一気に表示できるところまで表示する
|
|
int line;
|
|
for ( line = 0; line < 24; line++ )
|
|
{
|
|
pEvent = &playEvent[displayCount];
|
|
NN_LOG("0x%16llx : %X : %d\n", pEvent->GetProgramId(), pEvent->eventType, pEvent->minutes);
|
|
restPlayEventLength--;
|
|
displayCount++;
|
|
if(restPlayEventLength <= 0)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
NN_UNUSED_VAR(pEvent);
|
|
|
|
HeapManager::GetHeap()->Free(playEvent);
|
|
return;
|
|
}
|
|
|
|
}
|