DiscIO: merge initial WBFS reads
This commit is contained in:
parent
f416106eec
commit
3a2efc9f4f
|
@ -83,21 +83,17 @@ bool WbfsFileReader::OpenFiles(const std::string& filename)
|
||||||
|
|
||||||
bool WbfsFileReader::ReadHeader()
|
bool WbfsFileReader::ReadHeader()
|
||||||
{
|
{
|
||||||
m_files[0]->file.Seek(4, SEEK_SET);
|
|
||||||
|
|
||||||
// Read hd size info
|
// Read hd size info
|
||||||
m_files[0]->file.ReadBytes(&m_hd_sector_count, 4);
|
m_files[0]->file.ReadBytes(&m_header, sizeof(WbfsHeader));
|
||||||
m_hd_sector_count = Common::swap32(m_hd_sector_count);
|
m_header.hd_sector_count = Common::swap32(m_header.hd_sector_count);
|
||||||
|
|
||||||
m_files[0]->file.ReadBytes(&m_hd_sector_shift, 1);
|
m_hd_sector_size = 1ull << m_header.hd_sector_shift;
|
||||||
m_hd_sector_size = 1ull << m_hd_sector_shift;
|
|
||||||
|
|
||||||
if (m_size != (m_hd_sector_count * m_hd_sector_size))
|
if (m_size != (m_header.hd_sector_count * m_hd_sector_size))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Read wbfs cluster info
|
// Read wbfs cluster info
|
||||||
m_files[0]->file.ReadBytes(&m_wbfs_sector_shift, 1);
|
m_wbfs_sector_size = 1ull << m_header.wbfs_sector_shift;
|
||||||
m_wbfs_sector_size = 1ull << m_wbfs_sector_shift;
|
|
||||||
m_wbfs_sector_count = m_size / m_wbfs_sector_size;
|
m_wbfs_sector_count = m_size / m_wbfs_sector_size;
|
||||||
|
|
||||||
if (m_wbfs_sector_size < WII_SECTOR_SIZE)
|
if (m_wbfs_sector_size < WII_SECTOR_SIZE)
|
||||||
|
@ -106,14 +102,7 @@ bool WbfsFileReader::ReadHeader()
|
||||||
m_blocks_per_disc = (WII_SECTOR_COUNT * WII_SECTOR_SIZE) / m_wbfs_sector_size;
|
m_blocks_per_disc = (WII_SECTOR_COUNT * WII_SECTOR_SIZE) / m_wbfs_sector_size;
|
||||||
m_disc_info_size = align(WII_DISC_HEADER_SIZE + m_blocks_per_disc * sizeof(u16), m_hd_sector_size);
|
m_disc_info_size = align(WII_DISC_HEADER_SIZE + m_blocks_per_disc * sizeof(u16), m_hd_sector_size);
|
||||||
|
|
||||||
// Read disc table
|
return m_header.disc_table[0] != 0;
|
||||||
m_files[0]->file.Seek(2, SEEK_CUR);
|
|
||||||
m_files[0]->file.ReadBytes(m_disc_table, 500);
|
|
||||||
|
|
||||||
if (m_disc_table[0] == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WbfsFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
bool WbfsFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
||||||
|
@ -142,7 +131,7 @@ bool WbfsFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
||||||
|
|
||||||
File::IOFile& WbfsFileReader::SeekToCluster(u64 offset, u64* available)
|
File::IOFile& WbfsFileReader::SeekToCluster(u64 offset, u64* available)
|
||||||
{
|
{
|
||||||
u64 base_cluster = (offset >> m_wbfs_sector_shift);
|
u64 base_cluster = (offset >> m_header.wbfs_sector_shift);
|
||||||
if (base_cluster < m_blocks_per_disc)
|
if (base_cluster < m_blocks_per_disc)
|
||||||
{
|
{
|
||||||
u64 cluster_address = m_wbfs_sector_size * m_wlba_table[base_cluster];
|
u64 cluster_address = m_wbfs_sector_size * m_wlba_table[base_cluster];
|
||||||
|
|
|
@ -48,15 +48,21 @@ private:
|
||||||
u64 m_size;
|
u64 m_size;
|
||||||
|
|
||||||
u64 m_hd_sector_size;
|
u64 m_hd_sector_size;
|
||||||
u8 m_hd_sector_shift;
|
|
||||||
u32 m_hd_sector_count;
|
|
||||||
|
|
||||||
u64 m_wbfs_sector_size;
|
u64 m_wbfs_sector_size;
|
||||||
u8 m_wbfs_sector_shift;
|
|
||||||
u64 m_wbfs_sector_count;
|
u64 m_wbfs_sector_count;
|
||||||
u64 m_disc_info_size;
|
u64 m_disc_info_size;
|
||||||
|
|
||||||
u8 m_disc_table[500];
|
#pragma pack(1)
|
||||||
|
struct WbfsHeader
|
||||||
|
{
|
||||||
|
char magic[4];
|
||||||
|
u32 hd_sector_count;
|
||||||
|
u8 hd_sector_shift;
|
||||||
|
u8 wbfs_sector_shift;
|
||||||
|
u8 padding[2];
|
||||||
|
u8 disc_table[500];
|
||||||
|
} m_header;
|
||||||
|
#pragma pack()
|
||||||
|
|
||||||
u16* m_wlba_table;
|
u16* m_wlba_table;
|
||||||
u64 m_blocks_per_disc;
|
u64 m_blocks_per_disc;
|
||||||
|
|
Loading…
Reference in New Issue