mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-27 21:24:11 -04:00
strat: TitleId -> ProgramId, titles->contents
This commit is contained in:
parent
1636668762
commit
ea3ebbaa7d
86 changed files with 1138 additions and 1140 deletions
|
@ -31,7 +31,7 @@ namespace ams::ldr {
|
|||
/* Globals. */
|
||||
bool g_has_mounted_sd_card = false;
|
||||
|
||||
ncm::TitleId g_should_override_title_id;
|
||||
ncm::ProgramId g_should_override_program_id;
|
||||
bool g_should_override_hbl = false;
|
||||
bool g_should_override_sd = false;
|
||||
|
||||
|
@ -53,24 +53,24 @@ namespace ams::ldr {
|
|||
return relative_path;
|
||||
}
|
||||
|
||||
void UpdateShouldOverrideCache(ncm::TitleId title_id) {
|
||||
if (g_should_override_title_id != title_id) {
|
||||
cfg::GetOverrideKeyHeldStatus(&g_should_override_hbl, &g_should_override_sd, title_id);
|
||||
void UpdateShouldOverrideCache(ncm::ProgramId program_id) {
|
||||
if (g_should_override_program_id != program_id) {
|
||||
cfg::GetOverrideKeyHeldStatus(&g_should_override_hbl, &g_should_override_sd, program_id);
|
||||
}
|
||||
g_should_override_title_id = title_id;
|
||||
g_should_override_program_id = program_id;
|
||||
}
|
||||
|
||||
void InvalidateShouldOverrideCache() {
|
||||
g_should_override_title_id = {};
|
||||
g_should_override_program_id = {};
|
||||
}
|
||||
|
||||
bool ShouldOverrideWithHbl(ncm::TitleId title_id) {
|
||||
UpdateShouldOverrideCache(title_id);
|
||||
bool ShouldOverrideWithHbl(ncm::ProgramId program_id) {
|
||||
UpdateShouldOverrideCache(program_id);
|
||||
return g_should_override_hbl;
|
||||
}
|
||||
|
||||
bool ShouldOverrideWithSd(ncm::TitleId title_id) {
|
||||
UpdateShouldOverrideCache(title_id);
|
||||
bool ShouldOverrideWithSd(ncm::ProgramId program_id) {
|
||||
UpdateShouldOverrideCache(program_id);
|
||||
return g_should_override_sd;
|
||||
}
|
||||
|
||||
|
@ -97,31 +97,31 @@ namespace ams::ldr {
|
|||
return fopen(path, "rb");
|
||||
}
|
||||
|
||||
FILE *OpenLooseSdFile(ncm::TitleId title_id, const char *relative_path) {
|
||||
FILE *OpenLooseSdFile(ncm::ProgramId program_id, const char *relative_path) {
|
||||
/* Allow nullptr relative path -- those are simply not openable. */
|
||||
if (relative_path == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char path[FS_MAX_PATH];
|
||||
std::snprintf(path, FS_MAX_PATH, "/atmosphere/titles/%016lx/exefs/%s", static_cast<u64>(title_id), GetRelativePathStart(relative_path));
|
||||
std::snprintf(path, FS_MAX_PATH, "/atmosphere/contents/%016lx/exefs/%s", static_cast<u64>(program_id), GetRelativePathStart(relative_path));
|
||||
FixFileSystemPath(path);
|
||||
return OpenFile(SdCardFileSystemDeviceName, path);
|
||||
}
|
||||
|
||||
bool IsFileStubbed(ncm::TitleId title_id, const char *relative_path) {
|
||||
bool IsFileStubbed(ncm::ProgramId program_id, const char *relative_path) {
|
||||
/* Allow nullptr relative path -- those are simply not openable. */
|
||||
if (relative_path == nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Only allow stubbing in the case where we're considering SD card content. */
|
||||
if (!ShouldOverrideWithSd(title_id)) {
|
||||
if (!ShouldOverrideWithSd(program_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char path[FS_MAX_PATH];
|
||||
std::snprintf(path, FS_MAX_PATH, "/atmosphere/titles/%016lx/exefs/%s.stub", static_cast<u64>(title_id), GetRelativePathStart(relative_path));
|
||||
std::snprintf(path, FS_MAX_PATH, "/atmosphere/contents/%016lx/exefs/%s.stub", static_cast<u64>(program_id), GetRelativePathStart(relative_path));
|
||||
FixFileSystemPath(path);
|
||||
FILE *f = OpenFile(SdCardFileSystemDeviceName, path);
|
||||
if (f == nullptr) {
|
||||
|
@ -131,14 +131,14 @@ namespace ams::ldr {
|
|||
return true;
|
||||
}
|
||||
|
||||
FILE *OpenBaseExefsFile(ncm::TitleId title_id, const char *relative_path) {
|
||||
FILE *OpenBaseExefsFile(ncm::ProgramId program_id, const char *relative_path) {
|
||||
/* Allow nullptr relative path -- those are simply not openable. */
|
||||
if (relative_path == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* Check if stubbed. */
|
||||
if (IsFileStubbed(title_id, relative_path)) {
|
||||
if (IsFileStubbed(program_id, relative_path)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ namespace ams::ldr {
|
|||
}
|
||||
|
||||
/* ScopedCodeMount functionality. */
|
||||
ScopedCodeMount::ScopedCodeMount(const ncm::TitleLocation &loc) : is_code_mounted(false), is_hbl_mounted(false) {
|
||||
ScopedCodeMount::ScopedCodeMount(const ncm::ProgramLocation &loc) : is_code_mounted(false), is_hbl_mounted(false) {
|
||||
this->result = this->Initialize(loc);
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ namespace ams::ldr {
|
|||
InvalidateShouldOverrideCache();
|
||||
}
|
||||
|
||||
Result ScopedCodeMount::MountCodeFileSystem(const ncm::TitleLocation &loc) {
|
||||
Result ScopedCodeMount::MountCodeFileSystem(const ncm::ProgramLocation &loc) {
|
||||
char path[FS_MAX_PATH];
|
||||
|
||||
/* Try to get the content path. */
|
||||
|
@ -173,7 +173,7 @@ namespace ams::ldr {
|
|||
|
||||
/* Try to mount the content path. */
|
||||
FsFileSystem fs;
|
||||
R_TRY(fsldrOpenCodeFileSystem(static_cast<u64>(loc.title_id), path, &fs));
|
||||
R_TRY(fsldrOpenCodeFileSystem(static_cast<u64>(loc.program_id), path, &fs));
|
||||
AMS_ASSERT(fsdevMountDevice(CodeFileSystemDeviceName, fs) != -1);
|
||||
|
||||
/* Note that we mounted code. */
|
||||
|
@ -181,11 +181,11 @@ namespace ams::ldr {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ScopedCodeMount::MountSdCardCodeFileSystem(const ncm::TitleLocation &loc) {
|
||||
Result ScopedCodeMount::MountSdCardCodeFileSystem(const ncm::ProgramLocation &loc) {
|
||||
char path[FS_MAX_PATH];
|
||||
|
||||
/* Print and fix path. */
|
||||
std::snprintf(path, FS_MAX_PATH, "%s:/atmosphere/titles/%016lx/exefs.nsp", SdCardStorageMountPoint, static_cast<u64>(loc.title_id));
|
||||
std::snprintf(path, FS_MAX_PATH, "%s:/atmosphere/contents/%016lx/exefs.nsp", SdCardStorageMountPoint, static_cast<u64>(loc.program_id));
|
||||
FixFileSystemPath(path);
|
||||
R_TRY(MountNspFileSystem(CodeFileSystemDeviceName, path));
|
||||
|
||||
|
@ -208,7 +208,7 @@ namespace ams::ldr {
|
|||
}
|
||||
|
||||
|
||||
Result ScopedCodeMount::Initialize(const ncm::TitleLocation &loc) {
|
||||
Result ScopedCodeMount::Initialize(const ncm::ProgramLocation &loc) {
|
||||
bool is_sd_initialized = cfg::IsSdCardInitialized();
|
||||
|
||||
/* Check if we're ready to mount the SD card. */
|
||||
|
@ -220,11 +220,11 @@ namespace ams::ldr {
|
|||
}
|
||||
|
||||
/* Check if we should override contents. */
|
||||
if (ShouldOverrideWithHbl(loc.title_id)) {
|
||||
if (ShouldOverrideWithHbl(loc.program_id)) {
|
||||
/* Try to mount HBL. */
|
||||
this->MountHblFileSystem();
|
||||
}
|
||||
if (ShouldOverrideWithSd(loc.title_id)) {
|
||||
if (ShouldOverrideWithSd(loc.program_id)) {
|
||||
/* Try to mount Code NSP on SD. */
|
||||
this->MountSdCardCodeFileSystem(loc);
|
||||
}
|
||||
|
@ -237,25 +237,25 @@ namespace ams::ldr {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result OpenCodeFile(FILE *&out, ncm::TitleId title_id, const char *relative_path) {
|
||||
Result OpenCodeFile(FILE *&out, ncm::ProgramId program_id, const char *relative_path) {
|
||||
FILE *f = nullptr;
|
||||
const char *ecs_device_name = ecs::Get(title_id);
|
||||
const char *ecs_device_name = ecs::Get(program_id);
|
||||
|
||||
if (ecs_device_name != nullptr) {
|
||||
/* First priority: Open from external content. */
|
||||
f = OpenFile(ecs_device_name, relative_path);
|
||||
} else if (ShouldOverrideWithHbl(title_id)) {
|
||||
} else if (ShouldOverrideWithHbl(program_id)) {
|
||||
/* Next, try to open from HBL. */
|
||||
f = OpenFile(HblFileSystemDeviceName, relative_path);
|
||||
} else {
|
||||
/* If not ECS or HBL, try a loose file on the SD. */
|
||||
if (ShouldOverrideWithSd(title_id)) {
|
||||
f = OpenLooseSdFile(title_id, relative_path);
|
||||
if (ShouldOverrideWithSd(program_id)) {
|
||||
f = OpenLooseSdFile(program_id, relative_path);
|
||||
}
|
||||
|
||||
/* If we fail, try the original exefs. */
|
||||
if (f == nullptr) {
|
||||
f = OpenBaseExefsFile(title_id, relative_path);
|
||||
f = OpenBaseExefsFile(program_id, relative_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,9 +266,9 @@ namespace ams::ldr {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result OpenCodeFileFromBaseExefs(FILE *&out, ncm::TitleId title_id, const char *relative_path) {
|
||||
Result OpenCodeFileFromBaseExefs(FILE *&out, ncm::ProgramId program_id, const char *relative_path) {
|
||||
/* Open the file. */
|
||||
FILE *f = OpenBaseExefsFile(title_id, relative_path);
|
||||
FILE *f = OpenBaseExefsFile(program_id, relative_path);
|
||||
R_UNLESS(f != nullptr, fs::ResultPathNotFound());
|
||||
|
||||
out = f;
|
||||
|
@ -276,7 +276,7 @@ namespace ams::ldr {
|
|||
}
|
||||
|
||||
/* Redirection API. */
|
||||
Result ResolveContentPath(char *out_path, const ncm::TitleLocation &loc) {
|
||||
Result ResolveContentPath(char *out_path, const ncm::ProgramLocation &loc) {
|
||||
char path[FS_MAX_PATH];
|
||||
|
||||
/* Try to get the path from the registered resolver. */
|
||||
|
@ -284,14 +284,14 @@ namespace ams::ldr {
|
|||
R_TRY(lrOpenRegisteredLocationResolver(®));
|
||||
ON_SCOPE_EXIT { serviceClose(®.s); };
|
||||
|
||||
R_TRY_CATCH(lrRegLrResolveProgramPath(®, static_cast<u64>(loc.title_id), path)) {
|
||||
R_TRY_CATCH(lrRegLrResolveProgramPath(®, static_cast<u64>(loc.program_id), path)) {
|
||||
R_CATCH(lr::ResultProgramNotFound) {
|
||||
/* Program wasn't found via registered resolver, fall back to the normal resolver. */
|
||||
LrLocationResolver lr;
|
||||
R_TRY(lrOpenLocationResolver(static_cast<FsStorageId>(loc.storage_id), &lr));
|
||||
ON_SCOPE_EXIT { serviceClose(&lr.s); };
|
||||
|
||||
R_TRY(lrLrResolveProgramPath(&lr, static_cast<u64>(loc.title_id), path));
|
||||
R_TRY(lrLrResolveProgramPath(&lr, static_cast<u64>(loc.program_id), path));
|
||||
}
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
|
@ -301,15 +301,15 @@ namespace ams::ldr {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RedirectContentPath(const char *path, const ncm::TitleLocation &loc) {
|
||||
Result RedirectContentPath(const char *path, const ncm::ProgramLocation &loc) {
|
||||
LrLocationResolver lr;
|
||||
R_TRY(lrOpenLocationResolver(static_cast<FsStorageId>(loc.storage_id), &lr));
|
||||
ON_SCOPE_EXIT { serviceClose(&lr.s); };
|
||||
|
||||
return lrLrRedirectProgramPath(&lr, static_cast<u64>(loc.title_id), path);
|
||||
return lrLrRedirectProgramPath(&lr, static_cast<u64>(loc.program_id), path);
|
||||
}
|
||||
|
||||
Result RedirectHtmlDocumentPathForHbl(const ncm::TitleLocation &loc) {
|
||||
Result RedirectHtmlDocumentPathForHbl(const ncm::ProgramLocation &loc) {
|
||||
char path[FS_MAX_PATH];
|
||||
|
||||
/* Open a location resolver. */
|
||||
|
@ -318,11 +318,11 @@ namespace ams::ldr {
|
|||
ON_SCOPE_EXIT { serviceClose(&lr.s); };
|
||||
|
||||
/* If there's already a Html Document path, we don't need to set one. */
|
||||
R_UNLESS(R_FAILED(lrLrResolveApplicationHtmlDocumentPath(&lr, static_cast<u64>(loc.title_id), path)), ResultSuccess());
|
||||
R_UNLESS(R_FAILED(lrLrResolveApplicationHtmlDocumentPath(&lr, static_cast<u64>(loc.program_id), path)), ResultSuccess());
|
||||
|
||||
/* We just need to set this to any valid NCA path. Let's use the executable path. */
|
||||
R_TRY(lrLrResolveProgramPath(&lr, static_cast<u64>(loc.title_id), path));
|
||||
R_TRY(lrLrRedirectApplicationHtmlDocumentPath(&lr, static_cast<u64>(loc.title_id), static_cast<u64>(loc.title_id), path));
|
||||
R_TRY(lrLrResolveProgramPath(&lr, static_cast<u64>(loc.program_id), path));
|
||||
R_TRY(lrLrRedirectApplicationHtmlDocumentPath(&lr, static_cast<u64>(loc.program_id), static_cast<u64>(loc.program_id), path));
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue