diff --git a/Source/Core/DiscIO/DirectoryBlob.cpp b/Source/Core/DiscIO/DirectoryBlob.cpp index f731e9b13f..0396e7ecf2 100644 --- a/Source/Core/DiscIO/DirectoryBlob.cpp +++ b/Source/Core/DiscIO/DirectoryBlob.cpp @@ -97,11 +97,15 @@ bool DiscContent::Read(u64* offset, u64* length, u8** buffer) const { const u64 bytes_to_read = std::min(m_size - offset_in_content, *length); - if (std::holds_alternative(m_content_source)) + if (std::holds_alternative(m_content_source)) { - File::IOFile file(std::get(m_content_source), "rb"); - if (!file.Seek(offset_in_content, SEEK_SET) || !file.ReadBytes(*buffer, bytes_to_read)) + const auto& content = std::get(m_content_source); + File::IOFile file(content.m_filename, "rb"); + if (!file.Seek(content.m_offset + offset_in_content, SEEK_SET) || + !file.ReadBytes(*buffer, bytes_to_read)) + { return false; + } } else if (std::holds_alternative(m_content_source)) { @@ -136,14 +140,14 @@ void DiscContentContainer::Add(u64 offset, u64 size, ContentSource source) u64 DiscContentContainer::CheckSizeAndAdd(u64 offset, const std::string& path) { const u64 size = File::GetSize(path); - Add(offset, size, path); + Add(offset, size, ContentFile{path, 0}); return size; } u64 DiscContentContainer::CheckSizeAndAdd(u64 offset, u64 max_size, const std::string& path) { const u64 size = std::min(File::GetSize(path), max_size); - Add(offset, size, path); + Add(offset, size, ContentFile{path, 0}); return size; } @@ -791,7 +795,7 @@ void DirectoryBlobPartition::WriteDirectory(const File::FSTEntry& parent_entry, WriteEntryName(name_offset, entry.virtualName, name_table_offset); // write entry to virtual disc - m_contents.Add(*data_offset, entry.size, entry.physicalName); + m_contents.Add(*data_offset, entry.size, ContentFile{entry.physicalName, 0}); // 32 KiB aligned - many games are fine with less alignment, but not all *data_offset = Common::AlignUp(*data_offset + entry.size, 0x8000ull); diff --git a/Source/Core/DiscIO/DirectoryBlob.h b/Source/Core/DiscIO/DirectoryBlob.h index 93679045dc..ff7c8e6182 100644 --- a/Source/Core/DiscIO/DirectoryBlob.h +++ b/Source/Core/DiscIO/DirectoryBlob.h @@ -33,8 +33,18 @@ class DirectoryBlobReader; // Returns true if the path is inside a DirectoryBlob and doesn't represent the DirectoryBlob itself bool ShouldHideFromGameList(const std::string& volume_path); +// Content chunk that is loaded from a file in the host file system. +struct ContentFile +{ + // Path where the file can be found. + std::string m_filename; + + // Offset from the start of the file where the first byte of this content chunk is. + u64 m_offset; +}; + using ContentSource = - std::variant;