From c9cebdb00411ebc10b2f6c4637d0e4765400da2f Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 10 Jun 2025 14:10:32 +0200 Subject: [PATCH] split text util --- data/data_81076E4.s | 75 ----------------------- include/pokemon_abilities.h | 7 +++ include/pokemon_types.h | 9 +++ include/rescue_team_info.h | 1 - include/strings.h | 2 +- include/text_util.h | 12 +--- ld_script.ld | 8 ++- src/code_801602C.c | 4 +- src/code_801EE10.c | 4 +- src/code_809447C.c | 4 +- src/dungeon_damage.c | 2 +- src/dungeon_misc.c | 4 +- src/dungeon_move_util.c | 2 +- src/friend_list.c | 4 +- src/friend_rescue.c | 2 +- src/ground_lives.c | 2 +- src/ground_script.c | 4 +- src/items.c | 2 +- src/load_screen.c | 6 +- src/menu_input.c | 4 +- src/move_orb_actions_3.c | 2 +- src/moves.c | 2 +- src/naming_screen.c | 4 +- src/party_list_menu.c | 2 +- src/pokemon.c | 9 ++- src/pokemon_abilities.c | 15 +++++ src/pokemon_mail.c | 4 +- src/pokemon_summary_window.c | 3 +- src/pokemon_types.c | 26 ++++++++ src/rescue_team_info.c | 21 +++++-- src/strings.c | 2 +- src/text_util.c | 115 ++++++++++++++--------------------- src/thank_you_wonder_mail.c | 4 +- 33 files changed, 167 insertions(+), 200 deletions(-) create mode 100644 include/pokemon_abilities.h create mode 100644 include/pokemon_types.h create mode 100644 src/pokemon_abilities.c create mode 100644 src/pokemon_types.c diff --git a/data/data_81076E4.s b/data/data_81076E4.s index a6ebf274d..c01399c98 100644 --- a/data/data_81076E4.s +++ b/data/data_81076E4.s @@ -2,82 +2,7 @@ -@ START rescue_team_info.c -.string "pksdir0\0" -.global gRescueRankMaxPoints -gRescueRankMaxPoints: @ 8109810 -.4byte 50 -.4byte 500 -.4byte 1500 -.4byte 3000 -.4byte 7500 -.4byte 15000 -.4byte 100000000 - -.global gTeamNamePlaceholder -gTeamNamePlaceholder: @ 810982C -.string "Pokémon\0" -@ END rescue_team_info.c -@ text_util -.string "pksdir0\0" - -.global gUnknown_810983C -gUnknown_810983C: @ 810983C -.4byte gUnknown_8109888 -.4byte gUnknown_8109884 -.4byte gUnknown_8109880 -.4byte gUnknown_810987C -.4byte gUnknown_8109878 -.4byte gUnknown_8109874 -.4byte gUnknown_8109870 -.4byte gUnknown_810986C -.4byte gUnknown_8109868 -.4byte gUnknown_8109864 - -.global gUnknown_8109864 -gUnknown_8109864: @ 8109864 -.byte 0x82, 0x58, 0x00, 0x00 - -.global gUnknown_8109868 -gUnknown_8109868: @ 8109868 -.byte 0x82, 0x57, 0x00, 0x00 - -.global gUnknown_810986C -gUnknown_810986C: @ 810986C -.byte 0x82, 0x56, 0x00, 0x00 - -.global gUnknown_8109870 -gUnknown_8109870: @ 8109870 -.byte 0x82, 0x55, 0x00, 0x00 - -.global gUnknown_8109874 -gUnknown_8109874: @ 8109874 -.byte 0x82, 0x54, 0x00, 0x00 - -.global gUnknown_8109878 -gUnknown_8109878: @ 8109878 -.byte 0x82, 0x53, 0x00, 0x00 - -.global gUnknown_810987C -gUnknown_810987C: @ 810987C -.byte 0x82, 0x52, 0x00, 0x00 - -.global gUnknown_8109880 -gUnknown_8109880: @ 8109880 -.byte 0x82, 0x51, 0x00, 0x00 - -.global gUnknown_8109884 -gUnknown_8109884: @ 8109884 -.byte 0x82, 0x50, 0x00, 0x00 - -.global gUnknown_8109888 -gUnknown_8109888: @ 8109888 -.byte 0x82, 0x4f, 0x00, 0x00 -@ ??? -.string "pksdir0\0" -@ ??? -.string "pksdir0\0" @ START friend_area.c .string "pksdir0\0" diff --git a/include/pokemon_abilities.h b/include/pokemon_abilities.h new file mode 100644 index 000000000..414f96b4c --- /dev/null +++ b/include/pokemon_abilities.h @@ -0,0 +1,7 @@ +#ifndef GUARD_POKEMON_ABILITIES_H +#define GUARD_POKEMON_ABILITIES_H + +void CopyAbilityNametoBuffer(char *buffer, u8 index); +const u8 *GetAbilityDescription(u8 index); + +#endif // GUARD_POKEMON_ABILITIES_H diff --git a/include/pokemon_types.h b/include/pokemon_types.h new file mode 100644 index 000000000..0eef3acf8 --- /dev/null +++ b/include/pokemon_types.h @@ -0,0 +1,9 @@ +#ifndef GUARD_POKEMON_TYPES_H +#define GUARD_POKEMON_TYPES_H + +const char *GetUnformattedTypeString(u8 type); +const char * GetFormattedTypeString(u8 type); +u8 IsTypePhysical(u8 index); +u8 GetBestResistingType(u8 index); + +#endif // GUARD_POKEMON_TYPES_H diff --git a/include/rescue_team_info.h b/include/rescue_team_info.h index 31f4ab6e2..0117b8e21 100644 --- a/include/rescue_team_info.h +++ b/include/rescue_team_info.h @@ -30,7 +30,6 @@ void sub_80920D8(u8 *buffer); void SetRescueTeamName(u8 *buffer); s32 GetTeamRankPts(void); s32 GetPtsToNextRank(void); -void SetTeamRankPoints(s32 newPts); void AddToTeamRankPts(s32 newPts); u8 GetRescueTeamRank(void); const u8 *GetTeamRankString(u32 index); diff --git a/include/strings.h b/include/strings.h index a818f5c0b..daa4843a0 100644 --- a/include/strings.h +++ b/include/strings.h @@ -29,7 +29,7 @@ extern const u8 *const gUnknown_810AF50[20]; extern const u8 *const gAdventureLogText[32]; extern const u8 *const gRescueTeamRanks[MAX_TEAM_RANKS]; extern const u8 *const gAbilityNames[NUM_ABILITIES]; -extern const u8 *const AbilityDescriptions[NUM_ABILITIES]; +extern const u8 *const gAbilityDescriptions[NUM_ABILITIES]; extern const u8 *const gRangeNames[49]; extern const u8 *const gUnknown_810CF00; extern const u8 *const gTextType; diff --git a/include/text_util.h b/include/text_util.h index 9706cb891..9cb4119f8 100644 --- a/include/text_util.h +++ b/include/text_util.h @@ -1,16 +1,10 @@ #ifndef GUARD_TEXT_UTIL_H #define GUARD_TEXT_UTIL_H -void sub_80922B4(u8 *buffer, const u8 *string, s32 size); -u32 sub_80922E4(u32 r0); +void StrncpyCustom(u8 *buffer, const u8 *string, s32 n); // Regular strncpy, but it calls GetCharId for each char void CopyStringtoBuffer(u8 *buffer, const u8 *string); void BoundedCopyStringtoBuffer(u8 *buffer, u8 *string, s32 size); -const char *GetUnformattedTypeString(u8 type); -const char * GetFormattedTypeString(u8 type); -u8 IsTypePhysical(u8 index); -u8 sub_8092364(u8 index); -void CopyAbilityNametoBuffer(char *buffer, u8 index); -const u8 *GetAbilityDescription(u8 index); -u32 ReturnIntFromChar2(u8); +s32 ReturnIntFromChar(u8 c); +u32 GetCharId(u8); #endif diff --git a/ld_script.ld b/ld_script.ld index 31d090569..ba3717ace 100755 --- a/ld_script.ld +++ b/ld_script.ld @@ -312,6 +312,8 @@ SECTIONS { src/items.o(.text); src/rescue_team_info.o(.text); src/text_util.o(.text); + src/pokemon_types.o(.text); + src/pokemon_abilities.o(.text); src/friend_area.o(.text); src/moves.o(.text); src/number_util.o(.text); @@ -678,6 +680,10 @@ SECTIONS { src/pokemon_summary_window.o(.rodata); src/dungeon_info.o(.rodata); src/items.o(.rodata); + src/rescue_team_info.o(.rodata); + src/text_util.o(.rodata); + src/pokemon_types.o(.rodata); + src/pokemon_abilities.o(.rodata); data/data_81076E4.o(.rodata); src/game_options.o(.rodata); src/random_mersenne_twister.o(.rodata); @@ -689,9 +695,7 @@ SECTIONS { data/data_8109D10.o(.rodata); src/dungeon_data.o(.rodata); src/exclusive_pokemon.o(.rodata); - src/rescue_team_info.o(.rodata); src/strings.o(.rodata); - src/text_util.o(.rodata); data/data_810AE24_2.o(.rodata); src/position_util.o(.rodata); data/data_8115EB8.o(.rodata); diff --git a/src/code_801602C.c b/src/code_801602C.c index 27f8c43f3..e7a339f22 100644 --- a/src/code_801602C.c +++ b/src/code_801602C.c @@ -103,9 +103,9 @@ static void sub_8016110(void) case CONFIRM_NAME_MENU_PROMPT: BuildConfirmNameMenu(); if (sUnknown_203B200->unk4 == 1) - sub_80922B4(gFormatBuffer_Monsters[0], sUnknown_203B200->pokeName, POKEMON_NAME_LENGTH); + StrncpyCustom(gFormatBuffer_Monsters[0], sUnknown_203B200->pokeName, POKEMON_NAME_LENGTH); else - sub_80922B4(gFormatBuffer_Monsters[0], sUnknown_203B200->pokeName, POKEMON_NAME_LENGTH); + StrncpyCustom(gFormatBuffer_Monsters[0], sUnknown_203B200->pokeName, POKEMON_NAME_LENGTH); CreateMenuDialogueBoxAndPortrait(sIsNameOKPrompt, 0, 3, sUnknown_203B200->menus, 0, 4, 0, NULL, 32); break; diff --git a/src/code_801EE10.c b/src/code_801EE10.c index 67b5a636a..bbdd95eee 100644 --- a/src/code_801EE10.c +++ b/src/code_801EE10.c @@ -276,7 +276,7 @@ void sub_801F214(void) } } -extern void sub_80922B4(u8 *buffer, u8 *string, s32 size); +extern void StrncpyCustom(u8 *buffer, u8 *string, s32 size); void sub_801F280(bool8 param_1) { @@ -285,7 +285,7 @@ void sub_801F280(bool8 param_1) CallPrepareTextbox_8008C54(gUnknown_203B270->unk50); sub_80073B8(gUnknown_203B270->unk50); - sub_80922B4(buffer,gUnknown_203B270->pokeStruct->name,POKEMON_NAME_LENGTH); + StrncpyCustom(buffer,gUnknown_203B270->pokeStruct->name,POKEMON_NAME_LENGTH); strcpy(gFormatBuffer_Monsters[0],buffer); PrintFormattedStringOnWindow(0xc,0,gUnknown_80DC28C,gUnknown_203B270->unk50,0); // Move: {COLOR_1 YELLOW}{ARG_POKEMON_0){END_COLOR_TEXT_1} diff --git a/src/code_809447C.c b/src/code_809447C.c index 09a28157f..9271ecbce 100644 --- a/src/code_809447C.c +++ b/src/code_809447C.c @@ -65,8 +65,8 @@ void sub_8094558(u32 param_1,u8 *param_2,UnkDungeonGlobal_unk1CE98_sub *param_3) PrintYellowDungeonNametoBuffer(gFormatBuffer_Monsters[0], ¶m_3->dungeonLocation); PrintFormattedStringOnWindow(4,0x10,gUnknown_8113850,param_1,0); // #+Place: $m0 y = 0x1A; - sub_80922B4(gFormatBuffer_Monsters[0], param_3->buffer1, POKEMON_NAME_LENGTH); - sub_80922B4(gFormatBuffer_Monsters[1], param_3->buffer2, POKEMON_NAME_LENGTH); + StrncpyCustom(gFormatBuffer_Monsters[0], param_3->buffer1, POKEMON_NAME_LENGTH); + StrncpyCustom(gFormatBuffer_Monsters[1], param_3->buffer2, POKEMON_NAME_LENGTH); if (sub_8094528(param_3->moveID) != 0) { // $m1 was defeated by FormatString(gText_Pokemon1WasDefeatedBy,buffer, buffer + sizeof(buffer),0); diff --git a/src/dungeon_damage.c b/src/dungeon_damage.c index c764a9ca7..d6914657e 100644 --- a/src/dungeon_damage.c +++ b/src/dungeon_damage.c @@ -2,7 +2,7 @@ #include "constants/ability.h" #include "structs/str_dungeon.h" #include "dungeon_logic.h" -#include "text_util.h" +#include "pokemon_types.h" #include "dungeon_message.h" #include "string_format.h" #include "type_effectiveness.h" diff --git a/src/dungeon_misc.c b/src/dungeon_misc.c index 1007ff8bb..2fcd292bb 100644 --- a/src/dungeon_misc.c +++ b/src/dungeon_misc.c @@ -34,7 +34,7 @@ #include "dungeon_config.h" #include "game_options.h" #include "weather.h" -#include "text_util.h" +#include "pokemon_types.h" #include "dungeon_random.h" #include "position_util.h" #include "dungeon_ai_movement.h" @@ -1233,7 +1233,7 @@ void sub_806A120(Entity * pokemon, Entity * target, Move* move) if ((((EntityIsValid(pokemon)) && (EntityIsValid(target))) && (pokemon != target)) && (entityInfo = GetEntInfo(target), entityInfo->reflectClassStatus.status == STATUS_CONVERSION2)) { moveType = GetMoveTypeForMonster(pokemon, move); - uVar2_u32 = sub_8092364(moveType); + uVar2_u32 = GetBestResistingType(moveType); if (uVar2_u32 != TYPE_NONE) { entityInfo->types[0] = uVar2_u32; entityInfo->types[1] = 0; diff --git a/src/dungeon_move_util.c b/src/dungeon_move_util.c index d35aef4ca..2ab1d4f4b 100644 --- a/src/dungeon_move_util.c +++ b/src/dungeon_move_util.c @@ -38,7 +38,7 @@ #include "move_orb_actions_4.h" #include "weather.h" #include "targeting_flags.h" -#include "text_util.h" +#include "pokemon_types.h" extern void sub_80429C8(Entity *r0); extern bool8 sub_8045888(Entity *r0); diff --git a/src/friend_list.c b/src/friend_list.c index 3c43f103d..f4060b50e 100644 --- a/src/friend_list.c +++ b/src/friend_list.c @@ -291,7 +291,7 @@ void FriendList_ShowWindow(void) ; } - sub_80922B4(nameTxtBuff, pokePtr->name, POKEMON_NAME_LENGTH); + StrncpyCustom(nameTxtBuff, pokePtr->name, POKEMON_NAME_LENGTH); sub_808D930(txtBuff3, pokePtr->speciesNum); sprintfStatic(winTxtBuff, _("{color}%c%s{reset}"), color, nameTxtBuff); PrintStringOnWindow(8, GetMenuEntryYCoord(&sFriendList->unk358.s0.input, i), winTxtBuff, sFriendList->unk358.s0.winId, '\0'); @@ -470,7 +470,7 @@ UNUSED static PokemonStruct1 *sub_80243E8(void) u8 nameBuffer[20]; PokemonStruct1 *pokeStruct = &gRecruitedPokemonRef->pokemon[sFriendList->unk1A[(sFriendList->unk358.s0.input.unk1E * sFriendList->unk358.s0.input.unk1C) + sFriendList->unk358.s0.input.menuIndex]]; - sub_80922B4(nameBuffer, pokeStruct->name, POKEMON_NAME_LENGTH); + StrncpyCustom(nameBuffer, pokeStruct->name, POKEMON_NAME_LENGTH); sprintfStatic(buffer, "%s", nameBuffer); return pokeStruct; } diff --git a/src/friend_rescue.c b/src/friend_rescue.c index 8666ae5da..9171ec41b 100644 --- a/src/friend_rescue.c +++ b/src/friend_rescue.c @@ -1212,7 +1212,7 @@ void sub_8032828(void) CreateMenuDialogueBoxAndPortrait(&gUnknown_80E2D7C[0], 0, 6, gUnknown_80E2290, NULL, 4, 0, NULL, 0x101); break; case 0x59: - sub_80922B4(buffer, GetPlayerPokemonStruct()->name, POKEMON_NAME_LENGTH); + StrncpyCustom(buffer, GetPlayerPokemonStruct()->name, POKEMON_NAME_LENGTH); sprintfStatic(gUnknown_203B33C->unk424, gUnknown_80E32C4, buffer); CreateDialogueBoxAndPortrait(gUnknown_203B33C->unk424, 0, 0, 0x101); break; diff --git a/src/ground_lives.c b/src/ground_lives.c index 67ae8ff22..0390f0aaa 100644 --- a/src/ground_lives.c +++ b/src/ground_lives.c @@ -1380,7 +1380,7 @@ void sub_80A8EC0(u8 *buffer,s32 a1) sub_80A7DDC(&sp, &species); monStruct = sub_80A8D54(sp); if (monStruct != NULL) { - sub_80922B4(buffer, monStruct->name, POKEMON_NAME_LENGTH); + StrncpyCustom(buffer, monStruct->name, POKEMON_NAME_LENGTH); } else if (sp == 32) { CopyMonsterNameToBuffer(buffer, species); diff --git a/src/ground_script.c b/src/ground_script.c index a1aa4d7a7..3b65b3dc9 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -3280,7 +3280,7 @@ s32 sub_80A14E8(Action *action, u8 idx, u32 r2, s32 r3) { ptr->name[index] = gUnknown_2039D98[index]; } - sub_80922B4(gFormatBuffer_Names[r2], gUnknown_2039D98, POKEMON_NAME_LENGTH); + StrncpyCustom(gFormatBuffer_Names[r2], gUnknown_2039D98, POKEMON_NAME_LENGTH); IncrementAdventureNumJoined(); return 0; } @@ -3338,7 +3338,7 @@ s32 sub_80A14E8(Action *action, u8 idx, u32 r2, s32 r3) { pokemon->name[index] = gUnknown_2039D98[index]; } - sub_80922B4(gFormatBuffer_Names[r2], gUnknown_2039D98, POKEMON_NAME_LENGTH); + StrncpyCustom(gFormatBuffer_Names[r2], gUnknown_2039D98, POKEMON_NAME_LENGTH); IncrementAdventureNumJoined(); return 0; diff --git a/src/items.c b/src/items.c index 58c9cb40e..ccf10a95e 100644 --- a/src/items.c +++ b/src/items.c @@ -12,7 +12,7 @@ #include "string_format.h" #include "text_1.h" #include "text_2.h" -#include "text_util.h" +#include "pokemon_types.h" #include "strings.h" #include "dungeon_info.h" diff --git a/src/load_screen.c b/src/load_screen.c index 35a450932..d0c4485be 100644 --- a/src/load_screen.c +++ b/src/load_screen.c @@ -300,9 +300,9 @@ void DrawLoadScreenText(void) // Draw Player Name playerInfo = GetPlayerPokemonStruct(); if (playerInfo == NULL) - sub_80922B4(playerName, gNoNamePlaceholder, POKEMON_NAME_LENGTH); + StrncpyCustom(playerName, gNoNamePlaceholder, POKEMON_NAME_LENGTH); else - sub_80922B4(playerName, playerInfo->name, POKEMON_NAME_LENGTH); + StrncpyCustom(playerName, playerInfo->name, POKEMON_NAME_LENGTH); sprintfStatic(gLoadScreen->formattedPlayerName,gUnknown_80E7804,playerName); PrintStringOnWindow(64,12,gLoadScreen->formattedPlayerName,0,0); @@ -358,7 +358,7 @@ void DrawLoadScreenText(void) temp2 = gUnknown_203B484; if(temp2->unk4.speciesNum != MONSTER_NONE) { sub_808D930(speciesHelper,temp2->unk4.speciesNum); - sub_80922B4(nameHelper,temp2->unk4.name,POKEMON_NAME_LENGTH); + StrncpyCustom(nameHelper,temp2->unk4.name,POKEMON_NAME_LENGTH); sprintfStatic(gLoadScreen->formattedHelperInfo,gHelperInfoPlaceholder,nameHelper,speciesHelper); // %s (%s) } else diff --git a/src/menu_input.c b/src/menu_input.c index c93c34541..9938c8fc3 100644 --- a/src/menu_input.c +++ b/src/menu_input.c @@ -196,7 +196,7 @@ void sub_8012BC4(u32 x, u32 y, s32 n, s32 len, u32 color, u32 windowId) do { iVar1 = *piVar4; piVar4++; - chr = ReturnIntFromChar2(iVar1 + 0x30); + chr = GetCharId(iVar1 + 0x30); iVar3 = GetCharacter(chr); total_x += iVar3->width; DrawCharOnWindow(x - total_x, y, chr, color, windowId); @@ -210,7 +210,7 @@ void sub_8012BC4(u32 x, u32 y, s32 n, s32 len, u32 color, u32 windowId) void DrawCharOnWindowWidth12(u32 x, u32 y, u32 chr, u32 color, u32 windowId) { u32 add_x; - u32 chrId = ReturnIntFromChar2(chr); + u32 chrId = GetCharId(chr); const unkChar *chrInfo = GetCharacter(chrId); if (chrInfo->width < 12) diff --git a/src/move_orb_actions_3.c b/src/move_orb_actions_3.c index 55040671c..b97d69291 100644 --- a/src/move_orb_actions_3.c +++ b/src/move_orb_actions_3.c @@ -36,7 +36,7 @@ #include "structs/dungeon_entity.h" #include "structs/map.h" #include "structs/str_dungeon.h" -#include "text_util.h" +#include "pokemon_types.h" #include "trap.h" #include "weather.h" diff --git a/src/moves.c b/src/moves.c index 482670f8c..312339aa3 100644 --- a/src/moves.c +++ b/src/moves.c @@ -10,7 +10,7 @@ #include "string_format.h" #include "text_1.h" #include "text_2.h" -#include "text_util.h" +#include "pokemon_types.h" #include "strings.h" static EWRAM_DATA OpenedFile *sWazaParametersFile = { NULL }; // NDS=213C188 diff --git a/src/naming_screen.c b/src/naming_screen.c index 651783eaa..45dc3e11d 100644 --- a/src/naming_screen.c +++ b/src/naming_screen.c @@ -866,7 +866,7 @@ static void UpdateLetterWidths(void) sNamingScreen->letterWidths[i] = 8; return; } - chrId = ReturnIntFromChar2(sNamingScreen->textPtr[i]); + chrId = GetCharId(sNamingScreen->textPtr[i]); chrInfo = GetCharacter(chrId); sNamingScreen->letterWidths[i] = chrInfo->width; total += chrInfo->width; @@ -879,7 +879,7 @@ s32 GetStrWidth(u8 *buffer, s32 size) s32 width = 0; for (i = 0; i < size && buffer[i] != '\0'; i++) { - width += GetCharacter(ReturnIntFromChar2(buffer[i]))->width; + width += GetCharacter(GetCharId(buffer[i]))->width; } return width; diff --git a/src/party_list_menu.c b/src/party_list_menu.c index c28e5c56e..6cc100c74 100644 --- a/src/party_list_menu.c +++ b/src/party_list_menu.c @@ -780,7 +780,7 @@ void sub_8026E08(u32 r0) CallPrepareTextbox_8008C54(r0); sub_80073B8(r0); - sub_80922B4(gFormatBuffer_Monsters[0], sUnknown_203B2B8->pokeStruct->name, POKEMON_NAME_LENGTH); + StrncpyCustom(gFormatBuffer_Monsters[0], sUnknown_203B2B8->pokeStruct->name, POKEMON_NAME_LENGTH); sub_808D930(buffer, sUnknown_203B2B8->pokeStruct->speciesNum); sprintfStatic(buffer1, sUnknown_80DD6E0, gFormatBuffer_Monsters[0]); x = sub_8008ED0(buffer1); diff --git a/src/pokemon.c b/src/pokemon.c index 70b75d59e..bb5fb6571 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -39,7 +39,6 @@ extern s16 gBlastBurnIQReq; // 0x14d extern s16 gVoltTackleIQReq; // 0x14d extern char* gFormattedStatusNames[]; -extern u32 ReturnIntFromChar(u8 r0); extern void xxx_pokemon2_to_pokemonstruct_808DF44(PokemonStruct1*, PokemonStruct2*); // arm9.bin::0205C34C @@ -675,7 +674,7 @@ void PrintColoredPokeNameToBuffer(u8 *buffer, PokemonStruct1 *pokemon, s32 color { u8 nameBuffer [20]; - sub_80922B4(nameBuffer, pokemon->name, POKEMON_NAME_LENGTH); + StrncpyCustom(nameBuffer, pokemon->name, POKEMON_NAME_LENGTH); if (colorNum == COLOR_WHITE) { colorNum = COLOR_CYAN; } @@ -686,7 +685,7 @@ void sub_808D9DC(u8 *buffer, PokemonStruct2 *param_2, s32 colorNum) { u8 nameBuffer [20]; - sub_80922B4(nameBuffer, param_2->name, POKEMON_NAME_LENGTH); + StrncpyCustom(nameBuffer, param_2->name, POKEMON_NAME_LENGTH); if (colorNum == COLOR_WHITE) { colorNum = COLOR_YELLOW; } @@ -697,13 +696,13 @@ void sub_808DA0C(u8 *buffer, PokemonStruct2 *param_2) { u8 nameBuffer [20]; - sub_80922B4(nameBuffer, param_2->name, POKEMON_NAME_LENGTH); + StrncpyCustom(nameBuffer, param_2->name, POKEMON_NAME_LENGTH); sprintfStatic(buffer,"%s",nameBuffer); } void PrintPokeNameToBuffer(u8 *buffer, PokemonStruct1 *pokemon) { - sub_80922B4(buffer, pokemon->name, POKEMON_NAME_LENGTH); + StrncpyCustom(buffer, pokemon->name, POKEMON_NAME_LENGTH); } static const u8 gUnknown_8107645[12] = {0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/src/pokemon_abilities.c b/src/pokemon_abilities.c new file mode 100644 index 000000000..8457bf95d --- /dev/null +++ b/src/pokemon_abilities.c @@ -0,0 +1,15 @@ +#include "global.h" +#include "globaldata.h" +#include "pokemon_abilities.h" +#include "strings.h" + +// Unused +void CopyAbilityNametoBuffer(char *buffer, u8 index) +{ + strncpy(buffer, gAbilityNames[index], 0x50); +} + +const u8 *GetAbilityDescription(u8 index) +{ + return gAbilityDescriptions[index]; +} diff --git a/src/pokemon_mail.c b/src/pokemon_mail.c index b53769f95..15bd4e446 100644 --- a/src/pokemon_mail.c +++ b/src/pokemon_mail.c @@ -103,7 +103,7 @@ void CreateRescueTitle(unkStruct_802C39C *param_1) if (param_1->playerName == NULL) PrintStringOnWindow(178 - GetMaxPokeNameWidth(), param_1->y, GetMonSpecies(param_1->clientSpecies), param_1->unk0[0], 0); else { - sub_80922B4(buf_2, param_1->playerName, POKEMON_NAME_LENGTH); + StrncpyCustom(buf_2, param_1->playerName, POKEMON_NAME_LENGTH); PrintStringOnWindow(178 - GetMaxPokeNameWidth(), param_1->y, buf_2, param_1->unk0[0], 0); } } @@ -266,7 +266,7 @@ void CreateRescueDescription(unkStruct_802C39C *param_1) if (param_1->playerName == NULL) PrintStringOnWindow(68, y, GetMonSpecies(param_1->clientSpecies), param_1->unk0[0], 0); else { - sub_80922B4(buf_3, param_1->playerName, POKEMON_NAME_LENGTH); + StrncpyCustom(buf_3, param_1->playerName, POKEMON_NAME_LENGTH); sub_808D930(buf_4, param_1->clientSpecies); sprintfStatic(buf_2, gUnknown_80E8AD0, buf_3, buf_4); PrintStringOnWindow(68, y, buf_2, param_1->unk0[0], 0); diff --git a/src/pokemon_summary_window.c b/src/pokemon_summary_window.c index c5889073b..474c3f5ca 100644 --- a/src/pokemon_summary_window.c +++ b/src/pokemon_summary_window.c @@ -7,7 +7,8 @@ #include "pokemon_evolution.h" #include "text_1.h" #include "items.h" -#include "text_util.h" +#include "pokemon_types.h" +#include "pokemon_abilities.h" #include "friend_area.h" #include "dungeon_info.h" #include "dungeon_data.h" diff --git a/src/pokemon_types.c b/src/pokemon_types.c new file mode 100644 index 000000000..a87d6d0ad --- /dev/null +++ b/src/pokemon_types.c @@ -0,0 +1,26 @@ +#include "global.h" +#include "globaldata.h" +#include "pokemon_types.h" +#include "strings.h" +#include "dungeon_data.h" + +// arm9.bin::02061508 +const char *GetUnformattedTypeString(u8 type) +{ + return gUnformattedTypeStrings[type]; +} + +const char * GetFormattedTypeString(u8 type) +{ + return gFormattedTypeStrings[type]; +} + +u8 IsTypePhysical(u8 index) +{ + return gIsTypePhysicalTable[index]; +} + +u8 GetBestResistingType(u8 index) +{ + return gBestResistTypeTable[index]; +} diff --git a/src/rescue_team_info.c b/src/rescue_team_info.c index 54d400208..964a2a35f 100644 --- a/src/rescue_team_info.c +++ b/src/rescue_team_info.c @@ -1,4 +1,5 @@ #include "global.h" +#include "globaldata.h" #include "rescue_team_info.h" #include "code_8092334.h" #include "text_util.h" @@ -10,8 +11,16 @@ EWRAM_DATA struct RescueTeamData gRescueTeamInfo = {0}; extern void BoundedCopyStringtoBuffer(u8 *buffer, u8 *string, s32 size); extern const u8 *gRescueTeamRanks[]; -extern s32 gRescueRankMaxPoints[MAX_TEAM_RANKS]; -extern u8 gTeamNamePlaceholder[0x8]; // Pokemon + +static const s32 sRescueRankMaxPoints[MAX_TEAM_RANKS] = { + [NORMAL_RANK] = 50, + [BRONZE_RANK] = 500, + [SILVER_RANK] = 1500, + [GOLD_RANK] = 3000, + [PLATINUM_RANK] = 7500, + [DIAMOND_RANK] = 15000, + [LUCARIO_RANK] = 100000000, +}; void LoadRescueTeamInfo(void) { @@ -25,7 +34,7 @@ struct RescueTeamData *GetRescueTeamInfo(void) void InitializeRescueTeamInfo(void) { - BoundedCopyStringtoBuffer(gRescueTeamInfoRef->teamName, gTeamNamePlaceholder, TEAM_NAME_LENGTH); + BoundedCopyStringtoBuffer(gRescueTeamInfoRef->teamName, _("Pokémon"), TEAM_NAME_LENGTH); gRescueTeamInfoRef->teamRankPts = 0; gRescueTeamInfoRef->isTeamRenamed = FALSE; } @@ -41,7 +50,7 @@ void sub_80920B8(u8 *buffer) void sub_80920D8(u8 *buffer) { - sub_80922B4(buffer, gRescueTeamInfoRef->teamName, TEAM_NAME_LENGTH); + StrncpyCustom(buffer, gRescueTeamInfoRef->teamName, TEAM_NAME_LENGTH); } void SetRescueTeamName(u8 *buffer) @@ -68,7 +77,7 @@ s32 GetPtsToNextRank(void) } else { - return (gRescueRankMaxPoints[teamRank] - gRescueTeamInfoRef->teamRankPts); + return (sRescueRankMaxPoints[teamRank] - gRescueTeamInfoRef->teamRankPts); } } @@ -91,7 +100,7 @@ u8 GetRescueTeamRank(void) s32 rank; for(rank = NORMAL_RANK; rank < MAX_TEAM_RANKS; rank++){ - if (gRescueTeamInfoRef->teamRankPts < gRescueRankMaxPoints[rank]) { + if (gRescueTeamInfoRef->teamRankPts < sRescueRankMaxPoints[rank]) { return rank; } } diff --git a/src/strings.c b/src/strings.c index 929a3285b..cedc81e89 100644 --- a/src/strings.c +++ b/src/strings.c @@ -202,7 +202,7 @@ const u8 *const gAbilityNames[NUM_ABILITIES] = { [ABILITY_SHIELD_DUST] = _("Shield Dust"), }; -const u8 *const AbilityDescriptions[NUM_ABILITIES] = { +const u8 *const gAbilityDescriptions[NUM_ABILITIES] = { [ABILITY_UNKNOWN] = _("{color RED}-------"), [ABILITY_STENCH] = _("{color RED}Stench{reset}: May terrify an\nattacking foe."), [ABILITY_THICK_FAT] = _("{color RED}Thick Fat{reset}: Resistant to\nFire- and Ice-type moves."), diff --git a/src/text_util.c b/src/text_util.c index 2675a61d2..358931698 100644 --- a/src/text_util.c +++ b/src/text_util.c @@ -1,99 +1,78 @@ #include "global.h" +#include "globaldata.h" #include "text_util.h" -#include "strings.h" -#include "dungeon_data.h" -extern u32 gUnknown_810983C[26]; // TODO: verify size later - -u32 ReturnIntFromChar(u8 r0) +// Not sure what the deal is with these two funcs. GetCharId is mostly used alongside GetCharacter function, which gets char info, such as width, etc. +s32 ReturnIntFromChar(u8 c) { - return r0; + return c; } // arm9.bin::020614D0 -u32 ReturnIntFromChar2(u8 r0) +u32 GetCharId(u8 c) { - return r0; + return c; } UNUSED static void sub_8092290(u8 *buffer, u8 *string) { - while( *string != '\0' ) { - *buffer++ = ReturnIntFromChar2(*string++); - } - *buffer = 0; // append a 0 + while( *string != '\0' ) { + *buffer++ = GetCharId(*string++); + } + *buffer = '\0'; // append terminating char } -void sub_80922B4(u8 *buffer, const u8 *string, s32 size) +void StrncpyCustom(u8 *buffer, const u8 *string, s32 n) { - while(1) - { - if(size-- < 1 || *string == '\0') - { + while(1) { + if (n-- <= 0 || *string == '\0') { break; } - *buffer++ = ReturnIntFromChar2(*string++); + *buffer++ = GetCharId(*string++); } - *buffer = 0; // append a 0 + *buffer = '\0'; // append terminating char } -u32 sub_80922E4(u32 r0) +// Inverted font block - maybe used in international/Japanese games? +static const u8 *const sInvertedFontDigits[] = { + _("0"), + _("1"), + _("2"), + _("3"), + _("4"), + _("5"), + _("6"), + _("7"), + _("8"), + _("9"), +}; + +UNUSED static const u8 *GetDigitInvertedFontStr(u32 digit) { - return gUnknown_810983C[r0]; + return sInvertedFontDigits[digit]; } void CopyStringtoBuffer(u8 *buffer, const u8 *string) { - while( *string != '\0' ) { - *buffer++ = *string++; - } - *buffer = 0; // append a 0 + while( *string != '\0' ) { + *buffer++ = *string++; + } + *buffer = '\0'; // append a terminating char } void BoundedCopyStringtoBuffer(u8 *buffer, u8 *string, s32 size) { - while( 1 ) { - if (size-- < 1) { - break; + while( 1 ) { + if (size-- < 1) { + break; + } + if (*string == '\0') { + *buffer = '\0'; // append a terminating char and break + break; + } + // NOTE: *buffer++ = *string++ cases register flip + *buffer = *string; + buffer++; + string++; } - if (*string == '\0') { - *buffer = 0; // append a 0 and break - break; - } - // NOTE: *buffer++ = *string++ cases register flip - *buffer = *string; - buffer++; - string++; - } -} - -// arm9.bin::02061508 -const char *GetUnformattedTypeString(u8 type) -{ - return gUnformattedTypeStrings[type]; -} - -const char * GetFormattedTypeString(u8 type) -{ - return gFormattedTypeStrings[type]; -} - -u8 IsTypePhysical(u8 index) -{ - return gIsTypePhysicalTable[index]; -} - -u8 sub_8092364(u8 index) -{ - return gBestResistTypeTable[index]; -} - -void CopyAbilityNametoBuffer(char *buffer, u8 index) -{ - strncpy(buffer, gAbilityNames[index], 0x50); -} - -const u8 *GetAbilityDescription(u8 index) -{ - return AbilityDescriptions[index]; } diff --git a/src/thank_you_wonder_mail.c b/src/thank_you_wonder_mail.c index 0b01f9507..928d5a93a 100644 --- a/src/thank_you_wonder_mail.c +++ b/src/thank_you_wonder_mail.c @@ -1246,7 +1246,7 @@ void UpdateThankYouMailText(void) switch(sUnknown_203B2C4->state) { case 5: pokeStruct = GetPlayerPokemonStruct(); - sub_80922B4(buffer1,pokeStruct->name, POKEMON_NAME_LENGTH); + StrncpyCustom(buffer1,pokeStruct->name, POKEMON_NAME_LENGTH); sprintfStatic(sUnknown_203B2C4->formattedString,gUnknown_80DF250,buffer1); CreateDialogueBoxAndPortrait(sUnknown_203B2C4->formattedString,0,&sUnknown_203B2C4->monPortrait,0x10d); break; @@ -1404,7 +1404,7 @@ void UpdateThankYouMailText(void) break; case THANK_YOU_MAIL_COMMS_CLEANUP: pokeStruct2 = GetPlayerPokemonStruct(); - sub_80922B4(buffer2, pokeStruct2->name, POKEMON_NAME_LENGTH); + StrncpyCustom(buffer2, pokeStruct2->name, POKEMON_NAME_LENGTH); sprintfStatic(sUnknown_203B2C4->formattedString,gUnknown_80DF63C,buffer2); CreateDialogueBoxAndPortrait(sUnknown_203B2C4->formattedString,0,&sUnknown_203B2C4->monPortrait,0x10d); break;