decompile sluggula

This commit is contained in:
Behemoth 2020-09-03 23:19:53 +02:00
parent c19fc6d0fa
commit 5b89355daa
5 changed files with 257 additions and 520 deletions

View File

@ -1,478 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.syntax unified
.text
thumb_func_start Sluggula
Sluggula: @ 0x08023B94
push {r4, r5, lr}
adds r5, r0, #0
ldrb r0, [r5, #0xa]
cmp r0, #1
bne _08023BAC
ldr r1, _08023BA8 @ =gUnk_080CBDBC
adds r0, r5, #0
bl EnemyFunctionHandler
b _08023BEC
.align 2, 0
_08023BA8: .4byte gUnk_080CBDBC
_08023BAC:
cmp r0, #0
bne _08023C00
movs r1, #0x36
ldrsh r0, [r5, r1]
cmp r0, #0
bne _08023BD8
adds r0, r5, #0
bl sub_080012DC
adds r1, r0, #0
cmp r1, #0
beq _08023BD8
ldr r0, _08023BD4 @ =gUnk_080012C8
lsls r1, r1, #2
adds r1, r1, r0
ldr r1, [r1]
adds r0, r5, #0
bl _call_via_r1
b _08023C06
.align 2, 0
_08023BD4: .4byte gUnk_080012C8
_08023BD8:
ldr r4, _08023BFC @ =gUnk_080CBDD4
adds r0, r5, #0
bl GetNextFunction
lsls r0, r0, #2
adds r0, r0, r4
ldr r1, [r0]
adds r0, r5, #0
bl _call_via_r1
_08023BEC:
movs r3, #0x10
rsbs r3, r3, #0
adds r0, r5, #0
movs r1, #0
movs r2, #1
bl SetChildOffset
b _08023C06
.align 2, 0
_08023BFC: .4byte gUnk_080CBDD4
_08023C00:
adds r0, r5, #0
bl sub_08023E10
_08023C06:
pop {r4, r5, pc}
thumb_func_start sub_08023C08
sub_08023C08: @ 0x08023C08
push {lr}
ldr r2, _08023C1C @ =gUnk_080CBDEC
ldrb r1, [r0, #0xc]
lsls r1, r1, #2
adds r1, r1, r2
ldr r1, [r1]
bl _call_via_r1
pop {pc}
.align 2, 0
_08023C1C: .4byte gUnk_080CBDEC
thumb_func_start sub_08023C20
sub_08023C20: @ 0x08023C20
push {r4, lr}
adds r4, r0, #0
adds r0, #0x43
ldrb r0, [r0]
cmp r0, #0
beq _08023C34
adds r0, r4, #0
movs r1, #0x1c
bl sub_0804A9FC
_08023C34:
ldrb r0, [r4, #0xa]
cmp r0, #1
bne _08023C48
ldr r1, _08023C44 @ =gUnk_080CBDBC
adds r0, r4, #0
bl sub_0804AA30
b _08023C50
.align 2, 0
_08023C44: .4byte gUnk_080CBDBC
_08023C48:
ldr r1, _08023C54 @ =gUnk_080CBDD4
adds r0, r4, #0
bl sub_0804AA30
_08023C50:
pop {r4, pc}
.align 2, 0
_08023C54: .4byte gUnk_080CBDD4
thumb_func_start nullsub_137
nullsub_137: @ 0x08023C58
bx lr
.align 2, 0
thumb_func_start sub_08023C5C
sub_08023C5C: @ 0x08023C5C
push {r4, lr}
adds r4, r0, #0
bl sub_0804A720
movs r0, #1
strb r0, [r4, #0xc]
bl Random
movs r1, #0x30
ands r0, r1
adds r0, #0xb4
strb r0, [r4, #0xe]
bl Random
movs r1, #0x18
ands r0, r1
strb r0, [r4, #0x15]
lsrs r0, r0, #3
strb r0, [r4, #0x14]
ldrb r1, [r4, #0x14]
adds r0, r4, #0
bl InitializeAnimation
pop {r4, pc}
thumb_func_start sub_08023C8C
sub_08023C8C: @ 0x08023C8C
push {r4, lr}
adds r4, r0, #0
bl ProcessMovement
adds r0, r4, #0
bl GetNextFrame
adds r0, r4, #0
bl sub_08023E54
ldrb r0, [r4, #0xe]
subs r0, #1
strb r0, [r4, #0xe]
lsls r0, r0, #0x18
cmp r0, #0
bne _08023CDC
adds r0, r4, #0
adds r0, #0x5a
ldrb r0, [r0]
cmp r0, #1
beq _08023CBC
movs r0, #8
strb r0, [r4, #0xe]
b _08023CDC
_08023CBC:
bl Random
movs r1, #0x30
ands r0, r1
adds r0, #0xb4
strb r0, [r4, #0xe]
adds r0, r4, #0
bl sub_08023E9C
ldrb r0, [r4, #0x15]
lsrs r0, r0, #3
strb r0, [r4, #0x14]
ldrb r1, [r4, #0x14]
adds r0, r4, #0
bl InitializeAnimation
_08023CDC:
pop {r4, pc}
.align 2, 0
thumb_func_start sub_08023CE0
sub_08023CE0: @ 0x08023CE0
push {r4, lr}
adds r4, r0, #0
ldrb r0, [r4, #0xc]
cmp r0, #1
beq _08023D48
cmp r0, #1
bgt _08023CF4
cmp r0, #0
beq _08023CFA
b _08023DC0
_08023CF4:
cmp r0, #2
beq _08023D6E
b _08023DC0
_08023CFA:
adds r0, r4, #0
bl sub_0804A720
ldrb r1, [r4, #0xb]
cmp r1, #1
bne _08023D1C
movs r0, #2
strb r0, [r4, #0xc]
ldrb r0, [r4, #0xe]
cmp r0, #0
bne _08023D12
strb r1, [r4, #0xe]
_08023D12:
ldrb r0, [r4, #0x18]
movs r1, #3
orrs r0, r1
strb r0, [r4, #0x18]
b _08023D20
_08023D1C:
movs r0, #1
strb r0, [r4, #0xc]
_08023D20:
ldr r0, _08023D44 @ =0x0000FF80
strh r0, [r4, #0x36]
ldrb r2, [r4, #0x19]
movs r1, #0x3f
adds r0, r1, #0
ands r0, r2
movs r2, #0x40
orrs r0, r2
strb r0, [r4, #0x19]
ldrb r0, [r4, #0x1b]
ands r1, r0
orrs r1, r2
strb r1, [r4, #0x1b]
adds r0, r4, #0
movs r1, #6
bl InitializeAnimation
b _08023E0A
.align 2, 0
_08023D44: .4byte 0x0000FF80
_08023D48:
adds r0, r4, #0
movs r1, #1
movs r2, #0x20
bl PlayerInRange
cmp r0, #0
beq _08023E0A
movs r0, #2
strb r0, [r4, #0xc]
ldrb r0, [r4, #0xe]
cmp r0, #0
bne _08023D64
movs r0, #8
strb r0, [r4, #0xe]
_08023D64:
ldrb r0, [r4, #0x18]
movs r1, #3
orrs r0, r1
strb r0, [r4, #0x18]
b _08023E0A
_08023D6E:
ldrb r0, [r4, #0xe]
cmp r0, #0
beq _08023D94
subs r0, #1
strb r0, [r4, #0xe]
lsls r0, r0, #0x18
cmp r0, #0
bne _08023E0A
ldr r0, _08023D90 @ =0x0000012D
bl EnqueueSFX
adds r0, r4, #0
movs r1, #4
bl InitializeAnimation
b _08023E0A
.align 2, 0
_08023D90: .4byte 0x0000012D
_08023D94:
movs r1, #0xc0
lsls r1, r1, #5
adds r0, r4, #0
bl sub_08003FC4
cmp r0, #0
bne _08023E0A
movs r0, #3
strb r0, [r4, #0xc]
ldrb r1, [r4, #0x18]
subs r0, #7
ands r0, r1
movs r1, #1
orrs r0, r1
strb r0, [r4, #0x18]
movs r0, #0x84
bl EnqueueSFX
adds r0, r4, #0
bl UpdateSpriteForCollisionLayer
b _08023E0A
_08023DC0:
adds r0, r4, #0
bl GetNextFrame
adds r2, r4, #0
adds r2, #0x5a
ldrb r1, [r2]
cmp r1, #0
beq _08023E0A
movs r0, #0x80
ands r0, r1
cmp r0, #0
beq _08023DF2
movs r0, #0x10
movs r1, #1
bl CreateEnemy
adds r1, r0, #0
cmp r1, #0
beq _08023E0A
adds r0, r4, #0
bl sub_0804A4E4
bl DeleteThisEntity
b _08023E0A
_08023DF2:
ldr r1, _08023E0C @ =gUnk_080CBDF4
ldrb r0, [r2]
subs r0, #1
adds r0, r0, r1
ldrb r0, [r0]
lsls r0, r0, #0x18
asrs r0, r0, #0x18
ldrh r1, [r4, #0x32]
adds r0, r0, r1
movs r1, #0
strh r0, [r4, #0x32]
strb r1, [r2]
_08023E0A:
pop {r4, pc}
.align 2, 0
_08023E0C: .4byte gUnk_080CBDF4
thumb_func_start sub_08023E10
sub_08023E10: @ 0x08023E10
push {r4, lr}
adds r4, r0, #0
ldrb r0, [r4, #0xc]
cmp r0, #0
bne _08023E36
movs r0, #1
strb r0, [r4, #0xc]
adds r2, r4, #0
adds r2, #0x29
ldrb r1, [r2]
subs r0, #9
ands r0, r1
movs r1, #6
orrs r0, r1
strb r0, [r2]
adds r0, r4, #0
movs r1, #5
bl InitializeAnimation
_08023E36:
adds r0, r4, #0
bl GetNextFrame
adds r0, r4, #0
adds r0, #0x5a
ldrb r1, [r0]
movs r0, #0x80
ands r0, r1
cmp r0, #0
beq _08023E50
adds r0, r4, #0
bl DeleteEntity
_08023E50:
pop {r4, pc}
.align 2, 0
thumb_func_start sub_08023E54
sub_08023E54: @ 0x08023E54
push {r4, r5, lr}
adds r4, r0, #0
ldrb r0, [r4, #0xf]
adds r1, r0, #1
strb r1, [r4, #0xf]
lsls r0, r0, #0x18
lsrs r0, r0, #0x18
cmp r0, #0x1b
bls _08023E94
movs r0, #0
strb r0, [r4, #0xf]
movs r0, #0x10
movs r1, #2
bl CreateEnemy
adds r5, r0, #0
cmp r5, #0
beq _08023E94
ldrb r0, [r4, #0x14]
lsls r0, r0, #1
ldr r1, _08023E98 @ =gUnk_080CBDF7
adds r0, r0, r1
movs r2, #0
ldrsb r2, [r0, r2]
lsls r2, r2, #0x10
movs r3, #1
ldrsb r3, [r0, r3]
lsls r3, r3, #0x10
adds r0, r4, #0
adds r1, r5, #0
bl PositionRelative
_08023E94:
pop {r4, r5, pc}
.align 2, 0
_08023E98: .4byte gUnk_080CBDF7
thumb_func_start sub_08023E9C
sub_08023E9C: @ 0x08023E9C
push {r4, r5, r6, lr}
adds r5, r0, #0
bl Random
adds r6, r0, #0
adds r0, r5, #0
bl sub_08049FA0
cmp r0, #0
bne _08023EC2
movs r0, #1
ands r0, r6
cmp r0, #0
beq _08023EC2
adds r0, r5, #0
bl sub_08049EE4
adds r0, #4
b _08023F1C
_08023EC2:
adds r0, r5, #0
movs r1, #1
bl sub_08049FDC
cmp r0, #0
beq _08023F0A
movs r0, #6
ands r0, r6
cmp r0, #0
beq _08023F0A
ldr r0, _08023F00 @ =gUnk_020000B0
ldr r1, [r0]
adds r0, r5, #0
bl GetFacingDirection
ldrb r2, [r5, #0x15]
subs r1, r0, r2
cmp r1, #0
beq _08023F22
adds r0, r1, #4
movs r3, #0x1f
ands r0, r3
cmp r0, #8
bls _08023F22
ands r1, r3
cmp r1, #0xf
bhi _08023F04
adds r0, r2, #0
adds r0, #8
b _08023F1C
.align 2, 0
_08023F00: .4byte gUnk_020000B0
_08023F04:
adds r0, r2, #0
subs r0, #8
b _08023F1C
_08023F0A:
ldr r4, _08023F24 @ =gUnk_080CBDFF
lsrs r0, r6, #4
movs r1, #3
bl __modsi3
adds r0, r0, r4
ldrb r0, [r0]
ldrb r1, [r5, #0x15]
adds r0, r0, r1
_08023F1C:
movs r1, #0x18
ands r0, r1
strb r0, [r5, #0x15]
_08023F22:
pop {r4, r5, r6, pc}
.align 2, 0
_08023F24: .4byte gUnk_080CBDFF

View File

@ -0,0 +1,28 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.section .rodata
gUnk_080CBE02:: @ 080CBE02
.incbin "baserom.gba", 0x0CBE02, 0x0000019
gUnk_080CBE1B:: @ 080CBE1B
.incbin "baserom.gba", 0x0CBE1B, 0x0000019
gUnk_080CBE34:: @ 080CBE34
.incbin "baserom.gba", 0x0CBE34, 0x0000019
gUnk_080CBE4D:: @ 080CBE4D
.incbin "baserom.gba", 0x0CBE4D, 0x0000019
gUnk_080CBE66:: @ 080CBE66
.incbin "baserom.gba", 0x0CBE66, 0x0000024
gUnk_080CBE8A:: @ 080CBE8A
.incbin "baserom.gba", 0x0CBE8A, 0x0000014
gUnk_080CBE9E:: @ 080CBE9E
.incbin "baserom.gba", 0x0CBE9E, 0x0000006
gUnk_080CBEA4:: @ 080CBEA4
.incbin "baserom.gba", 0x0CBEA4, 0x0000020

View File

@ -3,48 +3,6 @@
.section .rodata
gUnk_080CBDBC:: @ 080CBDBC
.incbin "baserom.gba", 0x0CBDBC, 0x0000018
gUnk_080CBDD4:: @ 080CBDD4
.incbin "baserom.gba", 0x0CBDD4, 0x0000018
gUnk_080CBDEC:: @ 080CBDEC
.incbin "baserom.gba", 0x0CBDEC, 0x0000008
gUnk_080CBDF4:: @ 080CBDF4
.incbin "baserom.gba", 0x0CBDF4, 0x0000003
gUnk_080CBDF7:: @ 080CBDF7
.incbin "baserom.gba", 0x0CBDF7, 0x0000008
gUnk_080CBDFF:: @ 080CBDFF
.incbin "baserom.gba", 0x0CBDFF, 0x0000003
gUnk_080CBE02:: @ 080CBE02
.incbin "baserom.gba", 0x0CBE02, 0x0000019
gUnk_080CBE1B:: @ 080CBE1B
.incbin "baserom.gba", 0x0CBE1B, 0x0000019
gUnk_080CBE34:: @ 080CBE34
.incbin "baserom.gba", 0x0CBE34, 0x0000019
gUnk_080CBE4D:: @ 080CBE4D
.incbin "baserom.gba", 0x0CBE4D, 0x0000019
gUnk_080CBE66:: @ 080CBE66
.incbin "baserom.gba", 0x0CBE66, 0x0000024
gUnk_080CBE8A:: @ 080CBE8A
.incbin "baserom.gba", 0x0CBE8A, 0x0000014
gUnk_080CBE9E:: @ 080CBE9E
.incbin "baserom.gba", 0x0CBE9E, 0x0000006
gUnk_080CBEA4:: @ 080CBEA4
.incbin "baserom.gba", 0x0CBEA4, 0x0000020
gUnk_080CBEC4:: @ 080CBEC4
.incbin "baserom.gba", 0x0CBEC4, 0x0000018

View File

@ -341,6 +341,7 @@ SECTIONS {
src/enemy/moldorm.o(.text);
src/enemy/enemyE.o(.text);
src/enemy/moldworm.o(.text);
src/enemy/sluggula.o(.text);
asm/sluggula.o(.text);
asm/pesto.o(.text);
asm/puffstool.o(.text);
@ -934,6 +935,8 @@ SECTIONS {
data/animations/enemyE.o(.rodata);
src/enemy/moldworm.o(.rodata);
data/animations/moldworm.o(.rodata);
src/enemy/sluggula.o(.rodata);
data/animations/sluggula.o(.rodata);
data/data_080CBDBC.o(.rodata);
src/enemy.o(.rodata);
data/data_080D3D94.o(.rodata);

226
src/enemy/sluggula.c Normal file
View File

@ -0,0 +1,226 @@
#include "enemy.h"
#include "entity.h"
#include "functions.h"
extern s32 sub_080012DC(Entity*);
bool32 PlayerInRange(Entity*, u32, u32);
void sub_08023E10(Entity*);
void sub_08023E54(Entity*);
void sub_08023E9C(Entity*);
void sub_0804A4E4(Entity*, Entity*);
extern void (*const gUnk_080012C8[])(Entity*);
extern void (*const gUnk_080CBDBC[])(Entity*);
extern void (*const gUnk_080CBDD4[])(Entity*);
extern void (*const gUnk_080CBDEC[])(Entity*);
extern const s8 gUnk_080CBDF4[];
extern const s8 gUnk_080CBDF7[];
extern const s8 gUnk_080CBDFF[];
void Sluggula(Entity* this) {
if (this->entityType.form == 1) {
EnemyFunctionHandler(this, gUnk_080CBDBC);
SetChildOffset(this, 0, 1, -0x10);
} else if (this->entityType.form == 0) {
if (this->height.HALF.HI == 0) {
u32 idx = sub_080012DC(this);
if (idx != 0) {
gUnk_080012C8[idx](this);
return;
}
}
gUnk_080CBDD4[GetNextFunction(this)](this);
SetChildOffset(this, 0, 1, -0x10);
} else {
sub_08023E10(this);
}
}
void sub_08023C08(Entity* this) {
gUnk_080CBDEC[this->action](this);
}
void sub_08023C20(Entity* this) {
if (this->field_0x43)
sub_0804A9FC(this, 0x1c);
if (this->entityType.form == 1) {
sub_0804AA30(this, gUnk_080CBDBC);
} else {
sub_0804AA30(this, gUnk_080CBDD4);
}
}
void nullsub_137(Entity* this) {
/* ... */
}
void sub_08023C5C(Entity* this) {
sub_0804A720(this);
this->action = 1;
this->actionDelay = (Random() & 0x30) + 0xb4;
this->direction = DirectionRound(Random());
this->animationState = this->direction >> 3;
InitializeAnimation(this, this->animationState);
}
void sub_08023C8C(Entity* this) {
ProcessMovement(this);
GetNextFrame(this);
sub_08023E54(this);
if (--this->actionDelay == 0) {
if (this->frames.all != 1) {
this->actionDelay = 8;
} else {
this->actionDelay = (Random() & 0x30) + 0xb4;
sub_08023E9C(this);
this->animationState = this->direction >> 3;
InitializeAnimation(this, this->animationState);
}
}
}
void sub_08023CE0(Entity* this) {
switch (this->action) {
case 0:
sub_0804A720(this);
if (this->entityType.parameter == 1) {
this->action = 2;
if (this->actionDelay == 0) {
this->actionDelay = 1;
}
this->spriteSettings.b.draw = 3;
} else {
this->action = 1;
}
this->height.HALF.HI = -0x80;
this->spriteRendering.b3 = 1;
this->spriteOrientation.flipY = 1;
InitializeAnimation(this, 6);
break;
case 1:
if (PlayerInRange(this, 1, 0x20)) {
this->action = 2;
if (this->actionDelay == 0) {
this->actionDelay = 8;
}
this->spriteSettings.b.draw = 3;
}
break;
case 2:
if (this->actionDelay != 0) {
if (--this->actionDelay == 0) {
EnqueueSFX(0x12d);
InitializeAnimation(this, 4);
}
} else if (!sub_08003FC4(this, 0x1800)) {
this->action = 3;
this->spriteSettings.b.draw = 1;
EnqueueSFX(0x84);
UpdateSpriteForCollisionLayer(this);
}
break;
default:
GetNextFrame(this);
if (this->frames.all) {
if (this->frames.all & 0x80) {
Entity* ent = CreateEnemy(0x10, 1);
if (ent) {
sub_0804A4E4(this, ent);
DeleteThisEntity();
}
} else {
this->y.HALF.HI += gUnk_080CBDF4[this->frames.all - 1];
this->frames.all = 0;
}
}
break;
}
}
void sub_08023E10(Entity* this) {
if (this->action == 0) {
this->action = 1;
this->spritePriority.b0 = 6;
InitializeAnimation(this, 5);
}
GetNextFrame(this);
if (this->frames.all & 0x80)
DeleteEntity(this);
}
void sub_08023E54(Entity* this) {
Entity* ent;
if (this->field_0xf++ > 27) {
this->field_0xf = 0;
ent = CreateEnemy(0x10, 2);
if (ent) {
const s8* ptr = &gUnk_080CBDF7[this->animationState * 2];
PositionRelative(this, ent, ptr[0] << 0x10, ptr[1] << 0x10);
}
}
}
extern Entity* gUnk_020000B0;
void sub_08023E9C(Entity* this) {
u32 uVar3 = Random();
if (sub_08049FA0(this) == 0 && (uVar3 & 1)) {
this->direction = DirectionRoundUp(sub_08049EE4(this));
} else if (sub_08049FDC(this, 1) && (uVar3 & 6)) {
u32 uVar3 = GetFacingDirection(this, gUnk_020000B0) - this->direction;
if (uVar3 != 0 && ((uVar3 + 4) & 0x1f) > 8) {
if ((uVar3 & 0x1f) < 0x10) {
this->direction = DirectionRound(this->direction + 8);
} else {
this->direction = DirectionRound(this->direction - 8);
}
}
} else {
this->direction = DirectionRound(this->direction + gUnk_080CBDFF[(s32)(uVar3 >> 4) % 3]);
}
}
// clang-format off
void (*const gUnk_080CBDBC[])(Entity*) = {
sub_08023C08,
sub_08023C20,
sub_08001324,
sub_0804A7D4,
sub_08001242,
nullsub_137,
};
void (*const gUnk_080CBDD4[])(Entity*) = {
sub_08023CE0,
sub_08023C20,
sub_08001324,
sub_0804A7D4,
sub_08001242,
nullsub_137,
};
void (*const gUnk_080CBDEC[])(Entity*) = {
sub_08023C5C,
sub_08023C8C,
};
const s8 gUnk_080CBDF4[] = {
1, 2, 6,
};
const s8 gUnk_080CBDF7[] = {
0, 2, -2, 2, 0, -2, 2, 2
};
const s8 gUnk_080CBDFF[] = {
0, -8, 8,
};
// clang-format on