2018-06-21 17:16:23 +02:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-20 06:10:21 +02:00
|
|
|
#include <utility>
|
2018-06-21 17:16:23 +02:00
|
|
|
|
|
|
|
#include "common/logging/log.h"
|
2019-04-22 23:56:56 +02:00
|
|
|
#include "core/core.h"
|
2018-07-19 03:07:11 +02:00
|
|
|
#include "core/file_sys/content_archive.h"
|
2018-08-21 02:36:36 +02:00
|
|
|
#include "core/file_sys/romfs_factory.h"
|
2021-04-24 07:04:28 +02:00
|
|
|
#include "core/hle/kernel/k_process.h"
|
2018-06-21 17:16:23 +02:00
|
|
|
#include "core/hle/service/filesystem/filesystem.h"
|
2018-08-15 04:37:12 +02:00
|
|
|
#include "core/loader/deconstructed_rom_directory.h"
|
2018-06-21 17:16:23 +02:00
|
|
|
#include "core/loader/nca.h"
|
|
|
|
|
|
|
|
namespace Loader {
|
|
|
|
|
2018-08-06 00:27:05 +02:00
|
|
|
AppLoader_NCA::AppLoader_NCA(FileSys::VirtualFile file_)
|
|
|
|
: AppLoader(std::move(file_)), nca(std::make_unique<FileSys::NCA>(file)) {}
|
2018-06-21 17:16:23 +02:00
|
|
|
|
2018-08-15 04:37:12 +02:00
|
|
|
AppLoader_NCA::~AppLoader_NCA() = default;
|
|
|
|
|
2021-04-27 18:05:34 +02:00
|
|
|
FileType AppLoader_NCA::IdentifyType(const FileSys::VirtualFile& nca_file) {
|
|
|
|
const FileSys::NCA nca(nca_file);
|
2018-07-08 05:24:51 +02:00
|
|
|
|
2018-07-28 05:55:23 +02:00
|
|
|
if (nca.GetStatus() == ResultStatus::Success &&
|
2021-04-27 18:05:34 +02:00
|
|
|
nca.GetType() == FileSys::NCAContentType::Program) {
|
2018-06-21 17:16:23 +02:00
|
|
|
return FileType::NCA;
|
2021-04-27 18:05:34 +02:00
|
|
|
}
|
2018-06-21 17:16:23 +02:00
|
|
|
|
|
|
|
return FileType::Error;
|
|
|
|
}
|
|
|
|
|
2021-04-24 07:04:28 +02:00
|
|
|
AppLoader_NCA::LoadResult AppLoader_NCA::Load(Kernel::KProcess& process, Core::System& system) {
|
2018-06-21 17:16:23 +02:00
|
|
|
if (is_loaded) {
|
2019-04-09 23:03:04 +02:00
|
|
|
return {ResultStatus::ErrorAlreadyLoaded, {}};
|
2018-06-21 17:16:23 +02:00
|
|
|
}
|
|
|
|
|
2018-08-06 00:27:05 +02:00
|
|
|
const auto result = nca->GetStatus();
|
2018-06-21 17:16:23 +02:00
|
|
|
if (result != ResultStatus::Success) {
|
2019-04-09 23:03:04 +02:00
|
|
|
return {result, {}};
|
2018-06-21 17:16:23 +02:00
|
|
|
}
|
|
|
|
|
2019-04-09 23:03:04 +02:00
|
|
|
if (nca->GetType() != FileSys::NCAContentType::Program) {
|
|
|
|
return {ResultStatus::ErrorNCANotProgram, {}};
|
|
|
|
}
|
2018-07-19 03:07:11 +02:00
|
|
|
|
2018-08-06 00:27:05 +02:00
|
|
|
const auto exefs = nca->GetExeFS();
|
2019-04-09 23:03:04 +02:00
|
|
|
if (exefs == nullptr) {
|
|
|
|
return {ResultStatus::ErrorNoExeFS, {}};
|
|
|
|
}
|
2018-07-19 03:07:11 +02:00
|
|
|
|
2018-08-26 01:04:48 +02:00
|
|
|
directory_loader = std::make_unique<AppLoader_DeconstructedRomDirectory>(exefs, true);
|
2018-06-21 17:16:23 +02:00
|
|
|
|
2020-09-16 14:19:25 +02:00
|
|
|
const auto load_result = directory_loader->Load(process, system);
|
2019-04-09 23:03:04 +02:00
|
|
|
if (load_result.first != ResultStatus::Success) {
|
2018-08-06 00:27:05 +02:00
|
|
|
return load_result;
|
2019-04-09 23:03:04 +02:00
|
|
|
}
|
2018-06-21 17:16:23 +02:00
|
|
|
|
2019-04-09 23:03:04 +02:00
|
|
|
if (nca->GetRomFS() != nullptr && nca->GetRomFS()->GetSize() > 0) {
|
2020-09-17 00:29:24 +02:00
|
|
|
system.GetFileSystemController().RegisterRomFS(std::make_unique<FileSys::RomFSFactory>(
|
|
|
|
*this, system.GetContentProvider(), system.GetFileSystemController()));
|
2019-04-09 23:03:04 +02:00
|
|
|
}
|
2018-07-08 05:24:51 +02:00
|
|
|
|
2018-06-21 17:16:23 +02:00
|
|
|
is_loaded = true;
|
2019-04-09 23:03:04 +02:00
|
|
|
return load_result;
|
2018-07-08 05:24:51 +02:00
|
|
|
}
|
|
|
|
|
2018-07-19 03:07:11 +02:00
|
|
|
ResultStatus AppLoader_NCA::ReadRomFS(FileSys::VirtualFile& dir) {
|
2021-04-27 18:05:34 +02:00
|
|
|
if (nca == nullptr) {
|
2018-08-10 03:06:44 +02:00
|
|
|
return ResultStatus::ErrorNotInitialized;
|
2021-04-27 18:05:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nca->GetRomFS() == nullptr || nca->GetRomFS()->GetSize() == 0) {
|
2018-08-10 03:06:44 +02:00
|
|
|
return ResultStatus::ErrorNoRomFS;
|
2021-04-27 18:05:34 +02:00
|
|
|
}
|
|
|
|
|
2018-07-19 03:07:11 +02:00
|
|
|
dir = nca->GetRomFS();
|
2018-06-21 17:16:23 +02:00
|
|
|
return ResultStatus::Success;
|
|
|
|
}
|
|
|
|
|
2018-08-29 04:37:42 +02:00
|
|
|
u64 AppLoader_NCA::ReadRomFSIVFCOffset() const {
|
2021-04-27 18:05:34 +02:00
|
|
|
if (nca == nullptr) {
|
2018-08-29 04:37:42 +02:00
|
|
|
return 0;
|
2021-04-27 18:05:34 +02:00
|
|
|
}
|
|
|
|
|
2018-08-29 04:37:42 +02:00
|
|
|
return nca->GetBaseIVFCOffset();
|
|
|
|
}
|
|
|
|
|
2018-07-28 05:55:23 +02:00
|
|
|
ResultStatus AppLoader_NCA::ReadProgramId(u64& out_program_id) {
|
2021-04-27 18:05:34 +02:00
|
|
|
if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) {
|
2018-08-10 03:06:44 +02:00
|
|
|
return ResultStatus::ErrorNotInitialized;
|
2021-04-27 18:05:34 +02:00
|
|
|
}
|
|
|
|
|
2018-07-28 05:55:23 +02:00
|
|
|
out_program_id = nca->GetTitleId();
|
|
|
|
return ResultStatus::Success;
|
|
|
|
}
|
|
|
|
|
2019-01-15 21:56:52 +01:00
|
|
|
ResultStatus AppLoader_NCA::ReadBanner(std::vector<u8>& buffer) {
|
2021-04-27 18:05:34 +02:00
|
|
|
if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) {
|
2019-01-15 21:56:52 +01:00
|
|
|
return ResultStatus::ErrorNotInitialized;
|
2021-04-27 18:05:34 +02:00
|
|
|
}
|
|
|
|
|
2019-01-15 21:56:52 +01:00
|
|
|
const auto logo = nca->GetLogoPartition();
|
2021-04-27 18:05:34 +02:00
|
|
|
if (logo == nullptr) {
|
2019-01-15 21:56:52 +01:00
|
|
|
return ResultStatus::ErrorNoIcon;
|
2021-04-27 18:05:34 +02:00
|
|
|
}
|
|
|
|
|
2019-01-15 21:56:52 +01:00
|
|
|
buffer = logo->GetFile("StartupMovie.gif")->ReadAllBytes();
|
|
|
|
return ResultStatus::Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultStatus AppLoader_NCA::ReadLogo(std::vector<u8>& buffer) {
|
2021-04-27 18:05:34 +02:00
|
|
|
if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) {
|
2019-01-15 21:56:52 +01:00
|
|
|
return ResultStatus::ErrorNotInitialized;
|
2021-04-27 18:05:34 +02:00
|
|
|
}
|
|
|
|
|
2019-01-15 21:56:52 +01:00
|
|
|
const auto logo = nca->GetLogoPartition();
|
2021-04-27 18:05:34 +02:00
|
|
|
if (logo == nullptr) {
|
2019-01-15 21:56:52 +01:00
|
|
|
return ResultStatus::ErrorNoIcon;
|
2021-04-27 18:05:34 +02:00
|
|
|
}
|
|
|
|
|
2019-01-15 21:56:52 +01:00
|
|
|
buffer = logo->GetFile("NintendoLogo.png")->ReadAllBytes();
|
|
|
|
return ResultStatus::Success;
|
|
|
|
}
|
2019-05-26 17:40:41 +02:00
|
|
|
|
|
|
|
ResultStatus AppLoader_NCA::ReadNSOModules(Modules& modules) {
|
|
|
|
if (directory_loader == nullptr) {
|
|
|
|
return ResultStatus::ErrorNotInitialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
return directory_loader->ReadNSOModules(modules);
|
|
|
|
}
|
|
|
|
|
2018-06-21 17:16:23 +02:00
|
|
|
} // namespace Loader
|