From 48e6945e3e11f16874ece6e39d4bafaceb2372bf Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 17 May 2024 00:23:15 +0200 Subject: [PATCH 01/20] m_dvd work --- config/SOUE01/splits.txt | 8 + config/SOUE01/symbols.txt | 226 +++++++------- configure.py | 1 + include/egg/core/eggDecomp.h | 2 +- include/egg/core/eggDvdFile.h | 4 +- include/m/m_dvd.h | 190 ++++++++++++ src/m/m_dvd.cpp | 564 ++++++++++++++++++++++++++++++++++ 7 files changed, 881 insertions(+), 114 deletions(-) create mode 100644 include/m/m_dvd.h create mode 100644 src/m/m_dvd.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index b1f0165e..bedcd3d5 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -213,6 +213,14 @@ m/m_angle.cpp: .ctors start:0x804DB8CC end:0x804DB8D0 .sbss start:0x80575C08 end:0x80575C10 +m/m_dvd.cpp: + .text start:0x802EEBA0 end:0x802F0494 + .ctors start:0x804DB8D0 end:0x804DB8D4 + .data start:0x80542870 end:0x80542968 + .sdata start:0x80573FD0 end:0x80573FF8 + .sbss start:0x80575C10 end:0x80575C38 + .bss start:0x805B85C0 end:0x805CB078 + m/m_heap.cpp: .text start:0x802F0F00 end:0x802F1660 .rodata start:0x804F0570 end:0x804F0580 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 48b7e544..1a34ef73 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17718,86 +17718,86 @@ fn_802EE830 = .text:0x802EE830; // type:function size:0x58 fn_802EE890 = .text:0x802EE890; // type:function size:0x38 fn_802EE8D0 = .text:0x802EE8D0; // type:function size:0xB0 fn_802EE980 = .text:0x802EE980; // type:function size:0x214 -fn_802EEBA0 = .text:0x802EEBA0; // type:function size:0x40 -fn_802EEBE0 = .text:0x802EEBE0; // type:function size:0x40 -fn_802EEC20 = .text:0x802EEC20; // type:function size:0x40 -fn_802EEC60 = .text:0x802EEC60; // type:function size:0x40 -fn_802EECA0 = .text:0x802EECA0; // type:function size:0x40 +__dt__Q24mDvd42TUncompressInfo_cFv = .text:0x802EEBA0; // type:function size:0x40 +__dt__Q24mDvd41TUncompressInfo_cFv = .text:0x802EEBE0; // type:function size:0x40 +__dt__Q24mDvd41TUncompressInfo_cFv = .text:0x802EEC20; // type:function size:0x40 +__dt__Q24mDvd42TUncompressInfo_cFv = .text:0x802EEC60; // type:function size:0x40 +__dt__Q24mDvd41TUncompressInfo_cFv = .text:0x802EECA0; // type:function size:0x40 fn_802EECE0 = .text:0x802EECE0; // type:function size:0xC fn_802EECF0 = .text:0x802EECF0; // type:function size:0x40 -fn_802EED30 = .text:0x802EED30; // type:function size:0x3C -fn_802EED70 = .text:0x802EED70; // type:function size:0x40 -fn_802EEDB0 = .text:0x802EEDB0; // type:function size:0x38 -fn_802EEDF0 = .text:0x802EEDF0; // type:function size:0x8 -fn_802EEE00 = .text:0x802EEE00; // type:function size:0x8 -fn_802EEE10 = .text:0x802EEE10; // type:function size:0x24 -fn_802EEE40 = .text:0x802EEE40; // type:function size:0x4C -fn_802EEE90 = .text:0x802EEE90; // type:function size:0x8 -fn_802EEEA0 = .text:0x802EEEA0; // type:function size:0x88 -fn_802EEF30 = .text:0x802EEF30; // type:function size:0x158 -fn_802EF090 = .text:0x802EF090; // type:function size:0x8 -fn_802EF0A0 = .text:0x802EF0A0; // type:function size:0x30 -fn_802EF0D0 = .text:0x802EF0D0; // type:function size:0x60 -fn_802EF130 = .text:0x802EF130; // type:function size:0xC -fn_802EF140 = .text:0x802EF140; // type:function size:0x8 -fn_802EF150 = .text:0x802EF150; // type:function size:0x10 -fn_802EF160 = .text:0x802EF160; // type:function size:0x4 -fn_802EF170 = .text:0x802EF170; // type:function size:0x14 -fn_802EF190 = .text:0x802EF190; // type:function size:0x44 -fn_802EF1E0 = .text:0x802EF1E0; // type:function size:0x50 -fn_802EF230 = .text:0x802EF230; // type:function size:0x8 -fn_802EF240 = .text:0x802EF240; // type:function size:0x8 -fn_802EF250 = .text:0x802EF250; // type:function size:0x8 -fn_802EF260 = .text:0x802EF260; // type:function size:0xA8 -fn_802EF310 = .text:0x802EF310; // type:function size:0xB8 -fn_802EF3D0 = .text:0x802EF3D0; // type:function size:0x34 -fn_802EF410 = .text:0x802EF410; // type:function size:0x4C -fn_802EF460 = .text:0x802EF460; // type:function size:0x1C +findUncompressInfo__4mDvdFUc = .text:0x802EED30; // type:function size:0x3C +newUncompressObj__4mDvdFUc = .text:0x802EED70; // type:function size:0x40 +deleteUncompressObj__4mDvdFUc = .text:0x802EEDB0; // type:function size:0x38 +getOSThread__4mDvdFv = .text:0x802EEDF0; // type:function size:0x8 +getArchiveHeap__4mDvdFv = .text:0x802EEE00; // type:function size:0x8 +run__Q24mDvd10MyThread_cFP12mDvd_param_c = .text:0x802EEE10; // type:function size:0x24 +__ct__Q24mDvd10MyThread_cFiPQ23EGG4Heap = .text:0x802EEE40; // type:function size:0x4C +run__Q24mDvd10MyThread_cFv = .text:0x802EEE90; // type:function size:0x8 +create__4mDvdFiPQ23EGG4HeapPQ23EGG4HeapPQ23EGG4Heap = .text:0x802EEEA0; // type:function size:0x88 +loadToMainRAM__4mDvdFiPcPQ23EGG4HeapQ33EGG9DvdRipper15EAllocDirectionUlPUlPUlUl = .text:0x802EEF30; // type:function size:0x158 +ConvertPathToEntrynum__4mDvdFPCc = .text:0x802EF090; // type:function size:0x8 +IsExistPath__4mDvdFPCc = .text:0x802EF0A0; // type:function size:0x30 +__dt__14mDvd_command_cFv = .text:0x802EF0D0; // type:function size:0x60 +__nw__14mDvd_command_cFUl = .text:0x802EF130; // type:function size:0xC +__dl__14mDvd_command_cFPv = .text:0x802EF140; // type:function size:0x8 +doClear__14mDvd_command_cFv = .text:0x802EF150; // type:function size:0x10 +done__14mDvd_command_cFv = .text:0x802EF160; // type:function size:0x4 +waitDone__14mDvd_command_cFv = .text:0x802EF170; // type:function size:0x14 +waitUntilDone__14mDvd_command_cFv = .text:0x802EF190; // type:function size:0x44 +__ct__12mDvd_param_cFv = .text:0x802EF1E0; // type:function size:0x50 +kick__12mDvd_param_cFv = .text:0x802EF230; // type:function size:0x8 +waitForKick__12mDvd_param_cFv = .text:0x802EF240; // type:function size:0x8 +getFirstCommand__12mDvd_param_cFv = .text:0x802EF250; // type:function size:0x8 +addCommand__12mDvd_param_cFP14mDvd_command_c = .text:0x802EF260; // type:function size:0xA8 +removeCommand__12mDvd_param_cFP14mDvd_command_c = .text:0x802EF310; // type:function size:0xB8 +executeCB__12mDvd_param_cFPP14mDvd_command_c = .text:0x802EF3D0; // type:function size:0x34 +mainLoop__12mDvd_param_cFv = .text:0x802EF410; // type:function size:0x4C +__ct__14mDvd_command_cFv = .text:0x802EF460; // type:function size:0x1C fn_802EF480 = .text:0x802EF480; // type:function size:0x20 -fn_802EF4A0 = .text:0x802EF4A0; // type:function size:0x54 -fn_802EF500 = .text:0x802EF500; // type:function size:0x58 -fn_802EF560 = .text:0x802EF560; // type:function size:0x64 -fn_802EF5D0 = .text:0x802EF5D0; // type:function size:0x78 +destroy__14mDvd_command_cFPP14mDvd_command_c = .text:0x802EF4A0; // type:function size:0x54 +__dt__25mDvdCommandReadCallback_cFv = .text:0x802EF500; // type:function size:0x58 +__ct__25mDvdCommandReadCallback_cFPFPv_PvPv = .text:0x802EF560; // type:function size:0x64 +create__25mDvdCommandReadCallback_cFPFPv_PvPv = .text:0x802EF5D0; // type:function size:0x78 fn_802EF650 = .text:0x802EF650; // type:function size:0x30 -fn_802EF680 = .text:0x802EF680; // type:function size:0x54 -fn_802EF6E0 = .text:0x802EF6E0; // type:function size:0x58 -fn_802EF740 = .text:0x802EF740; // type:function size:0x74 -fn_802EF7C0 = .text:0x802EF7C0; // type:function size:0x16C -fn_802EF930 = .text:0x802EF930; // type:function size:0x8 -fn_802EF940 = .text:0x802EF940; // type:function size:0x8 -fn_802EF950 = .text:0x802EF950; // type:function size:0x80 -fn_802EF9D0 = .text:0x802EF9D0; // type:function size:0x4 -fn_802EF9E0 = .text:0x802EF9E0; // type:function size:0xA0 -fn_802EFA80 = .text:0x802EFA80; // type:function size:0xF8 -fn_802EFB80 = .text:0x802EFB80; // type:function size:0x18 -fn_802EFBA0 = .text:0x802EFBA0; // type:function size:0x64 -fn_802EFC10 = .text:0x802EFC10; // type:function size:0x6C -fn_802EFC80 = .text:0x802EFC80; // type:function size:0x58 -fn_802EFCE0 = .text:0x802EFCE0; // type:function size:0x58 -fn_802EFD40 = .text:0x802EFD40; // type:function size:0x60 -fn_802EFDA0 = .text:0x802EFDA0; // type:function size:0x80 -fn_802EFE20 = .text:0x802EFE20; // type:function size:0x64 +execute__25mDvdCommandReadCallback_cFv = .text:0x802EF680; // type:function size:0x54 +__dt__22mDvd_mountMemArchive_cFv = .text:0x802EF6E0; // type:function size:0x58 +__ct__22mDvd_mountMemArchive_cFi = .text:0x802EF740; // type:function size:0x74 +findPathWithCompressedExtension__FPCcPUc = .text:0x802EF7C0; // type:function size:0x16C +setAutoStreamDecomp__Fb = .text:0x802EF930; // type:function size:0x8 +getAutoStreamDecomp__Fv = .text:0x802EF940; // type:function size:0x8 +ConvertPathToEntrynum__FPCcPUc = .text:0x802EF950; // type:function size:0x80 +ConvertPathToEntrynum_Thunk__FPCcPUc = .text:0x802EF9D0; // type:function size:0x4 +create__22mDvd_mountMemArchive_cFPCcUcPQ23EGG4Heap = .text:0x802EF9E0; // type:function size:0xA0 +execute__22mDvd_mountMemArchive_cFv = .text:0x802EFA80; // type:function size:0xF8 +getArcBinary__22mDvd_mountMemArchive_cFv = .text:0x802EFB80; // type:function size:0x18 +onComplete__22mDvd_mountMemArchive_cFv = .text:0x802EFBA0; // type:function size:0x64 +__ct__21mDvd_toMainRam_base_cFi = .text:0x802EFC10; // type:function size:0x6C +__dt__21mDvd_toMainRam_base_cFv = .text:0x802EFC80; // type:function size:0x58 +__dt__20mDvd_toMainRam_arc_cFv = .text:0x802EFCE0; // type:function size:0x58 +__ct__20mDvd_toMainRam_arc_cFPQ23EGG7Archiveii = .text:0x802EFD40; // type:function size:0x60 +makeRequest__20mDvd_toMainRam_arc_cFPQ23EGG7ArchiveiiPQ23EGG4Heap = .text:0x802EFDA0; // type:function size:0x80 +create__FPQ23EGG7ArchivePCciPQ23EGG4Heap = .text:0x802EFE20; // type:function size:0x64 fn_802EFE90 = .text:0x802EFE90; // type:function size:0x30 -fn_802EFEC0 = .text:0x802EFEC0; // type:function size:0x78 -fn_802EFF40 = .text:0x802EFF40; // type:function size:0x4C -fn_802EFF90 = .text:0x802EFF90; // type:function size:0x9C +execute__20mDvd_toMainRam_arc_cFv = .text:0x802EFEC0; // type:function size:0x78 +__ct__23mDvd_toMainRam_normal_cFi = .text:0x802EFF40; // type:function size:0x4C +create__23mDvd_toMainRam_normal_cFPCciPQ23EGG4Heap = .text:0x802EFF90; // type:function size:0x9C fn_802F0030 = .text:0x802F0030; // type:function size:0x30 -fn_802F0060 = .text:0x802F0060; // type:function size:0x48 -fn_802F00B0 = .text:0x802F00B0; // type:function size:0x58 -fn_802F0110 = .text:0x802F0110; // type:function size:0xA0 -fn_802F01B0 = .text:0x802F01B0; // type:function size:0x18 -fn_802F01D0 = .text:0x802F01D0; // type:function size:0x58 -fn_802F0230 = .text:0x802F0230; // type:function size:0xE0 -fn_802F0310 = .text:0x802F0310; // type:function size:0x3C -fn_802F0350 = .text:0x802F0350; // type:function size:0x4 -fn_802F0360 = .text:0x802F0360; // type:function size:0x40 -fn_802F03A0 = .text:0x802F03A0; // type:function size:0x4 -fn_802F03B0 = .text:0x802F03B0; // type:function size:0x3C -fn_802F03F0 = .text:0x802F03F0; // type:function size:0x4 -fn_802F0400 = .text:0x802F0400; // type:function size:0x3C -fn_802F0440 = .text:0x802F0440; // type:function size:0x4 -fn_802F0450 = .text:0x802F0450; // type:function size:0x3C -fn_802F0490 = .text:0x802F0490; // type:function size:0x4 +create2__23mDvd_toMainRam_normal_cFPP23mDvd_toMainRam_normal_cPCciPQ23EGG4Heap = .text:0x802F0060; // type:function size:0x48 +__dt__23mDvd_toMainRam_normal_cFv = .text:0x802F00B0; // type:function size:0x58 +execute__23mDvd_toMainRam_normal_cFv = .text:0x802F0110; // type:function size:0xA0 +onComplete__23mDvd_toMainRam_normal_cFv = .text:0x802F01B0; // type:function size:0x18 +__dt__Q24mDvd10MyThread_cFv = .text:0x802F01D0; // type:function size:0x58 +__sinit_\m_dvd_cpp = .text:0x802F0230; // type:function size:0xE0 +Construct__Q24mDvd41TUncompressInfo_cCFv = .text:0x802F0310; // type:function size:0x3C +Destruct__Q24mDvd41TUncompressInfo_cCFv = .text:0x802F0350; // type:function size:0x4 +Construct__Q24mDvd42TUncompressInfo_cCFv = .text:0x802F0360; // type:function size:0x40 +Destruct__Q24mDvd42TUncompressInfo_cCFv = .text:0x802F03A0; // type:function size:0x4 +Construct__Q24mDvd41TUncompressInfo_cCFv = .text:0x802F03B0; // type:function size:0x3C +Destruct__Q24mDvd41TUncompressInfo_cCFv = .text:0x802F03F0; // type:function size:0x4 +Construct__Q24mDvd41TUncompressInfo_cCFv = .text:0x802F0400; // type:function size:0x3C +Destruct__Q24mDvd41TUncompressInfo_cCFv = .text:0x802F0440; // type:function size:0x4 +Construct__Q24mDvd42TUncompressInfo_cCFv = .text:0x802F0450; // type:function size:0x3C +Destruct__Q24mDvd42TUncompressInfo_cCFv = .text:0x802F0490; // type:function size:0x4 fn_802F04A0 = .text:0x802F04A0; // type:function size:0x48 fn_802F04F0 = .text:0x802F04F0; // type:function size:0x12C fn_802F0620 = .text:0x802F0620; // type:function size:0x9C @@ -22049,7 +22049,7 @@ fn_803ACF10 = .text:0x803ACF10; // type:function size:0xE4 OSCancelThread = .text:0x803AD000; // type:function size:0x1D4 scope:global fn_803AD1E0 = .text:0x803AD1E0; // type:function size:0x144 OSDetachThread = .text:0x803AD330; // type:function size:0xA0 -fn_803AD3D0 = .text:0x803AD3D0; // type:function size:0x29C +OSResumeThread = .text:0x803AD3D0; // type:function size:0x29C fn_803AD670 = .text:0x803AD670; // type:function size:0x18C OSSleepThread = .text:0x803AD800; // type:function size:0xF0 scope:global OSWakeupThread = .text:0x803AD8F0; // type:function size:0xF8 @@ -26137,7 +26137,7 @@ unmount__Q23EGG7ArchiveFv = .text:0x80493B80; // type:function size:0x94 getFile__Q23EGG7ArchiveFPCcPQ33EGG7Archive8FileInfo = .text:0x80493C20; // type:function size:0xC4 convertPathToEntryID__Q23EGG7ArchiveFPCc = .text:0x80493CF0; // type:function size:0x8 getFileFast__Q23EGG7ArchiveFlPQ33EGG7Archive8FileInfo = .text:0x80493D00; // type:function size:0xB8 -loadFromDiscFast__EGG__Archive = .text:0x80493DC0; // type:function size:0x148 +getFileFast__Q23EGG7ArchiveFlPQ23EGG4Heapl = .text:0x80493DC0; // type:function size:0x148 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 @@ -35717,18 +35717,18 @@ lbl_805427F0 = .data:0x805427F0; // type:object size:0x30 lbl_80542820 = .data:0x80542820; // type:object size:0x14 lbl_80542834 = .data:0x80542834; // type:object size:0x14 lbl_80542848 = .data:0x80542848; // type:object size:0x28 -lbl_80542870 = .data:0x80542870; // type:object size:0x18 -lbl_80542888 = .data:0x80542888; // type:object size:0x14 -lbl_8054289C = .data:0x8054289C; // type:object size:0x14 -lbl_805428B0 = .data:0x805428B0; // type:object size:0x14 -lbl_805428C4 = .data:0x805428C4; // type:object size:0x14 -lbl_805428D8 = .data:0x805428D8; // type:object size:0x14 -lbl_805428EC = .data:0x805428EC; // type:object size:0x14 -lbl_80542900 = .data:0x80542900; // type:object size:0x14 -lbl_80542914 = .data:0x80542914; // type:object size:0x14 -lbl_80542928 = .data:0x80542928; // type:object size:0x14 -lbl_8054293C = .data:0x8054293C; // type:object size:0x14 -lbl_80542950 = .data:0x80542950; // type:object size:0x18 +__vt__Q24mDvd10MyThread_c = .data:0x80542870; // type:object size:0x18 +__vt__23mDvd_toMainRam_normal_c = .data:0x80542888; // type:object size:0x14 +__vt__20mDvd_toMainRam_arc_c = .data:0x8054289C; // type:object size:0x14 +__vt__21mDvd_toMainRam_base_c = .data:0x805428B0; // type:object size:0x14 +__vt__22mDvd_mountMemArchive_c = .data:0x805428C4; // type:object size:0x14 +__vt__25mDvdCommandReadCallback_c = .data:0x805428D8; // type:object size:0x14 +__vt__14mDvd_command_c = .data:0x805428EC; // type:object size:0x14 +__vt__Q24mDvd41TUncompressInfo_c = .data:0x80542900; // type:object size:0x14 +__vt__Q24mDvd42TUncompressInfo_c = .data:0x80542914; // type:object size:0x14 +__vt__Q24mDvd41TUncompressInfo_c = .data:0x80542928; // type:object size:0x14 +__vt__Q24mDvd41TUncompressInfo_c = .data:0x8054293C; // type:object size:0x14 +__vt__Q24mDvd42TUncompressInfo_c = .data:0x80542950; // type:object size:0x18 lbl_80542968 = .data:0x80542968; // type:object size:0x28 lbl_80542990 = .data:0x80542990; // type:object size:0x29 lbl_805429BC = .data:0x805429BC; // type:object size:0x29 @@ -37092,11 +37092,11 @@ lbl_8056E7F8 = .data:0x8056E7F8; // type:object size:0x14 lbl_8056E80C = .data:0x8056E80C; // type:object size:0x14 lbl_8056E820 = .data:0x8056E820; // type:object size:0x10 lbl_8056E830 = .data:0x8056E830; // type:object size:0x28 -lbl_8056E858 = .data:0x8056E858; // type:object size:0x18 -lbl_8056E870 = .data:0x8056E870; // type:object size:0x18 -lbl_8056E888 = .data:0x8056E888; // type:object size:0x18 -lbl_8056E8A0 = .data:0x8056E8A0; // type:object size:0x18 -lbl_8056E8B8 = .data:0x8056E8B8; // type:object size:0x18 +__vt__Q23EGG15StreamDecompSZS = .data:0x8056E858; // type:object size:0x18 +__vt__Q23EGG15StreamDecompLRC = .data:0x8056E870; // type:object size:0x18 +__vt__Q23EGG14StreamDecompLH = .data:0x8056E888; // type:object size:0x18 +__vt__Q23EGG14StreamDecompRL = .data:0x8056E8A0; // type:object size:0x18 +__vt__Q23EGG14StreamDecompLZ = .data:0x8056E8B8; // type:object size:0x18 __vt__Q23EGG9Allocator = .data:0x8056E8D0; // type:object size:0x14 lbl_8056E8E8 = .data:0x8056E8E8; // type:object size:0x68 __vt__Q23EGG4Heap = .data:0x8056E950; // type:object size:0x30 @@ -40260,17 +40260,17 @@ lbl_80575BF8 = .sbss:0x80575BF8; // type:object size:0x4 data:4byte lbl_80575BFC = .sbss:0x80575BFC; // type:object size:0x1 data:byte lbl_80575C00 = .sbss:0x80575C00; // type:object size:0x8 data:4byte Zero__7mAng3_c = .sbss:0x80575C08; // type:object size:0x6 data:2byte -lbl_80575C10 = .sbss:0x80575C10; // type:object size:0x4 data:4byte -lbl_80575C14 = .sbss:0x80575C14; // type:object size:0x4 data:4byte -lbl_80575C18 = .sbss:0x80575C18; // type:object size:0x4 data:4byte -lbl_80575C1C = .sbss:0x80575C1C; // type:object size:0x4 data:4byte -lbl_80575C20 = .sbss:0x80575C20; // type:object size:0x4 data:4byte -lbl_80575C24 = .sbss:0x80575C24; // type:object size:0x4 data:4byte -lbl_80575C28 = .sbss:0x80575C28; // type:object size:0x4 data:4byte -lbl_80575C2C = .sbss:0x80575C2C; // type:object size:0x4 data:4byte -lbl_80575C30 = .sbss:0x80575C30; // type:object size:0x1 data:byte -lbl_80575C31 = .sbss:0x80575C31; // type:object size:0x1 data:byte -lbl_80575C34 = .sbss:0x80575C34; // type:object size:0x4 data:4byte +somePtr__4mDvd = .sbss:0x80575C10; // type:object size:0x4 data:4byte +someNumber__4mDvd = .sbss:0x80575C14; // type:object size:0x4 data:4byte +compressors_ptr__4mDvd = .sbss:0x80575C18; // type:object size:0x4 data:4byte +compressors_last__4mDvd = .sbss:0x80575C1C; // type:object size:0x4 data:4byte +sOsThread__4mDvd = .sbss:0x80575C20; // type:object size:0x4 data:4byte +sThread__4mDvd = .sbss:0x80575C24; // type:object size:0x4 data:4byte +sCommandHeap__4mDvd = .sbss:0x80575C28; // type:object size:0x4 data:4byte +sArchiveHeap__4mDvd = .sbss:0x80575C2C; // type:object size:0x4 data:4byte +isAutoStreamDecomp__4mDvd = .sbss:0x80575C30; // type:object size:0x1 data:byte +isRegistered__4mDvd = .sbss:0x80575C31; // type:object size:0x1 data:byte +mInstance__12mDvd_param_c = .sbss:0x80575C34; // type:object size:0x4 data:4byte s_SavedCurrentHeap__5mHeap = .sbss:0x80575C38; // type:object size:0x4 data:4byte g_archiveHeap__5mHeap = .sbss:0x80575C3C; // type:object size:0x4 data:4byte g_commandHeap__5mHeap = .sbss:0x80575C40; // type:object size:0x4 data:4byte @@ -49068,13 +49068,17 @@ m_searchManage__10fManager_c = .bss:0x805B8548; // type:object size:0x40 lbl_805B8588 = .bss:0x805B8588; // type:object size:0xC lbl_805B8594 = .bss:0x805B8594; // type:object size:0xC lbl_805B85A0 = .bss:0x805B85A0; // type:object size:0x20 data:4byte -lbl_805B85C0 = .bss:0x805B85C0; // type:object size:0xC data:4byte -lbl_805B85CC = .bss:0x805B85CC; // type:object size:0x6772 -lbl_805BED3E = .bss:0x805BED3E; // type:object size:0x28FA -lbl_805C1638 = .bss:0x805C1638; // type:object size:0x9930 -lbl_805CAF68 = .bss:0x805CAF68; // type:object size:0x30 -lbl_805CAF98 = .bss:0x805CAF98; // type:object size:0x10 -lbl_805CAFA8 = .bss:0x805CAFA8; // type:object size:0xD0 +DECOMP_SZS__4mDvd = .bss:0x805B85C0; // type:object size:0xC data:4byte +DECOMP_LZ__4mDvd = .bss:0x805B85CC; // type:object size:0xC data:4byte +DECOMP_LH__4mDvd = .bss:0x805B85D8; // type:object size:0xC data:4byte +DECOMP_LRC__4mDvd = .bss:0x805B85E4; // type:object size:0xC data:4byte +DECOMP_RL__4mDvd = .bss:0x805B85F0; // type:object size:0xC data:4byte +likely_align__4mDvd = .bss:0x805B85FC; // type:object size:0x7A04 +more_empty_space__4mDvd = .bss:0x805C0000; // type:object size:0x1638 +decompressor_alloc_space__4mDvd = .bss:0x805C1638; // type:object size:0x9930 +DVD_MANAGER__4mDvd = .bss:0x805CAF68; // type:object size:0x30 +lbl_805CAF98 = .bss:0x805CAF98; // type:object size:0xC +@LOCAL@loadToMainRAM__4mDvdFUiPcPQ23EGG4HeapUiUiPUiPUiUi@DvdFile = .bss:0x805CAFA8; // type:object size:0xD0 g_gameHeaps__5mHeap = .bss:0x805CB078; // type:object size:0x10 data:4byte lbl_805CB088 = .bss:0x805CB088; // type:object size:0x30 data:4byte lbl_805CB0B8 = .bss:0x805CB0B8; // type:object size:0x10 data:4byte diff --git a/configure.py b/configure.py index 8b572602..30824191 100644 --- a/configure.py +++ b/configure.py @@ -301,6 +301,7 @@ config.libs = [ Object(Matching, "f/f_list.cpp"), Object(Matching, "f/f_manager.cpp"), Object(Matching, "m/m_angle.cpp"), + Object(NonMatching, "m/m_dvd.cpp"), Object(Matching, "m/m_heap.cpp"), Object(NonMatching, "m/m_mtx.cpp"), # framework (f_name) diff --git a/include/egg/core/eggDecomp.h b/include/egg/core/eggDecomp.h index 46b8f11f..83248930 100644 --- a/include/egg/core/eggDecomp.h +++ b/include/egg/core/eggDecomp.h @@ -70,7 +70,7 @@ public: private: // NON-OFFICIAL struct SZSCompContext { - u8 _[0x18]; + u8 _[0x14]; /* 80494e00 */ static u32 getUncompressedSize(const void *src); /* 80494e30 */ void init(u32 maxCompSize); /* 80494e60 */ static int readSzsHeader(/* unk params*/); diff --git a/include/egg/core/eggDvdFile.h b/include/egg/core/eggDvdFile.h index 8d7c13da..a9e9ef2b 100644 --- a/include/egg/core/eggDvdFile.h +++ b/include/egg/core/eggDvdFile.h @@ -32,8 +32,8 @@ public: /* vt 0x0C | 80494450 */ virtual bool open(const char *path); /* vt 0x10 | 804944b0 */ virtual void close(); /* vt 0x14 | 80494510 */ virtual s32 readData(void *buffer, s32 length, s32 offset); - /* vt 0x18 | 804945e0 */ virtual s32 writeData(void *buffer, s32 length, s32 offset); - /* vt 0x1C | 80494670 */ virtual u32 getFileSize(); + /* vt 0x18 | 804945e0 */ virtual s32 writeData(const void *buffer, s32 length, s32 offset); + /* vt 0x1C | 80494670 */ virtual u32 getFileSize() const; /* vt 0x20 | 804943d0 */ virtual bool open(s32 entryNum); /* vt 0x24 | 804944a0 */ virtual bool open(const char *path, void *); diff --git a/include/m/m_dvd.h b/include/m/m_dvd.h new file mode 100644 index 00000000..1493e9d7 --- /dev/null +++ b/include/m/m_dvd.h @@ -0,0 +1,190 @@ +#ifndef M_DVD_H +#define M_DVD_H + +#include +#include +#include + +// TODO these are scattered +int findPathWithCompressedExtension(const char *name, u8 *outType); +int ConvertPathToEntrynum(const char *path, u8 *outType); + +// TODO onComplete -> doClear? + +namespace mDvd { + +extern void *somePtr; + +class TUncompressInfo_Base_c { +public: + TUncompressInfo_Base_c(u8 type, const char *extension) : mType(type), mExtension(extension) {} + virtual ~TUncompressInfo_Base_c() {} + virtual EGG::StreamDecomp *Construct() const { + return nullptr; + } + virtual void Destruct() const {} + + u8 mType; + const char *mExtension; +}; + +template +class TUncompressInfo_c : public TUncompressInfo_Base_c { +public: + TUncompressInfo_c(u8 type, const char *extension) : TUncompressInfo_Base_c(type, extension) {} + virtual T *Construct() const { + return new (somePtr) T(); + } + virtual void Destruct() const {} +}; + +class MyThread_c; + +TUncompressInfo_Base_c *findUncompressInfo(u8 type); + +void create(int priority, EGG::Heap *commandHeap, EGG::Heap *archiveHeap, EGG::Heap *threadHeap); +void *loadToMainRAM(u32 entryNum, char *dst, EGG::Heap *heap, EGG::DvdRipper::EAllocDirection allocDir, u32 offset, u32 *p6, u32 *p7, + u32 decompressorType); + +u32 IsExistPath(const char *path); + +OSThread *getOSThread(); +EGG::Heap *getArchiveHeap(); +} // namespace mDvd + +class mDvd_command_c { +public: + mDvd_command_c(); + virtual ~mDvd_command_c(); + + virtual u32 execute() = 0; + virtual void onComplete(); + + void doClear(); + void done(); + void waitDone(); + void waitUntilDone(); + static void destroy(mDvd_command_c **cmd); + + void *operator new(size_t size); + void operator delete(void *ptr); + + mDvd_command_c *mNext; + u8 mStatus; + u8 mMountDirection; + u8 mCompressionType; +}; + +typedef void *(*dvdReadCallback)(void *); + +class mDvdCommandReadCallback_c : public mDvd_command_c { +public: + mDvdCommandReadCallback_c(dvdReadCallback cb, void *cbData); + virtual ~mDvdCommandReadCallback_c(); + virtual u32 execute() override; + + static mDvdCommandReadCallback_c *create(dvdReadCallback cb, void *cbData); + + dvdReadCallback mCallback; + void *mCallbackData; + void *mDataPtr; +}; + +class mDvd_mountMemArchive_c : public mDvd_command_c { +public: + mDvd_mountMemArchive_c(int mountDirection); + virtual ~mDvd_mountMemArchive_c(); + virtual u32 execute(); + virtual void onComplete(); + + static mDvd_mountMemArchive_c *create(const char *path, u8 mountDirection, EGG::Heap *heap); + void *getArcBinary(); + + int mEntryNum; + EGG::Archive *mDataPtr; + EGG::Heap *mHeap; + u32 field_0x18; +}; + +class mDvd_toMainRam_base_c : public mDvd_command_c { +public: + mDvd_toMainRam_base_c(int mountDirection); + virtual ~mDvd_toMainRam_base_c(); + virtual u32 execute() = 0; + + void *mDataPtr; + int field_0x10; + u32 field_0x14; + EGG::Heap *mHeap; +}; + +class mDvd_toMainRam_arc_c : public mDvd_toMainRam_base_c { +public: + mDvd_toMainRam_arc_c(EGG::Archive *arc, int entryNum, int mountDirection); + virtual ~mDvd_toMainRam_arc_c(); + virtual u32 execute(); + + static mDvd_toMainRam_arc_c *makeRequest(EGG::Archive *arc, int entryNum, int mountDirection, EGG::Heap *heap); + static mDvd_toMainRam_arc_c *create(EGG::Archive *arc, const char *path, int mountDirection, EGG::Heap *heap); + + EGG::Archive *mArcPtr; + int mEntryNum; +}; + +class mDvd_toMainRam_normal_c : public mDvd_toMainRam_base_c { +public: + mDvd_toMainRam_normal_c(int mountDirection); + ~mDvd_toMainRam_normal_c(); + virtual u32 execute(); + virtual void onComplete(); + + static mDvd_toMainRam_normal_c *create(const char *path, int mountDirection, EGG::Heap *heap); + static void create2(mDvd_toMainRam_normal_c **cmd, const char *path, int mountDirection, EGG::Heap *heap); + + u8 mCompressionType2; + int mEntryNum; +}; + +class mDvd_param_c { +public: + mDvd_param_c(); + + OSMutex mMutex; + mDvd_command_c *mFirstRequest; + mDvd_command_c *mLastRequest; + OSThreadQueue mThreadQueue1; + OSThreadQueue mThreadQueue2; + + void kick(); + void waitForKick(); + + mDvd_command_c *getFirstCommand(); + void addCommand(mDvd_command_c *cmd); + void removeCommand(mDvd_command_c *cmd); + static u32 executeCB(mDvd_command_c **cmd); + void mainLoop(); + + static mDvd_param_c *mInstance; +}; + +namespace mDvd { + +class MyThread_c : EGG::Thread { +public: + MyThread_c(int priority, EGG::Heap *heap); + + virtual void *run() override; + + OSThread *getMyOsThread() { + return mOSThread; + } + + void setThreadHeap(EGG::Heap *heap) { + setThreadCurrentHeap(heap); + } + + static void *run(mDvd_param_c *dvd); +}; +} // namespace mDvd + +#endif diff --git a/src/m/m_dvd.cpp b/src/m/m_dvd.cpp new file mode 100644 index 00000000..ed486c44 --- /dev/null +++ b/src/m/m_dvd.cpp @@ -0,0 +1,564 @@ +#include +#include +#include +#include +#include +#include +#include + +namespace mDvd { + +TUncompressInfo_c DECOMP_SZS(3, ".szs"); +TUncompressInfo_c DECOMP_LZ(5, ".LZ"); +TUncompressInfo_c DECOMP_LH(7, ".LH"); +TUncompressInfo_c DECOMP_LRC(8, ".LRC"); +TUncompressInfo_c DECOMP_RL(4, ".RL"); + +// TODO This the space within which the actual decompressors +// are allocated. +char likely_align[0x7A04]; +char more_empty_space[0x1638]; +char decompressor_alloc_space[0x9930]; + +mDvd_param_c DVD_MANAGER; + +TUncompressInfo_Base_c *decompressorPtrs[1] = { + &DECOMP_LZ, +}; + +u8 g_mountDirection = 1; +int maxChunkSize = 0x10000; + +void *somePtr; +u32 someNumber; +TUncompressInfo_Base_c **compressors_ptr; +TUncompressInfo_Base_c **compressors_last; +OSThread *sOsThread; +mDvd::MyThread_c *sThread; +EGG::Heap *sCommandHeap; +EGG::Heap *sArchiveHeap; +bool isAutoStreamDecomp; +bool isRegistered; + +/** 802eece0 */ +extern "C" void fn_802EECE0(TUncompressInfo_Base_c **ptr, TUncompressInfo_Base_c **last) { + compressors_ptr = ptr; + compressors_last = last; +} + +/** 802eecf0 */ +extern "C" void fn_802EECF0() { + fn_802EECE0(decompressorPtrs, &decompressorPtrs[1]); + somePtr = decompressor_alloc_space; + someNumber = 0x24; +} + +/** 802eed30 */ +TUncompressInfo_Base_c *findUncompressInfo(u8 type) { + TUncompressInfo_Base_c **ptr = compressors_ptr; + while (ptr != compressors_last) { + if ((*ptr)->mType == type) { + return *ptr; + } + ptr++; + } + return nullptr; +} + +/** 802eed70 */ +EGG::StreamDecomp *newUncompressObj(u8 type) { + TUncompressInfo_Base_c *factory = findUncompressInfo(type); + if (factory != nullptr) { + return factory->Construct(); + } else { + return nullptr; + } +} + +/** 802eedb0 */ +void deleteUncompressObj(u8 type) { + TUncompressInfo_Base_c *factory = findUncompressInfo(type); + if (factory != nullptr) { + factory->Destruct(); + } +} + +OSThread *getOSThread() { + return sOsThread; +} + +EGG::Heap *getArchiveHeap() { + return sArchiveHeap; +} + +/** 802eee10 */ +void *MyThread_c::run(mDvd_param_c *dvd) { + dvd->mainLoop(); + return nullptr; +} + +/** 802eee40 */ +MyThread_c::MyThread_c(int priority, EGG::Heap *heap) : EGG::Thread(0x4000, 0, priority, heap) {} + +/** 802eee90 */ +void *MyThread_c::run() { + return run(mDvd_param_c::mInstance); +} + +/** 802eeea0 */ +void create(int priority, EGG::Heap *commandHeap, EGG::Heap *archiveHeap, EGG::Heap *threadHeap) { + sCommandHeap = commandHeap; + sArchiveHeap = archiveHeap; + mDvd::MyThread_c *thread = new (threadHeap, 0x04) mDvd::MyThread_c(priority, threadHeap); + sThread = thread; + sOsThread = thread->getMyOsThread(); + if (mHeap::g_assertHeap != nullptr) { + thread->setThreadHeap((EGG::Heap *)mHeap::g_assertHeap); + } + OSResumeThread(sThread->getMyOsThread()); +} + +/** 802eef30 */ +void *loadToMainRAM(int entryNum, char *dst, EGG::Heap *heap, EGG::DvdRipper::EAllocDirection allocDir, u32 offset, + u32 *p6, u32 *p7, u32 decompressorType) { + // TODO + + if (decompressorType == 0) { + } else { + extern EGG::DvdFile DvdFile; + if (mDvd::isRegistered == false) { + static EGG::DvdFile DvdFile; + + isRegistered = true; + } + } +} + +int ConvertPathToEntrynum(const char *path) { + return ::ConvertPathToEntrynum(path, nullptr); +} + +u32 IsExistPath(const char *path) { + u32 entry = ConvertPathToEntrynum(path); + // TODO fake match + return (((-entry - 1) | (entry + 1)) >> 0x1f); +} + +} // namespace mDvd + +mDvd_param_c *mDvd_param_c::mInstance; + +/** 802ef0d0 */ +mDvd_command_c::~mDvd_command_c() { + waitDone(); +} + +/** 802ef130 */ +void *mDvd_command_c::operator new(size_t size) { + return EGG::Heap::alloc(size, -4, mDvd::sCommandHeap); +} + +void mDvd_command_c::operator delete(void *ptr) { + EGG::Heap::free(ptr, mDvd::sCommandHeap); +} + +/** 802ef150 */ +void mDvd_command_c::doClear() { + onComplete(); +} + +/** 802ef170 */ +void mDvd_command_c::done() {} + +void mDvd_command_c::waitDone() { + mStatus = 1; + OSWakeupThread(&mDvd_param_c::mInstance->mThreadQueue2); +} + +/** 802ef190 */ +void mDvd_command_c::waitUntilDone() { + while (mStatus == 0) { + OSSleepThread(&mDvd_param_c::mInstance->mThreadQueue2); + } +} + +/** 802ef1e0 */ +mDvd_param_c::mDvd_param_c() { + mFirstRequest = nullptr; + mLastRequest = nullptr; + OSInitMutex(&mMutex); + OSInitThreadQueue(&mThreadQueue1); + OSInitThreadQueue(&mThreadQueue2); + mDvd_param_c::mInstance = this; +} + +/** 802ef230 */ +void mDvd_param_c::kick() { + OSWakeupThread(&mThreadQueue1); +} + +/** 802ef240 */ +void mDvd_param_c::waitForKick() { + OSSleepThread(&mThreadQueue1); +} + +/** 802ef250 */ +mDvd_command_c *mDvd_param_c::getFirstCommand() { + return mFirstRequest; +} + +/** 802ef260 */ +void mDvd_param_c::addCommand(mDvd_command_c *cmd) { + OSThread *dvdThread = mDvd::getOSThread(); + OSThread *currThread = OSGetCurrentThread(); + if (currThread == dvdThread) { + cmd->execute(); + } else { + OSLockMutex(&mMutex); + cmd->mNext = nullptr; + if (mLastRequest == nullptr) { + mLastRequest = cmd; + mFirstRequest = cmd; + } else { + mLastRequest->mNext = cmd; + mLastRequest = cmd; + } + OSUnlockMutex(&mMutex); + kick(); + } +} + +/** 802ef310 */ +void mDvd_param_c::removeCommand(mDvd_command_c *toRemove) { + OSLockMutex(&mMutex); + mDvd_command_c *prev = nullptr; + + for (mDvd_command_c *cmd = mFirstRequest; cmd != nullptr; cmd = cmd->mNext) { + if (cmd == toRemove) { + if (prev != nullptr) { + prev->mNext = cmd->mNext; + if (mLastRequest == cmd) { + mLastRequest = prev; + } + } else { + if (mFirstRequest == mLastRequest) { + mFirstRequest = nullptr; + mLastRequest = nullptr; + } else { + mFirstRequest = cmd->mNext; + } + } + } + + prev = cmd; + } + + OSUnlockMutex(&mMutex); + kick(); +} + +u32 mDvd_param_c::executeCB(mDvd_command_c **cmd) { + (*cmd)->execute(); + return 0; +} + +/** 802ef410 */ +void mDvd_param_c::mainLoop() { + mDvd_command_c *cmd; + while (true) { + waitForKick(); + while ((cmd = getFirstCommand()) != nullptr) { + removeCommand(cmd); + executeCB(&cmd); + } + } +} + +/** 802ef460 */ +mDvd_command_c::mDvd_command_c() { + mNext = nullptr; + mStatus = 0; +} + +/** 802ef480 */ +extern "C" void fn_802EF480(mDvd_command_c *cmd) { + delete cmd; +} + +/** 802ef4a0 */ +void mDvd_command_c::destroy(mDvd_command_c **cmd) { + if (cmd != nullptr && *cmd != nullptr) { + (*cmd)->doClear(); + // TODO + delete *cmd; + *cmd = nullptr; + } +} + +/** 802ef500 */ +mDvdCommandReadCallback_c::~mDvdCommandReadCallback_c() {} + +/** 802ef560 */ +mDvdCommandReadCallback_c::mDvdCommandReadCallback_c(dvdReadCallback cb, void *cbData) { + mCallback = cb; + mCallbackData = cbData; + mDataPtr = nullptr; +} + +/* 802ef5d0 */ +mDvdCommandReadCallback_c *mDvdCommandReadCallback_c::create(dvdReadCallback cb, void *cbData) { + // TODO instshuffle + mDvdCommandReadCallback_c *cmd = new mDvdCommandReadCallback_c(cb, cbData); + if (cmd != nullptr) { + mDvd_param_c::mInstance->addCommand(cmd); + } + return cmd; +} + +/** 802ef650 */ +extern "C" void fn_802EF650() {} + +/** 802ef680 */ +u32 mDvdCommandReadCallback_c::execute() { + mDataPtr = (mCallback)(mCallbackData); + waitDone(); + return (bool)mDataPtr; +} + +/** 802ef6e0 */ +mDvd_mountMemArchive_c::~mDvd_mountMemArchive_c() {} + +/** 802ef740 */ +mDvd_mountMemArchive_c::mDvd_mountMemArchive_c(int mountDirection) { + if (mountDirection == 0) { + mountDirection = mDvd::g_mountDirection; + } + mMountDirection = mountDirection; + mCompressionType = 0; + mEntryNum = -1; + mDataPtr = nullptr; + mHeap = nullptr; + field_0x18 = 0; +} + +/** 802ef7c0 */ +int findPathWithCompressedExtension(const char *name, u8 *outType) { + return 0; // TODO +} + +/** 802ef930 */ +void setAutoStreamDecomp(bool arg) { + mDvd::isAutoStreamDecomp = arg; +} + +/** 802ef940 */ +bool getAutoStreamDecomp() { + return mDvd::isAutoStreamDecomp; +} + +// TODO maybe weak +/** 802ef950 */ +int ConvertPathToEntrynum(const char *path, u8 *outType) { + return 0; // TODO +} + +// TODO thunk +/** 802ef950 */ +int ConvertPathToEntrynum_Thunk(const char *path, u8 *outType) { + return ConvertPathToEntrynum(path, outType); +} + +/** 802ef9e0 */ +mDvd_mountMemArchive_c *mDvd_mountMemArchive_c::create(const char *path, u8 mountDirection, EGG::Heap *heap) { + u8 type; + mDvd_mountMemArchive_c *cmd = nullptr; + int entryNum = ConvertPathToEntrynum_Thunk(path, &type); + if (entryNum != -1) { + cmd = new mDvd_mountMemArchive_c(mountDirection); + if (cmd != nullptr) { + cmd->mEntryNum = entryNum; + cmd->mHeap = heap; + cmd->mCompressionType = type; + mDvd_param_c::mInstance->addCommand(cmd); + } + } + + return cmd; +} + +/** 802efa80 */ +u32 mDvd_mountMemArchive_c::execute() { + void *data; + int align; + EGG::DvdRipper::EAllocDirection allocDirection; + EGG::Archive *archive; + EGG::Heap *heap; + + heap = mHeap != nullptr ? mHeap : mDvd::sArchiveHeap; + archive = nullptr; + + allocDirection = mMountDirection == 1 ? EGG::DvdRipper::ALLOC_DIR_TOP : EGG::DvdRipper::ALLOC_DIR_BOTTOM; + data = mDvd::loadToMainRAM(mEntryNum, nullptr, heap, allocDirection, 0, (u32 *)field_0x18, 0, mCompressionType); + if (data != nullptr) { + align = -4; + if (mMountDirection == 1) { + align = 4; + } + archive = EGG::Archive::mount(data, heap, align); + } + + if (archive == nullptr) { + if (data != nullptr) { + delete data; + } + field_0x18 = 0; + } else { + mDataPtr = archive; + } + waitDone(); + return (bool)mDataPtr; +} + +/** 802efb80 */ +void *mDvd_mountMemArchive_c::getArcBinary() { + void *result = nullptr; + if (mDataPtr != nullptr) { + result = mDataPtr->mHandle.header; + } + return result; +} + +/** 802efba0 */ +void mDvd_mountMemArchive_c::onComplete() { + if (mDataPtr != nullptr) { + void *data = mDataPtr->mHandle.header; + mDataPtr->unmount(); + mDataPtr = nullptr; + if (data != nullptr) { + EGG::Heap::free(data, nullptr); + } + } +} + +/** 802efc10 */ +mDvd_toMainRam_base_c::mDvd_toMainRam_base_c(int mountDirection) { + if (mountDirection == 0) { + mountDirection = mDvd::g_mountDirection; + } + mMountDirection = mountDirection; + mDataPtr = nullptr; + field_0x10 = 0; + field_0x14 = 0; + mHeap = nullptr; +} + +/** 802efc80 */ +mDvd_toMainRam_base_c::~mDvd_toMainRam_base_c() {} + +/** 802efce0 */ +mDvd_toMainRam_arc_c::~mDvd_toMainRam_arc_c() {} + +/** 802efd40 */ +mDvd_toMainRam_arc_c::mDvd_toMainRam_arc_c(EGG::Archive *arc, int entryNum, int mountDirection) + : mDvd_toMainRam_base_c(mountDirection), mArcPtr(arc) { + mEntryNum = entryNum; +} + +/** 802efda0 */ +mDvd_toMainRam_arc_c *mDvd_toMainRam_arc_c::makeRequest(EGG::Archive *arc, int entryNum, int mountDirection, + EGG::Heap *heap) { + mDvd_toMainRam_arc_c *cmd = new mDvd_toMainRam_arc_c(arc, entryNum, mountDirection); + if (cmd != nullptr) { + cmd->mHeap = heap; + mDvd_param_c::mInstance->addCommand(cmd); + } + return cmd; +} + +/** 802efe20 */ +mDvd_toMainRam_arc_c *create(EGG::Archive *arc, const char *path, int mountDirection, EGG::Heap *heap) { + int entryNum = arc->convertPathToEntryID(path); + mDvd_toMainRam_arc_c *cmd = nullptr; + if (entryNum != -1) { + cmd = mDvd_toMainRam_arc_c::makeRequest(arc, entryNum, mountDirection, heap); + } + return cmd; +} + +/** 802efe90 */ +extern "C" void fn_802EFE90() { + // TODO +} + +/** 802efec0 */ +u32 mDvd_toMainRam_arc_c::execute() { + EGG::Heap *heap = mHeap != nullptr ? mHeap : mDvd::sArchiveHeap; + mDataPtr = mArcPtr->getFileFast(mEntryNum, heap, mMountDirection == 1 ? 0x20 : -0x20); + waitDone(); + return (bool)mDataPtr; +} + +/** 802eff40 */ +mDvd_toMainRam_normal_c::mDvd_toMainRam_normal_c(int mountDirection) : mDvd_toMainRam_base_c(mountDirection) { + mCompressionType2 = 0; + mEntryNum = -1; +} + +/** 802eff90 */ +mDvd_toMainRam_normal_c *mDvd_toMainRam_normal_c::create(const char *path, int mountDirection, EGG::Heap *heap) { + u8 type; + int entryNum = ConvertPathToEntrynum(path, &type); + mDvd_toMainRam_normal_c *cmd; + if (entryNum == -1) { + cmd = nullptr; + } else { + cmd = new mDvd_toMainRam_normal_c(mountDirection); + if (cmd != nullptr) { + cmd->mEntryNum = entryNum; + cmd->mHeap = heap; + cmd->mCompressionType2 = type; + mDvd_param_c::mInstance->addCommand(cmd); + } + } + return cmd; +} + +/** 802f0030 */ +extern "C" void fn_802F0030() { + // TODO +} + +/** 802f0060 */ +void mDvd_toMainRam_normal_c::create2(mDvd_toMainRam_normal_c **cmd, const char *path, int mountDirection, + EGG::Heap *heap) { + if (*cmd == nullptr) { + *cmd = mDvd_toMainRam_normal_c::create(path, mountDirection, heap); + } +} + +/** 802f00b0 */ +mDvd_toMainRam_normal_c::~mDvd_toMainRam_normal_c() {} + +/** 802f0110 */ +u32 mDvd_toMainRam_normal_c::execute() { + // TODO + u32 p6; + u32 p7; + EGG::Heap *heap = mHeap != nullptr ? mHeap : mDvd::sArchiveHeap; + EGG::DvdRipper::EAllocDirection allocDirection = mMountDirection == 1 ? EGG::DvdRipper::ALLOC_DIR_TOP : EGG::DvdRipper::ALLOC_DIR_BOTTOM; + mDataPtr = mDvd::loadToMainRAM(mEntryNum, 0, heap, allocDirection, 0, &p6, &p7, mCompressionType2); + if (mDataPtr != nullptr) { + field_0x10 = p6; + field_0x14 = p7; + } + waitDone(); + return (bool)mDataPtr; +} + +/** 802f01b0 */ +void mDvd_toMainRam_normal_c::onComplete() { + if (mDataPtr == nullptr) { + return; + } + EGG::Heap::free(mDataPtr, nullptr); +} From bd7a4be508600ecec4f4cc2d283f4e8a868693b2 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 17 May 2024 00:53:01 +0200 Subject: [PATCH 02/20] small quote fixes unquote --- src/m/m_dvd.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/m/m_dvd.cpp b/src/m/m_dvd.cpp index ed486c44..8c9b60b8 100644 --- a/src/m/m_dvd.cpp +++ b/src/m/m_dvd.cpp @@ -150,7 +150,7 @@ mDvd_param_c *mDvd_param_c::mInstance; /** 802ef0d0 */ mDvd_command_c::~mDvd_command_c() { - waitDone(); + waitUntilDone(); } /** 802ef130 */ @@ -287,10 +287,10 @@ extern "C" void fn_802EF480(mDvd_command_c *cmd) { /** 802ef4a0 */ void mDvd_command_c::destroy(mDvd_command_c **cmd) { - if (cmd != nullptr && *cmd != nullptr) { + // TODO fake match, this looks like an inlined dtor + if (cmd != nullptr && cmd != nullptr && *cmd != nullptr) { (*cmd)->doClear(); - // TODO - delete *cmd; + fn_802EF480(*cmd); *cmd = nullptr; } } From 70ee8e4195e4b1565d7cc48ca68ec8b5819d5b0d Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 17 May 2024 01:00:05 +0200 Subject: [PATCH 03/20] rm unneeded forward declaration --- include/m/m_dvd.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/m/m_dvd.h b/include/m/m_dvd.h index 1493e9d7..50d82203 100644 --- a/include/m/m_dvd.h +++ b/include/m/m_dvd.h @@ -38,8 +38,6 @@ public: virtual void Destruct() const {} }; -class MyThread_c; - TUncompressInfo_Base_c *findUncompressInfo(u8 type); void create(int priority, EGG::Heap *commandHeap, EGG::Heap *archiveHeap, EGG::Heap *threadHeap); From f14d3b157dcd28371cfec6ace87b8a98a73956c1 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 17 May 2024 12:03:34 +0200 Subject: [PATCH 04/20] One regswap and one thunk away --- config/SOUE01/symbols.txt | 6 +- include/egg/core/eggArchive.h | 2 +- include/egg/core/eggDvdRipper.h | 2 +- src/d/d_heap.cpp | 2 +- src/m/m_dvd.cpp | 146 +++++++++++++++++++++++++------- 5 files changed, 121 insertions(+), 37 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 1a34ef73..0a25394e 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17734,7 +17734,7 @@ run__Q24mDvd10MyThread_cFP12mDvd_param_c = .text:0x802EEE10; // type:function si __ct__Q24mDvd10MyThread_cFiPQ23EGG4Heap = .text:0x802EEE40; // type:function size:0x4C run__Q24mDvd10MyThread_cFv = .text:0x802EEE90; // type:function size:0x8 create__4mDvdFiPQ23EGG4HeapPQ23EGG4HeapPQ23EGG4Heap = .text:0x802EEEA0; // type:function size:0x88 -loadToMainRAM__4mDvdFiPcPQ23EGG4HeapQ33EGG9DvdRipper15EAllocDirectionUlPUlPUlUl = .text:0x802EEF30; // type:function size:0x158 +loadToMainRAM__4mDvdFiPcPQ23EGG4HeapQ33EGG9DvdRipper15EAllocDirectionlPUlPUlUl = .text:0x802EEF30; // type:function size:0x158 ConvertPathToEntrynum__4mDvdFPCc = .text:0x802EF090; // type:function size:0x8 IsExistPath__4mDvdFPCc = .text:0x802EF0A0; // type:function size:0x30 __dt__14mDvd_command_cFv = .text:0x802EF0D0; // type:function size:0x60 @@ -17776,7 +17776,7 @@ __dt__21mDvd_toMainRam_base_cFv = .text:0x802EFC80; // type:function size:0x58 __dt__20mDvd_toMainRam_arc_cFv = .text:0x802EFCE0; // type:function size:0x58 __ct__20mDvd_toMainRam_arc_cFPQ23EGG7Archiveii = .text:0x802EFD40; // type:function size:0x60 makeRequest__20mDvd_toMainRam_arc_cFPQ23EGG7ArchiveiiPQ23EGG4Heap = .text:0x802EFDA0; // type:function size:0x80 -create__FPQ23EGG7ArchivePCciPQ23EGG4Heap = .text:0x802EFE20; // type:function size:0x64 +create__20mDvd_toMainRam_arc_cFPQ23EGG7ArchivePCciPQ23EGG4Heap = .text:0x802EFE20; // type:function size:0x64 fn_802EFE90 = .text:0x802EFE90; // type:function size:0x30 execute__20mDvd_toMainRam_arc_cFv = .text:0x802EFEC0; // type:function size:0x78 __ct__23mDvd_toMainRam_normal_cFi = .text:0x802EFF40; // type:function size:0x4C @@ -40269,7 +40269,7 @@ sThread__4mDvd = .sbss:0x80575C24; // type:object size:0x4 data:4byte sCommandHeap__4mDvd = .sbss:0x80575C28; // type:object size:0x4 data:4byte sArchiveHeap__4mDvd = .sbss:0x80575C2C; // type:object size:0x4 data:4byte isAutoStreamDecomp__4mDvd = .sbss:0x80575C30; // type:object size:0x1 data:byte -isRegistered__4mDvd = .sbss:0x80575C31; // type:object size:0x1 data:byte +@GUARD@loadToMainRAM__4mDvdFiPcPQ23EGG4HeapQ33EGG9DvdRipper15EAllocDirectionUlPUlPUlUl@DvdFile = .sbss:0x80575C31; // type:object size:0x1 data:byte mInstance__12mDvd_param_c = .sbss:0x80575C34; // type:object size:0x4 data:4byte s_SavedCurrentHeap__5mHeap = .sbss:0x80575C38; // type:object size:0x4 data:4byte g_archiveHeap__5mHeap = .sbss:0x80575C3C; // type:object size:0x4 data:4byte diff --git a/include/egg/core/eggArchive.h b/include/egg/core/eggArchive.h index 4600a3f8..72f2ec97 100644 --- a/include/egg/core/eggArchive.h +++ b/include/egg/core/eggArchive.h @@ -40,7 +40,7 @@ public: /* 80493760 */ static Archive *findArchive(NANDFileInfo *file); /* 804937f0 */ static void appendList(Archive *); // prob private /* 80493850 */ static void removeList(Archive *); - /* 80493860 */ static Archive *mount(void *data, Heap *heap, s32 align); + /* 80493860 */ static Archive *mount(void *data, Heap *heap, int align); /* 80493950 */ static Archive *mountFST(void *data, Heap *heap, s32 align); /* 80493a40 */ static Archive *mountNandFile(NANDFileInfo *, Heap *heap, s32 align); /* 80493ac0 */ static Archive *loadFST(const char *fileName, Heap *heap, s32 align); diff --git a/include/egg/core/eggDvdRipper.h b/include/egg/core/eggDvdRipper.h index 873508d6..fc2cc374 100644 --- a/include/egg/core/eggDvdRipper.h +++ b/include/egg/core/eggDvdRipper.h @@ -20,7 +20,7 @@ public: /* 804947e0 */ static u8 *loadToMainRAM(DvdFile *file, u8 *dst, Heap *heap, EAllocDirection allocDir, u32 offset, u32 *amountRead, u32 *fileSize); /* 804949b0 */ static void *loadToMainRAMDecomp(DvdFile *file, StreamDecomp *decompressor, u8 *dst, Heap *heap, - EAllocDirection allocDir, u32 offset, s32 size, u32 maxChunkSize, u32 *amountRead, u32 *fileSize); + EAllocDirection allocDir, s32 offset, u32 size, u32 maxChunkSize, u32 *amountRead, u32 *fileSize); public: /* 80574ed0 */ static bool sErrorRetry; diff --git a/src/d/d_heap.cpp b/src/d/d_heap.cpp index a29ba328..16ad0f70 100644 --- a/src/d/d_heap.cpp +++ b/src/d/d_heap.cpp @@ -18,7 +18,7 @@ extern "C" void fn_802DE710(); // TODO TU splits? void dHeapAllocator::onAlloc(EGG::HeapAllocArg *arg) { - if (arg->heap != nullptr) { + if (arg->ptr != nullptr) { return; } if (lbl_80571C58 == 0) { diff --git a/src/m/m_dvd.cpp b/src/m/m_dvd.cpp index 8c9b60b8..48718fe7 100644 --- a/src/m/m_dvd.cpp +++ b/src/m/m_dvd.cpp @@ -5,6 +5,11 @@ #include #include #include +#include +// clang-format off +// TODO a define in here stomps another header +#include +// clang-format on namespace mDvd { @@ -38,7 +43,6 @@ mDvd::MyThread_c *sThread; EGG::Heap *sCommandHeap; EGG::Heap *sArchiveHeap; bool isAutoStreamDecomp; -bool isRegistered; /** 802eece0 */ extern "C" void fn_802EECE0(TUncompressInfo_Base_c **ptr, TUncompressInfo_Base_c **last) { @@ -119,19 +123,40 @@ void create(int priority, EGG::Heap *commandHeap, EGG::Heap *archiveHeap, EGG::H } /** 802eef30 */ -void *loadToMainRAM(int entryNum, char *dst, EGG::Heap *heap, EGG::DvdRipper::EAllocDirection allocDir, u32 offset, +void *loadToMainRAM(int entryNum, char *dst, EGG::Heap *heap, EGG::DvdRipper::EAllocDirection allocDir, s32 offset, u32 *p6, u32 *p7, u32 decompressorType) { - // TODO + void *result; + u32 amountRead = 0; + u32 fileSize = 0; - if (decompressorType == 0) { - } else { - extern EGG::DvdFile DvdFile; - if (mDvd::isRegistered == false) { - static EGG::DvdFile DvdFile; + if (decompressorType != 0) { + EGG::StreamDecomp *decomp = newUncompressObj(decompressorType); + static EGG::DvdFile DvdFile; + DvdFile.open(entryNum); - isRegistered = true; + result = EGG::DvdRipper::loadToMainRAMDecomp(&DvdFile, decomp, (u8 *)dst, heap, allocDir, offset, 0, + maxChunkSize, nullptr, nullptr); + + deleteUncompressObj(decompressorType); + u32 size = DvdFile.mFileInfo.size; + DvdFile.close(); + if (result != nullptr) { + u32 b = EGG::ExpHeap::getSizeForMBlock(result); + DCStoreRangeNoSync(result, b); + fileSize = size; + amountRead = size; } + } else { + result = EGG::DvdRipper::loadToMainRAM(entryNum, (u8 *)dst, heap, allocDir, offset, &amountRead, &fileSize); } + + if (p6 != nullptr) { + *p6 = amountRead; + } + if (p7 != nullptr) { + *p7 = fileSize; + } + return result; } int ConvertPathToEntrynum(const char *path) { @@ -316,7 +341,11 @@ mDvdCommandReadCallback_c *mDvdCommandReadCallback_c::create(dvdReadCallback cb, } /** 802ef650 */ -extern "C" void fn_802EF650() {} +extern "C" mDvdCommandReadCallback_c *fn_802EF650(dvdReadCallback cb, void *cbData) { + mDvdCommandReadCallback_c *cmd = mDvdCommandReadCallback_c::create(cb, cbData); + while (!cmd) {} + return cmd; +} /** 802ef680 */ u32 mDvdCommandReadCallback_c::execute() { @@ -343,7 +372,54 @@ mDvd_mountMemArchive_c::mDvd_mountMemArchive_c(int mountDirection) { /** 802ef7c0 */ int findPathWithCompressedExtension(const char *name, u8 *outType) { - return 0; // TODO + // TODO regswap + int num; + u8 type; + char buf[256]; + mDvd::TUncompressInfo_Base_c **ptr; + + type = 0; + buf[255] = '\0'; + num = -1; + + strncpy(buf, name, sizeof(buf)); + if (buf[255] == '\0') { + char *end = buf + strlen(buf); + // Append the compressor extension and try to find a compressed version + for (ptr = mDvd::compressors_ptr; ptr != mDvd::compressors_last; ptr++) { + strncpy(end, (*ptr)->mExtension, sizeof(buf) - (end - buf)); + num = DVDConvertPathToEntrynum(buf); + if (num != -1) { + type = (*ptr)->mType; + goto end; + } + } + // No compressed version found + *end = '\0'; + end = strrchr(buf, '/'); + if (end == nullptr) { + end = buf; + } + end = strrchr(end, '.'); + if (end != nullptr) { + // Append the compressor extension and try to find a compressed version + for (ptr = mDvd::compressors_ptr; ptr != mDvd::compressors_last; ptr++) { + strncpy(end, (*ptr)->mExtension, sizeof(buf) - (end - buf)); + num = DVDConvertPathToEntrynum(buf); + if (num != -1) { + type = (*ptr)->mType; + goto end; + } + } + *end = '\0'; + } + } + +end: + if (num != -1 && outType != nullptr) { + *outType = type; + } + return num; } /** 802ef930 */ @@ -356,13 +432,20 @@ bool getAutoStreamDecomp() { return mDvd::isAutoStreamDecomp; } -// TODO maybe weak /** 802ef950 */ int ConvertPathToEntrynum(const char *path, u8 *outType) { - return 0; // TODO + int num = DVDConvertPathToEntrynum(path); + if (num != -1) { + if (outType != nullptr) { + *outType = 0; + } + } else if (getAutoStreamDecomp()) { + num = findPathWithCompressedExtension(path, outType); + } + return num; } -// TODO thunk +// TODO This thunk needs to not be inlined! /** 802ef950 */ int ConvertPathToEntrynum_Thunk(const char *path, u8 *outType) { return ConvertPathToEntrynum(path, outType); @@ -388,32 +471,27 @@ mDvd_mountMemArchive_c *mDvd_mountMemArchive_c::create(const char *path, u8 moun /** 802efa80 */ u32 mDvd_mountMemArchive_c::execute() { - void *data; - int align; EGG::DvdRipper::EAllocDirection allocDirection; EGG::Archive *archive; + void *data; EGG::Heap *heap; heap = mHeap != nullptr ? mHeap : mDvd::sArchiveHeap; archive = nullptr; allocDirection = mMountDirection == 1 ? EGG::DvdRipper::ALLOC_DIR_TOP : EGG::DvdRipper::ALLOC_DIR_BOTTOM; - data = mDvd::loadToMainRAM(mEntryNum, nullptr, heap, allocDirection, 0, (u32 *)field_0x18, 0, mCompressionType); + data = mDvd::loadToMainRAM(mEntryNum, nullptr, heap, allocDirection, 0, &field_0x18, 0, mCompressionType); if (data != nullptr) { - align = -4; - if (mMountDirection == 1) { - align = 4; - } - archive = EGG::Archive::mount(data, heap, align); + archive = EGG::Archive::mount(data, heap, mMountDirection == 1 ? 4 : -4); } - if (archive == nullptr) { + if (archive != nullptr) { + mDataPtr = archive; + } else { if (data != nullptr) { delete data; } field_0x18 = 0; - } else { - mDataPtr = archive; } waitDone(); return (bool)mDataPtr; @@ -476,7 +554,8 @@ mDvd_toMainRam_arc_c *mDvd_toMainRam_arc_c::makeRequest(EGG::Archive *arc, int e } /** 802efe20 */ -mDvd_toMainRam_arc_c *create(EGG::Archive *arc, const char *path, int mountDirection, EGG::Heap *heap) { +mDvd_toMainRam_arc_c *mDvd_toMainRam_arc_c::create(EGG::Archive *arc, const char *path, int mountDirection, + EGG::Heap *heap) { int entryNum = arc->convertPathToEntryID(path); mDvd_toMainRam_arc_c *cmd = nullptr; if (entryNum != -1) { @@ -486,8 +565,10 @@ mDvd_toMainRam_arc_c *create(EGG::Archive *arc, const char *path, int mountDirec } /** 802efe90 */ -extern "C" void fn_802EFE90() { - // TODO +extern "C" mDvd_toMainRam_arc_c *fn_802EFE90(EGG::Archive *arc, const char *path, int mountDirection, EGG::Heap *heap) { + mDvd_toMainRam_arc_c *cmd = mDvd_toMainRam_arc_c::create(arc, path, mountDirection, heap); + while (!cmd) {} + return cmd; } /** 802efec0 */ @@ -524,8 +605,10 @@ mDvd_toMainRam_normal_c *mDvd_toMainRam_normal_c::create(const char *path, int m } /** 802f0030 */ -extern "C" void fn_802F0030() { - // TODO +extern "C" mDvd_toMainRam_normal_c *fn_802F0030(const char *path, int mountDirection, EGG::Heap *heap) { + mDvd_toMainRam_normal_c *cmd = mDvd_toMainRam_normal_c::create(path, mountDirection, heap); + while (!cmd) {} + return cmd; } /** 802f0060 */ @@ -545,7 +628,8 @@ u32 mDvd_toMainRam_normal_c::execute() { u32 p6; u32 p7; EGG::Heap *heap = mHeap != nullptr ? mHeap : mDvd::sArchiveHeap; - EGG::DvdRipper::EAllocDirection allocDirection = mMountDirection == 1 ? EGG::DvdRipper::ALLOC_DIR_TOP : EGG::DvdRipper::ALLOC_DIR_BOTTOM; + EGG::DvdRipper::EAllocDirection allocDirection = + mMountDirection == 1 ? EGG::DvdRipper::ALLOC_DIR_TOP : EGG::DvdRipper::ALLOC_DIR_BOTTOM; mDataPtr = mDvd::loadToMainRAM(mEntryNum, 0, heap, allocDirection, 0, &p6, &p7, mCompressionType2); if (mDataPtr != nullptr) { field_0x10 = p6; From 34e739ed0dadfa00dd9c63b6203dd8e1d8a5738c Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 17 May 2024 12:06:17 +0200 Subject: [PATCH 05/20] Fix two symbol names --- config/SOUE01/symbols.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 0a25394e..cf274894 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -40269,7 +40269,7 @@ sThread__4mDvd = .sbss:0x80575C24; // type:object size:0x4 data:4byte sCommandHeap__4mDvd = .sbss:0x80575C28; // type:object size:0x4 data:4byte sArchiveHeap__4mDvd = .sbss:0x80575C2C; // type:object size:0x4 data:4byte isAutoStreamDecomp__4mDvd = .sbss:0x80575C30; // type:object size:0x1 data:byte -@GUARD@loadToMainRAM__4mDvdFiPcPQ23EGG4HeapQ33EGG9DvdRipper15EAllocDirectionUlPUlPUlUl@DvdFile = .sbss:0x80575C31; // type:object size:0x1 data:byte +@GUARD@loadToMainRAM__4mDvdFiPcPQ23EGG4HeapQ33EGG9DvdRipper15EAllocDirectionlPUlPUlUl@DvdFile = .sbss:0x80575C31; // type:object size:0x1 data:byte mInstance__12mDvd_param_c = .sbss:0x80575C34; // type:object size:0x4 data:4byte s_SavedCurrentHeap__5mHeap = .sbss:0x80575C38; // type:object size:0x4 data:4byte g_archiveHeap__5mHeap = .sbss:0x80575C3C; // type:object size:0x4 data:4byte @@ -49078,7 +49078,7 @@ more_empty_space__4mDvd = .bss:0x805C0000; // type:object size:0x1638 decompressor_alloc_space__4mDvd = .bss:0x805C1638; // type:object size:0x9930 DVD_MANAGER__4mDvd = .bss:0x805CAF68; // type:object size:0x30 lbl_805CAF98 = .bss:0x805CAF98; // type:object size:0xC -@LOCAL@loadToMainRAM__4mDvdFUiPcPQ23EGG4HeapUiUiPUiPUiUi@DvdFile = .bss:0x805CAFA8; // type:object size:0xD0 +@LOCAL@loadToMainRAM__4mDvdFiPcPQ23EGG4HeapQ33EGG9DvdRipper15EAllocDirectionlPUlPUlUl@DvdFile = .bss:0x805CAFA8; // type:object size:0xD0 g_gameHeaps__5mHeap = .bss:0x805CB078; // type:object size:0x10 data:4byte lbl_805CB088 = .bss:0x805CB088; // type:object size:0x30 data:4byte lbl_805CB0B8 = .bss:0x805CB0B8; // type:object size:0x10 data:4byte From 4576d215a53d2e75ae0f697f7d62d1da41a3659c Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 17 May 2024 12:11:02 +0200 Subject: [PATCH 06/20] Fixups --- config/SOUE01/symbols.txt | 8 ++++---- include/m/m_dvd.h | 1 - src/m/m_dvd.cpp | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index cf274894..1b6259ed 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17741,7 +17741,7 @@ __dt__14mDvd_command_cFv = .text:0x802EF0D0; // type:function size:0x60 __nw__14mDvd_command_cFUl = .text:0x802EF130; // type:function size:0xC __dl__14mDvd_command_cFPv = .text:0x802EF140; // type:function size:0x8 doClear__14mDvd_command_cFv = .text:0x802EF150; // type:function size:0x10 -done__14mDvd_command_cFv = .text:0x802EF160; // type:function size:0x4 +onComplete__14mDvd_command_cFv = .text:0x802EF160; // type:function size:0x4 waitDone__14mDvd_command_cFv = .text:0x802EF170; // type:function size:0x14 waitUntilDone__14mDvd_command_cFv = .text:0x802EF190; // type:function size:0x44 __ct__12mDvd_param_cFv = .text:0x802EF1E0; // type:function size:0x50 @@ -17787,7 +17787,7 @@ __dt__23mDvd_toMainRam_normal_cFv = .text:0x802F00B0; // type:function size:0x58 execute__23mDvd_toMainRam_normal_cFv = .text:0x802F0110; // type:function size:0xA0 onComplete__23mDvd_toMainRam_normal_cFv = .text:0x802F01B0; // type:function size:0x18 __dt__Q24mDvd10MyThread_cFv = .text:0x802F01D0; // type:function size:0x58 -__sinit_\m_dvd_cpp = .text:0x802F0230; // type:function size:0xE0 +__sinit_\m_dvd_cpp = .text:0x802F0230; // type:function size:0xE0 scope:local Construct__Q24mDvd41TUncompressInfo_cCFv = .text:0x802F0310; // type:function size:0x3C Destruct__Q24mDvd41TUncompressInfo_cCFv = .text:0x802F0350; // type:function size:0x4 Construct__Q24mDvd42TUncompressInfo_cCFv = .text:0x802F0360; // type:function size:0x40 @@ -39028,10 +39028,10 @@ lbl_80573FC8 = .sdata:0x80573FC8; // type:object size:0x8 data:4byte lbl_80573FD0 = .sdata:0x80573FD0; // type:object size:0x4 lbl_80573FD4 = .sdata:0x80573FD4; // type:object size:0x1 data:byte lbl_80573FD8 = .sdata:0x80573FD8; // type:object size:0x4 data:4byte -lbl_80573FDC = .sdata:0x80573FDC; // type:object size:0x8 +lbl_80573FDC = .sdata:0x80573FDC; // type:object size:0x5 data:string lbl_80573FE4 = .sdata:0x80573FE4; // type:object size:0x4 data:string lbl_80573FE8 = .sdata:0x80573FE8; // type:object size:0x4 data:string -lbl_80573FEC = .sdata:0x80573FEC; // type:object size:0x8 +lbl_80573FEC = .sdata:0x80573FEC; // type:object size:0x5 data:string lbl_80573FF4 = .sdata:0x80573FF4; // type:object size:0x4 data:string g_DefaultGameHeapId__5mHeap = .sdata:0x80573FF8; // type:object size:0x1 data:byte lbl_80574000 = .sdata:0x80574000; // type:object size:0x8 data:4byte diff --git a/include/m/m_dvd.h b/include/m/m_dvd.h index 50d82203..4fbb2809 100644 --- a/include/m/m_dvd.h +++ b/include/m/m_dvd.h @@ -59,7 +59,6 @@ public: virtual void onComplete(); void doClear(); - void done(); void waitDone(); void waitUntilDone(); static void destroy(mDvd_command_c **cmd); diff --git a/src/m/m_dvd.cpp b/src/m/m_dvd.cpp index 48718fe7..7aff42d9 100644 --- a/src/m/m_dvd.cpp +++ b/src/m/m_dvd.cpp @@ -193,7 +193,7 @@ void mDvd_command_c::doClear() { } /** 802ef170 */ -void mDvd_command_c::done() {} +void mDvd_command_c::onComplete() {} void mDvd_command_c::waitDone() { mStatus = 1; From 12ce20d3690e4dae2789e84a28a5437914517254 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 17 May 2024 14:06:47 +0200 Subject: [PATCH 07/20] Accurater symbols --- config/SOUE01/symbols.txt | 20 +++++++-------- configure.py | 2 +- src/m/m_dvd.cpp | 52 +++++++++++++++++++-------------------- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 1b6259ed..765a1871 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -40264,11 +40264,11 @@ somePtr__4mDvd = .sbss:0x80575C10; // type:object size:0x4 data:4byte someNumber__4mDvd = .sbss:0x80575C14; // type:object size:0x4 data:4byte compressors_ptr__4mDvd = .sbss:0x80575C18; // type:object size:0x4 data:4byte compressors_last__4mDvd = .sbss:0x80575C1C; // type:object size:0x4 data:4byte -sOsThread__4mDvd = .sbss:0x80575C20; // type:object size:0x4 data:4byte -sThread__4mDvd = .sbss:0x80575C24; // type:object size:0x4 data:4byte -sCommandHeap__4mDvd = .sbss:0x80575C28; // type:object size:0x4 data:4byte -sArchiveHeap__4mDvd = .sbss:0x80575C2C; // type:object size:0x4 data:4byte -isAutoStreamDecomp__4mDvd = .sbss:0x80575C30; // type:object size:0x1 data:byte +l_OSThread__4mDvd = .sbss:0x80575C20; // type:object size:0x4 data:4byte +l_MyThread__4mDvd = .sbss:0x80575C24; // type:object size:0x4 data:4byte +l_CommandHeap__4mDvd = .sbss:0x80575C28; // type:object size:0x4 data:4byte +l_ArchiveHeap__4mDvd = .sbss:0x80575C2C; // type:object size:0x4 data:4byte +l_IsAutoStreamDecomp__4mDvd = .sbss:0x80575C30; // type:object size:0x1 data:byte @GUARD@loadToMainRAM__4mDvdFiPcPQ23EGG4HeapQ33EGG9DvdRipper15EAllocDirectionlPUlPUlUl@DvdFile = .sbss:0x80575C31; // type:object size:0x1 data:byte mInstance__12mDvd_param_c = .sbss:0x80575C34; // type:object size:0x4 data:4byte s_SavedCurrentHeap__5mHeap = .sbss:0x80575C38; // type:object size:0x4 data:4byte @@ -49068,11 +49068,11 @@ m_searchManage__10fManager_c = .bss:0x805B8548; // type:object size:0x40 lbl_805B8588 = .bss:0x805B8588; // type:object size:0xC lbl_805B8594 = .bss:0x805B8594; // type:object size:0xC lbl_805B85A0 = .bss:0x805B85A0; // type:object size:0x20 data:4byte -DECOMP_SZS__4mDvd = .bss:0x805B85C0; // type:object size:0xC data:4byte -DECOMP_LZ__4mDvd = .bss:0x805B85CC; // type:object size:0xC data:4byte -DECOMP_LH__4mDvd = .bss:0x805B85D8; // type:object size:0xC data:4byte -DECOMP_LRC__4mDvd = .bss:0x805B85E4; // type:object size:0xC data:4byte -DECOMP_RL__4mDvd = .bss:0x805B85F0; // type:object size:0xC data:4byte +s_UncompressInfoSZS__4mDvd = .bss:0x805B85C0; // type:object size:0xC data:4byte +s_UncompressInfoLZ__4mDvd = .bss:0x805B85CC; // type:object size:0xC data:4byte +s_UncompressInfoLH__4mDvd = .bss:0x805B85D8; // type:object size:0xC data:4byte +s_UncompressInfoLRC__4mDvd = .bss:0x805B85E4; // type:object size:0xC data:4byte +s_UncompressInfoRL__4mDvd = .bss:0x805B85F0; // type:object size:0xC data:4byte likely_align__4mDvd = .bss:0x805B85FC; // type:object size:0x7A04 more_empty_space__4mDvd = .bss:0x805C0000; // type:object size:0x1638 decompressor_alloc_space__4mDvd = .bss:0x805C1638; // type:object size:0x9930 diff --git a/configure.py b/configure.py index 30824191..571a23f9 100644 --- a/configure.py +++ b/configure.py @@ -301,7 +301,7 @@ config.libs = [ Object(Matching, "f/f_list.cpp"), Object(Matching, "f/f_manager.cpp"), Object(Matching, "m/m_angle.cpp"), - Object(NonMatching, "m/m_dvd.cpp"), + Object(Matching, "m/m_dvd.cpp"), Object(Matching, "m/m_heap.cpp"), Object(NonMatching, "m/m_mtx.cpp"), # framework (f_name) diff --git a/src/m/m_dvd.cpp b/src/m/m_dvd.cpp index 7aff42d9..1e6e9a64 100644 --- a/src/m/m_dvd.cpp +++ b/src/m/m_dvd.cpp @@ -13,11 +13,11 @@ namespace mDvd { -TUncompressInfo_c DECOMP_SZS(3, ".szs"); -TUncompressInfo_c DECOMP_LZ(5, ".LZ"); -TUncompressInfo_c DECOMP_LH(7, ".LH"); -TUncompressInfo_c DECOMP_LRC(8, ".LRC"); -TUncompressInfo_c DECOMP_RL(4, ".RL"); +TUncompressInfo_c s_UncompressInfoSZS(3, ".szs"); +TUncompressInfo_c s_UncompressInfoLZ(5, ".LZ"); +TUncompressInfo_c s_UncompressInfoLH(7, ".LH"); +TUncompressInfo_c s_UncompressInfoLRC(8, ".LRC"); +TUncompressInfo_c s_UncompressInfoRL(4, ".RL"); // TODO This the space within which the actual decompressors // are allocated. @@ -28,7 +28,7 @@ char decompressor_alloc_space[0x9930]; mDvd_param_c DVD_MANAGER; TUncompressInfo_Base_c *decompressorPtrs[1] = { - &DECOMP_LZ, + &s_UncompressInfoLZ, }; u8 g_mountDirection = 1; @@ -38,11 +38,11 @@ void *somePtr; u32 someNumber; TUncompressInfo_Base_c **compressors_ptr; TUncompressInfo_Base_c **compressors_last; -OSThread *sOsThread; -mDvd::MyThread_c *sThread; -EGG::Heap *sCommandHeap; -EGG::Heap *sArchiveHeap; -bool isAutoStreamDecomp; +OSThread *l_OSThread; +mDvd::MyThread_c *l_MyThread; +EGG::Heap *l_CommandHeap; +EGG::Heap *l_ArchiveHeap; +bool l_IsAutoStreamDecomp; /** 802eece0 */ extern "C" void fn_802EECE0(TUncompressInfo_Base_c **ptr, TUncompressInfo_Base_c **last) { @@ -88,11 +88,11 @@ void deleteUncompressObj(u8 type) { } OSThread *getOSThread() { - return sOsThread; + return l_OSThread; } EGG::Heap *getArchiveHeap() { - return sArchiveHeap; + return l_ArchiveHeap; } /** 802eee10 */ @@ -111,15 +111,15 @@ void *MyThread_c::run() { /** 802eeea0 */ void create(int priority, EGG::Heap *commandHeap, EGG::Heap *archiveHeap, EGG::Heap *threadHeap) { - sCommandHeap = commandHeap; - sArchiveHeap = archiveHeap; + l_CommandHeap = commandHeap; + l_ArchiveHeap = archiveHeap; mDvd::MyThread_c *thread = new (threadHeap, 0x04) mDvd::MyThread_c(priority, threadHeap); - sThread = thread; - sOsThread = thread->getMyOsThread(); + l_MyThread = thread; + l_OSThread = thread->getMyOsThread(); if (mHeap::g_assertHeap != nullptr) { thread->setThreadHeap((EGG::Heap *)mHeap::g_assertHeap); } - OSResumeThread(sThread->getMyOsThread()); + OSResumeThread(l_MyThread->getMyOsThread()); } /** 802eef30 */ @@ -180,11 +180,11 @@ mDvd_command_c::~mDvd_command_c() { /** 802ef130 */ void *mDvd_command_c::operator new(size_t size) { - return EGG::Heap::alloc(size, -4, mDvd::sCommandHeap); + return EGG::Heap::alloc(size, -4, mDvd::l_CommandHeap); } void mDvd_command_c::operator delete(void *ptr) { - EGG::Heap::free(ptr, mDvd::sCommandHeap); + EGG::Heap::free(ptr, mDvd::l_CommandHeap); } /** 802ef150 */ @@ -394,8 +394,8 @@ int findPathWithCompressedExtension(const char *name, u8 *outType) { goto end; } } - // No compressed version found *end = '\0'; + // No compressed version found end = strrchr(buf, '/'); if (end == nullptr) { end = buf; @@ -424,12 +424,12 @@ end: /** 802ef930 */ void setAutoStreamDecomp(bool arg) { - mDvd::isAutoStreamDecomp = arg; + mDvd::l_IsAutoStreamDecomp = arg; } /** 802ef940 */ bool getAutoStreamDecomp() { - return mDvd::isAutoStreamDecomp; + return mDvd::l_IsAutoStreamDecomp; } /** 802ef950 */ @@ -476,7 +476,7 @@ u32 mDvd_mountMemArchive_c::execute() { void *data; EGG::Heap *heap; - heap = mHeap != nullptr ? mHeap : mDvd::sArchiveHeap; + heap = mHeap != nullptr ? mHeap : mDvd::l_ArchiveHeap; archive = nullptr; allocDirection = mMountDirection == 1 ? EGG::DvdRipper::ALLOC_DIR_TOP : EGG::DvdRipper::ALLOC_DIR_BOTTOM; @@ -573,7 +573,7 @@ extern "C" mDvd_toMainRam_arc_c *fn_802EFE90(EGG::Archive *arc, const char *path /** 802efec0 */ u32 mDvd_toMainRam_arc_c::execute() { - EGG::Heap *heap = mHeap != nullptr ? mHeap : mDvd::sArchiveHeap; + EGG::Heap *heap = mHeap != nullptr ? mHeap : mDvd::l_ArchiveHeap; mDataPtr = mArcPtr->getFileFast(mEntryNum, heap, mMountDirection == 1 ? 0x20 : -0x20); waitDone(); return (bool)mDataPtr; @@ -627,7 +627,7 @@ u32 mDvd_toMainRam_normal_c::execute() { // TODO u32 p6; u32 p7; - EGG::Heap *heap = mHeap != nullptr ? mHeap : mDvd::sArchiveHeap; + EGG::Heap *heap = mHeap != nullptr ? mHeap : mDvd::l_ArchiveHeap; EGG::DvdRipper::EAllocDirection allocDirection = mMountDirection == 1 ? EGG::DvdRipper::ALLOC_DIR_TOP : EGG::DvdRipper::ALLOC_DIR_BOTTOM; mDataPtr = mDvd::loadToMainRAM(mEntryNum, 0, heap, allocDirection, 0, &p6, &p7, mCompressionType2); From 6f6a16ecf249c5d3ed0236c944e9c6f845627693 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 17 May 2024 14:18:18 +0200 Subject: [PATCH 08/20] thunk --- src/m/m_dvd.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/m/m_dvd.cpp b/src/m/m_dvd.cpp index 1e6e9a64..fad1585b 100644 --- a/src/m/m_dvd.cpp +++ b/src/m/m_dvd.cpp @@ -445,8 +445,7 @@ int ConvertPathToEntrynum(const char *path, u8 *outType) { return num; } -// TODO This thunk needs to not be inlined! -/** 802ef950 */ +/** 802ef9d0 */ int ConvertPathToEntrynum_Thunk(const char *path, u8 *outType) { return ConvertPathToEntrynum(path, outType); } @@ -588,7 +587,7 @@ mDvd_toMainRam_normal_c::mDvd_toMainRam_normal_c(int mountDirection) : mDvd_toMa /** 802eff90 */ mDvd_toMainRam_normal_c *mDvd_toMainRam_normal_c::create(const char *path, int mountDirection, EGG::Heap *heap) { u8 type; - int entryNum = ConvertPathToEntrynum(path, &type); + int entryNum = ConvertPathToEntrynum_Thunk(path, &type); mDvd_toMainRam_normal_c *cmd; if (entryNum == -1) { cmd = nullptr; From b926034d1d4e6770cb63cdd00abe56ed2fc36a81 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 17 May 2024 14:22:42 +0200 Subject: [PATCH 09/20] Down to 1 regshuffle --- config/SOUE01/symbols.txt | 2 +- configure.py | 2 +- src/m/m_dvd.cpp | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 765a1871..c655e4e2 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -49076,7 +49076,7 @@ s_UncompressInfoRL__4mDvd = .bss:0x805B85F0; // type:object size:0xC data:4byte likely_align__4mDvd = .bss:0x805B85FC; // type:object size:0x7A04 more_empty_space__4mDvd = .bss:0x805C0000; // type:object size:0x1638 decompressor_alloc_space__4mDvd = .bss:0x805C1638; // type:object size:0x9930 -DVD_MANAGER__4mDvd = .bss:0x805CAF68; // type:object size:0x30 +l_param__4mDvd = .bss:0x805CAF68; // type:object size:0x30 lbl_805CAF98 = .bss:0x805CAF98; // type:object size:0xC @LOCAL@loadToMainRAM__4mDvdFiPcPQ23EGG4HeapQ33EGG9DvdRipper15EAllocDirectionlPUlPUlUl@DvdFile = .bss:0x805CAFA8; // type:object size:0xD0 g_gameHeaps__5mHeap = .bss:0x805CB078; // type:object size:0x10 data:4byte diff --git a/configure.py b/configure.py index 571a23f9..30824191 100644 --- a/configure.py +++ b/configure.py @@ -301,7 +301,7 @@ config.libs = [ Object(Matching, "f/f_list.cpp"), Object(Matching, "f/f_manager.cpp"), Object(Matching, "m/m_angle.cpp"), - Object(Matching, "m/m_dvd.cpp"), + Object(NonMatching, "m/m_dvd.cpp"), Object(Matching, "m/m_heap.cpp"), Object(NonMatching, "m/m_mtx.cpp"), # framework (f_name) diff --git a/src/m/m_dvd.cpp b/src/m/m_dvd.cpp index fad1585b..48058953 100644 --- a/src/m/m_dvd.cpp +++ b/src/m/m_dvd.cpp @@ -25,8 +25,9 @@ char likely_align[0x7A04]; char more_empty_space[0x1638]; char decompressor_alloc_space[0x9930]; -mDvd_param_c DVD_MANAGER; +mDvd_param_c l_param; +// unofficial TUncompressInfo_Base_c *decompressorPtrs[1] = { &s_UncompressInfoLZ, }; @@ -38,6 +39,7 @@ void *somePtr; u32 someNumber; TUncompressInfo_Base_c **compressors_ptr; TUncompressInfo_Base_c **compressors_last; +// official OSThread *l_OSThread; mDvd::MyThread_c *l_MyThread; EGG::Heap *l_CommandHeap; From dbccf07512a38d204e2ab9e824308c354d211818 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 17 May 2024 18:36:12 +0200 Subject: [PATCH 10/20] Small clarity improvements --- include/m/m_dvd.h | 4 ++-- src/m/m_dvd.cpp | 38 ++++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/include/m/m_dvd.h b/include/m/m_dvd.h index 4fbb2809..3ae6efde 100644 --- a/include/m/m_dvd.h +++ b/include/m/m_dvd.h @@ -110,8 +110,8 @@ public: virtual u32 execute() = 0; void *mDataPtr; - int field_0x10; - u32 field_0x14; + int mAmountRead; + u32 mFileSize; EGG::Heap *mHeap; }; diff --git a/src/m/m_dvd.cpp b/src/m/m_dvd.cpp index 48058953..9f7900aa 100644 --- a/src/m/m_dvd.cpp +++ b/src/m/m_dvd.cpp @@ -126,7 +126,7 @@ void create(int priority, EGG::Heap *commandHeap, EGG::Heap *archiveHeap, EGG::H /** 802eef30 */ void *loadToMainRAM(int entryNum, char *dst, EGG::Heap *heap, EGG::DvdRipper::EAllocDirection allocDir, s32 offset, - u32 *p6, u32 *p7, u32 decompressorType) { + u32 *outAmountRead, u32 *outFileSize, u32 decompressorType) { void *result; u32 amountRead = 0; u32 fileSize = 0; @@ -152,11 +152,11 @@ void *loadToMainRAM(int entryNum, char *dst, EGG::Heap *heap, EGG::DvdRipper::EA result = EGG::DvdRipper::loadToMainRAM(entryNum, (u8 *)dst, heap, allocDir, offset, &amountRead, &fileSize); } - if (p6 != nullptr) { - *p6 = amountRead; + if (outAmountRead != nullptr) { + *outAmountRead = amountRead; } - if (p7 != nullptr) { - *p7 = fileSize; + if (outFileSize != nullptr) { + *outFileSize = fileSize; } return result; } @@ -167,8 +167,7 @@ int ConvertPathToEntrynum(const char *path) { u32 IsExistPath(const char *path) { u32 entry = ConvertPathToEntrynum(path); - // TODO fake match - return (((-entry - 1) | (entry + 1)) >> 0x1f); + return entry != -1; } } // namespace mDvd @@ -374,9 +373,9 @@ mDvd_mountMemArchive_c::mDvd_mountMemArchive_c(int mountDirection) { /** 802ef7c0 */ int findPathWithCompressedExtension(const char *name, u8 *outType) { - // TODO regswap - int num; + // TODO regshuffle u8 type; + int num; char buf[256]; mDvd::TUncompressInfo_Base_c **ptr; @@ -393,7 +392,7 @@ int findPathWithCompressedExtension(const char *name, u8 *outType) { num = DVDConvertPathToEntrynum(buf); if (num != -1) { type = (*ptr)->mType; - goto end; + goto out; } } *end = '\0'; @@ -410,14 +409,14 @@ int findPathWithCompressedExtension(const char *name, u8 *outType) { num = DVDConvertPathToEntrynum(buf); if (num != -1) { type = (*ptr)->mType; - goto end; + goto out; } } *end = '\0'; } } -end: +out: if (num != -1 && outType != nullptr) { *outType = type; } @@ -526,8 +525,8 @@ mDvd_toMainRam_base_c::mDvd_toMainRam_base_c(int mountDirection) { } mMountDirection = mountDirection; mDataPtr = nullptr; - field_0x10 = 0; - field_0x14 = 0; + mAmountRead = 0; + mFileSize = 0; mHeap = nullptr; } @@ -625,16 +624,15 @@ mDvd_toMainRam_normal_c::~mDvd_toMainRam_normal_c() {} /** 802f0110 */ u32 mDvd_toMainRam_normal_c::execute() { - // TODO - u32 p6; - u32 p7; + u32 amountRead; + u32 fileSize; EGG::Heap *heap = mHeap != nullptr ? mHeap : mDvd::l_ArchiveHeap; EGG::DvdRipper::EAllocDirection allocDirection = mMountDirection == 1 ? EGG::DvdRipper::ALLOC_DIR_TOP : EGG::DvdRipper::ALLOC_DIR_BOTTOM; - mDataPtr = mDvd::loadToMainRAM(mEntryNum, 0, heap, allocDirection, 0, &p6, &p7, mCompressionType2); + mDataPtr = mDvd::loadToMainRAM(mEntryNum, 0, heap, allocDirection, 0, &amountRead, &fileSize, mCompressionType2); if (mDataPtr != nullptr) { - field_0x10 = p6; - field_0x14 = p7; + mAmountRead = amountRead; + mFileSize = fileSize; } waitDone(); return (bool)mDataPtr; From 0be8a31d4b5cded08ab25343101a9aed8fac6d88 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 17 May 2024 19:42:12 +0200 Subject: [PATCH 11/20] Rename --- include/m/m_dvd.h | 2 +- src/m/m_dvd.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/m/m_dvd.h b/include/m/m_dvd.h index 3ae6efde..17087eb2 100644 --- a/include/m/m_dvd.h +++ b/include/m/m_dvd.h @@ -100,7 +100,7 @@ public: int mEntryNum; EGG::Archive *mDataPtr; EGG::Heap *mHeap; - u32 field_0x18; + u32 mAmountRead; }; class mDvd_toMainRam_base_c : public mDvd_command_c { diff --git a/src/m/m_dvd.cpp b/src/m/m_dvd.cpp index 9f7900aa..72e7d45f 100644 --- a/src/m/m_dvd.cpp +++ b/src/m/m_dvd.cpp @@ -368,7 +368,7 @@ mDvd_mountMemArchive_c::mDvd_mountMemArchive_c(int mountDirection) { mEntryNum = -1; mDataPtr = nullptr; mHeap = nullptr; - field_0x18 = 0; + mAmountRead = 0; } /** 802ef7c0 */ @@ -480,7 +480,7 @@ u32 mDvd_mountMemArchive_c::execute() { archive = nullptr; allocDirection = mMountDirection == 1 ? EGG::DvdRipper::ALLOC_DIR_TOP : EGG::DvdRipper::ALLOC_DIR_BOTTOM; - data = mDvd::loadToMainRAM(mEntryNum, nullptr, heap, allocDirection, 0, &field_0x18, 0, mCompressionType); + data = mDvd::loadToMainRAM(mEntryNum, nullptr, heap, allocDirection, 0, &mAmountRead, 0, mCompressionType); if (data != nullptr) { archive = EGG::Archive::mount(data, heap, mMountDirection == 1 ? 4 : -4); } @@ -491,7 +491,7 @@ u32 mDvd_mountMemArchive_c::execute() { if (data != nullptr) { delete data; } - field_0x18 = 0; + mAmountRead = 0; } waitDone(); return (bool)mDataPtr; From 4f18026ff542cb67d075bd472ff98a4bdb57e742 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 17 May 2024 19:51:16 +0200 Subject: [PATCH 12/20] Fix vtable size --- config/SOUE01/symbols.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index c655e4e2..ba4c1a1c 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -35728,7 +35728,7 @@ __vt__Q24mDvd41TUncompressInfo_c = .data:0x80542900; // __vt__Q24mDvd42TUncompressInfo_c = .data:0x80542914; // type:object size:0x14 __vt__Q24mDvd41TUncompressInfo_c = .data:0x80542928; // type:object size:0x14 __vt__Q24mDvd41TUncompressInfo_c = .data:0x8054293C; // type:object size:0x14 -__vt__Q24mDvd42TUncompressInfo_c = .data:0x80542950; // type:object size:0x18 +__vt__Q24mDvd42TUncompressInfo_c = .data:0x80542950; // type:object size:0x14 lbl_80542968 = .data:0x80542968; // type:object size:0x28 lbl_80542990 = .data:0x80542990; // type:object size:0x29 lbl_805429BC = .data:0x805429BC; // type:object size:0x29 From e6d5ea1b385966ec0528d47e7310d20f53ede3f7 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 19 May 2024 15:59:24 +0200 Subject: [PATCH 13/20] Fix symbol names --- config/SOUE01/symbols.txt | 8 ++++---- include/m/m_dvd.h | 18 ++++-------------- src/m/m_dvd.cpp | 30 ++++++++++++++++-------------- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index ba4c1a1c..187b3e97 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17740,8 +17740,8 @@ IsExistPath__4mDvdFPCc = .text:0x802EF0A0; // type:function size:0x30 __dt__14mDvd_command_cFv = .text:0x802EF0D0; // type:function size:0x60 __nw__14mDvd_command_cFUl = .text:0x802EF130; // type:function size:0xC __dl__14mDvd_command_cFPv = .text:0x802EF140; // type:function size:0x8 -doClear__14mDvd_command_cFv = .text:0x802EF150; // type:function size:0x10 -onComplete__14mDvd_command_cFv = .text:0x802EF160; // type:function size:0x4 +done__14mDvd_command_cFv = .text:0x802EF150; // type:function size:0x10 +doClear__14mDvd_command_cFv = .text:0x802EF160; // type:function size:0x4 waitDone__14mDvd_command_cFv = .text:0x802EF170; // type:function size:0x14 waitUntilDone__14mDvd_command_cFv = .text:0x802EF190; // type:function size:0x44 __ct__12mDvd_param_cFv = .text:0x802EF1E0; // type:function size:0x50 @@ -17770,7 +17770,7 @@ ConvertPathToEntrynum_Thunk__FPCcPUc = .text:0x802EF9D0; // type:function size:0 create__22mDvd_mountMemArchive_cFPCcUcPQ23EGG4Heap = .text:0x802EF9E0; // type:function size:0xA0 execute__22mDvd_mountMemArchive_cFv = .text:0x802EFA80; // type:function size:0xF8 getArcBinary__22mDvd_mountMemArchive_cFv = .text:0x802EFB80; // type:function size:0x18 -onComplete__22mDvd_mountMemArchive_cFv = .text:0x802EFBA0; // type:function size:0x64 +doClear__22mDvd_mountMemArchive_cFv = .text:0x802EFBA0; // type:function size:0x64 __ct__21mDvd_toMainRam_base_cFi = .text:0x802EFC10; // type:function size:0x6C __dt__21mDvd_toMainRam_base_cFv = .text:0x802EFC80; // type:function size:0x58 __dt__20mDvd_toMainRam_arc_cFv = .text:0x802EFCE0; // type:function size:0x58 @@ -17785,7 +17785,7 @@ fn_802F0030 = .text:0x802F0030; // type:function size:0x30 create2__23mDvd_toMainRam_normal_cFPP23mDvd_toMainRam_normal_cPCciPQ23EGG4Heap = .text:0x802F0060; // type:function size:0x48 __dt__23mDvd_toMainRam_normal_cFv = .text:0x802F00B0; // type:function size:0x58 execute__23mDvd_toMainRam_normal_cFv = .text:0x802F0110; // type:function size:0xA0 -onComplete__23mDvd_toMainRam_normal_cFv = .text:0x802F01B0; // type:function size:0x18 +doClear__23mDvd_toMainRam_normal_cFv = .text:0x802F01B0; // type:function size:0x18 __dt__Q24mDvd10MyThread_cFv = .text:0x802F01D0; // type:function size:0x58 __sinit_\m_dvd_cpp = .text:0x802F0230; // type:function size:0xE0 scope:local Construct__Q24mDvd41TUncompressInfo_cCFv = .text:0x802F0310; // type:function size:0x3C diff --git a/include/m/m_dvd.h b/include/m/m_dvd.h index 17087eb2..a780afd6 100644 --- a/include/m/m_dvd.h +++ b/include/m/m_dvd.h @@ -5,10 +5,6 @@ #include #include -// TODO these are scattered -int findPathWithCompressedExtension(const char *name, u8 *outType); -int ConvertPathToEntrynum(const char *path, u8 *outType); - // TODO onComplete -> doClear? namespace mDvd { @@ -38,13 +34,7 @@ public: virtual void Destruct() const {} }; -TUncompressInfo_Base_c *findUncompressInfo(u8 type); - void create(int priority, EGG::Heap *commandHeap, EGG::Heap *archiveHeap, EGG::Heap *threadHeap); -void *loadToMainRAM(u32 entryNum, char *dst, EGG::Heap *heap, EGG::DvdRipper::EAllocDirection allocDir, u32 offset, u32 *p6, u32 *p7, - u32 decompressorType); - -u32 IsExistPath(const char *path); OSThread *getOSThread(); EGG::Heap *getArchiveHeap(); @@ -56,9 +46,9 @@ public: virtual ~mDvd_command_c(); virtual u32 execute() = 0; - virtual void onComplete(); + virtual void doClear(); - void doClear(); + void done(); void waitDone(); void waitUntilDone(); static void destroy(mDvd_command_c **cmd); @@ -92,7 +82,7 @@ public: mDvd_mountMemArchive_c(int mountDirection); virtual ~mDvd_mountMemArchive_c(); virtual u32 execute(); - virtual void onComplete(); + virtual void doClear(); static mDvd_mountMemArchive_c *create(const char *path, u8 mountDirection, EGG::Heap *heap); void *getArcBinary(); @@ -133,7 +123,7 @@ public: mDvd_toMainRam_normal_c(int mountDirection); ~mDvd_toMainRam_normal_c(); virtual u32 execute(); - virtual void onComplete(); + virtual void doClear(); static mDvd_toMainRam_normal_c *create(const char *path, int mountDirection, EGG::Heap *heap); static void create2(mDvd_toMainRam_normal_c **cmd, const char *path, int mountDirection, EGG::Heap *heap); diff --git a/src/m/m_dvd.cpp b/src/m/m_dvd.cpp index 72e7d45f..3719b92a 100644 --- a/src/m/m_dvd.cpp +++ b/src/m/m_dvd.cpp @@ -11,6 +11,8 @@ #include // clang-format on +static int ConvertPathToEntrynum(const char *path, u8 *outType); + namespace mDvd { TUncompressInfo_c s_UncompressInfoSZS(3, ".szs"); @@ -60,7 +62,7 @@ extern "C" void fn_802EECF0() { } /** 802eed30 */ -TUncompressInfo_Base_c *findUncompressInfo(u8 type) { +static TUncompressInfo_Base_c *findUncompressInfo(u8 type) { TUncompressInfo_Base_c **ptr = compressors_ptr; while (ptr != compressors_last) { if ((*ptr)->mType == type) { @@ -72,7 +74,7 @@ TUncompressInfo_Base_c *findUncompressInfo(u8 type) { } /** 802eed70 */ -EGG::StreamDecomp *newUncompressObj(u8 type) { +static EGG::StreamDecomp *newUncompressObj(u8 type) { TUncompressInfo_Base_c *factory = findUncompressInfo(type); if (factory != nullptr) { return factory->Construct(); @@ -82,7 +84,7 @@ EGG::StreamDecomp *newUncompressObj(u8 type) { } /** 802eedb0 */ -void deleteUncompressObj(u8 type) { +static void deleteUncompressObj(u8 type) { TUncompressInfo_Base_c *factory = findUncompressInfo(type); if (factory != nullptr) { factory->Destruct(); @@ -125,7 +127,7 @@ void create(int priority, EGG::Heap *commandHeap, EGG::Heap *archiveHeap, EGG::H } /** 802eef30 */ -void *loadToMainRAM(int entryNum, char *dst, EGG::Heap *heap, EGG::DvdRipper::EAllocDirection allocDir, s32 offset, +static void *loadToMainRAM(int entryNum, char *dst, EGG::Heap *heap, EGG::DvdRipper::EAllocDirection allocDir, s32 offset, u32 *outAmountRead, u32 *outFileSize, u32 decompressorType) { void *result; u32 amountRead = 0; @@ -161,11 +163,11 @@ void *loadToMainRAM(int entryNum, char *dst, EGG::Heap *heap, EGG::DvdRipper::EA return result; } -int ConvertPathToEntrynum(const char *path) { +static int ConvertPathToEntrynum(const char *path) { return ::ConvertPathToEntrynum(path, nullptr); } -u32 IsExistPath(const char *path) { +static u32 IsExistPath(const char *path) { u32 entry = ConvertPathToEntrynum(path); return entry != -1; } @@ -189,12 +191,12 @@ void mDvd_command_c::operator delete(void *ptr) { } /** 802ef150 */ -void mDvd_command_c::doClear() { - onComplete(); +void mDvd_command_c::done() { + doClear(); } /** 802ef170 */ -void mDvd_command_c::onComplete() {} +void mDvd_command_c::doClear() {} void mDvd_command_c::waitDone() { mStatus = 1; @@ -315,7 +317,7 @@ extern "C" void fn_802EF480(mDvd_command_c *cmd) { void mDvd_command_c::destroy(mDvd_command_c **cmd) { // TODO fake match, this looks like an inlined dtor if (cmd != nullptr && cmd != nullptr && *cmd != nullptr) { - (*cmd)->doClear(); + (*cmd)->done(); fn_802EF480(*cmd); *cmd = nullptr; } @@ -434,7 +436,7 @@ bool getAutoStreamDecomp() { } /** 802ef950 */ -int ConvertPathToEntrynum(const char *path, u8 *outType) { +static int ConvertPathToEntrynum(const char *path, u8 *outType) { int num = DVDConvertPathToEntrynum(path); if (num != -1) { if (outType != nullptr) { @@ -447,7 +449,7 @@ int ConvertPathToEntrynum(const char *path, u8 *outType) { } /** 802ef9d0 */ -int ConvertPathToEntrynum_Thunk(const char *path, u8 *outType) { +static int ConvertPathToEntrynum_Thunk(const char *path, u8 *outType) { return ConvertPathToEntrynum(path, outType); } @@ -507,7 +509,7 @@ void *mDvd_mountMemArchive_c::getArcBinary() { } /** 802efba0 */ -void mDvd_mountMemArchive_c::onComplete() { +void mDvd_mountMemArchive_c::doClear() { if (mDataPtr != nullptr) { void *data = mDataPtr->mHandle.header; mDataPtr->unmount(); @@ -639,7 +641,7 @@ u32 mDvd_toMainRam_normal_c::execute() { } /** 802f01b0 */ -void mDvd_toMainRam_normal_c::onComplete() { +void mDvd_toMainRam_normal_c::doClear() { if (mDataPtr == nullptr) { return; } From 725e43dd690968e66631c3e38c3f477c656fd271 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 19 May 2024 16:18:26 +0200 Subject: [PATCH 14/20] Names --- config/SOUE01/symbols.txt | 4 ++-- include/m/m_dvd.h | 4 +++- src/m/m_dvd.cpp | 10 +++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 187b3e97..71a0c2b2 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17723,8 +17723,8 @@ __dt__Q24mDvd41TUncompressInfo_cFv = .text:0x802EEBE0; / __dt__Q24mDvd41TUncompressInfo_cFv = .text:0x802EEC20; // type:function size:0x40 __dt__Q24mDvd42TUncompressInfo_cFv = .text:0x802EEC60; // type:function size:0x40 __dt__Q24mDvd41TUncompressInfo_cFv = .text:0x802EECA0; // type:function size:0x40 -fn_802EECE0 = .text:0x802EECE0; // type:function size:0xC -fn_802EECF0 = .text:0x802EECF0; // type:function size:0x40 +unk_setDecompressorPtrs__4mDvdFPPQ24mDvd22TUncompressInfo_Base_cPPQ24mDvd22TUncompressInfo_Base_c = .text:0x802EECE0; // type:function size:0xC +unk_initDecompressors__4mDvdFv = .text:0x802EECF0; // type:function size:0x40 findUncompressInfo__4mDvdFUc = .text:0x802EED30; // type:function size:0x3C newUncompressObj__4mDvdFUc = .text:0x802EED70; // type:function size:0x40 deleteUncompressObj__4mDvdFUc = .text:0x802EEDB0; // type:function size:0x38 diff --git a/include/m/m_dvd.h b/include/m/m_dvd.h index a780afd6..dee59241 100644 --- a/include/m/m_dvd.h +++ b/include/m/m_dvd.h @@ -5,7 +5,7 @@ #include #include -// TODO onComplete -> doClear? +void unk_initDecompressors(); namespace mDvd { @@ -35,6 +35,8 @@ public: }; void create(int priority, EGG::Heap *commandHeap, EGG::Heap *archiveHeap, EGG::Heap *threadHeap); +int ConvertPathToEntrynum(const char *path); +u32 IsExistPath(const char *path); OSThread *getOSThread(); EGG::Heap *getArchiveHeap(); diff --git a/src/m/m_dvd.cpp b/src/m/m_dvd.cpp index 3719b92a..ef4819d2 100644 --- a/src/m/m_dvd.cpp +++ b/src/m/m_dvd.cpp @@ -49,14 +49,14 @@ EGG::Heap *l_ArchiveHeap; bool l_IsAutoStreamDecomp; /** 802eece0 */ -extern "C" void fn_802EECE0(TUncompressInfo_Base_c **ptr, TUncompressInfo_Base_c **last) { +static void unk_setDecompressorPtrs(TUncompressInfo_Base_c **ptr, TUncompressInfo_Base_c **last) { compressors_ptr = ptr; compressors_last = last; } /** 802eecf0 */ -extern "C" void fn_802EECF0() { - fn_802EECE0(decompressorPtrs, &decompressorPtrs[1]); +void unk_initDecompressors() { + unk_setDecompressorPtrs(decompressorPtrs, &decompressorPtrs[1]); somePtr = decompressor_alloc_space; someNumber = 0x24; } @@ -163,11 +163,11 @@ static void *loadToMainRAM(int entryNum, char *dst, EGG::Heap *heap, EGG::DvdRip return result; } -static int ConvertPathToEntrynum(const char *path) { +int ConvertPathToEntrynum(const char *path) { return ::ConvertPathToEntrynum(path, nullptr); } -static u32 IsExistPath(const char *path) { +u32 IsExistPath(const char *path) { u32 entry = ConvertPathToEntrynum(path); return entry != -1; } From c1ca74d657fb11b67435d6e5679ab6482c4c5516 Mon Sep 17 00:00:00 2001 From: robojumper Date: Mon, 20 May 2024 23:22:31 +0200 Subject: [PATCH 15/20] DynamicLink --- config/SOUE01/splits.txt | 16 +- config/SOUE01/symbols.txt | 168 ++++++++--------- configure.py | 4 + include/DynamicLink.h | 96 ++++++++++ include/d/d_dvd.h | 41 +++++ include/d/d_dvd_unk.h | 26 +++ include/d/d_dylink.h | 12 ++ include/m/m_dvd.h | 18 +- include/rvl/OS/OSLink.h | 109 ++++++++++- src/DynamicLink.cpp | 373 ++++++++++++++++++++++++++++++++++++++ src/d/d_dvd.cpp | 62 +++++++ src/d/d_dvd_unk.cpp | 44 +++++ src/d/d_dylink.cpp | 130 +++++++++++++ src/m/m_dvd.cpp | 21 +-- 14 files changed, 1013 insertions(+), 107 deletions(-) create mode 100644 include/DynamicLink.h create mode 100644 include/d/d_dvd.h create mode 100644 include/d/d_dvd_unk.h create mode 100644 include/d/d_dylink.h create mode 100644 src/DynamicLink.cpp create mode 100644 src/d/d_dvd.cpp create mode 100644 src/d/d_dvd_unk.cpp create mode 100644 src/d/d_dylink.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index bedcd3d5..5ca0c46b 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -55,11 +55,19 @@ d/d_cc.cpp: .text start:0x80050A20 end:0x800520F0 d/d_dvd.cpp: - .text start:0x800520F0 end:0x80052E00 + .text start:0x800520F0 end:0x800522FC + .data start:0x805033F0 end:0x80503400 + .sdata start:0x80571C10 end:0x80571C20 + +d/d_dvd_unk.cpp: + .text start:0x80052300 end:0x80052E00 + .sbss start:0x805750D0 end:0x805750D8 d/d_dylink.cpp: .text start:0x80052E00 end:0x80053A30 .ctors start:0x804DB674 end:0x804DB678 + .data start:0x8050D2D8 end:0x8050D30C + .sbss start:0x805750E0 end:0x805750FC d/d_fader.cpp: .text start:0x80053A30 end:0x80053E70 @@ -183,6 +191,12 @@ toBeSorted/counters/extra_wallet_counter.cpp: .data start:0x805280B0 end:0x805280D0 .sbss start:0x80575640 end:0x80575648 +DynamicLink.cpp: + .text start:0x802DF100 end:0x802DFCB0 + .data start:0x805419E8 end:0x80541A70 + .sdata start:0x80573F78 end:0x80573FB0 + .sbss start:0x80575B80 end:0x80575BA0 + c/c_list.cpp: .text start:0x802E08C0 end:0x802E0A10 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 71a0c2b2..1ae97d22 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -2140,16 +2140,16 @@ fn_80052060 = .text:0x80052060; // type:function size:0x10 fn_80052070 = .text:0x80052070; // type:function size:0x10 fn_80052080 = .text:0x80052080; // type:function size:0x10 fn_80052090 = .text:0x80052090; // type:function size:0x60 -fn_800520F0 = .text:0x800520F0; // type:function size:0x4 -fn_80052100 = .text:0x80052100; // type:function size:0x28 -fn_80052130 = .text:0x80052130; // type:function size:0x40 -fn_80052170 = .text:0x80052170; // type:function size:0x128 -fn_800522A0 = .text:0x800522A0; // type:function size:0x5C -fn_80052300 = .text:0x80052300; // type:function size:0x34 -fn_80052340 = .text:0x80052340; // type:function size:0x8 -fn_80052350 = .text:0x80052350; // type:function size:0x35C +create__4dDvdFlPQ23EGG4HeapPQ23EGG4HeapPQ23EGG4Heap = .text:0x800520F0; // type:function size:0x4 +__ct__Q24dDvd8loader_cFv = .text:0x80052100; // type:function size:0x28 +__dt__Q24dDvd8loader_cFv = .text:0x80052130; // type:function size:0x40 +request__Q24dDvd8loader_cFPCcUcPQ23EGG4Heap = .text:0x80052170; // type:function size:0x128 +remove__Q24dDvd8loader_cFv = .text:0x800522A0; // type:function size:0x5C +create__Q24dDvd11unkstruct_cFPQ23EGG4Heap = .text:0x80052300; // type:function size:0x34 +getUnk__Q24dDvd11unkstruct_cFv = .text:0x80052340; // type:function size:0x8 +draw__Q27dDvdUnk11unkstruct_cFv = .text:0x80052350; // type:function size:0x35C fn_800526B0 = .text:0x800526B0; // type:function size:0x98 -fn_80052750 = .text:0x80052750; // type:function size:0x10 +init__Q24dDvd11unkstruct_cFv = .text:0x80052750; // type:function size:0x10 fn_80052760 = .text:0x80052760; // type:function size:0x88 fn_800527F0 = .text:0x800527F0; // type:function size:0x11C fn_80052910 = .text:0x80052910; // type:function size:0x48 @@ -2169,7 +2169,7 @@ fn_80052D50 = .text:0x80052D50; // type:function size:0x78 fn_80052DD0 = .text:0x80052DD0; // type:function size:0x2C fn_80052E00 = .text:0x80052E00; // type:function size:0x1A0 fn_80052FA0 = .text:0x80052FA0; // type:function size:0x30 -fn_80052FD0 = .text:0x80052FD0; // type:function size:0x20 +Unlink__4dDylFUs = .text:0x80052FD0; // type:function size:0x20 fn_80052FF0 = .text:0x80052FF0; // type:function size:0x84 fn_80053080 = .text:0x80053080; // type:function size:0x58 fn_800530E0 = .text:0x800530E0; // type:function size:0x7C @@ -2182,9 +2182,9 @@ fn_80053780 = .text:0x80053780; // type:function size:0x54 fn_800537E0 = .text:0x800537E0; // type:function size:0x30 fn_80053810 = .text:0x80053810; // type:function size:0x6C fn_80053880 = .text:0x80053880; // type:function size:0xC -fn_80053890 = .text:0x80053890; // type:function size:0xA0 +do_link__21dDynamicModuleControlFv = .text:0x80053890; // type:function size:0xA0 fn_80053930 = .text:0x80053930; // type:function size:0x9C -fn_800539D0 = .text:0x800539D0; // type:function size:0x54 +__sinit_\d_dylink_cpp = .text:0x800539D0; // type:function size:0x54 fn_80053A30 = .text:0x80053A30; // type:function size:0xE4 fn_80053B20 = .text:0x80053B20; // type:function size:0x128 fn_80053C50 = .text:0x80053C50; // type:function size:0x198 @@ -17229,42 +17229,42 @@ fn_802DEFE0 = .text:0x802DEFE0; // type:function size:0x80 OSReport = .text:0x802DF060; // type:function size:0x80 scope:weak OSVReport = .text:0x802DF0E0; // type:function size:0x4 scope:global fn_802DF0F0 = .text:0x802DF0F0; // type:function size:0x10 -fn_802DF100 = .text:0x802DF100; // type:function size:0xA0 -fn_802DF1A0 = .text:0x802DF1A0; // type:function size:0x48 -fn_802DF1F0 = .text:0x802DF1F0; // type:function size:0x94 -fn_802DF290 = .text:0x802DF290; // type:function size:0x74 -fn_802DF310 = .text:0x802DF310; // type:function size:0x24 -fn_802DF340 = .text:0x802DF340; // type:function size:0x8 -fn_802DF350 = .text:0x802DF350; // type:function size:0x8 -fn_802DF360 = .text:0x802DF360; // type:function size:0x8 -fn_802DF370 = .text:0x802DF370; // type:function size:0x4 -fn_802DF380 = .text:0x802DF380; // type:function size:0x8 -fn_802DF390 = .text:0x802DF390; // type:function size:0x8 -fn_802DF3A0 = .text:0x802DF3A0; // type:function size:0x8 -fn_802DF3B0 = .text:0x802DF3B0; // type:function size:0x8 -fn_802DF3C0 = .text:0x802DF3C0; // type:function size:0x8 -fn_802DF3D0 = .text:0x802DF3D0; // type:function size:0x80 -fn_802DF450 = .text:0x802DF450; // type:function size:0x68 -fn_802DF4C0 = .text:0x802DF4C0; // type:function size:0x8 -fn_802DF4D0 = .text:0x802DF4D0; // type:function size:0x5C -fn_802DF530 = .text:0x802DF530; // type:function size:0x10 -fn_802DF540 = .text:0x802DF540; // type:function size:0x84 -fn_802DF5D0 = .text:0x802DF5D0; // type:function size:0x138 -fn_802DF710 = .text:0x802DF710; // type:function size:0x8C -fn_802DF7A0 = .text:0x802DF7A0; // type:function size:0x54 -fn_802DF800 = .text:0x802DF800; // type:function size:0x4 -fn_802DF810 = .text:0x802DF810; // type:function size:0x250 -fn_802DFA60 = .text:0x802DFA60; // type:function size:0xA4 -fn_802DFB10 = .text:0x802DFB10; // type:function size:0x5C -fn_802DFB70 = .text:0x802DFB70; // type:function size:0x18 -fn_802DFB90 = .text:0x802DFB90; // type:function size:0x60 -fn_802DFBF0 = .text:0x802DFBF0; // type:function size:0x70 -fn_802DFC60 = .text:0x802DFC60; // type:function size:0x50 -fn_802DFCB0 = .text:0x802DFCB0; // type:function size:0x4 -fn_802DFCC0 = .text:0x802DFCC0; // type:function size:0x4 -fn_802DFCD0 = .text:0x802DFCD0; // type:function size:0x4 -fn_802DFCE0 = .text:0x802DFCE0; // type:function size:0x44 -fn_802DFD30 = .text:0x802DFD30; // type:function size:0x44 +__dt__24DynamicModuleControlBaseFv = .text:0x802DF100; // type:function size:0xA0 +__ct__24DynamicModuleControlBaseFv = .text:0x802DF1A0; // type:function size:0x48 +link__24DynamicModuleControlBaseFv = .text:0x802DF1F0; // type:function size:0x94 +unlink__24DynamicModuleControlBaseFv = .text:0x802DF290; // type:function size:0x74 +load_async__24DynamicModuleControlBaseFv = .text:0x802DF310; // type:function size:0x24 +getModuleName__24DynamicModuleControlBaseCFv = .text:0x802DF340; // type:function size:0x8 +getModuleSize__24DynamicModuleControlBaseCFv = .text:0x802DF350; // type:function size:0x8 +getModuleTypeString__24DynamicModuleControlBaseCFv = .text:0x802DF360; // type:function size:0x8 +dump__24DynamicModuleControlBaseFv = .text:0x802DF370; // type:function size:0x4 +do_load__24DynamicModuleControlBaseFv = .text:0x802DF380; // type:function size:0x8 +do_load_async__24DynamicModuleControlBaseFv = .text:0x802DF390; // type:function size:0x8 +do_unload__24DynamicModuleControlBaseFv = .text:0x802DF3A0; // type:function size:0x8 +do_link__24DynamicModuleControlBaseFv = .text:0x802DF3B0; // type:function size:0x8 +do_unlink__24DynamicModuleControlBaseFv = .text:0x802DF3C0; // type:function size:0x8 +__ct__20DynamicModuleControlFPCcPQ23EGG7ExpHeap = .text:0x802DF3D0; // type:function size:0x80 +__dt__20DynamicModuleControlFv = .text:0x802DF450; // type:function size:0x68 +getModuleName__20DynamicModuleControlCFv = .text:0x802DF4C0; // type:function size:0x8 +initialize__20DynamicModuleControlFPQ23EGG7ExpHeap = .text:0x802DF4D0; // type:function size:0x5C +callback__20DynamicModuleControlFPv = .text:0x802DF530; // type:function size:0x10 +checkHeapStatus__20DynamicModuleControlFv = .text:0x802DF540; // type:function size:0x84 +do_load__20DynamicModuleControlFv = .text:0x802DF5D0; // type:function size:0x138 +do_load_async__20DynamicModuleControlFv = .text:0x802DF710; // type:function size:0x8C +do_unload__20DynamicModuleControlFv = .text:0x802DF7A0; // type:function size:0x54 +dump__20DynamicModuleControlFv = .text:0x802DF800; // type:function size:0x4 +do_link__20DynamicModuleControlFv = .text:0x802DF810; // type:function size:0x250 +do_unlink__20DynamicModuleControlFv = .text:0x802DFA60; // type:function size:0xA4 +getModuleSize__20DynamicModuleControlCFv = .text:0x802DFB10; // type:function size:0x5C +getModuleTypeString__20DynamicModuleControlCFv = .text:0x802DFB70; // type:function size:0x18 +__dt__9DbMapFileFv = .text:0x802DFB90; // type:function size:0x60 +RegisterOnDvd__9DbMapFileFPCcPC12OSModuleInfo = .text:0x802DFBF0; // type:function size:0x70 +Unregister__9DbMapFileFv = .text:0x802DFC60; // type:function size:0x50 +ModuleProlog = .text:0x802DFCB0; // type:function size:0x4 +ModuleEpilog = .text:0x802DFCC0; // type:function size:0x4 +ModuleUnresolved = .text:0x802DFCD0; // type:function size:0x4 +ModuleConstructorsX = .text:0x802DFCE0; // type:function size:0x44 +ModuleDestructorsX = .text:0x802DFD30; // type:function size:0x44 fn_802DFD80 = .text:0x802DFD80; // type:function size:0x4 fn_802DFD90 = .text:0x802DFD90; // type:function size:0x234 fn_802DFFD0 = .text:0x802DFFD0; // type:function size:0x1B8 @@ -17755,11 +17755,11 @@ mainLoop__12mDvd_param_cFv = .text:0x802EF410; // type:function size:0x4C __ct__14mDvd_command_cFv = .text:0x802EF460; // type:function size:0x1C fn_802EF480 = .text:0x802EF480; // type:function size:0x20 destroy__14mDvd_command_cFPP14mDvd_command_c = .text:0x802EF4A0; // type:function size:0x54 -__dt__25mDvdCommandReadCallback_cFv = .text:0x802EF500; // type:function size:0x58 -__ct__25mDvdCommandReadCallback_cFPFPv_PvPv = .text:0x802EF560; // type:function size:0x64 -create__25mDvdCommandReadCallback_cFPFPv_PvPv = .text:0x802EF5D0; // type:function size:0x78 +__dt__15mDvd_callback_cFv = .text:0x802EF500; // type:function size:0x58 +__ct__15mDvd_callback_cFPFPv_bPv = .text:0x802EF560; // type:function size:0x64 +create__15mDvd_callback_cFPFPv_bPv = .text:0x802EF5D0; // type:function size:0x78 fn_802EF650 = .text:0x802EF650; // type:function size:0x30 -execute__25mDvdCommandReadCallback_cFv = .text:0x802EF680; // type:function size:0x54 +execute__15mDvd_callback_cFv = .text:0x802EF680; // type:function size:0x54 __dt__22mDvd_mountMemArchive_cFv = .text:0x802EF6E0; // type:function size:0x58 __ct__22mDvd_mountMemArchive_cFi = .text:0x802EF740; // type:function size:0x74 findPathWithCompressedExtension__FPCcPUc = .text:0x802EF7C0; // type:function size:0x16C @@ -21970,10 +21970,10 @@ fn_803A9500 = .text:0x803A9500; // type:function size:0x4 fn_803A9510 = .text:0x803A9510; // type:function size:0xC fn_803A9520 = .text:0x803A9520; // type:function size:0x2C4 fn_803A97F0 = .text:0x803A97F0; // type:function size:0x2E8 -fn_803A9AE0 = .text:0x803A9AE0; // type:function size:0x8 -fn_803A9AF0 = .text:0x803A9AF0; // type:function size:0x1C +OSLink = .text:0x803A9AE0; // type:function size:0x8 +OSLinkFixed = .text:0x803A9AF0; // type:function size:0x1C fn_803A9B10 = .text:0x803A9B10; // type:function size:0x240 -fn_803A9D50 = .text:0x803A9D50; // type:function size:0x1D4 +OSUnlink = .text:0x803A9D50; // type:function size:0x1D4 __OSModuleInit = .text:0x803A9F30; // type:function size:0x18 scope:global fn_803A9F50 = .text:0x803A9F50; // type:function size:0xA4 OSInitMessageQueue = .text:0x803AA000; // type:function size:0x60 @@ -30061,7 +30061,7 @@ lbl_80503314 = .data:0x80503314; // type:object size:0x6C __vt__7dBase_c = .data:0x80503380; // type:object size:0x4C lbl_805033D0 = .data:0x805033D0; // type:object size:0x10 lbl_805033E0 = .data:0x805033E0; // type:object size:0x10 -lbl_805033F0 = .data:0x805033F0; // type:object size:0x10 +__vt__Q24dDvd8loader_c = .data:0x805033F0; // type:object size:0x10 lbl_80503400 = .data:0x80503400; // type:object size:0x40 lbl_80503440 = .data:0x80503440; // type:object size:0x6DF8 lbl_8050A238 = .data:0x8050A238; // type:object size:0x14 @@ -30695,7 +30695,7 @@ lbl_8050D290 = .data:0x8050D290; // type:object size:0x14 lbl_8050D2A4 = .data:0x8050D2A4; // type:object size:0x14 lbl_8050D2B8 = .data:0x8050D2B8; // type:object size:0x14 lbl_8050D2CC = .data:0x8050D2CC; // type:object size:0xC -lbl_8050D2D8 = .data:0x8050D2D8; // type:object size:0x34 +lbl_8050D2D8 = .data:0x8050D2D8; // type:object size:0x32 data:string lbl_8050D30C = .data:0x8050D30C; // type:object size:0x14 lbl_8050D320 = .data:0x8050D320; // type:object size:0x10 lbl_8050D330 = .data:0x8050D330; // type:object size:0xC @@ -35665,8 +35665,8 @@ 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 -lbl_80541A10 = .data:0x80541A10; // type:object size:0x30 -lbl_80541A40 = .data:0x80541A40; // type:object size:0x30 +__vt__20DynamicModuleControl = .data:0x80541A10; // type:object size:0x30 +__vt__24DynamicModuleControlBase = .data:0x80541A40; // type:object size:0x30 lbl_80541A70 = .data:0x80541A70; // type:object size:0x808 lbl_80542278 = .data:0x80542278; // type:object size:0xB4 data:4byte lbl_8054232C = .data:0x8054232C; // type:object size:0x30 @@ -35722,7 +35722,7 @@ __vt__23mDvd_toMainRam_normal_c = .data:0x80542888; // type:object size:0x14 __vt__20mDvd_toMainRam_arc_c = .data:0x8054289C; // type:object size:0x14 __vt__21mDvd_toMainRam_base_c = .data:0x805428B0; // type:object size:0x14 __vt__22mDvd_mountMemArchive_c = .data:0x805428C4; // type:object size:0x14 -__vt__25mDvdCommandReadCallback_c = .data:0x805428D8; // type:object size:0x14 +__vt__15mDvd_callback_c = .data:0x805428D8; // type:object size:0x14 __vt__14mDvd_command_c = .data:0x805428EC; // type:object size:0x14 __vt__Q24mDvd41TUncompressInfo_c = .data:0x80542900; // type:object size:0x14 __vt__Q24mDvd42TUncompressInfo_c = .data:0x80542914; // type:object size:0x14 @@ -37570,8 +37570,8 @@ lbl_80571BF8 = .sdata:0x80571BF8; // type:object size:0x8 lbl_80571C00 = .sdata:0x80571C00; // type:object size:0x4 data:4byte lbl_80571C04 = .sdata:0x80571C04; // type:object size:0x4 data:4byte lbl_80571C08 = .sdata:0x80571C08; // type:object size:0x8 data:4byte -lbl_80571C10 = .sdata:0x80571C10; // type:object size:0x8 -lbl_80571C18 = .sdata:0x80571C18; // type:object size:0x8 +lbl_80571C10 = .sdata:0x80571C10; // type:object size:0x5 data:string +lbl_80571C18 = .sdata:0x80571C18; // type:object size:0x3 data:string lbl_80571C20 = .sdata:0x80571C20; // type:object size:0x8 data:string lbl_80571C28 = .sdata:0x80571C28; // type:object size:0x8 lbl_80571C30 = .sdata:0x80571C30; // type:object size:0x8 data:string @@ -39012,14 +39012,14 @@ lbl_80573F58 = .sdata:0x80573F58; // type:object size:0x8 lbl_80573F60 = .sdata:0x80573F60; // type:object size:0x8 lbl_80573F68 = .sdata:0x80573F68; // type:object size:0x8 data:4byte lbl_80573F70 = .sdata:0x80573F70; // type:object size:0x8 data:4byte -lbl_80573F78 = .sdata:0x80573F78; // type:object size:0x8 -lbl_80573F80 = .sdata:0x80573F80; // type:object size:0x8 -lbl_80573F88 = .sdata:0x80573F88; // type:object size:0x4 data:4byte -lbl_80573F8C = .sdata:0x80573F8C; // type:object size:0x8 -lbl_80573F94 = .sdata:0x80573F94; // type:object size:0x8 +lbl_80573F78 = .sdata:0x80573F78; // type:object size:0x5 data:string +lbl_80573F80 = .sdata:0x80573F80; // type:object size:0x6 data:string +sRelsDir__20DynamicModuleControl = .sdata:0x80573F88; // type:object size:0x4 data:4byte +lbl_80573F8C = .sdata:0x80573F8C; // type:object size:0x6 data:string +lbl_80573F94 = .sdata:0x80573F94; // type:object size:0x5 data:string lbl_80573F9C = .sdata:0x80573F9C; // type:object size:0x4 data:string -lbl_80573FA0 = .sdata:0x80573FA0; // type:object size:0x8 -lbl_80573FA8 = .sdata:0x80573FA8; // type:object size:0x8 +lbl_80573FA0 = .sdata:0x80573FA0; // type:object size:0x5 data:string +lbl_80573FA8 = .sdata:0x80573FA8; // type:object size:0x4 data:string lbl_80573FB0 = .sdata:0x80573FB0; // type:object size:0x4 data:4byte lbl_80573FB4 = .sdata:0x80573FB4; // type:object size:0x4 data:4byte m_rootUniqueID__7fBase_c = .sdata:0x80573FB8; // type:object size:0x4 data:4byte @@ -39689,13 +39689,13 @@ s_DrawControlFlags__7dBase_c = .sbss:0x805750C4; // type:object size:0x4 data:4b s_NextExecuteControlFlags__7dBase_c = .sbss:0x805750C8; // type:object size:0x4 data:4byte lbl_805750D0 = .sbss:0x805750D0; // type:object size:0x8 data:4byte lbl_805750D8 = .sbss:0x805750D8; // type:object size:0x8 data:4byte -lbl_805750E0 = .sbss:0x805750E0; // type:object size:0x4 data:4byte -lbl_805750E4 = .sbss:0x805750E4; // type:object size:0x4 data:4byte -lbl_805750E8 = .sbss:0x805750E8; // type:object size:0x4 data:4byte -lbl_805750EC = .sbss:0x805750EC; // type:object size:0x4 data:4byte -lbl_805750F0 = .sbss:0x805750F0; // type:object size:0x4 data:4byte -lbl_805750F4 = .sbss:0x805750F4; // type:object size:0x4 data:4byte -lbl_805750F8 = .sbss:0x805750F8; // type:object size:0x8 data:4byte +pDynamicNameTable = .sbss:0x805750E0; // type:object size:0x4 data:4byte +nDynamicNameTable = .sbss:0x805750E4; // type:object size:0x4 data:4byte +pDMC__4dDyl = .sbss:0x805750E8; // type:object size:0x4 data:4byte +nDMC__4dDyl = .sbss:0x805750EC; // type:object size:0x4 data:4byte +cCc_frmHeap__4dDyl = .sbss:0x805750F0; // type:object size:0x4 data:4byte +Initialized__4dDyl = .sbss:0x805750F4; // type:object size:0x1 data:byte +DVD__4dDyl = .sbss:0x805750F8; // type:object size:0x4 data:4byte lbl_80575100 = .sbss:0x80575100; // type:object size:0x8 data:byte lbl_80575108 = .sbss:0x80575108; // type:object size:0x8 data:byte lbl_80575110 = .sbss:0x80575110; // type:object size:0x8 data:4byte @@ -40231,14 +40231,14 @@ lbl_80575B68 = .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 -lbl_80575B80 = .sbss:0x80575B80; // type:object size:0x4 data:4byte -lbl_80575B84 = .sbss:0x80575B84; // type:object size:0x4 data:4byte -lbl_80575B88 = .sbss:0x80575B88; // type:object size:0x4 data:4byte -lbl_80575B8C = .sbss:0x80575B8C; // type:object size:0x4 data:4byte -lbl_80575B90 = .sbss:0x80575B90; // type:object size:0x4 data:4byte -lbl_80575B94 = .sbss:0x80575B94; // type:object size:0x4 data:4byte -lbl_80575B98 = .sbss:0x80575B98; // type:object size:0x4 data:4byte -lbl_80575B9C = .sbss:0x80575B9C; // type:object size:0x4 data:4byte +mFirst__24DynamicModuleControlBase = .sbss:0x80575B80; // type:object size:0x4 data:4byte +mLast__24DynamicModuleControlBase = .sbss:0x80575B84; // type:object size:0x4 data:4byte +sAllocBytes__20DynamicModuleControl = .sbss:0x80575B88; // type:object size:0x4 data:4byte +sDvdFile__20DynamicModuleControl = .sbss:0x80575B8C; // type:object size:0x4 data:4byte +sDylinkHeap__20DynamicModuleControl = .sbss:0x80575B90; // type:object size:0x4 data:4byte +sCurrentAllocatableSize__20DynamicModuleControl = .sbss:0x80575B94; // type:object size:0x4 data:4byte +sTotalFreeSize__20DynamicModuleControl = .sbss:0x80575B98; // type:object size:0x4 data:4byte +sArchive__20DynamicModuleControl = .sbss:0x80575B9C; // type:object size:0x4 data:4byte lbl_80575BA0 = .sbss:0x80575BA0; // type:object size:0x8 data:4byte m_forceExecuteList__7fBase_c = .sbss:0x80575BA8; // type:object size:0x8 data:4byte sLoadAsyncCallback__7fBase_c = .sbss:0x80575BB0; // type:object size:0x4 data:4byte diff --git a/configure.py b/configure.py index 30824191..d5e19ed9 100644 --- a/configure.py +++ b/configure.py @@ -281,6 +281,9 @@ config.libs = [ Object(Matching, "c/c_list.cpp"), Object(Matching, "c/c_tree.cpp"), Object(Matching, "d/d_base.cpp"), + Object(Matching, "d/d_dvd.cpp"), + Object(NonMatching, "d/d_dvd_unk.cpp"), + Object(NonMatching, "d/d_dylink.cpp"), Object(NonMatching, "d/d_heap.cpp"), Object(NonMatching, "d/d_stage.cpp"), Object(NonMatching, "d/d_sys.cpp"), @@ -304,6 +307,7 @@ config.libs = [ Object(NonMatching, "m/m_dvd.cpp"), Object(Matching, "m/m_heap.cpp"), Object(NonMatching, "m/m_mtx.cpp"), + Object(Matching, "DynamicLink.cpp"), # framework (f_name) # d stuff (d_name) ], diff --git a/include/DynamicLink.h b/include/DynamicLink.h new file mode 100644 index 00000000..109f4821 --- /dev/null +++ b/include/DynamicLink.h @@ -0,0 +1,96 @@ +#ifndef DYNAMICLINK_H +#define DYNAMICLINK_H + +#include +#include +#include + +class DbMapFile { +public: + DbMapFile(): unk_0(0) {} + ~DbMapFile(); + + void RegisterOnDvd(const char *, const OSModuleInfo *); + void Unregister(); +private: + UNKWORD unk_0; +}; + +// https://github.com/zeldaret/tp/blob/main/include/DynamicLink.h + +struct DynamicModuleControlBase { + /* 0x00 */ u16 mLinkCount; + /* 0x02 */ u16 mDoLinkCount; + /* 0x04 */ DynamicModuleControlBase* mPrev; + /* 0x08 */ DynamicModuleControlBase* mNext; + + /* 0x0C */ /*vtable*/ + /* 802df100 */ virtual ~DynamicModuleControlBase(); + /* 802df340 */ virtual const char* getModuleName() const; + /* 802df350 */ virtual int getModuleSize() const; + /* 802df360 */ virtual const char* getModuleTypeString() const; + /* 802df370 */ virtual void dump(); + /* 802df380 */ virtual bool do_load(); + /* 802df390 */ virtual BOOL do_load_async(); + /* 802df3a0 */ virtual bool do_unload(); + /* 802df3b0 */ virtual BOOL do_link(); + /* 802df3c0 */ virtual bool do_unlink(); + /* 802df1a0 */ DynamicModuleControlBase(); + /* 802df1f0 */ BOOL link(); + /* 802df290 */ BOOL unlink(); + /* 802df310 */ BOOL load_async(); + + static inline DynamicModuleControlBase* getFirstClass() { return mFirst; } + inline DynamicModuleControlBase* getNextClass() { return mNext; } + bool isLinked() const { return mLinkCount != 0; } + + static DynamicModuleControlBase* mFirst; + static DynamicModuleControlBase* mLast; +}; + +struct DynamicModuleControl : DynamicModuleControlBase { + /* 802df4c0 */ virtual const char* getModuleName() const; + /* 802df450 */ virtual ~DynamicModuleControl(); + /* 802dfb10 */ virtual int getModuleSize() const; + /* 802dfb70 */ virtual const char* getModuleTypeString() const; + /* 802df800 */ virtual void dump(); + /* 802df5d0 */ virtual bool do_load(); + /* 802df710 */ virtual BOOL do_load_async(); + /* 802df7a0 */ virtual bool do_unload(); + /* 802df810 */ virtual BOOL do_link(); + /* 802dfa60 */ virtual bool do_unlink(); + /* 802df3d0 */ DynamicModuleControl(char const*, EGG::ExpHeap *); + /* 802df4d0 */ static void initialize(EGG::ExpHeap *heap); + /* 802df530 */ static bool callback(void*); + void checkHeapStatus(); + + /* 0x10 */ UNKWORD unk_16; + /* 0x14 */ OSModuleHeader *mModule; + /* 0x18 */ void *mBss; + /* 0x1C */ UNKWORD unk_24; + /* 0x20 */ const char *mName; + /* 0x24 */ u8 mResourceType; + /* 0x25 */ u8 unk_33; + /* 0x28 */ UNKWORD unk_40; + /* 0x2C */ mDvd_callback_c *mDvdCallbackRequest; + /* 0x30 */ EGG::ExpHeap *mHeap; + /* 0x34 */ DbMapFile mpRelMapFile; + // Some of these might be members of DbMapFile + UNKWORD unk1; + UNKWORD unk2; + UNKWORD unk3; + UNKWORD unk4; + UNKWORD unk5; + UNKWORD unk6; + + static u32 sAllocBytes; + static mDvd_toMainRam_base_c *sDvdFile; + static EGG::ExpHeap *sDylinkHeap; + static u32 sCurrentAllocatableSize; + static u32 sTotalFreeSize; + static EGG::Archive *sArchive; + + static const char *sRelsDir; +}; + +#endif diff --git a/include/d/d_dvd.h b/include/d/d_dvd.h new file mode 100644 index 00000000..56fb848c --- /dev/null +++ b/include/d/d_dvd.h @@ -0,0 +1,41 @@ +#ifndef D_DVD_H +#define D_DVD_H + +#include +#include +#include + +namespace dDvd { + +// difference to NSMBW: additional heap arg +void create(s32 priority, EGG::Heap*, EGG::Heap*, EGG::Heap*); + +class loader_c { +public: + loader_c(); + /** vtable at 0x805033F0 */ + virtual ~loader_c(); + void *request(const char *path, u8 mountDirection, EGG::Heap *heap); + virtual void remove(); + +private: + u32 mSize; + mDvd_toMainRam_normal_c *mpCommand; + EGG::Heap* mpHeap; + void* mpBuffer; +}; + +class unkstruct_c { +public: + static unkstruct_c *create(EGG::Heap *heap); + void init(); + char getUnk(); + +private: + UNKWORD field_0x0; + char field_0x4; +}; + +} // dDvd + +#endif diff --git a/include/d/d_dvd_unk.h b/include/d/d_dvd_unk.h new file mode 100644 index 00000000..080a6eb6 --- /dev/null +++ b/include/d/d_dvd_unk.h @@ -0,0 +1,26 @@ +#ifndef D_DVD_UNK_H +#define D_DVD_UNK_H + +#include +#include + +namespace dDvdUnk { + +class unkstruct_c { +public: + static unkstruct_c *create(EGG::Heap *heap); + void draw(); + void execute(); + void init(); + char getUnk(); + + static void createFont(EGG::Heap *heap); + +private: + UNKWORD field_0x0; + char field_0x4; +}; + +} // dDvdUnk + +#endif diff --git a/include/d/d_dylink.h b/include/d/d_dylink.h new file mode 100644 index 00000000..c7a0a6a2 --- /dev/null +++ b/include/d/d_dylink.h @@ -0,0 +1,12 @@ +#ifndef D_DYLINK_H +#define D_DYLINK_H + +#include + +namespace dDyl { + +bool Unlink(u16 relId); + +} // dDyl + +#endif diff --git a/include/m/m_dvd.h b/include/m/m_dvd.h index dee59241..86be5449 100644 --- a/include/m/m_dvd.h +++ b/include/m/m_dvd.h @@ -1,6 +1,8 @@ #ifndef M_DVD_H #define M_DVD_H +#include +#include #include #include #include @@ -64,19 +66,19 @@ public: u8 mCompressionType; }; -typedef void *(*dvdReadCallback)(void *); +typedef bool (*dvdReadCallback)(void *); -class mDvdCommandReadCallback_c : public mDvd_command_c { +class mDvd_callback_c : public mDvd_command_c { public: - mDvdCommandReadCallback_c(dvdReadCallback cb, void *cbData); - virtual ~mDvdCommandReadCallback_c(); + mDvd_callback_c(dvdReadCallback cb, void *cbData); + virtual ~mDvd_callback_c(); virtual u32 execute() override; - static mDvdCommandReadCallback_c *create(dvdReadCallback cb, void *cbData); + static mDvd_callback_c *create(dvdReadCallback cb, void *cbData); dvdReadCallback mCallback; void *mCallbackData; - void *mDataPtr; + BOOL mSuccess; }; class mDvd_mountMemArchive_c : public mDvd_command_c { @@ -176,4 +178,8 @@ public: }; } // namespace mDvd +extern "C" void fn_802EF480(mDvd_command_c *cmd); +extern "C" mDvd_toMainRam_normal_c *fn_802F0030(const char *path, int mountDirection, EGG::Heap *heap); +extern "C" mDvd_toMainRam_arc_c *fn_802EFE90(EGG::Archive *arc, const char *path, int mountDirection, EGG::Heap *heap); + #endif diff --git a/include/rvl/OS/OSLink.h b/include/rvl/OS/OSLink.h index 0736a590..aa2a86cf 100644 --- a/include/rvl/OS/OSLink.h +++ b/include/rvl/OS/OSLink.h @@ -1,13 +1,112 @@ -#ifndef RVL_SDK_OS_LINK_H -#define RVL_SDK_OS_LINK_H -#include +#ifndef OSLINK_H +#define OSLINK_H + + #ifdef __cplusplus extern "C" { #endif +#define OS_MODULE_VERSION 3 + +typedef struct OSModuleHeader OSModuleHeader; + +typedef u32 OSModuleID; +typedef struct OSModuleQueue OSModuleQueue; +typedef struct OSModuleLink OSModuleLink; +typedef struct OSModuleInfo OSModuleInfo; +typedef struct OSSectionInfo OSSectionInfo; +typedef struct OSImportInfo OSImportInfo; +typedef struct OSRel OSRel; + +// OSModuleQueue __OSModuleList : 0x800030C8; +// void* __OSStringTable : 0x800030D0; +extern OSModuleQueue __OSModuleList; +extern void * __OSStringTable; + +struct OSModuleQueue { + OSModuleInfo* head; + OSModuleInfo* tail; +}; + +struct OSModuleLink { + OSModuleInfo* next; + OSModuleInfo* prev; +}; + +struct OSSectionInfo { + u32 offset; + u32 size; +}; + +struct OSModuleInfo { + OSModuleID id; // unique identifier for the module + OSModuleLink link; // doubly linked list of modules + u32 numSections; // # of sections + u32 sectionInfoOffset; // offset to section info table + u32 nameOffset; // offset to module name + u32 nameSize; // size of module name + u32 version; // version number +}; + +struct OSModuleHeader { + // CAUTION: info must be the 1st member + OSModuleInfo info; + + // OS_MODULE_VERSION == 1 + u32 bssSize; // total size of bss sections in bytes + u32 relOffset; + u32 impOffset; + u32 impSize; // size in bytes + u8 prologSection; // section # for prolog function + u8 epilogSection; // section # for epilog function + u8 unresolvedSection; // section # for unresolved function + u8 bssSection; // section # for bss section (set at run-time) + u32 prolog; // prolog function offset + u32 epilog; // epilog function offset + u32 unresolved; // unresolved function offset + + // OS_MODULE_VERSION == 2 +#if (2 <= OS_MODULE_VERSION) + u32 align; // module alignment constraint + u32 bssAlign; // bss alignment constraint +#endif + + // OS_MODULE_VERSION == 3 +#if (3 <= OS_MODULE_VERSION) + u32 fixSize; +#endif +}; + +#define OSGetSectionInfo(module) ((OSSectionInfo*)(((OSModuleInfo*)(module))->sectionInfoOffset)) + +#define OS_SECTIONINFO_EXEC 0x1 +#define OS_SECTIONINFO_OFFSET(offset) ((offset) & ~0x1) + +struct OSImportInfo { + OSModuleID id; // external module id + u32 offset; // offset to OSRel instructions +}; + +struct OSRel { + u16 offset; // byte offset from the previous entry + u8 type; + u8 section; + u32 addend; +}; + +#define R_DOLPHIN_NOP 201 // C9h current offset += OSRel.offset +#define R_DOLPHIN_SECTION 202 // CAh current section = OSRel.section +#define R_DOLPHIN_END 203 // CBh +#define R_DOLPHIN_MRKREF 204 // CCh + +BOOL OSLink(OSModuleInfo* newModule, void* bss); +BOOL OSLinkFixed(OSModuleInfo* newModule, void* bss); +BOOL OSUnlink(OSModuleInfo* module); +void OSSetStringTable(void* string_table); void __OSModuleInit(void); #ifdef __cplusplus -} -#endif +}; #endif + +#endif /* OSLINK_H */ diff --git a/src/DynamicLink.cpp b/src/DynamicLink.cpp new file mode 100644 index 00000000..2898ab14 --- /dev/null +++ b/src/DynamicLink.cpp @@ -0,0 +1,373 @@ +#include + +DynamicModuleControlBase *DynamicModuleControlBase::mFirst; +DynamicModuleControlBase *DynamicModuleControlBase::mLast; + +DynamicModuleControlBase::~DynamicModuleControlBase() { + if (mPrev != nullptr) { + mPrev->mNext = mNext; + } + if (mNext != nullptr) { + mNext->mPrev = mPrev; + } + if (mFirst == this) { + mFirst = mNext; + } + if (mLast == this) { + mLast = mPrev; + } + mNext = nullptr; + mPrev = nullptr; +} + +DynamicModuleControlBase::DynamicModuleControlBase() { + mLinkCount = 0; + mDoLinkCount = 0; + mNext = nullptr; + if (mFirst == nullptr) { + mFirst = this; + } + DynamicModuleControlBase *last = mLast; + mPrev = last; + if (last != nullptr) { + last->mNext = this; + } + mLast = this; +} + +BOOL DynamicModuleControlBase::link() { + if (mLinkCount == 0) { + do_load(); + if (!do_link()) { + return false; + } + + if (mDoLinkCount < 0xFFFF) { + mDoLinkCount++; + } + } + + if (mLinkCount < 0xFFFF) { + mLinkCount++; + } + + return true; +} + +BOOL DynamicModuleControlBase::unlink() { + if (mLinkCount != 0) { + if (mLinkCount < 0xFFFF && --mLinkCount == 0) { + do_unlink(); + do_unload(); + } + } + + return true; +} + +BOOL DynamicModuleControlBase::load_async() { + if (mLinkCount == 0) { + return do_load_async(); + } + return true; +} + +const char *DynamicModuleControlBase::getModuleName() const { + return nullptr; +} + +int DynamicModuleControlBase::getModuleSize() const { + return 0; +} + +const char *DynamicModuleControlBase::getModuleTypeString() const { + return "Base"; +} + +void DynamicModuleControlBase::dump() {} + +bool DynamicModuleControlBase::do_load() { + return true; +} + +BOOL DynamicModuleControlBase::do_load_async() { + return true; +} + +bool DynamicModuleControlBase::do_unload() { + return true; +} + +BOOL DynamicModuleControlBase::do_link() { + return true; +} + +bool DynamicModuleControlBase::do_unlink() { + return true; +} + +u32 DynamicModuleControl::sAllocBytes; +mDvd_toMainRam_base_c *DynamicModuleControl::sDvdFile; +EGG::ExpHeap *DynamicModuleControl::sDylinkHeap; +u32 DynamicModuleControl::sCurrentAllocatableSize; +u32 DynamicModuleControl::sTotalFreeSize; +EGG::Archive *DynamicModuleControl::sArchive; + +DynamicModuleControl::DynamicModuleControl(const char *name, EGG::ExpHeap *heap) + : mModule(nullptr), mBss(nullptr), unk_24(0), mName(name), mResourceType(0), unk_33(0), unk_40(0), + mDvdCallbackRequest(0), mHeap(heap), mpRelMapFile() {} + +DynamicModuleControl::~DynamicModuleControl() {} + +const char *DynamicModuleControl::getModuleName() const { + return mName; +} + +void DynamicModuleControl::initialize(EGG::ExpHeap *heap) { + sDylinkHeap = heap; + sCurrentAllocatableSize = heap->getAllocatableSize(4); + sTotalFreeSize = heap->getTotalFreeSize(); +} + +bool DynamicModuleControl::callback(void *arg) { + return static_cast(arg)->do_load(); +} + +void DynamicModuleControl::checkHeapStatus() { + if (mHeap == sDylinkHeap) { + int size = mHeap->getAllocatableSize(4); + if (sCurrentAllocatableSize > size) { + sCurrentAllocatableSize = size; + } + size = mHeap->getTotalFreeSize(); + if (sTotalFreeSize > size) { + sTotalFreeSize = size; + } + } +} + +const char *DynamicModuleControl::sRelsDir = "/rels"; + +bool DynamicModuleControl::do_load() { + char buf[64]; + if (mModule != nullptr) { + return true; + } + if (mHeap == nullptr) { + mHeap = sDylinkHeap; + } + snprintf(buf, sizeof(buf), "%s/%sNP.rel", sRelsDir, mName); + if (mModule == nullptr) { + if (sArchive != nullptr) { + sDvdFile = fn_802EFE90(sArchive, buf, 1, mHeap); + } else { + sDvdFile = fn_802F0030(buf, 1, mHeap); + } + + if (sDvdFile != nullptr) { + sDvdFile->waitUntilDone(); + checkHeapStatus(); + void *ptr = sDvdFile->mDataPtr; + sDvdFile->mDataPtr = nullptr; + mModule = static_cast(ptr); + fn_802EF480(sDvdFile); + sDvdFile = nullptr; + if (mModule != nullptr) { + unk_40 = 0; + mResourceType = 3; + } + } + } + + if (mModule == nullptr) { + return false; + } + if (unk_33 < 0xFF) { + unk_33++; + } + checkHeapStatus(); + return true; +} + +BOOL DynamicModuleControl::do_load_async() { + if (mDvdCallbackRequest == nullptr) { + if (mModule != nullptr) { + return true; + } + mDvdCallbackRequest = mDvd_callback_c::create(callback, this); + } + + if (mDvdCallbackRequest != nullptr && mDvdCallbackRequest->mStatus != 0) { + fn_802EF480(mDvdCallbackRequest); + mDvdCallbackRequest = nullptr; + return true; + } else { + return false; + } +} + +bool DynamicModuleControl::do_unload() { + if (mModule != nullptr) { + mHeap->free(mModule); + mModule = nullptr; + } + + return true; +} + +void DynamicModuleControl::dump() {} + +BOOL DynamicModuleControl::do_link() { + char mapPath[64]; + + if (mModule != nullptr) { + int alignedFixSize = ROUND_UP(mModule->fixSize, 0x20); + int alignedFixPtr = (int)&mModule->info + alignedFixSize; + int totalSize = EGG::ExpHeap::getSizeForMBlock(mModule); + BOOL result; + if (totalSize == 0) { + void *bss = mHeap->alloc(mModule->bssSize, 0x20); + if (bss == nullptr) { + goto error; + } + mBss = bss; + result = OSLink(&mModule->info, bss); + if (!result) { + goto error; + } + } else { + if (alignedFixSize + mModule->bssSize < totalSize) { + result = OSLinkFixed(&mModule->info, (void *)alignedFixPtr); + if (!result) { + goto error; + } + mHeap->resizeForMBlock(mModule, alignedFixSize + mModule->bssSize); + } else if ((int)mHeap->resizeForMBlock(mModule, alignedFixSize + mModule->bssSize) > 0) { + // TODO resizeForMBlock should maybe return int? + result = OSLinkFixed(&mModule->info, (void *)alignedFixPtr); + if (!result) { + goto error; + } + } else { + void *bss = mHeap->alloc(mModule->bssSize, 0x20); + if (!bss) { + goto error; + } + mBss = bss; + result = OSLinkFixed(&mModule->info, bss); + if (!result) { + goto error; + } + mHeap->resizeForMBlock(mModule, alignedFixSize); + } + } + + sAllocBytes = sAllocBytes + getModuleSize(); + snprintf(mapPath, sizeof(mapPath), "%s/%sNP.map", "/maps", mName); + mpRelMapFile.RegisterOnDvd(mapPath, &mModule->info); + unk_24 = ((UNKWORD(*)())mModule->prolog)(); + checkHeapStatus(); + return true; + } + +error: + unk_33 = 0; + if (mBss != nullptr) { + mHeap->free(mBss); + mBss = nullptr; + } + if (mModule != nullptr) { + mHeap->free(mModule); + mModule = nullptr; + } + return false; +} + +bool DynamicModuleControl::do_unlink() { + ((void (*)())mModule->epilog)(); + mpRelMapFile.Unregister(); + if (!OSUnlink(&mModule->info)) { + return false; + } + sAllocBytes -= getModuleSize(); + if (mBss != nullptr) { + mHeap->free(mBss); + mBss = nullptr; + } + return true; +} + +int DynamicModuleControl::getModuleSize() const { + if (mModule != nullptr) { + int size = EGG::ExpHeap::getSizeForMBlock(mModule); + if (mBss != nullptr) { + size += mModule->bssSize; + } + + return size; + } + return 0; +} + +const char *DynamicModuleControl::getModuleTypeString() const { + static const char *REL_LOAD_TYPES[4] = { + "????", + "MEM", + "ARAM", + "DVD", + }; + return REL_LOAD_TYPES[mResourceType & 3]; +} + +DbMapFile::~DbMapFile() { + if (unk_0) { + Unregister(); + } +} + +namespace nw4r { +namespace db { +// TODO +typedef struct MapFile { +} MapFile; +extern MapFile *MapFile_RegistOnDvd(void *arg, const char *buf, const OSModuleInfo *info); +extern void *MapFile_Unregist(MapFile *); +} // namespace db +} // namespace nw4r + +void DbMapFile::RegisterOnDvd(const char *path, const OSModuleInfo *info) { + if (mDvd::IsExistPath(path)) { + unk_0 = (UNKWORD)nw4r::db::MapFile_RegistOnDvd(((int *)this) + 1, path, info); + } else { + unk_0 = 0xffffffff; + } +} + +void DbMapFile::Unregister() { + if (unk_0 != 0) { + if (unk_0 != 0xffffffff) { + nw4r::db::MapFile_Unregist((nw4r::db::MapFile *)unk_0); + } + unk_0 = 0; + } +} +/* +// probably part of a different file +extern "C" void ModuleProlog() {} + +extern "C" void ModuleEpilog() {} + +extern "C" void ModuleUnresolved() {} + +extern "C" void ModuleConstructorsX(void (**ptrs)()) { + for (; *ptrs != nullptr; ptrs++) { + (*ptrs)(); + } +} + +extern "C" void ModuleDestructorsX(void (**ptrs)()) { + for (; *ptrs != nullptr; ptrs++) { + (*ptrs)(); + } +} +*/ diff --git a/src/d/d_dvd.cpp b/src/d/d_dvd.cpp new file mode 100644 index 00000000..afe8d10f --- /dev/null +++ b/src/d/d_dvd.cpp @@ -0,0 +1,62 @@ +#include +#include + +namespace dDvd { + +/** 800520f0 */ +void create(s32 priority, EGG::Heap *archiveHeap, EGG::Heap *commandHeap, EGG::Heap *threadHeap) { + mDvd::create(priority, archiveHeap, commandHeap, threadHeap); +} + +/** 80052100 */ +loader_c::loader_c() { + mpCommand = nullptr; + mSize = -1; + mpHeap = nullptr; + mpBuffer = nullptr; +} + +/** 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); + } + mpCommand = mDvd_toMainRam_normal_c::create(buf, mountDirection, heap); + } + if (mpCommand != nullptr && mpCommand->mStatus != 0) { + mpBuffer = mpCommand->mDataPtr; + mSize = mpCommand->mAmountRead; + mpCommand->mDataPtr = nullptr; + fn_802EF480(mpCommand); + mpCommand = nullptr; + return mpBuffer; + } else { + return nullptr; + } +} + +/** 800522a0 */ +void loader_c::remove() { + if (mpHeap != nullptr && mpBuffer != nullptr) { + mpHeap->free(mpBuffer); + mpBuffer = nullptr; + } +} + +} // namespace dDvd diff --git a/src/d/d_dvd_unk.cpp b/src/d/d_dvd_unk.cpp new file mode 100644 index 00000000..b4ab12d4 --- /dev/null +++ b/src/d/d_dvd_unk.cpp @@ -0,0 +1,44 @@ +#include +#include +#include + +namespace dDvdUnk { + +/** 805750d0 */ +static unkstruct_c *singleton; + +static nw4r::ut::ResFont *fontPtr; + +/** 80052300 */ +unkstruct_c *unkstruct_c::create(EGG::Heap *heap) { + singleton = new (heap, 0x04) unkstruct_c(); + singleton->init(); +} + +/** 80052340 */ +char unkstruct_c::getUnk() { + return field_0x4; +} + +/** 80052350 */ +void unkstruct_c::draw() { + // EGG:: +} + +/** 800526b0 */ +void unkstruct_c::execute() { + +} + +/** 80052750 */ +void unkstruct_c::init() { + field_0x0 = 0; + field_0x4 = 0; +} + + +void unkstruct_c::createFont(EGG::Heap *heap) { + fontPtr = new (heap, 0x04) nw4r::ut::ResFont(); +} + +} // namespace dDvdUnk diff --git a/src/d/d_dylink.cpp b/src/d/d_dylink.cpp new file mode 100644 index 00000000..a0e742d0 --- /dev/null +++ b/src/d/d_dylink.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +#include +// clang-format off +#include +// clang-format on + +struct RelNamePtr { + u16 relId; + const char *name; +}; + +struct DynamicModuleControl { + u16 loadCount; + + DynamicModuleControl *mpPrev; + DynamicModuleControl *mpNext; + + DynamicModuleControl(const char *name, EGG::Heap *heap); + virtual ~DynamicModuleControl(); + virtual const char *getModuleName(); + virtual UNKWORD getModuleSize(); + virtual const char *getModuleTypeString(); + virtual void dump(); + virtual bool do_load(); + virtual bool do_load_async(); + virtual bool do_unload(); + virtual bool do_link(); + virtual bool do_unlink(); + + bool link(); + bool unlink(); + bool load_async(); + + void *rel; + void *bss; + bool dataFromProlog; + const char *name; + bool includesType; + mDvd_callback_c *dvdCallbackRequest; + EGG::Heap *heap; + bool relMapFile; + UNKWORD unk1; + UNKWORD unk2; + UNKWORD unk3; + UNKWORD unk4; + UNKWORD unk5; + UNKWORD unk6; +}; + +static RelNamePtr *pDynamicNameTable; +static int nDynamicNameTable; + +namespace dDyl { + +DynamicModuleControl **pDMC; +int nDMC; +EGG::Heap *cCc_frmHeap; +u32 Initialized; +mDvd_callback_c *DVD; + +// initDylinkHeap +extern "C" int fn_80052E00(int maxRelId, RelNamePtr *dynNameTable, int dynNameTableNum, EGG::Heap *parentHeap) { + cCc_frmHeap = mHeap::createFrmHeap(maxRelId * 0x10 + dynNameTableNum * 0x48, parentHeap, + "ダイナミックリンク制御用ヒープ(dDyl::cCc_frmHeap)", 0x20, 0); + + mHeap _guard(cCc_frmHeap); + + nDMC = maxRelId; + pDMC = new DynamicModuleControl *[maxRelId](); + memset(pDMC, 0, sizeof(void *) * nDMC); + + pDynamicNameTable = dynNameTable; + nDynamicNameTable = dynNameTableNum; + + for (int i = 0; i < nDynamicNameTable; i++) { + RelNamePtr *rel = &pDynamicNameTable[i]; + if (rel->name != nullptr) { + for (int j = 0; j < nDMC; j++) { + DynamicModuleControl **dmc = &pDMC[j]; + if (*dmc != nullptr) { + const char *nm = (*dmc)->getModuleName(); + if (!strcmp(rel->name, nm)) { + pDMC[rel->relId] = pDMC[j]; + break; + } + } + } + if (pDMC[rel->relId] == nullptr) { + pDMC[rel->relId] = new DynamicModuleControl(rel->name, nullptr); + } + } + } + cCc_frmHeap->adjust(); + return 1; +} + +// isLoaded? +extern "C" bool fn_80052FA0(u16 relId) { + return pDMC[relId] != nullptr ? (bool)pDMC[relId]->loadCount : true; +} + +bool dDyl::Unlink(u16 relId) { + DynamicModuleControl *dmc = pDMC[relId]; + if (dmc != nullptr) { + return dmc->unlink(); + } + + return false; +} + +extern "C" int fn_80052FF0(u16 relId) { + if (!Initialized) { + return 0; + } + + DynamicModuleControl *dmc = pDMC[relId]; + if (dmc != nullptr) { + if (dmc->load_async()) { + return (bool)dmc->link() + 2; + } else { + return 0; + } + } else { + return 1; + } +} + +} // namespace dDyl diff --git a/src/m/m_dvd.cpp b/src/m/m_dvd.cpp index ef4819d2..a4c9ff04 100644 --- a/src/m/m_dvd.cpp +++ b/src/m/m_dvd.cpp @@ -324,19 +324,18 @@ void mDvd_command_c::destroy(mDvd_command_c **cmd) { } /** 802ef500 */ -mDvdCommandReadCallback_c::~mDvdCommandReadCallback_c() {} +mDvd_callback_c::~mDvd_callback_c() {} /** 802ef560 */ -mDvdCommandReadCallback_c::mDvdCommandReadCallback_c(dvdReadCallback cb, void *cbData) { +mDvd_callback_c::mDvd_callback_c(dvdReadCallback cb, void *cbData) { mCallback = cb; mCallbackData = cbData; - mDataPtr = nullptr; + mSuccess = false; } /* 802ef5d0 */ -mDvdCommandReadCallback_c *mDvdCommandReadCallback_c::create(dvdReadCallback cb, void *cbData) { - // TODO instshuffle - mDvdCommandReadCallback_c *cmd = new mDvdCommandReadCallback_c(cb, cbData); +mDvd_callback_c *mDvd_callback_c::create(dvdReadCallback cb, void *cbData) { + mDvd_callback_c *cmd = new mDvd_callback_c(cb, cbData); if (cmd != nullptr) { mDvd_param_c::mInstance->addCommand(cmd); } @@ -344,17 +343,17 @@ mDvdCommandReadCallback_c *mDvdCommandReadCallback_c::create(dvdReadCallback cb, } /** 802ef650 */ -extern "C" mDvdCommandReadCallback_c *fn_802EF650(dvdReadCallback cb, void *cbData) { - mDvdCommandReadCallback_c *cmd = mDvdCommandReadCallback_c::create(cb, cbData); +extern "C" mDvd_callback_c *fn_802EF650(dvdReadCallback cb, void *cbData) { + mDvd_callback_c *cmd = mDvd_callback_c::create(cb, cbData); while (!cmd) {} return cmd; } /** 802ef680 */ -u32 mDvdCommandReadCallback_c::execute() { - mDataPtr = (mCallback)(mCallbackData); +u32 mDvd_callback_c::execute() { + mSuccess = (mCallback)(mCallbackData); waitDone(); - return (bool)mDataPtr; + return (bool)mSuccess; } /** 802ef6e0 */ From 2a612801adeebec9940601a1a6912f43a7d7b64b Mon Sep 17 00:00:00 2001 From: robojumper Date: Mon, 20 May 2024 23:28:05 +0200 Subject: [PATCH 16/20] Fixup --- include/DynamicLink.h | 2 -- src/d/d_dylink.cpp | 42 +++--------------------------------------- 2 files changed, 3 insertions(+), 41 deletions(-) diff --git a/include/DynamicLink.h b/include/DynamicLink.h index 109f4821..1e9e3319 100644 --- a/include/DynamicLink.h +++ b/include/DynamicLink.h @@ -80,8 +80,6 @@ struct DynamicModuleControl : DynamicModuleControlBase { UNKWORD unk2; UNKWORD unk3; UNKWORD unk4; - UNKWORD unk5; - UNKWORD unk6; static u32 sAllocBytes; static mDvd_toMainRam_base_c *sDvdFile; diff --git a/src/d/d_dylink.cpp b/src/d/d_dylink.cpp index a0e742d0..3bec3f39 100644 --- a/src/d/d_dylink.cpp +++ b/src/d/d_dylink.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -11,44 +12,6 @@ struct RelNamePtr { const char *name; }; -struct DynamicModuleControl { - u16 loadCount; - - DynamicModuleControl *mpPrev; - DynamicModuleControl *mpNext; - - DynamicModuleControl(const char *name, EGG::Heap *heap); - virtual ~DynamicModuleControl(); - virtual const char *getModuleName(); - virtual UNKWORD getModuleSize(); - virtual const char *getModuleTypeString(); - virtual void dump(); - virtual bool do_load(); - virtual bool do_load_async(); - virtual bool do_unload(); - virtual bool do_link(); - virtual bool do_unlink(); - - bool link(); - bool unlink(); - bool load_async(); - - void *rel; - void *bss; - bool dataFromProlog; - const char *name; - bool includesType; - mDvd_callback_c *dvdCallbackRequest; - EGG::Heap *heap; - bool relMapFile; - UNKWORD unk1; - UNKWORD unk2; - UNKWORD unk3; - UNKWORD unk4; - UNKWORD unk5; - UNKWORD unk6; -}; - static RelNamePtr *pDynamicNameTable; static int nDynamicNameTable; @@ -98,7 +61,7 @@ extern "C" int fn_80052E00(int maxRelId, RelNamePtr *dynNameTable, int dynNameTa // isLoaded? extern "C" bool fn_80052FA0(u16 relId) { - return pDMC[relId] != nullptr ? (bool)pDMC[relId]->loadCount : true; + return pDMC[relId] != nullptr ? pDMC[relId]->isLinked() : true; } bool dDyl::Unlink(u16 relId) { @@ -118,6 +81,7 @@ extern "C" int fn_80052FF0(u16 relId) { DynamicModuleControl *dmc = pDMC[relId]; if (dmc != nullptr) { if (dmc->load_async()) { + // what is going on here? return (bool)dmc->link() + 2; } else { return 0; From 6449215af3568ef7d2c2b0b1743c9f91cd1bd513 Mon Sep 17 00:00:00 2001 From: robojumper Date: Mon, 20 May 2024 23:38:12 +0200 Subject: [PATCH 17/20] Guess this does actually work --- src/DynamicLink.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DynamicLink.cpp b/src/DynamicLink.cpp index 2898ab14..24bbbe5e 100644 --- a/src/DynamicLink.cpp +++ b/src/DynamicLink.cpp @@ -222,7 +222,7 @@ BOOL DynamicModuleControl::do_link() { if (mModule != nullptr) { int alignedFixSize = ROUND_UP(mModule->fixSize, 0x20); - int alignedFixPtr = (int)&mModule->info + alignedFixSize; + int alignedFixPtr = (int)mModule + alignedFixSize; int totalSize = EGG::ExpHeap::getSizeForMBlock(mModule); BOOL result; if (totalSize == 0) { From a349b8665bdf366e0cd7a7e343b3644387260795 Mon Sep 17 00:00:00 2001 From: robojumper Date: Wed, 22 May 2024 00:12:23 +0200 Subject: [PATCH 18/20] m_dvd match --- configure.py | 2 +- src/m/m_dvd.cpp | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/configure.py b/configure.py index d5e19ed9..38b302df 100644 --- a/configure.py +++ b/configure.py @@ -304,7 +304,7 @@ config.libs = [ Object(Matching, "f/f_list.cpp"), Object(Matching, "f/f_manager.cpp"), Object(Matching, "m/m_angle.cpp"), - Object(NonMatching, "m/m_dvd.cpp"), + Object(Matching, "m/m_dvd.cpp"), Object(Matching, "m/m_heap.cpp"), Object(NonMatching, "m/m_mtx.cpp"), Object(Matching, "DynamicLink.cpp"), diff --git a/src/m/m_dvd.cpp b/src/m/m_dvd.cpp index a4c9ff04..c503216b 100644 --- a/src/m/m_dvd.cpp +++ b/src/m/m_dvd.cpp @@ -374,11 +374,11 @@ mDvd_mountMemArchive_c::mDvd_mountMemArchive_c(int mountDirection) { /** 802ef7c0 */ int findPathWithCompressedExtension(const char *name, u8 *outType) { - // TODO regshuffle u8 type; - int num; char buf[256]; - mDvd::TUncompressInfo_Base_c **ptr; + int num; + char *end; + int size; type = 0; buf[255] = '\0'; @@ -386,10 +386,11 @@ int findPathWithCompressedExtension(const char *name, u8 *outType) { strncpy(buf, name, sizeof(buf)); if (buf[255] == '\0') { - char *end = buf + strlen(buf); + end = buf + strlen(buf); + size = sizeof(buf) - (end - buf); // Append the compressor extension and try to find a compressed version - for (ptr = mDvd::compressors_ptr; ptr != mDvd::compressors_last; ptr++) { - strncpy(end, (*ptr)->mExtension, sizeof(buf) - (end - buf)); + for (mDvd::TUncompressInfo_Base_c **ptr = mDvd::compressors_ptr; ptr != mDvd::compressors_last; ptr++) { + strncpy(end, (*ptr)->mExtension, size); num = DVDConvertPathToEntrynum(buf); if (num != -1) { type = (*ptr)->mType; @@ -404,9 +405,10 @@ int findPathWithCompressedExtension(const char *name, u8 *outType) { } end = strrchr(end, '.'); if (end != nullptr) { + size = sizeof(buf) - (end - buf); // Append the compressor extension and try to find a compressed version - for (ptr = mDvd::compressors_ptr; ptr != mDvd::compressors_last; ptr++) { - strncpy(end, (*ptr)->mExtension, sizeof(buf) - (end - buf)); + for (mDvd::TUncompressInfo_Base_c **ptr = mDvd::compressors_ptr; ptr != mDvd::compressors_last; ptr++) { + strncpy(end, (*ptr)->mExtension, size); num = DVDConvertPathToEntrynum(buf); if (num != -1) { type = (*ptr)->mType; From 02a492fe46cae57186685efda6383f2dc7470874 Mon Sep 17 00:00:00 2001 From: robojumper Date: Wed, 22 May 2024 00:39:12 +0200 Subject: [PATCH 19/20] Forceactive --- config/SOUE01/config.yml | 5 +++++ config/SOUE01/splits.txt | 2 +- src/DynamicLink.cpp | 25 +++++++++++++------------ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/config/SOUE01/config.yml b/config/SOUE01/config.yml index 3615db70..3acb2db1 100644 --- a/config/SOUE01/config.yml +++ b/config/SOUE01/config.yml @@ -12,6 +12,11 @@ force_active: [ "ProcessTab__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut15PrintContext", # "RemoveResourceBuffer__Q44nw4r2ut6detail11ResFontBaseFv", "RemoveResource__Q34nw4r2ut7ResFontFv", + "ModuleProlog", + "ModuleEpilog", + "ModuleUnresolved", + "ModuleConstructorsX", + "ModuleDestructorsX", ] # modules: # - object: orig/SOUE01/rels/d_a_asura_bulletNP.rel diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 5ca0c46b..fdd52647 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -192,7 +192,7 @@ toBeSorted/counters/extra_wallet_counter.cpp: .sbss start:0x80575640 end:0x80575648 DynamicLink.cpp: - .text start:0x802DF100 end:0x802DFCB0 + .text start:0x802DF100 end:0x802DFD74 .data start:0x805419E8 end:0x80541A70 .sdata start:0x80573F78 end:0x80573FB0 .sbss start:0x80575B80 end:0x80575BA0 diff --git a/src/DynamicLink.cpp b/src/DynamicLink.cpp index 24bbbe5e..f1d048a6 100644 --- a/src/DynamicLink.cpp +++ b/src/DynamicLink.cpp @@ -311,10 +311,10 @@ int DynamicModuleControl::getModuleSize() const { const char *DynamicModuleControl::getModuleTypeString() const { static const char *REL_LOAD_TYPES[4] = { - "????", - "MEM", - "ARAM", - "DVD", + "????", + "MEM", + "ARAM", + "DVD", }; return REL_LOAD_TYPES[mResourceType & 3]; } @@ -351,23 +351,24 @@ void DbMapFile::Unregister() { unk_0 = 0; } } -/* -// probably part of a different file -extern "C" void ModuleProlog() {} +extern "C" { -extern "C" void ModuleEpilog() {} +void ModuleProlog() {} -extern "C" void ModuleUnresolved() {} +void ModuleEpilog() {} -extern "C" void ModuleConstructorsX(void (**ptrs)()) { +void ModuleUnresolved() {} + +void ModuleConstructorsX(void (**ptrs)()) { for (; *ptrs != nullptr; ptrs++) { (*ptrs)(); } } -extern "C" void ModuleDestructorsX(void (**ptrs)()) { +void ModuleDestructorsX(void (**ptrs)()) { for (; *ptrs != nullptr; ptrs++) { (*ptrs)(); } } -*/ + +} From 77f8365ac5feb49236f8b5237eac91cdb1912b2c Mon Sep 17 00:00:00 2001 From: robojumper Date: Wed, 22 May 2024 19:46:13 +0200 Subject: [PATCH 20/20] Cleanups --- config/SOUE01/symbols.txt | 6 +++--- include/d/d_dvd.h | 11 ----------- include/m/m_dvd.h | 9 +++++---- include/rvl/OS/OSLink.h | 1 + src/DynamicLink.cpp | 10 +++++----- src/d/d_dvd.cpp | 2 +- src/m/m_dvd.cpp | 10 +++++----- 7 files changed, 20 insertions(+), 29 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 1ae97d22..5250ad05 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17753,7 +17753,7 @@ removeCommand__12mDvd_param_cFP14mDvd_command_c = .text:0x802EF310; // type:func executeCB__12mDvd_param_cFPP14mDvd_command_c = .text:0x802EF3D0; // type:function size:0x34 mainLoop__12mDvd_param_cFv = .text:0x802EF410; // type:function size:0x4C __ct__14mDvd_command_cFv = .text:0x802EF460; // type:function size:0x1C -fn_802EF480 = .text:0x802EF480; // type:function size:0x20 +do_delete__14mDvd_command_cFv = .text:0x802EF480; // type:function size:0x20 destroy__14mDvd_command_cFPP14mDvd_command_c = .text:0x802EF4A0; // type:function size:0x54 __dt__15mDvd_callback_cFv = .text:0x802EF500; // type:function size:0x58 __ct__15mDvd_callback_cFPFPv_bPv = .text:0x802EF560; // type:function size:0x64 @@ -17777,11 +17777,11 @@ __dt__20mDvd_toMainRam_arc_cFv = .text:0x802EFCE0; // type:function size:0x58 __ct__20mDvd_toMainRam_arc_cFPQ23EGG7Archiveii = .text:0x802EFD40; // type:function size:0x60 makeRequest__20mDvd_toMainRam_arc_cFPQ23EGG7ArchiveiiPQ23EGG4Heap = .text:0x802EFDA0; // type:function size:0x80 create__20mDvd_toMainRam_arc_cFPQ23EGG7ArchivePCciPQ23EGG4Heap = .text:0x802EFE20; // type:function size:0x64 -fn_802EFE90 = .text:0x802EFE90; // type:function size:0x30 +createOrFail__20mDvd_toMainRam_arc_cFPQ23EGG7ArchivePCciPQ23EGG4Heap = .text:0x802EFE90; // type:function size:0x30 execute__20mDvd_toMainRam_arc_cFv = .text:0x802EFEC0; // type:function size:0x78 __ct__23mDvd_toMainRam_normal_cFi = .text:0x802EFF40; // type:function size:0x4C create__23mDvd_toMainRam_normal_cFPCciPQ23EGG4Heap = .text:0x802EFF90; // type:function size:0x9C -fn_802F0030 = .text:0x802F0030; // type:function size:0x30 +createOrFail__23mDvd_toMainRam_normal_cFPCciPQ23EGG4Heap = .text:0x802F0030; // type:function size:0x30 create2__23mDvd_toMainRam_normal_cFPP23mDvd_toMainRam_normal_cPCciPQ23EGG4Heap = .text:0x802F0060; // type:function size:0x48 __dt__23mDvd_toMainRam_normal_cFv = .text:0x802F00B0; // type:function size:0x58 execute__23mDvd_toMainRam_normal_cFv = .text:0x802F0110; // type:function size:0xA0 diff --git a/include/d/d_dvd.h b/include/d/d_dvd.h index 56fb848c..a7addacb 100644 --- a/include/d/d_dvd.h +++ b/include/d/d_dvd.h @@ -25,17 +25,6 @@ private: void* mpBuffer; }; -class unkstruct_c { -public: - static unkstruct_c *create(EGG::Heap *heap); - void init(); - char getUnk(); - -private: - UNKWORD field_0x0; - char field_0x4; -}; - } // dDvd #endif diff --git a/include/m/m_dvd.h b/include/m/m_dvd.h index 86be5449..11890653 100644 --- a/include/m/m_dvd.h +++ b/include/m/m_dvd.h @@ -7,6 +7,8 @@ #include #include +// Note: names are taken from NSMBW where available but a lot are made up + void unk_initDecompressors(); namespace mDvd { @@ -56,6 +58,7 @@ public: void waitDone(); void waitUntilDone(); static void destroy(mDvd_command_c **cmd); + void do_delete(); void *operator new(size_t size); void operator delete(void *ptr); @@ -117,6 +120,7 @@ public: static mDvd_toMainRam_arc_c *makeRequest(EGG::Archive *arc, int entryNum, int mountDirection, EGG::Heap *heap); static mDvd_toMainRam_arc_c *create(EGG::Archive *arc, const char *path, int mountDirection, EGG::Heap *heap); + static mDvd_toMainRam_arc_c *createOrFail(EGG::Archive *arc, const char *path, int mountDirection, EGG::Heap *heap); EGG::Archive *mArcPtr; int mEntryNum; @@ -130,6 +134,7 @@ public: virtual void doClear(); static mDvd_toMainRam_normal_c *create(const char *path, int mountDirection, EGG::Heap *heap); + static mDvd_toMainRam_normal_c *createOrFail(const char *path, int mountDirection, EGG::Heap *heap); static void create2(mDvd_toMainRam_normal_c **cmd, const char *path, int mountDirection, EGG::Heap *heap); u8 mCompressionType2; @@ -178,8 +183,4 @@ public: }; } // namespace mDvd -extern "C" void fn_802EF480(mDvd_command_c *cmd); -extern "C" mDvd_toMainRam_normal_c *fn_802F0030(const char *path, int mountDirection, EGG::Heap *heap); -extern "C" mDvd_toMainRam_arc_c *fn_802EFE90(EGG::Archive *arc, const char *path, int mountDirection, EGG::Heap *heap); - #endif diff --git a/include/rvl/OS/OSLink.h b/include/rvl/OS/OSLink.h index aa2a86cf..8f6df8b0 100644 --- a/include/rvl/OS/OSLink.h +++ b/include/rvl/OS/OSLink.h @@ -1,6 +1,7 @@ #ifndef OSLINK_H #define OSLINK_H +#include #ifdef __cplusplus extern "C" { diff --git a/src/DynamicLink.cpp b/src/DynamicLink.cpp index f1d048a6..2c7947c0 100644 --- a/src/DynamicLink.cpp +++ b/src/DynamicLink.cpp @@ -159,9 +159,9 @@ bool DynamicModuleControl::do_load() { snprintf(buf, sizeof(buf), "%s/%sNP.rel", sRelsDir, mName); if (mModule == nullptr) { if (sArchive != nullptr) { - sDvdFile = fn_802EFE90(sArchive, buf, 1, mHeap); + sDvdFile = mDvd_toMainRam_arc_c::createOrFail(sArchive, buf, 1, mHeap); } else { - sDvdFile = fn_802F0030(buf, 1, mHeap); + sDvdFile = mDvd_toMainRam_normal_c::createOrFail(buf, 1, mHeap); } if (sDvdFile != nullptr) { @@ -170,7 +170,7 @@ bool DynamicModuleControl::do_load() { void *ptr = sDvdFile->mDataPtr; sDvdFile->mDataPtr = nullptr; mModule = static_cast(ptr); - fn_802EF480(sDvdFile); + sDvdFile->do_delete(); sDvdFile = nullptr; if (mModule != nullptr) { unk_40 = 0; @@ -198,7 +198,7 @@ BOOL DynamicModuleControl::do_load_async() { } if (mDvdCallbackRequest != nullptr && mDvdCallbackRequest->mStatus != 0) { - fn_802EF480(mDvdCallbackRequest); + mDvdCallbackRequest->do_delete(); mDvdCallbackRequest = nullptr; return true; } else { @@ -351,6 +351,7 @@ void DbMapFile::Unregister() { unk_0 = 0; } } + extern "C" { void ModuleProlog() {} @@ -370,5 +371,4 @@ void ModuleDestructorsX(void (**ptrs)()) { (*ptrs)(); } } - } diff --git a/src/d/d_dvd.cpp b/src/d/d_dvd.cpp index afe8d10f..2f7b9cfa 100644 --- a/src/d/d_dvd.cpp +++ b/src/d/d_dvd.cpp @@ -43,7 +43,7 @@ void *loader_c::request(const char *path, u8 mountDirection, EGG::Heap *heap) { mpBuffer = mpCommand->mDataPtr; mSize = mpCommand->mAmountRead; mpCommand->mDataPtr = nullptr; - fn_802EF480(mpCommand); + mpCommand->do_delete(); mpCommand = nullptr; return mpBuffer; } else { diff --git a/src/m/m_dvd.cpp b/src/m/m_dvd.cpp index c503216b..82fce847 100644 --- a/src/m/m_dvd.cpp +++ b/src/m/m_dvd.cpp @@ -309,8 +309,8 @@ mDvd_command_c::mDvd_command_c() { } /** 802ef480 */ -extern "C" void fn_802EF480(mDvd_command_c *cmd) { - delete cmd; +void mDvd_command_c::do_delete() { + delete this; } /** 802ef4a0 */ @@ -318,7 +318,7 @@ void mDvd_command_c::destroy(mDvd_command_c **cmd) { // TODO fake match, this looks like an inlined dtor if (cmd != nullptr && cmd != nullptr && *cmd != nullptr) { (*cmd)->done(); - fn_802EF480(*cmd); + (*cmd)->do_delete(); *cmd = nullptr; } } @@ -568,7 +568,7 @@ mDvd_toMainRam_arc_c *mDvd_toMainRam_arc_c::create(EGG::Archive *arc, const char } /** 802efe90 */ -extern "C" mDvd_toMainRam_arc_c *fn_802EFE90(EGG::Archive *arc, const char *path, int mountDirection, EGG::Heap *heap) { +mDvd_toMainRam_arc_c *mDvd_toMainRam_arc_c::createOrFail(EGG::Archive *arc, const char *path, int mountDirection, EGG::Heap *heap) { mDvd_toMainRam_arc_c *cmd = mDvd_toMainRam_arc_c::create(arc, path, mountDirection, heap); while (!cmd) {} return cmd; @@ -608,7 +608,7 @@ mDvd_toMainRam_normal_c *mDvd_toMainRam_normal_c::create(const char *path, int m } /** 802f0030 */ -extern "C" mDvd_toMainRam_normal_c *fn_802F0030(const char *path, int mountDirection, EGG::Heap *heap) { +mDvd_toMainRam_normal_c *mDvd_toMainRam_normal_c::createOrFail(const char *path, int mountDirection, EGG::Heap *heap) { mDvd_toMainRam_normal_c *cmd = mDvd_toMainRam_normal_c::create(path, mountDirection, heap); while (!cmd) {} return cmd;