[WIP] NCCHContainer: support for partitions if container is NCSD (#5345)

* GetProgramLaunchInfo: improve to for 3ds files

* NCSD: allow to load other partitions

* fix typo

* Update src/core/hle/service/fs/fs_user.cpp

Co-authored-by: Valentin Vanelslande <vvanelslandedev@gmail.com>

* Update src/core/hle/service/fs/fs_user.cpp

Co-authored-by: Valentin Vanelslande <vvanelslandedev@gmail.com>

Co-authored-by: Marshall Mohror <mohror64@gmail.com>
Co-authored-by: Valentin Vanelslande <vvanelslandedev@gmail.com>
This commit is contained in:
Ben
2020-07-14 16:14:30 +02:00
committed by GitHub
parent 897e473da4
commit 1722701c07
10 changed files with 226 additions and 34 deletions

View File

@ -114,14 +114,16 @@ static bool LZSS_Decompress(const u8* compressed, u32 compressed_size, u8* decom
return true;
}
NCCHContainer::NCCHContainer(const std::string& filepath, u32 ncch_offset)
: ncch_offset(ncch_offset), filepath(filepath) {
NCCHContainer::NCCHContainer(const std::string& filepath, u32 ncch_offset, u32 partition)
: ncch_offset(ncch_offset), partition(partition), filepath(filepath) {
file = FileUtil::IOFile(filepath, "rb");
}
Loader::ResultStatus NCCHContainer::OpenFile(const std::string& filepath, u32 ncch_offset) {
Loader::ResultStatus NCCHContainer::OpenFile(const std::string& filepath, u32 ncch_offset,
u32 partition) {
this->filepath = filepath;
this->ncch_offset = ncch_offset;
this->partition = partition;
file = FileUtil::IOFile(filepath, "rb");
if (!file.IsOpen()) {
@ -150,8 +152,13 @@ Loader::ResultStatus NCCHContainer::LoadHeader() {
// Skip NCSD header and load first NCCH (NCSD is just a container of NCCH files)...
if (Loader::MakeMagic('N', 'C', 'S', 'D') == ncch_header.magic) {
LOG_DEBUG(Service_FS, "Only loading the first (bootable) NCCH within the NCSD file!");
ncch_offset += 0x4000;
NCSD_Header ncsd_header;
file.Seek(ncch_offset, SEEK_SET);
file.ReadBytes(&ncsd_header, sizeof(NCSD_Header));
ASSERT(Loader::MakeMagic('N', 'C', 'S', 'D') == ncsd_header.magic);
ASSERT(partition < 8);
ncch_offset = ncsd_header.partitions[partition].offset * kBlockSize;
LOG_ERROR(Service_FS, "{}", ncch_offset);
file.Seek(ncch_offset, SEEK_SET);
file.ReadBytes(&ncch_header, sizeof(NCCH_Header));
}
@ -178,8 +185,12 @@ Loader::ResultStatus NCCHContainer::Load() {
// Skip NCSD header and load first NCCH (NCSD is just a container of NCCH files)...
if (Loader::MakeMagic('N', 'C', 'S', 'D') == ncch_header.magic) {
LOG_DEBUG(Service_FS, "Only loading the first (bootable) NCCH within the NCSD file!");
ncch_offset += 0x4000;
NCSD_Header ncsd_header;
file.Seek(ncch_offset, SEEK_SET);
file.ReadBytes(&ncsd_header, sizeof(NCSD_Header));
ASSERT(Loader::MakeMagic('N', 'C', 'S', 'D') == ncsd_header.magic);
ASSERT(partition < 8);
ncch_offset = ncsd_header.partitions[partition].offset * kBlockSize;
file.Seek(ncch_offset, SEEK_SET);
file.ReadBytes(&ncch_header, sizeof(NCCH_Header));
}