2018-09-07 15:00:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Atmosphère-NX
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-06-10 17:11:05 +00:00
|
|
|
#include <switch.h>
|
|
|
|
#include <stratosphere.hpp>
|
|
|
|
#include <atomic>
|
2018-07-28 19:29:54 +00:00
|
|
|
#include <algorithm>
|
2018-10-17 02:01:41 +00:00
|
|
|
#include <strings.h>
|
2018-06-10 17:11:05 +00:00
|
|
|
|
2018-06-14 23:50:01 +00:00
|
|
|
#include "debug.hpp"
|
2018-06-10 17:11:05 +00:00
|
|
|
#include "fsmitm_utils.hpp"
|
2018-10-17 02:01:41 +00:00
|
|
|
#include "ini.h"
|
2018-06-10 17:11:05 +00:00
|
|
|
|
2018-06-14 23:50:01 +00:00
|
|
|
static FsFileSystem g_sd_filesystem = {0};
|
2018-07-28 19:29:54 +00:00
|
|
|
static std::vector<u64> g_mitm_flagged_tids;
|
2018-10-17 03:41:19 +00:00
|
|
|
static std::vector<u64> g_disable_mitm_flagged_tids;
|
2018-07-28 19:29:54 +00:00
|
|
|
static std::atomic_bool g_has_initialized = false;
|
2018-10-17 02:01:41 +00:00
|
|
|
static std::atomic_bool g_has_hid_session = false;
|
|
|
|
|
|
|
|
static u64 g_override_key_combination = KEY_R;
|
2018-11-15 12:26:40 +00:00
|
|
|
static u64 g_override_hbl_tid = 0x010000000000100DULL;
|
2018-10-17 02:01:41 +00:00
|
|
|
static bool g_override_by_default = true;
|
2018-06-10 17:11:05 +00:00
|
|
|
|
2018-10-23 05:53:40 +00:00
|
|
|
/* Static buffer for loader.ini contents at runtime. */
|
|
|
|
static char g_config_ini_data[0x800];
|
|
|
|
|
2018-07-28 19:29:54 +00:00
|
|
|
static bool IsHexadecimal(const char *str) {
|
|
|
|
while (*str) {
|
2018-07-30 00:27:30 +00:00
|
|
|
if (isxdigit(*str)) {
|
|
|
|
str++;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2018-06-10 17:11:05 +00:00
|
|
|
}
|
2018-07-28 19:29:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Utils::InitializeSdThreadFunc(void *args) {
|
|
|
|
/* Get required services. */
|
|
|
|
Handle tmp_hnd = 0;
|
2018-06-12 22:00:09 +00:00
|
|
|
static const char * const required_active_services[] = {"pcv", "gpio", "pinmux", "psc:c"};
|
|
|
|
for (unsigned int i = 0; i < sizeof(required_active_services) / sizeof(required_active_services[0]); i++) {
|
2018-07-28 19:29:54 +00:00
|
|
|
if (R_FAILED(smGetServiceOriginal(&tmp_hnd, smEncodeName(required_active_services[i])))) {
|
|
|
|
/* TODO: Panic */
|
|
|
|
} else {
|
|
|
|
svcCloseHandle(tmp_hnd);
|
2018-06-12 22:00:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-28 19:29:54 +00:00
|
|
|
/* Mount SD. */
|
|
|
|
while (R_FAILED(fsMountSdcard(&g_sd_filesystem))) {
|
|
|
|
svcSleepThread(1000ULL);
|
2018-06-10 17:11:05 +00:00
|
|
|
}
|
2018-07-28 19:29:54 +00:00
|
|
|
|
|
|
|
/* Check for MitM flags. */
|
|
|
|
FsDir titles_dir;
|
|
|
|
if (R_SUCCEEDED(fsFsOpenDirectory(&g_sd_filesystem, "/atmosphere/titles", FS_DIROPEN_DIRECTORY, &titles_dir))) {
|
|
|
|
FsDirectoryEntry dir_entry;
|
|
|
|
FsFile f;
|
|
|
|
u64 read_entries;
|
|
|
|
while (R_SUCCEEDED((fsDirRead(&titles_dir, 0, &read_entries, 1, &dir_entry))) && read_entries == 1) {
|
|
|
|
if (strlen(dir_entry.name) == 0x10 && IsHexadecimal(dir_entry.name)) {
|
|
|
|
u64 title_id = strtoul(dir_entry.name, NULL, 16);
|
|
|
|
char title_path[FS_MAX_PATH] = {0};
|
2018-07-29 18:21:42 +00:00
|
|
|
strcpy(title_path, "/atmosphere/titles/");
|
2018-07-28 19:29:54 +00:00
|
|
|
strcat(title_path, dir_entry.name);
|
2018-11-15 12:26:40 +00:00
|
|
|
strcat(title_path, "/flags/fsmitm.flag");
|
2018-07-28 19:29:54 +00:00
|
|
|
if (R_SUCCEEDED(fsFsOpenFile(&g_sd_filesystem, title_path, FS_OPEN_READ, &f))) {
|
|
|
|
g_mitm_flagged_tids.push_back(title_id);
|
|
|
|
fsFileClose(&f);
|
2018-11-15 12:26:40 +00:00
|
|
|
} else {
|
|
|
|
/* TODO: Deprecate. */
|
|
|
|
memset(title_path, 0, sizeof(title_path));
|
|
|
|
strcpy(title_path, "/atmosphere/titles/");
|
|
|
|
strcat(title_path, dir_entry.name);
|
|
|
|
strcat(title_path, "/fsmitm.flag");
|
|
|
|
if (R_SUCCEEDED(fsFsOpenFile(&g_sd_filesystem, title_path, FS_OPEN_READ, &f))) {
|
|
|
|
g_mitm_flagged_tids.push_back(title_id);
|
|
|
|
fsFileClose(&f);
|
|
|
|
}
|
2018-07-28 19:29:54 +00:00
|
|
|
}
|
2018-10-17 03:41:19 +00:00
|
|
|
|
|
|
|
memset(title_path, 0, sizeof(title_path));
|
|
|
|
strcpy(title_path, "/atmosphere/titles/");
|
|
|
|
strcat(title_path, dir_entry.name);
|
2018-11-15 12:26:40 +00:00
|
|
|
strcat(title_path, "/flags/fsmitm_disable.flag");
|
2018-10-17 03:41:19 +00:00
|
|
|
if (R_SUCCEEDED(fsFsOpenFile(&g_sd_filesystem, title_path, FS_OPEN_READ, &f))) {
|
|
|
|
g_disable_mitm_flagged_tids.push_back(title_id);
|
|
|
|
fsFileClose(&f);
|
2018-11-15 12:26:40 +00:00
|
|
|
} else {
|
|
|
|
/* TODO: Deprecate. */
|
|
|
|
memset(title_path, 0, sizeof(title_path));
|
|
|
|
strcpy(title_path, "/atmosphere/titles/");
|
|
|
|
strcat(title_path, dir_entry.name);
|
|
|
|
strcat(title_path, "/fsmitm_disable.flag");
|
|
|
|
if (R_SUCCEEDED(fsFsOpenFile(&g_sd_filesystem, title_path, FS_OPEN_READ, &f))) {
|
|
|
|
g_disable_mitm_flagged_tids.push_back(title_id);
|
|
|
|
fsFileClose(&f);
|
|
|
|
}
|
2018-10-17 03:41:19 +00:00
|
|
|
}
|
2018-07-28 19:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fsDirClose(&titles_dir);
|
|
|
|
}
|
|
|
|
|
2018-10-23 05:53:40 +00:00
|
|
|
Utils::RefreshConfiguration();
|
2018-10-17 02:01:41 +00:00
|
|
|
|
2018-07-28 19:29:54 +00:00
|
|
|
g_has_initialized = true;
|
|
|
|
|
|
|
|
svcExitThread();
|
2018-06-10 17:11:05 +00:00
|
|
|
}
|
|
|
|
|
2018-10-17 02:01:41 +00:00
|
|
|
void Utils::InitializeHidThreadFunc(void *args) {
|
|
|
|
while (R_FAILED(hidInitialize())) {
|
|
|
|
svcSleepThread(1000ULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_has_hid_session = true;
|
|
|
|
|
|
|
|
svcExitThread();
|
|
|
|
}
|
|
|
|
|
2018-06-14 23:50:01 +00:00
|
|
|
bool Utils::IsSdInitialized() {
|
2018-07-28 19:29:54 +00:00
|
|
|
return g_has_initialized;
|
2018-06-14 23:50:01 +00:00
|
|
|
}
|
|
|
|
|
2018-10-17 02:01:41 +00:00
|
|
|
bool Utils::IsHidInitialized() {
|
|
|
|
return g_has_hid_session;
|
|
|
|
}
|
|
|
|
|
2018-06-10 17:11:05 +00:00
|
|
|
Result Utils::OpenSdFile(const char *fn, int flags, FsFile *out) {
|
2018-07-28 19:29:54 +00:00
|
|
|
if (!IsSdInitialized()) {
|
|
|
|
return 0xFA202;
|
2018-06-10 17:11:05 +00:00
|
|
|
}
|
2018-06-14 23:50:01 +00:00
|
|
|
|
|
|
|
return fsFsOpenFile(&g_sd_filesystem, fn, flags, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
Result Utils::OpenSdFileForAtmosphere(u64 title_id, const char *fn, int flags, FsFile *out) {
|
2018-07-28 19:29:54 +00:00
|
|
|
if (!IsSdInitialized()) {
|
|
|
|
return 0xFA202;
|
2018-06-14 23:50:01 +00:00
|
|
|
}
|
|
|
|
|
2018-06-10 17:11:05 +00:00
|
|
|
char path[FS_MAX_PATH];
|
2018-06-14 23:50:01 +00:00
|
|
|
if (*fn == '/') {
|
|
|
|
snprintf(path, sizeof(path), "/atmosphere/titles/%016lx%s", title_id, fn);
|
|
|
|
} else {
|
|
|
|
snprintf(path, sizeof(path), "/atmosphere/titles/%016lx/%s", title_id, fn);
|
|
|
|
}
|
2018-06-10 17:11:05 +00:00
|
|
|
return fsFsOpenFile(&g_sd_filesystem, path, flags, out);
|
2018-06-14 23:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result Utils::OpenRomFSSdFile(u64 title_id, const char *fn, int flags, FsFile *out) {
|
2018-07-28 19:29:54 +00:00
|
|
|
if (!IsSdInitialized()) {
|
|
|
|
return 0xFA202;
|
2018-06-14 23:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return OpenRomFSFile(&g_sd_filesystem, title_id, fn, flags, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
Result Utils::OpenSdDir(const char *path, FsDir *out) {
|
2018-07-28 19:29:54 +00:00
|
|
|
if (!IsSdInitialized()) {
|
|
|
|
return 0xFA202;
|
2018-06-14 23:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fsFsOpenDirectory(&g_sd_filesystem, path, FS_DIROPEN_DIRECTORY | FS_DIROPEN_FILE, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
Result Utils::OpenSdDirForAtmosphere(u64 title_id, const char *path, FsDir *out) {
|
2018-07-28 19:29:54 +00:00
|
|
|
if (!IsSdInitialized()) {
|
|
|
|
return 0xFA202;
|
2018-06-14 23:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char safe_path[FS_MAX_PATH];
|
|
|
|
if (*path == '/') {
|
|
|
|
snprintf(safe_path, sizeof(safe_path), "/atmosphere/titles/%016lx%s", title_id, path);
|
|
|
|
} else {
|
|
|
|
snprintf(safe_path, sizeof(safe_path), "/atmosphere/titles/%016lx/%s", title_id, path);
|
|
|
|
}
|
|
|
|
return fsFsOpenDirectory(&g_sd_filesystem, safe_path, FS_DIROPEN_DIRECTORY | FS_DIROPEN_FILE, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
Result Utils::OpenRomFSSdDir(u64 title_id, const char *path, FsDir *out) {
|
2018-07-28 19:29:54 +00:00
|
|
|
if (!IsSdInitialized()) {
|
|
|
|
return 0xFA202;
|
2018-06-14 23:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return OpenRomFSDir(&g_sd_filesystem, title_id, path, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Result Utils::OpenRomFSFile(FsFileSystem *fs, u64 title_id, const char *fn, int flags, FsFile *out) {
|
|
|
|
char path[FS_MAX_PATH];
|
|
|
|
if (*fn == '/') {
|
|
|
|
snprintf(path, sizeof(path), "/atmosphere/titles/%016lx/romfs%s", title_id, fn);
|
|
|
|
} else {
|
|
|
|
snprintf(path, sizeof(path), "/atmosphere/titles/%016lx/romfs/%s", title_id, fn);
|
|
|
|
}
|
|
|
|
return fsFsOpenFile(fs, path, flags, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
Result Utils::OpenRomFSDir(FsFileSystem *fs, u64 title_id, const char *path, FsDir *out) {
|
|
|
|
char safe_path[FS_MAX_PATH];
|
|
|
|
if (*path == '/') {
|
|
|
|
snprintf(safe_path, sizeof(safe_path), "/atmosphere/titles/%016lx/romfs%s", title_id, path);
|
|
|
|
} else {
|
|
|
|
snprintf(safe_path, sizeof(safe_path), "/atmosphere/titles/%016lx/romfs/%s", title_id, path);
|
|
|
|
}
|
|
|
|
return fsFsOpenDirectory(fs, safe_path, FS_DIROPEN_DIRECTORY | FS_DIROPEN_FILE, out);
|
|
|
|
}
|
2018-07-28 03:15:06 +00:00
|
|
|
|
2018-11-04 20:45:29 +00:00
|
|
|
bool Utils::HasSdRomfsContent(u64 title_id) {
|
2018-11-04 20:48:14 +00:00
|
|
|
/* Check for romfs.bin. */
|
|
|
|
FsFile data_file;
|
|
|
|
if (R_SUCCEEDED(Utils::OpenSdFileForAtmosphere(title_id, "romfs.bin", FS_OPEN_READ, &data_file))) {
|
|
|
|
fsFileClose(&data_file);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for romfs folder with non-zero content. */
|
2018-07-28 03:15:06 +00:00
|
|
|
FsDir dir;
|
2018-11-04 20:45:29 +00:00
|
|
|
if (R_FAILED(Utils::OpenRomFSSdDir(title_id, "", &dir))) {
|
|
|
|
return false;
|
2018-07-28 03:15:06 +00:00
|
|
|
}
|
2018-11-04 20:45:29 +00:00
|
|
|
ON_SCOPE_EXIT {
|
|
|
|
fsDirClose(&dir);
|
|
|
|
};
|
2018-07-28 03:15:06 +00:00
|
|
|
|
|
|
|
FsDirectoryEntry dir_entry;
|
|
|
|
u64 read_entries;
|
2018-11-04 20:45:29 +00:00
|
|
|
return R_SUCCEEDED(fsDirRead(&dir, 0, &read_entries, 1, &dir_entry)) && read_entries == 1;
|
2018-07-28 19:29:54 +00:00
|
|
|
}
|
|
|
|
|
2018-11-04 21:56:07 +00:00
|
|
|
Result Utils::SaveSdFileForAtmosphere(u64 title_id, const char *fn, void *data, size_t size) {
|
|
|
|
if (!IsSdInitialized()) {
|
|
|
|
return 0xFA202;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result rc = 0;
|
|
|
|
|
|
|
|
char path[FS_MAX_PATH];
|
|
|
|
if (*fn == '/') {
|
|
|
|
snprintf(path, sizeof(path), "/atmosphere/titles/%016lx%s", title_id, fn);
|
|
|
|
} else {
|
|
|
|
snprintf(path, sizeof(path), "/atmosphere/titles/%016lx/%s", title_id, fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unconditionally create. */
|
|
|
|
FsFile f;
|
|
|
|
fsFsCreateFile(&g_sd_filesystem, path, size, 0);
|
|
|
|
|
|
|
|
/* Try to open. */
|
|
|
|
rc = fsFsOpenFile(&g_sd_filesystem, path, FS_OPEN_READ | FS_OPEN_WRITE, &f);
|
|
|
|
if (R_FAILED(rc)) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Always close, if we opened. */
|
|
|
|
ON_SCOPE_EXIT {
|
|
|
|
fsFileClose(&f);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Try to make it big enough. */
|
|
|
|
rc = fsFileSetSize(&f, size);
|
|
|
|
if (R_FAILED(rc)) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to write the data. */
|
|
|
|
rc = fsFileWrite(&f, 0, data, size);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:26:40 +00:00
|
|
|
bool Utils::HasFlag(u64 tid, const char *flag) {
|
|
|
|
if (IsSdInitialized()) {
|
|
|
|
FsFile f;
|
|
|
|
char flag_path[FS_MAX_PATH];
|
|
|
|
|
|
|
|
memset(flag_path, 0, sizeof(flag_path));
|
|
|
|
snprintf(flag_path, sizeof(flag_path) - 1, "flags/%s.flag", flag);
|
|
|
|
if (OpenSdFileForAtmosphere(tid, flag_path, FS_OPEN_READ, &f)) {
|
|
|
|
fsFileClose(&f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: Deprecate. */
|
|
|
|
snprintf(flag_path, sizeof(flag_path) - 1, "%s.flag", flag);
|
|
|
|
if (OpenSdFileForAtmosphere(tid, flag_path, FS_OPEN_READ, &f)) {
|
|
|
|
fsFileClose(&f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Utils::HasGlobalFlag(u64 tid, const char *flag) {
|
|
|
|
if (IsSdInitialized()) {
|
|
|
|
FsFile f;
|
|
|
|
char flag_path[FS_MAX_PATH] = {0};
|
|
|
|
snprintf(flag_path, sizeof(flag_path), "/atmosphere/flags/%s.flag", flag);
|
|
|
|
if (fsFsOpenFile(&g_sd_filesystem, flag_path, FS_OPEN_READ, &f)) {
|
|
|
|
fsFileClose(&f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-28 19:29:54 +00:00
|
|
|
bool Utils::HasSdMitMFlag(u64 tid) {
|
2018-11-15 12:26:40 +00:00
|
|
|
if (tid == g_override_hbl_tid) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-28 19:29:54 +00:00
|
|
|
if (IsSdInitialized()) {
|
|
|
|
return std::find(g_mitm_flagged_tids.begin(), g_mitm_flagged_tids.end(), tid) != g_mitm_flagged_tids.end();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-17 02:01:41 +00:00
|
|
|
|
2018-10-17 03:41:19 +00:00
|
|
|
bool Utils::HasSdDisableMitMFlag(u64 tid) {
|
|
|
|
if (IsSdInitialized()) {
|
|
|
|
return std::find(g_disable_mitm_flagged_tids.begin(), g_disable_mitm_flagged_tids.end(), tid) != g_disable_mitm_flagged_tids.end();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-17 02:01:41 +00:00
|
|
|
Result Utils::GetKeysDown(u64 *keys) {
|
|
|
|
if (!Utils::IsHidInitialized()) {
|
|
|
|
return MAKERESULT(Module_Libnx, LibnxError_InitFail_HID);
|
|
|
|
}
|
|
|
|
|
|
|
|
hidScanInput();
|
|
|
|
*keys = hidKeysDown(CONTROLLER_P1_AUTO);
|
|
|
|
|
|
|
|
return 0x0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Utils::HasOverrideButton(u64 tid) {
|
2018-10-23 06:00:22 +00:00
|
|
|
if (tid < 0x0100000000010000ULL || !IsSdInitialized()) {
|
2018-10-17 02:01:41 +00:00
|
|
|
/* Disable button override disable for non-applications. */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-23 05:53:40 +00:00
|
|
|
/* Unconditionally refresh loader.ini contents. */
|
|
|
|
RefreshConfiguration();
|
|
|
|
|
2018-10-17 02:01:41 +00:00
|
|
|
u64 kDown = 0;
|
|
|
|
bool keys_triggered = (R_SUCCEEDED(GetKeysDown(&kDown)) && ((kDown & g_override_key_combination) != 0));
|
|
|
|
return IsSdInitialized() && (g_override_by_default ^ keys_triggered);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FsMitMIniHandler(void *user, const char *section, const char *name, const char *value) {
|
|
|
|
/* Taken and modified, with love, from Rajkosto's implementation. */
|
|
|
|
if (strcasecmp(section, "config") == 0) {
|
2018-11-15 12:26:40 +00:00
|
|
|
if (strcasecmp(name, "hbl_tid") == 0) {
|
|
|
|
u64 override_tid = strtoul(value, NULL, 16);
|
|
|
|
if (override_tid != 0) {
|
|
|
|
g_override_hbl_tid = override_tid;
|
|
|
|
}
|
|
|
|
} else if (strcasecmp(name, "override_key") == 0) {
|
2018-10-17 02:01:41 +00:00
|
|
|
if (value[0] == '!') {
|
|
|
|
g_override_by_default = true;
|
|
|
|
value++;
|
|
|
|
} else {
|
|
|
|
g_override_by_default = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcasecmp(value, "A") == 0) {
|
|
|
|
g_override_key_combination = KEY_A;
|
|
|
|
} else if (strcasecmp(value, "B") == 0) {
|
|
|
|
g_override_key_combination = KEY_B;
|
|
|
|
} else if (strcasecmp(value, "X") == 0) {
|
|
|
|
g_override_key_combination = KEY_X;
|
|
|
|
} else if (strcasecmp(value, "Y") == 0) {
|
|
|
|
g_override_key_combination = KEY_Y;
|
|
|
|
} else if (strcasecmp(value, "LS") == 0) {
|
|
|
|
g_override_key_combination = KEY_LSTICK;
|
|
|
|
} else if (strcasecmp(value, "RS") == 0) {
|
|
|
|
g_override_key_combination = KEY_RSTICK;
|
|
|
|
} else if (strcasecmp(value, "L") == 0) {
|
|
|
|
g_override_key_combination = KEY_L;
|
|
|
|
} else if (strcasecmp(value, "R") == 0) {
|
|
|
|
g_override_key_combination = KEY_R;
|
|
|
|
} else if (strcasecmp(value, "ZL") == 0) {
|
|
|
|
g_override_key_combination = KEY_ZL;
|
|
|
|
} else if (strcasecmp(value, "ZR") == 0) {
|
|
|
|
g_override_key_combination = KEY_ZR;
|
|
|
|
} else if (strcasecmp(value, "PLUS") == 0) {
|
|
|
|
g_override_key_combination = KEY_PLUS;
|
|
|
|
} else if (strcasecmp(value, "MINUS") == 0) {
|
|
|
|
g_override_key_combination = KEY_MINUS;
|
|
|
|
} else if (strcasecmp(value, "DLEFT") == 0) {
|
|
|
|
g_override_key_combination = KEY_DLEFT;
|
|
|
|
} else if (strcasecmp(value, "DUP") == 0) {
|
|
|
|
g_override_key_combination = KEY_DUP;
|
|
|
|
} else if (strcasecmp(value, "DRIGHT") == 0) {
|
|
|
|
g_override_key_combination = KEY_DRIGHT;
|
|
|
|
} else if (strcasecmp(value, "DDOWN") == 0) {
|
|
|
|
g_override_key_combination = KEY_DDOWN;
|
|
|
|
} else if (strcasecmp(value, "SL") == 0) {
|
|
|
|
g_override_key_combination = KEY_SL;
|
|
|
|
} else if (strcasecmp(value, "SR") == 0) {
|
|
|
|
g_override_key_combination = KEY_SR;
|
|
|
|
} else {
|
|
|
|
g_override_key_combination = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-23 05:53:40 +00:00
|
|
|
void Utils::RefreshConfiguration() {
|
|
|
|
FsFile config_file;
|
|
|
|
if (R_FAILED(fsFsOpenFile(&g_sd_filesystem, "/atmosphere/loader.ini", FS_OPEN_READ, &config_file))) {
|
2018-10-17 02:01:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 size;
|
2018-10-23 05:53:40 +00:00
|
|
|
if (R_FAILED(fsFileGetSize(&config_file, &size))) {
|
2018-10-17 02:01:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = std::min(size, (decltype(size))0x7FF);
|
|
|
|
|
2018-10-23 05:53:40 +00:00
|
|
|
/* Read in string. */
|
|
|
|
std::fill(g_config_ini_data, g_config_ini_data + 0x800, 0);
|
|
|
|
size_t r_s;
|
|
|
|
fsFileRead(&config_file, 0, g_config_ini_data, size, &r_s);
|
2018-10-23 06:00:22 +00:00
|
|
|
fsFileClose(&config_file);
|
2018-10-23 05:53:40 +00:00
|
|
|
|
|
|
|
ini_parse_string(g_config_ini_data, FsMitMIniHandler, NULL);
|
2018-10-17 02:01:41 +00:00
|
|
|
}
|