summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTal Hayon <talhayon1@gmail.com>2021-12-31 16:46:58 +0200
committerTal Hayon <talhayon1@gmail.com>2021-12-31 16:46:58 +0200
commitf57e040e1626fb2d624c354beb539c8fbaf01b4c (patch)
tree39672e122234dc4df82ac33d34a7e6de35d881dc /src
parent74029cb5e07db50778e53bdd495d1e5805772f90 (diff)
Decompiled getEmptyEntity - still not completely matching
Diffstat (limited to 'src')
-rw-r--r--src/entity.c71
-rw-r--r--src/interrupts.c2
2 files changed, 69 insertions, 4 deletions
diff --git a/src/entity.c b/src/entity.c
index 41d9b4f1..0c69b550 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -22,6 +22,7 @@ extern void sub_08017744(Entity*);
extern void UnloadHitbox();
extern void sub_0804AA1C();
+void ClearDeletedEntity(Entity*);
extern void _ClearAndUpdateEntities();
extern void UpdateEntities_arm(u32);
@@ -232,7 +233,73 @@ void EraseAllEntities() {
gUnk_03000000.unk[1].unk6 = 1;
}
-ASM_FUNC("./asm/getEmptyEntity.s", Entity* GetEmptyEntity());
+extern Entity gUnk_030015A0[0x4848];
+extern Entity gUnk_03003BE0;
+
+NONMATCH("./asm/getEmptyEntity.s", Entity* GetEmptyEntity()) {
+ u8 flags_ip;
+ Entity* ptr;
+ Entity* end;
+ Entity* rv;
+ Entity* currentEnt;
+ LinkedList* nextList;
+
+ LinkedList* listPtr;
+ LinkedList* endListPtr;
+
+ if (gEntCount <= 0x46) {
+ ptr = gUnk_030015A0;
+ end = ptr + ARRAY_COUNT(gUnk_030015A0);
+
+ do {
+ if (ptr->prev == 0) {
+ return ptr;
+ }
+ } while (++ptr < end);
+ }
+
+ ptr = &gPlayerEntity;
+
+ do {
+ if ((s32)ptr->prev < 0 && (ptr->flags & 0xc) && gUpdateContext.current_entity != ptr) {
+ ClearDeletedEntity(ptr);
+ return ptr;
+ }
+ } while (++ptr < &gUnk_03003BE0);
+
+ flags_ip = 0;
+ rv = NULL;
+ listPtr = gEntityLists;
+ endListPtr = listPtr + ARRAY_COUNT(gEntityLists);
+
+ do {
+ currentEnt = listPtr->first;
+ nextList = listPtr + 1;
+ while ((u32)currentEnt != (u32)listPtr) {
+ if (currentEnt->kind != MANAGER && (currentEnt->flags & 0x1c) == flags_ip &&
+ gUpdateContext.current_entity != currentEnt) {
+ flags_ip = currentEnt->flags & 0x1c;
+ rv = currentEnt;
+ }
+ currentEnt = currentEnt->next;
+ }
+
+ listPtr = nextList;
+ } while (listPtr < endListPtr);
+
+ if (rv) {
+ DeleteEntity(rv);
+ ClearDeletedEntity(rv);
+ }
+
+ return rv;
+}
+END_NONMATCH
+
+//#define NDEPRECATED
+
+#include "entity.h"
+#include "functions.h"
extern Entity gUnk_030011E8[7];
@@ -308,8 +375,6 @@ void DeleteEntity(Entity* ent) {
}
}
-void ClearDeletedEntity(Entity*);
-
void ClearAllDeletedEntities(void) {
Entity* ent = &gPlayerEntity;
do {
diff --git a/src/interrupts.c b/src/interrupts.c
index 90556e62..2993fffb 100644
--- a/src/interrupts.c
+++ b/src/interrupts.c
@@ -17,7 +17,7 @@ extern u16* gUnk_02025EB0;
extern u16* gUnk_0200B650;
extern u8 gUpdateVisibleTiles;
extern u8 gUnk_03003DF0[];
-extern u8 gUnk_03003BE0;
+extern Entity gUnk_03003BE0;
extern Entity* gPlayerClones[3];
extern u16 gUnk_080B2CD8[];