From cb521b7407a3ce7c41446df5851e18026b57c916 Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 24 Dec 2023 05:30:32 +0000 Subject: [PATCH 1/4] start cleaning up move_relearner.c --- arm9/arm9.lsf | 2 +- arm9/global.inc | 6 +-- arm9/src/move_relearner.c | 63 ++++++++++++++++++++++++++ arm9/src/pokemon.c | 14 ++---- arm9/src/scrcmd_move_relearner.c | 16 +++---- arm9/src/unk_02088DD8.c | 76 -------------------------------- arm9/src/use_item_on_mon.c | 6 +-- include/constants/pokemon.h | 2 +- include/move_relearner.h | 23 ++++++++++ include/options.h | 4 +- include/pokemon.h | 12 +++++ include/trainer_data.h | 4 +- include/unk_02088DD8.h | 27 ------------ 13 files changed, 121 insertions(+), 134 deletions(-) create mode 100644 arm9/src/move_relearner.c delete mode 100644 arm9/src/unk_02088DD8.c create mode 100644 include/move_relearner.h delete mode 100644 include/unk_02088DD8.h diff --git a/arm9/arm9.lsf b/arm9/arm9.lsf index 42b8cd0fb..5ada5dd59 100644 --- a/arm9/arm9.lsf +++ b/arm9/arm9.lsf @@ -310,7 +310,7 @@ Static arm9 Object unk_0208898C.o Object unk_02088AAC.o Object unk_02088D1C.o - Object unk_02088DD8.o + Object move_relearner.o Object unk_02088F0C.o Object unk_020893E0.o Object unk_02089498.o diff --git a/arm9/global.inc b/arm9/global.inc index 8877fb44e..25025406e 100644 --- a/arm9/global.inc +++ b/arm9/global.inc @@ -5448,9 +5448,9 @@ .extern sub_02088D84 .extern sub_02088DA0 .extern sub_02088DBC -.extern sub_02088DD8 -.extern sub_02088DF0 -.extern GetEligibleLevelUpMoves +.extern MoveRelearner_New +.extern MoveRelearner_Delete +.extern MoveRelearner_GetEligibleLevelUpMoves .extern sub_02088EF8 .extern sub_02088F0C .extern sub_02088F4C diff --git a/arm9/src/move_relearner.c b/arm9/src/move_relearner.c new file mode 100644 index 000000000..32c82de5b --- /dev/null +++ b/arm9/src/move_relearner.c @@ -0,0 +1,63 @@ +#include "global.h" +#include "move_relearner.h" +#include "pokemon.h" + +MoveRelearner *MoveRelearner_New(HeapID heapId) { + MoveRelearner *ret = AllocFromHeap(heapId, sizeof(MoveRelearner)); + memset(ret, 0, sizeof(MoveRelearner)); + return ret; +} + +void MoveRelearner_Delete(MoveRelearner *moveRelearner) { + FreeToHeap(moveRelearner); +} + +//BUILD FAILS - JUST NOT GONNA DO THIS SHIT RN +u16 *MoveRelearner_GetEligibleLevelUpMoves(Pokemon* mon, HeapID heapId) { + u16 species = (u16)GetMonData(mon, MON_DATA_SPECIES, NULL); + u8 form = (u8)GetMonData(mon, MON_DATA_FORM, NULL); + u8 level = (u8)GetMonData(mon, MON_DATA_LEVEL, NULL); + u16 moves[MAX_MON_MOVES]; + + for (u8 i = 0; i < MAX_MON_MOVES; ++i) { + moves[i] = (u16)GetMonData(mon, MON_DATA_MOVE1 + i, NULL); + } + + u16 *tableFromFile = AllocFromHeap(heapId, WOTBL_MAX * 2); + u16 *returnTable = AllocFromHeap(heapId, WOTBL_MAX * 2); + + LoadWotbl_HandleAlternateForm(species, form, tableFromFile); + + for (u8 i = 0, j, k = 0; i < WOTBL_MAX; i++) { + if (tableFromFile[i] == WOTBL_END) { + returnTable[k] = WOTBL_END; + break; + } else if (WOTBL_LVL(tableFromFile[i]) > level) { + continue; + } else { + tableFromFile[i] = WOTBL_MOVE(tableFromFile[i]); + for (j = 0; j < MAX_MON_MOVES; j++) { + if (tableFromFile[i] == moves[j]) { + break; + } + } + if (j == MAX_MON_MOVES) { + for (j = 0; j < k; j++) { + if (returnTable[j] == tableFromFile[i]) { + break; + } + } + if (j == k) { + returnTable[k] = tableFromFile[i]; + k++; + } + } + } + } + FreeToHeap(tableFromFile); + return returnTable; +} + +BOOL sub_02088EF8(const u16 *ptr) { //MoveRelearner_IsValidMove? + return *ptr != WOTBL_END; +} diff --git a/arm9/src/pokemon.c b/arm9/src/pokemon.c index 750aeb69e..353b96f13 100644 --- a/arm9/src/pokemon.c +++ b/arm9/src/pokemon.c @@ -2778,14 +2778,6 @@ u16 GetEggSpecies(u16 species) } } -#define WOTBL_END 0xFFFF -#define WOTBL_MOVE_MASK 0x01FF -#define WOTBL_MOVE_SHIFT 0 -#define WOTBL_LVL_MASK 0xFE00 -#define WOTBL_LVL_SHIFT 9 -#define WOTBL_MOVE(x) ((u16)(((x) & WOTBL_MOVE_MASK) >> WOTBL_MOVE_SHIFT)) -#define WOTBL_LVL(x) ((u8)(((x) & WOTBL_LVL_MASK) >> WOTBL_LVL_SHIFT)) - void InitBoxMonMoveset(struct BoxPokemon * boxmon) { BOOL decry; @@ -2803,7 +2795,7 @@ void InitBoxMonMoveset(struct BoxPokemon * boxmon) LoadWotbl_HandleAlternateForm(species, (int)form, wotbl); for (i = 0; wotbl[i] != WOTBL_END; i++) { - if ((wotbl[i] & WOTBL_LVL_MASK) > (level << WOTBL_LVL_SHIFT)) + if ((wotbl[i] & WOTBL_LEVEL_MASK) > (level << WOTBL_LEVEL_SHIFT)) break; move = WOTBL_MOVE(wotbl[i]); if (sub_020696A8(boxmon, move) == 0xFFFF) @@ -2908,7 +2900,7 @@ u32 sub_02069818(struct Pokemon * pokemon, u32 * r5, u16 * sp0) FreeToHeap(wotbl); return 0; } - while ((wotbl[*r5] & WOTBL_LVL_MASK) != (level << WOTBL_LVL_SHIFT)) + while ((wotbl[*r5] & WOTBL_LEVEL_MASK) != (level << WOTBL_LEVEL_SHIFT)) { (*r5)++; if (wotbl[*r5] == 0xFFFF) @@ -2917,7 +2909,7 @@ u32 sub_02069818(struct Pokemon * pokemon, u32 * r5, u16 * sp0) return 0; } } - if ((wotbl[*r5] & WOTBL_LVL_MASK) == (level << WOTBL_LVL_SHIFT)) + if ((wotbl[*r5] & WOTBL_LEVEL_MASK) == (level << WOTBL_LEVEL_SHIFT)) { *sp0 = WOTBL_MOVE(wotbl[*r5]); (*r5)++; diff --git a/arm9/src/scrcmd_move_relearner.c b/arm9/src/scrcmd_move_relearner.c index d69eba821..d34f73d25 100644 --- a/arm9/src/scrcmd_move_relearner.c +++ b/arm9/src/scrcmd_move_relearner.c @@ -3,7 +3,7 @@ #include "heap.h" #include "party.h" #include "unk_020377F0.h" -#include "unk_02088DD8.h" +#include "move_relearner.h" extern void* FieldSysGetAttrAddr(struct FieldSystem*, int idx); @@ -48,7 +48,7 @@ BOOL ScrCmd_Unk021F(struct ScriptContext* ctx) { //021F u16 mon_idx = ScriptGetVar(ctx); struct Party* party = SaveArray_Party_Get(ctx->fieldSystem->saveData); struct Pokemon* pokemon = Party_GetMonByIndex(party, mon_idx); - u16 *eligibleMoves = GetEligibleLevelUpMoves(pokemon, HEAP_ID_32); + u16 *eligibleMoves = MoveRelearner_GetEligibleLevelUpMoves(pokemon, HEAP_ID_32); *ret_ptr = (u16)sub_02088EF8(eligibleMoves); FreeToHeap(eligibleMoves); @@ -58,13 +58,13 @@ BOOL ScrCmd_Unk021F(struct ScriptContext* ctx) { //021F void sub_02045E74(struct ScriptContext* ctx, u8 a1, struct Pokemon* pokemon, u16 *eligibleMoves) { MoveRelearner **moveRelearnerPtr = FieldSysGetAttrAddr(ctx->fieldSystem, SCRIPTENV_RUNNING_APP_DATA); - MoveRelearner *moveRelearner = sub_02088DD8(HEAP_ID_32); + MoveRelearner *moveRelearner = MoveRelearner_New(HEAP_ID_32); *moveRelearnerPtr = moveRelearner; - moveRelearner->pokemon = pokemon; + moveRelearner->mon = pokemon; struct SaveData* save = FieldSystem_GetSaveData(ctx->fieldSystem); - moveRelearner->player = Save_PlayerData_GetProfileAddr(save); + moveRelearner->profile = Save_PlayerData_GetProfileAddr(save); moveRelearner->options = Save_PlayerData_GetOptionsAddr(ctx->fieldSystem->saveData); moveRelearner->eligibleMoves = eligibleMoves; @@ -86,7 +86,7 @@ BOOL ScrCmd_Unk0221(struct ScriptContext* ctx) //0221 - todo: RememberMove? u16 mon_idx = ScriptGetVar(ctx); struct Party* party = SaveArray_Party_Get(ctx->fieldSystem->saveData); struct Pokemon* pokemon = Party_GetMonByIndex(party, mon_idx); - u16 *eligibleMoves = GetEligibleLevelUpMoves(pokemon, HEAP_ID_32); + u16 *eligibleMoves = MoveRelearner_GetEligibleLevelUpMoves(pokemon, HEAP_ID_32); sub_02045E74(ctx, 1, pokemon, eligibleMoves); return TRUE; @@ -130,7 +130,7 @@ BOOL ScrCmd_Unk0223(struct ScriptContext* ctx) //0223 - todo: RememberMoveRespon *ret_ptr = 0xFF; } - sub_02088DF0(moveRelearner); + MoveRelearner_Delete(moveRelearner); return FALSE; } @@ -151,6 +151,6 @@ BOOL ScrCmd_Unk0225(struct ScriptContext* ctx) //0225 - todo: TeachMoveResponse? *ret_ptr = 0xFF; } - sub_02088DF0(moveRelearner); + MoveRelearner_Delete(moveRelearner); return FALSE; } diff --git a/arm9/src/unk_02088DD8.c b/arm9/src/unk_02088DD8.c deleted file mode 100644 index 9b2495be3..000000000 --- a/arm9/src/unk_02088DD8.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "global.h" -#include "heap.h" -#include "pokemon.h" -#include "unk_02088DD8.h" - -extern void LoadWotbl_HandleAlternateForm(int species, int form, u16 * wotbl); - -MoveRelearner *sub_02088DD8(HeapID heapId) { - MoveRelearner *returnPointer = AllocFromHeap(heapId, sizeof(MoveRelearner)); - memset(returnPointer, 0, sizeof(MoveRelearner)); - return returnPointer; -} - -void sub_02088DF0(MoveRelearner *moveRelearner) { - FreeToHeap(moveRelearner); -} - -#define WOTBL_END 0xFFFF -#define WOTBL_MOVE_MASK 0x01FF -#define WOTBL_MOVE_SHIFT 0 -#define WOTBL_LVL_MASK 0xFE00 -#define WOTBL_LVL_SHIFT 9 -#define WOTBL_MOVE(x) ((u16)(((x) & WOTBL_MOVE_MASK) >> WOTBL_MOVE_SHIFT)) -#define WOTBL_LVL(x) (/*(u8)*/(((x) & WOTBL_LVL_MASK) >> WOTBL_LVL_SHIFT)) -// i don't know why either. - -u16* GetEligibleLevelUpMoves(struct Pokemon* pokemon, HeapID heapId) { - u16 species = (u16)GetMonData(pokemon, MON_DATA_SPECIES, 0); - u8 form = (u8)GetMonData(pokemon, MON_DATA_FORM, 0); - u8 level = (u8)GetMonData(pokemon, MON_DATA_LEVEL, 0); - u16 moves[4]; - - for (u8 i = 0; i < 4; ++i) { - moves[i] = (u16)GetMonData(pokemon, MON_DATA_MOVE1 + i, 0); - } - - u16 *tableFromFile = AllocFromHeap(heapId, 44); - u16 *returnTable = AllocFromHeap(heapId, 44); - - LoadWotbl_HandleAlternateForm(species, form, tableFromFile); - - for (u8 i = 0, j, k = 0; i < 22; i++) { - if (tableFromFile[i] == WOTBL_END) { - returnTable[k] = WOTBL_END; - break; - } - else { - if (WOTBL_LVL(tableFromFile[i]) > level) continue; - - tableFromFile[i] = WOTBL_MOVE(tableFromFile[i]); - - for (j = 0; j < 4; j++) { - if (tableFromFile[i] == moves[j]) break; - } - if (j != 4) continue; - - if (k >= 0) { - // don't know when that would be false - for (j = 0; j < k; j++) { - if (returnTable[j] == tableFromFile[i]) break; - } - } - if (j != k) continue; - - returnTable[k] = tableFromFile[i]; - k++; - } - } - - FreeToHeap(tableFromFile); - return returnTable; -} - -BOOL sub_02088EF8(u16 *r0) { - return *r0 != 0xFFFF; -} diff --git a/arm9/src/use_item_on_mon.c b/arm9/src/use_item_on_mon.c index f72adeb4d..efc04720f 100644 --- a/arm9/src/use_item_on_mon.c +++ b/arm9/src/use_item_on_mon.c @@ -96,7 +96,7 @@ BOOL CanUseItemOnPokemon(struct Pokemon * pokemon, u16 itemId, s32 moveId, HeapI } if (GetItemAttr_PreloadedItemData(itemData, ITEMATTR_PP_RESTORE_ALL)) { - for (int i = 0; i < MON_MOVES; i++) + for (int i = 0; i < MAX_MON_MOVES; i++) { if (MonMoveCanRestorePP(pokemon, i) == TRUE) { @@ -388,7 +388,7 @@ BOOL UseItemOnPokemon(struct Pokemon * pokemon, u16 itemId, s32 moveIdx, u16 loc else if (GetItemAttr_PreloadedItemData(itemData, ITEMATTR_PP_RESTORE_ALL)) { sp50 = 0; - for (; sp50 < MON_MOVES; sp50++) + for (; sp50 < MAX_MON_MOVES; sp50++) { if (MonMoveRestorePP(pokemon, sp50, (s32)GetItemAttr_PreloadedItemData(itemData, ITEMATTR_PP_RESTORE_PARAM)) == 1) hadEffect = TRUE; @@ -707,7 +707,7 @@ void HealParty(struct Party * party) sp8 = 0; SetMonData(pokemon, MON_DATA_STATUS, &sp8); - for (j = 0; j < MON_MOVES; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { if (MonMoveCanRestorePP(pokemon, j) == 1) MonMoveRestorePP(pokemon, j, PP_RESTORE_ALL); diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index 944b245e6..25937a039 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -3,7 +3,7 @@ // Value and data limits #define MAX_LEVEL 100 -#define MON_MOVES 4 +#define MAX_MON_MOVES 4 #define MAX_EV 100 #define MAX_EV_SUM 510 diff --git a/include/move_relearner.h b/include/move_relearner.h new file mode 100644 index 000000000..17d4d8188 --- /dev/null +++ b/include/move_relearner.h @@ -0,0 +1,23 @@ +#ifndef POKEDIAMOND_MOVE_RELEARNER_H +#define POKEDIAMOND_MOVE_RELEARNER_H + +#include "player_data.h" +#include "pokemon.h" + +typedef struct MoveRelearner { + Pokemon *mon; + PlayerProfile *profile; + Options *options; + u16 *eligibleMoves; + u8 padding[0x5]; + u8 unk15; + u8 unk16; + u8 padding2[1]; +} MoveRelearner; + +MoveRelearner *MoveRelearner_New(HeapID heapId); +void MoveRelearner_Delete(MoveRelearner *moveRelearner); +u16 *MoveRelearner_GetEligibleLevelUpMoves(Pokemon *mon, HeapID heapId); +BOOL sub_02088EF8(const u16 *ptr); + +#endif //POKEDIAMOND_MOVE_RELEARNER_H diff --git a/include/options.h b/include/options.h index 667afaf9b..7f06ef806 100644 --- a/include/options.h +++ b/include/options.h @@ -5,14 +5,14 @@ struct SaveData; -struct Options { +typedef struct Options { u16 textSpeed:4; u16 soundMethod:2; u16 battleStyle:1; u16 battleScene:1; u16 buttonMode:2; u16 frame:5; -}; +} Options; struct Options * Options_New(HeapID heapId); void Options_Copy(struct Options * src, struct Options * dest); diff --git a/include/pokemon.h b/include/pokemon.h index 39e6df22f..a9a748735 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -12,6 +12,17 @@ #include "player_data.h" #include "sound_chatot.h" +#define WOTBL_END 0xFFFF +#define WOTBL_MAX 22 + +#define WOTBL_MOVEID_MASK 0x01FF +#define WOTBL_MOVEID_SHIFT 0 +#define WOTBL_LEVEL_MASK 0xFE00 +#define WOTBL_LEVEL_SHIFT 9 + +#define WOTBL_MOVE(x) ((u16)(((x) & WOTBL_MOVEID_MASK) >> WOTBL_MOVEID_SHIFT)) +#define WOTBL_LVL(x) ((u8)(((x) & WOTBL_LEVEL_MASK) >> WOTBL_LEVEL_SHIFT)) + struct BaseStats { /* 0x00 */ u8 hp; /* 0x01 */ u8 atk; @@ -266,6 +277,7 @@ u32 sub_020690C4(void); u32 sub_020690C8(void); u8 GetBoxMonUnownLetter(struct BoxPokemon * boxmon); u8 GetMonUnownLetter(struct Pokemon * pokemon); +void LoadWotbl_HandleAlternateForm(int species, int form, u16 *wotbl); struct BoxPokemon * sub_020690E4(struct Pokemon * pokemon); u16 GetMonEvolution(struct Party * party, struct Pokemon * pokemon, u32 context, u32 usedItem, u32 * method_ret); diff --git a/include/trainer_data.h b/include/trainer_data.h index 2885fe13c..70abab9d1 100644 --- a/include/trainer_data.h +++ b/include/trainer_data.h @@ -19,7 +19,7 @@ struct TrainerMonSpeciesMoves u16 difficulty; u16 level; u16 species; - u16 moves[MON_MOVES]; + u16 moves[MAX_MON_MOVES]; }; struct TrainerMonSpeciesItem @@ -36,7 +36,7 @@ struct TrainerMonSpeciesItemMoves u16 level; u16 species; u16 item; - u16 moves[MON_MOVES]; + u16 moves[MAX_MON_MOVES]; }; union TrainerMon diff --git a/include/unk_02088DD8.h b/include/unk_02088DD8.h deleted file mode 100644 index 624c3775e..000000000 --- a/include/unk_02088DD8.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef POKEDIAMOND_UNK_02088DD8_H -#define POKEDIAMOND_UNK_02088DD8_H - -#include "unk_020377F0.h" -#include "player_data.h" - -struct Options; -struct Pokemon; - -typedef struct MoveRelearner -{ - struct Pokemon* pokemon; - PlayerProfile* player; - struct Options* options; - u16 *eligibleMoves; - u8 padding[0x5]; - u8 unk15; - u8 unk16; - u8 padding2[1]; -} MoveRelearner; - -MoveRelearner *sub_02088DD8(HeapID heapId); -void sub_02088DF0(MoveRelearner *moveRelearner); -u16* GetEligibleLevelUpMoves(struct Pokemon* pokemon, HeapID heapId); -BOOL sub_02088EF8(u16 *r0); - -#endif From 4453b3aee6b3147137f35b562a1695029b0ba2bd Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 24 Dec 2023 22:51:20 +0000 Subject: [PATCH 2/4] fix build --- arm9/src/move_relearner.c | 1 - include/pokemon.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/arm9/src/move_relearner.c b/arm9/src/move_relearner.c index 32c82de5b..d5657dcfa 100644 --- a/arm9/src/move_relearner.c +++ b/arm9/src/move_relearner.c @@ -12,7 +12,6 @@ void MoveRelearner_Delete(MoveRelearner *moveRelearner) { FreeToHeap(moveRelearner); } -//BUILD FAILS - JUST NOT GONNA DO THIS SHIT RN u16 *MoveRelearner_GetEligibleLevelUpMoves(Pokemon* mon, HeapID heapId) { u16 species = (u16)GetMonData(mon, MON_DATA_SPECIES, NULL); u8 form = (u8)GetMonData(mon, MON_DATA_FORM, NULL); diff --git a/include/pokemon.h b/include/pokemon.h index a9a748735..853f1d860 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -21,7 +21,7 @@ #define WOTBL_LEVEL_SHIFT 9 #define WOTBL_MOVE(x) ((u16)(((x) & WOTBL_MOVEID_MASK) >> WOTBL_MOVEID_SHIFT)) -#define WOTBL_LVL(x) ((u8)(((x) & WOTBL_LEVEL_MASK) >> WOTBL_LEVEL_SHIFT)) +#define WOTBL_LVL(x) (((x) & WOTBL_LEVEL_MASK) >> WOTBL_LEVEL_SHIFT) struct BaseStats { /* 0x00 */ u8 hp; From 071bd9a7121d06c72b910e2c681f28503d1cc3cf Mon Sep 17 00:00:00 2001 From: red031000 Date: Fri, 2 Feb 2024 23:25:04 +0000 Subject: [PATCH 3/4] wotbl to levelUpLearnset --- arm9/global.inc | 2 +- arm9/src/move_relearner.c | 18 +++++++------- arm9/src/pokemon.c | 50 +++++++++++++++++++-------------------- include/pokemon.h | 18 +++++++------- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/arm9/global.inc b/arm9/global.inc index 25025406e..39d30be89 100644 --- a/arm9/global.inc +++ b/arm9/global.inc @@ -4815,7 +4815,7 @@ .extern Pokemon_UpdateArceusForm .extern BoxMon_UpdateArceusForm .extern GetArceusTypeByHeldItemEffect -.extern LoadWotbl_HandleAlternateForm +.extern LoadLevelUpLearnset_HandleAlternateForm .extern sub_02069FB0 .extern sub_0206A014 .extern sub_0206A094 diff --git a/arm9/src/move_relearner.c b/arm9/src/move_relearner.c index d5657dcfa..33a1f46df 100644 --- a/arm9/src/move_relearner.c +++ b/arm9/src/move_relearner.c @@ -22,19 +22,19 @@ u16 *MoveRelearner_GetEligibleLevelUpMoves(Pokemon* mon, HeapID heapId) { moves[i] = (u16)GetMonData(mon, MON_DATA_MOVE1 + i, NULL); } - u16 *tableFromFile = AllocFromHeap(heapId, WOTBL_MAX * 2); - u16 *returnTable = AllocFromHeap(heapId, WOTBL_MAX * 2); + u16 *tableFromFile = AllocFromHeap(heapId, LEVEL_UP_LEARNSET_MAX * 2); + u16 *returnTable = AllocFromHeap(heapId, LEVEL_UP_LEARNSET_MAX * 2); - LoadWotbl_HandleAlternateForm(species, form, tableFromFile); + LoadLevelUpLearnset_HandleAlternateForm(species, form, tableFromFile); - for (u8 i = 0, j, k = 0; i < WOTBL_MAX; i++) { - if (tableFromFile[i] == WOTBL_END) { - returnTable[k] = WOTBL_END; + for (u8 i = 0, j, k = 0; i < LEVEL_UP_LEARNSET_MAX; i++) { + if (tableFromFile[i] == LEVEL_UP_LEARNSET_END) { + returnTable[k] = LEVEL_UP_LEARNSET_END; break; - } else if (WOTBL_LVL(tableFromFile[i]) > level) { + } else if (LEVEL_UP_LEARNSET_LVL(tableFromFile[i]) > level) { continue; } else { - tableFromFile[i] = WOTBL_MOVE(tableFromFile[i]); + tableFromFile[i] = LEVEL_UP_LEARNSET_MOVE(tableFromFile[i]); for (j = 0; j < MAX_MON_MOVES; j++) { if (tableFromFile[i] == moves[j]) { break; @@ -58,5 +58,5 @@ u16 *MoveRelearner_GetEligibleLevelUpMoves(Pokemon* mon, HeapID heapId) { } BOOL sub_02088EF8(const u16 *ptr) { //MoveRelearner_IsValidMove? - return *ptr != WOTBL_END; + return *ptr != LEVEL_UP_LEARNSET_END; } diff --git a/arm9/src/pokemon.c b/arm9/src/pokemon.c index 353b96f13..55893a23a 100644 --- a/arm9/src/pokemon.c +++ b/arm9/src/pokemon.c @@ -43,7 +43,7 @@ u8 Party_MaskMonsWithPokerus(struct Party * party_p, u8 mask); BOOL BoxMon_HasPokerus(struct BoxPokemon * boxmon); BOOL BoxMon_IsImmuneToPokerus(struct BoxPokemon * boxmon); void BoxMon_UpdateArceusForm(struct BoxPokemon * boxmon); -void LoadWotbl_HandleAlternateForm(int species, int form, u16 * wotbl); +void LoadLevelUpLearnset_HandleAlternateForm(int species, int form, u16 *levelUpLearnset); void sub_0206A054(struct BoxPokemon * boxmon, PlayerProfile * a1, u32 pokeball, u32 a3, u32 encounterType, HeapID heapId); BOOL MonHasMove(struct Pokemon * pokemon, u16 move); BOOL sub_0206A144(struct BoxPokemon * boxmon, u32 a1); @@ -2781,27 +2781,27 @@ u16 GetEggSpecies(u16 species) void InitBoxMonMoveset(struct BoxPokemon * boxmon) { BOOL decry; - u16 * wotbl; + u16 *levelUpLearnset; int i; u16 species; u32 form; u8 level; u16 move; - wotbl = AllocFromHeap(HEAP_ID_DEFAULT, 22 * sizeof(u16)); + levelUpLearnset = AllocFromHeap(HEAP_ID_DEFAULT, 22 * sizeof(u16)); decry = AcquireBoxMonLock(boxmon); species = (u16)GetBoxMonData(boxmon, MON_DATA_SPECIES, NULL); form = GetBoxMonData(boxmon, MON_DATA_FORM, NULL); level = (u8)CalcBoxMonLevel(boxmon); - LoadWotbl_HandleAlternateForm(species, (int)form, wotbl); - for (i = 0; wotbl[i] != WOTBL_END; i++) + LoadLevelUpLearnset_HandleAlternateForm(species, (int)form, levelUpLearnset); + for (i = 0; levelUpLearnset[i] != LEVEL_UP_LEARNSET_END; i++) { - if ((wotbl[i] & WOTBL_LEVEL_MASK) > (level << WOTBL_LEVEL_SHIFT)) + if ((levelUpLearnset[i] & LEVEL_UP_LEARNSET_LEVEL_MASK) > (level << LEVEL_UP_LEARNSET_LEVEL_SHIFT)) break; - move = WOTBL_MOVE(wotbl[i]); + move = LEVEL_UP_LEARNSET_MOVE(levelUpLearnset[i]); if (sub_020696A8(boxmon, move) == 0xFFFF) sub_02069718(boxmon, move); } - FreeToHeap(wotbl); + FreeToHeap(levelUpLearnset); ReleaseBoxMonLock(boxmon, decry); } @@ -2888,34 +2888,34 @@ void BoxMonSetMoveInSlot(struct BoxPokemon * boxmon, u16 move, u8 slot) u32 sub_02069818(struct Pokemon * pokemon, u32 * r5, u16 * sp0) { u32 ret = 0; - u16 * wotbl = AllocFromHeap(HEAP_ID_DEFAULT, 22 * sizeof(u16)); + u16 *levelUpLearnset = AllocFromHeap(HEAP_ID_DEFAULT, 22 * sizeof(u16)); u16 species = (u16)GetMonData(pokemon, MON_DATA_SPECIES, NULL); u32 form = GetMonData(pokemon, MON_DATA_FORM, NULL); u8 level = (u8)GetMonData(pokemon, MON_DATA_LEVEL, NULL); - LoadWotbl_HandleAlternateForm(species, (int)form, wotbl); + LoadLevelUpLearnset_HandleAlternateForm(species, (int)form, levelUpLearnset); - if (wotbl[*r5] == 0xFFFF) + if (levelUpLearnset[*r5] == 0xFFFF) { - FreeToHeap(wotbl); + FreeToHeap(levelUpLearnset); return 0; } - while ((wotbl[*r5] & WOTBL_LEVEL_MASK) != (level << WOTBL_LEVEL_SHIFT)) + while ((levelUpLearnset[*r5] & LEVEL_UP_LEARNSET_LEVEL_MASK) != (level << LEVEL_UP_LEARNSET_LEVEL_SHIFT)) { (*r5)++; - if (wotbl[*r5] == 0xFFFF) + if (levelUpLearnset[*r5] == 0xFFFF) { - FreeToHeap(wotbl); + FreeToHeap(levelUpLearnset); return 0; } } - if ((wotbl[*r5] & WOTBL_LEVEL_MASK) == (level << WOTBL_LEVEL_SHIFT)) + if ((levelUpLearnset[*r5] & LEVEL_UP_LEARNSET_LEVEL_MASK) == (level << LEVEL_UP_LEARNSET_LEVEL_SHIFT)) { - *sp0 = WOTBL_MOVE(wotbl[*r5]); + *sp0 = LEVEL_UP_LEARNSET_MOVE(levelUpLearnset[*r5]); (*r5)++; ret = sub_02069698(pokemon, *sp0); } - FreeToHeap(wotbl); + FreeToHeap(levelUpLearnset); return ret; } @@ -3070,13 +3070,13 @@ s8 GetFlavorPreferenceFromPID(u32 personality, int flavor) int Species_LoadLearnsetTable(u16 species, u32 form, u16 * dest) { int i; - u16 * wotbl = AllocFromHeap(HEAP_ID_DEFAULT, 22 * sizeof(u16)); - LoadWotbl_HandleAlternateForm(species, (int)form, wotbl); - for (i = 0; wotbl[i] != WOTBL_END; i++) + u16 * levelUpLearnset = AllocFromHeap(HEAP_ID_DEFAULT, 22 * sizeof(u16)); + LoadLevelUpLearnset_HandleAlternateForm(species, (int)form, levelUpLearnset); + for (i = 0; levelUpLearnset[i] != LEVEL_UP_LEARNSET_END; i++) { - dest[i] = WOTBL_MOVE(wotbl[i]); + dest[i] = LEVEL_UP_LEARNSET_MOVE(levelUpLearnset[i]); } - FreeToHeap(wotbl); + FreeToHeap(levelUpLearnset); return i; } @@ -3290,9 +3290,9 @@ u32 GetArceusTypeByHeldItemEffect(u16 heldEffect) } } -void LoadWotbl_HandleAlternateForm(int species, int form, u16 * wotbl) +void LoadLevelUpLearnset_HandleAlternateForm(int species, int form, u16 *levelUpLearnset) { - ReadWholeNarcMemberByIdPair(wotbl, NARC_POKETOOL_PERSONAL_WOTBL, ResolveMonForm(species, form)); + ReadWholeNarcMemberByIdPair(levelUpLearnset, NARC_POKETOOL_PERSONAL_WOTBL, ResolveMonForm(species, form)); } void sub_02069FB0(struct SaveChatotSoundClip *r7, u32 r5, u16 r4, s32 r6, s32 sp18, u32 sp1C, HeapID heapId) diff --git a/include/pokemon.h b/include/pokemon.h index 853f1d860..74c5037b1 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -12,16 +12,16 @@ #include "player_data.h" #include "sound_chatot.h" -#define WOTBL_END 0xFFFF -#define WOTBL_MAX 22 +#define LEVEL_UP_LEARNSET_END 0xFFFF +#define LEVEL_UP_LEARNSET_MAX 22 -#define WOTBL_MOVEID_MASK 0x01FF -#define WOTBL_MOVEID_SHIFT 0 -#define WOTBL_LEVEL_MASK 0xFE00 -#define WOTBL_LEVEL_SHIFT 9 +#define LEVEL_UP_LEARNSET_MOVEID_MASK 0x01FF +#define LEVEL_UP_LEARNSET_MOVEID_SHIFT 0 +#define LEVEL_UP_LEARNSET_LEVEL_MASK 0xFE00 +#define LEVEL_UP_LEARNSET_LEVEL_SHIFT 9 -#define WOTBL_MOVE(x) ((u16)(((x) & WOTBL_MOVEID_MASK) >> WOTBL_MOVEID_SHIFT)) -#define WOTBL_LVL(x) (((x) & WOTBL_LEVEL_MASK) >> WOTBL_LEVEL_SHIFT) +#define LEVEL_UP_LEARNSET_MOVE(x) ((u16)(((x) & LEVEL_UP_LEARNSET_MOVEID_MASK) >> LEVEL_UP_LEARNSET_MOVEID_SHIFT)) +#define LEVEL_UP_LEARNSET_LVL(x) (((x) & LEVEL_UP_LEARNSET_LEVEL_MASK) >> LEVEL_UP_LEARNSET_LEVEL_SHIFT) struct BaseStats { /* 0x00 */ u8 hp; @@ -277,7 +277,7 @@ u32 sub_020690C4(void); u32 sub_020690C8(void); u8 GetBoxMonUnownLetter(struct BoxPokemon * boxmon); u8 GetMonUnownLetter(struct Pokemon * pokemon); -void LoadWotbl_HandleAlternateForm(int species, int form, u16 *wotbl); +void LoadLevelUpLearnset_HandleAlternateForm(int species, int form, u16 *levelUpLearnset); struct BoxPokemon * sub_020690E4(struct Pokemon * pokemon); u16 GetMonEvolution(struct Party * party, struct Pokemon * pokemon, u32 context, u32 usedItem, u32 * method_ret); From 305fb30028890249de4699e39ae15c8419f772d2 Mon Sep 17 00:00:00 2001 From: red031000 Date: Mon, 5 Feb 2024 01:03:24 +0000 Subject: [PATCH 4/4] address review --- arm9/global.inc | 2 +- arm9/src/move_relearner.c | 10 +++++----- arm9/src/pokemon.c | 6 +++--- arm9/src/scrcmd_move_relearner.c | 2 +- include/constants/pokemon.h | 9 +++++---- include/move_relearner.h | 2 +- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/arm9/global.inc b/arm9/global.inc index 39d30be89..58a1d9663 100644 --- a/arm9/global.inc +++ b/arm9/global.inc @@ -5451,7 +5451,7 @@ .extern MoveRelearner_New .extern MoveRelearner_Delete .extern MoveRelearner_GetEligibleLevelUpMoves -.extern sub_02088EF8 +.extern MoveRelearner_IsValidMove .extern sub_02088F0C .extern sub_02088F4C .extern sub_020892C4 diff --git a/arm9/src/move_relearner.c b/arm9/src/move_relearner.c index 33a1f46df..bf16c256c 100644 --- a/arm9/src/move_relearner.c +++ b/arm9/src/move_relearner.c @@ -13,13 +13,13 @@ void MoveRelearner_Delete(MoveRelearner *moveRelearner) { } u16 *MoveRelearner_GetEligibleLevelUpMoves(Pokemon* mon, HeapID heapId) { - u16 species = (u16)GetMonData(mon, MON_DATA_SPECIES, NULL); - u8 form = (u8)GetMonData(mon, MON_DATA_FORM, NULL); - u8 level = (u8)GetMonData(mon, MON_DATA_LEVEL, NULL); + u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL); + u8 form = GetMonData(mon, MON_DATA_FORM, NULL); + u8 level = GetMonData(mon, MON_DATA_LEVEL, NULL); u16 moves[MAX_MON_MOVES]; for (u8 i = 0; i < MAX_MON_MOVES; ++i) { - moves[i] = (u16)GetMonData(mon, MON_DATA_MOVE1 + i, NULL); + moves[i] = GetMonData(mon, MON_DATA_MOVE1 + i, NULL); } u16 *tableFromFile = AllocFromHeap(heapId, LEVEL_UP_LEARNSET_MAX * 2); @@ -57,6 +57,6 @@ u16 *MoveRelearner_GetEligibleLevelUpMoves(Pokemon* mon, HeapID heapId) { return returnTable; } -BOOL sub_02088EF8(const u16 *ptr) { //MoveRelearner_IsValidMove? +BOOL MoveRelearner_IsValidMove(const u16 *ptr) { return *ptr != LEVEL_UP_LEARNSET_END; } diff --git a/arm9/src/pokemon.c b/arm9/src/pokemon.c index 55893a23a..e072a5321 100644 --- a/arm9/src/pokemon.c +++ b/arm9/src/pokemon.c @@ -2787,7 +2787,7 @@ void InitBoxMonMoveset(struct BoxPokemon * boxmon) u32 form; u8 level; u16 move; - levelUpLearnset = AllocFromHeap(HEAP_ID_DEFAULT, 22 * sizeof(u16)); + levelUpLearnset = AllocFromHeap(HEAP_ID_DEFAULT, MAX_LEARNED_MOVES * sizeof(u16)); decry = AcquireBoxMonLock(boxmon); species = (u16)GetBoxMonData(boxmon, MON_DATA_SPECIES, NULL); form = GetBoxMonData(boxmon, MON_DATA_FORM, NULL); @@ -2888,7 +2888,7 @@ void BoxMonSetMoveInSlot(struct BoxPokemon * boxmon, u16 move, u8 slot) u32 sub_02069818(struct Pokemon * pokemon, u32 * r5, u16 * sp0) { u32 ret = 0; - u16 *levelUpLearnset = AllocFromHeap(HEAP_ID_DEFAULT, 22 * sizeof(u16)); + u16 *levelUpLearnset = AllocFromHeap(HEAP_ID_DEFAULT, MAX_LEARNED_MOVES * sizeof(u16)); u16 species = (u16)GetMonData(pokemon, MON_DATA_SPECIES, NULL); u32 form = GetMonData(pokemon, MON_DATA_FORM, NULL); u8 level = (u8)GetMonData(pokemon, MON_DATA_LEVEL, NULL); @@ -3070,7 +3070,7 @@ s8 GetFlavorPreferenceFromPID(u32 personality, int flavor) int Species_LoadLearnsetTable(u16 species, u32 form, u16 * dest) { int i; - u16 * levelUpLearnset = AllocFromHeap(HEAP_ID_DEFAULT, 22 * sizeof(u16)); + u16 * levelUpLearnset = AllocFromHeap(HEAP_ID_DEFAULT, MAX_LEARNED_MOVES * sizeof(u16)); LoadLevelUpLearnset_HandleAlternateForm(species, (int)form, levelUpLearnset); for (i = 0; levelUpLearnset[i] != LEVEL_UP_LEARNSET_END; i++) { diff --git a/arm9/src/scrcmd_move_relearner.c b/arm9/src/scrcmd_move_relearner.c index d34f73d25..53c4a63aa 100644 --- a/arm9/src/scrcmd_move_relearner.c +++ b/arm9/src/scrcmd_move_relearner.c @@ -50,7 +50,7 @@ BOOL ScrCmd_Unk021F(struct ScriptContext* ctx) { //021F struct Pokemon* pokemon = Party_GetMonByIndex(party, mon_idx); u16 *eligibleMoves = MoveRelearner_GetEligibleLevelUpMoves(pokemon, HEAP_ID_32); - *ret_ptr = (u16)sub_02088EF8(eligibleMoves); + *ret_ptr = (u16)MoveRelearner_IsValidMove(eligibleMoves); FreeToHeap(eligibleMoves); return FALSE; diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index 25937a039..d94e793f0 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -2,10 +2,11 @@ #define POKEDIAMOND_CONSTANTS_POKEMON_H // Value and data limits -#define MAX_LEVEL 100 -#define MAX_MON_MOVES 4 -#define MAX_EV 100 -#define MAX_EV_SUM 510 +#define MAX_LEVEL 100 +#define MAX_MON_MOVES 4 +#define MAX_EV 100 +#define MAX_EV_SUM 510 +#define MAX_LEARNED_MOVES 22 // Pokemon types #define TYPE_NONE 255 diff --git a/include/move_relearner.h b/include/move_relearner.h index 17d4d8188..c36f371d4 100644 --- a/include/move_relearner.h +++ b/include/move_relearner.h @@ -18,6 +18,6 @@ typedef struct MoveRelearner { MoveRelearner *MoveRelearner_New(HeapID heapId); void MoveRelearner_Delete(MoveRelearner *moveRelearner); u16 *MoveRelearner_GetEligibleLevelUpMoves(Pokemon *mon, HeapID heapId); -BOOL sub_02088EF8(const u16 *ptr); +BOOL MoveRelearner_IsValidMove(const u16 *ptr); #endif //POKEDIAMOND_MOVE_RELEARNER_H