From cbeb7034eb68a5285535b263ea661fa0e4362590 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 19 Dec 2015 17:52:10 -0500 Subject: [PATCH] Volume: Make GetTMD return a vector --- Source/Core/Core/Boot/Boot.cpp | 7 +-- Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp | 5 +- Source/Core/Core/IPC_HLE/WII_IPC_HLE.h | 3 +- .../Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp | 7 +-- .../Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp | 59 ++++++++++--------- .../Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.h | 2 +- Source/Core/DiscIO/Volume.h | 7 +-- Source/Core/DiscIO/VolumeWiiCrypted.cpp | 11 ++-- Source/Core/DiscIO/VolumeWiiCrypted.h | 3 +- 9 files changed, 50 insertions(+), 54 deletions(-) diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index d7f84b3ec6..46b293c392 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -268,11 +268,10 @@ bool CBoot::BootUp() if (unique_id.size() >= 4) VideoInterface::SetRegionReg(unique_id.at(3)); - u32 tmd_size; - std::unique_ptr tmd_buf = pVolume.GetTMD(&tmd_size); - if (tmd_size) + std::vector 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; diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp index 924073d2b8..89bedf79b4 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp @@ -23,6 +23,7 @@ They will also generate a true or false return for UpdateInterrupts() in WII_IPC #include #include #include +#include #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& tmd) { - CWII_IPC_HLE_Device_es::ES_DIVerify(_pTMD, _sz); + CWII_IPC_HLE_Device_es::ES_DIVerify(tmd); } void SDIO_EventNotify() diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE.h b/Source/Core/Core/IPC_HLE/WII_IPC_HLE.h index 430fedfea3..f442d02a78 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE.h +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE.h @@ -6,6 +6,7 @@ #include #include +#include #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& tmd); void SDIO_EventNotify(); diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp index 04e56a0772..d6e6f59427 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp @@ -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 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 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; } diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp index 73d08cc2e3..6a2a9a9a75 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp @@ -37,6 +37,7 @@ // otherwise we may not get __STDC_FORMAT_MACROS #include #include +#include #include #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& 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; } diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.h b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.h index 9720e766c1..bf9c06a918 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.h +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.h @@ -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& tmd); // This should only be cleared on power reset static std::string m_ContentFile; diff --git a/Source/Core/DiscIO/Volume.h b/Source/Core/DiscIO/Volume.h index 16ef5fddd3..0b7edf61fb 100644 --- a/Source/Core/DiscIO/Volume.h +++ b/Source/Core/DiscIO/Volume.h @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -82,11 +81,7 @@ public: } virtual bool GetTitleID(u64*) const { return false; } - virtual std::unique_ptr GetTMD(u32 *_sz) const - { - *_sz = 0; - return std::unique_ptr(); - } + virtual std::vector GetTMD() const { return {}; } virtual std::string GetUniqueID() const = 0; virtual std::string GetMakerID() const = 0; virtual u16 GetRevision() const = 0; diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.cpp b/Source/Core/DiscIO/VolumeWiiCrypted.cpp index 660dfb1e1e..16747f8782 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.cpp +++ b/Source/Core/DiscIO/VolumeWiiCrypted.cpp @@ -115,9 +115,8 @@ bool CVolumeWiiCrypted::GetTitleID(u64* buffer) const return true; } -std::unique_ptr CVolumeWiiCrypted::GetTMD(u32 *size) const +std::vector CVolumeWiiCrypted::GetTMD() const { - *size = 0; u32 tmd_size; u32 tmd_address; @@ -136,10 +135,10 @@ std::unique_ptr CVolumeWiiCrypted::GetTMD(u32 *size) const tmd_size = 1024 * 1024 * 4; } - std::unique_ptr buf{ new u8[tmd_size] }; - Read(m_VolumeOffset + tmd_address, tmd_size, buf.get(), false); - *size = tmd_size; - return buf; + std::vector buffer(tmd_size); + Read(m_VolumeOffset + tmd_address, tmd_size, buffer.data(), false); + + return buffer; } std::string CVolumeWiiCrypted::GetUniqueID() const diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.h b/Source/Core/DiscIO/VolumeWiiCrypted.h index 84420baf5a..8e0b2d88f8 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.h +++ b/Source/Core/DiscIO/VolumeWiiCrypted.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #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 GetTMD(u32 *_sz) const override; + std::vector GetTMD() const override; std::string GetUniqueID() const override; std::string GetMakerID() const override; u16 GetRevision() const override;