mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-09 22:56:35 +00:00
cfg: Allow more flexible hbl configuration
This commit is contained in:
parent
de1e6c9705
commit
e734b23f11
3 changed files with 108 additions and 38 deletions
|
@ -1,9 +1,18 @@
|
||||||
[hbl_config]
|
[hbl_config]
|
||||||
; program_id=010000000000100D
|
; Program Specific Config
|
||||||
|
; Up to 8 program-specific configurations can be set.
|
||||||
|
; These use `program_id_#` and `override_key_#`
|
||||||
|
; where # is in range [0,7].
|
||||||
|
; program_id_0=010000000000100D
|
||||||
|
; override_key_0=!R
|
||||||
|
|
||||||
|
; Any Application Config
|
||||||
|
; Note that this will only apply to program IDs that
|
||||||
|
; are both applications and not specified above
|
||||||
|
; by a program specific config.
|
||||||
; override_any_app=true
|
; override_any_app=true
|
||||||
; path=atmosphere/hbl.nsp
|
|
||||||
; override_key=!R
|
|
||||||
; override_any_app_key=R
|
; override_any_app_key=R
|
||||||
|
; path=atmosphere/hbl.nsp
|
||||||
|
|
||||||
[default_config]
|
[default_config]
|
||||||
; override_key=!L
|
; override_key=!L
|
||||||
|
|
|
@ -42,7 +42,6 @@ namespace ams::cfg {
|
||||||
bool HasGlobalFlag(const char *flag);
|
bool HasGlobalFlag(const char *flag);
|
||||||
|
|
||||||
/* HBL Configuration utilities. */
|
/* HBL Configuration utilities. */
|
||||||
bool IsHblProgramId(ncm::ProgramId program_id);
|
|
||||||
bool HasHblFlag(const char *flag);
|
bool HasHblFlag(const char *flag);
|
||||||
const char *GetHblPath();
|
const char *GetHblPath();
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,26 @@ namespace ams::cfg {
|
||||||
bool override_by_default;
|
bool override_by_default;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HblOverrideConfig {
|
struct ProgramOverrideKey {
|
||||||
OverrideKey override_key;
|
OverrideKey override_key;
|
||||||
OverrideKey override_any_app_key;
|
|
||||||
ncm::ProgramId program_id;
|
ncm::ProgramId program_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr ProgramOverrideKey InvalidProgramOverrideKey = {};
|
||||||
|
|
||||||
|
constexpr ProgramOverrideKey DefaultAppletPhotoViewerOverrideKey = {
|
||||||
|
.override_key = {
|
||||||
|
.key_combination = KEY_R,
|
||||||
|
.override_by_default = true,
|
||||||
|
},
|
||||||
|
.program_id = ncm::ProgramId::AppletPhotoViewer,
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr size_t MaxProgramOverrideKeys = 8;
|
||||||
|
|
||||||
|
struct HblOverrideConfig {
|
||||||
|
ProgramOverrideKey program_configs[MaxProgramOverrideKeys];
|
||||||
|
OverrideKey override_any_app_key;
|
||||||
bool override_any_app;
|
bool override_any_app;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -51,15 +67,20 @@ namespace ams::cfg {
|
||||||
};
|
};
|
||||||
|
|
||||||
HblOverrideConfig g_hbl_override_config = {
|
HblOverrideConfig g_hbl_override_config = {
|
||||||
.override_key = {
|
.program_configs = {
|
||||||
.key_combination = KEY_R,
|
DefaultAppletPhotoViewerOverrideKey,
|
||||||
.override_by_default = true,
|
InvalidProgramOverrideKey,
|
||||||
|
InvalidProgramOverrideKey,
|
||||||
|
InvalidProgramOverrideKey,
|
||||||
|
InvalidProgramOverrideKey,
|
||||||
|
InvalidProgramOverrideKey,
|
||||||
|
InvalidProgramOverrideKey,
|
||||||
|
InvalidProgramOverrideKey,
|
||||||
},
|
},
|
||||||
.override_any_app_key = {
|
.override_any_app_key = {
|
||||||
.key_combination = KEY_R,
|
.key_combination = KEY_R,
|
||||||
.override_by_default = false,
|
.override_by_default = false,
|
||||||
},
|
},
|
||||||
.program_id = ncm::ProgramId::AppletPhotoViewer,
|
|
||||||
.override_any_app = true,
|
.override_any_app = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -117,15 +138,60 @@ namespace ams::cfg {
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void SetHblSpecificProgramId(size_t i, const char *value) {
|
||||||
|
g_hbl_override_config.program_configs[i].program_id = {strtoul(value, nullptr, 16)};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void SetHblSpecificOverrideKey(size_t i, const char *value) {
|
||||||
|
g_hbl_override_config.program_configs[i].override_key = ParseOverrideKey(value);
|
||||||
|
}
|
||||||
|
|
||||||
int OverrideConfigIniHandler(void *user, const char *section, const char *name, const char *value) {
|
int OverrideConfigIniHandler(void *user, const char *section, const char *name, const char *value) {
|
||||||
/* Taken and modified, with love, from Rajkosto's implementation. */
|
/* Taken and modified, with love, from Rajkosto's implementation. */
|
||||||
if (strcasecmp(section, "hbl_config") == 0) {
|
if (strcasecmp(section, "hbl_config") == 0) {
|
||||||
/* TODO: Consider deprecating "title_id" string in the future." */
|
/* TODO: Consider deprecating "title_id" string in the future." */
|
||||||
if (strcasecmp(name, "program_id") == 0 || strcasecmp(name, "title_id") == 0) {
|
if (strcasecmp(name, "program_id") == 0 || strcasecmp(name, "program_id_0") == 0) {
|
||||||
u64 override_program_id = strtoul(value, NULL, 16);
|
SetHblSpecificProgramId(0, value);
|
||||||
if (override_program_id != 0) {
|
} else if (strcasecmp(name, "program_id_1") == 0) {
|
||||||
g_hbl_override_config.program_id = {override_program_id};
|
SetHblSpecificProgramId(1, value);
|
||||||
|
} else if (strcasecmp(name, "program_id_2") == 0) {
|
||||||
|
SetHblSpecificProgramId(2, value);
|
||||||
|
} else if (strcasecmp(name, "program_id_3") == 0) {
|
||||||
|
SetHblSpecificProgramId(3, value);
|
||||||
|
} else if (strcasecmp(name, "program_id_4") == 0) {
|
||||||
|
SetHblSpecificProgramId(4, value);
|
||||||
|
} else if (strcasecmp(name, "program_id_5") == 0) {
|
||||||
|
SetHblSpecificProgramId(5, value);
|
||||||
|
} else if (strcasecmp(name, "program_id_6") == 0) {
|
||||||
|
SetHblSpecificProgramId(6, value);
|
||||||
|
} else if (strcasecmp(name, "program_id_7") == 0) {
|
||||||
|
SetHblSpecificProgramId(7, value);
|
||||||
|
} else if (strcasecmp(name, "override_key") == 0 || strcasecmp(name, "override_key_0") == 0) {
|
||||||
|
SetHblSpecificOverrideKey(0, value);
|
||||||
|
} else if (strcasecmp(name, "override_key_1") == 0) {
|
||||||
|
SetHblSpecificOverrideKey(1, value);
|
||||||
|
} else if (strcasecmp(name, "override_key_2") == 0) {
|
||||||
|
SetHblSpecificOverrideKey(2, value);
|
||||||
|
} else if (strcasecmp(name, "override_key_3") == 0) {
|
||||||
|
SetHblSpecificOverrideKey(3, value);
|
||||||
|
} else if (strcasecmp(name, "override_key_4") == 0) {
|
||||||
|
SetHblSpecificOverrideKey(4, value);
|
||||||
|
} else if (strcasecmp(name, "override_key_5") == 0) {
|
||||||
|
SetHblSpecificOverrideKey(5, value);
|
||||||
|
} else if (strcasecmp(name, "override_key_6") == 0) {
|
||||||
|
SetHblSpecificOverrideKey(6, value);
|
||||||
|
} else if (strcasecmp(name, "override_key_7") == 0) {
|
||||||
|
SetHblSpecificOverrideKey(7, value);
|
||||||
|
} else if (strcasecmp(name, "override_any_app") == 0) {
|
||||||
|
if (strcasecmp(value, "true") == 0 || strcasecmp(value, "1") == 0) {
|
||||||
|
g_hbl_override_config.override_any_app = true;
|
||||||
|
} else if (strcasecmp(value, "false") == 0 || strcasecmp(value, "0") == 0) {
|
||||||
|
g_hbl_override_config.override_any_app = false;
|
||||||
|
} else {
|
||||||
|
/* I guess we default to not changing the value? */
|
||||||
}
|
}
|
||||||
|
} else if (strcasecmp(name, "override_any_app_key") == 0) {
|
||||||
|
g_hbl_override_config.override_any_app_key = ParseOverrideKey(value);
|
||||||
} else if (strcasecmp(name, "path") == 0) {
|
} else if (strcasecmp(name, "path") == 0) {
|
||||||
while (*value == '/' || *value == '\\') {
|
while (*value == '/' || *value == '\\') {
|
||||||
value++;
|
value++;
|
||||||
|
@ -138,18 +204,6 @@ namespace ams::cfg {
|
||||||
g_hbl_sd_path[i] = '/';
|
g_hbl_sd_path[i] = '/';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (strcasecmp(name, "override_key") == 0) {
|
|
||||||
g_hbl_override_config.override_key = ParseOverrideKey(value);
|
|
||||||
} else if (strcasecmp(name, "override_any_app") == 0) {
|
|
||||||
if (strcasecmp(value, "true") == 0 || strcasecmp(value, "1") == 0) {
|
|
||||||
g_hbl_override_config.override_any_app = true;
|
|
||||||
} else if (strcasecmp(value, "false") == 0 || strcasecmp(value, "0") == 0) {
|
|
||||||
g_hbl_override_config.override_any_app = false;
|
|
||||||
} else {
|
|
||||||
/* I guess we default to not changing the value? */
|
|
||||||
}
|
|
||||||
} else if (strcasecmp(name, "override_any_app_key") == 0) {
|
|
||||||
g_hbl_override_config.override_any_app_key = ParseOverrideKey(value);
|
|
||||||
}
|
}
|
||||||
} else if (strcasecmp(section, "default_config") == 0) {
|
} else if (strcasecmp(section, "default_config") == 0) {
|
||||||
if (strcasecmp(name, "override_key") == 0) {
|
if (strcasecmp(name, "override_key") == 0) {
|
||||||
|
@ -202,12 +256,21 @@ namespace ams::cfg {
|
||||||
return (cfg.override_by_default ^ keys_triggered);
|
return (cfg.override_by_default ^ keys_triggered);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool IsApplicationHblProgramId(ncm::ProgramId program_id) {
|
inline bool IsAnySpecificHblProgramId(ncm::ProgramId program_id) {
|
||||||
return g_hbl_override_config.override_any_app && ncm::IsApplicationProgramId(program_id);
|
for (size_t i = 0; i < MaxProgramOverrideKeys; i++) {
|
||||||
|
if (program_id == g_hbl_override_config.program_configs[i].program_id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool IsSpecificHblProgramId(ncm::ProgramId program_id) {
|
inline bool IsSpecificHblProgramId(size_t i, ncm::ProgramId program_id) {
|
||||||
return program_id == g_hbl_override_config.program_id;
|
return program_id == g_hbl_override_config.program_configs[i].program_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool IsAnyApplicationHblProgramId(ncm::ProgramId program_id) {
|
||||||
|
return g_hbl_override_config.override_any_app && ncm::IsApplicationProgramId(program_id) && !IsAnySpecificHblProgramId(program_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParseIniFile(util::ini::Handler handler, const char *path, void *user_ctx) {
|
void ParseIniFile(util::ini::Handler handler, const char *path, void *user_ctx) {
|
||||||
|
@ -272,11 +335,14 @@ namespace ams::cfg {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detect Hbl. */
|
/* Detect Hbl. */
|
||||||
if ((IsApplicationHblProgramId(program_id) && IsOverrideMatch(status, g_hbl_override_config.override_any_app_key)) ||
|
if (IsAnyApplicationHblProgramId(program_id) && IsOverrideMatch(status, g_hbl_override_config.override_any_app_key)) {
|
||||||
(IsSpecificHblProgramId(program_id) && IsOverrideMatch(status, g_hbl_override_config.override_key)))
|
|
||||||
{
|
|
||||||
status.SetHbl();
|
status.SetHbl();
|
||||||
}
|
}
|
||||||
|
for (size_t i = 0; i < MaxProgramOverrideKeys; i++) {
|
||||||
|
if (IsSpecificHblProgramId(i, program_id) && IsOverrideMatch(status, g_hbl_override_config.program_configs[i].override_key)) {
|
||||||
|
status.SetHbl();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Detect content specific keys. */
|
/* Detect content specific keys. */
|
||||||
const auto content_cfg = GetContentOverrideConfig(program_id);
|
const auto content_cfg = GetContentOverrideConfig(program_id);
|
||||||
|
@ -297,10 +363,6 @@ namespace ams::cfg {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* HBL Configuration utilities. */
|
/* HBL Configuration utilities. */
|
||||||
bool IsHblProgramId(ncm::ProgramId program_id) {
|
|
||||||
return IsApplicationHblProgramId(program_id) || IsSpecificHblProgramId(program_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *GetHblPath() {
|
const char *GetHblPath() {
|
||||||
return g_hbl_sd_path;
|
return g_hbl_sd_path;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue