summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTal Hayon <talhayon1@gmail.com>2022-07-26 15:51:55 +0300
committerTal Hayon <talhayon1@gmail.com>2022-07-27 07:34:59 +0300
commitc314ccd671d057cf83ff46cc6b2a45c4197fa693 (patch)
treef7b71359f5f3fd302a4a69d3a9a9255d6c9804f7 /src
parentba2bbbc0ec545788b5f10397385c0ca5c3409e42 (diff)
Adjust gleerok heap structure
Diffstat (limited to 'src')
-rw-r--r--src/enemy/gleerok.c155
1 files changed, 100 insertions, 55 deletions
diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c
index e6fa9f9b..44aa1ac6 100644
--- a/src/enemy/gleerok.c
+++ b/src/enemy/gleerok.c
@@ -7,14 +7,14 @@
#include "object.h"
typedef struct {
- u8 unk0;
- u8 unk1;
+ union SplitHWord unk0;
u8 unk2;
u8 unk3;
} Gleerok_HeapStruct2;
typedef struct {
- /*0x00*/ Gleerok_HeapStruct2 filler[11];
+ /*0x00*/ Gleerok_HeapStruct2 filler[6];
+ /*0x00*/ Gleerok_HeapStruct2 filler2[5];
/*0x2c*/ union SplitHWord unk_2c;
/*0x2e*/ u16 filler_2e;
/*0x30*/ u8 unk_30[6];
@@ -143,8 +143,8 @@ void sub_0802D170(GleerokEntity* this) {
return;
if (super->action == 1) {
- this->unk_84->filler[0].unk1 = 0x10;
- this->unk_84->filler[6].unk1 = 0x10;
+ this->unk_84->filler[0].unk0.HALF.HI = 0x10;
+ this->unk_84->filler2[0].unk0.HALF.HI = 0x10;
if (sub_0802EB08(this->unk_84, 0x40, 2) == 0 && sub_0802EA88(this->unk_84) == 0) {
super->action = 2;
gPlayerEntity.x.HALF.HI = gRoomControls.origin_x + 0x98;
@@ -158,7 +158,7 @@ void sub_0802D170(GleerokEntity* this) {
super->action = 3;
this->unk_80 = 0;
((Entity*)this->unk_84)->parent->timer = 24;
- this->unk_84->filler[6].unk1 = 0;
+ this->unk_84->filler2[0].unk0.HALF.HI = 0;
}
}
@@ -171,7 +171,7 @@ void sub_0802D218(GleerokEntity* this) {
super->subtimer = 0;
this->unk_7c.HALF_U.LO = 0xb4;
((Entity*)(this->unk_84))->parent->timer = 12;
- CreateObjectWithParent(super, 0x67, 0x2, this->unk_7c.HALF_U.LO);
+ CreateObjectWithParent(super, OBJECT_67, 0x2, this->unk_7c.HALF_U.LO);
}
void sub_0802D258(GleerokEntity* this) {
@@ -294,9 +294,9 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D3B8.inc", void sub_0802D3B8(GleerokE
this->unk_84->entities[uvar1] = super->child;
ptr = this->unk_84->filler;
ptr2 = ptr + uvar1;
- ptr2[0].unk1 = 0x10;
- ptr2[6].unk1 = 0;
- ptr[13].unk1 = 0;
+ ptr2[0].unk0.HALF.HI = 0x10;
+ ptr2[6].unk0.HALF.HI = 0;
+ ptr[13].unk0.HALF.HI = 0;
}
} while (++uvar1 < 5);
@@ -309,9 +309,9 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D3B8.inc", void sub_0802D3B8(GleerokE
super->child->parent = super;
((GleerokEntity*)super->child)->unk_84 = this->unk_84;
heap->ent2 = super->child;
- heap->filler[5].unk1 = 0x10;
- heap->filler[11].unk1 = 0;
- heap->filler[13].unk1 = 0;
+ heap->filler[5].unk0.HALF.HI = 0x10;
+ heap->filler2[5].unk0.HALF.HI = 0;
+ heap->filler[13].unk0.HALF.HI = 0;
}
#ifndef EU
gPlayerState.controlMode = CONTROL_DISABLED;
@@ -323,7 +323,7 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D3B8.inc", void sub_0802D3B8(GleerokE
COLLISION_ON(super);
super->flags2 |= 0x80;
}
- super->spritePriority.b0 = gUnk_080CD7C4[super->type2].unk1;
+ super->spritePriority.b0 = gUnk_080CD7C4[super->type2].unk0.HALF.HI;
super->subtimer = 0;
InitializeAnimation(super, 0x24);
break;
@@ -416,8 +416,8 @@ void sub_0802D714(GleerokEntity* this) {
return;
for (heap = this->unk_84, index = 0, val1 = 0, val2 = 0x10, ptr = this->unk_84->filler; index < 6; ptr++, ++index) {
- *(u16*)(ptr + 6) = val1;
- ptr->unk1 = val2;
+ ptr[6].unk0.HWORD = val1;
+ ptr->unk0.HALF.HI = val2;
}
super->subAction = 3;
@@ -575,7 +575,7 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D86C.inc", void sub_0802D86C(GleerokE
super->child = enemy;
if (enemy) {
enemy->parent = super->parent;
- super->timer = this->unk_84->filler[0].unk1;
+ super->timer = this->unk_84->filler[0].unk0.HALF.HI;
this->unk_84->ent = super->child;
((GleerokEntity*)super->child)->unk_84 = this->unk_84;
}
@@ -606,8 +606,8 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D86C.inc", void sub_0802D86C(GleerokE
SoundReq(SFX_BUTTON_PRESS);
}
} else {
- if (super->timer != this->unk_84->filler[0].unk1) {
- if (((super->timer - this->unk_84->filler[0].unk1) & 0x1f) > 0x10) {
+ if (super->timer != this->unk_84->filler[0].unk0.HALF.HI) {
+ if (((super->timer - this->unk_84->filler[0].unk0.HALF.HI) & 0x1f) > 0x10) {
if (++super->frameIndex >= 0x31) {
super->frameIndex = 0x28;
}
@@ -617,7 +617,7 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D86C.inc", void sub_0802D86C(GleerokE
}
}
- super->timer = this->unk_84->filler[0].unk1;
+ super->timer = this->unk_84->filler[0].unk0.HALF.HI;
}
}
@@ -652,13 +652,13 @@ END_NONMATCH
void sub_0802DB84(GleerokEntity* this) {
u32 timer;
super->direction = GetFacingDirection(super, &gPlayerEntity);
- if (this->unk_84->filler[0].unk1 == super->direction) {
+ if (this->unk_84->filler[0].unk0.HALF.HI == super->direction) {
super->subAction = 1;
this->unk_78 = 0;
return;
}
- if (((this->unk_84->filler[0].unk1 - super->direction) & 0x1f) > 0x10) {
+ if (((this->unk_84->filler[0].unk0.HALF.HI - super->direction) & 0x1f) > 0x10) {
timer = 0;
super->timer &= 0xfe;
} else {
@@ -686,7 +686,7 @@ void sub_0802DB84(GleerokEntity* this) {
void sub_0802DC1C(GleerokEntity* this) {
u32 diff = GetFacingDirection(super, &gPlayerEntity);
- diff = (this->unk_84->filler[0].unk1 - diff) & 0x1f;
+ diff = (this->unk_84->filler[0].unk0.HALF.HI - diff) & 0x1f;
if (diff > 0x10) {
if (diff <= 0x1d) {
@@ -709,11 +709,11 @@ void sub_0802DC1C(GleerokEntity* this) {
}
sub_0802EA48(this->unk_84, 5, 0x20, diff);
- if (sub_0802EA18(*(u16*)this->unk_84->filler, *(u16*)&this->unk_84->filler[5], 4)) {
+ if (sub_0802EA18(this->unk_84->filler[0].unk0.HWORD, this->unk_84->filler[5].unk0.HWORD, 4)) {
if (super->timer == 1) {
- *(u16*)&this->unk_84->filler[5] = (((this->unk_84->filler[0].unk1 - 4) & 0x1f) << 8) | 0xff;
+ this->unk_84->filler[5].unk0.HWORD = (((this->unk_84->filler[0].unk0.HALF.HI - 4) & 0x1f) << 8) | 0xff;
} else {
- *(u16*)&this->unk_84->filler[5] = (((this->unk_84->filler[0].unk1 + 4) & 0x1f) << 8);
+ this->unk_84->filler[5].unk0.HWORD = (((this->unk_84->filler[0].unk0.HALF.HI + 4) & 0x1f) << 8);
}
super->timer ^= 1;
@@ -730,13 +730,13 @@ void sub_0802DC1C(GleerokEntity* this) {
void sub_0802DCE0(GleerokEntity* this) {
if (this->unk_84->ent2->timer != 12) {
super->direction = GetFacingDirection(super, &gPlayerEntity);
- if (this->unk_84->filler[5].unk1 == super->direction) {
+ if (this->unk_84->filler[5].unk0.HALF.HI == super->direction) {
this->unk_84->ent2->timer = 12;
this->unk_82 = 4;
super->subtimer = 0;
} else {
s32 svar1, diff;
- diff = ((this->unk_84->filler[5].unk1 - super->direction) & 0x1f);
+ diff = ((this->unk_84->filler[5].unk0.HALF.HI - super->direction) & 0x1f);
svar1 = 1;
if (diff > 0x10) {
svar1 = 0;
@@ -759,7 +759,7 @@ void sub_0802DCE0(GleerokEntity* this) {
super->child = CreateProjectileWithParent(super, GLEEROK_PROJECTILE, 0);
if (super->child != NULL) {
- super->child->direction = this->unk_84->filler[5].unk1;
+ super->child->direction = this->unk_84->filler[5].unk0.HALF.HI;
super->child->type2 = this->unk_84->ent2->frame & 0xf;
super->child->parent = this->unk_84->ent2;
super->child->child = this->unk_84->entities[0];
@@ -803,10 +803,10 @@ void sub_0802DDD8(GleerokEntity* this) {
if ((Random() & 1) == 0) {
super->direction = 0;
- this->unk_7a = (this->unk_84->filler[0].unk1 + uvar1) & 0x1f;
+ this->unk_7a = (this->unk_84->filler[0].unk0.HALF.HI + uvar1) & 0x1f;
} else {
super->direction = 1;
- this->unk_7a = (this->unk_84->filler[0].unk1 - uvar1) & 0x1f;
+ this->unk_7a = (this->unk_84->filler[0].unk0.HALF.HI - uvar1) & 0x1f;
}
break;
@@ -826,7 +826,7 @@ void sub_0802DDD8(GleerokEntity* this) {
if (this->unk_84->ent2->subtimer == 1) {
super->child = CreateProjectileWithParent(super, GLEEROK_PROJECTILE, r2);
if (super->child != NULL) {
- super->child->direction = this->unk_84->filler[5].unk1;
+ super->child->direction = this->unk_84->filler[5].unk0.HALF.HI;
super->child->type2 = this->unk_84->ent2->frame & 0xf;
super->child->parent = this->unk_84->ent2;
super->child->child = this->unk_84->entities[0];
@@ -856,7 +856,7 @@ void sub_0802DDD8(GleerokEntity* this) {
}
sub_0802E768(this->unk_84);
- if (this->unk_7a == this->unk_84->filler[5].unk1) {
+ if (this->unk_7a == this->unk_84->filler[5].unk0.HALF.HI) {
if (super->type2 == 1) {
super->type2 = 2;
super->direction ^= 1;
@@ -886,7 +886,7 @@ void sub_0802DFA8(GleerokEntity* this) {
}
void sub_0802DFC0(GleerokEntity* this) {
- u32 val = this->unk_84->filler[0].unk1 & 7;
+ u32 val = this->unk_84->filler[0].unk0.HALF.HI & 7;
if (val) {
if (val > 4) {
super->direction = 0;
@@ -919,10 +919,10 @@ void sub_0802E034(GleerokEntity* this) {
val = 0;
} else {
super->direction = 3;
- val = gUnk_080CD840[heap->filler[0].unk1 >> 3];
+ val = gUnk_080CD840[heap->filler[0].unk0.HALF.HI >> 3];
}
- if (val != heap->filler[6].unk1) {
+ if (val != heap->filler2[0].unk0.HALF.HI) {
sub_0802EA68(heap, 0, 0x40, super->direction);
sub_0802EB08(heap, 0x40, 2);
} else {
@@ -934,7 +934,7 @@ void sub_0802E034(GleerokEntity* this) {
}
super->type2++;
- heap->filler[6].unk1 = 1;
+ heap->filler2[0].unk0.HALF.HI = 1;
}
}
@@ -1080,8 +1080,8 @@ void sub_0802E300(GleerokEntity* this) {
tmp = 0;
ptr = heap->filler;
do {
- ((u16*)ptr)[0xc] = tmp;
- ptr->unk1 = dir;
+ ptr[6].unk0.HWORD = tmp;
+ ptr->unk0.HALF.HI = dir;
ptr++;
index++;
} while (index <= 5);
@@ -1169,9 +1169,9 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE
s32 r7;
Gleerok_HeapStruct* heap = this->unk_84;
CopyPosition(heap->entities[0]->parent, heap->entities[0]);
- heap->entities[0]->direction = heap->filler[0].unk1;
+ heap->entities[0]->direction = heap->filler->unk0.HALF.HI;
- r6 = heap->filler[0].unk1;
+ r6 = heap->filler->unk0.HALF.HI;
if (r6 > 0x10) {
r6 ^= 0xf;
r6 = (r6 + 1) & 0xf;
@@ -1183,25 +1183,25 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE
heap->entities[0]->speed = ((r6 ^ 0xf) + 0x12) << 8;
LinearMoveUpdate(heap->entities[0]);
- sp4 = *(u32*)heap->unk_30;
+ sp4 = *(u32*)&heap->unk_30;
sp8 = this->unk_80;
for (index = 0; index <= 4; index++) {
s32 result;
CopyPosition(heap->entities[index], heap->entities[index + 1]);
- result = FixedMul(gSineTable[heap->filler[6 + (index + 1)].unk1], ((u8*)sp4)[r6]);
+ result = FixedMul(gSineTable[heap->filler2[(index + 1)].unk0.HALF.HI * 8], (heap->unk_30)[r6] << 8);
result = FixedDiv(result, 0x100);
- result = FixedMul(gSineTable[heap->filler[(index + 1)].unk1], result);
+ result = FixedMul(gSineTable[heap->filler[(index + 1)].unk0.HALF.HI * 8], result);
result = FixedDiv(result, 0x100);
heap->entities[index]->x.WORD += result << 8;
- result = FixedMul(gSineTable[heap->filler[6 + (index + 1)].unk1], ((u8*)sp4)[r6]);
+ result = FixedMul(gSineTable[heap->filler2[(index + 1)].unk0.HALF.HI * 8 + 0x40], (heap->unk_30)[r6] << 8);
result = FixedDiv(result, 0x100);
heap->entities[index]->y.WORD -= result << 8;
}
if (heap->ent2->timer == 24) {
- r7 = (heap->filler[5].unk1 >> 3) << 2;
+ r7 = (heap->filler[5].unk0.HALF.HI >> 3) << 2;
if (heap->unk_2c.HALF.HI > 0xc) {
r7 += 3;
} else {
@@ -1214,15 +1214,21 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE
} else {
if (this->unk_80 == 0) {
sub_0802E7CC(heap, 5, 0, 0);
- r7 = (heap->ent2->animationState / 2 + heap->ent2->animationState) / 4;
- r7 += heap->ent2->timer;
+ r7 = (heap->ent2->animationState + (heap->ent2->animationState >> 1));
+ r7 = (r7 >> 2) + heap->ent2->timer;
} else {
if (super->iframes == 0) {
- if ((super->animIndex != (heap->filler[5].unk1 >> 3) + 0x2f) || (super->frame & ANIM_DONE) != 0) {
- r7 = (heap->filler[5].unk1 >> 3) + 0x28;
+ if ((super->animIndex != (heap->filler[5].unk0.HALF.HI >> 3) + 0x2f)) {
+ r7 = (heap->filler[5].unk0.HALF.HI >> 3) + 0x28;
+ } else {
+ if ((super->frame & ANIM_DONE) != 0) {
+ r7 = (heap->filler[5].unk0.HALF.HI >> 3) + 0x28;
+ } else {
+ r7 = super->animIndex;
+ }
}
} else {
- r7 = (heap->filler[5].unk1 >> 3) + 0x2f;
+ r7 = (heap->filler[5].unk0.HALF.HI >> 3) + 0x2f;
}
}
@@ -1238,9 +1244,9 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE
u32 val;
sub_0802E7CC(heap, (u8)index, 0, 0);
r7 = heap->entities[index]->animationState * 12;
- r7 += (((s32)heap->filler[6 + (index + 1)].unk1) / 3) * 12;
+ r7 += (((s32)heap->filler2[(index + 1)].unk0.HALF.HI) / 3) * 12;
} else {
- r7 = heap->filler[index].unk1 >> 3;
+ r7 = heap->filler[index].unk0.HALF.HI >> 3;
r7 += 0x48;
}
if (heap->entities[index]->animIndex != r7) {
@@ -1250,10 +1256,49 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE
}
END_NONMATCH
-ASM_FUNC("asm/non_matching/gleerok/sub_0802E768.inc", bool32 sub_0802E768(Gleerok_HeapStruct* param_1));
+NONMATCH("asm/non_matching/gleerok/sub_0802E768.inc", bool32 sub_0802E768(Gleerok_HeapStruct* param_1)) {
+ u32 cVar1;
+ s32 bVar2;
+ s32 bVar2a;
+ u32 bVar3;
+
+ // solves regalloc
+ // register u32 bVar3 asm("r1");
+ u32 bVar3a;
+ u32 uVar4;
+ s32 iVar5;
+
+ for (uVar4 = 0; uVar4 <= 4; uVar4++) {
+ bVar3 = param_1->filler[uVar4].unk0.HALF.HI;
+ bVar2 = (bVar3 - param_1->filler[uVar4 + 1].unk0.HALF.HI) & 0x1f;
+
+ if (bVar2 > 0x10) {
+ if (bVar2 <= 0x1e) {
+ bVar3 = (bVar3 + 1) & 0x1f;
+ }
+ } else if (bVar2 > 1) {
+ bVar3 = (bVar3 - 1) & 0x1f;
+ }
+
+ param_1->filler[uVar4].unk0.HALF.HI = bVar3;
+ bVar3 = param_1->filler2[uVar4].unk0.HALF.HI;
+ bVar2 = (bVar3 - param_1->filler2[uVar4 + 1].unk0.HALF.HI) & 0x1f;
+
+ if (bVar2 > 0x10) {
+ if (bVar2 <= 0x1d) {
+ bVar3 = (bVar3 + 1) & 0x1f;
+ }
+ } else if (bVar2 > 2) {
+ bVar3 = (bVar3 - 1) & 0x1f;
+ }
+
+ param_1->filler2[uVar4].unk0.HALF.HI = bVar3;
+ }
+}
+END_NONMATCH
u32 sub_0802E7CC(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4) {
- param_1->entities[(u8)param_2]->animationState = param_1->filler[(u8)param_2].unk1;
+ param_1->entities[(u8)param_2]->animationState = param_1->filler[(u8)param_2].unk0.HALF.HI;
return param_1->entities[(u8)param_2]->animationState;
}