Merge pull request #3363 from lioncash/tmd

Volume: Make GetTMD return a vector
This commit is contained in:
Pierre Bourdon 2015-12-20 09:54:24 +01:00
commit 2842897d55
9 changed files with 50 additions and 54 deletions

View File

@ -268,11 +268,10 @@ bool CBoot::BootUp()
if (unique_id.size() >= 4)
VideoInterface::SetRegionReg(unique_id.at(3));
u32 tmd_size;
std::unique_ptr<u8[]> tmd_buf = pVolume.GetTMD(&tmd_size);
if (tmd_size)
std::vector<u8> tmd_buffer = pVolume.GetTMD();
if (!tmd_buffer.empty())
{
WII_IPC_HLE_Interface::ES_DIVerify(tmd_buf.get(), tmd_size);
WII_IPC_HLE_Interface::ES_DIVerify(tmd_buffer);
}
_StartupPara.bWii = pVolume.GetVolumeType() == DiscIO::IVolume::WII_DISC;

View File

@ -23,6 +23,7 @@ They will also generate a true or false return for UpdateInterrupts() in WII_IPC
#include <list>
#include <map>
#include <string>
#include <vector>
#include "Common/ChunkFile.h"
#include "Common/CommonPaths.h"
@ -206,9 +207,9 @@ void SetDefaultContentFile(const std::string& _rFilename)
}
}
void ES_DIVerify(u8 *_pTMD, u32 _sz)
void ES_DIVerify(const std::vector<u8>& tmd)
{
CWII_IPC_HLE_Device_es::ES_DIVerify(_pTMD, _sz);
CWII_IPC_HLE_Device_es::ES_DIVerify(tmd);
}
void SDIO_EventNotify()

View File

@ -6,6 +6,7 @@
#include <memory>
#include <string>
#include <vector>
#include "Common/CommonTypes.h"
@ -55,7 +56,7 @@ void DoState(PointerWrap &p);
// Set default content file
void SetDefaultContentFile(const std::string& _rFilename);
void ES_DIVerify(u8 *_pTMD, u32 _sz);
void ES_DIVerify(const std::vector<u8>& tmd);
void SDIO_EventNotify();

View File

@ -159,10 +159,9 @@ IPCCommandResult CWII_IPC_HLE_Device_di::IOCtlV(u32 _CommandAddress)
INFO_LOG(WII_IPC_DVD, "DVDLowOpenPartition: partition_offset 0x%016" PRIx64, partition_offset);
// Read TMD to the buffer
u32 tmd_size;
std::unique_ptr<u8[]> tmd_buf = DVDInterface::GetVolume().GetTMD(&tmd_size);
Memory::CopyToEmu(CommandBuffer.PayloadBuffer[0].m_Address, tmd_buf.get(), tmd_size);
WII_IPC_HLE_Interface::ES_DIVerify(tmd_buf.get(), tmd_size);
std::vector<u8> tmd_buffer = DVDInterface::GetVolume().GetTMD();
Memory::CopyToEmu(CommandBuffer.PayloadBuffer[0].m_Address, tmd_buffer.data(), tmd_buffer.size());
WII_IPC_HLE_Interface::ES_DIVerify(tmd_buffer);
ReturnValue = 1;
}

View File

@ -37,6 +37,7 @@
// otherwise we may not get __STDC_FORMAT_MACROS
#include <cinttypes>
#include <memory>
#include <vector>
#include <mbedtls/aes.h>
#include "Common/ChunkFile.h"
@ -1096,26 +1097,26 @@ bool CWII_IPC_HLE_Device_es::IsValid(u64 _TitleID) const
}
u32 CWII_IPC_HLE_Device_es::ES_DIVerify(u8* _pTMD, u32 _sz)
u32 CWII_IPC_HLE_Device_es::ES_DIVerify(const std::vector<u8>& tmd)
{
u64 titleID = 0xDEADBEEFDEADBEEFull;
u64 tmdTitleID = Common::swap64(*(u64*)(_pTMD+0x18c));
DVDInterface::GetVolume().GetTitleID(&titleID);
if (titleID != tmdTitleID)
{
u64 title_id = 0xDEADBEEFDEADBEEFull;
u64 tmd_title_id = Common::swap64(&tmd[0x18C]);
DVDInterface::GetVolume().GetTitleID(&title_id);
if (title_id != tmd_title_id)
return -1;
}
std::string tmdPath = Common::GetTMDFileName(tmdTitleID, Common::FROM_SESSION_ROOT);
File::CreateFullPath(tmdPath);
File::CreateFullPath(Common::GetTitleDataPath(tmdTitleID, Common::FROM_SESSION_ROOT));
std::string tmd_path = Common::GetTMDFileName(tmd_title_id, Common::FROM_SESSION_ROOT);
Movie::g_titleID = tmdTitleID;
std::string savePath = Common::GetTitleDataPath(tmdTitleID, Common::FROM_SESSION_ROOT);
File::CreateFullPath(tmd_path);
File::CreateFullPath(Common::GetTitleDataPath(tmd_title_id, Common::FROM_SESSION_ROOT));
Movie::g_titleID = tmd_title_id;
std::string save_path = Common::GetTitleDataPath(tmd_title_id, Common::FROM_SESSION_ROOT);
if (Movie::IsRecordingInput())
{
// TODO: Check for the actual save data
if (File::Exists(savePath + "banner.bin"))
if (File::Exists(save_path + "banner.bin"))
Movie::g_bClearSave = false;
else
Movie::g_bClearSave = true;
@ -1124,44 +1125,44 @@ u32 CWII_IPC_HLE_Device_es::ES_DIVerify(u8* _pTMD, u32 _sz)
// TODO: Force the game to save to another location, instead of moving the user's save.
if (Movie::IsPlayingInput() && Movie::IsConfigSaved() && Movie::IsStartingFromClearSave())
{
if (File::Exists(savePath + "banner.bin"))
if (File::Exists(save_path + "banner.bin"))
{
if (File::Exists(savePath + "../backup/"))
if (File::Exists(save_path + "../backup/"))
{
// The last run of this game must have been to play back a movie, so their save is already backed up.
File::DeleteDirRecursively(savePath);
File::DeleteDirRecursively(save_path);
}
else
{
#ifdef _WIN32
MoveFile(UTF8ToTStr(savePath).c_str(), UTF8ToTStr(savePath + "../backup/").c_str());
MoveFile(UTF8ToTStr(save_path).c_str(), UTF8ToTStr(save_path + "../backup/").c_str());
#else
File::CopyDir(savePath, savePath + "../backup/");
File::DeleteDirRecursively(savePath);
File::CopyDir(save_path, save_path + "../backup/");
File::DeleteDirRecursively(save_path);
#endif
}
}
}
else if (File::Exists(savePath + "../backup/"))
else if (File::Exists(save_path + "../backup/"))
{
// Delete the save made by a previous movie, and copy back the user's save.
if (File::Exists(savePath + "banner.bin"))
File::DeleteDirRecursively(savePath);
if (File::Exists(save_path + "banner.bin"))
File::DeleteDirRecursively(save_path);
#ifdef _WIN32
MoveFile(UTF8ToTStr(savePath + "../backup/").c_str(), UTF8ToTStr(savePath).c_str());
MoveFile(UTF8ToTStr(save_path + "../backup/").c_str(), UTF8ToTStr(save_path).c_str());
#else
File::CopyDir(savePath + "../backup/", savePath);
File::DeleteDirRecursively(savePath + "../backup/");
File::CopyDir(save_path + "../backup/", save_path);
File::DeleteDirRecursively(save_path + "../backup/");
#endif
}
if (!File::Exists(tmdPath))
if (!File::Exists(tmd_path))
{
File::IOFile _pTMDFile(tmdPath, "wb");
if (!_pTMDFile.WriteBytes(_pTMD, _sz))
File::IOFile tmd_file(tmd_path, "wb");
if (!tmd_file.WriteBytes(tmd.data(), tmd.size()))
ERROR_LOG(WII_IPC_ES, "DIVerify failed to write disc TMD to NAND.");
}
DiscIO::cUIDsys::AccessInstance().AddTitle(tmdTitleID);
DiscIO::cUIDsys::AccessInstance().AddTitle(tmd_title_id);
DiscIO::CNANDContentManager::Access().ClearCache();
return 0;
}

View File

@ -37,7 +37,7 @@ public:
IPCCommandResult IOCtlV(u32 _CommandAddress) override;
static u32 ES_DIVerify(u8 *_pTMD, u32 _sz);
static u32 ES_DIVerify(const std::vector<u8>& tmd);
// This should only be cleared on power reset
static std::string m_ContentFile;

View File

@ -6,7 +6,6 @@
#include <cstring>
#include <map>
#include <memory>
#include <string>
#include <vector>
@ -82,11 +81,7 @@ public:
}
virtual bool GetTitleID(u64*) const { return false; }
virtual std::unique_ptr<u8[]> GetTMD(u32 *_sz) const
{
*_sz = 0;
return std::unique_ptr<u8[]>();
}
virtual std::vector<u8> GetTMD() const { return {}; }
virtual std::string GetUniqueID() const = 0;
virtual std::string GetMakerID() const = 0;
virtual u16 GetRevision() const = 0;

View File

@ -115,9 +115,8 @@ bool CVolumeWiiCrypted::GetTitleID(u64* buffer) const
return true;
}
std::unique_ptr<u8[]> CVolumeWiiCrypted::GetTMD(u32 *size) const
std::vector<u8> CVolumeWiiCrypted::GetTMD() const
{
*size = 0;
u32 tmd_size;
u32 tmd_address;
@ -136,10 +135,10 @@ std::unique_ptr<u8[]> CVolumeWiiCrypted::GetTMD(u32 *size) const
tmd_size = 1024 * 1024 * 4;
}
std::unique_ptr<u8[]> buf{ new u8[tmd_size] };
Read(m_VolumeOffset + tmd_address, tmd_size, buf.get(), false);
*size = tmd_size;
return buf;
std::vector<u8> buffer(tmd_size);
Read(m_VolumeOffset + tmd_address, tmd_size, buffer.data(), false);
return buffer;
}
std::string CVolumeWiiCrypted::GetUniqueID() const

View File

@ -7,6 +7,7 @@
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <mbedtls/aes.h>
#include "Common/CommonTypes.h"
@ -25,7 +26,7 @@ public:
~CVolumeWiiCrypted();
bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const override;
bool GetTitleID(u64* buffer) const override;
std::unique_ptr<u8[]> GetTMD(u32 *_sz) const override;
std::vector<u8> GetTMD() const override;
std::string GetUniqueID() const override;
std::string GetMakerID() const override;
u16 GetRevision() const override;