Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decompiled lib func_us_801BBAB4/func_psp_09256018 #2254

Merged
merged 8 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/symbols.pspeu.stlib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func_us_801BB53C = 0x09254288;
EntityBreakable = 0x092546D0;
EntityChair = 0x09254DC0;
func_us_801BB8DC = 0x09255D78;
func_us_801BBAB4 = 0x09256018;
GetLang = 0x0925A830;
DrawCutsceneActorName = 0x0925A8D0;
CutsceneUnk3 = 0x0925ABE8;
Expand Down
7 changes: 7 additions & 0 deletions include/primitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ typedef enum {
// prim->r0 = prim->g0 = prim->b0 = 255 becomes
// PGREY(prim, 0) = 255
#define PGREY(p, n) p->r##n = p->g##n = p->b##n
// TODO: Merge these two macros
// This one was created to work for both PSP and PSX, but touches
// enough files to justify a separate PR to change the original.
#define PGREY_ALT(p, n, v) \
p->r##n = v; \
p->g##n = v; \
p->b##n = v;

typedef enum {
PRIM_NONE,
Expand Down
17 changes: 0 additions & 17 deletions include/unkstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,6 @@ typedef struct {
s32 unkC;
} Unkstruct_800FDB18;

typedef struct Unkstruct_801C6C6C {
union {
struct {
u16 w;
u16 x;
} c;
s32 p;
} x;
union {
struct {
u16 h;
u16 y;
} c;
s32 p;
} y;
} Unkstruct_801C6C6C;

typedef struct {
u16 start;
s16 current;
Expand Down
97 changes: 95 additions & 2 deletions src/st/lib/e_lesser_demon.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,101 @@
// Lesser demon start
INCLUDE_ASM("st/lib/nonmatchings/e_lesser_demon", func_us_801BB8DC);

u8 func_us_801BBAB4(void);
INCLUDE_ASM("st/lib/nonmatchings/e_lesser_demon", func_us_801BBAB4);
// Seems to be the windup just before the spit attack
u8 func_us_801BBAB4(void) {
Primitive* prim;
Pos tempPrim;
s32 primIndex;
s32 unkVar;
u8 randomVal;
u8 ret;
#ifdef VERSION_US
s32 dummy[2];
#endif

ret = false;
switch (g_CurrentEntity->ext.lesserDemon.unk84) {
case 0:
primIndex = g_api.AllocPrimitives(PRIM_TILE, 0x18);
if (primIndex != -1) {
g_CurrentEntity->primIndex = primIndex;
g_CurrentEntity->flags |= FLAG_HAS_PRIMS;
prim = &g_PrimBuf[primIndex];
g_CurrentEntity->ext.lesserDemon.unk7C = prim;
for (; prim != NULL; prim = prim->next) {
PGREY_ALT(prim, 0, 0)
prim->u0 = 2;
prim->v0 = 2;
prim->priority = g_CurrentEntity->zPriority + 2;
prim->drawMode =
DRAW_TPAGE2 | DRAW_TPAGE | DRAW_UNK02 | DRAW_TRANSP;
randomVal = Random() & 0x7F;
if (g_CurrentEntity->facingLeft) {
// These look like they could be -= and += respectively,
// but that oddly does not match
randomVal = randomVal - 0x40;
} else {
randomVal = randomVal + 0x40;
}
prim->x0 = (g_CurrentEntity->posX.i.hi +
((rcos((randomVal) * 0x10) * 0x60) >> 0xC) +
(Random() & 0x3F)) -
0x1F;
prim->y0 = (g_CurrentEntity->posY.i.hi +
((rsin((randomVal) * 0x10) * 0x60) >> 0xC) +
(Random() & 0x3F)) -
0x1F;
prim->x1 = 0;
prim->y1 = 0;
if (g_CurrentEntity->facingLeft) {
unkVar =
prim->x0 - (g_CurrentEntity->posX.i.hi + 0xA) << 0x10;
} else {
unkVar =
prim->x0 - (g_CurrentEntity->posX.i.hi - 0xA) << 0x10;
}
LOW(prim->x2) = -unkVar / 48;
unkVar =
(prim->y0 - (g_CurrentEntity->posY.i.hi - 0xB) << 0x10);
LOW(prim->x3) = -unkVar / 48;
}
} else {
ret = true;
g_CurrentEntity->ext.lesserDemon.unk84 = 2;
}
g_CurrentEntity->ext.lesserDemon.unk80 = 0;
g_CurrentEntity->ext.lesserDemon.unk84++;
break;
case 1:
prim = g_CurrentEntity->ext.lesserDemon.unk7C;
for (; prim != NULL; prim = prim->next) {
tempPrim.x.i.hi = prim->x0;
tempPrim.x.i.lo = prim->x1;
tempPrim.y.i.hi = prim->y0;
tempPrim.y.i.lo = prim->y1;
tempPrim.x.val += LOWU(prim->x2);
tempPrim.y.val += LOWU(prim->x3);
LOH(prim->x0) = tempPrim.x.i.hi;
LOH(prim->x1) = tempPrim.x.i.lo;
LOH(prim->y0) = tempPrim.y.i.hi;
LOH(prim->y1) = tempPrim.y.i.lo;
prim->r0 += 3;
}
prim = g_CurrentEntity->ext.lesserDemon.unk7C;
PrimToggleVisibility(prim, 0x18);
if (g_CurrentEntity->ext.lesserDemon.unk80++ > 0x30) {
primIndex = g_CurrentEntity->primIndex;
g_api.FreePrimitives(primIndex);
g_CurrentEntity->flags &= ~FLAG_HAS_PRIMS;
g_CurrentEntity->ext.lesserDemon.unk84++;
g_CurrentEntity->ext.lesserDemon.unk80 = 0;
}
break;
case 2:
ret = true;
}
return ret;
}

INCLUDE_ASM("st/lib/nonmatchings/e_lesser_demon", func_us_801BBEB0);

Expand Down
97 changes: 96 additions & 1 deletion src/st/lib_psp/unk_1D9E8.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,102 @@ INCLUDE_ASM("st/lib_psp/psp/lib_psp/unk_1D9E8", func_psp_09255068);

INCLUDE_ASM("st/lib_psp/psp/lib_psp/unk_1D9E8", func_us_801BB8DC);

INCLUDE_ASM("st/lib_psp/psp/lib_psp/unk_1D9E8", func_psp_09256018);
// func_us_801BBAB4 code is shared with PSX and is ready for merge
// Seems to be the windup just before the spit attack
u8 func_us_801BBAB4(void) {
Primitive* prim;
Pos tempPrim;
s32 primIndex;
s32 unkVar;
u8 randomVal;
u8 ret;
#ifdef VERSION_US
s32 dummy[2];
#endif

ret = false;
switch (g_CurrentEntity->ext.lesserDemon.unk84) {
case 0:
primIndex = g_api.AllocPrimitives(PRIM_TILE, 0x18);
if (primIndex != -1) {
g_CurrentEntity->primIndex = primIndex;
g_CurrentEntity->flags |= FLAG_HAS_PRIMS;
prim = &g_PrimBuf[primIndex];
g_CurrentEntity->ext.lesserDemon.unk7C = prim;
for (; prim != NULL; prim = prim->next) {
PGREY_ALT(prim, 0, 0)
prim->u0 = 2;
prim->v0 = 2;
prim->priority = g_CurrentEntity->zPriority + 2;
prim->drawMode =
DRAW_TPAGE2 | DRAW_TPAGE | DRAW_UNK02 | DRAW_TRANSP;
randomVal = Random() & 0x7F;
if (g_CurrentEntity->facingLeft) {
// These look like they could be -= and += respectively,
// but that oddly does not match
randomVal = randomVal - 0x40;
} else {
randomVal = randomVal + 0x40;
}
prim->x0 = (g_CurrentEntity->posX.i.hi +
((rcos((randomVal) * 0x10) * 0x60) >> 0xC) +
(Random() & 0x3F)) -
0x1F;
prim->y0 = (g_CurrentEntity->posY.i.hi +
((rsin((randomVal) * 0x10) * 0x60) >> 0xC) +
(Random() & 0x3F)) -
0x1F;
prim->x1 = 0;
prim->y1 = 0;
if (g_CurrentEntity->facingLeft) {
unkVar =
prim->x0 - (g_CurrentEntity->posX.i.hi + 0xA) << 0x10;
} else {
unkVar =
prim->x0 - (g_CurrentEntity->posX.i.hi - 0xA) << 0x10;
}
LOW(prim->x2) = -unkVar / 48;
unkVar =
(prim->y0 - (g_CurrentEntity->posY.i.hi - 0xB) << 0x10);
LOW(prim->x3) = -unkVar / 48;
}
} else {
ret = true;
g_CurrentEntity->ext.lesserDemon.unk84 = 2;
}
g_CurrentEntity->ext.lesserDemon.unk80 = 0;
g_CurrentEntity->ext.lesserDemon.unk84++;
break;
case 1:
prim = g_CurrentEntity->ext.lesserDemon.unk7C;
for (; prim != NULL; prim = prim->next) {
tempPrim.x.i.hi = prim->x0;
tempPrim.x.i.lo = prim->x1;
tempPrim.y.i.hi = prim->y0;
tempPrim.y.i.lo = prim->y1;
tempPrim.x.val += LOWU(prim->x2);
tempPrim.y.val += LOWU(prim->x3);
LOH(prim->x0) = tempPrim.x.i.hi;
LOH(prim->x1) = tempPrim.x.i.lo;
LOH(prim->y0) = tempPrim.y.i.hi;
LOH(prim->y1) = tempPrim.y.i.lo;
prim->r0 += 3;
}
prim = g_CurrentEntity->ext.lesserDemon.unk7C;
PrimToggleVisibility(prim, 0x18);
if (g_CurrentEntity->ext.lesserDemon.unk80++ > 0x30) {
primIndex = g_CurrentEntity->primIndex;
g_api.FreePrimitives(primIndex);
g_CurrentEntity->flags &= ~FLAG_HAS_PRIMS;
g_CurrentEntity->ext.lesserDemon.unk84++;
g_CurrentEntity->ext.lesserDemon.unk80 = 0;
}
break;
case 2:
ret = true;
}
return ret;
}

INCLUDE_ASM("st/lib_psp/psp/lib_psp/unk_1D9E8", func_psp_092564B8);

Expand Down
22 changes: 11 additions & 11 deletions src/st/nz0/e_spittle_bone.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void EntityRotateSpittlebone(Entity* self) {
// spit projectile from spittle bone
void EntitySpittleBoneSpit(Entity* self) {
Collider collider;
Unkstruct_801C6C6C test;
Pos tempPrim;
s16 primIndex;
Primitive* prim;
Entity* entity;
Expand Down Expand Up @@ -277,16 +277,16 @@ void EntitySpittleBoneSpit(Entity* self) {

prim = *(s32*)&self->ext.spittleBone.unk84;
while (prim != NULL) {
test.x.c.x = prim->x0;
test.x.c.w = prim->x1;
test.y.c.y = prim->y0;
test.y.c.h = prim->y1;
test.x.p += LOW(prim->x2);
test.y.p += LOW(prim->x3);
prim->x0 = test.x.c.x;
prim->x1 = test.x.c.w;
prim->y0 = test.y.c.y;
prim->y1 = test.y.c.h;
tempPrim.x.i.hi = prim->x0;
tempPrim.x.i.lo = prim->x1;
tempPrim.y.i.hi = prim->y0;
tempPrim.y.i.lo = prim->y1;
tempPrim.x.val += LOWU(prim->x2);
tempPrim.y.val += LOWU(prim->x3);
LOH(prim->x0) = tempPrim.x.i.hi;
LOH(prim->x1) = tempPrim.x.i.lo;
LOH(prim->y0) = tempPrim.y.i.hi;
LOH(prim->y1) = tempPrim.y.i.lo;
LOW(prim->x3) += 0x1800;
if (LOW(prim->x3) > 0) {
g_api.CheckCollision(
Expand Down
Loading