From 4bb48d09dd42278b1b97483bcf4a353a3573409e Mon Sep 17 00:00:00 2001 From: magumagu Date: Sun, 15 Jun 2014 21:27:23 -0700 Subject: [PATCH] DiskIO: Clean up GetTMD() API. --- Source/Core/Core/Boot/Boot.cpp | 10 ++++------ Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp | 10 +++++----- Source/Core/DiscIO/Volume.h | 7 ++++++- Source/Core/DiscIO/VolumeWiiCrypted.cpp | 6 ++++-- Source/Core/DiscIO/VolumeWiiCrypted.h | 2 +- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index 6f318288ed..349ea0893c 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -225,14 +225,12 @@ bool CBoot::BootUp() DVDInterface::SetDiscInside(VolumeHandler::IsValid()); - u32 _TMDsz = 0x208; - u8* _pTMD = new u8[_TMDsz]; - pVolume->GetTMD(_pTMD, &_TMDsz); - if (_TMDsz) + u32 tmd_size; + std::unique_ptr tmd_buf = pVolume->GetTMD(&tmd_size); + if (tmd_size) { - WII_IPC_HLE_Interface::ES_DIVerify(_pTMD, _TMDsz); + WII_IPC_HLE_Interface::ES_DIVerify(tmd_buf.get(), tmd_size); } - delete []_pTMD; _StartupPara.bWii = VolumeHandler::IsWii(); 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 5053a6842c..aef2190d1a 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 @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include "Common/CommonTypes.h" #include "Common/Logging/LogManager.h" @@ -113,11 +114,10 @@ bool 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 - u8 pTMD[0x800]; - u32 tmdSz; - VolumeHandler::GetVolume()->GetTMD(pTMD, &tmdSz); - Memory::CopyToEmu(CommandBuffer.PayloadBuffer[0].m_Address, pTMD, tmdSz); - WII_IPC_HLE_Interface::ES_DIVerify(pTMD, tmdSz); + u32 tmd_size; + std::unique_ptr tmd_buf = VolumeHandler::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); ReturnValue = 1; } diff --git a/Source/Core/DiscIO/Volume.h b/Source/Core/DiscIO/Volume.h index 7391c6b0c3..6162e0db8f 100644 --- a/Source/Core/DiscIO/Volume.h +++ b/Source/Core/DiscIO/Volume.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include @@ -20,7 +21,11 @@ public: virtual bool Read(u64 _Offset, u64 _Length, u8* _pBuffer) const = 0; virtual bool RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const = 0; virtual bool GetTitleID(u8*) const { return false; } - virtual void GetTMD(u8*, u32 *_sz) const { *_sz=0; } + virtual std::unique_ptr GetTMD(u32 *_sz) const + { + *_sz = 0; + return std::unique_ptr(); + } virtual std::string GetUniqueID() const = 0; virtual std::string GetRevisionSpecificUniqueID() const { return ""; } virtual std::string GetMakerID() const = 0; diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.cpp b/Source/Core/DiscIO/VolumeWiiCrypted.cpp index d00b38c37b..e83554fb07 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.cpp +++ b/Source/Core/DiscIO/VolumeWiiCrypted.cpp @@ -108,7 +108,7 @@ bool CVolumeWiiCrypted::GetTitleID(u8* _pBuffer) const // TitleID offset in tik is 0x1DC return RAWRead(m_VolumeOffset + 0x1DC, 8, _pBuffer); } -void CVolumeWiiCrypted::GetTMD(u8* _pBuffer, u32 * _sz) const +std::unique_ptr CVolumeWiiCrypted::GetTMD(u32 *_sz) const { *_sz = 0; u32 tmdSz, @@ -118,8 +118,10 @@ void CVolumeWiiCrypted::GetTMD(u8* _pBuffer, u32 * _sz) const RAWRead(m_VolumeOffset + 0x2a8, sizeof(u32), (u8*)&tmdAddr); tmdSz = Common::swap32(tmdSz); tmdAddr = Common::swap32(tmdAddr) << 2; - RAWRead(m_VolumeOffset + tmdAddr, tmdSz, _pBuffer); + std::unique_ptr buf{new u8[tmdSz]}; + RAWRead(m_VolumeOffset + tmdAddr, tmdSz, buf.get()); *_sz = tmdSz; + return buf; } std::string CVolumeWiiCrypted::GetUniqueID() const diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.h b/Source/Core/DiscIO/VolumeWiiCrypted.h index e984d61062..cd4fb5599d 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.h +++ b/Source/Core/DiscIO/VolumeWiiCrypted.h @@ -27,7 +27,7 @@ public: bool Read(u64 _Offset, u64 _Length, u8* _pBuffer) const override; bool RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const override; bool GetTitleID(u8* _pBuffer) const override; - void GetTMD(u8* _pBuffer, u32* _sz) const override; + virtual std::unique_ptr GetTMD(u32 *_sz) const override; std::string GetUniqueID() const override; std::string GetMakerID() const override; std::vector GetNames() const override;