mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-18 09:04:23 -04:00
fatal: refactor into sts namespace
This commit is contained in:
parent
442ebff829
commit
39d041466d
38 changed files with 2176 additions and 1926 deletions
|
@ -14,78 +14,82 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include "fatal_types.hpp"
|
||||
#include "fatal_config.hpp"
|
||||
|
||||
static FatalConfig g_fatal_config = {};
|
||||
namespace sts::fatal::srv {
|
||||
|
||||
static IEvent *g_fatal_settings_event = nullptr;
|
||||
namespace {
|
||||
|
||||
FatalConfig *GetFatalConfig() {
|
||||
return &g_fatal_config;
|
||||
}
|
||||
/* Global config. */
|
||||
FatalConfig g_config;
|
||||
|
||||
static void UpdateLanguageCode() {
|
||||
setGetLanguageCode(&GetFatalConfig()->language_code);
|
||||
}
|
||||
|
||||
IEvent *GetFatalSettingsEvent() {
|
||||
if (g_fatal_settings_event == nullptr) {
|
||||
Event evt;
|
||||
if (R_FAILED(setsysBindFatalDirtyFlagEvent(&evt))) {
|
||||
std::abort();
|
||||
/* Event creator. */
|
||||
IEvent *CreateFatalDirtyEvent() {
|
||||
Event evt;
|
||||
R_ASSERT(setsysBindFatalDirtyFlagEvent(&evt));
|
||||
return LoadReadOnlySystemEvent(evt.revent, [](u64 timeout) {
|
||||
u64 flags_0, flags_1;
|
||||
if (R_SUCCEEDED(setsysGetFatalDirtyFlags(&flags_0, &flags_1)) && (flags_0 & 1)) {
|
||||
g_config.UpdateLanguageCode();
|
||||
}
|
||||
return ResultSuccess;
|
||||
}, true);
|
||||
}
|
||||
g_fatal_settings_event = LoadReadOnlySystemEvent(evt.revent, [](u64 timeout) {
|
||||
u64 flags_0, flags_1;
|
||||
if (R_SUCCEEDED(setsysGetFatalDirtyFlags(&flags_0, &flags_1)) && (flags_0 & 1)) {
|
||||
UpdateLanguageCode();
|
||||
}
|
||||
return ResultSuccess;
|
||||
}, true);
|
||||
|
||||
/* Global event. */
|
||||
IEvent *g_fatal_dirty_event = CreateFatalDirtyEvent();
|
||||
}
|
||||
|
||||
return g_fatal_settings_event;
|
||||
}
|
||||
FatalConfig::FatalConfig() {
|
||||
/* Clear this. */
|
||||
std::memset(this, 0, sizeof(*this));
|
||||
|
||||
static void SetupConfigLanguages() {
|
||||
FatalConfig *config = GetFatalConfig();
|
||||
/* Get information from set. */
|
||||
setsysGetSerialNumber(this->serial_number);
|
||||
setsysGetFirmwareVersion(&this->firmware_version);
|
||||
setsysGetFlag(SetSysFlag_Quest, &this->quest_flag);
|
||||
this->UpdateLanguageCode();
|
||||
|
||||
/* Defaults. */
|
||||
config->error_msg = u8"Error Code: 2%03d-%04d (0x%x)\n";
|
||||
/* Read information from settings. */
|
||||
setsysGetSettingsItemValue("fatal", "transition_to_fatal", &this->transition_to_fatal, sizeof(this->transition_to_fatal));
|
||||
setsysGetSettingsItemValue("fatal", "show_extra_info", &this->show_extra_info, sizeof(this->show_extra_info));
|
||||
setsysGetSettingsItemValue("fatal", "quest_reboot_interval_second", &this->quest_reboot_interval_second, sizeof(this->quest_reboot_interval_second));
|
||||
|
||||
if (config->quest_flag) {
|
||||
config->error_desc = u8"Please call 1-800-875-1852 for service.\n";
|
||||
} else {
|
||||
config->error_desc = u8"An error has occured.\n\n"
|
||||
u8"Please press the POWER Button to restart the console normally, or a VOL button\n"
|
||||
u8"to reboot to a payload (or RCM, if none is present). If you are unable to\n"
|
||||
u8"restart the console, hold the POWER Button for 12 seconds to turn the console off.\n\n"
|
||||
u8"If the problem persists, refer to the Nintendo Support Website.\n"
|
||||
u8"support.nintendo.com/switch/error\n";
|
||||
/* Atmosphere extension for automatic reboot. */
|
||||
if (R_SUCCEEDED(setsysGetSettingsItemValue("atmosphere", "fatal_auto_reboot_interval", &this->fatal_auto_reboot_interval, sizeof(this->fatal_auto_reboot_interval)))) {
|
||||
this->fatal_auto_reboot_enabled = this->fatal_auto_reboot_interval != 0;
|
||||
}
|
||||
|
||||
/* Setup messages. */
|
||||
{
|
||||
this->error_msg = u8"Error Code: 2%03d-%04d (0x%x)\n";
|
||||
|
||||
this->error_desc = u8"An error has occured.\n\n"
|
||||
u8"Please press the POWER Button to restart the console normally, or a VOL button\n"
|
||||
u8"to reboot to a payload (or RCM, if none is present). If you are unable to\n"
|
||||
u8"restart the console, hold the POWER Button for 12 seconds to turn the console off.\n\n"
|
||||
u8"If the problem persists, refer to the Nintendo Support Website.\n"
|
||||
u8"support.nintendo.com/switch/error\n";
|
||||
|
||||
/* If you're running Atmosphere on a quest unit for some reason, talk to me on discord. */
|
||||
this->quest_desc = u8"Please call 1-800-875-1852 for service.\n\n"
|
||||
u8"Also, please be aware that running Atmosphere on a Quest device is not fully\n"
|
||||
u8"supported. Perhaps try booting your device without Atmosphere before calling\n"
|
||||
u8"an official Nintendo service hotline. If you encounter further issues, please\n"
|
||||
u8"contact SciresM#0524 on Discord, or via some other means.\n";
|
||||
|
||||
/* TODO: Try to load dynamically? */
|
||||
/* FsStorage message_storage; */
|
||||
/* TODO: if (R_SUCCEEDED(fsOpenDataStorageByDataId(0x010000000000081D, "fatal_msg"))) { ... } */
|
||||
}
|
||||
}
|
||||
|
||||
IEvent *GetFatalDirtyEvent() {
|
||||
return g_fatal_dirty_event;
|
||||
}
|
||||
|
||||
const FatalConfig &GetFatalConfig() {
|
||||
return g_config;
|
||||
}
|
||||
|
||||
/* TODO: Try to load dynamically. */
|
||||
/* FsStorage message_storage; */
|
||||
/* TODO: if (R_SUCCEEDED(fsOpenDataStorageByDataId(0x010000000000081D, "fatal_msg"))) { ... } */
|
||||
}
|
||||
|
||||
void InitializeFatalConfig() {
|
||||
FatalConfig *config = GetFatalConfig();
|
||||
|
||||
memset(config, 0, sizeof(*config));
|
||||
setsysGetSerialNumber(config->serial_number);
|
||||
setsysGetFirmwareVersion(&config->firmware_version);
|
||||
UpdateLanguageCode();
|
||||
|
||||
setsysGetSettingsItemValue("fatal", "transition_to_fatal", &config->transition_to_fatal, sizeof(config->transition_to_fatal));
|
||||
setsysGetSettingsItemValue("fatal", "show_extra_info", &config->show_extra_info, sizeof(config->show_extra_info));
|
||||
setsysGetSettingsItemValue("fatal", "quest_reboot_interval_second", &config->quest_reboot_interval_second, sizeof(config->quest_reboot_interval_second));
|
||||
|
||||
setsysGetFlag(SetSysFlag_Quest, &config->quest_flag);
|
||||
|
||||
config->is_auto_reboot_enabled = R_SUCCEEDED(setsysGetSettingsItemValue("atmosphere", "fatal_auto_reboot_interval", &config->fatal_auto_reboot_interval, sizeof(config->fatal_auto_reboot_interval)));
|
||||
config->is_auto_reboot_enabled &= (config->fatal_auto_reboot_interval != 0);
|
||||
|
||||
SetupConfigLanguages();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue