From af20c468f130cb9458ab5da7de117f11deda3164 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 24 Apr 2024 18:28:11 -0400 Subject: [PATCH] Match `ActorType.s` --- asm/main/Actor/ActorType.inc | 1 - asm/main/Actor/ActorType.s | 120 ------------------------ asm/main/Actor/ActorType_Unregister.inc | 21 +++++ src/Main/Actor/ActorType.cpp | 77 +++++++++++++-- tools/lcf.py | 1 - 5 files changed, 89 insertions(+), 131 deletions(-) delete mode 100644 asm/main/Actor/ActorType.inc delete mode 100644 asm/main/Actor/ActorType.s create mode 100644 asm/main/Actor/ActorType_Unregister.inc diff --git a/asm/main/Actor/ActorType.inc b/asm/main/Actor/ActorType.inc deleted file mode 100644 index 6f70f09b..00000000 --- a/asm/main/Actor/ActorType.inc +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/asm/main/Actor/ActorType.s b/asm/main/Actor/ActorType.s deleted file mode 100644 index f7a61967..00000000 --- a/asm/main/Actor/ActorType.s +++ /dev/null @@ -1,120 +0,0 @@ - .include "main/Actor/ActorType.inc" - .include "macros/function.inc" - - .text - - .global _ZN9ActorTypeC1EjPFP5ActorvEPv - arm_func_start _ZN9ActorTypeC1EjPFP5ActorvEPv -_ZN9ActorTypeC1EjPFP5ActorvEPv: ; 0x0203e784 - stmdb sp!, {r4, lr} - mov r4, r0 - stmia r4, {r1, r2, r3} - mov r1, #0 - str r1, [r4, #0xc] - str r1, [r4, #0x10] - bl _ZN9ActorType8RegisterEv - ldr r1, _0203e7b0 ; =sActorTypeList - mov r0, r4 - str r4, [r1, #4] - ldmia sp!, {r4, pc} - .align 2, 0 - arm_func_end _ZN9ActorTypeC1EjPFP5ActorvEPv -_0203e7b0: .word sActorTypeList - - .global _ZN9ActorTypeD1Ev - arm_func_start _ZN9ActorTypeD1Ev -_ZN9ActorTypeD1Ev: ; 0x0203e7b4 - stmdb sp!, {r4, lr} - mov r4, r0 - bl _ZN9ActorType10UnregisterEv - mov r0, r4 - ldmia sp!, {r4, pc} - arm_func_end _ZN9ActorTypeD1Ev - - .global _ZN9ActorType13func_0203e7c8Ev - arm_func_start _ZN9ActorType13func_0203e7c8Ev -_ZN9ActorType13func_0203e7c8Ev: ; 0x0203e7c8 - stmdb sp!, {r3, lr} - ldr r0, [r0, #8] - cmp r0, #0 - moveq r0, #0 - ldmeqia sp!, {r3, pc} - blx r0 - ldmia sp!, {r3, pc} - arm_func_end _ZN9ActorType13func_0203e7c8Ev - - .global _ZN9ActorType8RegisterEv - arm_func_start _ZN9ActorType8RegisterEv -_ZN9ActorType8RegisterEv: ; 0x0203e7e4 - ldr r1, _0203e810 ; =sActorTypeList - ldr r2, _0203e814 ; =sActorTypeList - ldr r1, [r1] - cmp r1, #0 - beq _0203e808 -_0203e7f8: - add r2, r1, #0x10 - ldr r1, [r1, #0x10] - cmp r1, #0 - bne _0203e7f8 -_0203e808: - str r0, [r2] - bx lr - .align 2, 0 - arm_func_end _ZN9ActorType8RegisterEv -_0203e810: .word sActorTypeList -_0203e814: .word sActorTypeList - - .global _ZN9ActorType10UnregisterEv - arm_func_start _ZN9ActorType10UnregisterEv -_ZN9ActorType10UnregisterEv: ; 0x0203e818 - ldr r1, _0203e860 ; =sActorTypeList - ldr r2, _0203e864 ; =sActorTypeList - ldr r1, [r1] - mov r3, #0 - cmp r1, #0 - beq _0203e84c -_0203e830: - cmp r1, r0 - beq _0203e84c - mov r3, r2 - add r2, r1, #0x10 - ldr r1, [r1, #0x10] - cmp r1, #0 - bne _0203e830 -_0203e84c: - cmp r3, #0 - ldrne r1, [r0, #0x10] - ldrne r0, [r3] - strne r1, [r0, #0x10] - bx lr - .align 2, 0 - arm_func_end _ZN9ActorType10UnregisterEv -_0203e860: .word sActorTypeList -_0203e864: .word sActorTypeList - - .global _ZN9ActorType4FindEj - arm_func_start _ZN9ActorType4FindEj -_ZN9ActorType4FindEj: ; 0x0203e868 - ldr r1, _0203e89c ; =sActorTypeList - ldr r2, [r1] - cmp r2, #0 - beq _0203e894 -_0203e878: - ldr r1, [r2] - cmp r0, r1 - moveq r0, r2 - bxeq lr - ldr r2, [r2, #0x10] - cmp r2, #0 - bne _0203e878 -_0203e894: - mov r0, #0 - bx lr - .align 2, 0 - arm_func_end _ZN9ActorType4FindEj -_0203e89c: .word sActorTypeList - - .bss - .global sActorTypeList -sActorTypeList: - .space 0x8 diff --git a/asm/main/Actor/ActorType_Unregister.inc b/asm/main/Actor/ActorType_Unregister.inc new file mode 100644 index 00000000..fe27d9f9 --- /dev/null +++ b/asm/main/Actor/ActorType_Unregister.inc @@ -0,0 +1,21 @@ + + ldr r1, sActorTypeList + ldr r2, sActorTypeList2 + ldr r1, [r1] + mov r3, #0 + cmp r1, #0 + beq _0203e84c +_0203e830: + cmp r1, r0 + beq _0203e84c + mov r3, r2 + add r2, r1, #0x10 + ldr r1, [r1, #0x10] + cmp r1, #0 + bne _0203e830 +_0203e84c: + cmp r3, #0 + ldrne r1, [r0, #0x10] + ldrne r0, [r3] + strne r1, [r0, #0x10] + bx lr diff --git a/src/Main/Actor/ActorType.cpp b/src/Main/Actor/ActorType.cpp index bf8f54ae..b6ece417 100644 --- a/src/Main/Actor/ActorType.cpp +++ b/src/Main/Actor/ActorType.cpp @@ -1,14 +1,73 @@ #include "Actor/ActorType.hpp" -#ifdef STUBS - ActorTypeList sActorTypeList; +ActorTypeList sActorTypeList2; -ActorType::ActorType(ActorTypeId id, ActorCreateFunc create, void *unk_08) {} -ActorType::~ActorType() {} -void ActorType::func_0203e7c8() {} -void ActorType::Register() {} -void ActorType::Unregister() {} -ActorType* ActorType::Find(ActorTypeId id) {} +// Kill duplicate dtors +KILL(_ZN9ActorTypeC2EjPFP5ActorvEPFivE) +KILL(_ZN9ActorTypeD2Ev) -#endif +ARM ActorType::ActorType(ActorTypeId id, ActorCreateFunc create, unk32 (*unk_08)()) { + this->id = id; + this->create = create; + this->unk_08 = unk_08; + this->unk_0c = 0; + this->next = NULL; + this->Register(); + sActorTypeList.tail = this; +} + +ARM ActorType::~ActorType() { + this->Unregister(); +} + +ARM unk32 ActorType::func_0203e7c8() { + if (this->unk_08 == NULL) { + return 0; + } + return (*unk_08)(); +} + +ARM void ActorType::Register() { + ActorType *actorType; + ActorType **tail = &sActorTypeList.tail; + + for (actorType = sActorTypeList.head; actorType != NULL; actorType = actorType->next) { + tail = &actorType->next; + } + + *tail = this; +} + +ARM void NONMATCH(ActorType::Unregister)() { + #ifndef NONMATCHING + #include "../asm/main/Actor/ActorType_Unregister.inc" + #else + ActorType *actorType; + + ActorType **current = &sActorTypeList2.head; + ActorType **previous = NULL; + + for (actorType = sActorTypeList.head; actorType != NULL; actorType = actorType->next) { + if (actorType == this) break; + previous = current; + current = &actorType->next; + } + + if (previous != NULL) { + (*previous)->next = this->next; + } + #endif +} + +ARM ActorType *ActorType::Find(ActorTypeId id) { + ActorType *actorType; + + for (actorType = sActorTypeList.head; actorType != NULL; actorType = actorType->next) { + if (id == actorType->id) { + return actorType; + } + } + + return NULL; +} diff --git a/tools/lcf.py b/tools/lcf.py index a77690d9..084d03a9 100644 --- a/tools/lcf.py +++ b/tools/lcf.py @@ -14,7 +14,6 @@ ARM9_OBJECTS = [ 'asm/main/main_02000000.s', 'src/Main/Actor/ActorType.cpp', - 'asm/main/Actor/ActorType.s', 'asm/main/main_0203e8a0.s',