Automatically update nickname buffer sizes

This commit is contained in:
GriffinR
2023-08-08 15:27:52 -04:00
parent da238562f0
commit 65fee186f8
20 changed files with 83 additions and 73 deletions
+16 -10
View File
@@ -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 + 1 + 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