- decompile slime and fireball guy

- continue percy decompile
- move entity function definitions to entity header
This commit is contained in:
Behemoth
2020-08-24 18:39:40 +02:00
parent 30137c802f
commit 73497fd8c2
22 changed files with 438 additions and 988 deletions
-3
View File
@@ -1,9 +1,6 @@
#include "global.h"
#include "entity.h"
extern Entity* CreateObject();
extern void CopyPosition();
Entity* CreateObjectWithParent(Entity* parentEnt, u32 subtype, u32 param1, u32 param2) {
Entity* ent;
+121
View File
@@ -0,0 +1,121 @@
#include "global.h"
#include "entity.h"
#include "functions.h"
typedef struct {
s8 h, v;
} PACKED PosOffset;
extern void sub_08045524(Entity*);
void sub_08045178(Entity*, Entity*, int, int);
extern void (*const gUnk_080D17E8[])(Entity*);
extern void (*const gUnk_080D1800[])(Entity*);
extern u8 gUnk_080D180C[4]; // Entity count per form
extern PosOffset gUnk_080D1810[4];
extern u8 gEntCount;
void FireballGuy(Entity* this) {
EnemyFunctionHandler(this, gUnk_080D17E8);
}
void sub_080453A4(Entity* this) {
gUnk_080D1800[this->action](this);
}
void sub_080453BC(Entity* this) {
if (this->currentHealth && this->cutsceneBeh.HALF.LO != this->currentHealth) {
this->action = 2;
} else {
sub_0804AA30(this, gUnk_080D17E8);
}
}
void nullsub_172(void) {
}
void sub_080453E8(Entity* this) {
this->action = 1;
this->actionDelay = 0;
this->spriteSettings.b.draw = 1;
this->nonPlanarMovement = 0x80;
this->cutsceneBeh.HALF.LO = this->currentHealth;
this->field_0x3c |= 0x10;
sub_0804A720(this);
InitializeAnimation(this, 0);
sub_08045524(this);
}
void sub_08045430(Entity* this) {
sub_080AEFE0(this);
GetNextFrame(this);
if (sub_08003FC4(this, 0x1800) == 0)
sub_08045524(this);
}
/* Split FireballGuy into new ones */
void sub_08045454(Entity* this) {
Entity* entities[4];
Entity* ent;
s32 count, i;
PosOffset* off;
u32 tmp;
/* Can we create enough new entities? */
count = gUnk_080D180C[this->entityType.form];
if (72 - count <= gEntCount)
return;
/* Create 2-5 new MiniFireballGuy */
for (i = 0; i < count; i++)
entities[i] = CreateEnemy(0x59, this->entityType.form);
off = gUnk_080D1810;
for (i = 0; i < count; i++) {
ent = entities[i];
ent->attachedEntity = entities[(i + 1) % count];
ent->parent = entities[(i + count - 1) % count];
tmp = 0;
ent->entityType.parameter = 1;
ent->height.HALF.HI = tmp;
ent->hurtBlinkTime = -0x10;
/* Set MiniFireballGuy offset relative to killed slime. */
sub_08045178(this, ent, off->h, off->v);
off++;
}
ent = CreateFx(this, 2, 0);
if (ent)
CopyPosition(this, ent);
DeleteEntity(this);
}
u32 sub_0804A024(Entity*, u32, u32);
void sub_08045524(Entity *this) {
u32 tmp, tmp1, tmp2;
this->field_0x20 = 0x1c000;
tmp = sub_0804A024(this,1,8);
if (tmp != 0xff && (Random() & 3) == 0) {
this->actionDelay = Random() & 3;
this->direction = tmp & 0x18;
} else {
if (this->actionDelay) {
this->actionDelay--;
return;
}
this->actionDelay = Random() & 3;
if (sub_08049FA0(this) == 0 && (Random() & 3)) {
tmp1 = sub_08049EE4(this);
tmp2 = Random() & 8;
tmp2 += 0xfc;
this->direction = (tmp1 + tmp2) & 0x18;
} else {
this->direction = Random() & 0x18;
}
}
}
+95
View File
@@ -0,0 +1,95 @@
#include "global.h"
#include "entity.h"
#include "room.h"
#include "functions.h"
void sub_08045374(Entity*);
extern u32 sub_0806FA04(u32, u32);
extern void sub_0804A720();
extern void sub_080452E4();
extern void sub_0804A9FC();
extern void sub_0804AA30();
extern void ReplaceMonitoredEntity(Entity*, Entity*);
extern void sub_0804A7D4(Entity*);
extern void (*const gUnk_080D17C0[])(Entity*);
extern void (*const gUnk_080D17D8[])(Entity*);
void MiniSlime(Entity* this) {
EnemyFunctionHandler(this, gUnk_080D17C0);
SetChildOffset(this, 0, 1, -8);
}
void sub_08045220(Entity* this) {
gUnk_080D17D8[this->action](this);
}
void sub_08045238(Entity* this) {
if (this->field_0x43)
sub_0804A9FC(this, 0x1c);
sub_0804AA30(this, gUnk_080D17C0);
}
void sub_0804525C(Entity* this) {
Entity* parent = this->parent;
if (this != parent && parent) {
this->field_0x6c.HALF.LO &= 0x7f;
this->parent->attachedEntity = this->attachedEntity;
this->attachedEntity->parent = this->parent;
if (this->field_0x6c.HALF.HI & 0x40)
ReplaceMonitoredEntity(this, parent);
}
sub_0804A7D4(this);
}
void nullsub_22(void) {
}
void sub_080452A4(Entity* this) {
this->action = 1;
this->spriteSettings.b.draw = 1;
this->nonPlanarMovement = 0x100;
sub_0804A720(this);
InitializeAnimation(this, 6);
if (this->entityType.parameter) {
this->action = 2;
this->actionDelay = 1;
} else {
sub_080452E4(this);
}
}
void sub_080452E4(Entity* this) {
this->action = 2;
this->actionDelay = (Random() & 0x1f) + 1;
}
void sub_080452FC(Entity *this) {
u32 cVar2, bVar3;
GetNextFrame(this);
if (--this->actionDelay == 0) {
this->action = 3;
this->actionDelay = 1;
if (0 < this->nonPlanarMovement)
this->actionDelay = sub_0806FA04(0x1000, this->nonPlanarMovement) >> 0x8;
if (sub_08049FA0(this) == 0 && (Random() & 3)) {
cVar2 = sub_08049EE4(this);
bVar3 = Random() & 8;
bVar3 += 0xfc;
this->direction = (cVar2 + bVar3) & 0x18;
} else {
this->direction = Random() & 0x18;
sub_08045374(this);
}
}
}
void sub_08045374(Entity* this) {
sub_080AEF88(this);
GetNextFrame(this);
if (--this->actionDelay == 0)
this->action = 1;
}
+78 -93
View File
@@ -1,5 +1,7 @@
#include "global.h"
#include "entity.h"
#include "room.h"
#include "functions.h"
typedef struct {
void* field_0x0;
@@ -7,28 +9,31 @@ typedef struct {
u8 freezeTime;
} EntityHandler;
extern void EnemyFunctionHandler(Entity*, void*);
extern void SetChildOffset(Entity*, u32, u32, u32);
extern void sub_0804AA30(Entity*, void*);
typedef struct {
s8 h, v;
} PACKED PosOffset;
void sub_08044FF8(Entity*);
void sub_08045178(Entity*, Entity*, int, int);
extern void sub_0804A9FC(Entity*, u32);
extern void sub_0804A720(Entity*);
extern void sub_08044FF8(Entity*);
extern u32 Random(void);
extern u32 sub_0806FA04(u32, u32);
extern u32 sub_08049FA0(Entity*);
extern u32 sub_08049EE4(Entity*);
extern u32 sub_080AEF88(void);
extern void sub_0804A4E4(Entity*, Entity*);
extern u32 sub_080002CC(Entity*, s32, s32);
extern void (*gUnk_080D16BC[])(Entity*);
extern void (*gUnk_080D16A4[])(Entity*);
extern void (*const gUnk_080D16BC[])(Entity*);
extern void (*const gUnk_080D16A4[])(Entity*);
extern u8 gUnk_080D16D0[4]; // Entity count per form
extern PosOffset gUnk_080D16D4[4];
extern u8 gUnk_080D16D0;
extern u8 gEntCount;
extern EntityHandler gUnk_03003DB8;
void Slime(Entity* this)
{
EnemyFunctionHandler(this, &gUnk_080D16A4);
void Slime(Entity* this) {
EnemyFunctionHandler(this, gUnk_080D16A4);
SetChildOffset(this, 0, 1, -12);
}
@@ -40,7 +45,7 @@ void sub_08044F88(Entity* this) {
if ((this->currentHealth != 0) && (this->cutsceneBeh.HALF.LO != this->currentHealth)) {
this->action = 4;
} else {
sub_0804AA30(this, &gUnk_080D16A4);
sub_0804AA30(this, gUnk_080D16A4);
}
if (this->field_0x43 != 0) {
@@ -61,32 +66,21 @@ void sub_08044FC8(Entity* this) {
}
void sub_08044FF8(Entity* this) {
u32 bVar1;
this->action = 2;
bVar1 = Random();
this->actionDelay = (bVar1 & 31) + 30;
this->actionDelay = (Random() & 31) + 30;
this->cutsceneBeh.HALF.LO = this->currentHealth;
}
void sub_08045018(Entity* this) {
u32 cVar1;
u32 param3;
u32 iVar3;
u32 randValue;
GetNextFrame(this);
param3 = this->actionDelay -= 1;
if (param3 == 0) {
if (--this->actionDelay == 0) {
this->action = 3;
this->actionDelay = 1;
if (0 < this->nonPlanarMovement) {
this->actionDelay = sub_0806FA04(4096, this->nonPlanarMovement) >> 8;
}
iVar3 = sub_08049FA0(this);
if ((iVar3 == 0) && (randValue = Random(), (randValue & 3) != 0)) {
cVar1 = sub_08049EE4(this);
this->direction = (cVar1 + 0xfc + (Random() & 8)) & 24;
if (sub_08049FA0(this) == 0 && (Random() & 3)) {
this->direction = (sub_08049EE4(this) + 0xfc + (Random() & 8)) & 24;
return;
}
this->direction = Random() & 24;
@@ -94,74 +88,65 @@ void sub_08045018(Entity* this) {
}
void sub_08045088(Entity* this) {
u8 bVar1;
sub_080AEF88();
sub_080AEF88(this);
GetNextFrame(this);
bVar1 = this->actionDelay -= 1;
if (bVar1 == 0) {
if (--this->actionDelay == 0) {
this->action = 1;
}
}
#ifdef NON_MATCHING
void sub_080450A8(Entity* this)
{
u8 bVar1;
u32 uVar2;
s32 iVar3;
s32 iVar4;
Entity* pEVar5;
Entity** ppEVar6;
s32 dividend;
u32 uVar7;
Entity* local_r6_72;
u32 divisor;
u8* pcVar8;
Entity* local_2c[4];
ppEVar6 = local_2c;
bVar1 = (&gUnk_080D16D0)[(this->entityType).form];
divisor = (u32)bVar1;
if ((int)gUnk_03003DB8.entityCount < (int)(72 - divisor)) {
uVar7 = divisor;
if (bVar1 != 0) {
do {
uVar2 = CreateEnemy(87, this->entityType.form);
*ppEVar6 = uVar2;
ppEVar6 = ppEVar6 + 1;
uVar7 = uVar7 - 1;
} while (uVar7 != 0);
}
pcVar8 = "\x06";
iVar4 = 0;
if (bVar1 != 0) {
do {
local_r6_72 = local_2c[iVar4];
dividend = iVar4 + 1;
iVar3 = Div(dividend, divisor);
local_r6_72->attachedEntity = local_2c[iVar3];
iVar4 = Div(iVar4 + divisor + -1, divisor);
local_r6_72->parent = local_2c[iVar4];
(local_r6_72->entityType).parameter = 1;
local_r6_72->height.WORD = 0;
local_r6_72->hurtBlinkTime = 240;
sub_08045178(this, local_r6_72, *pcVar8, pcVar8[1]);
pcVar8 = pcVar8 + 2;
iVar4 = dividend;
} while (dividend < divisor);
}
pEVar5 = CreateFx(this, 2, 0);
if (pEVar5 != NULL) {
CopyPosition(this, pEVar5);
}
DeleteEnemy(this);
}
}
#else
NAKED
/* Split slime into new ones */
void sub_080450A8(Entity* this) {
asm(".include \"asm/non_matching/slime/sub_080450A8.inc\"");
Entity* entities[4];
Entity* ent;
s32 count, i;
PosOffset* off;
/* Can we create enough new entities? */
count = gUnk_080D16D0[this->entityType.form];
if (72 - count <= gEntCount)
return;
/* Create 2-4 new MiniSlime */
for (i = 0; i < count; i++)
entities[i] = CreateEnemy(0x57, this->entityType.form);
off = gUnk_080D16D4;
for (i = 0; i < count; i++) {
ent = entities[i];
ent->attachedEntity = entities[(i + 1) % count];
ent->parent = entities[(i + count - 1) % count];
ent->entityType.parameter = 1;
ent->height.HALF.HI = 0;
ent->hurtBlinkTime = -0x10;
/* Set MiniSlime offset relative to killed slime. */
sub_08045178(this, ent, off->h, off->v);
off++;
}
ent = CreateFx(this, 2, 0);
if (ent)
CopyPosition(this, ent);
DeleteEntity(this);
}
void sub_08045178(Entity* this, Entity* child, int h, int v) {
int x, y;
if (child == NULL)
return;
sub_0804A4E4(this, child);
if (sub_080002CC(child, h, v))
return;
x = child->x.HALF.HI + h;
if (0 <= x && x < (gRoomControls.roomOriginX + gRoomControls.width))
child->x.HALF.HI = x;
y = child->y.HALF.HI + v;
if (0 <= y && y < (gRoomControls.roomOriginY + gRoomControls.height))
child->y.HALF.HI = y;
}
#endif
+8 -20
View File
@@ -84,24 +84,12 @@ void sub_0806b2b4(Entity* this) {
TextboxNoOverlap(gUnk_08112D50[index], this);
}
void Librari_Fusion(Entity *this)
{
if (this->action == 0) {
this->action++;
this->spriteSettings.b.draw = TRUE;
InitAnimationForceUpdate(this, 9);
}
else {
UpdateAnimationSingleFrame(this);
}
void Librari_Fusion(Entity* this) {
if (this->action == 0) {
this->action++;
this->spriteSettings.b.draw = TRUE;
InitAnimationForceUpdate(this, 9);
} else {
UpdateAnimationSingleFrame(this);
}
}
void Percy_Head(Entity *this) // ???
{
SetExtraSpriteFrame(this, 0, (this->frameSpriteSettings & 0x3f) + 0x13);
SetExtraSpriteFrame(this, 1, (this->frames.all & 0x7f) + 0xb);
SetExtraSpriteFrame(this, 2, this->frameIndex);
SetSpriteSubEntryOffsetData1(this, 2, 1);
SetSpriteSubEntryOffsetData2(this, 2, 0);
sub_0807000C(this);
}
+87 -16
View File
@@ -3,12 +3,28 @@
#include "npc.h"
#include "textbox.h"
#include "functions.h"
#include "flags.h"
extern void sub_0806B41C(Entity*);
void sub_0806B3CC(Entity*);
extern void sub_0806B3CC(Entity*);
extern u32 sub_08002632(Entity*);
extern void sub_0801DFB4(Entity*, u32, u32, u32);
extern u16* gUnk_08001A7C[40];
extern u16 gUnk_08112E54[4];
extern Dialog gUnk_08112E2C[5];
extern SpriteLoadData gUnk_08112E1C;
void Percy_Head(Entity* this) {
SetExtraSpriteFrame(this, 0, (this->frameSpriteSettings & 0x3f) + 0x13);
SetExtraSpriteFrame(this, 1, (this->frames.all & 0x7f) + 0xb);
SetExtraSpriteFrame(this, 2, this->frameIndex);
SetSpriteSubEntryOffsetData1(this, 2, 1);
SetSpriteSubEntryOffsetData2(this, 2, 0);
sub_0807000C(this);
}
void Percy(Entity* this) {
if ((this->flags & 2) != 0) {
sub_0806B41C(this);
@@ -17,20 +33,75 @@ void Percy(Entity* this) {
}
}
void sub_0806B3CC(Entity *this)
{
if (this->action == 0) {
if (!LoadExtraSpriteData(this, &gUnk_08112E1C)) {
return;
void sub_0806B3CC(Entity* this) {
if (this->action == 0) {
if (!LoadExtraSpriteData(this, &gUnk_08112E1C)) {
return;
}
this->action = 1;
InitializeAnimation(this, 0);
sub_08078778(this);
}
this->action = 1;
InitializeAnimation(this, 0);
sub_08078778(this);
}
GetNextFrame(this);
if (this->interactType != 0) {
this->interactType = 0;
TextboxNoOverlapFollow(0);
}
sub_0806ED78(this);
GetNextFrame(this);
if (this->interactType != 0) {
this->interactType = 0;
TextboxNoOverlapFollow(0);
}
sub_0806ED78(this);
}
void sub_0806B41C(Entity* this) {
u16* tmp;
u32 idx;
switch (this->action) {
case 0:
if (LoadExtraSpriteData(this, &gUnk_08112E1C)) {
this->action = 1;
this->spriteSettings.b.draw = 1;
if (this->entityType.parameter == 2) {
CreateFx(this, 0x25, 0);
}
sub_0807DD50(this);
}
break;
case 1:
if (this->interactType == 2) {
this->action = 2;
this->interactType = 0;
InitializeAnimation(this, sub_0806F5A4(GetFacingDirection(this, &gPlayerEntity)) + 4);
idx = sub_08002632(this);
tmp = gUnk_08001A7C[idx];
if (this->field_0x68.HALF.LO == 33)
tmp += 3;
sub_0801DFB4(this, tmp[0], tmp[1], tmp[2]);
gPlayerState.field_0x8b = 3;
} else {
sub_0807DD94(this, 0);
}
break;
case 2:
if (UpdateFuseInteraction(this)) {
this->action = 1;
}
break;
}
}
void sub_0806B4F0(Entity* this) {
ShowNPCDialogue(this, &gUnk_08112E2C[this->entityType.parameter]);
}
void sub_0806B504(Entity* this) {
int idx;
idx = 1;
if (CheckKinstoneFused(0x21)) {
idx = 3;
} else if (!CheckLocalFlag(0x86)) {
idx = 0;
SetLocalFlag(0x86);
}
TextboxNoOverlap(gUnk_08112E54[idx], this);
}
+1 -1
View File
@@ -20,7 +20,7 @@ void sub_0808F658(Entity* this) {
this->direction = 8;
this->nonPlanarMovement = gUnk_08121EB0[(this->entityType).form];
this->field_0x78.HWORD = gRoomControls.roomOriginX - 0x60;
this->field_0x7a.HWORD = gRoomControls.roomOriginX + gRoomControls.filler2[3] + 0x60;
this->field_0x7a.HWORD = gRoomControls.roomOriginX + gRoomControls.width + 0x60;
this->animationState = 0;
this->x.HALF.HI += (Random() & 0xf) << 4;
this->actionDelay = 0;
-2
View File
@@ -1,11 +1,9 @@
#include "global.h"
#include "entity.h"
extern void CopyPosition();
extern void sub_08086A6C();
extern s32 sub_080044EC();
extern void sub_080AEF88();
extern void DeleteThisEntity();
extern u32 Random(void);
extern void (*gUnk_081206C4[99])(Entity*);
-1
View File
@@ -7,7 +7,6 @@ extern u32 sub_080041A0(Entity*, Entity*, u32, u32);
void sub_08099ECC(Entity*);
extern void sub_0805E4E0(Entity*, u32);
extern void sub_0805B390(u32);
extern void CopyPosition(Entity*, Entity*);
extern void (*const gUnk_081237F8[])(Entity*);
-1
View File
@@ -5,7 +5,6 @@
extern BoundingBox gUnk_080FD168;
extern void SetTile(u32, u32, u32);
extern void CopyPosition(Entity*, Entity*);
void Object9E(Entity *this)
{
-2
View File
@@ -2,8 +2,6 @@
#include "entity.h"
extern void sub_080A0640(Entity*);
extern void PositionRelative(Entity*, Entity*, s32, s32);
extern void CopyPosition(Entity*, Entity*);
extern void (*const gUnk_081248C4[])(Entity*);
-2
View File
@@ -2,9 +2,7 @@
#include "entity.h"
extern u32 Random(void);
extern void CopyPosition(Entity*, Entity*);
extern void sub_0806F69C(Entity*);
extern void DeleteEntity(Entity*);
extern void (*const gUnk_08121060[])(Entity*);
extern void (*const gUnk_08121070[])(Entity*);
+1 -1
View File
@@ -2057,7 +2057,7 @@ extern EntityData gUnk_080DE4C8;
void sub_0804CBB0(void) {
if ((gPlayerEntity.y.HALF.HI - gRoomControls.roomOriginY) < (gRoomControls.filler2[4] >> 1)) {
if ((gPlayerEntity.y.HALF.HI - gRoomControls.roomOriginY) < (gRoomControls.height >> 1)) {
if (!CheckLocalFlag(0x17)) {
LoadRoomEntityList(&gUnk_080DE4C8);
}