Fixed XL Candy going out of bounds. Also added failsafe in case an invalid param is used.

This commit is contained in:
Eduardo Quezada 2022-08-30 22:05:47 -04:00
parent 494e8791d7
commit 29448b6acc

View file

@ -5714,21 +5714,27 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov
&& GetMonData(mon, MON_DATA_LEVEL, NULL) != MAX_LEVEL) && GetMonData(mon, MON_DATA_LEVEL, NULL) != MAX_LEVEL)
{ {
u8 param = ItemId_GetHoldEffectParam(item); u8 param = ItemId_GetHoldEffectParam(item);
dataUnsigned = 0;
if (param == 0) // Rare Candy if (param == 0) // Rare Candy
{ {
dataUnsigned = gExperienceTables[gBaseStats[GetMonData(mon, MON_DATA_SPECIES, NULL)].growthRate][GetMonData(mon, MON_DATA_LEVEL, NULL) + 1]; dataUnsigned = gExperienceTables[gBaseStats[GetMonData(mon, MON_DATA_SPECIES, NULL)].growthRate][GetMonData(mon, MON_DATA_LEVEL, NULL) + 1];
} }
else if (param < ARRAY_COUNT(sExpCandyExperienceTable)) // EXP Candies else if (param - 1 < ARRAY_COUNT(sExpCandyExperienceTable)) // EXP Candies
{ {
u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL); u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL);
dataUnsigned = sExpCandyExperienceTable[param - 1] + GetMonData(mon, MON_DATA_EXP, NULL); dataUnsigned = sExpCandyExperienceTable[param - 1] + GetMonData(mon, MON_DATA_EXP, NULL);
if (dataUnsigned > gExperienceTables[gBaseStats[species].growthRate][MAX_LEVEL]) if (dataUnsigned > gExperienceTables[gBaseStats[species].growthRate][MAX_LEVEL])
dataUnsigned = gExperienceTables[gBaseStats[species].growthRate][MAX_LEVEL]; dataUnsigned = gExperienceTables[gBaseStats[species].growthRate][MAX_LEVEL];
} }
if (dataUnsigned != 0) // Failsafe
{
SetMonData(mon, MON_DATA_EXP, &dataUnsigned); SetMonData(mon, MON_DATA_EXP, &dataUnsigned);
CalculateMonStats(mon); CalculateMonStats(mon);
retVal = FALSE; retVal = FALSE;
} }
}
// Cure status // Cure status
if ((itemEffect[i] & ITEM3_SLEEP) if ((itemEffect[i] & ITEM3_SLEEP)