From 303ff91f6a88386fd16514cb3c4b26b5b783d830 Mon Sep 17 00:00:00 2001 From: vabold Date: Fri, 17 Jun 2022 15:34:28 -0400 Subject: [PATCH 01/46] MenuCharacterManager: full match Co-Authored-By: riidefi <34194588+riidefi@users.noreply.github.com> --- pack/rel_objects.txt | 5 +- pack/rel_slices.csv | 2 +- pack/symbols.txt | 2 +- source/game/system/ResourceManager.cpp | 75 +++----------------------- source/game/system/ResourceManager.hpp | 30 ++++++++++- 5 files changed, 41 insertions(+), 73 deletions(-) diff --git a/pack/rel_objects.txt b/pack/rel_objects.txt index 31a8fed78..0bff53791 100644 --- a/pack/rel_objects.txt +++ b/pack/rel_objects.txt @@ -17,10 +17,11 @@ out/rel/data_808b2d50_808b3188.o out/LocalizedArchive.o out/MultiDvdArchive.o out/rel/text_8052ae5c_8053fc4c.o +out/rel/rodata_8088fe28_80891370.o +out/rel/data_808b31e8_808b3c08.o out/ResourceManager.o out/rel/text_80542878_80555464.o -out/rel/rodata_8088fe28_80891370.o -out/rel/data_808b31e8_808b42e0.o +out/rel/data_808b3c20_808b42e0.o out/Random.o out/rel/text_8055572c_80590128.o out/rel/rodata_80891380_80896148.o diff --git a/pack/rel_slices.csv b/pack/rel_slices.csv index d3aeae7ca..8b66ec9d4 100644 --- a/pack/rel_slices.csv +++ b/pack/rel_slices.csv @@ -4,7 +4,7 @@ enabled,name,textStart,textEnd,ctorsStart,ctorsEnd,dtorsStart,dtorsEnd,rodataSta 1,source/game/system/GhostFile.cpp,0x8051c088,0x8051d4d4,,,,,,,0x808b2d38,0x808b2d50,, 1,source/game/system/LocalizedArchive.cpp,0x8052a098,0x8052a538,,,,,0x8088fdc0,0x8088fe00,0x808b3188,0x808b31d8,, 1,source/game/system/MultiDvdArchive.cpp,0x8052a538,0x8052ae5c,,,,,0x8088fe00,0x8088fe28,0x808b31d8,0x808b31e8,, -1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,,,,,, +1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,,,0x808b3c08,0x808b3c20,, 1,source/game/util/Random.cpp,0x80555464,0x8055572c,,,,,0x80891370,0x80891380,0x808b42e0,0x808b42ec,, 1,source/game/kart/KartComponent.cpp,0x80590128,0x805901d0,,,,,,,,,0x809c1900,0x809c1910 1,source/game/ui/ControlGroup.cpp,0x805c23e4,0x805c2c18,,,,,,,,,, diff --git a/pack/symbols.txt b/pack/symbols.txt index 4a7c613f0..4a4651b17 100644 --- a/pack/symbols.txt +++ b/pack/symbols.txt @@ -9962,7 +9962,7 @@ 0x8053fc4c ResourceManager_createInstance 0x8053fc9c ResourceManager_destroyInstance 0x8053fcec ResourceManager_construct -0x8053fe68 unk_8053fe68 +0x8053fe68 __ct__Q26System20MenuCharacterManagerFv 0x8053fe94 unk_8053fe94 0x8053fed4 unk_8053fed4 0x8053ff14 unk_8053ff14 diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 567edbcf0..9a61dcef7 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -204,77 +204,16 @@ asm UNKNOWN_FUNCTION(ResourceManager_construct) { // clang-format on } -// Symbol: unk_8053fe68 -// PAL: 0x8053fe68..0x8053fe94 -MARK_BINARY_BLOB(unk_8053fe68, 0x8053fe68, 0x8053fe94); -asm UNKNOWN_FUNCTION(unk_8053fe68) { - // clang-format off - nofralloc; - lis r4, 0; - li r5, 0; - addi r4, r4, 0; - li r0, 2; - stw r5, 4(r3); - stw r5, 8(r3); - stw r5, 0xc(r3); - stw r4, 0(r3); - stw r5, 0x10(r3); - stw r0, 0x14(r3); - blr; - // clang-format on -} +namespace System { -// Symbol: unk_8053fe94 -// PAL: 0x8053fe94..0x8053fed4 -MARK_BINARY_BLOB(unk_8053fe94, 0x8053fe94, 0x8053fed4); -asm UNKNOWN_FUNCTION(unk_8053fe94) { - // clang-format off - nofralloc; - stwu r1, -0x10(r1); - mflr r0; - cmpwi r3, 0; - stw r0, 0x14(r1); - stw r31, 0xc(r1); - mr r31, r3; - beq lbl_8053febc; - cmpwi r4, 0; - ble lbl_8053febc; - bl unk_805553b0; -lbl_8053febc: - mr r3, r31; - lwz r31, 0xc(r1); - lwz r0, 0x14(r1); - mtlr r0; - addi r1, r1, 0x10; - blr; - // clang-format on +MenuCharacterManager::MenuCharacterManager() { + mCharacter = 0; + mModelType = 2; } -// Symbol: unk_8053fed4 -// PAL: 0x8053fed4..0x8053ff14 -MARK_BINARY_BLOB(unk_8053fed4, 0x8053fed4, 0x8053ff14); -asm UNKNOWN_FUNCTION(unk_8053fed4) { - // clang-format off - nofralloc; - stwu r1, -0x10(r1); - mflr r0; - cmpwi r3, 0; - stw r0, 0x14(r1); - stw r31, 0xc(r1); - mr r31, r3; - beq lbl_8053fefc; - cmpwi r4, 0; - ble lbl_8053fefc; - bl unk_805553b0; -lbl_8053fefc: - mr r3, r31; - lwz r31, 0xc(r1); - lwz r0, 0x14(r1); - mtlr r0; - addi r1, r1, 0x10; - blr; - // clang-format on -} +MenuCharacterManager::~MenuCharacterManager() {} + +} // namespace System // Symbol: unk_8053ff14 // PAL: 0x8053ff14..0x8053ff1c diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index ce825259f..7c1d7d904 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -15,7 +15,7 @@ UNKNOWN_FUNCTION(ResourceManager_destroyInstance); // PAL: 0x8053fcec..0x8053fe68 UNKNOWN_FUNCTION(ResourceManager_construct); // PAL: 0x8053fe68..0x8053fe94 -UNKNOWN_FUNCTION(unk_8053fe68); +UNKNOWN_FUNCTION(__ct__Q26System20MenuCharacterManagerFv); // PAL: 0x8053fe94..0x8053fed4 UNKNOWN_FUNCTION(unk_8053fe94); // PAL: 0x8053fed4..0x8053ff14 @@ -158,3 +158,31 @@ UNKNOWN_FUNCTION(unk_80542868); #ifdef __cplusplus } #endif + +namespace System { + +// begrudging riidefi magic +struct S { + virtual ~S() = 0; +}; +inline S::~S() {} +struct T { + T() { + mHeap1 = 0; + mHeap2 = 0; + _unk = 0; + } + void* mHeap1; + void* mHeap2; + s32 _unk; +}; + +class MenuCharacterManager : S, T { +public: + MenuCharacterManager(); + virtual ~MenuCharacterManager(); + s32 mCharacter; + s32 mModelType; +}; + +} // namespace System From 4a5b6344f1dda6ff6462cff93bd0f26125415f4f Mon Sep 17 00:00:00 2001 From: vabold Date: Fri, 17 Jun 2022 17:09:49 -0400 Subject: [PATCH 02/46] JobContext: full match Co-Authored-By: em-eight <107326447+em-eight@users.noreply.github.com> --- source/game/system/ResourceManager.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 7c1d7d904..29956398f 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -4,6 +4,10 @@ #include +#include +#include +#include + #ifdef __cplusplus extern "C" { #endif @@ -161,6 +165,15 @@ UNKNOWN_FUNCTION(unk_80542868); namespace System { +struct JobContext { + MultiDvdArchive* multiArchive; + DvdArchive* archive; + unk _08; + char filename[64]; + EGG::Heap* archiveHeap; + EGG::Heap* fileHeap; +}; + // begrudging riidefi magic struct S { virtual ~S() = 0; From e8aac6d4c843a1bd09d2f54f0d23bebdebce6c0a Mon Sep 17 00:00:00 2001 From: vabold Date: Fri, 17 Jun 2022 20:52:59 -0400 Subject: [PATCH 03/46] CourseCache: ctor, dtor, init --- pack/rel_objects.txt | 2 +- pack/rel_slices.csv | 2 +- source/game/system/LocalizedArchive.cpp | 18 ---- source/game/system/LocalizedArchive.hpp | 18 ++++ source/game/system/ResourceManager.cpp | 125 ++++-------------------- source/game/system/ResourceManager.hpp | 22 ++++- 6 files changed, 59 insertions(+), 128 deletions(-) diff --git a/pack/rel_objects.txt b/pack/rel_objects.txt index 0bff53791..5a47d1f94 100644 --- a/pack/rel_objects.txt +++ b/pack/rel_objects.txt @@ -21,7 +21,7 @@ out/rel/rodata_8088fe28_80891370.o out/rel/data_808b31e8_808b3c08.o out/ResourceManager.o out/rel/text_80542878_80555464.o -out/rel/data_808b3c20_808b42e0.o +out/rel/data_808b3c2c_808b42e0.o out/Random.o out/rel/text_8055572c_80590128.o out/rel/rodata_80891380_80896148.o diff --git a/pack/rel_slices.csv b/pack/rel_slices.csv index 8b66ec9d4..ed56ec9de 100644 --- a/pack/rel_slices.csv +++ b/pack/rel_slices.csv @@ -4,7 +4,7 @@ enabled,name,textStart,textEnd,ctorsStart,ctorsEnd,dtorsStart,dtorsEnd,rodataSta 1,source/game/system/GhostFile.cpp,0x8051c088,0x8051d4d4,,,,,,,0x808b2d38,0x808b2d50,, 1,source/game/system/LocalizedArchive.cpp,0x8052a098,0x8052a538,,,,,0x8088fdc0,0x8088fe00,0x808b3188,0x808b31d8,, 1,source/game/system/MultiDvdArchive.cpp,0x8052a538,0x8052ae5c,,,,,0x8088fe00,0x8088fe28,0x808b31d8,0x808b31e8,, -1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,,,0x808b3c08,0x808b3c20,, +1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,,,0x808b3c08,0x808b3c2c,, 1,source/game/util/Random.cpp,0x80555464,0x8055572c,,,,,0x80891370,0x80891380,0x808b42e0,0x808b42ec,, 1,source/game/kart/KartComponent.cpp,0x80590128,0x805901d0,,,,,,,,,0x809c1900,0x809c1910 1,source/game/ui/ControlGroup.cpp,0x805c23e4,0x805c2c18,,,,,,,,,, diff --git a/source/game/system/LocalizedArchive.cpp b/source/game/system/LocalizedArchive.cpp index bda9b61fd..01b2d7657 100644 --- a/source/game/system/LocalizedArchive.cpp +++ b/source/game/system/LocalizedArchive.cpp @@ -8,24 +8,6 @@ namespace System { static const char* LOCALIZED_SZS[] = {"", "_E.szs", "_G.szs", "_F.szs", "_S.szs", "_I.szs", "_N.szs", nullptr}; -class RaceSysDvdArchive : public MultiDvdArchive { -public: - RaceSysDvdArchive(); - void init() override; -}; - -class UIDvdArchive : public MultiDvdArchive { -public: - UIDvdArchive(); - void init() override; -}; - -class CourseDvdArchive : public MultiDvdArchive { -public: - CourseDvdArchive(); - void init() override; -}; - MultiDvdArchive* createMultiDvdArchive(ResourceChannelID kind) { MultiDvdArchive* archive = nullptr; diff --git a/source/game/system/LocalizedArchive.hpp b/source/game/system/LocalizedArchive.hpp index e50ac34ab..ebcd35635 100644 --- a/source/game/system/LocalizedArchive.hpp +++ b/source/game/system/LocalizedArchive.hpp @@ -6,4 +6,22 @@ namespace System { MultiDvdArchive* createMultiDvdArchive(ResourceChannelID kind); +class RaceSysDvdArchive : public MultiDvdArchive { +public: + RaceSysDvdArchive(); + void init() override; +}; + +class UIDvdArchive : public MultiDvdArchive { +public: + UIDvdArchive(); + void init() override; +}; + +class CourseDvdArchive : public MultiDvdArchive { +public: + CourseDvdArchive(); + void init() override; +}; + } // namespace System diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 9a61dcef7..11a2645af 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -2458,118 +2458,31 @@ asm UNKNOWN_FUNCTION(unk_805419ec) { // clang-format on } -// Symbol: unk_80541a10 -// PAL: 0x80541a10..0x80541a70 -MARK_BINARY_BLOB(unk_80541a10, 0x80541a10, 0x80541a70); -asm UNKNOWN_FUNCTION(unk_80541a10) { - // clang-format off - nofralloc; - stwu r1, -0x10(r1); - mflr r0; - stw r0, 0x14(r1); - stw r31, 0xc(r1); - mr r31, r3; - bl unk_805553b0; - lis r3, 0; - li r0, 0; - addi r3, r3, 0; - stw r3, 0(r31); - li r3, 0x1c; - stw r0, 0x10(r31); - stw r0, 0x14(r31); - bl unk_805553b0; - cmpwi r3, 0; - beq lbl_80541a54; - bl __ct__Q26System16CourseDvdArchiveFv; -lbl_80541a54: - stw r3, 0x20(r31); - mr r3, r31; - lwz r31, 0xc(r1); - lwz r0, 0x14(r1); - mtlr r0; - addi r1, r1, 0x10; - blr; - // clang-format on +// #ifdef NON_MATCHING +namespace System { + +CourseCache::CourseCache() { + mBuffer = nullptr; + mHeap = nullptr; + mArchive = new CourseDvdArchive(); } -// Symbol: unk_80541a70 -// PAL: 0x80541a70..0x80541ac4 -MARK_BINARY_BLOB(unk_80541a70, 0x80541a70, 0x80541ac4); -asm UNKNOWN_FUNCTION(unk_80541a70) { - // clang-format off - nofralloc; - stwu r1, -0x10(r1); - mflr r0; - li r4, -32; - stw r0, 0x14(r1); - stw r31, 0xc(r1); - lis r31, 0x32; - stw r30, 8(r1); - mr r30, r3; - addi r3, r31, -28672; - bl unk_805553b0; - stw r3, 0x10(r30); - addi r4, r31, -28672; - li r5, 1; - bl unk_805553b0; - stw r3, 0x14(r30); - lwz r31, 0xc(r1); - lwz r30, 8(r1); - lwz r0, 0x14(r1); - mtlr r0; - addi r1, r1, 0x10; - blr; - // clang-format on +void CourseCache::init() { + void* block = new (-32) u8[0x319000]; + mBuffer = block; + mHeap = EGG::ExpHeap::create(block, 0x319000, 1); } -// Symbol: unk_80541ac4 -// PAL: 0x80541ac4..0x80541b58 -MARK_BINARY_BLOB(unk_80541ac4, 0x80541ac4, 0x80541b58); -asm UNKNOWN_FUNCTION(unk_80541ac4) { - // clang-format off - nofralloc; - stwu r1, -0x10(r1); - mflr r0; - cmpwi r3, 0; - stw r0, 0x14(r1); - stw r31, 0xc(r1); - mr r31, r4; - stw r30, 8(r1); - mr r30, r3; - beq lbl_80541b3c; - lis r4, 0; - addi r4, r4, 0; - stw r4, 0(r3); - lwz r3, 0x20(r3); - bl clear__Q26System15MultiDvdArchiveFv; - lwz r3, 0x14(r30); - cmpwi r3, 0; - beq lbl_80541b20; - lwz r12, 0(r3); - lwz r12, 0x1c(r12); - mtctr r12; - bctrl; - lwz r3, 0x10(r30); - bl unk_805553b0; -lbl_80541b20: - mr r3, r30; - li r4, 0; - bl unk_805553b0; - cmpwi r31, 0; - ble lbl_80541b3c; - mr r3, r30; - bl unk_805553b0; -lbl_80541b3c: - mr r3, r30; - lwz r31, 0xc(r1); - lwz r30, 8(r1); - lwz r0, 0x14(r1); - mtlr r0; - addi r1, r1, 0x10; - blr; - // clang-format on +CourseCache::~CourseCache() { + mArchive->clear(); + if (mHeap) { + mHeap->destroy(); + delete[] (mBuffer); + } } +} // namespace System + // Symbol: unk_80541b58 // PAL: 0x80541b58..0x80541c18 MARK_BINARY_BLOB(unk_80541b58, 0x80541b58, 0x80541c18); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 29956398f..2f0429f7e 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -4,6 +4,8 @@ #include +#include +#include #include #include #include @@ -185,8 +187,8 @@ struct T { mHeap2 = 0; _unk = 0; } - void* mHeap1; - void* mHeap2; + EGG::ExpHeap* mHeap1; + EGG::ExpHeap* mHeap2; s32 _unk; }; @@ -198,4 +200,20 @@ class MenuCharacterManager : S, T { s32 mModelType; }; +class CourseCache : EGG::Disposer { +public: + CourseCache(); + void init(); + virtual ~CourseCache(); + void load(u32 courseId); + void loadOther(MultiDvdArchive* other, EGG::Heap* heap); + +private: + void* mBuffer; + EGG::ExpHeap* mHeap; + u32 mCourseId; + volatile u32 mState; + MultiDvdArchive* mArchive; +}; + } // namespace System From 0402e8718e5342063b5086183e156db1d70eee75 Mon Sep 17 00:00:00 2001 From: Aiden Date: Sat, 18 Jun 2022 04:06:14 -0400 Subject: [PATCH 04/46] CourseCache: load --- source/game/system/ResourceManager.cpp | 33 ++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 11a2645af..6a580b95f 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -2458,7 +2458,6 @@ asm UNKNOWN_FUNCTION(unk_805419ec) { // clang-format on } -// #ifdef NON_MATCHING namespace System { CourseCache::CourseCache() { @@ -2477,12 +2476,41 @@ CourseCache::~CourseCache() { mArchive->clear(); if (mHeap) { mHeap->destroy(); - delete[] (mBuffer); + delete[](mBuffer); } } } // namespace System + +#ifdef NON_MATCHING // requires rodata to work +namespace System { + +void CourseCache::load(s32 courseId) { + if (!mHeap) + return; + char buffer[128]; + mCourseId = courseId; + if (mState == 2) { + mArchive->clear(); + } + mState = 1; + + snprintf(buffer, sizeof(buffer), "Race/Course/%s", TRACK_NAMES[mCourseId]); + mArchive->rip(buffer, mHeap); + + // something is wrong - this matches but requires rippedArchiveCount() to + // return s32, which almost certainly breaks MultiDvdArchive + if ((u16)mArchive->rippedArchiveCount()) { + mState = 2; + } else { + mArchive->clear(); + mState = 0; + } +} + +} // namespace System +#else // Symbol: unk_80541b58 // PAL: 0x80541b58..0x80541c18 MARK_BINARY_BLOB(unk_80541b58, 0x80541b58, 0x80541c18); @@ -2542,6 +2570,7 @@ asm UNKNOWN_FUNCTION(unk_80541b58) { blr; // clang-format on } +#endif // Symbol: unk_80541c18 // PAL: 0x80541c18..0x80541c38 From 86f4ee3915a2ebb98fa07930e6990bc8349078c1 Mon Sep 17 00:00:00 2001 From: Theodoros Tyrovouzis Date: Sun, 19 Jun 2022 19:00:49 +0300 Subject: [PATCH 05/46] Add loadCourse WIP --- pack/symbols.txt | 2 +- source/game/system/ResourceManager.cpp | 45 +++++++++++++++++++++++++- source/game/system/ResourceManager.hpp | 26 ++++++++++++++- source/rvl/os/osThread.h | 3 ++ 4 files changed, 73 insertions(+), 3 deletions(-) diff --git a/pack/symbols.txt b/pack/symbols.txt index 4a4651b17..8fa00fe8b 100644 --- a/pack/symbols.txt +++ b/pack/symbols.txt @@ -9977,7 +9977,7 @@ 0x80540450 ResourceManager_load 0x80540558 unk_80540558 0x80540680 ResourceManager_loadUI -0x80540760 ResourceManager_loadCourse +0x80540760 loadCourse__Q26System15ResourceManagerF8CourseIdPQ23EGG4Heapb 0x80540918 ResourceManager_loadMission 0x80540b14 ResourceManager_loadCompetition 0x80540cfc unk_80540cfc diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 6a580b95f..f37d17813 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -1,5 +1,7 @@ #include "ResourceManager.hpp" +#include "rvl/os/osThread.h" + extern "C" { extern UNKNOWN_FUNCTION(load__Q26System10DvdArchiveFPCcUlPQ23EGG4Heap); extern UNKNOWN_FUNCTION(getFileCopy__Q26System10DvdArchiveFPcPQ23EGG4HeapPUlSc); @@ -882,7 +884,7 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadUI) { // Symbol: ResourceManager_loadCourse // PAL: 0x80540760..0x80540918 -MARK_BINARY_BLOB(ResourceManager_loadCourse, 0x80540760, 0x80540918); +/*MARK_BINARY_BLOB(ResourceManager_loadCourse, 0x80540760, 0x80540918); asm UNKNOWN_FUNCTION(ResourceManager_loadCourse) { // clang-format off nofralloc; @@ -1001,6 +1003,47 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadCourse) { addi r1, r1, 0xa0; blr; // clang-format on +}*/ + +namespace System { +void ResourceManager::requestLoad(s32 idx, MultiDvdArchive* m, const char* p, EGG::Heap* archiveHeap) { + this->jobContexts[idx].multiArchive = m; + strncpy(this->jobContexts[idx].filename, p, 0x40); + this->jobContexts[idx].archiveHeap = archiveHeap; + + this->taskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); + this->process(); + + if (!m->isLoaded()) { + OSSleepMilliseconds(16); + } +} + +MultiDvdArchive* ResourceManager::loadCourse(CourseId courseId, EGG::Heap* param_3, bool splitScreen) { + char courseName[128]; + + if (!this->multiArchives1[1]->isLoaded()) { + this->multiArchives1[1]->init(); + if (!splitScreen && this->courseCache.mState == 2 && courseId == this->courseCache.mCourseId) { + MultiDvdArchive* m = this->multiArchives1[1]; + if (this->courseCache.mState == 2) + m->loadOther(this->courseCache.mArchive, param_3); + } else { + if (splitScreen) { + snprintf(courseName, sizeof(courseName), "Race/Course/%s_d", COURSE_NAMES[courseId]); + if (!this->multiArchives1[1]->exists(courseName)) { + splitScreen = false; + } + } + if (!splitScreen) { + snprintf(courseName, sizeof(courseName), "Race/Course/%s", COURSE_NAMES[courseId]); + } + requestLoad(2, this->multiArchives1[1], courseName, param_3); + } + } + return this->multiArchives1[1]; +} + } // Symbol: ResourceManager_loadMission diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 2f0429f7e..43adb5206 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -167,6 +167,8 @@ UNKNOWN_FUNCTION(unk_80542868); namespace System { +const char* COURSE_NAMES[] = {"TODO"}; + struct JobContext { MultiDvdArchive* multiArchive; DvdArchive* archive; @@ -208,7 +210,7 @@ class CourseCache : EGG::Disposer { void load(u32 courseId); void loadOther(MultiDvdArchive* other, EGG::Heap* heap); -private: +//private: // idk if rii prefers to befriend every class over public-ing everything void* mBuffer; EGG::ExpHeap* mHeap; u32 mCourseId; @@ -216,4 +218,26 @@ class CourseCache : EGG::Disposer { MultiDvdArchive* mArchive; }; +typedef enum { + +} CourseId; + +class ResourceManager { + virtual ~ResourceManager(); +public: + MultiDvdArchive** multiArchives1; + MultiDvdArchive multiArchives2[12]; + MultiDvdArchive MultiArchives3[12]; + DvdArchive dvdArhive[4]; + JobContext jobContexts[7]; + EGG::TaskThread* taskThread; + CourseCache courseCache; + char unk5ac_60b[0x60b-0x5ac]; + + MultiDvdArchive* loadCourse(CourseId courseId, EGG::Heap* param_3, bool splitScreen); + void process(); + static void doLoadTask(void* jobContext); + void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, EGG::Heap* archiveHeap) ; +}; + } // namespace System diff --git a/source/rvl/os/osThread.h b/source/rvl/os/osThread.h index e44cd9e8e..c7800f2c3 100644 --- a/source/rvl/os/osThread.h +++ b/source/rvl/os/osThread.h @@ -18,6 +18,9 @@ u32* const __OSBusClock = (u32*)0x800000F8; #define OS_TIMER_CLOCK (__OSBusClock >> 2) +#define OSMillisecondsToTicks(msec) ((msec) * (OS_TIMER_CLOCK / 1000)) +#define OSSleepMilliseconds(msec) OSSleepTicks(OSMillisecondsToTicks((OSTime)msec)) + typedef struct OSThread { char _00[0x304]; char* stack_high; // 304 From 7b1721e4de34d7cf64e1adc83f179e8d53cf0313 Mon Sep 17 00:00:00 2001 From: Theodoros Tyrovouzis Date: Sun, 19 Jun 2022 20:35:58 +0300 Subject: [PATCH 06/46] WIP comment requestLoad ASM --- source/game/system/ResourceManager.cpp | 30 ++++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index f37d17813..425a6021d 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -477,7 +477,7 @@ asm UNKNOWN_FUNCTION(unk_805401fc) { // Symbol: unk_8054020c // PAL: 0x8054020c..0x805402c0 -MARK_BINARY_BLOB(unk_8054020c, 0x8054020c, 0x805402c0); +/*MARK_BINARY_BLOB(unk_8054020c, 0x8054020c, 0x805402c0); asm UNKNOWN_FUNCTION(unk_8054020c) { // clang-format off nofralloc; @@ -528,6 +528,21 @@ asm UNKNOWN_FUNCTION(unk_8054020c) { addi r1, r1, 0x20; blr; // clang-format on +}*/ + +namespace System { +void ResourceManager::requestLoad(s32 idx, MultiDvdArchive* m, const char* p, EGG::Heap* archiveHeap) { + this->jobContexts[idx].multiArchive = m; + strncpy(this->jobContexts[idx].filename, p, 0x40); + this->jobContexts[idx].archiveHeap = archiveHeap; + + this->taskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); + this->process(); + + if (!m->isLoaded()) { + OSSleepMilliseconds(16); + } +} } // Symbol: unk_805402c0 @@ -1006,19 +1021,6 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadCourse) { }*/ namespace System { -void ResourceManager::requestLoad(s32 idx, MultiDvdArchive* m, const char* p, EGG::Heap* archiveHeap) { - this->jobContexts[idx].multiArchive = m; - strncpy(this->jobContexts[idx].filename, p, 0x40); - this->jobContexts[idx].archiveHeap = archiveHeap; - - this->taskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); - this->process(); - - if (!m->isLoaded()) { - OSSleepMilliseconds(16); - } -} - MultiDvdArchive* ResourceManager::loadCourse(CourseId courseId, EGG::Heap* param_3, bool splitScreen) { char courseName[128]; From f3744cc9a3f2624803952b12c04e3fcbc295f107 Mon Sep 17 00:00:00 2001 From: Theodoros Tyrovouzis Date: Mon, 20 Jun 2022 00:56:00 +0300 Subject: [PATCH 07/46] Match loadCourse and requestLoad --- pack/rel_objects.txt | 3 +- pack/rel_slices.csv | 2 +- source/game/system/ResourceManager.cpp | 46 +++++++++++++++++--------- source/game/system/ResourceManager.hpp | 8 ++--- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/pack/rel_objects.txt b/pack/rel_objects.txt index 5a47d1f94..570624e14 100644 --- a/pack/rel_objects.txt +++ b/pack/rel_objects.txt @@ -17,10 +17,11 @@ out/rel/data_808b2d50_808b3188.o out/LocalizedArchive.o out/MultiDvdArchive.o out/rel/text_8052ae5c_8053fc4c.o -out/rel/rodata_8088fe28_80891370.o +out/rel/rodata_8088fe28_80890ae8.o out/rel/data_808b31e8_808b3c08.o out/ResourceManager.o out/rel/text_80542878_80555464.o +out/rel/rodata_80890b20_80891370.o out/rel/data_808b3c2c_808b42e0.o out/Random.o out/rel/text_8055572c_80590128.o diff --git a/pack/rel_slices.csv b/pack/rel_slices.csv index ed56ec9de..26a236a53 100644 --- a/pack/rel_slices.csv +++ b/pack/rel_slices.csv @@ -4,7 +4,7 @@ enabled,name,textStart,textEnd,ctorsStart,ctorsEnd,dtorsStart,dtorsEnd,rodataSta 1,source/game/system/GhostFile.cpp,0x8051c088,0x8051d4d4,,,,,,,0x808b2d38,0x808b2d50,, 1,source/game/system/LocalizedArchive.cpp,0x8052a098,0x8052a538,,,,,0x8088fdc0,0x8088fe00,0x808b3188,0x808b31d8,, 1,source/game/system/MultiDvdArchive.cpp,0x8052a538,0x8052ae5c,,,,,0x8088fe00,0x8088fe28,0x808b31d8,0x808b31e8,, -1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,,,0x808b3c08,0x808b3c2c,, +1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890AE8,0x80890B20,0x808b3c08,0x808b3c2c,, 1,source/game/util/Random.cpp,0x80555464,0x8055572c,,,,,0x80891370,0x80891380,0x808b42e0,0x808b42ec,, 1,source/game/kart/KartComponent.cpp,0x80590128,0x805901d0,,,,,,,,,0x809c1900,0x809c1910 1,source/game/ui/ControlGroup.cpp,0x805c23e4,0x805c2c18,,,,,,,,,, diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 425a6021d..622b5c905 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -2,6 +2,20 @@ #include "rvl/os/osThread.h" + + +extern const char* COURSE_NAMES[]; + +extern const int arr_80890AE8[]; +const int arr_80890AE8[] = { + 819200, + 921600, + 36, + 48, + 14, + 51200 +}; + extern "C" { extern UNKNOWN_FUNCTION(load__Q26System10DvdArchiveFPCcUlPQ23EGG4Heap); extern UNKNOWN_FUNCTION(getFileCopy__Q26System10DvdArchiveFPcPQ23EGG4HeapPUlSc); @@ -349,10 +363,10 @@ asm UNKNOWN_FUNCTION(unk_80540038) { // clang-format on } -// Symbol: ResourceManager_process +// Symbol: process__Q26System15ResourceManagerFv // PAL: 0x805400a0..0x805401ec -MARK_BINARY_BLOB(ResourceManager_process, 0x805400a0, 0x805401ec); -asm UNKNOWN_FUNCTION(ResourceManager_process) { +MARK_BINARY_BLOB(process__Q26System15ResourceManagerFv, 0x805400a0, 0x805401ec); +asm UNKNOWN_FUNCTION(process__Q26System15ResourceManagerFv) { // clang-format off nofralloc; stwu r1, -0x20(r1); @@ -505,7 +519,7 @@ asm UNKNOWN_FUNCTION(unk_8054020c) { lwz r3, 0x584(r27); bl unk_805553b0; mr r3, r27; - bl ResourceManager_process; + bl process__Q26System15ResourceManagerFv; mr r3, r29; bl isLoaded__Q26System15MultiDvdArchiveFv; cmpwi r3, 0; @@ -577,7 +591,7 @@ asm UNKNOWN_FUNCTION(unk_805402c0) { lwz r3, 0x584(r26); bl unk_805553b0; mr r3, r26; - bl ResourceManager_process; + bl process__Q26System15ResourceManagerFv; lwz r0, 0x20(r28); li r3, 0; cmpwi r0, 4; @@ -642,7 +656,7 @@ asm UNKNOWN_FUNCTION(unk_80540394) { lwz r3, 0x584(r26); bl unk_805553b0; mr r3, r26; - bl ResourceManager_process; + bl process__Q26System15ResourceManagerFv; mr r3, r28; bl isLoaded__Q26System15MultiDvdArchiveFv; cmpwi r3, 0; @@ -714,7 +728,7 @@ asm UNKNOWN_FUNCTION(ResourceManager_load) { li r6, 0; bl unk_805553b0; mr r3, r31; - bl ResourceManager_process; + bl process__Q26System15ResourceManagerFv; mr r3, r30; bl isLoaded__Q26System15MultiDvdArchiveFv; cmpwi r3, 0; @@ -796,7 +810,7 @@ asm UNKNOWN_FUNCTION(unk_80540558) { li r6, 0; bl unk_805553b0; mr r3, r30; - bl ResourceManager_process; + bl process__Q26System15ResourceManagerFv; lwz r0, 0x2c8(r28); li r3, 0; cmpwi r0, 4; @@ -868,7 +882,7 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadUI) { li r6, 0; bl unk_805553b0; mr r3, r29; - bl ResourceManager_process; + bl process__Q26System15ResourceManagerFv; mr r3, r31; bl isLoaded__Q26System15MultiDvdArchiveFv; cmpwi r3, 0; @@ -990,7 +1004,7 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadCourse) { li r6, 0; bl unk_805553b0; mr r3, r31; - bl ResourceManager_process; + bl process__Q26System15ResourceManagerFv; mr r3, r30; bl isLoaded__Q26System15MultiDvdArchiveFv; cmpwi r3, 0; @@ -1162,7 +1176,7 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadMission) { li r6, 0; bl unk_805553b0; mr r3, r28; - bl ResourceManager_process; + bl process__Q26System15ResourceManagerFv; mr r3, r29; bl isLoaded__Q26System15MultiDvdArchiveFv; cmpwi r3, 0; @@ -1299,7 +1313,7 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadCompetition) { li r6, 0; bl unk_805553b0; mr r3, r23; - bl ResourceManager_process; + bl process__Q26System15ResourceManagerFv; mr r3, r21; bl isLoaded__Q26System15MultiDvdArchiveFv; cmpwi r3, 0; @@ -1391,7 +1405,7 @@ asm UNKNOWN_FUNCTION(unk_80540cfc) { li r6, 0; bl unk_805553b0; mr r3, r28; - bl ResourceManager_process; + bl process__Q26System15ResourceManagerFv; mr r3, r31; bl isLoaded__Q26System15MultiDvdArchiveFv; cmpwi r3, 0; @@ -1491,7 +1505,7 @@ asm UNKNOWN_FUNCTION(unk_80540e3c) { li r6, 0; bl unk_805553b0; mr r3, r30; - bl ResourceManager_process; + bl process__Q26System15ResourceManagerFv; mr r3, r31; bl isLoaded__Q26System15MultiDvdArchiveFv; cmpwi r3, 0; @@ -1592,7 +1606,7 @@ asm UNKNOWN_FUNCTION(unk_80540f90) { li r6, 0; bl unk_805553b0; mr r3, r30; - bl ResourceManager_process; + bl process__Q26System15ResourceManagerFv; mr r3, r31; bl isLoaded__Q26System15MultiDvdArchiveFv; cmpwi r3, 0; @@ -2676,7 +2690,7 @@ asm UNKNOWN_FUNCTION(unk_80541c48) { cmpwi r31, 0; beq lbl_80541ca0; mr r3, r30; - bl ResourceManager_process; + bl process__Q26System15ResourceManagerFv; lbl_80541ca0: mr r3, r31; lwz r31, 0xc(r1); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 43adb5206..079f64b4d 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -33,7 +33,7 @@ UNKNOWN_FUNCTION(ResourceManager_destroy); // PAL: 0x80540038..0x805400a0 UNKNOWN_FUNCTION(unk_80540038); // PAL: 0x805400a0..0x805401ec -UNKNOWN_FUNCTION(ResourceManager_process); +UNKNOWN_FUNCTION(process__Q26System15ResourceManagerFv); // PAL: 0x805401ec..0x805401fc UNKNOWN_FUNCTION(unk_805401ec); // PAL: 0x805401fc..0x8054020c @@ -167,8 +167,6 @@ UNKNOWN_FUNCTION(unk_80542868); namespace System { -const char* COURSE_NAMES[] = {"TODO"}; - struct JobContext { MultiDvdArchive* multiArchive; DvdArchive* archive; @@ -213,8 +211,8 @@ class CourseCache : EGG::Disposer { //private: // idk if rii prefers to befriend every class over public-ing everything void* mBuffer; EGG::ExpHeap* mHeap; - u32 mCourseId; - volatile u32 mState; + s32 mCourseId; + s32 mState; MultiDvdArchive* mArchive; }; From 5651447a5a1de4f502d4c84f14533aefa4e050bd Mon Sep 17 00:00:00 2001 From: Aiden Date: Sun, 19 Jun 2022 19:20:01 -0400 Subject: [PATCH 08/46] CourseCache: loadOther, full match --- source/game/system/ResourceManager.cpp | 112 ++++++++++++------------- source/game/system/ResourceManager.hpp | 14 ++-- source/rvl/os/osThread.h | 3 +- 3 files changed, 63 insertions(+), 66 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 622b5c905..966f1d2f4 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -2,19 +2,10 @@ #include "rvl/os/osThread.h" - - extern const char* COURSE_NAMES[]; extern const int arr_80890AE8[]; -const int arr_80890AE8[] = { - 819200, - 921600, - 36, - 48, - 14, - 51200 -}; +const int arr_80890AE8[] = {819200, 921600, 36, 48, 14, 51200}; extern "C" { extern UNKNOWN_FUNCTION(load__Q26System10DvdArchiveFPCcUlPQ23EGG4Heap); @@ -545,19 +536,20 @@ asm UNKNOWN_FUNCTION(unk_8054020c) { }*/ namespace System { -void ResourceManager::requestLoad(s32 idx, MultiDvdArchive* m, const char* p, EGG::Heap* archiveHeap) { - this->jobContexts[idx].multiArchive = m; - strncpy(this->jobContexts[idx].filename, p, 0x40); - this->jobContexts[idx].archiveHeap = archiveHeap; +void ResourceManager::requestLoad(s32 idx, MultiDvdArchive* m, const char* p, + EGG::Heap* archiveHeap) { + this->jobContexts[idx].multiArchive = m; + strncpy(this->jobContexts[idx].filename, p, 0x40); + this->jobContexts[idx].archiveHeap = archiveHeap; - this->taskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); - this->process(); + this->taskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); + this->process(); - if (!m->isLoaded()) { - OSSleepMilliseconds(16); - } -} + if (!m->isLoaded()) { + OSSleepMilliseconds(16); + } } +} // namespace System // Symbol: unk_805402c0 // PAL: 0x805402c0..0x80540394 @@ -952,7 +944,8 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadCourse) { bne cr6, lbl_805408f0; lwz r4, 0x5a8(r31); mr r5, r29; - bl loadOther__Q26System15MultiDvdArchiveFPQ26System15MultiDvdArchivePQ23EGG4Heap; + bl +loadOther__Q26System15MultiDvdArchiveFPQ26System15MultiDvdArchivePQ23EGG4Heap; b lbl_805408f0; lbl_805407f4: cmpwi r30, 0; @@ -1035,32 +1028,37 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadCourse) { }*/ namespace System { -MultiDvdArchive* ResourceManager::loadCourse(CourseId courseId, EGG::Heap* param_3, bool splitScreen) { - char courseName[128]; - - if (!this->multiArchives1[1]->isLoaded()) { - this->multiArchives1[1]->init(); - if (!splitScreen && this->courseCache.mState == 2 && courseId == this->courseCache.mCourseId) { - MultiDvdArchive* m = this->multiArchives1[1]; - if (this->courseCache.mState == 2) - m->loadOther(this->courseCache.mArchive, param_3); - } else { - if (splitScreen) { - snprintf(courseName, sizeof(courseName), "Race/Course/%s_d", COURSE_NAMES[courseId]); - if (!this->multiArchives1[1]->exists(courseName)) { - splitScreen = false; - } - } - if (!splitScreen) { - snprintf(courseName, sizeof(courseName), "Race/Course/%s", COURSE_NAMES[courseId]); - } - requestLoad(2, this->multiArchives1[1], courseName, param_3); +MultiDvdArchive* ResourceManager::loadCourse(CourseId courseId, + EGG::Heap* param_3, + bool splitScreen) { + char courseName[128]; + + if (!this->multiArchives1[1]->isLoaded()) { + this->multiArchives1[1]->init(); + if (!splitScreen && this->courseCache.mState == 2 && + courseId == this->courseCache.mCourseId) { + MultiDvdArchive* m = this->multiArchives1[1]; + if (this->courseCache.mState == 2) + m->loadOther(this->courseCache.mArchive, param_3); + } else { + if (splitScreen) { + snprintf(courseName, sizeof(courseName), "Race/Course/%s_d", + COURSE_NAMES[courseId]); + if (!this->multiArchives1[1]->exists(courseName)) { + splitScreen = false; } + } + if (!splitScreen) { + snprintf(courseName, sizeof(courseName), "Race/Course/%s", + COURSE_NAMES[courseId]); + } + requestLoad(2, this->multiArchives1[1], courseName, param_3); } - return this->multiArchives1[1]; + } + return this->multiArchives1[1]; } -} +} // namespace System // Symbol: ResourceManager_loadMission // PAL: 0x80540918..0x80540b14 @@ -2540,8 +2538,8 @@ CourseCache::~CourseCache() { } } // namespace System - -#ifdef NON_MATCHING // requires rodata to work + +#ifdef NON_MATCHING // requires rodata to work namespace System { void CourseCache::load(s32 courseId) { @@ -2631,23 +2629,17 @@ asm UNKNOWN_FUNCTION(unk_80541b58) { } #endif -// Symbol: unk_80541c18 -// PAL: 0x80541c18..0x80541c38 -MARK_BINARY_BLOB(unk_80541c18, 0x80541c18, 0x80541c38); -asm UNKNOWN_FUNCTION(unk_80541c18) { - // clang-format off - nofralloc; - lwz r0, 0x1c(r3); - mr r6, r4; - cmpwi r0, 2; - bnelr; - lwz r4, 0x20(r3); - mr r3, r6; - b loadOther__Q26System15MultiDvdArchiveFPQ26System15MultiDvdArchivePQ23EGG4Heap; - blr; - // clang-format on +namespace System { + +void CourseCache::loadOther(MultiDvdArchive* other, EGG::Heap* heap) { + if (mState != 2) + return; + + other->loadOther(mArchive, heap); } +} // namespace System + // Symbol: unk_80541c38 // PAL: 0x80541c38..0x80541c48 MARK_BINARY_BLOB(unk_80541c38, 0x80541c38, 0x80541c48); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 079f64b4d..6b9f4aab4 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -208,7 +208,8 @@ class CourseCache : EGG::Disposer { void load(u32 courseId); void loadOther(MultiDvdArchive* other, EGG::Heap* heap); -//private: // idk if rii prefers to befriend every class over public-ing everything + // private: // idk if rii prefers to befriend every class over public-ing + // everything void* mBuffer; EGG::ExpHeap* mHeap; s32 mCourseId; @@ -222,20 +223,23 @@ typedef enum { class ResourceManager { virtual ~ResourceManager(); + public: MultiDvdArchive** multiArchives1; MultiDvdArchive multiArchives2[12]; MultiDvdArchive MultiArchives3[12]; - DvdArchive dvdArhive[4]; + DvdArchive dvdArchive[4]; JobContext jobContexts[7]; EGG::TaskThread* taskThread; CourseCache courseCache; - char unk5ac_60b[0x60b-0x5ac]; + char unk5ac_60b[0x60b - 0x5ac]; - MultiDvdArchive* loadCourse(CourseId courseId, EGG::Heap* param_3, bool splitScreen); + MultiDvdArchive* loadCourse(CourseId courseId, EGG::Heap* param_3, + bool splitScreen); void process(); static void doLoadTask(void* jobContext); - void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, EGG::Heap* archiveHeap) ; + void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, + EGG::Heap* archiveHeap); }; } // namespace System diff --git a/source/rvl/os/osThread.h b/source/rvl/os/osThread.h index c7800f2c3..c0a46c16d 100644 --- a/source/rvl/os/osThread.h +++ b/source/rvl/os/osThread.h @@ -19,7 +19,8 @@ u32* const __OSBusClock = (u32*)0x800000F8; #define OS_TIMER_CLOCK (__OSBusClock >> 2) #define OSMillisecondsToTicks(msec) ((msec) * (OS_TIMER_CLOCK / 1000)) -#define OSSleepMilliseconds(msec) OSSleepTicks(OSMillisecondsToTicks((OSTime)msec)) +#define OSSleepMilliseconds(msec) \ + OSSleepTicks(OSMillisecondsToTicks((OSTime)msec)) typedef struct OSThread { char _00[0x304]; From 162db4b1e9ef87d481441112ac8b59a5da3c1923 Mon Sep 17 00:00:00 2001 From: Aiden Date: Mon, 20 Jun 2022 03:42:32 -0400 Subject: [PATCH 09/46] ResourceManager: createInstance --- pack/symbols.txt | 2 +- source/game/system/ResourceManager.cpp | 45 ++++++++------------------ source/game/system/ResourceManager.hpp | 17 ++++++++-- 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/pack/symbols.txt b/pack/symbols.txt index 8fa00fe8b..90649cf01 100644 --- a/pack/symbols.txt +++ b/pack/symbols.txt @@ -9961,7 +9961,7 @@ 0x8053fb98 unk_8053fb98 0x8053fc4c ResourceManager_createInstance 0x8053fc9c ResourceManager_destroyInstance -0x8053fcec ResourceManager_construct +0x8053fcec __ct__Q26System15ResourceManagerFv 0x8053fe68 __ct__Q26System20MenuCharacterManagerFv 0x8053fe94 unk_8053fe94 0x8053fed4 unk_8053fed4 diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 966f1d2f4..701c2df72 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -44,37 +44,18 @@ extern UNKNOWN_FUNCTION(getSlotForCourseId); extern UNKNOWN_FUNCTION(unk_805553b0); } -// Symbol: ResourceManager_createInstance -// PAL: 0x8053fc4c..0x8053fc9c -MARK_BINARY_BLOB(ResourceManager_createInstance, 0x8053fc4c, 0x8053fc9c); -asm UNKNOWN_FUNCTION(ResourceManager_createInstance) { - // clang-format off - nofralloc; - stwu r1, -0x10(r1); - mflr r0; - lis r3, 0; - stw r0, 0x14(r1); - lwz r0, 0(r3); - cmpwi r0, 0; - bne lbl_8053fc84; - li r3, 0x61c; - bl unk_805553b0; - cmpwi r3, 0; - beq lbl_8053fc7c; - bl ResourceManager_construct; -lbl_8053fc7c: - lis r4, 0; - stw r3, 0(r4); -lbl_8053fc84: - lwz r0, 0x14(r1); - lis r3, 0; - lwz r3, 0(r3); - mtlr r0; - addi r1, r1, 0x10; - blr; - // clang-format on +namespace System { + +ResourceManager* ResourceManager::createInstance() { + if (spInstance == nullptr) { + spInstance = new ResourceManager(); + } + + return spInstance; } +} // namespace System + // Symbol: ResourceManager_destroyInstance // PAL: 0x8053fc9c..0x8053fcec MARK_BINARY_BLOB(ResourceManager_destroyInstance, 0x8053fc9c, 0x8053fcec); @@ -105,10 +86,10 @@ asm UNKNOWN_FUNCTION(ResourceManager_destroyInstance) { // clang-format on } -// Symbol: ResourceManager_construct +// Symbol: __ct__Q26System15ResourceManagerFv // PAL: 0x8053fcec..0x8053fe68 -MARK_BINARY_BLOB(ResourceManager_construct, 0x8053fcec, 0x8053fe68); -asm UNKNOWN_FUNCTION(ResourceManager_construct) { +MARK_BINARY_BLOB(__ct__Q26System15ResourceManagerFv, 0x8053fcec, 0x8053fe68); +asm UNKNOWN_FUNCTION(__ct__Q26System15ResourceManagerFv) { // clang-format off nofralloc; stwu r1, -0x20(r1); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 6b9f4aab4..2fea805ca 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -19,7 +19,7 @@ UNKNOWN_FUNCTION(ResourceManager_createInstance); // PAL: 0x8053fc9c..0x8053fcec UNKNOWN_FUNCTION(ResourceManager_destroyInstance); // PAL: 0x8053fcec..0x8053fe68 -UNKNOWN_FUNCTION(ResourceManager_construct); +UNKNOWN_FUNCTION(__ct__Q26System15ResourceManagerFv); // PAL: 0x8053fe68..0x8053fe94 UNKNOWN_FUNCTION(__ct__Q26System20MenuCharacterManagerFv); // PAL: 0x8053fe94..0x8053fed4 @@ -225,6 +225,13 @@ class ResourceManager { virtual ~ResourceManager(); public: + static ResourceManager* createInstance(); + static void destroyInstance(); + + static ResourceManager* spInstance; + + ResourceManager(); + MultiDvdArchive** multiArchives1; MultiDvdArchive multiArchives2[12]; MultiDvdArchive MultiArchives3[12]; @@ -232,7 +239,13 @@ class ResourceManager { JobContext jobContexts[7]; EGG::TaskThread* taskThread; CourseCache courseCache; - char unk5ac_60b[0x60b - 0x5ac]; + MenuCharacterManager menuCharacterManager[4]; + bool isGlobeLoadingBusy; + bool _60d; // these variables don't have names yet, but are used + EGG::ExpHeap* _610; + EGG::Heap* _614; + bool _618; + bool _619; MultiDvdArchive* loadCourse(CourseId courseId, EGG::Heap* param_3, bool splitScreen); From 7d21487b44979393f3d107669137031b037e6d66 Mon Sep 17 00:00:00 2001 From: vabold Date: Mon, 20 Jun 2022 20:30:14 -0400 Subject: [PATCH 10/46] ResourceManager: loadMission, loadCompetition Co-Authored-By: riidefi <34194588+riidefi@users.noreply.github.com> Co-Authored-By: em-eight <107326447+em-eight@users.noreply.github.com> --- pack/rel_objects.txt | 2 +- pack/rel_slices.csv | 2 +- pack/symbols.txt | 4 +- source/game/system/MultiDvdArchive.hpp | 21 +++-- source/game/system/ResourceManager.cpp | 115 +++++++++++++++++++++++-- source/game/system/ResourceManager.hpp | 10 ++- 6 files changed, 131 insertions(+), 23 deletions(-) diff --git a/pack/rel_objects.txt b/pack/rel_objects.txt index 8ad8a310c..9fa8fba43 100644 --- a/pack/rel_objects.txt +++ b/pack/rel_objects.txt @@ -21,7 +21,7 @@ out/rel/rodata_8088fe28_80890ad8.o out/rel/data_808b31e8_808b3bf8.o out/ResourceManager.o out/rel/text_80542878_80555464.o -out/rel/rodata_80890b20_80891370.o +out/rel/rodata_80890b97_80891370.o out/rel/data_808b3c2c_808b42e0.o out/Random.o out/rel/text_8055572c_80590128.o diff --git a/pack/rel_slices.csv b/pack/rel_slices.csv index 55eb42817..71bb645ac 100644 --- a/pack/rel_slices.csv +++ b/pack/rel_slices.csv @@ -4,7 +4,7 @@ enabled,name,textStart,textEnd,ctorsStart,ctorsEnd,dtorsStart,dtorsEnd,rodataSta 1,source/game/system/GhostFile.cpp,0x8051c088,0x8051d4d4,,,,,,,0x808b2d38,0x808b2d50,, 1,source/game/system/LocalizedArchive.cpp,0x8052a098,0x8052a538,,,,,0x8088fdc0,0x8088fe00,0x808b3188,0x808b31d8,, 1,source/game/system/MultiDvdArchive.cpp,0x8052a538,0x8052ae5c,,,,,0x8088fe00,0x8088fe28,0x808b31d8,0x808b31e8,, -1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890AD8,0x80890B20,0x808B3BF8,0x808b3c2c,, +1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890AD8,0x80890B97,0x808B3BF8,0x808b3c2c,, 1,source/game/util/Random.cpp,0x80555464,0x8055572c,,,,,0x80891370,0x80891380,0x808b42e0,0x808b42ec,, 1,source/game/kart/KartComponent.cpp,0x80590128,0x805901d0,,,,,,,,,0x809c1900,0x809c1910 1,source/game/ui/ControlGroup.cpp,0x805c23e4,0x805c2c18,,,,,,,,,, diff --git a/pack/symbols.txt b/pack/symbols.txt index 90649cf01..6217bd66a 100644 --- a/pack/symbols.txt +++ b/pack/symbols.txt @@ -9978,8 +9978,8 @@ 0x80540558 unk_80540558 0x80540680 ResourceManager_loadUI 0x80540760 loadCourse__Q26System15ResourceManagerF8CourseIdPQ23EGG4Heapb -0x80540918 ResourceManager_loadMission -0x80540b14 ResourceManager_loadCompetition +0x80540918 loadMission__Q26System15ResourceManagerF8CourseIdlPQ23EGG4Heapb +0x80540b14 loadCompetition__Q26System15ResourceManagerF8CourseIdPvUlPQ23EGG4HeapUc 0x80540cfc unk_80540cfc 0x80540e3c unk_80540e3c 0x80540f90 unk_80540f90 diff --git a/source/game/system/MultiDvdArchive.hpp b/source/game/system/MultiDvdArchive.hpp index 8b83a8226..0c5c66cd8 100644 --- a/source/game/system/MultiDvdArchive.hpp +++ b/source/game/system/MultiDvdArchive.hpp @@ -22,7 +22,19 @@ enum ResourceChannelID { RES_CHAN_NUM, }; +enum EResourceKind { + RES_KIND_FILE_DOUBLE_FORMAT, // 0 %s%s Supports prefix + RES_KIND_FILE_SINGLE_FORMAT, // 1 %s + RES_KIND_BUFFER, // 2 + RES_KIND_3, // unseen + RES_KIND_4, // _Dif loader + + RES_KIND_DEFAULT = RES_KIND_FILE_DOUBLE_FORMAT, +}; + class MultiDvdArchive { + friend class ResourceManager; + public: MultiDvdArchive(u16 archiveCount = 1); virtual ~MultiDvdArchive(); @@ -46,15 +58,6 @@ class MultiDvdArchive { void* getEarliestResBufInMem(); void* getFarthestResBufInMem(); - enum EResourceKind { - RES_KIND_FILE_DOUBLE_FORMAT, // 0 %s%s Supports prefix - RES_KIND_FILE_SINGLE_FORMAT, // 1 %s - RES_KIND_BUFFER, // 2 - RES_KIND_3, // unseen - RES_KIND_4, // _Dif loader - - RES_KIND_DEFAULT = RES_KIND_FILE_DOUBLE_FORMAT, - }; enum { SUFFIX_SIZE = 128, }; diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index b02b1d4f0..c65dad86f 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -4,6 +4,8 @@ #include #include +#pragma dont_reuse_strings on + extern RKScene* scenePtr; extern const char* EarthResourceListing; @@ -831,10 +833,12 @@ MultiDvdArchive* ResourceManager::loadCourse(CourseId courseId, } // namespace System -// Symbol: ResourceManager_loadMission +// Symbol: loadMission__Q26System15ResourceManagerF8CourseIdlPQ23EGG4Heapb // PAL: 0x80540918..0x80540b14 -MARK_BINARY_BLOB(ResourceManager_loadMission, 0x80540918, 0x80540b14); -asm UNKNOWN_FUNCTION(ResourceManager_loadMission) { +/*MARK_BINARY_BLOB(loadMission__Q26System15ResourceManagerF8CourseIdlPQ23EGG4Heapb, +0x80540918, 0x80540b14); asm +UNKNOWN_FUNCTION(loadMission__Q26System15ResourceManagerF8CourseIdlPQ23EGG4Heapb) +{ // clang-format off nofralloc; stwu r1, -0x120(r1); @@ -892,7 +896,8 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadMission) { bne cr6, lbl_80540af8; lwz r4, 0x5a8(r28); mr r5, r30; - bl loadOther__Q26System15MultiDvdArchiveFPQ26System15MultiDvdArchivePQ23EGG4Heap; + bl +loadOther__Q26System15MultiDvdArchiveFPQ26System15MultiDvdArchivePQ23EGG4Heap; b lbl_80540af8; lbl_805409f8: cmpwi r31, 0; @@ -970,12 +975,58 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadMission) { addi r1, r1, 0x120; blr; // clang-format on +}*/ + +namespace System { + +MultiDvdArchive* ResourceManager::loadMission(CourseId courseId, s32 missionNum, + EGG::Heap* param_3, + bool splitScreen) { + char missionPath[128]; + char courseName[128]; + + if (!this->multiArchives1[1]->isLoaded()) { + this->multiArchives1[1]->init(); + snprintf(missionPath, sizeof(missionPath), "Race/MissionRun/mr%02d.szs", + missionNum); + MultiDvdArchive* archive = this->multiArchives1[1]; + if (archive->archiveCount > 1) { + archive->kinds[1] = RES_KIND_FILE_SINGLE_FORMAT; + strncpy(archive->suffixes[1], missionPath, sizeof(missionPath)); + } + + if (!splitScreen && this->courseCache.mState == 2 && + courseId == this->courseCache.mCourseId) { + MultiDvdArchive* m = this->multiArchives1[1]; + if (this->courseCache.mState == 2) + m->loadOther(this->courseCache.mArchive, param_3); + } else { + if (splitScreen) { + snprintf(courseName, sizeof(courseName), "Race/Course/%s_d", + COURSE_NAMES[courseId]); + if (!this->multiArchives1[1]->exists(courseName)) { + splitScreen = false; + } + } + if (!splitScreen) { + snprintf(courseName, sizeof(courseName), "Race/Course/%s", + COURSE_NAMES[courseId]); + } + requestLoad(3, this->multiArchives1[1], courseName, param_3); + } + } + return this->multiArchives1[1]; } -// Symbol: ResourceManager_loadCompetition -// PAL: 0x80540b14..0x80540cfc -MARK_BINARY_BLOB(ResourceManager_loadCompetition, 0x80540b14, 0x80540cfc); -asm UNKNOWN_FUNCTION(ResourceManager_loadCompetition) { +} // namespace System + +// Symbol: +// loadCompetition__Q26System15ResourceManagerF8CourseIdPvUlPQ23EGG4HeapUc PAL: +// 0x80540b14..0x80540cfc +/*MARK_BINARY_BLOB(loadCompetition__Q26System15ResourceManagerF8CourseIdPvUlPQ23EGG4HeapUc, +0x80540b14, 0x80540cfc); asm +UNKNOWN_FUNCTION(loadCompetition__Q26System15ResourceManagerF8CourseIdPvUlPQ23EGG4HeapUc) +{ // clang-format off nofralloc; stwu r1, -0x140(r1); @@ -1107,8 +1158,56 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadCompetition) { addi r1, r1, 0x140; blr; // clang-format on +}*/ + +namespace System { + +MultiDvdArchive* ResourceManager::loadCompetition(CourseId courseId, + void* fileStart, u32 fileSize, + EGG::Heap* heap, u8 param6) { + char competitionPath[128]; + char courseName[128]; + + if (!this->multiArchives1[1]->isLoaded()) { + this->multiArchives1[1]->init(); + + u16 objCount = 1; + u16 var4 = 0; + for (u8 i = 0; i < 0x10; i++) { + if ((param6 & (1 << i)) != 0) { + snprintf(competitionPath, sizeof(competitionPath), + "Race/Competition/CommonObj/CommonObj%02d.szs", i + 1); + MultiDvdArchive* archive = this->multiArchives1[1]; + + if (objCount < archive->archiveCount) { + archive->kinds[objCount] = RES_KIND_FILE_SINGLE_FORMAT; + strncpy(archive->suffixes[objCount], competitionPath, + sizeof(competitionPath)); + } + + objCount++; + var4++; + if (var4 > 1) + break; + } + } + + if (objCount < this->multiArchives1[1]->archiveCount) { + MultiDvdArchive* archive = this->multiArchives1[1]; + archive->kinds[objCount] = RES_KIND_BUFFER; + archive->fileStarts[objCount] = fileStart; + archive->fileSizes[objCount] = fileSize; + } + + snprintf(courseName, sizeof(courseName), "Race/Course/%s", + COURSE_NAMES[courseId]); + requestLoad(4, this->multiArchives1[1], courseName, heap); + } + return this->multiArchives1[1]; } +} // namespace System + // Symbol: unk_80540cfc // PAL: 0x80540cfc..0x80540e3c MARK_BINARY_BLOB(unk_80540cfc, 0x80540cfc, 0x80540e3c); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index cd5825438..adff12ba0 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -52,9 +52,11 @@ UNKNOWN_FUNCTION(ResourceManager_loadUI); // PAL: 0x80540760..0x80540918 UNKNOWN_FUNCTION(ResourceManager_loadCourse); // PAL: 0x80540918..0x80540b14 -UNKNOWN_FUNCTION(ResourceManager_loadMission); +UNKNOWN_FUNCTION( + loadMission__Q26System15ResourceManagerF8CourseIdlPQ23EGG4Heapb); // PAL: 0x80540b14..0x80540cfc -UNKNOWN_FUNCTION(ResourceManager_loadCompetition); +UNKNOWN_FUNCTION( + loadCompetition__Q26System15ResourceManagerF8CourseIdPvUlPQ23EGG4HeapUc); // PAL: 0x80540cfc..0x80540e3c UNKNOWN_FUNCTION(unk_80540cfc); // PAL: 0x80540e3c..0x80540f90 @@ -260,6 +262,10 @@ class ResourceManager { MultiDvdArchive* loadCourse(CourseId courseId, EGG::Heap* param_3, bool splitScreen); + MultiDvdArchive* loadMission(CourseId courseId, s32 missionNum, + EGG::Heap* param_3, bool splitScreen); + MultiDvdArchive* loadCompetition(CourseId courseId, void* fileStart, + u32 fileSize, EGG::Heap* heap, u8 unk6); void process(); static void doLoadTask(void* jobContext); void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, From 379eff928b0a62f1b345530706fc283cc1e5bd68 Mon Sep 17 00:00:00 2001 From: vabold Date: Mon, 20 Jun 2022 21:20:10 -0400 Subject: [PATCH 11/46] ResourceManager: doLoadTask --- source/game/system/ResourceManager.cpp | 526 +------------------------ 1 file changed, 18 insertions(+), 508 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index c65dad86f..8b9315c94 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -87,46 +87,26 @@ System::ResourceManager::~ResourceManager() { taskThread = nullptr; } -} // namespace System +void ResourceManager::doLoadTask(void* jobContext) { + JobContext* context = &spInstance->jobContexts[(s32)jobContext]; -// Symbol: unk_80540038 -// PAL: 0x80540038..0x805400a0 -MARK_BINARY_BLOB(unk_80540038, 0x80540038, 0x805400a0); -asm UNKNOWN_FUNCTION(unk_80540038) { - // clang-format off - nofralloc; - lis r4, 0; - cmpwi r3, 6; - mulli r0, r3, 0x54; - lwz r4, 0(r4); - add r6, r4, r0; - beq lbl_8054005c; - cmpwi r3, 5; - beq lbl_80540070; - b lbl_80540088; -lbl_8054005c: - lwz r3, 0x33c(r6); - addi r4, r6, 0x344; - lwz r5, 0x340(r6); - lwz r6, 0x384(r6); - b load__Q26System10DvdArchiveFPCcUlPQ23EGG4Heap; -lbl_80540070: - lwz r3, 0x338(r6); - addi r4, r6, 0x344; - lwz r5, 0x384(r6); - li r7, 0; - lwz r6, 0x388(r6); - b load__Q26System15MultiDvdArchiveFPCcPQ23EGG4HeapPQ23EGG4Heapi; -lbl_80540088: - lwz r3, 0x338(r6); - addi r4, r6, 0x344; - lwz r5, 0x384(r6); - li r6, 0; - li r7, 0; - b load__Q26System15MultiDvdArchiveFPCcPQ23EGG4HeapPQ23EGG4Heapi; - // clang-format on + switch ((s32)jobContext) { + case 6: + context->archive->load(context->filename, context->_08, + context->archiveHeap); + return; + case 5: + context->multiArchive->load(context->filename, context->archiveHeap, + context->fileHeap, 0); + return; + default: + context->multiArchive->load(context->filename, context->archiveHeap, 0, 0); + return; + } } +} // namespace System + // Symbol: process__Q26System15ResourceManagerFv // PAL: 0x805400a0..0x805401ec MARK_BINARY_BLOB(process__Q26System15ResourceManagerFv, 0x805400a0, 0x805401ec); @@ -253,61 +233,6 @@ asm UNKNOWN_FUNCTION(unk_805401fc) { // clang-format on } -// Symbol: unk_8054020c -// PAL: 0x8054020c..0x805402c0 -/*MARK_BINARY_BLOB(unk_8054020c, 0x8054020c, 0x805402c0); -asm UNKNOWN_FUNCTION(unk_8054020c) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - stw r0, 0x24(r1); - stmw r27, 0xc(r1); - mr r28, r4; - mulli r31, r28, 0x54; - mr r27, r3; - mr r29, r5; - mr r4, r6; - add r3, r3, r31; - mr r30, r7; - stw r5, 0x338(r3); - addi r3, r3, 0x344; - li r5, 0x40; - bl unk_805553b0; - add r3, r27, r31; - lis r4, 0; - stw r30, 0x384(r3); - mr r5, r28; - addi r4, r4, 0; - li r6, 0; - lwz r3, 0x584(r27); - bl unk_805553b0; - mr r3, r27; - bl process__Q26System15ResourceManagerFv; - mr r3, r29; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_805402ac; - lis r4, 0x8000; - lis r3, 0x1062; - lwz r0, 0xf8(r4); - addi r4, r3, 0x4dd3; - li r3, 0; - srwi r0, r0, 2; - mulhwu r4, r4, r0; - srwi r0, r4, 6; - rlwinm r4, r4, 0x1e, 2, 0x1b; - rlwimi r3, r0, 4, 0x1c, 0x1f; - bl unk_805553b0; -lbl_805402ac: - lmw r27, 0xc(r1); - lwz r0, 0x24(r1); - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on -}*/ - namespace System { void ResourceManager::requestLoad(s32 idx, MultiDvdArchive* m, const char* p, EGG::Heap* archiveHeap) { @@ -676,131 +601,8 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadUI) { // clang-format on } -// Symbol: ResourceManager_loadCourse -// PAL: 0x80540760..0x80540918 -/*MARK_BINARY_BLOB(ResourceManager_loadCourse, 0x80540760, 0x80540918); -asm UNKNOWN_FUNCTION(ResourceManager_loadCourse) { - // clang-format off - nofralloc; - stwu r1, -0xa0(r1); - mflr r0; - stw r0, 0xa4(r1); - stw r31, 0x9c(r1); - mr r31, r3; - stw r30, 0x98(r1); - mr r30, r6; - stw r29, 0x94(r1); - mr r29, r5; - stw r28, 0x90(r1); - mr r28, r4; - lwz r7, 4(r3); - lwz r3, 4(r7); - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_805408f0; - lwz r3, 4(r31); - lwz r3, 4(r3); - lwz r12, 0(r3); - lwz r12, 0xc(r12); - mtctr r12; - bctrl; - cmpwi r30, 0; - bne lbl_805407f4; - lwz r0, 0x5a4(r31); - cmpwi cr6, r0, 2; - bne cr6, lbl_805407f4; - lwz r0, 0x5a0(r31); - cmpw r28, r0; - bne lbl_805407f4; - lwz r3, 4(r31); - lwz r3, 4(r3); - bne cr6, lbl_805408f0; - lwz r4, 0x5a8(r31); - mr r5, r29; - bl -loadOther__Q26System15MultiDvdArchiveFPQ26System15MultiDvdArchivePQ23EGG4Heap; - b lbl_805408f0; -lbl_805407f4: - cmpwi r30, 0; - beq lbl_80540840; - lis r4, 0; - lis r5, 0; - slwi r0, r28, 2; - addi r3, r1, 8; - addi r4, r4, 0; - addi r5, r5, 0; - lwzx r6, r4, r0; - li r4, 0x80; - crclr 6; - bl unk_805553b0; - lwz r3, 4(r31); - addi r4, r1, 8; - lwz r3, 4(r3); - bl exists__Q26System15MultiDvdArchiveFPCc; - cmpwi r3, 0; - bne lbl_80540840; - li r30, 0; -lbl_80540840: - cmpwi r30, 0; - bne lbl_80540874; - lis r4, 0; - lis r5, 0; - slwi r0, r28, 2; - addi r3, r1, 8; - addi r4, r4, 0; - addi r5, r5, 0; - lwzx r6, r4, r0; - addi r5, r5, 0x11; - li r4, 0x80; - crclr 6; - bl unk_805553b0; -lbl_80540874: - lwz r6, 4(r31); - addi r3, r31, 0x3ec; - addi r4, r1, 8; - li r5, 0x40; - lwz r30, 4(r6); - stw r30, 0x3e0(r31); - bl unk_805553b0; - lis r4, 0; - stw r29, 0x42c(r31); - lwz r3, 0x584(r31); - addi r4, r4, 0; - li r5, 2; - li r6, 0; - bl unk_805553b0; - mr r3, r31; - bl process__Q26System15ResourceManagerFv; - mr r3, r30; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_805408f0; - lis r4, 0x8000; - lis r3, 0x1062; - lwz r0, 0xf8(r4); - addi r4, r3, 0x4dd3; - li r3, 0; - srwi r0, r0, 2; - mulhwu r4, r4, r0; - srwi r0, r4, 6; - rlwinm r4, r4, 0x1e, 2, 0x1b; - rlwimi r3, r0, 4, 0x1c, 0x1f; - bl unk_805553b0; -lbl_805408f0: - lwz r3, 4(r31); - lwz r31, 0x9c(r1); - lwz r30, 0x98(r1); - lwz r29, 0x94(r1); - lwz r28, 0x90(r1); - lwz r0, 0xa4(r1); - lwz r3, 4(r3); - mtlr r0; - addi r1, r1, 0xa0; - blr; - // clang-format on -}*/ - namespace System { + MultiDvdArchive* ResourceManager::loadCourse(CourseId courseId, EGG::Heap* param_3, bool splitScreen) { @@ -831,154 +633,6 @@ MultiDvdArchive* ResourceManager::loadCourse(CourseId courseId, return this->multiArchives1[1]; } -} // namespace System - -// Symbol: loadMission__Q26System15ResourceManagerF8CourseIdlPQ23EGG4Heapb -// PAL: 0x80540918..0x80540b14 -/*MARK_BINARY_BLOB(loadMission__Q26System15ResourceManagerF8CourseIdlPQ23EGG4Heapb, -0x80540918, 0x80540b14); asm -UNKNOWN_FUNCTION(loadMission__Q26System15ResourceManagerF8CourseIdlPQ23EGG4Heapb) -{ - // clang-format off - nofralloc; - stwu r1, -0x120(r1); - mflr r0; - stw r0, 0x124(r1); - stmw r27, 0x10c(r1); - mr r28, r3; - mr r29, r4; - mr r27, r5; - mr r30, r6; - mr r31, r7; - lwz r8, 4(r3); - lwz r3, 4(r8); - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_80540af8; - lwz r3, 4(r28); - lwz r3, 4(r3); - lwz r12, 0(r3); - lwz r12, 0xc(r12); - mtctr r12; - bctrl; - lis r4, 0; - mr r6, r27; - addi r4, r4, 0; - addi r3, r1, 0x88; - addi r5, r4, 0x20; - li r4, 0x80; - crclr 6; - bl unk_805553b0; - lwz r3, 4(r28); - lwz r6, 4(r3); - lhz r0, 8(r6); - cmplwi r0, 1; - ble lbl_805409bc; - lwz r3, 0x18(r6); - li r0, 1; - addi r4, r1, 0x88; - li r5, 0x80; - stw r0, 4(r3); - lwz r3, 0x10(r6); - lwz r3, 4(r3); - bl unk_805553b0; -lbl_805409bc: - cmpwi r31, 0; - bne lbl_805409f8; - lwz r0, 0x5a4(r28); - cmpwi cr6, r0, 2; - bne cr6, lbl_805409f8; - lwz r0, 0x5a0(r28); - cmpw r29, r0; - bne lbl_805409f8; - lwz r3, 4(r28); - lwz r3, 4(r3); - bne cr6, lbl_80540af8; - lwz r4, 0x5a8(r28); - mr r5, r30; - bl -loadOther__Q26System15MultiDvdArchiveFPQ26System15MultiDvdArchivePQ23EGG4Heap; - b lbl_80540af8; -lbl_805409f8: - cmpwi r31, 0; - beq lbl_80540a48; - lis r4, 0; - lis r5, 0; - slwi r0, r29, 2; - addi r3, r1, 8; - addi r4, r4, 0; - addi r5, r5, 0; - lwzx r6, r4, r0; - addi r5, r5, 0x3b; - li r4, 0x80; - crclr 6; - bl unk_805553b0; - lwz r3, 4(r28); - addi r4, r1, 8; - lwz r3, 4(r3); - bl exists__Q26System15MultiDvdArchiveFPCc; - cmpwi r3, 0; - bne lbl_80540a48; - li r31, 0; -lbl_80540a48: - cmpwi r31, 0; - bne lbl_80540a7c; - lis r4, 0; - lis r5, 0; - slwi r0, r29, 2; - addi r3, r1, 8; - addi r4, r4, 0; - addi r5, r5, 0; - lwzx r6, r4, r0; - addi r5, r5, 0x4c; - li r4, 0x80; - crclr 6; - bl unk_805553b0; -lbl_80540a7c: - lwz r6, 4(r28); - addi r3, r28, 0x440; - addi r4, r1, 8; - li r5, 0x40; - lwz r29, 4(r6); - stw r29, 0x434(r28); - bl unk_805553b0; - lis r4, 0; - stw r30, 0x480(r28); - lwz r3, 0x584(r28); - addi r4, r4, 0; - li r5, 3; - li r6, 0; - bl unk_805553b0; - mr r3, r28; - bl process__Q26System15ResourceManagerFv; - mr r3, r29; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_80540af8; - lis r4, 0x8000; - lis r3, 0x1062; - lwz r0, 0xf8(r4); - addi r4, r3, 0x4dd3; - li r3, 0; - srwi r0, r0, 2; - mulhwu r4, r4, r0; - srwi r0, r4, 6; - rlwinm r4, r4, 0x1e, 2, 0x1b; - rlwimi r3, r0, 4, 0x1c, 0x1f; - bl unk_805553b0; -lbl_80540af8: - lwz r3, 4(r28); - lmw r27, 0x10c(r1); - lwz r0, 0x124(r1); - lwz r3, 4(r3); - mtlr r0; - addi r1, r1, 0x120; - blr; - // clang-format on -}*/ - -namespace System { - MultiDvdArchive* ResourceManager::loadMission(CourseId courseId, s32 missionNum, EGG::Heap* param_3, bool splitScreen) { @@ -1018,150 +672,6 @@ MultiDvdArchive* ResourceManager::loadMission(CourseId courseId, s32 missionNum, return this->multiArchives1[1]; } -} // namespace System - -// Symbol: -// loadCompetition__Q26System15ResourceManagerF8CourseIdPvUlPQ23EGG4HeapUc PAL: -// 0x80540b14..0x80540cfc -/*MARK_BINARY_BLOB(loadCompetition__Q26System15ResourceManagerF8CourseIdPvUlPQ23EGG4HeapUc, -0x80540b14, 0x80540cfc); asm -UNKNOWN_FUNCTION(loadCompetition__Q26System15ResourceManagerF8CourseIdPvUlPQ23EGG4HeapUc) -{ - // clang-format off - nofralloc; - stwu r1, -0x140(r1); - mflr r0; - stw r0, 0x144(r1); - stmw r21, 0x114(r1); - mr r23, r3; - mr r24, r4; - mr r25, r5; - mr r26, r6; - mr r27, r7; - mr r28, r8; - lwz r9, 4(r3); - lwz r3, 4(r9); - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_80540ce0; - lwz r3, 4(r23); - lwz r3, 4(r3); - lwz r12, 0(r3); - lwz r12, 0xc(r12); - mtctr r12; - bctrl; - lis r21, 0; - li r31, 1; - addi r21, r21, 0; - li r30, 0; - li r29, 0; - li r22, 1; -lbl_80540b80: - clrlwi r4, r29, 0x18; - slw r0, r22, r4; - and. r0, r28, r0; - beq lbl_80540bf4; - addi r6, r4, 1; - addi r3, r1, 0x88; - addi r5, r21, 0x5b; - li r4, 0x80; - crclr 6; - bl unk_805553b0; - lwz r4, 4(r23); - clrlwi r3, r31, 0x10; - lwz r6, 4(r4); - lhz r0, 8(r6); - cmplw r3, r0; - bge lbl_80540be0; - lwz r3, 0x18(r6); - rlwinm r0, r31, 2, 0xe, 0x1d; - addi r4, r1, 0x88; - li r5, 0x80; - stwx r22, r3, r0; - lwz r3, 0x10(r6); - lwzx r3, r3, r0; - bl unk_805553b0; -lbl_80540be0: - addi r30, r30, 1; - addi r31, r31, 1; - clrlwi r0, r30, 0x10; - cmplwi r0, 1; - bgt lbl_80540c00; -lbl_80540bf4: - addi r29, r29, 1; - cmplwi r29, 0x10; - blt lbl_80540b80; -lbl_80540c00: - lwz r4, 4(r23); - clrlwi r3, r31, 0x10; - lwz r4, 4(r4); - lhz r0, 8(r4); - cmplw r3, r0; - bge lbl_80540c38; - lwz r3, 0x18(r4); - rlwinm r5, r31, 2, 0xe, 0x1d; - li r0, 2; - stwx r0, r3, r5; - lwz r3, 0x14(r4); - stwx r25, r3, r5; - lwz r3, 0xc(r4); - stwx r26, r3, r5; -lbl_80540c38: - lis r4, 0; - lis r5, 0; - slwi r0, r24, 2; - addi r3, r1, 8; - addi r4, r4, 0; - addi r5, r5, 0; - lwzx r6, r4, r0; - addi r5, r5, 0x88; - li r4, 0x80; - crclr 6; - bl unk_805553b0; - lwz r6, 4(r23); - addi r3, r23, 0x494; - addi r4, r1, 8; - li r5, 0x40; - lwz r21, 4(r6); - stw r21, 0x488(r23); - bl unk_805553b0; - lis r4, 0; - stw r27, 0x4d4(r23); - lwz r3, 0x584(r23); - addi r4, r4, 0; - li r5, 4; - li r6, 0; - bl unk_805553b0; - mr r3, r23; - bl process__Q26System15ResourceManagerFv; - mr r3, r21; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_80540ce0; - lis r4, 0x8000; - lis r3, 0x1062; - lwz r0, 0xf8(r4); - addi r4, r3, 0x4dd3; - li r3, 0; - srwi r0, r0, 2; - mulhwu r4, r4, r0; - srwi r0, r4, 6; - rlwinm r4, r4, 0x1e, 2, 0x1b; - rlwimi r3, r0, 4, 0x1c, 0x1f; - bl unk_805553b0; -lbl_80540ce0: - lwz r3, 4(r23); - lmw r21, 0x114(r1); - lwz r0, 0x144(r1); - lwz r3, 4(r3); - mtlr r0; - addi r1, r1, 0x140; - blr; - // clang-format on -}*/ - -namespace System { - MultiDvdArchive* ResourceManager::loadCompetition(CourseId courseId, void* fileStart, u32 fileSize, EGG::Heap* heap, u8 param6) { From c615fbbdc73e55ce768515b5605d60ba061cabad Mon Sep 17 00:00:00 2001 From: vabold Date: Mon, 20 Jun 2022 21:36:52 -0400 Subject: [PATCH 12/46] Dummy: unused vtable calls --- source/game/system/ResourceManager.cpp | 40 +++++++++++--------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 8b9315c94..d45b66040 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -109,6 +109,7 @@ void ResourceManager::doLoadTask(void* jobContext) { // Symbol: process__Q26System15ResourceManagerFv // PAL: 0x805400a0..0x805401ec +// Notes: we cannot decompile this without DiscCheckThread MARK_BINARY_BLOB(process__Q26System15ResourceManagerFv, 0x805400a0, 0x805401ec); asm UNKNOWN_FUNCTION(process__Q26System15ResourceManagerFv) { // clang-format off @@ -207,31 +208,21 @@ asm UNKNOWN_FUNCTION(process__Q26System15ResourceManagerFv) { // clang-format on } -// Symbol: unk_805401ec -// PAL: 0x805401ec..0x805401fc -MARK_BINARY_BLOB(unk_805401ec, 0x805401ec, 0x805401fc); -asm UNKNOWN_FUNCTION(unk_805401ec) { - // clang-format off - nofralloc; - lwz r12, 0(r3); - lwz r12, 0x14(r12); - mtctr r12; - bctr; - // clang-format on -} +class Dummy { +public: + Dummy(); + virtual void _08() = 0; + virtual void _0c() = 0; + virtual void _10() = 0; + virtual void _14() = 0; + virtual void _18() = 0; + virtual void _1C() = 0; +}; -// Symbol: unk_805401fc -// PAL: 0x805401fc..0x8054020c -MARK_BINARY_BLOB(unk_805401fc, 0x805401fc, 0x8054020c); -asm UNKNOWN_FUNCTION(unk_805401fc) { - // clang-format off - nofralloc; - lwz r12, 0(r3); - lwz r12, 0x1c(r12); - mtctr r12; - bctr; - // clang-format on -} +// no clue what class this is supposed to be so here are two dummy functions +void _unk_call14(Dummy* dummy) { dummy->_14(); } + +void _unk_call1c(Dummy* dummy) { dummy->_1C(); } namespace System { void ResourceManager::requestLoad(s32 idx, MultiDvdArchive* m, const char* p, @@ -247,6 +238,7 @@ void ResourceManager::requestLoad(s32 idx, MultiDvdArchive* m, const char* p, OSSleepMilliseconds(16); } } + } // namespace System // Symbol: unk_805402c0 From 58edd967bc466ebd74609d844788a3f402c1a5f7 Mon Sep 17 00:00:00 2001 From: vabold Date: Mon, 20 Jun 2022 21:44:41 -0400 Subject: [PATCH 13/46] ResourceManager: requestLoad (DvdArchive) --- source/game/system/ResourceManager.cpp | 80 ++++++-------------------- source/game/system/ResourceManager.hpp | 2 + 2 files changed, 19 insertions(+), 63 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index d45b66040..36a2a258e 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -241,71 +241,25 @@ void ResourceManager::requestLoad(s32 idx, MultiDvdArchive* m, const char* p, } // namespace System -// Symbol: unk_805402c0 -// PAL: 0x805402c0..0x80540394 -MARK_BINARY_BLOB(unk_805402c0, 0x805402c0, 0x80540394); -asm UNKNOWN_FUNCTION(unk_805402c0) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - stw r0, 0x24(r1); - stmw r26, 8(r1); - mr r27, r4; - mulli r31, r27, 0x54; - mr r26, r3; - mr r28, r5; - mr r4, r6; - add r3, r3, r31; - mr r29, r7; - mr r30, r8; - stw r5, 0x33c(r3); - addi r3, r3, 0x344; - li r5, 0x40; - bl unk_805553b0; - add r3, r26, r31; - lis r4, 0; - stw r30, 0x384(r3); - mr r5, r27; - addi r4, r4, 0; - li r6, 0; - stw r29, 0x340(r3); - lwz r3, 0x584(r26); - bl unk_805553b0; - mr r3, r26; - bl process__Q26System15ResourceManagerFv; - lwz r0, 0x20(r28); - li r3, 0; - cmpwi r0, 4; - beq lbl_80540348; - lwz r0, 0x20(r28); - cmpwi r0, 5; - bne lbl_8054034c; -lbl_80540348: - li r3, 1; -lbl_8054034c: - cmpwi r3, 0; - bne lbl_80540380; - lis r4, 0x8000; - lis r3, 0x1062; - lwz r0, 0xf8(r4); - addi r4, r3, 0x4dd3; - li r3, 0; - srwi r0, r0, 2; - mulhwu r4, r4, r0; - srwi r0, r4, 6; - rlwinm r4, r4, 0x1e, 2, 0x1b; - rlwimi r3, r0, 4, 0x1c, 0x1f; - bl unk_805553b0; -lbl_80540380: - lmw r26, 8(r1); - lwz r0, 0x24(r1); - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on +namespace System { +void ResourceManager::requestLoad(s32 idx, DvdArchive* archive, + const char* filename, u32 unk, + EGG::Heap* archiveHeap) { + this->jobContexts[idx].archive = archive; + strncpy(this->jobContexts[idx].filename, filename, 0x40); + this->jobContexts[idx].archiveHeap = archiveHeap; + this->jobContexts[idx]._08 = unk; + + this->taskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); + this->process(); + + if (!archive->isLoaded()) { + OSSleepMilliseconds(16); + } } +} // namespace System + // Symbol: unk_80540394 // PAL: 0x80540394..0x80540450 MARK_BINARY_BLOB(unk_80540394, 0x80540394, 0x80540450); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index adff12ba0..73fc6dcc4 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -270,6 +270,8 @@ class ResourceManager { static void doLoadTask(void* jobContext); void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, EGG::Heap* archiveHeap); + void requestLoad(s32 idx, DvdArchive* archive, const char* filename, u32 unk, + EGG::Heap* archiveHeap); }; } // namespace System From a39d821db97cbaa83db623f444f44bed00617af9 Mon Sep 17 00:00:00 2001 From: vabold Date: Mon, 20 Jun 2022 21:47:48 -0400 Subject: [PATCH 14/46] ResourceManager: requestLoad (MultiDvdArchive, fileHeap) --- source/game/system/ResourceManager.cpp | 74 ++++++-------------------- source/game/system/ResourceManager.hpp | 2 + 2 files changed, 17 insertions(+), 59 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 36a2a258e..f8eec0678 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -239,9 +239,6 @@ void ResourceManager::requestLoad(s32 idx, MultiDvdArchive* m, const char* p, } } -} // namespace System - -namespace System { void ResourceManager::requestLoad(s32 idx, DvdArchive* archive, const char* filename, u32 unk, EGG::Heap* archiveHeap) { @@ -258,65 +255,24 @@ void ResourceManager::requestLoad(s32 idx, DvdArchive* archive, } } -} // namespace System +void ResourceManager::requestLoad(s32 idx, MultiDvdArchive* archive, + const char* filename, EGG::Heap* archiveHeap, + EGG::Heap* fileHeap) { + this->jobContexts[idx].multiArchive = archive; + strncpy(this->jobContexts[idx].filename, filename, 0x40); + this->jobContexts[idx].archiveHeap = archiveHeap; + this->jobContexts[idx].fileHeap = fileHeap; -// Symbol: unk_80540394 -// PAL: 0x80540394..0x80540450 -MARK_BINARY_BLOB(unk_80540394, 0x80540394, 0x80540450); -asm UNKNOWN_FUNCTION(unk_80540394) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - stw r0, 0x24(r1); - stmw r26, 8(r1); - mr r27, r4; - mulli r31, r27, 0x54; - mr r26, r3; - mr r28, r5; - mr r4, r6; - add r3, r3, r31; - mr r29, r7; - mr r30, r8; - stw r5, 0x338(r3); - addi r3, r3, 0x344; - li r5, 0x40; - bl unk_805553b0; - add r3, r26, r31; - lis r4, 0; - stw r29, 0x384(r3); - mr r5, r27; - addi r4, r4, 0; - li r6, 0; - stw r30, 0x388(r3); - lwz r3, 0x584(r26); - bl unk_805553b0; - mr r3, r26; - bl process__Q26System15ResourceManagerFv; - mr r3, r28; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_8054043c; - lis r4, 0x8000; - lis r3, 0x1062; - lwz r0, 0xf8(r4); - addi r4, r3, 0x4dd3; - li r3, 0; - srwi r0, r0, 2; - mulhwu r4, r4, r0; - srwi r0, r4, 6; - rlwinm r4, r4, 0x1e, 2, 0x1b; - rlwimi r3, r0, 4, 0x1c, 0x1f; - bl unk_805553b0; -lbl_8054043c: - lmw r26, 8(r1); - lwz r0, 0x24(r1); - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on + this->taskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); + this->process(); + + if (!archive->isLoaded()) { + OSSleepMilliseconds(16); + } } +} // namespace System + // Symbol: ResourceManager_load // PAL: 0x80540450..0x80540558 MARK_BINARY_BLOB(ResourceManager_load, 0x80540450, 0x80540558); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 73fc6dcc4..66ed4f47c 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -272,6 +272,8 @@ class ResourceManager { EGG::Heap* archiveHeap); void requestLoad(s32 idx, DvdArchive* archive, const char* filename, u32 unk, EGG::Heap* archiveHeap); + void requestLoad(s32 idx, MultiDvdArchive* archive, const char* filename, + EGG::Heap* archiveHeap, EGG::Heap* fileHeap); }; } // namespace System From 5326b9266edfccc78504c6619cd905e79ff0e17a Mon Sep 17 00:00:00 2001 From: vabold Date: Mon, 20 Jun 2022 22:39:21 -0400 Subject: [PATCH 15/46] ResourceManager: load / rodata --- pack/rel_objects.txt | 4 +- pack/rel_slices.csv | 2 +- source/game/system/ResourceManager.cpp | 265 +++++++++++++++++-------- source/game/system/ResourceManager.hpp | 2 + 4 files changed, 192 insertions(+), 81 deletions(-) diff --git a/pack/rel_objects.txt b/pack/rel_objects.txt index 9fa8fba43..3a84f5aa2 100644 --- a/pack/rel_objects.txt +++ b/pack/rel_objects.txt @@ -17,8 +17,8 @@ out/rel/data_808b2d50_808b3188.o out/LocalizedArchive.o out/MultiDvdArchive.o out/rel/text_8052ae5c_8053fc4c.o -out/rel/rodata_8088fe28_80890ad8.o -out/rel/data_808b31e8_808b3bf8.o +out/rel/rodata_8088fe28_80890490.o +out/rel/data_808b31e8_808b3960.o out/ResourceManager.o out/rel/text_80542878_80555464.o out/rel/rodata_80890b97_80891370.o diff --git a/pack/rel_slices.csv b/pack/rel_slices.csv index 71bb645ac..0b00f0015 100644 --- a/pack/rel_slices.csv +++ b/pack/rel_slices.csv @@ -4,7 +4,7 @@ enabled,name,textStart,textEnd,ctorsStart,ctorsEnd,dtorsStart,dtorsEnd,rodataSta 1,source/game/system/GhostFile.cpp,0x8051c088,0x8051d4d4,,,,,,,0x808b2d38,0x808b2d50,, 1,source/game/system/LocalizedArchive.cpp,0x8052a098,0x8052a538,,,,,0x8088fdc0,0x8088fe00,0x808b3188,0x808b31d8,, 1,source/game/system/MultiDvdArchive.cpp,0x8052a538,0x8052ae5c,,,,,0x8088fe00,0x8088fe28,0x808b31d8,0x808b31e8,, -1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890AD8,0x80890B97,0x808B3BF8,0x808b3c2c,, +1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890B97,0x808b3960,0x808b3c2c,, 1,source/game/util/Random.cpp,0x80555464,0x8055572c,,,,,0x80891370,0x80891380,0x808b42e0,0x808b42ec,, 1,source/game/kart/KartComponent.cpp,0x80590128,0x805901d0,,,,,,,,,0x809c1900,0x809c1910 1,source/game/ui/ControlGroup.cpp,0x805c23e4,0x805c2c18,,,,,,,,,, diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index f8eec0678..11292ac90 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -5,14 +5,186 @@ #include #pragma dont_reuse_strings on +#pragma legacy_struct_alignment off extern RKScene* scenePtr; extern const char* EarthResourceListing; -const char* EarthResourceListing = "/earth.brres.LZ"; // .rodata -extern const char* COURSE_NAMES[]; +const char* RESOURCES[] = {"/Race/Common", + "", + "", + "/Scene/UI/Font", + "/Scene/Model/Earth", + "/Scene/Model/MiiBody", + "/Scene/Model/Driver", + "/Demo/Award", + "/Scene/Model/BackModel"}; + +const char* COURSE_NAMES[] = { + "castle_course", // 808B3984 + "farm_course", // 808B3988 + "kinoko_course", // 808B398C + "volcano_course", // 808B3990 + "factory_course", // 808B3994 + "shopping_course", // 808B3998 + "boardcross_course", // 808B399C + "truck_course", // 808B39A0 + "beginner_course", // 808B39A4 + "senior_course", // 808B39A8 + "ridgehighway_course", // 808B39AC + "treehouse_course", // 808B39B0 + "koopa_course", // 808B39B4 + "rainbow_course", // 808B39B8 + "desert_course", // 808B39BC + "water_course", // 808B39C0 + "old_peach_gc", // 808B39C4 + "old_mario_gc", // 808B39C8 + "old_waluigi_gc", // 808B39CC + "old_donkey_gc", // 808B39D0 + "old_falls_ds", // 808B39D4 + "old_desert_ds", // 808B39D8 + "old_garden_ds", // 808B39DC + "old_town_ds", // 808B39E0 + "old_mario_sfc", // 808B39E4 + "old_obake_sfc", // 808B39E8 + "old_mario_64", // 808B39EC + "old_sherbet_64", // 808B39F0 + "old_koopa_64", // 808B39F4 + "old_donkey_64", // 808B39F8 + "old_koopa_gba", // 808B39FC + "old_heyho_gba", // 808B3A00 + "venice_battle", // 808B3A04 + "block_battle", // 808B3A08 + "casino_battle", // 808B3A0C + "skate_battle", // 808B3A10 + "sand_battle", // 808B3A14 + "old_CookieLand_gc", // 808B3A18 + "old_House_ds", // 808B3A1C + "old_battle4_sfc", // 808B3A20 + "old_battle3_gba", // 808B3A24 + "old_matenro_64", // 808B3A28 + nullptr, // 808B3A2C + nullptr, // 808B3A30 + nullptr, // 808B3A34 + nullptr, // 808B3A38 + nullptr, // 808B3A3C + nullptr, // 808B3A40 + nullptr, // 808B3A44 + nullptr, // 808B3A48 + nullptr, // 808B3A4C + nullptr, // 808B3A50 + nullptr, // 808B3A54 + nullptr, // 808B3A58 + "ring_mission", // 808B3A5C + "winningrun_demo", // 808B3A60 + "loser_demo", // 808B3A64 + "draw_dmeo", // 808B3A68 + "ending_demo", // 808B3A6C + nullptr, // 808B3A70 + nullptr, // 808B3A74 + nullptr, // 808B3A78 + nullptr, // 808B3A7C + nullptr, // 808B3A80 + nullptr, // 808B3A84 + nullptr, // 808B3A88 + nullptr // 808B3A8C +}; + +const char* CHARACTER_NAMES[] = { + "mr", // 808B3A90 + "bpc", // 808B3A94 + "wl", // 808B3A98 + "kp", // 808B3A9C + "bds", // 808B3AA0 + "ka", // 808B3AA4 + "bmr", // 808B3AA8 + "lg", // 808B3AAC + "ko", // 808B3AB0 + "dk", // 808B3AB4 + "ys", // 808B3AB8 + "wr", // 808B3ABC + "blg", // 808B3AC0 + "kk", // 808B3AC4 + "nk", // 808B3AC8 + "ds", // 808B3ACC + "pc", // 808B3AD0 + "ca", // 808B3AD4 + "dd", // 808B3AD8 + "kt", // 808B3ADC + "jr", // 808B3AE0 + "bk", // 808B3AE4 + "fk", // 808B3AE8 + "rs", // 808B3AEC + "sa_mii_m", // 808B3AF0 + "sa_mii_f", // 808B3AF4 + "sb_mii_m", // 808B3AF8 + "sb_mii_f", // 808B3AFC + "sc_mii_m", // 808B3B00 + "sc_mii_f", // 808B3B04 + "ma_mii_m", // 808B3B08 + "ma_mii_f", // 808B3B0C + "mb_mii_m", // 808B3B10 + "mb_mii_f", // 808B3B14 + "mc_mii_m", // 808B3B18 + "mc_mii_f", // 808B3B1C + "la_mii_m", // 808B3B20 + "la_mii_f", // 808B3B24 + "lb_mii_m", // 808B3B28 + "lb_mii_f", // 808B3B2C + "lc_mii_m", // 808B3B30 + "lc_mii_f", // 808B3B34 + "m_mii", // 808B3B38 + "s_mii", // 808B3B3C + "l_mii", // 808B3B40 + "pc_menu", // 808B3B44 + "ds_menu", // 808B3B48 + "rs_menu" // 808B3B4C +}; + +const char* VEHICLE_NAMES[] = { + "sdf_kart", // 808B3B50 + "mdf_kart", // 808B3B54 + "ldf_kart", // 808B3B58 + "sa_kart", // 808B3B5C + "ma_kart", // 808B3B60 + "la_kart", // 808B3B64 + "sb_kart", // 808B3B68 + "mb_kart", // 808B3B6C + "lb_kart", // 808B3B70 + "sc_kart", // 808B3B74 + "mc_kart", // 808B3B78 + "lc_kart", // 808B3B7C + "sd_kart", // 808B3B80 + "md_kart", // 808B3B84 + "ld_kart", // 808B3B88 + "se_kart", // 808B3B8C + "me_kart", // 808B3B90 + "le_kart", // 808B3B94 + "sdf_bike", // 808B3B98 + "mdf_bike", // 808B3B9C + "ldf_bike", // 808B3BA0 + "sa_bike", // 808B3BA4 + "ma_bike", // 808B3BA8 + "la_bike", // 808B3BAC + "sb_bike", // 808B3BB0 + "mb_bike", // 808B3BB4 + "lb_bike", // 808B3BB8 + "sc_bike", // 808B3BBC + "mc_bike", // 808B3BC0 + "lc_bike", // 808B3BC4 + "sd_bike", // 808B3BC8 + "md_bike", // 808B3BCC + "ld_bike", // 808B3BD0 + "se_bike", // 808B3BD4 + "me_bike", // 808B3BD8 + "le_bike", // 808B3BDC +}; +const char* TEAM_SUFFIXES[] = {"_red", "_blue", ""}; +const char* LOD_RES_SUFFIXES[] = {"", "_2", "_4"}; + +const char* EarthResourceListing = "/earth.brres.LZ"; extern const int arr_80890AE8[]; const int arr_80890AE8[] = {819200, 921600, 36, 48, 14, 51200}; @@ -271,85 +443,22 @@ void ResourceManager::requestLoad(s32 idx, MultiDvdArchive* archive, } } -} // namespace System +MultiDvdArchive* ResourceManager::load(ResourceChannelID channelId, + EGG::Heap* archiveHeap, + const char* filename) { + if (!filename) { + filename = RESOURCES[channelId]; + } -// Symbol: ResourceManager_load -// PAL: 0x80540450..0x80540558 -MARK_BINARY_BLOB(ResourceManager_load, 0x80540450, 0x80540558); -asm UNKNOWN_FUNCTION(ResourceManager_load) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - cmpwi r6, 0; - stw r0, 0x24(r1); - stw r31, 0x1c(r1); - mr r31, r3; - stw r30, 0x18(r1); - mr r30, r6; - stw r29, 0x14(r1); - stw r28, 0x10(r1); - mr r28, r5; - bne lbl_80540490; - lis r5, 0; - slwi r0, r4, 2; - addi r5, r5, 0; - lwzx r30, r5, r0; -lbl_80540490: - lwz r3, 4(r3); - slwi r29, r4, 2; - lwzx r3, r3, r29; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_80540530; - lbz r0, 0(r30); - extsb. r0, r0; - beq lbl_80540530; - lwz r6, 4(r31); - mr r4, r30; - addi r3, r31, 0x344; - li r5, 0x40; - lwzx r30, r6, r29; - stw r30, 0x338(r31); - bl unk_805553b0; - lis r4, 0; - stw r28, 0x384(r31); - lwz r3, 0x584(r31); - addi r4, r4, 0; - li r5, 0; - li r6, 0; - bl unk_805553b0; - mr r3, r31; - bl process__Q26System15ResourceManagerFv; - mr r3, r30; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_80540530; - lis r4, 0x8000; - lis r3, 0x1062; - lwz r0, 0xf8(r4); - addi r4, r3, 0x4dd3; - li r3, 0; - srwi r0, r0, 2; - mulhwu r4, r4, r0; - srwi r0, r4, 6; - rlwinm r4, r4, 0x1e, 2, 0x1b; - rlwimi r3, r0, 4, 0x1c, 0x1f; - bl unk_805553b0; -lbl_80540530: - lwz r3, 4(r31); - lwz r31, 0x1c(r1); - lwzx r3, r3, r29; - lwz r30, 0x18(r1); - lwz r29, 0x14(r1); - lwz r28, 0x10(r1); - lwz r0, 0x24(r1); - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on + if (!multiArchives1[channelId]->isLoaded() && filename[0]) { + requestLoad(0, this->multiArchives1[channelId], filename, archiveHeap); + } + + return this->multiArchives1[channelId]; } +} // namespace System + // Symbol: unk_80540558 // PAL: 0x80540558..0x80540680 MARK_BINARY_BLOB(unk_80540558, 0x80540558, 0x80540680); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 66ed4f47c..4b7290b4a 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -260,6 +260,8 @@ class ResourceManager { isGlobeLoadingBusy = false; } + MultiDvdArchive* load(ResourceChannelID channelId, EGG::Heap* archiveHeap, + const char* filename); MultiDvdArchive* loadCourse(CourseId courseId, EGG::Heap* param_3, bool splitScreen); MultiDvdArchive* loadMission(CourseId courseId, s32 missionNum, From c9e784fb48b3e84e3aa8fd712ac7a08994a3895e Mon Sep 17 00:00:00 2001 From: vabold Date: Mon, 20 Jun 2022 22:46:15 -0400 Subject: [PATCH 16/46] ResourceManager: rodata formatting --- source/game/system/ResourceManager.cpp | 257 +++++++++---------------- 1 file changed, 96 insertions(+), 161 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 11292ac90..df8adcafd 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -12,174 +12,109 @@ extern RKScene* scenePtr; extern const char* EarthResourceListing; // .rodata -const char* RESOURCES[] = {"/Race/Common", - "", - "", - "/Scene/UI/Font", - "/Scene/Model/Earth", - "/Scene/Model/MiiBody", - "/Scene/Model/Driver", - "/Demo/Award", - "/Scene/Model/BackModel"}; +const char* RESOURCES[] = { + // clang-format off + "/Race/Common", + "", + "", + "/Scene/UI/Font", + "/Scene/Model/Earth", + "/Scene/Model/MiiBody", + "/Scene/Model/Driver", + "/Demo/Award", + "/Scene/Model/BackModel" + // clang-format on +}; const char* COURSE_NAMES[] = { - "castle_course", // 808B3984 - "farm_course", // 808B3988 - "kinoko_course", // 808B398C - "volcano_course", // 808B3990 - "factory_course", // 808B3994 - "shopping_course", // 808B3998 - "boardcross_course", // 808B399C - "truck_course", // 808B39A0 - "beginner_course", // 808B39A4 - "senior_course", // 808B39A8 - "ridgehighway_course", // 808B39AC - "treehouse_course", // 808B39B0 - "koopa_course", // 808B39B4 - "rainbow_course", // 808B39B8 - "desert_course", // 808B39BC - "water_course", // 808B39C0 - "old_peach_gc", // 808B39C4 - "old_mario_gc", // 808B39C8 - "old_waluigi_gc", // 808B39CC - "old_donkey_gc", // 808B39D0 - "old_falls_ds", // 808B39D4 - "old_desert_ds", // 808B39D8 - "old_garden_ds", // 808B39DC - "old_town_ds", // 808B39E0 - "old_mario_sfc", // 808B39E4 - "old_obake_sfc", // 808B39E8 - "old_mario_64", // 808B39EC - "old_sherbet_64", // 808B39F0 - "old_koopa_64", // 808B39F4 - "old_donkey_64", // 808B39F8 - "old_koopa_gba", // 808B39FC - "old_heyho_gba", // 808B3A00 - "venice_battle", // 808B3A04 - "block_battle", // 808B3A08 - "casino_battle", // 808B3A0C - "skate_battle", // 808B3A10 - "sand_battle", // 808B3A14 - "old_CookieLand_gc", // 808B3A18 - "old_House_ds", // 808B3A1C - "old_battle4_sfc", // 808B3A20 - "old_battle3_gba", // 808B3A24 - "old_matenro_64", // 808B3A28 - nullptr, // 808B3A2C - nullptr, // 808B3A30 - nullptr, // 808B3A34 - nullptr, // 808B3A38 - nullptr, // 808B3A3C - nullptr, // 808B3A40 - nullptr, // 808B3A44 - nullptr, // 808B3A48 - nullptr, // 808B3A4C - nullptr, // 808B3A50 - nullptr, // 808B3A54 - nullptr, // 808B3A58 - "ring_mission", // 808B3A5C - "winningrun_demo", // 808B3A60 - "loser_demo", // 808B3A64 - "draw_dmeo", // 808B3A68 - "ending_demo", // 808B3A6C - nullptr, // 808B3A70 - nullptr, // 808B3A74 - nullptr, // 808B3A78 - nullptr, // 808B3A7C - nullptr, // 808B3A80 - nullptr, // 808B3A84 - nullptr, // 808B3A88 - nullptr // 808B3A8C + // clang-format off + "castle_course", + "farm_course", + "kinoko_course", + "volcano_course", + "factory_course", + "shopping_course", + "boardcross_course", + "truck_course", + "beginner_course", + "senior_course", + "ridgehighway_course", + "treehouse_course", + "koopa_course", + "rainbow_course", + "desert_course", + "water_course", + "old_peach_gc", + "old_mario_gc", + "old_waluigi_gc", + "old_donkey_gc", + "old_falls_ds", + "old_desert_ds", + "old_garden_ds", + "old_town_ds", + "old_mario_sfc", + "old_obake_sfc", + "old_mario_64", + "old_sherbet_64", + "old_koopa_64", + "old_donkey_64", + "old_koopa_gba", + "old_heyho_gba", + "venice_battle", + "block_battle", + "casino_battle", + "skate_battle", + "sand_battle", + "old_CookieLand_gc", + "old_House_ds", + "old_battle4_sfc", + "old_battle3_gba", + "old_matenro_64", + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + "ring_mission", + "winningrun_demo", + "loser_demo", + "draw_dmeo", + "ending_demo", + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr + // clang-format on }; const char* CHARACTER_NAMES[] = { - "mr", // 808B3A90 - "bpc", // 808B3A94 - "wl", // 808B3A98 - "kp", // 808B3A9C - "bds", // 808B3AA0 - "ka", // 808B3AA4 - "bmr", // 808B3AA8 - "lg", // 808B3AAC - "ko", // 808B3AB0 - "dk", // 808B3AB4 - "ys", // 808B3AB8 - "wr", // 808B3ABC - "blg", // 808B3AC0 - "kk", // 808B3AC4 - "nk", // 808B3AC8 - "ds", // 808B3ACC - "pc", // 808B3AD0 - "ca", // 808B3AD4 - "dd", // 808B3AD8 - "kt", // 808B3ADC - "jr", // 808B3AE0 - "bk", // 808B3AE4 - "fk", // 808B3AE8 - "rs", // 808B3AEC - "sa_mii_m", // 808B3AF0 - "sa_mii_f", // 808B3AF4 - "sb_mii_m", // 808B3AF8 - "sb_mii_f", // 808B3AFC - "sc_mii_m", // 808B3B00 - "sc_mii_f", // 808B3B04 - "ma_mii_m", // 808B3B08 - "ma_mii_f", // 808B3B0C - "mb_mii_m", // 808B3B10 - "mb_mii_f", // 808B3B14 - "mc_mii_m", // 808B3B18 - "mc_mii_f", // 808B3B1C - "la_mii_m", // 808B3B20 - "la_mii_f", // 808B3B24 - "lb_mii_m", // 808B3B28 - "lb_mii_f", // 808B3B2C - "lc_mii_m", // 808B3B30 - "lc_mii_f", // 808B3B34 - "m_mii", // 808B3B38 - "s_mii", // 808B3B3C - "l_mii", // 808B3B40 - "pc_menu", // 808B3B44 - "ds_menu", // 808B3B48 - "rs_menu" // 808B3B4C -}; + "mr", "bpc", "wl", "kp", "bds", "ka", + "bmr", "lg", "ko", "dk", "ys", "wr", + "blg", "kk", "nk", "ds", "pc", "ca", + "dd", "kt", "jr", "bk", "fk", "rs", + "sa_mii_m", "sa_mii_f", "sb_mii_m", "sb_mii_f", "sc_mii_m", "sc_mii_f", + "ma_mii_m", "ma_mii_f", "mb_mii_m", "mb_mii_f", "mc_mii_m", "mc_mii_f", + "la_mii_m", "la_mii_f", "lb_mii_m", "lb_mii_f", "lc_mii_m", "lc_mii_f", + "m_mii", "s_mii", "l_mii", "pc_menu", "ds_menu", "rs_menu"}; const char* VEHICLE_NAMES[] = { - "sdf_kart", // 808B3B50 - "mdf_kart", // 808B3B54 - "ldf_kart", // 808B3B58 - "sa_kart", // 808B3B5C - "ma_kart", // 808B3B60 - "la_kart", // 808B3B64 - "sb_kart", // 808B3B68 - "mb_kart", // 808B3B6C - "lb_kart", // 808B3B70 - "sc_kart", // 808B3B74 - "mc_kart", // 808B3B78 - "lc_kart", // 808B3B7C - "sd_kart", // 808B3B80 - "md_kart", // 808B3B84 - "ld_kart", // 808B3B88 - "se_kart", // 808B3B8C - "me_kart", // 808B3B90 - "le_kart", // 808B3B94 - "sdf_bike", // 808B3B98 - "mdf_bike", // 808B3B9C - "ldf_bike", // 808B3BA0 - "sa_bike", // 808B3BA4 - "ma_bike", // 808B3BA8 - "la_bike", // 808B3BAC - "sb_bike", // 808B3BB0 - "mb_bike", // 808B3BB4 - "lb_bike", // 808B3BB8 - "sc_bike", // 808B3BBC - "mc_bike", // 808B3BC0 - "lc_bike", // 808B3BC4 - "sd_bike", // 808B3BC8 - "md_bike", // 808B3BCC - "ld_bike", // 808B3BD0 - "se_bike", // 808B3BD4 - "me_bike", // 808B3BD8 - "le_bike", // 808B3BDC + "sdf_kart", "mdf_kart", "ldf_kart", "sa_kart", "ma_kart", "la_kart", + "sb_kart", "mb_kart", "lb_kart", "sc_kart", "mc_kart", "lc_kart", + "sd_kart", "md_kart", "ld_kart", "se_kart", "me_kart", "le_kart", + "sdf_bike", "mdf_bike", "ldf_bike", "sa_bike", "ma_bike", "la_bike", + "sb_bike", "mb_bike", "lb_bike", "sc_bike", "mc_bike", "lc_bike", + "sd_bike", "md_bike", "ld_bike", "se_bike", "me_bike", "le_bike", }; const char* TEAM_SUFFIXES[] = {"_red", "_blue", ""}; const char* LOD_RES_SUFFIXES[] = {"", "_2", "_4"}; From 1090ae566f8290cb0ad8857ce8dd899e041a933d Mon Sep 17 00:00:00 2001 From: Theodoros Tyrovouzis Date: Sat, 25 Jun 2022 23:31:27 +0300 Subject: [PATCH 17/46] A couple of more functions --- pack/rel_objects.txt | 2 +- pack/rel_slices.csv | 2 +- pack/symbols.txt | 8 +- source/game/system/DvdArchive.hpp | 1 + source/game/system/ResourceManager.cpp | 398 +++++-------------------- source/game/system/ResourceManager.hpp | 59 +++- 6 files changed, 127 insertions(+), 343 deletions(-) diff --git a/pack/rel_objects.txt b/pack/rel_objects.txt index 3a84f5aa2..cc6961629 100644 --- a/pack/rel_objects.txt +++ b/pack/rel_objects.txt @@ -21,7 +21,7 @@ out/rel/rodata_8088fe28_80890490.o out/rel/data_808b31e8_808b3960.o out/ResourceManager.o out/rel/text_80542878_80555464.o -out/rel/rodata_80890b97_80891370.o +out/rel/rodata_80890bd3_80891370.o out/rel/data_808b3c2c_808b42e0.o out/Random.o out/rel/text_8055572c_80590128.o diff --git a/pack/rel_slices.csv b/pack/rel_slices.csv index 0b00f0015..db9f70eda 100644 --- a/pack/rel_slices.csv +++ b/pack/rel_slices.csv @@ -4,7 +4,7 @@ enabled,name,textStart,textEnd,ctorsStart,ctorsEnd,dtorsStart,dtorsEnd,rodataSta 1,source/game/system/GhostFile.cpp,0x8051c088,0x8051d4d4,,,,,,,0x808b2d38,0x808b2d50,, 1,source/game/system/LocalizedArchive.cpp,0x8052a098,0x8052a538,,,,,0x8088fdc0,0x8088fe00,0x808b3188,0x808b31d8,, 1,source/game/system/MultiDvdArchive.cpp,0x8052a538,0x8052ae5c,,,,,0x8088fe00,0x8088fe28,0x808b31d8,0x808b31e8,, -1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890B97,0x808b3960,0x808b3c2c,, +1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890BD3,0x808b3960,0x808b3c2c,, 1,source/game/util/Random.cpp,0x80555464,0x8055572c,,,,,0x80891370,0x80891380,0x808b42e0,0x808b42ec,, 1,source/game/kart/KartComponent.cpp,0x80590128,0x805901d0,,,,,,,,,0x809c1900,0x809c1910 1,source/game/ui/ControlGroup.cpp,0x805c23e4,0x805c2c18,,,,,,,,,, diff --git a/pack/symbols.txt b/pack/symbols.txt index 6217bd66a..567307947 100644 --- a/pack/symbols.txt +++ b/pack/symbols.txt @@ -9980,7 +9980,7 @@ 0x80540760 loadCourse__Q26System15ResourceManagerF8CourseIdPQ23EGG4Heapb 0x80540918 loadMission__Q26System15ResourceManagerF8CourseIdlPQ23EGG4Heapb 0x80540b14 loadCompetition__Q26System15ResourceManagerF8CourseIdPvUlPQ23EGG4HeapUc -0x80540cfc unk_80540cfc +0x80540cfc loadKartFromArchive__Q26System15ResourceManagerFPQ26System15MultiDvdArchiveUl6KartId11CharacterId10BattleTeam8PlayModePQ23EGG4HeapPQ23EGG4Heap 0x80540e3c unk_80540e3c 0x80540f90 unk_80540f90 0x805410e4 unk_805410e4 @@ -9999,7 +9999,7 @@ 0x805415c4 unk_805415c4 0x805415d4 unk_805415d4 0x805415e4 unk_805415e4 -0x80541614 unk_80541614 +0x80541614 getArchiveStart__Q26System15ResourceManagerFQ26System17ResourceChannelIdUl 0x8054169c unk_8054169c 0x80541738 unk_80541738 0x80541794 ResourceManager_getMenuArchiveCount @@ -10007,8 +10007,8 @@ 0x80541878 ResourceManager_attachLayoutDir 0x80541998 ResourceManager_preloadCourseTask 0x805419ac ResourceManager_preloadCourseAsync -0x805419c8 unk_805419c8 -0x805419ec unk_805419ec +0x805419c8 getCharacterName__6SystemF11CharacterId +0x805419ec getKartName__6SystemF11CharacterId 0x80541a10 unk_80541a10 0x80541a70 unk_80541a70 0x80541ac4 unk_80541ac4 diff --git a/source/game/system/DvdArchive.hpp b/source/game/system/DvdArchive.hpp index 36e2a1d29..b9fb858ed 100644 --- a/source/game/system/DvdArchive.hpp +++ b/source/game/system/DvdArchive.hpp @@ -16,6 +16,7 @@ enum ArchiveState { class DvdArchive { friend class MultiDvdArchive; + friend class ResourceManager; public: DvdArchive(); diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index df8adcafd..58007ab2b 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -97,6 +97,7 @@ const char* COURSE_NAMES[] = { nullptr // clang-format on }; +const s32 COURSE_NAMES_SIZE = sizeof(COURSE_NAMES)/sizeof(COURSE_NAMES[0]); const char* CHARACTER_NAMES[] = { "mr", "bpc", "wl", "kp", "bds", "ka", @@ -108,6 +109,8 @@ const char* CHARACTER_NAMES[] = { "la_mii_m", "la_mii_f", "lb_mii_m", "lb_mii_f", "lc_mii_m", "lc_mii_f", "m_mii", "s_mii", "l_mii", "pc_menu", "ds_menu", "rs_menu"}; +const s32 CHAR_NAMES_SIZE = sizeof(CHARACTER_NAMES)/sizeof(CHARACTER_NAMES[0]); + const char* VEHICLE_NAMES[] = { "sdf_kart", "mdf_kart", "ldf_kart", "sa_kart", "ma_kart", "la_kart", "sb_kart", "mb_kart", "lb_kart", "sc_kart", "mc_kart", "lc_kart", @@ -116,6 +119,8 @@ const char* VEHICLE_NAMES[] = { "sb_bike", "mb_bike", "lb_bike", "sc_bike", "mc_bike", "lc_bike", "sd_bike", "md_bike", "ld_bike", "se_bike", "me_bike", "le_bike", }; +const s32 VEHICLE_NAMES_SIZE = sizeof(VEHICLE_NAMES)/sizeof(VEHICLE_NAMES[0]); + const char* TEAM_SUFFIXES[] = {"_red", "_blue", ""}; const char* LOD_RES_SUFFIXES[] = {"", "_2", "_4"}; @@ -664,300 +669,51 @@ MultiDvdArchive* ResourceManager::loadCompetition(CourseId courseId, } // namespace System -// Symbol: unk_80540cfc -// PAL: 0x80540cfc..0x80540e3c -MARK_BINARY_BLOB(unk_80540cfc, 0x80540cfc, 0x80540e3c); -asm UNKNOWN_FUNCTION(unk_80540cfc) { - // clang-format off - nofralloc; - stwu r1, -0xa0(r1); - mflr r0; - lis r11, 0; - cmpwi r7, 0x30; - stw r0, 0xa4(r1); - addi r11, r11, 0; - stw r31, 0x9c(r1); - mr r31, r4; - stw r30, 0x98(r1); - lwz r30, 0xa8(r1); - stw r29, 0x94(r1); - mr r29, r10; - stw r28, 0x90(r1); - mr r28, r3; - blt lbl_80540d40; - li r10, 0; - b lbl_80540d4c; -lbl_80540d40: - slwi r0, r7, 2; - addi r3, r11, 0x130; - lwzx r10, r3, r0; -lbl_80540d4c: - lis r4, 0; - cmpwi r6, 0x24; - addi r4, r4, 0; - addi r3, r1, 8; - addi r5, r4, 0x97; - li r4, 0x80; - blt lbl_80540d70; - li r6, 0; - b lbl_80540d7c; -lbl_80540d70: - slwi r0, r6, 2; - addi r6, r11, 0x1f0; - lwzx r6, r6, r0; -lbl_80540d7c: - slwi r0, r9, 2; - addi r9, r11, 0x28c; - slwi r8, r8, 2; - addi r7, r11, 0x280; - lwzx r7, r7, r8; - mr r8, r10; - lwzx r9, r9, r0; - crclr 6; - bl unk_805553b0; - stw r31, 0x4dc(r28); - addi r3, r28, 0x4e8; - addi r4, r1, 8; - li r5, 0x40; - bl unk_805553b0; - lis r4, 0; - stw r29, 0x528(r28); - lwz r3, 0x584(r28); - addi r4, r4, 0; - stw r30, 0x52c(r28); - li r5, 5; - li r6, 0; - bl unk_805553b0; - mr r3, r28; - bl process__Q26System15ResourceManagerFv; - mr r3, r31; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_80540e18; - lis r4, 0x8000; - lis r3, 0x1062; - lwz r0, 0xf8(r4); - addi r4, r3, 0x4dd3; - li r3, 0; - srwi r0, r0, 2; - mulhwu r4, r4, r0; - srwi r0, r4, 6; - rlwinm r4, r4, 0x1e, 2, 0x1b; - rlwimi r3, r0, 4, 0x1c, 0x1f; - bl unk_805553b0; -lbl_80540e18: - mr r3, r31; - lwz r31, 0x9c(r1); - lwz r30, 0x98(r1); - lwz r29, 0x94(r1); - lwz r28, 0x90(r1); - lwz r0, 0xa4(r1); - mtlr r0; - addi r1, r1, 0xa0; - blr; - // clang-format on -} -// Symbol: unk_80540e3c -// PAL: 0x80540e3c..0x80540f90 -MARK_BINARY_BLOB(unk_80540e3c, 0x80540e3c, 0x80540f90); -asm UNKNOWN_FUNCTION(unk_80540e3c) { - // clang-format off - nofralloc; - stwu r1, -0xb0(r1); - mflr r0; - stw r0, 0xb4(r1); - mulli r0, r4, 0x1c; - stmw r23, 0x8c(r1); - mr r30, r3; - add r3, r3, r0; - lis r29, 0; - addi r31, r3, 8; - mr r23, r5; - mr r24, r6; - mr r25, r7; - mr r26, r8; - mr r27, r9; - mr r28, r10; - mr r3, r31; - addi r29, r29, 0; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_80540f78; - cmpwi r24, 0x30; - blt lbl_80540e9c; - li r8, 0; - b lbl_80540ea8; -lbl_80540e9c: - slwi r0, r24, 2; - addi r3, r29, 0x130; - lwzx r8, r3, r0; -lbl_80540ea8: - lis r4, 0; - cmpwi r23, 0x24; - addi r4, r4, 0; - addi r3, r1, 8; - addi r5, r4, 0xab; - li r4, 0x80; - blt lbl_80540ecc; - li r6, 0; - b lbl_80540ed8; -lbl_80540ecc: - slwi r0, r23, 2; - addi r6, r29, 0x1f0; - lwzx r6, r6, r0; -lbl_80540ed8: - slwi r10, r25, 2; - addi r7, r29, 0x280; - slwi r0, r26, 2; - addi r9, r29, 0x28c; - lwzx r7, r7, r10; - lwzx r9, r9, r0; - crclr 6; - bl unk_805553b0; - stw r31, 0x4dc(r30); - addi r3, r30, 0x4e8; - addi r4, r1, 8; - li r5, 0x40; - bl unk_805553b0; - lis r4, 0; - stw r27, 0x528(r30); - lwz r3, 0x584(r30); - addi r4, r4, 0; - stw r28, 0x52c(r30); - li r5, 5; - li r6, 0; - bl unk_805553b0; - mr r3, r30; - bl process__Q26System15ResourceManagerFv; - mr r3, r31; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_80540f70; - lis r4, 0x8000; - lis r3, 0x1062; - lwz r0, 0xf8(r4); - addi r4, r3, 0x4dd3; - li r3, 0; - srwi r0, r0, 2; - mulhwu r4, r4, r0; - srwi r0, r4, 6; - rlwinm r4, r4, 0x1e, 2, 0x1b; - rlwimi r3, r0, 4, 0x1c, 0x1f; - bl unk_805553b0; -lbl_80540f70: - mr r3, r31; - b lbl_80540f7c; -lbl_80540f78: - mr r3, r31; -lbl_80540f7c: - lmw r23, 0x8c(r1); - lwz r0, 0xb4(r1); - mtlr r0; - addi r1, r1, 0xb0; - blr; - // clang-format on +namespace System { +MultiDvdArchive* ResourceManager::loadKartFromArchive(MultiDvdArchive* archive, u32 unu, VehicleId vehicleId, + CharacterId characterId, BattleTeam battleTeamId, PlayMode playMode, EGG::Heap* archiveHeap, EGG::Heap* fileHeap) { + char path[128]; + const char* driver = getCharacterName(characterId); + const char* kart = getVehicleName(vehicleId); + + snprintf(path, sizeof(path), "Race/Kart/%s%s-%s%s", kart, TEAM_SUFFIXES[battleTeamId], + driver, LOD_RES_SUFFIXES[playMode]); + requestLoadFile(5, archive, path, archiveHeap, fileHeap); + return archive; +} + +MultiDvdArchive* ResourceManager::loadKartFromArchive2(s32 archiveIdx, VehicleId vehicleId, + CharacterId characterId, BattleTeam battleTeamId, PlayMode playMode, EGG::Heap* archiveHeap, EGG::Heap* fileHeap) { + MultiDvdArchive* archive = &this->multiArchives2[archiveIdx]; + char path[128]; + + if (!archive->isLoaded()) { + const char* driver = getCharacterName(characterId); + const char* kart = getVehicleName(vehicleId); + snprintf(path, sizeof(path), "Race/Kart/%s%s-%s%s", kart, TEAM_SUFFIXES[battleTeamId], + driver, LOD_RES_SUFFIXES[playMode]); + requestLoadFile(5, archive, path, archiveHeap, fileHeap); + return archive; + } + return archive; } -// Symbol: unk_80540f90 -// PAL: 0x80540f90..0x805410e4 -MARK_BINARY_BLOB(unk_80540f90, 0x80540f90, 0x805410e4); -asm UNKNOWN_FUNCTION(unk_80540f90) { - // clang-format off - nofralloc; - stwu r1, -0xb0(r1); - mflr r0; - stw r0, 0xb4(r1); - mulli r0, r4, 0x1c; - stmw r23, 0x8c(r1); - mr r30, r3; - add r3, r3, r0; - lis r29, 0; - addi r31, r3, 0x158; - mr r23, r5; - mr r24, r6; - mr r25, r7; - mr r26, r8; - mr r27, r9; - mr r28, r10; - mr r3, r31; - addi r29, r29, 0; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_805410cc; - cmpwi r24, 0x30; - blt lbl_80540ff0; - li r8, 0; - b lbl_80540ffc; -lbl_80540ff0: - slwi r0, r24, 2; - addi r3, r29, 0x130; - lwzx r8, r3, r0; -lbl_80540ffc: - lis r4, 0; - cmpwi r23, 0x24; - addi r4, r4, 0; - addi r3, r1, 8; - addi r5, r4, 0xbf; - li r4, 0x80; - blt lbl_80541020; - li r6, 0; - b lbl_8054102c; -lbl_80541020: - slwi r0, r23, 2; - addi r6, r29, 0x1f0; - lwzx r6, r6, r0; -lbl_8054102c: - slwi r10, r25, 2; - addi r7, r29, 0x280; - slwi r0, r26, 2; - addi r9, r29, 0x28c; - lwzx r7, r7, r10; - lwzx r9, r9, r0; - crclr 6; - bl unk_805553b0; - stw r31, 0x4dc(r30); - addi r3, r30, 0x4e8; - addi r4, r1, 8; - li r5, 0x40; - bl unk_805553b0; - lis r4, 0; - stw r27, 0x528(r30); - lwz r3, 0x584(r30); - addi r4, r4, 0; - stw r28, 0x52c(r30); - li r5, 5; - li r6, 0; - bl unk_805553b0; - mr r3, r30; - bl process__Q26System15ResourceManagerFv; - mr r3, r31; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_805410c4; - lis r4, 0x8000; - lis r3, 0x1062; - lwz r0, 0xf8(r4); - addi r4, r3, 0x4dd3; - li r3, 0; - srwi r0, r0, 2; - mulhwu r4, r4, r0; - srwi r0, r4, 6; - rlwinm r4, r4, 0x1e, 2, 0x1b; - rlwimi r3, r0, 4, 0x1c, 0x1f; - bl unk_805553b0; -lbl_805410c4: - mr r3, r31; - b lbl_805410d0; -lbl_805410cc: - mr r3, r31; -lbl_805410d0: - lmw r23, 0x8c(r1); - lwz r0, 0xb4(r1); - mtlr r0; - addi r1, r1, 0xb0; - blr; - // clang-format on +MultiDvdArchive* ResourceManager::loadKartFromArchive3(s32 archiveIdx, VehicleId vehicleId, + CharacterId characterId, BattleTeam battleTeamId, PlayMode playMode, EGG::Heap* archiveHeap, EGG::Heap* fileHeap) { + MultiDvdArchive* archive = &this->multiArchives3[archiveIdx]; + char path[128]; + + if (!archive->isLoaded()) { + const char* driver = getCharacterName(characterId); + const char* kart = getVehicleName(vehicleId); + snprintf(path, sizeof(path), "Race/Kart/%s%s-%s%s", kart, TEAM_SUFFIXES[battleTeamId], + driver, LOD_RES_SUFFIXES[playMode]); + requestLoadFile(5, archive, path, archiveHeap, fileHeap); + return archive; + } + return archive; +} } // Symbol: unk_805410e4 @@ -1466,7 +1222,7 @@ asm UNKNOWN_FUNCTION(unk_805415e4) { // Symbol: unk_80541614 // PAL: 0x80541614..0x8054169c -MARK_BINARY_BLOB(unk_80541614, 0x80541614, 0x8054169c); +/*MARK_BINARY_BLOB(unk_80541614, 0x80541614, 0x8054169c); asm UNKNOWN_FUNCTION(unk_80541614) { // clang-format off nofralloc; @@ -1508,6 +1264,17 @@ asm UNKNOWN_FUNCTION(unk_80541614) { addi r1, r1, 0x20; blr; // clang-format on +}*/ + +namespace System { +void* ResourceManager::getArchiveStart(ResourceChannelID resId, u32 archiveIdx) { + if (!this->multiArchives1[resId]->isLoaded()) { + return nullptr; + } else if (archiveIdx < this->multiArchives1[resId]->archiveCount) { + return this->multiArchives1[resId]->archives[archiveIdx].mArchiveStart; + } + return nullptr; +} } // Symbol: unk_8054169c @@ -1803,46 +1570,21 @@ asm UNKNOWN_FUNCTION(ResourceManager_preloadCourseAsync) { // clang-format on } -// Symbol: unk_805419c8 -// PAL: 0x805419c8..0x805419ec -MARK_BINARY_BLOB(unk_805419c8, 0x805419c8, 0x805419ec); -asm UNKNOWN_FUNCTION(unk_805419c8) { - // clang-format off - nofralloc; - cmpwi r3, 0x30; - blt lbl_805419d8; - li r3, 0; - blr; -lbl_805419d8: - lis r4, 0; - slwi r0, r3, 2; - addi r4, r4, 0; - lwzx r3, r4, r0; - blr; - // clang-format on +namespace System { +const char* getCharacterName(CharacterId charId) { + if (charId >= CHAR_NAMES_SIZE) { + return nullptr; + } + return CHARACTER_NAMES[charId]; } -// Symbol: unk_805419ec -// PAL: 0x805419ec..0x80541a10 -MARK_BINARY_BLOB(unk_805419ec, 0x805419ec, 0x80541a10); -asm UNKNOWN_FUNCTION(unk_805419ec) { - // clang-format off - nofralloc; - cmpwi r3, 0x24; - blt lbl_805419fc; - li r3, 0; - blr; -lbl_805419fc: - lis r4, 0; - slwi r0, r3, 2; - addi r4, r4, 0; - lwzx r3, r4, r0; - blr; - // clang-format on +const char* getVehicleName(VehicleId vehicleId) { + if (vehicleId >= VEHICLE_NAMES_SIZE) { + return nullptr; + } + return VEHICLE_NAMES[vehicleId]; } -namespace System { - CourseCache::CourseCache() { mBuffer = nullptr; mHeap = nullptr; diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 4b7290b4a..cc918778d 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -51,12 +51,6 @@ UNKNOWN_FUNCTION(unk_80540558); UNKNOWN_FUNCTION(ResourceManager_loadUI); // PAL: 0x80540760..0x80540918 UNKNOWN_FUNCTION(ResourceManager_loadCourse); -// PAL: 0x80540918..0x80540b14 -UNKNOWN_FUNCTION( - loadMission__Q26System15ResourceManagerF8CourseIdlPQ23EGG4Heapb); -// PAL: 0x80540b14..0x80540cfc -UNKNOWN_FUNCTION( - loadCompetition__Q26System15ResourceManagerF8CourseIdPvUlPQ23EGG4HeapUc); // PAL: 0x80540cfc..0x80540e3c UNKNOWN_FUNCTION(unk_80540cfc); // PAL: 0x80540e3c..0x80540f90 @@ -95,8 +89,6 @@ UNKNOWN_FUNCTION(unk_805415c4); UNKNOWN_FUNCTION(unk_805415d4); // PAL: 0x805415e4..0x80541614 UNKNOWN_FUNCTION(unk_805415e4); -// PAL: 0x80541614..0x8054169c -UNKNOWN_FUNCTION(unk_80541614); // PAL: 0x8054169c..0x80541738 UNKNOWN_FUNCTION(unk_8054169c); // PAL: 0x80541738..0x80541794 @@ -221,10 +213,36 @@ class CourseCache : EGG::Disposer { MultiDvdArchive* mArchive; }; +// Enums that represent indices in vehicle name specifiers arrays. typedef enum { + // TODO: Fill +} CharacterId; +typedef enum { + // TODO: Fill +} VehicleId; + +// name of battle mode team +typedef enum { + BATTLE_TEAM_RED = 0, + BATTLE_TEAM_BLUE = 1, + BATTLE_TEAM_NONE = 2 // not in battle mode +} BattleTeam; + +// single player/number of multiplayer +typedef enum { + PLAYER_MODE_FOUR = 0, + PLAYER_MODE_TWO = 1, + PLAYER_MODE_SINGLE = 2 +} PlayMode; + +typedef enum { + // TODO: Fill } CourseId; +const char* getCharacterName(CharacterId charId); +const char* getVehicleName(VehicleId vehicleId); + class ResourceManager { virtual ~ResourceManager(); @@ -238,7 +256,7 @@ class ResourceManager { MultiDvdArchive** multiArchives1; MultiDvdArchive multiArchives2[12]; - MultiDvdArchive MultiArchives3[12]; + MultiDvdArchive multiArchives3[12]; DvdArchive dvdArchive[4]; JobContext jobContexts[7]; EGG::TaskThread* taskThread; @@ -268,6 +286,12 @@ class ResourceManager { EGG::Heap* param_3, bool splitScreen); MultiDvdArchive* loadCompetition(CourseId courseId, void* fileStart, u32 fileSize, EGG::Heap* heap, u8 unk6); + MultiDvdArchive* loadKartFromArchive(MultiDvdArchive* archive, u32 unu, VehicleId vehicleId, CharacterId characterId, + BattleTeam battleTeam, PlayMode playMode, EGG::Heap* archiveHeap, EGG::Heap* fileHeap); + MultiDvdArchive* loadKartFromArchive2(s32 archiveIdx, VehicleId vehicleId, CharacterId characterId, + BattleTeam battleTeamId, PlayMode playMode, EGG::Heap* archiveHeap, EGG::Heap* fileHeap); + MultiDvdArchive* loadKartFromArchive3(s32 archiveIdx, VehicleId vehicleId, CharacterId characterId, + BattleTeam battleTeamId, PlayMode playMode, EGG::Heap* archiveHeap, EGG::Heap* fileHeap); void process(); static void doLoadTask(void* jobContext); void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, @@ -276,6 +300,23 @@ class ResourceManager { EGG::Heap* archiveHeap); void requestLoad(s32 idx, MultiDvdArchive* archive, const char* filename, EGG::Heap* archiveHeap, EGG::Heap* fileHeap); + void* getArchiveStart(ResourceChannelID resId, u32 archiveIdx); + + // TODO: check if actually inline + inline void requestLoadFile(s32 idx, MultiDvdArchive* m, const char* p, EGG::Heap* archiveHeap, EGG::Heap* fileHeap) +{ + this->jobContexts[idx].multiArchive = m; + strncpy(this->jobContexts[idx].filename, p, sizeof(this->jobContexts[idx].filename)); + this->jobContexts[idx].archiveHeap = archiveHeap; + this->jobContexts[idx].fileHeap = fileHeap; + + this->taskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); + this->process(); + + if (!m->isLoaded()) { + OSSleepMilliseconds(16); + } +} }; } // namespace System From fa8838ee95efd4a7a6336aaba401c5efcea4c9b7 Mon Sep 17 00:00:00 2001 From: vabold Date: Sun, 26 Jun 2022 01:31:21 -0400 Subject: [PATCH 18/46] ResourceManager: loadUI, minor cleanup --- source/game/system/ResourceManager.cpp | 235 ++++++++----------------- source/game/system/ResourceManager.hpp | 48 +++-- 2 files changed, 100 insertions(+), 183 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 58007ab2b..285afe4fe 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -97,7 +97,7 @@ const char* COURSE_NAMES[] = { nullptr // clang-format on }; -const s32 COURSE_NAMES_SIZE = sizeof(COURSE_NAMES)/sizeof(COURSE_NAMES[0]); +const s32 COURSE_NAMES_SIZE = sizeof(COURSE_NAMES) / sizeof(COURSE_NAMES[0]); const char* CHARACTER_NAMES[] = { "mr", "bpc", "wl", "kp", "bds", "ka", @@ -109,7 +109,8 @@ const char* CHARACTER_NAMES[] = { "la_mii_m", "la_mii_f", "lb_mii_m", "lb_mii_f", "lc_mii_m", "lc_mii_f", "m_mii", "s_mii", "l_mii", "pc_menu", "ds_menu", "rs_menu"}; -const s32 CHAR_NAMES_SIZE = sizeof(CHARACTER_NAMES)/sizeof(CHARACTER_NAMES[0]); +const s32 CHAR_NAMES_SIZE = + sizeof(CHARACTER_NAMES) / sizeof(CHARACTER_NAMES[0]); const char* VEHICLE_NAMES[] = { "sdf_kart", "mdf_kart", "ldf_kart", "sa_kart", "ma_kart", "la_kart", @@ -119,7 +120,7 @@ const char* VEHICLE_NAMES[] = { "sb_bike", "mb_bike", "lb_bike", "sc_bike", "mc_bike", "lc_bike", "sd_bike", "md_bike", "ld_bike", "se_bike", "me_bike", "le_bike", }; -const s32 VEHICLE_NAMES_SIZE = sizeof(VEHICLE_NAMES)/sizeof(VEHICLE_NAMES[0]); +const s32 VEHICLE_NAMES_SIZE = sizeof(VEHICLE_NAMES) / sizeof(VEHICLE_NAMES[0]); const char* TEAM_SUFFIXES[] = {"_red", "_blue", ""}; const char* LOD_RES_SUFFIXES[] = {"", "_2", "_4"}; @@ -486,74 +487,16 @@ asm UNKNOWN_FUNCTION(unk_80540558) { // clang-format on } -// Symbol: ResourceManager_loadUI -// PAL: 0x80540680..0x80540760 -MARK_BINARY_BLOB(ResourceManager_loadUI, 0x80540680, 0x80540760); -asm UNKNOWN_FUNCTION(ResourceManager_loadUI) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - stw r0, 0x24(r1); - stw r31, 0x1c(r1); - mr r31, r4; - stw r30, 0x18(r1); - mr r30, r5; - stw r29, 0x14(r1); - mr r29, r3; - lwz r6, 4(r3); - lwz r3, 8(r6); - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_8054073c; - cmpwi r31, 0; - beq lbl_8054073c; - lwz r6, 4(r29); - mr r4, r31; - addi r3, r29, 0x398; - li r5, 0x40; - lwz r31, 8(r6); - stw r31, 0x38c(r29); - bl unk_805553b0; - lis r4, 0; - stw r30, 0x3d8(r29); - lwz r3, 0x584(r29); - addi r4, r4, 0; - li r5, 1; - li r6, 0; - bl unk_805553b0; - mr r3, r29; - bl process__Q26System15ResourceManagerFv; - mr r3, r31; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_8054073c; - lis r4, 0x8000; - lis r3, 0x1062; - lwz r0, 0xf8(r4); - addi r4, r3, 0x4dd3; - li r3, 0; - srwi r0, r0, 2; - mulhwu r4, r4, r0; - srwi r0, r4, 6; - rlwinm r4, r4, 0x1e, 2, 0x1b; - rlwimi r3, r0, 4, 0x1c, 0x1f; - bl unk_805553b0; -lbl_8054073c: - lwz r3, 4(r29); - lwz r31, 0x1c(r1); - lwz r30, 0x18(r1); - lwz r29, 0x14(r1); - lwz r0, 0x24(r1); - lwz r3, 8(r3); - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on -} - namespace System { +MultiDvdArchive* ResourceManager::loadUI(const char* filename, + EGG::Heap* archiveHeap) { + if (!this->multiArchives1[2]->isLoaded() && filename) { + requestLoad(1, this->multiArchives1[2], filename, archiveHeap); + } + return this->multiArchives1[2]; +} + MultiDvdArchive* ResourceManager::loadCourse(CourseId courseId, EGG::Heap* param_3, bool splitScreen) { @@ -667,54 +610,57 @@ MultiDvdArchive* ResourceManager::loadCompetition(CourseId courseId, return this->multiArchives1[1]; } -} // namespace System +MultiDvdArchive* ResourceManager::loadKartFromArchive( + MultiDvdArchive* archive, u32 unu, VehicleId vehicleId, + CharacterId characterId, BattleTeam battleTeamId, PlayMode playMode, + EGG::Heap* archiveHeap, EGG::Heap* fileHeap) { + char path[128]; + const char* driver = getCharacterName(characterId); + const char* kart = getVehicleName(vehicleId); + snprintf(path, sizeof(path), "Race/Kart/%s%s-%s%s", kart, + TEAM_SUFFIXES[battleTeamId], driver, LOD_RES_SUFFIXES[playMode]); + requestLoadFile(5, archive, path, archiveHeap, fileHeap); + return archive; +} -namespace System { -MultiDvdArchive* ResourceManager::loadKartFromArchive(MultiDvdArchive* archive, u32 unu, VehicleId vehicleId, - CharacterId characterId, BattleTeam battleTeamId, PlayMode playMode, EGG::Heap* archiveHeap, EGG::Heap* fileHeap) { - char path[128]; +MultiDvdArchive* ResourceManager::loadKartFromArchive2( + s32 archiveIdx, VehicleId vehicleId, CharacterId characterId, + BattleTeam battleTeamId, PlayMode playMode, EGG::Heap* archiveHeap, + EGG::Heap* fileHeap) { + MultiDvdArchive* archive = &this->multiArchives2[archiveIdx]; + char path[128]; + + if (!archive->isLoaded()) { const char* driver = getCharacterName(characterId); const char* kart = getVehicleName(vehicleId); - - snprintf(path, sizeof(path), "Race/Kart/%s%s-%s%s", kart, TEAM_SUFFIXES[battleTeamId], - driver, LOD_RES_SUFFIXES[playMode]); + snprintf(path, sizeof(path), "Race/Kart/%s%s-%s%s", kart, + TEAM_SUFFIXES[battleTeamId], driver, LOD_RES_SUFFIXES[playMode]); requestLoadFile(5, archive, path, archiveHeap, fileHeap); return archive; + } + return archive; } -MultiDvdArchive* ResourceManager::loadKartFromArchive2(s32 archiveIdx, VehicleId vehicleId, - CharacterId characterId, BattleTeam battleTeamId, PlayMode playMode, EGG::Heap* archiveHeap, EGG::Heap* fileHeap) { - MultiDvdArchive* archive = &this->multiArchives2[archiveIdx]; - char path[128]; +MultiDvdArchive* ResourceManager::loadKartFromArchive3( + s32 archiveIdx, VehicleId vehicleId, CharacterId characterId, + BattleTeam battleTeamId, PlayMode playMode, EGG::Heap* archiveHeap, + EGG::Heap* fileHeap) { + MultiDvdArchive* archive = &this->multiArchives3[archiveIdx]; + char path[128]; - if (!archive->isLoaded()) { - const char* driver = getCharacterName(characterId); - const char* kart = getVehicleName(vehicleId); - snprintf(path, sizeof(path), "Race/Kart/%s%s-%s%s", kart, TEAM_SUFFIXES[battleTeamId], - driver, LOD_RES_SUFFIXES[playMode]); - requestLoadFile(5, archive, path, archiveHeap, fileHeap); - return archive; - } + if (!archive->isLoaded()) { + const char* driver = getCharacterName(characterId); + const char* kart = getVehicleName(vehicleId); + snprintf(path, sizeof(path), "Race/Kart/%s%s-%s%s", kart, + TEAM_SUFFIXES[battleTeamId], driver, LOD_RES_SUFFIXES[playMode]); + requestLoadFile(5, archive, path, archiveHeap, fileHeap); return archive; + } + return archive; } -MultiDvdArchive* ResourceManager::loadKartFromArchive3(s32 archiveIdx, VehicleId vehicleId, - CharacterId characterId, BattleTeam battleTeamId, PlayMode playMode, EGG::Heap* archiveHeap, EGG::Heap* fileHeap) { - MultiDvdArchive* archive = &this->multiArchives3[archiveIdx]; - char path[128]; - - if (!archive->isLoaded()) { - const char* driver = getCharacterName(characterId); - const char* kart = getVehicleName(vehicleId); - snprintf(path, sizeof(path), "Race/Kart/%s%s-%s%s", kart, TEAM_SUFFIXES[battleTeamId], - driver, LOD_RES_SUFFIXES[playMode]); - requestLoadFile(5, archive, path, archiveHeap, fileHeap); - return archive; - } - return archive; -} -} +} // namespace System // Symbol: unk_805410e4 // PAL: 0x805410e4..0x805411d4 @@ -1220,62 +1166,19 @@ asm UNKNOWN_FUNCTION(unk_805415e4) { // clang-format on } -// Symbol: unk_80541614 -// PAL: 0x80541614..0x8054169c -/*MARK_BINARY_BLOB(unk_80541614, 0x80541614, 0x8054169c); -asm UNKNOWN_FUNCTION(unk_80541614) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - stw r0, 0x24(r1); - stw r31, 0x1c(r1); - slwi r31, r4, 2; - stw r30, 0x18(r1); - mr r30, r5; - stw r29, 0x14(r1); - mr r29, r3; - lwz r6, 4(r3); - lwzx r3, r6, r31; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_80541654; - li r3, 0; - b lbl_80541680; -lbl_80541654: - lwz r3, 4(r29); - lwzx r3, r3, r31; - lhz r0, 8(r3); - cmplw r30, r0; - bge lbl_8054167c; - mulli r0, r30, 0x24; - lwz r3, 4(r3); - add r3, r3, r0; - lwz r3, 8(r3); - b lbl_80541680; -lbl_8054167c: - li r3, 0; -lbl_80541680: - lwz r0, 0x24(r1); - lwz r31, 0x1c(r1); - lwz r30, 0x18(r1); - lwz r29, 0x14(r1); - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on -}*/ - namespace System { -void* ResourceManager::getArchiveStart(ResourceChannelID resId, u32 archiveIdx) { - if (!this->multiArchives1[resId]->isLoaded()) { - return nullptr; - } else if (archiveIdx < this->multiArchives1[resId]->archiveCount) { - return this->multiArchives1[resId]->archives[archiveIdx].mArchiveStart; - } + +void* ResourceManager::getArchiveStart(ResourceChannelID resId, + u32 archiveIdx) { + if (!this->multiArchives1[resId]->isLoaded()) { return nullptr; + } else if (archiveIdx < this->multiArchives1[resId]->archiveCount) { + return this->multiArchives1[resId]->archives[archiveIdx].mArchiveStart; + } + return nullptr; } -} + +} // namespace System // Symbol: unk_8054169c // PAL: 0x8054169c..0x80541738 @@ -1572,17 +1475,17 @@ asm UNKNOWN_FUNCTION(ResourceManager_preloadCourseAsync) { namespace System { const char* getCharacterName(CharacterId charId) { - if (charId >= CHAR_NAMES_SIZE) { - return nullptr; - } - return CHARACTER_NAMES[charId]; + if (charId >= CHAR_NAMES_SIZE) { + return nullptr; + } + return CHARACTER_NAMES[charId]; } const char* getVehicleName(VehicleId vehicleId) { - if (vehicleId >= VEHICLE_NAMES_SIZE) { - return nullptr; - } - return VEHICLE_NAMES[vehicleId]; + if (vehicleId >= VEHICLE_NAMES_SIZE) { + return nullptr; + } + return VEHICLE_NAMES[vehicleId]; } CourseCache::CourseCache() { diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index cc918778d..a63bd298b 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -224,16 +224,16 @@ typedef enum { // name of battle mode team typedef enum { - BATTLE_TEAM_RED = 0, - BATTLE_TEAM_BLUE = 1, - BATTLE_TEAM_NONE = 2 // not in battle mode + BATTLE_TEAM_RED = 0, + BATTLE_TEAM_BLUE = 1, + BATTLE_TEAM_NONE = 2 // not in battle mode } BattleTeam; // single player/number of multiplayer typedef enum { - PLAYER_MODE_FOUR = 0, - PLAYER_MODE_TWO = 1, - PLAYER_MODE_SINGLE = 2 + PLAYER_MODE_FOUR = 0, + PLAYER_MODE_TWO = 1, + PLAYER_MODE_SINGLE = 2 } PlayMode; typedef enum { @@ -280,18 +280,31 @@ class ResourceManager { MultiDvdArchive* load(ResourceChannelID channelId, EGG::Heap* archiveHeap, const char* filename); + MultiDvdArchive* loadUI(const char* filename, EGG::Heap* archiveHeap); MultiDvdArchive* loadCourse(CourseId courseId, EGG::Heap* param_3, bool splitScreen); MultiDvdArchive* loadMission(CourseId courseId, s32 missionNum, EGG::Heap* param_3, bool splitScreen); MultiDvdArchive* loadCompetition(CourseId courseId, void* fileStart, u32 fileSize, EGG::Heap* heap, u8 unk6); - MultiDvdArchive* loadKartFromArchive(MultiDvdArchive* archive, u32 unu, VehicleId vehicleId, CharacterId characterId, - BattleTeam battleTeam, PlayMode playMode, EGG::Heap* archiveHeap, EGG::Heap* fileHeap); - MultiDvdArchive* loadKartFromArchive2(s32 archiveIdx, VehicleId vehicleId, CharacterId characterId, - BattleTeam battleTeamId, PlayMode playMode, EGG::Heap* archiveHeap, EGG::Heap* fileHeap); - MultiDvdArchive* loadKartFromArchive3(s32 archiveIdx, VehicleId vehicleId, CharacterId characterId, - BattleTeam battleTeamId, PlayMode playMode, EGG::Heap* archiveHeap, EGG::Heap* fileHeap); + MultiDvdArchive* loadKartFromArchive(MultiDvdArchive* archive, u32 unu, + VehicleId vehicleId, + CharacterId characterId, + BattleTeam battleTeam, PlayMode playMode, + EGG::Heap* archiveHeap, + EGG::Heap* fileHeap); + MultiDvdArchive* loadKartFromArchive2(s32 archiveIdx, VehicleId vehicleId, + CharacterId characterId, + BattleTeam battleTeamId, + PlayMode playMode, + EGG::Heap* archiveHeap, + EGG::Heap* fileHeap); + MultiDvdArchive* loadKartFromArchive3(s32 archiveIdx, VehicleId vehicleId, + CharacterId characterId, + BattleTeam battleTeamId, + PlayMode playMode, + EGG::Heap* archiveHeap, + EGG::Heap* fileHeap); void process(); static void doLoadTask(void* jobContext); void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, @@ -303,10 +316,11 @@ class ResourceManager { void* getArchiveStart(ResourceChannelID resId, u32 archiveIdx); // TODO: check if actually inline - inline void requestLoadFile(s32 idx, MultiDvdArchive* m, const char* p, EGG::Heap* archiveHeap, EGG::Heap* fileHeap) -{ + inline void requestLoadFile(s32 idx, MultiDvdArchive* m, const char* p, + EGG::Heap* archiveHeap, EGG::Heap* fileHeap) { this->jobContexts[idx].multiArchive = m; - strncpy(this->jobContexts[idx].filename, p, sizeof(this->jobContexts[idx].filename)); + strncpy(this->jobContexts[idx].filename, p, + sizeof(this->jobContexts[idx].filename)); this->jobContexts[idx].archiveHeap = archiveHeap; this->jobContexts[idx].fileHeap = fileHeap; @@ -314,9 +328,9 @@ class ResourceManager { this->process(); if (!m->isLoaded()) { - OSSleepMilliseconds(16); + OSSleepMilliseconds(16); } -} + } }; } // namespace System From 60994f73ad0b64e49e8107c718eab06f032beec3 Mon Sep 17 00:00:00 2001 From: vabold Date: Sun, 26 Jun 2022 23:26:39 -0400 Subject: [PATCH 19/46] ResourceManager: loadSystemResource --- source/game/system/ResourceManager.cpp | 101 +++---------------------- source/game/system/ResourceManager.hpp | 16 ++++ 2 files changed, 28 insertions(+), 89 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 285afe4fe..c99387518 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #pragma dont_reuse_strings on @@ -398,97 +399,19 @@ MultiDvdArchive* ResourceManager::load(ResourceChannelID channelId, return this->multiArchives1[channelId]; } -} // namespace System - -// Symbol: unk_80540558 -// PAL: 0x80540558..0x80540680 -MARK_BINARY_BLOB(unk_80540558, 0x80540558, 0x80540680); -asm UNKNOWN_FUNCTION(unk_80540558) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - stw r0, 0x24(r1); - stmw r26, 8(r1); - mulli r31, r4, 0x24; - mr r30, r3; - mr r26, r4; - add r28, r3, r31; - mr r27, r5; - li r3, 1; - lwz r0, 0x2c8(r28); - cmpwi r0, 4; - beq lbl_8054059c; - lwz r0, 0x2c8(r28); - cmpwi r0, 5; - beq lbl_8054059c; - li r3, 0; -lbl_8054059c: - cmpwi r3, 0; - bne lbl_80540664; - mr r3, r26; - bl unk_805553b0; - lbz r0, 0(r3); - extsb. r0, r0; - beq lbl_80540664; - mr r3, r26; - bl unk_805553b0; - mr r29, r3; - mr r3, r26; - bl unk_805553b0; - add r5, r30, r31; - mr r4, r3; - addi r0, r5, 0x2a8; - stw r0, 0x534(r30); - addi r3, r30, 0x53c; - li r5, 0x40; - bl unk_805553b0; - lis r4, 0; - stw r27, 0x57c(r30); - lwz r3, 0x584(r30); - addi r4, r4, 0; - stw r29, 0x538(r30); - li r5, 6; - li r6, 0; - bl unk_805553b0; - mr r3, r30; - bl process__Q26System15ResourceManagerFv; - lwz r0, 0x2c8(r28); - li r3, 0; - cmpwi r0, 4; - beq lbl_8054062c; - lwz r0, 0x2c8(r28); - cmpwi r0, 5; - bne lbl_80540630; -lbl_8054062c: - li r3, 1; -lbl_80540630: - cmpwi r3, 0; - bne lbl_80540664; - lis r4, 0x8000; - lis r3, 0x1062; - lwz r0, 0xf8(r4); - addi r4, r3, 0x4dd3; - li r3, 0; - srwi r0, r0, 2; - mulhwu r4, r4, r0; - srwi r0, r4, 6; - rlwinm r4, r4, 0x1e, 2, 0x1b; - rlwimi r3, r0, 4, 0x1c, 0x1f; - bl unk_805553b0; -lbl_80540664: - add r3, r30, r31; - lmw r26, 8(r1); - lwz r0, 0x24(r1); - addi r3, r3, 0x2a8; - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on +DvdArchive* ResourceManager::loadSystemResource(s32 idx, + EGG::Heap* archiveHeap) { + if (!dvdArchive[idx].isLoaded()) { + const char* resourcePath = Resource::GetResourcePath((eSystemResource)idx); + if (resourcePath[0] != 0) { + requestLoadFile( + 6, &dvdArchive[idx], Resource::GetResourcePath((eSystemResource)idx), + Resource::GetResourceID((eSystemResource)idx), archiveHeap); + } + } + return &dvdArchive[idx]; } -namespace System { - MultiDvdArchive* ResourceManager::loadUI(const char* filename, EGG::Heap* archiveHeap) { if (!this->multiArchives1[2]->isLoaded() && filename) { diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index a63bd298b..6578fed36 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -280,6 +280,7 @@ class ResourceManager { MultiDvdArchive* load(ResourceChannelID channelId, EGG::Heap* archiveHeap, const char* filename); + DvdArchive* loadSystemResource(s32 idx, EGG::Heap* archiveHeap); MultiDvdArchive* loadUI(const char* filename, EGG::Heap* archiveHeap); MultiDvdArchive* loadCourse(CourseId courseId, EGG::Heap* param_3, bool splitScreen); @@ -331,6 +332,21 @@ class ResourceManager { OSSleepMilliseconds(16); } } + inline void requestLoadFile(s32 idx, DvdArchive* archive, + const char* filename, u32 unk, + EGG::Heap* archiveHeap) { + this->jobContexts[idx].archive = archive; + strncpy(this->jobContexts[idx].filename, filename, 0x40); + this->jobContexts[idx].archiveHeap = archiveHeap; + this->jobContexts[idx]._08 = unk; + + this->taskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); + this->process(); + + if (!archive->isLoaded()) { + OSSleepMilliseconds(16); + } + } }; } // namespace System From ad0e842bc426ed6b915525e64afb121f918b8189 Mon Sep 17 00:00:00 2001 From: vabold Date: Mon, 27 Jun 2022 18:57:29 -0400 Subject: [PATCH 20/46] ResourceManager: loadMenuKartModel, minor cleanup --- pack/rel_objects.txt | 2 +- pack/rel_slices.csv | 2 +- source/game/system/ResourceManager.cpp | 108 ++++++------------------- source/game/system/ResourceManager.hpp | 4 + 4 files changed, 31 insertions(+), 85 deletions(-) diff --git a/pack/rel_objects.txt b/pack/rel_objects.txt index cc6961629..c797b4315 100644 --- a/pack/rel_objects.txt +++ b/pack/rel_objects.txt @@ -21,7 +21,7 @@ out/rel/rodata_8088fe28_80890490.o out/rel/data_808b31e8_808b3960.o out/ResourceManager.o out/rel/text_80542878_80555464.o -out/rel/rodata_80890bd3_80891370.o +out/rel/rodata_80890c0e_80891370.o out/rel/data_808b3c2c_808b42e0.o out/Random.o out/rel/text_8055572c_80590128.o diff --git a/pack/rel_slices.csv b/pack/rel_slices.csv index db9f70eda..a1683cbb5 100644 --- a/pack/rel_slices.csv +++ b/pack/rel_slices.csv @@ -4,7 +4,7 @@ enabled,name,textStart,textEnd,ctorsStart,ctorsEnd,dtorsStart,dtorsEnd,rodataSta 1,source/game/system/GhostFile.cpp,0x8051c088,0x8051d4d4,,,,,,,0x808b2d38,0x808b2d50,, 1,source/game/system/LocalizedArchive.cpp,0x8052a098,0x8052a538,,,,,0x8088fdc0,0x8088fe00,0x808b3188,0x808b31d8,, 1,source/game/system/MultiDvdArchive.cpp,0x8052a538,0x8052ae5c,,,,,0x8088fe00,0x8088fe28,0x808b31d8,0x808b31e8,, -1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890BD3,0x808b3960,0x808b3c2c,, +1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890c0e,0x808b3960,0x808b3c2c,, 1,source/game/util/Random.cpp,0x80555464,0x8055572c,,,,,0x80891370,0x80891380,0x808b42e0,0x808b42ec,, 1,source/game/kart/KartComponent.cpp,0x80590128,0x805901d0,,,,,,,,,0x809c1900,0x809c1910 1,source/game/ui/ControlGroup.cpp,0x805c23e4,0x805c2c18,,,,,,,,,, diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index c99387518..847d7d14e 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -583,84 +583,31 @@ MultiDvdArchive* ResourceManager::loadKartFromArchive3( return archive; } -} // namespace System +MultiDvdArchive* ResourceManager::loadMenuKartModel(s32 archiveIdx, + CharacterId characterId, + BattleTeam battleTeam, + EGG::Heap* archiveHeap, + EGG::Heap* fileHeap) { + const char* characterName; + char buffer[128]; -// Symbol: unk_805410e4 -// PAL: 0x805410e4..0x805411d4 -MARK_BINARY_BLOB(unk_805410e4, 0x805410e4, 0x805411d4); -asm UNKNOWN_FUNCTION(unk_805410e4) { - // clang-format off - nofralloc; - stwu r1, -0xa0(r1); - mflr r0; - stw r0, 0xa4(r1); - mulli r0, r4, 0x1c; - stmw r27, 0x8c(r1); - mr r27, r5; - add r3, r3, r0; - mr r28, r6; - addi r31, r3, 8; - mr r29, r7; - mr r30, r8; - mr r3, r31; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_805411bc; - cmpwi r28, 2; - bne lbl_80541168; - lis r4, 0; - cmpwi r27, 0x30; - addi r4, r4, 0; - addi r3, r1, 8; - addi r5, r4, 0xd3; - li r4, 0x80; - blt lbl_8054114c; - li r6, 0; - b lbl_8054115c; -lbl_8054114c: - lis r6, 0; - slwi r0, r27, 2; - addi r6, r6, 0; - lwzx r6, r6, r0; -lbl_8054115c: - crclr 6; - bl unk_805553b0; - b lbl_805411a4; -lbl_80541168: - lis r4, 0; - cmpwi r27, 0x30; - addi r4, r4, 0; - addi r3, r1, 8; - addi r5, r4, 0xef; - li r4, 0x80; - blt lbl_8054118c; - li r6, 0; - b lbl_8054119c; -lbl_8054118c: - lis r6, 0; - slwi r0, r27, 2; - addi r6, r6, 0; - lwzx r6, r6, r0; -lbl_8054119c: - crclr 6; - bl unk_805553b0; -lbl_805411a4: - mr r3, r31; - mr r5, r29; - mr r6, r30; - addi r4, r1, 8; - li r7, 0; - bl load__Q26System15MultiDvdArchiveFPCcPQ23EGG4HeapPQ23EGG4Heapi; -lbl_805411bc: - mr r3, r31; - lmw r27, 0x8c(r1); - lwz r0, 0xa4(r1); - mtlr r0; - addi r1, r1, 0xa0; - blr; - // clang-format on + if (!multiArchives2[archiveIdx].isLoaded()) { + if (battleTeam == 2) { // not in battle mode + characterName = getCharacterName(characterId); + snprintf(buffer, sizeof(buffer), "Scene/Model/Kart/%s-allkart", + characterName); + } else { + characterName = getCharacterName(characterId); + snprintf(buffer, sizeof(buffer), "Scene/Model/Kart/%s-allkart_BT", + characterName); + } + multiArchives2[archiveIdx].load(buffer, archiveHeap, fileHeap, 0); + } + return &multiArchives2[archiveIdx]; } +} // namespace System + // Symbol: unk_805411d4 // PAL: 0x805411d4..0x805411e4 MARK_BINARY_BLOB(unk_805411d4, 0x805411d4, 0x805411e4); @@ -1397,18 +1344,13 @@ asm UNKNOWN_FUNCTION(ResourceManager_preloadCourseAsync) { } namespace System { + const char* getCharacterName(CharacterId charId) { - if (charId >= CHAR_NAMES_SIZE) { - return nullptr; - } - return CHARACTER_NAMES[charId]; + return (charId >= CHAR_NAMES_SIZE) ? nullptr : CHARACTER_NAMES[charId]; } const char* getVehicleName(VehicleId vehicleId) { - if (vehicleId >= VEHICLE_NAMES_SIZE) { - return nullptr; - } - return VEHICLE_NAMES[vehicleId]; + return (vehicleId >= VEHICLE_NAMES_SIZE) ? nullptr : VEHICLE_NAMES[vehicleId]; } CourseCache::CourseCache() { diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 6578fed36..b4d489f0d 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -306,6 +306,10 @@ class ResourceManager { PlayMode playMode, EGG::Heap* archiveHeap, EGG::Heap* fileHeap); + MultiDvdArchive* loadMenuKartModel(s32 archiveIdx, CharacterId characterId, + BattleTeam battleTeam, + EGG::Heap* archiveHeap, + EGG::Heap* fileHeap); void process(); static void doLoadTask(void* jobContext); void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, From fe8139ca6169b4e3d3770dfdbbd309960f27032b Mon Sep 17 00:00:00 2001 From: vabold Date: Mon, 27 Jun 2022 19:07:42 -0400 Subject: [PATCH 21/46] ResourceManager: unmountMulti, unmountArchive --- source/game/system/ResourceManager.cpp | 41 +++++--------------------- source/game/system/ResourceManager.hpp | 3 ++ 2 files changed, 10 insertions(+), 34 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 847d7d14e..5bda9784e 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -606,45 +606,18 @@ MultiDvdArchive* ResourceManager::loadMenuKartModel(s32 archiveIdx, return &multiArchives2[archiveIdx]; } -} // namespace System - -// Symbol: unk_805411d4 -// PAL: 0x805411d4..0x805411e4 -MARK_BINARY_BLOB(unk_805411d4, 0x805411d4, 0x805411e4); -asm UNKNOWN_FUNCTION(unk_805411d4) { - // clang-format off - nofralloc; - lwz r3, 4(r3); - slwi r0, r4, 2; - lwzx r3, r3, r0; - b unmount__Q26System15MultiDvdArchiveFv; - // clang-format on +void ResourceManager::unmountMulti(s32 archiveIdx) { + multiArchives1[archiveIdx]->unmount(); } -// Symbol: unk_805411e4 -// PAL: 0x805411e4..0x805411ec -MARK_BINARY_BLOB(unk_805411e4, 0x805411e4, 0x805411ec); -asm UNKNOWN_FUNCTION(unk_805411e4) { - // clang-format off - nofralloc; - mr r3, r4; - b unmount__Q26System15MultiDvdArchiveFv; - // clang-format on -} +void ResourceManager::unmountMulti(MultiDvdArchive* other) { other->unmount(); } -// Symbol: unk_805411ec -// PAL: 0x805411ec..0x805411fc -MARK_BINARY_BLOB(unk_805411ec, 0x805411ec, 0x805411fc); -asm UNKNOWN_FUNCTION(unk_805411ec) { - // clang-format off - nofralloc; - mulli r0, r4, 0x24; - add r3, r3, r0; - addi r3, r3, 0x2a8; - b unmount__Q26System10DvdArchiveFv; - // clang-format on +void ResourceManager::unmountArchive(s32 archiveIdx) { + dvdArchive[archiveIdx].unmount(); } +} // namespace System + // Symbol: ResourceManager_getFile // PAL: 0x805411fc..0x80541278 MARK_BINARY_BLOB(ResourceManager_getFile, 0x805411fc, 0x80541278); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index b4d489f0d..9ffff7bec 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -310,6 +310,9 @@ class ResourceManager { BattleTeam battleTeam, EGG::Heap* archiveHeap, EGG::Heap* fileHeap); + void unmountMulti(s32 archiveIdx); + void unmountMulti(MultiDvdArchive* other); + void unmountArchive(s32 archiveIdx); void process(); static void doLoadTask(void* jobContext); void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, From 9c7172b149d1ed4e0d76cbf2df83cb87c27530da Mon Sep 17 00:00:00 2001 From: vabold Date: Mon, 27 Jun 2022 19:17:39 -0400 Subject: [PATCH 22/46] ResourceManager: getFile --- source/game/system/ResourceManager.cpp | 49 ++++---------------------- source/game/system/ResourceManager.hpp | 1 + 2 files changed, 8 insertions(+), 42 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 5bda9784e..e494e6af9 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -616,50 +616,15 @@ void ResourceManager::unmountArchive(s32 archiveIdx) { dvdArchive[archiveIdx].unmount(); } -} // namespace System - -// Symbol: ResourceManager_getFile -// PAL: 0x805411fc..0x80541278 -MARK_BINARY_BLOB(ResourceManager_getFile, 0x805411fc, 0x80541278); -asm UNKNOWN_FUNCTION(ResourceManager_getFile) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - stw r0, 0x24(r1); - stw r31, 0x1c(r1); - slwi r31, r4, 2; - stw r30, 0x18(r1); - mr r30, r6; - stw r29, 0x14(r1); - mr r29, r5; - stw r28, 0x10(r1); - mr r28, r3; - lwz r7, 4(r3); - lwzx r3, r7, r31; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - beq lbl_80541254; - lwz r3, 4(r28); - mr r4, r29; - mr r5, r30; - lwzx r3, r3, r31; - bl getFile__Q26System15MultiDvdArchiveFPCcPUl; - b lbl_80541258; -lbl_80541254: - li r3, 0; -lbl_80541258: - lwz r0, 0x24(r1); - lwz r31, 0x1c(r1); - lwz r30, 0x18(r1); - lwz r29, 0x14(r1); - lwz r28, 0x10(r1); - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on +void* ResourceManager::getFile(s32 archiveIdx, const char* filename, + size_t* size) { + return (multiArchives1[archiveIdx]->isLoaded()) + ? multiArchives1[archiveIdx]->getFile(filename, size) + : nullptr; } +} // namespace System + // Symbol: unk_80541278 // PAL: 0x80541278..0x80541320 MARK_BINARY_BLOB(unk_80541278, 0x80541278, 0x80541320); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 9ffff7bec..0e097c6bc 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -313,6 +313,7 @@ class ResourceManager { void unmountMulti(s32 archiveIdx); void unmountMulti(MultiDvdArchive* other); void unmountArchive(s32 archiveIdx); + void* getFile(s32 archiveIdx, const char* filename, size_t* size); void process(); static void doLoadTask(void* jobContext); void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, From fc18118e19e76941ba1e63514e2e5968468cc2c5 Mon Sep 17 00:00:00 2001 From: vabold Date: Mon, 27 Jun 2022 19:35:05 -0400 Subject: [PATCH 23/46] ResourceManager: getCharacterFile --- pack/rel_objects.txt | 2 +- pack/rel_slices.csv | 2 +- source/game/system/ResourceManager.cpp | 65 +++++--------------------- source/game/system/ResourceManager.hpp | 1 + 4 files changed, 14 insertions(+), 56 deletions(-) diff --git a/pack/rel_objects.txt b/pack/rel_objects.txt index c797b4315..aa10402b7 100644 --- a/pack/rel_objects.txt +++ b/pack/rel_objects.txt @@ -21,7 +21,7 @@ out/rel/rodata_8088fe28_80890490.o out/rel/data_808b31e8_808b3960.o out/ResourceManager.o out/rel/text_80542878_80555464.o -out/rel/rodata_80890c0e_80891370.o +out/rel/rodata_80890c17_80891370.o out/rel/data_808b3c2c_808b42e0.o out/Random.o out/rel/text_8055572c_80590128.o diff --git a/pack/rel_slices.csv b/pack/rel_slices.csv index a1683cbb5..e8a63ab50 100644 --- a/pack/rel_slices.csv +++ b/pack/rel_slices.csv @@ -4,7 +4,7 @@ enabled,name,textStart,textEnd,ctorsStart,ctorsEnd,dtorsStart,dtorsEnd,rodataSta 1,source/game/system/GhostFile.cpp,0x8051c088,0x8051d4d4,,,,,,,0x808b2d38,0x808b2d50,, 1,source/game/system/LocalizedArchive.cpp,0x8052a098,0x8052a538,,,,,0x8088fdc0,0x8088fe00,0x808b3188,0x808b31d8,, 1,source/game/system/MultiDvdArchive.cpp,0x8052a538,0x8052ae5c,,,,,0x8088fe00,0x8088fe28,0x808b31d8,0x808b31e8,, -1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890c0e,0x808b3960,0x808b3c2c,, +1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890c17,0x808b3960,0x808b3c2c,, 1,source/game/util/Random.cpp,0x80555464,0x8055572c,,,,,0x80891370,0x80891380,0x808b42e0,0x808b42ec,, 1,source/game/kart/KartComponent.cpp,0x80590128,0x805901d0,,,,,,,,,0x809c1900,0x809c1910 1,source/game/ui/ControlGroup.cpp,0x805c23e4,0x805c2c18,,,,,,,,,, diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index e494e6af9..779c88c16 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -623,63 +623,20 @@ void* ResourceManager::getFile(s32 archiveIdx, const char* filename, : nullptr; } -} // namespace System +void* ResourceManager::getCharacterFile(CharacterId characterId, size_t* size) { + char buffer[128]; -// Symbol: unk_80541278 -// PAL: 0x80541278..0x80541320 -MARK_BINARY_BLOB(unk_80541278, 0x80541278, 0x80541320); -asm UNKNOWN_FUNCTION(unk_80541278) { - // clang-format off - nofralloc; - stwu r1, -0xa0(r1); - mflr r0; - stw r0, 0xa4(r1); - stw r31, 0x9c(r1); - mr r31, r5; - stw r30, 0x98(r1); - mr r30, r4; - stw r29, 0x94(r1); - mr r29, r3; - lwz r6, 4(r3); - lwz r3, 0x18(r6); - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_805412b8; - li r3, 0; - b lbl_80541304; -lbl_805412b8: - lis r3, 0; - cmpwi r30, 0x30; - addi r3, r3, 0; - li r4, 0x80; - addi r3, r3, 0x10e; - blt lbl_805412d8; - li r5, 0; - b lbl_805412e8; -lbl_805412d8: - lis r5, 0; - slwi r0, r30, 2; - addi r5, r5, 0; - lwzx r5, r5, r0; -lbl_805412e8: - crclr 6; - bl unk_805553b0; - lwz r3, 4(r29); - mr r5, r31; - addi r4, r1, 8; - lwz r3, 0x18(r3); - bl getFile__Q26System15MultiDvdArchiveFPCcPUl; -lbl_80541304: - lwz r0, 0xa4(r1); - lwz r31, 0x9c(r1); - lwz r30, 0x98(r1); - lwz r29, 0x94(r1); - mtlr r0; - addi r1, r1, 0xa0; - blr; - // clang-format on + if (!multiArchives1[6]->isLoaded()) { + return nullptr; + } + const char* character = getCharacterName(characterId); + // I can't believe this compiles + snprintf("%s.brres", sizeof(buffer), character); + return multiArchives1[6]->getFile(buffer, size); } +} // namespace System + // Symbol: unk_80541320 // PAL: 0x80541320..0x805413c8 MARK_BINARY_BLOB(unk_80541320, 0x80541320, 0x805413c8); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 0e097c6bc..fe5829c06 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -314,6 +314,7 @@ class ResourceManager { void unmountMulti(MultiDvdArchive* other); void unmountArchive(s32 archiveIdx); void* getFile(s32 archiveIdx, const char* filename, size_t* size); + void* getCharacterFile(CharacterId characterId, size_t* size); void process(); static void doLoadTask(void* jobContext); void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, From a456f998e99326812a4f0add69d0b1ac38ef12d8 Mon Sep 17 00:00:00 2001 From: vabold Date: Mon, 27 Jun 2022 19:40:09 -0400 Subject: [PATCH 24/46] ResourceManager: getVehicleFile --- pack/rel_objects.txt | 2 +- pack/rel_slices.csv | 2 +- source/game/system/ResourceManager.cpp | 66 +++++--------------------- source/game/system/ResourceManager.hpp | 1 + 4 files changed, 15 insertions(+), 56 deletions(-) diff --git a/pack/rel_objects.txt b/pack/rel_objects.txt index aa10402b7..dbc9eb740 100644 --- a/pack/rel_objects.txt +++ b/pack/rel_objects.txt @@ -21,7 +21,7 @@ out/rel/rodata_8088fe28_80890490.o out/rel/data_808b31e8_808b3960.o out/ResourceManager.o out/rel/text_80542878_80555464.o -out/rel/rodata_80890c17_80891370.o +out/rel/rodata_80890c20_80891370.o out/rel/data_808b3c2c_808b42e0.o out/Random.o out/rel/text_8055572c_80590128.o diff --git a/pack/rel_slices.csv b/pack/rel_slices.csv index e8a63ab50..2aa9e543b 100644 --- a/pack/rel_slices.csv +++ b/pack/rel_slices.csv @@ -4,7 +4,7 @@ enabled,name,textStart,textEnd,ctorsStart,ctorsEnd,dtorsStart,dtorsEnd,rodataSta 1,source/game/system/GhostFile.cpp,0x8051c088,0x8051d4d4,,,,,,,0x808b2d38,0x808b2d50,, 1,source/game/system/LocalizedArchive.cpp,0x8052a098,0x8052a538,,,,,0x8088fdc0,0x8088fe00,0x808b3188,0x808b31d8,, 1,source/game/system/MultiDvdArchive.cpp,0x8052a538,0x8052ae5c,,,,,0x8088fe00,0x8088fe28,0x808b31d8,0x808b31e8,, -1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890c17,0x808b3960,0x808b3c2c,, +1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890c20,0x808b3960,0x808b3c2c,, 1,source/game/util/Random.cpp,0x80555464,0x8055572c,,,,,0x80891370,0x80891380,0x808b42e0,0x808b42ec,, 1,source/game/kart/KartComponent.cpp,0x80590128,0x805901d0,,,,,,,,,0x809c1900,0x809c1910 1,source/game/ui/ControlGroup.cpp,0x805c23e4,0x805c2c18,,,,,,,,,, diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 779c88c16..c87aee9c1 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -635,63 +635,21 @@ void* ResourceManager::getCharacterFile(CharacterId characterId, size_t* size) { return multiArchives1[6]->getFile(buffer, size); } -} // namespace System +void* ResourceManager::getVehicleFile(s32 archiveIdx, VehicleId vehicleId, + size_t* size) { + char buffer[128]; -// Symbol: unk_80541320 -// PAL: 0x80541320..0x805413c8 -MARK_BINARY_BLOB(unk_80541320, 0x80541320, 0x805413c8); -asm UNKNOWN_FUNCTION(unk_80541320) { - // clang-format off - nofralloc; - stwu r1, -0xa0(r1); - mflr r0; - stw r0, 0xa4(r1); - mulli r0, r4, 0x1c; - stw r31, 0x9c(r1); - add r3, r3, r0; - stw r30, 0x98(r1); - addi r31, r3, 8; - mr r30, r6; - stw r29, 0x94(r1); - mr r29, r5; - mr r3, r31; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_80541364; - li r3, 0; - b lbl_805413ac; -lbl_80541364: - lis r3, 0; - cmpwi r29, 0x24; - addi r3, r3, 0; - li r4, 0x80; - addi r3, r3, 0x117; - blt lbl_80541384; - li r5, 0; - b lbl_80541394; -lbl_80541384: - lis r5, 0; - slwi r0, r29, 2; - addi r5, r5, 0; - lwzx r5, r5, r0; -lbl_80541394: - crclr 6; - bl unk_805553b0; - mr r3, r31; - mr r5, r30; - addi r4, r1, 8; - bl getFile__Q26System15MultiDvdArchiveFPCcPUl; -lbl_805413ac: - lwz r0, 0xa4(r1); - lwz r31, 0x9c(r1); - lwz r30, 0x98(r1); - lwz r29, 0x94(r1); - mtlr r0; - addi r1, r1, 0xa0; - blr; - // clang-format on + if (!multiArchives2[archiveIdx].isLoaded()) { + return nullptr; + } + const char* vehicle = getVehicleName(vehicleId); + // I can't believe this compiles + snprintf("%s.brres", sizeof(buffer), vehicle); + return multiArchives2[archiveIdx].getFile(buffer, size); } +} // namespace System + // Symbol: unk_805413c8 // PAL: 0x805413c8..0x80541438 MARK_BINARY_BLOB(unk_805413c8, 0x805413c8, 0x80541438); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index fe5829c06..e37ed4d8e 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -315,6 +315,7 @@ class ResourceManager { void unmountArchive(s32 archiveIdx); void* getFile(s32 archiveIdx, const char* filename, size_t* size); void* getCharacterFile(CharacterId characterId, size_t* size); + void* getVehicleFile(s32 archiveIdx, VehicleId vehicleId, size_t* size); void process(); static void doLoadTask(void* jobContext); void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, From 90d6cebedbc130fbc0db2ef27394397a6d975b6b Mon Sep 17 00:00:00 2001 From: vabold Date: Mon, 27 Jun 2022 20:15:57 -0400 Subject: [PATCH 25/46] ResourceManager: getFileCopy --- pack/symbols.txt | 2 +- source/game/system/ResourceManager.cpp | 55 ++++++-------------------- source/game/system/ResourceManager.hpp | 4 +- 3 files changed, 17 insertions(+), 44 deletions(-) diff --git a/pack/symbols.txt b/pack/symbols.txt index 567307947..688ac11cf 100644 --- a/pack/symbols.txt +++ b/pack/symbols.txt @@ -9992,7 +9992,7 @@ 0x80541320 unk_80541320 0x805413c8 unk_805413c8 0x80541438 unk_80541438 -0x805414a8 unk_805414a8 +0x805414a8 ResourceManager_loadBSP 0x8054155c unk_8054155c 0x805415b0 unk_805415b0 0x805415b4 unk_805415b4 diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index c87aee9c1..89d55f850 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -728,10 +728,11 @@ asm UNKNOWN_FUNCTION(unk_80541438) { // clang-format on } -// Symbol: unk_805414a8 +// Symbol: ResourceManager_loadBSP // PAL: 0x805414a8..0x8054155c -MARK_BINARY_BLOB(unk_805414a8, 0x805414a8, 0x8054155c); -asm UNKNOWN_FUNCTION(unk_805414a8) { +// Notes: requires Racedata decomp +MARK_BINARY_BLOB(ResourceManager_loadBSP, 0x805414a8, 0x8054155c); +asm UNKNOWN_FUNCTION(ResourceManager_loadBSP) { // clang-format off nofralloc; stwu r1, -0x30(r1); @@ -786,48 +787,18 @@ asm UNKNOWN_FUNCTION(unk_805414a8) { // clang-format on } -// Symbol: unk_8054155c -// PAL: 0x8054155c..0x805415b0 -MARK_BINARY_BLOB(unk_8054155c, 0x8054155c, 0x805415b0); -asm UNKNOWN_FUNCTION(unk_8054155c) { - // clang-format off - nofralloc; - mulli r10, r4, 0x24; - li r9, 1; - add r4, r3, r10; - lwz r0, 0x2c8(r4); - cmpwi r0, 4; - beq lbl_80541584; - lwz r0, 0x2c8(r4); - cmpwi r0, 5; - beq lbl_80541584; - li r9, 0; -lbl_80541584: - cmpwi r9, 0; - bne lbl_80541594; - li r3, 0; - blr; -lbl_80541594: - add r3, r3, r10; - mr r4, r5; - mr r5, r6; - mr r6, r7; - addi r3, r3, 0x2a8; - extsb r7, r8; - b getFileCopy__Q26System10DvdArchiveFPcPQ23EGG4HeapPUlSc; - // clang-format on -} +namespace System { -// Symbol: unk_805415b0 -// PAL: 0x805415b0..0x805415b4 -MARK_BINARY_BLOB(unk_805415b0, 0x805415b0, 0x805415b4); -asm UNKNOWN_FUNCTION(unk_805415b0) { - // clang-format off - nofralloc; - blr; - // clang-format on +void* ResourceManager::getFileCopy(s32 archiveIdx, char* filename, + EGG::Heap* heap, size_t* size, s8 param_5) { + return (!dvdArchive[archiveIdx].isLoaded()) + ? 0 + : dvdArchive[archiveIdx].getFileCopy(filename, heap, size, + param_5); } +} // namespace System + // Symbol: unk_805415b4 // PAL: 0x805415b4..0x805415c4 MARK_BINARY_BLOB(unk_805415b4, 0x805415b4, 0x805415c4); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index e37ed4d8e..72bc38512 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -76,7 +76,7 @@ UNKNOWN_FUNCTION(unk_805413c8); // PAL: 0x80541438..0x805414a8 UNKNOWN_FUNCTION(unk_80541438); // PAL: 0x805414a8..0x8054155c -UNKNOWN_FUNCTION(unk_805414a8); +UNKNOWN_FUNCTION(ResourceManager_loadBSP); // PAL: 0x8054155c..0x805415b0 UNKNOWN_FUNCTION(unk_8054155c); // PAL: 0x805415b0..0x805415b4 @@ -316,6 +316,8 @@ class ResourceManager { void* getFile(s32 archiveIdx, const char* filename, size_t* size); void* getCharacterFile(CharacterId characterId, size_t* size); void* getVehicleFile(s32 archiveIdx, VehicleId vehicleId, size_t* size); + void* getFileCopy(s32 archiveIdx, char* filename, EGG::Heap* heap, + size_t* size, s8 param_5); void process(); static void doLoadTask(void* jobContext); void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, From 5630c193c5fe24cfe4709a9aa4c95cdf0ce993a9 Mon Sep 17 00:00:00 2001 From: Theodoros Tyrovouzis Date: Tue, 28 Jun 2022 21:50:17 +0300 Subject: [PATCH 26/46] a couple of functions --- source/game/system/ResourceManager.cpp | 222 +++++-------------------- source/game/system/ResourceManager.hpp | 13 +- 2 files changed, 50 insertions(+), 185 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 89d55f850..f39cd9bf8 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -401,15 +401,15 @@ MultiDvdArchive* ResourceManager::load(ResourceChannelID channelId, DvdArchive* ResourceManager::loadSystemResource(s32 idx, EGG::Heap* archiveHeap) { - if (!dvdArchive[idx].isLoaded()) { + if (!dvdArchives[idx].isLoaded()) { const char* resourcePath = Resource::GetResourcePath((eSystemResource)idx); if (resourcePath[0] != 0) { requestLoadFile( - 6, &dvdArchive[idx], Resource::GetResourcePath((eSystemResource)idx), + 6, &dvdArchives[idx], Resource::GetResourcePath((eSystemResource)idx), Resource::GetResourceID((eSystemResource)idx), archiveHeap); } } - return &dvdArchive[idx]; + return &dvdArchives[idx]; } MultiDvdArchive* ResourceManager::loadUI(const char* filename, @@ -613,7 +613,7 @@ void ResourceManager::unmountMulti(s32 archiveIdx) { void ResourceManager::unmountMulti(MultiDvdArchive* other) { other->unmount(); } void ResourceManager::unmountArchive(s32 archiveIdx) { - dvdArchive[archiveIdx].unmount(); + dvdArchives[archiveIdx].unmount(); } void* ResourceManager::getFile(s32 archiveIdx, const char* filename, @@ -648,85 +648,20 @@ void* ResourceManager::getVehicleFile(s32 archiveIdx, VehicleId vehicleId, return multiArchives2[archiveIdx].getFile(buffer, size); } -} // namespace System - -// Symbol: unk_805413c8 -// PAL: 0x805413c8..0x80541438 -MARK_BINARY_BLOB(unk_805413c8, 0x805413c8, 0x80541438); -asm UNKNOWN_FUNCTION(unk_805413c8) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - stw r0, 0x24(r1); - mulli r0, r4, 0x1c; - stw r31, 0x1c(r1); - add r3, r3, r0; - stw r30, 0x18(r1); - addi r31, r3, 8; - mr r30, r6; - stw r29, 0x14(r1); - mr r29, r5; - mr r3, r31; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - beq lbl_80541418; - mr r3, r31; - mr r4, r29; - mr r5, r30; - bl getFile__Q26System15MultiDvdArchiveFPCcPUl; - b lbl_8054141c; -lbl_80541418: - li r3, 0; -lbl_8054141c: - lwz r0, 0x24(r1); - lwz r31, 0x1c(r1); - lwz r30, 0x18(r1); - lwz r29, 0x14(r1); - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on +void* ResourceManager::getMultiFile2(u16 idx, const char* filename, + size_t* size) { + return this->multiArchives2[idx].isLoaded() + ? this->multiArchives2[idx].getFile(filename, size) + : nullptr; } -// Symbol: unk_80541438 -// PAL: 0x80541438..0x805414a8 -MARK_BINARY_BLOB(unk_80541438, 0x80541438, 0x805414a8); -asm UNKNOWN_FUNCTION(unk_80541438) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - stw r0, 0x24(r1); - mulli r0, r4, 0x1c; - stw r31, 0x1c(r1); - add r3, r3, r0; - stw r30, 0x18(r1); - addi r31, r3, 0x158; - mr r30, r6; - stw r29, 0x14(r1); - mr r29, r5; - mr r3, r31; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - beq lbl_80541488; - mr r3, r31; - mr r4, r29; - mr r5, r30; - bl getFile__Q26System15MultiDvdArchiveFPCcPUl; - b lbl_8054148c; -lbl_80541488: - li r3, 0; -lbl_8054148c: - lwz r0, 0x24(r1); - lwz r31, 0x1c(r1); - lwz r30, 0x18(r1); - lwz r29, 0x14(r1); - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on +void* ResourceManager::getMultiFile3(u16 idx, const char* filename, + size_t* size) { + return this->multiArchives3[idx].isLoaded() + ? this->multiArchives3[idx].getFile(filename, size) + : nullptr; } +} // namespace System // Symbol: ResourceManager_loadBSP // PAL: 0x805414a8..0x8054155c @@ -788,80 +723,30 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadBSP) { } namespace System { - void* ResourceManager::getFileCopy(s32 archiveIdx, char* filename, EGG::Heap* heap, size_t* size, s8 param_5) { - return (!dvdArchive[archiveIdx].isLoaded()) + return (!dvdArchives[archiveIdx].isLoaded()) ? 0 - : dvdArchive[archiveIdx].getFileCopy(filename, heap, size, - param_5); + : dvdArchives[archiveIdx].getFileCopy(filename, heap, size, + param_5); } -} // namespace System - -// Symbol: unk_805415b4 -// PAL: 0x805415b4..0x805415c4 -MARK_BINARY_BLOB(unk_805415b4, 0x805415b4, 0x805415c4); -asm UNKNOWN_FUNCTION(unk_805415b4) { - // clang-format off - nofralloc; - lwz r3, 4(r3); - slwi r0, r4, 2; - lwzx r3, r3, r0; - b isLoaded__Q26System15MultiDvdArchiveFv; - // clang-format on +bool ResourceManager::isMultiArchive1Loaded(int idx) { + return this->multiArchives1[idx]->isLoaded(); } -// Symbol: unk_805415c4 -// PAL: 0x805415c4..0x805415d4 -MARK_BINARY_BLOB(unk_805415c4, 0x805415c4, 0x805415d4); -asm UNKNOWN_FUNCTION(unk_805415c4) { - // clang-format off - nofralloc; - mulli r0, r4, 0x1c; - add r3, r3, r0; - addi r3, r3, 8; - b isLoaded__Q26System15MultiDvdArchiveFv; - // clang-format on +bool ResourceManager::isMultiArchive2Loaded(int idx) { + return this->multiArchives2[idx].isLoaded(); } -// Symbol: unk_805415d4 -// PAL: 0x805415d4..0x805415e4 -MARK_BINARY_BLOB(unk_805415d4, 0x805415d4, 0x805415e4); -asm UNKNOWN_FUNCTION(unk_805415d4) { - // clang-format off - nofralloc; - mulli r0, r4, 0x1c; - add r3, r3, r0; - addi r3, r3, 0x158; - b isLoaded__Q26System15MultiDvdArchiveFv; - // clang-format on +bool ResourceManager::isMultiArchive3Loaded(int idx) { + return this->multiArchives3[idx].isLoaded(); } -// Symbol: unk_805415e4 -// PAL: 0x805415e4..0x80541614 -MARK_BINARY_BLOB(unk_805415e4, 0x805415e4, 0x80541614); -asm UNKNOWN_FUNCTION(unk_805415e4) { - // clang-format off - nofralloc; - mulli r0, r4, 0x24; - li r4, 1; - add r3, r3, r0; - lwz r0, 0x2c8(r3); - cmpwi r0, 4; - beq lbl_8054160c; - lwz r0, 0x2c8(r3); - cmpwi r0, 5; - beq lbl_8054160c; - li r4, 0; -lbl_8054160c: - mr r3, r4; - blr; - // clang-format on +bool ResourceManager::isDvdArchiveLoaded(int idx) { + return this->dvdArchives[idx].isLoaded(); } -namespace System { - void* ResourceManager::getArchiveStart(ResourceChannelID resId, u32 archiveIdx) { if (!this->multiArchives1[resId]->isLoaded()) { @@ -927,52 +812,17 @@ asm UNKNOWN_FUNCTION(unk_8054169c) { // clang-format on } -// Symbol: unk_80541738 -// PAL: 0x80541738..0x80541794 -MARK_BINARY_BLOB(unk_80541738, 0x80541738, 0x80541794); -asm UNKNOWN_FUNCTION(unk_80541738) { - // clang-format off - nofralloc; - stwu r1, -0x10(r1); - mflr r0; - stw r0, 0x14(r1); - stw r31, 0xc(r1); - slwi r31, r4, 2; - stw r30, 8(r1); - mr r30, r3; - lwz r5, 4(r3); - lwzx r3, r5, r31; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - beq lbl_80541778; - lwz r3, 4(r30); - lwzx r3, r3, r31; - lhz r3, 8(r3); - b lbl_8054177c; -lbl_80541778: - li r3, 0; -lbl_8054177c: - lwz r0, 0x14(r1); - lwz r31, 0xc(r1); - lwz r30, 8(r1); - mtlr r0; - addi r1, r1, 0x10; - blr; - // clang-format on +namespace System { +u16 ResourceManager::getLoadedArchiveCount(int idx) { + return this->multiArchives1[idx]->isLoaded() + ? this->multiArchives1[idx]->archiveCount + : 0; } -// Symbol: ResourceManager_getMenuArchiveCount -// PAL: 0x80541794..0x805417a4 -MARK_BINARY_BLOB(ResourceManager_getMenuArchiveCount, 0x80541794, 0x805417a4); -asm UNKNOWN_FUNCTION(ResourceManager_getMenuArchiveCount) { - // clang-format off - nofralloc; - lwz r3, 4(r3); - lwz r3, 8(r3); - lhz r3, 8(r3); - blr; - // clang-format on +u16 ResourceManager::getMenuArchiveCount() { + return this->multiArchives1[2]->archiveCount; } +} // namespace System // Symbol: unk_805417a4 // PAL: 0x805417a4..0x80541878 @@ -1150,6 +1000,10 @@ asm UNKNOWN_FUNCTION(ResourceManager_preloadCourseTask) { b unk_80541b58; // clang-format on } +/*namespace System { +void ResourceManager::preloadCourseTask(u32 courseId) { +ResourceManager::spInstance->courseCache.load(courseId); } +}*/ // Symbol: ResourceManager_preloadCourseAsync // PAL: 0x805419ac..0x805419c8 diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 72bc38512..a8c75909f 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -257,7 +257,7 @@ class ResourceManager { MultiDvdArchive** multiArchives1; MultiDvdArchive multiArchives2[12]; MultiDvdArchive multiArchives3[12]; - DvdArchive dvdArchive[4]; + DvdArchive dvdArchives[4]; JobContext jobContexts[7]; EGG::TaskThread* taskThread; CourseCache courseCache; @@ -316,8 +316,19 @@ class ResourceManager { void* getFile(s32 archiveIdx, const char* filename, size_t* size); void* getCharacterFile(CharacterId characterId, size_t* size); void* getVehicleFile(s32 archiveIdx, VehicleId vehicleId, size_t* size); + // TODO: Better name + void* getMultiFile2(u16 idx, const char* filename, size_t* size); + void* getMultiFile3(u16 idx, const char* filename, size_t* size); void* getFileCopy(s32 archiveIdx, char* filename, EGG::Heap* heap, size_t* size, s8 param_5); + // TODO: Better names + bool isMultiArchive1Loaded(int idx); + bool isMultiArchive2Loaded(int idx); + bool isMultiArchive3Loaded(int idx); + bool isDvdArchiveLoaded(int idx); + u16 getLoadedArchiveCount(int idx); + u16 getMenuArchiveCount(); + // static void preloadCourseTask(u32 courseId); void process(); static void doLoadTask(void* jobContext); void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, From f5657a713d7f07eb7e76bd950404fe53f2ee2169 Mon Sep 17 00:00:00 2001 From: vabold Date: Tue, 28 Jun 2022 19:10:33 -0400 Subject: [PATCH 27/46] ResourceManager: cleanup --- source/game/system/ResourceManager.cpp | 78 ++++++++++++++------------ source/game/system/ResourceManager.hpp | 18 +++--- 2 files changed, 51 insertions(+), 45 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index f39cd9bf8..20fda91be 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -392,7 +392,7 @@ MultiDvdArchive* ResourceManager::load(ResourceChannelID channelId, filename = RESOURCES[channelId]; } - if (!multiArchives1[channelId]->isLoaded() && filename[0]) { + if (!isMultiArchive1Loaded(channelId) && filename[0]) { requestLoad(0, this->multiArchives1[channelId], filename, archiveHeap); } @@ -401,7 +401,7 @@ MultiDvdArchive* ResourceManager::load(ResourceChannelID channelId, DvdArchive* ResourceManager::loadSystemResource(s32 idx, EGG::Heap* archiveHeap) { - if (!dvdArchives[idx].isLoaded()) { + if (!isDvdArchiveLoaded(idx)) { const char* resourcePath = Resource::GetResourcePath((eSystemResource)idx); if (resourcePath[0] != 0) { requestLoadFile( @@ -414,7 +414,7 @@ DvdArchive* ResourceManager::loadSystemResource(s32 idx, MultiDvdArchive* ResourceManager::loadUI(const char* filename, EGG::Heap* archiveHeap) { - if (!this->multiArchives1[2]->isLoaded() && filename) { + if (!isMultiArchive1Loaded(2) && filename) { requestLoad(1, this->multiArchives1[2], filename, archiveHeap); } return this->multiArchives1[2]; @@ -425,7 +425,7 @@ MultiDvdArchive* ResourceManager::loadCourse(CourseId courseId, bool splitScreen) { char courseName[128]; - if (!this->multiArchives1[1]->isLoaded()) { + if (!isMultiArchive1Loaded(1)) { this->multiArchives1[1]->init(); if (!splitScreen && this->courseCache.mState == 2 && courseId == this->courseCache.mCourseId) { @@ -456,7 +456,7 @@ MultiDvdArchive* ResourceManager::loadMission(CourseId courseId, s32 missionNum, char missionPath[128]; char courseName[128]; - if (!this->multiArchives1[1]->isLoaded()) { + if (!isMultiArchive1Loaded(1)) { this->multiArchives1[1]->init(); snprintf(missionPath, sizeof(missionPath), "Race/MissionRun/mr%02d.szs", missionNum); @@ -495,7 +495,7 @@ MultiDvdArchive* ResourceManager::loadCompetition(CourseId courseId, char competitionPath[128]; char courseName[128]; - if (!this->multiArchives1[1]->isLoaded()) { + if (!isMultiArchive1Loaded(1)) { this->multiArchives1[1]->init(); u16 objCount = 1; @@ -591,7 +591,7 @@ MultiDvdArchive* ResourceManager::loadMenuKartModel(s32 archiveIdx, const char* characterName; char buffer[128]; - if (!multiArchives2[archiveIdx].isLoaded()) { + if (!isMultiArchive2Loaded(archiveIdx)) { if (battleTeam == 2) { // not in battle mode characterName = getCharacterName(characterId); snprintf(buffer, sizeof(buffer), "Scene/Model/Kart/%s-allkart", @@ -618,7 +618,7 @@ void ResourceManager::unmountArchive(s32 archiveIdx) { void* ResourceManager::getFile(s32 archiveIdx, const char* filename, size_t* size) { - return (multiArchives1[archiveIdx]->isLoaded()) + return isMultiArchive1Loaded(archiveIdx) ? multiArchives1[archiveIdx]->getFile(filename, size) : nullptr; } @@ -626,7 +626,7 @@ void* ResourceManager::getFile(s32 archiveIdx, const char* filename, void* ResourceManager::getCharacterFile(CharacterId characterId, size_t* size) { char buffer[128]; - if (!multiArchives1[6]->isLoaded()) { + if (!isMultiArchive1Loaded(6)) { return nullptr; } const char* character = getCharacterName(characterId); @@ -639,7 +639,7 @@ void* ResourceManager::getVehicleFile(s32 archiveIdx, VehicleId vehicleId, size_t* size) { char buffer[128]; - if (!multiArchives2[archiveIdx].isLoaded()) { + if (!isMultiArchive2Loaded(archiveIdx)) { return nullptr; } const char* vehicle = getVehicleName(vehicleId); @@ -648,16 +648,16 @@ void* ResourceManager::getVehicleFile(s32 archiveIdx, VehicleId vehicleId, return multiArchives2[archiveIdx].getFile(buffer, size); } -void* ResourceManager::getMultiFile2(u16 idx, const char* filename, +void* ResourceManager::getMultiFile2(s32 idx, const char* filename, size_t* size) { - return this->multiArchives2[idx].isLoaded() + return isMultiArchive2Loaded(idx) ? this->multiArchives2[idx].getFile(filename, size) : nullptr; } -void* ResourceManager::getMultiFile3(u16 idx, const char* filename, +void* ResourceManager::getMultiFile3(s32 idx, const char* filename, size_t* size) { - return this->multiArchives3[idx].isLoaded() + return isMultiArchive3Loaded(idx) ? this->multiArchives3[idx].getFile(filename, size) : nullptr; } @@ -666,6 +666,7 @@ void* ResourceManager::getMultiFile3(u16 idx, const char* filename, // Symbol: ResourceManager_loadBSP // PAL: 0x805414a8..0x8054155c // Notes: requires Racedata decomp + MARK_BINARY_BLOB(ResourceManager_loadBSP, 0x805414a8, 0x8054155c); asm UNKNOWN_FUNCTION(ResourceManager_loadBSP) { // clang-format off @@ -723,33 +724,33 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadBSP) { } namespace System { + void* ResourceManager::getFileCopy(s32 archiveIdx, char* filename, EGG::Heap* heap, size_t* size, s8 param_5) { - return (!dvdArchives[archiveIdx].isLoaded()) - ? 0 - : dvdArchives[archiveIdx].getFileCopy(filename, heap, size, - param_5); + return !isDvdArchiveLoaded(archiveIdx) ? nullptr + : dvdArchives[archiveIdx].getFileCopy( + filename, heap, size, param_5); } -bool ResourceManager::isMultiArchive1Loaded(int idx) { +bool ResourceManager::isMultiArchive1Loaded(s32 idx) { return this->multiArchives1[idx]->isLoaded(); } -bool ResourceManager::isMultiArchive2Loaded(int idx) { +bool ResourceManager::isMultiArchive2Loaded(s32 idx) { return this->multiArchives2[idx].isLoaded(); } -bool ResourceManager::isMultiArchive3Loaded(int idx) { +bool ResourceManager::isMultiArchive3Loaded(s32 idx) { return this->multiArchives3[idx].isLoaded(); } -bool ResourceManager::isDvdArchiveLoaded(int idx) { +bool ResourceManager::isDvdArchiveLoaded(s32 idx) { return this->dvdArchives[idx].isLoaded(); } void* ResourceManager::getArchiveStart(ResourceChannelID resId, u32 archiveIdx) { - if (!this->multiArchives1[resId]->isLoaded()) { + if (!isMultiArchive1Loaded(resId)) { return nullptr; } else if (archiveIdx < this->multiArchives1[resId]->archiveCount) { return this->multiArchives1[resId]->archives[archiveIdx].mArchiveStart; @@ -813,15 +814,16 @@ asm UNKNOWN_FUNCTION(unk_8054169c) { } namespace System { -u16 ResourceManager::getLoadedArchiveCount(int idx) { - return this->multiArchives1[idx]->isLoaded() - ? this->multiArchives1[idx]->archiveCount - : 0; + +u16 ResourceManager::getLoadedArchiveCount(s32 idx) { + return isMultiArchive1Loaded(idx) ? this->multiArchives1[idx]->archiveCount + : 0; } u16 ResourceManager::getMenuArchiveCount() { return this->multiArchives1[2]->archiveCount; } + } // namespace System // Symbol: unk_805417a4 @@ -987,6 +989,15 @@ asm UNKNOWN_FUNCTION(ResourceManager_attachLayoutDir) { // clang-format on } +#ifdef NON_MATCHING +namespace System { + +void ResourceManager::preloadCourseTask(u32 courseId) { + ResourceManager::spInstance->courseCache.load(courseId); +} + +} // namespace System +#else // Symbol: ResourceManager_preloadCourseTask // PAL: 0x80541998..0x805419ac MARK_BINARY_BLOB(ResourceManager_preloadCourseTask, 0x80541998, 0x805419ac); @@ -1000,10 +1011,7 @@ asm UNKNOWN_FUNCTION(ResourceManager_preloadCourseTask) { b unk_80541b58; // clang-format on } -/*namespace System { -void ResourceManager::preloadCourseTask(u32 courseId) { -ResourceManager::spInstance->courseCache.load(courseId); } -}*/ +#endif // Symbol: ResourceManager_preloadCourseAsync // PAL: 0x805419ac..0x805419c8 @@ -1024,11 +1032,11 @@ asm UNKNOWN_FUNCTION(ResourceManager_preloadCourseAsync) { namespace System { const char* getCharacterName(CharacterId charId) { - return (charId >= CHAR_NAMES_SIZE) ? nullptr : CHARACTER_NAMES[charId]; + return charId >= CHAR_NAMES_SIZE ? nullptr : CHARACTER_NAMES[charId]; } const char* getVehicleName(VehicleId vehicleId) { - return (vehicleId >= VEHICLE_NAMES_SIZE) ? nullptr : VEHICLE_NAMES[vehicleId]; + return vehicleId >= VEHICLE_NAMES_SIZE ? nullptr : VEHICLE_NAMES[vehicleId]; } CourseCache::CourseCache() { @@ -1067,11 +1075,9 @@ void CourseCache::load(s32 courseId) { } mState = 1; - snprintf(buffer, sizeof(buffer), "Race/Course/%s", TRACK_NAMES[mCourseId]); + snprintf(buffer, sizeof(buffer), "Race/Course/%s", COURSE_NAMES[mCourseId]); mArchive->rip(buffer, mHeap); - // something is wrong - this matches but requires rippedArchiveCount() to - // return s32, which almost certainly breaks MultiDvdArchive if ((u16)mArchive->rippedArchiveCount()) { mState = 2; } else { diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index a8c75909f..fe83c74a0 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -201,7 +201,7 @@ class CourseCache : EGG::Disposer { CourseCache(); void init(); virtual ~CourseCache(); - void load(u32 courseId); + void load(s32 courseId); void loadOther(MultiDvdArchive* other, EGG::Heap* heap); // private: // idk if rii prefers to befriend every class over public-ing @@ -317,18 +317,18 @@ class ResourceManager { void* getCharacterFile(CharacterId characterId, size_t* size); void* getVehicleFile(s32 archiveIdx, VehicleId vehicleId, size_t* size); // TODO: Better name - void* getMultiFile2(u16 idx, const char* filename, size_t* size); - void* getMultiFile3(u16 idx, const char* filename, size_t* size); + void* getMultiFile2(s32 idx, const char* filename, size_t* size); + void* getMultiFile3(s32 idx, const char* filename, size_t* size); void* getFileCopy(s32 archiveIdx, char* filename, EGG::Heap* heap, size_t* size, s8 param_5); // TODO: Better names - bool isMultiArchive1Loaded(int idx); - bool isMultiArchive2Loaded(int idx); - bool isMultiArchive3Loaded(int idx); - bool isDvdArchiveLoaded(int idx); - u16 getLoadedArchiveCount(int idx); + bool isMultiArchive1Loaded(s32 idx); + bool isMultiArchive2Loaded(s32 idx); + bool isMultiArchive3Loaded(s32 idx); + bool isDvdArchiveLoaded(s32 idx); + u16 getLoadedArchiveCount(s32 idx); u16 getMenuArchiveCount(); - // static void preloadCourseTask(u32 courseId); + // static void preloadCourseTask(s32 courseId); void process(); static void doLoadTask(void* jobContext); void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, From 82e6b49b0e7e8e7f0d7ca31a5fd6a45a776b9182 Mon Sep 17 00:00:00 2001 From: Aiden Date: Wed, 29 Jun 2022 03:08:36 -0400 Subject: [PATCH 28/46] ResourceManager: clear --- source/game/system/ResourceManager.cpp | 70 ++++---------------------- source/game/system/ResourceManager.hpp | 24 ++++++++- 2 files changed, 34 insertions(+), 60 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 20fda91be..18cba69a0 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -1763,67 +1763,19 @@ asm UNKNOWN_FUNCTION(unk_805422cc) { // clang-format on } -// Symbol: unk_805423bc -// PAL: 0x805423bc..0x8054247c -MARK_BINARY_BLOB(unk_805423bc, 0x805423bc, 0x8054247c); -asm UNKNOWN_FUNCTION(unk_805423bc) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - stw r0, 0x24(r1); - stmw r26, 8(r1); - mr r26, r3; - li r27, 0; - li r31, 0; -lbl_805423d8: - clrlwi r0, r27, 0x18; - mulli r3, r0, 0x18; - add r28, r26, r3; - mulli r0, r0, 0x1c; - lwz r30, 0x5b0(r28); - add r3, r26, r0; - addi r29, r3, 8; - mr r3, r29; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - beq lbl_8054240c; - mr r3, r29; - bl unmount__Q26System15MultiDvdArchiveFv; -lbl_8054240c: - cmpwi r30, 0; - beq lbl_80542428; - lwz r12, 0(r30); - mr r3, r30; - lwz r12, 0x1c(r12); - mtctr r12; - bctrl; -lbl_80542428: - lwz r0, 0x5b8(r28); - cmpwi r0, 3; - beq lbl_80542440; - stw r31, 0x5b0(r28); - stw r31, 0x5b4(r28); - stw r31, 0x5b8(r28); -lbl_80542440: - addi r27, r27, 1; - cmplwi r27, 4; - blt lbl_805423d8; - lwz r3, 0x610(r26); - lwz r12, 0(r3); - lwz r12, 0x1c(r12); - mtctr r12; - bctrl; - li r0, 0; - stw r0, 0x610(r26); - lmw r26, 8(r1); - lwz r0, 0x24(r1); - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on +namespace System { + +void ResourceManager::clear() { + for (u8 i = 0; i < 4; i++) { + clear(i); + } + + this->_610->destroy(); + this->_610 = nullptr; } +} // namespace System + // Symbol: unk_8054247c // PAL: 0x8054247c..0x8054248c MARK_BINARY_BLOB(unk_8054247c, 0x8054247c, 0x8054248c); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index fe83c74a0..d59f33f74 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -186,6 +186,7 @@ struct T { }; class MenuCharacterManager : S, T { +friend class ResourceManager; public: MenuCharacterManager() { mCharacter = 0; @@ -261,7 +262,7 @@ class ResourceManager { JobContext jobContexts[7]; EGG::TaskThread* taskThread; CourseCache courseCache; - MenuCharacterManager menuCharacterManager[4]; + MenuCharacterManager menuManagers[4]; bool isGlobeLoadingBusy; bool _60d; // these variables don't have names yet, but are used EGG::ExpHeap* _610; @@ -329,6 +330,7 @@ class ResourceManager { u16 getLoadedArchiveCount(s32 idx); u16 getMenuArchiveCount(); // static void preloadCourseTask(s32 courseId); + void clear(); void process(); static void doLoadTask(void* jobContext); void requestLoad(s32 idx, MultiDvdArchive* m, const char* p, @@ -370,6 +372,26 @@ class ResourceManager { OSSleepMilliseconds(16); } } + inline void clear(s32 i) { + MultiDvdArchive* archive; + EGG::ExpHeap* heap; + + heap = menuManagers[i].mHeap1; + archive = &multiArchives2[i]; + + if (archive->isLoaded()) { + archive->unmount(); + } + if (heap) { + heap->destroy(); + } + + if (menuManagers[i]._unk != 3) { + menuManagers[i].mHeap1 = 0; + menuManagers[i].mHeap2 = 0; + menuManagers[i]._unk = 0; + } + } }; } // namespace System From 5dae6ae2890f058bbb5da5f239f9fffbe95bc113 Mon Sep 17 00:00:00 2001 From: vabold Date: Wed, 29 Jun 2022 04:52:28 -0400 Subject: [PATCH 29/46] ResourceManager: getBspFile, CourseCache: load --- pack/rel_objects.txt | 2 +- pack/rel_slices.csv | 2 +- pack/symbols.txt | 2 +- source/game/system/RaceConfig.hpp | 28 +++++++++ source/game/system/ResourceManager.cpp | 87 ++++---------------------- source/game/system/ResourceManager.hpp | 8 ++- 6 files changed, 48 insertions(+), 81 deletions(-) create mode 100644 source/game/system/RaceConfig.hpp diff --git a/pack/rel_objects.txt b/pack/rel_objects.txt index dbc9eb740..99861d84d 100644 --- a/pack/rel_objects.txt +++ b/pack/rel_objects.txt @@ -21,7 +21,7 @@ out/rel/rodata_8088fe28_80890490.o out/rel/data_808b31e8_808b3960.o out/ResourceManager.o out/rel/text_80542878_80555464.o -out/rel/rodata_80890c20_80891370.o +out/rel/rodata_80890c3b_80891370.o out/rel/data_808b3c2c_808b42e0.o out/Random.o out/rel/text_8055572c_80590128.o diff --git a/pack/rel_slices.csv b/pack/rel_slices.csv index 2aa9e543b..62bce9b0c 100644 --- a/pack/rel_slices.csv +++ b/pack/rel_slices.csv @@ -4,7 +4,7 @@ enabled,name,textStart,textEnd,ctorsStart,ctorsEnd,dtorsStart,dtorsEnd,rodataSta 1,source/game/system/GhostFile.cpp,0x8051c088,0x8051d4d4,,,,,,,0x808b2d38,0x808b2d50,, 1,source/game/system/LocalizedArchive.cpp,0x8052a098,0x8052a538,,,,,0x8088fdc0,0x8088fe00,0x808b3188,0x808b31d8,, 1,source/game/system/MultiDvdArchive.cpp,0x8052a538,0x8052ae5c,,,,,0x8088fe00,0x8088fe28,0x808b31d8,0x808b31e8,, -1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890c20,0x808b3960,0x808b3c2c,, +1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890c3b,0x808b3960,0x808b3c2c,, 1,source/game/util/Random.cpp,0x80555464,0x8055572c,,,,,0x80891370,0x80891380,0x808b42e0,0x808b42ec,, 1,source/game/kart/KartComponent.cpp,0x80590128,0x805901d0,,,,,,,,,0x809c1900,0x809c1910 1,source/game/ui/ControlGroup.cpp,0x805c23e4,0x805c2c18,,,,,,,,,, diff --git a/pack/symbols.txt b/pack/symbols.txt index 688ac11cf..becaf89ff 100644 --- a/pack/symbols.txt +++ b/pack/symbols.txt @@ -10012,7 +10012,7 @@ 0x80541a10 unk_80541a10 0x80541a70 unk_80541a70 0x80541ac4 unk_80541ac4 -0x80541b58 unk_80541b58 +0x80541b58 load__Q26System11CourseCacheFl 0x80541c18 unk_80541c18 0x80541c38 unk_80541c38 0x80541c48 unk_80541c48 diff --git a/source/game/system/RaceConfig.hpp b/source/game/system/RaceConfig.hpp new file mode 100644 index 000000000..af43b2843 --- /dev/null +++ b/source/game/system/RaceConfig.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include + +struct RaceConfigPlayer { + u8 _00[0x08 - 0x00]; + u32 vehicleId; + u32 characterId; + u32 type; + u8 _14[0xd0 - 0x14]; + s32 controllerId; + u8 _d4[0xf0 - 0xd4]; +}; + +struct RaceConfigScenario { + u8 _000[0x004 - 0x000]; + u8 playerCount; + u8 _005[0x008 - 0x005]; + RaceConfigPlayer players[12]; + // ... +}; + +struct RaceConfig { + static RaceConfig* spInstance; + u8 _0000[0x0020 - 0x0000]; + RaceConfigScenario raceScenario; + // ... +}; \ No newline at end of file diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 18cba69a0..921359dbf 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -661,12 +661,18 @@ void* ResourceManager::getMultiFile3(s32 idx, const char* filename, ? this->multiArchives3[idx].getFile(filename, size) : nullptr; } -} // namespace System -// Symbol: ResourceManager_loadBSP -// PAL: 0x805414a8..0x8054155c -// Notes: requires Racedata decomp +void* ResourceManager::getBspFile(s32 playerIdx, size_t* size) { + char buffer[32]; + + const char* vehicle = getVehicleName((VehicleId)RaceConfig::spInstance->raceScenario.players[playerIdx].vehicleId); + snprintf(buffer, sizeof(buffer), "/bsp/%s.bsp", vehicle); + + return (isMultiArchive1Loaded(0)) ? multiArchives1[0]->getFile(buffer, size) : nullptr; +} +} // namespace System +/* #else MARK_BINARY_BLOB(ResourceManager_loadBSP, 0x805414a8, 0x8054155c); asm UNKNOWN_FUNCTION(ResourceManager_loadBSP) { // clang-format off @@ -722,6 +728,7 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadBSP) { blr; // clang-format on } +#endif */ namespace System { @@ -1008,7 +1015,7 @@ asm UNKNOWN_FUNCTION(ResourceManager_preloadCourseTask) { mr r4, r3; lwz r3, 0(r5); addi r3, r3, 0x588; - b unk_80541b58; + b load__Q26System11CourseCacheFl; // clang-format on } #endif @@ -1059,11 +1066,6 @@ CourseCache::~CourseCache() { } } -} // namespace System - -#ifdef NON_MATCHING // requires rodata to work -namespace System { - void CourseCache::load(s32 courseId) { if (!mHeap) return; @@ -1086,71 +1088,6 @@ void CourseCache::load(s32 courseId) { } } -} // namespace System -#else -// Symbol: unk_80541b58 -// PAL: 0x80541b58..0x80541c18 -MARK_BINARY_BLOB(unk_80541b58, 0x80541b58, 0x80541c18); -asm UNKNOWN_FUNCTION(unk_80541b58) { - // clang-format off - nofralloc; - stwu r1, -0x90(r1); - mflr r0; - stw r0, 0x94(r1); - stw r31, 0x8c(r1); - mr r31, r3; - lwz r0, 0x14(r3); - cmpwi r0, 0; - beq lbl_80541c04; - lwz r0, 0x1c(r3); - stw r4, 0x18(r3); - cmpwi r0, 2; - bne lbl_80541b90; - lwz r3, 0x20(r3); - bl clear__Q26System15MultiDvdArchiveFv; -lbl_80541b90: - lwz r0, 0x18(r31); - li r3, 1; - lis r4, 0; - stw r3, 0x1c(r31); - lis r5, 0; - slwi r0, r0, 2; - addi r4, r4, 0; - addi r3, r1, 8; - addi r5, r5, 0; - lwzx r6, r4, r0; - addi r5, r5, 0x12c; - li r4, 0x80; - crclr 6; - bl unk_805553b0; - lwz r3, 0x20(r31); - addi r4, r1, 8; - lwz r5, 0x14(r31); - bl rip__Q26System15MultiDvdArchiveFPCcPQ23EGG4Heap; - lwz r3, 0x20(r31); - bl rippedArchiveCount__Q26System15MultiDvdArchiveFv; - clrlwi. r0, r3, 0x10; - beq lbl_80541bf4; - li r0, 2; - stw r0, 0x1c(r31); - b lbl_80541c04; -lbl_80541bf4: - lwz r3, 0x20(r31); - bl clear__Q26System15MultiDvdArchiveFv; - li r0, 0; - stw r0, 0x1c(r31); -lbl_80541c04: - lwz r0, 0x94(r1); - lwz r31, 0x8c(r1); - mtlr r0; - addi r1, r1, 0x90; - blr; - // clang-format on -} -#endif - -namespace System { - void CourseCache::loadOther(MultiDvdArchive* other, EGG::Heap* heap) { if (mState != 2) return; diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index d59f33f74..e8ce888eb 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { #endif @@ -114,7 +115,7 @@ UNKNOWN_FUNCTION(unk_80541a70); // PAL: 0x80541ac4..0x80541b58 UNKNOWN_FUNCTION(unk_80541ac4); // PAL: 0x80541b58..0x80541c18 -UNKNOWN_FUNCTION(unk_80541b58); +UNKNOWN_FUNCTION(load__Q26System11CourseCacheFl); // PAL: 0x80541c18..0x80541c38 UNKNOWN_FUNCTION(unk_80541c18); // PAL: 0x80541c38..0x80541c48 @@ -278,7 +279,7 @@ class ResourceManager { _614 = 0; isGlobeLoadingBusy = false; } - + MultiDvdArchive* load(ResourceChannelID channelId, EGG::Heap* archiveHeap, const char* filename); DvdArchive* loadSystemResource(s32 idx, EGG::Heap* archiveHeap); @@ -320,6 +321,7 @@ class ResourceManager { // TODO: Better name void* getMultiFile2(s32 idx, const char* filename, size_t* size); void* getMultiFile3(s32 idx, const char* filename, size_t* size); + void* getBspFile(s32 playerIdx, size_t* size); void* getFileCopy(s32 archiveIdx, char* filename, EGG::Heap* heap, size_t* size, s8 param_5); // TODO: Better names @@ -329,7 +331,7 @@ class ResourceManager { bool isDvdArchiveLoaded(s32 idx); u16 getLoadedArchiveCount(s32 idx); u16 getMenuArchiveCount(); - // static void preloadCourseTask(s32 courseId); + static void preloadCourseTask(s32 courseId); void clear(); void process(); static void doLoadTask(void* jobContext); From 04a9cb2b5d770ce8466d68eac93332b6149f5dc3 Mon Sep 17 00:00:00 2001 From: vabold Date: Wed, 29 Jun 2022 04:52:28 -0400 Subject: [PATCH 30/46] ResourceManager: getBspFile, CourseCache: load --- pack/rel_objects.txt | 2 +- pack/rel_slices.csv | 2 +- pack/symbols.txt | 2 +- source/game/system/RaceConfig.hpp | 28 +++++ source/game/system/ResourceManager.cpp | 137 +++++-------------------- source/game/system/ResourceManager.hpp | 44 ++++---- 6 files changed, 82 insertions(+), 133 deletions(-) create mode 100644 source/game/system/RaceConfig.hpp diff --git a/pack/rel_objects.txt b/pack/rel_objects.txt index dbc9eb740..99861d84d 100644 --- a/pack/rel_objects.txt +++ b/pack/rel_objects.txt @@ -21,7 +21,7 @@ out/rel/rodata_8088fe28_80890490.o out/rel/data_808b31e8_808b3960.o out/ResourceManager.o out/rel/text_80542878_80555464.o -out/rel/rodata_80890c20_80891370.o +out/rel/rodata_80890c3b_80891370.o out/rel/data_808b3c2c_808b42e0.o out/Random.o out/rel/text_8055572c_80590128.o diff --git a/pack/rel_slices.csv b/pack/rel_slices.csv index 2aa9e543b..62bce9b0c 100644 --- a/pack/rel_slices.csv +++ b/pack/rel_slices.csv @@ -4,7 +4,7 @@ enabled,name,textStart,textEnd,ctorsStart,ctorsEnd,dtorsStart,dtorsEnd,rodataSta 1,source/game/system/GhostFile.cpp,0x8051c088,0x8051d4d4,,,,,,,0x808b2d38,0x808b2d50,, 1,source/game/system/LocalizedArchive.cpp,0x8052a098,0x8052a538,,,,,0x8088fdc0,0x8088fe00,0x808b3188,0x808b31d8,, 1,source/game/system/MultiDvdArchive.cpp,0x8052a538,0x8052ae5c,,,,,0x8088fe00,0x8088fe28,0x808b31d8,0x808b31e8,, -1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890c20,0x808b3960,0x808b3c2c,, +1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890c3b,0x808b3960,0x808b3c2c,, 1,source/game/util/Random.cpp,0x80555464,0x8055572c,,,,,0x80891370,0x80891380,0x808b42e0,0x808b42ec,, 1,source/game/kart/KartComponent.cpp,0x80590128,0x805901d0,,,,,,,,,0x809c1900,0x809c1910 1,source/game/ui/ControlGroup.cpp,0x805c23e4,0x805c2c18,,,,,,,,,, diff --git a/pack/symbols.txt b/pack/symbols.txt index 688ac11cf..becaf89ff 100644 --- a/pack/symbols.txt +++ b/pack/symbols.txt @@ -10012,7 +10012,7 @@ 0x80541a10 unk_80541a10 0x80541a70 unk_80541a70 0x80541ac4 unk_80541ac4 -0x80541b58 unk_80541b58 +0x80541b58 load__Q26System11CourseCacheFl 0x80541c18 unk_80541c18 0x80541c38 unk_80541c38 0x80541c48 unk_80541c48 diff --git a/source/game/system/RaceConfig.hpp b/source/game/system/RaceConfig.hpp new file mode 100644 index 000000000..af43b2843 --- /dev/null +++ b/source/game/system/RaceConfig.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include + +struct RaceConfigPlayer { + u8 _00[0x08 - 0x00]; + u32 vehicleId; + u32 characterId; + u32 type; + u8 _14[0xd0 - 0x14]; + s32 controllerId; + u8 _d4[0xf0 - 0xd4]; +}; + +struct RaceConfigScenario { + u8 _000[0x004 - 0x000]; + u8 playerCount; + u8 _005[0x008 - 0x005]; + RaceConfigPlayer players[12]; + // ... +}; + +struct RaceConfig { + static RaceConfig* spInstance; + u8 _0000[0x0020 - 0x0000]; + RaceConfigScenario raceScenario; + // ... +}; \ No newline at end of file diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 18cba69a0..548acf32e 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -661,12 +661,21 @@ void* ResourceManager::getMultiFile3(s32 idx, const char* filename, ? this->multiArchives3[idx].getFile(filename, size) : nullptr; } -} // namespace System -// Symbol: ResourceManager_loadBSP -// PAL: 0x805414a8..0x8054155c -// Notes: requires Racedata decomp +void* ResourceManager::getBspFile(s32 playerIdx, size_t* size) { + char buffer[32]; + + const char* vehicle = getVehicleName( + (VehicleId)RaceConfig::spInstance->raceScenario.players[playerIdx] + .vehicleId); + snprintf(buffer, sizeof(buffer), "/bsp/%s.bsp", vehicle); + + return (isMultiArchive1Loaded(0)) ? multiArchives1[0]->getFile(buffer, size) + : nullptr; +} +} // namespace System +/* #else MARK_BINARY_BLOB(ResourceManager_loadBSP, 0x805414a8, 0x8054155c); asm UNKNOWN_FUNCTION(ResourceManager_loadBSP) { // clang-format off @@ -722,6 +731,7 @@ asm UNKNOWN_FUNCTION(ResourceManager_loadBSP) { blr; // clang-format on } +#endif */ namespace System { @@ -989,48 +999,25 @@ asm UNKNOWN_FUNCTION(ResourceManager_attachLayoutDir) { // clang-format on } -#ifdef NON_MATCHING +//#ifdef NON_MATCHING namespace System { -void ResourceManager::preloadCourseTask(u32 courseId) { - ResourceManager::spInstance->courseCache.load(courseId); -} - -} // namespace System -#else -// Symbol: ResourceManager_preloadCourseTask -// PAL: 0x80541998..0x805419ac -MARK_BINARY_BLOB(ResourceManager_preloadCourseTask, 0x80541998, 0x805419ac); -asm UNKNOWN_FUNCTION(ResourceManager_preloadCourseTask) { - // clang-format off - nofralloc; - lis r5, 0; - mr r4, r3; - lwz r3, 0(r5); - addi r3, r3, 0x588; - b unk_80541b58; - // clang-format on +// force not inline CourseCache::load +#ifdef __CWCC__ +#pragma dont_inline on +#endif +void preloadCourseTask(void* courseId) { + ResourceManager::spInstance->courseCache.load((CourseId)courseId); } +#ifdef __CWCC__ +#pragma dont_inline off #endif -// Symbol: ResourceManager_preloadCourseAsync -// PAL: 0x805419ac..0x805419c8 -MARK_BINARY_BLOB(ResourceManager_preloadCourseAsync, 0x805419ac, 0x805419c8); -asm UNKNOWN_FUNCTION(ResourceManager_preloadCourseAsync) { - // clang-format off - nofralloc; - lis r6, 0x1000; - lwz r3, 0x584(r3); - lis r7, 0; - mr r5, r4; - addi r4, r7, 0; - addi r6, r6, 2; - b unk_805553b0; - // clang-format on +void ResourceManager::preloadCourseAsync(CourseId courseId) { + this->taskThread->request(preloadCourseTask, (void*)courseId, + (void*)0x10000002); } -namespace System { - const char* getCharacterName(CharacterId charId) { return charId >= CHAR_NAMES_SIZE ? nullptr : CHARACTER_NAMES[charId]; } @@ -1059,12 +1046,7 @@ CourseCache::~CourseCache() { } } -} // namespace System - -#ifdef NON_MATCHING // requires rodata to work -namespace System { - -void CourseCache::load(s32 courseId) { +void CourseCache::load(CourseId courseId) { if (!mHeap) return; char buffer[128]; @@ -1086,71 +1068,6 @@ void CourseCache::load(s32 courseId) { } } -} // namespace System -#else -// Symbol: unk_80541b58 -// PAL: 0x80541b58..0x80541c18 -MARK_BINARY_BLOB(unk_80541b58, 0x80541b58, 0x80541c18); -asm UNKNOWN_FUNCTION(unk_80541b58) { - // clang-format off - nofralloc; - stwu r1, -0x90(r1); - mflr r0; - stw r0, 0x94(r1); - stw r31, 0x8c(r1); - mr r31, r3; - lwz r0, 0x14(r3); - cmpwi r0, 0; - beq lbl_80541c04; - lwz r0, 0x1c(r3); - stw r4, 0x18(r3); - cmpwi r0, 2; - bne lbl_80541b90; - lwz r3, 0x20(r3); - bl clear__Q26System15MultiDvdArchiveFv; -lbl_80541b90: - lwz r0, 0x18(r31); - li r3, 1; - lis r4, 0; - stw r3, 0x1c(r31); - lis r5, 0; - slwi r0, r0, 2; - addi r4, r4, 0; - addi r3, r1, 8; - addi r5, r5, 0; - lwzx r6, r4, r0; - addi r5, r5, 0x12c; - li r4, 0x80; - crclr 6; - bl unk_805553b0; - lwz r3, 0x20(r31); - addi r4, r1, 8; - lwz r5, 0x14(r31); - bl rip__Q26System15MultiDvdArchiveFPCcPQ23EGG4Heap; - lwz r3, 0x20(r31); - bl rippedArchiveCount__Q26System15MultiDvdArchiveFv; - clrlwi. r0, r3, 0x10; - beq lbl_80541bf4; - li r0, 2; - stw r0, 0x1c(r31); - b lbl_80541c04; -lbl_80541bf4: - lwz r3, 0x20(r31); - bl clear__Q26System15MultiDvdArchiveFv; - li r0, 0; - stw r0, 0x1c(r31); -lbl_80541c04: - lwz r0, 0x94(r1); - lwz r31, 0x8c(r1); - mtlr r0; - addi r1, r1, 0x90; - blr; - // clang-format on -} -#endif - -namespace System { - void CourseCache::loadOther(MultiDvdArchive* other, EGG::Heap* heap) { if (mState != 2) return; diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index d59f33f74..544dc6398 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { #endif @@ -114,7 +115,7 @@ UNKNOWN_FUNCTION(unk_80541a70); // PAL: 0x80541ac4..0x80541b58 UNKNOWN_FUNCTION(unk_80541ac4); // PAL: 0x80541b58..0x80541c18 -UNKNOWN_FUNCTION(unk_80541b58); +UNKNOWN_FUNCTION(load__Q26System11CourseCacheFl); // PAL: 0x80541c18..0x80541c38 UNKNOWN_FUNCTION(unk_80541c18); // PAL: 0x80541c38..0x80541c48 @@ -186,7 +187,8 @@ struct T { }; class MenuCharacterManager : S, T { -friend class ResourceManager; + friend class ResourceManager; + public: MenuCharacterManager() { mCharacter = 0; @@ -197,23 +199,6 @@ friend class ResourceManager; s32 mModelType; }; -class CourseCache : EGG::Disposer { -public: - CourseCache(); - void init(); - virtual ~CourseCache(); - void load(s32 courseId); - void loadOther(MultiDvdArchive* other, EGG::Heap* heap); - - // private: // idk if rii prefers to befriend every class over public-ing - // everything - void* mBuffer; - EGG::ExpHeap* mHeap; - s32 mCourseId; - s32 mState; - MultiDvdArchive* mArchive; -}; - // Enums that represent indices in vehicle name specifiers arrays. typedef enum { // TODO: Fill @@ -241,6 +226,24 @@ typedef enum { // TODO: Fill } CourseId; +class CourseCache : EGG::Disposer { +public: + CourseCache(); + void init(); + virtual ~CourseCache(); + void load(CourseId courseId); + void loadOther(MultiDvdArchive* other, EGG::Heap* heap); + + // private: // idk if rii prefers to befriend every class over public-ing + // everything + void* mBuffer; + EGG::ExpHeap* mHeap; + s32 mCourseId; + s32 mState; + MultiDvdArchive* mArchive; +}; + +void preloadCourseTask(void* courseId); const char* getCharacterName(CharacterId charId); const char* getVehicleName(VehicleId vehicleId); @@ -320,6 +323,7 @@ class ResourceManager { // TODO: Better name void* getMultiFile2(s32 idx, const char* filename, size_t* size); void* getMultiFile3(s32 idx, const char* filename, size_t* size); + void* getBspFile(s32 playerIdx, size_t* size); void* getFileCopy(s32 archiveIdx, char* filename, EGG::Heap* heap, size_t* size, s8 param_5); // TODO: Better names @@ -329,7 +333,7 @@ class ResourceManager { bool isDvdArchiveLoaded(s32 idx); u16 getLoadedArchiveCount(s32 idx); u16 getMenuArchiveCount(); - // static void preloadCourseTask(s32 courseId); + void preloadCourseAsync(CourseId courseId); void clear(); void process(); static void doLoadTask(void* jobContext); From 1e135a2c83fd61f6f55c7f40d6b0e4e632d40645 Mon Sep 17 00:00:00 2001 From: vabold Date: Thu, 30 Jun 2022 01:52:07 -0400 Subject: [PATCH 31/46] Unused: getNullString --- pack/rel_objects.txt | 2 +- pack/rel_slices.csv | 2 +- source/game/system/ResourceManager.cpp | 13 ++----------- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/pack/rel_objects.txt b/pack/rel_objects.txt index 99861d84d..b9f21b8ff 100644 --- a/pack/rel_objects.txt +++ b/pack/rel_objects.txt @@ -21,7 +21,7 @@ out/rel/rodata_8088fe28_80890490.o out/rel/data_808b31e8_808b3960.o out/ResourceManager.o out/rel/text_80542878_80555464.o -out/rel/rodata_80890c3b_80891370.o +out/rel/rodata_80890c3c_80891370.o out/rel/data_808b3c2c_808b42e0.o out/Random.o out/rel/text_8055572c_80590128.o diff --git a/pack/rel_slices.csv b/pack/rel_slices.csv index 62bce9b0c..2d836c67e 100644 --- a/pack/rel_slices.csv +++ b/pack/rel_slices.csv @@ -4,7 +4,7 @@ enabled,name,textStart,textEnd,ctorsStart,ctorsEnd,dtorsStart,dtorsEnd,rodataSta 1,source/game/system/GhostFile.cpp,0x8051c088,0x8051d4d4,,,,,,,0x808b2d38,0x808b2d50,, 1,source/game/system/LocalizedArchive.cpp,0x8052a098,0x8052a538,,,,,0x8088fdc0,0x8088fe00,0x808b3188,0x808b31d8,, 1,source/game/system/MultiDvdArchive.cpp,0x8052a538,0x8052ae5c,,,,,0x8088fe00,0x8088fe28,0x808b31d8,0x808b31e8,, -1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890c3b,0x808b3960,0x808b3c2c,, +1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890c3c,0x808b3960,0x808b3c2c,, 1,source/game/util/Random.cpp,0x80555464,0x8055572c,,,,,0x80891370,0x80891380,0x808b42e0,0x808b42ec,, 1,source/game/kart/KartComponent.cpp,0x80590128,0x805901d0,,,,,,,,,0x809c1900,0x809c1910 1,source/game/ui/ControlGroup.cpp,0x805c23e4,0x805c2c18,,,,,,,,,, diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index a8f650f10..f7cae7c1b 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -1076,17 +1076,8 @@ void CourseCache::loadOther(MultiDvdArchive* other, EGG::Heap* heap) { } // namespace System -// Symbol: unk_80541c38 -// PAL: 0x80541c38..0x80541c48 -MARK_BINARY_BLOB(unk_80541c38, 0x80541c38, 0x80541c48); -asm UNKNOWN_FUNCTION(unk_80541c38) { - // clang-format off - nofralloc; - lis r3, 0; - addi r3, r3, 0; - addi r3, r3, 0x13b; - blr; - // clang-format on +char* _unk_getNullString() { + return ""; } // Symbol: unk_80541c48 From 68115ce69379e1c73834d212f398d5377ce17ce0 Mon Sep 17 00:00:00 2001 From: vabold Date: Thu, 30 Jun 2022 02:35:10 -0400 Subject: [PATCH 32/46] ResourceManager: setArcResourceLink --- source/game/system/RaceConfig.hpp | 34 +++++------ source/game/system/ResourceManager.cpp | 78 +++++++------------------- source/game/system/ResourceManager.hpp | 4 +- 3 files changed, 41 insertions(+), 75 deletions(-) diff --git a/source/game/system/RaceConfig.hpp b/source/game/system/RaceConfig.hpp index af43b2843..30f756a36 100644 --- a/source/game/system/RaceConfig.hpp +++ b/source/game/system/RaceConfig.hpp @@ -3,26 +3,26 @@ #include struct RaceConfigPlayer { - u8 _00[0x08 - 0x00]; - u32 vehicleId; - u32 characterId; - u32 type; - u8 _14[0xd0 - 0x14]; - s32 controllerId; - u8 _d4[0xf0 - 0xd4]; + u8 _00[0x08 - 0x00]; + u32 vehicleId; + u32 characterId; + u32 type; + u8 _14[0xd0 - 0x14]; + s32 controllerId; + u8 _d4[0xf0 - 0xd4]; }; struct RaceConfigScenario { - u8 _000[0x004 - 0x000]; - u8 playerCount; - u8 _005[0x008 - 0x005]; - RaceConfigPlayer players[12]; - // ... + u8 _000[0x004 - 0x000]; + u8 playerCount; + u8 _005[0x008 - 0x005]; + RaceConfigPlayer players[12]; + // ... }; struct RaceConfig { - static RaceConfig* spInstance; - u8 _0000[0x0020 - 0x0000]; - RaceConfigScenario raceScenario; - // ... -}; \ No newline at end of file + static RaceConfig* spInstance; + u8 _0000[0x0020 - 0x0000]; + RaceConfigScenario raceScenario; + // ... +}; diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index f7cae7c1b..801d6b939 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -9,6 +9,8 @@ #pragma legacy_struct_alignment off extern RKScene* scenePtr; +extern void ArcResourceLink_set(void* arcResource, void* archiveStart, + const char* dirname); extern const char* EarthResourceListing; @@ -768,62 +770,26 @@ void* ResourceManager::getArchiveStart(ResourceChannelID resId, return nullptr; } -} // namespace System +bool ResourceManager::setArcResourceLink(s32 multiIdx, u32 archiveIdx, + void* arcResource, + const char* dirname) { + void* archiveStart; -// Symbol: unk_8054169c -// PAL: 0x8054169c..0x80541738 -MARK_BINARY_BLOB(unk_8054169c, 0x8054169c, 0x80541738); -asm UNKNOWN_FUNCTION(unk_8054169c) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - stw r0, 0x24(r1); - stmw r27, 0xc(r1); - slwi r31, r4, 2; - mr r27, r3; - mr r28, r5; - mr r29, r6; - mr r30, r7; - lwz r8, 4(r3); - lwzx r3, r8, r31; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_805416dc; - li r3, 0; - b lbl_80541724; -lbl_805416dc: - lwz r3, 4(r27); - lwzx r4, r3, r31; - lhz r0, 8(r4); - cmplw r28, r0; - bge lbl_80541720; - mr r3, r29; - bge lbl_8054170c; - mulli r0, r28, 0x24; - lwz r4, 4(r4); - add r4, r4, r0; - lwz r4, 8(r4); - b lbl_80541710; -lbl_8054170c: - li r4, 0; -lbl_80541710: - mr r5, r30; - bl unk_805553b0; - li r3, 1; - b lbl_80541724; -lbl_80541720: - li r3, 0; -lbl_80541724: - lmw r27, 0xc(r1); - lwz r0, 0x24(r1); - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on -} + if (!multiArchives1[multiIdx]->isLoaded()) { + return false; + } -namespace System { + if (archiveIdx < multiArchives1[multiIdx]->archiveCount) { + archiveStart = + (archiveIdx < multiArchives1[multiIdx]->archiveCount) + ? multiArchives1[multiIdx]->archives[archiveIdx].mArchiveStart + : nullptr; + ArcResourceLink_set(arcResource, archiveStart, dirname); + return true; + } + + return false; +} u16 ResourceManager::getLoadedArchiveCount(s32 idx) { return isMultiArchive1Loaded(idx) ? this->multiArchives1[idx]->archiveCount @@ -1076,9 +1042,7 @@ void CourseCache::loadOther(MultiDvdArchive* other, EGG::Heap* heap) { } // namespace System -char* _unk_getNullString() { - return ""; -} +char* _unk_getNullString() { return ""; } // Symbol: unk_80541c48 // PAL: 0x80541c48..0x80541cbc diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 31f887c25..b13e76990 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -281,7 +281,7 @@ class ResourceManager { _614 = 0; isGlobeLoadingBusy = false; } - + MultiDvdArchive* load(ResourceChannelID channelId, EGG::Heap* archiveHeap, const char* filename); DvdArchive* loadSystemResource(s32 idx, EGG::Heap* archiveHeap); @@ -331,6 +331,8 @@ class ResourceManager { bool isMultiArchive2Loaded(s32 idx); bool isMultiArchive3Loaded(s32 idx); bool isDvdArchiveLoaded(s32 idx); + bool setArcResourceLink(s32 multiIdx, u32 archiveIdx, void* arcResource, + const char* dirname); u16 getLoadedArchiveCount(s32 idx); u16 getMenuArchiveCount(); void preloadCourseAsync(CourseId courseId); From 19398d63ba800bc680a28730ce3d1ef79dd0c0c8 Mon Sep 17 00:00:00 2001 From: vabold Date: Thu, 30 Jun 2022 06:17:38 -0400 Subject: [PATCH 33/46] ResourceManager: attachArcResourceAccessor --- source/game/system/ResourceManager.cpp | 98 ++++++++------------------ source/game/system/ResourceManager.hpp | 2 + 2 files changed, 32 insertions(+), 68 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 801d6b939..78a986836 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -11,6 +11,8 @@ extern RKScene* scenePtr; extern void ArcResourceLink_set(void* arcResource, void* archiveStart, const char* dirname); +extern void ArcResourceAccessor_attach(void* arcResourceAccessor, + void* archiveStart, const char* dirname); extern const char* EarthResourceListing; @@ -800,77 +802,37 @@ u16 ResourceManager::getMenuArchiveCount() { return this->multiArchives1[2]->archiveCount; } -} // namespace System +void ResourceManager::attachArcResourceAccessor(void* arcResourceAccessor, + const char* dirname) { + // look, it's 6am, this horribleness matches perfectly and I'm tired + // ping me tomorrow to clean this up + void* archiveStart; -// Symbol: unk_805417a4 -// PAL: 0x805417a4..0x80541878 -MARK_BINARY_BLOB(unk_805417a4, 0x805417a4, 0x80541878); -asm UNKNOWN_FUNCTION(unk_805417a4) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - stw r0, 0x24(r1); - stw r31, 0x1c(r1); - mr r31, r5; - stw r30, 0x18(r1); - mr r30, r4; - stw r29, 0x14(r1); - mr r29, r3; - lwz r6, 4(r3); - lwz r3, 8(r6); - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_805417e4; - li r0, 0; - b lbl_80541808; -lbl_805417e4: - lwz r3, 4(r29); - lwz r3, 8(r3); - lhz r0, 8(r3); - cmpwi r0, 0; - beq lbl_80541804; - lwz r3, 4(r3); - lwz r0, 8(r3); - b lbl_80541808; -lbl_80541804: - li r0, 0; -lbl_80541808: - cmpwi r0, 0; - beq lbl_8054185c; - lwz r3, 4(r29); - lwz r3, 8(r3); - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_8054182c; - li r4, 0; - b lbl_80541850; -lbl_8054182c: - lwz r3, 4(r29); - lwz r3, 8(r3); - lhz r0, 8(r3); - cmpwi r0, 0; - beq lbl_8054184c; - lwz r3, 4(r3); - lwz r4, 8(r3); - b lbl_80541850; -lbl_8054184c: - li r4, 0; -lbl_80541850: - mr r3, r30; - mr r5, r31; - bl unk_805553b0; -lbl_8054185c: - lwz r0, 0x24(r1); - lwz r31, 0x1c(r1); - lwz r30, 0x18(r1); - lwz r29, 0x14(r1); - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on + if (!isMultiArchive1Loaded(2)) { + archiveStart = nullptr; + } else if (multiArchives1[2]->archiveCount != 0) { + archiveStart = multiArchives1[2]->archives->mArchiveStart; + } else { + archiveStart = nullptr; + } + + if (!archiveStart) { + return; + } + + if (!isMultiArchive1Loaded(2)) { + archiveStart = nullptr; + } else if (multiArchives1[2]->archiveCount != 0) { + archiveStart = multiArchives1[2]->archives->mArchiveStart; + } else { + archiveStart = nullptr; + } + + ArcResourceAccessor_attach(arcResourceAccessor, archiveStart, dirname); } +} // namespace System + // Symbol: ResourceManager_attachLayoutDir // PAL: 0x80541878..0x80541998 MARK_BINARY_BLOB(ResourceManager_attachLayoutDir, 0x80541878, 0x80541998); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index b13e76990..e4961298d 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -335,6 +335,8 @@ class ResourceManager { const char* dirname); u16 getLoadedArchiveCount(s32 idx); u16 getMenuArchiveCount(); + void attachArcResourceAccessor(void* arcResourceAccessor, + const char* dirname); void preloadCourseAsync(CourseId courseId); void clear(); void process(); From f2ba98d0694a21d4c9fd5cb13efbe52301daa22e Mon Sep 17 00:00:00 2001 From: vabold Date: Thu, 30 Jun 2022 06:17:38 -0400 Subject: [PATCH 34/46] ResourceManager: attachArcResourceAccessor --- source/game/system/ResourceManager.cpp | 206 +++++++++---------------- source/game/system/ResourceManager.hpp | 28 +++- 2 files changed, 99 insertions(+), 135 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 801d6b939..e4cb42d46 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -11,6 +11,11 @@ extern RKScene* scenePtr; extern void ArcResourceLink_set(void* arcResource, void* archiveStart, const char* dirname); +extern void ArcResourceAccessor_attach(void* arcResourceAccessor, + void* archiveStart, const char* dirname); +extern void MultiArcResourceAccessor_attach(void* multiArcResourceAccessor, + void* param_2); +// extern s16 getSlotForCourseId(System::CourseId courseId); extern const char* EarthResourceListing; @@ -676,67 +681,6 @@ void* ResourceManager::getBspFile(s32 playerIdx, size_t* size) { : nullptr; } -} // namespace System -/* #else -MARK_BINARY_BLOB(ResourceManager_loadBSP, 0x805414a8, 0x8054155c); -asm UNKNOWN_FUNCTION(ResourceManager_loadBSP) { - // clang-format off - nofralloc; - stwu r1, -0x30(r1); - mflr r0; - stw r0, 0x34(r1); - mulli r0, r4, 0xf0; - lis r4, 0; - stw r31, 0x2c(r1); - mr r31, r5; - stw r30, 0x28(r1); - mr r30, r3; - lwz r6, 0(r4); - lis r4, 0; - addi r4, r4, 0; - add r3, r6, r0; - lwz r0, 0x30(r3); - addi r5, r4, 0x120; - addi r3, r1, 8; - li r4, 0x20; - cmpwi r0, 0x24; - blt lbl_805414fc; - li r6, 0; - b lbl_8054150c; -lbl_805414fc: - lis r6, 0; - slwi r0, r0, 2; - addi r6, r6, 0; - lwzx r6, r6, r0; -lbl_8054150c: - crclr 6; - bl unk_805553b0; - lwz r3, 4(r30); - lwz r3, 0(r3); - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - beq lbl_80541540; - lwz r3, 4(r30); - mr r5, r31; - addi r4, r1, 8; - lwz r3, 0(r3); - bl getFile__Q26System15MultiDvdArchiveFPCcPUl; - b lbl_80541544; -lbl_80541540: - li r3, 0; -lbl_80541544: - lwz r0, 0x34(r1); - lwz r31, 0x2c(r1); - lwz r30, 0x28(r1); - mtlr r0; - addi r1, r1, 0x30; - blr; - // clang-format on -} -#endif */ - -namespace System { - void* ResourceManager::getFileCopy(s32 archiveIdx, char* filename, EGG::Heap* heap, size_t* size, s8 param_5) { return !isDvdArchiveLoaded(archiveIdx) ? nullptr @@ -744,7 +688,7 @@ void* ResourceManager::getFileCopy(s32 archiveIdx, char* filename, filename, heap, size, param_5); } -bool ResourceManager::isMultiArchive1Loaded(s32 idx) { +bool ResourceManager::isMultiArchive1Loaded(s32 idx) volatile { return this->multiArchives1[idx]->isLoaded(); } @@ -770,7 +714,7 @@ void* ResourceManager::getArchiveStart(ResourceChannelID resId, return nullptr; } -bool ResourceManager::setArcResourceLink(s32 multiIdx, u32 archiveIdx, +bool ResourceManager::setArcResourceLink(s32 multiIdx, u16 archiveIdx, void* arcResource, const char* dirname) { void* archiveStart; @@ -800,80 +744,40 @@ u16 ResourceManager::getMenuArchiveCount() { return this->multiArchives1[2]->archiveCount; } -} // namespace System +void ResourceManager::attachArcResourceAccessor(void* arcResourceAccessor, + const char* dirname) { + // look, it's 6am, this horribleness matches perfectly and I'm tired + // ping me tomorrow to clean this up + void* archiveStart; -// Symbol: unk_805417a4 -// PAL: 0x805417a4..0x80541878 -MARK_BINARY_BLOB(unk_805417a4, 0x805417a4, 0x80541878); -asm UNKNOWN_FUNCTION(unk_805417a4) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - stw r0, 0x24(r1); - stw r31, 0x1c(r1); - mr r31, r5; - stw r30, 0x18(r1); - mr r30, r4; - stw r29, 0x14(r1); - mr r29, r3; - lwz r6, 4(r3); - lwz r3, 8(r6); - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_805417e4; - li r0, 0; - b lbl_80541808; -lbl_805417e4: - lwz r3, 4(r29); - lwz r3, 8(r3); - lhz r0, 8(r3); - cmpwi r0, 0; - beq lbl_80541804; - lwz r3, 4(r3); - lwz r0, 8(r3); - b lbl_80541808; -lbl_80541804: - li r0, 0; -lbl_80541808: - cmpwi r0, 0; - beq lbl_8054185c; - lwz r3, 4(r29); - lwz r3, 8(r3); - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_8054182c; - li r4, 0; - b lbl_80541850; -lbl_8054182c: - lwz r3, 4(r29); - lwz r3, 8(r3); - lhz r0, 8(r3); - cmpwi r0, 0; - beq lbl_8054184c; - lwz r3, 4(r3); - lwz r4, 8(r3); - b lbl_80541850; -lbl_8054184c: - li r4, 0; -lbl_80541850: - mr r3, r30; - mr r5, r31; - bl unk_805553b0; -lbl_8054185c: - lwz r0, 0x24(r1); - lwz r31, 0x1c(r1); - lwz r30, 0x18(r1); - lwz r29, 0x14(r1); - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on + if (!isMultiArchive1Loaded(2)) { + archiveStart = nullptr; + } else if (multiArchives1[2]->archiveCount != 0) { + archiveStart = multiArchives1[2]->archives->mArchiveStart; + } else { + archiveStart = nullptr; + } + + if (!archiveStart) { + return; + } + + if (!isMultiArchive1Loaded(2)) { + archiveStart = nullptr; + } else if (multiArchives1[2]->archiveCount != 0) { + archiveStart = multiArchives1[2]->archives->mArchiveStart; + } else { + archiveStart = nullptr; + } + + ArcResourceAccessor_attach(arcResourceAccessor, archiveStart, dirname); } +} // namespace System + // Symbol: ResourceManager_attachLayoutDir // PAL: 0x80541878..0x80541998 -MARK_BINARY_BLOB(ResourceManager_attachLayoutDir, 0x80541878, 0x80541998); +/*MARK_BINARY_BLOB(ResourceManager_attachLayoutDir, 0x80541878, 0x80541998); asm UNKNOWN_FUNCTION(ResourceManager_attachLayoutDir) { // clang-format off nofralloc; @@ -963,9 +867,28 @@ asm UNKNOWN_FUNCTION(ResourceManager_attachLayoutDir) { addi r1, r1, 0x20; blr; // clang-format on -} +}*/ namespace System { +void ResourceManager::attatchLayoutDir(void* accessor, const char* dirname, + Whatever2* whatever2, bool param_5) { + if (!param_5) { + getGameScene(); + } + + for (u16 i = 0; i < this->getLoadedArchiveCountInverse(RES_CHAN_UI); i++) { + void* arcResource; + if (i < whatever2->_08) { + arcResource = &whatever2->_04[i]; + } else { + arcResource = nullptr; + } + + if (setArcResourceLink(RES_CHAN_UI, i, arcResource, dirname)) { + MultiArcResourceAccessor_attach(accessor, arcResource); + } + } +} // force not inline CourseCache::load #ifdef __CWCC__ @@ -1922,6 +1845,23 @@ asm UNKNOWN_FUNCTION(unk_80542754) { // clang-format on } +/*namespace System { +void ResourceManager::loadStaffGhostAsync(GhostFileGroup::GhostGroupType +ghostType, CourseId courseId, u8* destBuffer) { char filename[128]; + + s16 slot = getSlotForCourseId(courseId); + // TODO: 2->slow staff ghost + if (ghostType == 2) { + snprintf(filename, sizeof(filename), +"/Race/TimeAttack/ghost1/ghost1_comp_%02d.rkg", (s32)slot); } else { + snprintf(filename, sizeof(filename), +"/Race/TimeAttack/ghost2/ghost2_comp_%02d.rkg", (s32)slot); + } + + SystemManager::sInstance->ripFromDiscAsync(filename, nullptr, true, nullptr, +destBuffer); +} +}*/ // Symbol: SaveManager_loadStaffGhostAsync // PAL: 0x805427bc..0x80542868 MARK_BINARY_BLOB(SaveManager_loadStaffGhostAsync, 0x805427bc, 0x80542868); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index b13e76990..f997a1338 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { #endif @@ -247,6 +248,17 @@ void preloadCourseTask(void* courseId); const char* getCharacterName(CharacterId charId); const char* getVehicleName(VehicleId vehicleId); +// unknown structs +struct Whatever { + u32 _00; + u8 _04[0xa4 - 0x04]; +}; +struct Whatever2 { + u8 _00[0x4 - 0x0]; + Whatever* _04; + u16 _08; /* ... */ +}; + class ResourceManager { virtual ~ResourceManager(); @@ -327,14 +339,24 @@ class ResourceManager { void* getFileCopy(s32 archiveIdx, char* filename, EGG::Heap* heap, size_t* size, s8 param_5); // TODO: Better names - bool isMultiArchive1Loaded(s32 idx); + bool isMultiArchive1Loaded(s32 idx) volatile; bool isMultiArchive2Loaded(s32 idx); bool isMultiArchive3Loaded(s32 idx); bool isDvdArchiveLoaded(s32 idx); - bool setArcResourceLink(s32 multiIdx, u32 archiveIdx, void* arcResource, + bool setArcResourceLink(s32 multiIdx, u16 archiveIdx, void* arcResource, const char* dirname); u16 getLoadedArchiveCount(s32 idx); + // I need this terribleness to match attachArcResourceAccessor + inline u16 getLoadedArchiveCountInverse(u32 idx) volatile { + return !isMultiArchive1Loaded(idx) + ? 0 + : this->multiArchives1[idx]->archiveCount; + } u16 getMenuArchiveCount(); + void attatchLayoutDir(void* accessor, const char* dirname, Whatever2* param_4, + bool param_5); + void attachArcResourceAccessor(void* arcResourceAccessor, + const char* dirname); void preloadCourseAsync(CourseId courseId); void clear(); void process(); @@ -346,6 +368,8 @@ class ResourceManager { void requestLoad(s32 idx, MultiDvdArchive* archive, const char* filename, EGG::Heap* archiveHeap, EGG::Heap* fileHeap); void* getArchiveStart(ResourceChannelID resId, u32 archiveIdx); + static void loadStaffGhostAsync(GhostFileGroup::GhostGroupType ghostType, + CourseId courseId, u8* destBuffer); // TODO: check if actually inline inline void requestLoadFile(s32 idx, MultiDvdArchive* m, const char* p, From 9803b1c784b5f1396b9cfd64d0ff38f4dd8b0f89 Mon Sep 17 00:00:00 2001 From: Theodoros Tyrovouzis Date: Sat, 2 Jul 2022 22:01:27 +0300 Subject: [PATCH 35/46] request things --- source/game/system/ResourceManager.cpp | 27 ++++++++++++++++++++++---- source/game/system/ResourceManager.hpp | 11 +++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 78a986836..1d5e6eec3 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -827,7 +827,7 @@ void ResourceManager::attachArcResourceAccessor(void* arcResourceAccessor, } else { archiveStart = nullptr; } - + ArcResourceAccessor_attach(arcResourceAccessor, archiveStart, dirname); } @@ -1008,7 +1008,7 @@ char* _unk_getNullString() { return ""; } // Symbol: unk_80541c48 // PAL: 0x80541c48..0x80541cbc -MARK_BINARY_BLOB(unk_80541c48, 0x80541c48, 0x80541cbc); +/*MARK_BINARY_BLOB(unk_80541c48, 0x80541c48, 0x80541cbc); asm UNKNOWN_FUNCTION(unk_80541c48) { // clang-format off nofralloc; @@ -1045,11 +1045,11 @@ asm UNKNOWN_FUNCTION(unk_80541c48) { addi r1, r1, 0x10; blr; // clang-format on -} +}*/ // Symbol: unk_80541cbc // PAL: 0x80541cbc..0x80541ce0 -MARK_BINARY_BLOB(unk_80541cbc, 0x80541cbc, 0x80541ce0); +/*MARK_BINARY_BLOB(unk_80541cbc, 0x80541cbc, 0x80541ce0); asm UNKNOWN_FUNCTION(unk_80541cbc) { // clang-format off nofralloc; @@ -1064,8 +1064,27 @@ asm UNKNOWN_FUNCTION(unk_80541cbc) { li r3, 0; blr; // clang-format on +}*/ +namespace System { +bool ResourceManager::tryRequestTask(EGG::TaskThread::TFunction fun, + void* arg) { + bool res = this->requestTask(fun, arg, (void*)0x10000001); + if (res) { + this->process(); + } + return res; } +bool ResourceManager::requestTask(EGG::TaskThread::TFunction fun, void* arg, + void* _8) { + if (this->requestsEnabled) { + this->requestPending = true; + return this->taskThread->request(fun, arg, _8); + } + return false; +} +} // namespace System + // Symbol: unk_80541ce0 // PAL: 0x80541ce0..0x80541e44 MARK_BINARY_BLOB(unk_80541ce0, 0x80541ce0, 0x80541e44); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index e4961298d..beab4058d 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -270,12 +270,12 @@ class ResourceManager { bool _60d; // these variables don't have names yet, but are used EGG::ExpHeap* _610; EGG::Heap* _614; - bool _618; - bool _619; + bool requestPending; + bool requestsEnabled; void foo() volatile { - _618 = 0; - _619 = 1; + requestPending = false; + requestsEnabled = true; } void bar() volatile { _614 = 0; @@ -335,6 +335,9 @@ class ResourceManager { const char* dirname); u16 getLoadedArchiveCount(s32 idx); u16 getMenuArchiveCount(); + bool tryRequestTask(EGG::TaskThread::TFunction mainFunction, void* arg); + bool requestTask(EGG::TaskThread::TFunction mainFunction, void* arg, + void* _8); void attachArcResourceAccessor(void* arcResourceAccessor, const char* dirname); void preloadCourseAsync(CourseId courseId); From c19a7b390cae4c1304f9f6d8bd43b85e0843f20d Mon Sep 17 00:00:00 2001 From: Theodoros Tyrovouzis Date: Sun, 3 Jul 2022 00:12:42 +0300 Subject: [PATCH 36/46] doLoadGlobe --- source/game/system/ResourceManager.cpp | 26 +++++++++++++++++++++++++- source/game/system/ResourceManager.hpp | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 1d5e6eec3..cb8d477e7 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include #pragma dont_reuse_strings on @@ -1643,7 +1645,7 @@ asm UNKNOWN_FUNCTION(unk_8054247c) { // Symbol: unk_8054248c // PAL: 0x8054248c..0x80542524 -MARK_BINARY_BLOB(unk_8054248c, 0x8054248c, 0x80542524); +/*MARK_BINARY_BLOB(unk_8054248c, 0x8054248c, 0x80542524); asm UNKNOWN_FUNCTION(unk_8054248c) { // clang-format off nofralloc; @@ -1686,7 +1688,29 @@ asm UNKNOWN_FUNCTION(unk_8054248c) { addi r1, r1, 0x40; blr; // clang-format on +}*/ + +namespace System { +void ResourceManager::FUN_8054248c(EGG::Heap* globeHeap) { + EGG::LZStreamDecomp lzstream; + + const char* globePath = Resource::GetResourcePath(SYS_RES_GLOBE); + EGG::Archive* globeArchive = (EGG::Archive*)EGG::Archive::loadFromDisc( + globePath, globeHeap, 0xffffffe0); + globeArchive = + EGG::Archive::mountNoFastGet(globeArchive, globeHeap, 0xffffffe0); + + EGG::Archive::FileInfo globeInfo; + globeInfo.startOffset = 0; + globeInfo.length = 0; + globeArchive->getFile(EarthResourceListing, &globeInfo); + globePath = Resource::GetResourcePath(SYS_RES_GLOBE); + + EGG::DvdRipper::loadToMainRAMDecomp( + globePath, &lzstream, 0, globeHeap, EGG::DvdRipper::ALLOC_DIR_TOP, + globeInfo.startOffset, globeInfo.length, 0x20000); } +} // namespace System // Symbol: unk_80542524 // PAL: 0x80542524..0x80542584 diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index beab4058d..28bc4ccb5 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -341,6 +341,7 @@ class ResourceManager { void attachArcResourceAccessor(void* arcResourceAccessor, const char* dirname); void preloadCourseAsync(CourseId courseId); + static void FUN_8054248c(EGG::Heap* globeHeap); void clear(); void process(); static void doLoadTask(void* jobContext); From 60e56316a04089b5d606963a5293ec0c0a10cd69 Mon Sep 17 00:00:00 2001 From: Theodoros Tyrovouzis Date: Sun, 3 Jul 2022 11:59:20 +0300 Subject: [PATCH 37/46] globe loads --- source/egg/core/eggStreamDecomp.hpp | 9 +- source/game/system/ResourceManager.cpp | 296 ++----------------------- source/game/system/ResourceManager.hpp | 12 +- 3 files changed, 25 insertions(+), 292 deletions(-) diff --git a/source/egg/core/eggStreamDecomp.hpp b/source/egg/core/eggStreamDecomp.hpp index cb95d0ee8..11e3b94ee 100644 --- a/source/egg/core/eggStreamDecomp.hpp +++ b/source/egg/core/eggStreamDecomp.hpp @@ -16,10 +16,11 @@ namespace EGG { //! class StreamDecomp { public: - virtual bool init(void* dst, u32 maxCompressedSize) = 0; - virtual bool decomp(const void* src, u32 len) = 0; - virtual u32 getHeaderSize() = 0; - virtual u32 getUncompressedSize(const void* src) = 0; + virtual bool init(void* dst, u32 maxCompressedSize); + virtual bool decomp(const void* src, u32 len); + virtual u32 getHeaderSize(); + virtual u32 getUncompressedSize(const void* src); + void foo(); }; class LZStreamDecomp : public StreamDecomp { diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index cb8d477e7..806b09f05 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -176,7 +176,7 @@ extern UNKNOWN_FUNCTION(unk_805553b0); namespace System { -ResourceManager* ResourceManager::createInstance() { +volatile ResourceManager* ResourceManager::createInstance() { if (spInstance == nullptr) { spInstance = new ResourceManager(); } @@ -208,7 +208,7 @@ System::ResourceManager::~ResourceManager() { } void ResourceManager::doLoadTask(void* jobContext) { - JobContext* context = &spInstance->jobContexts[(s32)jobContext]; + JobContext* context = (JobContext*)&spInstance->jobContexts[(s32)jobContext]; switch ((s32)jobContext) { case 6: @@ -680,67 +680,6 @@ void* ResourceManager::getBspFile(s32 playerIdx, size_t* size) { : nullptr; } -} // namespace System -/* #else -MARK_BINARY_BLOB(ResourceManager_loadBSP, 0x805414a8, 0x8054155c); -asm UNKNOWN_FUNCTION(ResourceManager_loadBSP) { - // clang-format off - nofralloc; - stwu r1, -0x30(r1); - mflr r0; - stw r0, 0x34(r1); - mulli r0, r4, 0xf0; - lis r4, 0; - stw r31, 0x2c(r1); - mr r31, r5; - stw r30, 0x28(r1); - mr r30, r3; - lwz r6, 0(r4); - lis r4, 0; - addi r4, r4, 0; - add r3, r6, r0; - lwz r0, 0x30(r3); - addi r5, r4, 0x120; - addi r3, r1, 8; - li r4, 0x20; - cmpwi r0, 0x24; - blt lbl_805414fc; - li r6, 0; - b lbl_8054150c; -lbl_805414fc: - lis r6, 0; - slwi r0, r0, 2; - addi r6, r6, 0; - lwzx r6, r6, r0; -lbl_8054150c: - crclr 6; - bl unk_805553b0; - lwz r3, 4(r30); - lwz r3, 0(r3); - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - beq lbl_80541540; - lwz r3, 4(r30); - mr r5, r31; - addi r4, r1, 8; - lwz r3, 0(r3); - bl getFile__Q26System15MultiDvdArchiveFPCcPUl; - b lbl_80541544; -lbl_80541540: - li r3, 0; -lbl_80541544: - lwz r0, 0x34(r1); - lwz r31, 0x2c(r1); - lwz r30, 0x28(r1); - mtlr r0; - addi r1, r1, 0x30; - blr; - // clang-format on -} -#endif */ - -namespace System { - void* ResourceManager::getFileCopy(s32 archiveIdx, char* filename, EGG::Heap* heap, size_t* size, s8 param_5) { return !isDvdArchiveLoaded(archiveIdx) ? nullptr @@ -936,7 +875,8 @@ namespace System { #pragma dont_inline on #endif void preloadCourseTask(void* courseId) { - ResourceManager::spInstance->courseCache.load((CourseId)courseId); + ((ResourceManager*)ResourceManager::spInstance) + ->courseCache.load((CourseId)courseId); } #ifdef __CWCC__ #pragma dont_inline off @@ -1008,65 +948,6 @@ void CourseCache::loadOther(MultiDvdArchive* other, EGG::Heap* heap) { char* _unk_getNullString() { return ""; } -// Symbol: unk_80541c48 -// PAL: 0x80541c48..0x80541cbc -/*MARK_BINARY_BLOB(unk_80541c48, 0x80541c48, 0x80541cbc); -asm UNKNOWN_FUNCTION(unk_80541c48) { - // clang-format off - nofralloc; - stwu r1, -0x10(r1); - mflr r0; - stw r0, 0x14(r1); - stw r31, 0xc(r1); - stw r30, 8(r1); - mr r30, r3; - lbz r0, 0x619(r3); - cmpwi r0, 0; - beq lbl_80541c8c; - li r0, 1; - stb r0, 0x618(r3); - lis r6, 0x1000; - lwz r3, 0x584(r3); - addi r6, r6, 1; - bl unk_805553b0; - mr r31, r3; - b lbl_80541c90; -lbl_80541c8c: - li r31, 0; -lbl_80541c90: - cmpwi r31, 0; - beq lbl_80541ca0; - mr r3, r30; - bl process__Q26System15ResourceManagerFv; -lbl_80541ca0: - mr r3, r31; - lwz r31, 0xc(r1); - lwz r30, 8(r1); - lwz r0, 0x14(r1); - mtlr r0; - addi r1, r1, 0x10; - blr; - // clang-format on -}*/ - -// Symbol: unk_80541cbc -// PAL: 0x80541cbc..0x80541ce0 -/*MARK_BINARY_BLOB(unk_80541cbc, 0x80541cbc, 0x80541ce0); -asm UNKNOWN_FUNCTION(unk_80541cbc) { - // clang-format off - nofralloc; - lbz r0, 0x619(r3); - cmpwi r0, 0; - beq lbl_80541cd8; - li r0, 1; - stb r0, 0x618(r3); - lwz r3, 0x584(r3); - b unk_805553b0; -lbl_80541cd8: - li r3, 0; - blr; - // clang-format on -}*/ namespace System { bool ResourceManager::tryRequestTask(EGG::TaskThread::TFunction fun, void* arg) { @@ -1643,55 +1524,8 @@ asm UNKNOWN_FUNCTION(unk_8054247c) { // clang-format on } -// Symbol: unk_8054248c -// PAL: 0x8054248c..0x80542524 -/*MARK_BINARY_BLOB(unk_8054248c, 0x8054248c, 0x80542524); -asm UNKNOWN_FUNCTION(unk_8054248c) { - // clang-format off - nofralloc; - stwu r1, -0x40(r1); - mflr r0; - lis r4, 0; - stw r0, 0x44(r1); - addi r4, r4, 0; - stw r31, 0x3c(r1); - mr r31, r3; - li r3, 3; - stw r4, 0x10(r1); - bl unk_805553b0; - mr r4, r31; - li r5, -32; - bl unk_805553b0; - mr r4, r31; - li r5, -32; - bl unk_805553b0; - lis r4, 0; - li r0, 0; - stw r0, 8(r1); - addi r5, r1, 8; - lwz r4, 0(r4); - stw r0, 0xc(r1); - bl unk_805553b0; - li r3, 3; - bl unk_805553b0; - lwz r8, 8(r1); - mr r6, r31; - lwz r9, 0xc(r1); - addi r4, r1, 0x10; - li r5, 0; - li r7, 1; - lis r10, 2; - bl unk_805553b0; - lwz r0, 0x44(r1); - lwz r31, 0x3c(r1); - mtlr r0; - addi r1, r1, 0x40; - blr; - // clang-format on -}*/ - namespace System { -void ResourceManager::FUN_8054248c(EGG::Heap* globeHeap) { +u8* ResourceManager::FUN_8054248c(EGG::Heap* globeHeap) { EGG::LZStreamDecomp lzstream; const char* globePath = Resource::GetResourcePath(SYS_RES_GLOBE); @@ -1706,7 +1540,7 @@ void ResourceManager::FUN_8054248c(EGG::Heap* globeHeap) { globeArchive->getFile(EarthResourceListing, &globeInfo); globePath = Resource::GetResourcePath(SYS_RES_GLOBE); - EGG::DvdRipper::loadToMainRAMDecomp( + return EGG::DvdRipper::loadToMainRAMDecomp( globePath, &lzstream, 0, globeHeap, EGG::DvdRipper::ALLOC_DIR_TOP, globeInfo.startOffset, globeInfo.length, 0x20000); } @@ -1774,120 +1608,16 @@ asm UNKNOWN_FUNCTION(unk_80542584) { // clang-format on } -// Symbol: unk_805425d0 -// PAL: 0x805425d0..0x80542694 -MARK_BINARY_BLOB(unk_805425d0, 0x805425d0, 0x80542694); -asm UNKNOWN_FUNCTION(unk_805425d0) { - // clang-format off - nofralloc; - stwu r1, -0x50(r1); - mflr r0; - lis r4, 0; - lis r5, 0; - stw r0, 0x54(r1); - addi r4, r4, 0; - stw r31, 0x4c(r1); - stw r30, 0x48(r1); - stw r29, 0x44(r1); - stw r28, 0x40(r1); - mr r28, r3; - li r3, 3; - lwz r29, 0(r5); - lwz r30, 0x614(r29); - stw r4, 0x10(r1); - bl unk_805553b0; - mr r4, r30; - li r5, -32; - bl unk_805553b0; - mr r4, r30; - li r5, -32; - bl unk_805553b0; - lis r4, 0; - li r31, 0; - stw r31, 8(r1); - addi r5, r1, 8; - lwz r4, 0(r4); - stw r31, 0xc(r1); - bl unk_805553b0; - li r3, 3; - bl unk_805553b0; - lwz r8, 8(r1); - mr r6, r30; - lwz r9, 0xc(r1); - addi r4, r1, 0x10; - li r5, 0; - li r7, 1; - lis r10, 2; - bl unk_805553b0; - stw r3, 0(r28); - stb r31, 0x60c(r29); - lwz r0, 0x54(r1); - lwz r31, 0x4c(r1); - lwz r30, 0x48(r1); - lwz r29, 0x44(r1); - lwz r28, 0x40(r1); - mtlr r0; - addi r1, r1, 0x50; - blr; - // clang-format on +namespace System { +void ResourceManager::doLoadGlobe(u8** globeBlob) { + ResourceManager::spInstance->doLoadGlobeImpl(globeBlob); } -// Symbol: unk_80542694 -// PAL: 0x80542694..0x80542754 -MARK_BINARY_BLOB(unk_80542694, 0x80542694, 0x80542754); -asm UNKNOWN_FUNCTION(unk_80542694) { - // clang-format off - nofralloc; - stwu r1, -0x50(r1); - mflr r0; - lis r5, 0; - stw r0, 0x54(r1); - addi r5, r5, 0; - stw r31, 0x4c(r1); - stw r30, 0x48(r1); - stw r29, 0x44(r1); - mr r29, r4; - stw r28, 0x40(r1); - mr r28, r3; - lwz r30, 0x614(r3); - li r3, 3; - stw r5, 0x10(r1); - bl unk_805553b0; - mr r4, r30; - li r5, -32; - bl unk_805553b0; - mr r4, r30; - li r5, -32; - bl unk_805553b0; - lis r4, 0; - li r31, 0; - stw r31, 8(r1); - addi r5, r1, 8; - lwz r4, 0(r4); - stw r31, 0xc(r1); - bl unk_805553b0; - li r3, 3; - bl unk_805553b0; - lwz r8, 8(r1); - mr r6, r30; - lwz r9, 0xc(r1); - addi r4, r1, 0x10; - li r5, 0; - li r7, 1; - lis r10, 2; - bl unk_805553b0; - stw r3, 0(r29); - stb r31, 0x60c(r28); - lwz r0, 0x54(r1); - lwz r31, 0x4c(r1); - lwz r30, 0x48(r1); - lwz r29, 0x44(r1); - lwz r28, 0x40(r1); - mtlr r0; - addi r1, r1, 0x50; - blr; - // clang-format on +void ResourceManager::doLoadGlobeImpl(u8** globeBlob) volatile { + *globeBlob = ResourceManager::FUN_8054248c(this->globeHeap); + this->isGlobeLoadingBusy = false; } +} // namespace System // Symbol: unk_80542754 // PAL: 0x80542754..0x805427bc diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 28bc4ccb5..2e1d0b58e 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -251,10 +251,10 @@ class ResourceManager { virtual ~ResourceManager(); public: - static ResourceManager* createInstance(); + static volatile ResourceManager* createInstance(); static void destroyInstance(); - static ResourceManager* spInstance; + static volatile ResourceManager* spInstance; ResourceManager(); @@ -269,7 +269,7 @@ class ResourceManager { bool isGlobeLoadingBusy; bool _60d; // these variables don't have names yet, but are used EGG::ExpHeap* _610; - EGG::Heap* _614; + EGG::Heap* globeHeap; bool requestPending; bool requestsEnabled; @@ -278,7 +278,7 @@ class ResourceManager { requestsEnabled = true; } void bar() volatile { - _614 = 0; + globeHeap = nullptr; isGlobeLoadingBusy = false; } @@ -341,7 +341,9 @@ class ResourceManager { void attachArcResourceAccessor(void* arcResourceAccessor, const char* dirname); void preloadCourseAsync(CourseId courseId); - static void FUN_8054248c(EGG::Heap* globeHeap); + static void doLoadGlobe(u8** glodeBlob); + void doLoadGlobeImpl(u8** glodeBlob) volatile; + static u8* FUN_8054248c(EGG::Heap* globeHeap); void clear(); void process(); static void doLoadTask(void* jobContext); From 7262b44c4c990e01c24d9b4f815d542a1f4ec74c Mon Sep 17 00:00:00 2001 From: Theodoros Tyrovouzis Date: Sun, 3 Jul 2022 12:43:03 +0300 Subject: [PATCH 38/46] load globe async --- source/game/system/ResourceManager.cpp | 46 ++++---------------------- source/game/system/ResourceManager.hpp | 12 ++++++- 2 files changed, 18 insertions(+), 40 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 806b09f05..7c02f5dda 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -1609,53 +1609,21 @@ asm UNKNOWN_FUNCTION(unk_80542584) { } namespace System { -void ResourceManager::doLoadGlobe(u8** globeBlob) { - ResourceManager::spInstance->doLoadGlobeImpl(globeBlob); +void ResourceManager::doLoadGlobe(void* globeBlob) { + ResourceManager::spInstance->doLoadGlobeImpl((u8**)globeBlob); } void ResourceManager::doLoadGlobeImpl(u8** globeBlob) volatile { *globeBlob = ResourceManager::FUN_8054248c(this->globeHeap); this->isGlobeLoadingBusy = false; } -} // namespace System -// Symbol: unk_80542754 -// PAL: 0x80542754..0x805427bc -MARK_BINARY_BLOB(unk_80542754, 0x80542754, 0x805427bc); -asm UNKNOWN_FUNCTION(unk_80542754) { - // clang-format off - nofralloc; - stwu r1, -0x10(r1); - mflr r0; - mr r5, r4; - stw r0, 0x14(r1); - lbz r0, 0x60c(r3); - cmpwi r0, 0; - beq lbl_80542778; - li r3, 0; - b lbl_805427ac; -lbl_80542778: - li r4, 1; - stb r4, 0x60c(r3); - lbz r0, 0x619(r3); - cmpwi r0, 0; - beq lbl_805427a8; - stb r4, 0x618(r3); - lis r4, 0; - lis r6, 0x1000; - lwz r3, 0x584(r3); - addi r4, r4, 0; - addi r6, r6, 4; - bl unk_805553b0; -lbl_805427a8: - li r3, 1; -lbl_805427ac: - lwz r0, 0x14(r1); - mtlr r0; - addi r1, r1, 0x10; - blr; - // clang-format on +bool ResourceManager::loadGlobeAsync(void* arg) { + return this->isGlobeLoadingBusy + ? false + : requestGlobeTaskHelper(arg, (void*)0x10000004); } +} // namespace System // Symbol: SaveManager_loadStaffGhostAsync // PAL: 0x805427bc..0x80542868 diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 2e1d0b58e..c44d8f1e7 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -341,9 +341,19 @@ class ResourceManager { void attachArcResourceAccessor(void* arcResourceAccessor, const char* dirname); void preloadCourseAsync(CourseId courseId); - static void doLoadGlobe(u8** glodeBlob); + static void doLoadGlobe(void* glodeBlob); void doLoadGlobeImpl(u8** glodeBlob) volatile; + // for matching purposes + inline bool requestGlobeTaskHelper(void* arg, void* arg2) volatile { + this->isGlobeLoadingBusy = true; + if (this->requestsEnabled) { + this->requestPending = true; + this->taskThread->request(ResourceManager::doLoadGlobe, arg, arg2); + } + return true; + } static u8* FUN_8054248c(EGG::Heap* globeHeap); + bool loadGlobeAsync(void* arg); void clear(); void process(); static void doLoadTask(void* jobContext); From a970100c324be2c981ae762cadbaab698609357f Mon Sep 17 00:00:00 2001 From: Theodoros Tyrovouzis Date: Mon, 4 Jul 2022 00:34:41 +0300 Subject: [PATCH 39/46] (de)init globeHeap --- source/game/system/ResourceManager.cpp | 66 +++++++++++--------------- source/game/system/ResourceManager.hpp | 5 +- 2 files changed, 33 insertions(+), 38 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 7c02f5dda..0c4535263 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -18,6 +18,13 @@ extern void ArcResourceAccessor_attach(void* arcResourceAccessor, extern const char* EarthResourceListing; +// TODO: Define externally +struct GameScene { + u8 _00[0xc94 - 0x0]; + HeapCollection dynamicHeaps; +}; +extern "C" GameScene* getGameScene(); + // .rodata const char* RESOURCES[] = { // clang-format off @@ -143,7 +150,7 @@ extern UNKNOWN_FUNCTION(getFileCopy__Q26System10DvdArchiveFPcPQ23EGG4HeapPUlSc); // PAL: 0x805192cc extern UNKNOWN_FUNCTION(unmount__Q26System10DvdArchiveFv); // PAL: 0x8051bed0 -extern UNKNOWN_FUNCTION(getGameScene); +// extern UNKNOWN_FUNCTION(getGameScene); extern UNKNOWN_FUNCTION( createMultiDvdArchive__6SystemFQ26System17ResourceChannelID); extern UNKNOWN_FUNCTION(__ct__Q26System16CourseDvdArchiveFv); @@ -970,8 +977,8 @@ bool ResourceManager::requestTask(EGG::TaskThread::TFunction fun, void* arg, // Symbol: unk_80541ce0 // PAL: 0x80541ce0..0x80541e44 -MARK_BINARY_BLOB(unk_80541ce0, 0x80541ce0, 0x80541e44); -asm UNKNOWN_FUNCTION(unk_80541ce0) { +MARK_BINARY_BLOB(flush__Q26System15ResourceManagerFv, 0x80541ce0, 0x80541e44); +asm UNKNOWN_FUNCTION(flush__Q26System15ResourceManagerFv) { // clang-format off nofralloc; stwu r1, -0x20(r1); @@ -1544,42 +1551,26 @@ u8* ResourceManager::FUN_8054248c(EGG::Heap* globeHeap) { globePath, &lzstream, 0, globeHeap, EGG::DvdRipper::ALLOC_DIR_TOP, globeInfo.startOffset, globeInfo.length, 0x20000); } -} // namespace System -// Symbol: unk_80542524 -// PAL: 0x80542524..0x80542584 -MARK_BINARY_BLOB(unk_80542524, 0x80542524, 0x80542584); -asm UNKNOWN_FUNCTION(unk_80542524) { - // clang-format off - nofralloc; - stwu r1, -0x10(r1); - mflr r0; - cmpwi r5, 0; - stw r0, 0x14(r1); - stw r31, 0xc(r1); - mr r31, r4; - stw r30, 8(r1); - mr r30, r3; - bne lbl_80542550; - bl getGameScene; - lwz r5, 0xc98(r3); -lbl_80542550: - addis r3, r31, 2; - mr r4, r5; - addi r0, r3, 0x41f; - li r5, 0; - rlwinm r3, r0, 0, 0, 0x1a; - bl unk_805553b0; - stw r3, 0x614(r30); - lwz r31, 0xc(r1); - lwz r30, 8(r1); - lwz r0, 0x14(r1); - mtlr r0; - addi r1, r1, 0x10; - blr; - // clang-format on +void ResourceManager::initGlobeHeap(size_t size, EGG::Heap* heap) { + if (heap == nullptr) { + GameScene* gameScene = getGameScene(); + heap = gameScene->dynamicHeaps.mpHeaps[1]; + } + this->globeHeap = EGG::ExpHeap::create(size + 0x2041fU & 0xffffffe0, heap, 0); } +} // namespace System +#ifdef MATCHING +namespace System { +void ResourceManager::deinitGlobeHeap() volatile { + this->flush(); + this->globeHeap->destroy(); + this->globeHeap = nullptr; + this->isGlobeLoadingBusy = false; +} +} // namespace System +#else // Symbol: unk_80542584 // PAL: 0x80542584..0x805425d0 MARK_BINARY_BLOB(unk_80542584, 0x80542584, 0x805425d0); @@ -1591,7 +1582,7 @@ asm UNKNOWN_FUNCTION(unk_80542584) { stw r0, 0x14(r1); stw r31, 0xc(r1); mr r31, r3; - bl unk_80541ce0; + bl flush__Q26System15ResourceManagerFv; lwz r3, 0x614(r31); lwz r12, 0(r3); lwz r12, 0x1c(r12); @@ -1607,6 +1598,7 @@ asm UNKNOWN_FUNCTION(unk_80542584) { blr; // clang-format on } +#endif namespace System { void ResourceManager::doLoadGlobe(void* globeBlob) { diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index c44d8f1e7..c00c2106c 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -125,7 +125,7 @@ UNKNOWN_FUNCTION(unk_80541c48); // PAL: 0x80541cbc..0x80541ce0 UNKNOWN_FUNCTION(unk_80541cbc); // PAL: 0x80541ce0..0x80541e44 -UNKNOWN_FUNCTION(unk_80541ce0); +// UNKNOWN_FUNCTION(flush__Q26System15ResourceManagerFv); // PAL: 0x80541e44..0x80542030 UNKNOWN_FUNCTION(unk_80541e44); // PAL: 0x80542030..0x80542210 @@ -341,6 +341,9 @@ class ResourceManager { void attachArcResourceAccessor(void* arcResourceAccessor, const char* dirname); void preloadCourseAsync(CourseId courseId); + void initGlobeHeap(size_t size, EGG::Heap* heap); + void flush() volatile; + void deinitGlobeHeap() volatile; static void doLoadGlobe(void* glodeBlob); void doLoadGlobeImpl(u8** glodeBlob) volatile; // for matching purposes From 18cd71773a9ce069e9b7c991739290b39cdd916b Mon Sep 17 00:00:00 2001 From: Theodoros Tyrovouzis Date: Wed, 6 Jul 2022 21:50:22 +0300 Subject: [PATCH 40/46] WIP: doLoadMenuCharacterModel --- pack/rel_objects.txt | 2 +- pack/rel_slices.csv | 2 +- source/game/system/ResourceManager.cpp | 46 ++++++++++++++- source/game/system/ResourceManager.hpp | 77 +++++++++++++++----------- 4 files changed, 92 insertions(+), 35 deletions(-) diff --git a/pack/rel_objects.txt b/pack/rel_objects.txt index b9f21b8ff..65c6b4c6e 100644 --- a/pack/rel_objects.txt +++ b/pack/rel_objects.txt @@ -21,7 +21,7 @@ out/rel/rodata_8088fe28_80890490.o out/rel/data_808b31e8_808b3960.o out/ResourceManager.o out/rel/text_80542878_80555464.o -out/rel/rodata_80890c3c_80891370.o +out/rel/rodata_80890c77_80891370.o out/rel/data_808b3c2c_808b42e0.o out/Random.o out/rel/text_8055572c_80590128.o diff --git a/pack/rel_slices.csv b/pack/rel_slices.csv index 2d836c67e..af8f9ed79 100644 --- a/pack/rel_slices.csv +++ b/pack/rel_slices.csv @@ -4,7 +4,7 @@ enabled,name,textStart,textEnd,ctorsStart,ctorsEnd,dtorsStart,dtorsEnd,rodataSta 1,source/game/system/GhostFile.cpp,0x8051c088,0x8051d4d4,,,,,,,0x808b2d38,0x808b2d50,, 1,source/game/system/LocalizedArchive.cpp,0x8052a098,0x8052a538,,,,,0x8088fdc0,0x8088fe00,0x808b3188,0x808b31d8,, 1,source/game/system/MultiDvdArchive.cpp,0x8052a538,0x8052ae5c,,,,,0x8088fe00,0x8088fe28,0x808b31d8,0x808b31e8,, -1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890c3c,0x808b3960,0x808b3c2c,, +1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890c77,0x808b3960,0x808b3c2c,, 1,source/game/util/Random.cpp,0x80555464,0x8055572c,,,,,0x80891370,0x80891380,0x808b42e0,0x808b42ec,, 1,source/game/kart/KartComponent.cpp,0x80590128,0x805901d0,,,,,,,,,0x809c1900,0x809c1910 1,source/game/ui/ControlGroup.cpp,0x805c23e4,0x805c2c18,,,,,,,,,, diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 0c4535263..8cf24a756 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -1083,7 +1083,7 @@ asm UNKNOWN_FUNCTION(flush__Q26System15ResourceManagerFv) { // Symbol: unk_80541e44 // PAL: 0x80541e44..0x80542030 -MARK_BINARY_BLOB(unk_80541e44, 0x80541e44, 0x80542030); +/*MARK_BINARY_BLOB(unk_80541e44, 0x80541e44, 0x80542030); asm UNKNOWN_FUNCTION(unk_80541e44) { // clang-format off nofralloc; @@ -1225,7 +1225,51 @@ asm UNKNOWN_FUNCTION(unk_80541e44) { addi r1, r1, 0xa0; blr; // clang-format on +}*/ +namespace System { +namespace { +void RloadMenuKartModel(MultiDvdArchive* m, CharacterId characterId, + BattleTeam battleTeam, EGG::Heap* archiveHeap, + EGG::Heap* fileHeap) { + char buffer[128]; + + if (!m->isLoaded()) { + if (battleTeam == 2) { // not in battle mode + snprintf(buffer, sizeof(buffer), "Scene/Model/Kart/%s-allkart", + getCharacterName(characterId)); + } else { + snprintf(buffer, sizeof(buffer), "Scene/Model/Kart/%s-allkart_BT", + getCharacterName(characterId)); + } + m->load(buffer, archiveHeap, fileHeap, 0); + } } +void RloadMenuKartModel(MultiDvdArchive* m, MenuCharacterManager* c) { + RloadMenuKartModel(m, c->mCharacter, c->mModelType, c->archiveHeap, + c->fileHeap); +} +} // namespace +void ResourceManager::doLoadCharacterKartModel(s32 idxs) { + ResourceManager* resMgr = (ResourceManager*)ResourceManager::spInstance; + const u8 idx = idxs; + if (resMgr->multiArchives2[idx].isLoaded()) { + resMgr->multiArchives2[idx].unmount(); + } + resMgr->menuManagers[idx]._unk = 2; + resMgr->menuManagers[idx].destroy(); + + MultiDvdArchive* archive = &resMgr->multiArchives2[idx]; + RloadMenuKartModel(archive, &resMgr->menuManagers[idx]); + if (!archive->isLoaded()) { + OSSleepMilliseconds(16); + } + if (archive->isLoaded()) { + resMgr->menuManagers[idx]._unk = 4; + } else { + resMgr->menuManagers[idx]._unk = 0; + } +} +} // namespace System // Symbol: unk_80542030 // PAL: 0x80542030..0x80542210 diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index c00c2106c..329700894 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -170,38 +170,10 @@ struct JobContext { EGG::Heap* fileHeap; }; -// begrudging riidefi magic -struct S { - virtual ~S() = 0; -}; -inline S::~S() {} -struct T { - T() { - mHeap1 = 0; - mHeap2 = 0; - _unk = 0; - } - EGG::ExpHeap* mHeap1; - EGG::ExpHeap* mHeap2; - s32 _unk; -}; - -class MenuCharacterManager : S, T { - friend class ResourceManager; - -public: - MenuCharacterManager() { - mCharacter = 0; - mModelType = 2; - } - virtual ~MenuCharacterManager() {} - s32 mCharacter; - s32 mModelType; -}; - // Enums that represent indices in vehicle name specifiers arrays. typedef enum { // TODO: Fill + MARIO = 0 } CharacterId; typedef enum { @@ -226,6 +198,46 @@ typedef enum { // TODO: Fill } CourseId; +// begrudging riidefi magic +struct S { + virtual ~S() = 0; +}; +inline S::~S() {} +struct T { +public: + T() { + archiveHeap = 0; + fileHeap = 0; + _unk = 0; + } + EGG::ExpHeap* archiveHeap; + EGG::ExpHeap* fileHeap; + s32 _unk; + inline bool SOME_CHECK() const { + return archiveHeap && ((_unk <= 4 && (((1 << _unk) & 0x15U) != 0))); + } + inline void destroy() { + if (SOME_CHECK()) { + archiveHeap->freeAll(); + fileHeap->freeAll(); + } + _unk = 3; + } +}; + +class MenuCharacterManager : S, public T { + friend class ResourceManager; + +public: + MenuCharacterManager() { + mCharacter = MARIO; + mModelType = BATTLE_TEAM_NONE; + } + virtual ~MenuCharacterManager() {} + CharacterId mCharacter; + BattleTeam mModelType; +}; + class CourseCache : EGG::Disposer { public: CourseCache(); @@ -344,6 +356,7 @@ class ResourceManager { void initGlobeHeap(size_t size, EGG::Heap* heap); void flush() volatile; void deinitGlobeHeap() volatile; + void doLoadCharacterKartModel(s32 idxs); static void doLoadGlobe(void* glodeBlob); void doLoadGlobeImpl(u8** glodeBlob) volatile; // for matching purposes @@ -403,7 +416,7 @@ class ResourceManager { MultiDvdArchive* archive; EGG::ExpHeap* heap; - heap = menuManagers[i].mHeap1; + heap = menuManagers[i].archiveHeap; archive = &multiArchives2[i]; if (archive->isLoaded()) { @@ -414,8 +427,8 @@ class ResourceManager { } if (menuManagers[i]._unk != 3) { - menuManagers[i].mHeap1 = 0; - menuManagers[i].mHeap2 = 0; + menuManagers[i].archiveHeap = 0; + menuManagers[i].fileHeap = 0; menuManagers[i]._unk = 0; } } From 2be87d6aae368cd6a02c873fd794a86ea4ed5ded Mon Sep 17 00:00:00 2001 From: riidefi <34194588+riidefi@users.noreply.github.com> Date: Wed, 6 Jul 2022 13:23:04 -0600 Subject: [PATCH 41/46] Match doLoadCharacterKartModel --- source/game/system/ResourceManager.cpp | 148 +------------------------ source/game/system/ResourceManager.hpp | 7 +- 2 files changed, 6 insertions(+), 149 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 19304b1f2..eefc18184 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -1103,152 +1103,8 @@ asm UNKNOWN_FUNCTION(flush__Q26System15ResourceManagerFv) { // clang-format on } -// Symbol: unk_80541e44 -// PAL: 0x80541e44..0x80542030 -/*MARK_BINARY_BLOB(unk_80541e44, 0x80541e44, 0x80542030); -asm UNKNOWN_FUNCTION(unk_80541e44) { - // clang-format off - nofralloc; - stwu r1, -0xa0(r1); - mflr r0; - stw r0, 0xa4(r1); - stmw r26, 0x88(r1); - clrlwi r28, r3, 0x18; - lis r3, 0; - mulli r26, r28, 0x1c; - lwz r27, 0(r3); - add r3, r27, r26; - addi r3, r3, 8; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - beq lbl_80541e84; - add r3, r27, r26; - addi r3, r3, 8; - bl unmount__Q26System15MultiDvdArchiveFv; -lbl_80541e84: - mulli r28, r28, 0x18; - li r0, 2; - li r4, 0; - add r31, r27, r28; - stw r0, 0x5b8(r31); - lwz r3, 0x5b0(r31); - cmpwi r3, 0; - beq lbl_80541ed4; - lwz r6, 0x5b8(r31); - li r5, 0; - cmplwi r6, 4; - bgt lbl_80541ec8; - li r0, 1; - slw r0, r0, r6; - andi. r0, r0, 0x15; - beq lbl_80541ec8; - li r5, 1; -lbl_80541ec8: - cmpwi r5, 0; - beq lbl_80541ed4; - li r4, 1; -lbl_80541ed4: - cmpwi r4, 0; - beq lbl_80541eec; - bl unk_805553b0; - add r3, r27, r28; - lwz r3, 0x5b4(r3); - bl unk_805553b0; -lbl_80541eec: - li r0, 3; - stw r0, 0x5b8(r31); - add r4, r27, r28; - add r3, r27, r26; - addi r30, r3, 8; - lwz r29, 0x5b4(r4); - lwz r28, 0x5b0(r31); - mr r3, r30; - lwz r27, 0x5c0(r4); - lwz r26, 0x5bc(r4); - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_80541fbc; - cmpwi r27, 2; - bne lbl_80541f68; - lis r4, 0; - cmpwi r26, 0x30; - addi r4, r4, 0; - addi r3, r1, 8; - addi r5, r4, 0x13c; - li r4, 0x80; - blt lbl_80541f4c; - li r6, 0; - b lbl_80541f5c; -lbl_80541f4c: - lis r6, 0; - slwi r0, r26, 2; - addi r6, r6, 0; - lwzx r6, r6, r0; -lbl_80541f5c: - crclr 6; - bl unk_805553b0; - b lbl_80541fa4; -lbl_80541f68: - lis r4, 0; - cmpwi r26, 0x30; - addi r4, r4, 0; - addi r3, r1, 8; - addi r5, r4, 0x158; - li r4, 0x80; - blt lbl_80541f8c; - li r6, 0; - b lbl_80541f9c; -lbl_80541f8c: - lis r6, 0; - slwi r0, r26, 2; - addi r6, r6, 0; - lwzx r6, r6, r0; -lbl_80541f9c: - crclr 6; - bl unk_805553b0; -lbl_80541fa4: - mr r3, r30; - mr r5, r28; - mr r6, r29; - addi r4, r1, 8; - li r7, 0; - bl load__Q26System15MultiDvdArchiveFPCcPQ23EGG4HeapPQ23EGG4Heapi; -lbl_80541fbc: - mr r3, r30; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_80541ff8; - lis r4, 0x8000; - lis r3, 0x1062; - lwz r0, 0xf8(r4); - addi r4, r3, 0x4dd3; - li r3, 0; - srwi r0, r0, 2; - mulhwu r4, r4, r0; - srwi r0, r4, 6; - rlwinm r4, r4, 0x1e, 2, 0x1b; - rlwimi r3, r0, 4, 0x1c, 0x1f; - bl unk_805553b0; -lbl_80541ff8: - mr r3, r30; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - beq lbl_80542014; - li r0, 4; - stw r0, 0x5b8(r31); - b lbl_8054201c; -lbl_80542014: - li r0, 0; - stw r0, 0x5b8(r31); -lbl_8054201c: - lmw r26, 0x88(r1); - lwz r0, 0xa4(r1); - mtlr r0; - addi r1, r1, 0xa0; - blr; - // clang-format on -}*/ namespace System { + namespace { void RloadMenuKartModel(MultiDvdArchive* m, CharacterId characterId, BattleTeam battleTeam, EGG::Heap* archiveHeap, @@ -1272,7 +1128,7 @@ void RloadMenuKartModel(MultiDvdArchive* m, MenuCharacterManager* c) { } } // namespace void ResourceManager::doLoadCharacterKartModel(s32 idxs) { - ResourceManager* resMgr = (ResourceManager*)ResourceManager::spInstance; + ResourceManager* resMgr = ResourceManager::spInstance_REAL; const u8 idx = idxs; if (resMgr->multiArchives2[idx].isLoaded()) { resMgr->multiArchives2[idx].unmount(); diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index af3396b99..89a004624 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -155,7 +155,7 @@ UNKNOWN_FUNCTION(unk_80542754); UNKNOWN_FUNCTION(SaveManager_loadStaffGhostAsync); // PAL: 0x80542868..0x80542878 UNKNOWN_FUNCTION(unk_80542868); - +UNKNOWN_FUNCTION(flush__Q26System15ResourceManagerFv); #ifdef __cplusplus } #endif @@ -215,7 +215,7 @@ struct T { EGG::ExpHeap* fileHeap; s32 _unk; inline bool SOME_CHECK() const { - return archiveHeap && ((_unk <= 4 && (((1 << _unk) & 0x15U) != 0))); + return archiveHeap && ((_unk <= 4u && (((1 << _unk) & 0x15U) != 0))); } inline void destroy() { if (SOME_CHECK()) { @@ -279,6 +279,7 @@ class ResourceManager { static void destroyInstance(); static volatile ResourceManager* spInstance; + static ResourceManager* spInstance_REAL; ResourceManager(); @@ -377,7 +378,7 @@ class ResourceManager { void initGlobeHeap(size_t size, EGG::Heap* heap); void flush() volatile; void deinitGlobeHeap() volatile; - void doLoadCharacterKartModel(s32 idxs); + static void doLoadCharacterKartModel(s32 idxs); static void doLoadGlobe(void* glodeBlob); void doLoadGlobeImpl(u8** glodeBlob) volatile; // for matching purposes From b6c2c74c02597a3b51f35a71f139ccea90d830a5 Mon Sep 17 00:00:00 2001 From: riidefi <34194588+riidefi@users.noreply.github.com> Date: Wed, 6 Jul 2022 13:28:01 -0600 Subject: [PATCH 42/46] Match deinitGlobeHeap --- source/game/system/ResourceManager.cpp | 35 ++------------------------ source/game/system/ResourceManager.hpp | 4 +-- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index eefc18184..aeaf62f15 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -1483,44 +1483,13 @@ void ResourceManager::initGlobeHeap(size_t size, EGG::Heap* heap) { } } // namespace System -#ifdef MATCHING namespace System { -void ResourceManager::deinitGlobeHeap() volatile { +void ResourceManager::deinitGlobeHeap() { this->flush(); this->globeHeap->destroy(); - this->globeHeap = nullptr; - this->isGlobeLoadingBusy = false; + bar(); } } // namespace System -#else -// Symbol: unk_80542584 -// PAL: 0x80542584..0x805425d0 -MARK_BINARY_BLOB(unk_80542584, 0x80542584, 0x805425d0); -asm UNKNOWN_FUNCTION(unk_80542584) { - // clang-format off - nofralloc; - stwu r1, -0x10(r1); - mflr r0; - stw r0, 0x14(r1); - stw r31, 0xc(r1); - mr r31, r3; - bl flush__Q26System15ResourceManagerFv; - lwz r3, 0x614(r31); - lwz r12, 0(r3); - lwz r12, 0x1c(r12); - mtctr r12; - bctrl; - li r0, 0; - stw r0, 0x614(r31); - stb r0, 0x60c(r31); - lwz r0, 0x14(r1); - lwz r31, 0xc(r1); - mtlr r0; - addi r1, r1, 0x10; - blr; - // clang-format on -} -#endif namespace System { void ResourceManager::doLoadGlobe(void* globeBlob) { diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 89a004624..63d6c94e6 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -376,8 +376,8 @@ class ResourceManager { const char* dirname); void preloadCourseAsync(CourseId courseId); void initGlobeHeap(size_t size, EGG::Heap* heap); - void flush() volatile; - void deinitGlobeHeap() volatile; + void flush(); + void deinitGlobeHeap(); static void doLoadCharacterKartModel(s32 idxs); static void doLoadGlobe(void* glodeBlob); void doLoadGlobeImpl(u8** glodeBlob) volatile; From 3d31d8cd9c8e20750391b03408a501497abb3225 Mon Sep 17 00:00:00 2001 From: Theodoros Tyrovouzis Date: Thu, 7 Jul 2022 13:07:06 +0300 Subject: [PATCH 43/46] doLoadCharacterModel and staffGhost --- pack/rel_objects.txt | 2 +- pack/rel_slices.csv | 2 +- source/game/system/ResourceManager.cpp | 253 ++++--------------------- source/game/system/ResourceManager.hpp | 1 + 4 files changed, 43 insertions(+), 215 deletions(-) diff --git a/pack/rel_objects.txt b/pack/rel_objects.txt index 65c6b4c6e..6dab0276f 100644 --- a/pack/rel_objects.txt +++ b/pack/rel_objects.txt @@ -21,7 +21,7 @@ out/rel/rodata_8088fe28_80890490.o out/rel/data_808b31e8_808b3960.o out/ResourceManager.o out/rel/text_80542878_80555464.o -out/rel/rodata_80890c77_80891370.o +out/rel/rodata_80890d0c_80891370.o out/rel/data_808b3c2c_808b42e0.o out/Random.o out/rel/text_8055572c_80590128.o diff --git a/pack/rel_slices.csv b/pack/rel_slices.csv index af8f9ed79..552cdc386 100644 --- a/pack/rel_slices.csv +++ b/pack/rel_slices.csv @@ -4,7 +4,7 @@ enabled,name,textStart,textEnd,ctorsStart,ctorsEnd,dtorsStart,dtorsEnd,rodataSta 1,source/game/system/GhostFile.cpp,0x8051c088,0x8051d4d4,,,,,,,0x808b2d38,0x808b2d50,, 1,source/game/system/LocalizedArchive.cpp,0x8052a098,0x8052a538,,,,,0x8088fdc0,0x8088fe00,0x808b3188,0x808b31d8,, 1,source/game/system/MultiDvdArchive.cpp,0x8052a538,0x8052ae5c,,,,,0x8088fe00,0x8088fe28,0x808b31d8,0x808b31e8,, -1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890c77,0x808b3960,0x808b3c2c,, +1,source/game/system/ResourceManager.cpp,0x8053FC4C,0x80542878,,,,,0x80890490,0x80890d0c,0x808b3960,0x808b3c2c,, 1,source/game/util/Random.cpp,0x80555464,0x8055572c,,,,,0x80891370,0x80891380,0x808b42e0,0x808b42ec,, 1,source/game/kart/KartComponent.cpp,0x80590128,0x805901d0,,,,,,,,,0x809c1900,0x809c1910 1,source/game/ui/ControlGroup.cpp,0x805c23e4,0x805c2c18,,,,,,,,,, diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index aeaf62f15..fb90f80e5 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -17,7 +17,7 @@ extern void ArcResourceAccessor_attach(void* arcResourceAccessor, void* archiveStart, const char* dirname); extern void MultiArcResourceAccessor_attach(void* multiArcResourceAccessor, void* param_2); -// extern s16 getSlotForCourseId(System::CourseId courseId); +extern "C" s16 getSlotForCourseId(System::CourseId courseId); extern const char* EarthResourceListing; @@ -179,7 +179,7 @@ extern UNKNOWN_FUNCTION(clear__Q26System15MultiDvdArchiveFv); // PAL: 0x8052ae08 extern UNKNOWN_FUNCTION(rippedArchiveCount__Q26System15MultiDvdArchiveFv); // PAL: 0x80552d90 -extern UNKNOWN_FUNCTION(getSlotForCourseId); +// extern UNKNOWN_FUNCTION(getSlotForCourseId); // PAL: 0x805553b0 extern UNKNOWN_FUNCTION(unk_805553b0); } @@ -1147,150 +1147,29 @@ void ResourceManager::doLoadCharacterKartModel(s32 idxs) { resMgr->menuManagers[idx]._unk = 0; } } -} // namespace System -// Symbol: unk_80542030 -// PAL: 0x80542030..0x80542210 -MARK_BINARY_BLOB(unk_80542030, 0x80542030, 0x80542210); -asm UNKNOWN_FUNCTION(unk_80542030) { - // clang-format off - nofralloc; - stwu r1, -0xa0(r1); - mflr r0; - stw r0, 0xa4(r1); - mulli r0, r4, 0x1c; - stmw r26, 0x88(r1); - mr r27, r3; - add r3, r3, r0; - mr r26, r4; - addi r30, r3, 8; - mr r3, r30; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - beq lbl_8054206c; - mr r3, r30; - bl unmount__Q26System15MultiDvdArchiveFv; -lbl_8054206c: - mulli r26, r26, 0x18; - li r0, 2; - li r4, 0; - add r31, r27, r26; - stw r0, 0x5b8(r31); - lwz r3, 0x5b0(r31); - cmpwi r3, 0; - beq lbl_805420bc; - lwz r6, 0x5b8(r31); - li r5, 0; - cmplwi r6, 4; - bgt lbl_805420b0; - li r0, 1; - slw r0, r0, r6; - andi. r0, r0, 0x15; - beq lbl_805420b0; - li r5, 1; -lbl_805420b0: - cmpwi r5, 0; - beq lbl_805420bc; - li r4, 1; -lbl_805420bc: - cmpwi r4, 0; - beq lbl_805420d4; - bl unk_805553b0; - add r3, r27, r26; - lwz r3, 0x5b4(r3); - bl unk_805553b0; -lbl_805420d4: - li r0, 3; - stw r0, 0x5b8(r31); - add r4, r27, r26; - mr r3, r30; - lwz r26, 0x5b4(r4); - lwz r27, 0x5b0(r31); - lwz r28, 0x5c0(r4); - lwz r29, 0x5bc(r4); - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_8054219c; - cmpwi r28, 2; - bne lbl_80542148; - lis r4, 0; - cmpwi r29, 0x30; - addi r4, r4, 0; - addi r3, r1, 8; - addi r5, r4, 0x177; - li r4, 0x80; - blt lbl_8054212c; - li r6, 0; - b lbl_8054213c; -lbl_8054212c: - lis r6, 0; - slwi r0, r29, 2; - addi r6, r6, 0; - lwzx r6, r6, r0; -lbl_8054213c: - crclr 6; - bl unk_805553b0; - b lbl_80542184; -lbl_80542148: - lis r4, 0; - cmpwi r29, 0x30; - addi r4, r4, 0; - addi r3, r1, 8; - addi r5, r4, 0x193; - li r4, 0x80; - blt lbl_8054216c; - li r6, 0; - b lbl_8054217c; -lbl_8054216c: - lis r6, 0; - slwi r0, r29, 2; - addi r6, r6, 0; - lwzx r6, r6, r0; -lbl_8054217c: - crclr 6; - bl unk_805553b0; -lbl_80542184: - mr r3, r30; - mr r5, r27; - mr r6, r26; - addi r4, r1, 8; - li r7, 0; - bl load__Q26System15MultiDvdArchiveFPCcPQ23EGG4HeapPQ23EGG4Heapi; -lbl_8054219c: - mr r3, r30; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_805421d8; - lis r4, 0x8000; - lis r3, 0x1062; - lwz r0, 0xf8(r4); - addi r4, r3, 0x4dd3; - li r3, 0; - srwi r0, r0, 2; - mulhwu r4, r4, r0; - srwi r0, r4, 6; - rlwinm r4, r4, 0x1e, 2, 0x1b; - rlwimi r3, r0, 4, 0x1c, 0x1f; - bl unk_805553b0; -lbl_805421d8: - mr r3, r30; - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - beq lbl_805421f4; - li r0, 4; - stw r0, 0x5b8(r31); - b lbl_805421fc; -lbl_805421f4: - li r0, 0; - stw r0, 0x5b8(r31); -lbl_805421fc: - lmw r26, 0x88(r1); - lwz r0, 0xa4(r1); - mtlr r0; - addi r1, r1, 0xa0; - blr; - // clang-format on +void ResourceManager::doLoadCharacterKartModelPriv(s32 idx) { + if (this->multiArchives2[idx].isLoaded()) { + this->multiArchives2[idx].unmount(); + } + this->menuManagers[idx]._unk = 2; + this->menuManagers[idx].destroy(); + + MultiDvdArchive* archive = &this->multiArchives2[idx]; + RloadMenuKartModel(archive, this->menuManagers[idx].mCharacter, + this->menuManagers[idx].mModelType, + this->menuManagers[idx].archiveHeap, + this->menuManagers[idx].fileHeap); + if (!archive->isLoaded()) { + OSSleepMilliseconds(16); + } + if (archive->isLoaded()) { + this->menuManagers[idx]._unk = 4; + } else { + this->menuManagers[idx]._unk = 0; + } } +} // namespace System // Symbol: unk_80542210 // PAL: 0x80542210..0x805422cc @@ -1506,78 +1385,26 @@ bool ResourceManager::loadGlobeAsync(void* arg) { ? false : requestGlobeTaskHelper(arg, (void*)0x10000004); } -} // namespace System -/*namespace System { -void ResourceManager::loadStaffGhostAsync(GhostFileGroup::GhostGroupType -ghostType, CourseId courseId, u8* destBuffer) { char filename[128]; - - s16 slot = getSlotForCourseId(courseId); - // TODO: 2->slow staff ghost - if (ghostType == 2) { - snprintf(filename, sizeof(filename), -"/Race/TimeAttack/ghost1/ghost1_comp_%02d.rkg", (s32)slot); } else { - snprintf(filename, sizeof(filename), -"/Race/TimeAttack/ghost2/ghost2_comp_%02d.rkg", (s32)slot); - } +void ResourceManager::loadStaffGhostAsync( + GhostFileGroup::GhostGroupType ghostType, CourseId courseId, + u8* destBuffer) { + char filename[128]; - SystemManager::sInstance->ripFromDiscAsync(filename, nullptr, true, nullptr, -destBuffer); -} -}*/ -// Symbol: SaveManager_loadStaffGhostAsync -// PAL: 0x805427bc..0x80542868 -MARK_BINARY_BLOB(SaveManager_loadStaffGhostAsync, 0x805427bc, 0x80542868); -asm UNKNOWN_FUNCTION(SaveManager_loadStaffGhostAsync) { - // clang-format off - nofralloc; - stwu r1, -0x90(r1); - mflr r0; - stw r0, 0x94(r1); - stw r31, 0x8c(r1); - mr r31, r5; - stw r30, 0x88(r1); - mr r30, r3; - mr r3, r4; - bl getSlotForCourseId; - cmpwi r30, 2; - mr r0, r3; - bne lbl_80542810; - lis r4, 0; - addi r3, r1, 8; - addi r4, r4, 0; - extsh r6, r0; - addi r5, r4, 0x1b2; - li r4, 0x80; - crclr 6; - bl unk_805553b0; - b lbl_80542830; -lbl_80542810: - lis r4, 0; - addi r3, r1, 8; - addi r4, r4, 0; - extsh r6, r0; - addi r5, r4, 0x1df; - li r4, 0x80; - crclr 6; - bl unk_805553b0; -lbl_80542830: - lis r3, 0; - mr r8, r31; - lwz r3, 0(r3); - addi r4, r1, 8; - li r5, 0; - li r6, 1; - li r7, 0; - bl unk_805553b0; - lwz r0, 0x94(r1); - lwz r31, 0x8c(r1); - lwz r30, 0x88(r1); - mtlr r0; - addi r1, r1, 0x90; - blr; - // clang-format on + s16 slot = getSlotForCourseId(courseId); + // TODO: 2->slow staff ghost + if (ghostType == 2) { + snprintf(filename, sizeof(filename), + "/Race/TimeAttack/ghost1/ghost1_comp_%02d.rkg", (s32)slot); + } else { + snprintf(filename, sizeof(filename), + "/Race/TimeAttack/ghost2/ghost2_comp_%02d.rkg", (s32)slot); + } + + SystemManager::sInstance->ripFromDiscAsync(filename, nullptr, true, nullptr, + destBuffer); } +} // namespace System // Symbol: unk_80542868 // PAL: 0x80542868..0x80542878 diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 63d6c94e6..ce1727b87 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -379,6 +379,7 @@ class ResourceManager { void flush(); void deinitGlobeHeap(); static void doLoadCharacterKartModel(s32 idxs); + void doLoadCharacterKartModelPriv(s32 idxs); static void doLoadGlobe(void* glodeBlob); void doLoadGlobeImpl(u8** glodeBlob) volatile; // for matching purposes From d62af99fe8c0c01c9518ca43775438ff57519e0e Mon Sep 17 00:00:00 2001 From: Theodoros Tyrovouzis Date: Thu, 7 Jul 2022 13:41:19 +0300 Subject: [PATCH 44/46] loadCharMdlAsync --- source/game/system/ResourceManager.cpp | 77 +++++--------------------- source/game/system/ResourceManager.hpp | 4 +- 2 files changed, 18 insertions(+), 63 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index fb90f80e5..8c30b98cf 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -1127,9 +1127,9 @@ void RloadMenuKartModel(MultiDvdArchive* m, MenuCharacterManager* c) { c->fileHeap); } } // namespace -void ResourceManager::doLoadCharacterKartModel(s32 idxs) { +void ResourceManager::doLoadCharacterKartModel(void* idxs) { ResourceManager* resMgr = ResourceManager::spInstance_REAL; - const u8 idx = idxs; + const u8 idx = (const u8)idxs; if (resMgr->multiArchives2[idx].isLoaded()) { resMgr->multiArchives2[idx].unmount(); } @@ -1169,68 +1169,21 @@ void ResourceManager::doLoadCharacterKartModelPriv(s32 idx) { this->menuManagers[idx]._unk = 0; } } -} // namespace System -// Symbol: unk_80542210 -// PAL: 0x80542210..0x805422cc -MARK_BINARY_BLOB(unk_80542210, 0x80542210, 0x805422cc); -asm UNKNOWN_FUNCTION(unk_80542210) { - // clang-format off - nofralloc; - stwu r1, -0x10(r1); - mflr r0; - mulli r9, r4, 0x18; - mr r10, r4; - stw r0, 0x14(r1); - li r7, 0; - add r4, r3, r9; - lwz r0, 0x5b0(r4); - cmpwi r0, 0; - beq lbl_80542268; - lwz r8, 0x5b8(r4); - li r4, 0; - cmplwi r8, 4; - bgt lbl_8054225c; - li r0, 1; - slw r0, r0, r8; - andi. r0, r0, 0x15; - beq lbl_8054225c; - li r4, 1; -lbl_8054225c: - cmpwi r4, 0; - beq lbl_80542268; - li r7, 1; -lbl_80542268: - cmpwi r7, 0; - bne lbl_80542278; - li r3, 0; - b lbl_805422bc; -lbl_80542278: - add r7, r3, r9; - li r4, 1; - stw r5, 0x5bc(r7); - stw r6, 0x5c0(r7); - stw r4, 0x5b8(r7); - lbz r0, 0x619(r3); - cmpwi r0, 0; - beq lbl_805422b8; - stb r4, 0x618(r3); - lis r4, 0; - lis r6, 0x1000; - lwz r3, 0x584(r3); - mr r5, r10; - addi r4, r4, 0; - addi r6, r6, 3; - bl unk_805553b0; -lbl_805422b8: - li r3, 1; -lbl_805422bc: - lwz r0, 0x14(r1); - mtlr r0; - addi r1, r1, 0x10; - blr; - // clang-format on +bool ResourceManager::loadKartMenuModelAsync(s32 idx, CharacterId characterId, + BattleTeam battleTeam) { + if (!this->menuManagers[idx].SOME_CHECK()) { + return false; + } else { + this->menuManagers[idx].mCharacter = characterId; + this->menuManagers[idx].mModelType = battleTeam; + this->menuManagers[idx]._unk = 1; + this->requestTask(ResourceManager::doLoadCharacterKartModel, (void*)idx, + (void*)0x10000003); + return true; + } } +} // namespace System // Symbol: unk_805422cc // PAL: 0x805422cc..0x805423bc diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index ce1727b87..5e6844693 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -378,8 +378,10 @@ class ResourceManager { void initGlobeHeap(size_t size, EGG::Heap* heap); void flush(); void deinitGlobeHeap(); - static void doLoadCharacterKartModel(s32 idxs); + static void doLoadCharacterKartModel(void* idxs); void doLoadCharacterKartModelPriv(s32 idxs); + bool loadKartMenuModelAsync(s32 idx, CharacterId characterId, + BattleTeam battleTeam); static void doLoadGlobe(void* glodeBlob); void doLoadGlobeImpl(u8** glodeBlob) volatile; // for matching purposes From 4b7731b32b1d226f8050c34b967f5e43a5e91203 Mon Sep 17 00:00:00 2001 From: Theodoros Tyrovouzis Date: Thu, 7 Jul 2022 13:58:56 +0300 Subject: [PATCH 45/46] FUN22CC --- source/game/system/ResourceManager.cpp | 196 ++++--------------------- source/game/system/ResourceManager.hpp | 11 ++ 2 files changed, 37 insertions(+), 170 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 8c30b98cf..27dd330e6 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -25,6 +25,9 @@ extern const char* EarthResourceListing; struct GameScene { u8 _00[0xc94 - 0x0]; HeapCollection dynamicHeaps; + inline EGG::ExpHeap*& getHeap(s32 heapIdx) { + return dynamicHeaps.mpHeaps[heapIdx]; + } }; extern "C" GameScene* getGameScene(); @@ -782,103 +785,6 @@ void ResourceManager::attachArcResourceAccessor(void* arcResourceAccessor, ArcResourceAccessor_attach(arcResourceAccessor, archiveStart, dirname); } -} // namespace System - -// Symbol: ResourceManager_attachLayoutDir -// PAL: 0x80541878..0x80541998 -/*MARK_BINARY_BLOB(ResourceManager_attachLayoutDir, 0x80541878, 0x80541998); -asm UNKNOWN_FUNCTION(ResourceManager_attachLayoutDir) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - cmpwi r7, 0; - stw r0, 0x24(r1); - stmw r26, 8(r1); - mr r27, r3; - mr r28, r4; - mr r29, r5; - mr r30, r6; - bne lbl_805418a4; - bl getGameScene; -lbl_805418a4: - li r31, 0; - b lbl_80541950; -lbl_805418ac: - lhz r0, 8(r30); - clrlwi r3, r31, 0x10; - cmplw r3, r0; - bge lbl_805418cc; - mulli r0, r3, 0xa4; - lwz r3, 4(r30); - add r26, r3, r0; - b lbl_805418d0; -lbl_805418cc: - li r26, 0; -lbl_805418d0: - lwz r3, 4(r27); - lwz r3, 8(r3); - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - bne lbl_805418ec; - li r0, 0; - b lbl_80541938; -lbl_805418ec: - lwz r3, 4(r27); - clrlwi r0, r31, 0x10; - lwz r4, 8(r3); - lhz r3, 8(r4); - cmplw r0, r3; - bge lbl_80541934; - mr r3, r26; - bge lbl_80541920; - mulli r0, r0, 0x24; - lwz r4, 4(r4); - add r4, r4, r0; - lwz r4, 8(r4); - b lbl_80541924; -lbl_80541920: - li r4, 0; -lbl_80541924: - mr r5, r29; - bl unk_805553b0; - li r0, 1; - b lbl_80541938; -lbl_80541934: - li r0, 0; -lbl_80541938: - cmpwi r0, 0; - beq lbl_8054194c; - mr r3, r28; - mr r4, r26; - bl unk_805553b0; -lbl_8054194c: - addi r31, r31, 1; -lbl_80541950: - lwz r3, 4(r27); - lwz r3, 8(r3); - bl isLoaded__Q26System15MultiDvdArchiveFv; - cmpwi r3, 0; - beq lbl_80541974; - lwz r3, 4(r27); - lwz r3, 8(r3); - lhz r3, 8(r3); - b lbl_80541978; -lbl_80541974: - li r3, 0; -lbl_80541978: - clrlwi r0, r31, 0x10; - cmplw r0, r3; - blt lbl_805418ac; - lmw r26, 8(r1); - lwz r0, 0x24(r1); - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on -}*/ - -namespace System { void ResourceManager::attatchLayoutDir(void* accessor, const char* dirname, Whatever2* whatever2, bool param_5) { if (!param_5) { @@ -1183,82 +1089,32 @@ bool ResourceManager::loadKartMenuModelAsync(s32 idx, CharacterId characterId, return true; } } -} // namespace System -// Symbol: unk_805422cc -// PAL: 0x805422cc..0x805423bc -MARK_BINARY_BLOB(unk_805422cc, 0x805422cc, 0x805423bc); -asm UNKNOWN_FUNCTION(unk_805422cc) { - // clang-format off - nofralloc; - stwu r1, -0x20(r1); - mflr r0; - stw r0, 0x24(r1); - stmw r26, 8(r1); - mr r28, r3; - mr r29, r4; - mr r26, r5; - bl getGameScene; - slwi r31, r26, 2; - lis r5, 0xd; - add r3, r3, r31; - lwz r4, 0xc94(r3); - addi r3, r5, -32768; - li r5, 0; - bl unk_805553b0; - stw r3, 0x610(r28); - li r30, 0; - lis r26, 0xe; - li r27, 0; -lbl_80542318: - clrlwi r0, r30, 0x18; - cmplw r0, r29; - bge lbl_80542374; - bl getGameScene; - mr r0, r3; - addi r3, r26, 0x1000; - add r4, r0, r31; - li r5, 0; - lwz r4, 0xc94(r4); - bl unk_805553b0; - clrlwi r0, r30, 0x18; - mulli r0, r0, 0x18; - add r4, r28, r0; - lwz r0, 0x5b0(r4); - cmpwi r0, 0; - bne lbl_8054235c; - stw r3, 0x5b0(r4); -lbl_8054235c: - lwz r0, 0x5b4(r4); - lwz r3, 0x610(r28); - cmpwi r0, 0; - bne lbl_8054239c; - stw r3, 0x5b4(r4); - b lbl_8054239c; -lbl_80542374: - mulli r0, r0, 0x18; - add r3, r28, r0; - lwz r0, 0x5b0(r3); - cmpwi r0, 0; - bne lbl_8054238c; - stw r27, 0x5b0(r3); -lbl_8054238c: - lwz r0, 0x5b4(r3); - cmpwi r0, 0; - bne lbl_8054239c; - stw r27, 0x5b4(r3); -lbl_8054239c: - addi r30, r30, 1; - cmplwi r30, 4; - blt lbl_80542318; - lmw r26, 8(r1); - lwz r0, 0x24(r1); - mtlr r0; - addi r1, r1, 0x20; - blr; - // clang-format on +static inline EGG::ExpHeap* createExpHeap(u32 size, s32 heapIdx) { + return EGG::ExpHeap::create(size, getGameScene()->getHeap(heapIdx), 0); } +static inline void setHeap(EGG::ExpHeap** heapDest, EGG::ExpHeap* heapSrc) { + if (*heapDest == 0) { + *heapDest = heapSrc; + } +} + +void ResourceManager::FUN_805422cc(u32 count, s32 heapIdx) { + this->_610 = createExpHeap(0xc8000, heapIdx); + for (u8 i = 0; i < 4; i++) { + if (i < count) { + EGG::ExpHeap* heap = createExpHeap(0xe1000, heapIdx); + this->menuManagers[i].setArchiveHeap(heap); + this->menuManagers[i].setFileHeap(this->_610); + } else { + this->menuManagers[i].setArchiveHeap(0); + this->menuManagers[i].setFileHeap(0); + } + } +} +} // namespace System + namespace System { void ResourceManager::clear() { diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 5e6844693..3ccc58c25 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -224,6 +224,16 @@ struct T { } _unk = 3; } + inline void setArchiveHeap(EGG::ExpHeap* heapSrc) { + if (this->archiveHeap == 0) { + this->archiveHeap = heapSrc; + } + } + inline void setFileHeap(EGG::ExpHeap* heapSrc) { + if (this->fileHeap == 0) { + this->fileHeap = heapSrc; + } + } }; class MenuCharacterManager : S, public T { @@ -382,6 +392,7 @@ class ResourceManager { void doLoadCharacterKartModelPriv(s32 idxs); bool loadKartMenuModelAsync(s32 idx, CharacterId characterId, BattleTeam battleTeam); + void FUN_805422cc(u32 count, s32 heapIdx); static void doLoadGlobe(void* glodeBlob); void doLoadGlobeImpl(u8** glodeBlob) volatile; // for matching purposes From f2b0dfe4dbe46d9dd9096084cc8f0f82445784a8 Mon Sep 17 00:00:00 2001 From: Aiden Date: Thu, 7 Jul 2022 13:14:57 -0400 Subject: [PATCH 46/46] ResourceManager: start cleanup --- source/game/system/ResourceManager.cpp | 410 +++++++++++----------- source/game/system/ResourceManager.hpp | 468 +++++++++++++------------ 2 files changed, 455 insertions(+), 423 deletions(-) diff --git a/source/game/system/ResourceManager.cpp b/source/game/system/ResourceManager.cpp index 27dd330e6..9b337c1c2 100644 --- a/source/game/system/ResourceManager.cpp +++ b/source/game/system/ResourceManager.cpp @@ -24,9 +24,9 @@ extern const char* EarthResourceListing; // TODO: Define externally struct GameScene { u8 _00[0xc94 - 0x0]; - HeapCollection dynamicHeaps; + HeapCollection mDynamicHeaps; inline EGG::ExpHeap*& getHeap(s32 heapIdx) { - return dynamicHeaps.mpHeaps[heapIdx]; + return mDynamicHeaps.mpHeaps[heapIdx]; } }; extern "C" GameScene* getGameScene(); @@ -190,7 +190,7 @@ extern UNKNOWN_FUNCTION(unk_805553b0); namespace System { volatile ResourceManager* ResourceManager::createInstance() { - if (spInstance == nullptr) { + if (!spInstance) { spInstance = new ResourceManager(); } @@ -198,7 +198,7 @@ volatile ResourceManager* ResourceManager::createInstance() { } void ResourceManager::destroyInstance() { - if (spInstance != nullptr) { + if (spInstance) { delete spInstance; } spInstance = nullptr; @@ -206,34 +206,35 @@ void ResourceManager::destroyInstance() { ResourceManager::ResourceManager() { foo(); - taskThread = EGG::TaskThread::create(14, 24, 0xC800, scenePtr->getA()); - taskThread->mTaskEndMessageQueue = &System::SystemManager::sInstance->_B8; - multiArchives1 = new MultiDvdArchive*[9]; + mpTaskThread = EGG::TaskThread::create(14, 24, 0xC800, scenePtr->getA()); + mpTaskThread->mTaskEndMessageQueue = &System::SystemManager::sInstance->_B8; + mppSceneArchives = new MultiDvdArchive*[9]; for (u16 i = 0; i < 9; ++i) { - multiArchives1[i] = createMultiDvdArchive((ResourceChannelID)i); + mppSceneArchives[i] = createMultiDvdArchive((ResourceChannelID)i); } bar(); } System::ResourceManager::~ResourceManager() { - taskThread->destroy(); - taskThread = nullptr; + mpTaskThread->destroy(); + mpTaskThread = nullptr; } void ResourceManager::doLoadTask(void* jobContext) { - JobContext* context = (JobContext*)&spInstance->jobContexts[(s32)jobContext]; + JobContext* context = (JobContext*)&spInstance->mJobContexts[(s32)jobContext]; switch ((s32)jobContext) { case 6: - context->archive->load(context->filename, context->_08, - context->archiveHeap); + context->mpArchive->load(context->mFilename, context->_08, + context->mpArchiveHeap); return; case 5: - context->multiArchive->load(context->filename, context->archiveHeap, - context->fileHeap, 0); + context->mpMultiArchive->load(context->mFilename, context->mpArchiveHeap, + context->mpFileHeap, 0); return; default: - context->multiArchive->load(context->filename, context->archiveHeap, 0, 0); + context->mpMultiArchive->load(context->mFilename, context->mpArchiveHeap, 0, + 0); return; } } @@ -358,14 +359,15 @@ void _unk_call14(Dummy* dummy) { dummy->_14(); } void _unk_call1c(Dummy* dummy) { dummy->_1C(); } namespace System { + void ResourceManager::requestLoad(s32 idx, MultiDvdArchive* m, const char* p, EGG::Heap* archiveHeap) { - this->jobContexts[idx].multiArchive = m; - strncpy(this->jobContexts[idx].filename, p, 0x40); - this->jobContexts[idx].archiveHeap = archiveHeap; + mJobContexts[idx].mpMultiArchive = m; + strncpy(mJobContexts[idx].mFilename, p, 0x40); + mJobContexts[idx].mpArchiveHeap = archiveHeap; - this->taskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); - this->process(); + mpTaskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); + process(); if (!m->isLoaded()) { OSSleepMilliseconds(16); @@ -375,13 +377,13 @@ void ResourceManager::requestLoad(s32 idx, MultiDvdArchive* m, const char* p, void ResourceManager::requestLoad(s32 idx, DvdArchive* archive, const char* filename, u32 unk, EGG::Heap* archiveHeap) { - this->jobContexts[idx].archive = archive; - strncpy(this->jobContexts[idx].filename, filename, 0x40); - this->jobContexts[idx].archiveHeap = archiveHeap; - this->jobContexts[idx]._08 = unk; + mJobContexts[idx].mpArchive = archive; + strncpy(mJobContexts[idx].mFilename, filename, 0x40); + mJobContexts[idx].mpArchiveHeap = archiveHeap; + mJobContexts[idx]._08 = unk; - this->taskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); - this->process(); + mpTaskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); + process(); if (!archive->isLoaded()) { OSSleepMilliseconds(16); @@ -391,13 +393,13 @@ void ResourceManager::requestLoad(s32 idx, DvdArchive* archive, void ResourceManager::requestLoad(s32 idx, MultiDvdArchive* archive, const char* filename, EGG::Heap* archiveHeap, EGG::Heap* fileHeap) { - this->jobContexts[idx].multiArchive = archive; - strncpy(this->jobContexts[idx].filename, filename, 0x40); - this->jobContexts[idx].archiveHeap = archiveHeap; - this->jobContexts[idx].fileHeap = fileHeap; + mJobContexts[idx].mpMultiArchive = archive; + strncpy(mJobContexts[idx].mFilename, filename, 0x40); + mJobContexts[idx].mpArchiveHeap = archiveHeap; + mJobContexts[idx].mpFileHeap = fileHeap; - this->taskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); - this->process(); + mpTaskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); + process(); if (!archive->isLoaded()) { OSSleepMilliseconds(16); @@ -411,32 +413,35 @@ MultiDvdArchive* ResourceManager::load(ResourceChannelID channelId, filename = RESOURCES[channelId]; } - if (!isMultiArchive1Loaded(channelId) && filename[0]) { - requestLoad(0, this->multiArchives1[channelId], filename, archiveHeap); + if (!isSceneArchiveLoaded(channelId) && filename[0]) { + requestLoad(0, mppSceneArchives[channelId], filename, archiveHeap); } - return this->multiArchives1[channelId]; + return mppSceneArchives[channelId]; } DvdArchive* ResourceManager::loadSystemResource(s32 idx, EGG::Heap* archiveHeap) { - if (!isDvdArchiveLoaded(idx)) { + if (!isSystemArchiveLoaded(idx)) { const char* resourcePath = Resource::GetResourcePath((eSystemResource)idx); + if (resourcePath[0] != 0) { - requestLoadFile( - 6, &dvdArchives[idx], Resource::GetResourcePath((eSystemResource)idx), - Resource::GetResourceID((eSystemResource)idx), archiveHeap); + requestLoadFile(6, &mSystemArchives[idx], + Resource::GetResourcePath((eSystemResource)idx), + Resource::GetResourceID((eSystemResource)idx), + archiveHeap); } } - return &dvdArchives[idx]; + + return &mSystemArchives[idx]; } MultiDvdArchive* ResourceManager::loadUI(const char* filename, EGG::Heap* archiveHeap) { - if (!isMultiArchive1Loaded(2) && filename) { - requestLoad(1, this->multiArchives1[2], filename, archiveHeap); + if (!isSceneArchiveLoaded(2) && filename) { + requestLoad(1, mppSceneArchives[2], filename, archiveHeap); } - return this->multiArchives1[2]; + return mppSceneArchives[2]; } MultiDvdArchive* ResourceManager::loadCourse(CourseId courseId, @@ -444,18 +449,21 @@ MultiDvdArchive* ResourceManager::loadCourse(CourseId courseId, bool splitScreen) { char courseName[128]; - if (!isMultiArchive1Loaded(1)) { - this->multiArchives1[1]->init(); - if (!splitScreen && this->courseCache.mState == 2 && - courseId == this->courseCache.mCourseId) { - MultiDvdArchive* m = this->multiArchives1[1]; - if (this->courseCache.mState == 2) - m->loadOther(this->courseCache.mArchive, param_3); + if (!isSceneArchiveLoaded(1)) { + mppSceneArchives[1]->init(); + + if (!splitScreen && mCourseCache.mState == 2 && + courseId == mCourseCache.mCourseId) { + MultiDvdArchive* m = mppSceneArchives[1]; + + if (mCourseCache.mState == 2) + m->loadOther(mCourseCache.mpArchive, param_3); } else { if (splitScreen) { snprintf(courseName, sizeof(courseName), "Race/Course/%s_d", COURSE_NAMES[courseId]); - if (!this->multiArchives1[1]->exists(courseName)) { + + if (!mppSceneArchives[1]->exists(courseName)) { splitScreen = false; } } @@ -463,10 +471,10 @@ MultiDvdArchive* ResourceManager::loadCourse(CourseId courseId, snprintf(courseName, sizeof(courseName), "Race/Course/%s", COURSE_NAMES[courseId]); } - requestLoad(2, this->multiArchives1[1], courseName, param_3); + requestLoad(2, mppSceneArchives[1], courseName, param_3); } } - return this->multiArchives1[1]; + return mppSceneArchives[1]; } MultiDvdArchive* ResourceManager::loadMission(CourseId courseId, s32 missionNum, @@ -475,26 +483,31 @@ MultiDvdArchive* ResourceManager::loadMission(CourseId courseId, s32 missionNum, char missionPath[128]; char courseName[128]; - if (!isMultiArchive1Loaded(1)) { - this->multiArchives1[1]->init(); + if (!isSceneArchiveLoaded(1)) { + mppSceneArchives[1]->init(); + snprintf(missionPath, sizeof(missionPath), "Race/MissionRun/mr%02d.szs", missionNum); - MultiDvdArchive* archive = this->multiArchives1[1]; + + MultiDvdArchive* archive = mppSceneArchives[1]; + if (archive->archiveCount > 1) { archive->kinds[1] = RES_KIND_FILE_SINGLE_FORMAT; strncpy(archive->suffixes[1], missionPath, sizeof(missionPath)); } - if (!splitScreen && this->courseCache.mState == 2 && - courseId == this->courseCache.mCourseId) { - MultiDvdArchive* m = this->multiArchives1[1]; - if (this->courseCache.mState == 2) - m->loadOther(this->courseCache.mArchive, param_3); + if (!splitScreen && mCourseCache.mState == 2 && + courseId == mCourseCache.mCourseId) { + MultiDvdArchive* m = mppSceneArchives[1]; + + if (mCourseCache.mState == 2) + m->loadOther(mCourseCache.mpArchive, param_3); } else { if (splitScreen) { snprintf(courseName, sizeof(courseName), "Race/Course/%s_d", COURSE_NAMES[courseId]); - if (!this->multiArchives1[1]->exists(courseName)) { + + if (!mppSceneArchives[1]->exists(courseName)) { splitScreen = false; } } @@ -502,10 +515,10 @@ MultiDvdArchive* ResourceManager::loadMission(CourseId courseId, s32 missionNum, snprintf(courseName, sizeof(courseName), "Race/Course/%s", COURSE_NAMES[courseId]); } - requestLoad(3, this->multiArchives1[1], courseName, param_3); + requestLoad(3, mppSceneArchives[1], courseName, param_3); } } - return this->multiArchives1[1]; + return mppSceneArchives[1]; } MultiDvdArchive* ResourceManager::loadCompetition(CourseId courseId, @@ -514,16 +527,17 @@ MultiDvdArchive* ResourceManager::loadCompetition(CourseId courseId, char competitionPath[128]; char courseName[128]; - if (!isMultiArchive1Loaded(1)) { - this->multiArchives1[1]->init(); + if (!isSceneArchiveLoaded(1)) { + mppSceneArchives[1]->init(); u16 objCount = 1; u16 var4 = 0; + for (u8 i = 0; i < 0x10; i++) { if ((param6 & (1 << i)) != 0) { snprintf(competitionPath, sizeof(competitionPath), "Race/Competition/CommonObj/CommonObj%02d.szs", i + 1); - MultiDvdArchive* archive = this->multiArchives1[1]; + MultiDvdArchive* archive = mppSceneArchives[1]; if (objCount < archive->archiveCount) { archive->kinds[objCount] = RES_KIND_FILE_SINGLE_FORMAT; @@ -538,8 +552,8 @@ MultiDvdArchive* ResourceManager::loadCompetition(CourseId courseId, } } - if (objCount < this->multiArchives1[1]->archiveCount) { - MultiDvdArchive* archive = this->multiArchives1[1]; + if (objCount < mppSceneArchives[1]->archiveCount) { + MultiDvdArchive* archive = mppSceneArchives[1]; archive->kinds[objCount] = RES_KIND_BUFFER; archive->fileStarts[objCount] = fileStart; archive->fileSizes[objCount] = fileSize; @@ -547,9 +561,9 @@ MultiDvdArchive* ResourceManager::loadCompetition(CourseId courseId, snprintf(courseName, sizeof(courseName), "Race/Course/%s", COURSE_NAMES[courseId]); - requestLoad(4, this->multiArchives1[1], courseName, heap); + requestLoad(4, mppSceneArchives[1], courseName, heap); } - return this->multiArchives1[1]; + return mppSceneArchives[1]; } MultiDvdArchive* ResourceManager::loadKartFromArchive( @@ -570,12 +584,13 @@ MultiDvdArchive* ResourceManager::loadKartFromArchive2( s32 archiveIdx, VehicleId vehicleId, CharacterId characterId, BattleTeam battleTeamId, PlayMode playMode, EGG::Heap* archiveHeap, EGG::Heap* fileHeap) { - MultiDvdArchive* archive = &this->multiArchives2[archiveIdx]; + MultiDvdArchive* archive = &mKartArchives[archiveIdx]; char path[128]; if (!archive->isLoaded()) { const char* driver = getCharacterName(characterId); const char* kart = getVehicleName(vehicleId); + snprintf(path, sizeof(path), "Race/Kart/%s%s-%s%s", kart, TEAM_SUFFIXES[battleTeamId], driver, LOD_RES_SUFFIXES[playMode]); requestLoadFile(5, archive, path, archiveHeap, fileHeap); @@ -588,7 +603,7 @@ MultiDvdArchive* ResourceManager::loadKartFromArchive3( s32 archiveIdx, VehicleId vehicleId, CharacterId characterId, BattleTeam battleTeamId, PlayMode playMode, EGG::Heap* archiveHeap, EGG::Heap* fileHeap) { - MultiDvdArchive* archive = &this->multiArchives3[archiveIdx]; + MultiDvdArchive* archive = &mBackupKartArchives[archiveIdx]; char path[128]; if (!archive->isLoaded()) { @@ -610,8 +625,8 @@ MultiDvdArchive* ResourceManager::loadMenuKartModel(s32 archiveIdx, const char* characterName; char buffer[128]; - if (!isMultiArchive2Loaded(archiveIdx)) { - if (battleTeam == 2) { // not in battle mode + if (!isKartArchiveLoaded(archiveIdx)) { + if (battleTeam == BATTLE_TEAM_NONE) { characterName = getCharacterName(characterId); snprintf(buffer, sizeof(buffer), "Scene/Model/Kart/%s-allkart", characterName); @@ -620,64 +635,66 @@ MultiDvdArchive* ResourceManager::loadMenuKartModel(s32 archiveIdx, snprintf(buffer, sizeof(buffer), "Scene/Model/Kart/%s-allkart_BT", characterName); } - multiArchives2[archiveIdx].load(buffer, archiveHeap, fileHeap, 0); + mKartArchives[archiveIdx].load(buffer, archiveHeap, fileHeap, 0); } - return &multiArchives2[archiveIdx]; + return &mKartArchives[archiveIdx]; } void ResourceManager::unmountMulti(s32 archiveIdx) { - multiArchives1[archiveIdx]->unmount(); + mppSceneArchives[archiveIdx]->unmount(); } void ResourceManager::unmountMulti(MultiDvdArchive* other) { other->unmount(); } void ResourceManager::unmountArchive(s32 archiveIdx) { - dvdArchives[archiveIdx].unmount(); + mSystemArchives[archiveIdx].unmount(); } void* ResourceManager::getFile(s32 archiveIdx, const char* filename, size_t* size) { - return isMultiArchive1Loaded(archiveIdx) - ? multiArchives1[archiveIdx]->getFile(filename, size) + return isSceneArchiveLoaded(archiveIdx) + ? mppSceneArchives[archiveIdx]->getFile(filename, size) : nullptr; } void* ResourceManager::getCharacterFile(CharacterId characterId, size_t* size) { char buffer[128]; - if (!isMultiArchive1Loaded(6)) { + if (!isSceneArchiveLoaded(6)) { return nullptr; } + const char* character = getCharacterName(characterId); // I can't believe this compiles snprintf("%s.brres", sizeof(buffer), character); - return multiArchives1[6]->getFile(buffer, size); + return mppSceneArchives[6]->getFile(buffer, size); } void* ResourceManager::getVehicleFile(s32 archiveIdx, VehicleId vehicleId, size_t* size) { char buffer[128]; - if (!isMultiArchive2Loaded(archiveIdx)) { + if (!isKartArchiveLoaded(archiveIdx)) { return nullptr; } + const char* vehicle = getVehicleName(vehicleId); // I can't believe this compiles snprintf("%s.brres", sizeof(buffer), vehicle); - return multiArchives2[archiveIdx].getFile(buffer, size); + return mKartArchives[archiveIdx].getFile(buffer, size); } -void* ResourceManager::getMultiFile2(s32 idx, const char* filename, - size_t* size) { - return isMultiArchive2Loaded(idx) - ? this->multiArchives2[idx].getFile(filename, size) +void* ResourceManager::getKartArchiveFile(s32 idx, const char* filename, + size_t* size) { + return isKartArchiveLoaded(idx) + ? this->mKartArchives[idx].getFile(filename, size) : nullptr; } -void* ResourceManager::getMultiFile3(s32 idx, const char* filename, - size_t* size) { - return isMultiArchive3Loaded(idx) - ? this->multiArchives3[idx].getFile(filename, size) +void* ResourceManager::getBackupKartArchiveFile(s32 idx, const char* filename, + size_t* size) { + return isBackupKartArchiveLoaded(idx) + ? this->mBackupKartArchives[idx].getFile(filename, size) : nullptr; } @@ -689,39 +706,40 @@ void* ResourceManager::getBspFile(s32 playerIdx, size_t* size) { .vehicleId); snprintf(buffer, sizeof(buffer), "/bsp/%s.bsp", vehicle); - return (isMultiArchive1Loaded(0)) ? multiArchives1[0]->getFile(buffer, size) - : nullptr; + return (isSceneArchiveLoaded(0)) ? mppSceneArchives[0]->getFile(buffer, size) + : nullptr; } void* ResourceManager::getFileCopy(s32 archiveIdx, char* filename, EGG::Heap* heap, size_t* size, s8 param_5) { - return !isDvdArchiveLoaded(archiveIdx) ? nullptr - : dvdArchives[archiveIdx].getFileCopy( - filename, heap, size, param_5); + return !isSystemArchiveLoaded(archiveIdx) + ? nullptr + : mSystemArchives[archiveIdx].getFileCopy(filename, heap, size, + param_5); } -bool ResourceManager::isMultiArchive1Loaded(s32 idx) volatile { - return this->multiArchives1[idx]->isLoaded(); +bool ResourceManager::isSceneArchiveLoaded(s32 idx) volatile { + return mppSceneArchives[idx]->isLoaded(); } -bool ResourceManager::isMultiArchive2Loaded(s32 idx) { - return this->multiArchives2[idx].isLoaded(); +bool ResourceManager::isKartArchiveLoaded(s32 idx) { + return mKartArchives[idx].isLoaded(); } -bool ResourceManager::isMultiArchive3Loaded(s32 idx) { - return this->multiArchives3[idx].isLoaded(); +bool ResourceManager::isBackupKartArchiveLoaded(s32 idx) { + return mBackupKartArchives[idx].isLoaded(); } -bool ResourceManager::isDvdArchiveLoaded(s32 idx) { - return this->dvdArchives[idx].isLoaded(); +bool ResourceManager::isSystemArchiveLoaded(s32 idx) { + return mSystemArchives[idx].isLoaded(); } void* ResourceManager::getArchiveStart(ResourceChannelID resId, u32 archiveIdx) { - if (!isMultiArchive1Loaded(resId)) { + if (!isSceneArchiveLoaded(resId)) { return nullptr; - } else if (archiveIdx < this->multiArchives1[resId]->archiveCount) { - return this->multiArchives1[resId]->archives[archiveIdx].mArchiveStart; + } else if (archiveIdx < mppSceneArchives[resId]->archiveCount) { + return mppSceneArchives[resId]->archives[archiveIdx].mArchiveStart; } return nullptr; } @@ -731,14 +749,14 @@ bool ResourceManager::setArcResourceLink(s32 multiIdx, u16 archiveIdx, const char* dirname) { void* archiveStart; - if (!multiArchives1[multiIdx]->isLoaded()) { + if (!mppSceneArchives[multiIdx]->isLoaded()) { return false; } - if (archiveIdx < multiArchives1[multiIdx]->archiveCount) { + if (archiveIdx < mppSceneArchives[multiIdx]->archiveCount) { archiveStart = - (archiveIdx < multiArchives1[multiIdx]->archiveCount) - ? multiArchives1[multiIdx]->archives[archiveIdx].mArchiveStart + (archiveIdx < mppSceneArchives[multiIdx]->archiveCount) + ? mppSceneArchives[multiIdx]->archives[archiveIdx].mArchiveStart : nullptr; ArcResourceLink_set(arcResource, archiveStart, dirname); return true; @@ -748,12 +766,11 @@ bool ResourceManager::setArcResourceLink(s32 multiIdx, u16 archiveIdx, } u16 ResourceManager::getLoadedArchiveCount(s32 idx) { - return isMultiArchive1Loaded(idx) ? this->multiArchives1[idx]->archiveCount - : 0; + return isSceneArchiveLoaded(idx) ? mppSceneArchives[idx]->archiveCount : 0; } u16 ResourceManager::getMenuArchiveCount() { - return this->multiArchives1[2]->archiveCount; + return mppSceneArchives[2]->archiveCount; } void ResourceManager::attachArcResourceAccessor(void* arcResourceAccessor, @@ -762,10 +779,10 @@ void ResourceManager::attachArcResourceAccessor(void* arcResourceAccessor, // ping me tomorrow to clean this up void* archiveStart; - if (!isMultiArchive1Loaded(2)) { + if (!isSceneArchiveLoaded(2)) { archiveStart = nullptr; - } else if (multiArchives1[2]->archiveCount != 0) { - archiveStart = multiArchives1[2]->archives->mArchiveStart; + } else if (mppSceneArchives[2]->archiveCount != 0) { + archiveStart = mppSceneArchives[2]->archives->mArchiveStart; } else { archiveStart = nullptr; } @@ -774,10 +791,10 @@ void ResourceManager::attachArcResourceAccessor(void* arcResourceAccessor, return; } - if (!isMultiArchive1Loaded(2)) { + if (!isSceneArchiveLoaded(2)) { archiveStart = nullptr; - } else if (multiArchives1[2]->archiveCount != 0) { - archiveStart = multiArchives1[2]->archives->mArchiveStart; + } else if (mppSceneArchives[2]->archiveCount != 0) { + archiveStart = mppSceneArchives[2]->archives->mArchiveStart; } else { archiveStart = nullptr; } @@ -793,6 +810,7 @@ void ResourceManager::attatchLayoutDir(void* accessor, const char* dirname, for (u16 i = 0; i < this->getLoadedArchiveCountInverse(RES_CHAN_UI); i++) { void* arcResource; + if (i < whatever2->_08) { arcResource = &whatever2->_04[i]; } else { @@ -811,15 +829,14 @@ void ResourceManager::attatchLayoutDir(void* accessor, const char* dirname, #endif void preloadCourseTask(void* courseId) { ((ResourceManager*)ResourceManager::spInstance) - ->courseCache.load((CourseId)courseId); + ->mCourseCache.load((CourseId)courseId); } #ifdef __CWCC__ #pragma dont_inline off #endif void ResourceManager::preloadCourseAsync(CourseId courseId) { - this->taskThread->request(preloadCourseTask, (void*)courseId, - (void*)0x10000002); + mpTaskThread->request(preloadCourseTask, (void*)courseId, (void*)0x10000002); } const char* getCharacterName(CharacterId charId) { @@ -831,44 +848,44 @@ const char* getVehicleName(VehicleId vehicleId) { } CourseCache::CourseCache() { - mBuffer = nullptr; - mHeap = nullptr; - mArchive = new CourseDvdArchive(); + mpBuffer = nullptr; + mpHeap = nullptr; + mpArchive = new CourseDvdArchive(); } void CourseCache::init() { void* block = new (-32) u8[0x319000]; - mBuffer = block; - mHeap = EGG::ExpHeap::create(block, 0x319000, 1); + mpBuffer = block; + mpHeap = EGG::ExpHeap::create(block, 0x319000, 1); } CourseCache::~CourseCache() { - mArchive->clear(); - if (mHeap) { - mHeap->destroy(); - delete[](mBuffer); + mpArchive->clear(); + if (mpHeap) { + mpHeap->destroy(); + delete[](mpBuffer); } } void CourseCache::load(CourseId courseId) { - if (!mHeap) + if (!mpHeap) return; char buffer[128]; mCourseId = courseId; if (mState == 2) { - mArchive->clear(); + mpArchive->clear(); } - mState = 1; + mState = COURSE_CACHE_STATE_UNK1; snprintf(buffer, sizeof(buffer), "Race/Course/%s", COURSE_NAMES[mCourseId]); - mArchive->rip(buffer, mHeap); + mpArchive->rip(buffer, mpHeap); - if ((u16)mArchive->rippedArchiveCount()) { - mState = 2; + if ((u16)mpArchive->rippedArchiveCount()) { + mState = COURSE_CACHE_STATE_UNK2; } else { - mArchive->clear(); - mState = 0; + mpArchive->clear(); + mState = COURSE_CACHE_STATE_UNK0; } } @@ -876,7 +893,7 @@ void CourseCache::loadOther(MultiDvdArchive* other, EGG::Heap* heap) { if (mState != 2) return; - other->loadOther(mArchive, heap); + other->loadOther(mpArchive, heap); } } // namespace System @@ -884,23 +901,25 @@ void CourseCache::loadOther(MultiDvdArchive* other, EGG::Heap* heap) { char* _unk_getNullString() { return ""; } namespace System { + bool ResourceManager::tryRequestTask(EGG::TaskThread::TFunction fun, void* arg) { bool res = this->requestTask(fun, arg, (void*)0x10000001); if (res) { - this->process(); + process(); } return res; } bool ResourceManager::requestTask(EGG::TaskThread::TFunction fun, void* arg, void* _8) { - if (this->requestsEnabled) { - this->requestPending = true; - return this->taskThread->request(fun, arg, _8); + if (mRequestsEnabled) { + mRequestPending = true; + return mpTaskThread->request(fun, arg, _8); } return false; } + } // namespace System // Symbol: unk_80541ce0 @@ -1012,13 +1031,14 @@ asm UNKNOWN_FUNCTION(flush__Q26System15ResourceManagerFv) { namespace System { namespace { + void RloadMenuKartModel(MultiDvdArchive* m, CharacterId characterId, BattleTeam battleTeam, EGG::Heap* archiveHeap, EGG::Heap* fileHeap) { char buffer[128]; if (!m->isLoaded()) { - if (battleTeam == 2) { // not in battle mode + if (battleTeam == BATTLE_TEAM_NONE) { // not in battle mode snprintf(buffer, sizeof(buffer), "Scene/Model/Kart/%s-allkart", getCharacterName(characterId)); } else { @@ -1028,62 +1048,64 @@ void RloadMenuKartModel(MultiDvdArchive* m, CharacterId characterId, m->load(buffer, archiveHeap, fileHeap, 0); } } + void RloadMenuKartModel(MultiDvdArchive* m, MenuCharacterManager* c) { - RloadMenuKartModel(m, c->mCharacter, c->mModelType, c->archiveHeap, - c->fileHeap); + RloadMenuKartModel(m, c->mCharacter, c->mTeam, c->mpArchiveHeap, + c->mpFileHeap); } + } // namespace + void ResourceManager::doLoadCharacterKartModel(void* idxs) { ResourceManager* resMgr = ResourceManager::spInstance_REAL; const u8 idx = (const u8)idxs; - if (resMgr->multiArchives2[idx].isLoaded()) { - resMgr->multiArchives2[idx].unmount(); + if (resMgr->mKartArchives[idx].isLoaded()) { + resMgr->mKartArchives[idx].unmount(); } - resMgr->menuManagers[idx]._unk = 2; - resMgr->menuManagers[idx].destroy(); + resMgr->mMenuManagers[idx].mState = MENU_CHARACTER_MANAGER_STATE_UNK2; + resMgr->mMenuManagers[idx].destroy(); - MultiDvdArchive* archive = &resMgr->multiArchives2[idx]; - RloadMenuKartModel(archive, &resMgr->menuManagers[idx]); + MultiDvdArchive* archive = &resMgr->mKartArchives[idx]; + RloadMenuKartModel(archive, &resMgr->mMenuManagers[idx]); if (!archive->isLoaded()) { OSSleepMilliseconds(16); } if (archive->isLoaded()) { - resMgr->menuManagers[idx]._unk = 4; + resMgr->mMenuManagers[idx].mState = MENU_CHARACTER_MANAGER_STATE_UNK4; } else { - resMgr->menuManagers[idx]._unk = 0; + resMgr->mMenuManagers[idx].mState = MENU_CHARACTER_MANAGER_STATE_CLEARED; } } void ResourceManager::doLoadCharacterKartModelPriv(s32 idx) { - if (this->multiArchives2[idx].isLoaded()) { - this->multiArchives2[idx].unmount(); + if (mKartArchives[idx].isLoaded()) { + mKartArchives[idx].unmount(); } - this->menuManagers[idx]._unk = 2; - this->menuManagers[idx].destroy(); - - MultiDvdArchive* archive = &this->multiArchives2[idx]; - RloadMenuKartModel(archive, this->menuManagers[idx].mCharacter, - this->menuManagers[idx].mModelType, - this->menuManagers[idx].archiveHeap, - this->menuManagers[idx].fileHeap); + mMenuManagers[idx].mState = MENU_CHARACTER_MANAGER_STATE_UNK2; + mMenuManagers[idx].destroy(); + + MultiDvdArchive* archive = &mKartArchives[idx]; + RloadMenuKartModel(archive, mMenuManagers[idx].mCharacter, + mMenuManagers[idx].mTeam, mMenuManagers[idx].mpArchiveHeap, + mMenuManagers[idx].mpFileHeap); if (!archive->isLoaded()) { OSSleepMilliseconds(16); } if (archive->isLoaded()) { - this->menuManagers[idx]._unk = 4; + mMenuManagers[idx].mState = MENU_CHARACTER_MANAGER_STATE_UNK4; } else { - this->menuManagers[idx]._unk = 0; + mMenuManagers[idx].mState = MENU_CHARACTER_MANAGER_STATE_CLEARED; } } bool ResourceManager::loadKartMenuModelAsync(s32 idx, CharacterId characterId, BattleTeam battleTeam) { - if (!this->menuManagers[idx].SOME_CHECK()) { + if (!mMenuManagers[idx].SOME_CHECK()) { return false; } else { - this->menuManagers[idx].mCharacter = characterId; - this->menuManagers[idx].mModelType = battleTeam; - this->menuManagers[idx]._unk = 1; + mMenuManagers[idx].mCharacter = characterId; + mMenuManagers[idx].mTeam = battleTeam; + mMenuManagers[idx].mState = MENU_CHARACTER_MANAGER_STATE_UNK1; this->requestTask(ResourceManager::doLoadCharacterKartModel, (void*)idx, (void*)0x10000003); return true; @@ -1100,16 +1122,16 @@ static inline void setHeap(EGG::ExpHeap** heapDest, EGG::ExpHeap* heapSrc) { } } -void ResourceManager::FUN_805422cc(u32 count, s32 heapIdx) { - this->_610 = createExpHeap(0xc8000, heapIdx); +void ResourceManager::createMenuHeaps(u32 count, s32 heapIdx) { + mpMenuHeap = createExpHeap(0xc8000, heapIdx); for (u8 i = 0; i < 4; i++) { if (i < count) { EGG::ExpHeap* heap = createExpHeap(0xe1000, heapIdx); - this->menuManagers[i].setArchiveHeap(heap); - this->menuManagers[i].setFileHeap(this->_610); + mMenuManagers[i].setArchiveHeap(heap); + mMenuManagers[i].setFileHeap(mpMenuHeap); } else { - this->menuManagers[i].setArchiveHeap(0); - this->menuManagers[i].setFileHeap(0); + mMenuManagers[i].setArchiveHeap(nullptr); + mMenuManagers[i].setFileHeap(nullptr); } } } @@ -1122,8 +1144,8 @@ void ResourceManager::clear() { clear(i); } - this->_610->destroy(); - this->_610 = nullptr; + mpMenuHeap->destroy(); + mpMenuHeap = nullptr; } } // namespace System @@ -1142,7 +1164,7 @@ asm UNKNOWN_FUNCTION(unk_8054247c) { } namespace System { -u8* ResourceManager::FUN_8054248c(EGG::Heap* globeHeap) { +u8* ResourceManager::loadGlobe(EGG::Heap* globeHeap) { EGG::LZStreamDecomp lzstream; const char* globePath = Resource::GetResourcePath(SYS_RES_GLOBE); @@ -1165,34 +1187,32 @@ u8* ResourceManager::FUN_8054248c(EGG::Heap* globeHeap) { void ResourceManager::initGlobeHeap(size_t size, EGG::Heap* heap) { if (heap == nullptr) { GameScene* gameScene = getGameScene(); - heap = gameScene->dynamicHeaps.mpHeaps[1]; + heap = gameScene->mDynamicHeaps.mpHeaps[1]; } - this->globeHeap = EGG::ExpHeap::create(size + 0x2041fU & 0xffffffe0, heap, 0); + mpGlobeHeap = EGG::ExpHeap::create(size + 0x2041fU & 0xffffffe0, heap, 0); } } // namespace System namespace System { + void ResourceManager::deinitGlobeHeap() { - this->flush(); - this->globeHeap->destroy(); + flush(); + mpGlobeHeap->destroy(); bar(); } -} // namespace System -namespace System { void ResourceManager::doLoadGlobe(void* globeBlob) { ResourceManager::spInstance->doLoadGlobeImpl((u8**)globeBlob); } void ResourceManager::doLoadGlobeImpl(u8** globeBlob) volatile { - *globeBlob = ResourceManager::FUN_8054248c(this->globeHeap); - this->isGlobeLoadingBusy = false; + *globeBlob = ResourceManager::loadGlobe(mpGlobeHeap); + mIsGlobeLoadingBusy = false; } bool ResourceManager::loadGlobeAsync(void* arg) { - return this->isGlobeLoadingBusy - ? false - : requestGlobeTaskHelper(arg, (void*)0x10000004); + return mIsGlobeLoadingBusy ? false + : requestGlobeTaskHelper(arg, (void*)0x10000004); } void ResourceManager::loadStaffGhostAsync( diff --git a/source/game/system/ResourceManager.hpp b/source/game/system/ResourceManager.hpp index 3ccc58c25..01d28e7d2 100644 --- a/source/game/system/ResourceManager.hpp +++ b/source/game/system/ResourceManager.hpp @@ -11,150 +11,12 @@ #include #include #include + #ifdef __cplusplus extern "C" { #endif -// PAL: 0x8053fc4c..0x8053fc9c -UNKNOWN_FUNCTION(ResourceManager_createInstance); -// PAL: 0x8053fc9c..0x8053fcec -UNKNOWN_FUNCTION(ResourceManager_destroyInstance); -// PAL: 0x8053fcec..0x8053fe68 -UNKNOWN_FUNCTION(__ct__Q26System15ResourceManagerFv); -// PAL: 0x8053fe68..0x8053fe94 -UNKNOWN_FUNCTION(__ct__Q26System20MenuCharacterManagerFv); -// PAL: 0x8053fe94..0x8053fed4 -UNKNOWN_FUNCTION(unk_8053fe94); -// PAL: 0x8053fed4..0x8053ff14 -UNKNOWN_FUNCTION(unk_8053fed4); -// PAL: 0x8053ff14..0x8053ff1c -UNKNOWN_FUNCTION(unk_8053ff14); -// PAL: 0x8053ff1c..0x80540038 -UNKNOWN_FUNCTION(ResourceManager_destroy); -// PAL: 0x80540038..0x805400a0 -UNKNOWN_FUNCTION(unk_80540038); -// PAL: 0x805400a0..0x805401ec UNKNOWN_FUNCTION(process__Q26System15ResourceManagerFv); -// PAL: 0x805401ec..0x805401fc -UNKNOWN_FUNCTION(unk_805401ec); -// PAL: 0x805401fc..0x8054020c -UNKNOWN_FUNCTION(unk_805401fc); -// PAL: 0x8054020c..0x805402c0 -UNKNOWN_FUNCTION(unk_8054020c); -// PAL: 0x805402c0..0x80540394 -UNKNOWN_FUNCTION(unk_805402c0); -// PAL: 0x80540394..0x80540450 -UNKNOWN_FUNCTION(unk_80540394); -// PAL: 0x80540450..0x80540558 -UNKNOWN_FUNCTION(ResourceManager_load); -// PAL: 0x80540558..0x80540680 -UNKNOWN_FUNCTION(unk_80540558); -// PAL: 0x80540680..0x80540760 -UNKNOWN_FUNCTION(ResourceManager_loadUI); -// PAL: 0x80540760..0x80540918 -UNKNOWN_FUNCTION(ResourceManager_loadCourse); -// PAL: 0x80540cfc..0x80540e3c -UNKNOWN_FUNCTION(unk_80540cfc); -// PAL: 0x80540e3c..0x80540f90 -UNKNOWN_FUNCTION(unk_80540e3c); -// PAL: 0x80540f90..0x805410e4 -UNKNOWN_FUNCTION(unk_80540f90); -// PAL: 0x805410e4..0x805411d4 -UNKNOWN_FUNCTION(unk_805410e4); -// PAL: 0x805411d4..0x805411e4 -UNKNOWN_FUNCTION(unk_805411d4); -// PAL: 0x805411e4..0x805411ec -UNKNOWN_FUNCTION(unk_805411e4); -// PAL: 0x805411ec..0x805411fc -UNKNOWN_FUNCTION(unk_805411ec); -// PAL: 0x805411fc..0x80541278 -UNKNOWN_FUNCTION(ResourceManager_getFile); -// PAL: 0x80541278..0x80541320 -UNKNOWN_FUNCTION(unk_80541278); -// PAL: 0x80541320..0x805413c8 -UNKNOWN_FUNCTION(unk_80541320); -// PAL: 0x805413c8..0x80541438 -UNKNOWN_FUNCTION(unk_805413c8); -// PAL: 0x80541438..0x805414a8 -UNKNOWN_FUNCTION(unk_80541438); -// PAL: 0x805414a8..0x8054155c -UNKNOWN_FUNCTION(ResourceManager_loadBSP); -// PAL: 0x8054155c..0x805415b0 -UNKNOWN_FUNCTION(unk_8054155c); -// PAL: 0x805415b0..0x805415b4 -UNKNOWN_FUNCTION(unk_805415b0); -// PAL: 0x805415b4..0x805415c4 -UNKNOWN_FUNCTION(unk_805415b4); -// PAL: 0x805415c4..0x805415d4 -UNKNOWN_FUNCTION(unk_805415c4); -// PAL: 0x805415d4..0x805415e4 -UNKNOWN_FUNCTION(unk_805415d4); -// PAL: 0x805415e4..0x80541614 -UNKNOWN_FUNCTION(unk_805415e4); -// PAL: 0x8054169c..0x80541738 -UNKNOWN_FUNCTION(unk_8054169c); -// PAL: 0x80541738..0x80541794 -UNKNOWN_FUNCTION(unk_80541738); -// PAL: 0x80541794..0x805417a4 -UNKNOWN_FUNCTION(ResourceManager_getMenuArchiveCount); -// PAL: 0x805417a4..0x80541878 -UNKNOWN_FUNCTION(unk_805417a4); -// PAL: 0x80541878..0x80541998 -UNKNOWN_FUNCTION(ResourceManager_attachLayoutDir); -// PAL: 0x80541998..0x805419ac -UNKNOWN_FUNCTION(ResourceManager_preloadCourseTask); -// PAL: 0x805419ac..0x805419c8 -UNKNOWN_FUNCTION(ResourceManager_preloadCourseAsync); -// PAL: 0x805419c8..0x805419ec -UNKNOWN_FUNCTION(unk_805419c8); -// PAL: 0x805419ec..0x80541a10 -UNKNOWN_FUNCTION(unk_805419ec); -// PAL: 0x80541a10..0x80541a70 -UNKNOWN_FUNCTION(unk_80541a10); -// PAL: 0x80541a70..0x80541ac4 -UNKNOWN_FUNCTION(unk_80541a70); -// PAL: 0x80541ac4..0x80541b58 -UNKNOWN_FUNCTION(unk_80541ac4); -// PAL: 0x80541b58..0x80541c18 -UNKNOWN_FUNCTION(load__Q26System11CourseCacheFl); -// PAL: 0x80541c18..0x80541c38 -UNKNOWN_FUNCTION(unk_80541c18); -// PAL: 0x80541c38..0x80541c48 -UNKNOWN_FUNCTION(unk_80541c38); -// PAL: 0x80541c48..0x80541cbc -UNKNOWN_FUNCTION(unk_80541c48); -// PAL: 0x80541cbc..0x80541ce0 -UNKNOWN_FUNCTION(unk_80541cbc); -// PAL: 0x80541ce0..0x80541e44 -// UNKNOWN_FUNCTION(flush__Q26System15ResourceManagerFv); -// PAL: 0x80541e44..0x80542030 -UNKNOWN_FUNCTION(unk_80541e44); -// PAL: 0x80542030..0x80542210 -UNKNOWN_FUNCTION(unk_80542030); -// PAL: 0x80542210..0x805422cc -UNKNOWN_FUNCTION(unk_80542210); -// PAL: 0x805422cc..0x805423bc -UNKNOWN_FUNCTION(unk_805422cc); -// PAL: 0x805423bc..0x8054247c -UNKNOWN_FUNCTION(unk_805423bc); -// PAL: 0x8054247c..0x8054248c -UNKNOWN_FUNCTION(unk_8054247c); -// PAL: 0x8054248c..0x80542524 -UNKNOWN_FUNCTION(unk_8054248c); -// PAL: 0x80542524..0x80542584 -UNKNOWN_FUNCTION(unk_80542524); -// PAL: 0x80542584..0x805425d0 -UNKNOWN_FUNCTION(unk_80542584); -// PAL: 0x805425d0..0x80542694 -UNKNOWN_FUNCTION(unk_805425d0); -// PAL: 0x80542694..0x80542754 -UNKNOWN_FUNCTION(unk_80542694); -// PAL: 0x80542754..0x805427bc -UNKNOWN_FUNCTION(unk_80542754); -// PAL: 0x805427bc..0x80542868 -UNKNOWN_FUNCTION(SaveManager_loadStaffGhostAsync); -// PAL: 0x80542868..0x80542878 -UNKNOWN_FUNCTION(unk_80542868); UNKNOWN_FUNCTION(flush__Q26System15ResourceManagerFv); #ifdef __cplusplus } @@ -163,22 +25,103 @@ UNKNOWN_FUNCTION(flush__Q26System15ResourceManagerFv); namespace System { struct JobContext { - MultiDvdArchive* multiArchive; - DvdArchive* archive; + MultiDvdArchive* mpMultiArchive; + DvdArchive* mpArchive; unk _08; - char filename[64]; - EGG::Heap* archiveHeap; - EGG::Heap* fileHeap; + char mFilename[64]; + EGG::Heap* mpArchiveHeap; + EGG::Heap* mpFileHeap; }; // Enums that represent indices in vehicle name specifiers arrays. typedef enum { - // TODO: Fill - MARIO = 0 + MARIO = 0x0, + BABY_PEACH = 0x1, + WALUIGI = 0x2, + BOWSER = 0x3, + BABY_DAISY = 0x4, + DRY_BONES = 0x5, + BABY_MARIO = 0x6, + LUIGI = 0x7, + TOAD = 0x8, + DONKEY_KONG = 0x9, + YOSHI = 0xA, + WARIO = 0xB, + BABY_LUIGI = 0xC, + TOADETTE = 0xD, + KOOPA_TROOPA = 0xE, + DAISY = 0xF, + PEACH = 0x10, + BIRDO = 0x11, + DIDDY_KONG = 0x12, + KING_BOO = 0x13, + BOWSER_JR = 0x14, + DRY_BOWSER = 0x15, + FUNKY_KONG = 0x16, + ROSALINA = 0x17, + MII_S_A_MALE = 0x18, + MII_S_A_FEMALE = 0x19, + MII_S_B_MALE = 0x1A, + MII_S_B_FEMALE = 0x1B, + MII_S_C_MALE = 0x1C, + MII_S_C_FEMALE = 0x1D, + MII_M_A_MALE = 0x1E, + MII_M_A_FEMALE = 0x1F, + MII_M_B_MALE = 0x20, + MII_M_B_FEMALE = 0x21, + MII_M_C_MALE = 0x22, + MII_M_C_FEMALE = 0x23, + MII_L_A_MALE = 0x24, + MII_L_A_FEMALE = 0x25, + MII_L_B_MALE = 0x26, + MII_L_B_FEMALE = 0x27, + MII_L_C_MALE = 0x28, + MII_L_C_FEMALE = 0x29, + MII_M = 0x2A, + MII_S = 0x2B, + MII_L = 0x2C, + PEACH_BIKER = 0x2D, + DAISY_BIKER = 0x2E, + ROSALINA_BIKER = 0x2F } CharacterId; typedef enum { - // TODO: Fill + STANDARD_KART_S = 0x0, + STANDARD_KART_M = 0x1, + STANDARD_KART_L = 0x2, + BABY_BOOSTER = 0x3, + CLASSIC_DRAGSTER = 0x4, + OFFROADER = 0x5, + MINI_BEAST = 0x6, + WILD_WING = 0x7, + FLAME_FLYER = 0x8, + CHEEP_CHARGER = 0x9, + SUPER_BLOOPER = 0xA, + PIRANHA_PROWLER = 0xB, + RALLY_ROMPER = 0xC, + ROYAL_RACER = 0xD, + JETSETTER = 0xE, + BLUE_FALCON = 0xF, + SPRINTER = 0x10, + HONEYCOUPE = 0x11, + STANDARD_BIKE_S = 0x12, + STANDARD_BIKE_M = 0x13, + STANDARD_BIKE_L = 0x14, + BULLET_BIKE = 0x15, + MACH_BIKE = 0x16, + BOWSER_BIKE = 0x17, + BIT_BIKE = 0x18, + BON_BON = 0x19, + WARIO_BIKE = 0x1A, + QUACKER = 0x1B, + RAPIDE = 0x1C, + SHOOTING_STAR = 0x1D, + MAGIKRUISER = 0x1E, + NITROCYCLE = 0x1F, + SPEAR = 0x20, + JET_BUBBLE = 0x21, + DOLPHIN_DASHER = 0x22, + PHANTOM = 0x23 } VehicleId; // name of battle mode team @@ -196,9 +139,79 @@ typedef enum { } PlayMode; typedef enum { - // TODO: Fill + // Race courses + + // Nitro tracks + MARIO_CIRCUIT = 0x0, + MOO_MOO_MEADOWS = 0x1, + MUSHROOM_GORGE = 0x2, + GRUMBLE_VOLCANO = 0x3, + TOADS_FACTORY = 0x4, + COCONUT_MALL = 0x5, + DK_SUMMIT = 0x6, // "snowboard cross" enjoyers punching air + WARIOS_GOLD_MINE = 0x7, + LUIGI_CIRCUIT = 0x8, + DAISY_CIRCUIT = 0x9, + MOONVIEW_HIGHWAY = 0xA, + MAPLE_TREEWAY = 0xB, + BOWSERS_CASTLE = 0xC, + RAINBOW_ROAD = 0xD, + DRY_DRY_RUINS = 0xE, + KOOPA_CAPE = 0xF, + + // Retro tracks + GCN_PEACH_BEACH = 0x10, + GCN_MARIO_CIRCUIT = 0x11, + GCN_WALUIGI_STADIUM = 0x12, + GCN_DK_MOUNTAIN = 0x13, + DS_YOSHI_FALLS = 0x14, + DS_DESERT_HILLS = 0x15, + DS_PEACH_GARDENS = 0x16, + DS_DELFINO_SQUARE = 0x17, + SNES_MARIO_CIRCUIT_3 = 0x18, + SNES_GHOST_VALLEY_2 = 0x19, + N64_MARIO_RACEWAY = 0x1A, + N64_SHERBET_LAND = 0x1B, + N64_BOWSERS_CASTLE = 0x1C, + N64_DKS_JUNGLE_PARKWAY = 0x1D, + GBA_BOWSER_CASTLE_3 = 0x1E, + GBA_SHY_GUY_BEACH = 0x1F, + + // Battle courses + DELFINO_PIER = 0x20, + BLOCK_PLAZA = 0x21, + CHAIN_CHOMP_ROULETTE = 0x22, + FUNKY_STADIUM = 0x23, + THWOMP_DESERT = 0x24, + GCN_COOKIE_LAND = 0x25, + DS_TWILIGHT_HOUSE = 0x26, + SNES_BATTLE_COURSE_4 = 0x27, + GBA_BATTLE_COURSE_3 = 0x28, + N64_SKYSCRAPER = 0x29, + + // Other courses + GALAXY_COLOSSEUM = 0x36, + WINNING_DEMO = 0x37, + LOSING_DEMO = 0x38, + DRAW_DEMO = 0x39, + SUNSET_LUIGI_CIRCUIT = 0x3A } CourseId; +typedef enum { + MENU_CHARACTER_MANAGER_STATE_CLEARED = 0, + MENU_CHARACTER_MANAGER_STATE_UNK1 = 1, + MENU_CHARACTER_MANAGER_STATE_UNK2 = 2, + MENU_CHARACTER_MANAGER_STATE_UNK3 = 3, + MENU_CHARACTER_MANAGER_STATE_UNK4 = 4 +} MenuCharacterManagerState; + +typedef enum { + COURSE_CACHE_STATE_UNK0 = 0, + COURSE_CACHE_STATE_UNK1 = 1, + COURSE_CACHE_STATE_UNK2 = 2, + COURSE_CACHE_STATE_UNK3 = 3 +} CourseCacheState; + // begrudging riidefi magic struct S { virtual ~S() = 0; @@ -207,31 +220,33 @@ inline S::~S() {} struct T { public: T() { - archiveHeap = 0; - fileHeap = 0; - _unk = 0; + mpArchiveHeap = nullptr; + mpFileHeap = nullptr; + mState = MENU_CHARACTER_MANAGER_STATE_CLEARED; } - EGG::ExpHeap* archiveHeap; - EGG::ExpHeap* fileHeap; - s32 _unk; + EGG::ExpHeap* mpArchiveHeap; + EGG::ExpHeap* mpFileHeap; + MenuCharacterManagerState mState; + + // what am I looking at inline bool SOME_CHECK() const { - return archiveHeap && ((_unk <= 4u && (((1 << _unk) & 0x15U) != 0))); + return mpArchiveHeap && ((mState <= 4u && (((1 << mState) & 0x15U) != 0))); } inline void destroy() { if (SOME_CHECK()) { - archiveHeap->freeAll(); - fileHeap->freeAll(); + mpArchiveHeap->freeAll(); + mpFileHeap->freeAll(); } - _unk = 3; + mState = MENU_CHARACTER_MANAGER_STATE_UNK3; } inline void setArchiveHeap(EGG::ExpHeap* heapSrc) { - if (this->archiveHeap == 0) { - this->archiveHeap = heapSrc; + if (!mpArchiveHeap) { + mpArchiveHeap = heapSrc; } } inline void setFileHeap(EGG::ExpHeap* heapSrc) { - if (this->fileHeap == 0) { - this->fileHeap = heapSrc; + if (!mpFileHeap) { + mpFileHeap = heapSrc; } } }; @@ -242,11 +257,11 @@ class MenuCharacterManager : S, public T { public: MenuCharacterManager() { mCharacter = MARIO; - mModelType = BATTLE_TEAM_NONE; + mTeam = BATTLE_TEAM_NONE; } virtual ~MenuCharacterManager() {} CharacterId mCharacter; - BattleTeam mModelType; + BattleTeam mTeam; }; class CourseCache : EGG::Disposer { @@ -259,11 +274,11 @@ class CourseCache : EGG::Disposer { // private: // idk if rii prefers to befriend every class over public-ing // everything - void* mBuffer; - EGG::ExpHeap* mHeap; - s32 mCourseId; - s32 mState; - MultiDvdArchive* mArchive; + void* mpBuffer; + EGG::ExpHeap* mpHeap; + CourseId mCourseId; + CourseCacheState mState; + MultiDvdArchive* mpArchive; }; void preloadCourseTask(void* courseId); @@ -273,12 +288,12 @@ const char* getVehicleName(VehicleId vehicleId); // unknown structs struct Whatever { u32 _00; - u8 _04[0xa4 - 0x04]; + u8 _04[0xa4 - 0x4]; }; struct Whatever2 { u8 _00[0x4 - 0x0]; Whatever* _04; - u16 _08; /* ... */ + u16 _08; // ... }; class ResourceManager { @@ -288,33 +303,34 @@ class ResourceManager { static volatile ResourceManager* createInstance(); static void destroyInstance(); + // Pretty sure this is actual source code static volatile ResourceManager* spInstance; static ResourceManager* spInstance_REAL; ResourceManager(); - MultiDvdArchive** multiArchives1; - MultiDvdArchive multiArchives2[12]; - MultiDvdArchive multiArchives3[12]; - DvdArchive dvdArchives[4]; - JobContext jobContexts[7]; - EGG::TaskThread* taskThread; - CourseCache courseCache; - MenuCharacterManager menuManagers[4]; - bool isGlobeLoadingBusy; - bool _60d; // these variables don't have names yet, but are used - EGG::ExpHeap* _610; - EGG::Heap* globeHeap; - bool requestPending; - bool requestsEnabled; + MultiDvdArchive** mppSceneArchives; + MultiDvdArchive mKartArchives[12]; + MultiDvdArchive mBackupKartArchives[12]; // TODO: better name + DvdArchive mSystemArchives[4]; + JobContext mJobContexts[7]; + EGG::TaskThread* mpTaskThread; + CourseCache mCourseCache; + MenuCharacterManager mMenuManagers[4]; + bool mIsGlobeLoadingBusy; + bool _60d; // this variable is only used in GameScene + EGG::ExpHeap* mpMenuHeap; + EGG::Heap* mpGlobeHeap; + bool mRequestPending; + bool mRequestsEnabled; void foo() volatile { - requestPending = false; - requestsEnabled = true; + mRequestPending = false; + mRequestsEnabled = true; } void bar() volatile { - globeHeap = nullptr; - isGlobeLoadingBusy = false; + mpGlobeHeap = nullptr; + mIsGlobeLoadingBusy = false; } MultiDvdArchive* load(ResourceChannelID channelId, EGG::Heap* archiveHeap, @@ -355,33 +371,29 @@ class ResourceManager { void* getFile(s32 archiveIdx, const char* filename, size_t* size); void* getCharacterFile(CharacterId characterId, size_t* size); void* getVehicleFile(s32 archiveIdx, VehicleId vehicleId, size_t* size); - // TODO: Better name - void* getMultiFile2(s32 idx, const char* filename, size_t* size); - void* getMultiFile3(s32 idx, const char* filename, size_t* size); + void* getKartArchiveFile(s32 idx, const char* filename, size_t* size); + void* getBackupKartArchiveFile(s32 idx, const char* filename, size_t* size); void* getBspFile(s32 playerIdx, size_t* size); void* getFileCopy(s32 archiveIdx, char* filename, EGG::Heap* heap, size_t* size, s8 param_5); - // TODO: Better names - bool isMultiArchive1Loaded(s32 idx) volatile; - bool isMultiArchive2Loaded(s32 idx); - bool isMultiArchive3Loaded(s32 idx); - bool isDvdArchiveLoaded(s32 idx); + bool isSceneArchiveLoaded(s32 idx) volatile; + bool isKartArchiveLoaded(s32 idx); + bool isBackupKartArchiveLoaded(s32 idx); + bool isSystemArchiveLoaded(s32 idx); bool setArcResourceLink(s32 multiIdx, u16 archiveIdx, void* arcResource, const char* dirname); u16 getLoadedArchiveCount(s32 idx); // I need this terribleness to match attachArcResourceAccessor inline u16 getLoadedArchiveCountInverse(u32 idx) volatile { - return !isMultiArchive1Loaded(idx) - ? 0 - : this->multiArchives1[idx]->archiveCount; + return !isSceneArchiveLoaded(idx) ? 0 : mppSceneArchives[idx]->archiveCount; } u16 getMenuArchiveCount(); bool tryRequestTask(EGG::TaskThread::TFunction mainFunction, void* arg); bool requestTask(EGG::TaskThread::TFunction mainFunction, void* arg, void* _8); - void attatchLayoutDir(void* accessor, const char* dirname, Whatever2* param_4, - bool param_5); + void attatchLayoutDir(void* accessor, const char* dirname, Whatever2* param_3, + bool param_4); void attachArcResourceAccessor(void* arcResourceAccessor, const char* dirname); void preloadCourseAsync(CourseId courseId); @@ -392,19 +404,19 @@ class ResourceManager { void doLoadCharacterKartModelPriv(s32 idxs); bool loadKartMenuModelAsync(s32 idx, CharacterId characterId, BattleTeam battleTeam); - void FUN_805422cc(u32 count, s32 heapIdx); - static void doLoadGlobe(void* glodeBlob); + void createMenuHeaps(u32 count, s32 heapIdx); + static void doLoadGlobe(void* globeBlob); void doLoadGlobeImpl(u8** glodeBlob) volatile; // for matching purposes inline bool requestGlobeTaskHelper(void* arg, void* arg2) volatile { - this->isGlobeLoadingBusy = true; - if (this->requestsEnabled) { - this->requestPending = true; - this->taskThread->request(ResourceManager::doLoadGlobe, arg, arg2); + mIsGlobeLoadingBusy = true; + if (mRequestsEnabled) { + mRequestPending = true; + mpTaskThread->request(ResourceManager::doLoadGlobe, arg, arg2); } return true; } - static u8* FUN_8054248c(EGG::Heap* globeHeap); + static u8* loadGlobe(EGG::Heap* globeHeap); bool loadGlobeAsync(void* arg); void clear(); void process(); @@ -422,14 +434,14 @@ class ResourceManager { // TODO: check if actually inline inline void requestLoadFile(s32 idx, MultiDvdArchive* m, const char* p, EGG::Heap* archiveHeap, EGG::Heap* fileHeap) { - this->jobContexts[idx].multiArchive = m; - strncpy(this->jobContexts[idx].filename, p, - sizeof(this->jobContexts[idx].filename)); - this->jobContexts[idx].archiveHeap = archiveHeap; - this->jobContexts[idx].fileHeap = fileHeap; + mJobContexts[idx].mpMultiArchive = m; + strncpy(mJobContexts[idx].mFilename, p, + sizeof(mJobContexts[idx].mFilename)); + mJobContexts[idx].mpArchiveHeap = archiveHeap; + mJobContexts[idx].mpFileHeap = fileHeap; - this->taskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); - this->process(); + mpTaskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); + process(); if (!m->isLoaded()) { OSSleepMilliseconds(16); @@ -438,13 +450,13 @@ class ResourceManager { inline void requestLoadFile(s32 idx, DvdArchive* archive, const char* filename, u32 unk, EGG::Heap* archiveHeap) { - this->jobContexts[idx].archive = archive; - strncpy(this->jobContexts[idx].filename, filename, 0x40); - this->jobContexts[idx].archiveHeap = archiveHeap; - this->jobContexts[idx]._08 = unk; + mJobContexts[idx].mpArchive = archive; + strncpy(mJobContexts[idx].mFilename, filename, 0x40); + mJobContexts[idx].mpArchiveHeap = archiveHeap; + mJobContexts[idx]._08 = unk; - this->taskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); - this->process(); + mpTaskThread->request(ResourceManager::doLoadTask, (void*)idx, 0); + process(); if (!archive->isLoaded()) { OSSleepMilliseconds(16); @@ -454,8 +466,8 @@ class ResourceManager { MultiDvdArchive* archive; EGG::ExpHeap* heap; - heap = menuManagers[i].archiveHeap; - archive = &multiArchives2[i]; + heap = mMenuManagers[i].mpArchiveHeap; + archive = &mKartArchives[i]; if (archive->isLoaded()) { archive->unmount(); @@ -464,10 +476,10 @@ class ResourceManager { heap->destroy(); } - if (menuManagers[i]._unk != 3) { - menuManagers[i].archiveHeap = 0; - menuManagers[i].fileHeap = 0; - menuManagers[i]._unk = 0; + if (mMenuManagers[i].mState != MENU_CHARACTER_MANAGER_STATE_UNK3) { + mMenuManagers[i].mpArchiveHeap = nullptr; + mMenuManagers[i].mpFileHeap = nullptr; + mMenuManagers[i].mState = MENU_CHARACTER_MANAGER_STATE_CLEARED; } } };