From ee2b88ebb627869a6153fe3135df232793f02e87 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 2 Aug 2015 17:39:03 +0200 Subject: [PATCH] Filesystem: Store pointer to beginning of FST in file infos Needed for the next commit. --- Source/Core/DiscIO/FileSystemGCWii.cpp | 18 +++++++++++------- Source/Core/DiscIO/FileSystemGCWii.h | 7 ++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Source/Core/DiscIO/FileSystemGCWii.cpp b/Source/Core/DiscIO/FileSystemGCWii.cpp index 8e8254e21c..9280dbab16 100644 --- a/Source/Core/DiscIO/FileSystemGCWii.cpp +++ b/Source/Core/DiscIO/FileSystemGCWii.cpp @@ -22,8 +22,10 @@ namespace DiscIO { -FileInfoGCWii::FileInfoGCWii(u8 offset_shift, const u8* fst_entry, const u8* name_table_start) - : m_offset_shift(offset_shift), m_fst_entry(fst_entry), m_name_table_start(name_table_start) +constexpr u32 FST_ENTRY_SIZE = 4 * 3; // An FST entry consists of three 32-bit integers + +FileInfoGCWii::FileInfoGCWii(const u8* fst, u8 offset_shift, u32 index, u32 total_file_infos) + : m_fst(fst), m_offset_shift(offset_shift), m_index(index), m_total_file_infos(total_file_infos) { } @@ -33,7 +35,8 @@ FileInfoGCWii::~FileInfoGCWii() u32 FileInfoGCWii::Get(EntryProperty entry_property) const { - return Common::swap32(m_fst_entry + sizeof(u32) * static_cast(entry_property)); + return Common::swap32(m_fst + FST_ENTRY_SIZE * m_index + + sizeof(u32) * static_cast(entry_property)); } u32 FileInfoGCWii::GetSize() const @@ -55,7 +58,8 @@ std::string FileInfoGCWii::GetName() const { // TODO: Should we really always use SHIFT-JIS? // Some names in Pikmin (NTSC-U) don't make sense without it, but is it correct? - const u8* name = m_name_table_start + (Get(EntryProperty::NAME_OFFSET) & 0xFFFFFF); + u32 name_offset = Get(EntryProperty::NAME_OFFSET) & 0xFFFFFF; + const u8* name = m_fst + FST_ENTRY_SIZE * m_total_file_infos + name_offset; return SHIFTJISToUTF8(reinterpret_cast(name)); } @@ -76,7 +80,7 @@ FileSystemGCWii::FileSystemGCWii(const Volume* _rVolume, const Partition& partit return; const u64 fst_offset = static_cast(*fst_offset_unshifted) << m_offset_shift; const u64 fst_size = static_cast(*fst_size_unshifted) << m_offset_shift; - if (fst_size < 0xC) + if (fst_size < FST_ENTRY_SIZE) return; // 128 MiB is more than the total amount of RAM in a Wii. @@ -99,12 +103,12 @@ FileSystemGCWii::FileSystemGCWii(const Volume* _rVolume, const Partition& partit // Create all file info objects u32 number_of_file_infos = Common::swap32(*((u32*)m_file_system_table.data() + 2)); const u8* fst_start = m_file_system_table.data(); - const u8* name_table_start = fst_start + (number_of_file_infos * 0xC); + const u8* name_table_start = fst_start + (FST_ENTRY_SIZE * number_of_file_infos); const u8* name_table_end = fst_start + fst_size; if (name_table_end < name_table_start) return; for (u32 i = 0; i < number_of_file_infos; i++) - m_FileInfoVector.emplace_back(m_offset_shift, fst_start + (i * 0xC), name_table_start); + m_FileInfoVector.emplace_back(fst_start, m_offset_shift, i, number_of_file_infos); // If we haven't returned yet, everything succeeded m_Valid = true; diff --git a/Source/Core/DiscIO/FileSystemGCWii.h b/Source/Core/DiscIO/FileSystemGCWii.h index ab4af8d0f0..d4fb9dd90e 100644 --- a/Source/Core/DiscIO/FileSystemGCWii.h +++ b/Source/Core/DiscIO/FileSystemGCWii.h @@ -21,7 +21,7 @@ class FileInfoGCWii : public FileInfo { public: // Does not take ownership of pointers - FileInfoGCWii(u8 offset_shift, const u8* fst_entry, const u8* name_table_start); + FileInfoGCWii(const u8* fst, u8 offset_shift, u32 index, u32 total_file_infos); ~FileInfoGCWii() override; @@ -40,9 +40,10 @@ private: u32 Get(EntryProperty entry_property) const; + const u8* const m_fst; const u8 m_offset_shift; - const u8* const m_fst_entry; - const u8* const m_name_table_start; + const u32 m_index; + const u32 m_total_file_infos; }; class FileSystemGCWii : public FileSystem