sub_806AD3C

This commit is contained in:
DizzyEggg 2024-11-22 17:12:03 +01:00
parent d4d2d809dd
commit a64495b6b3
9 changed files with 116 additions and 274 deletions

View File

@ -7,264 +7,6 @@
thumb_func_start sub_806ACE8
sub_806ACE8:
push {r4,r5,lr}
adds r4, r1, 0
ldr r0, [r0, 0x70]
mov r12, r0
movs r5, 0xEF
movs r2, 0x8C
lsls r2, 1
add r2, r12
movs r3, 0x3
_0806ACFA:
ldrb r1, [r2]
adds r0, r5, 0
ands r0, r1
strb r0, [r2]
adds r2, 0x8
subs r3, 0x1
cmp r3, 0
bge _0806ACFA
movs r2, 0x9C
lsls r2, 1
add r2, r12
ldrb r0, [r2]
movs r3, 0xEF
ands r3, r0
movs r5, 0
strb r3, [r2]
ldrh r1, [r4, 0x2]
movs r0, 0xB0
lsls r0, 1
cmp r1, r0
bne _0806AD2E
movs r1, 0x10
adds r0, r3, 0
orrs r0, r1
strb r0, [r2]
b _0806AD36
_0806AD2E:
ldrb r0, [r4]
movs r1, 0x10
orrs r0, r1
strb r0, [r4]
_0806AD36:
pop {r4,r5}
pop {r0}
bx r0
thumb_func_end sub_806ACE8
thumb_func_start sub_806AD3C
sub_806AD3C:
push {r4-r7,lr}
mov r7, r10
mov r6, r9
mov r5, r8
push {r5-r7}
ldr r4, _0806AE1C
add sp, r4
ldr r0, _0806AE20
ldr r0, [r0]
ldr r1, _0806AE24
adds r4, r0, r1
mov r0, sp
movs r1, 0
bl sub_803D808
str r0, [sp, 0x200]
movs r7, 0
cmp r7, r0
bge _0806ADEC
mov r6, sp
adds r7, r0, 0
_0806AD66:
adds r0, r6, 0
bl ExtractSpeciesIndex
strh r0, [r4]
adds r0, r6, 0
bl ExtractLevel
strh r0, [r4, 0x2]
adds r0, r4, 0x4
movs r2, 0
ldrsh r1, [r4, r2]
movs r3, 0x2
ldrsh r2, [r4, r3]
bl sub_8072AC8
ldrh r0, [r4, 0x4]
cmp r0, 0
bne _0806AD90
movs r0, 0xB8
lsls r0, 1
strh r0, [r4, 0x4]
_0806AD90:
movs r1, 0
ldrsh r0, [r4, r1]
movs r2, 0x2
ldrsh r1, [r4, r2]
bl sub_806C444
strh r0, [r4, 0xC]
movs r5, 0
movs r3, 0xE
adds r3, r4
mov r9, r3
movs r0, 0x10
adds r0, r4
mov r8, r0
movs r1, 0x14
adds r1, r4
mov r10, r1
_0806ADB2:
movs r2, 0
ldrsh r0, [r4, r2]
movs r3, 0x2
ldrsh r1, [r4, r3]
adds r2, r5, 0
bl sub_806C488
mov r2, r9
adds r1, r2, r5
strb r0, [r1]
movs r3, 0
ldrsh r0, [r4, r3]
movs r2, 0x2
ldrsh r1, [r4, r2]
adds r2, r5, 0
bl sub_806C4D4
mov r3, r8
adds r1, r3, r5
strb r0, [r1]
adds r5, 0x1
cmp r5, 0x1
ble _0806ADB2
mov r4, r10
adds r6, 0x8
subs r7, 0x1
cmp r7, 0
bne _0806AD66
ldr r7, [sp, 0x200]
_0806ADEC:
cmp r7, 0x3F
bgt _0806ADFC
movs r0, 0
_0806ADF2:
strh r0, [r4]
adds r4, 0x14
adds r7, 0x1
cmp r7, 0x3F
ble _0806ADF2
_0806ADFC:
movs r7, 0
ldr r4, _0806AE28
ldr r3, _0806AE20
ldr r2, _0806AE2C
movs r1, 0
_0806AE06:
ldr r0, [r3]
adds r0, r2
adds r0, r7
strb r1, [r0]
adds r7, 0x1
cmp r7, r4
ble _0806AE06
movs r0, 0x1
mov r10, r0
movs r7, 0
b _0806AE94
.align 2, 0
_0806AE1C: .4byte 0xfffffdfc
_0806AE20: .4byte gDungeon
_0806AE24: .4byte 0x00002f3c
_0806AE28: .4byte 0x000001a7
_0806AE2C: .4byte 0x0000363c
_0806AE30:
movs r2, 0x1
negs r2, r2
mov r8, r2
mov r9, r8
ldr r3, [sp, 0x200]
cmp r3, 0
ble _0806AE7A
mov r5, sp
adds r6, r3, 0
_0806AE42:
adds r0, r5, 0
bl ExtractSpeciesIndex
lsls r0, 16
asrs r4, r0, 16
ldr r1, _0806AECC
ldr r0, [r1]
ldr r2, _0806AED0
adds r0, r2
adds r0, r4
ldrb r0, [r0]
cmp r0, 0
bne _0806AE72
adds r0, r5, 0
bl ExtractLevel
adds r1, r0, 0
adds r0, r4, 0
bl CalculateEXPGain
cmp r9, r0
bge _0806AE72
mov r9, r0
mov r8, r4
_0806AE72:
adds r5, 0x8
subs r6, 0x1
cmp r6, 0
bne _0806AE42
_0806AE7A:
mov r3, r8
cmp r3, 0
blt _0806AE9A
ldr r1, _0806AECC
ldr r0, [r1]
ldr r2, _0806AED0
adds r0, r2
add r0, r8
mov r3, r10
strb r3, [r0]
movs r0, 0x2
add r10, r0
adds r7, 0x1
_0806AE94:
ldr r1, [sp, 0x200]
cmp r7, r1
blt _0806AE30
_0806AE9A:
movs r7, 0
ldr r5, _0806AECC
ldr r4, _0806AED0
movs r3, 0x1
ldr r2, _0806AED4
_0806AEA4:
ldr r0, [r5]
adds r0, r4
adds r1, r0, r7
ldrb r0, [r1]
cmp r0, 0
bne _0806AEB2
strb r3, [r1]
_0806AEB2:
adds r7, 0x1
cmp r7, r2
ble _0806AEA4
movs r3, 0x81
lsls r3, 2
add sp, r3
pop {r3-r5}
mov r8, r3
mov r9, r4
mov r10, r5
pop {r4-r7}
pop {r0}
bx r0
.align 2, 0
_0806AECC: .4byte gDungeon
_0806AED0: .4byte 0x0000363c
_0806AED4: .4byte 0x000001a7
thumb_func_end sub_806AD3C
thumb_func_start sub_806AED8
sub_806AED8:
push {r4-r7,lr}

View File

@ -310,7 +310,7 @@ _08073532:
bl sub_80838EC
adds r0, r7, 0
adds r1, r5, 0
bl sub_806ACE8
bl MarkLastUsedMonMove
b _0807359C
_0807354A:
movs r3, 0

View File

@ -31,9 +31,11 @@ bool8 IsIQSkillSet(u8 *IQSkillFlags, u32 IQSkill);
void SetDefaultIQSkills(u8 *param_1, bool8 enableSelfCurer);
void sub_808F468(PokemonStruct1 *param_1, EvolveStatus *evolveStatus, u8 param_3);
u32 sub_808F734(PokemonStruct1 *pokemon, s16 _species);
s16 ExtractSpeciesIndex(UnkDungeonGlobal_unk1CD98 *r0);
s32 ExtractLevel(UnkDungeonGlobal_unk1CD98 *r0);
// pokemon_3.s
extern void CreatePokemonInfoTabScreen(u32, s16, u32 *, u32 *, u32);
extern void sub_808FF20(u32 *, PokemonStruct1 *, bool8);
#endif // GUARD_POKEMON_3_H
#endif // GUARD_POKEMON_3_H

View File

@ -305,6 +305,17 @@ typedef struct unkDungeonE260
/* 0x2 */ u16 unk2;
} unkDungeonE260;
// Size: 0x14
typedef struct unkDungeon2F3C
{
/* 0x0 */ s16 species;
/* 0x2 */ s16 level;
/* 0x4 */ u16 moves[MAX_MON_MOVES];
/* 0xC */ u16 unkC;
/* 0xE */ u8 unkE[2];
/* 0x10 */ u8 unk10[2];
} unkDungeon2F3C;
// size: 0x1CEDC
typedef struct Dungeon
{
@ -342,11 +353,10 @@ typedef struct Dungeon
unkDungeon644 unk644;
EntityInfo unk69C[MAX_TEAM_MEMBERS];
EntityInfo unkEBC[DUNGEON_MAX_WILD_POKEMON_BODY_SIZE];
u8 fill2F3C[0x343C - 0x2F3C];
/* 0x2F3C */ unkDungeon2F3C unk2F3C[64];
/* 0x343C */ UnkDungeonGlobal_unk1CD98 unk343C[32];
u8 fill353C[0x363c-0x353c];
/* 0x363C */ u8 expYieldRankings[NUM_MONSTERS];
u8 fill37D9[0x37E4 - 0x37D9];
/* 0x363C */ u8 expYieldRankings[MONSTER_MAX];
/* 0x37E4 */ s32 unk37E4;
u8 fill37E8[4];
/* 0x37EC */ u8 unk37EC;

View File

@ -8,13 +8,12 @@
#include "dungeon_random.h"
#include "bg_palette_buffer.h"
#include "code_800D090.h"
#include "pokemon_3.h"
#include "game_options.h"
#include "constants/dungeon.h"
extern void sub_80901D8(DungeonLocation *param_1,DungeonLocation *param_2);
extern s32 sub_80902C8(u8 dungeon);
extern s16 ExtractSpeciesIndex(UnkDungeonGlobal_unk1CD98 *r0);
extern u32 ExtractLevel(UnkDungeonGlobal_unk1CD98 *r0);
extern void sub_808E9C4(UnkDungeonGlobal_unk1CD98 *r0, s16 r1);
extern bool8 sub_80848EC(void);
extern u8 GetFloorType(void);

View File

@ -838,3 +838,91 @@ void EndAbilityImmuneStatus(Entity *attacker, Entity *target)
}
}
}
void MarkLastUsedMonMove(Entity *entity, Move *move)
{
s32 i;
EntityInfo *entInfo = GetEntInfo(entity);
for (i = 0; i < MAX_MON_MOVES; i++) {
entInfo->moves.moves[i].moveFlags &= ~(MOVE_FLAG_LAST_USED);
}
entInfo->moves.struggleMoveFlags &= ~(MOVE_FLAG_LAST_USED);
if (move->id == MOVE_STRUGGLE) {
entInfo->moves.struggleMoveFlags |= MOVE_FLAG_LAST_USED;
}
else {
move->moveFlags |= MOVE_FLAG_LAST_USED;
}
}
extern s32 sub_803D808(UnkDungeonGlobal_unk1CD98 *strPtr, s32 id);
extern void sub_8072AC8(u16 *param_1, s16 species, s32 param_3);
s32 sub_806C444(s16 species, s32 level);
s32 sub_806C488(s16 species, s32 level, s32 categoryIndex);
s32 sub_806C4D4(s16 species, s32 level, s32 categoryIndex);
void sub_806AD3C(void)
{
s32 r10;
s32 i, j;
UnkDungeonGlobal_unk1CD98 sp[64];
unkDungeon2F3C *structPtr = gDungeon->unk2F3C;
s32 var_24 = sub_803D808(sp, 0);
for (i = 0; i < var_24; structPtr++, i++) {
structPtr->species = ExtractSpeciesIndex(&sp[i]);
structPtr->level = ExtractLevel(&sp[i]);
sub_8072AC8(structPtr->moves, structPtr->species, structPtr->level);
if (structPtr->moves[0] == MOVE_NOTHING) {
structPtr->moves[0] = MOVE_BLOWBACK;
}
structPtr->unkC = sub_806C444(structPtr->species, structPtr->level);
for (j = 0; j < 2; j++) {
structPtr->unkE[j] = sub_806C488(structPtr->species, structPtr->level, j);
structPtr->unk10[j] = sub_806C4D4(structPtr->species, structPtr->level, j);
}
}
for (; i < 64; structPtr++, i++) {
structPtr->species = 0;
}
for (i = 0; i < MONSTER_MAX; i++) {
gDungeon->expYieldRankings[i] = 0;
}
r10 = 1;
for (i = 0; i < var_24; i++) {
s32 j;
s32 expSpecies = -1;
s32 expGain = -1;
for (j = 0; j < var_24; j++) {
s32 species = ExtractSpeciesIndex(&sp[j]);
if (gDungeon->expYieldRankings[species] == 0) {
s32 level = ExtractLevel(&sp[j]);
s32 exp = CalculateEXPGain(species, level);
if (expGain < exp) {
expGain = exp;
expSpecies = species;
}
}
}
if (expSpecies < 0)
break;
gDungeon->expYieldRankings[expSpecies] = r10;
r10 += 2;
}
for (i = 0; i < MONSTER_MAX; i++) {
if (gDungeon->expYieldRankings[i] == 0) {
gDungeon->expYieldRankings[i] = 1;
}
}
}

View File

@ -19,6 +19,7 @@
#include "moves.h"
#include "math.h"
#include "pokemon.h"
#include "pokemon_3.h"
#include "pokemon_mid.h"
#include "status_checks_1.h"
#include "structs/dungeon_entity.h"
@ -207,9 +208,8 @@ extern void nullsub_87(Entity *);
extern void nullsub_86(Entity *);
extern void sub_8041E0C(Entity *);
extern void sub_8041DD8(Entity *r0, s32 r1); // NOTE: is s16 in another file
extern s32 sub_803D870(void *, u32);
extern s32 sub_803D870(UnkDungeonGlobal_unk1CD98 *strPtr, s32 id);
extern bool8 sub_806AA0C(s32, u32);
u32 ExtractSpeciesIndex(PokemonStruct1 **r0); // TODO: look more into this and fix it.
void MuzzleTarget(Entity *pokemon, Entity *target)
{
@ -241,7 +241,7 @@ void TransformStatusTarget(Entity * pokemon, Entity * target)
s32 index;
EntityInfo *entityInfo;
OpenedFile *sprite;
PokemonStruct1 *auStack544[128];
UnkDungeonGlobal_unk1CD98 auStack544[64];
if (!EntityExists(target))
return;
@ -260,7 +260,7 @@ void TransformStatusTarget(Entity * pokemon, Entity * target)
sprite = NULL;
for (index = 0; index < DUNGEON_MAX_POKEMON; index++) {
species = ExtractSpeciesIndex(&auStack544[DungeonRandInt(iVar5) * 2]);
species = ExtractSpeciesIndex(&auStack544[DungeonRandInt(iVar5)]);
apparentID_s16 = GetMonsterApparentID(target, species);
apparentID = apparentID_s16;

View File

@ -65,7 +65,7 @@ extern Entity *GetMonsterAtPos(DungeonPos *pos);
extern Entity *sub_80696FC(Entity *);
extern Entity *sub_806977C(Entity *);
extern void sub_806F2BC(Entity *attacker, Entity *target, u8 moveType, s32 a2, struct DamageStruct *dmgStruct);
extern void sub_806ACE8(Entity *entity, Move *move);
extern void MarkLastUsedMonMove(Entity *entity, Move *move);
extern s32 sub_8057070(Move *move);
extern bool8 MoveRequiresCharging(Entity* pokemon,u16 param_2);
extern s32 sub_800ED20(u16 param_1);
@ -2091,7 +2091,7 @@ bool8 TryUseChosenMove(struct Entity *attacker, u32 r6, s32 itemId, u32 var_30,
}
if (moveUsable && r6) {
sub_806ACE8(attacker, move);
MarkLastUsedMonMove(attacker, move);
}
if (GetEntInfo(attacker)->muzzled.muzzled == TRUE && FailsWhileMuzzled(move->id)) {

View File

@ -274,7 +274,7 @@ s32 GetUnownIndex(s16 index)
return 0;
}
u32 ExtractSpeciesIndex(PokemonStruct1 *r0)
s16 ExtractSpeciesIndex(UnkDungeonGlobal_unk1CD98 *r0)
{
return r0->unk0 & 0x000001ff;
}
@ -291,9 +291,10 @@ void sub_808E9D8(PokemonStruct1 *r0, s32 r1, s16 r2)
r0->unk0 = r2_32 | (r1 << 9) ;
}
u32 ExtractLevel(PokemonStruct1 *r0)
s32 ExtractLevel(UnkDungeonGlobal_unk1CD98 *r0)
{
return (r0->unk0 >> 9);
u16 bitfield = r0->unk0;
return (bitfield >> 9);
}
// Unused