tt_001 duplicate function decomp (#1670)

- Decompiled duplicate function func_us_801714F4
- Decompiled duplicate function func_us_80172904
- Decompiled duplicate function func_us_8017293C (renamed
Tt001UpdateAnim per tt_000 duplicate)
- Decompiled duplicate function func_us_80172B50
- Decompiled duplicate function func_us_80172B88
- Added EntitySearch D_80170EE4[] to servant.h to be used by
func_us_80172B88 similar to duplicate in tt_000

A lot of these are in the same order in tt_000, so I would assume they
could be moved to shared static functions at some point.
This commit is contained in:
Onenutmcgee 2024-09-25 02:39:35 -05:00 committed by GitHub
parent 181a6fe95b
commit e357fcaeeb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 150 additions and 129 deletions

View File

@ -1 +1 @@
_D_80174D3C = 0x060D1DFC;
_g_IsServantDestroyed = 0x060D1DFC;

View File

@ -1,6 +1,6 @@
func_801710E8 = 0x092e7680;
func_8017110C = 0x092e76c8;
func_801713C8 = 0x092e7a78;
CheckEntityValid = 0x092e7a78;
func_80171560 = 0x092e7b80;
CreateBlueTrailEntity = 0x092e7b90;
func_8017160C = 0x092e7c68;
@ -22,7 +22,7 @@ func_80173C0C = 0x092EB7D8;
func_80173C14 = 0x092EB7E0;
func_80173C1C = 0x092EB7E8;
func_80173C24 = 0x092EB7F0;
func_80173C2C = 0x092eb7f8;
DestroyServantEntity = 0x092eb7f8;
DestroyEntity = 0x092eb850;
func_80173F30 = 0x092eb8e8;
func_80173F74 = 0x092eb988;
@ -75,6 +75,6 @@ g_CurrentServant = 0x092ed808;
g_CurrentRoomX = 0x092ed810;
g_CurrentRoomY = 0x092ed818;
D_80174D40 = 0x092ED820;
D_80174D3C = 0x092ED828;
g_IsServantDestroyed = 0x092ED828;
D_80174C3C = 0x092ED830;
D_80174C30 = 0x092ed930;

View File

@ -79,8 +79,6 @@ DestroyEntity = 0x801C4C64;
AnimateEntity = 0x801C4D94;
GetDistanceToPlayerX = 0x801C4F64;
GetSideToPlayer = 0x801C4FD4;
MoveEntity = 0x801C5018;
FallEntity = 0x801C5048;
UnkCollisionFunc3 = 0x801C5074;
UnkCollisionFunc2 = 0x801C52EC;
AllocEntity = 0x801C54D4;

View File

@ -0,0 +1,2 @@
CheckEntityValid = 0x801713C8;
g_IsServantDestroyed = 0x80174D3C;

View File

@ -0,0 +1,5 @@
g_EntityRanges = 0x80170EE4;
CheckEntityValid = 0x801714F4;
DestroyServantEntity = 0x80172904;
DestroyEntity = 0x80172AE4;
g_IsServantDestroyed = 0x8017381C;

View File

@ -62,10 +62,12 @@ extern Sprite D_80170608[];
extern s32 D_80170658[][5];
extern u16 D_80170720[];
extern s32 D_80171090;
extern EntitySearch D_80171094[];
extern EntitySearch g_EntityRanges[];
#ifdef VERSION_PSP
extern ServantDesc D_8D1DC40;
#endif
void DestroyEntity(Entity* entity);
#endif

View File

@ -26,15 +26,15 @@ void f60D101C() {}
void f60D1028() {}
void f60D1034() {}
extern s32 D_80174D3C; // 0x060D1DFCh
extern s32 g_IsServantDestroyed; // 0x060D1DFCh
void DestroyEntity(Entity*); // func_0600FFB8h
// PSX: func_80173C2C
// SAT: func_060D1040
void func_80173C2C(Entity* entity) {
void DestroyServantEntity(Entity* entity) {
if (entity->params == 0xF) {
D_80174D3C = 1;
g_IsServantDestroyed = 1;
}
func_0600FFB8(entity); // DestroyEntity
}

View File

@ -0,0 +1,16 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
s32 AccumulateTowardZero(s32 arg0, s32 arg1) {
if (arg0 < 0) {
arg0 += arg1;
if (arg0 > 0) {
arg0 = 0;
}
} else {
arg0 -= arg1;
if (arg0 < 0) {
arg0 = 0;
}
}
return arg0;
}

View File

@ -0,0 +1,19 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
s32 CheckEntityValid(Entity* entity) {
if (entity->hitboxState == 0)
return 0;
if (entity->posX.i.hi < -16)
return 0;
if (entity->posX.i.hi > 272)
return 0;
if (entity->posY.i.hi > 240)
return 0;
if (entity->posY.i.hi < 0)
return 0;
if (entity->hitPoints >= 0x7000)
return 0;
if (entity->hitPoints <= 0)
return 0;
return 1;
}

View File

@ -0,0 +1,9 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
void DestroyServantEntity(Entity* self) {
switch (self->params) {
case 15:
g_IsServantDestroyed = 1;
break;
}
DestroyEntity(self);
}

View File

@ -0,0 +1,16 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
Entity* SearchForEntityInRange(s32 rangeIndex, s32 entityId) {
volatile u32 pad; // fake?
s16 start = g_EntityRanges[rangeIndex].start;
s16 end = g_EntityRanges[rangeIndex].end;
Entity* entity = &g_Entities[start];
s32 i;
for (i = start; end >= i; i++, entity++) {
if (entity->entityId == entityId) {
return entity;
}
}
return NULL;
}

View File

@ -0,0 +1,45 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
u32 ServantUpdateAnim(Entity* self, s8* frameProps, AnimationFrame** frames) {
AnimationFrame* animFrame;
s32 ret;
ret = 0;
if (self->animFrameDuration == -1) {
ret = -1;
} else if (self->animFrameDuration == 0) {
self->animFrameDuration = self->anim[self->animFrameIdx].duration;
} else if (--self->animFrameDuration == 0) {
self->animFrameIdx++;
animFrame = &self->anim[self->animFrameIdx];
// Effectively a switch statement, but breaks if I actually use one.
if (animFrame->duration == 0) {
self->animFrameIdx = animFrame->unk2;
self->animFrameDuration = self->anim[self->animFrameIdx].duration;
ret = 0;
} else if (animFrame->duration == 0xFFFF) {
self->animFrameIdx--;
self->animFrameDuration = -1;
ret = -1;
} else if (animFrame->duration == 0xFFFE) {
self->anim = frames[animFrame->unk2];
self->animFrameIdx = 0;
ret = -2;
self->animFrameDuration = self->anim->duration;
} else {
self->animFrameDuration = animFrame->duration;
}
}
if (frameProps != NULL) {
// This is ugly - theoretically the type for frameProps should be
// FrameProperty* but anything besides this where we assign this big
// expression fails.
frameProps =
&frameProps[(self->anim[self->animFrameIdx].unk2 >> 9) << 2];
self->hitboxOffX = *frameProps++;
self->hitboxOffY = *frameProps++;
self->hitboxWidth = *frameProps++;
self->hitboxHeight = *frameProps++;
}
self->animCurFrame = self->anim[self->animFrameIdx].unk2 & 0x1FF;
return ret;
}

View File

@ -35,7 +35,7 @@ s16 D_80174C0C[16];
s32 D_80174C2C;
FamiliarStats D_80174C30;
Point16 D_80174C3C[4][16];
s32 D_80174D3C;
s32 g_IsServantDestroyed;
s32 D_80174D40;
s32 _unused[26];
@ -54,13 +54,13 @@ void func_80173C0C(void);
void func_80173C14(void);
void func_80173C1C(void);
void func_80173C24(void);
void func_80173C2C(Entity* self);
void DestroyServantEntity(Entity* self);
ServantDesc g_ServantDesc = {
func_80171ED4, func_80172120, func_80172C30, func_8017339C,
func_801733A4, func_801733AC, func_801733B4, func_801733BC,
func_801733C4, func_801733CC, BatFamiliarBlueTrail, func_80173C0C,
func_80173C14, func_80173C1C, func_80173C24, func_80173C2C,
func_80173C14, func_80173C1C, func_80173C24, DestroyServantEntity,
};
#endif
@ -98,10 +98,9 @@ extern s16 D_80174C0C[16];
extern s32 D_80174C2C;
extern FamiliarStats D_80174C30;
extern Point16 D_80174C3C[4][16];
extern s32 D_80174D3C;
extern s32 g_IsServantDestroyed;
extern s32 D_80174D40;
void DestroyEntity(Entity* entity);
void ProcessEvent(Entity* self, bool resetEvent);
void CreateEventEntity(Entity* entityParent, s32 entityId, s32 params);
#endif
@ -190,24 +189,7 @@ Entity* func_8017110C(Entity* self) {
return NULL;
}
s32 func_801713C8(Entity* entity) {
if (entity->hitboxState == 0)
return 0;
if (entity->posX.i.hi < -16)
return 0;
if (entity->posX.i.hi > 272)
return 0;
if (entity->posY.i.hi > 240)
return 0;
if (entity->posY.i.hi < 0)
return 0;
if (entity->hitPoints >= 0x7000)
return 0;
if (entity->hitPoints <= 0)
return 0;
return 1;
}
#include "../check_entity_valid.h"
#ifndef VERSION_PSP
bool func_80171434(s16 x, s16 y, s16* outX, s16* outY) {
@ -548,7 +530,7 @@ void func_80171ED4(s32 arg0) {
}
e->ext.bat.cameraX = g_Tilemap.scrollX.i.hi;
e->ext.bat.cameraY = g_Tilemap.scrollY.i.hi;
D_80174D3C = 0;
g_IsServantDestroyed = 0;
}
s16 func_80173F74(s16 x1, s16 x2, s16 minDistance);
@ -559,7 +541,7 @@ INCLUDE_ASM("servant/tt_000/nonmatchings/10E8", func_80172120);
#else
void func_80172120(Entity* self) {
g_api.func_8011A3AC(self, 0, 0, &D_80174C30);
if (D_80174D3C != 0) {
if (g_IsServantDestroyed != 0) {
self->zPriority = PLAYER.zPriority - 2;
}
if (D_8003C708.flags & 0x20) {
@ -732,7 +714,7 @@ void func_80172120(Entity* self) {
SquareRoot12(
(D_80174B24 * D_80174B24 + D_80174B28 * D_80174B28) << 12) >>
12;
if (!func_801713C8(self->ext.bat.target) || D_80174B2C < 8) {
if (!CheckEntityValid(self->ext.bat.target) || D_80174B2C < 8) {
self->ext.bat.unk8C = 0;
self->step++;
func_801710E8(self, D_8017054C);
@ -791,7 +773,7 @@ void func_80172C30(Entity* self) {
}
g_api.func_8011A3AC(self, 0, 0, &D_80174C30);
if (D_80174D3C != 0) {
if (g_IsServantDestroyed != 0) {
self->zPriority = PLAYER.zPriority - 2;
}
switch (self->step) {
@ -1058,96 +1040,17 @@ void func_80173C1C(void) {}
void func_80173C24(void) {}
void func_80173C2C(Entity* entity) {
switch (entity->params) {
case 15:
D_80174D3C = 1;
break;
}
DestroyEntity(entity);
}
#include "../destroy_servant_entity.h"
#ifndef VERSION_PSP
u32 Tt000UpdateAnim(Entity* self, s8* frameProps, AnimationFrame** frames) {
AnimationFrame* animFrame;
s32 ret;
ret = 0;
if (self->animFrameDuration == -1) {
ret = -1;
} else if (self->animFrameDuration == 0) {
self->animFrameDuration = self->anim[self->animFrameIdx].duration;
} else if (--self->animFrameDuration == 0) {
self->animFrameIdx++;
animFrame = &self->anim[self->animFrameIdx];
// Effectively a switch statement, but breaks if I actually use one.
if (animFrame->duration == 0) {
self->animFrameIdx = animFrame->unk2;
self->animFrameDuration = self->anim[self->animFrameIdx].duration;
ret = 0;
} else if (animFrame->duration == 0xFFFF) {
self->animFrameIdx--;
self->animFrameDuration = -1;
ret = -1;
} else if (animFrame->duration == 0xFFFE) {
self->anim = frames[animFrame->unk2];
self->animFrameIdx = 0;
ret = -2;
self->animFrameDuration = self->anim->duration;
} else {
self->animFrameDuration = animFrame->duration;
}
}
if (frameProps != NULL) {
// This is ugly - theoretically the type for frameProps should be
// FrameProperty* but anything besides this where we assign this big
// expression fails.
frameProps =
&frameProps[(self->anim[self->animFrameIdx].unk2 >> 9) << 2];
self->hitboxOffX = *frameProps++;
self->hitboxOffY = *frameProps++;
self->hitboxWidth = *frameProps++;
self->hitboxHeight = *frameProps++;
}
self->animCurFrame = self->anim[self->animFrameIdx].unk2 & 0x1FF;
return ret;
}
#include "../servant_update_anim.h"
#endif
#include "../../destroy_entity.h"
#ifndef VERSION_PSP
s32 func_80173E78(s32 arg0, s32 arg1) {
if (arg0 < 0) {
arg0 += arg1;
if (arg0 > 0) {
arg0 = 0;
}
} else {
arg0 -= arg1;
if (arg0 < 0) {
arg0 = 0;
}
}
return arg0;
}
Entity* func_80173EB0(s32 rangeIndex, s32 entityId) {
volatile u32 pad; // fake?
s16 start = D_80171094[rangeIndex].start;
s16 end = D_80171094[rangeIndex].end;
Entity* entity = &g_Entities[start];
s32 i;
for (i = start; end >= i; i++, entity++) {
if (entity->entityId == entityId) {
return entity;
}
}
return NULL;
}
#include "../accumulate_toward_zero.h"
#include "../search_for_entity_in_range.h"
#endif
s16 func_80173F30(Entity* entity, s16 x, s16 y) {

View File

@ -92,7 +92,7 @@ ServantEvent g_Events[] = {
// clang-format on
s32 D_80171090 = 99;
EntitySearch D_80171094[] = {{5, 7}, {32, 63}};
EntitySearch g_EntityRanges[] = {{5, 7}, {32, 63}};
ServantEvent* g_EventQueue = g_Events;
u32 g_CurrentServant = 0;
u32 g_CurrentRoomX = 0;

View File

@ -1,11 +1,14 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#include "common.h"
#include <servant.h>
extern s32 g_IsServantDestroyed;
INCLUDE_ASM("servant/tt_001/nonmatchings/F84", func_us_80170F84);
INCLUDE_ASM("servant/tt_001/nonmatchings/F84", func_us_80171284);
INCLUDE_ASM("servant/tt_001/nonmatchings/F84", func_us_801714F4);
#include "../check_entity_valid.h"
void func_us_80171560(void) {}
@ -41,15 +44,18 @@ void func_us_801728F4(void) {}
void func_us_801728FC(void) {}
INCLUDE_ASM("servant/tt_001/nonmatchings/F84", func_us_80172904);
#include "../destroy_servant_entity.h"
INCLUDE_ASM("servant/tt_001/nonmatchings/F84", func_us_8017293C);
#ifndef VERSION_PSP
#include "../servant_update_anim.h"
#endif
INCLUDE_ASM("servant/tt_001/nonmatchings/F84", func_us_80172AE4);
#include "../../destroy_entity.h"
INCLUDE_ASM("servant/tt_001/nonmatchings/F84", func_us_80172B50);
INCLUDE_ASM("servant/tt_001/nonmatchings/F84", func_us_80172B88);
#ifndef VERSION_PSP
#include "../accumulate_toward_zero.h"
#include "../search_for_entity_in_range.h"
#endif
INCLUDE_ASM("servant/tt_001/nonmatchings/F84", func_us_80172C08);

View File

@ -348,7 +348,7 @@ class sotn_function:
filepath_split = self.asm_filename.split("/")
self.overlay = filepath_split[2]
if self.overlay in ["st", "boss"]:
if self.overlay in ["st", "boss", "servant"]:
self.overlay = filepath_split[3]
if self.overlay == "weapon":
self.overlay = filepath_split[4]