Fixed XL Candy going out of bounds. Also added failsafe in case an invalid param is used.
This commit is contained in:
parent
494e8791d7
commit
29448b6acc
1 changed files with 10 additions and 4 deletions
|
@ -5714,20 +5714,26 @@ 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];
|
||||||
}
|
}
|
||||||
SetMonData(mon, MON_DATA_EXP, &dataUnsigned);
|
|
||||||
CalculateMonStats(mon);
|
if (dataUnsigned != 0) // Failsafe
|
||||||
retVal = FALSE;
|
{
|
||||||
|
SetMonData(mon, MON_DATA_EXP, &dataUnsigned);
|
||||||
|
CalculateMonStats(mon);
|
||||||
|
retVal = FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cure status
|
// Cure status
|
||||||
|
|
Loading…
Reference in a new issue