From e143804af010b52d5723be3b583435e71e99f07f Mon Sep 17 00:00:00 2001 From: Meowsy Date: Mon, 10 Dec 2018 04:32:00 -0500 Subject: [PATCH 1/3] Document pocket magic numbers. --- include/item_menu.h | 8 +++-- src/item_menu.c | 86 ++++++++++++++++++++++----------------------- 2 files changed, 48 insertions(+), 46 deletions(-) diff --git a/include/item_menu.h b/include/item_menu.h index 649eb934cd..e8fc4c398f 100644 --- a/include/item_menu.h +++ b/include/item_menu.h @@ -1,6 +1,8 @@ #ifndef GUARD_item_menu_H #define GUARD_item_menu_H +#include "item.h" + // Exported type declarations struct BagStruct { @@ -8,8 +10,8 @@ struct BagStruct u8 location; u8 pocket; u16 unk6; - u16 cursorPosition[5]; - u16 scrollPosition[5]; + u16 cursorPosition[POCKETS_COUNT]; + u16 scrollPosition[POCKETS_COUNT]; }; extern struct BagStruct gUnknown_0203CE58; @@ -36,7 +38,7 @@ struct UnkBagStruct u8 unk825; u8 filler[2]; u8 unk828; - u8 unk829[5]; + u8 unk829[POCKETS_COUNT]; u8 unk82E[6]; s16 unk834; u8 filler4[0xE]; diff --git a/src/item_menu.c b/src/item_menu.c index 1744a1bfad..a7d1016511 100755 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -432,8 +432,8 @@ struct ListBuffer2 { struct TempWallyStruct { struct ItemSlot bagPocket_Items[30]; struct ItemSlot bagPocket_PokeBalls[16]; - u16 cursorPosition[5]; - u16 scrollPosition[5]; + u16 cursorPosition[POCKETS_COUNT]; + u16 scrollPosition[POCKETS_COUNT]; u8 filler[0x2]; u16 pocket; }; @@ -455,60 +455,60 @@ extern const u16 gUnknown_0860F074[]; void ResetBagScrollPositions(void) { - gUnknown_0203CE58.pocket = 0; + gUnknown_0203CE58.pocket = ITEMS_POCKET; memset(gUnknown_0203CE58.cursorPosition, 0, 10); memset(gUnknown_0203CE58.scrollPosition, 0, 10); } void CB2_BagMenuFromStartMenu(void) { - GoToBagMenu(0, 5, CB2_ReturnToFieldWithOpenMenu); + GoToBagMenu(0, POCKETS_COUNT, CB2_ReturnToFieldWithOpenMenu); } void sub_81AABB0(void) { if (!InBattlePyramid()) - GoToBagMenu(1, 5, SetCB2ToReshowScreenAfterMenu2); + GoToBagMenu(1, POCKETS_COUNT, SetCB2ToReshowScreenAfterMenu2); else sub_81C4F98(1, SetCB2ToReshowScreenAfterMenu2); } void CB2_ChooseBerry(void) { - GoToBagMenu(4, 3, CB2_ReturnToFieldContinueScript); + GoToBagMenu(4, BERRIES_POCKET, CB2_ReturnToFieldContinueScript); } void sub_81AABF0(void(*callback)(void)) { - GoToBagMenu(5, 3, callback); + GoToBagMenu(5, BERRIES_POCKET, callback); } void CB2_GoToSellMenu(void) { - GoToBagMenu(3, 5, CB2_ExitSellMenu); + GoToBagMenu(3, POCKETS_COUNT, CB2_ExitSellMenu); } void sub_81AAC14(void) { - GoToBagMenu(6, 5, sub_816B31C); + GoToBagMenu(6, POCKETS_COUNT, sub_816B31C); } void sub_81AAC28(void) { - GoToBagMenu(9, 5, bag_menu_leave_maybe_3); + GoToBagMenu(9, POCKETS_COUNT, bag_menu_leave_maybe_3); gSpecialVar_0x8005 = 0; gSpecialVar_Result = 0; } void sub_81AAC50(void) { - GoToBagMenu(7, 5, bag_menu_leave_maybe_2); + GoToBagMenu(7, POCKETS_COUNT, bag_menu_leave_maybe_2); gSpecialVar_Result = 0; } void sub_81AAC70(void) { - GoToBagMenu(8, 5, bag_menu_leave_maybe); + GoToBagMenu(8, POCKETS_COUNT, bag_menu_leave_maybe); gSpecialVar_Result = 0; } @@ -526,9 +526,9 @@ void GoToBagMenu(u8 bagMenuType, u8 pocketId, void ( *postExitMenuMainCallback2) gUnknown_0203CE58.location = bagMenuType; if (postExitMenuMainCallback2) gUnknown_0203CE58.bagCallback = postExitMenuMainCallback2; - if (pocketId <= 4) + if (pocketId <= POCKETS_COUNT - 1) gUnknown_0203CE58.pocket = pocketId; - temp = gUnknown_0203CE58.location - 4; + temp = gUnknown_0203CE58.location - (POCKETS_COUNT - 1); if (temp <= 1) gUnknown_0203CE54->unk81B = 1; gUnknown_0203CE54->unk0 = 0; @@ -788,7 +788,7 @@ void get_name(s8 *dest, u16 itemId) { switch (gUnknown_0203CE58.pocket) { - case 2: + case TMHM_POCKET: StringCopy(gStringVar2, gMoveNames[ItemIdToBattleMoveId(itemId)]); if (itemId >= ITEM_HM01) { @@ -801,7 +801,7 @@ void get_name(s8 *dest, u16 itemId) StringExpandPlaceholders(dest, gText_UnkF908Var1Clear7Var2); } break; - case 3: + case BERRIES_POCKET: ConvertIntToDecimalStringN(gStringVar1, itemId - ITEM_CHERI_BERRY + 1, 2, 2); CopyItemName(itemId, gStringVar2); StringExpandPlaceholders(dest, gText_UnkF908Var1Clear7Var2); @@ -851,14 +851,14 @@ void sub_81AB520(u8 rboxId, int item_index_in_pocket, u8 a) itemQuantity = BagGetQuantityByPocketPosition(gUnknown_0203CE58.pocket + 1, item_index_in_pocket); if (itemId >= ITEM_HM01 && itemId <= ITEM_HM08) BlitBitmapToWindow(rboxId, gBagMenuHMIcon_Gfx, 8, a - 1, 16, 16); - if (gUnknown_0203CE58.pocket == 3) + if (gUnknown_0203CE58.pocket == BERRIES_POCKET) { ConvertIntToDecimalStringN(gStringVar1, itemQuantity, 1, 3); StringExpandPlaceholders(gStringVar4, gText_xVar1); offset = GetStringRightAlignXOffset(7, gStringVar4, 0x77); bag_menu_print(rboxId, 7, gStringVar4, offset, a, 0, 0, -1, 0); } - else if (gUnknown_0203CE58.pocket != 4 && (unique = ItemId_GetImportance(itemId)) == FALSE) + else if (gUnknown_0203CE58.pocket != KEYITEMS_POCKET && (unique = ItemId_GetImportance(itemId)) == FALSE) { ConvertIntToDecimalStringN(gStringVar1, itemQuantity, 1, 2); StringExpandPlaceholders(gStringVar4, gText_xVar1); @@ -973,8 +973,8 @@ void sub_81AB9A8(u8 pocketId) struct BagPocket *pocket = &gBagPockets[pocketId]; switch (pocketId) { - case 2: - case 3: + case TMHM_POCKET: + case BERRIES_POCKET: SortBerriesOrTMHMs(pocket); break; default: @@ -995,7 +995,7 @@ void sub_81AB9A8(u8 pocketId) void sub_81ABA6C(void) { u8 i; - for (i = 0; i < 5; i++) + for (i = 0; i < POCKETS_COUNT; i++) sub_81AB9A8(i); } @@ -1007,14 +1007,14 @@ void sub_81ABA88(u8 a) void sub_81ABAC4(void) { u8 i; - for (i = 0; i < 5; i++) + for (i = 0; i < POCKETS_COUNT; i++) sub_81ABA88(i); } void sub_81ABAE0(void) { u8 i; - for (i = 0; i < 5; i++) + for (i = 0; i < POCKETS_COUNT; i++) sub_8122298(&gUnknown_0203CE58.scrollPosition[i], &gUnknown_0203CE58.cursorPosition[i], gUnknown_0203CE54->unk82E[i], gUnknown_0203CE54->unk829[i], 8); } @@ -1055,7 +1055,7 @@ void sub_81ABC3C(u8 a) void sub_81ABC54(u8 a, s16 b) { - u8 r3 = (gUnknown_0203CE58.pocket == 3) ? 3 : 2; + u8 r3 = (gUnknown_0203CE58.pocket == BERRIES_POCKET) ? 3 : 2; ConvertIntToDecimalStringN(gStringVar1, b, 2, r3); StringExpandPlaceholders(gStringVar4, gText_xVar1); AddTextPrinterParameterized(a, 1, gStringVar4, GetStringCenterAlignXOffset(1, gStringVar4, 0x28), 2, 0, 0); @@ -1063,7 +1063,7 @@ void sub_81ABC54(u8 a, s16 b) void sub_81ABCC0(int a, int b, int c) { - u8 r3 = (gUnknown_0203CE58.pocket == 3) ? 3 : 2; + u8 r3 = (gUnknown_0203CE58.pocket == BERRIES_POCKET) ? 3 : 2; ConvertIntToDecimalStringN(gStringVar1, b, 2, r3); StringExpandPlaceholders(gStringVar4, gText_xVar1); AddTextPrinterParameterized(a, 1, gStringVar4, 0, 1, -1, 0); @@ -1164,10 +1164,10 @@ u8 GetSwitchBagPocketDirection(void) void ChangeBagPocketId(u8 *bagPocketId, s8 deltaBagPocketId) { - if (deltaBagPocketId == 1 && *bagPocketId == 4) + if (deltaBagPocketId == 1 && *bagPocketId == POCKETS_COUNT - 1) *bagPocketId = 0; else if (deltaBagPocketId == -1 && *bagPocketId == 0) - *bagPocketId = 4; + *bagPocketId = POCKETS_COUNT - 1; else *bagPocketId += deltaBagPocketId; } @@ -1444,7 +1444,7 @@ void sub_81AC644(u8 unused) default: if (sub_81221AC() == TRUE || InUnionRoom() == TRUE) { - if (gUnknown_0203CE58.pocket == 4 || !sub_8122148(gSpecialVar_ItemId)) + if (gUnknown_0203CE58.pocket == KEYITEMS_POCKET || !sub_8122148(gSpecialVar_ItemId)) { gUnknown_0203CE54->unk820 = &gUnknown_08614046; gUnknown_0203CE54->unk828 = 1; @@ -1459,14 +1459,14 @@ void sub_81AC644(u8 unused) { switch (gUnknown_0203CE58.pocket) { - case 0: + case ITEMS_POCKET: gUnknown_0203CE54->unk820 = &gUnknown_0203CE54->unk824; gUnknown_0203CE54->unk828 = 4; memcpy(&gUnknown_0203CE54->unk824, &gUnknown_0861402C, 4); if (ItemIsMail(gSpecialVar_ItemId) == TRUE) gUnknown_0203CE54->unk824 = 6; break; - case 4: + case KEYITEMS_POCKET: gUnknown_0203CE54->unk820 = &gUnknown_0203CE54->unk824; gUnknown_0203CE54->unk828 = 4; memcpy(&gUnknown_0203CE54->unk824, &gUnknown_08614030, 4); @@ -1478,22 +1478,22 @@ void sub_81AC644(u8 unused) gUnknown_0203CE54->unk824 = 7; } break; - case 1: + case BALLS_POCKET: gUnknown_0203CE54->unk820 = gUnknown_08614034; gUnknown_0203CE54->unk828 = 4; break; - case 2: + case TMHM_POCKET: gUnknown_0203CE54->unk820 = gUnknown_08614038; gUnknown_0203CE54->unk828 = 4; break; - case 3: + case BERRIES_POCKET: gUnknown_0203CE54->unk820 = gUnknown_0861403C; gUnknown_0203CE54->unk828 = 6; break; } } } - if (gUnknown_0203CE58.pocket == 2) + if (gUnknown_0203CE58.pocket == TMHM_POCKET) { ClearWindowTilemap(1); PrintTMHMMoveData(gSpecialVar_ItemId); @@ -1624,17 +1624,17 @@ bool8 sub_81ACDFC(s8 a) void bag_menu_remove_some_window(void) { if (gUnknown_0203CE54->unk828 == 1) - bag_menu_remove_window(0); + bag_menu_remove_window(0); else if (gUnknown_0203CE54->unk828 == 2) { - bag_menu_remove_window(1); + bag_menu_remove_window(1); } else if (gUnknown_0203CE54->unk828 == 4) { - bag_menu_remove_window(2); + bag_menu_remove_window(2); } else - bag_menu_remove_window(3); + bag_menu_remove_window(3); } void ItemMenu_UseOutOfBattle(u8 taskId) @@ -1648,7 +1648,7 @@ void ItemMenu_UseOutOfBattle(u8 taskId) { FillWindowPixelBuffer(1, 0); schedule_bg_copy_tilemap_to_vram(0); - if (gUnknown_0203CE58.pocket != 3) + if (gUnknown_0203CE58.pocket != BERRIES_POCKET) ItemId_GetFieldFunc(gSpecialVar_ItemId)(taskId); else sub_80FDD10(taskId); @@ -1842,7 +1842,7 @@ void ItemMenu_UseInBattle(u8 taskId) void bag_menu_mail_related(void) { - GoToBagMenu(12, 5, NULL); + GoToBagMenu(12, POCKETS_COUNT, NULL); } void item_menu_type_2(u8 taskId) @@ -1857,7 +1857,7 @@ void item_menu_type_2(u8 taskId) StringExpandPlaceholders(gStringVar4, gText_Var1CantBeHeldHere); DisplayItemMessage(taskId, 1, gStringVar4, sub_81AD350); } - else if (gUnknown_0203CE58.pocket != 4 && !ItemId_GetImportance(gSpecialVar_ItemId)) + else if (gUnknown_0203CE58.pocket != KEYITEMS_POCKET && !ItemId_GetImportance(gSpecialVar_ItemId)) { unknown_ItemMenu_Confirm(taskId); } @@ -1871,7 +1871,7 @@ void item_menu_type_b(u8 taskId) { if (ItemIsMail(gSpecialVar_ItemId) == TRUE) DisplayItemMessage(taskId, 1, gText_CantWriteMail, sub_81AD350); - else if (gUnknown_0203CE58.pocket != 4 && !ItemId_GetImportance(gSpecialVar_ItemId)) + else if (gUnknown_0203CE58.pocket != KEYITEMS_POCKET && !ItemId_GetImportance(gSpecialVar_ItemId)) gTasks[taskId].func = unknown_ItemMenu_Confirm; else bag_menu_print_cant_be_held_msg(taskId); @@ -2157,7 +2157,7 @@ void DoWallyTutorialBagMenu(void) PrepareBagForWallyTutorial(); AddBagItem(ITEM_POTION, 1); AddBagItem(ITEM_POKE_BALL, 1); - GoToBagMenu(10, 0, SetCB2ToReshowScreenAfterMenu2); + GoToBagMenu(10, ITEMS_POCKET, SetCB2ToReshowScreenAfterMenu2); } void Task_WallyTutorialBagMenu(u8 taskId) From 0aa41ad6472a095864dc97649ae18bbd261383bb Mon Sep 17 00:00:00 2001 From: Meowsy Date: Mon, 10 Dec 2018 11:38:27 -0500 Subject: [PATCH 2/3] Fix whitespace to be consistent. --- src/strings.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/strings.c b/src/strings.c index 7b3df0eca3..7b0178fa17 100644 --- a/src/strings.c +++ b/src/strings.c @@ -255,25 +255,25 @@ const u8 gText_ThePC[] = _("the PC"); const u8 *const gReturnToXStringsTable[] = { gText_TheField, - gText_TheBattle, - gText_ThePokemonList, - gText_TheShop, - gText_TheField, - gText_TheField, - gText_ThePC, - gText_TheField, - gText_TheField, - gText_TheField, - gText_TheBattle, - gText_ThePC + gText_TheBattle, + gText_ThePokemonList, + gText_TheShop, + gText_TheField, + gText_TheField, + gText_ThePC, + gText_TheField, + gText_TheField, + gText_TheField, + gText_TheBattle, + gText_ThePC }; const u8 *const gReturnToXStringsTable2[] = { gText_TheField, - gText_TheBattle, - gText_ThePokemonList, - gText_TheField + gText_TheBattle, + gText_ThePokemonList, + gText_TheField }; const u8 gText_ReturnToVar1[] = _("Return to\n{STR_VAR_1}."); @@ -286,10 +286,10 @@ const u8 gText_KeyItemsPocket[] = _("KEY ITEMS"); const u8 *const gPocketNamesStringsTable[] = { gText_ItemsPocket, - gText_PokeBallsPocket, - gText_TMHMPocket, - gText_BerriesPocket, - gText_KeyItemsPocket + gText_PokeBallsPocket, + gText_TMHMPocket, + gText_BerriesPocket, + gText_KeyItemsPocket }; const u8 gText_UnkF908Var1Clear7Var2[] = _("{NO}{STR_VAR_1}{CLEAR 0x07}{STR_VAR_2}"); From 2f008e866b2d0541e864e3c2c14c5b4437720fe4 Mon Sep 17 00:00:00 2001 From: Meowsy Date: Mon, 10 Dec 2018 11:39:57 -0500 Subject: [PATCH 3/3] Document return locations. --- include/item_menu.h | 14 ++++++++++++++ src/item_menu.c | 26 +++++++++++++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/include/item_menu.h b/include/item_menu.h index e8fc4c398f..4631382cb4 100644 --- a/include/item_menu.h +++ b/include/item_menu.h @@ -3,6 +3,20 @@ #include "item.h" +#define RETURN_LOCATION_FIELD 0 +#define RETURN_LOCATION_BATTLE 1 +#define RETURN_LOCATION_POKEMON_LIST 2 +#define RETURN_LOCATION_SHOP 3 +#define RETURN_LOCATION_FIELD_2 4 +#define RETURN_LOCATION_FIELD_3 5 +#define RETURN_LOCATION_PC 6 +#define RETURN_LOCATION_FIELD_4 7 +#define RETURN_LOCATION_FIELD_5 8 +#define RETURN_LOCATION_FIELD_6 9 +#define RETURN_LOCATION_BATTLE_2 10 +#define RETURN_LOCATION_PC_2 11 +#define RETURN_LOCATION_UNCHANGED 12 + // Exported type declarations struct BagStruct { diff --git a/src/item_menu.c b/src/item_menu.c index a7d1016511..bc2bfb3b72 100755 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -462,53 +462,53 @@ void ResetBagScrollPositions(void) void CB2_BagMenuFromStartMenu(void) { - GoToBagMenu(0, POCKETS_COUNT, CB2_ReturnToFieldWithOpenMenu); + GoToBagMenu(RETURN_LOCATION_FIELD, POCKETS_COUNT, CB2_ReturnToFieldWithOpenMenu); } void sub_81AABB0(void) { if (!InBattlePyramid()) - GoToBagMenu(1, POCKETS_COUNT, SetCB2ToReshowScreenAfterMenu2); + GoToBagMenu(RETURN_LOCATION_BATTLE, POCKETS_COUNT, SetCB2ToReshowScreenAfterMenu2); else sub_81C4F98(1, SetCB2ToReshowScreenAfterMenu2); } void CB2_ChooseBerry(void) { - GoToBagMenu(4, BERRIES_POCKET, CB2_ReturnToFieldContinueScript); + GoToBagMenu(RETURN_LOCATION_FIELD_2, BERRIES_POCKET, CB2_ReturnToFieldContinueScript); } void sub_81AABF0(void(*callback)(void)) { - GoToBagMenu(5, BERRIES_POCKET, callback); + GoToBagMenu(RETURN_LOCATION_FIELD_3, BERRIES_POCKET, callback); } void CB2_GoToSellMenu(void) { - GoToBagMenu(3, POCKETS_COUNT, CB2_ExitSellMenu); + GoToBagMenu(RETURN_LOCATION_SHOP, POCKETS_COUNT, CB2_ExitSellMenu); } void sub_81AAC14(void) { - GoToBagMenu(6, POCKETS_COUNT, sub_816B31C); + GoToBagMenu(RETURN_LOCATION_PC, POCKETS_COUNT, sub_816B31C); } void sub_81AAC28(void) { - GoToBagMenu(9, POCKETS_COUNT, bag_menu_leave_maybe_3); + GoToBagMenu(RETURN_LOCATION_FIELD_6, POCKETS_COUNT, bag_menu_leave_maybe_3); gSpecialVar_0x8005 = 0; gSpecialVar_Result = 0; } void sub_81AAC50(void) { - GoToBagMenu(7, POCKETS_COUNT, bag_menu_leave_maybe_2); + GoToBagMenu(RETURN_LOCATION_FIELD_4, POCKETS_COUNT, bag_menu_leave_maybe_2); gSpecialVar_Result = 0; } void sub_81AAC70(void) { - GoToBagMenu(8, POCKETS_COUNT, bag_menu_leave_maybe); + GoToBagMenu(RETURN_LOCATION_FIELD_5, POCKETS_COUNT, bag_menu_leave_maybe); gSpecialVar_Result = 0; } @@ -522,11 +522,11 @@ void GoToBagMenu(u8 bagMenuType, u8 pocketId, void ( *postExitMenuMainCallback2) } else { - if (bagMenuType != 12) + if (bagMenuType != RETURN_LOCATION_UNCHANGED) gUnknown_0203CE58.location = bagMenuType; if (postExitMenuMainCallback2) gUnknown_0203CE58.bagCallback = postExitMenuMainCallback2; - if (pocketId <= POCKETS_COUNT - 1) + if (pocketId < POCKETS_COUNT) gUnknown_0203CE58.pocket = pocketId; temp = gUnknown_0203CE58.location - (POCKETS_COUNT - 1); if (temp <= 1) @@ -1842,7 +1842,7 @@ void ItemMenu_UseInBattle(u8 taskId) void bag_menu_mail_related(void) { - GoToBagMenu(12, POCKETS_COUNT, NULL); + GoToBagMenu(RETURN_LOCATION_UNCHANGED, POCKETS_COUNT, NULL); } void item_menu_type_2(u8 taskId) @@ -2157,7 +2157,7 @@ void DoWallyTutorialBagMenu(void) PrepareBagForWallyTutorial(); AddBagItem(ITEM_POTION, 1); AddBagItem(ITEM_POKE_BALL, 1); - GoToBagMenu(10, ITEMS_POCKET, SetCB2ToReshowScreenAfterMenu2); + GoToBagMenu(RETURN_LOCATION_BATTLE_2, ITEMS_POCKET, SetCB2ToReshowScreenAfterMenu2); } void Task_WallyTutorialBagMenu(u8 taskId)