From 6a890d864148e239c39650f1011f46fb491fd7fb Mon Sep 17 00:00:00 2001 From: flb Date: Sat, 11 Sep 2021 19:45:52 +0200 Subject: [PATCH] Check if DayBreak is run as NRO --- troposphere/daybreak/source/ui.cpp | 31 +++++++++++++++++++++--------- troposphere/daybreak/source/ui.hpp | 4 ++-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/troposphere/daybreak/source/ui.cpp b/troposphere/daybreak/source/ui.cpp index 47d0860ad..b3f68a9f2 100644 --- a/troposphere/daybreak/source/ui.cpp +++ b/troposphere/daybreak/source/ui.cpp @@ -1216,7 +1216,7 @@ namespace dbk { } } - void InitializeMenu(u32 screen_width, u32 screen_height) { + bool InitializeMenu(u32 screen_width, u32 screen_height) { Result rc = 0; /* Configure and initialize the gamepad. */ @@ -1237,7 +1237,7 @@ namespace dbk { u64 version; if (R_FAILED(rc = splGetConfig(static_cast(ExosphereApiVersionConfigItem), &version))) { ChangeMenu(std::make_shared("Atmosphere not found", "Daybreak requires Atmosphere to be installed.", rc)); - return; + return false; } const u32 version_micro = (version >> 40) & 0xff; @@ -1248,7 +1248,13 @@ namespace dbk { const bool ams_supports_sysupdate_api = EncodeVersion(version_major, version_minor, version_micro) >= EncodeVersion(0, 14, 0); if (!ams_supports_sysupdate_api) { ChangeMenu(std::make_shared("Outdated Atmosphere version", "Daybreak requires Atmosphere 0.14.0 or later.", rc)); - return; + return false; + } + + /* Ensure DayBreak is ran as a NRO. */ + if (envIsNso()) { + ChangeMenu(std::make_shared("DayBreak installs are not supported", "Please launch Daybreak via the Homebrew menu.", rc)); + return false; } /* Attempt to get the supported version. */ @@ -1263,16 +1269,23 @@ namespace dbk { /* Change the current menu to the main menu. */ g_current_menu = std::make_shared(); + + return true; } - void InitializeMenu(u32 screen_width, u32 screen_height, const char *update_path) { - InitializeMenu(screen_width, screen_height); + bool InitializeMenu(u32 screen_width, u32 screen_height, const char *update_path) { + if (InitializeMenu(screen_width, screen_height)) { - /* Set the update path. */ - snprintf(g_update_path, sizeof(g_update_path), "%s", update_path); + /* Set the update path. */ + strncpy(g_update_path, update_path, sizeof(g_update_path)); - /* Change the menu. */ - ChangeMenu(std::make_shared(g_current_menu)); + /* Change the menu. */ + ChangeMenu(std::make_shared(g_current_menu)); + + return true; + } + + return false; } void UpdateMenu(u64 ns) { diff --git a/troposphere/daybreak/source/ui.hpp b/troposphere/daybreak/source/ui.hpp index 41fbe65c1..211a0c43d 100644 --- a/troposphere/daybreak/source/ui.hpp +++ b/troposphere/daybreak/source/ui.hpp @@ -263,8 +263,8 @@ namespace dbk { virtual void Draw(NVGcontext *vg, u64 ns) override; }; - void InitializeMenu(u32 screen_width, u32 screen_height); - void InitializeMenu(u32 screen_width, u32 screen_height, const char *update_path); + bool InitializeMenu(u32 screen_width, u32 screen_height); + bool InitializeMenu(u32 screen_width, u32 screen_height, const char *update_path); void UpdateMenu(u64 ns); void RenderMenu(NVGcontext *vg, u64 ns); bool IsExitRequested();