Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fix for possible crash when decompressing trainer back pics #2074

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/battle_gfx_sfx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,17 @@ void DecompressTrainerFrontPic(u16 frontPicId, u8 battlerId)
void DecompressTrainerBackPic(u16 backPicId, u8 battlerId)
{
u8 position = GetBattlerPosition(battlerId);
#ifdef BUGFIX
CpuCopy32(gTrainerBackPicTable[backPicId].data, gMonSpritesGfxPtr->sprites.ptr[position], gTrainerBackPicTable[backPicId].size);
#else
// Trainer back pics aren't compressed!
// Attempting to decompress the uncompressed data can softlock or crash the game.
// This is ok in vanilla by chance, because the pixels in the trainer back sprites that correspond
// to the compressed data's header are all 0, so the decompression does nothing.
DecompressPicFromTable_2(&gTrainerBackPicTable[backPicId],
gMonSpritesGfxPtr->sprites.ptr[position],
SPECIES_NONE);
#endif
LoadCompressedPalette(gTrainerBackPicPaletteTable[backPicId].data,
OBJ_PLTT_ID(battlerId), PLTT_SIZE_4BPP);
}
Expand Down
20 changes: 17 additions & 3 deletions src/trainer_pokemon_sprites.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ bool16 ResetAllPicSprites(void)
return FALSE;
}

static bool16 DecompressPic(u16 species, u32 personality, bool8 isFrontPic, u8 *dest, bool8 isTrainer, bool8 ignoreDeoxys)
static bool16 DecompressPic(u16 picId, u32 personality, bool8 isFrontPic, u8 *dest, bool8 isTrainer, bool8 ignoreDeoxys)
{
if (!isTrainer)
{
u16 species = picId;
if (isFrontPic)
{
if (!ignoreDeoxys)
Expand All @@ -78,10 +79,23 @@ static bool16 DecompressPic(u16 species, u32 personality, bool8 isFrontPic, u8 *
}
else
{
u16 trainerPicId = picId;
if (isFrontPic)
DecompressPicFromTable(&gTrainerFrontPicTable[species], dest, species);
{
DecompressPicFromTable(&gTrainerFrontPicTable[trainerPicId], dest, trainerPicId);
}
else
DecompressPicFromTable(&gTrainerBackPicTable[species], dest, species);
{
#ifdef BUGFIX
CpuCopy32(gTrainerBackPicTable[trainerPicId].data, dest, gTrainerBackPicTable[trainerPicId].size);
#else
// Trainer back pics aren't compressed!
// Attempting to decompress the uncompressed data can softlock or crash the game.
// This is ok in vanilla by chance, because the pixels in the trainer back sprites that correspond
// to the compressed data's header are all 0, so the decompression does nothing.
DecompressPicFromTable(&gTrainerBackPicTable[trainerPicId], dest, trainerPicId);
#endif
}
}
return FALSE;
}
Expand Down
Loading