From e2ae2b3b0b11cc869468bed8a850e2012a68c2d9 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 4 May 2020 12:41:14 +0200 Subject: Add new file format RVZ based on WIA --- Source/Core/DiscIO/Blob.cpp | 1 + Source/Core/DiscIO/Blob.h | 5 +++-- Source/Core/DiscIO/WIABlob.cpp | 35 ++++++++++++++++++++++++----------- Source/Core/DiscIO/WIABlob.h | 16 +++++++++++----- 4 files changed, 39 insertions(+), 18 deletions(-) (limited to 'Source/Core/DiscIO') diff --git a/Source/Core/DiscIO/Blob.cpp b/Source/Core/DiscIO/Blob.cpp index 97e48eb047..c2c44caa60 100644 --- a/Source/Core/DiscIO/Blob.cpp +++ b/Source/Core/DiscIO/Blob.cpp @@ -207,6 +207,7 @@ std::unique_ptr CreateBlobReader(const std::string& filename) case WBFS_MAGIC: return WbfsFileReader::Create(std::move(file), filename); case WIA_MAGIC: + case RVZ_MAGIC: return WIAFileReader::Create(std::move(file), filename); default: if (auto directory_blob = DirectoryBlobReader::Create(filename)) diff --git a/Source/Core/DiscIO/Blob.h b/Source/Core/DiscIO/Blob.h index 49e42e6741..149df2afc3 100644 --- a/Source/Core/DiscIO/Blob.h +++ b/Source/Core/DiscIO/Blob.h @@ -37,7 +37,8 @@ enum class BlobType CISO, WBFS, TGC, - WIA + WIA, + RVZ, }; class BlobReader @@ -176,7 +177,7 @@ bool ConvertToPlain(BlobReader* infile, const std::string& infile_path, const std::string& outfile_path, CompressCB callback = nullptr, void* arg = nullptr); bool ConvertToWIA(BlobReader* infile, const std::string& infile_path, - const std::string& outfile_path, WIACompressionType compression_type, + const std::string& outfile_path, bool rvz, WIACompressionType compression_type, int compression_level, int chunk_size, CompressCB callback = nullptr, void* arg = nullptr); diff --git a/Source/Core/DiscIO/WIABlob.cpp b/Source/Core/DiscIO/WIABlob.cpp index 1924c7d08d..7414c48221 100644 --- a/Source/Core/DiscIO/WIABlob.cpp +++ b/Source/Core/DiscIO/WIABlob.cpp @@ -51,14 +51,21 @@ bool WIAFileReader::Initialize(const std::string& path) if (!m_file.Seek(0, SEEK_SET) || !m_file.ReadArray(&m_header_1, 1)) return false; - if (m_header_1.magic != WIA_MAGIC) + if (m_header_1.magic != WIA_MAGIC && m_header_1.magic != RVZ_MAGIC) return false; - const u32 version = Common::swap32(m_header_1.version); - const u32 version_compatible = Common::swap32(m_header_1.version_compatible); - if (WIA_VERSION < version_compatible || WIA_VERSION_READ_COMPATIBLE > version) + m_rvz = m_header_1.magic == RVZ_MAGIC; + + const u32 version = m_rvz ? RVZ_VERSION : WIA_VERSION; + const u32 version_read_compatible = + m_rvz ? RVZ_VERSION_READ_COMPATIBLE : WIA_VERSION_READ_COMPATIBLE; + + const u32 file_version = Common::swap32(m_header_1.version); + const u32 file_version_compatible = Common::swap32(m_header_1.version_compatible); + + if (version < file_version_compatible || version_read_compatible > file_version) { - ERROR_LOG(DISCIO, "Unsupported WIA version %s in %s", VersionToString(version).c_str(), + ERROR_LOG(DISCIO, "Unsupported version %s in %s", VersionToString(file_version).c_str(), path.c_str()); return false; } @@ -229,6 +236,11 @@ std::unique_ptr WIAFileReader::Create(File::IOFile file, const st return blob->m_valid ? std::move(blob) : nullptr; } +BlobType WIAFileReader::GetBlobType() const +{ + return m_rvz ? BlobType::RVZ : BlobType::WIA; +} + bool WIAFileReader::Read(u64 offset, u64 size, u8* out_ptr) { if (offset + size > Common::swap64(m_header_1.iso_file_size)) @@ -1730,7 +1742,7 @@ bool WIAFileReader::WriteHeader(File::IOFile* file, const u8* data, size_t size, ConversionResultCode WIAFileReader::ConvertToWIA(BlobReader* infile, const VolumeDisc* infile_volume, - File::IOFile* outfile, WIACompressionType compression_type, + File::IOFile* outfile, bool rvz, WIACompressionType compression_type, int compression_level, int chunk_size, CompressCB callback, void* arg) { ASSERT(infile->IsDataSizeAccurate()); @@ -1952,9 +1964,10 @@ WIAFileReader::ConvertToWIA(BlobReader* infile, const VolumeDisc* infile_volume, header_2.group_entries_offset = Common::swap64(group_entries_offset); header_2.group_entries_size = Common::swap32(static_cast(compressed_group_entries->size())); - header_1.magic = WIA_MAGIC; - header_1.version = Common::swap32(WIA_VERSION); - header_1.version_compatible = Common::swap32(WIA_VERSION_WRITE_COMPATIBLE); + header_1.magic = rvz ? RVZ_MAGIC : WIA_MAGIC; + header_1.version = Common::swap32(rvz ? RVZ_VERSION : WIA_VERSION); + header_1.version_compatible = + Common::swap32(rvz ? RVZ_VERSION_WRITE_COMPATIBLE : WIA_VERSION_WRITE_COMPATIBLE); header_1.header_2_size = Common::swap32(sizeof(WIAHeader2)); mbedtls_sha1_ret(reinterpret_cast(&header_2), sizeof(header_2), header_1.header_2_hash.data()); @@ -1975,7 +1988,7 @@ WIAFileReader::ConvertToWIA(BlobReader* infile, const VolumeDisc* infile_volume, } bool ConvertToWIA(BlobReader* infile, const std::string& infile_path, - const std::string& outfile_path, WIACompressionType compression_type, + const std::string& outfile_path, bool rvz, WIACompressionType compression_type, int compression_level, int chunk_size, CompressCB callback, void* arg) { File::IOFile outfile(outfile_path, "wb"); @@ -1991,7 +2004,7 @@ bool ConvertToWIA(BlobReader* infile, const std::string& infile_path, std::unique_ptr infile_volume = CreateDisc(infile_path); const ConversionResultCode result = - WIAFileReader::ConvertToWIA(infile, infile_volume.get(), &outfile, compression_type, + WIAFileReader::ConvertToWIA(infile, infile_volume.get(), &outfile, rvz, compression_type, compression_level, chunk_size, callback, arg); if (result == ConversionResultCode::ReadFailed) diff --git a/Source/Core/DiscIO/WIABlob.h b/Source/Core/DiscIO/WIABlob.h index 653f7312f3..356d8a3edb 100644 --- a/Source/Core/DiscIO/WIABlob.h +++ b/Source/Core/DiscIO/WIABlob.h @@ -37,6 +37,7 @@ enum class WIACompressionType : u32 }; constexpr u32 WIA_MAGIC = 0x01414957; // "WIA\x1" (byteswapped to little endian) +constexpr u32 RVZ_MAGIC = 0x015A5652; // "RVZ\x1" (byteswapped to little endian) class WIAFileReader : public BlobReader { @@ -45,7 +46,7 @@ public: static std::unique_ptr Create(File::IOFile file, const std::string& path); - BlobType GetBlobType() const override { return BlobType::WIA; } + BlobType GetBlobType() const override; u64 GetRawSize() const override { return Common::swap64(m_header_1.wia_file_size); } u64 GetDataSize() const override { return Common::swap64(m_header_1.iso_file_size); } @@ -59,7 +60,7 @@ public: bool ReadWiiDecrypted(u64 offset, u64 size, u8* out_ptr, u64 partition_data_offset) override; static ConversionResultCode ConvertToWIA(BlobReader* infile, const VolumeDisc* infile_volume, - File::IOFile* outfile, + File::IOFile* outfile, bool rvz, WIACompressionType compression_type, int compression_level, int chunk_size, CompressCB callback, void* arg); @@ -489,6 +490,7 @@ private: } bool m_valid; + bool m_rvz; WIACompressionType m_compression_type; File::IOFile m_file; @@ -504,13 +506,17 @@ private: std::map m_data_entries; + // Perhaps we could set WIA_VERSION_WRITE_COMPATIBLE to 0.9, but WIA version 0.9 was never in + // any official release of wit, and interim versions (either source or binaries) are hard to find. + // Since we've been unable to check if we're write compatible with 0.9, we set it 1.0 to be safe. + static constexpr u32 WIA_VERSION = 0x01000000; static constexpr u32 WIA_VERSION_WRITE_COMPATIBLE = 0x01000000; static constexpr u32 WIA_VERSION_READ_COMPATIBLE = 0x00080000; - // Perhaps we could set WIA_VERSION_WRITE_COMPATIBLE to 0.9, but WIA version 0.9 was never in - // any official release of wit, and interim versions (either source or binaries) are hard to find. - // Since we've been unable to check if we're write compatible with 0.9, we set it 1.0 to be safe. + static constexpr u32 RVZ_VERSION = 0x00010000; + static constexpr u32 RVZ_VERSION_WRITE_COMPATIBLE = 0x00010000; + static constexpr u32 RVZ_VERSION_READ_COMPATIBLE = 0x00010000; }; } // namespace DiscIO -- cgit v1.2.3