From bf1649821ec87eb1e13edc8939f07a7a33b443be Mon Sep 17 00:00:00 2001 From: Martin Griffin Date: Wed, 17 Jun 2026 21:17:08 +0100 Subject: [PATCH] Always call Get(Box)MonData3 in UBFIX builds --- include/pokemon.h | 15 +++++++++++---- src/pokemon.c | 20 ++++++++++++-------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/include/pokemon.h b/include/pokemon.h index 3d75157f91f4..e42848733ed9 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -436,17 +436,24 @@ void SetMultiuseSpriteTemplateToPokemon(u16 speciesTag, u8 battlerPosition); void SetMultiuseSpriteTemplateToTrainerBack(u16 trainerPicId, u8 battlerPosition); void SetMultiuseSpriteTemplateToTrainerFront(u16 trainerPicId, u8 battlerPosition); +#define GetMonData(...) CAT(GetMonData, NARG_8(__VA_ARGS__))(__VA_ARGS__) +#define GetBoxMonData(...) CAT(GetBoxMonData, NARG_8(__VA_ARGS__))(__VA_ARGS__) +u32 GetMonData3(struct Pokemon *mon, s32 field, u8 *data); +u32 GetBoxMonData3(struct BoxPokemon *boxMon, s32 field, u8 *data); + +#ifndef UBFIX /* GameFreak called Get(Box)MonData with either 2 or 3 arguments, for * type safety we have a Get(Box)MonData macro which dispatches to * either Get(Box)MonData2 or Get(Box)MonData3 based on the number of * arguments. The two functions are aliases of each other, but they * differ for matching purposes in the caller's codegen. */ -#define GetMonData(...) CAT(GetMonData, NARG_8(__VA_ARGS__))(__VA_ARGS__) -#define GetBoxMonData(...) CAT(GetBoxMonData, NARG_8(__VA_ARGS__))(__VA_ARGS__) -u32 GetMonData3(struct Pokemon *mon, s32 field, u8 *data); u32 GetMonData2(struct Pokemon *mon, s32 field); -u32 GetBoxMonData3(struct BoxPokemon *boxMon, s32 field, u8 *data); u32 GetBoxMonData2(struct BoxPokemon *boxMon, s32 field); +#else +/* Just call Get(Box)MonData3 with an explicit NULL. */ +#define GetMonData2(mon, field) GetMonData3(mon, field, NULL) +#define GetBoxMonData2(boxMon, field) GetBoxMonData3(boxMon, field, NULL) +#endif void SetMonData(struct Pokemon *mon, s32 field, const void *dataArg); void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg); diff --git a/src/pokemon.c b/src/pokemon.c index 9245fc012c68..44b3cbd641b2 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -3635,10 +3635,6 @@ static union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 perso return substruct; } -/* GameFreak called GetMonData with either 2 or 3 arguments, for type - * safety we have a GetMonData macro (in include/pokemon.h) which - * dispatches to either GetMonData2 or GetMonData3 based on the number - * of arguments. */ u32 GetMonData3(struct Pokemon *mon, s32 field, u8 *data) { u32 ret; @@ -3707,12 +3703,14 @@ u32 GetMonData3(struct Pokemon *mon, s32 field, u8 *data) return ret; } +#ifndef UBFIX +/* GameFreak called GetMonData with either 2 or 3 arguments, for type + * safety we have a GetMonData macro (in include/pokemon.h) which + * dispatches to either GetMonData2 or GetMonData3 based on the number + * of arguments. In UBFIX builds, GetMonData3 is always called. */ u32 GetMonData2(struct Pokemon *mon, s32 field) __attribute__((alias("GetMonData3"))); +#endif -/* GameFreak called GetBoxMonData with either 2 or 3 arguments, for type - * safety we have a GetBoxMonData macro (in include/pokemon.h) which - * dispatches to either GetBoxMonData2 or GetBoxMonData3 based on the - * number of arguments. */ u32 GetBoxMonData3(struct BoxPokemon *boxMon, s32 field, u8 *data) { s32 i; @@ -4069,7 +4067,13 @@ u32 GetBoxMonData3(struct BoxPokemon *boxMon, s32 field, u8 *data) return retVal; } +#ifndef UBFIX +/* GameFreak called GetBoxMonData with either 2 or 3 arguments, for type + * safety we have a GetBoxMonData macro (in include/pokemon.h) which + * dispatches to either GetBoxMonData2 or GetBoxMonData3 based on the + * number of arguments. In UBFIX builds, GetBoxMonData3 is always called. */ u32 GetBoxMonData2(struct BoxPokemon *boxMon, s32 field) __attribute__((alias("GetBoxMonData3"))); +#endif #define SET8(lhs) (lhs) = *data #define SET16(lhs) (lhs) = data[0] + (data[1] << 8)