Document src/event_data.c

This commit is contained in:
cbt6
2022-11-07 14:52:23 +08:00
parent 965f3cc1f6
commit dea9552563
6 changed files with 118 additions and 99 deletions
+44 -33
View File
@@ -5,6 +5,14 @@
static bool8 IsFlagOrVarStoredInQuestLog(u16 idx, u8 a1);
#define NUM_SPECIAL_FLAGS (SPECIAL_FLAGS_END - SPECIAL_FLAGS_START + 1)
#define NUM_TEMP_FLAGS (TEMP_FLAGS_END - TEMP_FLAGS_START + 1)
#define NUM_TEMP_VARS (TEMP_VARS_END - TEMP_VARS_START + 1)
#define SPECIAL_FLAGS_SIZE (NUM_SPECIAL_FLAGS / 8) // 8 flags per byte
#define TEMP_FLAGS_SIZE (NUM_TEMP_FLAGS / 8)
#define TEMP_VARS_SIZE (NUM_TEMP_VARS * 2) // 1/2 var per byte
EWRAM_DATA u16 gSpecialVar_0x8000 = 0;
EWRAM_DATA u16 gSpecialVar_0x8001 = 0;
EWRAM_DATA u16 gSpecialVar_0x8002 = 0;
@@ -25,7 +33,7 @@ EWRAM_DATA u16 gSpecialVar_MonBoxPos = 0;
EWRAM_DATA u16 gSpecialVar_TextColor = 0;
EWRAM_DATA u16 gSpecialVar_PrevTextColor = 0;
EWRAM_DATA u16 gSpecialVar_0x8014 = 0;
EWRAM_DATA u8 sSpecialFlags[SPECIAL_FLAGS_COUNT] = {};
EWRAM_DATA u8 sSpecialFlags[SPECIAL_FLAGS_SIZE] = {};
u16 gLastQuestLogStoredFlagOrVarIdx;
@@ -33,15 +41,15 @@ extern u16 *const gSpecialVars[];
void InitEventData(void)
{
memset(gSaveBlock1Ptr->flags, 0, NUM_FLAG_BYTES);
memset(gSaveBlock1Ptr->vars, 0, VARS_COUNT * 2);
memset(sSpecialFlags, 0, SPECIAL_FLAGS_COUNT);
memset(gSaveBlock1Ptr->flags, 0, sizeof(gSaveBlock1Ptr->flags));
memset(gSaveBlock1Ptr->vars, 0, sizeof(gSaveBlock1Ptr->vars));
memset(sSpecialFlags, 0, sizeof(sSpecialFlags));
}
void ClearTempFieldEventData(void)
{
memset(gSaveBlock1Ptr->flags, 0, 4);
memset(gSaveBlock1Ptr->vars, 0, 16 * 2);
memset(gSaveBlock1Ptr->flags + (TEMP_FLAGS_START / 8), 0, TEMP_FLAGS_SIZE);
memset(gSaveBlock1Ptr->vars + ((TEMP_VARS_START - VARS_START) * 2), 0, TEMP_VARS_SIZE);
FlagClear(FLAG_SYS_WHITE_FLUTE_ACTIVE);
FlagClear(FLAG_SYS_BLACK_FLUTE_ACTIVE);
FlagClear(FLAG_SYS_USE_STRENGTH);
@@ -49,37 +57,41 @@ void ClearTempFieldEventData(void)
FlagClear(FLAG_SYS_INFORMED_OF_LOCAL_WIRELESS_PLAYER);
}
void sub_806E168(void) // Unused
// Unused
static void DisableNationalPokedex_RSE(void)
{
u16 *ptr = GetVarPointer(VAR_0x403C);
gSaveBlock2Ptr->pokedex.nationalMagic = 0;
gSaveBlock2Ptr->pokedex.unused = 0;
*ptr = 0;
FlagClear(FLAG_0x838);
}
void sub_806E190(void)
// The magic numbers used here (0xDA and 0x0302) correspond to those
// used in RSE for enabling the national Pokedex
void EnableNationalPokedex_RSE(void)
{
// Note: the var, struct member, and flag are never used
u16 *ptr = GetVarPointer(VAR_0x403C);
gSaveBlock2Ptr->pokedex.nationalMagic = 0xDA;
gSaveBlock2Ptr->pokedex.unused = 0xDA;
*ptr = 0x0302;
FlagSet(FLAG_0x838);
}
bool32 sub_806E1C0(void) // Unused
// Unused
static bool32 IsNationalPokedexEnabled_RSE(void)
{
if (gSaveBlock2Ptr->pokedex.nationalMagic != 0xDA)
return FALSE;
if (VarGet(VAR_0x403C) != 0x0302)
return FALSE;
if (!FlagGet(FLAG_0x838))
return FALSE;
return TRUE;
if (gSaveBlock2Ptr->pokedex.unused == 0xDA
&& VarGet(VAR_0x403C) == 0x0302
&& FlagGet(FLAG_0x838))
return TRUE;
return FALSE;
}
void DisableNationalPokedex(void)
{
u16 *nationalDexVar = GetVarPointer(VAR_NATIONAL_DEX);
gSaveBlock2Ptr->pokedex.unknown2 = 0;
gSaveBlock2Ptr->pokedex.nationalMagic = 0;
*nationalDexVar = 0;
FlagClear(FLAG_SYS_NATIONAL_DEX);
}
@@ -87,20 +99,19 @@ void DisableNationalPokedex(void)
void EnableNationalPokedex(void)
{
u16 *nationalDexVar = GetVarPointer(VAR_NATIONAL_DEX);
gSaveBlock2Ptr->pokedex.unknown2 = 0xB9;
gSaveBlock2Ptr->pokedex.nationalMagic = 0xB9;
*nationalDexVar = 0x6258;
FlagSet(FLAG_SYS_NATIONAL_DEX);
}
bool32 IsNationalPokedexEnabled(void)
{
if (gSaveBlock2Ptr->pokedex.unknown2 != 0xB9)
return FALSE;
if (VarGet(VAR_NATIONAL_DEX) != 0x6258)
return FALSE;
if (!FlagGet(FLAG_SYS_NATIONAL_DEX))
return FALSE;
return TRUE;
if (gSaveBlock2Ptr->pokedex.nationalMagic == 0xB9
&& VarGet(VAR_NATIONAL_DEX) == 0x6258
&& FlagGet(FLAG_SYS_NATIONAL_DEX))
return TRUE;
return FALSE;
}
void DisableMysteryGift(void)
@@ -153,21 +164,21 @@ void ResetMysteryEventVars(void)
void DisableResetRTC(void)
{
VarSet(VAR_0x4032, 0);
FlagClear(FLAG_0x837);
VarSet(VAR_RESET_RTC_ENABLE, 0);
FlagClear(FLAG_SYS_RESET_RTC_ENABLE);
}
void EnableResetRTC(void)
{
VarSet(VAR_0x4032, 0x0920);
FlagSet(FLAG_0x837);
VarSet(VAR_RESET_RTC_ENABLE, 0x0920);
FlagSet(FLAG_SYS_RESET_RTC_ENABLE);
}
bool32 CanResetRTC(void)
{
if (!FlagGet(FLAG_0x837))
if (!FlagGet(FLAG_SYS_RESET_RTC_ENABLE))
return FALSE;
if (VarGet(VAR_0x4032) != 0x0920)
if (VarGet(VAR_RESET_RTC_ENABLE) != 0x0920)
return FALSE;
return TRUE;
}
+1 -1
View File
@@ -130,7 +130,7 @@ void NewGameInitData(void)
ClearPlayerLinkBattleRecords();
InitHeracrossSizeRecord();
InitMagikarpSizeRecord();
sub_806E190();
EnableNationalPokedex_RSE();
gPlayerPartyCount = 0;
ZeroPlayerPartyMons();
ResetPokemonStorageSystem();