From eb476f9f0cbd59cb4f43e3a4539ba34c31d2b492 Mon Sep 17 00:00:00 2001 From: Ninjdai Date: Sun, 12 Nov 2023 11:17:18 +0100 Subject: [PATCH] Added warning screen for RTC and inacurrate emus --- include/strings.h | 2 ++ src/main_menu.c | 28 +++++++++++++++++++++++++++- src/strings.c | 3 +++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/strings.h b/include/strings.h index 845e16e9f..11e7d2f31 100644 --- a/include/strings.h +++ b/include/strings.h @@ -328,6 +328,8 @@ extern const u8 gText_SaveFileErased[]; extern const u8 gText_SaveFileCorrupted[]; extern const u8 gJPText_No1MSubCircuit[]; extern const u8 gText_BatteryRunDry[]; +extern const u8 gText_EmuWarning[]; +extern const u8 gText_TimeWarning[]; extern const u8 gText_MainMenuNewGame[]; extern const u8 gText_MainMenuOption[]; extern const u8 gText_MainMenuContinue[]; diff --git a/src/main_menu.c b/src/main_menu.c index 53aa1228c..8d3af495a 100644 --- a/src/main_menu.c +++ b/src/main_menu.c @@ -179,6 +179,7 @@ static u8 sBirchSpeechMainTaskId; static u32 InitMainMenu(bool8); static void Task_MainMenuCheckSaveFile(u8); static void Task_MainMenuCheckBattery(u8); +static bool8 IsAccurateGBA(void); static void Task_WaitForSaveFileErrorWindow(u8); static void CreateMainMenuErrorWindow(const u8 *); static void ClearMainMenuWindowTilemap(const struct WindowTemplate *); @@ -702,8 +703,19 @@ static void Task_WaitForSaveFileErrorWindow(u8 taskId) } } +static bool8 IsAccurateGBA(void) { // tests to see whether running on either an accurate emulator in >=2020, or real hardware + u32 code[5] = {0xFF1EE12F, 0xE1DF00B0, 0xE12FFF1E, 0xAAAABBBB, 0xCCCCDDDD}; // ARM: _;ldrh r0, [pc];bx lr + u32 func = (u32) &code[0]; + if (func & 3) // not word aligned; safer to just return false here + return FALSE; + func = (func & ~3) | 0x2; // misalign PC to test PC-relative loading + return ((u32 (*)(void)) func)() == code[3] >> 16; +} + static void Task_MainMenuCheckBattery(u8 taskId) { + s16 *data = gTasks[taskId].data; + if (!gPaletteFade.active) { SetGpuReg(REG_OFFSET_WIN0H, 0); @@ -716,7 +728,21 @@ static void Task_MainMenuCheckBattery(u8 taskId) if (!(RtcGetErrorStatus() & RTC_ERR_FLAG_MASK)) { - gTasks[taskId].func = Task_DisplayMainMenu; + if (tMenuType != HAS_NO_SAVED_GAME) + RtcCalcLocalTime(); + if (!IsAccurateGBA()) { + CreateMainMenuErrorWindow(gText_EmuWarning); + gTasks[taskId].func = Task_WaitForBatteryDryErrorWindow; + // save exists and stored day count is more than a day ahead of RTC + } else if (tMenuType != HAS_NO_SAVED_GAME && VarGet(VAR_DAYS) > gLocalTime.days + 1) { + // Reset days var to today + 1 + // Allowing daily events to happen again in a day + VarSet(VAR_DAYS, gLocalTime.days + 1); + CreateMainMenuErrorWindow(gText_TimeWarning); + gTasks[taskId].func = Task_WaitForBatteryDryErrorWindow; + } else { + gTasks[taskId].func = Task_DisplayMainMenu; + } } else { diff --git a/src/strings.c b/src/strings.c index f9137c4f1..6dcd0072c 100644 --- a/src/strings.c +++ b/src/strings.c @@ -36,6 +36,9 @@ const u8 gText_SaveFileCorrupted[] = _("The save file is corrupted. The\npreviou const u8 gText_SaveFileErased[] = _("The save file has been erased\ndue to corruption or damage."); const u8 gJPText_No1MSubCircuit[] = _("1Mサブきばんが ささっていません!"); const u8 gText_BatteryRunDry[] = _("The internal battery has run dry.\nThe game can be played.\pHowever, clock-based events will\nno longer occur."); +const u8 gText_EmuWarning[] = _("Inaccurate emulator detected.\nYou should use a recent emulator with\nsupport for RTC (Real Time Clock).\nThe game should still work, but\nyou may encouter errors"); +const u8 gText_TimeWarning[] = _("Real Time Clock is more than 1 day\nbehind saved time.\nPlease don't tamper with the RTC, as it may\nbreak some functionnality"); + const u8 gText_Player[] = _("PLAYER"); // Unused const u8 gText_Pokedex[] = _("POKéDEX"); // Unused const u8 gText_Time[] = _("TIME");