From aba34015db0dcd414d185e6d66ad078de0e6ec80 Mon Sep 17 00:00:00 2001 From: Ruby Date: Thu, 24 Apr 2025 01:34:37 +0800 Subject: [PATCH] Time menu for RTC in debug menu. (#6634) Co-authored-by: psf <77138753+pkmnsnfrn@users.noreply.github.com> Co-authored-by: Bassoonian --- asm/macros/event.inc | 6 + data/scripts/debug.inc | 31 ++++ include/config/overworld.h | 5 +- include/fake_rtc.h | 4 + src/debug.c | 303 +++++++++++++++++++++++++++++++++++++ src/fake_rtc.c | 50 +++++- src/scrcmd.c | 6 + 7 files changed, 400 insertions(+), 5 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 3a651191de..d93829f55b 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -338,6 +338,12 @@ .byte SCR_OP_GETTIME .endm + @ Sets the values of variable VAR_0x8000 to the time of day according to those found in rtc.h. + @ 0 = MORNING, 1 = DAY, 2 = EVENING, 3 = NIGHT + .macro gettimeofday + callnative ScrCmd_gettimeofday + .endm + @ Plays the specified sound. Only one sound may play at a time, with newer ones interrupting older ones. .macro playse song:req .byte SCR_OP_PLAYSE diff --git a/data/scripts/debug.inc b/data/scripts/debug.inc index 29640b2d2e..d82ce2f358 100644 --- a/data/scripts/debug.inc +++ b/data/scripts/debug.inc @@ -584,3 +584,34 @@ Debug_EventScript_FontTest:: @Debug_EventScript_InflictStatus1_Close: @ releaseall @ end + +Debug_EventScript_TellTheTime:: + callnative DebugMenu_CalculateTime + msgbox Debug_EventScript_TellTheTime_Text_0, MSGBOX_DEFAULT + waitmessage + closemessage + end + +Debug_EventScript_PrintTimeOfDay:: + callnative DebugMenu_CalculateTimeOfDay + msgbox DebugEventScript_PrintWeekday_Text_0, MSGBOX_DEFAULT + waitmessage + closemessage + end + +Debug_EventScript_FakeRTCNotEnabled:: + msgbox Debug_EventScript_FakeRTCNotEnabled_Text_0, MSGBOX_DEFAULT + waitmessage + closemessage + return + +Debug_EventScript_FakeRTCNotEnabled_Text_0: + .string "You currently do not have Fake RTC\nenabled. Please enable it in include/\lconfig/overworld.h$" + + +Debug_EventScript_TellTheTime_Text_0: + .string "Time and date:\n" + .string "{STR_VAR_1}, {STR_VAR_2}:{STR_VAR_3}$" + +DebugEventScript_PrintWeekday_Text_0: + .string "Time of day: {STR_VAR_1}$" diff --git a/include/config/overworld.h b/include/config/overworld.h index 739aaeee77..ad926820f2 100644 --- a/include/config/overworld.h +++ b/include/config/overworld.h @@ -81,13 +81,14 @@ #define OW_STORM_DRAIN GEN_LATEST // In Gen8+, if a Pokémon with Storm Drain is leading the party, there is a 50% chance to encounter a Water-type Pokémon. #define OW_FLASH_FIRE GEN_LATEST // In Gen8+, if a Pokémon with Flash Fire is leading the party, there is a 50% chance to encounter a Fire-type Pokémon. -// These generational defines only make a distinction for OW_ALTERED_TIME_RATIO +// These defines only make a distinction for OW_ALTERED_TIME_RATIO #define GEN_8_PLA GEN_LATEST + 2 +#define TIME_DEBUG GEN_LATEST + 3 //Time #define OW_TIMES_OF_DAY GEN_LATEST // Different generations have the times of day change at different times. #define OW_USE_FAKE_RTC FALSE // When TRUE, seconds on the in-game clock will only advance once every 60 playTimeVBlanks (every 60 frames). -#define OW_ALTERED_TIME_RATIO GEN_LATEST // In GEN_8_PLA, the time in game moves forward 60 seconds for every second in the RTC. In GEN_9, it is 20 seconds. This has no effect if OW_USE_FAKE_RTC is FALSE. +#define OW_ALTERED_TIME_RATIO GEN_LATEST // In GEN_8_PLA, the time in game moves forward 60 seconds for every second in the RTC. In GEN_9, it is 20 seconds. TIME_DEBUG is 1:1, and meant for debugging purposes. This has no effect if OW_USE_FAKE_RTC is FALSE. #define OW_TIME_OF_DAY_ENCOUNTERS FALSE // If TRUE, will allow the user to define and use different encounter tables based on the time of day. #define OW_TIME_OF_DAY_DISABLE_FALLBACK FALSE // If TRUE, if the encounter table for a specific map and time is empty, the area will have no encounters instead of falling back to the vanilla map and time. #define OW_TIME_OF_DAY_FALLBACK TIME_MORNING // The time of day that encounter tables fall back to. diff --git a/include/fake_rtc.h b/include/fake_rtc.h index 92599b987a..34c29d7adf 100644 --- a/include/fake_rtc.h +++ b/include/fake_rtc.h @@ -8,7 +8,11 @@ struct SiiRtcInfo* FakeRtc_GetCurrentTime(void); void FakeRtc_GetRawInfo(struct SiiRtcInfo *rtc); void FakeRtc_AdvanceTimeBy(u32 days, u32 hours, u32 minutes, u32 seconds); void FakeRtc_ManuallySetTime(u32 day, u32 hour, u32 minute, u32 second); +void FakeRtc_ForwardTimeTo(u32 hour, u32 minute, u32 second); void FakeRtc_TickTimeForward(void); u32 FakeRtc_GetSecondsRatio(void); +void Script_PauseFakeRtc(void); +void Script_ResumeFakeRtc(void); +void Script_ToggleFakeRtc(void); #endif // GUARD_FAKE_RTC_UTIL_H diff --git a/src/debug.c b/src/debug.c index 2ac63e347e..4861699932 100644 --- a/src/debug.c +++ b/src/debug.c @@ -66,6 +66,9 @@ #include "constants/songs.h" #include "constants/species.h" #include "constants/weather.h" +#include "siirtc.h" +#include "rtc.h" +#include "fake_rtc.h" #include "save.h" // ******************************* @@ -101,6 +104,34 @@ enum UtilDebugMenu DEBUG_UTIL_MENU_ITEM_BERRY_FUNCTIONS, DEBUG_UTIL_MENU_ITEM_EWRAM_COUNTERS, DEBUG_UTIL_MENU_ITEM_STEVEN_MULTI, + DEBUG_UTIL_MENU_ITEM_TIME_MENU, +}; + +enum TimeMenuDebugMenu +{ + DEBUG_TIME_MENU_ITEM_PRINTTIME, + DEBUG_TIME_MENU_ITEM_PRINTTIMEOFDAY, + DEBUG_TIME_MENU_ITEM_TIMESOFDAY, + DEBUG_TIME_MENU_ITEM_WEEKDAYS, +}; + +enum TimeMenuTimeOfDay +{ + DEBUG_TIME_MENU_ITEM_MORNING, + DEBUG_TIME_MENU_ITEM_DAY, + DEBUG_TIME_MENU_ITEM_EVENING, + DEBUG_TIME_MENU_ITEM_NIGHT, +}; + +enum TimeMenuWeekdays +{ + DEBUG_TIME_MENU_ITEM_SUNDAY, + DEBUG_TIME_MENU_ITEM_MONDAY, + DEBUG_TIME_MENU_ITEM_TUESDAY, + DEBUG_TIME_MENU_ITEM_WEDNESDAY, + DEBUG_TIME_MENU_ITEM_THURSDAY, + DEBUG_TIME_MENU_ITEM_FRIDAY, + DEBUG_TIME_MENU_ITEM_SATURDAY, }; enum GivePCBagDebugMenu @@ -307,6 +338,7 @@ static EWRAM_DATA struct DebugMenuListData *sDebugMenuListData = NULL; static EWRAM_DATA struct DebugBattleData *sDebugBattleData = NULL; EWRAM_DATA bool8 gIsDebugBattle = FALSE; EWRAM_DATA u32 gDebugAIFlags = 0; +EWRAM_DATA u32 gDebugTime = 0; // ******************************* // Define functions @@ -370,6 +402,15 @@ static void DebugAction_Util_ExpansionVersion(u8 taskId); static void DebugAction_Util_BerryFunctions(u8 taskId); static void DebugAction_Util_CheckEWRAMCounters(u8 taskId); static void DebugAction_Util_Steven_Multi(u8 taskId); +static void DebugAction_Util_OpenTimeMenu(u8 taskId); + +static void DebugAction_TimeMenu_PrintTime(u8 taskId); +static void DebugAction_TimeMenu_PrintTimeOfDay(u8 taskId); +static void DebugAction_TimeMenu_TimesOfDay(u8 taskId); +static void DebugAction_TimeMenu_Weekdays(u8 taskId); + +static void DebugAction_TimeMenu_ChangeTimeOfDay(u8 taskId); +static void DebugAction_TimeMenu_ChangeWeekdays(u8 taskId); static void DebugAction_OpenPCBagFillMenu(u8 taskId); static void DebugAction_PCBag_Fill_PCBoxes_Fast(u8 taskId); @@ -479,6 +520,9 @@ extern const u8 Debug_BoxFilledMessage[]; extern const u8 Debug_ShowExpansionVersion[]; extern const u8 Debug_EventScript_EWRAMCounters[]; extern const u8 Debug_EventScript_Steven_Multi[]; +extern const u8 Debug_EventScript_PrintTimeOfDay[]; +extern const u8 Debug_EventScript_TellTheTime[]; +extern const u8 Debug_EventScript_FakeRTCNotEnabled[]; extern const u8 Debug_BerryPestsDisabled[]; extern const u8 Debug_BerryWeedsDisabled[]; @@ -502,6 +546,26 @@ static const u8 sDebugText_Util_WarpToMap_SelectMap[] = _("Map: {STR_VAR_1} static const u8 sDebugText_Util_WarpToMap_SelectWarp[] = _("Warp:{CLEAR_TO 90}\n{STR_VAR_1}{CLEAR_TO 90}\n{CLEAR_TO 90}\n{STR_VAR_3}{CLEAR_TO 90}"); static const u8 sDebugText_Util_WarpToMap_SelMax[] = _("{STR_VAR_1} / {STR_VAR_2}"); static const u8 sDebugText_Util_Weather_ID[] = _("Weather ID: {STR_VAR_3}\n{STR_VAR_1}\n{STR_VAR_2}"); + +//Time Menu + +static const u8 *const gDayNameStringsTable[WEEKDAY_COUNT] = { + COMPOUND_STRING("Sunday"), + COMPOUND_STRING("Monday"), + COMPOUND_STRING("Tuesday"), + COMPOUND_STRING("Wednesday"), + COMPOUND_STRING("Thursday"), + COMPOUND_STRING("Friday"), + COMPOUND_STRING("Saturday"), +}; + +static const u8 *const gTimeOfDayStringsTable[TIMES_OF_DAY_COUNT] = { + COMPOUND_STRING("Morning"), + COMPOUND_STRING("Day"), + COMPOUND_STRING("Evening"), + COMPOUND_STRING("Night"), +}; + // Flags/Vars Menu static const u8 sDebugText_FlagsVars_Flag[] = _("Flag: {STR_VAR_1}{CLEAR_TO 90}\n{STR_VAR_2}{CLEAR_TO 90}\n{STR_VAR_3}"); static const u8 sDebugText_FlagsVars_VariableHex[] = _("{STR_VAR_1}{CLEAR_TO 90}\n0x{STR_VAR_2}{CLEAR_TO 90}"); @@ -584,6 +648,34 @@ static const struct ListMenuItem sDebugMenu_Items_Utilities[] = [DEBUG_UTIL_MENU_ITEM_BERRY_FUNCTIONS] = {COMPOUND_STRING("Berry Functions…{CLEAR_TO 110}{RIGHT_ARROW}"), DEBUG_UTIL_MENU_ITEM_BERRY_FUNCTIONS}, [DEBUG_UTIL_MENU_ITEM_EWRAM_COUNTERS] = {COMPOUND_STRING("EWRAM Counters…{CLEAR_TO 110}{RIGHT_ARROW}"), DEBUG_UTIL_MENU_ITEM_EWRAM_COUNTERS}, [DEBUG_UTIL_MENU_ITEM_STEVEN_MULTI] = {COMPOUND_STRING("Steven Multi"), DEBUG_UTIL_MENU_ITEM_STEVEN_MULTI}, + [DEBUG_UTIL_MENU_ITEM_TIME_MENU] = {COMPOUND_STRING("Time Menu"), DEBUG_UTIL_MENU_ITEM_TIME_MENU}, +}; + +static const struct ListMenuItem sDebugMenu_Items_TimeMenu[] = +{ + [DEBUG_TIME_MENU_ITEM_PRINTTIME] = {COMPOUND_STRING("Print current time"), DEBUG_TIME_MENU_ITEM_PRINTTIME}, + [DEBUG_TIME_MENU_ITEM_PRINTTIMEOFDAY] = {COMPOUND_STRING("{FONT_NARROW}Print current time of day"), DEBUG_TIME_MENU_ITEM_PRINTTIMEOFDAY}, + [DEBUG_TIME_MENU_ITEM_TIMESOFDAY] = {COMPOUND_STRING("{FONT_NARROW}Change current time of day"), DEBUG_TIME_MENU_ITEM_TIMESOFDAY}, + [DEBUG_TIME_MENU_ITEM_WEEKDAYS] = {COMPOUND_STRING("Change current weekday"), DEBUG_TIME_MENU_ITEM_WEEKDAYS}, +}; + +static const struct ListMenuItem sDebugMenu_Items_TimeMenu_TimesOfDay[] = +{ + [DEBUG_TIME_MENU_ITEM_MORNING] = {gTimeOfDayStringsTable[TIME_MORNING], DEBUG_TIME_MENU_ITEM_MORNING}, + [DEBUG_TIME_MENU_ITEM_DAY] = {gTimeOfDayStringsTable[TIME_DAY], DEBUG_TIME_MENU_ITEM_DAY}, + [DEBUG_TIME_MENU_ITEM_EVENING] = {gTimeOfDayStringsTable[TIME_EVENING], DEBUG_TIME_MENU_ITEM_EVENING}, + [DEBUG_TIME_MENU_ITEM_NIGHT] = {gTimeOfDayStringsTable[TIME_NIGHT], DEBUG_TIME_MENU_ITEM_NIGHT}, +}; + +static const struct ListMenuItem sDebugMenu_Items_TimeMenu_Weekdays[] = +{ + [DEBUG_TIME_MENU_ITEM_SUNDAY] = {gDayNameStringsTable[WEEKDAY_SUN], DEBUG_TIME_MENU_ITEM_SUNDAY}, + [DEBUG_TIME_MENU_ITEM_MONDAY] = {gDayNameStringsTable[WEEKDAY_MON], DEBUG_TIME_MENU_ITEM_MONDAY}, + [DEBUG_TIME_MENU_ITEM_TUESDAY] = {gDayNameStringsTable[WEEKDAY_TUE], DEBUG_TIME_MENU_ITEM_TUESDAY}, + [DEBUG_TIME_MENU_ITEM_WEDNESDAY] = {gDayNameStringsTable[WEEKDAY_WED], DEBUG_TIME_MENU_ITEM_WEDNESDAY}, + [DEBUG_TIME_MENU_ITEM_THURSDAY] = {gDayNameStringsTable[WEEKDAY_THU], DEBUG_TIME_MENU_ITEM_THURSDAY}, + [DEBUG_TIME_MENU_ITEM_FRIDAY] = {gDayNameStringsTable[WEEKDAY_FRI], DEBUG_TIME_MENU_ITEM_FRIDAY}, + [DEBUG_TIME_MENU_ITEM_SATURDAY] = {gDayNameStringsTable[WEEKDAY_SAT], DEBUG_TIME_MENU_ITEM_SATURDAY}, }; static const struct ListMenuItem sDebugMenu_Items_PCBag[] = @@ -757,6 +849,7 @@ static void (*const sDebugMenu_Actions_Utilities[])(u8) = [DEBUG_UTIL_MENU_ITEM_BERRY_FUNCTIONS] = DebugAction_Util_BerryFunctions, [DEBUG_UTIL_MENU_ITEM_EWRAM_COUNTERS] = DebugAction_Util_CheckEWRAMCounters, [DEBUG_UTIL_MENU_ITEM_STEVEN_MULTI] = DebugAction_Util_Steven_Multi, + [DEBUG_UTIL_MENU_ITEM_TIME_MENU] = DebugAction_Util_OpenTimeMenu, }; static void (*const sDebugMenu_Actions_PCBag[])(u8) = @@ -849,6 +942,33 @@ static void (*const sDebugMenu_Actions_BerryFunctions[])(u8) = [DEBUG_BERRY_FUNCTIONS_MENU_WEEDS] = DebugAction_BerryFunctions_Weeds, }; +static void (*const sDebugMenu_Actions_TimeMenu[])(u8) = +{ + [DEBUG_TIME_MENU_ITEM_PRINTTIME] = DebugAction_TimeMenu_PrintTime, + [DEBUG_TIME_MENU_ITEM_PRINTTIMEOFDAY] = DebugAction_TimeMenu_PrintTimeOfDay, + [DEBUG_TIME_MENU_ITEM_TIMESOFDAY] = DebugAction_TimeMenu_TimesOfDay, + [DEBUG_TIME_MENU_ITEM_WEEKDAYS] = DebugAction_TimeMenu_Weekdays, +}; + +static void (*const sDebugMenu_Actions_TimeMenu_TimesOfDay[])(u8) = +{ + [DEBUG_TIME_MENU_ITEM_MORNING] = DebugAction_TimeMenu_ChangeTimeOfDay, + [DEBUG_TIME_MENU_ITEM_DAY] = DebugAction_TimeMenu_ChangeTimeOfDay, + [DEBUG_TIME_MENU_ITEM_EVENING] = DebugAction_TimeMenu_ChangeTimeOfDay, + [DEBUG_TIME_MENU_ITEM_NIGHT] = DebugAction_TimeMenu_ChangeTimeOfDay, +}; + +static void (*const sDebugMenu_Actions_TimeMenu_Weekdays[])(u8) = +{ + [DEBUG_TIME_MENU_ITEM_SUNDAY] = DebugAction_TimeMenu_ChangeWeekdays, + [DEBUG_TIME_MENU_ITEM_MONDAY] = DebugAction_TimeMenu_ChangeWeekdays, + [DEBUG_TIME_MENU_ITEM_TUESDAY] = DebugAction_TimeMenu_ChangeWeekdays, + [DEBUG_TIME_MENU_ITEM_WEDNESDAY] = DebugAction_TimeMenu_ChangeWeekdays, + [DEBUG_TIME_MENU_ITEM_THURSDAY] = DebugAction_TimeMenu_ChangeWeekdays, + [DEBUG_TIME_MENU_ITEM_FRIDAY] = DebugAction_TimeMenu_ChangeWeekdays, + [DEBUG_TIME_MENU_ITEM_SATURDAY] = DebugAction_TimeMenu_ChangeWeekdays, +}; + // ******************************* // Windows static const struct WindowTemplate sDebugMenuWindowTemplateMain = @@ -999,6 +1119,27 @@ static const struct ListMenuTemplate sDebugMenu_ListTemplate_BerryFunctions = .totalItems = ARRAY_COUNT(sDebugMenu_Items_BerryFunctions), }; +static const struct ListMenuTemplate sDebugMenu_ListTemplate_TimeMenu = +{ + .items = sDebugMenu_Items_TimeMenu, + .moveCursorFunc = ListMenuDefaultCursorMoveFunc, + .totalItems = ARRAY_COUNT(sDebugMenu_Items_TimeMenu), +}; + +static const struct ListMenuTemplate sDebugMenu_ListTemplate_TimeMenu_TimesOfDay = +{ + .items = sDebugMenu_Items_TimeMenu_TimesOfDay, + .moveCursorFunc = ListMenuDefaultCursorMoveFunc, + .totalItems = ARRAY_COUNT(sDebugMenu_Items_TimeMenu_TimesOfDay), +}; + +static const struct ListMenuTemplate sDebugMenu_ListTemplate_TimeMenu_Weekdays = +{ + .items = sDebugMenu_Items_TimeMenu_Weekdays, + .moveCursorFunc = ListMenuDefaultCursorMoveFunc, + .totalItems = ARRAY_COUNT(sDebugMenu_Items_TimeMenu_Weekdays), +}; + // ******************************* // Functions universal void Debug_ShowMainMenu(void) @@ -1444,6 +1585,21 @@ static void DebugTask_HandleMenuInput_Scripts(u8 taskId) DebugTask_HandleMenuInput_General(taskId, sDebugMenu_Actions_Scripts, DebugTask_HandleMenuInput_Main, sDebugMenu_ListTemplate_Main); } +static void DebugTask_HandleMenuInput_TimeMenu(u8 taskId) +{ + DebugTask_HandleMenuInput_General(taskId, sDebugMenu_Actions_TimeMenu, DebugTask_HandleMenuInput_Main, sDebugMenu_ListTemplate_Main); +} + +static void DebugTask_HandleMenuInput_TimeMenu_TimesOfDay(u8 taskId) +{ + DebugTask_HandleMenuInput_General(taskId, sDebugMenu_Actions_TimeMenu_TimesOfDay, DebugTask_HandleMenuInput_Main, sDebugMenu_ListTemplate_Main); +} + +static void DebugTask_HandleMenuInput_TimeMenu_Weekdays(u8 taskId) +{ + DebugTask_HandleMenuInput_General(taskId, sDebugMenu_Actions_TimeMenu_Weekdays, DebugTask_HandleMenuInput_Main, sDebugMenu_ListTemplate_Main); +} + static void DebugTask_HandleMenuInput_FlagsVars(u8 taskId) { void (*func)(u8); @@ -1702,6 +1858,30 @@ static void DebugAction_Util_BerryFunctions(u8 taskId) Debug_ShowMenu(DebugTask_HandleMenuInput_BerryFunctions, sDebugMenu_ListTemplate_BerryFunctions); } +static void DebugAction_Util_OpenTimeMenu(u8 taskId) +{ + Debug_DestroyMenu_Full(taskId); + Debug_ShowMenu(DebugTask_HandleMenuInput_TimeMenu, sDebugMenu_ListTemplate_TimeMenu); +} + +static void DebugAction_TimeMenu_TimesOfDay(u8 taskId) +{ + Debug_DestroyMenu_Full(taskId); + if (!OW_USE_FAKE_RTC) + Debug_DestroyMenu_Full_Script(taskId, Debug_EventScript_FakeRTCNotEnabled); + else + Debug_ShowMenu(DebugTask_HandleMenuInput_TimeMenu_TimesOfDay, sDebugMenu_ListTemplate_TimeMenu_TimesOfDay); +} + +static void DebugAction_TimeMenu_Weekdays(u8 taskId) +{ + Debug_DestroyMenu_Full(taskId); + if (!OW_USE_FAKE_RTC) + Debug_DestroyMenu_Full_Script(taskId, Debug_EventScript_FakeRTCNotEnabled); + else + Debug_ShowMenu(DebugTask_HandleMenuInput_TimeMenu_Weekdays, sDebugMenu_ListTemplate_TimeMenu_Weekdays); +} + // ******************************* // Actions Utilities @@ -2134,6 +2314,60 @@ void BufferExpansionVersion(struct ScriptContext *ctx) string = StringCopy(string, sText_Unreleased); } +static void DebugAction_TimeMenu_PrintTime(u8 taskId) +{ + Debug_DestroyMenu_Full(taskId); + LockPlayerFieldControls(); + Debug_DestroyMenu_Full_Script(taskId, Debug_EventScript_TellTheTime); +} + +void DebugMenu_CalculateTime(struct ScriptContext *ctx) +{ + if (OW_USE_FAKE_RTC) + { + struct SiiRtcInfo *rtc = FakeRtc_GetCurrentTime(); + StringExpandPlaceholders(gStringVar1, gDayNameStringsTable[rtc->dayOfWeek]); + ConvertIntToDecimalStringN(gStringVar2, rtc->hour, STR_CONV_MODE_LEFT_ALIGN, 3); + ConvertIntToDecimalStringN(gStringVar3, rtc->minute, STR_CONV_MODE_LEADING_ZEROS, 2); + } + else + { + u32 day = ((gLocalTime.days - 1) + 6) % 7 ; + RtcCalcLocalTime(); + StringExpandPlaceholders(gStringVar1, gDayNameStringsTable[day]); + ConvertIntToDecimalStringN(gStringVar2, gLocalTime.hours, STR_CONV_MODE_LEFT_ALIGN, 3); + ConvertIntToDecimalStringN(gStringVar3, gLocalTime.minutes, STR_CONV_MODE_LEADING_ZEROS, 2); + } +} + +static void DebugAction_TimeMenu_PrintTimeOfDay(u8 taskId) +{ + Debug_DestroyMenu_Full(taskId); + LockPlayerFieldControls(); + Debug_DestroyMenu_Full_Script(taskId, Debug_EventScript_PrintTimeOfDay); +} + +void DebugMenu_CalculateTimeOfDay(struct ScriptContext *ctx) +{ + switch (GetTimeOfDay()) + { + case TIME_MORNING: + StringExpandPlaceholders(gStringVar1, gTimeOfDayStringsTable[TIME_MORNING]); + break; + case TIME_DAY: + StringExpandPlaceholders(gStringVar1, gTimeOfDayStringsTable[TIME_DAY]); + break; + case TIME_EVENING: + StringExpandPlaceholders(gStringVar1, gTimeOfDayStringsTable[TIME_EVENING]); + break; + case TIME_NIGHT: + StringExpandPlaceholders(gStringVar1, gTimeOfDayStringsTable[TIME_NIGHT]); + break; + default: + break; + } +} + // ******************************* // Actions Scripts static void DebugAction_Util_Script_1(u8 taskId) @@ -3537,6 +3771,75 @@ static void DebugAction_Give_DayCareEgg(u8 taskId) TriggerPendingDaycareEgg(); } +// ******************************* +// Actions TimeMenu + +static void DebugAction_TimeMenu_ChangeTimeOfDay(u8 taskId) +{ + u32 input = ListMenu_ProcessInput(gTasks[taskId].tMenuTaskId); + + DebugAction_DestroyExtraWindow(taskId); + switch (input) + { + case DEBUG_TIME_MENU_ITEM_MORNING: + FakeRtc_ForwardTimeTo(MORNING_HOUR_BEGIN, 0, 0); + break; + case DEBUG_TIME_MENU_ITEM_DAY: + FakeRtc_ForwardTimeTo(DAY_HOUR_BEGIN, 0, 0); + break; + case DEBUG_TIME_MENU_ITEM_EVENING: + FakeRtc_ForwardTimeTo(EVENING_HOUR_BEGIN, 0, 0); + break; + case DEBUG_TIME_MENU_ITEM_NIGHT: + FakeRtc_ForwardTimeTo(NIGHT_HOUR_BEGIN, 0, 0); + break; + } + Debug_DestroyMenu_Full(taskId); + SetMainCallback2(CB2_LoadMap); +} + +static void DebugAction_TimeMenu_ChangeWeekdays(u8 taskId) +{ + u32 input = ListMenu_ProcessInput(gTasks[taskId].tMenuTaskId); + struct SiiRtcInfo *rtc = FakeRtc_GetCurrentTime(); + u32 daysToAdd = 0; + + DebugAction_DestroyExtraWindow(taskId); + switch(input) + { + case DEBUG_TIME_MENU_ITEM_SUNDAY: + daysToAdd = ((WEEKDAY_SUN - rtc->dayOfWeek) + WEEKDAY_COUNT) % WEEKDAY_COUNT; + FakeRtc_AdvanceTimeBy(daysToAdd, 0, 0, 0); + break; + case DEBUG_TIME_MENU_ITEM_MONDAY: + daysToAdd = ((WEEKDAY_MON - rtc->dayOfWeek) + WEEKDAY_COUNT) % WEEKDAY_COUNT; + FakeRtc_AdvanceTimeBy(daysToAdd, 0, 0, 0); + break; + case DEBUG_TIME_MENU_ITEM_TUESDAY: + daysToAdd = ((WEEKDAY_TUE - rtc->dayOfWeek) + WEEKDAY_COUNT) % WEEKDAY_COUNT; + FakeRtc_AdvanceTimeBy(daysToAdd, 0, 0, 0); + break; + case DEBUG_TIME_MENU_ITEM_WEDNESDAY: + daysToAdd = ((WEEKDAY_WED - rtc->dayOfWeek) + WEEKDAY_COUNT) % WEEKDAY_COUNT; + FakeRtc_AdvanceTimeBy(daysToAdd, 0, 0, 0); + break; + case DEBUG_TIME_MENU_ITEM_THURSDAY: + daysToAdd = ((WEEKDAY_THU - rtc->dayOfWeek) + WEEKDAY_COUNT) % WEEKDAY_COUNT; + FakeRtc_AdvanceTimeBy(daysToAdd, 0, 0, 0); + break; + case DEBUG_TIME_MENU_ITEM_FRIDAY: + daysToAdd = ((WEEKDAY_FRI - rtc->dayOfWeek) + WEEKDAY_COUNT) % WEEKDAY_COUNT; + FakeRtc_AdvanceTimeBy(daysToAdd, 0, 0, 0); + break; + case DEBUG_TIME_MENU_ITEM_SATURDAY: + daysToAdd = ((WEEKDAY_SAT - rtc->dayOfWeek) + WEEKDAY_COUNT) % WEEKDAY_COUNT; + FakeRtc_AdvanceTimeBy(daysToAdd, 0, 0, 0); + break; + } + Debug_DestroyMenu_Full(taskId); + SetMainCallback2(CB2_LoadMap); +} + // ******************************* // Actions PCBag diff --git a/src/fake_rtc.c b/src/fake_rtc.c index 1c139331b6..2024065b7d 100644 --- a/src/fake_rtc.c +++ b/src/fake_rtc.c @@ -8,6 +8,8 @@ #include "event_data.h" #include "script.h" +static void FakeRtc_CalcTimeDifference(struct Time *result, struct SiiRtcInfo *t1, struct Time *t2); + void FakeRtc_Reset(void) { #if OW_USE_FAKE_RTC @@ -59,6 +61,47 @@ void FakeRtc_AdvanceTimeBy(u32 days, u32 hours, u32 minutes, u32 seconds) ConvertDateTimeToRtc(rtc, &dateTime); } +void FakeRtc_ForwardTimeTo(u32 hour, u32 minute, u32 second) +{ + Script_PauseFakeRtc(); + struct Time diff, target; + struct SiiRtcInfo *fakeRtc = FakeRtc_GetCurrentTime(); + + target.hours = hour; + target.minutes = minute; + target.seconds = second; + + FakeRtc_CalcTimeDifference(&diff, fakeRtc, &target); + FakeRtc_AdvanceTimeBy(0, diff.hours, diff.minutes, diff.seconds); + Script_ResumeFakeRtc(); +} + +static void FakeRtc_CalcTimeDifference(struct Time *result, struct SiiRtcInfo *t1, struct Time *t2) +{ + result->seconds = t2->seconds - t1->second; + result->minutes = t2->minutes - t1->minute; + result->hours = t2->hours - t1->hour; + result->days = t2->days - t1->day; + + if (result->seconds < 0) + { + result->seconds += SECONDS_PER_MINUTE; + --result->minutes; + } + + if (result->minutes < 0) + { + result->minutes += MINUTES_PER_HOUR; + --result->hours; + } + + if (result->hours < 0) + { + result->hours += HOURS_PER_DAY; + --result->days; + } +} + void FakeRtc_ManuallySetTime(u32 day, u32 hour, u32 minute, u32 second) { FakeRtc_Reset(); @@ -67,9 +110,10 @@ void FakeRtc_ManuallySetTime(u32 day, u32 hour, u32 minute, u32 second) u32 FakeRtc_GetSecondsRatio(void) { - return (OW_ALTERED_TIME_RATIO == GEN_8_PLA) ? 60 : - (OW_ALTERED_TIME_RATIO == GEN_9) ? 20 : - 1; + return (OW_ALTERED_TIME_RATIO == GEN_8_PLA) ? 60 : + (OW_ALTERED_TIME_RATIO == GEN_9) ? 20 : + (OW_ALTERED_TIME_RATIO == TIME_DEBUG) ? 1 : + 1; } STATIC_ASSERT((OW_FLAG_PAUSE_TIME == 0 || OW_USE_FAKE_RTC == TRUE), FakeRtcMustBeTrueToPauseTime); diff --git a/src/scrcmd.c b/src/scrcmd.c index f1511c7583..3852632fac 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -901,6 +901,12 @@ bool8 ScrCmd_gettime(struct ScriptContext *ctx) return FALSE; } +bool8 ScrCmd_gettimeofday(struct ScriptContext *ctx) +{ + gSpecialVar_0x8000 = GetTimeOfDay(); + return FALSE; +} + bool8 ScrCmd_setweather(struct ScriptContext *ctx) { u16 weather = VarGet(ScriptReadHalfword(ctx));