From 3966bb2d89a7aa3f8ae28cb3f30ec1dcaae95a64 Mon Sep 17 00:00:00 2001 From: cawtds <38510667+cawtds@users.noreply.github.com> Date: Mon, 10 Nov 2025 17:11:43 +0100 Subject: [PATCH] fix spinda spots --- include/pokemon.h | 2 +- src/decompress.c | 6 ++- src/pokemon.c | 121 +++++++++++++++++++++++++--------------------- 3 files changed, 72 insertions(+), 57 deletions(-) diff --git a/include/pokemon.h b/include/pokemon.h index 44958208d..a30a52218 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -836,7 +836,7 @@ enum KantoDexOrder NationalToKantoDexNum(enum NationalDexOrder natDexNum); enum NationalDexOrder HoennToNationalDexNum(enum HoennDexOrder hoennNum); u16 KantoNumToSpecies(enum KantoDexOrder kantoNum); u16 HoennNumToSpecies(enum HoennDexOrder hoennNum); -void DrawSpindaSpots(u32 species, u32 personality, u8 *dest, bool8 isFrontPic); +void DrawSpindaSpots(u32 personality, u8 *dest, bool32 isSecondFrame); void EvolutionRenameMon(struct Pokemon *mon, u16 oldSpecies, u16 newSpecies); u8 GetPlayerFlankId(void); u16 GetLinkTrainerFlankId(u8 linkPlayerId); diff --git a/src/decompress.c b/src/decompress.c index 5bd728f76..715f04295 100644 --- a/src/decompress.c +++ b/src/decompress.c @@ -1157,7 +1157,11 @@ void LoadSpecialPokePic(void *dest, s32 species, u32 personality, bool8 isFrontP DecompressDataWithHeaderWram(gSpeciesInfo[SPECIES_NONE].backPic, dest); } - DrawSpindaSpots(species, personality, dest, isFrontPic); + if (species == SPECIES_SPINDA && isFrontPic) + { + DrawSpindaSpots(personality, dest, FALSE); + DrawSpindaSpots(personality, dest, TRUE); + } } void Unused_DecompressDataWithHeaderWramIndirect(const void **src, void *dest) diff --git a/src/pokemon.c b/src/pokemon.c index 42a593649..3b6d7f5db 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -5297,63 +5297,74 @@ u16 KantoNumToSpecies(enum KantoDexOrder kantoNum) (destPixels) is an 8 bit pointer, so it addresses two pixels. Shifting by 4 accesses the 2nd of these pixels, so this is done every other time. */ -#define DRAW_SPINDA_SPOTS(personality, dest) \ -{ \ - s32 i; \ - for (i = 0; i < (s32)ARRAY_COUNT(sSpindaSpotGraphics); i++) \ - { \ - s32 row; \ - u8 x = sSpindaSpotGraphics[i].x + ((personality & 0x0F) - 8); \ - u8 y = sSpindaSpotGraphics[i].y + (((personality & 0xF0) >> 4) - 8); \ - \ - for (row = 0; row < SPINDA_SPOT_HEIGHT; row++) \ - { \ - s32 column; \ - s32 spotPixelRow = sSpindaSpotGraphics[i].image[row]; \ - \ - for (column = x; column < x + SPINDA_SPOT_WIDTH; column++) \ - { \ - /* Get target pixels on Spinda's sprite */ \ - u8 *destPixels = dest + ((column / 8) * TILE_SIZE_4BPP) + \ - ((column % 8) / 2) + \ - ((y / 8) * TILE_SIZE_4BPP * 8) + \ - ((y % 8) * 4); \ - \ - /* Is this pixel in the 16x16 spot image part of the spot? */ \ - if (spotPixelRow & 1) \ - { \ - /* destPixels addressess two pixels, alternate which */ \ - /* of the two pixels is being considered for drawing */ \ - if (column & 1) \ - { \ - /* Draw spot pixel if this is Spinda's body color */ \ - if ((u8)((*destPixels & 0xF0) - (FIRST_SPOT_COLOR << 4))\ - <= ((LAST_SPOT_COLOR - FIRST_SPOT_COLOR) << 4))\ - *destPixels += (SPOT_COLOR_ADJUSTMENT << 4); \ - } \ - else \ - { \ - /* Draw spot pixel if this is Spinda's body color */ \ - if ((u8)((*destPixels & 0xF) - FIRST_SPOT_COLOR) \ - <= (LAST_SPOT_COLOR - FIRST_SPOT_COLOR)) \ - *destPixels += SPOT_COLOR_ADJUSTMENT; \ - } \ - } \ - \ - spotPixelRow >>= 1; \ - } \ - \ - y++; \ - } \ - \ - personality >>= 8; \ - } \ -} -void DrawSpindaSpots(u32 species, u32 personality, u8 *dest, bool8 isFrontPic) +// Draw spot pixel if this is Spinda's body color +#define TRY_DRAW_SPOT_PIXEL(pixels, shift) \ + if (((*(pixels) & (0xF << (shift))) >= (FIRST_SPOT_COLOR << (shift))) \ + && ((*(pixels) & (0xF << (shift))) <= (LAST_SPOT_COLOR << (shift)))) \ + { \ + *(pixels) += (SPOT_COLOR_ADJUSTMENT << (shift)); \ + } + + +void DrawSpindaSpots(u32 personality, u8 *dest, bool32 isSecondFrame) { - if (species == SPECIES_SPINDA && isFrontPic) - DRAW_SPINDA_SPOTS(personality, dest); + s32 i; + for (i = 0; i < (s32)ARRAY_COUNT(sSpindaSpotGraphics); i++) + { + s32 row; + u8 x = sSpindaSpotGraphics[i].x + (personality & 0x0F); + u8 y = sSpindaSpotGraphics[i].y + ((personality & 0xF0) >> 4); + + if (isSecondFrame) + { + x -= 12; + y += 56; + } + else + { + x -= 8; + y -= 8; + } + + for (row = 0; row < SPINDA_SPOT_HEIGHT; row++) + { + s32 column; + s32 spotPixelRow = sSpindaSpotGraphics[i].image[row]; + + for (column = x; column < x + SPINDA_SPOT_WIDTH; column++) + { + /* Get target pixels on Spinda's sprite */ + u8 *destPixels = dest + ((column / 8) * TILE_SIZE_4BPP) + + ((column % 8) / 2) + + ((y / 8) * TILE_SIZE_4BPP * 8) + + ((y % 8) * 4); + + /* Is this pixel in the 16x16 spot image part of the spot? */ + if (spotPixelRow & 1) + { + /* destPixels addressess two pixels, alternate which */ + /* of the two pixels is being considered for drawing */ + if (column & 1) + { + /* Draw spot pixel if this is Spinda's body color */ + TRY_DRAW_SPOT_PIXEL(destPixels, 4); + } + else + { + /* Draw spot pixel if this is Spinda's body color */ + TRY_DRAW_SPOT_PIXEL(destPixels, 0); + } + } + + spotPixelRow >>= 1; + } + + y++; + } + + personality >>= 8; + } } void EvolutionRenameMon(struct Pokemon *mon, u16 oldSpecies, u16 newSpecies)