From aaea5398f41a519f3a04cd5691c63c683ed18fbd Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 14 Jun 2019 12:58:29 +0200 Subject: [PATCH] Fix Castfrom ability pop-up and refactor one function --- data/battle_scripts_1.s | 1 + src/battle_gfx_sfx_util.c | 195 ++++++++++++++------------------------ 2 files changed, 74 insertions(+), 122 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 44ce1fdbf0..50494a1bde 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -6257,6 +6257,7 @@ BattleScript_CastformChange:: end3 BattleScript_82DB4AF:: + copybyte gBattlerAbility, sBATTLER call BattleScript_AbilityPopUp docastformchangeanimation waitstate diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index 9dceb3c56b..339974701d 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -505,16 +505,12 @@ bool8 mplay_80342A4(u8 battlerId) return TRUE; } -void BattleLoadOpponentMonSpriteGfx(struct Pokemon *mon, u8 battlerId) +static void BattleLoadMonSpriteGfx(struct Pokemon *mon, u32 battlerId, bool32 opponent) { - u32 monsPersonality, currentPersonality, otId; - u16 species; - u8 position; - u16 paletteOffset; + u32 monsPersonality, currentPersonality, otId, species, paletteOffset, position; const void *lzPaletteData; monsPersonality = GetMonData(mon, MON_DATA_PERSONALITY); - if (gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies == SPECIES_NONE) { species = GetMonData(mon, MON_DATA_SPECIES); @@ -528,9 +524,27 @@ void BattleLoadOpponentMonSpriteGfx(struct Pokemon *mon, u8 battlerId) otId = GetMonData(mon, MON_DATA_OT_ID); position = GetBattlerPosition(battlerId); - HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], + if (opponent) + { + HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites[position], species, currentPersonality); + } + else + { + if (sub_80688F8(1, battlerId) == 1 || gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies != SPECIES_NONE) + { + HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[species], + gMonSpritesGfxPtr->sprites[position], + species, currentPersonality); + } + else + { + HandleLoadSpecialPokePic(&gMonBackPicTable[species], + gMonSpritesGfxPtr->sprites[position], + species, currentPersonality); + } + } paletteOffset = 0x100 + battlerId * 16; @@ -558,71 +572,14 @@ void BattleLoadOpponentMonSpriteGfx(struct Pokemon *mon, u8 battlerId) } } +void BattleLoadOpponentMonSpriteGfx(struct Pokemon *mon, u8 battlerId) +{ + BattleLoadMonSpriteGfx(mon, battlerId, TRUE); +} + void BattleLoadPlayerMonSpriteGfx(struct Pokemon *mon, u8 battlerId) { - u32 monsPersonality, currentPersonality, otId; - u16 species; - u8 position; - u16 paletteOffset; - const void *lzPaletteData; - - monsPersonality = GetMonData(mon, MON_DATA_PERSONALITY); - - if (gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies == SPECIES_NONE) - { - species = GetMonData(mon, MON_DATA_SPECIES); - currentPersonality = monsPersonality; - } - else - { - species = gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies; - currentPersonality = gTransformedPersonalities[battlerId]; - } - - otId = GetMonData(mon, MON_DATA_OT_ID); - position = GetBattlerPosition(battlerId); - - if (sub_80688F8(1, battlerId) == 1 || gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies != SPECIES_NONE) - { - HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[species], - gMonSpritesGfxPtr->sprites[position], - species, currentPersonality); - } - else - { - HandleLoadSpecialPokePic(&gMonBackPicTable[species], - gMonSpritesGfxPtr->sprites[position], - species, currentPersonality); - } - - paletteOffset = 0x100 + battlerId * 16; - - if (gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies == SPECIES_NONE) - lzPaletteData = GetMonFrontSpritePal(mon); - else - lzPaletteData = GetFrontSpritePalFromSpeciesAndPersonality(species, otId, monsPersonality); - - LZDecompressWram(lzPaletteData, gDecompressionBuffer); - LoadPalette(gDecompressionBuffer, paletteOffset, 0x20); - LoadPalette(gDecompressionBuffer, 0x80 + battlerId * 16, 0x20); - - if (species == SPECIES_CASTFORM) - { - paletteOffset = 0x100 + battlerId * 16; - LZDecompressWram(lzPaletteData, gBattleStruct->castformPalette[0]); - LoadPalette(gBattleStruct->castformPalette[gBattleMonForms[battlerId]], paletteOffset, 0x20); - } - - // transform's pink color - if (gBattleSpritesDataPtr->battlerData[battlerId].transformSpecies != SPECIES_NONE) - { - BlendPalette(paletteOffset, 16, 6, RGB_WHITE); - CpuCopy32(gPlttBufferFaded + paletteOffset, gPlttBufferUnfaded + paletteOffset, 32); - } -} - -void nullsub_23(void) -{ + BattleLoadMonSpriteGfx(mon, battlerId, FALSE); } void nullsub_24(u16 species) @@ -849,11 +806,52 @@ void CopyBattleSpriteInvisibility(u8 battlerId) void HandleSpeciesGfxDataChange(u8 battlerAtk, u8 battlerDef, bool8 notTransform, bool32 megaEvo) { - u16 paletteOffset; - u32 personalityValue; - u32 otId; - u8 position; - const u32 *lzPaletteData; + u32 personalityValue, otId, position, paletteOffset, targetSpecies; + const void *lzPaletteData, *src; + void *dst; + + if (IsContest()) + { + position = 0; + targetSpecies = gContestResources->field_18->unk2; + personalityValue = gContestResources->field_18->unk8; + otId = gContestResources->field_18->unkC; + + HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[targetSpecies], + gMonSpritesGfxPtr->sprites[0], + targetSpecies, + gContestResources->field_18->unk10); + } + else + { + position = GetBattlerPosition(battlerAtk); + + if (GetBattlerSide(battlerDef) == B_SIDE_OPPONENT) + targetSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerDef]], MON_DATA_SPECIES); + else + targetSpecies = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerDef]], MON_DATA_SPECIES); + + if (GetBattlerSide(battlerAtk) == B_SIDE_PLAYER) + { + personalityValue = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerAtk]], MON_DATA_PERSONALITY); + otId = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerAtk]], MON_DATA_OT_ID); + + HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[targetSpecies], + gMonSpritesGfxPtr->sprites[position], + targetSpecies, + gTransformedPersonalities[battlerAtk]); + } + else + { + personalityValue = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerAtk]], MON_DATA_PERSONALITY); + otId = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerAtk]], MON_DATA_OT_ID); + + HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[targetSpecies], + gMonSpritesGfxPtr->sprites[position], + targetSpecies, + gTransformedPersonalities[battlerAtk]); + } + } if (notTransform) { @@ -870,53 +868,6 @@ void HandleSpeciesGfxDataChange(u8 battlerAtk, u8 battlerDef, bool8 notTransform } else { - const void *src; - void *dst; - u16 targetSpecies; - - if (IsContest()) - { - position = 0; - targetSpecies = gContestResources->field_18->unk2; - personalityValue = gContestResources->field_18->unk8; - otId = gContestResources->field_18->unkC; - - HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[targetSpecies], - gMonSpritesGfxPtr->sprites[0], - targetSpecies, - gContestResources->field_18->unk10); - } - else - { - position = GetBattlerPosition(battlerAtk); - - if (GetBattlerSide(battlerDef) == B_SIDE_OPPONENT) - targetSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerDef]], MON_DATA_SPECIES); - else - targetSpecies = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerDef]], MON_DATA_SPECIES); - - if (GetBattlerSide(battlerAtk) == B_SIDE_PLAYER) - { - personalityValue = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerAtk]], MON_DATA_PERSONALITY); - otId = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerAtk]], MON_DATA_OT_ID); - - HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[targetSpecies], - gMonSpritesGfxPtr->sprites[position], - targetSpecies, - gTransformedPersonalities[battlerAtk]); - } - else - { - personalityValue = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerAtk]], MON_DATA_PERSONALITY); - otId = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerAtk]], MON_DATA_OT_ID); - - HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[targetSpecies], - gMonSpritesGfxPtr->sprites[position], - targetSpecies, - gTransformedPersonalities[battlerAtk]); - } - } - src = gMonSpritesGfxPtr->sprites[position]; dst = (void *)(VRAM + 0x10000 + gSprites[gBattlerSpriteIds[battlerAtk]].oam.tileNum * 32); DmaCopy32(3, src, dst, 0x800);