From 88dd5330a82b409e88c5009128750666223b00cb Mon Sep 17 00:00:00 2001 From: emoose Date: Sat, 11 Jan 2020 19:04:31 +0000 Subject: [PATCH] [VFS] Fix sketchy ReadMagic function... Haven't been able to test yet though - hope it's reading in the correct endian! --- src/xenia/vfs/devices/stfs_container_device.cc | 11 +++++------ src/xenia/vfs/devices/stfs_container_device.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/xenia/vfs/devices/stfs_container_device.cc b/src/xenia/vfs/devices/stfs_container_device.cc index 3c21fcc62..c8bb33fb4 100644 --- a/src/xenia/vfs/devices/stfs_container_device.cc +++ b/src/xenia/vfs/devices/stfs_container_device.cc @@ -698,11 +698,9 @@ StfsContainerDevice::BlockHash StfsContainerDevice::STFSGetLevel0HashEntry( return STFSGetLevelNHashEntry(map_ptr, block_index, 0, use_secondary_block); } -const char* StfsContainerDevice::ReadMagic(const std::wstring& path) { +uint32_t StfsContainerDevice::ReadMagic(const std::wstring& path) { auto map = MappedMemory::Open(path, MappedMemory::Mode::kRead, 0, 4); - auto magic_data = xe::load(map->data()); - auto magic_bytes = static_cast(static_cast(&magic_data)); - return std::move(magic_bytes); + return xe::load_and_swap(map->data()); } bool StfsContainerDevice::ResolveFromFolder(const std::wstring& path) { @@ -728,8 +726,9 @@ bool StfsContainerDevice::ResolveFromFolder(const std::wstring& path) { auto path = xe::join_paths(current_file.path, current_file.name); auto magic = ReadMagic(path); - if (memcmp(magic, "LIVE", 4) == 0 || memcmp(magic, "PIRS", 4) == 0 || - memcmp(magic, "CON ", 4) == 0) { + if (magic == XContentPackageType::kPackageTypeCon || + magic == XContentPackageType::kPackageTypeLive || + magic == XContentPackageType::kPackageTypePirs) { local_path_ = xe::join_paths(current_file.path, current_file.name); XELOGI("STFS Package found: %s", xe::to_string(local_path_).c_str()); return true; diff --git a/src/xenia/vfs/devices/stfs_container_device.h b/src/xenia/vfs/devices/stfs_container_device.h index 0a7afd6b7..343dc5e08 100644 --- a/src/xenia/vfs/devices/stfs_container_device.h +++ b/src/xenia/vfs/devices/stfs_container_device.h @@ -448,7 +448,7 @@ class StfsContainerDevice : public Device { const uint32_t kSTFSDataBlocksPerHashLevel[3] = {0xAA, 0x70E4, 0x4AF768}; - const char* ReadMagic(const std::wstring& path); + uint32_t ReadMagic(const std::wstring& path); bool ResolveFromFolder(const std::wstring& path); Error MapFiles();