diff --git a/src/xenia/vfs/devices/stfs_container_device.cc b/src/xenia/vfs/devices/stfs_container_device.cc index 7160ddd4f..e3ecdedff 100644 --- a/src/xenia/vfs/devices/stfs_container_device.cc +++ b/src/xenia/vfs/devices/stfs_container_device.cc @@ -561,13 +561,10 @@ StfsContainerDevice::Error StfsContainerDevice::ReadSTFS() { return Error::kSuccess; } -size_t StfsContainerDevice::BlockToOffsetSTFS(uint64_t block_index) { - uint64_t block; - uint32_t block_shift = 0; - if (((header_.header.header_size + 0x0FFF) & 0xB000) == 0xB000 || - !header_.metadata.stfs_volume_descriptor.flags.read_only_format) { - block_shift = - header_.header.magic == XContentPackageType::kPackageTypeCon ? 1 : 0; +size_t StfsContainerDevice::BlockToOffsetSTFS(uint64_t block_index) const { + uint32_t blocks_per_hash_table = 1; + if (!header_.metadata.stfs_volume_descriptor.flags.read_only_format) { + blocks_per_hash_table = 2; } // For every level there is a hash table @@ -576,9 +573,9 @@ size_t StfsContainerDevice::BlockToOffsetSTFS(uint64_t block_index) { // Level 2: hash table of next 170 level 1 hash tables // And so on... uint64_t base = kBlocksPerHashLevel[0]; - block = block_index; + uint64_t block = block_index; for (uint32_t i = 0; i < 3; i++) { - block += (block_index + (base << block_shift)) / (base << block_shift); + block += ((block_index + base) / base) * blocks_per_hash_table; if (block_index < base) { break; } diff --git a/src/xenia/vfs/devices/stfs_container_device.h b/src/xenia/vfs/devices/stfs_container_device.h index 500b1ab21..29d12cfa0 100644 --- a/src/xenia/vfs/devices/stfs_container_device.h +++ b/src/xenia/vfs/devices/stfs_container_device.h @@ -462,7 +462,7 @@ class StfsContainerDevice : public Device { void BlockToOffsetSVOD(size_t sector, size_t* address, size_t* file_index); Error ReadSTFS(); - size_t BlockToOffsetSTFS(uint64_t block); + size_t BlockToOffsetSTFS(uint64_t block_index) const; StfsHashEntry GetBlockHash(const uint8_t* map_ptr, uint32_t block_index, uint32_t table_offset);