From f2c127eb57bb6909ada95c7dbb423203cc0a75f6 Mon Sep 17 00:00:00 2001 From: cawtds <38510667+cawtds@users.noreply.github.com> Date: Sun, 22 Mar 2026 22:17:39 +0100 Subject: [PATCH] cleanup --- include/apprentice.h | 2 +- include/global.h | 4 +- include/string_util.h | 6 ++- include/strings.h | 2 +- src/apprentice.c | 2 +- src/daycare.c | 6 +-- src/naming_screen.c | 2 +- src/string_util.c | 94 ++++++++++++++++++++++--------------------- src/strings.c | 5 +-- 9 files changed, 63 insertions(+), 60 deletions(-) diff --git a/include/apprentice.h b/include/apprentice.h index f14b6f37b..75a773bde 100644 --- a/include/apprentice.h +++ b/include/apprentice.h @@ -20,6 +20,6 @@ void Apprentice_ScriptContext_Enable(void); void ResetApprenticeStruct(struct Apprentice *apprentice); void ResetAllApprenticeData(void); void CallApprenticeFunction(void); -const u8 *GetApprenticeNameInLanguage(u32 apprenticeId, u8 language); +const u8 *GetApprenticeNameInLanguage(u32 apprenticeId, enum Language language); #endif // GUARD_APPRENTICE_H diff --git a/include/global.h b/include/global.h index efbb806e6..3f2e65573 100644 --- a/include/global.h +++ b/include/global.h @@ -33,8 +33,8 @@ // IDE support #if defined(__APPLE__) || defined(__CYGWIN__) || defined(__INTELLISENSE__) // We define these when using certain IDEs to fool preproc -#define _(x) {x} -#define __(x) {x} +#define _(x) {0} +#define __(x) {0} #define INCBIN(...) {0} #define INCBIN_U8 INCBIN #define INCBIN_U16 INCBIN diff --git a/include/string_util.h b/include/string_util.h index 770390063..75951a222 100644 --- a/include/string_util.h +++ b/include/string_util.h @@ -1,6 +1,8 @@ #ifndef GUARD_STRING_UTIL_H #define GUARD_STRING_UTIL_H +#include "constants/global.h" + enum StringConvertMode { STR_CONV_MODE_LEFT_ALIGN, @@ -40,11 +42,11 @@ u8 *StringCopyPadded(u8 *dest, const u8 *src, u8 c, u16 n); u8 *StringFillWithTerminator(u8 *dest, u16 n); u8 *StringCopyN_Multibyte(u8 *dest, const u8 *src, u32 n); u32 StringLength_Multibyte(const u8 *str); -u8 *WriteColorChangeControlCode(u8 *dest, u32 colorType, u8 color); +u8 *WriteColorChangeControlCode(u8 *dest, enum TextColorType colorType, u8 color); bool32 IsStringJapanese(u8 *str); u8 GetExtCtrlCodeLength(u8 code); s32 StringCompareWithoutExtCtrlCodes(const u8 *str1, const u8 *str2); -void ConvertInternationalString(u8 *s, u8 language); +void ConvertInternationalString(u8 *s, enum Language language); void StripExtCtrlCodes(u8 *str); bool32 DoesStringProperlyTerminate(const u8 *str, u32 last); diff --git a/include/strings.h b/include/strings.h index 12daefe06..edcb63b6b 100644 --- a/include/strings.h +++ b/include/strings.h @@ -928,7 +928,7 @@ extern const u8 gDaycareText_GetAlongVeryWell[]; extern const u8 gDaycareText_GetAlong[]; extern const u8 gDaycareText_DontLikeOther[]; extern const u8 gDaycareText_PlayOther[]; -extern const u8 gExpandedPlaceholder_Empty[]; +extern const u8 gText_EmptyString[]; extern const u8 gText_HatchedFromEgg[]; extern const u8 gText_NickHatchPrompt[]; diff --git a/src/apprentice.c b/src/apprentice.c index e3963a7da..3822f44ea 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -1237,7 +1237,7 @@ static void GetShouldApprenticeLeave(void) gSpecialVar_0x8004 = TRUE; } -const u8 *GetApprenticeNameInLanguage(u32 apprenticeId, u8 language) +const u8 *GetApprenticeNameInLanguage(u32 apprenticeId, enum Language language) { const struct ApprenticeTrainer *apprentice = &gApprentices[apprenticeId]; diff --git a/src/daycare.c b/src/daycare.c index 89b6a9c62..650721a18 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -106,8 +106,8 @@ static const struct WindowTemplate sDaycareLevelMenuWindowTemplate = static const struct ListMenuItem sLevelMenuItems[] = { - {gExpandedPlaceholder_Empty, 0}, - {gExpandedPlaceholder_Empty, 1}, + {gText_EmptyString, 0}, + {gText_EmptyString, 1}, {gOtherText_Exit, DAYCARE_LEVEL_MENU_EXIT} }; @@ -1354,7 +1354,7 @@ void CreateEgg(struct Pokemon *mon, u16 species, bool8 setHotSpringsLocation) { u8 metLevel; enum PokeBall ball; - u8 language; + enum Language language; u8 metLocation; u8 isEgg; diff --git a/src/naming_screen.c b/src/naming_screen.c index 575e68feb..f9d5209a3 100644 --- a/src/naming_screen.c +++ b/src/naming_screen.c @@ -1917,7 +1917,7 @@ static void DrawTextEntry(void) for (i = 0; i < maxChars; i++) { temp[0] = sNamingScreen->textBuffer[i]; - temp[1] = gExpandedPlaceholder_Empty[0]; + temp[1] = gText_EmptyString[0]; extraWidth = (IsWideLetter(temp[0]) == TRUE) ? 2 : 0; AddTextPrinterParameterized(sNamingScreen->windows[WIN_TEXT_ENTRY], FONT_NORMAL, temp, i * 8 + xpos + extraWidth, 1, TEXT_SKIP_DRAW, NULL); diff --git a/src/string_util.c b/src/string_util.c index e0fd40662..51576f3f8 100644 --- a/src/string_util.c +++ b/src/string_util.c @@ -26,9 +26,6 @@ static const s32 sPowersOfTen[] = 1000000000, }; -extern const u8 gExpandedPlaceholder_Empty[]; -extern u8 gExpandedPlaceholder_Kun[]; -extern u8 gExpandedPlaceholder_Chan[]; extern u8 gExpandedPlaceholder_Sapphire[]; extern u8 gExpandedPlaceholder_Ruby[]; extern u8 gExpandedPlaceholder_Aqua[]; @@ -380,40 +377,37 @@ u8 *StringBraille(u8 *dest, const u8 *src) } } -static u8 *ExpandPlaceholder_UnknownStringVar(void) +static const u8 *ExpandPlaceholder_UnknownStringVar(void) { return gUnknownStringVar; } -static u8 *ExpandPlaceholder_PlayerName(void) +static const u8 *ExpandPlaceholder_PlayerName(void) { return gSaveBlock2Ptr->playerName; } -static u8 *ExpandPlaceholder_StringVar1(void) +static const u8 *ExpandPlaceholder_StringVar1(void) { return gStringVar1; } -static u8 *ExpandPlaceholder_StringVar2(void) +static const u8 *ExpandPlaceholder_StringVar2(void) { return gStringVar2; } -static u8 *ExpandPlaceholder_StringVar3(void) +static const u8 *ExpandPlaceholder_StringVar3(void) { return gStringVar3; } -static u8 *ExpandPlaceholder_KunChan(void) +static const u8 *ExpandPlaceholder_KunChan(void) { - if (gSaveBlock2Ptr->playerGender == MALE) - return gExpandedPlaceholder_Kun; - else - return gExpandedPlaceholder_Chan; + return gText_EmptyString; } -static u8 *ExpandPlaceholder_RivalName(void) +static const u8 *ExpandPlaceholder_RivalName(void) { if (gSaveBlock1Ptr->rivalName[0] == EOS) { @@ -428,7 +422,7 @@ static u8 *ExpandPlaceholder_RivalName(void) } } -static u8 *ExpandPlaceholder_Version(void) +static const u8 *ExpandPlaceholder_Version(void) { #if defined(FIRERED) return gExpandedPlaceholder_Ruby; @@ -437,7 +431,7 @@ static u8 *ExpandPlaceholder_Version(void) #endif } -static u8 *ExpandPlaceholder_Magma(void) +static const u8 *ExpandPlaceholder_Magma(void) { #if defined(FIRERED) return gExpandedPlaceholder_Magma; @@ -446,7 +440,7 @@ static u8 *ExpandPlaceholder_Magma(void) #endif } -static u8 *ExpandPlaceholder_Aqua(void) +static const u8 *ExpandPlaceholder_Aqua(void) { #if defined(FIRERED) return gExpandedPlaceholder_Aqua; @@ -455,7 +449,7 @@ static u8 *ExpandPlaceholder_Aqua(void) #endif } -static u8 *ExpandPlaceholder_Maxie(void) +static const u8 *ExpandPlaceholder_Maxie(void) { #if defined(FIRERED) return gExpandedPlaceholder_Maxie; @@ -464,7 +458,7 @@ static u8 *ExpandPlaceholder_Maxie(void) #endif } -static u8 *ExpandPlaceholder_Archie(void) +static const u8 *ExpandPlaceholder_Archie(void) { #if defined(FIRERED) return gExpandedPlaceholder_Archie; @@ -473,7 +467,7 @@ static u8 *ExpandPlaceholder_Archie(void) #endif } -static u8 *ExpandPlaceholder_Groudon(void) +static const u8 *ExpandPlaceholder_Groudon(void) { #if defined(FIRERED) return gExpandedPlaceholder_Groudon; @@ -482,7 +476,7 @@ static u8 *ExpandPlaceholder_Groudon(void) #endif } -static u8 *ExpandPlaceholder_Kyogre(void) +static const u8 *ExpandPlaceholder_Kyogre(void) { #if defined(FIRERED) return gExpandedPlaceholder_Kyogre; @@ -493,7 +487,7 @@ static u8 *ExpandPlaceholder_Kyogre(void) const u8 *GetExpandedPlaceholder(u32 id) { - typedef u8 *(*ExpandPlaceholderFunc)(void); + typedef const u8 *(*ExpandPlaceholderFunc)(void); static const ExpandPlaceholderFunc funcs[] = { @@ -514,7 +508,7 @@ const u8 *GetExpandedPlaceholder(u32 id) }; if (id >= ARRAY_COUNT(funcs)) - return gExpandedPlaceholder_Empty; + return gText_EmptyString; else return funcs[id](); } @@ -570,7 +564,7 @@ u8 *StringCopyN_Multibyte(u8 *dest, const u8 *src, u32 n) else { *dest++ = *src++; - if (*(src - 1) == 0xF9) + if (*(src - 1) == CHAR_EXTRA_SYMBOL) *dest++ = *src++; } } @@ -585,7 +579,7 @@ u32 StringLength_Multibyte(const u8 *str) while (*str != EOS) { - if (*str == 0xF9) + if (*str == CHAR_EXTRA_SYMBOL) str++; str++; length++; @@ -594,23 +588,31 @@ u32 StringLength_Multibyte(const u8 *str) return length; } -u8 *WriteColorChangeControlCode(u8 *dest, u32 colorType, u8 color) +u8 *WriteColorChangeControlCode(u8 *dest, enum TextColorType colorType, u8 color) { - *dest = 0xFC; + *dest = EXT_CTRL_CODE_BEGIN; dest++; switch (colorType) { - case 0: - *dest = 1; + case TEXT_COLOR_TYPE_FOREGROUND: + *dest = EXT_CTRL_CODE_COLOR; dest++; break; - case 1: - *dest = 3; + case TEXT_COLOR_TYPE_SHADOW: + *dest = EXT_CTRL_CODE_SHADOW; dest++; break; - case 2: - *dest = 2; + case TEXT_COLOR_TYPE_HIGHLIGHT: + *dest = EXT_CTRL_CODE_HIGHLIGHT; + dest++; + break; + case TEXT_COLOR_TYPE_ACCENT: + *dest = EXT_CTRL_CODE_ACCENT; + dest++; + break; + case TEXT_COLOR_TYPE_BACKGROUND: + *dest = EXT_CTRL_CODE_BACKGROUND; dest++; break; } @@ -676,7 +678,7 @@ u8 GetExtCtrlCodeLength(u8 code) static const u8 *SkipExtCtrlCode(const u8 *s) { - while (*s == 0xFC) + while (*s == EXT_CTRL_CODE_BEGIN) { s++; s += GetExtCtrlCodeLength(*s); @@ -700,11 +702,11 @@ s32 StringCompareWithoutExtCtrlCodes(const u8 *str1, const u8 *str2) if (*str1 < *str2) { retVal = -1; - if (*str2 == 0xFF) + if (*str2 == EOS) retVal = 1; } - if (*str1 == 0xFF) + if (*str1 == EOS) return retVal; str1++; @@ -713,13 +715,13 @@ s32 StringCompareWithoutExtCtrlCodes(const u8 *str1, const u8 *str2) retVal = 1; - if (*str1 == 0xFF) + if (*str1 == EOS) retVal = -1; return retVal; } -void ConvertInternationalString(u8 *s, u8 language) +void ConvertInternationalString(u8 *s, enum Language language) { if (language == LANGUAGE_JAPANESE) { @@ -727,9 +729,9 @@ void ConvertInternationalString(u8 *s, u8 language) StripExtCtrlCodes(s); i = StringLength(s); - s[i++] = 0xFC; - s[i++] = 22; - s[i++] = 0xFF; + s[i++] = EXT_CTRL_CODE_BEGIN; + s[i++] = EXT_CTRL_CODE_ENG; + s[i++] = EOS; i--; @@ -739,8 +741,8 @@ void ConvertInternationalString(u8 *s, u8 language) i--; } - s[0] = 0xFC; - s[1] = 21; + s[0] = EXT_CTRL_CODE_BEGIN; + s[1] = EXT_CTRL_CODE_JPN; } } @@ -748,9 +750,9 @@ void StripExtCtrlCodes(u8 *str) { u16 srcIndex = 0; u16 destIndex = 0; - while (str[srcIndex] != 0xFF) + while (str[srcIndex] != EOS) { - if (str[srcIndex] == 0xFC) + if (str[srcIndex] == EXT_CTRL_CODE_BEGIN) { srcIndex++; srcIndex += GetExtCtrlCodeLength(str[srcIndex]); @@ -760,7 +762,7 @@ void StripExtCtrlCodes(u8 *str) str[destIndex++] = str[srcIndex++]; } } - str[destIndex] = 0xFF; + str[destIndex] = EOS; } bool32 DoesStringProperlyTerminate(const u8 *str, u32 last) diff --git a/src/strings.c b/src/strings.c index bc5dc6500..7765c6b6d 100644 --- a/src/strings.c +++ b/src/strings.c @@ -3,9 +3,8 @@ #include "strings.h" #include "constants/item.h" -const u8 gExpandedPlaceholder_Empty[] = _(""); -const u8 gExpandedPlaceholder_Kun[] = _(""); -const u8 gExpandedPlaceholder_Chan[] = _(""); +const u8 gText_EmptyString[] = _(""); + const u8 gExpandedPlaceholder_Sapphire[] = _("SAPPHIRE"); const u8 gExpandedPlaceholder_Ruby[] = _("RUBY"); const u8 gExpandedPlaceholder_Aqua[] = _("AQUA");