Decompile DRA func_80129864 (#1364)

PSX: https://decomp.me/scratch/0camu
PSP: https://decomp.me/scratch/g2m4c

The previous version of the PSX decomp.me has some clues to better
variable names but I was having trouble solving the final register
mismatches.
This commit is contained in:
Josh Lory 2024-07-01 17:06:55 -07:00 committed by GitHub
parent 0312a85553
commit fd2bc9382e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 239 additions and 5 deletions

View File

@ -67,6 +67,7 @@ D_800B0798 = 0x800B085C;
D_800B07C8 = 0x800B088C;
D_800B0830 = 0x800B08F4;
D_800B083C = 0x800B0900;
D_800B0846 = 0x800B090A;
D_800B0858 = 0x800B091C;
D_800B0860 = 0x800B0924;
D_800B08CC = 0x800B0990;
@ -176,7 +177,6 @@ func_8010E3B8 = 0x8010E0FC;
func_80113EE0 = 0x80113BD0;
func_80113F7C = 0x80113C6C;
func_80115394 = 0x80115084;
func_80118970 = 0x80118668;
func_80118C28 = 0x80118920;
EntityNumberMovesToHpMeter = 0x80118A04;
EntityGuardText = 0x80119280;
@ -192,14 +192,12 @@ EntityLevelUpAnimation = 0x8012162C;
func_80121F58 = 0x80121C04;
EntityMist = 0x80121FC8;
EntitySubwpnThrownDagger = 0x80124814;
func_80129864 = 0x801294F0;
EntityStopWatch = 0x8012A528;
EntityBatEcho = 0x8012BB84;
func_8012CB0C = 0x8012C798;
func_8012F178 = 0x8012ED9C;
func_8012F83C = 0x8012F42C;
func_8012F894 = 0x8012F484;
func_80134714 = 0x801342F0;
PlaySfx = 0x801343D4;
g_DebugFreeze = 0x80135E88;
g_DebugHitboxViewMode = 0x80135E8C;

View File

@ -1122,6 +1122,14 @@ typedef struct {
u8 unk29;
} ET_80123B40;
typedef struct {
struct Entity* ent;
s16 unk80;
s16 unk82;
s16 unk84;
s16 unk86;
} ET_80129864;
typedef union { // offset=0x7C
struct Primitive* prim;
char stub[0x40];
@ -1226,5 +1234,6 @@ typedef union { // offset=0x7C
ET_Owl owl;
ET_AlucardWaterEffect aluwater;
ET_80123B40 et_80123B40;
ET_80129864 et_80129864;
ET_801B28E4 et_801B28E4;
} Ext;

View File

@ -2303,7 +2303,231 @@ void EntityAguneaHitEnemy(Entity* self) {
}
}
INCLUDE_ASM("dra/nonmatchings/843B0", func_80129864);
void func_80129864(Entity* self) {
s32 a = 11;
s32 b = 25;
Primitive* prim;
s32 s1;
s32 s3;
s32 s4;
s32 i;
s32 s6;
s32 s7;
s32 action;
u8 temp_u;
u8 temp_v;
s32 angle_diff;
s32 angle_offset;
s32 otherX, otherY;
switch (self->step) {
case 0:
self->primIndex = AllocPrimitives(4, 0x10);
if (self->primIndex == -1) {
DestroyEntity(self);
return;
}
prim = &g_PrimBuf[self->primIndex];
for (i = 0; i < 8; i++) {
prim->type = 1;
prim->u0 = 1;
prim->v0 = 1;
prim->drawMode = DRAW_UNK02;
prim->priority = 0;
prim = prim->next;
prim->priority = 0x1C2;
prim->drawMode =
DRAW_UNK_100 | DRAW_UNK_40 | DRAW_TPAGE2 | DRAW_TPAGE |
DRAW_HIDE | DRAW_COLORS | DRAW_UNK02 | DRAW_TRANSP;
prim->tpage = 0x1A;
prim->clut = 0x19F;
prim = prim->next;
}
self->facingLeft = (PLAYER.facingLeft + 1) & 1; // !PLAYER.facingLeft
self->ext.et_80129864.unk80 = D_800B0858[(u8)self->params];
self->animSet = 9;
self->unk4C = D_800B0798;
self->palette = PAL_OVL(0x19F);
self->drawMode = DRAW_UNK_40 | DRAW_TPAGE2 | DRAW_TPAGE;
self->zPriority = 0x1C3;
self->flags = FLAG_UNK_08000000 | FLAG_UNK_04000000 | FLAG_UNK_800000 |
FLAG_UNK_100000 | FLAG_UNK_20000 | FLAG_UNK_10000;
self->drawFlags = 4;
if (self->params & 0x7F00) {
func_8011A328(self, 3);
} else {
func_8011A328(self, 1);
}
self->hitboxWidth = 6;
self->hitboxHeight = 6;
self->step++;
break;
case 1:
s1 = rcos(self->ext.et_80129864.unk82) >> 8;
self->ext.et_80129864.unk82 += 0x80;
self->ext.et_80129864.unk80 += s1;
if (self->posY.i.hi < -0x20) {
self->ext.et_80129864.ent = func_80118970();
self->ext.et_80129864.unk84 = 0;
self->ext.et_80129864.unk80 = 0xC00;
if ((self->params & 0xFF) > 1) {
self->facingLeft = (self->facingLeft + 1) & 1;
}
self->step++;
}
break;
case 2:
if (self->ext.et_80129864.unk84 < 0x18) {
angle_offset = 0x10;
} else if (self->ext.et_80129864.unk84 < 0x28) {
angle_offset = 0x20;
} else if (self->ext.et_80129864.unk84 < 0x38) {
angle_offset = 0x40;
} else {
angle_offset = 0x80;
}
if (self->ext.et_80129864.ent != NULL) {
if (!self->ext.et_80129864.ent->entityId) {
self->step++;
break;
} else {
otherX = self->ext.et_80129864.ent->posX.i.hi;
otherY = self->ext.et_80129864.ent->posY.i.hi;
}
} else {
if (self->facingLeft) {
otherX = 0x140;
otherY = 0xA0;
} else {
otherX = -0x40;
otherY = 0xA0;
}
if (self->params & 1) {
otherY += 0x40;
}
}
s1 = ratan2(self->posY.i.hi - otherY, otherX - self->posX.i.hi) & 0xFFF;
s3 = self->ext.et_80129864.unk80 & 0xFFF;
angle_diff = abs(s3 - s1);
angle_offset = CLAMP_MAX(angle_offset, angle_diff);
if (s3 < s1) {
if (angle_diff < 0x800) {
s3 += angle_offset;
} else {
s3 -= angle_offset;
}
} else {
if (angle_diff < 0x800) {
s3 -= angle_offset;
} else {
s3 += angle_offset;
}
}
self->ext.et_80129864.unk80 = s3 & 0xFFF;
if (++self->ext.et_80129864.unk84 > 0x60) {
self->step++;
}
break;
case 3:
self->flags = FLAG_UNK_08000000 | FLAG_UNK_800000 | FLAG_UNK_100000 |
FLAG_UNK_10000;
s1 = rcos(self->ext.et_80129864.unk82) >> 8;
self->ext.et_80129864.unk82 += 0x80;
self->ext.et_80129864.unk80 += s1;
break;
}
self->velocityX = rcos(self->ext.et_80129864.unk80) << 6;
self->velocityY = -(rsin(self->ext.et_80129864.unk80) << 6);
self->posX.val += self->velocityX;
self->posY.val += self->velocityY;
if (self->facingLeft) {
self->rotZ = self->ext.et_80129864.unk80;
} else {
self->rotZ = 0x800 - self->ext.et_80129864.unk80;
}
prim = &g_PrimBuf[self->primIndex];
for (i = 0; i < 8; i++) {
if (self->ext.et_80129864.unk86 == i) {
prim->x1 = 1;
}
switch (prim->x1) {
case 0:
action = 0;
break;
case 1:
action = 1;
prim->x1 += 1;
prim->y1 = 0x100;
prim->x0 = self->posX.i.hi;
prim->y0 = self->posY.i.hi;
prim->x2 = self->ext.et_80129864.unk80;
break;
case 2:
prim->y1 -= 16;
action = 2;
break;
}
s3 = prim->x2;
s6 = prim->x0;
s7 = prim->y0;
s4 = prim->y1;
prim = prim->next;
switch (action) {
case 0:
prim->drawMode |= DRAW_HIDE;
break;
case 1:
temp_u = D_800B0846[self->animCurFrame * 2];
temp_v = D_800B0846[self->animCurFrame * 2 + 1];
prim->u0 = prim->u2 = temp_u;
prim->u1 = prim->u3 = temp_u + 31;
prim->v0 = prim->v1 = temp_v;
prim->v2 = prim->v3 = temp_v + 15;
prim->r0 = prim->b0 = prim->g0 = prim->r1 = prim->b1 = prim->g1 =
prim->r2 = prim->b2 = prim->g2 = prim->r3 = prim->b3 =
prim->g3 = 0x80;
prim->drawMode &= ~DRAW_HIDE;
break;
case 2:
if (prim->g3 > 4) {
prim->g3 -= 12;
}
prim->r0 = prim->b0 = prim->g0 = prim->r1 = prim->b1 = prim->g1 =
prim->r2 = prim->b2 = prim->g2 = prim->r3 = prim->b3 = prim->g3;
break;
}
if (action) {
s1 = s3 - 0x200;
prim->x0 = s6 + ((((rcos(s1) >> 4) * a >> 8) * s4) >> 8);
prim->y0 = s7 - ((((rsin(s1) >> 4) * a >> 8) * s4) >> 8);
s1 = s3 + 0x200;
prim->x2 = s6 + ((((rcos(s1) >> 4) * a >> 8) * s4) >> 8);
prim->y2 = s7 - ((((rsin(s1) >> 4) * a >> 8) * s4) >> 8);
s1 = s3 - 0x734;
prim->x1 = s6 + ((((rcos(s1) >> 4) * b >> 8) * s4) >> 8);
prim->y1 = s7 - ((((rsin(s1) >> 4) * b >> 8) * s4) >> 8);
s1 = s3 + 0x734;
prim->x3 = s6 + ((((rcos(s1) >> 4) * b >> 8) * s4) >> 8);
prim->y3 = s7 - ((((rsin(s1) >> 4) * b >> 8) * s4) >> 8);
}
prim = prim->next;
}
self->ext.et_80129864.unk86 += 1;
self->ext.et_80129864.unk86 = self->ext.et_80129864.unk86 % 8;
}
// opens hole in backround and spirit comes out (ID 0x40)
void EntitySummonSpirit(Entity* self) {

View File

@ -369,6 +369,8 @@ extern AnimationFrame D_800B0798[];
extern s32 D_800B07C8;
extern s32 D_800B0830[];
extern s32 D_800B083C[];
extern u8 D_800B0846[];
extern u16 D_800B0858[];
extern s16 D_800B0860[];
extern unk_800B08CC D_800B08CC[];
extern s32 D_800B0914;

View File

@ -166,6 +166,8 @@ s16 D_800ACF94[16]; // guessed size
u8 D_800ACFB4[20][4]; // TODO AnimationFrames*[], random size
s32 D_800B0830[99]; // random size to play safe
s32 D_800B083C[99]; // random size to play safe
u8 D_800B0846[18]; // guessed size
u16 D_800B0858[2]; // might be part of the next array
s16 D_800B0860[99]; // random size to play safe
AnimationFrame D_800B0798[40]; // random size to play safe
u8 D_800B0F94[100][5]; // random size to play safe
@ -608,4 +610,3 @@ void EntityTransparentWhiteCircle(Entity* self) { NOT_IMPLEMENTED; }
void EntityStopWatch(Entity* self) { NOT_IMPLEMENTED; }
void EntityBatEcho(Entity* self) { NOT_IMPLEMENTED; }
void func_8012F894(Entity* self) { NOT_IMPLEMENTED; }
void func_80129864(Entity* self) { NOT_IMPLEMENTED; }