Merge pull request #418 from hatal175/macro

Decompile macro* files
This commit is contained in:
notyourav
2022-03-02 13:29:23 -08:00
committed by GitHub
20 changed files with 738 additions and 1801 deletions
+99
View File
@@ -0,0 +1,99 @@
#include "entity.h"
#include "coord.h"
#include "object.h"
void sub_0809E518(Entity*);
void nullsub_125(Entity*);
void sub_0809E5F0(Entity*);
void MacroAcorn(Entity* this) {
static void (*const actionFuncs[])(Entity*) = {
sub_0809E518,
nullsub_125,
};
actionFuncs[this->action](this);
}
void sub_0809E518(Entity* this) {
u32 bVar2;
Entity* pEVar3;
this->action = 1;
if (this->type == 0xff) {
this->frameIndex = this->type2;
} else {
bVar2 = (this->type & 1) ? 4 : 0;
if ((this->type & 2)) {
if (gEntCount < 0x45) {
this->frameIndex = bVar2;
pEVar3 = CreateObject(HUGE_ACORN, 0xff, ++bVar2);
CopyPosition(this, pEVar3);
pEVar3 = CreateObject(HUGE_ACORN, 0xff, ++bVar2);
PositionRelative(this, pEVar3, 0, 0x10000);
pEVar3->spriteOffsetY = -1;
pEVar3 = CreateObject(HUGE_ACORN, 0xff, ++bVar2);
CopyPosition(this, pEVar3);
} else {
DeleteThisEntity();
}
} else {
pEVar3 = CreateObject(HUGE_ACORN, 0xff, bVar2 + 1);
if (pEVar3 == NULL) {
DeleteThisEntity();
} else {
this->frameIndex = bVar2;
CopyPosition(this, pEVar3);
}
}
sub_0809E5F0(this);
}
if ((this->frameIndex & 1) != 0) {
this->spriteRendering.b3 = 3;
this->spritePriority.b0 = 7;
}
}
void nullsub_125(Entity* this) {
}
void sub_0809E5F0(Entity* this) {
u32 position = COORD_TO_TILE(this);
this->field_0x80.HWORD = position;
switch (this->type) {
case 2:
SetTile(0x4022, position - 0x3d, 1);
SetTile(0x406d, position - 0x3c, 1);
case 0:
SetTile(0x406c, position - 0x42, 1);
SetTile(0x4022, position - 0x41, 1);
SetTile(0x4022, position - 0x40, 1);
SetTile(0x4022, position - 0x3f, 1);
SetTile(0x4022, position - 2, 1);
SetTile(0x4022, position - 1, 1);
SetTile(0x4022, position, 1);
SetTile(0x4022, position + 1, 1);
SetTile(0x406e, position + 0x3e, 1);
SetTile(0x4022, position + 0x3f, 1);
SetTile(0x4022, position + 0x40, 1);
SetTile(0x406f, position + 0x41, 1);
break;
case 3:
SetTile(0x4022, position - 0x44, 1);
SetTile(0x406c, position - 0x45, 1);
case 1:
SetTile(0x4022, position - 0x42, 1);
SetTile(0x4022, position - 0x41, 1);
SetTile(0x4022, position - 0x40, 1);
SetTile(0x406d, position - 0x3f, 1);
SetTile(0x4022, position - 2, 1);
SetTile(0x4022, position - 1, 1);
SetTile(0x4022, position, 1);
SetTile(0x4022, position + 1, 1);
SetTile(0x406e, position + 0x3e, 1);
SetTile(0x4022, position + 0x3f, 1);
SetTile(0x4022, position + 0x40, 1);
SetTile(0x406f, position + 0x41, 1);
break;
}
}
+208
View File
@@ -0,0 +1,208 @@
#define NENT_DEPRECATED
#include "entity.h"
#include "functions.h"
#include "flags.h"
#include "asm.h"
#include "npc.h"
typedef struct {
Entity base;
u8 filler[0x10];
u16 playerWithinRect;
u8 filler2[0x6];
u16 unk80;
u16 tilePos;
} MacroBookEntity;
void MacroBook_Init(MacroBookEntity*);
void MacroBook_Action1(MacroBookEntity*);
void MacroBook_Action2(MacroBookEntity*);
void MacroBook_Action3(MacroBookEntity*);
void sub_0809A958(MacroBookEntity*);
void sub_0809AA00(MacroBookEntity*);
void sub_0809A9D4(MacroBookEntity*);
void sub_0809AA9C(MacroBookEntity*, Entity*, u32);
void MacroBook(Entity* this) {
static void (*const actionFuncs[])(MacroBookEntity*) = {
MacroBook_Init,
MacroBook_Action1,
MacroBook_Action2,
MacroBook_Action3,
};
actionFuncs[this->action]((MacroBookEntity*)this);
}
void MacroBook_Init(MacroBookEntity* this) {
super->action = 1;
super->actionDelay = 0x80;
super->field_0xf = 0;
super->spriteRendering.b0 = 3;
this->unk80 = 0x80;
this->playerWithinRect = 0;
super->x.HALF.HI -= 4;
super->spriteOffsetY = -4;
super->spritePriority.b0 = 7;
super->spriteRendering.b3 = 3;
sub_0805EC9C(super, this->unk80, this->unk80, 0);
UpdateSpriteForCollisionLayer(super);
InitAnimationForceUpdate(super, super->field_0xf);
sub_0809A958(this);
}
void MacroBook_Action1(MacroBookEntity* this) {
UpdateAnimationSingleFrame(super);
sub_0809AA00(this);
if (super->actionDelay) {
super->actionDelay--;
} else {
if ((super->frame & 0x80) != 0) {
if (super->field_0xf == 3) {
super->action = 2;
super->actionDelay = 90;
super->field_0xf = 0;
InitAnimationForceUpdate(super, 2);
} else {
InitAnimationForceUpdate(super, super->field_0xf);
}
}
}
}
void MacroBook_Action2(MacroBookEntity* this) {
UpdateAnimationSingleFrame(super);
sub_0809AA00(this);
if (super->field_0xf < 2) {
super->action = 1;
super->actionDelay = 0;
} else if (super->actionDelay) {
super->actionDelay--;
if (gPlayerClones[0] != 0) {
return;
}
super->action = 1;
super->actionDelay = 0;
} else {
if ((super->frame & 0x80) == 0) {
return;
}
super->action = 3;
super->actionDelay = 0;
InitAnimationForceUpdate(super, 3);
RequestPriorityDuration(super, 0x78);
}
}
void MacroBook_Action3(MacroBookEntity* this) {
switch (super->frame & 0xe0) {
case 0x80:
if (super->frameDuration == 0) {
DeleteThisEntity();
}
break;
case 0x40:
super->frame &= 0xbf;
sub_0809A9D4(this);
break;
case 0x20:
super->actionDelay++;
super->frame &= 0xdf;
SetPlayerControl(0xff);
SetGlobalFlag(0x2a);
default:
UpdateAnimationSingleFrame(super);
break;
}
if (super->actionDelay) {
this->unk80 += 8;
super->x.WORD += 0x400;
sub_0805EC9C(super, this->unk80, this->unk80, 0);
} else {
sub_0809AA9C(this, super->child, 0);
sub_0809AA9C(this, &gPlayerEntity, 1);
if (gPlayerClones[0] != NULL) {
sub_0809AA9C(this, gPlayerClones[0], 1);
}
}
}
void sub_0809A958(MacroBookEntity* this) {
static const u16 tileIndices[] = {
0x4074, 0x4074, 0x4074, 0x4074, 0x4074, 0x4074, 0x4074, 0x4074, 0x4074, 0x4074,
0x4074, 0x4074, 0x4074, 0x4074, 0x4074, 0x4074, 0, 0, 0x4022, 0x4022,
};
int index;
int index2;
int tilePos;
const u16* tileIndexPtr;
this->tilePos = COORD_TO_TILE_OFFSET(super, -4, 0);
tilePos = this->tilePos - 0x82;
tileIndexPtr = tileIndices;
for (index = 0; index < 5; index++, tilePos += 0x40) {
for (index2 = 0; index2 < 4; index2++, tileIndexPtr++) {
if ((*tileIndexPtr & 0x4000) != 0) {
SetTile(*tileIndexPtr, tilePos + index2, 1);
}
}
}
}
void sub_0809A9D4(MacroBookEntity* this) {
int index;
int index2;
int tilePos;
tilePos = this->tilePos - 0x82;
for (index = 0; index < 5; index++, tilePos += 0x40) {
for (index2 = 0; index2 < 4; index2++) {
sub_0807BA8C(tilePos + index2, 1);
}
}
}
void sub_0809AA00(MacroBookEntity* this) {
Entity* ent;
super->field_0xf = 0;
if (super->child == NULL) {
for (ent = FindEntityByID(NPC, TOWN_MINISH, 7); ent != NULL; ent = FindNextDuplicateID(ent, NPC)) {
if (ent->type == 0 && ent->type2 == 8) {
super->child = ent;
}
}
} else {
sub_0809AA9C(this, super->child, 0);
}
ent = &gPlayerEntity;
this->playerWithinRect = EntityInRectRadius(super, ent, 0x20, 0x22);
if (this->playerWithinRect != 0) {
sub_0809AA9C(this, ent, 1);
ent = gPlayerClones[0];
if (ent != NULL) {
sub_0809AA9C(this, ent, 1);
}
}
}
void sub_0809AA9C(MacroBookEntity* this, Entity* ent, u32 arg3) {
u32 bVar1;
bVar1 = super->frame & 3;
if (bVar1 == 1) {
ent->spriteOffsetY = bVar1;
} else if (bVar1 == 2) {
ent->spriteOffsetY = bVar1;
} else {
ent->spriteOffsetY = 0;
}
if (ent->x.HALF.HI <= gRoomControls.origin_x + 0x15a) {
super->field_0xf++;
ent->spriteOffsetY++;
}
}
+112
View File
@@ -0,0 +1,112 @@
#define NENT_DEPRECATED
#include "entity.h"
#include "room.h"
#include "asm.h"
typedef struct {
Entity base;
u8 filler[8];
s16 y2;
} MacroDecorationEntity;
void sub_08097DEC(MacroDecorationEntity*);
void sub_08097EA4(MacroDecorationEntity*);
void sub_08097EB8(MacroDecorationEntity*);
void sub_08097F34(MacroDecorationEntity*);
void sub_08097F10(MacroDecorationEntity*);
s32 sub_08097F60(MacroDecorationEntity*, s32);
void MacroDecoration(Entity* this) {
static void (*const actionFuncs[])(MacroDecorationEntity*) = {
sub_08097DEC,
sub_08097EA4,
};
actionFuncs[this->action]((MacroDecorationEntity*)this);
}
void sub_08097DEC(MacroDecorationEntity* this) {
u32 bVar1;
u32 uVar2;
super->action = 1;
UpdateSpriteForCollisionLayer(super);
switch (super->type) {
case 0:
super->x.HALF.HI &= 0xfff0;
super->y.HALF.HI &= 0xfff0;
sub_08097EB8(this);
if (super->type2 == 0) {
return;
}
ChangeObjPalette(super, super->type2 + 0xb);
return;
case 1:
bVar1 = super->frameIndex = super->type2;
bVar1 = (bVar1 << 0x18) >> 0x19;
switch ((s32)bVar1) {
case 2:
ChangeObjPalette(super, 0xd);
case 0:
super->spriteOrientation.flipY = 1;
break;
case 1:
super->spriteOrientation.flipY = 2;
super->spritePriority.b0 = 3;
ChangeObjPalette(super, 0xb);
break;
}
break;
case 2:
case 3:
super->frameIndex = super->type2;
super->spriteSettings.draw = 3;
break;
default:
return;
}
sub_08097F34(this);
}
void sub_08097EA4(MacroDecorationEntity* this) {
if (super->type) {
sub_08097F10(this);
}
}
void sub_08097EB8(MacroDecorationEntity* this) {
static const s16 tilePosArray[] = {
0xff7e, 0x4089, 0xff7f, 0x4022, 0xff80, 0x4022, 0xff81, 0x408a, 0xffbe, 0x4022, 0xffbf, 0x4022, 0xffc0, 0x4022,
0xffc1, 0x4022, 0xfffe, 0x4022, 0xffff, 0x4022, 0, 0x4022, 1, 0x4022, 2, 0x408b, 0x3e, 0x4022,
0x3f, 0x4022, 0x40, 0x4026, 0x41, 0x4022, 0x7e, 0x408c, 0x7f, 0x408c, 0x7fff, 0xffff,
};
const s16* tilePosPtr;
u16 tile = COORD_TO_TILE(super);
for (tilePosPtr = tilePosArray; *tilePosPtr != 0x7fff; tilePosPtr += 2) {
SetTile((u16)tilePosPtr[1], tile + tilePosPtr[0], 1);
}
}
void sub_08097F10(MacroDecorationEntity* this) {
super->y.HALF.HI = this->y2 - sub_08097F60(this, gRoomControls.scroll_y - gRoomControls.origin_y);
}
void sub_08097F34(MacroDecorationEntity* this) {
this->y2 = super->y.HALF.HI + sub_08097F60(this, super->y.HALF.HI - gRoomControls.origin_y);
sub_08097F10(this);
}
s32 sub_08097F60(MacroDecorationEntity* this, s32 arg2) {
switch (super->type) {
case 1:
if (super->frameIndex >> 1 == 1) {
arg2 >>= 3;
break;
}
case 2:
case 3:
arg2 >>= 1;
}
return arg2;
}
+12
View File
@@ -0,0 +1,12 @@
#include "entity.h"
void sub_0808C964(Entity*);
void sub_0808CA10(Entity*);
void MacroMushromStalks(Entity* this) {
static void (*const actionFuncs[])(Entity*) = {
sub_0808C964,
sub_0808CA10,
};
actionFuncs[this->action](this);
}
+251
View File
@@ -0,0 +1,251 @@
#define NENT_DEPRECATED
#include "entity.h"
#include "coord.h"
#include "functions.h"
#include "object.h"
#include "area.h"
typedef struct {
Entity base;
union SplitHWord unk68;
u16 unk6a;
} MacroPlayerEntity;
extern u8 gUnk_02018EB0[];
extern int sub_0807A094(int);
void MacroPlayer_Type0(MacroPlayerEntity*);
void MacroPlayer_Type1(MacroPlayerEntity*);
void MacroPlayer_Type0_Init(MacroPlayerEntity*);
void MacroPlayer_Type0_Action1(MacroPlayerEntity*);
void MacroPlayer_Type0_Action2(MacroPlayerEntity*);
void MacroPlayer_Type0_Action3(MacroPlayerEntity*);
void MacroPlayer_Type0_Action4(MacroPlayerEntity*);
void MacroPlayer_Type0_Action5(MacroPlayerEntity*);
void MacroPlayer_Type0_Action6(MacroPlayerEntity*);
void MacroPlayer_Type0_Action7(MacroPlayerEntity*);
void MacroPlayer_Type0_Action8(MacroPlayerEntity*);
void MacroPlayer_Type0_Action9(MacroPlayerEntity*);
void MacroPlayer_Type0_Action10(MacroPlayerEntity*);
void sub_0808CB9C(MacroPlayerEntity*);
void MacroPlayer(Entity* this) {
static void (*const typeFuncs[])(MacroPlayerEntity*) = {
MacroPlayer_Type0,
MacroPlayer_Type1,
};
typeFuncs[this->type]((MacroPlayerEntity*)this);
}
void MacroPlayer_Type0(MacroPlayerEntity* this) {
static void (*const actionFuncs[])(MacroPlayerEntity*) = {
MacroPlayer_Type0_Init, MacroPlayer_Type0_Action1, MacroPlayer_Type0_Action2, MacroPlayer_Type0_Action3,
MacroPlayer_Type0_Action4, MacroPlayer_Type0_Action5, MacroPlayer_Type0_Action6, MacroPlayer_Type0_Action7,
MacroPlayer_Type0_Action8, MacroPlayer_Type0_Action9, MacroPlayer_Type0_Action10,
};
actionFuncs[super->action](this);
sub_0808CB9C(this);
}
void MacroPlayer_Type1(MacroPlayerEntity* this) {
Entity* pEVar1;
if (super->action == 0) {
super->action = 1;
super->spriteSettings.draw = 3;
super->spriteIndex = 0xa7;
super->frameIndex = 13;
super->spriteVramOffset = 1;
super->palette.b.b0 = 5;
super->spriteRendering.b3 = 0;
super->spritePriority.b0 = 0;
super->spriteOrientation.flipY = 2;
}
pEVar1 = super->parent;
super->x = pEVar1->x;
super->y = pEVar1->y;
super->z.WORD = 0;
SortEntityBelow(pEVar1, super);
if (super->subAction != 0) {
super->spriteVramOffset = 0;
super->subAction = 0;
super->frameIndex = 4;
}
}
void sub_0808CB9C(MacroPlayerEntity* this) {
u32 uVar1;
u32 uVar2;
u32 uVar3;
u32 uVar4;
u32 val;
uVar2 = this->unk68.HWORD;
uVar1 = this->unk68.HALF.LO;
uVar4 = uVar2 >> 8;
val = 0;
uVar3 = super->animationState;
val = uVar3 > 4;
super->spriteSettings.flipX = val;
if (uVar1 < 0xb8) {
uVar1 += super->animationState >> 1;
}
if ((uVar4 != (u16)super->spriteIndex) || (uVar1 != super->animIndex)) {
super->spriteIndex = uVar4;
InitAnimationForceUpdate(super, uVar1);
}
}
void MacroPlayer_Type0_Init(MacroPlayerEntity* this) {
Entity* pEVar1;
u8* ptr;
super->action++;
super->spriteSettings.draw = 1;
super->animationState = 4;
super->spriteRendering.b3 = 0;
super->spritePriority.b0 = 0;
super->spriteOrientation.flipY = 2;
this->unk68.HWORD = 0x114;
super->animIndex = 0xff;
super->z.HALF.HI = 0xff50;
this->unk6a = 4;
super->spriteRendering.b0 = 3;
sub_0805EC9C(super, 4, 4, 0);
ptr = gUnk_02018EB0;
*(Entity**)&ptr[0x14] = super;
ChangeObjPalette(super, sub_0807A094(0));
pEVar1 = CreateObject(PORTAL_FALLING_PLAYER, 1, 0);
if (pEVar1 != NULL) {
pEVar1->parent = super;
super->child = pEVar1;
}
}
void sub_0808CC88(MacroPlayerEntity* this) {
if (this->unk6a < 0x400) {
this->unk6a += 4;
sub_0805EC9C(super, this->unk6a, this->unk6a, 0);
sub_0806FCF4(super, this->unk6a, 8, 2);
}
}
void MacroPlayer_Type0_Action1(MacroPlayerEntity* this) {
sub_0808CC88(this);
if (GravityUpdate(super, 0x1000) == 0) {
super->action++;
super->direction = DirectionSouthWest;
super->speed = 0x100;
super->zVelocity = 0x30000;
super->spriteSettings.shadow = 0;
super->child->subAction = 1;
gUnk_02018EB0[0x18] = 1;
}
}
void MacroPlayer_Type0_Action2(MacroPlayerEntity* this) {
sub_0808CC88(this);
UpdateAnimationSingleFrame(super);
if (GravityUpdate(super, 0x2000)) {
LinearMoveUpdate(super);
} else {
super->action++;
super->direction = 10;
super->speed = 0xc0;
super->zVelocity = 0x28000;
gUnk_02018EB0[0x19] = 1;
}
}
void MacroPlayer_Type0_Action3(MacroPlayerEntity* this) {
sub_0808CC88(this);
UpdateAnimationSingleFrame(super);
if (GravityUpdate(super, 0x2000)) {
LinearMoveUpdate(super);
} else {
super->action++;
super->direction = 17;
super->speed = 0x100;
super->zVelocity = 0x24000;
gUnk_02018EB0[0x1a] = 1;
}
}
void MacroPlayer_Type0_Action4(MacroPlayerEntity* this) {
sub_0808CC88(this);
if (GravityUpdate(super, 0x1800)) {
UpdateAnimationSingleFrame(super);
LinearMoveUpdate(super);
if (super->x.HALF.HI < 0x80) {
super->x.HALF.HI = 0x80;
}
} else {
super->action++;
super->actionDelay = 60;
this->unk68.HWORD = 0xc04;
DeleteEntity(super->child);
sub_0805EC60(super);
}
}
void MacroPlayer_Type0_Action5(MacroPlayerEntity* this) {
if (--super->actionDelay == 0) {
super->action++;
super->actionDelay = 0x10;
}
}
void MacroPlayer_Type0_Action6(MacroPlayerEntity* this) {
static const u8 gUnk_081216B4[] = { 0, 0x1a, 0x2, 0x5, 0x4, 0x11, 0x6, 0x1a };
u32 uVar2;
if (--super->actionDelay == 0) {
uVar2 = gArea.curPortalExitDirection;
super->action += 1;
super->action += uVar2;
super->animationState = gUnk_081216B4[uVar2 * 2];
super->direction = gUnk_081216B4[uVar2 * 2 + 1];
super->speed = 0x140;
}
}
void MacroPlayer_Type0_Action7(MacroPlayerEntity* this) {
UpdateAnimationSingleFrame(super);
LinearMoveUpdate(super);
if (super->y.HALF.HI < 200) {
super->direction = DirectionWest;
}
if (super->x.HALF.HI < 0x30) {
gUnk_02018EB0[0x1b] = 1;
}
}
void MacroPlayer_Type0_Action8(MacroPlayerEntity* this) {
UpdateAnimationSingleFrame(super);
LinearMoveUpdate(super);
if (super->y.HALF.HI < 200) {
super->direction = DirectionEast;
}
if (super->x.HALF.HI > 0xd0) {
gUnk_02018EB0[0x1b] = 1;
}
}
void MacroPlayer_Type0_Action9(MacroPlayerEntity* this) {
UpdateAnimationSingleFrame(super);
LinearMoveUpdate(super);
if (super->y.HALF.HI > 0x120) {
gUnk_02018EB0[0x1b] = 1;
}
}
void MacroPlayer_Type0_Action10(MacroPlayerEntity* this) {
UpdateAnimationSingleFrame(super);
LinearMoveUpdate(super);
if (super->y.HALF.HI < 200) {
super->direction = DirectionWest;
}
if (super->x.HALF.HI < 0x10) {
gUnk_02018EB0[0x1b] = 1;
}
}
+44
View File
@@ -0,0 +1,44 @@
#include "entity.h"
#include "asm.h"
void sub_0800445C(Entity*);
void MacroShoes_Init(Entity*);
void MacroShoes_Idle(Entity*);
static const Hitbox MacroShoes_Type0Hitbox;
static const Hitbox MacroShoes_Type1Hitbox;
static const Hitbox* const MacroShoes_TypeHitboxes[] = {
&MacroShoes_Type0Hitbox,
&MacroShoes_Type1Hitbox,
};
static const Hitbox MacroShoes_Type0Hitbox = {
0, 0, { 4, 0, 0, 0 }, 0x34, 0x20,
};
static const Hitbox MacroShoes_Type1Hitbox = {
0, 0, { 4, 0, 0, 0 }, 0x30, 0x10,
};
void MacroShoes(Entity* this) {
static void (*const actionFuncs[])(Entity*) = {
MacroShoes_Init,
MacroShoes_Idle,
};
actionFuncs[this->action](this);
sub_0800445C(this);
}
void MacroShoes_Init(Entity* this) {
this->action = 1;
this->hitbox = (Hitbox*)MacroShoes_TypeHitboxes[this->type];
if (this->type2 == 1) {
SetTile(0x4024, 0x410, 1);
SetTile(0x4026, 0x411, 1);
SetTile(0x4025, 0x412, 1);
}
}
void MacroShoes_Idle(Entity* this) {
}