From 8a570bf00c7b0e709a73f64b78ad4daeb9765d17 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Fri, 7 Feb 2020 13:45:10 +0800 Subject: [PATCH] core: Use LayeredFS while reading RomFS Only enabled for NCCHs that do not have an override romfs. LayeredFS files should be put in the `load` directory in User Directory. The directory structure is similar to yuzu's but currently does not allow named mods yet. Replacement files should be put in `load/mods//romfs` while patches/stubs should be put in `load/mods/<Title ID>/romfs_ext`. --- src/core/file_sys/ncch_container.cpp | 28 +++++++++++++++++++++------- src/core/loader/3dsx.cpp | 4 ++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/core/file_sys/ncch_container.cpp b/src/core/file_sys/ncch_container.cpp index f0687fa9e..53432f945 100644 --- a/src/core/file_sys/ncch_container.cpp +++ b/src/core/file_sys/ncch_container.cpp @@ -11,6 +11,7 @@ #include "common/common_types.h" #include "common/logging/log.h" #include "core/core.h" +#include "core/file_sys/layered_fs.h" #include "core/file_sys/ncch_container.h" #include "core/file_sys/patch.h" #include "core/file_sys/seed_db.h" @@ -597,12 +598,24 @@ Loader::ResultStatus NCCHContainer::ReadRomFS(std::shared_ptr<RomFSReader>& romf if (!romfs_file_inner.IsOpen()) return Loader::ResultStatus::Error; + std::shared_ptr<RomFSReader> direct_romfs; if (is_encrypted) { - romfs_file = std::make_shared<RomFSReader>(std::move(romfs_file_inner), romfs_offset, - romfs_size, secondary_key, romfs_ctr, 0x1000); + direct_romfs = + std::make_shared<DirectRomFSReader>(std::move(romfs_file_inner), romfs_offset, + romfs_size, secondary_key, romfs_ctr, 0x1000); } else { - romfs_file = - std::make_shared<RomFSReader>(std::move(romfs_file_inner), romfs_offset, romfs_size); + direct_romfs = std::make_shared<DirectRomFSReader>(std::move(romfs_file_inner), + romfs_offset, romfs_size); + } + + const auto path = + fmt::format("{}mods/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), + ncch_header.program_id); + if (FileUtil::Exists(path + "romfs/") || FileUtil::Exists(path + "romfs_ext/")) { + romfs_file = std::make_shared<LayeredFS>(std::move(direct_romfs), path + "romfs/", + path + "romfs_ext/"); + } else { + romfs_file = std::move(direct_romfs); } return Loader::ResultStatus::Success; @@ -614,9 +627,10 @@ Loader::ResultStatus NCCHContainer::ReadOverrideRomFS(std::shared_ptr<RomFSReade if (FileUtil::Exists(split_filepath)) { FileUtil::IOFile romfs_file_inner(split_filepath, "rb"); if (romfs_file_inner.IsOpen()) { - LOG_WARNING(Service_FS, "File {} overriding built-in RomFS", split_filepath); - romfs_file = std::make_shared<RomFSReader>(std::move(romfs_file_inner), 0, - romfs_file_inner.GetSize()); + LOG_WARNING(Service_FS, "File {} overriding built-in RomFS; LayeredFS not enabled", + split_filepath); + romfs_file = std::make_shared<DirectRomFSReader>(std::move(romfs_file_inner), 0, + romfs_file_inner.GetSize()); return Loader::ResultStatus::Success; } } diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp index 7629ad376..84321011b 100644 --- a/src/core/loader/3dsx.cpp +++ b/src/core/loader/3dsx.cpp @@ -309,8 +309,8 @@ ResultStatus AppLoader_THREEDSX::ReadRomFS(std::shared_ptr<FileSys::RomFSReader> if (!romfs_file_inner.IsOpen()) return ResultStatus::Error; - romfs_file = std::make_shared<FileSys::RomFSReader>(std::move(romfs_file_inner), - romfs_offset, romfs_size); + romfs_file = std::make_shared<FileSys::DirectRomFSReader>(std::move(romfs_file_inner), + romfs_offset, romfs_size); return ResultStatus::Success; }