diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp index 6081a6f847..e2967565d0 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp @@ -79,11 +79,11 @@ CWII_IPC_HLE_Device_es::CWII_IPC_HLE_Device_es(u32 _DeviceID, const std::string& // here should be code to scan for the title ids in the NAND m_TitleIDs.clear(); - m_TitleIDs.push_back(0x0000000100000002ULL); -/* m_TitleIDs.push_back(0x0001000248414741ULL); - m_TitleIDs.push_back(0x0001000248414341ULL); - m_TitleIDs.push_back(0x0001000248414241ULL); - m_TitleIDs.push_back(0x0001000248414141ULL);*/ + /*m_TitleIDs.push_back(0x0000000100000002ULL); + m_TitleIDs.push_back(0x0001000248414741ULL); // TMD Size: 0x8c + m_TitleIDs.push_back(0x0001000248414341ULL); // TMD Size: 0xac +/* m_TitleIDs.push_back(0x0001000248414241ULL); + m_TitleIDs.push_back(0x0001000248414141ULL); */ INFO_LOG(WII_IPC_ES, "Set default title to %08x/%08x", m_TitleID>>32, m_TitleID); @@ -140,8 +140,9 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress) u64 TitleID = Memory::Read_U64(Buffer.InBuffer[0].m_Address); DiscIO::CNANDContentLoader& rNANDCOntent = AccessContentDevice(TitleID); + _dbg_assert_(WII_IPC_ES, rNANDCOntent.IsValid()); - Memory::Write_U32(rNANDCOntent.GetContentSize(), Buffer.PayloadBuffer[0].m_Address); + Memory::Write_U32((u32)rNANDCOntent.GetContentSize(), Buffer.PayloadBuffer[0].m_Address); INFO_LOG(WII_IPC_ES, "ES: IOCTL_ES_GETTITLECONTENTSCNT: TitleID: %08x/%08x content count %i", TitleID>>32, TitleID, rNANDCOntent.GetContentSize()); @@ -151,6 +152,38 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress) } break; + case IOCTL_ES_GETTITLECONTENTS: + { + _dbg_assert_msg_(WII_IPC_ES, Buffer.NumberInBuffer == 2, "CWII_IPC_HLE_Device_es: IOCTL_ES_GETTITLECONTENTS no in buffer"); + _dbg_assert_msg_(WII_IPC_ES, Buffer.NumberPayloadBuffer == 1, "CWII_IPC_HLE_Device_es: IOCTL_ES_GETTITLECONTENTS no out buffer"); + + u64 TitleID = Memory::Read_U64(Buffer.InBuffer[0].m_Address); + u32 MaxCount = Memory::Read_U32(Buffer.InBuffer[1].m_Address); + std::string TitleFilename = CreateTitleContentPath(TitleID); + DiscIO::CNANDContentLoader Loader(TitleFilename); + + ERROR_LOG(WII_IPC_ES, "IOCTL_ES_GETTITLECONTENTS: title: %08x/%08x buffersize: %i", TitleID >> 32, TitleID, MaxCount); + + u32 Count = 0; + if (Loader.IsValid()) + { + const std::vector& rContent = Loader.GetContent(); + for (size_t i=0; i=MaxCount) + break; + } + } + Memory::Write_U32(0, _CommandAddress + 0x4); + ERROR_LOG(WII_IPC_ES, "IOCTL_ES_GETTITLECONTENTS: Count %i", Count); + return true; + } + break; + + case IOCTL_ES_OPENTITLECONTENT: { _dbg_assert_(WII_IPC_ES, Buffer.NumberInBuffer == 3); @@ -318,7 +351,7 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress) _dbg_assert_msg_(WII_IPC_ES, Buffer.NumberPayloadBuffer == 1, "IOCTL_ES_GETTITLECNT has no out buffer"); _dbg_assert_msg_(WII_IPC_ES, Buffer.PayloadBuffer[0].m_Size == 4, "IOCTL_ES_GETTITLECNT payload[0].size != 4"); - Memory::Write_U32(m_TitleIDs.size(), Buffer.PayloadBuffer[0].m_Address); + Memory::Write_U32((u32)m_TitleIDs.size(), Buffer.PayloadBuffer[0].m_Address); ERROR_LOG(WII_IPC_ES, "IOCTL_ES_GETTITLECNT: Number of Titles %i", m_TitleIDs.size()); @@ -431,6 +464,76 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress) } break; + case IOCTL_ES_GETTMDVIEWCNT: + { + _dbg_assert_msg_(WII_IPC_ES, Buffer.NumberInBuffer == 1, "CWII_IPC_HLE_Device_es: IOCTL_ES_GETTMDVIEWCNT no in buffer"); + _dbg_assert_msg_(WII_IPC_ES, Buffer.NumberPayloadBuffer == 1, "CWII_IPC_HLE_Device_es: IOCTL_ES_GETTMDVIEWCNT no out buffer"); + + u64 TitleID = Memory::Read_U64(Buffer.InBuffer[0].m_Address); + std::string TitleFilename = CreateTitleContentPath(TitleID); + DiscIO::CNANDContentLoader Loader(TitleFilename); + + _dbg_assert_(WII_IPC_ES, Loader.IsValid()); + u32 TMDViewCnt = 0; + if (Loader.IsValid()) + { + TMDViewCnt += DiscIO::CNANDContentLoader::TICKET_VIEW_SIZE; + TMDViewCnt += 2; // title version + TMDViewCnt += 2; // num entries + TMDViewCnt += Loader.GetContentSize() * (4+2+2+8); // content id, index, type, size + } + Memory::Write_U32(TMDViewCnt, Buffer.PayloadBuffer[0].m_Address); + + Memory::Write_U32(0, _CommandAddress + 0x4); + + INFO_LOG(WII_IPC_ES, "IOCTL_ES_GETTMDVIEWCNT: title: %08x/%08x -> count %i", TitleID >> 32, TitleID, TMDViewCnt); + + return true; + } + break; + + case IOCTL_ES_GETTMDVIEWS: + { + _dbg_assert_msg_(WII_IPC_ES, Buffer.NumberInBuffer == 2, "CWII_IPC_HLE_Device_es: IOCTL_ES_GETTMDVIEWCNT no in buffer"); + _dbg_assert_msg_(WII_IPC_ES, Buffer.NumberPayloadBuffer == 1, "CWII_IPC_HLE_Device_es: IOCTL_ES_GETTMDVIEWCNT no out buffer"); + + u64 TitleID = Memory::Read_U64(Buffer.InBuffer[0].m_Address); + u32 MaxCount = Memory::Read_U32(Buffer.InBuffer[1].m_Address); + std::string TitleFilename = CreateTitleContentPath(TitleID); + DiscIO::CNANDContentLoader Loader(TitleFilename); + + INFO_LOG(WII_IPC_ES, "IOCTL_ES_GETTMDVIEWCNT: title: %08x/%08x buffersize: %i", TitleID >> 32, TitleID, MaxCount); + + u32 Count = 0; + u8* p = Memory::GetPointer(Buffer.PayloadBuffer[0].m_Address); + if (Loader.IsValid()) + { + u32 Address = Buffer.PayloadBuffer[0].m_Address; + + Memory::WriteBigEData(Loader.GetTicket(), Address, DiscIO::CNANDContentLoader::TICKET_VIEW_SIZE); + Address += DiscIO::CNANDContentLoader::TICKET_VIEW_SIZE; + + Memory::Write_U16(Loader.GetTitleVersion(), Address); Address += 2; + Memory::Write_U16(Loader.GetNumEntries(), Address); Address += 2; + + const std::vector& rContent = Loader.GetContent(); + for (size_t i=0; i> 32, TitleID); - } - break; - case IOCTL_ES_GETCONSUMPTION: // (Input: 8 bytes, Output: 0 bytes, 4 bytes) _dbg_assert_msg_(WII_IPC_ES, 0, "IOCTL_ES_GETCONSUMPTION: this looks really wrong..."); break; @@ -483,7 +575,6 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress) _dbg_assert_msg_(WII_IPC_ES, 0, "IOCTL_ES_DIGETTICKETVIEW: this looks really wrong..."); break; - default: _dbg_assert_msg_(WII_IPC_ES, 0, "CWII_IPC_HLE_Device_es: 0x%x", Buffer.Parameter); @@ -510,7 +601,7 @@ DiscIO::CNANDContentLoader& CWII_IPC_HLE_Device_es::AccessContentDevice(u64 _Tit if (itr != m_NANDContent.end()) return *itr->second; - std::string TitleFilename = CreateTitleFileName(_TitleID); + std::string TitleFilename = CreateTitleContentPath(_TitleID); m_NANDContent[_TitleID] = new DiscIO::CNANDContentLoader(TitleFilename); _dbg_assert_(WII_IPC_ES, m_NANDContent[_TitleID]->IsValid()); @@ -533,10 +624,11 @@ std::string CWII_IPC_HLE_Device_es::CreateTicketFileName(u64 _TitleID) const return TicketFilename; } -std::string CWII_IPC_HLE_Device_es::CreateTitleFileName(u64 _TitleID) const +std::string CWII_IPC_HLE_Device_es::CreateTitleContentPath(u64 _TitleID) const { char TicketFilename[1024]; - sprintf(TicketFilename, "%stitle/%08x/%08x.app", FULL_WII_USER_DIR, (u32)(_TitleID >> 32), (u32)_TitleID); + sprintf(TicketFilename, "%stitle/%08x/%08x/content", FULL_WII_USER_DIR, (u32)(_TitleID >> 32), (u32)_TitleID); return TicketFilename; -} \ No newline at end of file +} + diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.h index 93831bc611..61b83c64c9 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.h @@ -122,7 +122,7 @@ private: bool IsValid(u64 _TitleID) const; std::string CreateTicketFileName(u64 _TitleID) const; - std::string CreateTitleFileName(u64 _TitleID) const; + std::string CreateTitleContentPath(u64 _TitleID) const; }; #endif diff --git a/Source/Core/DiscIO/Src/NANDContentLoader.cpp b/Source/Core/DiscIO/Src/NANDContentLoader.cpp index 802b722406..3e29a2f799 100644 --- a/Source/Core/DiscIO/Src/NANDContentLoader.cpp +++ b/Source/Core/DiscIO/Src/NANDContentLoader.cpp @@ -177,14 +177,17 @@ bool CNANDContentLoader::CreateFromDirectory(const std::string& _rPath) fread(pTMD, Size, 1, pTMDFile); fclose(pTMDFile); + memcpy(m_TicketView, pTMD + 0x180, TICKET_VIEW_SIZE); + ////// - u32 numEntries = Common::swap16(pTMD + 0x01de); + m_TileVersion = Common::swap16(pTMD + 0x01dc); + m_numEntries = Common::swap16(pTMD + 0x01de); m_BootIndex = Common::swap16(pTMD + 0x01e0); m_TitleID = Common::swap64(pTMD + 0x018C); - m_Content.resize(numEntries); + m_Content.resize(m_numEntries); - for (u32 i = 0; i < numEntries; i++) + for (u32 i = 0; i < m_numEntries; i++) { SNANDContent& rContent = m_Content[i]; diff --git a/Source/Core/DiscIO/Src/NANDContentLoader.h b/Source/Core/DiscIO/Src/NANDContentLoader.h index f6d188fd76..7757f7440c 100644 --- a/Source/Core/DiscIO/Src/NANDContentLoader.h +++ b/Source/Core/DiscIO/Src/NANDContentLoader.h @@ -49,14 +49,29 @@ public: u32 GetBootIndex() const { return m_BootIndex; } size_t GetContentSize() const { return m_Content.size(); } SNANDContent* GetContentByIndex(int _Index); + const u8* GetTicket() const { return m_TicketView; } + + const std::vector& GetContent() const { return m_Content; } static bool IsWiiWAD(const std::string& _rName); + const u16 GetTitleVersion() const {return m_TileVersion;} + const u16 GetNumEntries() const {return m_numEntries;} + + + enum + { + TICKET_VIEW_SIZE = 0x58 + }; + private: bool m_Valid; u64 m_TitleID; u32 m_BootIndex; + u16 m_numEntries; + u16 m_TileVersion; + u8 m_TicketView[TICKET_VIEW_SIZE]; std::vector m_Content;