From cc3b62d6c131fd54db75b7dbc76b1fc7659f25ca Mon Sep 17 00:00:00 2001 From: robojumper Date: Wed, 1 May 2024 21:16:43 +0200 Subject: [PATCH] File manager, plausible setup --- config/SOUE01/splits.txt | 3 ++ config/SOUE01/symbols.txt | 26 +++++------ include/egg/core/eggHeap.h | 2 +- include/m/m_vec.h | 3 +- include/toBeSorted/file_manager.h | 7 +-- include/toBeSorted/save_file.h | 14 +++--- src/toBeSorted/file_manager.cpp | 72 +++++++++++++++++++++++++------ src/toBeSorted/save_file.cpp | 4 +- 8 files changed, 91 insertions(+), 40 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 232dd3e7..cf8cb5fa 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -19,6 +19,9 @@ toBeSorted/save_file.cpp: toBeSorted/file_manager.cpp: .text start:0x80009D30 end:0x80011730 .ctors start:0x804DB648 end:0x804DB64C + .data start:0x80500400 end:0x80500410 + .sbss start:0x80574FF8 end:0x80575000 + .bss start:0x80580070 end:0x80580080 toBeSorted/save_manager.cpp: .text start:0x80011730 end:0x80015310 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 1254741b..f7fe385e 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -155,7 +155,7 @@ fn_800071D0 = .text:0x800071D0; // type:function size:0x8C fn_80007260 = .text:0x80007260; // type:function size:0xE4 OSPanic = .text:0x80007350; // type:function size:0xDC scope:weak fn_80007430 = .text:0x80007430; // type:function size:0x24 -fn_80007460 = .text:0x80007460; // type:function size:0x40 +__dt__7mVec3_cFv = .text:0x80007460; // type:function size:0x40 fn_800074A0 = .text:0x800074A0; // type:function size:0xC8 fn_80007570 = .text:0x80007570; // type:function size:0x58 fn_800075D0 = .text:0x800075D0; // type:function size:0x8C @@ -227,7 +227,7 @@ fn_80009770 = .text:0x80009770; // type:function size:0x74 fn_800097F0 = .text:0x800097F0; // type:function size:0x17C fn_80009970 = .text:0x80009970; // type:function size:0x34 getStoryFlags0__8SaveFileFv = .text:0x800099B0; // type:function size:0x8 -getStoryFlags1__8SaveFileFv = .text:0x800099C0; // type:function size:0x8 +getStoryFlags1__8SaveFileCFv = .text:0x800099C0; // type:function size:0x8 getItemFlags0__8SaveFileFv = .text:0x800099D0; // type:function size:0x8 getItemFlags1__8SaveFileFv = .text:0x800099E0; // type:function size:0x8 getDungeonFlags0__8SaveFileFv = .text:0x800099F0; // type:function size:0x8 @@ -248,8 +248,8 @@ getAreaT1__8SaveFileFv = .text:0x80009BE0; // type:function size:0x8 setAreaT2__8SaveFileFPc = .text:0x80009BF0; // type:function size:0x11C getAreaT2__8SaveFileFv = .text:0x80009D10; // type:function size:0x8 getAreaT3__8SaveFileFv = .text:0x80009D20; // type:function size:0x8 -fn_80009D30 = .text:0x80009D30; // type:function size:0x10 -fn_80009D40 = .text:0x80009D40; // type:function size:0x40 +__ct__8UnkClassFv = .text:0x80009D30; // type:function size:0x10 +__dt__8UnkClassFv = .text:0x80009D40; // type:function size:0x40 fn_80009D80 = .text:0x80009D80; // type:function size:0x4 fn_80009D90 = .text:0x80009D90; // type:function size:0x4 fn_80009DA0 = .text:0x80009DA0; // type:function size:0xC @@ -265,7 +265,7 @@ getFileCurrentHealth__11FileManagerFi = .text:0x8000A2A0; // type:function size: getFileHealthCapacity__11FileManagerFi = .text:0x8000A2C0; // type:function size:0x14 fn_8000A2E0__11FileManagerFv = .text:0x8000A2E0; // type:function size:0x50 getStoryFlagsMut__11FileManagerFv = .text:0x8000A330; // type:function size:0x24 -getStoryFlagsConst__11FileManagerFv = .text:0x8000A360; // type:function size:0x44 +getStoryFlagsConst__11FileManagerCFv = .text:0x8000A360; // type:function size:0x44 getItemFlagsMut__11FileManagerFv = .text:0x8000A3B0; // type:function size:0x24 getItemFlagsConst__11FileManagerFv = .text:0x8000A3E0; // type:function size:0x44 getDungeonFlagsMut__11FileManagerFv = .text:0x8000A430; // type:function size:0x24 @@ -432,11 +432,11 @@ isFileUnk3__11FileManagerFi = .text:0x80011390; // type:function size:0x20 get_0xA84C__11FileManagerFv = .text:0x800113B0; // type:function size:0xC checkRegionCode__11FileManagerFv = .text:0x800113C0; // type:function size:0x78 checkFileCRC__11FileManagerFi = .text:0x80011440; // type:function size:0x50 -isFileInactive__11FileManagerFv = .text:0x80011490; // type:function size:0x6C +isFileInactive__11FileManagerCFv = .text:0x80011490; // type:function size:0x6C setPlayerInfoFileA__11FileManagerFv = .text:0x80011500; // type:function size:0xE0 setT3Info__11FileManagerFP7mVec3_cP7mAng3_c = .text:0x800115E0; // type:function size:0xD8 getRegionVersion__11FileManagerFPc = .text:0x800116C0; // type:function size:0x28 -fn_800116F0 = .text:0x800116F0; // type:function size:0x3C +__sinit_\file_manager_cpp = .text:0x800116F0; // type:function size:0x3C fn_80011730 = .text:0x80011730; // type:function size:0x2C fn_80011760 = .text:0x80011760; // type:function size:0x1D4 fn_80011940 = .text:0x80011940; // type:function size:0x100 @@ -26206,10 +26206,10 @@ becomeCurrentHeap__Q23EGG4HeapFv = .text:0x804959A0; // type:function size:0x58 _becomeCurrentHeapWithoutLock__Q23EGG4HeapFv = .text:0x80495A00; // type:function size:0x3C initAllocator__Q23EGG4HeapFPQ23EGG9Allocatorl = .text:0x80495A40; // type:function size:0x14 __nw__FUlPv = .text:0x80495A60; // type:function size:0x8 -__nw__FUlPQ23EGG4Heapi = .text:0x80495A70; // type:function size:0x10 +__nw__FUlPQ23EGG4HeapUi = .text:0x80495A70; // type:function size:0x10 __nwa__FUl = .text:0x80495A80; // type:function size:0x10 -__nwa__FUli = .text:0x80495A90; // type:function size:0x8 -__nwa__FUlPQ23EGG4Heapi = .text:0x80495AA0; // type:function size:0x10 +__nwa__FUlUi = .text:0x80495A90; // type:function size:0x8 +__nwa__FUlPQ23EGG4HeapUi = .text:0x80495AA0; // type:function size:0x10 __ct__Q23EGG7ExpHeapFP12MEMiHeapHead = .text:0x80495AB0; // type:function size:0x3C __dt__Q23EGG7ExpHeapFv = .text:0x80495AF0; // type:function size:0x74 create__Q23EGG7ExpHeapFPvUlUs = .text:0x80495B70; // type:function size:0xB8 @@ -27388,7 +27388,7 @@ __destroy_global_chain = .text:0x804C65D8; // type:function size:0x48 scope:glob fn_804C6620 = .text:0x804C6620; // type:function size:0x104 fn_804C6724 = .text:0x804C6724; // type:function size:0xBC __construct_array = .text:0x804C67E0; // type:function size:0xF8 -fn_804C68D8 = .text:0x804C68D8; // type:function size:0x78 +__destroy_arr = .text:0x804C68D8; // type:function size:0x78 fn_804C6950 = .text:0x804C6950; // type:function size:0x80 __ptmf_test = .text:0x804C69D0; // type:function size:0x30 fn_804C6A00 = .text:0x804C6A00; // type:function size:0x3C @@ -29842,7 +29842,7 @@ lbl_80500300 = .data:0x80500300; // type:object size:0x10 lbl_80500310 = .data:0x80500310; // type:object size:0x28 lbl_80500338 = .data:0x80500338; // type:object size:0x5C lbl_80500394 = .data:0x80500394; // type:object size:0x6C -lbl_80500400 = .data:0x80500400; // type:object size:0x10 +__vt__8UnkClass = .data:0x80500400; // type:object size:0x10 lbl_80500410 = .data:0x80500410; // type:object size:0xB0 jumptable_805004C0 = .data:0x805004C0; // type:object size:0x58 scope:local jumptable_80500518 = .data:0x80500518; // type:object size:0x80 scope:local @@ -39631,7 +39631,7 @@ lbl_80574FE0 = .sbss:0x80574FE0; // type:object size:0x1 data:byte lbl_80574FE4 = .sbss:0x80574FE4; // type:object size:0x4 data:4byte lbl_80574FE8 = .sbss:0x80574FE8; // type:object size:0x4 data:4byte lbl_80574FEC = .sbss:0x80574FEC; // type:object size:0xC -lbl_80574FF8 = .sbss:0x80574FF8; // type:object size:0x4 +sInstance__8UnkClass = .sbss:0x80574FF8; // type:object size:0x4 sInstance__11FileManager = .sbss:0x80574FFC; // type:object size:0x4 data:4byte lbl_80575000 = .sbss:0x80575000; // type:object size:0x8 data:4byte lbl_80575008 = .sbss:0x80575008; // type:object size:0x8 data:4byte diff --git a/include/egg/core/eggHeap.h b/include/egg/core/eggHeap.h index 10b114e9..db384abd 100644 --- a/include/egg/core/eggHeap.h +++ b/include/egg/core/eggHeap.h @@ -159,6 +159,6 @@ public: /* 80495a70 */ void *operator new(size_t size, EGG::Heap *heap, u32 align); /* 80495a80 */ void *operator new(size_t size, EGG::Allocator *alloc); /* 80495a90 */ void *operator new[](size_t size, u32 align); -/* 80495aa0 */ void *operator new[](size_t size, EGG::Heap *heap, int align); +/* 80495aa0 */ void *operator new[](size_t size, EGG::Heap *heap, u32 align); #endif diff --git a/include/m/m_vec.h b/include/m/m_vec.h index 02817ec0..b182642e 100644 --- a/include/m/m_vec.h +++ b/include/m/m_vec.h @@ -8,7 +8,8 @@ class mVec3_c : public EGG::Vector3f { public: /// @brief Constructs an empty vector. - mVec3_c() {} + /* 80009ee0 */ mVec3_c() {} + /* 80007460 */ ~mVec3_c() {} /// @brief Constructs a vector from a float array. mVec3_c(const f32 *p) { diff --git a/include/toBeSorted/file_manager.h b/include/toBeSorted/file_manager.h index 9b588943..0bf79629 100644 --- a/include/toBeSorted/file_manager.h +++ b/include/toBeSorted/file_manager.h @@ -46,7 +46,7 @@ public: /* 80009DB0 */ FileManager(); // /* 80009EE0 */ // mVec3(); - /* 80009EF0 */ static FileManager create(EGG::Heap *); + /* 80009EF0 */ static FileManager *create(EGG::Heap *); /* 80009F30 */ bool loadSaveData(void *out, char *name, bool isSkipData); /* 80009F70 */ void saveSaveData(void *unk, bool isSkipData); /* 8000A000 */ void refreshSaveFileData(); @@ -57,7 +57,7 @@ public: /* 8000A2E0 */ void fn_8000A2E0(); // idk something blank save files /* 8000A330 */ u16 *getStoryFlagsMut(); - /* 8000A360 */ u16 *getStoryFlagsConst(); + /* 8000A360 */ const u16 *getStoryFlagsConst() const; /* 8000A3B0 */ u16 *getItemFlagsMut(); /* 8000A3E0 */ u16 *getItemFlagsConst(); /* 8000A430 */ u16 *getDungeonFlagsMut(); @@ -243,6 +243,7 @@ public: /* 80010440 */ void clearTempFileData(); /* 800104A0 */ void saveAfterCredits(); /* 80011210 */ SaveFile *getCurrentFile(); + inline const SaveFile *getCurrentFile() const { return isFileInactive() ? &mFileB : &mFileA; } /* 80011250 */ u16 *getSkipFlags2(); /* 80011260 */ SaveFile *getFileA(); /* 80011270 */ SaveFile *getFileB(); @@ -254,7 +255,7 @@ public: /* 800113B0 */ u8 get_0xA84C(); /* 800113C0 */ bool checkRegionCode(); /* 80011440 */ bool checkFileCRC(int fileNum); - /* 80011490 */ bool isFileInactive(); + /* 80011490 */ bool isFileInactive() const; /* 80011500 */ void setPlayerInfoFileA(); /* 800115E0 */ void setT3Info(mVec3_c *pos, mAng3_c *rot); /* 800116C0 */ static void getRegionVersion(char *out); diff --git a/include/toBeSorted/save_file.h b/include/toBeSorted/save_file.h index ea8d0b45..1a8fea8d 100644 --- a/include/toBeSorted/save_file.h +++ b/include/toBeSorted/save_file.h @@ -1,20 +1,20 @@ #ifndef SAVE_FILE_H #define SAVE_FILE_H -#include "UnknownTypeBelongings.h" +#include "m/m_vec.h" #include // Ghidra: SaveFile // Size: 0x53c0 // non-offical name -class SaveFile { +struct SaveFile { public: /* 0x 0000 */ char field_0x0000[0x8 - 0x0]; /* 0x 0008 */ s64 savedTime; - /* 0x 0010 */ Vec3f pos_t1; - /* 0x 001c */ Vec3f pos_t2; - /* 0x 0028 */ Vec3f pos_t3; - /* 0x 0034 */ Vec3f beacon_pos[32][5]; + /* 0x 0010 */ mVec3_c pos_t1; + /* 0x 001c */ mVec3_c pos_t2; + /* 0x 0028 */ mVec3_c pos_t3; + /* 0x 0034 */ mVec3_c beacon_pos[32][5]; /* 0x 07b4 */ s32 beedleShopPathSegment; /* 0x 07b8 */ f32 beedlShopPathSegFrac; /* 0x 07bc */ char field_0x07BC[0x7c0 - 0x7bc]; @@ -86,7 +86,7 @@ public: // ---------------------------------------------------------- public: /* 800099b0 */ u16 *getStoryFlags0(); - /* 800099c0 */ u16 *getStoryFlags1(); + /* 800099c0 */ const u16 *getStoryFlags1() const; /* 800099d0 */ u16 *getItemFlags0(); /* 800099e0 */ u16 *getItemFlags1(); /* 800099F0 */ u16 *getDungeonFlags0(); diff --git a/src/toBeSorted/file_manager.cpp b/src/toBeSorted/file_manager.cpp index 3447b05a..436720f2 100644 --- a/src/toBeSorted/file_manager.cpp +++ b/src/toBeSorted/file_manager.cpp @@ -1,18 +1,53 @@ #include "toBeSorted/file_manager.h" #include "f/f_base.h" +#include +#include "libc.h" + +// This class here makes no sense and the name might +// be a total misnomer, but this gets the sinit section correct +class UnkClass { +public: + UnkClass(); + virtual ~UnkClass(); + + static UnkClass sInstance; +}; +// This seems really pointless since the class only has a virtual destructor +// and no members but /shrug +UnkClass UnkClass::sInstance; + +UnkClass::UnkClass() {} +UnkClass::~UnkClass() {} + +FileManager *FileManager::sInstance; extern "C" { - /* 80009D30 */ void fn_80009D30() {} // some ctor - /* 80009D40 */ void fn_80009D40() {} // some dtor /* 80009D80 */ void fn_80009D80() {} // return /* 80009D90 */ void fn_80009D90() {} // return - /* 80009DA0 */ void fn_80009DA0() {} // memset(param_1, 0, 0x20) a 0x24 structure is implied here (0x20 data) a crc is at 0x24 + /* 80009DA0 */ void fn_80009DA0(void *ptr) { + memset(ptr, 0, 0x20); + } // memset(param_1, 0, 0x20) a 0x24 structure is implied here (0x20 data) a crc is at 0x24 } -/* 80009DB0 */ FileManager::FileManager() {} +/* 80009DB0 */ FileManager::FileManager() { + // TODO the assembly code looks really wild + u32 numSaves = (u32)(mHeroName - mHeroNames[0]) / 0x12; + for (int i = 0; i < numSaves; i++) { + mHeroNames[i][0] = '\0'; + } + + mHeroName[0] = '\0'; + mCurrentArea[0] = '\0'; + sInstance = this; + mpSavedSaveFiles = mHeap::g_gameHeaps[0]->alloc(0xfbe0, 0x20); + mpSkipData = mHeap::g_gameHeaps[0]->alloc(0x80, 0x20); + fn_8000A2E0(); +} /* 80009EE0 */ // mVec3(); -/* 80009EF0 */ FileManager FileManager::create(EGG::Heap*){} +/* 80009EF0 */ FileManager *FileManager::create(EGG::Heap* heap) { + return new(heap, 0x04) FileManager(); +} /* 80009F30 */ bool FileManager::loadSaveData(void* out, char* name, bool isSkipData){} /* 80009F70 */ void FileManager::saveSaveData(void* unk, bool isSkipData){} /* 8000A000 */ void FileManager::refreshSaveFileData(){} @@ -20,14 +55,20 @@ extern "C" { /* 8000A280 */ s64 FileManager::getFileSaveTime(int fileNum){} /* 8000A2A0 */ s16 FileManager::getFileCurrentHealth(int fileNum){} /* 8000A2C0 */ s16 FileManager::getFileHealthCapacity(int fileNum){} -/* 8000A2E0 */ void FileManager::fn_8000A2E0(){} +/* 8000A2E0 */ void FileManager::fn_8000A2E0(){ + // maybe call this function "reset" + mIsFileUnk1[0] = true; + initBlankSaveFiles(); + m_0xA84D = 0; + mSelectedFile = 1; +} /* 8000A330 */ u16* FileManager::getStoryFlagsMut() { return getCurrentFile()->getStoryFlags0(); } -/* 8000A360 */ u16* FileManager::getStoryFlagsConst() { - return (isFileInactive() ? mFileB : mFileA).getStoryFlags1(); +/* 8000A360 */ const u16* FileManager::getStoryFlagsConst() const { + return getCurrentFile()->getStoryFlags1(); } /* 8000A3B0 */ u16* FileManager::getItemFlagsMut() {} /* 8000A3E0 */ u16* FileManager::getItemFlagsConst() {} @@ -213,10 +254,16 @@ u16* FileManager::getStoryFlagsMut() { /* 80010440 */ void FileManager::clearTempFileData() {} /* 800104A0 */ void FileManager::saveAfterCredits() {} -/* 80011210 */ SaveFile* FileManager::getCurrentFile() {} +/* 80011210 */ SaveFile* FileManager::getCurrentFile() { + return isFileInactive() ? &mFileB : &mFileA; +} /* 80011250 */ u16* FileManager::getSkipFlags2() {} -/* 80011260 */ SaveFile* FileManager::getFileA() {} -/* 80011270 */ SaveFile* FileManager::getFileB() {} +/* 80011260 */ SaveFile* FileManager::getFileA() { + return &mFileA; +} +/* 80011270 */ SaveFile* FileManager::getFileB() { + return &mFileB; +} /* 80011280 */ void FileManager::calcFileCRC(const SaveFile* file, u32 length) {} /* 80011290 */ void FileManager::updateEmptyFiles() {} /* 800112D0 */ void FileManager::updateEmptyFileFlags() {} @@ -226,7 +273,7 @@ u16* FileManager::getStoryFlagsMut() { /* 800113C0 */ bool FileManager::checkRegionCode() {} /* 80011440 */ bool FileManager::checkFileCRC(int fileNum) {} /* 80011490 */ -bool FileManager::isFileInactive() { +bool FileManager::isFileInactive() const { fBase_c* actor = fManager_c::searchBaseByGroupType(1, nullptr); if (actor) { if (actor->profile_name == fProfile::TITLE && !mAntiCommitFlag) @@ -238,4 +285,3 @@ bool FileManager::isFileInactive() { /* 80011500 */ void FileManager::setPlayerInfoFileA() {} /* 800115E0 */ void FileManager::setT3Info(mVec3_c* pos, mAng3_c* rot) {} /* 800116C0 */ void FileManager::getRegionVersion(char* out) {} - diff --git a/src/toBeSorted/save_file.cpp b/src/toBeSorted/save_file.cpp index c876ccd5..d55d11f3 100644 --- a/src/toBeSorted/save_file.cpp +++ b/src/toBeSorted/save_file.cpp @@ -6,7 +6,7 @@ u16* SaveFile::getStoryFlags0() { return story_flags; } // 0x800099c0 getStoryFlags1__8SaveFileFv -u16* SaveFile::getStoryFlags1() { +const u16* SaveFile::getStoryFlags1() const { return story_flags; } // 0x800099d0 getItemFlags0__8SaveFileFv @@ -105,4 +105,4 @@ s8* SaveFile::getAreaT2() { // 0x80009D20 getAreaT3__8SaveFileFv s8* SaveFile::getAreaT3() { return area_t3; -} \ No newline at end of file +}