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/DiscExtractor.cpp | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'Source/Core/DiscIO/DiscExtractor.cpp') diff --git a/Source/Core/DiscIO/DiscExtractor.cpp b/Source/Core/DiscIO/DiscExtractor.cpp index 1220aadd50..4ebaf249fd 100644 --- a/Source/Core/DiscIO/DiscExtractor.cpp +++ b/Source/Core/DiscIO/DiscExtractor.cpp @@ -160,13 +160,13 @@ bool ExportTMD(const Volume& volume, const Partition& partition, const std::stri if (volume.GetVolumeType() != Platform::WII_DISC) return false; - std::optional size = volume.ReadSwapped(partition.offset + 0x2a4, PARTITION_NONE); - std::optional offset = volume.ReadSwapped(partition.offset + 0x2a8, PARTITION_NONE); + const std::optional size = volume.ReadSwapped(partition.offset + 0x2a4, PARTITION_NONE); + const std::optional offset = + volume.ReadSwappedAndShifted(partition.offset + 0x2a8, PARTITION_NONE); if (!size || !offset) return false; - const u64 actual_offset = partition.offset + (static_cast(*offset) << 2); - return ExportData(volume, PARTITION_NONE, actual_offset, *size, export_filename); + return ExportData(volume, PARTITION_NONE, *offset, *size, export_filename); } bool ExportCertificateChain(const Volume& volume, const Partition& partition, @@ -175,13 +175,13 @@ bool ExportCertificateChain(const Volume& volume, const Partition& partition, if (volume.GetVolumeType() != Platform::WII_DISC) return false; - std::optional size = volume.ReadSwapped(partition.offset + 0x2ac, PARTITION_NONE); - std::optional offset = volume.ReadSwapped(partition.offset + 0x2b0, PARTITION_NONE); + const std::optional size = volume.ReadSwapped(partition.offset + 0x2ac, PARTITION_NONE); + const std::optional offset = + volume.ReadSwappedAndShifted(partition.offset + 0x2b0, PARTITION_NONE); if (!size || !offset) return false; - const u64 actual_offset = partition.offset + (static_cast(*offset) << 2); - return ExportData(volume, PARTITION_NONE, actual_offset, *size, export_filename); + return ExportData(volume, PARTITION_NONE, *offset, *size, export_filename); } bool ExportH3Hashes(const Volume& volume, const Partition& partition, @@ -190,12 +190,12 @@ bool ExportH3Hashes(const Volume& volume, const Partition& partition, if (volume.GetVolumeType() != Platform::WII_DISC) return false; - std::optional offset = volume.ReadSwapped(partition.offset + 0x2b4, PARTITION_NONE); + const std::optional offset = + volume.ReadSwappedAndShifted(partition.offset + 0x2b4, PARTITION_NONE); if (!offset) return false; - const u64 actual_offset = partition.offset + (static_cast(*offset) << 2); - return ExportData(volume, PARTITION_NONE, actual_offset, 0x18000, export_filename); + return ExportData(volume, PARTITION_NONE, *offset, 0x18000, export_filename); } bool ExportHeader(const Volume& volume, const Partition& partition, @@ -239,9 +239,7 @@ std::optional GetBootDOLOffset(const Volume& volume, const Partition& parti if (!IsDisc(volume_type)) return {}; - const std::optional offset = volume.ReadSwapped(0x420, partition); - const u8 offset_shift = volume_type == Platform::WII_DISC ? 2 : 0; - return offset ? static_cast(*offset) << offset_shift : std::optional(); + return volume.ReadSwappedAndShifted(0x420, partition); } std::optional GetBootDOLSize(const Volume& volume, const Partition& partition, u64 dol_offset) @@ -295,9 +293,7 @@ std::optional GetFSTOffset(const Volume& volume, const Partition& partition if (!IsDisc(volume_type)) return {}; - const std::optional offset = volume.ReadSwapped(0x424, partition); - const u8 offset_shift = volume_type == Platform::WII_DISC ? 2 : 0; - return offset ? static_cast(*offset) << offset_shift : std::optional(); + return volume.ReadSwappedAndShifted(0x424, partition); } std::optional GetFSTSize(const Volume& volume, const Partition& partition) @@ -306,9 +302,7 @@ std::optional GetFSTSize(const Volume& volume, const Partition& partition) if (!IsDisc(volume_type)) return {}; - const std::optional size = volume.ReadSwapped(0x428, partition); - const u8 offset_shift = volume_type == Platform::WII_DISC ? 2 : 0; - return size ? static_cast(*size) << offset_shift : std::optional(); + return volume.ReadSwappedAndShifted(0x428, partition); } bool ExportFST(const Volume& volume, const Partition& partition, const std::string& export_filename) -- cgit v1.2.3