From 5e3c98af1dc06e9530e8c290a43bb702274e6ec3 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Wed, 7 Jun 2017 11:49:34 +0200 Subject: DiscIO: Add a Volume::ReadSwappedAndShifted function This is a fairly common operation, so let's make a utility function for it to cut down on code duplication. --- Source/Core/DiscIO/VolumeWii.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'Source/Core/DiscIO/VolumeWii.cpp') diff --git a/Source/Core/DiscIO/VolumeWii.cpp b/Source/Core/DiscIO/VolumeWii.cpp index 4e8bba6b91..bce96822e7 100644 --- a/Source/Core/DiscIO/VolumeWii.cpp +++ b/Source/Core/DiscIO/VolumeWii.cpp @@ -52,22 +52,22 @@ VolumeWii::VolumeWii(std::unique_ptr reader) if (!number_of_partitions) continue; - std::optional read_buffer = - m_pReader->ReadSwapped(0x40000 + (partition_group * 8) + 4); - if (!read_buffer) + const std::optional partition_table_offset = + ReadSwappedAndShifted(0x40000 + (partition_group * 8) + 4, PARTITION_NONE); + if (!partition_table_offset) continue; - const u64 partition_table_offset = static_cast(*read_buffer) << 2; for (u32 i = 0; i < number_of_partitions; i++) { - read_buffer = m_pReader->ReadSwapped(partition_table_offset + (i * 8)); - if (!read_buffer) + const std::optional partition_offset = + ReadSwappedAndShifted(*partition_table_offset + (i * 8), PARTITION_NONE); + if (!partition_offset) continue; - const u64 partition_offset = static_cast(*read_buffer) << 2; - const Partition partition(partition_offset); + + const Partition partition(*partition_offset); const std::optional partition_type = - m_pReader->ReadSwapped(partition_table_offset + (i * 8) + 4); + m_pReader->ReadSwapped(*partition_table_offset + (i * 8) + 4); if (!partition_type) continue; @@ -84,10 +84,10 @@ VolumeWii::VolumeWii(std::unique_ptr reader) auto get_tmd = [this, partition]() -> IOS::ES::TMDReader { const std::optional tmd_size = m_pReader->ReadSwapped(partition.offset + 0x2a4); - std::optional tmd_address = m_pReader->ReadSwapped(partition.offset + 0x2a8); + const std::optional tmd_address = + ReadSwappedAndShifted(partition.offset + 0x2a8, PARTITION_NONE); if (!tmd_size || !tmd_address) return INVALID_TMD; - *tmd_address <<= 2; if (!IOS::ES::IsValidTMDSize(*tmd_size)) { // This check is normally done by ES in ES_DiVerify, but that would happen too late -- cgit v1.2.3