Merge pull request #458 from EllipticEllipsis/code_08049D30

Decompile the file formerly known as `code_08049D30`
This commit is contained in:
notyourav 2022-03-20 19:28:07 -07:00 committed by GitHub
commit f57f815879
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 417 additions and 1175 deletions

File diff suppressed because it is too large Load Diff

View File

@ -52,7 +52,7 @@ extern void LoadResources(void);
extern bool32 LoadSwapGFX(Entity*, u16, u32);
extern void MenuFadeIn(u32, u32);
extern void ModBombs(s32);
extern u32 PlayerInRange(Entity*, u32, u32);
extern bool32 PlayerInRange(Entity*, u32, s32);
extern bool32 ProcessMovement1(Entity*);
extern bool32 ProcessMovement12(Entity*);
extern bool32 ProcessMovement2(Entity*);
@ -130,15 +130,16 @@ extern void sub_0803C0AC(Entity*);
extern void sub_08049CF4(Entity*);
extern Entity* sub_08049DF4(u32);
extern u32 sub_08049EE4(Entity*);
extern u32 sub_08049F1C(Entity*, Entity*, u32);
extern u32 sub_08049F84(Entity*, u32);
extern u32 sub_08049FA0(Entity*);
extern u32 sub_08049FDC(Entity*, u32);
extern bool32 sub_08049F1C(Entity*, Entity*, s32);
extern bool32 sub_08049F84(Entity*, s32);
extern bool32 sub_08049FA0(Entity*);
extern bool32 sub_08049FDC(Entity*, u32);
extern u32 sub_0804A024(Entity*, u32, u32);
extern u32 sub_0804A044(Entity*, Entity*, u32);
extern void sub_0804A4E4(Entity*, Entity*);
extern void sub_0804A720(Entity*);
extern void sub_0804AA1C(Entity*);
extern void sub_0804C128();
extern void sub_0804C128(void);
extern u32 sub_080542AC(u32);
extern void sub_08054564();
extern void sub_08054570(void);

View File

@ -83,6 +83,16 @@ typedef struct {
static_assert(sizeof(RoomVars) == 0xCC);
extern RoomVars gRoomVars;
typedef struct {
u8 area;
u8 room;
u16 unk_02;
u32 unk_04;
} RoomMemory;
extern RoomMemory* gUnk_020354B0;
extern RoomMemory gRoomMemory[];
// Packets used to store which entities to load in a room
typedef struct {
u8 kind;

View File

@ -428,7 +428,7 @@ SECTIONS {
src/enemy/enemy66.o(.text);
/* END enemies */
src/code_08049CD4.o(.text); /* enemyUtils.c */
asm/code_08049D30.o(.text);
src/code_08049DF4.o(.text);
src/enemyUtils.o(.text);
src/createEnemy.o(.text);
src/enterPortalSubtask.o(.text);

View File

@ -1,25 +1,76 @@
#define NENT_DEPRECATED
#include "global.h"
extern u32* gUnk_020354B0;
extern u32 gRoomMemory;
#include "room.h"
extern void MemFill32(u32, void*, u32);
void sub_08049DCC(RoomMemory*);
RoomMemory* sub_08049D88(void);
void ClearRoomMemory(void) {
MemFill32(0xFFFFFFFF, &gRoomMemory, 0x40);
gUnk_020354B0 = &gRoomMemory;
MemFill32(0xFFFFFFFF, gRoomMemory, 0x40);
gUnk_020354B0 = gRoomMemory;
}
void sub_08049CF4(u8* arg0) {
u8 field_0x6c = *(arg0 + 0x6c);
void sub_08049CF4(GenericEntity* ent) {
u8 field_0x6c = ent->field_0x6c.HALF.LO;
if (field_0x6c & 0x80) {
*(gUnk_020354B0 + 1) |= 1 << (field_0x6c & 0x1f);
gUnk_020354B0->unk_04 |= 1 << (field_0x6c & 0x1f);
}
}
u32 sub_08049D1C(u32 arg0) {
u32 bitmask = *(gUnk_020354B0 + 1) >> arg0;
u32 bitmask = gUnk_020354B0->unk_04 >> arg0;
u32 output = 1;
output &= ~bitmask;
return output;
}
void UpdateRoomTracker(void) {
gUnk_020354B0 = gRoomMemory;
do {
if (gUnk_020354B0->area == gRoomControls.area && gUnk_020354B0->room == gRoomControls.room) {
sub_08049DCC(gUnk_020354B0);
return;
}
gUnk_020354B0++;
} while (gUnk_020354B0 < gRoomMemory + 8);
gUnk_020354B0 = sub_08049D88();
}
RoomMemory* sub_08049D88(void) {
RoomMemory* rm = gRoomMemory;
RoomMemory* r1 = rm + 1;
do {
if (r1->unk_02 > rm->unk_02) {
rm = r1;
}
r1++;
} while (r1 < gRoomMemory + 8);
rm->area = gRoomControls.area;
rm->room = gRoomControls.room;
rm->unk_02 = 0xFFFF;
rm->unk_04 = 0;
sub_08049DCC(rm);
return rm;
}
void sub_08049DCC(RoomMemory* rm) {
RoomMemory* r1 = gRoomMemory;
do {
if (r1->unk_02 < rm->unk_02) {
r1->unk_02++;
}
r1++;
} while (r1 < gRoomMemory + 8);
rm->unk_02 = 0;
}

324
src/code_08049DF4.c Normal file
View File

@ -0,0 +1,324 @@
#define NENT_DEPRECATED
#include "asm.h"
#include "global.h"
#include "entity.h"
#include "functions.h"
#include "map.h"
#include "player.h"
#include "room.h"
extern Entity* gUnk_020000B0;
extern Entity* (*const gUnk_080D3BE8[])(void);
extern void ReplaceMonitoredEntity(Entity*, Entity*);
Entity* sub_08049DF4(u32 arg0) {
if (gUnk_020000B0 != NULL) {
return gUnk_020000B0;
}
return gUnk_080D3BE8[arg0]();
}
Entity* sub_08049E18(void) {
if ((gPlayerState.field_0x3c[0] == 0) && !(gPlayerState.flags & 0x22189b75)) {
gUnk_020000B0 = &gPlayerEntity;
return &gPlayerEntity;
}
return NULL;
}
Entity* sub_08049E4C(void) {
if ((gPlayerState.field_0x3c[0] == 0) && !(gPlayerState.flags & 0x22189bf5)) {
gUnk_020000B0 = &gPlayerEntity;
return &gPlayerEntity;
}
return NULL;
}
Entity* sub_08049E80(void) {
if ((gPlayerState.field_0x3c[0] != 0) || !(gPlayerState.flags & 0x80)) {
return NULL;
}
gUnk_020000B0 = &gPlayerEntity;
return &gPlayerEntity;
}
Entity* sub_08049EB0(void) {
if ((gPlayerState.field_0x3c[0] == 0) && !(gPlayerState.flags & 0x80190)) {
gUnk_020000B0 = &gPlayerEntity;
return &gPlayerEntity;
}
return NULL;
}
u32 sub_08049EE4(Entity* ent) {
GenericEntity* genEnt = (GenericEntity*)ent;
u16 tempLO = genEnt->field_0x70.HALF.LO + 4 * genEnt->field_0x6e.HALF.LO;
u16 tempHI = genEnt->field_0x70.HALF.HI + 4 * genEnt->field_0x6e.HALF.HI;
return CalculateDirectionTo(genEnt->base.x.HALF.HI, genEnt->base.y.HALF.HI, tempLO, tempHI);
}
bool32 sub_08049F1C(Entity* entA, Entity* entB, s32 maxDist) {
if ((entA->collisionLayer & entB->collisionLayer) != 0) {
s32 xDiff = entB->x.HALF.HI - entA->x.HALF.HI;
s32 yDiff = entB->y.HALF.HI - entA->y.HALF.HI;
s32 maxDistSq = maxDist * maxDist;
s32 distSq = xDiff * xDiff + yDiff * yDiff;
if (maxDistSq >= distSq) {
return TRUE;
}
}
return FALSE;
}
bool32 PlayerInRange(Entity* ent, u32 arg1, s32 maxDist) {
Entity* tempEnt = sub_08049DF4(arg1);
if (tempEnt == NULL) {
return FALSE;
} else {
return sub_08049F1C(ent, tempEnt, maxDist);
}
}
u32 sub_08049F84(Entity* ent, s32 arg2) {
Entity* target = sub_08049DF4(arg2);
if (target == NULL) {
return 0xFF;
} else {
return GetFacingDirection(ent, target);
}
}
bool32 sub_08049FA0(Entity* ent) {
GenericEntity* genEnt = (GenericEntity*)ent;
u32 temp = 8 * genEnt->field_0x6e.HALF.LO;
if (temp >= genEnt->base.x.HALF.HI - genEnt->field_0x70.HALF_U.LO) {
temp = 8 * genEnt->field_0x6e.HALF.HI;
if (temp >= genEnt->base.y.HALF.HI - genEnt->field_0x70.HALF_U.HI) {
return TRUE;
}
}
return FALSE;
}
bool32 sub_08049FDC(Entity* ent, u32 arg1) {
u32 temp;
GenericEntity* genEnt = (GenericEntity*)ent;
GenericEntity* tempEnt = (GenericEntity*)sub_08049DF4(arg1);
if (tempEnt != NULL) {
temp = 8 * genEnt->field_0x6e.HALF.LO;
if (temp >= tempEnt->base.x.HALF.HI - genEnt->field_0x70.HALF_U.LO) {
temp = 8 * genEnt->field_0x6e.HALF.HI;
if (temp >= tempEnt->base.y.HALF.HI - genEnt->field_0x70.HALF_U.HI) {
return TRUE;
}
}
}
return FALSE;
}
u32 sub_0804A024(Entity* ent, u32 arg1, u32 arg2) {
Entity* tempEnt = sub_08049DF4(arg1);
if (tempEnt == NULL) {
return 0xFF;
} else {
return sub_0804A044(ent, tempEnt, arg2);
}
}
u32 sub_0804A168(Entity*, Entity*, LayerStruct*);
u32 sub_0804A318(Entity*, Entity*, LayerStruct*);
u32 sub_0804A044(Entity* entA, Entity* entB, u32 arg2) {
LayerStruct* layer;
s32 ret;
s32 yDiff;
s32 xDiff;
s32 flags;
if ((entB->collisionLayer & entA->collisionLayer) != 0) {
flags = 0;
xDiff = entB->x.HALF.HI + entB->hitbox->offset_x - entA->x.HALF.HI - entA->hitbox->offset_x;
if (arg2 >= xDiff + (arg2 >> 1)) {
flags |= 1;
}
if (arg2 << 1 >= xDiff + arg2) {
flags |= 2;
}
yDiff = entB->y.HALF.HI + entB->hitbox->offset_y - entA->y.HALF.HI - entA->hitbox->offset_y;
if (arg2 >= yDiff + (arg2 >> 1)) {
flags |= 4;
}
if (arg2 << 1 >= yDiff + arg2) {
flags |= 8;
}
//! @bug flags & 5 can never equal 0xA
if (flags && ((flags & 5) != 0xA)) {
layer = GetLayerByIndex(entA->collisionLayer);
if (xDiff < 0) {
xDiff = -xDiff;
}
if (yDiff < 0) {
yDiff = -yDiff;
}
if (xDiff < yDiff) {
if (flags & 1) {
ret = sub_0804A168(entA, entB, layer);
if (ret != 0xFF) {
return ret;
}
}
if (!(flags & 4)) {
return 0xFF;
}
ret = sub_0804A318(entA, entB, layer);
} else {
if (flags & 4) {
ret = sub_0804A318(entA, entB, layer);
if (ret != 0xFF) {
return ret;
}
}
if (!(flags & 1)) {
return 0xFF;
}
ret = sub_0804A168(entA, entB, layer);
}
if (ret != 0xFF) {
return ret;
}
}
}
return 0xFF;
}
bool32 sub_0804A4BC(u8* arg0, u8* arg1, s32 arg2, u32 arg3);
u32 sub_0804A168(Entity* entA, Entity* entB, LayerStruct* layer) {
u32 uVar2;
u32 uVar3;
u32 tile1;
u32 tile2;
if (entB->y.HALF.HI > entA->y.HALF.HI) {
uVar2 = entA->x.HALF.HI - 4;
uVar3 = ((uVar2 & 0xF) < 8) ? 10 : 5;
tile1 = TILE(uVar2, entA->y.HALF.HI + 10);
tile2 = TILE(uVar2, entB->y.HALF.HI);
if (sub_0804A4BC(&layer->collisionData[tile1], &layer->collisionData[tile2], 0x40, uVar3)) {
uVar2 = entA->x.HALF.HI + 4;
uVar3 ^= 0xF;
tile1 = TILE(uVar2, entA->y.HALF.HI + 10);
tile2 = TILE(uVar2, entB->y.HALF.HI);
if (sub_0804A4BC(&layer->collisionData[tile1], &layer->collisionData[tile2], 0x40, uVar3)) {
return 0x10;
}
}
} else {
uVar2 = entA->x.HALF.HI - 4;
uVar3 = ((uVar2 & 0xF) < 8) ? 10 : 5;
tile1 = TILE(uVar2, entA->y.HALF.HI - 10);
tile2 = TILE(uVar2, entB->y.HALF.HI);
if (sub_0804A4BC(&layer->collisionData[tile1], &layer->collisionData[tile2], -0x40, uVar3)) {
uVar2 = entA->x.HALF.HI + 4;
uVar3 ^= 0xF;
tile1 = TILE(uVar2, entA->y.HALF.HI - 10);
tile2 = TILE(uVar2, entB->y.HALF.HI);
if (sub_0804A4BC(&layer->collisionData[tile1], &layer->collisionData[tile2], -0x40, uVar3)) {
return 0;
}
}
}
return 0xFF;
}
u32 sub_0804A318(Entity* entA, Entity* entB, LayerStruct* layer) {
u32 uVar2;
u32 uVar3;
u32 tile1;
u32 tile2;
if (entB->x.HALF.HI > entA->x.HALF.HI) {
uVar2 = entA->y.HALF.HI - 4;
uVar3 = ((uVar2 & 0xF) < 8) ? 0xC : 3;
tile1 = TILE(entA->x.HALF.HI + 10, uVar2);
tile2 = TILE(entB->x.HALF.HI, uVar2);
if (sub_0804A4BC(&layer->collisionData[tile1], &layer->collisionData[tile2], 1, uVar3)) {
uVar2 = entA->y.HALF.HI + 4;
uVar3 ^= 0xF;
tile1 = TILE(entA->x.HALF.HI + 10, uVar2);
tile2 = TILE(entB->x.HALF.HI, uVar2);
if (sub_0804A4BC(&layer->collisionData[tile1], &layer->collisionData[tile2], 1, uVar3)) {
return 8;
}
}
} else {
uVar2 = entA->y.HALF.HI - 4;
uVar3 = ((uVar2 & 0xF) < 8) ? 0xC : 3;
tile1 = TILE(entA->x.HALF.HI - 10, uVar2);
tile2 = TILE(entB->x.HALF.HI, uVar2);
if (sub_0804A4BC(&layer->collisionData[tile1], &layer->collisionData[tile2], -1, uVar3)) {
uVar2 = entA->y.HALF.HI + 4;
uVar3 ^= 0xF;
tile1 = TILE(entA->x.HALF.HI - 10, uVar2);
tile2 = TILE(entB->x.HALF.HI, uVar2);
if (sub_0804A4BC(&layer->collisionData[tile1], &layer->collisionData[tile2], -1, uVar3)) {
return 0x18;
}
}
}
return 0xFF;
}
bool32 sub_0804A4BC(u8* arg0, u8* arg1, s32 arg2, u32 arg3) {
while (arg0 != arg1) {
u8 r0 = *arg0;
if (r0 != 0) {
if (r0 > 0xF) {
return FALSE;
}
r0 &= arg3;
if (r0 != 0) {
return FALSE;
}
}
arg0 += arg2;
}
return TRUE;
}
void sub_0804A4E4(Entity* entA, Entity* entB) {
GenericEntity* r5 = (GenericEntity*)entA;
GenericEntity* r6 = (GenericEntity*)entB;
r6->field_0x6c.HALF.HI = (r5->field_0x6c.HALF.HI & 0x40) | 4;
r6->field_0x6c.HALF.LO = r5->field_0x6c.HALF.LO;
r6->field_0x70.HALF.LO = r5->field_0x70.HALF.LO;
r6->field_0x70.HALF.HI = r5->field_0x70.HALF.HI;
r6->field_0x6e.HALF.LO = r5->field_0x6e.HALF.LO;
r6->field_0x6e.HALF.HI = r5->field_0x6e.HALF.HI;
CopyPositionAndSpriteOffset(&r5->base, &r6->base);
if (r5->field_0x6c.HALF.HI & 0x40) {
ReplaceMonitoredEntity(&r5->base, &r6->base);
}
}

View File

@ -306,12 +306,12 @@ bool32 sub_08030650(ArmosEntity* this) {
return 1;
}
} else if (this->unk_80 != 2) {
if ((sub_08049FDC(super, 1) == 0) || (0x20 < (gUnk_020000B0->x.HALF.HI - super->x.HALF.HI) + 0x10U)) {
if (!sub_08049FDC(super, 1) || (0x20 < (gUnk_020000B0->x.HALF.HI - super->x.HALF.HI) + 0x10U)) {
return FALSE;
}
return TRUE;
} else {
if (sub_08049FDC(super, 1) == 0) {
if (!sub_08049FDC(super, 1)) {
return FALSE;
}
if (gUnk_020000B0->x.HALF.HI >= (s32)(gRoomControls.origin_x + 0xa8)) {

View File

@ -610,8 +610,6 @@ void sub_08021644(Entity* this) {
}
}
extern u32 sub_08049F1C(Entity*, Entity*, u32);
u32 sub_08021664(Entity* this, Entity* ent) {
switch (this->animationState) {
case 0:

View File

@ -34,14 +34,14 @@ enum FlyingPotSubActions {
/* 1 */ FLYING_POT_SUBACTION_1,
/* 2 */ FLYING_POT_SUBACTION_2,
/* 3 */ FLYING_POT_SUBACTION_3,
/* 4 */ FLYING_POT_SUBACTION_4,
/* 4 */ FLYING_POT_SUBACTION_DO_NOTHING,
/* 5 */ FLYING_POT_SUBACTION_5,
};
// Functions
void FlyingPot_OnTick(FlyingPotEntity*); // 0803708C
void sub_080370A4(FlyingPotEntity*); // 080370A4
void sub_0803712C(FlyingPotEntity*); // 0803712C
void FlyingPot_OnTick(FlyingPotEntity*); // 0803708C
void FlyingPot_OnCollision(FlyingPotEntity*); // 080370A4
void FlyingPot_OnGrabbed(FlyingPotEntity*); // 0803712C
// Subactions
void FlyingPot_SubAction0(FlyingPotEntity*); // 08037144
@ -64,8 +64,12 @@ void sub_08037408(FlyingPotEntity*);
void sub_08037418(FlyingPotEntity*);
void (*const FlyingPot_Functions[])(Entity*) = {
(EntityActionPtr)FlyingPot_OnTick, (EntityActionPtr)sub_080370A4, GenericKnockback, GenericDeath, GenericConfused,
(EntityActionPtr)sub_0803712C,
(EntityActionPtr)FlyingPot_OnTick,
(EntityActionPtr)FlyingPot_OnCollision,
GenericKnockback,
GenericDeath,
GenericConfused,
(EntityActionPtr)FlyingPot_OnGrabbed,
};
void FlyingPot(Entity* thisx) {
@ -87,7 +91,7 @@ void FlyingPot_OnTick(FlyingPotEntity* this) {
FlyingPot_Actions[super->action](this);
}
void sub_080370A4(FlyingPotEntity* this) {
void FlyingPot_OnCollision(FlyingPotEntity* this) {
sub_08037418(this);
if (super->bitfield == 0x9D) {
@ -104,7 +108,7 @@ void sub_080370A4(FlyingPotEntity* this) {
EnemyFunctionHandlerAfterCollision(super, FlyingPot_Functions);
}
void sub_0803712C(FlyingPotEntity* this) {
void FlyingPot_OnGrabbed(FlyingPotEntity* this) {
static void (*const FlyingPot_SubActions[])(FlyingPotEntity*) = {
FlyingPot_SubAction0, FlyingPot_SubAction1, FlyingPot_SubAction2,
FlyingPot_SubAction3, FlyingPot_SubActionDoNothing, FlyingPot_SubAction5,

View File

@ -42,9 +42,6 @@ void sub_08037ACC(GibdoEntity*);
void Gibdo_CreateObjects(GibdoEntity*);
void sub_08037A14(GibdoEntity*);
extern void sub_0804A4E4(Entity*, Entity*);
u32 sub_0804A044(Entity*, Entity*, u32);
void (*const Gibdo_Functions[6])(Entity*);
void (*const gUnk_080CF2AC[9])(GibdoEntity*);
extern Entity* gUnk_020000B0;

View File

@ -8,9 +8,6 @@ extern void (*const gUnk_080012C8[])(Entity*);
const s8 gUnk_080CF490[];
const u8 gUnk_080CF498[];
extern s32 sub_080012DC(Entity*);
extern u32 sub_0804A044(Entity*, Entity*, u32);
void sub_08037E14(Entity* this);
bool32 sub_08037E90(Entity* this);

View File

@ -19,9 +19,6 @@ extern const s8 gUnk_080CA5D4[];
void sub_080205F8(Entity*);
void sub_08020604(Entity*);
extern u32 sub_08049F1C(Entity*, Entity*, u32);
extern void sub_0804AA1C(Entity*);
extern Entity* gUnk_020000B0;
enum {

View File

@ -8,8 +8,6 @@
#include "enemy.h"
#include "functions.h"
extern void sub_0804A4E4(Entity*, Entity*);
extern void (*const RockChuchu_Functions[])(Entity*);
extern void (*const gUnk_080CB960[])(Entity*);

View File

@ -12,7 +12,6 @@ extern void (*const Rope_Functions[6])(Entity*);
extern void (*const gUnk_080CE460[4])(Entity*);
extern void (*const gUnk_080CE470[3])(Entity*);
extern Entity* gUnk_020000B0;
extern u32 sub_0804A044(Entity*, Entity*, u32);
void sub_08031600(Entity*);
u32 sub_0803163C(Entity*);

View File

@ -14,9 +14,6 @@ extern void (*const gUnk_080012C8[])(Entity*);
extern void (*const RopeGolden_Functions[6])(Entity*);
extern void (*const gUnk_080CF4E0[4])(Entity*);
extern s32 sub_080012DC(Entity*);
extern u32 sub_0804A044(Entity*, Entity*, u32);
void sub_080383AC(Entity*);
void sub_080383E4(Entity*);

View File

@ -15,8 +15,6 @@ typedef struct {
void sub_08044FF8(Entity*);
void sub_08045178(Entity*, Entity*, int, int);
extern void sub_0804A4E4(Entity*, Entity*);
extern void (*const gUnk_080D16BC[])(Entity*);
extern void (*const Slime_Functions[])(Entity*);
extern u8 gUnk_080D16D0[4]; // Entity count per form

View File

@ -8,13 +8,9 @@
#include "enemy.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*);
@ -178,7 +174,7 @@ extern Entity* gUnk_020000B0;
void sub_08023E9C(Entity* this) {
u32 uVar3 = Random();
if (sub_08049FA0(this) == 0 && (uVar3 & 1)) {
if (!sub_08049FA0(this) && (uVar3 & 1)) {
this->direction = DirectionRoundUp(sub_08049EE4(this));
} else if (sub_08049FDC(this, 1) && (uVar3 & 6)) {
u32 uVar3 = GetFacingDirection(this, gUnk_020000B0) - this->direction;

View File

@ -9,11 +9,6 @@
#include "functions.h"
#include "hitbox.h"
extern void sub_08001318(Entity*);
extern u32 PlayerInRange(Entity*, u32, u32);
extern void sub_0804A4E4(Entity*, Entity*);
extern void sub_0804AA1C(Entity*);
u32 sub_080228CC(Entity*);
u32 sub_080228F0(Entity*);