nsp: Use title ID from NPDM metadata for extracted type NSPs

Avoids 0 being used as title ID for all extracted NSPs.
This commit is contained in:
Zach Hilman 2019-06-10 00:19:23 -04:00
parent 364932df3a
commit 1c75945dc4
2 changed files with 22 additions and 1 deletions

View file

@ -85,12 +85,29 @@ Loader::ResultStatus NSP::GetProgramStatus(u64 title_id) const {
} }
u64 NSP::GetFirstTitleID() const { u64 NSP::GetFirstTitleID() const {
if (IsExtractedType()) {
return GetProgramTitleID();
}
if (program_status.empty()) if (program_status.empty())
return 0; return 0;
return program_status.begin()->first; return program_status.begin()->first;
} }
u64 NSP::GetProgramTitleID() const { u64 NSP::GetProgramTitleID() const {
if (IsExtractedType()) {
if (GetExeFS() == nullptr || !IsDirectoryExeFS(GetExeFS())) {
return 0;
}
ProgramMetadata meta;
if (meta.Load(GetExeFS()->GetFile("main.npdm")) == Loader::ResultStatus::Success) {
return meta.GetTitleID();
} else {
return 0;
}
}
const auto out = GetFirstTitleID(); const auto out = GetFirstTitleID();
if ((out & 0x800) == 0) if ((out & 0x800) == 0)
return out; return out;
@ -102,6 +119,10 @@ u64 NSP::GetProgramTitleID() const {
} }
std::vector<u64> NSP::GetTitleIDs() const { std::vector<u64> NSP::GetTitleIDs() const {
if (IsExtractedType()) {
return {GetProgramTitleID()};
}
std::vector<u64> out; std::vector<u64> out;
out.reserve(ncas.size()); out.reserve(ncas.size());
for (const auto& kv : ncas) for (const auto& kv : ncas)

View file

@ -77,7 +77,7 @@ AppLoader_NSP::LoadResult AppLoader_NSP::Load(Kernel::Process& process) {
return {ResultStatus::ErrorAlreadyLoaded, {}}; return {ResultStatus::ErrorAlreadyLoaded, {}};
} }
if (title_id == 0) { if (!nsp->IsExtractedType() && title_id == 0) {
return {ResultStatus::ErrorNSPMissingProgramNCA, {}}; return {ResultStatus::ErrorNSPMissingProgramNCA, {}};
} }