strat: TitleId -> ProgramId, titles->contents

This commit is contained in:
Michael Scire 2019-10-27 21:43:01 -07:00 committed by SciresM
parent 1636668762
commit ea3ebbaa7d
86 changed files with 1138 additions and 1140 deletions

View file

@ -34,7 +34,7 @@ namespace ams {
}
extern ncm::TitleId CurrentTitleId;
extern ncm::ProgramId CurrentProgramId;
void WEAK ExceptionHandler(FatalErrorContext *ctx) {
R_ASSERT(amsBpcInitialize());
@ -49,7 +49,7 @@ namespace ams {
{
ams_ctx.magic = FatalErrorContext::Magic;
ams_ctx.error_desc = ctx->error_desc;
ams_ctx.title_id = static_cast<u64>(CurrentTitleId);
ams_ctx.program_id = static_cast<u64>(CurrentProgramId);
for (size_t i = 0; i < FatalErrorContext::NumGprs; i++) {
ams_ctx.gprs[i] = ctx->cpu_gprs[i].x;
}

View file

@ -22,101 +22,101 @@ namespace ams::boot2 {
/* Launch lists. */
/* psc, bus, pcv is the minimal set of required titles to get SD card. */
/* psc, bus, pcv is the minimal set of required programs to get SD card. */
/* bus depends on pcie, and pcv depends on settings. */
constexpr ncm::TitleId PreSdCardLaunchPrograms[] = {
ncm::TitleId::Psc, /* psc */
ncm::TitleId::Pcie, /* pcie */
ncm::TitleId::Bus, /* bus */
ncm::TitleId::Settings, /* settings */
ncm::TitleId::Pcv, /* pcv */
ncm::TitleId::Usb, /* usb */
constexpr ncm::ProgramId PreSdCardLaunchPrograms[] = {
ncm::ProgramId::Psc, /* psc */
ncm::ProgramId::Pcie, /* pcie */
ncm::ProgramId::Bus, /* bus */
ncm::ProgramId::Settings, /* settings */
ncm::ProgramId::Pcv, /* pcv */
ncm::ProgramId::Usb, /* usb */
};
constexpr size_t NumPreSdCardLaunchPrograms = util::size(PreSdCardLaunchPrograms);
constexpr ncm::TitleId AdditionalLaunchPrograms[] = {
ncm::TitleId::Tma, /* tma */
ncm::TitleId::Am, /* am */
ncm::TitleId::NvServices, /* nvservices */
ncm::TitleId::NvnFlinger, /* nvnflinger */
ncm::TitleId::Vi, /* vi */
ncm::TitleId::Ns, /* ns */
ncm::TitleId::LogManager, /* lm */
ncm::TitleId::Ppc, /* ppc */
ncm::TitleId::Ptm, /* ptm */
ncm::TitleId::Hid, /* hid */
ncm::TitleId::Audio, /* audio */
ncm::TitleId::Lbl, /* lbl */
ncm::TitleId::Wlan, /* wlan */
ncm::TitleId::Bluetooth, /* bluetooth */
ncm::TitleId::BsdSockets, /* bsdsockets */
ncm::TitleId::Nifm, /* nifm */
ncm::TitleId::Ldn, /* ldn */
ncm::TitleId::Account, /* account */
ncm::TitleId::Friends, /* friends */
ncm::TitleId::Nfc, /* nfc */
ncm::TitleId::JpegDec, /* jpegdec */
ncm::TitleId::CapSrv, /* capsrv */
ncm::TitleId::Ssl, /* ssl */
ncm::TitleId::Nim, /* nim */
ncm::TitleId::Bcat, /* bcat */
ncm::TitleId::Erpt, /* erpt */
ncm::TitleId::Es, /* es */
ncm::TitleId::Pctl, /* pctl */
ncm::TitleId::Btm, /* btm */
ncm::TitleId::Eupld, /* eupld */
ncm::TitleId::Glue, /* glue */
/* ncm::TitleId::Eclct, */ /* eclct */ /* Skip launching error collection in Atmosphere to lessen telemetry. */
ncm::TitleId::Npns, /* npns */
ncm::TitleId::Fatal, /* fatal */
ncm::TitleId::Ro, /* ro */
ncm::TitleId::Profiler, /* profiler */
ncm::TitleId::Sdb, /* sdb */
ncm::TitleId::Migration, /* migration */
ncm::TitleId::Grc, /* grc */
ncm::TitleId::Olsc, /* olsc */
ncm::TitleId::Ngct, /* ngct */
constexpr ncm::ProgramId AdditionalLaunchPrograms[] = {
ncm::ProgramId::Tma, /* tma */
ncm::ProgramId::Am, /* am */
ncm::ProgramId::NvServices, /* nvservices */
ncm::ProgramId::NvnFlinger, /* nvnflinger */
ncm::ProgramId::Vi, /* vi */
ncm::ProgramId::Ns, /* ns */
ncm::ProgramId::LogManager, /* lm */
ncm::ProgramId::Ppc, /* ppc */
ncm::ProgramId::Ptm, /* ptm */
ncm::ProgramId::Hid, /* hid */
ncm::ProgramId::Audio, /* audio */
ncm::ProgramId::Lbl, /* lbl */
ncm::ProgramId::Wlan, /* wlan */
ncm::ProgramId::Bluetooth, /* bluetooth */
ncm::ProgramId::BsdSockets, /* bsdsockets */
ncm::ProgramId::Nifm, /* nifm */
ncm::ProgramId::Ldn, /* ldn */
ncm::ProgramId::Account, /* account */
ncm::ProgramId::Friends, /* friends */
ncm::ProgramId::Nfc, /* nfc */
ncm::ProgramId::JpegDec, /* jpegdec */
ncm::ProgramId::CapSrv, /* capsrv */
ncm::ProgramId::Ssl, /* ssl */
ncm::ProgramId::Nim, /* nim */
ncm::ProgramId::Bcat, /* bcat */
ncm::ProgramId::Erpt, /* erpt */
ncm::ProgramId::Es, /* es */
ncm::ProgramId::Pctl, /* pctl */
ncm::ProgramId::Btm, /* btm */
ncm::ProgramId::Eupld, /* eupld */
ncm::ProgramId::Glue, /* glue */
/* ncm::ProgramId::Eclct, */ /* eclct */ /* Skip launching error collection in Atmosphere to lessen telemetry. */
ncm::ProgramId::Npns, /* npns */
ncm::ProgramId::Fatal, /* fatal */
ncm::ProgramId::Ro, /* ro */
ncm::ProgramId::Profiler, /* profiler */
ncm::ProgramId::Sdb, /* sdb */
ncm::ProgramId::Migration, /* migration */
ncm::ProgramId::Grc, /* grc */
ncm::ProgramId::Olsc, /* olsc */
ncm::ProgramId::Ngct, /* ngct */
};
constexpr size_t NumAdditionalLaunchPrograms = util::size(AdditionalLaunchPrograms);
constexpr ncm::TitleId AdditionalMaintenanceLaunchPrograms[] = {
ncm::TitleId::Tma, /* tma */
ncm::TitleId::Am, /* am */
ncm::TitleId::NvServices, /* nvservices */
ncm::TitleId::NvnFlinger, /* nvnflinger */
ncm::TitleId::Vi, /* vi */
ncm::TitleId::Ns, /* ns */
ncm::TitleId::LogManager, /* lm */
ncm::TitleId::Ppc, /* ppc */
ncm::TitleId::Ptm, /* ptm */
ncm::TitleId::Hid, /* hid */
ncm::TitleId::Audio, /* audio */
ncm::TitleId::Lbl, /* lbl */
ncm::TitleId::Wlan, /* wlan */
ncm::TitleId::Bluetooth, /* bluetooth */
ncm::TitleId::BsdSockets, /* bsdsockets */
ncm::TitleId::Nifm, /* nifm */
ncm::TitleId::Ldn, /* ldn */
ncm::TitleId::Account, /* account */
ncm::TitleId::Nfc, /* nfc */
ncm::TitleId::JpegDec, /* jpegdec */
ncm::TitleId::CapSrv, /* capsrv */
ncm::TitleId::Ssl, /* ssl */
ncm::TitleId::Nim, /* nim */
ncm::TitleId::Erpt, /* erpt */
ncm::TitleId::Es, /* es */
ncm::TitleId::Pctl, /* pctl */
ncm::TitleId::Btm, /* btm */
ncm::TitleId::Glue, /* glue */
/* ncm::TitleId::Eclct, */ /* eclct */ /* Skip launching error collection in Atmosphere to lessen telemetry. */
ncm::TitleId::Fatal, /* fatal */
ncm::TitleId::Ro, /* ro */
ncm::TitleId::Profiler, /* profiler */
ncm::TitleId::Sdb, /* sdb */
ncm::TitleId::Migration, /* migration */
ncm::TitleId::Grc, /* grc */
ncm::TitleId::Olsc, /* olsc */
ncm::TitleId::Ngct, /* ngct */
constexpr ncm::ProgramId AdditionalMaintenanceLaunchPrograms[] = {
ncm::ProgramId::Tma, /* tma */
ncm::ProgramId::Am, /* am */
ncm::ProgramId::NvServices, /* nvservices */
ncm::ProgramId::NvnFlinger, /* nvnflinger */
ncm::ProgramId::Vi, /* vi */
ncm::ProgramId::Ns, /* ns */
ncm::ProgramId::LogManager, /* lm */
ncm::ProgramId::Ppc, /* ppc */
ncm::ProgramId::Ptm, /* ptm */
ncm::ProgramId::Hid, /* hid */
ncm::ProgramId::Audio, /* audio */
ncm::ProgramId::Lbl, /* lbl */
ncm::ProgramId::Wlan, /* wlan */
ncm::ProgramId::Bluetooth, /* bluetooth */
ncm::ProgramId::BsdSockets, /* bsdsockets */
ncm::ProgramId::Nifm, /* nifm */
ncm::ProgramId::Ldn, /* ldn */
ncm::ProgramId::Account, /* account */
ncm::ProgramId::Nfc, /* nfc */
ncm::ProgramId::JpegDec, /* jpegdec */
ncm::ProgramId::CapSrv, /* capsrv */
ncm::ProgramId::Ssl, /* ssl */
ncm::ProgramId::Nim, /* nim */
ncm::ProgramId::Erpt, /* erpt */
ncm::ProgramId::Es, /* es */
ncm::ProgramId::Pctl, /* pctl */
ncm::ProgramId::Btm, /* btm */
ncm::ProgramId::Glue, /* glue */
/* ncm::ProgramId::Eclct, */ /* eclct */ /* Skip launching error collection in Atmosphere to lessen telemetry. */
ncm::ProgramId::Fatal, /* fatal */
ncm::ProgramId::Ro, /* ro */
ncm::ProgramId::Profiler, /* profiler */
ncm::ProgramId::Sdb, /* sdb */
ncm::ProgramId::Migration, /* migration */
ncm::ProgramId::Grc, /* grc */
ncm::ProgramId::Olsc, /* olsc */
ncm::ProgramId::Ngct, /* ngct */
};
constexpr size_t NumAdditionalMaintenanceLaunchPrograms = util::size(AdditionalMaintenanceLaunchPrograms);
@ -134,12 +134,12 @@ namespace ams::boot2 {
return c == '\r' || c == '\n';
}
void LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 launch_flags) {
void LaunchProgram(os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 launch_flags) {
os::ProcessId process_id = os::InvalidProcessId;
/* Launch, lightly validate result. */
{
const auto launch_result = pm::shell::LaunchTitle(&process_id, loc, launch_flags);
const auto launch_result = pm::shell::LaunchProgram(&process_id, loc, launch_flags);
AMS_ASSERT(!(svc::ResultOutOfResource::Includes(launch_result)));
AMS_ASSERT(!(svc::ResultOutOfMemory::Includes(launch_result)));
AMS_ASSERT(!(svc::ResultLimitReached::Includes(launch_result)));
@ -150,9 +150,9 @@ namespace ams::boot2 {
}
}
void LaunchList(const ncm::TitleId *launch_list, size_t num_entries) {
void LaunchList(const ncm::ProgramId *launch_list, size_t num_entries) {
for (size_t i = 0; i < num_entries; i++) {
LaunchTitle(nullptr, ncm::TitleLocation::Make(launch_list[i], ncm::StorageId::NandSystem), 0);
LaunchProgram(nullptr, ncm::ProgramLocation::Make(launch_list[i], ncm::StorageId::NandSystem), 0);
}
}
@ -190,35 +190,35 @@ namespace ams::boot2 {
}
template<typename F>
void IterateOverFlaggedTitlesOnSdCard(F f) {
/* Validate that the titles directory exists. */
DIR *titles_dir = opendir("sdmc:/atmosphere/titles");
if (titles_dir == nullptr) {
void IterateOverFlaggedProgramsOnSdCard(F f) {
/* Validate that the contents directory exists. */
DIR *contents_dir = opendir("sdmc:/atmosphere/contents");
if (contents_dir == nullptr) {
return;
}
ON_SCOPE_EXIT { closedir(titles_dir); };
ON_SCOPE_EXIT { closedir(contents_dir); };
/* Iterate over entries in the titles directory */
/* Iterate over entries in the contents directory */
struct dirent *ent;
while ((ent = readdir(titles_dir)) != nullptr) {
/* Check that the subdirectory can be converted to a title id. */
if (std::strlen(ent->d_name) == 2 * sizeof(ncm::TitleId) && IsHexadecimal(ent->d_name)) {
/* Check if we've already launched the title. */
ncm::TitleId title_id{std::strtoul(ent->d_name, nullptr, 16)};
while ((ent = readdir(contents_dir)) != nullptr) {
/* Check that the subdirectory can be converted to a program id. */
if (std::strlen(ent->d_name) == 2 * sizeof(ncm::ProgramId) && IsHexadecimal(ent->d_name)) {
/* Check if we've already launched the program. */
ncm::ProgramId program_id{std::strtoul(ent->d_name, nullptr, 16)};
/* Check if the title is flagged. */
if (!cfg::HasTitleSpecificFlag(title_id, "boot2")) {
/* Check if the program is flagged. */
if (!cfg::HasContentSpecificFlag(program_id, "boot2")) {
continue;
}
/* Call the iteration callback. */
f(title_id);
f(program_id);
}
}
}
void DetectAndDeclareFutureMitms() {
IterateOverFlaggedTitlesOnSdCard([](ncm::TitleId title_id) {
IterateOverFlaggedProgramsOnSdCard([](ncm::ProgramId program_id) {
/* When we find a flagged program, check if it has a mitm list. */
char mitm_list[0x400];
size_t mitm_list_size = 0;
@ -226,7 +226,7 @@ namespace ams::boot2 {
/* Read the mitm list off the SD card. */
{
char path[FS_MAX_PATH];
std::snprintf(mitm_list, sizeof(mitm_list), "sdmc:/atmosphere/titles/%016lx/mitm.lst", static_cast<u64>(title_id));
std::snprintf(mitm_list, sizeof(mitm_list), "sdmc:/atmosphere/contents/%016lx/mitm.lst", static_cast<u64>(program_id));
FILE *f = fopen(path, "rb");
if (f == nullptr) {
return;
@ -278,14 +278,14 @@ namespace ams::boot2 {
}
void LaunchFlaggedProgramsOnSdCard() {
IterateOverFlaggedTitlesOnSdCard([](ncm::TitleId title_id) {
/* Check if we've already launched the title. */
if (pm::info::HasLaunchedTitle(title_id)) {
IterateOverFlaggedProgramsOnSdCard([](ncm::ProgramId program_id) {
/* Check if we've already launched the program. */
if (pm::info::HasLaunchedProgram(program_id)) {
return;
}
/* Launch the title. */
LaunchTitle(nullptr, ncm::TitleLocation::Make(title_id, ncm::StorageId::None), 0);
/* Launch the program. */
LaunchProgram(nullptr, ncm::ProgramLocation::Make(program_id, ncm::StorageId::None), 0);
});
}
@ -314,7 +314,7 @@ namespace ams::boot2 {
}
/* Launch Atmosphere boot2, using FsStorageId_None to force SD card boot. */
LaunchTitle(nullptr, ncm::TitleLocation::Make(ncm::TitleId::Boot2, ncm::StorageId::None), 0);
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::ProgramId::Boot2, ncm::StorageId::None), 0);
}
void LaunchPostSdCardBootPrograms() {
@ -327,7 +327,7 @@ namespace ams::boot2 {
}
/* Launch Atmosphere dmnt, using FsStorageId_None to force SD card boot. */
LaunchTitle(nullptr, ncm::TitleLocation::Make(ncm::TitleId::Dmnt, ncm::StorageId::None), 0);
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::ProgramId::Dmnt, ncm::StorageId::None), 0);
/* Check for and forward declare non-atmosphere mitm modules. */
DetectAndDeclareFutureMitms();
@ -337,7 +337,7 @@ namespace ams::boot2 {
LaunchList(AdditionalMaintenanceLaunchPrograms, NumAdditionalMaintenanceLaunchPrograms);
/* Starting in 7.0.0, npns is launched during maintenance boot. */
if (hos::GetVersion() >= hos::Version_700) {
LaunchTitle(nullptr, ncm::TitleLocation::Make(ncm::TitleId::Npns, ncm::StorageId::NandSystem), 0);
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::ProgramId::Npns, ncm::StorageId::NandSystem), 0);
}
} else {
LaunchList(AdditionalLaunchPrograms, NumAdditionalLaunchPrograms);

View file

@ -47,20 +47,20 @@ namespace ams::cfg {
}
/* Flag utilities. */
bool HasFlag(ncm::TitleId title_id, const char *flag) {
return HasTitleSpecificFlag(title_id, flag) || (IsHblTitleId(title_id) && HasHblFlag(flag));
bool HasFlag(ncm::ProgramId program_id, const char *flag) {
return HasContentSpecificFlag(program_id, flag) || (IsHblProgramId(program_id) && HasHblFlag(flag));
}
bool HasTitleSpecificFlag(ncm::TitleId title_id, const char *flag) {
char title_flag[FS_MAX_PATH];
std::snprintf(title_flag, sizeof(title_flag) - 1, "/atmosphere/titles/%016lx/flags/%s.flag", static_cast<u64>(title_id), flag);
return HasFlagFile(title_flag);
bool HasContentSpecificFlag(ncm::ProgramId program_id, const char *flag) {
char content_flag[FS_MAX_PATH];
std::snprintf(content_flag, sizeof(content_flag) - 1, "/atmosphere/contents/%016lx/flags/%s.flag", static_cast<u64>(program_id), flag);
return HasFlagFile(content_flag);
}
bool HasGlobalFlag(const char *flag) {
char title_flag[FS_MAX_PATH];
std::snprintf(title_flag, sizeof(title_flag) - 1, "/atmosphere/flags/%s.flag", flag);
return HasFlagFile(title_flag);
char global_flag[FS_MAX_PATH];
std::snprintf(global_flag, sizeof(global_flag) - 1, "/atmosphere/flags/%s.flag", flag);
return HasFlagFile(global_flag);
}
bool HasHblFlag(const char *flag) {

View file

@ -28,11 +28,11 @@ namespace ams::cfg {
struct HblOverrideConfig {
OverrideKey override_key;
ncm::TitleId title_id;
ncm::ProgramId program_id;
bool override_any_app;
};
struct TitleSpecificOverrideConfig {
struct ContentSpecificOverrideConfig {
OverrideKey override_key;
OverrideKey cheat_enable_key;
};
@ -53,7 +53,7 @@ namespace ams::cfg {
.key_combination = KEY_R,
.override_by_default = false,
},
.title_id = ncm::TitleId::AppletPhotoViewer,
.program_id = ncm::ProgramId::AppletPhotoViewer,
.override_any_app = true,
};
@ -114,10 +114,11 @@ namespace ams::cfg {
int LoaderIniHandler(void *user, const char *section, const char *name, const char *value) {
/* Taken and modified, with love, from Rajkosto's implementation. */
if (strcasecmp(section, "hbl_config") == 0) {
if (strcasecmp(name, "title_id") == 0) {
u64 override_tid = strtoul(value, NULL, 16);
if (override_tid != 0) {
g_hbl_override_config.title_id = {override_tid};
/* TODO: Consider deprecating "title_id" string in the future." */
if (strcasecmp(name, "program_id") == 0 || strcasecmp(name, "title_id") == 0) {
u64 override_program_id = strtoul(value, NULL, 16);
if (override_program_id != 0) {
g_hbl_override_config.program_id = {override_program_id};
}
} else if (strcasecmp(name, "path") == 0) {
while (*value == '/' || *value == '\\') {
@ -148,8 +149,8 @@ namespace ams::cfg {
return 1;
}
int TitleSpecificIniHandler(void *user, const char *section, const char *name, const char *value) {
TitleSpecificOverrideConfig *config = reinterpret_cast<TitleSpecificOverrideConfig *>(user);
int ContentSpecificIniHandler(void *user, const char *section, const char *name, const char *value) {
ContentSpecificOverrideConfig *config = reinterpret_cast<ContentSpecificOverrideConfig *>(user);
if (strcasecmp(section, "override_config") == 0) {
if (strcasecmp(name, "override_key") == 0) {
@ -163,7 +164,7 @@ namespace ams::cfg {
return 1;
}
bool IsOverrideKeyHeld(OverrideKey *cfg) {
bool IsOverrideKeyHeld(const OverrideKey *cfg) {
u64 kHeld = 0;
bool keys_triggered = (R_SUCCEEDED(hid::GetKeysHeld(&kHeld)) && ((kHeld & cfg->key_combination) != 0));
return IsSdCardInitialized() && (cfg->override_by_default ^ keys_triggered);
@ -192,28 +193,28 @@ namespace ams::cfg {
ParseIniFile(LoaderIniHandler, "/atmosphere/loader.ini", nullptr);
}
TitleSpecificOverrideConfig GetTitleOverrideConfig(ncm::TitleId title_id) {
ContentSpecificOverrideConfig GetContentOverrideConfig(ncm::ProgramId program_id) {
char path[FS_MAX_PATH];
std::snprintf(path, sizeof(path) - 1, "/atmosphere/titles/%016lx/config.ini", static_cast<u64>(title_id));
std::snprintf(path, sizeof(path) - 1, "/atmosphere/contents/%016lx/config.ini", static_cast<u64>(program_id));
TitleSpecificOverrideConfig config = {
ContentSpecificOverrideConfig config = {
.override_key = g_default_override_key,
.cheat_enable_key = g_default_cheat_enable_key,
};
ParseIniFile(TitleSpecificIniHandler, path, &config);
ParseIniFile(ContentSpecificIniHandler, path, &config);
return config;
}
}
bool IsHblOverrideKeyHeld(ncm::TitleId title_id) {
bool IsHblOverrideKeyHeld(ncm::ProgramId program_id) {
/* If the SD card isn't initialized, we can't override. */
if (!IsSdCardInitialized()) {
return false;
}
/* For system modules and anything launched before the home menu, always override. */
if (title_id < ncm::TitleId::AppletStart || !pm::info::HasLaunchedTitle(ncm::TitleId::AppletQlaunch)) {
if (program_id < ncm::ProgramId::AppletStart || !pm::info::HasLaunchedProgram(ncm::ProgramId::AppletQlaunch)) {
return true;
}
@ -221,40 +222,40 @@ namespace ams::cfg {
RefreshLoaderConfiguration();
/* Check HBL config. */
return IsHblTitleId(title_id) && IsOverrideKeyHeld(&g_hbl_override_config.override_key);
return IsHblProgramId(program_id) && IsOverrideKeyHeld(&g_hbl_override_config.override_key);
}
bool IsTitleOverrideKeyHeld(ncm::TitleId title_id) {
bool IsProgramOverrideKeyHeld(ncm::ProgramId program_id) {
/* If the SD card isn't initialized, we can't override. */
if (!IsSdCardInitialized()) {
return false;
}
/* For system modules and anything launched before the home menu, always override. */
if (title_id < ncm::TitleId::AppletStart || !pm::info::HasLaunchedTitle(ncm::TitleId::AppletQlaunch)) {
if (program_id < ncm::ProgramId::AppletStart || !pm::info::HasLaunchedProgram(ncm::ProgramId::AppletQlaunch)) {
return true;
}
/* Unconditionally refresh loader.ini contents. */
RefreshLoaderConfiguration();
TitleSpecificOverrideConfig title_cfg = GetTitleOverrideConfig(title_id);
return IsOverrideKeyHeld(&title_cfg.override_key);
const auto content_cfg = GetContentOverrideConfig(program_id);
return IsOverrideKeyHeld(&content_cfg.override_key);
}
void GetOverrideKeyHeldStatus(bool *out_hbl, bool *out_title, ncm::TitleId title_id) {
void GetOverrideKeyHeldStatus(bool *out_hbl, bool *out_program, ncm::ProgramId program_id) {
/* If the SD card isn't initialized, we can't override. */
if (!IsSdCardInitialized()) {
*out_hbl = false;
*out_title = false;
*out_program = false;
return;
}
/* For system modules and anything launched before the home menu, always override. */
if (title_id < ncm::TitleId::AppletStart || !pm::info::HasLaunchedTitle(ncm::TitleId::AppletQlaunch)) {
if (program_id < ncm::ProgramId::AppletStart || !pm::info::HasLaunchedProgram(ncm::ProgramId::AppletQlaunch)) {
*out_hbl = false;
*out_title = true;
*out_program = true;
return;
}
@ -262,31 +263,31 @@ namespace ams::cfg {
RefreshLoaderConfiguration();
/* Set HBL output. */
*out_hbl = IsHblTitleId(title_id) && IsOverrideKeyHeld(&g_hbl_override_config.override_key);
*out_hbl = IsHblProgramId(program_id) && IsOverrideKeyHeld(&g_hbl_override_config.override_key);
/* Set title specific output. */
TitleSpecificOverrideConfig title_cfg = GetTitleOverrideConfig(title_id);
*out_title = IsOverrideKeyHeld(&title_cfg.override_key);
/* Set content specific output. */
const auto content_cfg = GetContentOverrideConfig(program_id);
*out_program = IsOverrideKeyHeld(&content_cfg.override_key);
}
bool IsCheatEnableKeyHeld(ncm::TitleId title_id) {
bool IsCheatEnableKeyHeld(ncm::ProgramId program_id) {
/* If the SD card isn't initialized, don't apply cheats. */
if (!IsSdCardInitialized()) {
return false;
}
/* Don't apply cheats to HBL. */
if (IsHblOverrideKeyHeld(title_id)) {
if (IsHblOverrideKeyHeld(program_id)) {
return false;
}
TitleSpecificOverrideConfig title_cfg = GetTitleOverrideConfig(title_id);
return IsOverrideKeyHeld(&title_cfg.cheat_enable_key);
const auto content_cfg = GetContentOverrideConfig(program_id);
return IsOverrideKeyHeld(&content_cfg.cheat_enable_key);
}
/* HBL Configuration utilities. */
bool IsHblTitleId(ncm::TitleId title_id) {
return (g_hbl_override_config.override_any_app && ncm::IsApplicationTitleId(title_id)) || (title_id == g_hbl_override_config.title_id);
bool IsHblProgramId(ncm::ProgramId program_id) {
return (g_hbl_override_config.override_any_app && ncm::IsApplicationProgramId(program_id)) || (program_id == g_hbl_override_config.program_id);
}
const char *GetHblPath() {

View file

@ -35,7 +35,7 @@ namespace ams::hid {
Result EnsureHidInitialized() {
if (!g_initialized_hid) {
if (!serviceIsActive(hidGetServiceSession())) {
if (!pm::info::HasLaunchedTitle(ncm::TitleId::Hid)) {
if (!pm::info::HasLaunchedProgram(ncm::ProgramId::Hid)) {
return MAKERESULT(Module_Libnx, LibnxError_InitFail_HID);
}
InitializeHid();

View file

@ -17,17 +17,17 @@
#include <switch.h>
#include "ldr_ams.h"
static Result _ldrAtmosphereHasLaunchedTitle(Service *srv, bool *out, u64 tid) {
static Result _ldrAtmosphereHasLaunchedProgram(Service *srv, bool *out, u64 program_id) {
u8 tmp;
Result rc = serviceDispatchInOut(srv, 65000, tid, tmp);
Result rc = serviceDispatchInOut(srv, 65000, program_id, tmp);
if (R_SUCCEEDED(rc) && out) *out = tmp & 1;
return rc;
}
Result ldrDmntAtmosphereHasLaunchedTitle(bool *out, u64 tid) {
return _ldrAtmosphereHasLaunchedTitle(ldrDmntGetServiceSession(), out, tid);
Result ldrDmntAtmosphereHasLaunchedProgram(bool *out, u64 program_id) {
return _ldrAtmosphereHasLaunchedProgram(ldrDmntGetServiceSession(), out, program_id);
}
Result ldrPmAtmosphereHasLaunchedTitle(bool *out, u64 tid) {
return _ldrAtmosphereHasLaunchedTitle(ldrPmGetServiceSession(), out, tid);
Result ldrPmAtmosphereHasLaunchedProgram(bool *out, u64 program_id) {
return _ldrAtmosphereHasLaunchedProgram(ldrPmGetServiceSession(), out, program_id);
}

View file

@ -11,8 +11,8 @@
extern "C" {
#endif
Result ldrPmAtmosphereHasLaunchedTitle(bool *out, u64 tid);
Result ldrDmntAtmosphereHasLaunchedTitle(bool *out, u64 tid);
Result ldrPmAtmosphereHasLaunchedProgram(bool *out, u64 program_id);
Result ldrDmntAtmosphereHasLaunchedProgram(bool *out, u64 program_id);
#ifdef __cplusplus
}

View file

@ -20,24 +20,24 @@ namespace ams::ldr::pm {
/* Information API. */
Result CreateProcess(Handle *out, PinId pin_id, u32 flags, Handle reslimit) {
return ldrPmCreateProcess(flags, pin_id.value, reslimit, out);
return ldrPmCreateProcess(pin_id.value, flags, reslimit, out);
}
Result GetProgramInfo(ProgramInfo *out, const ncm::TitleLocation &loc) {
return ldrPmGetProgramInfo(static_cast<u64>(loc.title_id), static_cast<FsStorageId>(loc.storage_id), reinterpret_cast<LoaderProgramInfo *>(out));
Result GetProgramInfo(ProgramInfo *out, const ncm::ProgramLocation &loc) {
return ldrPmGetProgramInfo(reinterpret_cast<const NcmProgramLocation *>(&loc), reinterpret_cast<LoaderProgramInfo *>(out));
}
Result PinTitle(PinId *out, const ncm::TitleLocation &loc) {
Result PinProgram(PinId *out, const ncm::ProgramLocation &loc) {
static_assert(sizeof(*out) == sizeof(u64), "PinId definition!");
return ldrPmRegisterTitle(static_cast<u64>(loc.title_id), static_cast<FsStorageId>(loc.storage_id), reinterpret_cast<u64 *>(out));
return ldrPmPinProgram(reinterpret_cast<const NcmProgramLocation *>(&loc), reinterpret_cast<u64 *>(out));
}
Result UnpinTitle(PinId pin_id) {
return ldrPmUnregisterTitle(pin_id.value);
Result UnpinProgram(PinId pin_id) {
return ldrPmUnpinProgram(pin_id.value);
}
Result HasLaunchedTitle(bool *out, ncm::TitleId title_id) {
return ldrPmAtmosphereHasLaunchedTitle(out, static_cast<u64>(title_id));
Result HasLaunchedProgram(bool *out, ncm::ProgramId program_id) {
return ldrPmAtmosphereHasLaunchedProgram(out, static_cast<u64>(program_id));
}
}

View file

@ -17,32 +17,26 @@
#include <switch.h>
#include "pm_ams.h"
Result pminfoAtmosphereGetProcessId(u64 *out_pid, u64 tid) {
return serviceDispatchInOut(pminfoGetServiceSession(), 65000, tid, *out_pid);
Result pminfoAtmosphereGetProcessId(u64 *out_pid, u64 program_id) {
return serviceDispatchInOut(pminfoGetServiceSession(), 65000, program_id, *out_pid);
}
Result pminfoAtmosphereHasLaunchedTitle(bool *out, u64 tid) {
Result pminfoAtmosphereHasLaunchedProgram(bool *out, u64 program_id) {
u8 tmp;
Result rc = serviceDispatchInOut(pminfoGetServiceSession(), 65001, tid, tmp);
Result rc = serviceDispatchInOut(pminfoGetServiceSession(), 65001, program_id, tmp);
if (R_SUCCEEDED(rc) && out) *out = tmp & 1;
return rc;
}
Result pmdmntAtmosphereGetProcessInfo(Handle* handle_out, u64 *tid_out, u8 *sid_out, u64 pid) {
struct {
u64 title_id;
u8 storage_id;
} out;
Result pmdmntAtmosphereGetProcessInfo(Handle* handle_out, NcmProgramLocation *loc_out, u64 pid) {
Handle tmp_handle;
Result rc = serviceDispatchInOut(pmdmntGetServiceSession(), 65000, pid, out,
Result rc = serviceDispatchInOut(pmdmntGetServiceSession(), 65000, pid, *loc_out,
.out_handle_attrs = { SfOutHandleAttr_HipcCopy },
.out_handles = &tmp_handle,
);
if (R_SUCCEEDED(rc)) {
if (tid_out) *tid_out = out.title_id;
if (sid_out) *sid_out = out.storage_id;
if (handle_out) {
*handle_out = tmp_handle;
} else {

View file

@ -11,10 +11,10 @@
extern "C" {
#endif
Result pminfoAtmosphereGetProcessId(u64 *out_pid, u64 tid);
Result pminfoAtmosphereHasLaunchedTitle(bool *out, u64 tid);
Result pminfoAtmosphereGetProcessId(u64 *out_pid, u64 program_id);
Result pminfoAtmosphereHasLaunchedProgram(bool *out, u64 program_id);
Result pmdmntAtmosphereGetProcessInfo(Handle *out, u64 *tid_out, u8 *sid_out, u64 pid);
Result pmdmntAtmosphereGetProcessInfo(Handle *out, NcmProgramLocation *loc_out, u64 pid);
Result pmdmntAtmosphereGetCurrentLimitInfo(u64 *out_cur, u64 *out_lim, u32 group, u32 resource);
#ifdef __cplusplus

View file

@ -24,8 +24,8 @@ namespace ams::pm::dmnt {
return pmdmntStartProcess(static_cast<u64>(process_id));
}
Result GetProcessId(os::ProcessId *out_process_id, const ncm::TitleId title_id) {
return pmdmntGetProcessId(reinterpret_cast<u64 *>(out_process_id), static_cast<u64>(title_id));
Result GetProcessId(os::ProcessId *out_process_id, const ncm::ProgramId program_id) {
return pmdmntGetProcessId(reinterpret_cast<u64 *>(out_process_id), static_cast<u64>(program_id));
}
Result GetApplicationProcessId(os::ProcessId *out_process_id) {
@ -39,10 +39,10 @@ namespace ams::pm::dmnt {
return ResultSuccess();
}
Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::TitleLocation *out_loc, os::ProcessId process_id) {
Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::ProgramLocation *out_loc, os::ProcessId process_id) {
*out_handle = INVALID_HANDLE;
*out_loc = {};
return pmdmntAtmosphereGetProcessInfo(out_handle, reinterpret_cast<u64 *>(&out_loc->title_id), &out_loc->storage_id, static_cast<u64>(process_id));
return pmdmntAtmosphereGetProcessInfo(out_handle, reinterpret_cast<NcmProgramLocation *>(out_loc), static_cast<u64>(process_id));
}
Result AtmosphereGetCurrentLimitInfo(u64 *out_current_value, u64 *out_limit_value, ResourceLimitGroup group, LimitableResource resource) {

View file

@ -22,44 +22,45 @@ namespace ams::pm::info {
/* Global lock. */
os::Mutex g_info_lock;
std::set<u64> g_cached_launched_titles;
/* TODO: Less memory-intensive storage? */
std::set<u64> g_cached_launched_programs;
}
/* Information API. */
Result GetTitleId(ncm::TitleId *out_title_id, os::ProcessId process_id) {
Result GetProgramId(ncm::ProgramId *out_program_id, os::ProcessId process_id) {
std::scoped_lock lk(g_info_lock);
return pminfoGetProgramId(reinterpret_cast<u64 *>(out_title_id), static_cast<u64>(process_id));
return pminfoGetProgramId(reinterpret_cast<u64 *>(out_program_id), static_cast<u64>(process_id));
}
Result GetProcessId(os::ProcessId *out_process_id, ncm::TitleId title_id) {
Result GetProcessId(os::ProcessId *out_process_id, ncm::ProgramId program_id) {
std::scoped_lock lk(g_info_lock);
return pminfoAtmosphereGetProcessId(reinterpret_cast<u64 *>(out_process_id), static_cast<u64>(title_id));
return pminfoAtmosphereGetProcessId(reinterpret_cast<u64 *>(out_process_id), static_cast<u64>(program_id));
}
Result WEAK HasLaunchedTitle(bool *out, ncm::TitleId title_id) {
Result WEAK HasLaunchedProgram(bool *out, ncm::ProgramId program_id) {
std::scoped_lock lk(g_info_lock);
if (g_cached_launched_titles.find(static_cast<u64>(title_id)) != g_cached_launched_titles.end()) {
if (g_cached_launched_programs.find(static_cast<u64>(program_id)) != g_cached_launched_programs.end()) {
*out = true;
return ResultSuccess();
}
bool has_launched = false;
R_TRY(pminfoAtmosphereHasLaunchedTitle(&has_launched, static_cast<u64>(title_id)));
R_TRY(pminfoAtmosphereHasLaunchedProgram(&has_launched, static_cast<u64>(program_id)));
if (has_launched) {
g_cached_launched_titles.insert(static_cast<u64>(title_id));
g_cached_launched_programs.insert(static_cast<u64>(program_id));
}
*out = has_launched;
return ResultSuccess();
}
bool HasLaunchedTitle(ncm::TitleId title_id) {
bool HasLaunchedProgram(ncm::ProgramId program_id) {
bool has_launched = false;
R_ASSERT(HasLaunchedTitle(&has_launched, title_id));
R_ASSERT(HasLaunchedProgram(&has_launched, program_id));
return has_launched;
}

View file

@ -18,9 +18,9 @@
namespace ams::pm::shell {
/* Shell API. */
Result WEAK LaunchTitle(os::ProcessId *out_process_id, const ncm::TitleLocation &loc, u32 launch_flags) {
static_assert(sizeof(ncm::TitleLocation) == sizeof(NcmProgramLocation));
static_assert(alignof(ncm::TitleLocation) == alignof(NcmProgramLocation));
Result WEAK LaunchProgram(os::ProcessId *out_process_id, const ncm::ProgramLocation &loc, u32 launch_flags) {
static_assert(sizeof(ncm::ProgramLocation) == sizeof(NcmProgramLocation));
static_assert(alignof(ncm::ProgramLocation) == alignof(NcmProgramLocation));
return pmshellLaunchProgram(launch_flags, reinterpret_cast<const NcmProgramLocation *>(&loc), reinterpret_cast<u64 *>(out_process_id));
}

View file

@ -19,8 +19,8 @@
namespace ams::sm::manager {
/* Manager API. */
Result RegisterProcess(os::ProcessId process_id, ncm::TitleId title_id, const void *acid, size_t acid_size, const void *aci, size_t aci_size) {
return smManagerAtmosphereRegisterProcess(static_cast<u64>(process_id), static_cast<u64>(title_id), acid, acid_size, aci, aci_size);
Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, const void *acid, size_t acid_size, const void *aci, size_t aci_size) {
return smManagerAtmosphereRegisterProcess(static_cast<u64>(process_id), static_cast<u64>(program_id), acid, acid_size, aci, aci_size);
}
Result UnregisterProcess(os::ProcessId process_id) {

View file

@ -36,9 +36,9 @@ namespace ams::sm::mitm {
});
}
Result AcknowledgeSession(Service *out_service, os::ProcessId *out_pid, ncm::TitleId *out_tid, ServiceName name) {
Result AcknowledgeSession(Service *out_service, os::ProcessId *out_process_id, ncm::ProgramId *out_program_id, ServiceName name) {
return impl::DoWithMitmSession([&]() {
return smAtmosphereMitmAcknowledgeSession(out_service, &out_pid->value, &out_tid->value, impl::ConvertName(name));
return smAtmosphereMitmAcknowledgeSession(out_service, &out_process_id->value, &out_program_id->value, impl::ConvertName(name));
});
}

View file

@ -148,10 +148,10 @@ namespace ams::updater {
NcmContentMetaKey *records = reinterpret_cast<NcmContentMetaKey *>(work_buffer);
const auto title_type = GetNcmContentMetaType(mode);
const auto content_meta_type = GetNcmContentMetaType(mode);
s32 written_entries;
s32 total_entries;
R_TRY(ncmContentMetaDatabaseList(&meta_db, &total_entries, &written_entries, records, MaxContentMetas * sizeof(*records), title_type, 0, 0, UINT64_MAX, NcmContentInstallType_Full));
R_TRY(ncmContentMetaDatabaseList(&meta_db, &total_entries, &written_entries, records, MaxContentMetas * sizeof(*records), content_meta_type, 0, 0, UINT64_MAX, NcmContentInstallType_Full));
if (total_entries <= 0) {
return ResultBootImagePackageNotFound();
}
@ -165,14 +165,14 @@ namespace ams::updater {
R_TRY(ncmContentMetaDatabaseGetAttributes(&meta_db, &records[i], &attr));
if (attr & NcmContentMetaAttribute_IncludesExFatDriver) {
*out_data_id = records[i].title_id;
*out_data_id = records[i].id;
return ResultSuccess();
}
}
}
/* If there's only one entry or no exfat entries, return that entry. */
*out_data_id = records[0].title_id;
*out_data_id = records[0].id;
return ResultSuccess();
}