2018-09-07 17:00:13 +02:00
|
|
|
/*
|
2019-04-08 04:00:49 +02:00
|
|
|
* Copyright (c) 2018-2019 Atmosphère-NX
|
2018-09-07 17:00:13 +02:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2019-04-05 22:36:38 +02:00
|
|
|
|
2018-06-10 19:11:05 +02:00
|
|
|
#pragma once
|
|
|
|
#include <switch.h>
|
|
|
|
#include <stratosphere.hpp>
|
|
|
|
|
2019-02-23 16:39:40 +01:00
|
|
|
struct OverrideKey {
|
|
|
|
u64 key_combination;
|
|
|
|
bool override_by_default;
|
|
|
|
};
|
|
|
|
|
2019-05-22 21:11:40 +02:00
|
|
|
struct OverrideLocale {
|
|
|
|
u64 language_code;
|
|
|
|
u32 region_code;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum RegionCode : u32 {
|
|
|
|
RegionCode_Japan = 0,
|
|
|
|
RegionCode_America = 1,
|
|
|
|
RegionCode_Europe = 2,
|
|
|
|
RegionCode_Australia = 3,
|
|
|
|
RegionCode_China = 4,
|
|
|
|
RegionCode_Korea = 5,
|
|
|
|
RegionCode_Taiwan = 6,
|
|
|
|
|
|
|
|
RegionCode_Max,
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr inline u64 EncodeLanguageCode(const char *code) {
|
|
|
|
u64 lang_code = 0;
|
|
|
|
for (size_t i = 0; i < sizeof(lang_code); i++) {
|
|
|
|
if (code[i] == '\x00') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lang_code |= static_cast<u64>(code[i]) << (8ul * i);
|
|
|
|
}
|
|
|
|
return lang_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum LanguageCode : u64 {
|
|
|
|
LanguageCode_Japanese = EncodeLanguageCode("ja"),
|
|
|
|
LanguageCode_AmericanEnglish = EncodeLanguageCode("en-US"),
|
|
|
|
LanguageCode_French = EncodeLanguageCode("fr"),
|
|
|
|
LanguageCode_German = EncodeLanguageCode("de"),
|
|
|
|
LanguageCode_Italian = EncodeLanguageCode("it"),
|
|
|
|
LanguageCode_Spanish = EncodeLanguageCode("es"),
|
|
|
|
LanguageCode_Chinese = EncodeLanguageCode("zh-CN"),
|
|
|
|
LanguageCode_Korean = EncodeLanguageCode("ko"),
|
|
|
|
LanguageCode_Dutch = EncodeLanguageCode("nl"),
|
|
|
|
LanguageCode_Portuguese = EncodeLanguageCode("pt"),
|
|
|
|
LanguageCode_Russian = EncodeLanguageCode("ru"),
|
|
|
|
LanguageCode_Taiwanese = EncodeLanguageCode("zh-TW"),
|
|
|
|
LanguageCode_BritishEnglish = EncodeLanguageCode("en-GB"),
|
|
|
|
LanguageCode_CanadianFrench = EncodeLanguageCode("fr-CA"),
|
|
|
|
LanguageCode_LatinAmericanSpanish = EncodeLanguageCode("es-419"),
|
|
|
|
/* 4.0.0+ */
|
|
|
|
LanguageCode_SimplifiedChinese = EncodeLanguageCode("zh-Hans"),
|
|
|
|
LanguageCode_TraditionalChinese = EncodeLanguageCode("zh-Hant"),
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-06-10 19:11:05 +02:00
|
|
|
class Utils {
|
|
|
|
public:
|
2018-06-15 01:50:01 +02:00
|
|
|
static bool IsSdInitialized();
|
2019-01-29 11:29:29 +01:00
|
|
|
static void WaitSdInitialized();
|
2019-04-05 22:36:38 +02:00
|
|
|
|
2018-06-10 19:11:05 +02:00
|
|
|
static Result OpenSdFile(const char *fn, int flags, FsFile *out);
|
2018-06-15 01:50:01 +02:00
|
|
|
static Result OpenSdFileForAtmosphere(u64 title_id, const char *fn, int flags, FsFile *out);
|
|
|
|
static Result OpenRomFSSdFile(u64 title_id, const char *fn, int flags, FsFile *out);
|
|
|
|
static Result OpenSdDir(const char *path, FsDir *out);
|
|
|
|
static Result OpenSdDirForAtmosphere(u64 title_id, const char *path, FsDir *out);
|
2019-04-05 22:36:38 +02:00
|
|
|
static Result OpenRomFSSdDir(u64 title_id, const char *path, FsDir *out);
|
|
|
|
|
2018-06-15 01:50:01 +02:00
|
|
|
static Result OpenRomFSFile(FsFileSystem *fs, u64 title_id, const char *fn, int flags, FsFile *out);
|
|
|
|
static Result OpenRomFSDir(FsFileSystem *fs, u64 title_id, const char *path, FsDir *out);
|
2019-04-05 22:36:38 +02:00
|
|
|
|
2018-11-04 22:56:07 +01:00
|
|
|
static Result SaveSdFileForAtmosphere(u64 title_id, const char *fn, void *data, size_t size);
|
2019-04-05 22:36:38 +02:00
|
|
|
|
2018-11-04 21:45:29 +01:00
|
|
|
static bool HasSdRomfsContent(u64 title_id);
|
2019-04-05 22:36:38 +02:00
|
|
|
|
2019-01-29 11:29:29 +01:00
|
|
|
/* Delayed Initialization + MitM detection. */
|
|
|
|
static void InitializeThreadFunc(void *args);
|
2019-04-05 22:36:38 +02:00
|
|
|
|
2019-01-09 21:50:01 +01:00
|
|
|
static bool IsHblTid(u64 tid);
|
2019-03-26 17:05:19 +01:00
|
|
|
static bool IsWebAppletTid(u64 tid);
|
2019-04-05 22:36:38 +02:00
|
|
|
|
2018-11-29 21:30:32 +01:00
|
|
|
static bool HasTitleFlag(u64 tid, const char *flag);
|
|
|
|
static bool HasHblFlag(const char *flag);
|
2018-11-15 13:26:40 +01:00
|
|
|
static bool HasGlobalFlag(const char *flag);
|
2018-11-29 21:30:32 +01:00
|
|
|
static bool HasFlag(u64 tid, const char *flag);
|
2019-04-05 22:36:38 +02:00
|
|
|
|
2018-07-28 21:29:54 +02:00
|
|
|
static bool HasSdMitMFlag(u64 tid);
|
2018-10-17 05:41:19 +02:00
|
|
|
static bool HasSdDisableMitMFlag(u64 tid);
|
2019-04-05 22:36:38 +02:00
|
|
|
|
|
|
|
|
2018-12-11 04:30:59 +01:00
|
|
|
static bool IsHidAvailable();
|
2019-03-16 05:28:38 +01:00
|
|
|
static Result GetKeysHeld(u64 *keys);
|
2019-04-05 22:36:38 +02:00
|
|
|
|
2019-02-23 16:39:40 +01:00
|
|
|
static OverrideKey GetTitleOverrideKey(u64 tid);
|
2018-10-17 04:01:41 +02:00
|
|
|
static bool HasOverrideButton(u64 tid);
|
2019-04-05 22:36:38 +02:00
|
|
|
|
2019-05-22 21:11:40 +02:00
|
|
|
static OverrideLocale GetTitleOverrideLocale(u64 tid);
|
|
|
|
|
2019-02-05 10:51:05 +01:00
|
|
|
/* Settings! */
|
|
|
|
static Result GetSettingsItemValueSize(const char *name, const char *key, u64 *out_size);
|
|
|
|
static Result GetSettingsItemValue(const char *name, const char *key, void *out, size_t max_size, u64 *out_size);
|
2019-04-05 22:36:38 +02:00
|
|
|
|
|
|
|
static Result GetSettingsItemBooleanValue(const char *name, const char *key, bool *out);
|
2019-05-22 21:11:40 +02:00
|
|
|
|
2019-04-13 00:28:46 +02:00
|
|
|
/* Error occurred. */
|
|
|
|
static void RebootToFatalError(AtmosphereFatalErrorContext *ctx);
|
2018-10-17 04:01:41 +02:00
|
|
|
private:
|
2018-10-23 07:53:40 +02:00
|
|
|
static void RefreshConfiguration();
|
2018-06-10 19:11:05 +02:00
|
|
|
};
|