From c2e9eb97184dbb97f82f6c6ee1b3544008371c3e Mon Sep 17 00:00:00 2001 From: mat <26722564+matcool@users.noreply.github.com> Date: Mon, 24 Jun 2024 21:25:55 -0300 Subject: [PATCH] make safeModeCheck return a boolean --- loader/src/load.cpp | 37 ++++++++++++++++++++++--------------- loader/src/load.hpp | 2 +- loader/src/load.mm | 13 +++++++------ 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/loader/src/load.cpp b/loader/src/load.cpp index 169ca472..f18dad23 100644 --- a/loader/src/load.cpp +++ b/loader/src/load.cpp @@ -84,21 +84,26 @@ void tryShowForwardCompat() { } #ifdef GEODE_IS_WINDOWS - void safeModeCheck() { - // yes this is quite funny - if (GetAsyncKeyState(VK_SHIFT) != 0) { - auto choice = MessageBoxA( - NULL, - "(This has been triggered because you were holding SHIFT)\n" - "Do you want to activate Geode Safe Mode? This disables loading any mods.", - "Attention", - MB_YESNO | MB_ICONINFORMATION - ); - if (choice == IDYES) { - LoaderImpl::get()->forceSafeMode(); - } - } +bool safeModeCheck() { + // yes this is quite funny + if (GetAsyncKeyState(VK_SHIFT) != 0) { + auto choice = MessageBoxA( + NULL, + "(This has been triggered because you were holding SHIFT)\n" + "Do you want to activate Geode Safe Mode? This disables loading any mods.", + "Attention", + MB_YESNO | MB_ICONINFORMATION + ); + return choice == IDYES; } + return false; +} +#else !defined(GEODE_IS_MACOS) +// macos is defined in load.mm, this is for android +// on android the launcher just adds the launch args to enable safe mode +bool safeModeCheck() { + return false; +} #endif int geodeEntry(void* platformData) { @@ -110,7 +115,9 @@ int geodeEntry(void* platformData) { console::openIfClosed(); } - safeModeCheck(); + if (safeModeCheck()) { + LoaderImpl::get()->forceSafeMode(); + } std::string forwardCompatSuffix; if (LoaderImpl::get()->isForwardCompatMode()) diff --git a/loader/src/load.hpp b/loader/src/load.hpp index 72cd36b4..bae09e2a 100644 --- a/loader/src/load.hpp +++ b/loader/src/load.hpp @@ -1,3 +1,3 @@ #pragma once -void safeModeCheck(); +bool safeModeCheck(); int geodeEntry(void* platformData); \ No newline at end of file diff --git a/loader/src/load.mm b/loader/src/load.mm index c534823c..55756495 100644 --- a/loader/src/load.mm +++ b/loader/src/load.mm @@ -1,14 +1,15 @@ #include "load.hpp" -#include -#include +#include #ifdef GEODE_IS_MACOS +#include +#include #include #include #include -void safeModeCheck() { +bool safeModeCheck() { if (CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, (CGKeyCode)56)) { // 56 is Shift key NSAlert *alert = [NSAlert new]; alert.messageText = @"The shift key was held down. Would you like to enable safe mode?"; @@ -16,10 +17,10 @@ void safeModeCheck() { NSButton *cancelButton = [alert addButtonWithTitle:@"No"]; alert.window.defaultButtonCell = cancelButton.cell; NSModalResponse choice = [alert runModal]; - if (choice == NSAlertFirstButtonReturn) { // if Yes is clicked - LoaderImpl::get()->forceSafeMode(); - } + // if Yes is clicked + return choice == NSAlertFirstButtonReturn; } + return false; } #endif \ No newline at end of file