diff options
author | Akira Akashi <rubenru09@aol.com> | 2021-07-01 03:49:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-01 03:49:48 +0100 |
commit | ca53a63f5a7570d6393e13f0fb2c2bafb1adeb38 (patch) | |
tree | bf5b3f918ae19bac1c0548b5e51db033310e5fb9 /arm9/src | |
parent | 93557dd264b6a3c69f00366888e4d35a0d5b0a7c (diff) | |
parent | 9427ad1dde34ad16643423e001f1126015e5ef27 (diff) |
Merge pull request #419 from SNBeast/master
Decompile unk_02088DD8.s
Diffstat (limited to 'arm9/src')
-rw-r--r-- | arm9/src/scrcmd_24.c | 8 | ||||
-rw-r--r-- | arm9/src/unk_02088DD8.c | 76 |
2 files changed, 78 insertions, 6 deletions
diff --git a/arm9/src/scrcmd_24.c b/arm9/src/scrcmd_24.c index b38ed05a..bfa737be 100644 --- a/arm9/src/scrcmd_24.c +++ b/arm9/src/scrcmd_24.c @@ -10,10 +10,6 @@ extern struct UnkStruct_02037CF0* FUN_02037CF0(u32 heap_id, struct UnkSavStruct8 extern u8 FUN_02037D5C(struct UnkStruct_02037CF0*); extern void FUN_02038864(struct UnkSavStruct80*, struct UnkStruct_02088DD8*); extern BOOL FUN_0203BC04(struct ScriptContext* ctx); -extern struct UnkStruct_02088DD8* FUN_02088DD8(u32 heap_id); -extern void FUN_02088DF0(struct UnkStruct_02037CF0*); -extern void* FUN_02088DF8(struct Pokemon* pokemon, u32 heap_id); -extern BOOL FUN_02088EF8(void*); THUMB_FUNC BOOL ScrCmd_Unk01C6(struct ScriptContext* ctx) { @@ -57,7 +53,7 @@ THUMB_FUNC BOOL ScrCmd_Unk021F(struct ScriptContext* ctx) u16 mon_idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); struct PlayerParty* party = SavArray_PlayerParty_get(ctx->unk80->saveBlock2); struct Pokemon* pokemon = GetPartyMonByIndex(party, mon_idx); - void* unk_ptr = FUN_02088DF8(pokemon, 32); + void* unk_ptr = GetEligibleLevelUpMoves(pokemon, 32); *ret_ptr = (u16)FUN_02088EF8(unk_ptr); FreeToHeap(unk_ptr); @@ -96,7 +92,7 @@ THUMB_FUNC BOOL ScrCmd_Unk0221(struct ScriptContext* ctx) u16 mon_idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); struct PlayerParty* party = SavArray_PlayerParty_get(ctx->unk80->saveBlock2); struct Pokemon* pokemon = GetPartyMonByIndex(party, mon_idx); - void* unk_ptr = FUN_02088DF8(pokemon, 32); + void* unk_ptr = GetEligibleLevelUpMoves(pokemon, 32); FUN_02045E74(ctx, 1, pokemon, unk_ptr); return TRUE; diff --git a/arm9/src/unk_02088DD8.c b/arm9/src/unk_02088DD8.c new file mode 100644 index 00000000..b4633d25 --- /dev/null +++ b/arm9/src/unk_02088DD8.c @@ -0,0 +1,76 @@ +#include "global.h" +#include "heap.h" +#include "pokemon.h" +#include "unk_02088DD8.h" + +extern void LoadWotbl_HandleAlternateForme(int species, int forme, u16 * wotbl); + +THUMB_FUNC struct UnkStruct_02088DD8* FUN_02088DD8(u32 heap_id) { + struct UnkStruct_02088DD8 *returnPointer = AllocFromHeap(heap_id, sizeof(struct UnkStruct_02088DD8)); + __builtin__clear(returnPointer, sizeof(struct UnkStruct_02088DD8)); + return returnPointer; +} + +THUMB_FUNC void FUN_02088DF0(struct UnkStruct_02037CF0 *r0) { + FreeToHeap(r0); +} + +#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. + +THUMB_FUNC u16* GetEligibleLevelUpMoves(struct Pokemon* pokemon, u32 heap_id) { + u16 species = (u16)GetMonData(pokemon, MON_DATA_SPECIES, 0); + u8 forme = (u8)GetMonData(pokemon, MON_DATA_FORME, 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(heap_id, 44); + u16 *returnTable = AllocFromHeap(heap_id, 44); + + LoadWotbl_HandleAlternateForme(species, forme, 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; +} + +THUMB_FUNC BOOL FUN_02088EF8(u16 *r0) { + return *r0 != 0xFFFF; +} |