From dc2ab096cb8248d7c6f2c487f047dead40aba0c8 Mon Sep 17 00:00:00 2001 From: PabloMK7 Date: Fri, 8 Aug 2025 23:32:53 +0200 Subject: [PATCH] loader: Fix compressed 3dsx icon reading --- src/core/loader/3dsx.cpp | 20 +++++++++++++------- src/core/loader/3dsx.h | 6 +++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp index e989ee7e2..83a41a5e7 100644 --- a/src/core/loader/3dsx.cpp +++ b/src/core/loader/3dsx.cpp @@ -249,6 +249,17 @@ static THREEDSX_Error Load3DSXFile(Core::System& system, FileUtil::IOFile* file, return ERROR_NONE; } +AppLoader_THREEDSX::AppLoader_THREEDSX(Core::System& system_, FileUtil::IOFile&& file, + const std::string& filename, const std::string& filepath) + : AppLoader(system_, std::move(file)), filename(filename), filepath(filepath) { + + filetype = IdentifyType(this->file.get()); + + if (FileUtil::Z3DSReadIOFile::GetUnderlyingFileMagic(this->file.get()) != std::nullopt) { + this->file = std::make_unique(std::move(this->file)); + } +} + FileType AppLoader_THREEDSX::IdentifyType(FileUtil::IOFile* file) { u32 magic; file->Seek(0, SEEK_SET); @@ -270,10 +281,6 @@ ResultStatus AppLoader_THREEDSX::Load(std::shared_ptr& process) if (!file->IsOpen()) return ResultStatus::Error; - if (FileUtil::Z3DSReadIOFile::GetUnderlyingFileMagic(file.get()) != std::nullopt) { - file = std::make_unique(std::move(file)); - } - std::shared_ptr codeset; if (Load3DSXFile(system, file.get(), Memory::PROCESS_IMAGE_VADDR, &codeset) != ERROR_NONE) return ResultStatus::Error; @@ -341,13 +348,12 @@ AppLoader::CompressFileInfo AppLoader_THREEDSX::GetCompressFileInfo() { info.recommended_compressed_extension = "z3dsx"; info.recommended_uncompressed_extension = "3dsx"; info.underlying_magic = std::array({'3', 'D', 'S', 'X'}); - info.is_compressed = - FileUtil::Z3DSReadIOFile::GetUnderlyingFileMagic(file.get()) != std::nullopt; + info.is_compressed = file->IsCompressed(); return info; } bool AppLoader_THREEDSX::IsFileCompressed() { - return FileUtil::Z3DSReadIOFile::GetUnderlyingFileMagic(file.get()) != std::nullopt; + return file->IsCompressed(); } ResultStatus AppLoader_THREEDSX::ReadIcon(std::vector& buffer) { diff --git a/src/core/loader/3dsx.h b/src/core/loader/3dsx.h index e7cf2ab74..60c035f57 100644 --- a/src/core/loader/3dsx.h +++ b/src/core/loader/3dsx.h @@ -19,8 +19,7 @@ namespace Loader { class AppLoader_THREEDSX final : public AppLoader { public: AppLoader_THREEDSX(Core::System& system_, FileUtil::IOFile&& file, const std::string& filename, - const std::string& filepath) - : AppLoader(system_, std::move(file)), filename(filename), filepath(filepath) {} + const std::string& filepath); /** * Returns the type of the file @@ -30,7 +29,7 @@ public: static FileType IdentifyType(FileUtil::IOFile* file); FileType GetFileType() override { - return IdentifyType(file.get()); + return filetype; } ResultStatus Load(std::shared_ptr& process) override; @@ -46,6 +45,7 @@ public: private: std::string filename; std::string filepath; + FileType filetype; }; } // namespace Loader