From 0e3b13ee3e3b8de816431736b818dda44147d294 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 31 May 2024 02:50:17 +0200 Subject: [PATCH 01/20] State system + match d_t_rock_boat --- config/SOUE01/rels/d_t_rock_boatNP/splits.txt | 4 +- .../SOUE01/rels/d_t_rock_boatNP/symbols.txt | 86 ++++++------- .../SOUE01/rels/d_t_tumble_weedNP/splits.txt | 3 + .../SOUE01/rels/d_t_tumble_weedNP/symbols.txt | 108 ++++++++--------- config/SOUE01/splits.txt | 14 +++ config/SOUE01/symbols.txt | 86 ++++++------- configure.py | 5 +- include/c/c_math.h | 5 + include/d/a/obj/d_a_obj_base.h | 4 +- include/d/tg/d_t_rock_boat.h | 36 ++++++ include/d/tg/d_t_tumble_weed.h | 44 +++++++ include/f/f_list_nd.h | 1 + include/s/docgroup.h | 10 ++ include/s/s_FState.hpp | 41 +++++++ include/s/s_FStateFct.hpp | 26 ++++ include/s/s_FStateID.hpp | 58 +++++++++ include/s/s_FStateMgr.hpp | 17 +++ include/s/s_Phase.hpp | 34 ++++++ include/s/s_State.hpp | 14 +++ include/s/s_StateID.hpp | 43 +++++++ include/s/s_StateIDChk.hpp | 10 ++ include/s/s_StateInterfaces.hpp | 73 +++++++++++ include/s/s_StateMethod.hpp | 49 ++++++++ include/s/s_StateMethodUsr_FI.hpp | 16 +++ include/s/s_StateMgr.hpp | 37 ++++++ src/REL/d/t/d_t_rock_boat.cpp | 37 ++++++ src/REL/d/t/d_t_tumble_weed.cpp | 114 ++++++++++++++++++ src/s/s_Phase.cpp | 28 +++++ src/s/s_StateID.cpp | 53 ++++++++ src/s/s_StateMethod.cpp | 74 ++++++++++++ src/s/s_StateMethodUsr_FI.cpp | 27 +++++ 31 files changed, 1013 insertions(+), 144 deletions(-) create mode 100644 include/d/tg/d_t_rock_boat.h create mode 100644 include/d/tg/d_t_tumble_weed.h create mode 100644 include/s/docgroup.h create mode 100644 include/s/s_FState.hpp create mode 100644 include/s/s_FStateFct.hpp create mode 100644 include/s/s_FStateID.hpp create mode 100644 include/s/s_FStateMgr.hpp create mode 100644 include/s/s_Phase.hpp create mode 100644 include/s/s_State.hpp create mode 100644 include/s/s_StateID.hpp create mode 100644 include/s/s_StateIDChk.hpp create mode 100644 include/s/s_StateInterfaces.hpp create mode 100644 include/s/s_StateMethod.hpp create mode 100644 include/s/s_StateMethodUsr_FI.hpp create mode 100644 include/s/s_StateMgr.hpp create mode 100644 src/s/s_Phase.cpp create mode 100644 src/s/s_StateID.cpp create mode 100644 src/s/s_StateMethod.cpp create mode 100644 src/s/s_StateMethodUsr_FI.cpp diff --git a/config/SOUE01/rels/d_t_rock_boatNP/splits.txt b/config/SOUE01/rels/d_t_rock_boatNP/splits.txt index 86bb8f92..3fc7e803 100644 --- a/config/SOUE01/rels/d_t_rock_boatNP/splits.txt +++ b/config/SOUE01/rels/d_t_rock_boatNP/splits.txt @@ -2,7 +2,7 @@ Sections: .text type:code align:16 .ctors type:rodata align:4 .dtors type:rodata align:4 - .rodata type:rodata align:16 + .data type:data align:16 .bss type:bss align:8 REL/executor.c: @@ -16,3 +16,5 @@ REL/global_destructor_chain.c: REL/d/t/d_t_rock_boat.cpp: .text start:0x000000F0 end:0x00000A28 .ctors start:0x00000000 end:0x00000004 + .data start:0x00000000 end:0x00000200 + .bss start:0x00000008 end:0x00000048 diff --git a/config/SOUE01/rels/d_t_rock_boatNP/symbols.txt b/config/SOUE01/rels/d_t_rock_boatNP/symbols.txt index 85063c83..ea8907ed 100644 --- a/config/SOUE01/rels/d_t_rock_boatNP/symbols.txt +++ b/config/SOUE01/rels/d_t_rock_boatNP/symbols.txt @@ -3,50 +3,50 @@ _epilog = .text:0x00000030; // type:function size:0x2C scope:global _unresolved = .text:0x00000060; // type:function size:0x4 scope:global __register_global_object = .text:0x00000070; // type:function size:0x1C scope:global __destroy_global_chain = .text:0x00000090; // type:function size:0x54 scope:global -fn_487_F0 = .text:0x000000F0; // type:function size:0xAC -fn_487_1A0 = .text:0x000001A0; // type:function size:0x58 -fn_487_200 = .text:0x00000200; // type:function size:0x58 -fn_487_260 = .text:0x00000260; // type:function size:0x6C -fn_487_2D0 = .text:0x000002D0; // type:function size:0xA0 -fn_487_370 = .text:0x00000370; // type:function size:0xA4 -fn_487_420 = .text:0x00000420; // type:function size:0x50 -fn_487_470 = .text:0x00000470; // type:function size:0x10 -fn_487_480 = .text:0x00000480; // type:function size:0x8 -fn_487_490 = .text:0x00000490; // type:function size:0x30 -fn_487_4C0 = .text:0x000004C0; // type:function size:0x10 -fn_487_4D0 = .text:0x000004D0; // type:function size:0x8 -fn_487_4E0 = .text:0x000004E0; // type:function size:0x4 -fn_487_4F0 = .text:0x000004F0; // type:function size:0x90 -fn_487_580 = .text:0x00000580; // type:function size:0x4 -fn_487_590 = .text:0x00000590; // type:function size:0xC8 -fn_487_660 = .text:0x00000660; // type:function size:0x10 -fn_487_670 = .text:0x00000670; // type:function size:0x60 -fn_487_6D0 = .text:0x000006D0; // type:function size:0xC -fn_487_6E0 = .text:0x000006E0; // type:function size:0x1C -fn_487_700 = .text:0x00000700; // type:function size:0x1C -fn_487_720 = .text:0x00000720; // type:function size:0x1C -fn_487_740 = .text:0x00000740; // type:function size:0x10 -fn_487_750 = .text:0x00000750; // type:function size:0x10 -fn_487_760 = .text:0x00000760; // type:function size:0x10 -fn_487_770 = .text:0x00000770; // type:function size:0x10 -fn_487_780 = .text:0x00000780; // type:function size:0x10 -fn_487_790 = .text:0x00000790; // type:function size:0x10 -fn_487_7A0 = .text:0x000007A0; // type:function size:0x30 -fn_487_7D0 = .text:0x000007D0; // type:function size:0x30 -fn_487_800 = .text:0x00000800; // type:function size:0x30 -fn_487_830 = .text:0x00000830; // type:function size:0x10C -fn_487_940 = .text:0x00000940; // type:function size:0x58 -fn_487_9A0 = .text:0x000009A0; // type:function size:0x88 +dTgRockBoat_c_classInit__Fv = .text:0x000000F0; // type:function size:0xAC +__dt__8dTgAbs_cFv = .text:0x000001A0; // type:function size:0x58 +__dt__26sFState_c<13dTgRockBoat_c>Fv = .text:0x00000200; // type:function size:0x58 +__dt__29sFStateFct_c<13dTgRockBoat_c>Fv = .text:0x00000260; // type:function size:0x6C +__dt__82sStateMgr_c<13dTgRockBoat_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>Fv = .text:0x000002D0; // type:function size:0xA0 +__dt__52sFStateMgr_c<13dTgRockBoat_c,20sStateMethodUsr_FI_c>Fv = .text:0x00000370; // type:function size:0xA4 +create__13dTgRockBoat_cFv = .text:0x00000420; // type:function size:0x50 +changeState__82sStateMgr_c<13dTgRockBoat_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>FRC12sStateIDIf_c = .text:0x00000470; // type:function size:0x10 +doDelete__13dTgRockBoat_cFv = .text:0x00000480; // type:function size:0x8 +actorExecute__13dTgRockBoat_cFv = .text:0x00000490; // type:function size:0x30 +executeState__82sStateMgr_c<13dTgRockBoat_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>Fv = .text:0x000004C0; // type:function size:0x10 +draw__13dTgRockBoat_cFv = .text:0x000004D0; // type:function size:0x8 +initializeState_Wait__13dTgRockBoat_cFv = .text:0x000004E0; // type:function size:0x4 +executeState_Wait__13dTgRockBoat_cFv = .text:0x000004F0; // type:function size:0x90 +finalizeState_Wait__13dTgRockBoat_cFv = .text:0x00000580; // type:function size:0x4 +__dt__13dTgRockBoat_cFv = .text:0x00000590; // type:function size:0xC8 +getStateID__82sStateMgr_c<13dTgRockBoat_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>CFv = .text:0x00000660; // type:function size:0x10 +build__29sFStateFct_c<13dTgRockBoat_c>FRC12sStateIDIf_c = .text:0x00000670; // type:function size:0x60 +dispose__29sFStateFct_c<13dTgRockBoat_c>FRP10sStateIf_c = .text:0x000006D0; // type:function size:0xC +initialize__26sFState_c<13dTgRockBoat_c>Fv = .text:0x000006E0; // type:function size:0x1C +execute__26sFState_c<13dTgRockBoat_c>Fv = .text:0x00000700; // type:function size:0x1C +finalize__26sFState_c<13dTgRockBoat_c>Fv = .text:0x00000720; // type:function size:0x1C +initializeState__82sStateMgr_c<13dTgRockBoat_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>Fv = .text:0x00000740; // type:function size:0x10 +finalizeState__82sStateMgr_c<13dTgRockBoat_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>Fv = .text:0x00000750; // type:function size:0x10 +refreshState__82sStateMgr_c<13dTgRockBoat_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>Fv = .text:0x00000760; // type:function size:0x10 +getState__82sStateMgr_c<13dTgRockBoat_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>CFv = .text:0x00000770; // type:function size:0x10 +getNewStateID__82sStateMgr_c<13dTgRockBoat_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>CFv = .text:0x00000780; // type:function size:0x10 +getOldStateID__82sStateMgr_c<13dTgRockBoat_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>CFv = .text:0x00000790; // type:function size:0x10 +finalizeState__28sFStateID_c<13dTgRockBoat_c>CFR13dTgRockBoat_c = .text:0x000007A0; // type:function size:0x30 +executeState__28sFStateID_c<13dTgRockBoat_c>CFR13dTgRockBoat_c = .text:0x000007D0; // type:function size:0x30 +initializeState__28sFStateID_c<13dTgRockBoat_c>CFR13dTgRockBoat_c = .text:0x00000800; // type:function size:0x30 +__sinit_\d_t_rock_boat_cpp = .text:0x00000830; // type:function size:0x10C scope:local +__dt__28sFStateID_c<13dTgRockBoat_c>Fv = .text:0x00000940; // type:function size:0x58 +isSameName__28sFStateID_c<13dTgRockBoat_c>CFPCc = .text:0x000009A0; // type:function size:0x88 _ctors = .ctors:0x00000000; // type:label scope:global _dtors = .dtors:0x00000000; // type:label scope:global __destroy_global_chain_reference = .dtors:0x00000000; // type:object size:0x4 scope:global -lbl_487_section4_0 = .rodata:0x00000000; // type:object size:0x10 data:4byte -lbl_487_section4_10 = .rodata:0x00000010; // type:object size:0x78 -lbl_487_section4_88 = .rodata:0x00000088; // type:object size:0x30 -lbl_487_section4_B8 = .rodata:0x000000B8; // type:object size:0x30 -lbl_487_section4_E8 = .rodata:0x000000E8; // type:object size:0x18 -lbl_487_section4_100 = .rodata:0x00000100; // type:object size:0xCC -lbl_487_section4_1CC = .rodata:0x000001CC; // type:object size:0x34 +g_profile_TAG_ROCK_BOAT = .data:0x00000000; // type:object size:0x10 data:4byte +__vt__13dTgRockBoat_c = .data:0x00000010; // type:object size:0x74 +__vt__52sFStateMgr_c<13dTgRockBoat_c,20sStateMethodUsr_FI_c> = .data:0x00000088; // type:object size:0x30 +__vt__82sStateMgr_c<13dTgRockBoat_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c> = .data:0x000000B8; // type:object size:0x30 +__vt__29sFStateFct_c<13dTgRockBoat_c> = .data:0x000000E8; // type:object size:0x14 +__vt__26sFState_c<13dTgRockBoat_c> = .data:0x00000100; // type:object size:0x18 +__vt__28sFStateID_c<13dTgRockBoat_c> = .data:0x000001CC; // type:object size:0x34 __global_destructor_chain = .bss:0x00000000; // type:object size:0x4 scope:global -lbl_487_bss_8 = .bss:0x00000008; // type:object size:0x10 -lbl_487_bss_18 = .bss:0x00000018; // type:object size:0x30 data:4byte +lbl_487_bss_8 = .bss:0x00000008; // type:object size:0xC scope:local +StateID_Wait__13dTgRockBoat_c = .bss:0x00000018; // type:object size:0x30 data:4byte diff --git a/config/SOUE01/rels/d_t_tumble_weedNP/splits.txt b/config/SOUE01/rels/d_t_tumble_weedNP/splits.txt index 6637ccf5..978aeadb 100644 --- a/config/SOUE01/rels/d_t_tumble_weedNP/splits.txt +++ b/config/SOUE01/rels/d_t_tumble_weedNP/splits.txt @@ -17,3 +17,6 @@ REL/global_destructor_chain.c: REL/d/t/d_t_tumble_weed.cpp: .text start:0x000000F0 end:0x00001288 .ctors start:0x00000000 end:0x00000004 + .rodata start:0x00000000 end:0x00000064 + .data start:0x00000000 end:0x00000294 + .bss start:0x00000008 end:0x000000C8 diff --git a/config/SOUE01/rels/d_t_tumble_weedNP/symbols.txt b/config/SOUE01/rels/d_t_tumble_weedNP/symbols.txt index ddb33f7e..2b24ae56 100644 --- a/config/SOUE01/rels/d_t_tumble_weedNP/symbols.txt +++ b/config/SOUE01/rels/d_t_tumble_weedNP/symbols.txt @@ -3,66 +3,66 @@ _epilog = .text:0x00000030; // type:function size:0x2C scope:global _unresolved = .text:0x00000060; // type:function size:0x4 scope:global __register_global_object = .text:0x00000070; // type:function size:0x1C scope:global __destroy_global_chain = .text:0x00000090; // type:function size:0x54 scope:global -fn_476_F0 = .text:0x000000F0; // type:function size:0xC0 -fn_476_1B0 = .text:0x000001B0; // type:function size:0x58 -fn_476_210 = .text:0x00000210; // type:function size:0x58 -fn_476_270 = .text:0x00000270; // type:function size:0x6C -fn_476_2E0 = .text:0x000002E0; // type:function size:0xA0 -fn_476_380 = .text:0x00000380; // type:function size:0xA4 -fn_476_430 = .text:0x00000430; // type:function size:0x48 -fn_476_480 = .text:0x00000480; // type:function size:0x10 -fn_476_490 = .text:0x00000490; // type:function size:0x8 -fn_476_4A0 = .text:0x000004A0; // type:function size:0x48 -fn_476_4F0 = .text:0x000004F0; // type:function size:0x10 -fn_476_500 = .text:0x00000500; // type:function size:0x1C -fn_476_520 = .text:0x00000520; // type:function size:0x8 -fn_476_530 = .text:0x00000530; // type:function size:0x4 -fn_476_540 = .text:0x00000540; // type:function size:0xA0 -fn_476_5E0 = .text:0x000005E0; // type:function size:0x4 -fn_476_5F0 = .text:0x000005F0; // type:function size:0x4 -fn_476_600 = .text:0x00000600; // type:function size:0xC8 -fn_476_6D0 = .text:0x000006D0; // type:function size:0x4 -fn_476_6E0 = .text:0x000006E0; // type:function size:0x44 -fn_476_730 = .text:0x00000730; // type:function size:0x74 -fn_476_7B0 = .text:0x000007B0; // type:function size:0x4 -fn_476_7C0 = .text:0x000007C0; // type:function size:0x98 -fn_476_860 = .text:0x00000860; // type:function size:0x54 -fn_476_8C0 = .text:0x000008C0; // type:function size:0x288 -fn_476_B50 = .text:0x00000B50; // type:function size:0x114 -fn_476_C70 = .text:0x00000C70; // type:function size:0xD8 -fn_476_D50 = .text:0x00000D50; // type:function size:0x10 -fn_476_D60 = .text:0x00000D60; // type:function size:0x60 -fn_476_DC0 = .text:0x00000DC0; // type:function size:0xC -fn_476_DD0 = .text:0x00000DD0; // type:function size:0x1C -fn_476_DF0 = .text:0x00000DF0; // type:function size:0x1C -fn_476_E10 = .text:0x00000E10; // type:function size:0x1C -fn_476_E30 = .text:0x00000E30; // type:function size:0x10 -fn_476_E40 = .text:0x00000E40; // type:function size:0x10 -fn_476_E50 = .text:0x00000E50; // type:function size:0x10 -fn_476_E60 = .text:0x00000E60; // type:function size:0x10 -fn_476_E70 = .text:0x00000E70; // type:function size:0x10 -fn_476_E80 = .text:0x00000E80; // type:function size:0x10 -fn_476_E90 = .text:0x00000E90; // type:function size:0x30 -fn_476_EC0 = .text:0x00000EC0; // type:function size:0x30 -fn_476_EF0 = .text:0x00000EF0; // type:function size:0x30 -fn_476_F20 = .text:0x00000F20; // type:function size:0x27C -fn_476_11A0 = .text:0x000011A0; // type:function size:0x58 -fn_476_1200 = .text:0x00001200; // type:function size:0x88 +dTgTumbleWeed_c_classInit__Fv = .text:0x000000F0; // type:function size:0xC0 +__dt__8dTgAbs_cFv = .text:0x000001B0; // type:function size:0x58 +__dt__28sFState_c<15dTgTumbleWeed_c>Fv = .text:0x00000210; // type:function size:0x58 +__dt__31sFStateFct_c<15dTgTumbleWeed_c>Fv = .text:0x00000270; // type:function size:0x6C +__dt__84sStateMgr_c<15dTgTumbleWeed_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>Fv = .text:0x000002E0; // type:function size:0xA0 +__dt__54sFStateMgr_c<15dTgTumbleWeed_c,20sStateMethodUsr_FI_c>Fv = .text:0x00000380; // type:function size:0xA4 +create__15dTgTumbleWeed_cFv = .text:0x00000430; // type:function size:0x48 +changeState__84sStateMgr_c<15dTgTumbleWeed_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>FRC12sStateIDIf_c = .text:0x00000480; // type:function size:0x10 +doDelete__15dTgTumbleWeed_cFv = .text:0x00000490; // type:function size:0x8 +actorExecute__15dTgTumbleWeed_cFv = .text:0x000004A0; // type:function size:0x48 +executeState__84sStateMgr_c<15dTgTumbleWeed_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>Fv = .text:0x000004F0; // type:function size:0x10 +decr__FPUs = .text:0x00000500; // type:function size:0x1C +draw__15dTgTumbleWeed_cFv = .text:0x00000520; // type:function size:0x8 +initializeState_AreaOut__15dTgTumbleWeed_cFv = .text:0x00000530; // type:function size:0x4 +executeState_AreaOut__15dTgTumbleWeed_cFv = .text:0x00000540; // type:function size:0xA0 +finalizeState_AreaOut__15dTgTumbleWeed_cFv = .text:0x000005E0; // type:function size:0x4 +initializeState_AreaIn__15dTgTumbleWeed_cFv = .text:0x000005F0; // type:function size:0x4 +executeState_AreaIn__15dTgTumbleWeed_cFv = .text:0x00000600; // type:function size:0xC8 +finalizeState_AreaIn__15dTgTumbleWeed_cFv = .text:0x000006D0; // type:function size:0x4 +initializeState_Wind__15dTgTumbleWeed_cFv = .text:0x000006E0; // type:function size:0x44 +executeState_Wind__15dTgTumbleWeed_cFv = .text:0x00000730; // type:function size:0x74 +finalizeState_Wind__15dTgTumbleWeed_cFv = .text:0x000007B0; // type:function size:0x4 +shouldSpawnTumbleweed__15dTgTumbleWeed_cFv = .text:0x000007C0; // type:function size:0x98 +shouldDoWind__15dTgTumbleWeed_cFv = .text:0x00000860; // type:function size:0x54 +doSpawnTumbleweed__15dTgTumbleWeed_cFv = .text:0x000008C0; // type:function size:0x288 +getWind__15dTgTumbleWeed_cFP7mVec3_c = .text:0x00000B50; // type:function size:0x114 +__dt__15dTgTumbleWeed_cFv = .text:0x00000C70; // type:function size:0xD8 +getStateID__84sStateMgr_c<15dTgTumbleWeed_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>CFv = .text:0x00000D50; // type:function size:0x10 +build__31sFStateFct_c<15dTgTumbleWeed_c>FRC12sStateIDIf_c = .text:0x00000D60; // type:function size:0x60 +dispose__31sFStateFct_c<15dTgTumbleWeed_c>FRP10sStateIf_c = .text:0x00000DC0; // type:function size:0xC +initialize__28sFState_c<15dTgTumbleWeed_c>Fv = .text:0x00000DD0; // type:function size:0x1C +execute__28sFState_c<15dTgTumbleWeed_c>Fv = .text:0x00000DF0; // type:function size:0x1C +finalize__28sFState_c<15dTgTumbleWeed_c>Fv = .text:0x00000E10; // type:function size:0x1C +initializeState__84sStateMgr_c<15dTgTumbleWeed_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>Fv = .text:0x00000E30; // type:function size:0x10 +finalizeState__84sStateMgr_c<15dTgTumbleWeed_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>Fv = .text:0x00000E40; // type:function size:0x10 +refreshState__84sStateMgr_c<15dTgTumbleWeed_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>Fv = .text:0x00000E50; // type:function size:0x10 +getState__84sStateMgr_c<15dTgTumbleWeed_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>CFv = .text:0x00000E60; // type:function size:0x10 +getNewStateID__84sStateMgr_c<15dTgTumbleWeed_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>CFv = .text:0x00000E70; // type:function size:0x10 +getOldStateID__84sStateMgr_c<15dTgTumbleWeed_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>CFv = .text:0x00000E80; // type:function size:0x10 +finalizeState__30sFStateID_c<15dTgTumbleWeed_c>CFR15dTgTumbleWeed_c = .text:0x00000E90; // type:function size:0x30 +executeState__30sFStateID_c<15dTgTumbleWeed_c>CFR15dTgTumbleWeed_c = .text:0x00000EC0; // type:function size:0x30 +initializeState__30sFStateID_c<15dTgTumbleWeed_c>CFR15dTgTumbleWeed_c = .text:0x00000EF0; // type:function size:0x30 +__sinit_\d_t_tumble_weed_cpp = .text:0x00000F20; // type:function size:0x27C +__dt__30sFStateID_c<15dTgTumbleWeed_c>Fv = .text:0x000011A0; // type:function size:0x58 +isSameName__30sFStateID_c<15dTgTumbleWeed_c>CFPCc = .text:0x00001200; // type:function size:0x88 _ctors = .ctors:0x00000000; // type:label scope:global _dtors = .dtors:0x00000000; // type:label scope:global __destroy_global_chain_reference = .dtors:0x00000000; // type:object size:0x4 scope:global lbl_476_rodata_0 = .rodata:0x00000000; // type:object size:0x1C data:float lbl_476_rodata_1C = .rodata:0x0000001C; // type:object size:0x4 data:float lbl_476_rodata_20 = .rodata:0x00000020; // type:object size:0x44 data:float -lbl_476_data_0 = .data:0x00000000; // type:object size:0x10 data:4byte -lbl_476_data_10 = .data:0x00000010; // type:object size:0x78 -lbl_476_data_88 = .data:0x00000088; // type:object size:0x30 -lbl_476_data_B8 = .data:0x000000B8; // type:object size:0x30 -lbl_476_data_E8 = .data:0x000000E8; // type:object size:0x18 -lbl_476_data_100 = .data:0x00000100; // type:object size:0x160 -lbl_476_data_260 = .data:0x00000260; // type:object size:0x34 +g_profile_TAG_TUMBLE_WEED = .data:0x00000000; // type:object size:0x10 data:4byte +__vt__15dTgTumbleWeed_c = .data:0x00000010; // type:object size:0x74 +__vt__54sFStateMgr_c<15dTgTumbleWeed_c,20sStateMethodUsr_FI_c> = .data:0x00000088; // type:object size:0x30 +__vt__84sStateMgr_c<15dTgTumbleWeed_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c> = .data:0x000000B8; // type:object size:0x30 +__vt__31sFStateFct_c<15dTgTumbleWeed_c> = .data:0x000000E8; // type:object size:0x14 +__vt__28sFState_c<15dTgTumbleWeed_c> = .data:0x00000100; // type:object size:0x18 +__vt__30sFStateID_c<15dTgTumbleWeed_c> = .data:0x00000260; // type:object size:0x34 __global_destructor_chain = .bss:0x00000000; // type:object size:0x4 scope:global lbl_476_bss_8 = .bss:0x00000008; // type:object size:0x10 data:4byte -lbl_476_bss_18 = .bss:0x00000018; // type:object size:0x40 data:4byte -lbl_476_bss_58 = .bss:0x00000058; // type:object size:0x40 data:4byte +StateID_AreaOut__15dTgTumbleWeed_c = .bss:0x00000018; // type:object size:0x30 data:4byte +lbl_476_bss_58 = .bss:0x00000058; // type:object size:0x30 data:4byte lbl_476_bss_98 = .bss:0x00000098; // type:object size:0x30 data:4byte diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 8428ae57..393ae007 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -198,6 +198,20 @@ toBeSorted/counters/extra_wallet_counter.cpp: .data start:0x805280B0 end:0x805280D0 .sbss start:0x80575640 end:0x80575648 +s/s_StateId.cpp: + .text start:0x802DDDB0 end:0x802DE1F4 + .ctors start:0x804DB8B8 end:0x804DB8BC + .data start:0x80541930 end:0x805419A8 + .sbss start:0x80575B68 end:0x80575B70 + .bss start:0x805B84B0 end:0x805B84C8 + +s/s_StateMethod.cpp: + .text start:0x802DE200 end:0x802DE534 + .data start:0x805419A8 end:0x805419E8 + +s/s_StateMethodUsr_FI.cpp: + .text start:0x802DE540 end:0x802DE6EC + DynamicLink.cpp: .text start:0x802DF100 end:0x802DFD74 .data start:0x805419E8 end:0x80541A70 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 0570fe6b..2bcfdfc2 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -1118,7 +1118,7 @@ fn_8002E2A0 = .text:0x8002E2A0; // type:function size:0x90 fn_8002E330 = .text:0x8002E330; // type:function size:0x27C fn_8002E5B0 = .text:0x8002E5B0; // type:function size:0x8 fn_8002E5C0 = .text:0x8002E5C0; // type:function size:0x70 -fn_8002E630 = .text:0x8002E630; // type:function size:0x98 +create__12dAcObjBase_cFQ28fProfile14PROFILE_NAME_eScUlP7mVec3_cP7mAng3_cP7mVec3_cUl = .text:0x8002E630; // type:function size:0x98 fn_8002E6D0 = .text:0x8002E6D0; // type:function size:0xA0 fn_8002E770 = .text:0x8002E770; // type:function size:0x7C fn_8002E7F0 = .text:0x8002E7F0; // type:function size:0x58 @@ -1231,7 +1231,7 @@ fn_80032840 = .text:0x80032840; // type:function size:0x10 fn_80032850 = .text:0x80032850; // type:function size:0x64 fn_800328C0 = .text:0x800328C0; // type:function size:0x58 fn_80032920 = .text:0x80032920; // type:function size:0x10 -fn_80032930 = .text:0x80032930; // type:function size:0x8 +getStateID__14sStateMethod_cCFv = .text:0x80032930; // type:function size:0x8 fn_80032940 = .text:0x80032940; // type:function size:0x10 fn_80032950 = .text:0x80032950; // type:function size:0x8 fn_80032960 = .text:0x80032960; // type:function size:0x94 @@ -1620,10 +1620,10 @@ fn_8003EE80 = .text:0x8003EE80; // type:function size:0xC fn_8003EE90 = .text:0x8003EE90; // type:function size:0x1C fn_8003EEB0 = .text:0x8003EEB0; // type:function size:0x1C fn_8003EED0 = .text:0x8003EED0; // type:function size:0x1C -fn_8003EEF0 = .text:0x8003EEF0; // type:function size:0xC -fn_8003EF00 = .text:0x8003EF00; // type:function size:0x8 -fn_8003EF10 = .text:0x8003EF10; // type:function size:0x8 -fn_8003EF20 = .text:0x8003EF20; // type:function size:0x8 +refreshStateMethod__14sStateMethod_cFv = .text:0x8003EEF0; // type:function size:0xC +getState__14sStateMethod_cCFv = .text:0x8003EF00; // type:function size:0x8 +getNewStateID__14sStateMethod_cCFv = .text:0x8003EF10; // type:function size:0x8 +getOldStateID__14sStateMethod_cCFv = .text:0x8003EF20; // type:function size:0x8 fn_8003EF30 = .text:0x8003EF30; // type:function size:0x10 fn_8003EF40 = .text:0x8003EF40; // type:function size:0x10 fn_8003EF50 = .text:0x8003EF50; // type:function size:0x10 @@ -17168,36 +17168,36 @@ fn_802DDC20 = .text:0x802DDC20; // type:function size:0x40 fn_802DDC60 = .text:0x802DDC60; // type:function size:0x58 fn_802DDCC0 = .text:0x802DDCC0; // type:function size:0xA8 fn_802DDD70 = .text:0x802DDD70; // type:function size:0x40 -fn_802DDDB0 = .text:0x802DDDB0; // type:function size:0x34 -fn_802DDDF0 = .text:0x802DDDF0; // type:function size:0x58 -fn_802DDE50 = .text:0x802DDE50; // type:function size:0x10 -fn_802DDE60 = .text:0x802DDE60; // type:function size:0x68 -fn_802DDED0 = .text:0x802DDED0; // type:function size:0x10 -fn_802DDEE0 = .text:0x802DDEE0; // type:function size:0x34 -fn_802DDF20 = .text:0x802DDF20; // type:function size:0x8 -fn_802DDF30 = .text:0x802DDF30; // type:function size:0x8 -fn_802DDF40 = .text:0x802DDF40; // type:function size:0x8 -fn_802DDF50 = .text:0x802DDF50; // type:function size:0x40 -fn_802DDF90 = .text:0x802DDF90; // type:function size:0x40 -fn_802DDFD0 = .text:0x802DDFD0; // type:function size:0x58 -fn_802DE030 = .text:0x802DE030; // type:function size:0x40 -fn_802DE070 = .text:0x802DE070; // type:function size:0x40 -fn_802DE0B0 = .text:0x802DE0B0; // type:function size:0x40 -fn_802DE0F0 = .text:0x802DE0F0; // type:function size:0x58 -fn_802DE150 = .text:0x802DE150; // type:function size:0x40 -fn_802DE190 = .text:0x802DE190; // type:function size:0x8 -fn_802DE1A0 = .text:0x802DE1A0; // type:function size:0x54 -fn_802DE200 = .text:0x802DE200; // type:function size:0x48 -fn_802DE250 = .text:0x802DE250; // type:function size:0x58 -fn_802DE2B0 = .text:0x802DE2B0; // type:function size:0xA8 -fn_802DE360 = .text:0x802DE360; // type:function size:0xC4 -fn_802DE430 = .text:0x802DE430; // type:function size:0x8C -fn_802DE4C0 = .text:0x802DE4C0; // type:function size:0x74 -fn_802DE540 = .text:0x802DE540; // type:function size:0x3C -fn_802DE580 = .text:0x802DE580; // type:function size:0x68 -fn_802DE5F0 = .text:0x802DE5F0; // type:function size:0x4C -fn_802DE640 = .text:0x802DE640; // type:function size:0x54 -fn_802DE6A0 = .text:0x802DE6A0; // type:function size:0x4C +__ct__10sStateID_cFPCc = .text:0x802DDDB0; // type:function size:0x34 +__dt__10sStateID_cFv = .text:0x802DDDF0; // type:function size:0x58 +isNull__10sStateID_cCFv = .text:0x802DDE50; // type:function size:0x10 +isEqual__10sStateID_cCFRC12sStateIDIf_c = .text:0x802DDE60; // type:function size:0x68 +__eq__10sStateID_cCFRC12sStateIDIf_c = .text:0x802DDED0; // type:function size:0x10 +__ne__10sStateID_cCFRC12sStateIDIf_c = .text:0x802DDEE0; // type:function size:0x34 +isSameName__10sStateID_cCFPCc = .text:0x802DDF20; // type:function size:0x8 +name__10sStateID_cCFv = .text:0x802DDF30; // type:function size:0x8 +number__10sStateID_cCFv = .text:0x802DDF40; // type:function size:0x8 +__dt__13sStateFctIf_cFv = .text:0x802DDF50; // type:function size:0x40 +__dt__15sStateIDChkIf_cFv = .text:0x802DDF90; // type:function size:0x40 +__dt__13sStateIDChk_cFv = .text:0x802DDFD0; // type:function size:0x58 +__dt__12sStateIDIf_cFv = .text:0x802DE030; // type:function size:0x40 +__dt__10sStateIf_cFv = .text:0x802DE070; // type:function size:0x40 +__dt__16sStateMethodIf_cFv = .text:0x802DE0B0; // type:function size:0x40 +__dt__20sStateMethodUsr_FI_cFv = .text:0x802DE0F0; // type:function size:0x58 +__dt__13sStateMgrIf_cFv = .text:0x802DE150; // type:function size:0x40 +isNormalID__13sStateIDChk_cCFRC12sStateIDIf_c = .text:0x802DE190; // type:function size:0x8 +__sinit_\s_StateId_cpp = .text:0x802DE1A0; // type:function size:0x54 scope:local +__ct__14sStateMethod_cFR15sStateIDChkIf_cR13sStateFctIf_cRC12sStateIDIf_c = .text:0x802DE200; // type:function size:0x48 +__dt__14sStateMethod_cFv = .text:0x802DE250; // type:function size:0x58 +initializeStateMethod__14sStateMethod_cFv = .text:0x802DE2B0; // type:function size:0xA8 +executeStateMethod__14sStateMethod_cFv = .text:0x802DE360; // type:function size:0xC4 +finalizeStateMethod__14sStateMethod_cFv = .text:0x802DE430; // type:function size:0x8C +changeStateMethod__14sStateMethod_cFRC12sStateIDIf_c = .text:0x802DE4C0; // type:function size:0x74 +__ct__20sStateMethodUsr_FI_cFR15sStateIDChkIf_cR13sStateFctIf_cRC12sStateIDIf_c = .text:0x802DE540; // type:function size:0x3C +initializeStateLocalMethod__20sStateMethodUsr_FI_cFv = .text:0x802DE580; // type:function size:0x68 +executeStateLocalMethod__20sStateMethodUsr_FI_cFv = .text:0x802DE5F0; // type:function size:0x4C +finalizeStateLocalMethod__20sStateMethodUsr_FI_cFv = .text:0x802DE640; // type:function size:0x54 +changeStateLocalMethod__20sStateMethodUsr_FI_cFRC12sStateIDIf_c = .text:0x802DE6A0; // type:function size:0x4C fn_802DE6F0 = .text:0x802DE6F0; // type:function size:0x4 fn_802DE700 = .text:0x802DE700; // type:function size:0x8 fn_802DE710 = .text:0x802DE710; // type:function size:0x2C @@ -17288,7 +17288,7 @@ fn_802E0AB0 = .text:0x802E0AB0; // type:function size:0x34 fn_802E0AF0 = .text:0x802E0AF0; // type:function size:0x1BC fn_802E0CB0 = .text:0x802E0CB0; // type:function size:0x48 fn_802E0D00 = .text:0x802E0D00; // type:function size:0x8 -fn_802E0D10 = .text:0x802E0D10; // type:function size:0x8 +rnd__2cMFv = .text:0x802E0D10; // type:function size:0x8 fn_802E0D20 = .text:0x802E0D20; // type:function size:0x58 fn_802E0D80 = .text:0x802E0D80; // type:function size:0x38 fn_802E0DC0 = .text:0x802E0DC0; // type:function size:0x48 @@ -35658,10 +35658,10 @@ lbl_805417B8 = .data:0x805417B8; // type:object size:0x8C lbl_80541844 = .data:0x80541844; // type:object size:0x58 lbl_8054189C = .data:0x8054189C; // type:object size:0x4C lbl_805418E8 = .data:0x805418E8; // type:object size:0x48 -lbl_80541930 = .data:0x80541930; // type:object size:0x10 -lbl_80541940 = .data:0x80541940; // type:object size:0x40 -lbl_80541980 = .data:0x80541980; // type:object size:0x28 -lbl_805419A8 = .data:0x805419A8; // type:object size:0x40 +__vt__13sStateIDChk_c = .data:0x80541930; // type:object size:0x10 +__vt__20sStateMethodUsr_FI_c = .data:0x80541940; // type:object size:0x40 +__vt__10sStateID_c = .data:0x80541980; // type:object size:0x28 +__vt__14sStateMethod_c = .data:0x805419A8; // type:object size:0x40 lbl_805419E8 = .data:0x805419E8; // type:object size:0xC data:string lbl_805419F4 = .data:0x805419F4; // type:object size:0xC data:string lbl_80541A00 = .data:0x80541A00; // type:object size:0x10 @@ -40272,7 +40272,7 @@ lbl_80575B00 = .sbss:0x80575B00; // type:object size:0x20 data:4byte lbl_80575B20 = .sbss:0x80575B20; // type:object size:0x20 data:4byte lbl_80575B40 = .sbss:0x80575B40; // type:object size:0x20 data:4byte lbl_80575B60 = .sbss:0x80575B60; // type:object size:0x8 data:4byte -lbl_80575B68 = .sbss:0x80575B68; // type:object size:0x8 data:4byte +sm_numberMemo__10sStateID_c = .sbss:0x80575B68; // type:object size:0x8 data:4byte lbl_80575B70 = .sbss:0x80575B70; // type:object size:0x8 data:4byte lbl_80575B78 = .sbss:0x80575B78; // type:object size:0x4 data:4byte lbl_80575B7C = .sbss:0x80575B7C; // type:object size:0x4 data:4byte @@ -49102,7 +49102,7 @@ lbl_805B8378 = .bss:0x805B8378; // type:object size:0x28 data:4byte lbl_805B83A0 = .bss:0x805B83A0; // type:object size:0x100 lbl_805B84A0 = .bss:0x805B84A0; // type:object size:0x10 data:4byte lbl_805B84B0 = .bss:0x805B84B0; // type:object size:0xC -lbl_805B84BC = .bss:0x805B84BC; // type:object size:0xC +null__8sStateID = .bss:0x805B84BC; // type:object size:0xC m_tmpCtData__7fBase_c = .bss:0x805B84C8; // type:object size:0x10 data:4byte m_connectManage__10fManager_c = .bss:0x805B84D8; // type:object size:0x10 data:4byte m_createManage__10fManager_c = .bss:0x805B84E8; // type:object size:0x14 data:4byte diff --git a/configure.py b/configure.py index 7782d9dd..13218904 100644 --- a/configure.py +++ b/configure.py @@ -311,6 +311,9 @@ config.libs = [ Object(Matching, "m/m_heap.cpp"), Object(NonMatching, "m/m_mtx.cpp"), Object(Matching, "m/m_pad.cpp"), + Object(Matching, "s/s_StateId.cpp"), + Object(Matching, "s/s_StateMethod.cpp"), + Object(Matching, "s/s_StateMethodUsr_FI.cpp"), Object(Matching, "DynamicLink.cpp"), # framework (f_name) # d stuff (d_name) @@ -1051,7 +1054,7 @@ config.libs = [ Rel(NonMatching, "d_t_reaction", "REL/d/t/d_t_reaction.cpp"), Rel(NonMatching, "d_t_restart_time_stone", "REL/d/t/d_t_restart_time_stone.cpp"), Rel(NonMatching, "d_t_ride_rock_set", "REL/d/t/d_t_ride_rock_set.cpp"), - Rel(NonMatching, "d_t_rock_boat", "REL/d/t/d_t_rock_boat.cpp"), + Rel(Matching, "d_t_rock_boat", "REL/d/t/d_t_rock_boat.cpp"), Rel(NonMatching, "d_t_roll_attack_log", "REL/d/t/d_t_roll_attack_log.cpp"), Rel(NonMatching, "d_t_ro_at_target_manager", "REL/d/t/d_t_ro_at_target_manager.cpp"), Rel(NonMatching, "d_t_scene_change", "REL/d/t/d_t_scene_change.cpp"), diff --git a/include/c/c_math.h b/include/c/c_math.h index e192fa20..78e47876 100644 --- a/include/c/c_math.h +++ b/include/c/c_math.h @@ -5,6 +5,11 @@ namespace cM { static s16 atan2s(f32, f32); +void initRnd(s32); +f32 rnd(); +int rndInt(int max); +f32 rndF(f32 max); +f32 rndFX(f32 amp); } // namespace cM #endif diff --git a/include/d/a/obj/d_a_obj_base.h b/include/d/a/obj/d_a_obj_base.h index ed6d5abd..c46e92a9 100644 --- a/include/d/a/obj/d_a_obj_base.h +++ b/include/d/a/obj/d_a_obj_base.h @@ -49,9 +49,9 @@ public: /* 8002ea20 */ virtual bool drop(); public: - /* 8002e630 */ static dAcObjBase_c create(fProfile::PROFILE_NAME_e actorId, u32 roomId, u32 params1, mVec3_c *pos, + /* 8002e630 */ static void create(fProfile::PROFILE_NAME_e actorId, s8 roomId, u32 params1, mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, u32 params2); - /* 8002e6d0 */ static dAcObjBase_c create(char *name, u32 roomId, u32 params1, mVec3_c *pos, mAng3_c *rot, + /* 8002e6d0 */ static void create(char *name, u32 roomId, u32 params1, mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, u32 params2, u16 id, u8 viewclipId); /* 8002e770 */ static dAcObjBase_c *findObject(fProfile::PROFILE_NAME_e actorId, fLiNdBa_c *refList, dAcObjBase_c *parent); diff --git a/include/d/tg/d_t_rock_boat.h b/include/d/tg/d_t_rock_boat.h new file mode 100644 index 00000000..378593b4 --- /dev/null +++ b/include/d/tg/d_t_rock_boat.h @@ -0,0 +1,36 @@ +#ifndef D_T_ROCK_BOAT +#define D_T_ROCK_BOAT + +#include +#include +#include +#include + +class dTgAbs_c : public dAcBase_c { +public: + virtual ~dTgAbs_c() {} +}; + +class dTgRockBoat_c : public dTgAbs_c { +public: + dTgRockBoat_c() : mStateMgr(*this, sStateID::null) {} + virtual ~dTgRockBoat_c() {} + virtual int create() override; + virtual int actorExecute() override; + virtual int draw() override; + virtual int doDelete() override; + + STATE_FUNC_DECLARE(dTgRockBoat_c, Wait); + +private: + + sFStateMgr_c mStateMgr; + int cooldown; + int boatNum; + + void dummy() { + mStateMgr.getStateID(); + } +}; + +#endif diff --git a/include/d/tg/d_t_tumble_weed.h b/include/d/tg/d_t_tumble_weed.h new file mode 100644 index 00000000..baf61848 --- /dev/null +++ b/include/d/tg/d_t_tumble_weed.h @@ -0,0 +1,44 @@ +#ifndef D_T_TUMBLE_WEED_H +#define D_T_TUMBLE_WEED_H + +#include +#include +#include +#include + +class fLiNdTumbleweed_c : public fLiNdBa_c { +public: + fLiNdTumbleweed_c(fBase_c *owner) : fLiNdBa_c(owner) {} + u16 someField; +}; + +class dTgTumbleWeed_c : public dTg_c { +public: + dTgTumbleWeed_c() : mStateMgr(*this, sStateID::null), childTumbleweed(nullptr) {} + virtual ~dTgTumbleWeed_c() {} + virtual int create() override; + virtual int actorExecute() override; + virtual int draw() override; + virtual int doDelete() override; + + STATE_FUNC_DECLARE(dTgTumbleWeed_c, AreaOut); + STATE_FUNC_DECLARE(dTgTumbleWeed_c, AreaIn); + STATE_FUNC_DECLARE(dTgTumbleWeed_c, Wind); + +private: + bool shouldSpawnTumbleweed(); + bool shouldDoWind(); + void doSpawnTumbleweed(); + void getWind(mVec3_c *); + void unused() { + mStateMgr.getStateID(); + } + + sFStateMgr_c mStateMgr; + u16 tumbleweedTimer; + u16 padding; + u16 windTimer; + fLiNdTumbleweed_c childTumbleweed; +}; + +#endif diff --git a/include/f/f_list_nd.h b/include/f/f_list_nd.h index 6e5cc8eb..6adb8ea6 100644 --- a/include/f/f_list_nd.h +++ b/include/f/f_list_nd.h @@ -12,6 +12,7 @@ class fBase_c; class fLiNdBa_c : public cListNd_c { public: fLiNdBa_c(fBase_c *owner) : p_owner(owner) {} + ~fLiNdBa_c() { unlink(); } inline fLiNdBa_c *getPrev() const { return (fLiNdBa_c *)cListNd_c::getPrev(); diff --git a/include/s/docgroup.h b/include/s/docgroup.h new file mode 100644 index 00000000..a99aa2fb --- /dev/null +++ b/include/s/docgroup.h @@ -0,0 +1,10 @@ +#pragma once +// [This header file defines documentation groups for better categorization] + +/// @ingroup game +/// @defgroup slib sLib +/// @brief Provides various utilities (including the state system). + +/// @defgroup state sState +/// @ingroup slib +/// @brief A state system implementation. diff --git a/include/s/s_FState.hpp b/include/s/s_FState.hpp new file mode 100644 index 00000000..2772d3dd --- /dev/null +++ b/include/s/s_FState.hpp @@ -0,0 +1,41 @@ +#pragma once +#include +#include + +/// @brief A state holder for a given class. +/// @tparam T The class that this state belongs to. +/// @ingroup state +template +class sFState_c : public sStateIf_c { +public: + sFState_c(T &owner) : mpOwner(owner) { mpID = nullptr; } + + enum STATE_ACTION_e { + INITIALIZE, + EXECUTE, + FINALIZE + }; + + /// @brief Performs a state action. + /// @details [Gets inlined, needed for function order to match]. + /// @param action The action to perform. + void performAction(STATE_ACTION_e action) { + if (action == FINALIZE) { + mpID->finalizeState(mpOwner); + } else if (action == EXECUTE) { + mpID->executeState(mpOwner); + } else if (action == INITIALIZE) { + mpID->initializeState(mpOwner); + } + } + + virtual void initialize() { performAction(INITIALIZE); } + virtual void execute() { performAction(EXECUTE); } + virtual void finalize() { performAction(FINALIZE); } + + void setID(const sFStateID_c *id) { mpID = id; } + +private: + T &mpOwner; ///< The owner of this state. + const sFStateID_c *mpID; ///< The state ID that runs the state methods. +}; diff --git a/include/s/s_FStateFct.hpp b/include/s/s_FStateFct.hpp new file mode 100644 index 00000000..55c1d861 --- /dev/null +++ b/include/s/s_FStateFct.hpp @@ -0,0 +1,26 @@ +#pragma once +#include +#include +#include + +/// @brief A state factory for a given class. +/// @tparam T The class that this state belongs to. +/// @ingroup state +template +class sFStateFct_c : public sStateFctIf_c { +public: + sFStateFct_c(T &owner) : mState(owner) {} + + virtual sStateIf_c* build(const sStateIDIf_c &id) { + if (!id.isNull()) { + mState.setID((const sFStateID_c *) &id); + return &mState; + } + return nullptr; + } + + virtual void dispose(sStateIf_c *&id) { id = nullptr; } + +private: + sFState_c mState; +}; diff --git a/include/s/s_FStateID.hpp b/include/s/s_FStateID.hpp new file mode 100644 index 00000000..1100c54b --- /dev/null +++ b/include/s/s_FStateID.hpp @@ -0,0 +1,58 @@ +#pragma once +#include +#include + +/// @brief An implementation of a state ID for a given class. +/// @details It adds the ability to call the three state methods on a state owner class. +/// @tparam T The class that this state belongs to. +/// @ingroup state +template +class sFStateID_c : public sStateID_c { +public: + typedef void (T::*stateFunc)(); + + /** + * @brief Constructs a new sFStateID_c instance. + * + * @param name The name of this state ID. + * @param initialize The initialize method for this state ID. + * @param execute The execute method for this state ID. + * @param finalize The finalize method for this state ID. + */ + sFStateID_c(const char *name, stateFunc initialize, stateFunc execute, stateFunc finalize) : + sStateID_c(name), + mpInitialize(initialize), + mpExecute(execute), + mpFinalize(finalize) {} + + /// @brief Returns true if the given name matches this state ID's name. + virtual bool isSameName(const char *otherName) const { + char *part = strrchr(otherName, ':'); + if (part != nullptr) { + otherName = part + 1; + } + const char *thisName = strrchr(name(), ':') + 1; + if (strcmp(thisName, otherName) == 0) { + return true; + } else { + return false; + } + } + + /// @brief Calls the initialize method on the owner. + /// @param owner The owner of this state ID. + virtual void initializeState(T &owner) const { (owner.*mpInitialize)(); } + + /// @brief Calls the execute method on the owner. + /// @param owner The owner of this state ID. + virtual void executeState(T &owner) const { (owner.*mpExecute)(); } + + /// @brief Calls the finalize method on the owner. + /// @param owner The owner of this state ID. + virtual void finalizeState(T &owner) const { (owner.*mpFinalize)(); } + +private: + stateFunc mpInitialize; ///< The initialize method for this state ID. + stateFunc mpExecute; ///< The execute method for this state ID. + stateFunc mpFinalize; ///< The finalize method for this state ID. +}; diff --git a/include/s/s_FStateMgr.hpp b/include/s/s_FStateMgr.hpp new file mode 100644 index 00000000..be2858c4 --- /dev/null +++ b/include/s/s_FStateMgr.hpp @@ -0,0 +1,17 @@ +#pragma once +#include +#include +#include +#include +#include + +/// @brief A wrapper for sStateMgr_c that uses sFStateFct_c and sStateIDChk_c. +/// @tparam T The class that this state belongs to. +/// @tparam Method The method to use for the state manager. +/// @ingroup state +template +class sFStateMgr_c : public sStateMgr_c { +public: + sFStateMgr_c(T &owner, const sStateIDIf_c &initializeState) : + sStateMgr_c(owner, initializeState) {} +}; diff --git a/include/s/s_Phase.hpp b/include/s/s_Phase.hpp new file mode 100644 index 00000000..d21b2f80 --- /dev/null +++ b/include/s/s_Phase.hpp @@ -0,0 +1,34 @@ +#pragma once + +/// @brief A phase is a list of methods to be called in order. +/// @ingroup slib dol +class sPhase_c { +public: + /// @brief Return value of a phase method and ::callMethod. + /// @unofficial + enum METHOD_RESULT_e { + WAIT, ///< Do not proceed to the next method in the phase. + OK, ///< Proceed to the next method in the phase. + DONE ///< The phase is done. + }; + typedef METHOD_RESULT_e (phaseMethod)(void *); + + /** + * @brief Constructs a new phase with a given method list. + * + * @param methodList The list of methods in the phase. + * @param count The length of the method list. + */ + sPhase_c(phaseMethod **methodList, int count); + /** + * @brief Executes the phase until the end is reached or a method returns METHOD_RESULT_e::WAIT. + * + * @param thisPtr A pointer to the owner. + * @return METHOD_RESULT_e::WAIT if the phase is not done yet, and METHOD_RESULT_e::DONE if the phase is finished. + */ + METHOD_RESULT_e callMethod(void *thisPtr); + + phaseMethod **mpMethodList; ///< The method list. + unsigned short mPhaseLength; ///< The length of the method list. + unsigned short mCurrMethod; ///< The index of the method to execute. +}; diff --git a/include/s/s_State.hpp b/include/s/s_State.hpp new file mode 100644 index 00000000..1df9c01f --- /dev/null +++ b/include/s/s_State.hpp @@ -0,0 +1,14 @@ +#pragma once +#include +#include + +#define STATE_FUNC_DECLARE(class, name) void initializeState_##name(); \ + void executeState_##name(); \ + void finalizeState_##name(); \ + static sFStateID_c StateID_##name + +#define STATE_DEFINE(class, name) sFStateID_c class::StateID_##name( \ + #class "::StateID_" #name, \ + &class::initializeState_##name, \ + &class::executeState_##name, \ + &class::finalizeState_##name) diff --git a/include/s/s_StateID.hpp b/include/s/s_StateID.hpp new file mode 100644 index 00000000..cbfaab57 --- /dev/null +++ b/include/s/s_StateID.hpp @@ -0,0 +1,43 @@ +#pragma once +#include + +/// @brief A generic implementation of a state ID. +/// @details It simply contains a name string and a unique number. +/// @ingroup state +class sStateID_c : public sStateIDIf_c { +public: + class NumberMemo_c { + public: + NumberMemo_c() : curr(0) {} + unsigned int get() { + curr++; + return curr; + } + unsigned int curr; + }; + + sStateID_c(const char *name); + virtual ~sStateID_c(); + + virtual bool isNull() const; + virtual bool isEqual(const sStateIDIf_c &other) const; + + virtual bool operator==(const sStateIDIf_c &other) const; + virtual bool operator!=(const sStateIDIf_c &other) const; + + virtual bool isSameName(const char *name) const; + virtual const char *name() const; + virtual unsigned int number() const; + +protected: + const char *mpName; ///< The name of this state ID. + unsigned int mNumber; ///< The number of this state ID. + + static NumberMemo_c sm_numberMemo; ///< Used to give each state a unique number. +}; + +namespace sStateID { + + /// @ingroup state + extern sStateID_c null; ///< A null state instance. +} diff --git a/include/s/s_StateIDChk.hpp b/include/s/s_StateIDChk.hpp new file mode 100644 index 00000000..41d99213 --- /dev/null +++ b/include/s/s_StateIDChk.hpp @@ -0,0 +1,10 @@ +#pragma once +#include + +/// @brief A default implementation of a state ID checker. +/// @details ::isNormalID always returns true. +class sStateIDChk_c : public sStateIDChkIf_c { +public: + virtual ~sStateIDChk_c(); + virtual bool isNormalID(const sStateIDIf_c &) const { return true; } +}; diff --git a/include/s/s_StateInterfaces.hpp b/include/s/s_StateInterfaces.hpp new file mode 100644 index 00000000..cb624230 --- /dev/null +++ b/include/s/s_StateInterfaces.hpp @@ -0,0 +1,73 @@ +#pragma once + +/// @addtogroup state +/// @{ + +class sStateMethodIf_c { +public: + virtual ~sStateMethodIf_c(); +}; + +/// @brief The interface for state IDs. +/// @details A state ID is made up of a name string and a unique number, where 0 denotes a null state. +/// Null states do not have any corresponding behaviour. They can be used, for example, +/// if a state holder needs to be initialized but the initial state ID is not known yet. +class sStateIDIf_c { +public: + virtual ~sStateIDIf_c(); + + virtual bool isNull() const = 0; ///< Returns whether this is a null state. + virtual bool isEqual(const sStateIDIf_c &other) const = 0; ///< Returns whether both states have the same number. + + virtual bool operator==(const sStateIDIf_c &other) const = 0; ///< Overloaded equality operator, using ::isEqual. + virtual bool operator!=(const sStateIDIf_c &other) const = 0; ///< Overloaded inequality operator, using ::isEqual. + + virtual bool isSameName(const char *name) const = 0; ///< Returns whether this state ID is called @p name. + virtual const char *name() const = 0; ///< Returns the name of this state ID. + virtual unsigned int number() const = 0; ///< Returns the number of this state ID. +}; + +/// @brief The interface for a state holder. +/// @details A state holder is linked to a state ID and can execute its corresponding behaviour. +class sStateIf_c { +public: + virtual ~sStateIf_c(); + virtual const void initialize() = 0; ///< Initializes the state. + virtual const void execute() = 0; ///< Executes the state. + virtual const void finalize() = 0; ///< Prepares the state for termination. +}; + +/// @brief The interface for state factories. +/// @details A state factory produces a state holder from a given state ID. +class sStateFctIf_c { +public: + virtual ~sStateFctIf_c(); + virtual sStateIf_c *build(sStateIDIf_c const &id) = 0; ///< Returns a new state with a given state ID. + virtual void dispose(sStateIf_c *&id) = 0; ///< Clears out the pointer to a state. +}; + +/// @brief The interface for state ID checkers. +/// @details [This class is not really used, but it seems to be intended for testing if a state is "normal", most likely a debug leftover]. +class sStateIDChkIf_c { +public: + virtual ~sStateIDChkIf_c(); + virtual bool isNormalID(const sStateIDIf_c &id) const = 0; ///< Returns whether a state ID is normal. +}; + +/// @brief The interface for state managers. +/// @details A state manager handles execution of and transitioning between state IDs. +class sStateMgrIf_c { +public: + virtual ~sStateMgrIf_c(); + virtual void initializeState() = 0; ///< Initializes the current state. + virtual void executeState() = 0; ///< Executes the current state. + virtual void finalizeState() = 0; ///< Prepares the current state for termination. + virtual void changeState(const sStateIDIf_c &newStateID) = 0; ///< Transitions to a new state ID. + virtual void refreshState() = 0; ///< Marks the current state to be executed again. + virtual sStateIf_c *getState() const = 0; ///< Gets the state holder. + virtual const sStateIDIf_c *getNewStateID() const = 0; ///< Gets the next state ID. + virtual const sStateIDIf_c *getStateID() const = 0; ///< Gets the current state ID. + virtual const sStateIDIf_c *getOldStateID() const = 0; ///< Gets the previous state ID. +}; + +/// @} diff --git a/include/s/s_StateMethod.hpp b/include/s/s_StateMethod.hpp new file mode 100644 index 00000000..8dadaa9e --- /dev/null +++ b/include/s/s_StateMethod.hpp @@ -0,0 +1,49 @@ +#pragma once +#include + +/// @brief A class that handles state execution and transition. +/// @details [Presumably, sStateMethod_c actually means "methods for state interaction", or something like that]. +/// @ingroup state +class sStateMethod_c : public sStateMethodIf_c { +public: + /** + * @brief Constructs a new sStateMethod_c instance. + * + * @param checker The state checker to use. + * @param factory The state factory to use. + * @param initialState The initial state ID of this instance. + */ + sStateMethod_c(sStateIDChkIf_c &checker, sStateFctIf_c &factory, const sStateIDIf_c &initialState); + virtual ~sStateMethod_c(); ///< Destroys the sStateMethod_c instance. + + virtual void initializeStateMethod(); ///< @copydoc sStateMgrIf_c::initializeState + virtual void executeStateMethod(); ///< @copydoc sStateMgrIf_c::executeState + virtual void finalizeStateMethod(); ///< @copydoc sStateMgrIf_c::finalizeState + virtual void changeStateMethod(const sStateIDIf_c &newStateID); ///< @copydoc sStateMgrIf_c::changeState + virtual void refreshStateMethod() { mRefreshStateMethod = true; } ///< @copydoc sStateMgrIf_c::refreshState + virtual sStateIf_c *getState() const { return mpState; } ///< @copydoc sStateMgrIf_c::getState + virtual const sStateIDIf_c *getNewStateID() const { return mpNewStateID; } ///< @copydoc sStateMgrIf_c::getNewStateID + virtual const sStateIDIf_c *getStateID() const { return mpStateID; } ///< @copydoc sStateMgrIf_c::getStateID + virtual const sStateIDIf_c *getOldStateID() const { return mpOldStateID; } ///< @copydoc sStateMgrIf_c::getOldStateID + + virtual int initializeStateLocalMethod() = 0; ///< Performs the actual state initialization. + virtual void executeStateLocalMethod() = 0; ///< Performs the actual state execution. + virtual void finalizeStateLocalMethod() = 0; ///< Performs the actual state termination. + virtual void changeStateLocalMethod(const sStateIDIf_c &newStateID) = 0; ///< Performs the actual state transition. + +protected: + sStateIDChkIf_c &mpStateChk; ///< @unused The state checker to use. + sStateFctIf_c &mpStateFct; ///< The state factory which produces the state holder. + + bool mInitFinalizeLock; ///< A lock to ensure ::initializeStateMethod and ::finalizeStateMethod are not called recursively. + bool mExecutionLock; ///< A lock to ensure ::executeStateMethod is not called recursively. + bool mIsValid; ///< If the state holder contains a valid state ID. + bool mStateChanged; ///< If the current state has changed during execution. + bool mRefreshStateMethod; ///< True, if after a state transition, the state should be executed again. + + const sStateIDIf_c *mpNewStateID; ///< The next state ID. + const sStateIDIf_c *mpOldStateID; ///< The previous state ID. + const sStateIDIf_c *mpStateID; ///< The current state ID. + + sStateIf_c *mpState; ///< The current state holder. +}; diff --git a/include/s/s_StateMethodUsr_FI.hpp b/include/s/s_StateMethodUsr_FI.hpp new file mode 100644 index 00000000..0921f336 --- /dev/null +++ b/include/s/s_StateMethodUsr_FI.hpp @@ -0,0 +1,16 @@ +#pragma once +#include + +/// @brief An extension to sStateMethod_c that implements the remaining abstract methods. +/// @details [Name might mean "Functionality implementation"]. +/// @ingroup state +class sStateMethodUsr_FI_c : public sStateMethod_c { +public: + sStateMethodUsr_FI_c(sStateIDChkIf_c &checker, sStateFctIf_c &factory, const sStateIDIf_c &initialState); + virtual ~sStateMethodUsr_FI_c(); + + virtual int initializeStateLocalMethod(); + virtual void executeStateLocalMethod(); + virtual void finalizeStateLocalMethod(); + virtual void changeStateLocalMethod(const sStateIDIf_c &newStateID); +}; diff --git a/include/s/s_StateMgr.hpp b/include/s/s_StateMgr.hpp new file mode 100644 index 00000000..3fe4c74c --- /dev/null +++ b/include/s/s_StateMgr.hpp @@ -0,0 +1,37 @@ +#pragma once +#include + +/** + * @brief An implementation of sStateMgrIf_c. + * + * @tparam T The parent class for this state manager. + * @tparam Method The state method handler to use. + * @tparam Factory The state factory to use. + * @tparam Check The state ID checker to use. + * @ingroup state + */ +template class Factory, class Check> +class sStateMgr_c : sStateMgrIf_c { +public: + sStateMgr_c(T &owner, const sStateIDIf_c &initialState) : + mFactory(owner), + mMethod(mCheck, mFactory, initialState) {} + + virtual void initializeState() { mMethod.initializeStateMethod(); } + virtual void executeState() { mMethod.executeStateMethod(); } + virtual void finalizeState() { mMethod.finalizeStateMethod(); } + + virtual void changeState(const sStateIDIf_c &newState) { mMethod.changeStateMethod(newState); } + + virtual void refreshState() { mMethod.refreshStateMethod(); } + + virtual sStateIf_c *getState() const { return mMethod.getState(); } + virtual const sStateIDIf_c *getNewStateID() const { return mMethod.getNewStateID(); } + virtual const sStateIDIf_c *getStateID() const { return mMethod.getStateID(); } + virtual const sStateIDIf_c *getOldStateID() const { return mMethod.getOldStateID(); } + +private: + Check mCheck; + Factory mFactory; + Method mMethod; +}; diff --git a/src/REL/d/t/d_t_rock_boat.cpp b/src/REL/d/t/d_t_rock_boat.cpp index e69de29b..c22d2b7c 100644 --- a/src/REL/d/t/d_t_rock_boat.cpp +++ b/src/REL/d/t/d_t_rock_boat.cpp @@ -0,0 +1,37 @@ +#include +#include + +SPECIAL_ACTOR_PROFILE(TAG_ROCK_BOAT, dTgRockBoat_c, fProfile::TAG_ROCK_BOAT, 0x173, 0, 3); + +STATE_DEFINE(dTgRockBoat_c, Wait); + +int dTgRockBoat_c::create() { + mStateMgr.changeState(StateID_Wait); + cooldown = 1; + return 1; +} + +int dTgRockBoat_c::doDelete() { + return 1; +} + +int dTgRockBoat_c::actorExecute() { + mStateMgr.executeState(); + return 1; +} + +int dTgRockBoat_c::draw() { + return 1; +} + +void dTgRockBoat_c::initializeState_Wait() {} +void dTgRockBoat_c::executeState_Wait() { + if (cooldown > 0 && --cooldown == 0) { + dAcObjBase_c::create(fProfile::OBJ_ROCK_BOAT, roomid, (boatNum << 0x1c) | 0xff, &position, 0, 0, -1); + cooldown = 0x259; + if (++boatNum == 0xf) { + boatNum = 0; + } + } +} +void dTgRockBoat_c::finalizeState_Wait() {} diff --git a/src/REL/d/t/d_t_tumble_weed.cpp b/src/REL/d/t/d_t_tumble_weed.cpp index e69de29b..c98f6121 100644 --- a/src/REL/d/t/d_t_tumble_weed.cpp +++ b/src/REL/d/t/d_t_tumble_weed.cpp @@ -0,0 +1,114 @@ +#include +#include +#include + +SPECIAL_ACTOR_PROFILE(TAG_TUMBLE_WEED, dTgTumbleWeed_c, fProfile::TUMBLE_WEED_TAG, 0x0244, 0, 0); + +STATE_DEFINE(dTgTumbleWeed_c, AreaOut); +STATE_DEFINE(dTgTumbleWeed_c, AreaIn); +STATE_DEFINE(dTgTumbleWeed_c, Wind); + +int dTgTumbleWeed_c::create() { + tumbleweedTimer = 0; + windTimer = 0x96; + mStateMgr.changeState(StateID_AreaOut); + return 1; +} + +u16 decr(u16 *num); + +int dTgTumbleWeed_c::doDelete() { + return 1; +} + +int dTgTumbleWeed_c::actorExecute() { + mStateMgr.executeState(); + decr(&tumbleweedTimer); + return 1; +} + +u16 decr(u16 *num) { + if (*num != 0) { + (*num)--; + } + return *num; +} + +int dTgTumbleWeed_c::draw() { + return 1; +} + +void dTgTumbleWeed_c::initializeState_AreaOut() {} +void dTgTumbleWeed_c::executeState_AreaOut() { + if (decr(&windTimer) == 0) { + windTimer = 0x96; + if (shouldDoWind()) { + mStateMgr.changeState(StateID_Wind); + return; + } + } + if (isWithinPlayerRadius(scale.x)) { + mStateMgr.changeState(StateID_AreaIn); + } +} +void dTgTumbleWeed_c::finalizeState_AreaOut() {} + +void dTgTumbleWeed_c::initializeState_AreaIn() {} +void dTgTumbleWeed_c::executeState_AreaIn() { + if (tumbleweedTimer == 0) { + if (shouldSpawnTumbleweed()) { + doSpawnTumbleweed(); + } + tumbleweedTimer = 600; + } + if (decr(&windTimer) == 0) { + windTimer = 0x96; + if (shouldDoWind()) { + mStateMgr.changeState(StateID_Wind); + return; + } + } + if (!isWithinPlayerRadius(scale.x)) { + mStateMgr.changeState(StateID_AreaOut); + } +} +void dTgTumbleWeed_c::finalizeState_AreaIn() {} + +extern "C" void fn_475_1B00(fBase_c *, mVec3_c&); +void dTgTumbleWeed_c::initializeState_Wind() { + mVec3_c vec; + getWind(&vec); + if (childTumbleweed.p_owner != nullptr) { + fn_475_1B00(childTumbleweed.p_owner, vec); + } +} + +void dTgTumbleWeed_c::executeState_Wind() { + if (isWithinPlayerRadius(scale.x)) { + mStateMgr.changeState(StateID_AreaIn); + } else { + mStateMgr.changeState(StateID_AreaOut); + } +} +void dTgTumbleWeed_c::finalizeState_Wind() {} + +bool dTgTumbleWeed_c::shouldSpawnTumbleweed() { + bool spawnAllowed = false; + if (childTumbleweed.p_owner == nullptr && cM::rnd() <= 0.8f) { + spawnAllowed = true; + } + + if (spawnAllowed) { + return true; + } + + return false; +} + + +bool dTgTumbleWeed_c::shouldDoWind() { + return childTumbleweed.p_owner != nullptr && cM::rnd() <= 0.5f; +} +void dTgTumbleWeed_c::doSpawnTumbleweed() { +} +void dTgTumbleWeed_c::getWind(mVec3_c*) {} diff --git a/src/s/s_Phase.cpp b/src/s/s_Phase.cpp new file mode 100644 index 00000000..9418fbe9 --- /dev/null +++ b/src/s/s_Phase.cpp @@ -0,0 +1,28 @@ +#include + +sPhase_c::sPhase_c(phaseMethod **methodList, int count) { + mpMethodList = methodList; + mPhaseLength = count; + mCurrMethod = 0; +} + +sPhase_c::METHOD_RESULT_e sPhase_c::callMethod(void *thisPtr) { + if (mCurrMethod >= mPhaseLength) { + return DONE; + } + + METHOD_RESULT_e result = OK; + while (result == OK) { + result = (mpMethodList[mCurrMethod])(thisPtr); + + if (result == OK) { + // Go to the next method + mCurrMethod++; + if (mCurrMethod >= mPhaseLength) { + return DONE; + } + } + } + + return result; +} diff --git a/src/s/s_StateID.cpp b/src/s/s_StateID.cpp new file mode 100644 index 00000000..548a01e7 --- /dev/null +++ b/src/s/s_StateID.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include + +sStateID_c::NumberMemo_c sStateID_c::sm_numberMemo; +sStateID_c sStateID::null(nullptr); + +sStateID_c::sStateID_c(const char *name) { + mpName = name; + mNumber = (name != nullptr) ? sm_numberMemo.get() : 0; +} + +sStateID_c::~sStateID_c() {} + +bool sStateID_c::isNull() const { + return mNumber == 0; +} + +bool sStateID_c::isEqual(const sStateIDIf_c &other) const { + return number() == other.number(); +} + +bool sStateID_c::operator==(const sStateIDIf_c &other) const { + return isEqual(other); +} + +bool sStateID_c::operator!=(const sStateIDIf_c &other) const { + return !isEqual(other); +} + +bool sStateID_c::isSameName(const char *name) const { + // Just return false, the full implementation is in sFStateID_c + return false; +} + +const char *sStateID_c::name() const { + return mpName; +} + +unsigned int sStateID_c::number() const { + return mNumber; +} + +sStateFctIf_c::~sStateFctIf_c() {} +sStateIDChkIf_c::~sStateIDChkIf_c() {} +sStateIDChk_c::~sStateIDChk_c() {} +sStateIDIf_c::~sStateIDIf_c() {} +sStateIf_c::~sStateIf_c() {} +sStateMethodIf_c::~sStateMethodIf_c() {} +sStateMethodUsr_FI_c::~sStateMethodUsr_FI_c() {} +sStateMgrIf_c::~sStateMgrIf_c() {} diff --git a/src/s/s_StateMethod.cpp b/src/s/s_StateMethod.cpp new file mode 100644 index 00000000..fec04f78 --- /dev/null +++ b/src/s/s_StateMethod.cpp @@ -0,0 +1,74 @@ +#include +#include +#include +#include + +sStateMethod_c::sStateMethod_c(sStateIDChkIf_c &checker, sStateFctIf_c &factory, const sStateIDIf_c &initialState) : + mpStateChk(checker), + mpStateFct(factory), + mInitFinalizeLock(false), + mExecutionLock(false), + mIsValid(false), + mStateChanged(false), + mRefreshStateMethod(false), + mpNewStateID(&initialState), + mpOldStateID(&sStateID::null), + mpStateID(&initialState), + mpState(nullptr) { +} + +sStateMethod_c::~sStateMethod_c() {} + +void sStateMethod_c::initializeStateMethod() { + if (!mpNewStateID->isNull() && !mInitFinalizeLock && !mIsValid) { + mInitFinalizeLock = true; + + mpStateID = mpNewStateID; + int ret = initializeStateLocalMethod(); + if (ret != 0) { + mIsValid = true; + } else { + mIsValid = false; + } + + mInitFinalizeLock = false; + } +} + +void sStateMethod_c::executeStateMethod() { + if (!mExecutionLock) { + int i = 2; + do { + if (mRefreshStateMethod) { + i--; + } + mRefreshStateMethod = false; + // We only want to execute if we have a valid next state + if (!mpNewStateID->isNull()) { + mExecutionLock = true; + executeStateLocalMethod(); + mExecutionLock = false; + } + } while (mRefreshStateMethod && mStateChanged && i); + } +} + +void sStateMethod_c::finalizeStateMethod() { + if (!mpNewStateID->isNull() && mIsValid && !mInitFinalizeLock) { + mInitFinalizeLock = true; + + mpOldStateID = mpStateID; + finalizeStateLocalMethod(); + mIsValid = false; + + mInitFinalizeLock = false; + } +} + +void sStateMethod_c::changeStateMethod(const sStateIDIf_c &newID) { + if (!newID.isNull()) { + mpNewStateID = &newID; + changeStateLocalMethod(newID); + mStateChanged = true; + } +} diff --git a/src/s/s_StateMethodUsr_FI.cpp b/src/s/s_StateMethodUsr_FI.cpp new file mode 100644 index 00000000..cbcb5a54 --- /dev/null +++ b/src/s/s_StateMethodUsr_FI.cpp @@ -0,0 +1,27 @@ +#include +#include + +sStateMethodUsr_FI_c::sStateMethodUsr_FI_c(sStateIDChkIf_c &check, sStateFctIf_c &factory, const sStateIDIf_c &state) : + sStateMethod_c(check, factory, state) { +} + +int sStateMethodUsr_FI_c::initializeStateLocalMethod() { + mpState = mpStateFct.build(*getNewStateID()); // Create new state holder with the next state ID + mpState->initialize(); + return 1; +} + +void sStateMethodUsr_FI_c::executeStateLocalMethod() { + initializeStateMethod(); // Ensure we are in a valid state (this only actually initializes the state if !mIsValid) + mpState->execute(); +} + +void sStateMethodUsr_FI_c::finalizeStateLocalMethod() { + mpState->finalize(); + mpStateFct.dispose(mpState); +} + +void sStateMethodUsr_FI_c::changeStateLocalMethod(const sStateIDIf_c &newID) { + finalizeStateMethod(); // Terminate the current state + initializeStateMethod(); // Initialize the new state +} From 374e93821ed87c05e972f9c0c49424a8cb1cf061 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 31 May 2024 12:00:20 +0200 Subject: [PATCH 02/20] Document, fixup --- config/SOUE01/splits.txt | 3 +++ config/SOUE01/symbols.txt | 4 ++-- configure.py | 1 + include/d/tg/d_t_tumble_weed.h | 4 ++-- include/f/f_list_nd.h | 8 +++++++- include/f/f_manager.h | 1 + include/s/README.txt | 17 +++++++++++++++++ include/s/s_FState.hpp | 3 +++ include/s/s_FStateFct.hpp | 3 +++ include/s/s_FStateID.hpp | 3 +++ include/s/s_FStateMgr.hpp | 3 +++ include/s/s_Phase.hpp | 3 +++ include/s/s_State.hpp | 3 +++ include/s/s_StateID.hpp | 3 +++ include/s/s_StateIDChk.hpp | 3 +++ include/s/s_StateInterfaces.hpp | 3 +++ include/s/s_StateMethod.hpp | 3 +++ include/s/s_StateMethodUsr_FI.hpp | 3 +++ include/s/s_StateMgr.hpp | 3 +++ src/f/f_base.cpp | 5 ++--- src/s/s_Phase.cpp | 3 +++ src/s/s_StateID.cpp | 3 +++ src/s/s_StateMethod.cpp | 4 ++++ src/s/s_StateMethodUsr_FI.cpp | 3 +++ 24 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 include/s/README.txt diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 393ae007..af8e679c 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -212,6 +212,9 @@ s/s_StateMethod.cpp: s/s_StateMethodUsr_FI.cpp: .text start:0x802DE540 end:0x802DE6EC +s/s_Phase.cpp: + .text start:0x802DEEB0 end:0x802DEF74 + DynamicLink.cpp: .text start:0x802DF100 end:0x802DFD74 .data start:0x805419E8 end:0x80541A70 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 2bcfdfc2..0b0428d6 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17221,8 +17221,8 @@ fn_802DED40 = .text:0x802DED40; // type:function size:0x4 fn_802DED50 = .text:0x802DED50; // type:function size:0x50 fn_802DEDA0 = .text:0x802DEDA0; // type:function size:0x64 fn_802DEE10 = .text:0x802DEE10; // type:function size:0x98 -fn_802DEEB0 = .text:0x802DEEB0; // type:function size:0x14 -fn_802DEED0 = .text:0x802DEED0; // type:function size:0xA4 +__ct__8sPhase_cFPPFPv_Q28sPhase_c15METHOD_RESULT_ei = .text:0x802DEEB0; // type:function size:0x14 +callMethod__8sPhase_cFPv = .text:0x802DEED0; // type:function size:0xA4 fn_802DEF80 = .text:0x802DEF80; // type:function size:0x8 fn_802DEF90 = .text:0x802DEF90; // type:function size:0x4C fn_802DEFE0 = .text:0x802DEFE0; // type:function size:0x80 diff --git a/configure.py b/configure.py index 13218904..4ee79aad 100644 --- a/configure.py +++ b/configure.py @@ -314,6 +314,7 @@ config.libs = [ Object(Matching, "s/s_StateId.cpp"), Object(Matching, "s/s_StateMethod.cpp"), Object(Matching, "s/s_StateMethodUsr_FI.cpp"), + Object(Matching, "s/s_Phase.cpp"), Object(Matching, "DynamicLink.cpp"), # framework (f_name) # d stuff (d_name) diff --git a/include/d/tg/d_t_tumble_weed.h b/include/d/tg/d_t_tumble_weed.h index baf61848..e3a80dd4 100644 --- a/include/d/tg/d_t_tumble_weed.h +++ b/include/d/tg/d_t_tumble_weed.h @@ -6,9 +6,9 @@ #include #include -class fLiNdTumbleweed_c : public fLiNdBa_c { +class fLiNdTumbleweed_c : public fLiNdBaAutoUnlink_c { public: - fLiNdTumbleweed_c(fBase_c *owner) : fLiNdBa_c(owner) {} + fLiNdTumbleweed_c(fBase_c *owner) : fLiNdBaAutoUnlink_c(owner) {} u16 someField; }; diff --git a/include/f/f_list_nd.h b/include/f/f_list_nd.h index 6adb8ea6..cc237048 100644 --- a/include/f/f_list_nd.h +++ b/include/f/f_list_nd.h @@ -12,7 +12,7 @@ class fBase_c; class fLiNdBa_c : public cListNd_c { public: fLiNdBa_c(fBase_c *owner) : p_owner(owner) {} - ~fLiNdBa_c() { unlink(); } + ~fLiNdBa_c() {} inline fLiNdBa_c *getPrev() const { return (fLiNdBa_c *)cListNd_c::getPrev(); @@ -28,4 +28,10 @@ public: fBase_c *p_owner; }; +class fLiNdBaAutoUnlink_c : public fLiNdBa_c { +public: + fLiNdBaAutoUnlink_c(fBase_c *owner) : fLiNdBa_c(owner) {} + ~fLiNdBaAutoUnlink_c() { unlink(); } +}; + #endif diff --git a/include/f/f_manager.h b/include/f/f_manager.h index d54f9acf..e2c18609 100644 --- a/include/f/f_manager.h +++ b/include/f/f_manager.h @@ -29,6 +29,7 @@ public: PROC_FLAG_DRAW = GET_PROC_FLAG(DRAW) }; fManager_c(fBase_c *owner) : connect_node(owner), execute_node(owner), draw_node(owner), search_node(owner) {} + ~fManager_c() {} /* 802e28c0 */ int getSearchTableNum(); /* 802e28d0 */ static fBase_c *searchBaseByID(fBaseID_e id); /* 802e2920 */ static fBase_c *searchBaseByProfName(ProfileName profID, const fBase_c *parent); diff --git a/include/s/README.txt b/include/s/README.txt new file mode 100644 index 00000000..99281a97 --- /dev/null +++ b/include/s/README.txt @@ -0,0 +1,17 @@ +This library was ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +with differences/modifications outlined below: + +## No inline destructors + +The NSMBW code uses inlined destructors. In SS, these destructors are all part of the s_StateID.cpp(?) TU, +and pretty much every generic instantiation of the state manager (which for a large part are in RELs) +will call back into those destructors in the main DOL. + +## s_StateIDChk.hpp + +In order for vtable ordering to match, some classes had to be extracted to a new header. + +## sStateMethodIf_c + +S_StateMethod_c's destructors calls back into another destructors. sStateMethodIf_c follows the example of +the other abstract interface classes and provides this dtor. diff --git a/include/s/s_FState.hpp b/include/s/s_FState.hpp index 2772d3dd..a883d6f3 100644 --- a/include/s/s_FState.hpp +++ b/include/s/s_FState.hpp @@ -2,6 +2,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief A state holder for a given class. /// @tparam T The class that this state belongs to. /// @ingroup state diff --git a/include/s/s_FStateFct.hpp b/include/s/s_FStateFct.hpp index 55c1d861..3d349d3e 100644 --- a/include/s/s_FStateFct.hpp +++ b/include/s/s_FStateFct.hpp @@ -3,6 +3,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief A state factory for a given class. /// @tparam T The class that this state belongs to. /// @ingroup state diff --git a/include/s/s_FStateID.hpp b/include/s/s_FStateID.hpp index 1100c54b..7ea2295a 100644 --- a/include/s/s_FStateID.hpp +++ b/include/s/s_FStateID.hpp @@ -2,6 +2,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief An implementation of a state ID for a given class. /// @details It adds the ability to call the three state methods on a state owner class. /// @tparam T The class that this state belongs to. diff --git a/include/s/s_FStateMgr.hpp b/include/s/s_FStateMgr.hpp index be2858c4..f154cbb6 100644 --- a/include/s/s_FStateMgr.hpp +++ b/include/s/s_FStateMgr.hpp @@ -5,6 +5,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief A wrapper for sStateMgr_c that uses sFStateFct_c and sStateIDChk_c. /// @tparam T The class that this state belongs to. /// @tparam Method The method to use for the state manager. diff --git a/include/s/s_Phase.hpp b/include/s/s_Phase.hpp index d21b2f80..4b3d6403 100644 --- a/include/s/s_Phase.hpp +++ b/include/s/s_Phase.hpp @@ -1,5 +1,8 @@ #pragma once +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief A phase is a list of methods to be called in order. /// @ingroup slib dol class sPhase_c { diff --git a/include/s/s_State.hpp b/include/s/s_State.hpp index 1df9c01f..8a7079f9 100644 --- a/include/s/s_State.hpp +++ b/include/s/s_State.hpp @@ -2,6 +2,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + #define STATE_FUNC_DECLARE(class, name) void initializeState_##name(); \ void executeState_##name(); \ void finalizeState_##name(); \ diff --git a/include/s/s_StateID.hpp b/include/s/s_StateID.hpp index cbfaab57..e74d155e 100644 --- a/include/s/s_StateID.hpp +++ b/include/s/s_StateID.hpp @@ -1,6 +1,9 @@ #pragma once #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief A generic implementation of a state ID. /// @details It simply contains a name string and a unique number. /// @ingroup state diff --git a/include/s/s_StateIDChk.hpp b/include/s/s_StateIDChk.hpp index 41d99213..c808ad8b 100644 --- a/include/s/s_StateIDChk.hpp +++ b/include/s/s_StateIDChk.hpp @@ -1,6 +1,9 @@ #pragma once #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief A default implementation of a state ID checker. /// @details ::isNormalID always returns true. class sStateIDChk_c : public sStateIDChkIf_c { diff --git a/include/s/s_StateInterfaces.hpp b/include/s/s_StateInterfaces.hpp index cb624230..0acd6f80 100644 --- a/include/s/s_StateInterfaces.hpp +++ b/include/s/s_StateInterfaces.hpp @@ -1,5 +1,8 @@ #pragma once +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @addtogroup state /// @{ diff --git a/include/s/s_StateMethod.hpp b/include/s/s_StateMethod.hpp index 8dadaa9e..4feb0c6a 100644 --- a/include/s/s_StateMethod.hpp +++ b/include/s/s_StateMethod.hpp @@ -1,6 +1,9 @@ #pragma once #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief A class that handles state execution and transition. /// @details [Presumably, sStateMethod_c actually means "methods for state interaction", or something like that]. /// @ingroup state diff --git a/include/s/s_StateMethodUsr_FI.hpp b/include/s/s_StateMethodUsr_FI.hpp index 0921f336..8104557f 100644 --- a/include/s/s_StateMethodUsr_FI.hpp +++ b/include/s/s_StateMethodUsr_FI.hpp @@ -1,6 +1,9 @@ #pragma once #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief An extension to sStateMethod_c that implements the remaining abstract methods. /// @details [Name might mean "Functionality implementation"]. /// @ingroup state diff --git a/include/s/s_StateMgr.hpp b/include/s/s_StateMgr.hpp index 3fe4c74c..66d07020 100644 --- a/include/s/s_StateMgr.hpp +++ b/include/s/s_StateMgr.hpp @@ -1,6 +1,9 @@ #pragma once #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /** * @brief An implementation of sStateMgrIf_c. * diff --git a/src/f/f_base.cpp b/src/f/f_base.cpp index 661ec622..640f83e2 100644 --- a/src/f/f_base.cpp +++ b/src/f/f_base.cpp @@ -24,7 +24,6 @@ void (*fBase_c::sUnloadCallback)(); fBase_c::fBase_c() : unique_ID(m_rootUniqueID), params(m_tmpCtData.params), profile_name(m_tmpCtData.prof_name), group_type(m_tmpCtData.group_type), manager(this) { - fManager_c *mgr = &manager; m_rootUniqueID = (fBaseID_e)(m_rootUniqueID + 1); if (m_rootUniqueID == INVALID) { @@ -33,8 +32,8 @@ fBase_c::fBase_c() } } - fManager_c::m_connectManage.addTreeNode(&mgr->connect_node, m_tmpCtData.connect_parent); - int searchTableIdx = mgr->getSearchTableNum(); + fManager_c::m_connectManage.addTreeNode(&manager.connect_node, m_tmpCtData.connect_parent); + int searchTableIdx = manager.getSearchTableNum(); fManager_c::m_searchManage[searchTableIdx].prepend(&manager.search_node); const fProfile::fBaseProfile_c *profile = (*fProfile::sProfileList)[profile_name]; diff --git a/src/s/s_Phase.cpp b/src/s/s_Phase.cpp index 9418fbe9..734bb35e 100644 --- a/src/s/s_Phase.cpp +++ b/src/s/s_Phase.cpp @@ -1,5 +1,8 @@ #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + sPhase_c::sPhase_c(phaseMethod **methodList, int count) { mpMethodList = methodList; mPhaseLength = count; diff --git a/src/s/s_StateID.cpp b/src/s/s_StateID.cpp index 548a01e7..bf9100ec 100644 --- a/src/s/s_StateID.cpp +++ b/src/s/s_StateID.cpp @@ -4,6 +4,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + sStateID_c::NumberMemo_c sStateID_c::sm_numberMemo; sStateID_c sStateID::null(nullptr); diff --git a/src/s/s_StateMethod.cpp b/src/s/s_StateMethod.cpp index fec04f78..7c59854f 100644 --- a/src/s/s_StateMethod.cpp +++ b/src/s/s_StateMethod.cpp @@ -3,6 +3,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + sStateMethod_c::sStateMethod_c(sStateIDChkIf_c &checker, sStateFctIf_c &factory, const sStateIDIf_c &initialState) : mpStateChk(checker), mpStateFct(factory), @@ -37,6 +40,7 @@ void sStateMethod_c::initializeStateMethod() { void sStateMethod_c::executeStateMethod() { if (!mExecutionLock) { + // Skyward Sword change: Prevent runaway state changes? int i = 2; do { if (mRefreshStateMethod) { diff --git a/src/s/s_StateMethodUsr_FI.cpp b/src/s/s_StateMethodUsr_FI.cpp index cbcb5a54..9e42fc58 100644 --- a/src/s/s_StateMethodUsr_FI.cpp +++ b/src/s/s_StateMethodUsr_FI.cpp @@ -1,6 +1,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + sStateMethodUsr_FI_c::sStateMethodUsr_FI_c(sStateIDChkIf_c &check, sStateFctIf_c &factory, const sStateIDIf_c &state) : sStateMethod_c(check, factory, state) { } From 8ecaacda93da648ddc8413a77e60ca1fe32d87ee Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 1 Jun 2024 23:57:11 +0200 Subject: [PATCH 03/20] Documentation, header guards --- include/s/README.txt | 3 ++- include/s/docgroup.h | 6 +++++- include/s/s_FState.hpp | 6 +++++- include/s/s_FStateFct.hpp | 6 +++++- include/s/s_FStateID.hpp | 6 +++++- include/s/s_FStateMgr.hpp | 6 +++++- include/s/s_Phase.hpp | 5 ++++- include/s/s_State.hpp | 6 +++++- include/s/s_StateID.hpp | 6 +++++- include/s/s_StateIDChk.hpp | 6 +++++- include/s/s_StateInterfaces.hpp | 5 ++++- include/s/s_StateMethod.hpp | 6 +++++- include/s/s_StateMethodUsr_FI.hpp | 6 +++++- include/s/s_StateMgr.hpp | 6 +++++- 14 files changed, 65 insertions(+), 14 deletions(-) diff --git a/include/s/README.txt b/include/s/README.txt index 99281a97..5be519ee 100644 --- a/include/s/README.txt +++ b/include/s/README.txt @@ -5,7 +5,8 @@ with differences/modifications outlined below: The NSMBW code uses inlined destructors. In SS, these destructors are all part of the s_StateID.cpp(?) TU, and pretty much every generic instantiation of the state manager (which for a large part are in RELs) -will call back into those destructors in the main DOL. +will call back into those destructors in the main DOL. As a result, the destructors were made not inline +and explicitly instantiated in s_StateID.cpp ## s_StateIDChk.hpp diff --git a/include/s/docgroup.h b/include/s/docgroup.h index a99aa2fb..43c81fd9 100644 --- a/include/s/docgroup.h +++ b/include/s/docgroup.h @@ -1,4 +1,6 @@ -#pragma once +#ifndef S_DOCGROUP_H +#define S_DOCGROUP_H + // [This header file defines documentation groups for better categorization] /// @ingroup game @@ -8,3 +10,5 @@ /// @defgroup state sState /// @ingroup slib /// @brief A state system implementation. + +#endif diff --git a/include/s/s_FState.hpp b/include/s/s_FState.hpp index a883d6f3..5ce14991 100644 --- a/include/s/s_FState.hpp +++ b/include/s/s_FState.hpp @@ -1,4 +1,6 @@ -#pragma once +#ifndef S_FSTATE_H +#define S_FSTATE_H + #include #include @@ -42,3 +44,5 @@ private: T &mpOwner; ///< The owner of this state. const sFStateID_c *mpID; ///< The state ID that runs the state methods. }; + +#endif diff --git a/include/s/s_FStateFct.hpp b/include/s/s_FStateFct.hpp index 3d349d3e..cb488d2d 100644 --- a/include/s/s_FStateFct.hpp +++ b/include/s/s_FStateFct.hpp @@ -1,4 +1,6 @@ -#pragma once +#ifndef S_FSTATEFCT_H +#define S_FSTATEFCT_H + #include #include #include @@ -27,3 +29,5 @@ public: private: sFState_c mState; }; + +#endif diff --git a/include/s/s_FStateID.hpp b/include/s/s_FStateID.hpp index 7ea2295a..5fd05476 100644 --- a/include/s/s_FStateID.hpp +++ b/include/s/s_FStateID.hpp @@ -1,4 +1,6 @@ -#pragma once +#ifndef S_FSTATEID_H +#define S_FSTATEID_H + #include #include @@ -59,3 +61,5 @@ private: stateFunc mpExecute; ///< The execute method for this state ID. stateFunc mpFinalize; ///< The finalize method for this state ID. }; + +#endif diff --git a/include/s/s_FStateMgr.hpp b/include/s/s_FStateMgr.hpp index f154cbb6..a001ffea 100644 --- a/include/s/s_FStateMgr.hpp +++ b/include/s/s_FStateMgr.hpp @@ -1,4 +1,6 @@ -#pragma once +#ifndef S_FSTATEMGR_H +#define S_FSTATEMGR_H + #include #include #include @@ -18,3 +20,5 @@ public: sFStateMgr_c(T &owner, const sStateIDIf_c &initializeState) : sStateMgr_c(owner, initializeState) {} }; + +#endif diff --git a/include/s/s_Phase.hpp b/include/s/s_Phase.hpp index 4b3d6403..596484b6 100644 --- a/include/s/s_Phase.hpp +++ b/include/s/s_Phase.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef S_PHASE_H +#define S_PHASE_H // Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib // See include/s/README.txt for changes made @@ -35,3 +36,5 @@ public: unsigned short mPhaseLength; ///< The length of the method list. unsigned short mCurrMethod; ///< The index of the method to execute. }; + +#endif diff --git a/include/s/s_State.hpp b/include/s/s_State.hpp index 8a7079f9..97a5847e 100644 --- a/include/s/s_State.hpp +++ b/include/s/s_State.hpp @@ -1,4 +1,6 @@ -#pragma once +#ifndef S_STATE_H +#define S_STATE_H + #include #include @@ -15,3 +17,5 @@ &class::initializeState_##name, \ &class::executeState_##name, \ &class::finalizeState_##name) + +#endif diff --git a/include/s/s_StateID.hpp b/include/s/s_StateID.hpp index e74d155e..422d9143 100644 --- a/include/s/s_StateID.hpp +++ b/include/s/s_StateID.hpp @@ -1,4 +1,6 @@ -#pragma once +#ifndef S_STATEID_H +#define S_STATEID_H + #include // Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib @@ -44,3 +46,5 @@ namespace sStateID { /// @ingroup state extern sStateID_c null; ///< A null state instance. } + +#endif diff --git a/include/s/s_StateIDChk.hpp b/include/s/s_StateIDChk.hpp index c808ad8b..5237cbaf 100644 --- a/include/s/s_StateIDChk.hpp +++ b/include/s/s_StateIDChk.hpp @@ -1,4 +1,6 @@ -#pragma once +#ifndef S_STATEIDCHK_H +#define S_STATEIDCHK_H + #include // Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib @@ -11,3 +13,5 @@ public: virtual ~sStateIDChk_c(); virtual bool isNormalID(const sStateIDIf_c &) const { return true; } }; + +#endif diff --git a/include/s/s_StateInterfaces.hpp b/include/s/s_StateInterfaces.hpp index 0acd6f80..8e28f44c 100644 --- a/include/s/s_StateInterfaces.hpp +++ b/include/s/s_StateInterfaces.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef S_STATEINTERFACES_H +#define S_STATEINTERFACES_H // Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib // See include/s/README.txt for changes made @@ -74,3 +75,5 @@ public: }; /// @} + +#endif diff --git a/include/s/s_StateMethod.hpp b/include/s/s_StateMethod.hpp index 4feb0c6a..4d7b630d 100644 --- a/include/s/s_StateMethod.hpp +++ b/include/s/s_StateMethod.hpp @@ -1,4 +1,6 @@ -#pragma once +#ifndef S_STATEMETHOD_H +#define S_STATEMETHOD_H + #include // Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib @@ -50,3 +52,5 @@ protected: sStateIf_c *mpState; ///< The current state holder. }; + +#endif diff --git a/include/s/s_StateMethodUsr_FI.hpp b/include/s/s_StateMethodUsr_FI.hpp index 8104557f..a18516df 100644 --- a/include/s/s_StateMethodUsr_FI.hpp +++ b/include/s/s_StateMethodUsr_FI.hpp @@ -1,4 +1,6 @@ -#pragma once +#ifndef S_STATEMETHODUSR_FI_H +#define S_STATEMETHODUSR_FI_H + #include // Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib @@ -17,3 +19,5 @@ public: virtual void finalizeStateLocalMethod(); virtual void changeStateLocalMethod(const sStateIDIf_c &newStateID); }; + +#endif diff --git a/include/s/s_StateMgr.hpp b/include/s/s_StateMgr.hpp index 66d07020..c043eb71 100644 --- a/include/s/s_StateMgr.hpp +++ b/include/s/s_StateMgr.hpp @@ -1,4 +1,6 @@ -#pragma once +#ifndef S_STATEMGR_H +#define S_STATEMGR_H + #include // Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib @@ -38,3 +40,5 @@ private: Factory mFactory; Method mMethod; }; + +#endif From 6da4bb94c539f71ee3ef4c5d79c789127b70ddaf Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 25 May 2024 19:30:32 +0200 Subject: [PATCH 04/20] d_rawarchive mostly matching --- config/SOUE01/splits.txt | 1 + config/SOUE01/symbols.txt | 64 ++--- configure.py | 1 + include/d/d_rawarchive.h | 104 ++++++++ include/egg/core/eggArchive.h | 2 +- include/m/m_heap.h | 2 +- include/rvl/ARC/arc.h | 6 +- include/toBeSorted/arc_manager.h | 37 --- src/d/d_rawarchive.cpp | 430 +++++++++++++++++++++++++++++++ src/m/m_heap.cpp | 2 +- 10 files changed, 574 insertions(+), 75 deletions(-) create mode 100644 include/d/d_rawarchive.h delete mode 100644 include/toBeSorted/arc_manager.h create mode 100644 src/d/d_rawarchive.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 8428ae57..d9385aba 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -107,6 +107,7 @@ d/d_player.cpp: d/d_rawarchive.cpp: .text start:0x80061B10 end:0x800629D0 + .data start:0x8050DDD8 end:0x8050DDF8 d/d_scene.cpp: .text start:0x800629D0 end:0x80062E40 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 0570fe6b..d978003d 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -2741,35 +2741,35 @@ fn_80061AB0 = .text:0x80061AB0; // type:function size:0x5C fn_80061B10 = .text:0x80061B10; // type:function size:0x88 fn_80061BA0 = .text:0x80061BA0; // type:function size:0x34 fn_80061BE0 = .text:0x80061BE0; // type:function size:0x10 -fn_80061BF0 = .text:0x80061BF0; // type:function size:0x28 -fn_80061C20 = .text:0x80061C20; // type:function size:0x80 -fn_80061CA0 = .text:0x80061CA0; // type:function size:0xA0 -fn_80061D40 = .text:0x80061D40; // type:function size:0x8 -fn_80061D50 = .text:0x80061D50; // type:function size:0x8 -fn_80061D60 = .text:0x80061D60; // type:function size:0x104 -fn_80061E70 = .text:0x80061E70; // type:function size:0x74 -fn_80061EF0 = .text:0x80061EF0; // type:function size:0xD0 -fn_80061FC0 = .text:0x80061FC0; // type:function size:0x34 -fn_80062000 = .text:0x80062000; // type:function size:0x9C -fn_800620A0 = .text:0x800620A0; // type:function size:0x104 -fn_800621B0 = .text:0x800621B0; // type:function size:0x14C -fn_80062300 = .text:0x80062300; // type:function size:0x5C -fn_80062360 = .text:0x80062360; // type:function size:0x14 -fn_80062380 = .text:0x80062380; // type:function size:0x74 -fn_80062400 = .text:0x80062400; // type:function size:0x90 -fn_80062490 = .text:0x80062490; // type:function size:0xAC -fn_80062540 = .text:0x80062540; // type:function size:0xB0 -fn_800625F0 = .text:0x800625F0; // type:function size:0x44 -fn_80062640 = .text:0x80062640; // type:function size:0x44 -fn_80062690 = .text:0x80062690; // type:function size:0x2C -fn_800626C0 = .text:0x800626C0; // type:function size:0x5C -fn_80062720 = .text:0x80062720; // type:function size:0x60 -fn_80062780 = .text:0x80062780; // type:function size:0x80 -fn_80062800 = .text:0x80062800; // type:function size:0x34 -fn_80062840 = .text:0x80062840; // type:function size:0x80 -fn_800628C0 = .text:0x800628C0; // type:function size:0x90 -fn_80062950 = .text:0x80062950; // type:function size:0x34 -fn_80062990 = .text:0x80062990; // type:function size:0x40 +__ct__14dRawArcEntry_cFv = .text:0x80061BF0; // type:function size:0x28 +__dt__14dRawArcEntry_cFv = .text:0x80061C20; // type:function size:0x80 +searchCallback__14dRawArcEntry_cFPvPvPC11ARCDirEntryPCcb = .text:0x80061CA0; // type:function size:0xA0 +searchCallback1__14dRawArcEntry_cFPvPvPC11ARCDirEntryPCc = .text:0x80061D40; // type:function size:0x8 +searchCallback2__14dRawArcEntry_cFPvPvPC11ARCDirEntryPCc = .text:0x80061D50; // type:function size:0x8 +destroy__14dRawArcEntry_cFPv = .text:0x80061D60; // type:function size:0x104 +loadArcFromDiskChecked__14dRawArcEntry_cFPCcPCcUcPQ23EGG4Heap = .text:0x80061E70; // type:function size:0x74 +loadArcFromDisk__14dRawArcEntry_cFPCcPCcUcPQ23EGG4Heap = .text:0x80061EF0; // type:function size:0xD0 +checkArcExistsOnDisk__14dRawArcEntry_cFPCcPCc = .text:0x80061FC0; // type:function size:0x34 +checkArcExistsOnDiskInner__14dRawArcEntry_cFPcPCcPCc = .text:0x80062000; // type:function size:0x9C +mount__14dRawArcEntry_cFPCcPvPvUcPQ23EGG4Heap = .text:0x800620A0; // type:function size:0x104 +ensureLoadedMaybe__14dRawArcEntry_cFPv = .text:0x800621B0; // type:function size:0x14C +onMount__14dRawArcEntry_cFPv = .text:0x80062300; // type:function size:0x5C +__ct__14dRawArcTable_cFv = .text:0x80062360; // type:function size:0x14 +__dt__14dRawArcTable_cFv = .text:0x80062380; // type:function size:0x74 +init__14dRawArcTable_cFUsPvPQ23EGG4Heap = .text:0x80062400; // type:function size:0x90 +getArcOrLoadFromDisk__14dRawArcTable_cFPCcPCcUcPQ23EGG4Heap = .text:0x80062490; // type:function size:0xAC +addEntryFromSuperArc__14dRawArcTable_cFPCcPvUcPQ23EGG4Heap = .text:0x80062540; // type:function size:0xB0 +ensureLoadedMaybe2__14dRawArcTable_cFPCc = .text:0x800625F0; // type:function size:0x44 +ensureLoadedMaybe__14dRawArcTable_cFPCc = .text:0x80062640; // type:function size:0x44 +hasEntry__14dRawArcTable_cFPCc = .text:0x80062690; // type:function size:0x2C +decreaseRefCount__14dRawArcTable_cFPCc = .text:0x800626C0; // type:function size:0x5C +getDataFromOarc__14dRawArcTable_cFPCcPCc = .text:0x80062720; // type:function size:0x60 +getSubEntryData__14dRawArcTable_cFPCcPCc = .text:0x80062780; // type:function size:0x80 +getLoadedArcData__14dRawArcTable_cFPCc = .text:0x80062800; // type:function size:0x34 +ensureAllEntriesLoaded__14dRawArcTable_cFv = .text:0x80062840; // type:function size:0x80 +findEntry__14dRawArcTable_cCFPCc = .text:0x800628C0; // type:function size:0x90 +findEmptySlot__14dRawArcTable_cFv = .text:0x80062950; // type:function size:0x34 +findLoadedEntry__14dRawArcTable_cFPCc = .text:0x80062990; // type:function size:0x40 fn_800629D0 = .text:0x800629D0; // type:function size:0x60 fn_80062A30 = .text:0x80062A30; // type:function size:0x50 fn_80062A80 = .text:0x80062A80; // type:function size:0x58 @@ -26141,7 +26141,7 @@ getFileFast__Q23EGG7ArchiveFlPQ23EGG4Heapl = .text:0x80493DC0; // type:function countFileCallbackFunc__3EGGFPvPvUlPC11ARCDirEntryPCc = .text:0x80493F10; // type:function size:0x18 countFile__Q23EGG7ArchiveFv = .text:0x80493F30; // type:function size:0x38 searchInsideWithPath__3EGGFPQ23EGG7ArchiveP9ARCHandlePFPvPvUlPC11ARCDirEntryPCc_vPvPcUl = .text:0x80493F70; // type:function size:0x144 -searchInside__Q23EGG7ArchiveFPFPvPvUlPC11ARCDirEntryPCc_vPv = .text:0x804940C0; // type:function size:0x74 +searchInside__Q23EGG7ArchiveFPFPvPvPC11ARCDirEntryPCc_vPv = .text:0x804940C0; // type:function size:0x74 loadFromDisc__EGG__Archive = .text:0x80494140; // type:function size:0x114 initialize__Q23EGG7DvdFileFv = .text:0x80494260; // type:function size:0x40 __ct__Q23EGG7DvdFileFv = .text:0x804942A0; // type:function size:0x44 @@ -27385,11 +27385,11 @@ strlen = .text:0x804C64DC; // type:function size:0x1C scope:weak __va_arg = .text:0x804C64F8; // type:function size:0xC8 scope:global __register_global_object = .text:0x804C65C0; // type:function size:0x18 scope:global __destroy_global_chain = .text:0x804C65D8; // type:function size:0x48 scope:global -fn_804C6620 = .text:0x804C6620; // type:function size:0x104 +__construct_new_array = .text:0x804C6620; // type:function size:0x104 fn_804C6724 = .text:0x804C6724; // type:function size:0xBC __construct_array = .text:0x804C67E0; // type:function size:0xF8 __destroy_arr = .text:0x804C68D8; // type:function size:0x78 -fn_804C6950 = .text:0x804C6950; // type:function size:0x80 +__destroy_new_array = .text:0x804C6950; // type:function size:0x80 __ptmf_test = .text:0x804C69D0; // type:function size:0x30 fn_804C6A00 = .text:0x804C6A00; // type:function size:0x3C __ptmf_scall = .text:0x804C6A3C; // type:function size:0x28 diff --git a/configure.py b/configure.py index 7782d9dd..7abf0df5 100644 --- a/configure.py +++ b/configure.py @@ -287,6 +287,7 @@ config.libs = [ Object(NonMatching, "d/d_dvd_unk.cpp"), Object(NonMatching, "d/d_dylink.cpp"), Object(NonMatching, "d/d_heap.cpp"), + Object(NonMatching, "d/d_rawarchive.cpp"), Object(NonMatching, "d/d_stage.cpp"), Object(NonMatching, "d/d_sys.cpp"), Object(NonMatching, "d/a/d_a_base.cpp"), diff --git a/include/d/d_rawarchive.h b/include/d/d_rawarchive.h new file mode 100644 index 00000000..7432f3f3 --- /dev/null +++ b/include/d/d_rawarchive.h @@ -0,0 +1,104 @@ +#ifndef D_RAWARCHIVE_H +#define D_RAWARCHIVE_H + +#include +#include + +// TODO: loading status could be an enum (-2/-1/0/+1) + +// Ghidra: ArcManagerEntry +// size: 0x40 +class dRawArcEntry_c { +public: + dRawArcEntry_c(); + ~dRawArcEntry_c(); + + bool destroy(void *arg); + bool loadArcFromDiskChecked(const char *fileName, const char *dirName, u8 mountDirection, EGG::Heap *heap); + bool loadArcFromDisk(const char *fileName, const char *dirName, u8 mountDirection, EGG::Heap *heap); + static bool checkArcExistsOnDisk(const char *fileName, const char *dirName); + static bool checkArcExistsOnDiskInner(char *outBuf, const char *fileName, const char *dirName); + + int mount(const char *name, void *data, void *callbackArg, u8 mountDirection, EGG::Heap *heap); + int onMount(void *callbackArg); + + int ensureLoadedMaybe(void *callbackArg); + + inline bool isReferenced() { + return mRefCount != 0; + } + + inline const char *name() { + return mArcName; + } + + inline bool isNotLoaded() { + return mpArc == nullptr; + } + + inline bool isLoading() { + return mpDvdReq != nullptr; + } + + inline void increaseRefCount() { + mRefCount++; + } + + inline void decreaseRefCount() { + mRefCount--; + } + + inline void *getData() { + return mpData; + } + + inline EGG::Archive *getArc() { + return mpArc; + } + +private: + static void searchCallback(void *, void *, const ARCDirEntry *, const char *, bool); + static void searchCallback1(void *, void *, const ARCDirEntry *, const char *); + static void searchCallback2(void *, void *, const ARCDirEntry *, const char *); + +private: + /* 0x00 */ char mArcName[0x20]; + /* 0x20 */ u16 mRefCount; + /* 0x24 */ mDvd_mountMemArchive_c *mpDvdReq; + /* 0x28 */ EGG::Archive *mpArc; + /* 0x2C */ EGG::Heap *mpCommandHeap; + /* 0x30 */ void *mpData; + /* 0x34 */ u32 mAmountRead; + /* 0x38 */ u32 mChecksum; + /* 0x3C */ EGG::FrmHeap *mpFrmHeap; +}; + +// Ghidra: ArcManagerEntryTable +// size: 0xC +class dRawArcTable_c { +public: + dRawArcTable_c(); + ~dRawArcTable_c(); + + bool init(u16 count, void *callbackArg, EGG::Heap *heap); + bool getArcOrLoadFromDisk(const char *name, const char *dirName, u8 mountDirection, EGG::Heap *heap); + bool addEntryFromSuperArc(const char *name, void *data, u8 mountDirection, EGG::Heap *heap); + int ensureLoadedMaybe2(const char *name); + int ensureLoadedMaybe(const char *name); + bool hasEntry(const char *name); + bool decreaseRefCount(const char *name); + void *getDataFromOarc(const char *name, const char *path); + void *getSubEntryData(const char *name, const char *path); + void *getLoadedArcData(const char *name); + int ensureAllEntriesLoaded(); + dRawArcEntry_c *findEntry(const char *name) const; + dRawArcEntry_c *findEmptySlot(); + dRawArcEntry_c *findLoadedEntry(const char *name); + +private: + /* 0x0 */ dRawArcEntry_c *mpEntries; + /* 0x4 */ u16 mCount; + /* 0x8 */ void *mCallbackArg; +}; + +#endif; diff --git a/include/egg/core/eggArchive.h b/include/egg/core/eggArchive.h index 72f2ec97..506362d8 100644 --- a/include/egg/core/eggArchive.h +++ b/include/egg/core/eggArchive.h @@ -45,7 +45,7 @@ public: /* 80493a40 */ static Archive *mountNandFile(NANDFileInfo *, Heap *heap, s32 align); /* 80493ac0 */ static Archive *loadFST(const char *fileName, Heap *heap, s32 align); /* 80493b80 */ void unmount(); - /* 80493c20 */ u32 getFile(const char *name, FileInfo *out); + /* 80493c20 */ void *getFile(const char *name, FileInfo *out); /* 80493cf0 */ s32 convertPathToEntryID(const char *path); /* 80493d00 */ void *getFileFast(s32 entryId, FileInfo *fileinfo); /* 80493dc0 */ void *getFileFast(s32 entryId, Heap *heap, s32 align); diff --git a/include/m/m_heap.h b/include/m/m_heap.h index c6681bb6..05cc8308 100644 --- a/include/m/m_heap.h +++ b/include/m/m_heap.h @@ -44,7 +44,7 @@ public: /* 802f1590 */ static void createCommandHeap(size_t size, EGG::Heap *parentHeap); /* 802f15c0 */ static void createDylinkHeap(size_t size, EGG::Heap *parentHeap); /* 802f15f0 */ static EGG::AssertHeap *createAssertHeap(EGG::Heap *parentHeap); - /* 802f1640 */ static EGG::Heap *makeHeapOnCurrentGameHeap(size_t size, const char *name, u32 align, u32 flags); + /* 802f1640 */ static EGG::FrmHeap *makeHeapOnCurrentGameHeap(size_t size, const char *name, u32 align, u32 flags); static int getDefaultGameHeapId(); diff --git a/include/rvl/ARC/arc.h b/include/rvl/ARC/arc.h index 33096322..1731aba5 100644 --- a/include/rvl/ARC/arc.h +++ b/include/rvl/ARC/arc.h @@ -74,9 +74,9 @@ typedef struct ARCEntry { typedef struct ARCDirEntry { ARCHandle *handle; // at 0x0 - u32 path_begin; // at 0x4 - u32 path_it; // at 0x8 - u32 path_end; // at 0xC + u32 entryNum; // at 0x4 + u32 isDir; // at 0x8 + const char *name; // at 0xC } ARCDirEntry; BOOL ARCGetCurrentDir(ARCHandle *handle, char *string, u32 maxlen); diff --git a/include/toBeSorted/arc_manager.h b/include/toBeSorted/arc_manager.h deleted file mode 100644 index 1c7615a3..00000000 --- a/include/toBeSorted/arc_manager.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef ARC_MANAGER_H -#define ARC_MANAGER_H - -#include - -// Ghidra: ArcManagerEntry -// size: 0x40 -struct ArcManagerEntry { - /* 0x00 */ char arc_name[0x20]; - /* 0x20 */ u16 ref_count; - /* 0x24 */ int dvd_req_ptr; - /* 0x28 */ int archive_ptr; - /* 0x2C */ int heap_ptr_0; - /* 0x30 */ char field_0x30[0x3C - 0x30]; - /* 0x3C */ int heap_ptr_1; -}; - -// Ghidra: ArcManagerEntryTable -// size: 0xC -class ArcMangerEntryTable { -public: - /* 0x0 */ ArcManagerEntry *entries; - /* 0x4 */ u16 count; - /* 0x8 */ u32 field_0x8; - -public: - ArcMangerEntryTable(); -}; - -class OarcManager { -public: - void *getDataFromOarc(char *oarcName, char *fileName); -}; - -OarcManager g_OarcManager; - -#endif; diff --git a/src/d/d_rawarchive.cpp b/src/d/d_rawarchive.cpp new file mode 100644 index 00000000..db540865 --- /dev/null +++ b/src/d/d_rawarchive.cpp @@ -0,0 +1,430 @@ +#include +#include +// clang-format off +#include +// clang-format on + + +class UnkManager { +public: + /* vtable at 8050df50 */ + /** 800651c0 */ + virtual void CreateArc(void *data, const char *path); + /** 800653d0 */ + virtual void DestroyArc(const char *path); + + u32 stage; +}; + +extern "C" int fn_80061B10(void *d, u32 len) { + u32 *data = (u32*)d; + u32 result = 0; + // Compiler will unroll this loop + for (u32 len_words = len / 4; len_words != 0; len_words--) { + result += *data++; + } + return result; +} + +extern "C" int fn_80061BA0(void *data, u32 len) { + int result = fn_80061B10(data, len); + return result != 0 ? result : -1; +} + +extern "C" void fn_80061BE0(UnkManager *mgr, const char *name, size_t len) { + // Sets stage to all spaces + mgr->stage = 0x20202020; + // copies the stage name? + memcpy((char*)&mgr->stage, name, len); +} + +dRawArcEntry_c::dRawArcEntry_c() { + mArcName[0] = '\0'; + mRefCount = 0; + mpDvdReq = nullptr; + mpArc = nullptr; + mpCommandHeap = nullptr; + mpData = nullptr; + mChecksum = 0; + mpFrmHeap = 0; +} + +dRawArcEntry_c::~dRawArcEntry_c() { + // Wait for request to complete before destroying + if (mpDvdReq->mStatus == 0) { + do { + VIWaitForRetrace(); + } while (mpDvdReq->mStatus == 0); + } + destroy(nullptr); +} + + +void dRawArcEntry_c::searchCallback(void *arg, void *data, const ARCDirEntry *entry, const char *path, bool ctrl) { + UnkManager *mgr = (UnkManager *)arg; + if (entry->isDir) { + int len = strlen(entry->name); + fn_80061BE0(mgr, entry->name, len <= 4 ? len : 4); + } else { + // dolphin: arg vtable at 8050df50 + // any others? + if (ctrl) { + mgr->CreateArc(data, path); + // branch to 800651c0, sets up room + } else { + mgr->DestroyArc(path); + // branch to 800653d0, destroys room + } + } +} + +void dRawArcEntry_c::searchCallback1(void *a, void *b, const ARCDirEntry *c, const char *d) { + searchCallback(a, b, c, d, true); +} + +void dRawArcEntry_c::searchCallback2(void *a, void *b, const ARCDirEntry *c, const char *d) { + searchCallback(a, b, c, d, false); +} + + +bool dRawArcEntry_c::destroy(void *arg) { + if (mpDvdReq != nullptr) { + if (mpDvdReq->mStatus == 0) { + // Can't destroy if the request is still ongoing + return false; + } + mpArc = mpDvdReq->mDataPtr; + mpData = mpDvdReq->getArcBinary(); + mAmountRead = mpDvdReq->mAmountRead; + mpCommandHeap = mpDvdReq->mHeap; + mpDvdReq->do_delete(); + mpDvdReq = nullptr; + } + + if (mpArc != nullptr) { + if (arg != nullptr) { + mpArc->searchInside(searchCallback2, arg); + } + + if (mpFrmHeap != nullptr) { + mHeap::destroyFrmHeap(mpFrmHeap); + mpFrmHeap = nullptr; + } + mpArc->unmount(); + mpArc = nullptr; + } + + if (mpData != nullptr) { + EGG::Heap::free(mpData, nullptr); + mpData = nullptr; + } + + mAmountRead = 0; + mChecksum = 0; + mpCommandHeap = 0; + return true; +} + +bool dRawArcEntry_c::loadArcFromDiskChecked(const char *fileName, const char *dirName, u8 mountDirection, + EGG::Heap *heap) { + char arcPath[128]; + arcPath[0] = '\0'; + + if (checkArcExistsOnDiskInner(arcPath, fileName, dirName)) { + return loadArcFromDisk(fileName, arcPath, mountDirection, heap); + } + return false; +} + +// Regswap +inline void inline_strncat(char *dest, const char *src, size_t destSize) { + if (src != nullptr) { + size_t destLen = strlen(dest); + size_t srcLen = strlen(src); + size_t count = destLen + srcLen + 1 >= destSize ? destSize - destLen - 1 : srcLen; + strncpy(dest + destLen, src, count); + size_t offset = destLen + count; + dest[offset] = '\0'; + } +} + +inline void inline_strncpy(char *dest, const char *src, size_t destSize) { + if (src != dest) { + dest[0] = '\0'; + inline_strncat(dest, src, destSize); + } +} + +bool dRawArcEntry_c::loadArcFromDisk(const char *arcName, const char *arcPath, u8 mountDirection, EGG::Heap *heap) { + mpDvdReq = mDvd_mountMemArchive_c::create(arcPath, mountDirection, heap); + if (mpDvdReq == nullptr) { + return false; + } + inline_strncpy(mArcName, arcName, sizeof(mArcName)); + return true; +} + +bool dRawArcEntry_c::checkArcExistsOnDisk(const char *fileName, const char *dirName) { + char path[128]; + path[0] = '\0'; + return checkArcExistsOnDiskInner(path, fileName, dirName); +} + +// sprintf2 +extern "C" void fn_8003D650(char *out, const char *fmt, ...); + +bool dRawArcEntry_c::checkArcExistsOnDiskInner(char *outBuf, const char *fileName, const char *dirName) { + fn_8003D650(outBuf, "/US/%s/%s.arc", dirName, fileName); + if (!mDvd::IsExistPath(outBuf)) { + fn_8003D650(outBuf, "/%s/%s.arc", dirName, fileName); + if (!mDvd::IsExistPath(outBuf)) { + return false; + } + } + return true; +} + +int dRawArcEntry_c::mount(const char *name, void *data, void *callbackArg, u8 mountDirection, EGG::Heap *heap) { + inline_strncpy(mArcName, name, sizeof(mArcName)); + // TODO this conditional uses a few more instructions in the original binary + mpArc = EGG::Archive::mount(data, heap, mountDirection != 1 ? 4 : -4); + if (mpArc == nullptr) { + return -1; + } else { + int result = onMount(callbackArg); + int ret = 0; + if (result == -1) { + ret = result; + } + return ret; + } +} + +int dRawArcEntry_c::ensureLoadedMaybe(void *callbackArg) { + if (mpArc == nullptr) { + if (mpDvdReq == nullptr) { + return -1; + } + + if (mpDvdReq->mStatus == 0) { + return 1; + } + + mpArc = mpDvdReq->mDataPtr; + mpData = mpDvdReq->getArcBinary(); + mAmountRead = mpDvdReq->mAmountRead; + if (mpData != nullptr) { + u32 blockSize = EGG::ExpHeap::getSizeForMBlock(mpData); + if (mAmountRead != blockSize) { + mAmountRead = blockSize; + } + } + + mpCommandHeap = mpDvdReq->mHeap; + mpDvdReq->do_delete(); + mpDvdReq = nullptr; + if (mpArc == nullptr) { + return -1; + } + mpFrmHeap = mHeap::makeHeapOnCurrentGameHeap(-1, this->mArcName, 0x20, 0); + if (mpFrmHeap == nullptr) { + return -1; + } + int result = onMount(callbackArg); + mHeap::restoreCurrentHeap(); + mHeap::adjustFrmHeap(mpFrmHeap); + mChecksum = fn_80061BA0(mpData, mAmountRead); + if (result == -1) { + return result; + } + DCStoreRange(mpFrmHeap, mpFrmHeap->mHeapHandle->end - (u8*)mpFrmHeap); + } + + return 0; +} + +int dRawArcEntry_c::onMount(void *callbackArg) { + mpArc->countFile(); + if (callbackArg != nullptr) { + mpArc->searchInside(searchCallback1, callbackArg); + } + return 0; +} + + +dRawArcTable_c::dRawArcTable_c() { + mpEntries = nullptr; + mCount = 0; + mCallbackArg = nullptr; +} + +dRawArcTable_c::~dRawArcTable_c() { + if (mpEntries) { + delete[] mpEntries; + mpEntries = nullptr; + mCount = 0; + } +} + +bool dRawArcTable_c::init(u16 count, void *callbackArg, EGG::Heap *heap) { + mpEntries = new (heap, 0x04) dRawArcEntry_c[count](); + if (mpEntries == nullptr) { + return false; + } + + mCount = count; + mCallbackArg = callbackArg; + return true; +} + +bool dRawArcTable_c::getArcOrLoadFromDisk(const char *name, const char *dirName, u8 mountDirection, EGG::Heap *heap) { + dRawArcEntry_c *entry = findEntry(name); + if (entry == nullptr) { + entry = findEmptySlot(); + if (entry == nullptr) { + return false; + } + bool result = entry->loadArcFromDiskChecked(name, dirName, mountDirection, heap); + if (!result) { + entry->destroy(mCallbackArg); + return false; + } + } + entry->increaseRefCount(); + return true; +} + +bool dRawArcTable_c::addEntryFromSuperArc(const char *name, void *data, u8 mountDirection, EGG::Heap *heap) { + dRawArcEntry_c *entry = findEntry(name); + if (entry == nullptr) { + entry = findEmptySlot(); + if (entry == nullptr) { + return false; + } + int result = entry->mount(name, data, mCallbackArg, mountDirection, heap); + if (result != 0) { + entry->destroy(mCallbackArg); + return false; + } + } + entry->increaseRefCount(); + return true; +} + +int dRawArcTable_c::ensureLoadedMaybe2(const char *name) { + dRawArcEntry_c *entry = findEntry(name); + if (entry == nullptr) { + return -2; + } + return entry->ensureLoadedMaybe(mCallbackArg); +} + +int dRawArcTable_c::ensureLoadedMaybe(const char *name) { + dRawArcEntry_c *entry = findEntry(name); + if (entry == nullptr) { + return -2; + } + return entry->ensureLoadedMaybe(mCallbackArg); +} + +bool dRawArcTable_c::hasEntry(const char *name) { + return findEntry(name) != nullptr; +} + +bool dRawArcTable_c::decreaseRefCount(const char *name) { + dRawArcEntry_c *entry = findEntry(name); + if (entry == nullptr) { + return false; + } + entry->decreaseRefCount(); + if (!entry->isReferenced()) { + entry->destroy(mCallbackArg); + } + return true; +} + +void *dRawArcTable_c::getDataFromOarc(const char *name, const char *path) { + void *data = nullptr; + dRawArcEntry_c *entry = findLoadedEntry(name); + if (entry != nullptr) { + EGG::Archive *arc = entry->getArc(); + if (arc != nullptr) { + data = arc->getFile(path, nullptr); + } + } + return data; +} + +void *dRawArcTable_c::getSubEntryData(const char *name, const char *path) { + void *data = nullptr; + dRawArcEntry_c *entry = findLoadedEntry(name); + if (entry != nullptr) { + EGG::Archive *arc = entry->getArc(); + if (arc != nullptr) { + int num = arc->convertPathToEntryID(path); + if (num >= 0) { + data = arc->getFileFast(num, nullptr); + } + } + } + return data; +} + +void *dRawArcTable_c::getLoadedArcData(const char *name) { + dRawArcEntry_c *entry = findLoadedEntry(name); + return entry == nullptr ? nullptr : entry->getData(); +} + +int dRawArcTable_c::ensureAllEntriesLoaded() { + dRawArcEntry_c *entry = mpEntries; + int result = 0; + for (int i = 0; i < mCount; i++) { + if (entry->isLoading()) { + result = entry->ensureLoadedMaybe(mCallbackArg); + if (result != 0) { + return result; + } + } + entry++; + } + + return 0; +} + + +extern "C" bool strequals(const char *, const char*); + +// TODO the load from self can happen earlier +dRawArcEntry_c *dRawArcTable_c::findEntry(const char *name) const { + dRawArcEntry_c *entry = mpEntries; + for (int i = 0; i < mCount; i++) { + if (entry->isReferenced() && strequals(entry->name(), name)) { + return entry; + } + entry++; + } + + return nullptr; +} + +dRawArcEntry_c *dRawArcTable_c::findEmptySlot() { + dRawArcEntry_c *entry = mpEntries; + for (int i = 0; i < mCount; i++) { + if (!entry->isReferenced()) { + return entry; + } + entry++; + } + + return nullptr; +} + +dRawArcEntry_c *dRawArcTable_c::findLoadedEntry(const char *name) { + dRawArcEntry_c *entry = findEntry(name); + if (entry == nullptr) { + return nullptr; + } else if (entry->isNotLoaded()) { + return nullptr; + } + return entry; +} diff --git a/src/m/m_heap.cpp b/src/m/m_heap.cpp index ca18857f..5220d771 100644 --- a/src/m/m_heap.cpp +++ b/src/m/m_heap.cpp @@ -207,6 +207,6 @@ EGG::AssertHeap *mHeap::createAssertHeap(EGG::Heap *parent) { return g_assertHeap; } -EGG::Heap *mHeap::makeHeapOnCurrentGameHeap(size_t size, const char *name, u32 align, u32 flags) { +EGG::FrmHeap *mHeap::makeHeapOnCurrentGameHeap(size_t size, const char *name, u32 align, u32 flags) { return makeFrmHeapAndUpdate(size, g_gameHeaps[0], name, align, flags); } From 92e5d46eefee9adf6aa99ddf53f8020e8955cfe2 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 25 May 2024 20:07:15 +0200 Subject: [PATCH 05/20] Fix conditional --- src/d/d_rawarchive.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/d/d_rawarchive.cpp b/src/d/d_rawarchive.cpp index db540865..0501f256 100644 --- a/src/d/d_rawarchive.cpp +++ b/src/d/d_rawarchive.cpp @@ -4,7 +4,6 @@ #include // clang-format on - class UnkManager { public: /* vtable at 8050df50 */ @@ -17,7 +16,7 @@ public: }; extern "C" int fn_80061B10(void *d, u32 len) { - u32 *data = (u32*)d; + u32 *data = (u32 *)d; u32 result = 0; // Compiler will unroll this loop for (u32 len_words = len / 4; len_words != 0; len_words--) { @@ -35,7 +34,7 @@ extern "C" void fn_80061BE0(UnkManager *mgr, const char *name, size_t len) { // Sets stage to all spaces mgr->stage = 0x20202020; // copies the stage name? - memcpy((char*)&mgr->stage, name, len); + memcpy((char *)&mgr->stage, name, len); } dRawArcEntry_c::dRawArcEntry_c() { @@ -59,7 +58,6 @@ dRawArcEntry_c::~dRawArcEntry_c() { destroy(nullptr); } - void dRawArcEntry_c::searchCallback(void *arg, void *data, const ARCDirEntry *entry, const char *path, bool ctrl) { UnkManager *mgr = (UnkManager *)arg; if (entry->isDir) { @@ -86,7 +84,6 @@ void dRawArcEntry_c::searchCallback2(void *a, void *b, const ARCDirEntry *c, con searchCallback(a, b, c, d, false); } - bool dRawArcEntry_c::destroy(void *arg) { if (mpDvdReq != nullptr) { if (mpDvdReq->mStatus == 0) { @@ -186,8 +183,7 @@ bool dRawArcEntry_c::checkArcExistsOnDiskInner(char *outBuf, const char *fileNam int dRawArcEntry_c::mount(const char *name, void *data, void *callbackArg, u8 mountDirection, EGG::Heap *heap) { inline_strncpy(mArcName, name, sizeof(mArcName)); - // TODO this conditional uses a few more instructions in the original binary - mpArc = EGG::Archive::mount(data, heap, mountDirection != 1 ? 4 : -4); + mpArc = EGG::Archive::mount(data, heap, (mountDirection == 0 || mountDirection == 1) ? 4 : -4); if (mpArc == nullptr) { return -1; } else { @@ -237,7 +233,7 @@ int dRawArcEntry_c::ensureLoadedMaybe(void *callbackArg) { if (result == -1) { return result; } - DCStoreRange(mpFrmHeap, mpFrmHeap->mHeapHandle->end - (u8*)mpFrmHeap); + DCStoreRange(mpFrmHeap, mpFrmHeap->mHeapHandle->end - (u8 *)mpFrmHeap); } return 0; @@ -251,7 +247,6 @@ int dRawArcEntry_c::onMount(void *callbackArg) { return 0; } - dRawArcTable_c::dRawArcTable_c() { mpEntries = nullptr; mCount = 0; @@ -391,8 +386,7 @@ int dRawArcTable_c::ensureAllEntriesLoaded() { return 0; } - -extern "C" bool strequals(const char *, const char*); +extern "C" bool strequals(const char *, const char *); // TODO the load from self can happen earlier dRawArcEntry_c *dRawArcTable_c::findEntry(const char *name) const { From 556fd33fc329f7634f9b0dadc94011bd46dc6b13 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 25 May 2024 16:43:01 -0400 Subject: [PATCH 06/20] fixed regswap and matching --- configure.py | 2 +- src/d/d_rawarchive.cpp | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/configure.py b/configure.py index 7abf0df5..4d2e457c 100644 --- a/configure.py +++ b/configure.py @@ -287,7 +287,7 @@ config.libs = [ Object(NonMatching, "d/d_dvd_unk.cpp"), Object(NonMatching, "d/d_dylink.cpp"), Object(NonMatching, "d/d_heap.cpp"), - Object(NonMatching, "d/d_rawarchive.cpp"), + Object(Matching, "d/d_rawarchive.cpp"), Object(NonMatching, "d/d_stage.cpp"), Object(NonMatching, "d/d_sys.cpp"), Object(NonMatching, "d/a/d_a_base.cpp"), diff --git a/src/d/d_rawarchive.cpp b/src/d/d_rawarchive.cpp index 0501f256..888ade40 100644 --- a/src/d/d_rawarchive.cpp +++ b/src/d/d_rawarchive.cpp @@ -137,10 +137,17 @@ bool dRawArcEntry_c::loadArcFromDiskChecked(const char *fileName, const char *di inline void inline_strncat(char *dest, const char *src, size_t destSize) { if (src != nullptr) { size_t destLen = strlen(dest); - size_t srcLen = strlen(src); - size_t count = destLen + srcLen + 1 >= destSize ? destSize - destLen - 1 : srcLen; - strncpy(dest + destLen, src, count); - size_t offset = destLen + count; + size_t copyLen = strlen(src); + + // Make sure copy length isnt more than destination length + if (destLen + copyLen + 1 >= destSize) { + copyLen = destSize - destLen - 1; + } + + strncpy(dest + destLen, src, copyLen); + + // make sure string is null terminated + size_t offset = destLen + copyLen; dest[offset] = '\0'; } } From eea008649598ace5e625ec9771cb5291de04420c Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 25 May 2024 22:47:39 +0200 Subject: [PATCH 07/20] Expatriate the inline string methods --- include/inline_string.h | 31 +++++++++++++++++++++++++++++++ src/d/d_rawarchive.cpp | 30 +----------------------------- src/toBeSorted/file_manager.cpp | 5 ++--- 3 files changed, 34 insertions(+), 32 deletions(-) create mode 100644 include/inline_string.h diff --git a/include/inline_string.h b/include/inline_string.h new file mode 100644 index 00000000..3909422f --- /dev/null +++ b/include/inline_string.h @@ -0,0 +1,31 @@ +#ifndef INLINE_STRING_H +#define INLINE_STRING_H + +#include + +inline void inline_strncat(char *dest, const char *src, size_t destSize) { + if (src != nullptr) { + size_t destLen = strlen(dest); + size_t copyLen = strlen(src); + + // Make sure copy length isnt more than destination length + if (destLen + copyLen + 1 >= destSize) { + copyLen = destSize - destLen - 1; + } + + strncpy(dest + destLen, src, copyLen); + + // make sure string is null terminated + size_t offset = destLen + copyLen; + dest[offset] = '\0'; + } +} + +inline void inline_strncpy(char *dest, const char *src, size_t destSize) { + if (src != dest) { + dest[0] = '\0'; + inline_strncat(dest, src, destSize); + } +} + +#endif diff --git a/src/d/d_rawarchive.cpp b/src/d/d_rawarchive.cpp index 888ade40..75043513 100644 --- a/src/d/d_rawarchive.cpp +++ b/src/d/d_rawarchive.cpp @@ -1,8 +1,6 @@ #include +#include #include -// clang-format off -#include -// clang-format on class UnkManager { public: @@ -133,32 +131,6 @@ bool dRawArcEntry_c::loadArcFromDiskChecked(const char *fileName, const char *di return false; } -// Regswap -inline void inline_strncat(char *dest, const char *src, size_t destSize) { - if (src != nullptr) { - size_t destLen = strlen(dest); - size_t copyLen = strlen(src); - - // Make sure copy length isnt more than destination length - if (destLen + copyLen + 1 >= destSize) { - copyLen = destSize - destLen - 1; - } - - strncpy(dest + destLen, src, copyLen); - - // make sure string is null terminated - size_t offset = destLen + copyLen; - dest[offset] = '\0'; - } -} - -inline void inline_strncpy(char *dest, const char *src, size_t destSize) { - if (src != dest) { - dest[0] = '\0'; - inline_strncat(dest, src, destSize); - } -} - bool dRawArcEntry_c::loadArcFromDisk(const char *arcName, const char *arcPath, u8 mountDirection, EGG::Heap *heap) { mpDvdReq = mDvd_mountMemArchive_c::create(arcPath, mountDirection, heap); if (mpDvdReq == nullptr) { diff --git a/src/toBeSorted/file_manager.cpp b/src/toBeSorted/file_manager.cpp index d6bbd9a9..33f5ec69 100644 --- a/src/toBeSorted/file_manager.cpp +++ b/src/toBeSorted/file_manager.cpp @@ -1,8 +1,7 @@ #include "toBeSorted/file_manager.h" #include "f/f_base.h" #include -// #include "libc.h" -#include +#include // This class here makes no sense and the name might // be a total misnomer, but this gets the sinit section correct @@ -142,7 +141,7 @@ inline void strnsth(char *dest, const char *src, size_t max_len) { char buf[0x20]; buf[0] = '\0'; - strnsth(buf, "F405", 0x20); + inline_strncpy(buf, "F405", sizeof(buf)); file->setAreaT1(buf); file->room_id_t1 = 0; file->forced_layer_t1 = 0; From 69d5f223fbfb73ad5be539bf2e147f2234f9eedf Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 25 May 2024 22:50:24 +0200 Subject: [PATCH 08/20] Remove outdated comment --- src/d/d_rawarchive.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/d/d_rawarchive.cpp b/src/d/d_rawarchive.cpp index 75043513..279bfd2c 100644 --- a/src/d/d_rawarchive.cpp +++ b/src/d/d_rawarchive.cpp @@ -367,7 +367,6 @@ int dRawArcTable_c::ensureAllEntriesLoaded() { extern "C" bool strequals(const char *, const char *); -// TODO the load from self can happen earlier dRawArcEntry_c *dRawArcTable_c::findEntry(const char *name) const { dRawArcEntry_c *entry = mpEntries; for (int i = 0; i < mCount; i++) { From 82d7176ed1f5c9745d08f7df015135484c7516ee Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 26 May 2024 00:43:09 +0200 Subject: [PATCH 09/20] Remove dead code --- src/toBeSorted/file_manager.cpp | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/toBeSorted/file_manager.cpp b/src/toBeSorted/file_manager.cpp index 33f5ec69..4a525a74 100644 --- a/src/toBeSorted/file_manager.cpp +++ b/src/toBeSorted/file_manager.cpp @@ -100,29 +100,6 @@ u16 *FileManager::getStoryFlagsMut() { /* 8000AA30 */ u16 *FileManager::getSkipFlags() {} /* 8000AA40 */ void FileManager::setSkipFlagsChecked(u16 *flags, u32 offset, u16 count) {} -// This does strncat things - append src to dest -inline void fake_strncat(char *dest, const char *src, size_t max_len) { - if (src != nullptr) { - size_t len = strlen(dest); - size_t count = strlen(src); - count = len + count + 1 >= max_len ? max_len - len - 1 : count; - strncpy(dest + len, src, count); - // one instshuffle here - this should be (len + count), - // but then regalloc blows up and uses one more register in initFile - dest[count + len] = '\0'; - } -} - -// A function like this is inlined into in a bunch of area-related code -// It doesn't make a whole lot of sense to use strncat on a string just -// clipped to zero length... -inline void strnsth(char *dest, const char *src, size_t max_len) { - if (src != dest) { - dest[0] = '\0'; - fake_strncat(dest, src, max_len); - } -} - /* 8000AAA0 */ void FileManager::initFile(int fileNum) { mIsFileInvalid[1] = 1; From be163e6de709e5d44ed3faf38b69202d16bfe6b0 Mon Sep 17 00:00:00 2001 From: robojumper Date: Tue, 28 May 2024 23:15:30 +0200 Subject: [PATCH 10/20] CurrentStageArcManager WIP --- config/SOUE01/splits.txt | 8 + config/SOUE01/symbols.txt | 66 +++--- configure.py | 1 + include/d/d_rawarchive.h | 4 +- src/d/d_rawarchive.cpp | 4 +- .../current_stage_arc_manager.cpp | 205 ++++++++++++++++++ 6 files changed, 251 insertions(+), 37 deletions(-) create mode 100644 src/toBeSorted/arc_managers/current_stage_arc_manager.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index d9385aba..6414087d 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -119,6 +119,14 @@ d/d_stage.cpp: d/d_sys.cpp: .text start:0x80064250 end:0x80064920 +toBeSorted/arc_managers/current_stage_arc_manager.cpp: + .text start:0x80068FD0 end:0x80069910 + .ctors start:0x804DB6A8 end:0x804DB6AC + .data start:0x8050DFE0 end:0x8050E010 + .sdata start:0x80571D30 end:0x80571D40 + .sbss start:0x80575278 end:0x80575280 + .bss start:0x805A0868 end:0x805A08C8 + toBeSorted/sceneflag_manager.cpp: .text start:0x800BD8C0 end:0x800BE7A8 .sbss start:0x805753E0 end:0x805753F0 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index d978003d..665363a2 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -723,7 +723,7 @@ fn_8001F680 = .text:0x8001F680; // type:function size:0x70 fn_8001F6F0 = .text:0x8001F6F0; // type:function size:0x4 fn_8001F700 = .text:0x8001F700; // type:function size:0xA8 fn_8001F7B0 = .text:0x8001F7B0; // type:function size:0x64 -fn_8001F820 = .text:0x8001F820; // type:function size:0xD0 +sprintf__15SizedString<32>FPCce = .text:0x8001F820; // type:function size:0xD0 fn_8001F8F0 = .text:0x8001F8F0; // type:function size:0x14 fn_8001F910 = .text:0x8001F910; // type:function size:0xD4 fn_8001F9F0 = .text:0x8001F9F0; // type:function size:0xB4 @@ -2982,26 +2982,26 @@ fn_80068E70 = .text:0x80068E70; // type:function size:0xC fn_80068E80 = .text:0x80068E80; // type:function size:0x6C fn_80068EF0 = .text:0x80068EF0; // type:function size:0xC0 fn_80068FB0 = .text:0x80068FB0; // type:function size:0x20 -fn_80068FD0 = .text:0x80068FD0; // type:function size:0x54 -fn_80069030 = .text:0x80069030; // type:function size:0x64 -fn_800690A0 = .text:0x800690A0; // type:function size:0x14 -fn_800690C0 = .text:0x800690C0; // type:function size:0x218 -fn_800692E0 = .text:0x800692E0; // type:function size:0x38 -fn_80069320 = .text:0x80069320; // type:function size:0x14 -fn_80069340 = .text:0x80069340; // type:function size:0x14 -fn_80069360 = .text:0x80069360; // type:function size:0x10C -fn_80069470 = .text:0x80069470; // type:function size:0x5C -fn_800694D0 = .text:0x800694D0; // type:function size:0x74 -fn_80069550 = .text:0x80069550; // type:function size:0x38 -fn_80069590 = .text:0x80069590; // type:function size:0x3C -fn_800695D0 = .text:0x800695D0; // type:function size:0x28 -fn_80069600 = .text:0x80069600; // type:function size:0x48 -fn_80069650 = .text:0x80069650; // type:function size:0x48 -fn_800696A0 = .text:0x800696A0; // type:function size:0x8 -fn_800696B0 = .text:0x800696B0; // type:function size:0x12C -fn_800697E0 = .text:0x800697E0; // type:function size:0xB0 -fn_80069890 = .text:0x80069890; // type:function size:0x64 -fn_80069900 = .text:0x80069900; // type:function size:0x10 +__ct__22CurrentStageArcManagerFv = .text:0x80068FD0; // type:function size:0x54 +__dt__22CurrentStageArcManagerFv = .text:0x80069030; // type:function size:0x64 +init__22CurrentStageArcManagerFPQ23EGG4Heap = .text:0x800690A0; // type:function size:0x14 +setStage__22CurrentStageArcManagerFPCc = .text:0x800690C0; // type:function size:0x218 +decrement__22CurrentStageArcManagerFv = .text:0x800692E0; // type:function size:0x38 +getData__22CurrentStageArcManagerFPCc = .text:0x80069320; // type:function size:0x14 +getFileFromCurrentLay0Arc__22CurrentStageArcManagerFPCc = .text:0x80069340; // type:function size:0x14 +loadFileFromExtraLayerArc__22CurrentStageArcManagerFi = .text:0x80069360; // type:function size:0x10C +unloadExtraLayerArc__22CurrentStageArcManagerFv = .text:0x80069470; // type:function size:0x5C +loadRoomArc__22CurrentStageArcManagerFi = .text:0x800694D0; // type:function size:0x74 +addEntryFromSuperArc__22CurrentStageArcManagerFPCcPv = .text:0x80069550; // type:function size:0x38 +unloadRoomArc__22CurrentStageArcManagerFi = .text:0x80069590; // type:function size:0x3C +decrement__22CurrentStageArcManagerFPCc = .text:0x800695D0; // type:function size:0x28 +loadFromRoomArc__22CurrentStageArcManagerFiPCc = .text:0x80069600; // type:function size:0x48 +getDataFromRoomArc__22CurrentStageArcManagerFiPCc = .text:0x80069650; // type:function size:0x48 +getHeap__Fv = .text:0x800696A0; // type:function size:0x8 +getCurrentStageDirectory__22CurrentStageArcManagerFv = .text:0x800696B0; // type:function size:0x12C +getRoomArcDirectory__22CurrentStageArcManagerCFi = .text:0x800697E0; // type:function size:0xB0 +create__22CurrentStageArcManagerFPQ23EGG4Heap = .text:0x80069890; // type:function size:0x64 +__sinit_\current_stage_arc_manager_cpp = .text:0x80069900; // type:function size:0x10 scope:local fn_80069910 = .text:0x80069910; // type:function size:0x44 fn_80069960 = .text:0x80069960; // type:function size:0x64 fn_800699D0 = .text:0x800699D0; // type:function size:0x14 @@ -30762,8 +30762,8 @@ lbl_8050DD58 = .data:0x8050DD58; // type:object size:0x18 lbl_8050DD70 = .data:0x8050DD70; // type:object size:0x30 lbl_8050DDA0 = .data:0x8050DDA0; // type:object size:0x18 lbl_8050DDB8 = .data:0x8050DDB8; // type:object size:0x20 -lbl_8050DDD8 = .data:0x8050DDD8; // type:object size:0x10 -lbl_8050DDE8 = .data:0x8050DDE8; // type:object size:0x10 +lbl_8050DDD8 = .data:0x8050DDD8; // type:object size:0xE data:string +lbl_8050DDE8 = .data:0x8050DDE8; // type:object size:0xB data:string lbl_8050DDF8 = .data:0x8050DDF8; // type:object size:0x50 lbl_8050DE48 = .data:0x8050DE48; // type:object size:0x10 lbl_8050DE58 = .data:0x8050DE58; // type:object size:0x5C @@ -30783,10 +30783,10 @@ lbl_8050DFB0 = .data:0x8050DFB0; // type:object size:0xC lbl_8050DFBC = .data:0x8050DFBC; // type:object size:0xC lbl_8050DFC8 = .data:0x8050DFC8; // type:object size:0xC lbl_8050DFD4 = .data:0x8050DFD4; // type:object size:0xC -lbl_8050DFE0 = .data:0x8050DFE0; // type:object size:0xC -lbl_8050DFEC = .data:0x8050DFEC; // type:object size:0xC -lbl_8050DFF8 = .data:0x8050DFF8; // type:object size:0xC -lbl_8050E004 = .data:0x8050E004; // type:object size:0xC +lbl_8050DFE0 = .data:0x8050DFE0; // type:object size:0xA data:string +lbl_8050DFEC = .data:0x8050DFEC; // type:object size:0xB data:string +lbl_8050DFF8 = .data:0x8050DFF8; // type:object size:0x9 data:string +__vt__22CurrentStageArcManager = .data:0x8050E004; // type:object size:0xC lbl_8050E010 = .data:0x8050E010; // type:object size:0x10 data:string lbl_8050E020 = .data:0x8050E020; // type:object size:0xC data:string lbl_8050E02C = .data:0x8050E02C; // type:object size:0xC @@ -37658,8 +37658,8 @@ lbl_80571D10 = .sdata:0x80571D10; // type:object size:0x8 lbl_80571D18 = .sdata:0x80571D18; // type:object size:0x8 lbl_80571D20 = .sdata:0x80571D20; // type:object size:0x8 lbl_80571D28 = .sdata:0x80571D28; // type:object size:0x8 data:string -lbl_80571D30 = .sdata:0x80571D30; // type:object size:0x8 -lbl_80571D38 = .sdata:0x80571D38; // type:object size:0x8 +lbl_80571D30 = .sdata:0x80571D30; // type:object size:0x7 data:string +lbl_80571D38 = .sdata:0x80571D38; // type:object size:0x7 data:string lbl_80571D40 = .sdata:0x80571D40; // type:object size:0x8 lbl_80571D48 = .sdata:0x80571D48; // type:object size:0x8 lbl_80571D50 = .sdata:0x80571D50; // type:object size:0x8 @@ -39821,8 +39821,8 @@ lbl_80575260 = .sbss:0x80575260; // type:object size:0x8 data:4byte lbl_80575268 = .sbss:0x80575268; // type:object size:0x8 data:4byte lbl_80575270 = .sbss:0x80575270; // type:object size:0x1 data:byte lbl_80575274 = .sbss:0x80575274; // type:object size:0x4 data:4byte -lbl_80575278 = .sbss:0x80575278; // type:object size:0x4 data:4byte -lbl_8057527C = .sbss:0x8057527C; // type:object size:0x1 data:byte +sInstance__22CurrentStageArcManager = .sbss:0x80575278; // type:object size:0x4 data:4byte +@GUARD@getCurrentStageDirectory__22CurrentStageArcManagerFv@sStageDirTmp = .sbss:0x8057527C; // type:object size:0x1 data:byte lbl_80575280 = .sbss:0x80575280; // type:object size:0x8 data:4byte lbl_80575288 = .sbss:0x80575288; // type:object size:0x8 data:4byte lbl_80575290 = .sbss:0x80575290; // type:object size:0x4 @@ -48208,8 +48208,8 @@ lbl_805A07E4 = .bss:0x805A07E4; // type:object size:0xC lbl_805A07F0 = .bss:0x805A07F0; // type:object size:0xC lbl_805A07FC = .bss:0x805A07FC; // type:object size:0x44 data:byte lbl_805A0840 = .bss:0x805A0840; // type:object size:0x28 data:byte -lbl_805A0868 = .bss:0x805A0868; // type:object size:0x40 data:byte -lbl_805A08A8 = .bss:0x805A08A8; // type:object size:0x20 data:byte +@LOCAL@getCurrentStageDirectory__22CurrentStageArcManagerFv@sStageDirTmp = .bss:0x805A0868; // type:object size:0x40 data:byte +s_roomArcTmp = .bss:0x805A08A8; // type:object size:0x20 data:byte lbl_805A08C8 = .bss:0x805A08C8; // type:object size:0x138 data:2byte lbl_805A0A00 = .bss:0x805A0A00; // type:object size:0x28 data:byte lbl_805A0A28 = .bss:0x805A0A28; // type:object size:0x28 data:byte diff --git a/configure.py b/configure.py index 4d2e457c..6db3bbcc 100644 --- a/configure.py +++ b/configure.py @@ -292,6 +292,7 @@ config.libs = [ Object(NonMatching, "d/d_sys.cpp"), Object(NonMatching, "d/a/d_a_base.cpp"), Object(NonMatching, "d/a/obj/d_a_obj_base.cpp"), + Object(Matching, "toBeSorted/arc_managers/current_stage_arc_manager.cpp"), Object(Matching, "toBeSorted/save_file.cpp"), Object(Matching, "toBeSorted/counters/counter.cpp"), Object(Matching, "toBeSorted/counters/rupee_counter.cpp"), diff --git a/include/d/d_rawarchive.h b/include/d/d_rawarchive.h index 7432f3f3..43abc63c 100644 --- a/include/d/d_rawarchive.h +++ b/include/d/d_rawarchive.h @@ -81,12 +81,12 @@ public: ~dRawArcTable_c(); bool init(u16 count, void *callbackArg, EGG::Heap *heap); - bool getArcOrLoadFromDisk(const char *name, const char *dirName, u8 mountDirection, EGG::Heap *heap); + u32 getArcOrLoadFromDisk(const char *name, const char *dirName, u8 mountDirection, EGG::Heap *heap); bool addEntryFromSuperArc(const char *name, void *data, u8 mountDirection, EGG::Heap *heap); int ensureLoadedMaybe2(const char *name); int ensureLoadedMaybe(const char *name); bool hasEntry(const char *name); - bool decreaseRefCount(const char *name); + u32 decreaseRefCount(const char *name); void *getDataFromOarc(const char *name, const char *path); void *getSubEntryData(const char *name, const char *path); void *getLoadedArcData(const char *name); diff --git a/src/d/d_rawarchive.cpp b/src/d/d_rawarchive.cpp index 279bfd2c..7a1da9d5 100644 --- a/src/d/d_rawarchive.cpp +++ b/src/d/d_rawarchive.cpp @@ -251,7 +251,7 @@ bool dRawArcTable_c::init(u16 count, void *callbackArg, EGG::Heap *heap) { return true; } -bool dRawArcTable_c::getArcOrLoadFromDisk(const char *name, const char *dirName, u8 mountDirection, EGG::Heap *heap) { +u32 dRawArcTable_c::getArcOrLoadFromDisk(const char *name, const char *dirName, u8 mountDirection, EGG::Heap *heap) { dRawArcEntry_c *entry = findEntry(name); if (entry == nullptr) { entry = findEmptySlot(); @@ -305,7 +305,7 @@ bool dRawArcTable_c::hasEntry(const char *name) { return findEntry(name) != nullptr; } -bool dRawArcTable_c::decreaseRefCount(const char *name) { +u32 dRawArcTable_c::decreaseRefCount(const char *name) { dRawArcEntry_c *entry = findEntry(name); if (entry == nullptr) { return false; diff --git a/src/toBeSorted/arc_managers/current_stage_arc_manager.cpp b/src/toBeSorted/arc_managers/current_stage_arc_manager.cpp new file mode 100644 index 00000000..6f0f33bd --- /dev/null +++ b/src/toBeSorted/arc_managers/current_stage_arc_manager.cpp @@ -0,0 +1,205 @@ +#include +#include +#include +// clang-format off +#include +// clang-format on + +template +struct SizedString { + SizedString() { + mChars[0] = '\0'; + } + + char mChars[Size]; + + char *operator&() { + return mChars; + } + + const char *operator&() const { + return mChars; + } + + inline void set(const char *src) { + if (src != mChars) { + mChars[0] = '\0'; + append(src); + } + } + + inline void append(const char *src) { + if (src != nullptr) { + size_t destLen = strlen(mChars); + size_t copyLen = strlen(src); + + // Make sure copy length isnt more than destination length + if (destLen + copyLen + 1 >= Size) { + size_t tmpLen = Size - destLen; + copyLen = tmpLen - 1; + } + + strncpy(mChars + destLen, src, copyLen); + + // make sure string is null terminated + size_t offset = destLen + copyLen; + mChars[offset] = '\0'; + } + } + + void sprintf(const char *fmt, ...); +}; + +class CurrentStageArcManager { + CurrentStageArcManager(); + virtual ~CurrentStageArcManager(); + + SizedString<32> mStageName; + SizedString<32> mCurrentLoadingStageArcName; + SizedString<32> mStageExtraLayerArcName; + + dRawArcTable_c mArcTable; + + static CurrentStageArcManager *sInstance; + + static bool create(EGG::Heap *heap); + + void init(EGG::Heap *heap); + bool setStage(const char *stage); + bool decrement(); + void *getData(const char *fileName); + void *getFileFromCurrentLay0Arc(const char *fileName); + bool loadFileFromExtraLayerArc(int layer); + bool unloadExtraLayerArc(); + bool loadRoomArc(int room); + bool addEntryFromSuperArc(const char *name, void *data); + bool unloadRoomArc(int room); + bool decrement(const char *path); + void *loadFromRoomArc(int roomId, const char *fileName); + void *getDataFromRoomArc(int roomId, const char *fileName); + const char *getCurrentStageDirectory(); + const char *getRoomArcDirectory(int room) const; + + static EGG::ExpHeap *getHeap(); +}; + +CurrentStageArcManager *CurrentStageArcManager::sInstance; + +CurrentStageArcManager::CurrentStageArcManager() { + sInstance = this; +} + +CurrentStageArcManager::~CurrentStageArcManager() { + sInstance = nullptr; +} + +extern char lbl_80575250; + +void CurrentStageArcManager::init(EGG::Heap *heap) { + mArcTable.init(18, &lbl_80575250, heap); +} + +// sprintf +extern "C" void fn_8001F820(char *str, const char *src, ...); + +bool CurrentStageArcManager::setStage(const char *newStage) { + mStageName.set(newStage); + + mCurrentLoadingStageArcName.sprintf("%s_stg_l0", mStageName); + if (dRawArcEntry_c::checkArcExistsOnDisk(&mCurrentLoadingStageArcName, getCurrentStageDirectory())) { + return (bool)mArcTable.getArcOrLoadFromDisk(&mCurrentLoadingStageArcName, getCurrentStageDirectory(), 0, + dHeap::work2Heap.heap); + } else { + mCurrentLoadingStageArcName.sprintf("%s_stg", mStageName); + return (bool)mArcTable.getArcOrLoadFromDisk(&mCurrentLoadingStageArcName, getCurrentStageDirectory(), 0, + dHeap::work2Heap.heap); + } +} + +bool CurrentStageArcManager::decrement() { + return mArcTable.decreaseRefCount(&mCurrentLoadingStageArcName); +} + +void *CurrentStageArcManager::getData(const char *fileName) { + return mArcTable.getDataFromOarc(&mCurrentLoadingStageArcName, fileName); +} + +void *CurrentStageArcManager::getFileFromCurrentLay0Arc(const char *fileName) { + return mArcTable.getSubEntryData(&mCurrentLoadingStageArcName, fileName); +} + +bool CurrentStageArcManager::loadFileFromExtraLayerArc(int layer) { + if (layer == 0) { + return true; + } + + mStageExtraLayerArcName.sprintf("%s_stg_l%d", mStageName, layer); + if (dRawArcEntry_c::checkArcExistsOnDisk(&mStageExtraLayerArcName, getCurrentStageDirectory())) { + return (bool)mArcTable.getArcOrLoadFromDisk(&mStageExtraLayerArcName, getCurrentStageDirectory(), 0, + dHeap::work2Heap.heap); + } else { + return true; + } +} + +bool CurrentStageArcManager::unloadExtraLayerArc() { + if (mArcTable.hasEntry(&mStageExtraLayerArcName)) { + return mArcTable.decreaseRefCount(&mStageExtraLayerArcName); + } + return true; +} + +bool CurrentStageArcManager::loadRoomArc(int room) { + return (bool)mArcTable.getArcOrLoadFromDisk(getRoomArcDirectory(room), getCurrentStageDirectory(), 0, dHeap::work2Heap.heap); +} + +bool CurrentStageArcManager::addEntryFromSuperArc(const char *path, void *data) { + return (bool)mArcTable.addEntryFromSuperArc(path, data, 0, EGG::Heap::sCurrentHeap); +} + +bool CurrentStageArcManager::unloadRoomArc(int room) { + mArcTable.decreaseRefCount(getRoomArcDirectory(room)); + return true; +} + +bool CurrentStageArcManager::decrement(const char *path) { + mArcTable.decreaseRefCount(path); + return true; +} + +void *CurrentStageArcManager::loadFromRoomArc(int roomId, const char *fileName) { + return mArcTable.getDataFromOarc(getRoomArcDirectory(roomId), fileName); +} + +void *CurrentStageArcManager::getDataFromRoomArc(int roomId, const char *fileName) { + return mArcTable.getSubEntryData(getRoomArcDirectory(roomId), fileName); +} + +EGG::ExpHeap *getHeap() { + return dHeap::workExHeap.heap; +} + +const char *CurrentStageArcManager::getCurrentStageDirectory() { + static SizedString<64> sStageDirTmp; + sStageDirTmp.set("Stage/"); + sStageDirTmp.append(&mStageName); + + return &sStageDirTmp; +} + +static SizedString<32> s_roomArcTmp; + +const char *CurrentStageArcManager::getRoomArcDirectory(int room) const { + s_roomArcTmp.sprintf("%s_r%02d", mStageName, room); + return &s_roomArcTmp; +} + +bool CurrentStageArcManager::create(EGG::Heap *heap) { + new (heap, 0x04) CurrentStageArcManager(); + + if (CurrentStageArcManager::sInstance == nullptr) { + return false; + } + CurrentStageArcManager::sInstance->init(heap); + return true; +} From e6429777e5090a5cc07c0fa1fe1fe91d42a772af Mon Sep 17 00:00:00 2001 From: robojumper Date: Wed, 29 May 2024 20:02:57 +0200 Subject: [PATCH 11/20] sized_string (can we fix libc headers yet?) --- include/d/d_rawarchive.h | 9 ++- include/inline_string.h | 31 --------- include/sized_string.h | 69 +++++++++++++++++++ src/d/d_rawarchive.cpp | 8 +-- .../current_stage_arc_manager.cpp | 53 ++------------ src/toBeSorted/file_manager.cpp | 11 +-- 6 files changed, 88 insertions(+), 93 deletions(-) delete mode 100644 include/inline_string.h create mode 100644 include/sized_string.h diff --git a/include/d/d_rawarchive.h b/include/d/d_rawarchive.h index 43abc63c..61d048f4 100644 --- a/include/d/d_rawarchive.h +++ b/include/d/d_rawarchive.h @@ -3,6 +3,9 @@ #include #include +// clang-format off +#include +// clang-format on // TODO: loading status could be an enum (-2/-1/0/+1) @@ -28,8 +31,8 @@ public: return mRefCount != 0; } - inline const char *name() { - return mArcName; + inline const char *name() const { + return &mArcName; } inline bool isNotLoaded() { @@ -62,7 +65,7 @@ private: static void searchCallback2(void *, void *, const ARCDirEntry *, const char *); private: - /* 0x00 */ char mArcName[0x20]; + /* 0x00 */ SizedString<32> mArcName; /* 0x20 */ u16 mRefCount; /* 0x24 */ mDvd_mountMemArchive_c *mpDvdReq; /* 0x28 */ EGG::Archive *mpArc; diff --git a/include/inline_string.h b/include/inline_string.h deleted file mode 100644 index 3909422f..00000000 --- a/include/inline_string.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef INLINE_STRING_H -#define INLINE_STRING_H - -#include - -inline void inline_strncat(char *dest, const char *src, size_t destSize) { - if (src != nullptr) { - size_t destLen = strlen(dest); - size_t copyLen = strlen(src); - - // Make sure copy length isnt more than destination length - if (destLen + copyLen + 1 >= destSize) { - copyLen = destSize - destLen - 1; - } - - strncpy(dest + destLen, src, copyLen); - - // make sure string is null terminated - size_t offset = destLen + copyLen; - dest[offset] = '\0'; - } -} - -inline void inline_strncpy(char *dest, const char *src, size_t destSize) { - if (src != dest) { - dest[0] = '\0'; - inline_strncat(dest, src, destSize); - } -} - -#endif diff --git a/include/sized_string.h b/include/sized_string.h new file mode 100644 index 00000000..1d619dda --- /dev/null +++ b/include/sized_string.h @@ -0,0 +1,69 @@ +#ifndef SIZED_STRING_H +#define SIZED_STRING_H + +#include + +/** + * A statically sized string buffer used for resource + * identification where strings are guaranteed to be short. + * + * Note: We aren't aware of any other projects that use a similar + * class and given that SS has no debugging info anywhere it's hard + * to be certain about anything. + */ +template +struct SizedString { + SizedString() { + mChars[0] = '\0'; + } + + char mChars[Size]; + + char *operator&() { + return mChars; + } + + const char *operator&() const { + return mChars; + } + + void operator=(const char *src) { + if (src != mChars) { + mChars[0] = '\0'; + operator+=(src); + } + } + + void operator+=(const char *src) { + if (src != nullptr) { + size_t destLen = strlen(mChars); + size_t copyLen = strlen(src); + + // Make sure copy length isnt more than destination length + if (destLen + copyLen + 1 >= Size) { + size_t tmpLen = Size - destLen; + copyLen = tmpLen - 1; + } + + strncpy(mChars + destLen, src, copyLen); + + // make sure string is null terminated + size_t offset = destLen + copyLen; + mChars[offset] = '\0'; + } + } + + int sprintf(const char *fmt, ...) { + va_list args; + va_start(args, fmt); + + int printed = vsnprintf(this->mChars, Size, fmt, args); + if (printed != strlen(this->mChars)) { + this->mChars[0] = '\0'; + } + va_end(list); + return printed; + } +}; + +#endif diff --git a/src/d/d_rawarchive.cpp b/src/d/d_rawarchive.cpp index 7a1da9d5..9adc35b4 100644 --- a/src/d/d_rawarchive.cpp +++ b/src/d/d_rawarchive.cpp @@ -1,5 +1,4 @@ #include -#include #include class UnkManager { @@ -36,7 +35,6 @@ extern "C" void fn_80061BE0(UnkManager *mgr, const char *name, size_t len) { } dRawArcEntry_c::dRawArcEntry_c() { - mArcName[0] = '\0'; mRefCount = 0; mpDvdReq = nullptr; mpArc = nullptr; @@ -136,7 +134,7 @@ bool dRawArcEntry_c::loadArcFromDisk(const char *arcName, const char *arcPath, u if (mpDvdReq == nullptr) { return false; } - inline_strncpy(mArcName, arcName, sizeof(mArcName)); + mArcName = arcName; return true; } @@ -161,7 +159,7 @@ bool dRawArcEntry_c::checkArcExistsOnDiskInner(char *outBuf, const char *fileNam } int dRawArcEntry_c::mount(const char *name, void *data, void *callbackArg, u8 mountDirection, EGG::Heap *heap) { - inline_strncpy(mArcName, name, sizeof(mArcName)); + mArcName = name; mpArc = EGG::Archive::mount(data, heap, (mountDirection == 0 || mountDirection == 1) ? 4 : -4); if (mpArc == nullptr) { return -1; @@ -201,7 +199,7 @@ int dRawArcEntry_c::ensureLoadedMaybe(void *callbackArg) { if (mpArc == nullptr) { return -1; } - mpFrmHeap = mHeap::makeHeapOnCurrentGameHeap(-1, this->mArcName, 0x20, 0); + mpFrmHeap = mHeap::makeHeapOnCurrentGameHeap(-1, name(), 0x20, 0); if (mpFrmHeap == nullptr) { return -1; } diff --git a/src/toBeSorted/arc_managers/current_stage_arc_manager.cpp b/src/toBeSorted/arc_managers/current_stage_arc_manager.cpp index 6f0f33bd..87b1dd91 100644 --- a/src/toBeSorted/arc_managers/current_stage_arc_manager.cpp +++ b/src/toBeSorted/arc_managers/current_stage_arc_manager.cpp @@ -2,54 +2,9 @@ #include #include // clang-format off -#include +#include // clang-format on -template -struct SizedString { - SizedString() { - mChars[0] = '\0'; - } - - char mChars[Size]; - - char *operator&() { - return mChars; - } - - const char *operator&() const { - return mChars; - } - - inline void set(const char *src) { - if (src != mChars) { - mChars[0] = '\0'; - append(src); - } - } - - inline void append(const char *src) { - if (src != nullptr) { - size_t destLen = strlen(mChars); - size_t copyLen = strlen(src); - - // Make sure copy length isnt more than destination length - if (destLen + copyLen + 1 >= Size) { - size_t tmpLen = Size - destLen; - copyLen = tmpLen - 1; - } - - strncpy(mChars + destLen, src, copyLen); - - // make sure string is null terminated - size_t offset = destLen + copyLen; - mChars[offset] = '\0'; - } - } - - void sprintf(const char *fmt, ...); -}; - class CurrentStageArcManager { CurrentStageArcManager(); virtual ~CurrentStageArcManager(); @@ -103,7 +58,7 @@ void CurrentStageArcManager::init(EGG::Heap *heap) { extern "C" void fn_8001F820(char *str, const char *src, ...); bool CurrentStageArcManager::setStage(const char *newStage) { - mStageName.set(newStage); + mStageName = newStage; mCurrentLoadingStageArcName.sprintf("%s_stg_l0", mStageName); if (dRawArcEntry_c::checkArcExistsOnDisk(&mCurrentLoadingStageArcName, getCurrentStageDirectory())) { @@ -181,8 +136,8 @@ EGG::ExpHeap *getHeap() { const char *CurrentStageArcManager::getCurrentStageDirectory() { static SizedString<64> sStageDirTmp; - sStageDirTmp.set("Stage/"); - sStageDirTmp.append(&mStageName); + sStageDirTmp = "Stage/"; + sStageDirTmp += &mStageName; return &sStageDirTmp; } diff --git a/src/toBeSorted/file_manager.cpp b/src/toBeSorted/file_manager.cpp index 4a525a74..1f6ea9e4 100644 --- a/src/toBeSorted/file_manager.cpp +++ b/src/toBeSorted/file_manager.cpp @@ -1,7 +1,9 @@ #include "toBeSorted/file_manager.h" #include "f/f_base.h" #include -#include +// clang-format off +#include +// clang-format on // This class here makes no sense and the name might // be a total misnomer, but this gets the sinit section correct @@ -116,10 +118,9 @@ u16 *FileManager::getStoryFlagsMut() { file->selectedDowsingSlot = 0x8; file->lastUsedPouchItemSlot = 0x8; - char buf[0x20]; - buf[0] = '\0'; - inline_strncpy(buf, "F405", sizeof(buf)); - file->setAreaT1(buf); + SizedString<32> buf; + buf = "F405"; + file->setAreaT1(&buf); file->room_id_t1 = 0; file->forced_layer_t1 = 0; file->entrance_t1_load_flag = 1; From 892a040a97251463297db6f2b8eeaa95f69f4eea Mon Sep 17 00:00:00 2001 From: robojumper Date: Wed, 29 May 2024 21:45:20 +0200 Subject: [PATCH 12/20] oarc_manager --- config/SOUE01/splits.txt | 6 + config/SOUE01/symbols.txt | 54 ++++---- configure.py | 1 + include/d/d_rawarchive.h | 10 +- include/sized_string.h | 4 + src/d/d_dvd.cpp | 19 ++- src/d/d_rawarchive.cpp | 28 ++-- .../current_stage_arc_manager.cpp | 2 - src/toBeSorted/arc_managers/oarc_manager.cpp | 124 ++++++++++++++++++ 9 files changed, 188 insertions(+), 60 deletions(-) create mode 100644 src/toBeSorted/arc_managers/oarc_manager.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 6414087d..821c6294 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -127,6 +127,12 @@ toBeSorted/arc_managers/current_stage_arc_manager.cpp: .sbss start:0x80575278 end:0x80575280 .bss start:0x805A0868 end:0x805A08C8 +toBeSorted/arc_managers/oarc_manager.cpp: + .text start:0x80069910 end:0x80069ED4 + .data start:0x8050E010 end:0x8050E038 + .sdata start:0x80571D40 end:0x80571D68 + .sbss start:0x80575280 end:0x80575288 + toBeSorted/sceneflag_manager.cpp: .text start:0x800BD8C0 end:0x800BE7A8 .sbss start:0x805753E0 end:0x805753F0 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 665363a2..e92c1510 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -1552,7 +1552,7 @@ fn_8003D590 = .text:0x8003D590; // type:function size:0x30 fn_8003D5C0 = .text:0x8003D5C0; // type:function size:0x4 fn_8003D5D0 = .text:0x8003D5D0; // type:function size:0xC fn_8003D5E0 = .text:0x8003D5E0; // type:function size:0x68 -fn_8003D650 = .text:0x8003D650; // type:function size:0xD0 +sprintf__16SizedString<128>FPCce = .text:0x8003D650; // type:function size:0xD0 fn_8003D720 = .text:0x8003D720; // type:function size:0x40 fn_8003D760 = .text:0x8003D760; // type:function size:0x11C fn_8003D880 = .text:0x8003D880; // type:function size:0x20C @@ -2750,7 +2750,7 @@ destroy__14dRawArcEntry_cFPv = .text:0x80061D60; // type:function size:0x104 loadArcFromDiskChecked__14dRawArcEntry_cFPCcPCcUcPQ23EGG4Heap = .text:0x80061E70; // type:function size:0x74 loadArcFromDisk__14dRawArcEntry_cFPCcPCcUcPQ23EGG4Heap = .text:0x80061EF0; // type:function size:0xD0 checkArcExistsOnDisk__14dRawArcEntry_cFPCcPCc = .text:0x80061FC0; // type:function size:0x34 -checkArcExistsOnDiskInner__14dRawArcEntry_cFPcPCcPCc = .text:0x80062000; // type:function size:0x9C +checkArcExistsOnDiskInner__14dRawArcEntry_cFR16SizedString<128>PCcPCc = .text:0x80062000; // type:function size:0x9C mount__14dRawArcEntry_cFPCcPvPvUcPQ23EGG4Heap = .text:0x800620A0; // type:function size:0x104 ensureLoadedMaybe__14dRawArcEntry_cFPv = .text:0x800621B0; // type:function size:0x14C onMount__14dRawArcEntry_cFPv = .text:0x80062300; // type:function size:0x5C @@ -3002,23 +3002,23 @@ getCurrentStageDirectory__22CurrentStageArcManagerFv = .text:0x800696B0; // type getRoomArcDirectory__22CurrentStageArcManagerCFi = .text:0x800697E0; // type:function size:0xB0 create__22CurrentStageArcManagerFPQ23EGG4Heap = .text:0x80069890; // type:function size:0x64 __sinit_\current_stage_arc_manager_cpp = .text:0x80069900; // type:function size:0x10 scope:local -fn_80069910 = .text:0x80069910; // type:function size:0x44 -fn_80069960 = .text:0x80069960; // type:function size:0x64 -fn_800699D0 = .text:0x800699D0; // type:function size:0x14 -fn_800699F0 = .text:0x800699F0; // type:function size:0x34 -fn_80069A30 = .text:0x80069A30; // type:function size:0x48 -fn_80069A80 = .text:0x80069A80; // type:function size:0x44 -fn_80069AD0 = .text:0x80069AD0; // type:function size:0x8 -fn_80069AE0 = .text:0x80069AE0; // type:function size:0x8 -fn_80069AF0 = .text:0x80069AF0; // type:function size:0x30 -fn_80069B20 = .text:0x80069B20; // type:function size:0x8 -fn_80069B30 = .text:0x80069B30; // type:function size:0x10 -fn_80069B40 = .text:0x80069B40; // type:function size:0x10 -fn_80069B50 = .text:0x80069B50; // type:function size:0x10 -fn_80069B60 = .text:0x80069B60; // type:function size:0x178 -fn_80069CE0 = .text:0x80069CE0; // type:function size:0x178 -fn_80069E60 = .text:0x80069E60; // type:function size:0x8 -fn_80069E70 = .text:0x80069E70; // type:function size:0x64 +__ct__11OarcManagerFv = .text:0x80069910; // type:function size:0x44 +__dt__11OarcManagerFv = .text:0x80069960; // type:function size:0x64 +init__11OarcManagerFPQ23EGG4Heap = .text:0x800699D0; // type:function size:0x14 +checkIfObjectArcExistsOnDisk__11OarcManagerFPCc = .text:0x800699F0; // type:function size:0x34 +loadObjectArcFromDisk__11OarcManagerFPCcPQ23EGG4Heap = .text:0x80069A30; // type:function size:0x48 +addEntryFromSuperArc__11OarcManagerFPCcPvPQ23EGG4Heap = .text:0x80069A80; // type:function size:0x44 +ensureLoaded1__11OarcManagerFPCc = .text:0x80069AD0; // type:function size:0x8 +ensureLoaded2__11OarcManagerFPCc = .text:0x80069AE0; // type:function size:0x8 +decrement__11OarcManagerFPCc = .text:0x80069AF0; // type:function size:0x30 +getData__11OarcManagerFPCcPCc = .text:0x80069B20; // type:function size:0x8 +getMdlFromArc2__11OarcManagerFPCc = .text:0x80069B30; // type:function size:0x10 +getMdlFromArc__11OarcManagerFPCc = .text:0x80069B40; // type:function size:0x10 +getZevFromArc__11OarcManagerFPCc = .text:0x80069B50; // type:function size:0x10 +getDzbFromArc__11OarcManagerFPCcPCc = .text:0x80069B60; // type:function size:0x178 +getPlcFromArc__11OarcManagerFPCcPCc = .text:0x80069CE0; // type:function size:0x178 +getSubEntryData__11OarcManagerFPCcPCc = .text:0x80069E60; // type:function size:0x8 +create__11OarcManagerFPQ23EGG4Heap = .text:0x80069E70; // type:function size:0x64 fn_80069EE0 = .text:0x80069EE0; // type:function size:0x6C fn_80069F50 = .text:0x80069F50; // type:function size:0xC fn_80069F60 = .text:0x80069F60; // type:function size:0x88 @@ -30789,7 +30789,7 @@ lbl_8050DFF8 = .data:0x8050DFF8; // type:object size:0x9 data:string __vt__22CurrentStageArcManager = .data:0x8050E004; // type:object size:0xC lbl_8050E010 = .data:0x8050E010; // type:object size:0x10 data:string lbl_8050E020 = .data:0x8050E020; // type:object size:0xC data:string -lbl_8050E02C = .data:0x8050E02C; // type:object size:0xC +__vt__11OarcManager = .data:0x8050E02C; // type:object size:0xC lbl_8050E038 = .data:0x8050E038; // type:object size:0x10 lbl_8050E048 = .data:0x8050E048; // type:object size:0xC lbl_8050E054 = .data:0x8050E054; // type:object size:0xC @@ -35664,7 +35664,7 @@ lbl_80541980 = .data:0x80541980; // type:object size:0x28 lbl_805419A8 = .data:0x805419A8; // type:object size:0x40 lbl_805419E8 = .data:0x805419E8; // type:object size:0xC data:string lbl_805419F4 = .data:0x805419F4; // type:object size:0xC data:string -lbl_80541A00 = .data:0x80541A00; // type:object size:0x10 +@LOCAL@getModuleTypeString__20DynamicModuleControlCFv@REL_LOAD_TYPES = .data:0x80541A00; // type:object size:0x10 __vt__20DynamicModuleControl = .data:0x80541A10; // type:object size:0x30 __vt__24DynamicModuleControlBase = .data:0x80541A40; // type:object size:0x30 lbl_80541A70 = .data:0x80541A70; // type:object size:0x808 @@ -37660,11 +37660,11 @@ lbl_80571D20 = .sdata:0x80571D20; // type:object size:0x8 lbl_80571D28 = .sdata:0x80571D28; // type:object size:0x8 data:string lbl_80571D30 = .sdata:0x80571D30; // type:object size:0x7 data:string lbl_80571D38 = .sdata:0x80571D38; // type:object size:0x7 data:string -lbl_80571D40 = .sdata:0x80571D40; // type:object size:0x8 -lbl_80571D48 = .sdata:0x80571D48; // type:object size:0x8 -lbl_80571D50 = .sdata:0x80571D50; // type:object size:0x8 -lbl_80571D58 = .sdata:0x80571D58; // type:object size:0x8 -lbl_80571D60 = .sdata:0x80571D60; // type:object size:0x8 +lbl_80571D40 = .sdata:0x80571D40; // type:object size:0x7 data:string +lbl_80571D48 = .sdata:0x80571D48; // type:object size:0x5 data:string +lbl_80571D50 = .sdata:0x80571D50; // type:object size:0x5 data:string +lbl_80571D58 = .sdata:0x80571D58; // type:object size:0x5 data:string +lbl_80571D60 = .sdata:0x80571D60; // type:object size:0x5 data:string lbl_80571D68 = .sdata:0x80571D68; // type:object size:0x8 lbl_80571D70 = .sdata:0x80571D70; // type:object size:0x4 lbl_80571D74 = .sdata:0x80571D74; // type:object size:0x4 @@ -39823,7 +39823,7 @@ lbl_80575270 = .sbss:0x80575270; // type:object size:0x1 data:byte lbl_80575274 = .sbss:0x80575274; // type:object size:0x4 data:4byte sInstance__22CurrentStageArcManager = .sbss:0x80575278; // type:object size:0x4 data:4byte @GUARD@getCurrentStageDirectory__22CurrentStageArcManagerFv@sStageDirTmp = .sbss:0x8057527C; // type:object size:0x1 data:byte -lbl_80575280 = .sbss:0x80575280; // type:object size:0x8 data:4byte +sInstance__11OarcManager = .sbss:0x80575280; // type:object size:0x4 data:4byte lbl_80575288 = .sbss:0x80575288; // type:object size:0x8 data:4byte lbl_80575290 = .sbss:0x80575290; // type:object size:0x4 lbl_80575294 = .sbss:0x80575294; // type:object size:0x4 diff --git a/configure.py b/configure.py index 6db3bbcc..508f7951 100644 --- a/configure.py +++ b/configure.py @@ -293,6 +293,7 @@ config.libs = [ Object(NonMatching, "d/a/d_a_base.cpp"), Object(NonMatching, "d/a/obj/d_a_obj_base.cpp"), Object(Matching, "toBeSorted/arc_managers/current_stage_arc_manager.cpp"), + Object(Matching, "toBeSorted/arc_managers/oarc_manager.cpp"), Object(Matching, "toBeSorted/save_file.cpp"), Object(Matching, "toBeSorted/counters/counter.cpp"), Object(Matching, "toBeSorted/counters/rupee_counter.cpp"), diff --git a/include/d/d_rawarchive.h b/include/d/d_rawarchive.h index 61d048f4..53ec867a 100644 --- a/include/d/d_rawarchive.h +++ b/include/d/d_rawarchive.h @@ -19,8 +19,8 @@ public: bool destroy(void *arg); bool loadArcFromDiskChecked(const char *fileName, const char *dirName, u8 mountDirection, EGG::Heap *heap); bool loadArcFromDisk(const char *fileName, const char *dirName, u8 mountDirection, EGG::Heap *heap); - static bool checkArcExistsOnDisk(const char *fileName, const char *dirName); - static bool checkArcExistsOnDiskInner(char *outBuf, const char *fileName, const char *dirName); + static BOOL checkArcExistsOnDisk(const char *fileName, const char *dirName); + static BOOL checkArcExistsOnDiskInner(SizedString<128> &path, const char *fileName, const char *dirName); int mount(const char *name, void *data, void *callbackArg, u8 mountDirection, EGG::Heap *heap); int onMount(void *callbackArg); @@ -84,12 +84,12 @@ public: ~dRawArcTable_c(); bool init(u16 count, void *callbackArg, EGG::Heap *heap); - u32 getArcOrLoadFromDisk(const char *name, const char *dirName, u8 mountDirection, EGG::Heap *heap); - bool addEntryFromSuperArc(const char *name, void *data, u8 mountDirection, EGG::Heap *heap); + BOOL getArcOrLoadFromDisk(const char *name, const char *dirName, u8 mountDirection, EGG::Heap *heap); + BOOL addEntryFromSuperArc(const char *name, void *data, u8 mountDirection, EGG::Heap *heap); int ensureLoadedMaybe2(const char *name); int ensureLoadedMaybe(const char *name); bool hasEntry(const char *name); - u32 decreaseRefCount(const char *name); + BOOL decreaseRefCount(const char *name); void *getDataFromOarc(const char *name, const char *path); void *getSubEntryData(const char *name, const char *path); void *getLoadedArcData(const char *name); diff --git a/include/sized_string.h b/include/sized_string.h index 1d619dda..c1abcd5f 100644 --- a/include/sized_string.h +++ b/include/sized_string.h @@ -17,6 +17,10 @@ struct SizedString { mChars[0] = '\0'; } + SizedString(const char *src) { + operator=(src); + } + char mChars[Size]; char *operator&() { diff --git a/src/d/d_dvd.cpp b/src/d/d_dvd.cpp index 2f7b9cfa..3afda769 100644 --- a/src/d/d_dvd.cpp +++ b/src/d/d_dvd.cpp @@ -1,6 +1,8 @@ #include #include - +// clang-format off +#include +// clang-format on namespace dDvd { /** 800520f0 */ @@ -19,25 +21,20 @@ loader_c::loader_c() { /** 80052130 */ loader_c::~loader_c() {} -// sprintf2 -extern "C" void fn_8003D650(char *out, const char *fmt, ...); - /** 80052170 */ void *loader_c::request(const char *path, u8 mountDirection, EGG::Heap *heap) { - char buf[128]; - if (mpBuffer != nullptr) { return mpBuffer; } if (mpCommand == 0) { mSize = -1; mpHeap = heap != nullptr ? heap : mDvd::getArchiveHeap(); - buf[0] = '\0'; - fn_8003D650(buf, "US%s", path); - if (!mDvd::IsExistPath(buf)) { - fn_8003D650(buf, "%s", path); + SizedString<128> buf; + buf.sprintf("US%s", path); + if (!mDvd::IsExistPath(&buf)) { + buf.sprintf("%s", path); } - mpCommand = mDvd_toMainRam_normal_c::create(buf, mountDirection, heap); + mpCommand = mDvd_toMainRam_normal_c::create(&buf, mountDirection, heap); } if (mpCommand != nullptr && mpCommand->mStatus != 0) { mpBuffer = mpCommand->mDataPtr; diff --git a/src/d/d_rawarchive.cpp b/src/d/d_rawarchive.cpp index 9adc35b4..64bfbaa4 100644 --- a/src/d/d_rawarchive.cpp +++ b/src/d/d_rawarchive.cpp @@ -120,11 +120,10 @@ bool dRawArcEntry_c::destroy(void *arg) { bool dRawArcEntry_c::loadArcFromDiskChecked(const char *fileName, const char *dirName, u8 mountDirection, EGG::Heap *heap) { - char arcPath[128]; - arcPath[0] = '\0'; + SizedString<128> path; - if (checkArcExistsOnDiskInner(arcPath, fileName, dirName)) { - return loadArcFromDisk(fileName, arcPath, mountDirection, heap); + if (checkArcExistsOnDiskInner(path, fileName, dirName)) { + return loadArcFromDisk(fileName, &path, mountDirection, heap); } return false; } @@ -138,20 +137,19 @@ bool dRawArcEntry_c::loadArcFromDisk(const char *arcName, const char *arcPath, u return true; } -bool dRawArcEntry_c::checkArcExistsOnDisk(const char *fileName, const char *dirName) { - char path[128]; - path[0] = '\0'; +BOOL dRawArcEntry_c::checkArcExistsOnDisk(const char *fileName, const char *dirName) { + SizedString<128> path; return checkArcExistsOnDiskInner(path, fileName, dirName); } // sprintf2 extern "C" void fn_8003D650(char *out, const char *fmt, ...); -bool dRawArcEntry_c::checkArcExistsOnDiskInner(char *outBuf, const char *fileName, const char *dirName) { - fn_8003D650(outBuf, "/US/%s/%s.arc", dirName, fileName); - if (!mDvd::IsExistPath(outBuf)) { - fn_8003D650(outBuf, "/%s/%s.arc", dirName, fileName); - if (!mDvd::IsExistPath(outBuf)) { +BOOL dRawArcEntry_c::checkArcExistsOnDiskInner(SizedString<128> &path, const char *fileName, const char *dirName) { + path.sprintf("/US/%s/%s.arc", dirName, fileName); + if (!mDvd::IsExistPath(&path)) { + path.sprintf("/%s/%s.arc", dirName, fileName); + if (!mDvd::IsExistPath(&path)) { return false; } } @@ -249,7 +247,7 @@ bool dRawArcTable_c::init(u16 count, void *callbackArg, EGG::Heap *heap) { return true; } -u32 dRawArcTable_c::getArcOrLoadFromDisk(const char *name, const char *dirName, u8 mountDirection, EGG::Heap *heap) { +BOOL dRawArcTable_c::getArcOrLoadFromDisk(const char *name, const char *dirName, u8 mountDirection, EGG::Heap *heap) { dRawArcEntry_c *entry = findEntry(name); if (entry == nullptr) { entry = findEmptySlot(); @@ -266,7 +264,7 @@ u32 dRawArcTable_c::getArcOrLoadFromDisk(const char *name, const char *dirName, return true; } -bool dRawArcTable_c::addEntryFromSuperArc(const char *name, void *data, u8 mountDirection, EGG::Heap *heap) { +BOOL dRawArcTable_c::addEntryFromSuperArc(const char *name, void *data, u8 mountDirection, EGG::Heap *heap) { dRawArcEntry_c *entry = findEntry(name); if (entry == nullptr) { entry = findEmptySlot(); @@ -303,7 +301,7 @@ bool dRawArcTable_c::hasEntry(const char *name) { return findEntry(name) != nullptr; } -u32 dRawArcTable_c::decreaseRefCount(const char *name) { +BOOL dRawArcTable_c::decreaseRefCount(const char *name) { dRawArcEntry_c *entry = findEntry(name); if (entry == nullptr) { return false; diff --git a/src/toBeSorted/arc_managers/current_stage_arc_manager.cpp b/src/toBeSorted/arc_managers/current_stage_arc_manager.cpp index 87b1dd91..0e1d7111 100644 --- a/src/toBeSorted/arc_managers/current_stage_arc_manager.cpp +++ b/src/toBeSorted/arc_managers/current_stage_arc_manager.cpp @@ -54,8 +54,6 @@ void CurrentStageArcManager::init(EGG::Heap *heap) { mArcTable.init(18, &lbl_80575250, heap); } -// sprintf -extern "C" void fn_8001F820(char *str, const char *src, ...); bool CurrentStageArcManager::setStage(const char *newStage) { mStageName = newStage; diff --git a/src/toBeSorted/arc_managers/oarc_manager.cpp b/src/toBeSorted/arc_managers/oarc_manager.cpp new file mode 100644 index 00000000..61a3b650 --- /dev/null +++ b/src/toBeSorted/arc_managers/oarc_manager.cpp @@ -0,0 +1,124 @@ +#include +#include +#include +// clang-format off +#include +// clang-format on + +class OarcManager { + OarcManager(); + virtual ~OarcManager(); + + dRawArcTable_c mArcTable; + + static OarcManager *sInstance; + + static bool create(EGG::Heap *heap); + + void init(EGG::Heap *heap); + + bool checkIfObjectArcExistsOnDisk(const char *object); + bool loadObjectArcFromDisk(const char *object, EGG::Heap *heap); + bool addEntryFromSuperArc(const char *object, void *data, EGG::Heap *heap); + void ensureLoaded1(const char *object); + void ensureLoaded2(const char *object); + bool decrement(const char *path); + void *getData(const char *oarcName, const char *fileName); + + void *getMdlFromArc2(const char *oarcName); + void *getMdlFromArc(const char *oarcName); + void *getZevFromArc(const char *oarcName); + void *getDzbFromArc(const char *oarcName, const char *fileName); + void *getPlcFromArc(const char *oarcName, const char *fileName); + void *getSubEntryData(const char *oarcName, const char *fileName); +}; + +OarcManager *OarcManager::sInstance; + +OarcManager::OarcManager() { + sInstance = this; +} + +OarcManager::~OarcManager() { + sInstance = nullptr; +} + +extern char lbl_80575250; + +void OarcManager::init(EGG::Heap *heap) { + mArcTable.init(200, &lbl_80575250, heap); +} + +bool OarcManager::checkIfObjectArcExistsOnDisk(const char *object) { + return dRawArcEntry_c::checkArcExistsOnDisk(object, "Object"); +} + +bool OarcManager::loadObjectArcFromDisk(const char *object, EGG::Heap *heap) { + if (heap == nullptr) { + heap = dHeap::work2Heap.heap; + } + return mArcTable.getArcOrLoadFromDisk(object, "Object", 0, heap); +} + +bool OarcManager::addEntryFromSuperArc(const char *object, void *data, EGG::Heap *heap) { + if (heap == nullptr) { + heap = EGG::Heap::sCurrentHeap; + } + return mArcTable.addEntryFromSuperArc(object, data, 0, heap); +} + +void OarcManager::ensureLoaded1(const char *object) { + mArcTable.ensureLoadedMaybe2(object); +} + +void OarcManager::ensureLoaded2(const char *object) { + mArcTable.ensureLoadedMaybe(object); +} + +bool OarcManager::decrement(const char *path) { + return mArcTable.decreaseRefCount(path); +} + +void *OarcManager::getData(const char *oarcName, const char *fileName) { + return mArcTable.getDataFromOarc(oarcName, fileName); +} + +void *OarcManager::getMdlFromArc2(const char *oarcName) { + return mArcTable.getDataFromOarc(oarcName, "g3d/model.brres"); +} + +void *OarcManager::getMdlFromArc(const char *oarcName) { + return mArcTable.getSubEntryData(oarcName, "g3d/model.brres"); +} + +void *OarcManager::getZevFromArc(const char *oarcName) { + return mArcTable.getDataFromOarc(oarcName, "dat/zev.dat"); +} + +void *OarcManager::getDzbFromArc(const char *oarcName, const char *fileName) { + SizedString<32> str = "dzb/"; + str += fileName; + str += ".dzb"; + return mArcTable.getDataFromOarc(oarcName, &str); +} + +void *OarcManager::getPlcFromArc(const char *oarcName, const char *fileName) { + SizedString<32> str = "dat/"; + str += fileName; + str += ".plc"; + return mArcTable.getDataFromOarc(oarcName, &str); +} + +void *OarcManager::getSubEntryData(const char *oarcName, const char *fileName) { + return mArcTable.getSubEntryData(oarcName, fileName); +} + +bool OarcManager::create(EGG::Heap *heap) { + new (heap, 0x04) OarcManager(); + + if (OarcManager::sInstance == nullptr) { + return false; + } + OarcManager::sInstance->init(heap); + return true; +} From 7d8831508e72c43ab5bac9e03d79256ede991a30 Mon Sep 17 00:00:00 2001 From: robojumper Date: Wed, 29 May 2024 23:02:12 +0200 Subject: [PATCH 13/20] Layout arc manager --- config/SOUE01/splits.txt | 6 ++ config/SOUE01/symbols.txt | 28 +++---- configure.py | 1 + .../arc_managers/layout_arc_manager.cpp | 84 +++++++++++++++++++ 4 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 src/toBeSorted/arc_managers/layout_arc_manager.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 821c6294..780ca726 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -133,6 +133,12 @@ toBeSorted/arc_managers/oarc_manager.cpp: .sdata start:0x80571D40 end:0x80571D68 .sbss start:0x80575280 end:0x80575288 +toBeSorted/arc_managers/layout_arc_manager.cpp: + .text start:0x8006A0C0 end:0x8006A2D4 + .data start:0x8050E048 end:0x8050E054 + .sdata start:0x80571D68 end:0x80571D70 + .sbss start:0x80575288 end:0x80575290 + toBeSorted/sceneflag_manager.cpp: .text start:0x800BD8C0 end:0x800BE7A8 .sbss start:0x805753E0 end:0x805753F0 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index e92c1510..309f9c48 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -3023,17 +3023,17 @@ fn_80069EE0 = .text:0x80069EE0; // type:function size:0x6C fn_80069F50 = .text:0x80069F50; // type:function size:0xC fn_80069F60 = .text:0x80069F60; // type:function size:0x88 fn_80069FF0 = .text:0x80069FF0; // type:function size:0xC4 -fn_8006A0C0 = .text:0x8006A0C0; // type:function size:0x44 -fn_8006A110 = .text:0x8006A110; // type:function size:0x64 -fn_8006A180 = .text:0x8006A180; // type:function size:0x14 -fn_8006A1A0 = .text:0x8006A1A0; // type:function size:0x48 -fn_8006A1F0 = .text:0x8006A1F0; // type:function size:0x8 -fn_8006A200 = .text:0x8006A200; // type:function size:0x8 -fn_8006A210 = .text:0x8006A210; // type:function size:0x8 -fn_8006A220 = .text:0x8006A220; // type:function size:0x30 -fn_8006A250 = .text:0x8006A250; // type:function size:0x8 -fn_8006A260 = .text:0x8006A260; // type:function size:0x8 -fn_8006A270 = .text:0x8006A270; // type:function size:0x64 +__ct__16LayoutArcManagerFv = .text:0x8006A0C0; // type:function size:0x44 +__dt__16LayoutArcManagerFv = .text:0x8006A110; // type:function size:0x64 +init__16LayoutArcManagerFPQ23EGG4Heap = .text:0x8006A180; // type:function size:0x14 +loadLayoutArcFromDisk__16LayoutArcManagerFPCcPQ23EGG4Heap = .text:0x8006A1A0; // type:function size:0x48 +ensureLoaded1__16LayoutArcManagerFPCc = .text:0x8006A1F0; // type:function size:0x8 +ensureLoaded2__16LayoutArcManagerFPCc = .text:0x8006A200; // type:function size:0x8 +hasEntry__16LayoutArcManagerFPCc = .text:0x8006A210; // type:function size:0x8 +decrement__16LayoutArcManagerFPCc = .text:0x8006A220; // type:function size:0x30 +getData__16LayoutArcManagerFPCcPCc = .text:0x8006A250; // type:function size:0x8 +getLoadedData__16LayoutArcManagerFPCc = .text:0x8006A260; // type:function size:0x8 +create__16LayoutArcManagerFPQ23EGG4Heap = .text:0x8006A270; // type:function size:0x64 fn_8006A2E0 = .text:0x8006A2E0; // type:function size:0x6C fn_8006A350 = .text:0x8006A350; // type:function size:0xC fn_8006A360 = .text:0x8006A360; // type:function size:0x88 @@ -30791,7 +30791,7 @@ lbl_8050E010 = .data:0x8050E010; // type:object size:0x10 data:string lbl_8050E020 = .data:0x8050E020; // type:object size:0xC data:string __vt__11OarcManager = .data:0x8050E02C; // type:object size:0xC lbl_8050E038 = .data:0x8050E038; // type:object size:0x10 -lbl_8050E048 = .data:0x8050E048; // type:object size:0xC +__vt__16LayoutArcManager = .data:0x8050E048; // type:object size:0xC lbl_8050E054 = .data:0x8050E054; // type:object size:0xC lbl_8050E060 = .data:0x8050E060; // type:object size:0x30 lbl_8050E090 = .data:0x8050E090; // type:object size:0x2FC @@ -37665,7 +37665,7 @@ lbl_80571D48 = .sdata:0x80571D48; // type:object size:0x5 data:string lbl_80571D50 = .sdata:0x80571D50; // type:object size:0x5 data:string lbl_80571D58 = .sdata:0x80571D58; // type:object size:0x5 data:string lbl_80571D60 = .sdata:0x80571D60; // type:object size:0x5 data:string -lbl_80571D68 = .sdata:0x80571D68; // type:object size:0x8 +lbl_80571D68 = .sdata:0x80571D68; // type:object size:0x7 data:string lbl_80571D70 = .sdata:0x80571D70; // type:object size:0x4 lbl_80571D74 = .sdata:0x80571D74; // type:object size:0x4 lbl_80571D78 = .sdata:0x80571D78; // type:object size:0x4 data:wstring @@ -39824,7 +39824,7 @@ lbl_80575274 = .sbss:0x80575274; // type:object size:0x4 data:4byte sInstance__22CurrentStageArcManager = .sbss:0x80575278; // type:object size:0x4 data:4byte @GUARD@getCurrentStageDirectory__22CurrentStageArcManagerFv@sStageDirTmp = .sbss:0x8057527C; // type:object size:0x1 data:byte sInstance__11OarcManager = .sbss:0x80575280; // type:object size:0x4 data:4byte -lbl_80575288 = .sbss:0x80575288; // type:object size:0x8 data:4byte +sInstance__16LayoutArcManager = .sbss:0x80575288; // type:object size:0x8 data:4byte lbl_80575290 = .sbss:0x80575290; // type:object size:0x4 lbl_80575294 = .sbss:0x80575294; // type:object size:0x4 lbl_80575298 = .sbss:0x80575298; // type:object size:0x4 data:4byte diff --git a/configure.py b/configure.py index 508f7951..89ec3c98 100644 --- a/configure.py +++ b/configure.py @@ -294,6 +294,7 @@ config.libs = [ Object(NonMatching, "d/a/obj/d_a_obj_base.cpp"), Object(Matching, "toBeSorted/arc_managers/current_stage_arc_manager.cpp"), Object(Matching, "toBeSorted/arc_managers/oarc_manager.cpp"), + Object(Matching, "toBeSorted/arc_managers/layout_arc_manager.cpp"), Object(Matching, "toBeSorted/save_file.cpp"), Object(Matching, "toBeSorted/counters/counter.cpp"), Object(Matching, "toBeSorted/counters/rupee_counter.cpp"), diff --git a/src/toBeSorted/arc_managers/layout_arc_manager.cpp b/src/toBeSorted/arc_managers/layout_arc_manager.cpp new file mode 100644 index 00000000..6c38803f --- /dev/null +++ b/src/toBeSorted/arc_managers/layout_arc_manager.cpp @@ -0,0 +1,84 @@ +#include +#include +#include +// clang-format off +#include +// clang-format on + +class LayoutArcManager { + LayoutArcManager(); + virtual ~LayoutArcManager(); + + dRawArcTable_c mArcTable; + + static LayoutArcManager *sInstance; + + static bool create(EGG::Heap *heap); + + void init(EGG::Heap *heap); + + bool loadLayoutArcFromDisk(const char *object, EGG::Heap *heap); + void ensureLoaded1(const char *object); + void ensureLoaded2(const char *object); + bool hasEntry(const char *object); + bool decrement(const char *path); + void *getData(const char *oarcName, const char *fileName); + void *getLoadedData(const char *path); +}; + +LayoutArcManager *LayoutArcManager::sInstance; + +LayoutArcManager::LayoutArcManager() { + sInstance = this; +} + +LayoutArcManager::~LayoutArcManager() { + sInstance = nullptr; +} + +extern char lbl_80575250; + +void LayoutArcManager::init(EGG::Heap *heap) { + mArcTable.init(16, &lbl_80575250, heap); +} + +bool LayoutArcManager::loadLayoutArcFromDisk(const char *object, EGG::Heap *heap) { + if (heap == nullptr) { + heap = dHeap::layoutResHeap.heap; + } + return mArcTable.getArcOrLoadFromDisk(object, "Layout", 0, heap); +} + +void LayoutArcManager::ensureLoaded1(const char *object) { + mArcTable.ensureLoadedMaybe2(object); +} + +void LayoutArcManager::ensureLoaded2(const char *object) { + mArcTable.ensureLoadedMaybe(object); +} + +bool LayoutArcManager::hasEntry(const char *object) { + return mArcTable.hasEntry(object); +} + +bool LayoutArcManager::decrement(const char *path) { + return mArcTable.decreaseRefCount(path); +} + +void *LayoutArcManager::getData(const char *oarcName, const char *fileName) { + return mArcTable.getDataFromOarc(oarcName, fileName); +} + +void *LayoutArcManager::getLoadedData(const char *path) { + return mArcTable.getLoadedArcData(path); +} + +bool LayoutArcManager::create(EGG::Heap *heap) { + new (heap, 0x04) LayoutArcManager(); + + if (LayoutArcManager::sInstance == nullptr) { + return false; + } + LayoutArcManager::sInstance->init(heap); + return true; +} From 8d6e8826d33956a78cd553c5200ce79aeeecc38a Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 2 Jun 2024 00:13:33 +0200 Subject: [PATCH 14/20] Headers --- .../arc_managers/current_stage_arc_manager.h | 41 ++++++++++++++++++ .../arc_managers/layout_arc_manager.h | 29 +++++++++++++ .../toBeSorted/arc_managers/oarc_manager.h | 36 ++++++++++++++++ .../current_stage_arc_manager.cpp | 43 ++----------------- .../arc_managers/layout_arc_manager.cpp | 27 +----------- src/toBeSorted/arc_managers/oarc_manager.cpp | 34 +-------------- 6 files changed, 111 insertions(+), 99 deletions(-) create mode 100644 include/toBeSorted/arc_managers/current_stage_arc_manager.h create mode 100644 include/toBeSorted/arc_managers/layout_arc_manager.h create mode 100644 include/toBeSorted/arc_managers/oarc_manager.h diff --git a/include/toBeSorted/arc_managers/current_stage_arc_manager.h b/include/toBeSorted/arc_managers/current_stage_arc_manager.h new file mode 100644 index 00000000..f4f11ce5 --- /dev/null +++ b/include/toBeSorted/arc_managers/current_stage_arc_manager.h @@ -0,0 +1,41 @@ +#ifndef CURRENT_STAGE_ARC_MANAGER_H +#define CURRENT_STAGE_ARC_MANAGER_H + +#include +#include +#include + +class CurrentStageArcManager { + CurrentStageArcManager(); + virtual ~CurrentStageArcManager(); + + SizedString<32> mStageName; + SizedString<32> mCurrentLoadingStageArcName; + SizedString<32> mStageExtraLayerArcName; + + dRawArcTable_c mArcTable; + + static CurrentStageArcManager *sInstance; + + static bool create(EGG::Heap *heap); + + void init(EGG::Heap *heap); + bool setStage(const char *stage); + bool decrement(); + void *getData(const char *fileName); + void *getFileFromCurrentLay0Arc(const char *fileName); + bool loadFileFromExtraLayerArc(int layer); + bool unloadExtraLayerArc(); + bool loadRoomArc(int room); + bool addEntryFromSuperArc(const char *name, void *data); + bool unloadRoomArc(int room); + bool decrement(const char *path); + void *loadFromRoomArc(int roomId, const char *fileName); + void *getDataFromRoomArc(int roomId, const char *fileName); + const char *getCurrentStageDirectory(); + const char *getRoomArcDirectory(int room) const; + + static EGG::ExpHeap *getHeap(); +}; + +#endif diff --git a/include/toBeSorted/arc_managers/layout_arc_manager.h b/include/toBeSorted/arc_managers/layout_arc_manager.h new file mode 100644 index 00000000..0534cf2f --- /dev/null +++ b/include/toBeSorted/arc_managers/layout_arc_manager.h @@ -0,0 +1,29 @@ +#ifndef LAYOUT_ARC_MANAGER_H +#define LAYOUT_ARC_MANAGER_H + +#include +#include +#include + +class LayoutArcManager { + LayoutArcManager(); + virtual ~LayoutArcManager(); + + dRawArcTable_c mArcTable; + + static LayoutArcManager *sInstance; + + static bool create(EGG::Heap *heap); + + void init(EGG::Heap *heap); + + bool loadLayoutArcFromDisk(const char *object, EGG::Heap *heap); + void ensureLoaded1(const char *object); + void ensureLoaded2(const char *object); + bool hasEntry(const char *object); + bool decrement(const char *path); + void *getData(const char *oarcName, const char *fileName); + void *getLoadedData(const char *path); +}; + +#endif diff --git a/include/toBeSorted/arc_managers/oarc_manager.h b/include/toBeSorted/arc_managers/oarc_manager.h new file mode 100644 index 00000000..96c7e0d7 --- /dev/null +++ b/include/toBeSorted/arc_managers/oarc_manager.h @@ -0,0 +1,36 @@ +#ifndef OARC_MANAGER_H +#define OARC_MANAGER_H + +#include +#include +#include + +class OarcManager { + OarcManager(); + virtual ~OarcManager(); + + dRawArcTable_c mArcTable; + + static OarcManager *sInstance; + + static bool create(EGG::Heap *heap); + + void init(EGG::Heap *heap); + + bool checkIfObjectArcExistsOnDisk(const char *object); + bool loadObjectArcFromDisk(const char *object, EGG::Heap *heap); + bool addEntryFromSuperArc(const char *object, void *data, EGG::Heap *heap); + void ensureLoaded1(const char *object); + void ensureLoaded2(const char *object); + bool decrement(const char *path); + void *getData(const char *oarcName, const char *fileName); + + void *getMdlFromArc2(const char *oarcName); + void *getMdlFromArc(const char *oarcName); + void *getZevFromArc(const char *oarcName); + void *getDzbFromArc(const char *oarcName, const char *fileName); + void *getPlcFromArc(const char *oarcName, const char *fileName); + void *getSubEntryData(const char *oarcName, const char *fileName); +}; + +#endif diff --git a/src/toBeSorted/arc_managers/current_stage_arc_manager.cpp b/src/toBeSorted/arc_managers/current_stage_arc_manager.cpp index 0e1d7111..f7e26c3d 100644 --- a/src/toBeSorted/arc_managers/current_stage_arc_manager.cpp +++ b/src/toBeSorted/arc_managers/current_stage_arc_manager.cpp @@ -1,42 +1,5 @@ #include -#include -#include -// clang-format off -#include -// clang-format on - -class CurrentStageArcManager { - CurrentStageArcManager(); - virtual ~CurrentStageArcManager(); - - SizedString<32> mStageName; - SizedString<32> mCurrentLoadingStageArcName; - SizedString<32> mStageExtraLayerArcName; - - dRawArcTable_c mArcTable; - - static CurrentStageArcManager *sInstance; - - static bool create(EGG::Heap *heap); - - void init(EGG::Heap *heap); - bool setStage(const char *stage); - bool decrement(); - void *getData(const char *fileName); - void *getFileFromCurrentLay0Arc(const char *fileName); - bool loadFileFromExtraLayerArc(int layer); - bool unloadExtraLayerArc(); - bool loadRoomArc(int room); - bool addEntryFromSuperArc(const char *name, void *data); - bool unloadRoomArc(int room); - bool decrement(const char *path); - void *loadFromRoomArc(int roomId, const char *fileName); - void *getDataFromRoomArc(int roomId, const char *fileName); - const char *getCurrentStageDirectory(); - const char *getRoomArcDirectory(int room) const; - - static EGG::ExpHeap *getHeap(); -}; +#include CurrentStageArcManager *CurrentStageArcManager::sInstance; @@ -54,7 +17,6 @@ void CurrentStageArcManager::init(EGG::Heap *heap) { mArcTable.init(18, &lbl_80575250, heap); } - bool CurrentStageArcManager::setStage(const char *newStage) { mStageName = newStage; @@ -103,7 +65,8 @@ bool CurrentStageArcManager::unloadExtraLayerArc() { } bool CurrentStageArcManager::loadRoomArc(int room) { - return (bool)mArcTable.getArcOrLoadFromDisk(getRoomArcDirectory(room), getCurrentStageDirectory(), 0, dHeap::work2Heap.heap); + return (bool)mArcTable.getArcOrLoadFromDisk(getRoomArcDirectory(room), getCurrentStageDirectory(), 0, + dHeap::work2Heap.heap); } bool CurrentStageArcManager::addEntryFromSuperArc(const char *path, void *data) { diff --git a/src/toBeSorted/arc_managers/layout_arc_manager.cpp b/src/toBeSorted/arc_managers/layout_arc_manager.cpp index 6c38803f..308a6118 100644 --- a/src/toBeSorted/arc_managers/layout_arc_manager.cpp +++ b/src/toBeSorted/arc_managers/layout_arc_manager.cpp @@ -1,30 +1,5 @@ #include -#include -#include -// clang-format off -#include -// clang-format on - -class LayoutArcManager { - LayoutArcManager(); - virtual ~LayoutArcManager(); - - dRawArcTable_c mArcTable; - - static LayoutArcManager *sInstance; - - static bool create(EGG::Heap *heap); - - void init(EGG::Heap *heap); - - bool loadLayoutArcFromDisk(const char *object, EGG::Heap *heap); - void ensureLoaded1(const char *object); - void ensureLoaded2(const char *object); - bool hasEntry(const char *object); - bool decrement(const char *path); - void *getData(const char *oarcName, const char *fileName); - void *getLoadedData(const char *path); -}; +#include LayoutArcManager *LayoutArcManager::sInstance; diff --git a/src/toBeSorted/arc_managers/oarc_manager.cpp b/src/toBeSorted/arc_managers/oarc_manager.cpp index 61a3b650..f791bb76 100644 --- a/src/toBeSorted/arc_managers/oarc_manager.cpp +++ b/src/toBeSorted/arc_managers/oarc_manager.cpp @@ -1,37 +1,5 @@ #include -#include -#include -// clang-format off -#include -// clang-format on - -class OarcManager { - OarcManager(); - virtual ~OarcManager(); - - dRawArcTable_c mArcTable; - - static OarcManager *sInstance; - - static bool create(EGG::Heap *heap); - - void init(EGG::Heap *heap); - - bool checkIfObjectArcExistsOnDisk(const char *object); - bool loadObjectArcFromDisk(const char *object, EGG::Heap *heap); - bool addEntryFromSuperArc(const char *object, void *data, EGG::Heap *heap); - void ensureLoaded1(const char *object); - void ensureLoaded2(const char *object); - bool decrement(const char *path); - void *getData(const char *oarcName, const char *fileName); - - void *getMdlFromArc2(const char *oarcName); - void *getMdlFromArc(const char *oarcName); - void *getZevFromArc(const char *oarcName); - void *getDzbFromArc(const char *oarcName, const char *fileName); - void *getPlcFromArc(const char *oarcName, const char *fileName); - void *getSubEntryData(const char *oarcName, const char *fileName); -}; +#include OarcManager *OarcManager::sInstance; From 5d9ca41e213c91629ebd6ffa9f748d81aac97489 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 2 Jun 2024 01:03:41 +0200 Subject: [PATCH 15/20] Fix return types --- include/d/a/obj/d_a_obj_base.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/d/a/obj/d_a_obj_base.h b/include/d/a/obj/d_a_obj_base.h index c46e92a9..77fbd8a1 100644 --- a/include/d/a/obj/d_a_obj_base.h +++ b/include/d/a/obj/d_a_obj_base.h @@ -49,9 +49,9 @@ public: /* 8002ea20 */ virtual bool drop(); public: - /* 8002e630 */ static void create(fProfile::PROFILE_NAME_e actorId, s8 roomId, u32 params1, mVec3_c *pos, + /* 8002e630 */ static dAcObjBase_c *create(fProfile::PROFILE_NAME_e actorId, s8 roomId, u32 params1, mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, u32 params2); - /* 8002e6d0 */ static void create(char *name, u32 roomId, u32 params1, mVec3_c *pos, mAng3_c *rot, + /* 8002e6d0 */ static dAcObjBase_c *create(char *name, u32 roomId, u32 params1, mVec3_c *pos, mAng3_c *rot, mVec3_c *scale, u32 params2, u16 id, u8 viewclipId); /* 8002e770 */ static dAcObjBase_c *findObject(fProfile::PROFILE_NAME_e actorId, fLiNdBa_c *refList, dAcObjBase_c *parent); From be50ec23ad026295af85f26a7f23740c8ea4173d Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 7 Jun 2024 13:14:55 +0200 Subject: [PATCH 16/20] REL sieve --- tools/rel_sieve.py | 83 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tools/rel_sieve.py diff --git a/tools/rel_sieve.py b/tools/rel_sieve.py new file mode 100644 index 00000000..047bb49d --- /dev/null +++ b/tools/rel_sieve.py @@ -0,0 +1,83 @@ +""" +REL Sieve finds RELs that are good candidates for matching. + +RELs have a bunch of dependencies on the main DOL, not all of which are +decomped or have correct headers set up yet, so we can't start matching every +REL right now. The REL sieve finds rels where dependencies *are* set up already +and suggests good candidates for matching. + +The approach is that we start with the assumption that every REL *can* be matched +right now, and then when you look at a REL you may find dependencies that block +this REL (usually in terms of a function call). You then add this function label +to the list in this file and re-run the script, at which point this REL and any others +that call this function will be filtered out. You then repeat the process until +you find a REL you can somewhat easily match. + +When a system in the DOL becomes available (via headers or a full-on decomp) you +can remove the corresponding function label here and more RELs may become available. +Of course, some of these RELs may have other dependencies, which you can then add etc. + +The hope is that this helps us keep an overview over which RELs can be matched and +which DOL systems are good candidates for decomping. +""" + +import glob +import os +import pathlib + +BLOCKING_SYMBOLS = [ + ['fn_80353D70', 'UnkCollider::ctor'], + ['fn_80353F30', 'UnkCollider::ctor2'], + ['fn_80353FF0', 'UnkCollider::init'], + ['fn_800C3EC0', 'ActorEventFlowManagerRelated::checkEventFinished'], + ['fn_802E6000', 'mdlAnmChr_c::create'], + ['fn_802EB6F0', 'm3d::mdl_c::mdl_c'], + ['fn_802EDF30', 'm3d::smdl_c::smdl_c'], + ['fn_800275C0', 'EffectsStruct::ctor'], + ['fn_80027610', 'EffectsStruct::ctor'], + ['fn_803465D0', 'ActorCollision::ctor'], + ['fn_80341A70', 'checkCollision'], + ['fn_80016C10', 'AnimModelWrapper::ctor'], + ['fn_802EBBD0', 'm3d::scnLeaf_c::scnLeaf_c'], + ['fn_8009C910', 'ActorEventRelated::ctor'], + ['fn_802E32B0', 'm2d::FrameCtrl_c::setFrame'], + ['fn_802F04A0', 'mFader_c::draw'], + ['fn_801695F0', 'LytCommonTitle::ctor'], + ['fn_80067020', 'matrixCreateFromPosRotYScale'], + ['fn_800C43D0', 'ActorEventFlowManagerRelated *FUN_800c43d0'], + ['fn_801BB3C0', 'isCurrentStage'], + ['fn_8037DCC0', 'EnemySoundMgr'], + ['fn_800A6690', 'ActorOnRail::ctor'], + ['fn_80355080', 'getColliderManager'], + ['fn_800975D0', 'initializeDowsingTarget'], + ['fn_800A0680', 'getCurrentEventActor'], + ['fn_80390FE0', 'something harp sound'], + ['fn_801BB6F0', 'getCamera'], + ['fn_800225F0', 'something light'], + ['fn_80179250', 'shutter fence list'], +] + +def main(): + data = {} + for folder in os.listdir('./build/SOUE01'): + if folder.startswith('d_'): + data[folder] = [] + s_files = glob.glob(f'./build/SOUE01/{folder}/asm/REL/d/**/*.s', recursive=True) + # maybe won't be true at some point? + assert len(s_files) == 1 + text = pathlib.Path(s_files[0]).read_text() + for [sym, comment] in BLOCKING_SYMBOLS: + if sym in text: + data[folder].append(comment) + + + output = sorted([ + [rel, deps] for rel, deps in data.items() + ], key=lambda x: -len(x[1])) + + for [rel, deps] in output: + print(rel + ':', ", ".join(deps) if len(deps) else "No unidentified dependencies! Go decomp this REL, or add a blocker to this script") + + +if __name__ == "__main__": + main() From 545356024567b0a53a81ea114f146b885a82d4f0 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 7 Jun 2024 14:20:14 +0200 Subject: [PATCH 17/20] exclude matched RELs --- tools/rel_sieve.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/rel_sieve.py b/tools/rel_sieve.py index 047bb49d..03363b6c 100644 --- a/tools/rel_sieve.py +++ b/tools/rel_sieve.py @@ -22,6 +22,7 @@ which DOL systems are good candidates for decomping. """ import glob +import json import os import pathlib @@ -58,9 +59,15 @@ BLOCKING_SYMBOLS = [ ] def main(): + matched_names = set() + with open('./objdiff.json') as f: + objdiff = json.load(f) + for unit in objdiff["units"]: + if unit.get("complete", False): + matched_names.add(unit["name"].split('/')[-1]) data = {} for folder in os.listdir('./build/SOUE01'): - if folder.startswith('d_'): + if folder.startswith('d_') and not folder[:-2] in matched_names: data[folder] = [] s_files = glob.glob(f'./build/SOUE01/{folder}/asm/REL/d/**/*.s', recursive=True) # maybe won't be true at some point? From 9bed59fae53fb70725da6a8aaf7f2c3a40007709 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 7 Jun 2024 18:34:33 +0200 Subject: [PATCH 18/20] Reword --- tools/rel_sieve.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/rel_sieve.py b/tools/rel_sieve.py index 03363b6c..e8b160bd 100644 --- a/tools/rel_sieve.py +++ b/tools/rel_sieve.py @@ -83,7 +83,7 @@ def main(): ], key=lambda x: -len(x[1])) for [rel, deps] in output: - print(rel + ':', ", ".join(deps) if len(deps) else "No unidentified dependencies! Go decomp this REL, or add a blocker to this script") + print(rel + ':', ", ".join(deps) if len(deps) else "No identified blockers! Go decomp this REL, or add a blocker to this script") if __name__ == "__main__": From ce606a10e48c5f6be661bac54de153e4a33a0d13 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 8 Jun 2024 20:10:37 +0200 Subject: [PATCH 19/20] d_t_counter --- config/SOUE01/rels/d_t_timerNP/splits.txt | 3 +- config/SOUE01/rels/d_t_timerNP/symbols.txt | 43 ++++----- configure.py | 2 +- include/d/tg/d_t_timer.h | 41 +++++++++ include/toBeSorted/sceneflag_manager.h | 63 +++++++++++++ src/REL/d/t/d_t_timer.cpp | 100 +++++++++++++++++++++ src/toBeSorted/sceneflag_manager.cpp | 60 +------------ 7 files changed, 231 insertions(+), 81 deletions(-) create mode 100644 include/d/tg/d_t_timer.h create mode 100644 include/toBeSorted/sceneflag_manager.h diff --git a/config/SOUE01/rels/d_t_timerNP/splits.txt b/config/SOUE01/rels/d_t_timerNP/splits.txt index 94400ef5..1601c0cd 100644 --- a/config/SOUE01/rels/d_t_timerNP/splits.txt +++ b/config/SOUE01/rels/d_t_timerNP/splits.txt @@ -2,7 +2,7 @@ Sections: .text type:code align:16 .ctors type:rodata align:4 .dtors type:rodata align:4 - .rodata type:rodata align:8 + .data type:data align:8 .bss type:bss align:8 REL/executor.c: @@ -10,3 +10,4 @@ REL/executor.c: REL/d/t/d_t_timer.cpp: .text start:0x00000070 end:0x000004CC + .data start:0x00000000 end:0x0000011C diff --git a/config/SOUE01/rels/d_t_timerNP/symbols.txt b/config/SOUE01/rels/d_t_timerNP/symbols.txt index 3a383e26..a6825912 100644 --- a/config/SOUE01/rels/d_t_timerNP/symbols.txt +++ b/config/SOUE01/rels/d_t_timerNP/symbols.txt @@ -1,26 +1,27 @@ _prolog = .text:0x00000000; // type:function size:0x2C scope:global _epilog = .text:0x00000030; // type:function size:0x2C scope:global _unresolved = .text:0x00000060; // type:function size:0x4 scope:global -fn_506_70 = .text:0x00000070; // type:function size:0x4C -fn_506_C0 = .text:0x000000C0; // type:function size:0x58 -fn_506_120 = .text:0x00000120; // type:function size:0x24 -fn_506_150 = .text:0x00000150; // type:function size:0xD4 -fn_506_230 = .text:0x00000230; // type:function size:0xB8 -fn_506_2F0 = .text:0x000002F0; // type:function size:0xC -fn_506_300 = .text:0x00000300; // type:function size:0xC -fn_506_310 = .text:0x00000310; // type:function size:0xC -fn_506_320 = .text:0x00000320; // type:function size:0xC -fn_506_330 = .text:0x00000330; // type:function size:0x8 -fn_506_340 = .text:0x00000340; // type:function size:0x8 -fn_506_350 = .text:0x00000350; // type:function size:0x8 -fn_506_360 = .text:0x00000360; // type:function size:0x28 -fn_506_390 = .text:0x00000390; // type:function size:0x8 -fn_506_3A0 = .text:0x000003A0; // type:function size:0x44 -fn_506_3F0 = .text:0x000003F0; // type:function size:0x58 -fn_506_450 = .text:0x00000450; // type:function size:0x8 -fn_506_460 = .text:0x00000460; // type:function size:0x4 -fn_506_470 = .text:0x00000470; // type:function size:0x5C +dTgTimer_c_classInit__Fv = .text:0x00000070; // type:function size:0x4C +__dt__14dTgTimerBase_cFv = .text:0x000000C0; // type:function size:0x58 +increment__FPUs = .text:0x00000120; // type:function size:0x24 +create__10dTgTimer_cFv = .text:0x00000150; // type:function size:0xD4 +actorExecute__10dTgTimer_cFv = .text:0x00000230; // type:function size:0xB8 +getSubtypeFromParams__10dTgTimer_cFv = .text:0x000002F0; // type:function size:0xC +getTimerFromParams__10dTgTimer_cFv = .text:0x00000300; // type:function size:0xC +getCheckSceneflag__10dTgTimer_cFv = .text:0x00000310; // type:function size:0xC +getSetSceneflag__10dTgTimer_cFv = .text:0x00000320; // type:function size:0xC +getTimer__10dTgTimer_cFv = .text:0x00000330; // type:function size:0x8 +getConstant0x50__10dTgTimer_cFv = .text:0x00000340; // type:function size:0x8 +setTimer__10dTgTimer_cFUs = .text:0x00000350; // type:function size:0x8 +getTargetTime__10dTgTimer_cFv = .text:0x00000360; // type:function size:0x28 +resetTimer__10dTgTimer_cFv = .text:0x00000390; // type:function size:0x8 +incrementTimer__10dTgTimer_cFv = .text:0x000003A0; // type:function size:0x44 +checkShouldTrigger__10dTgTimer_cFv = .text:0x000003F0; // type:function size:0x58 +getStoredTargetTime__10dTgTimer_cFv = .text:0x00000450; // type:function size:0x8 +getConstant0x50_Thunk__10dTgTimer_cFv = .text:0x00000460; // type:function size:0x4 +__dt__10dTgTimer_cFv = .text:0x00000470; // type:function size:0x5C _ctors = .ctors:0x00000000; // type:label scope:global _dtors = .dtors:0x00000000; // type:label scope:global -lbl_506_section4_0 = .rodata:0x00000000; // type:object size:0x34 data:4byte -lbl_506_section4_34 = .rodata:0x00000034; // type:object size:0xE8 +g_profile_TIMER_TAG = .data:0x00000000; // type:object size:0x10 data:4byte +__vt__10dTgTimer_c = .data:0x00000034; // type:object size:0x74 +__vt__14dTgTimerBase_c = .data:0x000000A8; // type:object size:0x74 diff --git a/configure.py b/configure.py index 7782d9dd..72a05527 100644 --- a/configure.py +++ b/configure.py @@ -1073,7 +1073,7 @@ config.libs = [ Rel(NonMatching, "d_t_sw_area", "REL/d/t/d_t_sw_area.cpp"), Rel(Matching, "d_t_tackle", "REL/d/t/d_t_tackle.cpp"), Rel(NonMatching, "d_t_telop", "REL/d/t/d_t_telop.cpp"), - Rel(NonMatching, "d_t_timer", "REL/d/t/d_t_timer.cpp"), + Rel(Matching, "d_t_timer", "REL/d/t/d_t_timer.cpp"), Rel(NonMatching, "d_t_time_area_check", "REL/d/t/d_t_time_area_check.cpp"), Rel(NonMatching, "d_t_time_door_beam", "REL/d/t/d_t_time_door_beam.cpp"), Rel(NonMatching, "d_t_touch", "REL/d/t/d_t_touch.cpp"), diff --git a/include/d/tg/d_t_timer.h b/include/d/tg/d_t_timer.h new file mode 100644 index 00000000..463bf0b3 --- /dev/null +++ b/include/d/tg/d_t_timer.h @@ -0,0 +1,41 @@ +#ifndef D_T_TIMER_H +#define D_T_TIMER_H + +#include + +class dTgTimerBase_c : public dAcBase_c { +public: + virtual ~dTgTimerBase_c() {} +}; + + +class dTgTimer_c : public dTgTimerBase_c { +public: + dTgTimer_c() {} + virtual ~dTgTimer_c() {} + + virtual int create() override; + virtual int actorExecute() override; + + int getSubtypeFromParams(); + u16 getTimerFromParams(); + + u16 getCheckSceneflag(); + u16 getSetSceneflag(); + u16 getTimer(); + u16 setTimer(u16 val); + u16 getTargetTime(); + bool checkShouldTrigger(); + u16 getStoredTargetTime(); + + u16 getConstant0x50(); + void incrementTimer(); + void resetTimer(); + u16 getConstant0x50_Thunk(); + + u16 (dTgTimer_c::*mGetTargetTimeFunc)(); + u16 mTimer; + u16 mTargetTime; +}; + +#endif diff --git a/include/toBeSorted/sceneflag_manager.h b/include/toBeSorted/sceneflag_manager.h new file mode 100644 index 00000000..bb2106e6 --- /dev/null +++ b/include/toBeSorted/sceneflag_manager.h @@ -0,0 +1,63 @@ +#ifndef SCENEFLAG_MANAGER_H +#define SCENEFLAG_MANAGER_H + +#include +#include +#include + +class SceneflagManager { +public: + FlagSpace mSceneflags; + FlagSpace mTempflags; + FlagSpace mZoneflags; + BitwiseFlagHelper mFlagHelper; + u16 mSceneIdx; + u8 mShouldCommit; + + static u16 sTempFlags[4]; + static u16 sSceneFlags[8]; + static u16 sZoneFlags[0xFC]; + + static SceneflagManager *sInstance; + void doNothing(); + void setShouldCommit(u16 flag); + SceneflagManager(); + s32 isNotTempOrZoneFlag(u16 flag); + s32 isZoneFlag(u32 flag); + void updateFlagindex(u16 flagindex); + void copyFromSave(u32 flagindex); + void unsetAllTempflags(); + void zoneflagsResetAll(); + void zoneflagsResetForRoom(u16 roomId); + void unsetZoneAndTempflags(); + void unsetAllZoneflags(); + void unsetZoneflagsForRoom(u16 roomId); + u16 getZoneflagSlot(u16 roomId, u16 flag); + u16 getSceneflagSlotGlobal(u16 sceneIdx, u16 flag); + u16 getSceneflagSlot(u16 flag); + u16 getTempflagSlot(u16 flag); + bool checkZoneFlag(u16 roomId, u16 flag); + bool checkUncommittedZoneflag(u16 roomId, u16 flag); + u16 checkUncommittedZoneflag2(u16 roomId, u16 flag) { + return checkUncommittedZoneflag(roomId, flag); + } + bool checkUncommittedTempOrSceneflag(u16 flag); + u16 checkUncommittedTempOrSceneflag2(u16 flag) { + return checkUncommittedTempOrSceneflag(flag); + } + u16 checkFlag(u16 roomId, u16 flag); + bool checkSceneflagGlobal(u16 sceneIdx, u16 flag); + bool checkTempOrSceneflag(u16 flag); + bool checkUncommittedFlag(u16 roomId, u16 flag); + void setZoneflag(u16 roomId, u16 flag); + void setFlag(u16 roomId, u16 flag); + void setSceneflagGlobal(u16 sceneIdx, u16 flag); + void setTempOrSceneflag(u16 flag); + void unsetZoneflag(u16 roomId, u16 flag); + void unsetFlag(u16 roomId, u16 flag); + void unsetSceneflagGlobal(u16 sceneIdx, u16 flag); + void unsetTempOrSceneflag(u16 flag); + s32 doCommit(); +}; + +#endif diff --git a/src/REL/d/t/d_t_timer.cpp b/src/REL/d/t/d_t_timer.cpp index e69de29b..2a01f374 100644 --- a/src/REL/d/t/d_t_timer.cpp +++ b/src/REL/d/t/d_t_timer.cpp @@ -0,0 +1,100 @@ +#include +#include + +SPECIAL_ACTOR_PROFILE(TIMER_TAG, dTgTimer_c, fProfile::TAG_TIMER, 0x029F, 0, 0); + +// TODO counter abstraction +bool increment(u16 *t) { + if (*t < 0xFFFF) { + (*t)++; + return true; + } + return false; +} + +int dTgTimer_c::create() { + switch (getSubtypeFromParams()) { + case 0: + mGetTargetTimeFunc = dTgTimer_c::getConstant0x50_Thunk; + break; + case 1: + mTargetTime = getTimerFromParams() * 0x1e; + mGetTargetTimeFunc = getStoredTargetTime; + break; + default: + mTargetTime = getTimerFromParams(); + mGetTargetTimeFunc = getStoredTargetTime; + break; + } + resetTimer(); + return 1; +} + +int dTgTimer_c::actorExecute() { + bool getFlag = SceneflagManager::sInstance->checkFlag(roomid, getCheckSceneflag()); + if (getFlag) { + if (checkShouldTrigger()) { + SceneflagManager::sInstance->setFlag(roomid, getSetSceneflag()); + } else { + incrementTimer(); + } + } else { + resetTimer(); + } + return 1; +} + +int dTgTimer_c::getSubtypeFromParams() { + return params & 0xFF; +} + +u16 dTgTimer_c::getTimerFromParams() { + return params >> 8 & 0xFF; +} + +u16 dTgTimer_c::getCheckSceneflag() { + return params >> 0x10 & 0xFF; +} + +u16 dTgTimer_c::getSetSceneflag() { + return params >> 0x18 & 0xFF; +} + +u16 dTgTimer_c::getTimer() { + return mTimer; +} + +u16 dTgTimer_c::getConstant0x50() { + return 0x50; +} + +u16 dTgTimer_c::setTimer(u16 val) { + mTimer = val; +} + +u16 dTgTimer_c::getTargetTime() { + return (this->*mGetTargetTimeFunc)(); +} + +void dTgTimer_c::resetTimer() { + setTimer(0); +} + +void dTgTimer_c::incrementTimer() { + u16 t = getTimer(); + increment(&t); + setTimer(t); +} + +bool dTgTimer_c::checkShouldTrigger() { + return getTargetTime() <= getTimer(); +} + +u16 dTgTimer_c::getStoredTargetTime() { + return mTargetTime; +} + +// TODO what causes this (likely weak) thunk? +u16 dTgTimer_c::getConstant0x50_Thunk() { + return getConstant0x50(); +} diff --git a/src/toBeSorted/sceneflag_manager.cpp b/src/toBeSorted/sceneflag_manager.cpp index 1cef7560..36ab7087 100644 --- a/src/toBeSorted/sceneflag_manager.cpp +++ b/src/toBeSorted/sceneflag_manager.cpp @@ -1,64 +1,8 @@ #include "libc.h" #include -#include "toBeSorted/bitwise_flag_helper.h" +#include "toBeSorted/sceneflag_manager.h" #include "toBeSorted/file_manager.h" -#include "toBeSorted/flag_space.h" - -class SceneflagManager { -public: - FlagSpace mSceneflags; - FlagSpace mTempflags; - FlagSpace mZoneflags; - BitwiseFlagHelper mFlagHelper; - u16 mSceneIdx; - u8 mShouldCommit; - - static u16 sTempFlags[4]; - static u16 sSceneFlags[8]; - static u16 sZoneFlags[0xFC]; - - static SceneflagManager *sInstance; - void doNothing(); - void setShouldCommit(u16 flag); - SceneflagManager(); - s32 isNotTempOrZoneFlag(u16 flag); - s32 isZoneFlag(u32 flag); - void updateFlagindex(u16 flagindex); - void copyFromSave(u32 flagindex); - void unsetAllTempflags(); - void zoneflagsResetAll(); - void zoneflagsResetForRoom(u16 roomId); - void unsetZoneAndTempflags(); - void unsetAllZoneflags(); - void unsetZoneflagsForRoom(u16 roomId); - u16 getZoneflagSlot(u16 roomId, u16 flag); - u16 getSceneflagSlotGlobal(u16 sceneIdx, u16 flag); - u16 getSceneflagSlot(u16 flag); - u16 getTempflagSlot(u16 flag); - bool checkZoneFlag(u16 roomId, u16 flag); - bool checkUncommittedZoneflag(u16 roomId, u16 flag); - u16 checkUncommittedZoneflag2(u16 roomId, u16 flag) { - return checkUncommittedZoneflag(roomId, flag); - } - bool checkUncommittedTempOrSceneflag(u16 flag); - u16 checkUncommittedTempOrSceneflag2(u16 flag) { - return checkUncommittedTempOrSceneflag(flag); - } - bool checkFlag(u16 roomId, u16 flag); - bool checkSceneflagGlobal(u16 sceneIdx, u16 flag); - bool checkTempOrSceneflag(u16 flag); - bool checkUncommittedFlag(u16 roomId, u16 flag); - void setZoneflag(u16 roomId, u16 flag); - void setFlag(u16 roomId, u16 flag); - void setSceneflagGlobal(u16 sceneIdx, u16 flag); - void setTempOrSceneflag(u16 flag); - void unsetZoneflag(u16 roomId, u16 flag); - void unsetFlag(u16 roomId, u16 flag); - void unsetSceneflagGlobal(u16 sceneIdx, u16 flag); - void unsetTempOrSceneflag(u16 flag); - s32 doCommit(); -}; SceneflagManager *SceneflagManager::sInstance = nullptr; u16 SceneflagManager::sTempFlags[] = {}; @@ -200,7 +144,7 @@ bool SceneflagManager::checkUncommittedTempOrSceneflag(u16 flag) { // mFlagHelper.checkFlag(getSceneflagSlot2(flag), flag % 16, pData, mSceneflags.mCount); } } -bool SceneflagManager::checkFlag(u16 roomId, u16 flag) { +u16 SceneflagManager::checkFlag(u16 roomId, u16 flag) { if (isZoneFlag(flag)) { return checkZoneFlag(roomId, flag); } else { From 70dbbb1cb11cb9018b2823d7083c9db942ee7725 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 9 Jun 2024 22:47:44 -0400 Subject: [PATCH 20/20] added macro for declaring state manager (used for annoying dummy funcs) --- include/d/tg/d_t_rock_boat.h | 7 +------ include/d/tg/d_t_tumble_weed.h | 5 +---- include/s/s_State.hpp | 16 ++++++++++------ 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/include/d/tg/d_t_rock_boat.h b/include/d/tg/d_t_rock_boat.h index 378593b4..28d0d669 100644 --- a/include/d/tg/d_t_rock_boat.h +++ b/include/d/tg/d_t_rock_boat.h @@ -23,14 +23,9 @@ public: STATE_FUNC_DECLARE(dTgRockBoat_c, Wait); private: - - sFStateMgr_c mStateMgr; + STATE_MGR_DECLARE(dTgRockBoat_c); int cooldown; int boatNum; - - void dummy() { - mStateMgr.getStateID(); - } }; #endif diff --git a/include/d/tg/d_t_tumble_weed.h b/include/d/tg/d_t_tumble_weed.h index e3a80dd4..5f8f9ecd 100644 --- a/include/d/tg/d_t_tumble_weed.h +++ b/include/d/tg/d_t_tumble_weed.h @@ -30,11 +30,8 @@ private: bool shouldDoWind(); void doSpawnTumbleweed(); void getWind(mVec3_c *); - void unused() { - mStateMgr.getStateID(); - } - sFStateMgr_c mStateMgr; + STATE_MGR_DECLARE(dTgTumbleWeed_c); u16 tumbleweedTimer; u16 padding; u16 windTimer; diff --git a/include/s/s_State.hpp b/include/s/s_State.hpp index 97a5847e..9ec6614a 100644 --- a/include/s/s_State.hpp +++ b/include/s/s_State.hpp @@ -7,15 +7,19 @@ // Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib // See include/s/README.txt for changes made -#define STATE_FUNC_DECLARE(class, name) void initializeState_##name(); \ +#define STATE_FUNC_DECLARE(class, name) \ + void initializeState_##name(); \ void executeState_##name(); \ void finalizeState_##name(); \ static sFStateID_c StateID_##name -#define STATE_DEFINE(class, name) sFStateID_c class::StateID_##name( \ - #class "::StateID_" #name, \ - &class::initializeState_##name, \ - &class::executeState_##name, \ - &class::finalizeState_##name) +#define STATE_DEFINE(class, name) \ + sFStateID_c class ::StateID_##name(#class "::StateID_" #name, &class ::initializeState_##name, \ + &class ::executeState_##name, &class ::finalizeState_##name) +#define STATE_MGR_DECLARE(class_name) \ + sFStateMgr_c mStateMgr; \ + void dummy_GetStateID() { \ + mStateMgr.getStateID(); \ + } #endif