Skip to content

Commit

Permalink
ask to update on <1.6.0 mariko
Browse files Browse the repository at this point in the history
  • Loading branch information
HookedBehemoth committed Oct 21, 2023
1 parent 0e476eb commit f1b7766
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 3 deletions.
26 changes: 26 additions & 0 deletions applet/main.cpp
Expand Up @@ -70,6 +70,32 @@ extern "C" void userAppExit(void) {
}

int main(int const argc, char const *argv[]) {
if (!util::IsErista() && !util::SupportsMarikoRebootToConfig()) {
consoleInit(nullptr);

printf("Update to at least Atmosphère 1.6.1\n");

consoleUpdate(nullptr);

/* Configure input */
padConfigureInput(8, HidNpadStyleSet_NpadStandard);

/* Initialize pad */
PadState pad;
padInitializeAny(&pad);

while (appletMainLoop()) {
/* Update padstate */
padUpdate(&pad);

if (padGetButtonsDown(&pad))
break;
}

consoleExit(nullptr);
return 0;
}

std::vector<TuiItem> items;

/* Load available boot configs */
Expand Down
37 changes: 35 additions & 2 deletions common/util.cpp
Expand Up @@ -17,15 +17,48 @@

#include <switch.h>

#include <optional>
#include <cstdio>

namespace util {

bool IsErista() {
u64 type=0;
static std::optional<bool> impl;

if (impl.has_value())
return *impl;

u64 type = 0;

if (R_FAILED(splGetConfig(SplConfigItem_HardwareType, &type)))
return false;

return type == 0 /* SplHardwareType_Icosa */ || type == 1 /* SplHardwareType_Copper */;
impl = (type == 0 /* SplHardwareType_Icosa */ || type == 1 /* SplHardwareType_Copper */);

return *impl;
}

/**
* Since 1.6.0, Atmosphère bpc-mitm overwrites the reboot on mariko to prevent clearing
* Timers. We are using those timing registers to communicate with hekate.
*/
bool SupportsMarikoRebootToConfig() {
static std::optional<bool> impl;

if (impl.has_value())
return *impl;

u64 version = 0;

if (R_FAILED(splGetConfig(static_cast<SplConfigItem>(65000), &version)))
return false;

const u32 version_minor = (version >> 48) & 0xff;
const u32 version_major = (version >> 56) & 0xff;

impl = (version_major >= 1 && version_minor >= 6);

return *impl;
}

}
2 changes: 2 additions & 0 deletions common/util.hpp
Expand Up @@ -19,4 +19,6 @@ namespace util {

bool IsErista();

bool SupportsMarikoRebootToConfig();

}
25 changes: 24 additions & 1 deletion overlay/main.cpp
Expand Up @@ -101,6 +101,25 @@ class PancakeGui : public tsl::Gui {
}
};

class PleaseUpdateGui final : public tsl::Gui {
virtual tsl::elm::Element *createUI() override {
auto const frame = new tsl::elm::OverlayFrame(AppTitle, AppVersion);

auto const custom = new tsl::elm::CustomDrawer([msgW = 0, msgH = 0](tsl::gfx::Renderer *drawer, u16 x, u16 y, u16 w, u16 h) mutable {
drawer->drawString("\uE150", false, x + (w / 2) - (90 / 2), 300, 90, 0xffff);
auto [width, height] = drawer->drawString("Update to at least\nAtmosphère 1.6.1", false, x + (w / 2) - (msgW / 2), 380, 25, 0xffff);
if (msgW == 0) {
msgW = width;
msgH = height;
}
});

frame->setContent(custom);

return frame;
}
};

class PancakeOverlay final : public tsl::Overlay {
public:
virtual void initServices() override {
Expand All @@ -118,7 +137,11 @@ class PancakeOverlay final : public tsl::Overlay {
}

virtual std::unique_ptr<tsl::Gui> loadInitialGui() override {
return std::make_unique<PancakeGui>();
if (!util::IsErista() && !util::SupportsMarikoRebootToConfig()) {
return std::make_unique<PleaseUpdateGui>();
} else {
return std::make_unique<PancakeGui>();
}
}
};

Expand Down

0 comments on commit f1b7766

Please sign in to comment.