Skip to content

Commit

Permalink
Decompile no0 func_us_801CE2E0 (#1960)
Browse files Browse the repository at this point in the history
Big thanks to bismurphy for helping me work out the array copy that
appears at the beginning of the function (ended up being an inline array
declaration)

https://decomp.me/scratch/Fo9ZW

This entity does not appear in the entity list and doesn't seem to be
called from anywhere so I think it may be unused and deadstripped out of
the PSP.
  • Loading branch information
JoshSchreuder authored Dec 3, 2024
1 parent 09cb3a7 commit 54fcdd5
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 4 deletions.
5 changes: 3 additions & 2 deletions config/splat.us.stno0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ segments:
- [0x1B3C, .data, e_misc]
- [0x1C14, data]
- [0x1C34, data, clock_room]
- [0x1CA0, data]
- [0x1CA0, .data, 4E2E0]
- [0x1CC4, data]
- [0x1E94, .data, e_skelerang]
- [0x1F80, .data, e_plate_lord]
- [0x1F90, data]
Expand Down Expand Up @@ -112,7 +113,7 @@ segments:
- [0x4A4CC, c, e_misc]
- [0x4C750, c]
- [0x4CAAC, c, clock_room]
- [0x4E2E0, c]
- [0x4E2E0, c, 4E2E0]
- [0x4E654, c, e_stage_name]
- [0x4F4A8, c, e_diplocephalus]
- [0x50990, c, e_diplocephalus_2]
Expand Down
13 changes: 13 additions & 0 deletions include/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -2249,6 +2249,18 @@ typedef struct {
struct Entity* parent;
} ET_801737F0;

typedef struct {
/* 0x7C */ u8 unk7C;
/* 0x7D */ u8 : 8;
/* 0x7E */ u16 : 16;
/* 0x80 */ s16 unk80;
/* 0x82 */ u16 : 16;
/* 0x84 */ u16 posX;
/* 0x86 */ u16 posY;
/* 0x88 */ u16 unk88;
/* 0x8A */ s16 unk8A;
} ET_801CE2E0;

typedef union { // offset=0x7C
struct Primitive* prim;
ET_Placeholder ILLEGAL;
Expand Down Expand Up @@ -2437,6 +2449,7 @@ typedef union { // offset=0x7C
ET_DiplocephalusFireball diplocephalusFireball;
ET_PlateLord plateLord;
ET_PlatelordUnknown plateLordUnknown;
ET_801CE2E0 et_801CE2E0;
} Ext;

#define SYNC_FIELD(struct1, struct2, field) \
Expand Down
90 changes: 88 additions & 2 deletions src/st/no0/4E2E0.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,92 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#include "no0.h"

INCLUDE_ASM("st/no0/nonmatchings/4E2E0", func_us_801CE2E0);
static u8 anim_unk[] = {
0x01, 0x01, 0x01, 0x02, 0x01, 0x03, 0x01, 0x04, 0x01, 0x05, 0x01, 0x06,
0x01, 0x07, 0x01, 0x08, 0x01, 0x09, 0x01, 0x0A, 0x01, 0x0B, 0x01, 0x0C,
0x01, 0x0D, 0x01, 0x0E, 0x01, 0x0F, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00};

INCLUDE_RODATA("st/no0/nonmatchings/4E2E0", D_us_801C14A8);
// Does not appear in the entity list and appears to be unused
void func_us_801CE2E0(Entity* self) {
s16 yOffsets[8] = {-2, -1, -1, 0, 0, 1, 1, 2};
Entity* player;
s32 collision;
s16 offset;
u16 flags;

if (self->step != 0) {
UnkAnimFunc(anim_unk, self, 5);
self->rotZ += 0x80;
player = &PLAYER;
if (self->ext.et_801CE2E0.unk88 & 0x40) {
self->velocityY = FIX(-0.5);
} else {
self->velocityY = FIX(0.5);
}

self->velocityX = 0;
self->ext.et_801CE2E0.unk88++;
MoveEntity();
if (self->ext.et_801CE2E0.unk7C & 0x4) {
offset = (self->posY.i.hi + g_Tilemap.scrollY.i.hi) -
self->ext.et_801CE2E0.posY;
if (offset > 0 || (offset < 0 && (g_Player.pl_vram_flag ^ 2) & 2)) {
player->posY.i.hi += offset;
}
}
flags = 15;
if (self->ext.et_801CE2E0.unk8A != 0) {
self->ext.et_801CE2E0.unk8A--;
flags = 11;
}

if (self->ext.et_801CE2E0.unk80 & 0xF &&
(self->ext.et_801CE2E0.unk80 & 0xF0)) {
flags |= 0x10;
}

collision = GetPlayerCollisionWith(self, 24, 8, flags);
if (self->ext.et_801CE2E0.unk80 & 0xF) {
if (self->ext.et_801CE2E0.unk80 & 0xF0) {
offset = -yOffsets[(self->ext.et_801CE2E0.unk80 & 0xF) - 1];
} else {
offset = yOffsets[self->ext.et_801CE2E0.unk80 - 1];
}
self->posY.i.hi += offset;
if (collision & 4) {
player->posY.i.hi += offset;
}
self->ext.et_801CE2E0.unk80--;
}

if (collision & 4) {
if (self->ext.et_801CE2E0.unk7C != 4 &&
!(self->ext.et_801CE2E0.unk80 & 0xF) &&
F(player->velocityY).i.hi > 0) {
self->ext.et_801CE2E0.unk80 = 8;
}
offset = self->posX.i.hi + g_Tilemap.scrollX.i.hi -
self->ext.et_801CE2E0.posX;
if ((offset > 0 && g_Player.pl_vram_flag != 4) ||
(offset < 0 && g_Player.pl_vram_flag != 8)) {
player->posX.i.hi += offset;
}
} else if (self->ext.et_801CE2E0.unk7C & 4) {
self->ext.et_801CE2E0.unk8A = 8;
}

if ((collision & 0x2) && !(self->ext.et_801CE2E0.unk80 & 0xF)) {
self->ext.et_801CE2E0.unk80 = 24;
}
self->ext.et_801CE2E0.unk7C = collision;
} else {
InitializeEntity(D_us_80180AAC);
self->animCurFrame = 1;
self->hitboxWidth = 24;
self->hitboxHeight = 8;
self->hitboxState = 2;
self->ext.et_801CE2E0.unk88 = 0;
}
self->ext.et_801CE2E0.posX = self->posX.i.hi + g_Tilemap.scrollX.i.hi;
self->ext.et_801CE2E0.posY = self->posY.i.hi + g_Tilemap.scrollY.i.hi;
}
2 changes: 2 additions & 0 deletions src/st/no0/no0.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ extern u16 g_EInitCommon[];
extern u16 g_EInitParticle[];
extern u16 g_EInitInteractable[];

extern EInit D_us_80180AAC;

// Axe knight
extern EInit g_EInitAxeKnightAxe;

Expand Down

0 comments on commit 54fcdd5

Please sign in to comment.