From 333b6d99d2370fe1c9ef769771d8ae04178ff105 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 4 Jul 2017 16:08:12 +0200 Subject: [PATCH] VolumeWii: Change the format of partition maps Having a separate map for each type of data is a bit unnecessary. --- Source/Core/DiscIO/VolumeWii.cpp | 32 +++++++++++++++----------------- Source/Core/DiscIO/VolumeWii.h | 13 +++++++++---- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Source/Core/DiscIO/VolumeWii.cpp b/Source/Core/DiscIO/VolumeWii.cpp index 93c7133036..cf570e39ea 100644 --- a/Source/Core/DiscIO/VolumeWii.cpp +++ b/Source/Core/DiscIO/VolumeWii.cpp @@ -107,10 +107,8 @@ VolumeWii::VolumeWii(std::unique_ptr reader) // We've read everything. Time to store it! (The reason we don't store anything // earlier is because we want to be able to skip adding the partition if an error occurs.) const Partition partition(partition_offset); - m_partition_types[partition] = *partition_type; - m_partition_keys[partition] = std::move(aes_context); - m_partition_tickets[partition] = std::move(ticket); - m_partition_tmds[partition] = std::move(tmd); + m_partitions.emplace(partition, PartitionDetails{std::move(aes_context), std::move(ticket), + std::move(tmd), *partition_type}); if (m_game_partition == PARTITION_NONE && *partition_type == 0) m_game_partition = partition; } @@ -127,10 +125,10 @@ bool VolumeWii::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer, const Partition return m_pReader->Read(_ReadOffset, _Length, _pBuffer); // Get the decryption key for the partition - auto it = m_partition_keys.find(partition); - if (it == m_partition_keys.end()) + auto it = m_partitions.find(partition); + if (it == m_partitions.end()) return false; - mbedtls_aes_context* aes_context = it->second.get(); + mbedtls_aes_context* aes_context = it->second.key.get(); std::vector read_buffer(BLOCK_TOTAL_SIZE); while (_Length > 0) @@ -177,7 +175,7 @@ bool VolumeWii::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer, const Partition std::vector VolumeWii::GetPartitions() const { std::vector partitions; - for (const auto& pair : m_partition_keys) + for (const auto& pair : m_partitions) partitions.push_back(pair.first); return partitions; } @@ -189,8 +187,8 @@ Partition VolumeWii::GetGamePartition() const std::optional VolumeWii::GetPartitionType(const Partition& partition) const { - auto it = m_partition_types.find(partition); - return it != m_partition_types.end() ? it->second : std::optional(); + auto it = m_partitions.find(partition); + return it != m_partitions.end() ? it->second.type : std::optional(); } std::optional VolumeWii::GetTitleID(const Partition& partition) const @@ -203,14 +201,14 @@ std::optional VolumeWii::GetTitleID(const Partition& partition) const const IOS::ES::TicketReader& VolumeWii::GetTicket(const Partition& partition) const { - auto it = m_partition_tickets.find(partition); - return it != m_partition_tickets.end() ? it->second : INVALID_TICKET; + auto it = m_partitions.find(partition); + return it != m_partitions.end() ? it->second.ticket : INVALID_TICKET; } const IOS::ES::TMDReader& VolumeWii::GetTMD(const Partition& partition) const { - auto it = m_partition_tmds.find(partition); - return it != m_partition_tmds.end() ? it->second : INVALID_TMD; + auto it = m_partitions.find(partition); + return it != m_partitions.end() ? it->second.tmd : INVALID_TMD; } u64 VolumeWii::PartitionOffsetToRawOffset(u64 offset, const Partition& partition) @@ -338,10 +336,10 @@ u64 VolumeWii::GetRawSize() const bool VolumeWii::CheckIntegrity(const Partition& partition) const { // Get the decryption key for the partition - auto it = m_partition_keys.find(partition); - if (it == m_partition_keys.end()) + auto it = m_partitions.find(partition); + if (it == m_partitions.end()) return false; - mbedtls_aes_context* aes_context = it->second.get(); + mbedtls_aes_context* aes_context = it->second.key.get(); // Get partition data size u32 partSizeDiv4; diff --git a/Source/Core/DiscIO/VolumeWii.h b/Source/Core/DiscIO/VolumeWii.h index 780bdb6dd4..d8cdfe8cb8 100644 --- a/Source/Core/DiscIO/VolumeWii.h +++ b/Source/Core/DiscIO/VolumeWii.h @@ -64,11 +64,16 @@ public: static constexpr unsigned int BLOCK_TOTAL_SIZE = BLOCK_HEADER_SIZE + BLOCK_DATA_SIZE; private: + struct PartitionDetails + { + std::unique_ptr key; + IOS::ES::TicketReader ticket; + IOS::ES::TMDReader tmd; + u32 type; + }; + std::unique_ptr m_pReader; - std::map m_partition_types; - std::map> m_partition_keys; - std::map m_partition_tickets; - std::map m_partition_tmds; + std::map m_partitions; Partition m_game_partition; mutable u64 m_last_decrypted_block;