diff --git a/include/battle_message.h b/include/battle_message.h index d34d2125a2f6..d62c260049d0 100644 --- a/include/battle_message.h +++ b/include/battle_message.h @@ -1,7 +1,11 @@ #ifndef GUARD_BATTLE_MESSAGE_H #define GUARD_BATTLE_MESSAGE_H -#define TEXT_BUFF_ARRAY_COUNT 16 +// This buffer can hold many different things. Some of the things it can hold +// that have explicit sizes are listed below to ensure it can contain them. +#define TEXT_BUFF_ARRAY_COUNT max(16, \ + max(MOVE_NAME_LENGTH + 2, /* +2 to hold the "!" and EOS. */ \ + POKEMON_NAME_LENGTH + 1)) // for 0xFD #define B_TXT_BUFF1 0x0 diff --git a/include/constants/global.h b/include/constants/global.h index 04f1d548c458..199acfe6c609 100644 --- a/include/constants/global.h +++ b/include/constants/global.h @@ -92,6 +92,7 @@ // string lengths #define ITEM_NAME_LENGTH 14 #define POKEMON_NAME_LENGTH 10 +#define POKEMON_NAME_BUFFER_SIZE max(20, POKEMON_NAME_LENGTH + 1) // Frequently used buffer size. Larger than necessary #define PLAYER_NAME_LENGTH 7 #define MAIL_WORDS_COUNT 9 #define EASY_CHAT_BATTLE_WORDS_COUNT 6 diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index 0f1ce1b17f29..2104298775a5 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -556,7 +556,7 @@ static u32 CopyLinkOpponentMonData(u8 monId, u8 *dst) { struct BattlePokemon battleMon; struct MovePpInfo moveData; - u8 nickname[20]; + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; u8 *src; s16 data16; u32 data32; diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index 3b2e0142538c..054563ad3a8e 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -450,7 +450,7 @@ static u32 CopyLinkPartnerMonData(u8 monId, u8 *dst) { struct BattlePokemon battleMon; struct MovePpInfo moveData; - u8 nickname[20]; + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; u8 *src; s16 data16; u32 data32; diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 8246a6f80f8b..12402f91ea20 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -561,7 +561,7 @@ static u32 GetOpponentMonData(u8 monId, u8 *dst) { struct BattlePokemon battleMon; struct MovePpInfo moveData; - u8 nickname[20]; + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; u8 *src; s16 data16; u32 data32; diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 3d0531325ef1..cdc5fe8429c5 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -1608,7 +1608,7 @@ static u32 CopyPlayerMonData(u8 monId, u8 *dst) { struct BattlePokemon battleMon; struct MovePpInfo moveData; - u8 nickname[20]; + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; u8 *src; s16 data16; u32 data32; diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index 5b08a2c529b5..6127e2d655de 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -634,7 +634,7 @@ static u32 CopyPlayerPartnerMonData(u8 monId, u8 *dst) { struct BattlePokemon battleMon; struct MovePpInfo moveData; - u8 nickname[20]; + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; u8 *src; s16 data16; u32 data32; diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index 872a61c0e76f..b2db595f8aa9 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -542,7 +542,7 @@ static u32 CopyRecordedOpponentMonData(u8 monId, u8 *dst) { struct BattlePokemon battleMon; struct MovePpInfo moveData; - u8 nickname[20]; + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; u8 *src; s16 data16; u32 data32; diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index d23aaa8b04f3..591ddb67e306 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -525,7 +525,7 @@ static u32 CopyRecordedPlayerMonData(u8 monId, u8 *dst) { struct BattlePokemon battleMon; struct MovePpInfo moveData; - u8 nickname[20]; + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; u8 *src; s16 data16; u32 data32; diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index ca81677f20e1..5b94f2dd2641 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -452,7 +452,7 @@ static u32 CopyWallyMonData(u8 monId, u8 *dst) { struct BattlePokemon battleMon; struct MovePpInfo moveData; - u8 nickname[20]; + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; u8 *src; s16 data16; u32 data32; diff --git a/src/battle_message.c b/src/battle_message.c index b02e9e445c51..f005404ead57 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -1323,7 +1323,8 @@ const u8 gText_Draw[] = _("{HIGHLIGHT TRANSPARENT}Draw"); static const u8 sText_SpaceIs[] = _(" is"); static const u8 sText_ApostropheS[] = _("'s"); -// For displaying names of invalid moves +// For displaying names of invalid moves. +// This is large enough that the text for TYPE_ELECTRIC will exceed TEXT_BUFF_ARRAY_COUNT. static const u8 sATypeMove_Table[NUMBER_OF_MON_TYPES][17] = { [TYPE_NORMAL] = _("a NORMAL move"), @@ -1472,7 +1473,7 @@ static const u16 sGrammarMoveUsedTable[] = MOVE_COVET, 0 }; -static const u8 sDummyWeirdStatusString[] = {EOS, EOS, EOS, EOS, EOS, EOS, EOS, EOS, 0, 0}; +static const u8 sText_EmptyStatus[] = _("$$$$$$$"); static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = { @@ -2259,10 +2260,10 @@ static const u8 *TryGetStatusString(u8 *src) u32 chars1, chars2; u8 *statusPtr; - memcpy(status, sDummyWeirdStatusString, 8); + memcpy(status, sText_EmptyStatus, min(ARRAY_COUNT(status), ARRAY_COUNT(sText_EmptyStatus))); statusPtr = status; - for (i = 0; i < 8; i++) + for (i = 0; i < ARRAY_COUNT(status); i++) { if (*src == EOS) break; // one line required to match -g *statusPtr = *src; @@ -2304,11 +2305,16 @@ static const u8 *TryGetStatusString(u8 *src) StringGet_Nickname(text); \ toCpy = text; +// Ensure the defined length for an item name can contain the full defined length of a berry name. +// This ensures that custom Enigma Berry names will fit in the text buffer at the top of BattleStringExpandPlaceholders. +STATIC_ASSERT(BERRY_NAME_LENGTH + ARRAY_COUNT(sText_BerrySuffix) <= ITEM_NAME_LENGTH, BerryNameTooLong); + u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst) { u32 dstID = 0; // if they used dstID, why not use srcID as well? const u8 *toCpy = NULL; - u8 text[30]; + // This buffer may hold either the name of a trainer, pokemon, or item. + u8 text[max(max(max(32, TRAINER_NAME_LENGTH + 1), POKEMON_NAME_LENGTH + 1), ITEM_NAME_LENGTH)]; u8 multiplayerId; s32 i; @@ -2753,7 +2759,7 @@ static void ExpandBattleTextBuffPlaceholders(const u8 *src, u8 *dst) { u32 srcID = 1; u32 value = 0; - u8 text[12]; + u8 nickname[POKEMON_NAME_LENGTH + 1]; u16 hword; *dst = EOS; @@ -2793,7 +2799,7 @@ static void ExpandBattleTextBuffPlaceholders(const u8 *src, u8 *dst) case B_BUFF_MON_NICK_WITH_PREFIX: // poke nick with prefix if (GetBattlerSide(src[srcID + 1]) == B_SIDE_PLAYER) { - GetMonData(&gPlayerParty[src[srcID + 2]], MON_DATA_NICKNAME, text); + GetMonData(&gPlayerParty[src[srcID + 2]], MON_DATA_NICKNAME, nickname); } else { @@ -2802,10 +2808,10 @@ static void ExpandBattleTextBuffPlaceholders(const u8 *src, u8 *dst) else StringAppend(dst, sText_WildPkmnPrefix); - GetMonData(&gEnemyParty[src[srcID + 2]], MON_DATA_NICKNAME, text); + GetMonData(&gEnemyParty[src[srcID + 2]], MON_DATA_NICKNAME, nickname); } - StringGet_Nickname(text); - StringAppend(dst, text); + StringGet_Nickname(nickname); + StringAppend(dst, nickname); srcID += 3; break; case B_BUFF_STAT: // stats diff --git a/src/contest.c b/src/contest.c index 741a0e12db9d..151e87af4996 100644 --- a/src/contest.c +++ b/src/contest.c @@ -2775,7 +2775,7 @@ static bool8 IsPlayerLinkLeader(void) void CreateContestMonFromParty(u8 partyIndex) { - u8 name[20]; + u8 name[max(PLAYER_NAME_LENGTH + 1, POKEMON_NAME_BUFFER_SIZE)]; u16 heldItem; s16 cool; s16 beauty; @@ -2785,10 +2785,8 @@ void CreateContestMonFromParty(u8 partyIndex) StringCopy(name, gSaveBlock2Ptr->playerName); if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK) - { StripPlayerNameForLinkContest(name); - } - memcpy(gContestMons[gContestPlayerMonIndex].trainerName, name, 8); + memcpy(gContestMons[gContestPlayerMonIndex].trainerName, name, PLAYER_NAME_LENGTH + 1); if (gSaveBlock2Ptr->playerGender == MALE) gContestMons[gContestPlayerMonIndex].trainerGfxId = OBJ_EVENT_GFX_LINK_BRENDAN; else @@ -6020,8 +6018,10 @@ static u8 GetMonNicknameLanguage(u8 *nickname) if (nickname[0] == EXT_CTRL_CODE_BEGIN && nickname[1] == EXT_CTRL_CODE_JPN) return GAME_LANGUAGE; - if (StringLength(nickname) < PLAYER_NAME_LENGTH - 1) + if (StringLength(nickname) <= 5) { + // Name is short enough that it might be Japanese. + // Make sure all the character values are valid latin name characters. while (*nickname != EOS) { if ((*nickname >= CHAR_A && *nickname <= CHAR_z) @@ -6039,12 +6039,18 @@ static u8 GetMonNicknameLanguage(u8 *nickname) || *nickname == CHAR_DBL_QUOTE_LEFT || *nickname == CHAR_DBL_QUOTE_RIGHT || *nickname == CHAR_SGL_QUOTE_LEFT - || *nickname == CHAR_DBL_QUOTE_LEFT) // Most likely a typo, CHAR_SGL_QUOTE_RIGHT should be here instead. +#ifdef BUGFIX + || *nickname == CHAR_SGL_QUOTE_RIGHT +#else + || *nickname == CHAR_DBL_QUOTE_LEFT // Most likely a typo, CHAR_SGL_QUOTE_RIGHT should be here instead. +#endif + ) { nickname++; } else { + // Invalid latin name character, assume the name was Japanese. ret = LANGUAGE_JAPANESE; break; } @@ -6101,7 +6107,7 @@ void StripPlayerAndMonNamesForLinkContest(struct ContestPokemon *mon, s32 langua name = mon->trainerName; if (language == LANGUAGE_JAPANESE) { - name[PLAYER_NAME_LENGTH] = EOS; + name[7] = EOS; name[6] = name[4]; name[5] = name[3]; name[4] = name[2]; diff --git a/src/daycare.c b/src/daycare.c index 59bd7b723388..48f642baa47b 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -93,16 +93,14 @@ static const u8 sJapaneseEggNickname[] = _("タマゴ"); // "tamago" ("egg" in J u8 *GetMonNickname2(struct Pokemon *mon, u8 *dest) { - u8 nickname[POKEMON_NAME_LENGTH * 2]; - + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; GetMonData(mon, MON_DATA_NICKNAME, nickname); return StringCopy_Nickname(dest, nickname); } u8 *GetBoxMonNickname(struct BoxPokemon *mon, u8 *dest) { - u8 nickname[POKEMON_NAME_LENGTH * 2]; - + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; GetBoxMonData(mon, MON_DATA_NICKNAME, nickname); return StringCopy_Nickname(dest, nickname); } @@ -946,12 +944,12 @@ static bool8 IsEggPending(struct DayCare *daycare) // gStringVar3 = first mon trainer's name static void _GetDaycareMonNicknames(struct DayCare *daycare) { - u8 text[12]; + u8 otName[max(12, PLAYER_NAME_LENGTH + 1)]; if (GetBoxMonData(&daycare->mons[0].mon, MON_DATA_SPECIES) != 0) { GetBoxMonNickname(&daycare->mons[0].mon, gStringVar1); - GetBoxMonData(&daycare->mons[0].mon, MON_DATA_OT_NAME, text); - StringCopy(gStringVar3, text); + GetBoxMonData(&daycare->mons[0].mon, MON_DATA_OT_NAME, otName); + StringCopy(gStringVar3, otName); } if (GetBoxMonData(&daycare->mons[1].mon, MON_DATA_SPECIES) != 0) @@ -1146,7 +1144,7 @@ static u8 *AppendMonGenderSymbol(u8 *name, struct BoxPokemon *boxMon) static void GetDaycareLevelMenuText(struct DayCare *daycare, u8 *dest) { - u8 monNames[DAYCARE_MON_COUNT][20]; + u8 monNames[DAYCARE_MON_COUNT][POKEMON_NAME_BUFFER_SIZE]; u8 i; *dest = EOS; @@ -1204,8 +1202,7 @@ static void DaycareAddTextPrinter(u8 windowId, const u8 *text, u32 x, u32 y) static void DaycarePrintMonNickname(struct DayCare *daycare, u8 windowId, u32 daycareSlotId, u32 y) { - u8 nickname[POKEMON_NAME_LENGTH * 2]; - + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; GetBoxMonNickname(&daycare->mons[daycareSlotId].mon, nickname); AppendMonGenderSymbol(nickname, &daycare->mons[daycareSlotId].mon); DaycareAddTextPrinter(windowId, nickname, 8, y); diff --git a/src/egg_hatch.c b/src/egg_hatch.c index 96d431a22682..e9d287cf7210 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -399,7 +399,7 @@ void ScriptHatchMon(void) static bool8 _CheckDaycareMonReceivedMail(struct DayCare *daycare, u8 daycareId) { - u8 nickname[32]; + u8 nickname[max(32, POKEMON_NAME_BUFFER_SIZE)]; struct DaycareMon *daycareMon = &daycare->mons[daycareId]; GetBoxMonNickname(&daycareMon->mon, nickname); diff --git a/src/evolution_scene.c b/src/evolution_scene.c index 3b92a0c4354c..dc198626164c 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -208,7 +208,7 @@ void BeginEvolutionScene(struct Pokemon *mon, u16 postEvoSpecies, bool8 canStopE void EvolutionScene(struct Pokemon *mon, u16 postEvoSpecies, bool8 canStopEvo, u8 partyId) { - u8 name[20]; + u8 name[POKEMON_NAME_BUFFER_SIZE]; u16 currSpecies; u32 trainerId, personality; const struct CompressedSpritePalette* pokePal; @@ -467,7 +467,7 @@ static void CB2_TradeEvolutionSceneLoadGraphics(void) void TradeEvolutionScene(struct Pokemon *mon, u16 postEvoSpecies, u8 preEvoSpriteId, u8 partyId) { - u8 name[20]; + u8 name[POKEMON_NAME_BUFFER_SIZE]; u16 currSpecies; u32 trainerId, personality; const struct CompressedSpritePalette* pokePal; @@ -775,8 +775,7 @@ static void Task_EvolutionScene(u8 taskId) var = MonTryLearningNewMove(mon, gTasks[taskId].tLearnsFirstMove); if (var != MOVE_NONE && !gTasks[taskId].tEvoWasStopped) { - u8 text[20]; - + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; if (!(gTasks[taskId].tBits & TASK_BIT_LEARN_MOVE)) { StopMapMusic(); @@ -786,8 +785,8 @@ static void Task_EvolutionScene(u8 taskId) gTasks[taskId].tBits |= TASK_BIT_LEARN_MOVE; gTasks[taskId].tLearnsFirstMove = FALSE; gTasks[taskId].tLearnMoveState = MVSTATE_INTRO_MSG_1; - GetMonData(mon, MON_DATA_NICKNAME, text); - StringCopy_Nickname(gBattleTextBuff1, text); + GetMonData(mon, MON_DATA_NICKNAME, nickname); + StringCopy_Nickname(gBattleTextBuff1, nickname); if (var == MON_HAS_MAX_MOVES) gTasks[taskId].tState = EVOSTATE_REPLACE_MOVE; @@ -1195,13 +1194,12 @@ static void Task_TradeEvolutionScene(u8 taskId) var = MonTryLearningNewMove(mon, gTasks[taskId].tLearnsFirstMove); if (var != MOVE_NONE && !gTasks[taskId].tEvoWasStopped) { - u8 text[20]; - + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; gTasks[taskId].tBits |= TASK_BIT_LEARN_MOVE; gTasks[taskId].tLearnsFirstMove = FALSE; gTasks[taskId].tLearnMoveState = 0; - GetMonData(mon, MON_DATA_NICKNAME, text); - StringCopy_Nickname(gBattleTextBuff1, text); + GetMonData(mon, MON_DATA_NICKNAME, nickname); + StringCopy_Nickname(gBattleTextBuff1, nickname); if (var == MON_HAS_MAX_MOVES) gTasks[taskId].tState = T_EVOSTATE_REPLACE_MOVE; diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index 2e79a1f6b65d..63c7c30c26be 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -44,7 +44,7 @@ struct HallofFameMon u32 personality; u16 species:9; u16 lvl:7; - u8 nick[POKEMON_NAME_LENGTH]; + u8 nickname[POKEMON_NAME_LENGTH]; }; struct HallofFameTeam @@ -338,7 +338,7 @@ static const struct HallofFameMon sDummyFameMon = .personality = 0, .species = SPECIES_NONE, .lvl = 0, - .nick = {0} + .nickname = {0} }; // Unused, order of party slots on Hall of Fame screen @@ -442,18 +442,16 @@ static void Task_Hof_InitMonData(u8 taskId) for (i = 0; i < PARTY_SIZE; i++) { - u8 nick[POKEMON_NAME_LENGTH + 2]; + u8 nickname[POKEMON_NAME_LENGTH + 1]; if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES)) { sHofMonPtr->mon[i].species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES_OR_EGG); sHofMonPtr->mon[i].tid = GetMonData(&gPlayerParty[i], MON_DATA_OT_ID); sHofMonPtr->mon[i].personality = GetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY); sHofMonPtr->mon[i].lvl = GetMonData(&gPlayerParty[i], MON_DATA_LEVEL); - GetMonData(&gPlayerParty[i], MON_DATA_NICKNAME, nick); + GetMonData(&gPlayerParty[i], MON_DATA_NICKNAME, nickname); for (j = 0; j < POKEMON_NAME_LENGTH; j++) - { - sHofMonPtr->mon[i].nick[j] = nick[j]; - } + sHofMonPtr->mon[i].nickname[j] = nickname[j]; gTasks[taskId].tMonNumber++; } else @@ -462,7 +460,7 @@ static void Task_Hof_InitMonData(u8 taskId) sHofMonPtr->mon[i].tid = 0; sHofMonPtr->mon[i].personality = 0; sHofMonPtr->mon[i].lvl = 0; - sHofMonPtr->mon[i].nick[0] = EOS; + sHofMonPtr->mon[i].nickname[0] = EOS; } } @@ -1115,7 +1113,7 @@ static void HallOfFame_PrintWelcomeText(u8 unusedPossiblyWindowId, u8 unused2) static void HallOfFame_PrintMonInfo(struct HallofFameMon* currMon, u8 unused1, u8 unused2) { - u8 text[30]; + u8 text[max(32, POKEMON_NAME_LENGTH + 1)]; u8 *stringPtr; s32 dexNumber; s32 width; @@ -1148,8 +1146,8 @@ static void HallOfFame_PrintMonInfo(struct HallofFameMon* currMon, u8 unused1, u AddTextPrinterParameterized3(0, FONT_NORMAL, 0x10, 1, sMonInfoTextColors, TEXT_SKIP_DRAW, text); } - // nick, species names, gender and level - memcpy(text, currMon->nick, POKEMON_NAME_LENGTH); + // nickname, species names, gender and level + memcpy(text, currMon->nickname, POKEMON_NAME_LENGTH); text[POKEMON_NAME_LENGTH] = EOS; if (currMon->species == SPECIES_EGG) { diff --git a/src/menu_specialized.c b/src/menu_specialized.c index 8f25c3188f52..15fdafbeb238 100644 --- a/src/menu_specialized.c +++ b/src/menu_specialized.c @@ -918,7 +918,7 @@ static u8 *GetConditionMenuMonString(u8 *dst, u16 boxId, u16 monId) *(dst++) = TEXT_COLOR_TRANSPARENT; *(dst++) = TEXT_COLOR_LIGHT_BLUE; if (GetBoxOrPartyMonData(box, mon, MON_DATA_IS_EGG, NULL)) - return StringCopyPadded(dst, gText_EggNickname, 0, 12); + return StringCopyPadded(dst, gText_EggNickname, 0, POKEMON_NAME_LENGTH + 2); GetBoxOrPartyMonData(box, mon, MON_DATA_NICKNAME, dst); StringGet_Nickname(dst); species = GetBoxOrPartyMonData(box, mon, MON_DATA_SPECIES, NULL); @@ -1020,7 +1020,7 @@ void GetConditionMenuMonNameAndLocString(u8 *locationDst, u8 *nameDst, u16 boxId locationDst[3] = TEXT_COLOR_TRANSPARENT; locationDst[4] = TEXT_COLOR_LIGHT_BLUE; if (box == TOTAL_BOXES_COUNT) // Party mon. - BufferConditionMenuSpacedStringN(&locationDst[5], gText_InParty, 8); + BufferConditionMenuSpacedStringN(&locationDst[5], gText_InParty, BOX_NAME_LENGTH); else BufferConditionMenuSpacedStringN(&locationDst[5], GetBoxNamePtr(box), BOX_NAME_LENGTH); } @@ -1029,7 +1029,7 @@ void GetConditionMenuMonNameAndLocString(u8 *locationDst, u8 *nameDst, u16 boxId for (i = 0; i < POKEMON_NAME_LENGTH + 2; i++) nameDst[i] = CHAR_SPACE; nameDst[i] = EOS; - for (i = 0; i < 8; i++) + for (i = 0; i < BOX_NAME_LENGTH; i++) locationDst[i] = CHAR_SPACE; locationDst[i] = EOS; } diff --git a/src/pokemon.c b/src/pokemon.c index d8b45081f7fe..7bc9f3bee317 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -2406,7 +2406,7 @@ void CreateMonWithEVSpread(struct Pokemon *mon, u16 species, u8 level, u8 fixedI void CreateBattleTowerMon(struct Pokemon *mon, struct BattleTowerPokemon *src) { s32 i; - u8 nickname[30]; + u8 nickname[max(32, POKEMON_NAME_BUFFER_SIZE)]; u8 language; u8 value; @@ -2460,7 +2460,7 @@ void CreateBattleTowerMon(struct Pokemon *mon, struct BattleTowerPokemon *src) void CreateBattleTowerMon_HandleLevel(struct Pokemon *mon, struct BattleTowerPokemon *src, bool8 lvl50) { s32 i; - u8 nickname[30]; + u8 nickname[max(32, POKEMON_NAME_BUFFER_SIZE)]; u8 level; u8 language; u8 value; @@ -4629,7 +4629,7 @@ void CopyPlayerPartyMonToBattleData(u8 battlerId, u8 partyIndex) { u16 *hpSwitchout; s32 i; - u8 nickname[POKEMON_NAME_LENGTH * 2]; + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; gBattleMons[battlerId].species = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES, NULL); gBattleMons[battlerId].item = GetMonData(&gPlayerParty[partyIndex], MON_DATA_HELD_ITEM, NULL); diff --git a/src/pokenav_conditions.c b/src/pokenav_conditions.c index 05f86cab2f7e..1ebf6edbe9a2 100644 --- a/src/pokenav_conditions.c +++ b/src/pokenav_conditions.c @@ -348,7 +348,7 @@ static u8 *CopyConditionMonNameGender(u8 *str, u16 listId, bool8 skipPadding) *(str++) = TEXT_COLOR_LIGHT_BLUE; if (GetBoxOrPartyMonData(boxId, monId, MON_DATA_IS_EGG, NULL)) - return StringCopyPadded(str, gText_EggNickname, CHAR_SPACE, 12); + return StringCopyPadded(str, gText_EggNickname, CHAR_SPACE, POKEMON_NAME_LENGTH + 2); GetBoxOrPartyMonData(boxId, monId, MON_DATA_NICKNAME, str); StringGet_Nickname(str); @@ -445,7 +445,7 @@ static void CopyMonNameGenderLocation(s16 listId, u8 loadId) } else { - for (i = 0; i < 12; i++) + for (i = 0; i < POKEMON_NAME_LENGTH + 2; i++) menu->nameText[loadId][i] = CHAR_SPACE; menu->nameText[loadId][i] = EOS; diff --git a/src/trade.c b/src/trade.c index 971f0d966e60..28e8f89d1c5b 100644 --- a/src/trade.c +++ b/src/trade.c @@ -1864,7 +1864,7 @@ static void SetSelectedMon(u8 cursorPosition) static void DrawSelectedMonScreen(u8 whichParty) { s8 nameStringWidth; - u8 nickname[20]; + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; u8 movesString[56]; u8 i; u8 partyIdx; @@ -1950,7 +1950,7 @@ static void DrawSelectedMonScreen(u8 whichParty) static u8 GetMonNicknameWidth(u8 *str, u8 whichParty, u8 partyIdx) { - u8 nickname[POKEMON_NAME_LENGTH]; + u8 nickname[POKEMON_NAME_LENGTH + 1]; if (whichParty == TRADE_PLAYER) GetMonData(&gPlayerParty[partyIdx], MON_DATA_NICKNAME, nickname); @@ -2006,8 +2006,8 @@ static void PrintPartyMonNickname(u8 whichParty, u8 windowId, u8 *nickname) static void PrintPartyNicknames(u8 whichParty) { u8 i; - u8 nickname[20]; - u8 str[32]; + u8 nickname[POKEMON_NAME_BUFFER_SIZE]; + u8 str[max(32, POKEMON_NAME_BUFFER_SIZE)]; struct Pokemon *party = (whichParty == TRADE_PLAYER) ? gPlayerParty : gEnemyParty; for (i = 0; i < sTradeMenu->partyCounts[whichParty]; i++) @@ -2023,7 +2023,7 @@ static void PrintLevelAndGender(u8 whichParty, u8 monIdx, u8 x, u8 y, u8 width, u8 level; u32 symbolTile; u8 gender; - u8 nickname[POKEMON_NAME_LENGTH]; + u8 nickname[POKEMON_NAME_LENGTH + 1]; CopyToBgTilemapBufferRect_ChangePalette(1, gTradeMenuMonBox_Tilemap, width, height, 6, 3, 0); CopyBgTilemapBufferToVram(1); @@ -3330,7 +3330,7 @@ static void LoadTradeSequenceSpriteSheetsAndPalettes(void) static void BufferTradeSceneStrings(void) { u8 mpId; - u8 name[20]; + u8 name[POKEMON_NAME_BUFFER_SIZE]; const struct InGameTrade *ingameTrade; if (sTradeAnim->isLinkTrade) @@ -4539,7 +4539,7 @@ u16 GetInGameTradeSpeciesInfo(void) static void BufferInGameTradeMonName(void) { - u8 nickname[32]; + u8 nickname[max(32, POKEMON_NAME_BUFFER_SIZE)]; const struct InGameTrade *inGameTrade = &sIngameTrades[gSpecialVar_0x8004]; GetMonData(&gPlayerParty[gSpecialVar_0x8005], MON_DATA_NICKNAME, nickname); StringCopy_Nickname(gStringVar1, nickname);