more decomp and some code cleanup

This commit is contained in:
Seth Barberee 2024-01-12 20:22:32 -08:00
parent 197574e0ed
commit e7e452299f
4 changed files with 268 additions and 280 deletions

View File

@ -5,256 +5,6 @@
.text
thumb_func_start HandleStickyTrap
HandleStickyTrap:
push {r4-r7,lr}
mov r7, r10
mov r6, r9
mov r5, r8
push {r5-r7}
sub sp, 0x5C
str r0, [sp, 0x54]
mov r10, r1
ldr r0, [r1, 0x70]
mov r8, r0
mov r0, r10
movs r1, 0xE
bl HasHeldItem
lsls r0, 24
cmp r0, 0
beq _08080278
ldr r0, _08080274
b _08080300
.align 2, 0
_08080274: .4byte gUnknown_80FDC7C
_08080278:
movs r6, 0
mov r1, r8
ldrb r0, [r1, 0x7]
movs r1, 0x60
add r1, r8
mov r9, r1
cmp r0, 0
beq _080802C8
movs r5, 0
ldr r7, _0808030C
mov r0, sp
str r0, [sp, 0x58]
_08080290:
lsls r4, r5, 2
ldr r0, [r7]
adds r2, r4, r0
ldrb r1, [r2]
movs r0, 0x1
ands r0, r1
cmp r0, 0
beq _080802C2
ldrb r0, [r2, 0x2]
bl IsNotSpecialItem
lsls r0, 24
cmp r0, 0
beq _080802C2
ldr r0, [r7]
adds r2, r0, r4
ldrb r1, [r2]
movs r0, 0x8
ands r0, r1
cmp r0, 0
bne _080802C2
ldr r1, [sp, 0x58]
stm r1!, {r2}
str r1, [sp, 0x58]
adds r6, 0x1
_080802C2:
adds r5, 0x1
cmp r5, 0x13
ble _08080290
_080802C8:
mov r0, r9
ldrb r1, [r0]
movs r0, 0x1
ands r0, r1
cmp r0, 0
beq _080802FA
mov r0, r8
adds r0, 0x62
ldrb r0, [r0]
bl IsNotSpecialItem
lsls r0, 24
cmp r0, 0
beq _080802FA
mov r0, r9
ldrb r1, [r0]
movs r0, 0x8
ands r0, r1
cmp r0, 0
bne _080802FA
lsls r0, r6, 2
add r0, sp
mov r1, r9
str r1, [r0]
adds r6, 0x1
_080802FA:
cmp r6, 0
bne _08080314
ldr r0, _08080310
_08080300:
ldr r2, [r0]
ldr r0, [sp, 0x54]
mov r1, r10
bl sub_80522F4
b _0808034A
.align 2, 0
_0808030C: .4byte gTeamInventoryRef
_08080310: .4byte gUnknown_80FDC40
_08080314:
adds r0, r6, 0
bl DungeonRandInt
ldr r2, _0808035C
lsls r0, 2
mov r1, sp
adds r4, r1, r0
ldr r1, [r4]
adds r0, r2, 0
bl sub_8045BF8
ldr r2, [r4]
ldrb r1, [r2]
movs r0, 0x8
orrs r0, r1
strb r0, [r2]
movs r1, 0xC9
lsls r1, 1
mov r0, r10
bl sub_80421C0
ldr r0, _08080360
ldr r2, [r0]
ldr r0, [sp, 0x54]
mov r1, r10
bl sub_80522F4
_0808034A:
add sp, 0x5C
pop {r3-r5}
mov r8, r3
mov r9, r4
mov r10, r5
pop {r4-r7}
pop {r0}
bx r0
.align 2, 0
_0808035C: .4byte gUnknown_202DE58
_08080360: .4byte gUnknown_80FDC18
thumb_func_end HandleStickyTrap
thumb_func_start HandleSpinTrap
HandleSpinTrap:
push {lr}
cmp r1, 0
beq _08080370
movs r2, 0x1
bl ConfuseStatusTarget
_08080370:
pop {r0}
bx r0
thumb_func_end HandleSpinTrap
thumb_func_start HandleWarpTrap
HandleWarpTrap:
push {lr}
cmp r1, 0
beq _08080382
movs r2, 0
movs r3, 0
bl sub_807D148
_08080382:
pop {r0}
bx r0
thumb_func_end HandleWarpTrap
thumb_func_start HandleSlumberTrap
HandleSlumberTrap:
push {r4,r5,lr}
adds r5, r0, 0
adds r4, r1, 0
cmp r4, 0
beq _080803A8
ldr r1, _080803B0
adds r0, r4, 0
movs r2, 0x1
bl CalculateStatusTurns
adds r2, r0, 0
adds r0, r5, 0
adds r1, r4, 0
movs r3, 0x1
bl sub_8075C58
_080803A8:
pop {r4,r5}
pop {r0}
bx r0
.align 2, 0
_080803B0: .4byte gUnknown_80F4E74
thumb_func_end HandleSlumberTrap
thumb_func_start HandleSlowTrap
HandleSlowTrap:
push {lr}
cmp r1, 0
beq _080803C2
movs r2, 0x1
movs r3, 0x1
bl LowerMovementSpeedTarget
_080803C2:
pop {r0}
bx r0
thumb_func_end HandleSlowTrap
thumb_func_start HandlePoisonTrap
HandlePoisonTrap:
push {lr}
cmp r1, 0
beq _080803D4
movs r2, 0x1
bl PoisonedStatusTarget
_080803D4:
pop {r0}
bx r0
thumb_func_end HandlePoisonTrap
thumb_func_start HandleSelfdestructTrap
HandleSelfdestructTrap:
push {lr}
sub sp, 0x8
adds r2, r1, 0x4
movs r3, 0
str r3, [sp]
ldr r3, _080803F4
str r3, [sp, 0x4]
movs r3, 0x1
bl sub_807DF38
add sp, 0x8
pop {r0}
bx r0
.align 2, 0
_080803F4: .4byte 0x00000212
thumb_func_end HandleSelfdestructTrap
thumb_func_start HandleExplosionTrap
HandleExplosionTrap:
push {lr}
sub sp, 0x8
adds r2, r1, 0x4
movs r3, 0
str r3, [sp]
ldr r3, _08080414
str r3, [sp, 0x4]
movs r3, 0x2
bl sub_807DF38
add sp, 0x8
pop {r0}
bx r0
.align 2, 0
_08080414: .4byte 0x00000212
thumb_func_end HandleExplosionTrap
thumb_func_start HandleGrimyTrap
HandleGrimyTrap:
push {r4-r7,lr}

View File

@ -59,6 +59,7 @@ bool8 AddKecleonWareItem(u8 itemIndex);
void FillInventoryGaps();
bool8 AddHeldItemToInventory(BulkItem* slot);
bool8 IsNotMoneyOrUsedTMItem(u8 id);
bool8 IsNotSpecialItem(u8 id);
s32 FindItemInInventory(u8 id);
bool8 IsHMItem(u8 id);
bool8 IsEdibleItem(u8 id);
@ -82,4 +83,4 @@ s32 SaveTeamInventory(u8 *, u32 size);
s32 sub_8090FEC(s32, u8 *strbuf, u8);
u32 sub_80913E0(Item *slot, u32, struct subStruct_203B240 **);
#endif // GUARD_ITEMS_H
#endif // GUARD_ITEMS_H

View File

@ -5,7 +5,7 @@ extern void sub_80526D0(u8 r0);
extern u8 sub_8045888(Entity *r0);
extern void sub_80523A8(Entity *r0, const char r1[], u8 r2);
extern u8 sub_8052DC0(Entity *);
extern u8 sub_803F428(u32);
extern u8 sub_803F428(Position *);
void sub_805229C(void)
{
@ -33,17 +33,13 @@ void sub_80522E8(Entity *r0, const char r1[])
void sub_80522F4(Entity *r0, Entity *r1, const char r2[])
{
u8 temp;
u32 temp_reg;
u32 temp2;
temp = sub_8045888(r0);
temp_reg = (-temp | temp);
temp2 = temp_reg >> 31;
u8 flag;
flag = sub_8045888(r0) ? TRUE : FALSE;
if(sub_8052DC0(r1) != 0)
{
temp2 = 1;
flag = TRUE;
}
if(temp2 != 0)
if(flag)
{
sub_80523A8(r0, r2, 1);
}
@ -51,35 +47,27 @@ void sub_80522F4(Entity *r0, Entity *r1, const char r2[])
void sub_805232C(Entity *r0, Entity *r1, const char r2[])
{
u8 temp;
u32 temp_reg;
u32 temp2;
temp = sub_8045888(r0);
temp_reg = (-temp | temp);
temp2 = temp_reg >> 31;
u8 flag;
flag = sub_8045888(r0) ? TRUE : FALSE;
if(sub_8052DC0(r1) != 0)
{
temp2 = 1;
flag = TRUE;
}
if(temp2 != 0)
if(flag)
{
sub_80523A8(r0, r2, 0);
}
}
void sub_8052364(Entity *r0, u32 r1, const char r2[])
void sub_8052364(Entity *r0, Position *pos, const char r2[])
{
u8 temp;
u32 temp_reg;
u32 temp2;
temp = sub_8045888(r0);
temp_reg = (-temp | temp);
temp2 = temp_reg >> 31;
if(sub_803F428(r1) != 0)
u8 flag;
flag = sub_8045888(r0) ? TRUE : FALSE;
if(sub_803F428(pos) != 0)
{
temp2 = 1;
flag = TRUE;
}
if(temp2 != 0)
if(flag)
{
sub_80523A8(r0, r2, 1);
}

View File

@ -1,8 +1,12 @@
#include "global.h"
#include "constants/type.h"
#include "constants/trap.h"
#include "structs/str_dungeon.h"
#include "trap.h"
#include "status.h"
#include "code_80521D0.h"
#include "items.h"
#include "code_808417C.h"
#include "dungeon_items.h"
#include "dungeon_random.h"
@ -12,6 +16,7 @@
#include "move_effects_target.h"
extern u8 gAvailablePokemonNames[];
extern u8 gUnknown_202DE58[];
extern u8 *gTrapNames[];
extern u8 *gUnknown_80FC5FC[];
@ -20,13 +25,17 @@ extern u8 *gUnknown_80FDB5C[];
extern u8 *gUnknown_80FDB7C[];
extern u8 *gUnknown_80FD7F4[];
extern u8 *gUnknown_80FD7F8[];
extern s16 gUnknown_80F4E74[];
extern u8 *gUnknown_80FDC18[];
extern u8 *gUnknown_80FDC40[];
extern u8 *gUnknown_80FDC7C[];
extern s16 gUnknown_80F4F84;
extern s16 gUnknown_80F4F86;
extern u32 gUnknown_8106A4C;
extern u32 gUnknown_8106A50;
void sub_8045BF8(u8 *, Item *);
void HandleTripTrap(Entity *pokemon,Entity *target);
void HandleMudTrap(Entity *pokemon,Entity *target);
void HandleStickyTrap(Entity *pokemon,Entity *target);
@ -47,7 +56,7 @@ void HandleWonderTile(Entity *pokemon,Entity *target);
void HandlePokemonTrap(Entity *pokemon,Position *pos);
void sub_806F324(Entity *,s16,u32,u32);
void sub_806F480(Entity *, u32);
extern void sub_80421C0(u32, u32);
extern void sub_80421C0(Entity *, u32);
void sub_804225C(Entity *, Position *, u8);
void sub_8071DA4(Entity *);
extern u8 sub_803F428(Position *pos);
@ -57,6 +66,8 @@ void sub_8049ED4(void);
void sub_80522F4(Entity *r0, Entity *r1, const char r2[]);
u8 sub_803D6FC(void);
Entity *sub_8045684(u8, Position *, u8);
extern void sub_807D148(Entity *pokemon, Entity *target, u32 r2, Position *r3);
extern void sub_807DF38(Entity *pokemon, Entity *target, Position *pos, u32, u8 moveType, s16);
bool8 CanLayTrap(Position *pos)
{
@ -355,3 +366,241 @@ void HandleMudTrap(Entity *pokemon, Entity *target)
}
}
}
#ifdef NONMATCHING
void HandleStickyTrap(Entity *pokemon,Entity *target)
{
EntityInfo *info;
Item *item;
Item *pbVar3;
int index;
int itemCount;
int newIndex;
Item *itemStack [20];
bool32 flag;
info = target->info;
if (HasHeldItem(target,0xe)) {
sub_80522F4(pokemon,target,*gUnknown_80FDC7C);
}
else
{
itemCount = 0;
if (flag = info->isTeamLeader, item = &info->heldItem, flag != '\0') {
for(index = 0; index < 0x14; index++)
{
pbVar3 = &gTeamInventoryRef->teamItems[index];
if ((((pbVar3->flags & 1) != 0) && (IsNotSpecialItem(pbVar3->id))) &&
(gTeamInventoryRef->teamItems[index].flags & 8) == 0) {
itemStack[itemCount] = pbVar3;
itemCount++;
}
}
}
if ((((item->flags & 1) != 0) && (IsNotSpecialItem((info->heldItem).id)))
&& ((item->flags & 8) == 0)) {
itemStack[itemCount] = item;
itemCount = itemCount + 1;
}
if (itemCount == 0) {
sub_80522F4(pokemon,target,*gUnknown_80FDC40);
}
else
{
newIndex = DungeonRandInt(itemCount);
sub_8045BF8(gUnknown_202DE58, itemStack[newIndex]);
itemStack[newIndex]->flags |= 8;
sub_80421C0(target, 0x192);
sub_80522F4(pokemon,target,*gUnknown_80FDC18);
}
}
}
#else
NAKED
void HandleStickyTrap(Entity *pokemon,Entity *target)
{
asm_unified("\tpush {r4-r7,lr}\n"
"\tmov r7, r10\n"
"\tmov r6, r9\n"
"\tmov r5, r8\n"
"\tpush {r5-r7}\n"
"\tsub sp, 0x5C\n"
"\tstr r0, [sp, 0x54]\n"
"\tmov r10, r1\n"
"\tldr r0, [r1, 0x70]\n"
"\tmov r8, r0\n"
"\tmov r0, r10\n"
"\tmovs r1, 0xE\n"
"\tbl HasHeldItem\n"
"\tlsls r0, 24\n"
"\tcmp r0, 0\n"
"\tbeq _08080278\n"
"\tldr r0, _08080274\n"
"\tb _08080300\n"
"\t.align 2, 0\n"
"_08080274: .4byte gUnknown_80FDC7C\n"
"_08080278:\n"
"\tmovs r6, 0\n"
"\tmov r1, r8\n"
"\tldrb r0, [r1, 0x7]\n"
"\tmovs r1, 0x60\n"
"\tadd r1, r8\n"
"\tmov r9, r1\n"
"\tcmp r0, 0\n"
"\tbeq _080802C8\n"
"\tmovs r5, 0\n"
"\tldr r7, _0808030C\n"
"\tmov r0, sp\n"
"\tstr r0, [sp, 0x58]\n"
"_08080290:\n"
"\tlsls r4, r5, 2\n"
"\tldr r0, [r7]\n"
"\tadds r2, r4, r0\n"
"\tldrb r1, [r2]\n"
"\tmovs r0, 0x1\n"
"\tands r0, r1\n"
"\tcmp r0, 0\n"
"\tbeq _080802C2\n"
"\tldrb r0, [r2, 0x2]\n"
"\tbl IsNotSpecialItem\n"
"\tlsls r0, 24\n"
"\tcmp r0, 0\n"
"\tbeq _080802C2\n"
"\tldr r0, [r7]\n"
"\tadds r2, r0, r4\n"
"\tldrb r1, [r2]\n"
"\tmovs r0, 0x8\n"
"\tands r0, r1\n"
"\tcmp r0, 0\n"
"\tbne _080802C2\n"
"\tldr r1, [sp, 0x58]\n"
"\tstm r1!, {r2}\n"
"\tstr r1, [sp, 0x58]\n"
"\tadds r6, 0x1\n"
"_080802C2:\n"
"\tadds r5, 0x1\n"
"\tcmp r5, 0x13\n"
"\tble _08080290\n"
"_080802C8:\n"
"\tmov r0, r9\n"
"\tldrb r1, [r0]\n"
"\tmovs r0, 0x1\n"
"\tands r0, r1\n"
"\tcmp r0, 0\n"
"\tbeq _080802FA\n"
"\tmov r0, r8\n"
"\tadds r0, 0x62\n"
"\tldrb r0, [r0]\n"
"\tbl IsNotSpecialItem\n"
"\tlsls r0, 24\n"
"\tcmp r0, 0\n"
"\tbeq _080802FA\n"
"\tmov r0, r9\n"
"\tldrb r1, [r0]\n"
"\tmovs r0, 0x8\n"
"\tands r0, r1\n"
"\tcmp r0, 0\n"
"\tbne _080802FA\n"
"\tlsls r0, r6, 2\n"
"\tadd r0, sp\n"
"\tmov r1, r9\n"
"\tstr r1, [r0]\n"
"\tadds r6, 0x1\n"
"_080802FA:\n"
"\tcmp r6, 0\n"
"\tbne _08080314\n"
"\tldr r0, _08080310\n"
"_08080300:\n"
"\tldr r2, [r0]\n"
"\tldr r0, [sp, 0x54]\n"
"\tmov r1, r10\n"
"\tbl sub_80522F4\n"
"\tb _0808034A\n"
"\t.align 2, 0\n"
"_0808030C: .4byte gTeamInventoryRef\n"
"_08080310: .4byte gUnknown_80FDC40\n"
"_08080314:\n"
"\tadds r0, r6, 0\n"
"\tbl DungeonRandInt\n"
"\tldr r2, _0808035C\n"
"\tlsls r0, 2\n"
"\tmov r1, sp\n"
"\tadds r4, r1, r0\n"
"\tldr r1, [r4]\n"
"\tadds r0, r2, 0\n"
"\tbl sub_8045BF8\n"
"\tldr r2, [r4]\n"
"\tldrb r1, [r2]\n"
"\tmovs r0, 0x8\n"
"\torrs r0, r1\n"
"\tstrb r0, [r2]\n"
"\tmovs r1, 0xC9\n"
"\tlsls r1, 1\n"
"\tmov r0, r10\n"
"\tbl sub_80421C0\n"
"\tldr r0, _08080360\n"
"\tldr r2, [r0]\n"
"\tldr r0, [sp, 0x54]\n"
"\tmov r1, r10\n"
"\tbl sub_80522F4\n"
"_0808034A:\n"
"\tadd sp, 0x5C\n"
"\tpop {r3-r5}\n"
"\tmov r8, r3\n"
"\tmov r9, r4\n"
"\tmov r10, r5\n"
"\tpop {r4-r7}\n"
"\tpop {r0}\n"
"\tbx r0\n"
"\t.align 2, 0\n"
"_0808035C: .4byte gUnknown_202DE58\n"
"_08080360: .4byte gUnknown_80FDC18");
}
#endif
void HandleSpinTrap(Entity *pokemon, Entity *target)
{
if(target != NULL)
ConfuseStatusTarget(pokemon, target, TRUE);
}
void HandleWarpTrap(Entity *pokemon, Entity *target)
{
if(target != NULL)
sub_807D148(pokemon, target, 0, NULL);
}
void HandleSlumberTrap(Entity *pokemon, Entity *target)
{
s32 turns;
if(target != NULL)
{
turns = CalculateStatusTurns(target, gUnknown_80F4E74, TRUE);
sub_8075C58(pokemon, target, turns, TRUE);
}
}
void HandleSlowTrap(Entity *pokemon, Entity *target)
{
if(target != NULL)
LowerMovementSpeedTarget(pokemon, target, 1, TRUE);
}
void HandlePoisonTrap(Entity *pokemon, Entity *target)
{
if(target != NULL)
PoisonedStatusTarget(pokemon, target, TRUE);
}
void HandleSelfdestructTrap(Entity *pokemon,Entity *target)
{
sub_807DF38(pokemon, target, &target->pos, 1, TYPE_NONE, 0x212);
}
void HandleExplosionTrap(Entity *pokemon,Entity *target)
{
sub_807DF38(pokemon, target, &target->pos, 2, TYPE_NONE, 0x212);
}