102 lines
2.3 KiB
C
102 lines
2.3 KiB
C
#include "global.h"
|
|
#include "string_util.h"
|
|
#include "strings.h"
|
|
#include "text.h"
|
|
#include "datetime.h"
|
|
#include "rtc.h"
|
|
#include "fake_rtc.h"
|
|
#include "event_data.h"
|
|
#include "script.h"
|
|
|
|
void FakeRtc_Reset(void)
|
|
{
|
|
#if OW_USE_FAKE_RTC
|
|
memset(&gSaveBlock3Ptr->fakeRTC, 0, sizeof(gSaveBlock3Ptr->fakeRTC));
|
|
gSaveBlock3Ptr->fakeRTC.year = 0; // offset by gGen3Epoch.year
|
|
gSaveBlock3Ptr->fakeRTC.month = gGen3Epoch.month;
|
|
gSaveBlock3Ptr->fakeRTC.day = gGen3Epoch.day;
|
|
gSaveBlock3Ptr->fakeRTC.dayOfWeek = gGen3Epoch.dayOfWeek;
|
|
#endif
|
|
}
|
|
|
|
struct SiiRtcInfo *FakeRtc_GetCurrentTime(void)
|
|
{
|
|
#if OW_USE_FAKE_RTC
|
|
return &gSaveBlock3Ptr->fakeRTC;
|
|
#else
|
|
return NULL;
|
|
#endif
|
|
}
|
|
|
|
void FakeRtc_GetRawInfo(struct SiiRtcInfo *rtc)
|
|
{
|
|
struct SiiRtcInfo *fakeRtc = FakeRtc_GetCurrentTime();
|
|
if (fakeRtc != NULL)
|
|
memcpy(rtc, fakeRtc, sizeof(struct SiiRtcInfo));
|
|
}
|
|
|
|
void FakeRtc_TickTimeForward(void)
|
|
{
|
|
if (!OW_USE_FAKE_RTC)
|
|
return;
|
|
|
|
if (FlagGet(OW_FLAG_PAUSE_TIME))
|
|
return;
|
|
|
|
FakeRtc_AdvanceTimeBy(0, 0, 0, FakeRtc_GetSecondsRatio());
|
|
}
|
|
|
|
void FakeRtc_AdvanceTimeBy(u32 days, u32 hours, u32 minutes, u32 seconds)
|
|
{
|
|
struct DateTime dateTime;
|
|
struct SiiRtcInfo *rtc = FakeRtc_GetCurrentTime();
|
|
|
|
ConvertRtcToDateTime(&dateTime, rtc);
|
|
DateTime_AddSeconds(&dateTime, seconds);
|
|
DateTime_AddMinutes(&dateTime, minutes);
|
|
DateTime_AddHours(&dateTime, hours);
|
|
DateTime_AddDays(&dateTime, days);
|
|
ConvertDateTimeToRtc(rtc, &dateTime);
|
|
}
|
|
|
|
void FakeRtc_ManuallySetTime(u32 day, u32 hour, u32 minute, u32 second)
|
|
{
|
|
FakeRtc_Reset();
|
|
FakeRtc_AdvanceTimeBy(day, hour, minute, second);
|
|
}
|
|
|
|
void AdvanceScript(void)
|
|
{
|
|
FakeRtc_AdvanceTimeBy(300, 0, 0, 0);
|
|
}
|
|
|
|
u32 FakeRtc_GetSecondsRatio(void)
|
|
{
|
|
return (OW_ALTERED_TIME_RATIO == GEN_8_PLA) ? 60 :
|
|
(OW_ALTERED_TIME_RATIO == GEN_9) ? 20 :
|
|
1;
|
|
}
|
|
|
|
STATIC_ASSERT((OW_FLAG_PAUSE_TIME == 0 || OW_USE_FAKE_RTC == TRUE), FakeRtcMustBeTrueToPauseTime);
|
|
|
|
void Script_PauseFakeRtc(void)
|
|
{
|
|
Script_RequestEffects(SCREFF_V1 | SCREFF_SAVE);
|
|
|
|
FlagSet(OW_FLAG_PAUSE_TIME);
|
|
}
|
|
|
|
void Script_ResumeFakeRtc(void)
|
|
{
|
|
Script_RequestEffects(SCREFF_V1 | SCREFF_SAVE);
|
|
|
|
FlagClear(OW_FLAG_PAUSE_TIME);
|
|
}
|
|
|
|
void Script_ToggleFakeRtc(void)
|
|
{
|
|
Script_RequestEffects(SCREFF_V1 | SCREFF_SAVE);
|
|
|
|
FlagToggle(OW_FLAG_PAUSE_TIME);
|
|
}
|