mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-23 19:26:55 -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,93 +14,104 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
#include "fatal_types.hpp"
|
||||
#include "fatal_repair.hpp"
|
||||
#include "fatal_throw.hpp"
|
||||
#include "fatal_service_for_self.hpp"
|
||||
|
||||
static bool InRepairWithoutVolHeld() {
|
||||
if (GetRuntimeFirmwareVersion() < FirmwareVersion_300) {
|
||||
return false;
|
||||
}
|
||||
namespace sts::fatal::srv {
|
||||
|
||||
bool in_repair;
|
||||
if (R_FAILED(setsysGetFlag(SetSysFlag_InRepairProcessEnable, &in_repair)) || !in_repair) {
|
||||
return false;
|
||||
}
|
||||
namespace {
|
||||
|
||||
{
|
||||
GpioPadSession vol_btn;
|
||||
if (R_FAILED(gpioOpenSession(&vol_btn, GpioPadName_ButtonVolUp))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Ensure we close even on early return. */
|
||||
ON_SCOPE_EXIT { gpioPadClose(&vol_btn); };
|
||||
|
||||
/* Set direction input. */
|
||||
gpioPadSetDirection(&vol_btn, GpioDirection_Input);
|
||||
|
||||
/* Ensure that we're holding the volume button for a full second. */
|
||||
TimeoutHelper timeout_helper(1000000000UL);
|
||||
while (!timeout_helper.TimedOut()) {
|
||||
GpioValue val;
|
||||
if (R_FAILED(gpioPadGetValue(&vol_btn, &val)) || val != GpioValue_Low) {
|
||||
return true;
|
||||
bool IsInRepair() {
|
||||
/* Before firmware 3.0.0, this wasn't implemented. */
|
||||
if (GetRuntimeFirmwareVersion() < FirmwareVersion_300) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Sleep for 100 ms. */
|
||||
svcSleepThread(100000000UL);
|
||||
bool in_repair;
|
||||
return R_SUCCEEDED(setsysGetFlag(SetSysFlag_InRepairProcessEnable, &in_repair)) && in_repair;
|
||||
}
|
||||
|
||||
bool IsInRepairWithoutVolHeld() {
|
||||
if (IsInRepair()) {
|
||||
GpioPadSession vol_btn;
|
||||
if (R_FAILED(gpioOpenSession(&vol_btn, GpioPadName_ButtonVolUp))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Ensure we close even on early return. */
|
||||
ON_SCOPE_EXIT { gpioPadClose(&vol_btn); };
|
||||
|
||||
/* Set direction input. */
|
||||
gpioPadSetDirection(&vol_btn, GpioDirection_Input);
|
||||
|
||||
/* Ensure that we're holding the volume button for a full second. */
|
||||
TimeoutHelper timeout_helper(1'000'000'000ul);
|
||||
while (!timeout_helper.TimedOut()) {
|
||||
GpioValue val;
|
||||
if (R_FAILED(gpioPadGetValue(&vol_btn, &val)) || val != GpioValue_Low) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Sleep for 100 ms. */
|
||||
svcSleepThread(100'000'000ul);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NeedsRunTimeReviser() {
|
||||
/* Before firmware 5.0.0, this wasn't implemented. */
|
||||
if (GetRuntimeFirmwareVersion() < FirmwareVersion_300) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool requires_time_reviser;
|
||||
return R_SUCCEEDED(setsysGetFlag(SetSysFlag_RequiresRunRepairTimeReviser, &requires_time_reviser)) && requires_time_reviser;
|
||||
}
|
||||
|
||||
bool IsTimeReviserCartridgeInserted() {
|
||||
FsGameCardHandle gc_hnd;
|
||||
u8 gc_attr;
|
||||
{
|
||||
FsDeviceOperator devop;
|
||||
if (R_FAILED(fsOpenDeviceOperator(&devop))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Ensure we close even on early return. */
|
||||
ON_SCOPE_EXIT { fsDeviceOperatorClose(&devop); };
|
||||
|
||||
/* Check that a gamecard is inserted. */
|
||||
bool inserted;
|
||||
if (R_FAILED(fsDeviceOperatorIsGameCardInserted(&devop, &inserted)) || !inserted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check that we can retrieve the gamecard's attributes. */
|
||||
if (R_FAILED(fsDeviceOperatorGetGameCardHandle(&devop, &gc_hnd)) || R_FAILED(fsDeviceOperatorGetGameCardAttribute(&devop, &gc_hnd, &gc_attr))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check that the gamecard is a repair tool. */
|
||||
return (gc_attr & FsGameCardAttribute_Repair) == FsGameCardAttribute_Repair;
|
||||
}
|
||||
|
||||
bool IsInRepairWithoutTimeReviserCartridge() {
|
||||
return NeedsRunTimeReviser() && IsTimeReviserCartridgeInserted();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CheckRepairStatus() {
|
||||
if (IsInRepairWithoutVolHeld()) {
|
||||
ThrowFatalForSelf(ResultFatalInRepairWithoutVolHeld);
|
||||
}
|
||||
|
||||
if (IsInRepairWithoutTimeReviserCartridge()) {
|
||||
ThrowFatalForSelf(ResultFatalInRepairWithoutTimeReviserCartridge);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool InRepairWithoutTimeReviserCartridge() {
|
||||
if (GetRuntimeFirmwareVersion() < FirmwareVersion_500) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool requires_time_reviser;
|
||||
if (R_FAILED(setsysGetFlag(SetSysFlag_RequiresRunRepairTimeReviser, &requires_time_reviser)) || !requires_time_reviser) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FsGameCardHandle gc_hnd;
|
||||
u8 gc_attr;
|
||||
{
|
||||
FsDeviceOperator devop;
|
||||
if (R_FAILED(fsOpenDeviceOperator(&devop))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Ensure we close even on early return. */
|
||||
ON_SCOPE_EXIT { fsDeviceOperatorClose(&devop); };
|
||||
|
||||
/* Check that a gamecard is inserted. */
|
||||
bool inserted;
|
||||
if (R_FAILED(fsDeviceOperatorIsGameCardInserted(&devop, &inserted)) || !inserted) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Check that we can retrieve the gamecard's attributes. */
|
||||
if (R_FAILED(fsDeviceOperatorGetGameCardHandle(&devop, &gc_hnd)) || R_FAILED(fsDeviceOperatorGetGameCardAttribute(&devop, &gc_hnd, &gc_attr))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check that the gamecard is a repair tool. */
|
||||
return (gc_attr & FsGameCardAttribute_Repair) == FsGameCardAttribute_Repair;
|
||||
}
|
||||
|
||||
void CheckRepairStatus() {
|
||||
if (InRepairWithoutVolHeld()) {
|
||||
ThrowFatalForSelf(ResultFatalInRepairWithoutVolHeld);
|
||||
}
|
||||
|
||||
if (InRepairWithoutTimeReviserCartridge()) {
|
||||
ThrowFatalForSelf(ResultFatalInRepairWithoutTimeReviserCartridge);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue