From cc3b62d6c131fd54db75b7dbc76b1fc7659f25ca Mon Sep 17 00:00:00 2001 From: robojumper Date: Wed, 1 May 2024 21:16:43 +0200 Subject: [PATCH 01/23] 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 +} From 210e350ee02a8d6348fdddf0792ecd772ab7a784 Mon Sep 17 00:00:00 2001 From: robojumper Date: Thu, 2 May 2024 00:10:44 +0200 Subject: [PATCH 02/23] some crc --- config/SOUE01/symbols.txt | 24 +-- include/m/m_heap.h | 2 +- include/toBeSorted/file_manager.h | 33 +++-- include/toBeSorted/save_file.h | 42 +++--- src/toBeSorted/file_manager.cpp | 237 +++++++++++++++++++++++++++--- src/toBeSorted/save_file.cpp | 40 ++--- 6 files changed, 292 insertions(+), 86 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index f7fe385e..81006c4c 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -229,19 +229,19 @@ fn_80009970 = .text:0x80009970; // type:function size:0x34 getStoryFlags0__8SaveFileFv = .text:0x800099B0; // 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 +getItemFlags1__8SaveFileCFv = .text:0x800099E0; // type:function size:0x8 getDungeonFlags0__8SaveFileFv = .text:0x800099F0; // type:function size:0x8 -getDungeonFlags1__8SaveFileFv = .text:0x80009A00; // type:function size:0x8 +getDungeonFlags1__8SaveFileCFv = .text:0x80009A00; // type:function size:0x8 getSceneFlags0__8SaveFileFv = .text:0x80009A10; // type:function size:0x8 -getSceneFlags1__8SaveFileFv = .text:0x80009A20; // type:function size:0x8 +getSceneFlags1__8SaveFileCFv = .text:0x80009A20; // type:function size:0x8 getTboxFlags0__8SaveFileFv = .text:0x80009A30; // type:function size:0x8 -getTboxFlags1__8SaveFileFv = .text:0x80009A40; // type:function size:0x8 +getTboxFlags1__8SaveFileCFv = .text:0x80009A40; // type:function size:0x8 getTempFlags0__8SaveFileFv = .text:0x80009A50; // type:function size:0x8 -getTempFlags1__8SaveFileFv = .text:0x80009A60; // type:function size:0x8 +getTempFlags1__8SaveFileCFv = .text:0x80009A60; // type:function size:0x8 getZoneFlags0__8SaveFileFv = .text:0x80009A70; // type:function size:0x8 -getZoneFlags1__8SaveFileFv = .text:0x80009A80; // type:function size:0x8 -getUnkFlags0__8SaveFileFv = .text:0x80009A90; // type:function size:0x8 -getUnkFlags1__8SaveFileFv = .text:0x80009AA0; // type:function size:0x8 +getZoneFlags1__8SaveFileCFv = .text:0x80009A80; // type:function size:0x8 +getEnemyFlags0__8SaveFileFv = .text:0x80009A90; // type:function size:0x8 +getEnemyFlags1__8SaveFileCFv = .text:0x80009AA0; // type:function size:0x8 getPlayerName__8SaveFileFv = .text:0x80009AB0; // type:function size:0x8 setAreaT1__8SaveFileFPc = .text:0x80009AC0; // type:function size:0x11C getAreaT1__8SaveFileFv = .text:0x80009BE0; // type:function size:0x8 @@ -410,7 +410,7 @@ saveFileAToSelectedFile__11FileManagerFv = .text:0x8000EF80; // type:function si saveFileAToFile__11FileManagerFi = .text:0x8000EF90; // type:function size:0x794 copyCurrentToFileB__11FileManagerFv = .text:0x8000F730; // type:function size:0x6B4 copySelectedFileSkipData__11FileManagerFv = .text:0x8000FDF0; // type:function size:0xC -copySkipData__11FileManagerFi = .text:0x8000FE00; // type:function size:0xA8 +copySkipData__11FileManagerFUc = .text:0x8000FE00; // type:function size:0xA8 setInfo_FileB__11FileManagerFv = .text:0x8000FEB0; // type:function size:0xAC clearFileA__11FileManagerFv = .text:0x8000FF60; // type:function size:0x94 initBlankSaveFiles__11FileManagerFv = .text:0x80010000; // type:function size:0x154 @@ -424,14 +424,14 @@ getCurrentFile__11FileManagerFv = .text:0x80011210; // type:function size:0x40 getSkipFlags2__11FileManagerFv = .text:0x80011250; // type:function size:0xC getFileA__11FileManagerFv = .text:0x80011260; // type:function size:0x8 getFileB__11FileManagerFv = .text:0x80011270; // type:function size:0x8 -calcFileCRC__11FileManagerFPC8SaveFileUi = .text:0x80011280; // type:function size:0xC +calcFileCRC__11FileManagerFPCvUi = .text:0x80011280; // type:function size:0xC updateEmptyFiles__11FileManagerFv = .text:0x80011290; // type:function size:0x34 updateEmptyFileFlags__11FileManagerFv = .text:0x800112D0; // type:function size:0x9C isFileEmpty__11FileManagerFi = .text:0x80011370; // type:function size:0x20 -isFileUnk3__11FileManagerFi = .text:0x80011390; // type:function size:0x20 +isFileDirty__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 +checkFileCRC__11FileManagerFUc = .text:0x80011440; // type:function size:0x50 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 diff --git a/include/m/m_heap.h b/include/m/m_heap.h index 4ee94d11..65edc4e5 100644 --- a/include/m/m_heap.h +++ b/include/m/m_heap.h @@ -33,7 +33,7 @@ namespace mHeap { u32 unk); /* 802f1450 */ int getGameHeapNum(); /* 802f1460 */ EGG::ExpHeap *createGameHeap(s32 heapNum, size_t size, EGG::Heap *parentHeap); -/* 802f1510 */ EGG::Heap *createGameHeap1(s32 size, EGG::Heap *parentHeap); +/* 802f1510 */ EGG::ExpHeap *createGameHeap1(s32 size, EGG::Heap *parentHeap); /* 802f1560 */ EGG::ExpHeap *createArchiveHeap(size_t size, EGG::Heap *parentHeap); /* 802f1590 */ EGG::ExpHeap *createCommandHeap(size_t size, EGG::Heap *parentHeap); /* 802f15c0 */ EGG::ExpHeap *createDylinkHeap(size_t size, EGG::Heap *parentHeap); diff --git a/include/toBeSorted/file_manager.h b/include/toBeSorted/file_manager.h index 0bf79629..1be099b1 100644 --- a/include/toBeSorted/file_manager.h +++ b/include/toBeSorted/file_manager.h @@ -8,14 +8,29 @@ enum ITEM_ID {}; enum SAVE_ITEM_ID {}; +class SkipData { +public: + /** 0x00 */ u16 data[16]; + /** 0x20 */ u32 crc; +}; + +class SavedSaveFiles { +public: + /** 0x00 */ char regionCode[4]; + /** 0x04 */ u8 unk1[0x1C - 0x04]; + /** 0x1C */ u32 m_0x1C; + /** 0x20 */ SaveFile saveFiles[3]; + /** 0xfb60 */ SkipData skipData[3]; + /** 0xfbcc */ u8 unk2[0xfbe0 - 0xfb60]; +}; + class FileManager { public: - /* 0x0000 */ void *mpSavedSaveFiles; - /* 0x0004 */ void *mpSkipData; // skip data Arrary (3 entries ) + /* 0x0000 */ SavedSaveFiles *mpSavedSaveFiles; + /* 0x0004 */ SkipData *mpSkipData; // skip data Arrary (3 entries ) /* 0x0008 */ SaveFile mFileA; /* 0x53C8 */ SaveFile mFileB; - /* 0xA788 */ u16 mSkipFlags[16]; - /* 0xA7A8 */ u32 mSkipFlagsCRC; + /* 0xA788 */ SkipData mSkipData; /* 0xA7AC */ wchar_t mHeroNames[3][9]; // each name is 9 wchars /* 0xA7E2 */ wchar_t mHeroName[9]; // The current Hero Name /* 0xA7F4 */ char mCurrentArea[32]; @@ -219,7 +234,7 @@ public: /* 8000D040 */ u8 getSkykeepPuzzleTile(u32 spot); /* 8000D0B0 */ void checkFileStatus(); - /* 8000D1D0 */ void checkSkipDataCRCs(); + /* 8000D1D0 */ bool checkSkipDataCRCs(); /* 8000D270 */ void saveOrClearSelectedFileToFileA(); /* 8000D280 */ void saveOrClearToFileA(int fileNum); /* 8000D9C0 */ void copyFileBToCurrentFile(); @@ -230,7 +245,7 @@ public: /* 8000EF90 */ void saveFileAToFile(int fileNum); /* 8000F730 */ void copyCurrentToFileB(); /* 8000FDF0 */ void copySelectedFileSkipData(); - /* 8000FE00 */ void copySkipData(int fileNum); + /* 8000FE00 */ void copySkipData(u8 fileNum); /* 8000FEB0 */ void setInfo_FileB(); /* 8000FF60 */ void clearFileA(); @@ -247,14 +262,14 @@ public: /* 80011250 */ u16 *getSkipFlags2(); /* 80011260 */ SaveFile *getFileA(); /* 80011270 */ SaveFile *getFileB(); - /* 80011280 */ void calcFileCRC(const SaveFile *file, u32 length); + /* 80011280 */ u32 calcFileCRC(const void *data, u32 length); /* 80011290 */ void updateEmptyFiles(); /* 800112D0 */ void updateEmptyFileFlags(); /* 80011370 */ bool isFileEmpty(int fileNum); - /* 80011390 */ bool isFileUnk3(int fileNum); + /* 80011390 */ bool isFileDirty(int fileNum); /* 800113B0 */ u8 get_0xA84C(); /* 800113C0 */ bool checkRegionCode(); - /* 80011440 */ bool checkFileCRC(int fileNum); + /* 80011440 */ bool checkFileCRC(u8 fileNum); /* 80011490 */ bool isFileInactive() const; /* 80011500 */ void setPlayerInfoFileA(); /* 800115E0 */ void setT3Info(mVec3_c *pos, mAng3_c *rot); diff --git a/include/toBeSorted/save_file.h b/include/toBeSorted/save_file.h index 1a8fea8d..22c57de2 100644 --- a/include/toBeSorted/save_file.h +++ b/include/toBeSorted/save_file.h @@ -9,7 +9,7 @@ // non-offical name struct SaveFile { public: - /* 0x 0000 */ char field_0x0000[0x8 - 0x0]; + /* 0x 0000 */ s64 playTime; /* 0x 0008 */ s64 savedTime; /* 0x 0010 */ mVec3_c pos_t1; /* 0x 001c */ mVec3_c pos_t2; @@ -17,11 +17,11 @@ public: /* 0x 0034 */ mVec3_c beacon_pos[32][5]; /* 0x 07b4 */ s32 beedleShopPathSegment; /* 0x 07b8 */ f32 beedlShopPathSegFrac; - /* 0x 07bc */ char field_0x07BC[0x7c0 - 0x7bc]; + /* 0x 07bc */ u32 field_0x07BC; /* 0x 07c0 */ s32 pouch_items[8]; /* 0x 07e0 */ s32 item_check_items[60]; /* 0x 08d0 */ int file_area_index; - /* 0x 08d4 */ s16 player_name[8]; + /* 0x 08d4 */ wchar_t player_name[8]; /* 0x 08e4 */ u16 story_flags[128]; /* 0x 09e4 */ u16 item_flags[64]; /* 0x 0a64 */ u16 dungeon_flags[8][22]; @@ -34,15 +34,15 @@ public: /* 0x 302c */ u16 hitByEnemyCounts[100]; /* 0x 30f4 */ u16 temp_flags[4]; /* 0x 30fc */ u16 zone_flags[252]; - /* 0x 32f4 */ u16 unk_flags[4096]; // size guessed? (saw memset) - /* 0x 52f4 */ s16 air_potion_timer; - /* 0x 52f6 */ s16 air_potion_plus_timer; - /* 0x 52f8 */ s16 stamina_potion_timer; - /* 0x 52fa */ s16 stamina_potion_plus_timer; - /* 0x 52fc */ s16 gaurdian_potion_timer; - /* 0x 52fe */ s16 gaurdian_potion_plus_timer; - /* 0x 5300 */ s16 field_0x5300; - /* 0x 5302 */ s16 health_capacity; + /* 0x 32f4 */ u16 enemy_flags[4096]; + /* 0x 52f4 */ u16 air_potion_timer; + /* 0x 52f6 */ u16 air_potion_plus_timer; + /* 0x 52f8 */ u16 stamina_potion_timer; + /* 0x 52fa */ u16 stamina_potion_plus_timer; + /* 0x 52fc */ u16 gaurdian_potion_timer; + /* 0x 52fe */ u16 gaurdian_potion_plus_timer; + /* 0x 5300 */ u16 field_0x5300; + /* 0x 5302 */ u16 health_capacity; /* 0x 5304 */ u16 unused_heart_related; /* 0x 5306 */ u16 current_health; /* 0x 5308 */ u16 room_id_t1; @@ -88,20 +88,20 @@ public: /* 800099b0 */ u16 *getStoryFlags0(); /* 800099c0 */ const u16 *getStoryFlags1() const; /* 800099d0 */ u16 *getItemFlags0(); - /* 800099e0 */ u16 *getItemFlags1(); + /* 800099e0 */ const u16 *getItemFlags1() const; /* 800099F0 */ u16 *getDungeonFlags0(); - /* 80009A00 */ u16 *getDungeonFlags1(); + /* 80009A00 */ const u16 *getDungeonFlags1() const; /* 80009A10 */ u16 *getSceneFlags0(); - /* 80009A20 */ u16 *getSceneFlags1(); + /* 80009A20 */ const u16 *getSceneFlags1() const; /* 80009A30 */ u16 *getTboxFlags0(); - /* 80009A40 */ u16 *getTboxFlags1(); + /* 80009A40 */ const u16 *getTboxFlags1() const; /* 80009A50 */ u16 *getTempFlags0(); - /* 80009A60 */ u16 *getTempFlags1(); + /* 80009A60 */ const u16 *getTempFlags1() const; /* 80009A70 */ u16 *getZoneFlags0(); - /* 80009A80 */ u16 *getZoneFlags1(); - /* 80009A90 */ u16 *getUnkFlags0(); - /* 80009AA0 */ u16 *getUnkFlags1(); - /* 80009AB0 */ s16 *getPlayerName(); // UTF16-BE + /* 80009A80 */ const u16 *getZoneFlags1() const; + /* 80009A90 */ u16 *getEnemyFlags0(); + /* 80009AA0 */ const u16 *getEnemyFlags1() const; + /* 80009AB0 */ wchar_t *getPlayerName(); // UTF16-BE /* 80009AC0 */ void setAreaT1(char *name); /* 80009BE0 */ char *getAreaT1(); /* 80009BF0 */ void setAreaT2(char *name); diff --git a/src/toBeSorted/file_manager.cpp b/src/toBeSorted/file_manager.cpp index 436720f2..cde98210 100644 --- a/src/toBeSorted/file_manager.cpp +++ b/src/toBeSorted/file_manager.cpp @@ -1,25 +1,27 @@ #include "toBeSorted/file_manager.h" #include "f/f_base.h" #include -#include "libc.h" +// #include "libc.h" +#include // 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(); + /* vtable at 80500400 */ 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; +/* 80574FF8 */ UnkClass UnkClass::sInstance; -UnkClass::UnkClass() {} -UnkClass::~UnkClass() {} +/* 80009D30 */ UnkClass::UnkClass() {} +/* 80009D40 */ UnkClass::~UnkClass() {} -FileManager *FileManager::sInstance; +/* 80574FFC */ FileManager *FileManager::sInstance; extern "C" { /* 80009D80 */ void fn_80009D80() {} // return @@ -39,8 +41,9 @@ extern "C" { mHeroName[0] = '\0'; mCurrentArea[0] = '\0'; sInstance = this; - mpSavedSaveFiles = mHeap::g_gameHeaps[0]->alloc(0xfbe0, 0x20); - mpSkipData = mHeap::g_gameHeaps[0]->alloc(0x80, 0x20); + // TODO these should probably use the new operators? + mpSavedSaveFiles = (SavedSaveFiles*) mHeap::g_gameHeaps[0]->alloc(sizeof(SavedSaveFiles), 0x20); + mpSkipData = (SkipData*) mHeap::g_gameHeaps[0]->alloc(0x80, 0x20); fn_8000A2E0(); } /* 80009EE0 */ // mVec3(); @@ -96,7 +99,58 @@ u16* FileManager::getStoryFlagsMut() { /* 8000AA30 */ u16* FileManager::getSkipFlags() {} /* 8000AA40 */ void FileManager::setSkipFlagsChecked(u16* flags, u32 offset, u16 count) {} -/* 8000AAA0 */ void FileManager::initFile(int fileNum) {} +inline void strncat(char *dest, const char *src, size_t count) { + if (dest != src) { + dest[0] = '\0'; + if (src != nullptr) { + size_t len = strlen(dest); + size_t count = strlen(src); + count = len + count + 1 >= 0x20 ? 0x1f - len : count; + strncpy(dest + len, src, count)[count] = '\0'; + } + } +} + +/* 8000AAA0 */ void FileManager::initFile(int fileNum) { + SaveFile *file; + char buf[0x20]; + + mIsFileInvalid[1] = 1; + file = getFileA(); + if (fileNum != 0) { + file = &mFileB; + } + file->new_file = 0; + file->health_capacity = 0x18; + file->unused_heart_related = 0x18; + file->current_health = 0x18; + file->shield_pouch_slot = 8; + file->equipped_b_item = 0xb; + file->selectedDowsingSlot = 0x8; + file->lastUsedPouchItemSlot = 0x8; + + buf[0] = '\0'; + strncat(buf, "F405", 0x20); + /* + buf[0] = '\0'; + // TODO looks like an inlined strncat, + // hence the needless comparison to a .data string + // Not sure how we can do this? + // strncat(buf, etc, 0x20); + if (etc != buf) { + buf[0] = '\0'; + if (etc != nullptr) { + size_t len = strlen(buf); + size_t count = strlen(etc); + count = len + count + 1 >= 0x20 ? 0x1f - len : count; + strncpy(buf + len, etc, count)[count] = '\0'; + } + }*/ + file->setAreaT1(buf); + file->room_id_t1 = 0; + file->forced_layer_t1 = 0; + file->entrance_t1_load_flag = 1; +} /* 8000ABD0 */ void FileManager::setCurrentHealthCapacity(s16 health) {} /* 8000AC00 */ s16 FileManager::getCurrentHealthCapacity() {} @@ -229,29 +283,163 @@ u16* FileManager::getStoryFlagsMut() { /* 8000CFE0 */ void FileManager::setSkykeepPuzzle(u32 spot, u8 tile) {} /* 8000D040 */ u8 FileManager::getSkykeepPuzzleTile(u32 spot) {} -/* 8000D0B0 */ void FileManager::checkFileStatus() {} -/* 8000D1D0 */ void FileManager::checkSkipDataCRCs() {} -/* 8000D270 */ void FileManager::saveOrClearSelectedFileToFileA() {} +/* 8000D0B0 */ void FileManager::checkFileStatus() { + mIsFileInvalid[2] = 0; + SkipData *data; + SavedSaveFiles *files = mpSavedSaveFiles; + + if (!checkRegionCode()) { + mIsFileInvalid[2] = 1; + } + if (files->m_0x1C != 0x1d) { + mIsFileInvalid[2] = 1; + } + + for (u8 i = 0; i < 3; i++) { + if (checkFileCRC(i) == 0) { + mIsFileDataDirty[i] = 1; + } else { + mIsFileDataDirty[i] = 0; + } + } + + int i; + for (i = 0, data = files->skipData; i < 3; i++, data++) { + u32 crc = calcFileCRC(data->data, sizeof(data->data)); + if (crc != data->crc) { + fn_80009DA0(data); + data->crc = calcFileCRC(data->data, sizeof(data->data)); + } + } +} +/* 8000D1D0 */ bool FileManager::checkSkipDataCRCs() { + SkipData *data; + bool dirty = false; + int i; + for (data = &mpSkipData[0], i = 0; i < 3; i++, data++) { + u32 crc = calcFileCRC(data->data, sizeof(data->data)); + if (crc == data->crc) { + mIsFileSkipDataDirty[i & 0xff] = 0; + } else { + mIsFileSkipDataDirty[i & 0xff] = 1; + dirty = true; + } + } + return dirty; +} +/* 8000D270 */ void FileManager::saveOrClearSelectedFileToFileA() { + saveOrClearToFileA(mSelectedFile); +} /* 8000D280 */ void FileManager::saveOrClearToFileA(int fileNum) {} /* 8000D9C0 */ void FileManager::copyFileBToCurrentFile() {} -/* 8000E060 */ void FileManager::copyFileAToSelectedFile() {} +/* 8000E060 */ void FileManager::copyFileAToSelectedFile() { + copyFileAToFile(mSelectedFile); +} /* 8000E070 */ void FileManager::copyFileAToFile(int fileNum) {} /* 8000E7C0 */ void FileManager::copyFile(int from, int to) {} -/* 8000EF80 */ void FileManager::saveFileAToSelectedFile() {} +/* 8000EF80 */ void FileManager::saveFileAToSelectedFile() { + saveFileAToFile(mSelectedFile); +} /* 8000EF90 */ void FileManager::saveFileAToFile(int fileNum) {} /* 8000F730 */ void FileManager::copyCurrentToFileB() {} -/* 8000FDF0 */ void FileManager::copySelectedFileSkipData() {} -/* 8000FE00 */ void FileManager::copySkipData(int fileNum) {} +/* 8000FDF0 */ void FileManager::copySelectedFileSkipData() { + copySkipData(mSelectedFile); +} +/* 8000FE00 */ void FileManager::copySkipData(u8 fileNum) { + if (fileNum < 3) { + SkipData *curr = &mSkipData; + SkipData *data = mpSkipData; + curr->crc = calcFileCRC(&curr->data, sizeof(mSkipData.data)); + data[fileNum] = *curr; + } +} /* 8000FEB0 */ void FileManager::setInfo_FileB() {} -/* 8000FF60 */ void FileManager::clearFileA() {} +/* 8000FF60 */ void FileManager::clearFileA() { + SkipData *data; + SaveFile *file = getFileA(); + memset(file, 0, sizeof(SaveFile)); + file->new_file = 1; + file->checksum = calcFileCRC(file, sizeof(SaveFile) - sizeof(u32)); + data = &mSkipData; + memset(&data->data, 0, sizeof(SkipData)); + data->crc = calcFileCRC(data->data, sizeof(mSkipData.data)); +} -/* 80010000 */ void FileManager::initBlankSaveFiles() {} -/* 80010160 */ void FileManager::initSkipData() {} +/* 80010000 */ void FileManager::initBlankSaveFiles() { + memset(mpSavedSaveFiles, 0, 0xfbe0); + mSelectedFile = 0; + memset(mIsFileEmpty, 0, 3); + SkipData *data; + + SaveFile *file; + SavedSaveFiles *saved = mpSavedSaveFiles; + + mHeroNames[0][0] = '\0'; + mPlayTime[0] = 0; + mCurrentHealth[0] = 0; + mCurrentHealthCapacity[0] = 0; + + mHeroNames[1][0] = '\0'; + mPlayTime[1] = 0; + mCurrentHealth[1] = 0; + mCurrentHealthCapacity[1] = 0; + + mHeroNames[2][0] = '\0'; + mPlayTime[2] = 0; + mCurrentHealth[2] = 0; + mCurrentHealthCapacity[2] = 0; + + getRegionVersion(saved->regionCode); + saved->m_0x1C = 0x1d; + + file = &saved->saveFiles[0]; + for (int num = 0; num < 3; num++, file++) { + file->new_file = 1; + u32 crc = calcFileCRC(file, sizeof(SaveFile) - sizeof(u32)); + file->checksum = crc; + } + + int i; + for (i = 0, data = saved->skipData; i < 3; i++, data++) { + u32 crc = calcFileCRC(data->data, sizeof(data->data)); + data->crc = crc; + } + + clearFileA(); + mIsFileUnk1[1] = 0; + mIsFileUnk1[2] = 0; + mIsFileInvalid[0] = 0; + mIsFileInvalid[1] = 0; + m_0xA84C = 0; + mIsFileInvalid[2] = 0; + mIsFileDataDirty[0] = 0; + mIsFileDataDirty[1] = 0; + mIsFileDataDirty[2] = 0; + initSkipData(); +} +/* 80010160 */ void FileManager::initSkipData() { + memset(mpSkipData, 0, 0x80); + SkipData *data; + int i; + for (i = 0, data = &mpSkipData[0]; i < 3; i++, data++) { + u32 crc = calcFileCRC(data->data, sizeof(data->data)); + data->crc = crc; + } + mIsFileSkipDataDirty[0] = 0; + mIsFileSkipDataDirty[1] = 0; + mIsFileSkipDataDirty[2] = 0; +} /* 800101F0 */ void FileManager::unsetFileANewFile() {} /* 80010220 */ void FileManager::saveT1SaveInfo(u8 entranceT1LoadFlag) {} /* 80010350 */ void FileManager::copyFileSkipData(int fileNum) {} -/* 80010440 */ void FileManager::clearTempFileData() {} +extern "C" void fn_800C01F0(); // todo flag managers +/* 80010440 */ void FileManager::clearTempFileData() { + memset(&mFileA, 0, sizeof(SaveFile)); + memset(&mFileB, 0, sizeof(SaveFile)); + memset(&mSkipData, 0, sizeof(SkipData)); + fn_800C01F0(); +} /* 800104A0 */ void FileManager::saveAfterCredits() {} /* 80011210 */ SaveFile* FileManager::getCurrentFile() { @@ -264,14 +452,17 @@ u16* FileManager::getStoryFlagsMut() { /* 80011270 */ SaveFile* FileManager::getFileB() { return &mFileB; } -/* 80011280 */ void FileManager::calcFileCRC(const SaveFile* file, u32 length) {} -/* 80011290 */ void FileManager::updateEmptyFiles() {} +/* 80011280 */ u32 FileManager::calcFileCRC(const void *data, u32 length) {} +/* 80011290 */ void FileManager::updateEmptyFiles() { + updateEmptyFileFlags(); + refreshSaveFileData(); +} /* 800112D0 */ void FileManager::updateEmptyFileFlags() {} /* 80011370 */ bool FileManager::isFileEmpty(int fileNum) {} -/* 80011390 */ bool FileManager::isFileUnk3(int fileNum) {} +/* 80011390 */ bool FileManager::isFileDirty(int fileNum) {} /* 800113B0 */ u8 FileManager::get_0xA84C() {} /* 800113C0 */ bool FileManager::checkRegionCode() {} -/* 80011440 */ bool FileManager::checkFileCRC(int fileNum) {} +/* 80011440 */ bool FileManager::checkFileCRC(u8 fileNum) {} /* 80011490 */ bool FileManager::isFileInactive() const { fBase_c* actor = fManager_c::searchBaseByGroupType(1, nullptr); diff --git a/src/toBeSorted/save_file.cpp b/src/toBeSorted/save_file.cpp index d55d11f3..c41f1fcb 100644 --- a/src/toBeSorted/save_file.cpp +++ b/src/toBeSorted/save_file.cpp @@ -5,7 +5,7 @@ u16* SaveFile::getStoryFlags0() { return story_flags; } -// 0x800099c0 getStoryFlags1__8SaveFileFv +// 0x800099c0 getStoryFlags1__8SaveFileCFv const u16* SaveFile::getStoryFlags1() const { return story_flags; } @@ -13,60 +13,60 @@ const u16* SaveFile::getStoryFlags1() const { u16* SaveFile::getItemFlags0() { return item_flags; } -// 0x800099e0 getItemFlags1__8SaveFileFv -u16* SaveFile::getItemFlags1() { +// 0x800099e0 getItemFlags1__8SaveFileCFv +const u16* SaveFile::getItemFlags1() const { return item_flags; } // 0x800099F0 getDungeonFlags0__8SaveFileFv u16* SaveFile::getDungeonFlags0() { return dungeon_flags[0]; } -// 0x80009A00 getDungeonFlags1__8SaveFileFv -u16* SaveFile::getDungeonFlags1() { +// 0x80009A00 getDungeonFlags1__8SaveFileCFv +const u16* SaveFile::getDungeonFlags1() const { return dungeon_flags[0]; } // 0x80009A10 getSceneFlags0__8SaveFileFv u16* SaveFile::getSceneFlags0() { return scene_flags; } -// 0x80009A20 getSceneFlags1__8SaveFileFv -u16* SaveFile::getSceneFlags1() { +// 0x80009A20 getSceneFlags1__8SaveFileCFv +const u16* SaveFile::getSceneFlags1() const { return scene_flags; } // 0x80009A30 getTboxFlags0__8SaveFileFv u16* SaveFile::getTboxFlags0() { return tbox_flags; } -// 0x80009A40 getTboxFlags1__8SaveFileFv -u16* SaveFile::getTboxFlags1() { +// 0x80009A40 getTboxFlags1__8SaveFileCFv +const u16* SaveFile::getTboxFlags1() const { return tbox_flags; } // 0x80009A50 getTempFlags0__8SaveFileFv u16* SaveFile::getTempFlags0() { return temp_flags; } -// 0x80009A60 getTempFlags1__8SaveFileFv -u16* SaveFile::getTempFlags1() { +// 0x80009A60 getTempFlags1__8SaveFileCFv +const u16* SaveFile::getTempFlags1() const { return temp_flags; } // 0x80009A70 getZoneFlags0__8SaveFileFv u16* SaveFile::getZoneFlags0() { return zone_flags; } -// 0x80009A80 getZoneFlags1__8SaveFileFv -u16* SaveFile::getZoneFlags1() { +// 0x80009A80 getZoneFlags1__8SaveFileCFv +const u16* SaveFile::getZoneFlags1() const { return zone_flags; } -// 0x80009A90 getUnkFlags0__8SaveFileFv -u16* SaveFile::getUnkFlags0() { - return unk_flags; +// 0x80009A90 getEnemyFlags0__8SaveFileFv +u16* SaveFile::getEnemyFlags0() { + return enemy_flags; } -// 0x80009AA0 getUnkFlags1__8SaveFileFv -u16* SaveFile::getUnkFlags1() { - return unk_flags; +// 0x80009AA0 getEnemyFlags1__8SaveFileCFv +const u16* SaveFile::getEnemyFlags1() const { + return enemy_flags; } // 0x80009AB0 getPlayerName__8SaveFileFv -s16* SaveFile::getPlayerName() { +wchar_t* SaveFile::getPlayerName() { return player_name; } From 274675aa64fd7cef283e16fe9c04d7d55ce3d945 Mon Sep 17 00:00:00 2001 From: robojumper Date: Thu, 2 May 2024 00:52:14 +0200 Subject: [PATCH 03/23] tiniest cleanup --- src/toBeSorted/file_manager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/toBeSorted/file_manager.cpp b/src/toBeSorted/file_manager.cpp index cde98210..9da73cbb 100644 --- a/src/toBeSorted/file_manager.cpp +++ b/src/toBeSorted/file_manager.cpp @@ -315,13 +315,13 @@ inline void strncat(char *dest, const char *src, size_t count) { /* 8000D1D0 */ bool FileManager::checkSkipDataCRCs() { SkipData *data; bool dirty = false; - int i; + u8 i; for (data = &mpSkipData[0], i = 0; i < 3; i++, data++) { u32 crc = calcFileCRC(data->data, sizeof(data->data)); if (crc == data->crc) { - mIsFileSkipDataDirty[i & 0xff] = 0; + mIsFileSkipDataDirty[i] = 0; } else { - mIsFileSkipDataDirty[i & 0xff] = 1; + mIsFileSkipDataDirty[i] = 1; dirty = true; } } From 1fef0aad286b943e34998b7f8829d4ab3b88c7b4 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Thu, 2 May 2024 15:12:45 -0400 Subject: [PATCH 04/23] The ctor is closer now --- config/SOUE01/symbols.txt | 2 +- include/toBeSorted/file_manager.h | 17 +-- src/toBeSorted/file_manager.cpp | 209 +++++++++++++++--------------- 3 files changed, 116 insertions(+), 112 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 81006c4c..f852a0cb 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 -__dt__7mVec3_cFv = .text:0x80007460; // type:function size:0x40 +__dt__7mVec3_cFv = .text:0x80007460; // type:function size:0x40 scope:weak fn_800074A0 = .text:0x800074A0; // type:function size:0xC8 fn_80007570 = .text:0x80007570; // type:function size:0x58 fn_800075D0 = .text:0x800075D0; // type:function size:0x8C diff --git a/include/toBeSorted/file_manager.h b/include/toBeSorted/file_manager.h index 1be099b1..282cfc4b 100644 --- a/include/toBeSorted/file_manager.h +++ b/include/toBeSorted/file_manager.h @@ -4,7 +4,6 @@ #include "toBeSorted/save_file.h" #include - enum ITEM_ID {}; enum SAVE_ITEM_ID {}; @@ -16,12 +15,12 @@ public: class SavedSaveFiles { public: - /** 0x00 */ char regionCode[4]; - /** 0x04 */ u8 unk1[0x1C - 0x04]; - /** 0x1C */ u32 m_0x1C; - /** 0x20 */ SaveFile saveFiles[3]; - /** 0xfb60 */ SkipData skipData[3]; - /** 0xfbcc */ u8 unk2[0xfbe0 - 0xfb60]; + /* 0x0000 */ char regionCode[4]; + /* 0x0004 */ u8 unk1[0x1C - 0x04]; + /* 0x001C */ u32 m_0x1C; + /* 0x0020 */ SaveFile saveFiles[3]; + /* 0xfb60 */ SkipData skipData[3]; + /* 0xfbcc */ u8 unk2[0xfbe0 - 0xfbcc]; }; class FileManager { @@ -258,7 +257,9 @@ public: /* 80010440 */ void clearTempFileData(); /* 800104A0 */ void saveAfterCredits(); /* 80011210 */ SaveFile *getCurrentFile(); - inline const SaveFile *getCurrentFile() const { return isFileInactive() ? &mFileB : &mFileA; } + inline const SaveFile *getCurrentFile() const { + return isFileInactive() ? &mFileB : &mFileA; + } /* 80011250 */ u16 *getSkipFlags2(); /* 80011260 */ SaveFile *getFileA(); /* 80011270 */ SaveFile *getFileB(); diff --git a/src/toBeSorted/file_manager.cpp b/src/toBeSorted/file_manager.cpp index 9da73cbb..6ffe1132 100644 --- a/src/toBeSorted/file_manager.cpp +++ b/src/toBeSorted/file_manager.cpp @@ -24,41 +24,43 @@ public: /* 80574FFC */ FileManager *FileManager::sInstance; extern "C" { - /* 80009D80 */ void fn_80009D80() {} // return - /* 80009D90 */ void fn_80009D90() {} // return - /* 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 +/* 80009D80 */ void fn_80009D80() {} // return +/* 80009D90 */ void fn_80009D90() {} // return +/* 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() { // TODO the assembly code looks really wild - u32 numSaves = (u32)(mHeroName - mHeroNames[0]) / 0x12; - for (int i = 0; i < numSaves; i++) { + mHeroNames[0][0] = '\0'; + u32 num_files = (u32)(mHeroName - mHeroNames[0]); + num_files = num_files / sizeof(mHeroName); + for (int i = 1; mHeroNames[i] < mHeroName && i < num_files; i++) { mHeroNames[i][0] = '\0'; } - mHeroName[0] = '\0'; mCurrentArea[0] = '\0'; sInstance = this; // TODO these should probably use the new operators? - mpSavedSaveFiles = (SavedSaveFiles*) mHeap::g_gameHeaps[0]->alloc(sizeof(SavedSaveFiles), 0x20); - mpSkipData = (SkipData*) mHeap::g_gameHeaps[0]->alloc(0x80, 0x20); + mpSavedSaveFiles = (SavedSaveFiles *)mHeap::g_gameHeaps[0]->alloc(sizeof(SavedSaveFiles), 0x20); + mpSkipData = (SkipData *)mHeap::g_gameHeaps[0]->alloc(0x80, 0x20); + fn_8000A2E0(); } /* 80009EE0 */ // mVec3(); -/* 80009EF0 */ FileManager *FileManager::create(EGG::Heap* heap) { - return new(heap, 0x04) FileManager(); +/* 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(){} -/* 8000A260 */ wchar_t* FileManager::getFileHeroname(int fileNum){} -/* 8000A280 */ s64 FileManager::getFileSaveTime(int fileNum){} -/* 8000A2A0 */ s16 FileManager::getFileCurrentHealth(int fileNum){} -/* 8000A2C0 */ s16 FileManager::getFileHealthCapacity(int fileNum){} -/* 8000A2E0 */ void FileManager::fn_8000A2E0(){ +/* 80009F30 */ bool FileManager::loadSaveData(void *out, char *name, bool isSkipData) {} +/* 80009F70 */ void FileManager::saveSaveData(void *unk, bool isSkipData) {} +/* 8000A000 */ void FileManager::refreshSaveFileData() {} +/* 8000A260 */ wchar_t *FileManager::getFileHeroname(int fileNum) {} +/* 8000A280 */ s64 FileManager::getFileSaveTime(int fileNum) {} +/* 8000A2A0 */ s16 FileManager::getFileCurrentHealth(int fileNum) {} +/* 8000A2C0 */ s16 FileManager::getFileHealthCapacity(int fileNum) {} +/* 8000A2E0 */ void FileManager::fn_8000A2E0() { // maybe call this function "reset" mIsFileUnk1[0] = true; initBlankSaveFiles(); @@ -66,38 +68,38 @@ extern "C" { mSelectedFile = 1; } -/* 8000A330 */ -u16* FileManager::getStoryFlagsMut() { +/* 8000A330 */ +u16 *FileManager::getStoryFlagsMut() { return getCurrentFile()->getStoryFlags0(); } -/* 8000A360 */ const u16* FileManager::getStoryFlagsConst() const { +/* 8000A360 */ const u16 *FileManager::getStoryFlagsConst() const { return getCurrentFile()->getStoryFlags1(); } -/* 8000A3B0 */ u16* FileManager::getItemFlagsMut() {} -/* 8000A3E0 */ u16* FileManager::getItemFlagsConst() {} -/* 8000A430 */ u16* FileManager::getDungeonFlagsMut() {} -/* 8000A460 */ u16* FileManager::getDungeonFlagsConst() {} -/* 8000A4B0 */ u16* FileManager::getSceneFlagsMut() {} -/* 8000A4E0 */ u16* FileManager::getSceneFlagsConst() {} -/* 8000A530 */ u16* FileManager::getTBoxFlagsMut() {} -/* 8000A560 */ u16* FileManager::getTBoxFlagsConst() {} -/* 8000A5B0 */ u16* FileManager::getTempFlagsMut() {} -/* 8000A5E0 */ u16* FileManager::getTempFlagsConst() {} -/* 8000A630 */ u16* FileManager::getZoneFlagsMut() {} -/* 8000A660 */ u16* FileManager::getZoneFlagsConst() {} -/* 8000A6B0 */ u16* FileManager::getEnemyDefeatFlagsMut() {} -/* 8000A6E0 */ u16* FileManager::getEnemyDefeatFlagsConst() {} -/* 8000A730 */ void FileManager::setStoryFlags(u16* flags, u32 offset, u16 count) {} -/* 8000A790 */ void FileManager::setItemFlags(u16* flags, u32 offset, u16 count) {} -/* 8000A7F0 */ void FileManager::setDungeonFlags(u16* flags, u32 offset, u16 count) {} -/* 8000A850 */ void FileManager::setSceneFlags(u16* flags, u32 offset, u16 count) {} -/* 8000A8B0 */ void FileManager::setTBoxFlags(u16* flags, u32 offset, u16 count) {} -/* 8000A910 */ void FileManager::setTempFlags(u16* flags, u32 offset, u16 count) {} -/* 8000A970 */ void FileManager::setZoneFlags(u16* flags, u32 offset, u16 count) {} -/* 8000A9D0 */ void FileManager::setEnemyDefeatFlags(u16* flags, u32 offset, u16 count) {} +/* 8000A3B0 */ u16 *FileManager::getItemFlagsMut() {} +/* 8000A3E0 */ u16 *FileManager::getItemFlagsConst() {} +/* 8000A430 */ u16 *FileManager::getDungeonFlagsMut() {} +/* 8000A460 */ u16 *FileManager::getDungeonFlagsConst() {} +/* 8000A4B0 */ u16 *FileManager::getSceneFlagsMut() {} +/* 8000A4E0 */ u16 *FileManager::getSceneFlagsConst() {} +/* 8000A530 */ u16 *FileManager::getTBoxFlagsMut() {} +/* 8000A560 */ u16 *FileManager::getTBoxFlagsConst() {} +/* 8000A5B0 */ u16 *FileManager::getTempFlagsMut() {} +/* 8000A5E0 */ u16 *FileManager::getTempFlagsConst() {} +/* 8000A630 */ u16 *FileManager::getZoneFlagsMut() {} +/* 8000A660 */ u16 *FileManager::getZoneFlagsConst() {} +/* 8000A6B0 */ u16 *FileManager::getEnemyDefeatFlagsMut() {} +/* 8000A6E0 */ u16 *FileManager::getEnemyDefeatFlagsConst() {} +/* 8000A730 */ void FileManager::setStoryFlags(u16 *flags, u32 offset, u16 count) {} +/* 8000A790 */ void FileManager::setItemFlags(u16 *flags, u32 offset, u16 count) {} +/* 8000A7F0 */ void FileManager::setDungeonFlags(u16 *flags, u32 offset, u16 count) {} +/* 8000A850 */ void FileManager::setSceneFlags(u16 *flags, u32 offset, u16 count) {} +/* 8000A8B0 */ void FileManager::setTBoxFlags(u16 *flags, u32 offset, u16 count) {} +/* 8000A910 */ void FileManager::setTempFlags(u16 *flags, u32 offset, u16 count) {} +/* 8000A970 */ void FileManager::setZoneFlags(u16 *flags, u32 offset, u16 count) {} +/* 8000A9D0 */ void FileManager::setEnemyDefeatFlags(u16 *flags, u32 offset, u16 count) {} -/* 8000AA30 */ u16* FileManager::getSkipFlags() {} -/* 8000AA40 */ void FileManager::setSkipFlagsChecked(u16* flags, u32 offset, u16 count) {} +/* 8000AA30 */ u16 *FileManager::getSkipFlags() {} +/* 8000AA40 */ void FileManager::setSkipFlagsChecked(u16 *flags, u32 offset, u16 count) {} inline void strncat(char *dest, const char *src, size_t count) { if (dest != src) { @@ -157,22 +159,22 @@ inline void strncat(char *dest, const char *src, size_t count) { /* 8000AC50 */ void FileManager::setCurrentHealth(s16 health) {} /* 8000AC80 */ s16 FileManager::getCurrentHealth() {} -/* 8000ACD0 */ u16 FileManager::getLoadRoomT1() {} -/* 8000AD20 */ u16 FileManager::getLoadRoomT2() {} +/* 8000ACD0 */ u16 FileManager::getLoadRoomT1() {} +/* 8000AD20 */ u16 FileManager::getLoadRoomT2() {} /* 8000AD70 */ void FileManager::setLoadRoomT3(s16 room) {} -/* 8000ADA0 */ u16 FileManager::getLoadRoomT3() {} +/* 8000ADA0 */ u16 FileManager::getLoadRoomT3() {} -/* 8000ADF0 */ mVec3_c* FileManager::getPosT1() {} -/* 8000AE40 */ void FileManager::setPosT2(mVec3_c* pos) {} -/* 8000AE90 */ mVec3_c* FileManager::getPosT2() {} -/* 8000AEE0 */ void FileManager::setPosT3(mVec3_c* pos) {} -/* 8000AF30 */ mVec3_c* FileManager::getPosT3() {} +/* 8000ADF0 */ mVec3_c *FileManager::getPosT1() {} +/* 8000AE40 */ void FileManager::setPosT2(mVec3_c *pos) {} +/* 8000AE90 */ mVec3_c *FileManager::getPosT2() {} +/* 8000AEE0 */ void FileManager::setPosT3(mVec3_c *pos) {} +/* 8000AF30 */ mVec3_c *FileManager::getPosT3() {} -/* 8000AF80 */ s16 FileManager::getAngleT1() {} +/* 8000AF80 */ s16 FileManager::getAngleT1() {} /* 8000AFD0 */ void FileManager::setAngleT2(s16 angle) {} -/* 8000B000 */ s16 FileManager::getAngleT2() {} +/* 8000B000 */ s16 FileManager::getAngleT2() {} /* 8000B050 */ void FileManager::setAngleT3(s16 angle) {} -/* 8000B080 */ s16 FileManager::getAngleT3() {} +/* 8000B080 */ s16 FileManager::getAngleT3() {} /* 8000B0D0 */ void FileManager::setPouchData(s32 slot, u32 slotData) {} /* 8000B130 */ u32 FileManager::getPouchData(s32 slot) {} @@ -181,38 +183,38 @@ inline void strncat(char *dest, const char *src, size_t count) { /* 8000B250 */ void FileManager::setPouchUpperData(s32 slot, s32 data) {} /* 8000B2C0 */ u16 FileManager::getPouchUpperData(s32 slot) {} -/* 8000B2F0 */ void FileManager::setItemCheckData(u32 idx, u32 itemData){} -/* 8000B360 */ u32 FileManager::getItemCheckData(u32 idx){} -/* 8000B3F0 */ void FileManager::setItemCheckItem(u32 idx, ITEM_ID item){} -/* 8000B480 */ ITEM_ID FileManager::getItemCheckItem(u32 idx){} -/* 8000B4B0 */ void FileManager::setItemCheckUpperData(u32 idx, u32 itemData){} -/* 8000B540 */ u32 FileManager::getItemCheckUpperData(){} +/* 8000B2F0 */ void FileManager::setItemCheckData(u32 idx, u32 itemData) {} +/* 8000B360 */ u32 FileManager::getItemCheckData(u32 idx) {} +/* 8000B3F0 */ void FileManager::setItemCheckItem(u32 idx, ITEM_ID item) {} +/* 8000B480 */ ITEM_ID FileManager::getItemCheckItem(u32 idx) {} +/* 8000B4B0 */ void FileManager::setItemCheckUpperData(u32 idx, u32 itemData) {} +/* 8000B540 */ u32 FileManager::getItemCheckUpperData() {} -/* 8000B570 */ void FileManager::setEquippedItem(u8 bWheelItem){} -/* 8000B5A0 */ u8 FileManager::getEquippedItem(){} -/* 8000B5F0 */ void FileManager::setSelectedPouchSlot(u8 slot){} -/* 8000B620 */ u8 FileManager::getSelectedPouchSlot(){} -/* 8000B670 */ void FileManager::setShieldPouchSlot(u8 slot){} -/* 8000B6A0 */ u8 FileManager::getShieldPouchSlot(){} +/* 8000B570 */ void FileManager::setEquippedItem(u8 bWheelItem) {} +/* 8000B5A0 */ u8 FileManager::getEquippedItem() {} +/* 8000B5F0 */ void FileManager::setSelectedPouchSlot(u8 slot) {} +/* 8000B620 */ u8 FileManager::getSelectedPouchSlot() {} +/* 8000B670 */ void FileManager::setShieldPouchSlot(u8 slot) {} +/* 8000B6A0 */ u8 FileManager::getShieldPouchSlot() {} -/* 8000B6F0 */ void FileManager::setAirPotionTimer(s16 time){} -/* 8000B720 */ s16 FileManager::getAirPotionTimer(){} -/* 8000B770 */ void FileManager::setAirPotionPlusTimer(s16 time){} -/* 8000B7A0 */ s16 FileManager::getAirPotionPlusTimer(){} -/* 8000B7F0 */ void FileManager::setStaminaPotionTimer(s16 time){} -/* 8000B820 */ s16 FileManager::getStaminaPotionTimer(){} -/* 8000B870 */ void FileManager::setStaminaPotionPlusTimer(s16 time){} -/* 8000B8A0 */ s16 FileManager::getStaminaPotionPlusTimer(){} -/* 8000B8F0 */ void FileManager::setGuardianPotionTimer(s16 time){} -/* 8000B920 */ s16 FileManager::getGuardianPotionTimer(){} -/* 8000B970 */ void FileManager::setGuardianPotionPlusTimer(s16 time){} -/* 8000B9A0 */ s16 FileManager::getGuardianPotionPlusTimer(){} +/* 8000B6F0 */ void FileManager::setAirPotionTimer(s16 time) {} +/* 8000B720 */ s16 FileManager::getAirPotionTimer() {} +/* 8000B770 */ void FileManager::setAirPotionPlusTimer(s16 time) {} +/* 8000B7A0 */ s16 FileManager::getAirPotionPlusTimer() {} +/* 8000B7F0 */ void FileManager::setStaminaPotionTimer(s16 time) {} +/* 8000B820 */ s16 FileManager::getStaminaPotionTimer() {} +/* 8000B870 */ void FileManager::setStaminaPotionPlusTimer(s16 time) {} +/* 8000B8A0 */ s16 FileManager::getStaminaPotionPlusTimer() {} +/* 8000B8F0 */ void FileManager::setGuardianPotionTimer(s16 time) {} +/* 8000B920 */ s16 FileManager::getGuardianPotionTimer() {} +/* 8000B970 */ void FileManager::setGuardianPotionPlusTimer(s16 time) {} +/* 8000B9A0 */ s16 FileManager::getGuardianPotionPlusTimer() {} /* 8000B9F0 */ void FileManager::setDowsingSlotIdx(u8 idx) {} /* 8000BA20 */ u8 FileManager::getDowsingSlotIdx() {} -/* 8000BA70 */ void FileManager::setBeaconPos(u32 beaconArea, u32 beaconNum, mVec3_c* pos) {} -/* 8000BB80 */ mVec3_c* FileManager::getBeaconPos(u32 beaconArea, u32 beaconNum) {} +/* 8000BA70 */ void FileManager::setBeaconPos(u32 beaconArea, u32 beaconNum, mVec3_c *pos) {} +/* 8000BB80 */ mVec3_c *FileManager::getBeaconPos(u32 beaconArea, u32 beaconNum) {} /* 8000BC70 */ void FileManager::setEnemyKillCount(u32 enemy, u16 killCount) {} /* 8000BCE0 */ u16 FileManager::getEnemyKillCount(u32 enemy) {} /* 8000BD60 */ void FileManager::setHitCountFromEnemy(u32 enemy, u16 hitCount) {} @@ -221,9 +223,9 @@ inline void strncat(char *dest, const char *src, size_t count) { /* 8000BE50 */ void FileManager::setLoadRoomT1_FileB(s16 roomId) {} /* 8000BE80 */ s16 FileManager::getLoadRoomT1_FileB() {} /* 8000BE90 */ void FileManager::setEntranceT1_FileB(u8 entrance) {} -/* 8000BEC0 */ u8 FileManager::getEntranceT1_FileB() {} -/* 8000BED0 */ void FileManager::setAreaT1_FileB(const char* name) {} -/* 8000BF80 */ char* FileManager::getAreaT1_FileB() {} +/* 8000BEC0 */ u8 FileManager::getEntranceT1_FileB() {} +/* 8000BED0 */ void FileManager::setAreaT1_FileB(const char *name) {} +/* 8000BF80 */ char *FileManager::getAreaT1_FileB() {} /* 8000C080 */ void FileManager::setNightT1_FileB(bool night) {} /* 8000C0B0 */ bool FileManager::getNightT1_FileB() {} /* 8000C0C0 */ void FileManager::setEntranceT1LoadFlag_FileB(u8 flag) {} @@ -231,13 +233,13 @@ inline void strncat(char *dest, const char *src, size_t count) { /* 8000C120 */ void FileManager::getForcedLayerT1_FileB() {} /* 8000C130 */ void FileManager::setCurrentHealth_FileB(s16 health) {} -/* 8000C160 */ void FileManager::setHeroname(const wchar_t* name) {} -/* 8000C230 */ wchar_t* FileManager::getHeroname() {} +/* 8000C160 */ void FileManager::setHeroname(const wchar_t *name) {} +/* 8000C230 */ wchar_t *FileManager::getHeroname() {} -/* 8000C360 */ char* FileManager::getAreaT1() {} -/* 8000C470 */ char* FileManager::getAreaT2() {} -/* 8000C580 */ void FileManager::setAreaT3(const char* name) {} -/* 8000C630 */ char* FileManager::getAreaT3() {} +/* 8000C360 */ char *FileManager::getAreaT1() {} +/* 8000C470 */ char *FileManager::getAreaT2() {} +/* 8000C580 */ void FileManager::setAreaT3(const char *name) {} +/* 8000C630 */ char *FileManager::getAreaT3() {} /* 8000C740 */ u8 FileManager::getForcedLayerT1() {} /* 8000C790 */ u8 FileManager::getForcedLayerT2() {} @@ -388,7 +390,7 @@ inline void strncat(char *dest, const char *src, size_t count) { mPlayTime[2] = 0; mCurrentHealth[2] = 0; mCurrentHealthCapacity[2] = 0; - + getRegionVersion(saved->regionCode); saved->m_0x1C = 0x1d; @@ -410,7 +412,7 @@ inline void strncat(char *dest, const char *src, size_t count) { mIsFileUnk1[2] = 0; mIsFileInvalid[0] = 0; mIsFileInvalid[1] = 0; - m_0xA84C = 0; + m_0xA84C = 0; mIsFileInvalid[2] = 0; mIsFileDataDirty[0] = 0; mIsFileDataDirty[1] = 0; @@ -442,14 +444,14 @@ extern "C" void fn_800C01F0(); // todo flag managers } /* 800104A0 */ void FileManager::saveAfterCredits() {} -/* 80011210 */ SaveFile* FileManager::getCurrentFile() { +/* 80011210 */ SaveFile *FileManager::getCurrentFile() { return isFileInactive() ? &mFileB : &mFileA; } -/* 80011250 */ u16* FileManager::getSkipFlags2() {} -/* 80011260 */ SaveFile* FileManager::getFileA() { +/* 80011250 */ u16 *FileManager::getSkipFlags2() {} +/* 80011260 */ SaveFile *FileManager::getFileA() { return &mFileA; } -/* 80011270 */ SaveFile* FileManager::getFileB() { +/* 80011270 */ SaveFile *FileManager::getFileB() { return &mFileB; } /* 80011280 */ u32 FileManager::calcFileCRC(const void *data, u32 length) {} @@ -465,14 +467,15 @@ extern "C" void fn_800C01F0(); // todo flag managers /* 80011440 */ bool FileManager::checkFileCRC(u8 fileNum) {} /* 80011490 */ bool FileManager::isFileInactive() const { - fBase_c* actor = fManager_c::searchBaseByGroupType(1, nullptr); + fBase_c *actor = fManager_c::searchBaseByGroupType(1, nullptr); if (actor) { - if (actor->profile_name == fProfile::TITLE && !mAntiCommitFlag) + if (actor->profile_name == fProfile::TITLE && !mAntiCommitFlag) { return true; + } return false; } return false; } /* 80011500 */ void FileManager::setPlayerInfoFileA() {} -/* 800115E0 */ void FileManager::setT3Info(mVec3_c* pos, mAng3_c* rot) {} -/* 800116C0 */ void FileManager::getRegionVersion(char* out) {} +/* 800115E0 */ void FileManager::setT3Info(mVec3_c *pos, mAng3_c *rot) {} +/* 800116C0 */ void FileManager::getRegionVersion(char *out) {} From 792b7e8058d97ad52acf780b4dfa2c838e605271 Mon Sep 17 00:00:00 2001 From: robojumper Date: Thu, 2 May 2024 23:55:01 +0200 Subject: [PATCH 05/23] FileManager::initFile closer --- src/toBeSorted/file_manager.cpp | 46 +++++++++++++++------------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/toBeSorted/file_manager.cpp b/src/toBeSorted/file_manager.cpp index 6ffe1132..75959c7d 100644 --- a/src/toBeSorted/file_manager.cpp +++ b/src/toBeSorted/file_manager.cpp @@ -101,15 +101,26 @@ u16 *FileManager::getStoryFlagsMut() { /* 8000AA30 */ u16 *FileManager::getSkipFlags() {} /* 8000AA40 */ void FileManager::setSkipFlagsChecked(u16 *flags, u32 offset, u16 count) {} -inline void strncat(char *dest, const char *src, size_t count) { - if (dest != src) { +// This does strncat things - append src to dest +inline void strncat(char *dest, const char *src, size_t max_len) { + if (src != nullptr) { + size_t len = strlen(dest); + size_t count = strlen(src); + count = len + count + 1 >= max_len ? max_len - len - 1 : count; + strncpy(dest + len, src, count); + // one instshuffle here - this should be (len + count), + // but then regalloc blows up and uses one more register in initFile + dest[count + len] = '\0'; + } +} + +// A function like this is inlined into in a bunch of area-related code +// It doesn't make a whole lot of sense to use strncat on a string just +// clipped to zero length... +inline void strnsth(char *dest, const char *src, size_t max_len) { + if (src != dest) { dest[0] = '\0'; - if (src != nullptr) { - size_t len = strlen(dest); - size_t count = strlen(src); - count = len + count + 1 >= 0x20 ? 0x1f - len : count; - strncpy(dest + len, src, count)[count] = '\0'; - } + strncat(dest, src, max_len); } } @@ -132,22 +143,7 @@ inline void strncat(char *dest, const char *src, size_t count) { file->lastUsedPouchItemSlot = 0x8; buf[0] = '\0'; - strncat(buf, "F405", 0x20); - /* - buf[0] = '\0'; - // TODO looks like an inlined strncat, - // hence the needless comparison to a .data string - // Not sure how we can do this? - // strncat(buf, etc, 0x20); - if (etc != buf) { - buf[0] = '\0'; - if (etc != nullptr) { - size_t len = strlen(buf); - size_t count = strlen(etc); - count = len + count + 1 >= 0x20 ? 0x1f - len : count; - strncpy(buf + len, etc, count)[count] = '\0'; - } - }*/ + strnsth(buf, "F405", 0x20); file->setAreaT1(buf); file->room_id_t1 = 0; file->forced_layer_t1 = 0; @@ -318,7 +314,7 @@ inline void strncat(char *dest, const char *src, size_t count) { SkipData *data; bool dirty = false; u8 i; - for (data = &mpSkipData[0], i = 0; i < 3; i++, data++) { + for (data = &mpSkipData[0], i = 0; (s32)i < 3; i++, data++) { u32 crc = calcFileCRC(data->data, sizeof(data->data)); if (crc == data->crc) { mIsFileSkipDataDirty[i] = 0; From a9aac2a5ad3badfeaee6ddaaa5c1b9ccc7e4942a Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 3 May 2024 00:23:57 +0200 Subject: [PATCH 06/23] Small cleanups --- config/SOUE01/splits.txt | 1 + src/toBeSorted/file_manager.cpp | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index cf8cb5fa..4937e0e3 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -20,6 +20,7 @@ toBeSorted/file_manager.cpp: .text start:0x80009D30 end:0x80011730 .ctors start:0x804DB648 end:0x804DB64C .data start:0x80500400 end:0x80500410 + .sdata start:0x80571848 end:0x80571850 .sbss start:0x80574FF8 end:0x80575000 .bss start:0x80580070 end:0x80580080 diff --git a/src/toBeSorted/file_manager.cpp b/src/toBeSorted/file_manager.cpp index 75959c7d..84bd84b4 100644 --- a/src/toBeSorted/file_manager.cpp +++ b/src/toBeSorted/file_manager.cpp @@ -102,7 +102,7 @@ u16 *FileManager::getStoryFlagsMut() { /* 8000AA40 */ void FileManager::setSkipFlagsChecked(u16 *flags, u32 offset, u16 count) {} // This does strncat things - append src to dest -inline void strncat(char *dest, const char *src, size_t max_len) { +inline void fake_strncat(char *dest, const char *src, size_t max_len) { if (src != nullptr) { size_t len = strlen(dest); size_t count = strlen(src); @@ -120,16 +120,14 @@ inline void strncat(char *dest, const char *src, size_t max_len) { inline void strnsth(char *dest, const char *src, size_t max_len) { if (src != dest) { dest[0] = '\0'; - strncat(dest, src, max_len); + fake_strncat(dest, src, max_len); } } /* 8000AAA0 */ void FileManager::initFile(int fileNum) { - SaveFile *file; - char buf[0x20]; mIsFileInvalid[1] = 1; - file = getFileA(); + SaveFile *file = getFileA(); if (fileNum != 0) { file = &mFileB; } @@ -142,6 +140,7 @@ inline void strnsth(char *dest, const char *src, size_t max_len) { file->selectedDowsingSlot = 0x8; file->lastUsedPouchItemSlot = 0x8; + char buf[0x20]; buf[0] = '\0'; strnsth(buf, "F405", 0x20); file->setAreaT1(buf); @@ -314,7 +313,7 @@ inline void strnsth(char *dest, const char *src, size_t max_len) { SkipData *data; bool dirty = false; u8 i; - for (data = &mpSkipData[0], i = 0; (s32)i < 3; i++, data++) { + for (data = mpSkipData, i = 0; (s32)i < 3; i++, data++) { u32 crc = calcFileCRC(data->data, sizeof(data->data)); if (crc == data->crc) { mIsFileSkipDataDirty[i] = 0; @@ -390,7 +389,7 @@ inline void strnsth(char *dest, const char *src, size_t max_len) { getRegionVersion(saved->regionCode); saved->m_0x1C = 0x1d; - file = &saved->saveFiles[0]; + file = saved->saveFiles; for (int num = 0; num < 3; num++, file++) { file->new_file = 1; u32 crc = calcFileCRC(file, sizeof(SaveFile) - sizeof(u32)); @@ -419,7 +418,7 @@ inline void strnsth(char *dest, const char *src, size_t max_len) { memset(mpSkipData, 0, 0x80); SkipData *data; int i; - for (i = 0, data = &mpSkipData[0]; i < 3; i++, data++) { + for (i = 0, data = mpSkipData; i < 3; i++, data++) { u32 crc = calcFileCRC(data->data, sizeof(data->data)); data->crc = crc; } @@ -455,7 +454,16 @@ extern "C" void fn_800C01F0(); // todo flag managers updateEmptyFileFlags(); refreshSaveFileData(); } -/* 800112D0 */ void FileManager::updateEmptyFileFlags() {} +/* 800112D0 */ void FileManager::updateEmptyFileFlags() { + SaveFile *saves = mpSavedSaveFiles->saveFiles; + for (int i = 0; i < 3; i++) { + if (saves[i].new_file == 1) { + mIsFileEmpty[i] = 1; + } else { + mIsFileEmpty[i] = 0; + } + } +} /* 80011370 */ bool FileManager::isFileEmpty(int fileNum) {} /* 80011390 */ bool FileManager::isFileDirty(int fileNum) {} /* 800113B0 */ u8 FileManager::get_0xA84C() {} From 37925e4376af619f1e7b66891dd8380b033d71dd Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 28 Apr 2024 02:38:46 +0200 Subject: [PATCH 07/23] Almost matching DungeonflagManager --- config/SOUE01/splits.txt | 5 ++ config/SOUE01/symbols.txt | 24 +++---- configure.py | 1 + src/toBeSorted/dungeonflag_manager.cpp | 98 ++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 12 deletions(-) create mode 100644 src/toBeSorted/dungeonflag_manager.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 1f79f5f6..66a7b4af 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -122,6 +122,11 @@ toBeSorted/unk_flag_stuff.cpp: toBeSorted/bitwise_flag_helper.cpp: .text start:0x800BF200 end:0x800BF264 +toBeSorted/dungeonflag_manager.cpp: + .text start:0x800BF8D0 end:0x800BFBA0 + .sbss start:0x80575404 end:0x80575408 + .bss start:0x805A9C58 end:0x805A9C68 + toBeSorted/skipflag_manager.cpp: .text start:0x800BFBA0 end:0x800BFE00 .sbss start:0x80575408 end:0x8057540C diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index dfd2e61c..4fe4a163 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -2228,7 +2228,7 @@ fn_80054CF0 = .text:0x80054CF0; // type:function size:0x88 fn_80054D80 = .text:0x80054D80; // type:function size:0x98 fn_80054E20 = .text:0x80054E20; // type:function size:0x88 fn_80054EB0 = .text:0x80054EB0; // type:function size:0x4 -fn_80054EC0 = .text:0x80054EC0; // type:function size:0xC +__nw__FUl = .text:0x80054EC0; // type:function size:0xC fn_80054ED0 = .text:0x80054ED0; // type:function size:0xC __dl__FPv = .text:0x80054EE0; // type:function size:0x8 fn_80054EF0 = .text:0x80054EF0; // type:function size:0x8 @@ -4171,15 +4171,15 @@ fn_800BF820 = .text:0x800BF820; // type:function size:0x3C fn_800BF860 = .text:0x800BF860; // type:function size:0x10 fn_800BF870 = .text:0x800BF870; // type:function size:0x4 fn_800BF880 = .text:0x800BF880; // type:function size:0x4C -fn_800BF8D0 = .text:0x800BF8D0; // type:function size:0x54 -fn_800BF930 = .text:0x800BF930; // type:function size:0xC -fn_800BF940 = .text:0x800BF940; // type:function size:0x3C -fn_800BF980 = .text:0x800BF980; // type:function size:0x54 -fn_800BF9E0 = .text:0x800BF9E0; // type:function size:0xC -fn_800BF9F0 = .text:0x800BF9F0; // type:function size:0x6C -fn_800BFA60 = .text:0x800BFA60; // type:function size:0x60 -fn_800BFAC0 = .text:0x800BFAC0; // type:function size:0x50 -fn_800BFB10 = .text:0x800BFB10; // type:function size:0x8C +copyFromSave__18DungeonflagManagerFUs = .text:0x800BF8D0; // type:function size:0x54 +setCommitFlag__18DungeonflagManagerFUs = .text:0x800BF930; // type:function size:0xC +__ct__18DungeonflagManagerFv = .text:0x800BF940; // type:function size:0x3C +setupFlagStuff__18DungeonflagManagerFv = .text:0x800BF980; // type:function size:0x54 +copyFromSave__18DungeonflagManagerFs = .text:0x800BF9E0; // type:function size:0xC +setToValue__18DungeonflagManagerFUsUi = .text:0x800BF9F0; // type:function size:0x6C +setFlag__18DungeonflagManagerFUs = .text:0x800BFA60; // type:function size:0x60 +getDungeonFlag__18DungeonflagManagerFUs = .text:0x800BFAC0; // type:function size:0x50 +doCommit__18DungeonflagManagerFv = .text:0x800BFB10; // type:function size:0x8C copyFromSave__15SkipflagManagerFv = .text:0x800BFBA0; // type:function size:0x44 setCommitFlag__15SkipflagManagerFUs = .text:0x800BFBF0; // type:function size:0xC __ct__15SkipflagManagerFv = .text:0x800BFC00; // type:function size:0x2C @@ -39848,7 +39848,7 @@ sTBoxFlags__15TBoxFlagManager = .sbss:0x805753F4; // type:object size:0x4 sInstance__18EnemyDefeatManager = .sbss:0x805753F8; // type:object size:0x4 data:4byte lbl_805753FC = .sbss:0x805753FC; // type:object size:0x4 data:4byte lbl_80575400 = .sbss:0x80575400; // type:object size:0x4 data:4byte -lbl_80575404 = .sbss:0x80575404; // type:object size:0x4 data:4byte +sInstance__18DungeonflagManager = .sbss:0x80575404; // type:object size:0x4 data:4byte sInstance__15SkipflagManager = .sbss:0x80575408; // type:object size:0x4 data:4byte lbl_80575410 = .sbss:0x80575410; // type:object size:0x8 data:4byte lbl_80575418 = .sbss:0x80575418; // type:object size:0x8 @@ -48236,7 +48236,7 @@ lbl_805A78E0 = .bss:0x805A78E0; // type:object size:0x1F8 sEnemyDefeatFlags__18EnemyDefeatManager = .bss:0x805A7AD8; // type:object size:0x2000 lbl_805A9AD8 = .bss:0x805A9AD8; // type:object size:0x100 lbl_805A9BD8 = .bss:0x805A9BD8; // type:object size:0x80 -lbl_805A9C58 = .bss:0x805A9C58; // type:object size:0x10 +sDungeonFlags__18DungeonflagManager = .bss:0x805A9C58; // type:object size:0x10 sSkipFlags__15SkipflagManager = .bss:0x805A9C68; // type:object size:0x20 lbl_805A9C88 = .bss:0x805A9C88; // type:object size:0x10 data:4byte lbl_805A9C98 = .bss:0x805A9C98; // type:object size:0x208 diff --git a/configure.py b/configure.py index 87235f4a..0b18234e 100644 --- a/configure.py +++ b/configure.py @@ -274,6 +274,7 @@ config.libs = [ Object(Matching, "toBeSorted/sceneflag_manager.cpp"), Object(NonMatching, "toBeSorted/flag_space.cpp"), Object(NonMatching, "toBeSorted/misc_flag_managers.cpp"), + Object(NonMatching, "toBeSorted/dungeonflag_manager.cpp"), Object(Matching, "toBeSorted/skipflag_manager.cpp"), Object(Matching, "c/c_list.cpp"), Object(Matching, "c/c_tree.cpp"), diff --git a/src/toBeSorted/dungeonflag_manager.cpp b/src/toBeSorted/dungeonflag_manager.cpp new file mode 100644 index 00000000..527a54c5 --- /dev/null +++ b/src/toBeSorted/dungeonflag_manager.cpp @@ -0,0 +1,98 @@ +#include "toBeSorted/bitwise_flag_helper.h" +#include "toBeSorted/file_manager.h" +#include "toBeSorted/flag_space.h" +#include "toBeSorted/unk_flag_stuff.h" +#include + +// TODO move +extern "C" UnkFlagDefinition lbl_80511AF0[]; + +class DungeonflagManager { +public: + bool mShouldCommit; + u16 mFlagIndex; + UnkFlagStuff *mFlagStuff; + FlagSpace mFlagSpace; + + static u16 sDungeonFlags[8]; + static DungeonflagManager *sInstance; + + void copyFromSave(s16 flag); + void copyFromSave(u16 flagIndex); + void setCommitFlag(u16 flag); + DungeonflagManager(); + void setupFlagStuff(); + void setToValue(u16 flag, u32 value); + void setFlag(u16 flag); + u32 getDungeonFlag(u16 flag); + bool doCommit(); +}; + +/** 80575404 */ +DungeonflagManager *DungeonflagManager::sInstance = nullptr; +/** 805a9c58 */ +u16 DungeonflagManager::sDungeonFlags[8] = {}; + +/** 800bf9e0 */ +void DungeonflagManager::copyFromSave(u16 flagIndex) { + u16 *ptr = FileManager::sInstance->getDungeonFlagsConst(); + mFlagSpace.copyFromSaveFile(ptr + (flagIndex & 0x1fff) * 8, 0, 0x8); +} + +/** 800bf930 */ +void DungeonflagManager::setCommitFlag(u16 flag) { + mShouldCommit = true; +} + +/** 0x800bf940 */ +DungeonflagManager::DungeonflagManager() + : mShouldCommit(false), mFlagIndex(-1), mFlagStuff(nullptr), + mFlagSpace(sDungeonFlags, ARRAY_LENGTH(sDungeonFlags)) {} + +/** 800bf980 */ +void DungeonflagManager::setupFlagStuff() { + mFlagStuff = new UnkFlagStuff(0x11, lbl_80511AF0); + mShouldCommit = false; +} + +/** 800bf9e0 */ +void DungeonflagManager::copyFromSave(s16 flag) { + mFlagIndex = flag; + copyFromSave((u16)flag); +} + +/** 800bf9f0 */ +void DungeonflagManager::setToValue(u16 flag, u32 value) { + u16 *data = mFlagSpace.getFlagPtrChecked(); + mFlagStuff->setCounterOrFlag(flag, data, 8, value); + setCommitFlag(flag); +} + +/** 800bfa60 */ +void DungeonflagManager::setFlag(u16 flag) { + u16 *data = mFlagSpace.getFlagPtrChecked(); + mFlagStuff->setCounterOrFlag(flag, data, 8, 1); + setCommitFlag(flag); +} + +/** 800fbac0 */ +u32 DungeonflagManager::getDungeonFlag(u16 flag) { + u16 *data = mFlagSpace.getFlagPtrUnchecked(); + return mFlagStuff->getCounterOrFlag(flag, data, 8); +} + +/** 800fbb10 */ +bool DungeonflagManager::doCommit() { + FileManager *instance; + u16 idx = mFlagIndex; + if (idx == 0xFFFF) { + return false; + } else if (mShouldCommit) { + instance = FileManager::sInstance; + u16 *ptr = mFlagSpace.getFlagPtrUnchecked(); + instance->setDungeonFlags(ptr, (idx & 0x1fff) * 8, 0x08); + mShouldCommit = false; + return true; + } + return false; +} From b9320f5372d8e1e5425be39c7d7ec0243d4c34c6 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 28 Apr 2024 11:13:26 +0200 Subject: [PATCH 08/23] Correct address comment --- src/toBeSorted/dungeonflag_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/toBeSorted/dungeonflag_manager.cpp b/src/toBeSorted/dungeonflag_manager.cpp index 527a54c5..4c463a31 100644 --- a/src/toBeSorted/dungeonflag_manager.cpp +++ b/src/toBeSorted/dungeonflag_manager.cpp @@ -33,7 +33,7 @@ DungeonflagManager *DungeonflagManager::sInstance = nullptr; /** 805a9c58 */ u16 DungeonflagManager::sDungeonFlags[8] = {}; -/** 800bf9e0 */ +/** 800bf8d0 */ void DungeonflagManager::copyFromSave(u16 flagIndex) { u16 *ptr = FileManager::sInstance->getDungeonFlagsConst(); mFlagSpace.copyFromSaveFile(ptr + (flagIndex & 0x1fff) * 8, 0, 0x8); From 4353833983e4d82e607746c6f9ccfc289c5eaf4a Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 28 Apr 2024 11:29:13 +0200 Subject: [PATCH 09/23] inline shenanigans --- config/SOUE01/splits.txt | 2 +- src/toBeSorted/dungeonflag_manager.cpp | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 66a7b4af..79f8f510 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -123,7 +123,7 @@ toBeSorted/bitwise_flag_helper.cpp: .text start:0x800BF200 end:0x800BF264 toBeSorted/dungeonflag_manager.cpp: - .text start:0x800BF8D0 end:0x800BFBA0 + .text start:0x800BF8D0 end:0x800BFB9C .sbss start:0x80575404 end:0x80575408 .bss start:0x805A9C58 end:0x805A9C68 diff --git a/src/toBeSorted/dungeonflag_manager.cpp b/src/toBeSorted/dungeonflag_manager.cpp index 4c463a31..cf4410f5 100644 --- a/src/toBeSorted/dungeonflag_manager.cpp +++ b/src/toBeSorted/dungeonflag_manager.cpp @@ -7,10 +7,16 @@ // TODO move extern "C" UnkFlagDefinition lbl_80511AF0[]; +// TODO what's preventing this from actually matching +// is that we pretend this TU contains the instance, +// which breaks .sbss section alignment. +// It's much more likely that a separate TU contains +// all instance pointers + class DungeonflagManager { public: bool mShouldCommit; - u16 mFlagIndex; + u16 mStageIndex; UnkFlagStuff *mFlagStuff; FlagSpace mFlagSpace; @@ -26,6 +32,12 @@ public: void setFlag(u16 flag); u32 getDungeonFlag(u16 flag); bool doCommit(); + + /** inline shenanigans to get copyFromSave to match */ + static inline u16 *saveFilePtr(u16 flagIndex) { + u32 offset = (flagIndex & 0x1fff) * 8; + return FileManager::sInstance->getDungeonFlagsConst() + offset; + } }; /** 80575404 */ @@ -35,8 +47,7 @@ u16 DungeonflagManager::sDungeonFlags[8] = {}; /** 800bf8d0 */ void DungeonflagManager::copyFromSave(u16 flagIndex) { - u16 *ptr = FileManager::sInstance->getDungeonFlagsConst(); - mFlagSpace.copyFromSaveFile(ptr + (flagIndex & 0x1fff) * 8, 0, 0x8); + mFlagSpace.copyFromSaveFile(saveFilePtr(flagIndex), 0, 0x8); } /** 800bf930 */ @@ -46,7 +57,7 @@ void DungeonflagManager::setCommitFlag(u16 flag) { /** 0x800bf940 */ DungeonflagManager::DungeonflagManager() - : mShouldCommit(false), mFlagIndex(-1), mFlagStuff(nullptr), + : mShouldCommit(false), mStageIndex(-1), mFlagStuff(nullptr), mFlagSpace(sDungeonFlags, ARRAY_LENGTH(sDungeonFlags)) {} /** 800bf980 */ @@ -57,7 +68,7 @@ void DungeonflagManager::setupFlagStuff() { /** 800bf9e0 */ void DungeonflagManager::copyFromSave(s16 flag) { - mFlagIndex = flag; + mStageIndex = flag; copyFromSave((u16)flag); } @@ -84,7 +95,7 @@ u32 DungeonflagManager::getDungeonFlag(u16 flag) { /** 800fbb10 */ bool DungeonflagManager::doCommit() { FileManager *instance; - u16 idx = mFlagIndex; + u16 idx = mStageIndex; if (idx == 0xFFFF) { return false; } else if (mShouldCommit) { From b8b65fdf33db2ad598e868a03318fd53621787ce Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 3 May 2024 09:58:23 +0200 Subject: [PATCH 10/23] Remove instance from dungeon flag mgr TU --- config/SOUE01/splits.txt | 1 - config/SOUE01/symbols.txt | 2 +- configure.py | 2 +- src/toBeSorted/dungeonflag_manager.cpp | 5 +++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 79f8f510..afe56b13 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -124,7 +124,6 @@ toBeSorted/bitwise_flag_helper.cpp: toBeSorted/dungeonflag_manager.cpp: .text start:0x800BF8D0 end:0x800BFB9C - .sbss start:0x80575404 end:0x80575408 .bss start:0x805A9C58 end:0x805A9C68 toBeSorted/skipflag_manager.cpp: diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 4fe4a163..1e503497 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -39848,7 +39848,7 @@ sTBoxFlags__15TBoxFlagManager = .sbss:0x805753F4; // type:object size:0x4 sInstance__18EnemyDefeatManager = .sbss:0x805753F8; // type:object size:0x4 data:4byte lbl_805753FC = .sbss:0x805753FC; // type:object size:0x4 data:4byte lbl_80575400 = .sbss:0x80575400; // type:object size:0x4 data:4byte -sInstance__18DungeonflagManager = .sbss:0x80575404; // type:object size:0x4 data:4byte +lbl_80575404 = .sbss:0x80575404; // type:object size:0x4 data:4byte sInstance__15SkipflagManager = .sbss:0x80575408; // type:object size:0x4 data:4byte lbl_80575410 = .sbss:0x80575410; // type:object size:0x8 data:4byte lbl_80575418 = .sbss:0x80575418; // type:object size:0x8 diff --git a/configure.py b/configure.py index 0b18234e..103ebb33 100644 --- a/configure.py +++ b/configure.py @@ -274,7 +274,7 @@ config.libs = [ Object(Matching, "toBeSorted/sceneflag_manager.cpp"), Object(NonMatching, "toBeSorted/flag_space.cpp"), Object(NonMatching, "toBeSorted/misc_flag_managers.cpp"), - Object(NonMatching, "toBeSorted/dungeonflag_manager.cpp"), + Object(Matching, "toBeSorted/dungeonflag_manager.cpp"), Object(Matching, "toBeSorted/skipflag_manager.cpp"), Object(Matching, "c/c_list.cpp"), Object(Matching, "c/c_tree.cpp"), diff --git a/src/toBeSorted/dungeonflag_manager.cpp b/src/toBeSorted/dungeonflag_manager.cpp index cf4410f5..7c4d083a 100644 --- a/src/toBeSorted/dungeonflag_manager.cpp +++ b/src/toBeSorted/dungeonflag_manager.cpp @@ -21,7 +21,7 @@ public: FlagSpace mFlagSpace; static u16 sDungeonFlags[8]; - static DungeonflagManager *sInstance; + // static DungeonflagManager *sInstance; void copyFromSave(s16 flag); void copyFromSave(u16 flagIndex); @@ -41,7 +41,8 @@ public: }; /** 80575404 */ -DungeonflagManager *DungeonflagManager::sInstance = nullptr; +// DungeonflagManager *DungeonflagManager::sInstance = nullptr; + /** 805a9c58 */ u16 DungeonflagManager::sDungeonFlags[8] = {}; From 85bcf13ade6429c13d50d29b1d3fd6c0aa77f87b Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 3 May 2024 09:58:42 +0200 Subject: [PATCH 11/23] Remove nonmatch comment --- src/toBeSorted/dungeonflag_manager.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/toBeSorted/dungeonflag_manager.cpp b/src/toBeSorted/dungeonflag_manager.cpp index 7c4d083a..fcdd80a5 100644 --- a/src/toBeSorted/dungeonflag_manager.cpp +++ b/src/toBeSorted/dungeonflag_manager.cpp @@ -7,12 +7,6 @@ // TODO move extern "C" UnkFlagDefinition lbl_80511AF0[]; -// TODO what's preventing this from actually matching -// is that we pretend this TU contains the instance, -// which breaks .sbss section alignment. -// It's much more likely that a separate TU contains -// all instance pointers - class DungeonflagManager { public: bool mShouldCommit; From cf42625664a8bed75f0ab65307a355ad07f37e32 Mon Sep 17 00:00:00 2001 From: robojumper Date: Thu, 2 May 2024 13:48:08 +0200 Subject: [PATCH 12/23] Match the single-counter TUs --- config/SOUE01/splits.txt | 43 ++++++++++ config/SOUE01/symbols.txt | 84 +++++++++---------- configure.py | 7 ++ include/toBeSorted/counters/counter.h | 43 ++++++++++ src/toBeSorted/counters/arrow_counter.cpp | 15 ++++ src/toBeSorted/counters/bomb_counter.cpp | 15 ++++ .../counters/extra_wallet_counter.cpp | 16 ++++ src/toBeSorted/counters/key_piece_counter.cpp | 15 ++++ src/toBeSorted/counters/rupee_counter.cpp | 52 ++++++++++++ .../counters/slingshot_seed_counter.cpp | 15 ++++ src/toBeSorted/counters/tear_counter.cpp | 15 ++++ 11 files changed, 278 insertions(+), 42 deletions(-) create mode 100644 include/toBeSorted/counters/counter.h create mode 100644 src/toBeSorted/counters/arrow_counter.cpp create mode 100644 src/toBeSorted/counters/bomb_counter.cpp create mode 100644 src/toBeSorted/counters/extra_wallet_counter.cpp create mode 100644 src/toBeSorted/counters/key_piece_counter.cpp create mode 100644 src/toBeSorted/counters/rupee_counter.cpp create mode 100644 src/toBeSorted/counters/slingshot_seed_counter.cpp create mode 100644 src/toBeSorted/counters/tear_counter.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index f84fec00..ebd3baeb 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -127,6 +127,49 @@ toBeSorted/skipflag_manager.cpp: .sbss start:0x80575408 end:0x8057540C .bss start:0x805A9C68 end:0x805A9C88 +toBeSorted/counters/rupee_counter.cpp: + .text start:0x8016DE10 end:0x8016DF98 + .ctors start:0x804DB7BC end:0x804DB7C0 + .rodata start:0x804E91B0 end:0x804E91D0 + .data start:0x80527FF0 end:0x80528010 + .sbss start:0x80575610 end:0x80575618 + +toBeSorted/counters/arrow_counter.cpp: + .text start:0x8016DFA0 end:0x8016E018 + .ctors start:0x804DB7C0 end:0x804DB7C4 + .data start:0x80528010 end:0x80528030 + .sbss start:0x80575618 end:0x80575620 + +toBeSorted/counters/bomb_counter.cpp: + .text start:0x8016E020 end:0x8016E098 + .ctors start:0x804DB7C4 end:0x804DB7C8 + .data start:0x80528030 end:0x80528050 + .sbss start:0x80575620 end:0x80575628 + +toBeSorted/counters/tear_counter.cpp: + .text start:0x8016E0A0 end:0x8016E118 + .ctors start:0x804DB7C8 end:0x804DB7CC + .data start:0x80528050 end:0x80528070 + .sbss start:0x80575628 end:0x80575630 + +toBeSorted/counters/slingshot_seed_counter.cpp: + .text start:0x8016E120 end:0x8016E198 + .ctors start:0x804DB7CC end:0x804DB7D0 + .data start:0x80528070 end:0x80528090 + .sbss start:0x80575630 end:0x80575638 + +toBeSorted/counters/key_piece_counter.cpp: + .text start:0x8016E1A0 end:0x8016E218 + .ctors start:0x804DB7D0 end:0x804DB7D4 + .data start:0x80528090 end:0x805280B0 + .sbss start:0x80575638 end:0x80575640 + +toBeSorted/counters/extra_wallet_counter.cpp: + .text start:0x8016E220 end:0x8016E298 + .ctors start:0x804DB7D4 end:0x804DB7D8 + .data start:0x805280B0 end:0x805280D0 + .sbss start:0x80575640 end:0x80575648 + c/c_list.cpp: .text start:0x802E08C0 end:0x802E0A10 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 195dcdc3..73de0c19 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -9354,10 +9354,10 @@ fn_8016CB40 = .text:0x8016CB40; // type:function size:0x1C fn_8016CB60 = .text:0x8016CB60; // type:function size:0x78 fn_8016CBE0 = .text:0x8016CBE0; // type:function size:0x3C fn_8016CC20 = .text:0x8016CC20; // type:function size:0x14 -fn_8016CC40 = .text:0x8016CC40; // type:function size:0xF0 -fn_8016CD30 = .text:0x8016CD30; // type:function size:0x20 -fn_8016CD50 = .text:0x8016CD50; // type:function size:0x20 -fn_8016CD70 = .text:0x8016CD70; // type:function size:0x24 +checkedAdd__7CounterFi = .text:0x8016CC40; // type:function size:0xF0 +getCommittedValue__7CounterFv = .text:0x8016CD30; // type:function size:0x20 +getUncommittedValue__7CounterFv = .text:0x8016CD50; // type:function size:0x20 +setValue__7CounterFUs = .text:0x8016CD70; // type:function size:0x24 fn_8016CDA0 = .text:0x8016CDA0; // type:function size:0x64 fn_8016CE10 = .text:0x8016CE10; // type:function size:0x10 fn_8016CE20 = .text:0x8016CE20; // type:function size:0x14 @@ -9432,36 +9432,36 @@ fn_8016D990 = .text:0x8016D990; // type:function size:0x8 fn_8016D9A0 = .text:0x8016D9A0; // type:function size:0x8 fn_8016D9B0 = .text:0x8016D9B0; // type:function size:0x8 fn_8016D9C0 = .text:0x8016D9C0; // type:function size:0x448 -fn_8016DE10 = .text:0x8016DE10; // type:function size:0xAC -fn_8016DEC0 = .text:0x8016DEC0; // type:function size:0x2C -fn_8016DEF0 = .text:0x8016DEF0; // type:function size:0x40 -fn_8016DF30 = .text:0x8016DF30; // type:function size:0x18 -fn_8016DF50 = .text:0x8016DF50; // type:function size:0x38 -fn_8016DF90 = .text:0x8016DF90; // type:function size:0x8 -fn_8016DFA0 = .text:0x8016DFA0; // type:function size:0x40 -fn_8016DFE0 = .text:0x8016DFE0; // type:function size:0x18 -fn_8016E000 = .text:0x8016E000; // type:function size:0x8 -fn_8016E010 = .text:0x8016E010; // type:function size:0x8 -fn_8016E020 = .text:0x8016E020; // type:function size:0x40 -fn_8016E060 = .text:0x8016E060; // type:function size:0x18 -fn_8016E080 = .text:0x8016E080; // type:function size:0x8 -fn_8016E090 = .text:0x8016E090; // type:function size:0x8 -fn_8016E0A0 = .text:0x8016E0A0; // type:function size:0x40 -fn_8016E0E0 = .text:0x8016E0E0; // type:function size:0x18 -fn_8016E100 = .text:0x8016E100; // type:function size:0x8 -fn_8016E110 = .text:0x8016E110; // type:function size:0x8 -fn_8016E120 = .text:0x8016E120; // type:function size:0x40 -fn_8016E160 = .text:0x8016E160; // type:function size:0x18 -fn_8016E180 = .text:0x8016E180; // type:function size:0x8 -fn_8016E190 = .text:0x8016E190; // type:function size:0x8 -fn_8016E1A0 = .text:0x8016E1A0; // type:function size:0x40 -fn_8016E1E0 = .text:0x8016E1E0; // type:function size:0x18 -fn_8016E200 = .text:0x8016E200; // type:function size:0x8 -fn_8016E210 = .text:0x8016E210; // type:function size:0x8 -fn_8016E220 = .text:0x8016E220; // type:function size:0x40 -fn_8016E260 = .text:0x8016E260; // type:function size:0x18 -fn_8016E280 = .text:0x8016E280; // type:function size:0x8 -fn_8016E290 = .text:0x8016E290; // type:function size:0x8 +getBaseCapacity__Fv = .text:0x8016DE10; // type:function size:0xAC +getExtraWalletCapacity__Fv = .text:0x8016DEC0; // type:function size:0x2C +__dt__12RupeeCounterFv = .text:0x8016DEF0; // type:function size:0x40 +__ct__12RupeeCounterFv = .text:0x8016DF30; // type:function size:0x18 +getMax__12RupeeCounterFv = .text:0x8016DF50; // type:function size:0x38 +__sinit_\rupee_counter_cpp = .text:0x8016DF90; // type:function size:0x8 scope:local +__dt__12ArrowCounterFv = .text:0x8016DFA0; // type:function size:0x40 +__ct__12ArrowCounterFv = .text:0x8016DFE0; // type:function size:0x18 +getMax__12ArrowCounterFv = .text:0x8016E000; // type:function size:0x8 +__sinit_\arrow_counter_cpp = .text:0x8016E010; // type:function size:0x8 scope:local +__dt__11BombCounterFv = .text:0x8016E020; // type:function size:0x40 +__ct__11BombCounterFv = .text:0x8016E060; // type:function size:0x18 +getMax__11BombCounterFv = .text:0x8016E080; // type:function size:0x8 +__sinit_\bomb_counter_cpp = .text:0x8016E090; // type:function size:0x8 scope:local +__dt__11TearCounterFv = .text:0x8016E0A0; // type:function size:0x40 +__ct__11TearCounterFv = .text:0x8016E0E0; // type:function size:0x18 +getMax__11TearCounterFv = .text:0x8016E100; // type:function size:0x8 +__sinit_\tear_counter_cpp = .text:0x8016E110; // type:function size:0x8 scope:local +__dt__20SlingshotSeedCounterFv = .text:0x8016E120; // type:function size:0x40 +__ct__20SlingshotSeedCounterFv = .text:0x8016E160; // type:function size:0x18 +getMax__20SlingshotSeedCounterFv = .text:0x8016E180; // type:function size:0x8 +__sinit_\slingshot_seed_counter_cpp = .text:0x8016E190; // type:function size:0x8 scope:local +__dt__15KeyPieceCounterFv = .text:0x8016E1A0; // type:function size:0x40 +__ct__15KeyPieceCounterFv = .text:0x8016E1E0; // type:function size:0x18 +getMax__15KeyPieceCounterFv = .text:0x8016E200; // type:function size:0x8 +__sinit_\key_piece_counter_cpp = .text:0x8016E210; // type:function size:0x8 scope:local +__dt__18ExtraWalletCounterFv = .text:0x8016E220; // type:function size:0x40 +__ct__18ExtraWalletCounterFv = .text:0x8016E260; // type:function size:0x18 +getMax__18ExtraWalletCounterFv = .text:0x8016E280; // type:function size:0x8 +__sinit_\extra_wallet_counter_cpp = .text:0x8016E290; // type:function size:0x8 scope:local fn_8016E2A0 = .text:0x8016E2A0; // type:function size:0x6C fn_8016E310 = .text:0x8016E310; // type:function size:0x194 fn_8016E4B0 = .text:0x8016E4B0; // type:function size:0x1C @@ -28352,7 +28352,7 @@ lbl_804E8D18 = .rodata:0x804E8D18; // type:object size:0x10 lbl_804E8D28 = .rodata:0x804E8D28; // type:object size:0x48 data:4byte lbl_804E8D70 = .rodata:0x804E8D70; // type:object size:0x40 data:4byte lbl_804E8DB0 = .rodata:0x804E8DB0; // type:object size:0x400 -lbl_804E91B0 = .rodata:0x804E91B0; // type:object size:0x20 data:4byte +wallet_definitions = .rodata:0x804E91B0; // type:object size:0x20 scope:local data:4byte lbl_804E91D0 = .rodata:0x804E91D0; // type:object size:0xA8 lbl_804E9278 = .rodata:0x804E9278; // type:object size:0xA0 lbl_804E9318 = .rodata:0x804E9318; // type:object size:0xA8 @@ -33327,13 +33327,13 @@ lbl_80527F70 = .data:0x80527F70; // type:object size:0x20 lbl_80527F90 = .data:0x80527F90; // type:object size:0x20 lbl_80527FB0 = .data:0x80527FB0; // type:object size:0x20 lbl_80527FD0 = .data:0x80527FD0; // type:object size:0x20 -lbl_80527FF0 = .data:0x80527FF0; // type:object size:0x20 -lbl_80528010 = .data:0x80528010; // type:object size:0x20 -lbl_80528030 = .data:0x80528030; // type:object size:0x20 -lbl_80528050 = .data:0x80528050; // type:object size:0x20 -lbl_80528070 = .data:0x80528070; // type:object size:0x20 -lbl_80528090 = .data:0x80528090; // type:object size:0x20 -lbl_805280B0 = .data:0x805280B0; // type:object size:0x20 +__vt__12RupeeCounter = .data:0x80527FF0; // type:object size:0x20 +__vt__12ArrowCounter = .data:0x80528010; // type:object size:0x20 +__vt__11BombCounter = .data:0x80528030; // type:object size:0x20 +__vt__11TearCounter = .data:0x80528050; // type:object size:0x20 +__vt__20SlingshotSeedCounter = .data:0x80528070; // type:object size:0x20 +__vt__15KeyPieceCounter = .data:0x80528090; // type:object size:0x20 +__vt__18ExtraWalletCounter = .data:0x805280B0; // type:object size:0x20 lbl_805280D0 = .data:0x805280D0; // type:object size:0xC lbl_805280DC = .data:0x805280DC; // type:object size:0xC lbl_805280E8 = .data:0x805280E8; // type:object size:0x10 diff --git a/configure.py b/configure.py index c3cea48b..67462de3 100644 --- a/configure.py +++ b/configure.py @@ -285,6 +285,13 @@ config.libs = [ Object(NonMatching, "d/a/d_a_base.cpp"), Object(NonMatching, "d/a/obj/d_a_obj_base.cpp"), Object(Matching, "toBeSorted/save_file.cpp"), + Object(Matching, "toBeSorted/counters/rupee_counter.cpp"), + Object(Matching, "toBeSorted/counters/arrow_counter.cpp"), + Object(Matching, "toBeSorted/counters/bomb_counter.cpp"), + Object(Matching, "toBeSorted/counters/tear_counter.cpp"), + Object(Matching, "toBeSorted/counters/slingshot_seed_counter.cpp"), + Object(Matching, "toBeSorted/counters/key_piece_counter.cpp"), + Object(Matching, "toBeSorted/counters/extra_wallet_counter.cpp"), Object(NonMatching, "toBeSorted/file_manager.cpp"), Object(NonMatching, "toBeSorted/save_manager.cpp"), Object(NonMatching, "f/f_base.cpp"), diff --git a/include/toBeSorted/counters/counter.h b/include/toBeSorted/counters/counter.h new file mode 100644 index 00000000..9747dd49 --- /dev/null +++ b/include/toBeSorted/counters/counter.h @@ -0,0 +1,43 @@ +#ifndef COUNTER_H +#define COUNTER_H + +#include + +class Counter { +public: + Counter(u16 id): counterId(id) {} + // No vtable, this class appears to be header-only + virtual ~Counter() {}; + /* 8016cc40 */ virtual s32 checkedAdd(s32 num) { + s32 uncommitted = getUncommittedValue(); + s32 max = getMax(); + s32 result = uncommitted + num; + if (result < 0) { + setValue(0); + } else if (result < max) { + setValue(result); + } else { + setValue(max); + } + + if (result < 0) { + return result; + } + + return result <= max ? 0 : (result - max); + } + virtual u16 getCommittedValue() { + return 0; + } + virtual u16 getMax() = 0; + virtual u16 getUncommittedValue() { + return 0; + } + virtual void setValue(u16 num) { + return; + } + + u16 counterId; +}; + +#endif COUNTER_H diff --git a/src/toBeSorted/counters/arrow_counter.cpp b/src/toBeSorted/counters/arrow_counter.cpp new file mode 100644 index 00000000..a7837350 --- /dev/null +++ b/src/toBeSorted/counters/arrow_counter.cpp @@ -0,0 +1,15 @@ +#include + +class ArrowCounter : public Counter { +public: + ArrowCounter(); + /* 8016DFA0 */ ~ArrowCounter() {} + virtual u16 getMax() override; +}; + +/* 80575618 */ ArrowCounter lbl_80575618; + +/* 8016DFE0 */ ArrowCounter::ArrowCounter() : Counter(0x1f2) {} +/* 8016E000 */ u16 ArrowCounter::getMax() { + return 20; +} diff --git a/src/toBeSorted/counters/bomb_counter.cpp b/src/toBeSorted/counters/bomb_counter.cpp new file mode 100644 index 00000000..4511ea56 --- /dev/null +++ b/src/toBeSorted/counters/bomb_counter.cpp @@ -0,0 +1,15 @@ +#include + +class BombCounter : public Counter { +public: + BombCounter(); + /* 8016E020 */ ~BombCounter() {} + virtual u16 getMax() override; +}; + +/* 80575620 */ BombCounter lbl_80575620; + +/* 8016E060 */ BombCounter::BombCounter(): Counter(0x1f3) { } +/* 8016E080 */ u16 BombCounter::getMax() { + return 10; +} diff --git a/src/toBeSorted/counters/extra_wallet_counter.cpp b/src/toBeSorted/counters/extra_wallet_counter.cpp new file mode 100644 index 00000000..0d8a2f52 --- /dev/null +++ b/src/toBeSorted/counters/extra_wallet_counter.cpp @@ -0,0 +1,16 @@ +#include + +class ExtraWalletCounter : public Counter { +public: + ExtraWalletCounter(); + /* 8016E220 */ ~ExtraWalletCounter() {} + virtual u16 getMax() override; +}; + + +/* 80575640 */ ExtraWalletCounter lbl_80575640; + +/* 8016E260 */ ExtraWalletCounter::ExtraWalletCounter(): Counter(0x1fc) { } +/* 8016E280 */ u16 ExtraWalletCounter::getMax() { + return 3; +} diff --git a/src/toBeSorted/counters/key_piece_counter.cpp b/src/toBeSorted/counters/key_piece_counter.cpp new file mode 100644 index 00000000..8a3b6914 --- /dev/null +++ b/src/toBeSorted/counters/key_piece_counter.cpp @@ -0,0 +1,15 @@ +#include + +class KeyPieceCounter : public Counter { +public: + KeyPieceCounter(); + /* 8016E1A0 */ ~KeyPieceCounter() {} + virtual u16 getMax() override; +}; + +/* 80575638 */ KeyPieceCounter lbl_80575638; + +/* 8016E1E0 */ KeyPieceCounter::KeyPieceCounter() : Counter(0x1f9) {} +/* 8016E200 */ u16 KeyPieceCounter::getMax() { + return 5; +} diff --git a/src/toBeSorted/counters/rupee_counter.cpp b/src/toBeSorted/counters/rupee_counter.cpp new file mode 100644 index 00000000..d8b4920c --- /dev/null +++ b/src/toBeSorted/counters/rupee_counter.cpp @@ -0,0 +1,52 @@ +#include + +class RupeeCounter : public Counter { +public: + RupeeCounter(); + /* 8016DEF0 */ ~RupeeCounter() {} + virtual u16 getMax() override; +}; + +struct WalletStruct { + u32 flag; + u16 capacity; +}; + +/* 804E91B0 */ +const struct WalletStruct wallet_definitions[4] = { + {0x6c, 500}, + {0x6d, 1000}, + {0x6e, 5000}, + {0x6f, 9000}, +}; + +// TODO set up item flag manager +extern "C" void *lbl_80575400; +extern "C" u16 fn_800BF5E0(void *data, u16 flag); + +/* 8016DE10 */ u16 getBaseCapacity() { + int i = 0; + WalletStruct tmp[4] = {wallet_definitions[0], wallet_definitions[1], wallet_definitions[2], wallet_definitions[3]}; + const WalletStruct *wallet = &tmp[3]; + for (; i < 4; i++, wallet--) { + if (fn_800BF5E0(lbl_80575400, wallet->flag)) { + return wallet->capacity; + } + } + return 300; +} + +// TODO main counters class +extern "C" u16 fn_8016D730(u16); + +/* 8016DEC0 */ u16 getExtraWalletCapacity() { + return 300 * fn_8016D730(0x27); +} + +/* 80575610 */ RupeeCounter lbl_80575610; + +/* 8016DF30 */ RupeeCounter::RupeeCounter() : Counter(0x1f5) {} + +/* 8016DF50 */ u16 RupeeCounter::getMax() { + return (getBaseCapacity() + getExtraWalletCapacity()); +} diff --git a/src/toBeSorted/counters/slingshot_seed_counter.cpp b/src/toBeSorted/counters/slingshot_seed_counter.cpp new file mode 100644 index 00000000..1af7fb6c --- /dev/null +++ b/src/toBeSorted/counters/slingshot_seed_counter.cpp @@ -0,0 +1,15 @@ +#include + +class SlingshotSeedCounter : public Counter { +public: + SlingshotSeedCounter(); + /* 8016E120 */ ~SlingshotSeedCounter() {} + virtual u16 getMax() override; +}; + +/* 80575630 */ SlingshotSeedCounter lbl_80575630; + +/* 8016E160 */ SlingshotSeedCounter::SlingshotSeedCounter() : Counter(0x1ed) {} +/* 8016E180 */ u16 SlingshotSeedCounter::getMax() { + return 20; +} diff --git a/src/toBeSorted/counters/tear_counter.cpp b/src/toBeSorted/counters/tear_counter.cpp new file mode 100644 index 00000000..edb48276 --- /dev/null +++ b/src/toBeSorted/counters/tear_counter.cpp @@ -0,0 +1,15 @@ +#include + +class TearCounter : public Counter { +public: + TearCounter(); + /* 8016E0A0 */ ~TearCounter() {} + virtual u16 getMax() override; +}; + +/* 80575628 */ TearCounter lbl_80575628; + +/* 8016E0E0 */ TearCounter::TearCounter(): Counter(0x1f4) { } +/* 8016E100 */ u16 TearCounter::getMax() { + return 15; +} From 5f621162a254bd495e5d697451dc43f5c520d272 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 3 May 2024 09:50:23 +0200 Subject: [PATCH 13/23] Main counters file --- config/SOUE01/splits.txt | 3 ++ configure.py | 1 + include/toBeSorted/counters/counter.h | 32 ++-------------- src/toBeSorted/counters/counter.cpp | 55 +++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 28 deletions(-) create mode 100644 src/toBeSorted/counters/counter.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index ebd3baeb..523e8e25 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -127,6 +127,9 @@ toBeSorted/skipflag_manager.cpp: .sbss start:0x80575408 end:0x8057540C .bss start:0x805A9C68 end:0x805A9C88 +toBeSorted/counters/counter.cpp: + .text start:0x8016CC40 end:0x8016CD94 + toBeSorted/counters/rupee_counter.cpp: .text start:0x8016DE10 end:0x8016DF98 .ctors start:0x804DB7BC end:0x804DB7C0 diff --git a/configure.py b/configure.py index 67462de3..ae51b22b 100644 --- a/configure.py +++ b/configure.py @@ -285,6 +285,7 @@ config.libs = [ Object(NonMatching, "d/a/d_a_base.cpp"), Object(NonMatching, "d/a/obj/d_a_obj_base.cpp"), Object(Matching, "toBeSorted/save_file.cpp"), + Object(Matching, "toBeSorted/counters/counter.cpp"), Object(Matching, "toBeSorted/counters/rupee_counter.cpp"), Object(Matching, "toBeSorted/counters/arrow_counter.cpp"), Object(Matching, "toBeSorted/counters/bomb_counter.cpp"), diff --git a/include/toBeSorted/counters/counter.h b/include/toBeSorted/counters/counter.h index 9747dd49..0741b0d3 100644 --- a/include/toBeSorted/counters/counter.h +++ b/include/toBeSorted/counters/counter.h @@ -6,36 +6,12 @@ class Counter { public: Counter(u16 id): counterId(id) {} - // No vtable, this class appears to be header-only virtual ~Counter() {}; - /* 8016cc40 */ virtual s32 checkedAdd(s32 num) { - s32 uncommitted = getUncommittedValue(); - s32 max = getMax(); - s32 result = uncommitted + num; - if (result < 0) { - setValue(0); - } else if (result < max) { - setValue(result); - } else { - setValue(max); - } - - if (result < 0) { - return result; - } - - return result <= max ? 0 : (result - max); - } - virtual u16 getCommittedValue() { - return 0; - } + virtual s32 checkedAdd(s32 num); + virtual u16 getCommittedValue(); virtual u16 getMax() = 0; - virtual u16 getUncommittedValue() { - return 0; - } - virtual void setValue(u16 num) { - return; - } + virtual u16 getUncommittedValue(); + virtual void setValue(u16 num); u16 counterId; }; diff --git a/src/toBeSorted/counters/counter.cpp b/src/toBeSorted/counters/counter.cpp new file mode 100644 index 00000000..2c388e44 --- /dev/null +++ b/src/toBeSorted/counters/counter.cpp @@ -0,0 +1,55 @@ +#include + +// TODO use the item flag manager once it exists +class ItemFlagManager { +public: + ItemFlagManager() {} + /** 0x08 */ virtual ~ItemFlagManager(); + /** 0x0C */ virtual void setFlagszptr(); + /** 0x10 */ virtual void onDirty(); + /** 0x14 */ virtual void copyFlagsFromSave() = 0; + /** 0x18 */ virtual void setupUnkFlagsStuff() = 0; + /** 0x1C */ virtual bool doCommit() = 0; + /** 0x20 */ virtual void setFlag(u16 flag); + /** 0x24 */ virtual void unsetFlag(u16 flag); + /** 0x28 */ virtual void setFlagOrCounterToValue(u16 flag, u16 value); + /** 0x2C */ virtual u16 getCounterOrFlag(u16 flag); + /** 0x30 */ virtual u16 getUncommittedValue(u16 flag); + /** 0x34 */ virtual void unk3(); + /** 0x38 */ virtual u16 *getSaveFlagSpace() = 0; +}; + +// TODO set up item flag manager +extern "C" ItemFlagManager *lbl_80575400; + + +/* 8016cc40 */ s32 Counter::checkedAdd(s32 num) { + s32 uncommitted = getUncommittedValue(); + s32 max = getMax(); + s32 result = uncommitted + num; + if (result < 0) { + setValue(0); + } else if (result < max) { + setValue(result); + } else { + setValue(max); + } + + if (result < 0) { + return result; + } + + return result <= max ? 0 : (result - max); +} + +/* 8016cd30 */ u16 Counter::getCommittedValue() { + return lbl_80575400->getCounterOrFlag(counterId | 0x4000); +} + +/* 8016cd50 */ u16 Counter::getUncommittedValue() { + return lbl_80575400->getUncommittedValue(counterId | 0x4000); +} + +/* 8016cd70 */ void Counter::setValue(u16 num) { + lbl_80575400->setFlagOrCounterToValue(counterId | 0x4000, num); +} From d3e39ebc28e85751eaf03c2eca887194dabe6460 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 3 May 2024 10:01:24 +0200 Subject: [PATCH 14/23] Cleanup --- src/toBeSorted/counters/rupee_counter.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/toBeSorted/counters/rupee_counter.cpp b/src/toBeSorted/counters/rupee_counter.cpp index d8b4920c..cd754fc6 100644 --- a/src/toBeSorted/counters/rupee_counter.cpp +++ b/src/toBeSorted/counters/rupee_counter.cpp @@ -12,22 +12,19 @@ struct WalletStruct { u16 capacity; }; -/* 804E91B0 */ -const struct WalletStruct wallet_definitions[4] = { - {0x6c, 500}, - {0x6d, 1000}, - {0x6e, 5000}, - {0x6f, 9000}, -}; - // TODO set up item flag manager extern "C" void *lbl_80575400; extern "C" u16 fn_800BF5E0(void *data, u16 flag); /* 8016DE10 */ u16 getBaseCapacity() { int i = 0; - WalletStruct tmp[4] = {wallet_definitions[0], wallet_definitions[1], wallet_definitions[2], wallet_definitions[3]}; - const WalletStruct *wallet = &tmp[3]; + /* 804E91B0 */ WalletStruct wallet_definitions[4] = { + {0x6c, 500}, + {0x6d, 1000}, + {0x6e, 5000}, + {0x6f, 9000}, + }; + const WalletStruct *wallet = &wallet_definitions[3]; for (; i < 4; i++, wallet--) { if (fn_800BF5E0(lbl_80575400, wallet->flag)) { return wallet->capacity; From dcb2c48b588405ab01807516bb2ee920f734a1f2 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 4 May 2024 19:57:10 +0200 Subject: [PATCH 15/23] Update counters for ipa file --- src/toBeSorted/counters/arrow_counter.cpp | 7 +++---- src/toBeSorted/counters/bomb_counter.cpp | 7 +++---- src/toBeSorted/counters/extra_wallet_counter.cpp | 7 +++---- src/toBeSorted/counters/key_piece_counter.cpp | 7 +++---- src/toBeSorted/counters/rupee_counter.cpp | 15 ++++++++------- .../counters/slingshot_seed_counter.cpp | 7 +++---- src/toBeSorted/counters/tear_counter.cpp | 7 +++---- 7 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/toBeSorted/counters/arrow_counter.cpp b/src/toBeSorted/counters/arrow_counter.cpp index a7837350..a770d160 100644 --- a/src/toBeSorted/counters/arrow_counter.cpp +++ b/src/toBeSorted/counters/arrow_counter.cpp @@ -4,12 +4,11 @@ class ArrowCounter : public Counter { public: ArrowCounter(); /* 8016DFA0 */ ~ArrowCounter() {} - virtual u16 getMax() override; + /* 8016E000 */ virtual u16 getMax() override { + return 20; + }; }; /* 80575618 */ ArrowCounter lbl_80575618; /* 8016DFE0 */ ArrowCounter::ArrowCounter() : Counter(0x1f2) {} -/* 8016E000 */ u16 ArrowCounter::getMax() { - return 20; -} diff --git a/src/toBeSorted/counters/bomb_counter.cpp b/src/toBeSorted/counters/bomb_counter.cpp index 4511ea56..02d11af0 100644 --- a/src/toBeSorted/counters/bomb_counter.cpp +++ b/src/toBeSorted/counters/bomb_counter.cpp @@ -4,12 +4,11 @@ class BombCounter : public Counter { public: BombCounter(); /* 8016E020 */ ~BombCounter() {} - virtual u16 getMax() override; + /* 8016E080 */ virtual u16 getMax() override { + return 10; + } }; /* 80575620 */ BombCounter lbl_80575620; /* 8016E060 */ BombCounter::BombCounter(): Counter(0x1f3) { } -/* 8016E080 */ u16 BombCounter::getMax() { - return 10; -} diff --git a/src/toBeSorted/counters/extra_wallet_counter.cpp b/src/toBeSorted/counters/extra_wallet_counter.cpp index 0d8a2f52..342f2e81 100644 --- a/src/toBeSorted/counters/extra_wallet_counter.cpp +++ b/src/toBeSorted/counters/extra_wallet_counter.cpp @@ -4,13 +4,12 @@ class ExtraWalletCounter : public Counter { public: ExtraWalletCounter(); /* 8016E220 */ ~ExtraWalletCounter() {} - virtual u16 getMax() override; + /* 8016E280 */ virtual u16 getMax() override { + return 3; + } }; /* 80575640 */ ExtraWalletCounter lbl_80575640; /* 8016E260 */ ExtraWalletCounter::ExtraWalletCounter(): Counter(0x1fc) { } -/* 8016E280 */ u16 ExtraWalletCounter::getMax() { - return 3; -} diff --git a/src/toBeSorted/counters/key_piece_counter.cpp b/src/toBeSorted/counters/key_piece_counter.cpp index 8a3b6914..55ddded7 100644 --- a/src/toBeSorted/counters/key_piece_counter.cpp +++ b/src/toBeSorted/counters/key_piece_counter.cpp @@ -4,12 +4,11 @@ class KeyPieceCounter : public Counter { public: KeyPieceCounter(); /* 8016E1A0 */ ~KeyPieceCounter() {} - virtual u16 getMax() override; + /* 8016E200 */ virtual u16 getMax() override { + return 5; + } }; /* 80575638 */ KeyPieceCounter lbl_80575638; /* 8016E1E0 */ KeyPieceCounter::KeyPieceCounter() : Counter(0x1f9) {} -/* 8016E200 */ u16 KeyPieceCounter::getMax() { - return 5; -} diff --git a/src/toBeSorted/counters/rupee_counter.cpp b/src/toBeSorted/counters/rupee_counter.cpp index cd754fc6..d1264a74 100644 --- a/src/toBeSorted/counters/rupee_counter.cpp +++ b/src/toBeSorted/counters/rupee_counter.cpp @@ -1,10 +1,15 @@ #include +static u16 getBaseCapacity(); +static u16 getExtraWalletCapacity(); + class RupeeCounter : public Counter { public: RupeeCounter(); /* 8016DEF0 */ ~RupeeCounter() {} - virtual u16 getMax() override; + /* 8016DF50 */ virtual u16 getMax() override { + return (getBaseCapacity() + getExtraWalletCapacity()); + } }; struct WalletStruct { @@ -16,7 +21,7 @@ struct WalletStruct { extern "C" void *lbl_80575400; extern "C" u16 fn_800BF5E0(void *data, u16 flag); -/* 8016DE10 */ u16 getBaseCapacity() { +/* 8016DE10 */ static u16 getBaseCapacity() { int i = 0; /* 804E91B0 */ WalletStruct wallet_definitions[4] = { {0x6c, 500}, @@ -36,14 +41,10 @@ extern "C" u16 fn_800BF5E0(void *data, u16 flag); // TODO main counters class extern "C" u16 fn_8016D730(u16); -/* 8016DEC0 */ u16 getExtraWalletCapacity() { +/* 8016DEC0 */ static u16 getExtraWalletCapacity() { return 300 * fn_8016D730(0x27); } /* 80575610 */ RupeeCounter lbl_80575610; /* 8016DF30 */ RupeeCounter::RupeeCounter() : Counter(0x1f5) {} - -/* 8016DF50 */ u16 RupeeCounter::getMax() { - return (getBaseCapacity() + getExtraWalletCapacity()); -} diff --git a/src/toBeSorted/counters/slingshot_seed_counter.cpp b/src/toBeSorted/counters/slingshot_seed_counter.cpp index 1af7fb6c..797018d6 100644 --- a/src/toBeSorted/counters/slingshot_seed_counter.cpp +++ b/src/toBeSorted/counters/slingshot_seed_counter.cpp @@ -4,12 +4,11 @@ class SlingshotSeedCounter : public Counter { public: SlingshotSeedCounter(); /* 8016E120 */ ~SlingshotSeedCounter() {} - virtual u16 getMax() override; + /* 8016E180 */ virtual u16 getMax() override { + return 20; + }; }; /* 80575630 */ SlingshotSeedCounter lbl_80575630; /* 8016E160 */ SlingshotSeedCounter::SlingshotSeedCounter() : Counter(0x1ed) {} -/* 8016E180 */ u16 SlingshotSeedCounter::getMax() { - return 20; -} diff --git a/src/toBeSorted/counters/tear_counter.cpp b/src/toBeSorted/counters/tear_counter.cpp index edb48276..2a8503cd 100644 --- a/src/toBeSorted/counters/tear_counter.cpp +++ b/src/toBeSorted/counters/tear_counter.cpp @@ -4,12 +4,11 @@ class TearCounter : public Counter { public: TearCounter(); /* 8016E0A0 */ ~TearCounter() {} - virtual u16 getMax() override; + /* 8016E100 */ virtual u16 getMax() override { + return 15; + }; }; /* 80575628 */ TearCounter lbl_80575628; /* 8016E0E0 */ TearCounter::TearCounter(): Counter(0x1f4) { } -/* 8016E100 */ u16 TearCounter::getMax() { - return 15; -} From 3b8a4efbfd28d229e0e0e2e013d2a390b2ed217f Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 4 May 2024 20:21:58 -0400 Subject: [PATCH 16/23] Matching. Pulled from ogws --- config/SOUE01/splits.txt | 3 ++ config/SOUE01/symbols.txt | 10 ++--- configure.py | 1 + src/nw4r/ut/ut_LinkList.cpp | 76 +++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 src/nw4r/ut/ut_LinkList.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index f84fec00..8b4cd82f 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -170,6 +170,9 @@ rvl/CX/cx.c: nw4r/ut/ut_list.cpp: .text start:0x8042A530 end:0x8042A850 +nw4r/ut/ut_LinkList.cpp: + .text start:0x8042A850 end:0x8042A9E0 + nw4r/db/db_directPrint.cpp: .text start:0x804342A0 end:0x80434E9C .rodata start:0x804F5D28 end:0x804F5FDC diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 195dcdc3..39171bc6 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -23934,11 +23934,11 @@ List_Remove__Q24nw4r2utFPQ34nw4r2ut4ListPv = .text:0x8042A750; // type:function List_GetNext__Q24nw4r2utFPCQ34nw4r2ut4ListPCv = .text:0x8042A7C0; // type:function size:0x20 List_GetPrev__Q24nw4r2utFPCQ34nw4r2ut4ListPCv = .text:0x8042A7E0; // type:function size:0x1C List_GetNth__Q24nw4r2utFPCQ34nw4r2ut4ListUs = .text:0x8042A800; // type:function size:0x50 -fn_8042A850 = .text:0x8042A850; // type:function size:0x84 -fn_8042A8E0 = .text:0x8042A8E0; // type:function size:0x48 -fn_8042A930 = .text:0x8042A930; // type:function size:0x44 -fn_8042A980 = .text:0x8042A980; // type:function size:0x2C -fn_8042A9B0 = .text:0x8042A9B0; // type:function size:0x30 +__dt__Q44nw4r2ut6detail12LinkListImplFv = .text:0x8042A850; // type:function size:0x84 +Erase__Q44nw4r2ut6detail12LinkListImplFQ54nw4r2ut6detail12LinkListImpl8Iterator = .text:0x8042A8E0; // type:function size:0x48 +Clear__Q44nw4r2ut6detail12LinkListImplFv = .text:0x8042A930; // type:function size:0x44 +Insert__Q44nw4r2ut6detail12LinkListImplFQ54nw4r2ut6detail12LinkListImpl8IteratorPQ34nw4r2ut12LinkListNode = .text:0x8042A980; // type:function size:0x2C +Erase__Q44nw4r2ut6detail12LinkListImplFPQ34nw4r2ut12LinkListNode = .text:0x8042A9B0; // type:function size:0x30 fn_8042A9E0 = .text:0x8042A9E0; // type:function size:0x74 fn_8042AA60 = .text:0x8042AA60; // type:function size:0x78 fn_8042AAE0 = .text:0x8042AAE0; // type:function size:0x1C diff --git a/configure.py b/configure.py index c3cea48b..075220c3 100644 --- a/configure.py +++ b/configure.py @@ -318,6 +318,7 @@ config.libs = [ "ut", [ Object(Matching, "nw4r/ut/ut_list.cpp"), + Object(Matching, "nw4r/ut/ut_LinkList.cpp"), ], ), # EGG diff --git a/src/nw4r/ut/ut_LinkList.cpp b/src/nw4r/ut/ut_LinkList.cpp new file mode 100644 index 00000000..5b0d8ee1 --- /dev/null +++ b/src/nw4r/ut/ut_LinkList.cpp @@ -0,0 +1,76 @@ +#include + +namespace nw4r { +namespace ut { +namespace detail { + +/* 8042a850 */ +LinkListImpl::~LinkListImpl() { + Clear(); +} + +/* 8042a8e0 */ +LinkListImpl::Iterator LinkListImpl::Erase(LinkListImpl::Iterator it) { + Iterator copy(it); + return Erase(it, ++copy); +} + +/* 8042a930 */ +void LinkListImpl::Clear() { + Erase(GetBeginIter(), GetEndIter()); +} + +/* 8042a980 */ +LinkListImpl::Iterator LinkListImpl::Insert(Iterator it, LinkListNode *p) { + LinkListNode *next = it.mNode; + LinkListNode *prev = next->mPrev; + + // prev <- p -> next + p->mNext = next; + p->mPrev = prev; + // prev <-> p <-> next + next->mPrev = p; + prev->mNext = p; + + mSize++; + + return Iterator(p); +} + +/* 8042a9b0 */ +LinkListImpl::Iterator LinkListImpl::Erase(LinkListNode *p) { + LinkListNode *next = p->mNext; + LinkListNode *prev = p->mPrev; + + // Remove connections to node + next->mPrev = prev; + prev->mNext = next; + + mSize--; + + // Isolate node + p->mNext = NULL; + p->mPrev = NULL; + + return Iterator(next); +} + +/* Not in SS */ +LinkListImpl::Iterator LinkListImpl::Erase(Iterator begin, Iterator end) { + LinkListNode *pCur = begin.mNode; + LinkListNode *pEnd = end.mNode; + + while (pCur != pEnd) { + // Preserve next node before erasing pointers + LinkListNode *pNext = pCur->mNext; + // Erase current node + Erase(pCur); + pCur = pNext; + } + + return Iterator(pEnd); +} + +} // namespace detail +} // namespace ut +} // namespace nw4r From 93a9b77d427393cafbe2dab2dda72ef67956a2f6 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 4 May 2024 20:35:32 -0400 Subject: [PATCH 17/23] ut_binaryFileFormat Matching --- config/SOUE01/splits.txt | 3 +++ config/SOUE01/symbols.txt | 2 +- configure.py | 1 + include/nw4r/ut/ut_binaryFileFormat.h | 3 +-- src/nw4r/ut/ut_binaryFileFormat.cpp | 28 +++++++++++++++++++++++++++ 5 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 src/nw4r/ut/ut_binaryFileFormat.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index f84fec00..afc23448 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -170,6 +170,9 @@ rvl/CX/cx.c: nw4r/ut/ut_list.cpp: .text start:0x8042A530 end:0x8042A850 +nw4r/ut/ut_binaryFileFormat.cpp: + .text start:0x8042A9E0 end:0x8042AA54 + nw4r/db/db_directPrint.cpp: .text start:0x804342A0 end:0x80434E9C .rodata start:0x804F5D28 end:0x804F5FDC diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 195dcdc3..bd62870f 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -23939,7 +23939,7 @@ fn_8042A8E0 = .text:0x8042A8E0; // type:function size:0x48 fn_8042A930 = .text:0x8042A930; // type:function size:0x44 fn_8042A980 = .text:0x8042A980; // type:function size:0x2C fn_8042A9B0 = .text:0x8042A9B0; // type:function size:0x30 -fn_8042A9E0 = .text:0x8042A9E0; // type:function size:0x74 +IsValidBinaryFile__Q24nw4r2utFPCQ34nw4r2ut16BinaryFileHeaderUlUsUs = .text:0x8042A9E0; // type:function size:0x74 fn_8042AA60 = .text:0x8042AA60; // type:function size:0x78 fn_8042AAE0 = .text:0x8042AAE0; // type:function size:0x1C fn_8042AB00 = .text:0x8042AB00; // type:function size:0x1C diff --git a/configure.py b/configure.py index c3cea48b..da4b8b2c 100644 --- a/configure.py +++ b/configure.py @@ -318,6 +318,7 @@ config.libs = [ "ut", [ Object(Matching, "nw4r/ut/ut_list.cpp"), + Object(Matching, "nw4r/ut/ut_binaryFileFormat.cpp"), ], ), # EGG diff --git a/include/nw4r/ut/ut_binaryFileFormat.h b/include/nw4r/ut/ut_binaryFileFormat.h index eeb5faca..8185fc24 100644 --- a/include/nw4r/ut/ut_binaryFileFormat.h +++ b/include/nw4r/ut/ut_binaryFileFormat.h @@ -19,8 +19,7 @@ struct BinaryFileHeader { u16 numBlocks; // at 0xE }; -bool IsValidBinaryFile(const BinaryFileHeader* header, u32 magic, u16 version, - u16 numBlocks); +bool IsValidBinaryFile(const BinaryFileHeader *header, unsigned long magic, u16 version, u16 numBlocks); } // namespace ut } // namespace nw4r diff --git a/src/nw4r/ut/ut_binaryFileFormat.cpp b/src/nw4r/ut/ut_binaryFileFormat.cpp new file mode 100644 index 00000000..1b62b51c --- /dev/null +++ b/src/nw4r/ut/ut_binaryFileFormat.cpp @@ -0,0 +1,28 @@ +#include + +namespace nw4r { +namespace ut { + +/* 8042a9e0 */ +bool IsValidBinaryFile(const BinaryFileHeader *header, unsigned long magic, u16 version, u16 numBlocks) { + if (header->magic != magic) { + return false; + } + if (header->byteOrder != 0xFEFF) { + return false; + } + if (header->version != version) { + return false; + } + if (header->fileSize < (numBlocks * sizeof(BinaryBlockHeader) + sizeof(BinaryFileHeader))) { + return false; + } + + if (header->numBlocks < numBlocks) { + return false; + } + return true; +} + +} // namespace ut +} // namespace nw4r From 3d4d5ea068876e0a3df7ea295fbd1245d3d85c41 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 4 May 2024 21:59:49 -0400 Subject: [PATCH 18/23] Added nw4r ut splits and files --- config/SOUE01/splits.txt | 49 +++ config/SOUE01/symbols.txt | 398 ++++++++++++------------- configure.py | 14 + src/nw4r/ut/ut_CharStrmReader.cpp | 0 src/nw4r/ut/ut_CharWriter.cpp | 0 src/nw4r/ut/ut_DvdFileStream.cpp | 0 src/nw4r/ut/ut_DvdLockedFileStream.cpp | 0 src/nw4r/ut/ut_FileStream.cpp | 0 src/nw4r/ut/ut_Font.cpp | 0 src/nw4r/ut/ut_IOStream.cpp | 0 src/nw4r/ut/ut_LockedCache.cpp | 0 src/nw4r/ut/ut_NandFileStream.cpp | 0 src/nw4r/ut/ut_ResFont.cpp | 0 src/nw4r/ut/ut_ResFontBase.cpp | 0 src/nw4r/ut/ut_TagProcessorBase.cpp | 0 src/nw4r/ut/ut_TextWriterBase.cpp | 0 16 files changed, 262 insertions(+), 199 deletions(-) create mode 100644 src/nw4r/ut/ut_CharStrmReader.cpp create mode 100644 src/nw4r/ut/ut_CharWriter.cpp create mode 100644 src/nw4r/ut/ut_DvdFileStream.cpp create mode 100644 src/nw4r/ut/ut_DvdLockedFileStream.cpp create mode 100644 src/nw4r/ut/ut_FileStream.cpp create mode 100644 src/nw4r/ut/ut_Font.cpp create mode 100644 src/nw4r/ut/ut_IOStream.cpp create mode 100644 src/nw4r/ut/ut_LockedCache.cpp create mode 100644 src/nw4r/ut/ut_NandFileStream.cpp create mode 100644 src/nw4r/ut/ut_ResFont.cpp create mode 100644 src/nw4r/ut/ut_ResFontBase.cpp create mode 100644 src/nw4r/ut/ut_TagProcessorBase.cpp create mode 100644 src/nw4r/ut/ut_TextWriterBase.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 8b4cd82f..bb76869b 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -173,6 +173,55 @@ nw4r/ut/ut_list.cpp: nw4r/ut/ut_LinkList.cpp: .text start:0x8042A850 end:0x8042A9E0 +nw4r/ut/ut_binaryFileFormat.cpp: + .text start:0x8042A9E0 end:0x8042AA54 + +nw4r/ut/ut_CharStrmReader.cpp: + .text start:0x8042AA60 end:0x8042AB80 + +nw4r/ut/ut_TagProcessorBase.cpp: + .text start:0x8042AB80 end:0x8042B4D4 + +nw4r/ut/ut_IOStream.cpp: + .text start:0x8042B4E0 end:0x8042B55C + .ctors start:0x804DB938 end:0x804DB93C + +nw4r/ut/ut_FileStream.cpp: + .text start:0x8042B560 end:0x8042B6EC + .ctors start:0x804DB93C end:0x804DB940 + +nw4r/ut/ut_DvdFileStream.cpp: + .text start:0x8042B6F0 end:0x8042BDAC + .ctors start:0x804DB940 end:0x804DB944 + +nw4r/ut/ut_DvdLockedFileStream.cpp: + .text start:0x8042BDB0 end:0x8042C1DC + .ctors start:0x804DB944 end:0x804DB948 + +nw4r/ut/ut_NandFileStream.cpp: + .text start:0x8042C1E0 end:0x8042CA4C + .ctors start:0x804DB948 end:0x804DB94C + +nw4r/ut/ut_LockedCache.cpp: + .text start:0x8042CA50 end:0x8042CC28 + .ctors start:0x804DB94C end:0x804DB950 + +nw4r/ut/ut_Font.cpp: + .text start:0x8042CC30 end:0x8042CD20 + +nw4r/ut/ut_ResFontBase.cpp: + .text start:0x8042CD20 end:0x8042D4B8 + +nw4r/ut/ut_ResFont.cpp: + .text start:0x8042D4C0 end:0x8042D7CC + +nw4r/ut/ut_CharWriter.cpp: + .text start:0x8042D7D0 end:0x8042EF1C + +nw4r/ut/ut_TextWriterBase.cpp: + .text start:0x8042EF20 end:0x80434294 + .ctors start:0x804DB950 end:0x804DB954 + nw4r/db/db_directPrint.cpp: .text start:0x804342A0 end:0x80434E9C .rodata start:0x804F5D28 end:0x804F5FDC diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 39171bc6..cea99b0e 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -23939,205 +23939,205 @@ Erase__Q44nw4r2ut6detail12LinkListImplFQ54nw4r2ut6detail12LinkListImpl8Iterator Clear__Q44nw4r2ut6detail12LinkListImplFv = .text:0x8042A930; // type:function size:0x44 Insert__Q44nw4r2ut6detail12LinkListImplFQ54nw4r2ut6detail12LinkListImpl8IteratorPQ34nw4r2ut12LinkListNode = .text:0x8042A980; // type:function size:0x2C Erase__Q44nw4r2ut6detail12LinkListImplFPQ34nw4r2ut12LinkListNode = .text:0x8042A9B0; // type:function size:0x30 -fn_8042A9E0 = .text:0x8042A9E0; // type:function size:0x74 -fn_8042AA60 = .text:0x8042AA60; // type:function size:0x78 -fn_8042AAE0 = .text:0x8042AAE0; // type:function size:0x1C -fn_8042AB00 = .text:0x8042AB00; // type:function size:0x1C -fn_8042AB20 = .text:0x8042AB20; // type:function size:0x60 -fn_8042AB80 = .text:0x8042AB80; // type:function size:0x10 -fn_8042AB90 = .text:0x8042AB90; // type:function size:0x40 -fn_8042ABD0 = .text:0x8042ABD0; // type:function size:0x12C -fn_8042AD00 = .text:0x8042AD00; // type:function size:0x1E4 -fn_8042AEF0 = .text:0x8042AEF0; // type:function size:0x64 -fn_8042AF60 = .text:0x8042AF60; // type:function size:0xC4 -fn_8042B030 = .text:0x8042B030; // type:function size:0x10 -fn_8042B040 = .text:0x8042B040; // type:function size:0x40 -fn_8042B080 = .text:0x8042B080; // type:function size:0x12C -fn_8042B1B0 = .text:0x8042B1B0; // type:function size:0x1E4 -fn_8042B3A0 = .text:0x8042B3A0; // type:function size:0x64 -fn_8042B410 = .text:0x8042B410; // type:function size:0xC4 -fn_8042B4E0 = .text:0x8042B4E0; // type:function size:0x8 -fn_8042B4F0 = .text:0x8042B4F0; // type:function size:0x8 -fn_8042B500 = .text:0x8042B500; // type:function size:0x8 -fn_8042B510 = .text:0x8042B510; // type:function size:0x8 -fn_8042B520 = .text:0x8042B520; // type:function size:0x8 -fn_8042B530 = .text:0x8042B530; // type:function size:0x8 -fn_8042B540 = .text:0x8042B540; // type:function size:0x8 -fn_8042B550 = .text:0x8042B550; // type:function size:0xC -fn_8042B560 = .text:0x8042B560; // type:function size:0x4 -fn_8042B570 = .text:0x8042B570; // type:function size:0x8 -fn_8042B580 = .text:0x8042B580; // type:function size:0x64 -fn_8042B5F0 = .text:0x8042B5F0; // type:function size:0x50 -fn_8042B640 = .text:0x8042B640; // type:function size:0x88 -fn_8042B6D0 = .text:0x8042B6D0; // type:function size:0x8 -fn_8042B6E0 = .text:0x8042B6E0; // type:function size:0xC -fn_8042B6F0 = .text:0x8042B6F0; // type:function size:0x2C -fn_8042B720 = .text:0x8042B720; // type:function size:0x28 -fn_8042B750 = .text:0x8042B750; // type:function size:0xBC -fn_8042B810 = .text:0x8042B810; // type:function size:0x130 -fn_8042B940 = .text:0x8042B940; // type:function size:0x78 -fn_8042B9C0 = .text:0x8042B9C0; // type:function size:0x50 -fn_8042BA10 = .text:0x8042BA10; // type:function size:0x88 -fn_8042BAA0 = .text:0x8042BAA0; // type:function size:0xF4 -fn_8042BBA0 = .text:0x8042BBA0; // type:function size:0x3C -fn_8042BBE0 = .text:0x8042BBE0; // type:function size:0x80 -fn_8042BC60 = .text:0x8042BC60; // type:function size:0x8 -fn_8042BC70 = .text:0x8042BC70; // type:function size:0x8 -fn_8042BC80 = .text:0x8042BC80; // type:function size:0x5C -fn_8042BCE0 = .text:0x8042BCE0; // type:function size:0x8 -fn_8042BCF0 = .text:0x8042BCF0; // type:function size:0x8 -fn_8042BD00 = .text:0x8042BD00; // type:function size:0x8 -fn_8042BD10 = .text:0x8042BD10; // type:function size:0x8 -fn_8042BD20 = .text:0x8042BD20; // type:function size:0x8 -fn_8042BD30 = .text:0x8042BD30; // type:function size:0x8 -fn_8042BD40 = .text:0x8042BD40; // type:function size:0x8 -fn_8042BD50 = .text:0x8042BD50; // type:function size:0x8 -fn_8042BD60 = .text:0x8042BD60; // type:function size:0x8 -fn_8042BD70 = .text:0x8042BD70; // type:function size:0x8 -fn_8042BD80 = .text:0x8042BD80; // type:function size:0x8 -fn_8042BD90 = .text:0x8042BD90; // type:function size:0x8 -fn_8042BDA0 = .text:0x8042BDA0; // type:function size:0xC -fn_8042BDB0 = .text:0x8042BDB0; // type:function size:0x84 -fn_8042BE40 = .text:0x8042BE40; // type:function size:0x84 -fn_8042BED0 = .text:0x8042BED0; // type:function size:0x58 -fn_8042BF30 = .text:0x8042BF30; // type:function size:0x34 -fn_8042BF70 = .text:0x8042BF70; // type:function size:0xD4 -fn_8042C050 = .text:0x8042C050; // type:function size:0xD4 -fn_8042C130 = .text:0x8042C130; // type:function size:0x58 -fn_8042C190 = .text:0x8042C190; // type:function size:0x8 -fn_8042C1A0 = .text:0x8042C1A0; // type:function size:0x8 -fn_8042C1B0 = .text:0x8042C1B0; // type:function size:0x8 -fn_8042C1C0 = .text:0x8042C1C0; // type:function size:0x8 -fn_8042C1D0 = .text:0x8042C1D0; // type:function size:0xC -fn_8042C1E0 = .text:0x8042C1E0; // type:function size:0x2C -fn_8042C210 = .text:0x8042C210; // type:function size:0x70 -fn_8042C280 = .text:0x8042C280; // type:function size:0x70 -fn_8042C2F0 = .text:0x8042C2F0; // type:function size:0x78 -fn_8042C370 = .text:0x8042C370; // type:function size:0xE8 -fn_8042C460 = .text:0x8042C460; // type:function size:0x258 -fn_8042C6C0 = .text:0x8042C6C0; // type:function size:0x50 -fn_8042C710 = .text:0x8042C710; // type:function size:0x7C -fn_8042C790 = .text:0x8042C790; // type:function size:0xA4 -fn_8042C840 = .text:0x8042C840; // type:function size:0x7C -fn_8042C8C0 = .text:0x8042C8C0; // type:function size:0xA8 -fn_8042C970 = .text:0x8042C970; // type:function size:0x8 -fn_8042C980 = .text:0x8042C980; // type:function size:0x8 -fn_8042C990 = .text:0x8042C990; // type:function size:0x8 -fn_8042C9A0 = .text:0x8042C9A0; // type:function size:0x8 -fn_8042C9B0 = .text:0x8042C9B0; // type:function size:0x8 -fn_8042C9C0 = .text:0x8042C9C0; // type:function size:0x8 -fn_8042C9D0 = .text:0x8042C9D0; // type:function size:0x8 -fn_8042C9E0 = .text:0x8042C9E0; // type:function size:0x8 -fn_8042C9F0 = .text:0x8042C9F0; // type:function size:0x8 -fn_8042CA00 = .text:0x8042CA00; // type:function size:0x8 -fn_8042CA10 = .text:0x8042CA10; // type:function size:0x8 -fn_8042CA20 = .text:0x8042CA20; // type:function size:0x8 -fn_8042CA30 = .text:0x8042CA30; // type:function size:0x8 -fn_8042CA40 = .text:0x8042CA40; // type:function size:0xC -fn_8042CA50 = .text:0x8042CA50; // type:function size:0x60 -fn_8042CAB0 = .text:0x8042CAB0; // type:function size:0x78 -fn_8042CB30 = .text:0x8042CB30; // type:function size:0x70 -fn_8042CBA0 = .text:0x8042CBA0; // type:function size:0x40 -fn_8042CBE0 = .text:0x8042CBE0; // type:function size:0x4 -fn_8042CBF0 = .text:0x8042CBF0; // type:function size:0x4 -fn_8042CC00 = .text:0x8042CC00; // type:function size:0x4 -fn_8042CC10 = .text:0x8042CC10; // type:function size:0x18 -fn_8042CC30 = .text:0x8042CC30; // type:function size:0xA4 -fn_8042CCE0 = .text:0x8042CCE0; // type:function size:0x40 -fn_8042CD20 = .text:0x8042CD20; // type:function size:0x54 -fn_8042CD80 = .text:0x8042CD80; // type:function size:0x40 -fn_8042CDC0 = .text:0x8042CDC0; // type:function size:0xC -fn_8042CDD0 = .text:0x8042CDD0; // type:function size:0x18 -fn_8042CDF0 = .text:0x8042CDF0; // type:function size:0xC -fn_8042CE00 = .text:0x8042CE00; // type:function size:0xC -fn_8042CE10 = .text:0x8042CE10; // type:function size:0xC -fn_8042CE20 = .text:0x8042CE20; // type:function size:0x14 -fn_8042CE40 = .text:0x8042CE40; // type:function size:0x14 -fn_8042CE60 = .text:0x8042CE60; // type:function size:0x10 -fn_8042CE70 = .text:0x8042CE70; // type:function size:0x10 -fn_8042CE80 = .text:0x8042CE80; // type:function size:0x10 -fn_8042CE90 = .text:0x8042CE90; // type:function size:0x8 -fn_8042CEA0 = .text:0x8042CEA0; // type:function size:0x10 -fn_8042CEB0 = .text:0x8042CEB0; // type:function size:0x10 -fn_8042CEC0 = .text:0x8042CEC0; // type:function size:0x18 -fn_8042CEE0 = .text:0x8042CEE0; // type:function size:0x20 -fn_8042CF00 = .text:0x8042CF00; // type:function size:0xBC -fn_8042CFC0 = .text:0x8042CFC0; // type:function size:0xC -fn_8042CFD0 = .text:0x8042CFD0; // type:function size:0x44 -fn_8042D020 = .text:0x8042D020; // type:function size:0x114 -fn_8042D140 = .text:0x8042D140; // type:function size:0xC4 -fn_8042D210 = .text:0x8042D210; // type:function size:0xBC -fn_8042D2D0 = .text:0x8042D2D0; // type:function size:0xC -fn_8042D2E0 = .text:0x8042D2E0; // type:function size:0xCC -fn_8042D3B0 = .text:0x8042D3B0; // type:function size:0x108 -fn_8042D4C0 = .text:0x8042D4C0; // type:function size:0x3C -fn_8042D500 = .text:0x8042D500; // type:function size:0x58 -fn_8042D560 = .text:0x8042D560; // type:function size:0x148 -fn_8042D6B0 = .text:0x8042D6B0; // type:function size:0x4 -fn_8042D6C0 = .text:0x8042D6C0; // type:function size:0x10C -fn_8042D7D0 = .text:0x8042D7D0; // type:function size:0x380 -fn_8042DB50 = .text:0x8042DB50; // type:function size:0x40 -fn_8042DB90 = .text:0x8042DB90; // type:function size:0x930 -fn_8042E4C0 = .text:0x8042E4C0; // type:function size:0xC4 -fn_8042E590 = .text:0x8042E590; // type:function size:0x78 -fn_8042E610 = .text:0x8042E610; // type:function size:0x60 -fn_8042E670 = .text:0x8042E670; // type:function size:0x60 -fn_8042E6D0 = .text:0x8042E6D0; // type:function size:0x60 -fn_8042E730 = .text:0x8042E730; // type:function size:0x130 -fn_8042E860 = .text:0x8042E860; // type:function size:0x27C -fn_8042EAE0 = .text:0x8042EAE0; // type:function size:0x150 -fn_8042EC30 = .text:0x8042EC30; // type:function size:0x2EC -fn_8042EF20 = .text:0x8042EF20; // type:function size:0x5C -fn_8042EF80 = .text:0x8042EF80; // type:function size:0x58 -fn_8042EFE0 = .text:0x8042EFE0; // type:function size:0x90 -fn_8042F070 = .text:0x8042F070; // type:function size:0x7C -fn_8042F0F0 = .text:0x8042F0F0; // type:function size:0x204 -fn_8042F300 = .text:0x8042F300; // type:function size:0x204 -fn_8042F510 = .text:0x8042F510; // type:function size:0x1E0 -fn_8042F6F0 = .text:0x8042F6F0; // type:function size:0x180 -fn_8042F870 = .text:0x8042F870; // type:function size:0x144 -fn_8042F9C0 = .text:0x8042F9C0; // type:function size:0x144 -fn_8042FB10 = .text:0x8042FB10; // type:function size:0x118 -fn_8042FC30 = .text:0x8042FC30; // type:function size:0x21C -fn_8042FE50 = .text:0x8042FE50; // type:function size:0x1B8 -fn_80430010 = .text:0x80430010; // type:function size:0x140 -fn_80430150 = .text:0x80430150; // type:function size:0x110 -fn_80430260 = .text:0x80430260; // type:function size:0xAC -fn_80430310 = .text:0x80430310; // type:function size:0x8 -fn_80430320 = .text:0x80430320; // type:function size:0x4 -fn_80430330 = .text:0x80430330; // type:function size:0x154 -fn_80430490 = .text:0x80430490; // type:function size:0x5BC -fn_80430A50 = .text:0x80430A50; // type:function size:0x8 -fn_80430A60 = .text:0x80430A60; // type:function size:0x110 -fn_80430B70 = .text:0x80430B70; // type:function size:0x804 -fn_80431380 = .text:0x80431380; // type:function size:0x4D8 -fn_80431860 = .text:0x80431860; // type:function size:0x18 -fn_80431880 = .text:0x80431880; // type:function size:0x5C -fn_804318E0 = .text:0x804318E0; // type:function size:0x58 -fn_80431940 = .text:0x80431940; // type:function size:0x90 -fn_804319D0 = .text:0x804319D0; // type:function size:0x7C -fn_80431A50 = .text:0x80431A50; // type:function size:0x204 -fn_80431C60 = .text:0x80431C60; // type:function size:0x204 -fn_80431E70 = .text:0x80431E70; // type:function size:0x1E0 -fn_80432050 = .text:0x80432050; // type:function size:0x180 -fn_804321D0 = .text:0x804321D0; // type:function size:0x144 -fn_80432320 = .text:0x80432320; // type:function size:0x144 -fn_80432470 = .text:0x80432470; // type:function size:0x118 -fn_80432590 = .text:0x80432590; // type:function size:0x21C -fn_804327B0 = .text:0x804327B0; // type:function size:0x1B8 -fn_80432970 = .text:0x80432970; // type:function size:0x140 -fn_80432AB0 = .text:0x80432AB0; // type:function size:0x110 -fn_80432BC0 = .text:0x80432BC0; // type:function size:0xAC -fn_80432C70 = .text:0x80432C70; // type:function size:0x8 -fn_80432C80 = .text:0x80432C80; // type:function size:0x4 -fn_80432C90 = .text:0x80432C90; // type:function size:0x154 -fn_80432DF0 = .text:0x80432DF0; // type:function size:0x5BC -fn_804333B0 = .text:0x804333B0; // type:function size:0x8 -fn_804333C0 = .text:0x804333C0; // type:function size:0x120 -fn_804334E0 = .text:0x804334E0; // type:function size:0x828 -fn_80433D10 = .text:0x80433D10; // type:function size:0x4D8 -fn_804341F0 = .text:0x804341F0; // type:function size:0x18 -fn_80434210 = .text:0x80434210; // type:function size:0x84 +IsValidBinaryFile__Q24nw4r2utFPCQ34nw4r2ut16BinaryFileHeaderUlUsUs = .text:0x8042A9E0; // type:function size:0x74 +ReadNextCharUTF8__Q34nw4r2ut14CharStrmReaderFv = .text:0x8042AA60; // type:function size:0x78 +ReadNextCharUTF16__Q34nw4r2ut14CharStrmReaderFv = .text:0x8042AAE0; // type:function size:0x1C +ReadNextCharCP1252__Q34nw4r2ut14CharStrmReaderFv = .text:0x8042AB00; // type:function size:0x1C +ReadNextCharSJIS__Q34nw4r2ut14CharStrmReaderFv = .text:0x8042AB20; // type:function size:0x60 +__ct__Q34nw4r2ut19TagProcessorBaseFv = .text:0x8042AB80; // type:function size:0x10 +__dt__Q34nw4r2ut19TagProcessorBaseFv = .text:0x8042AB90; // type:function size:0x40 +Process__Q34nw4r2ut19TagProcessorBase = .text:0x8042ABD0; // type:function size:0x12C +CalcRect__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut4RectUsPQ34nw4r2ut15PrintContext = .text:0x8042AD00; // type:function size:0x1E4 +ProcessLinefeed__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut15PrintContext = .text:0x8042AEF0; // type:function size:0x64 +ProcessTab__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut15PrintContext = .text:0x8042AF60; // type:function size:0xC4 +__ct__Q34nw4r2ut19TagProcessorBaseFv = .text:0x8042B030; // type:function size:0x10 +__dt__Q34nw4r2ut19TagProcessorBaseFv = .text:0x8042B040; // type:function size:0x40 +Process__Q34nw4r2ut19TagProcessorBaseFUsPQ34nw4r2ut15PrintContext = .text:0x8042B080; // type:function size:0x12C +CalcRect__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut4RectUsPQ34nw4r2ut15PrintContext = .text:0x8042B1B0; // type:function size:0x1E4 +ProcessLinefeed__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut15PrintContext = .text:0x8042B3A0; // type:function size:0x64 +ProcessTab__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut15PrintContext = .text:0x8042B410; // type:function size:0xC4 +ReadAsync__Q34nw4r2ut8IOStreamFPvUlPFlPQ34nw4r2ut8IOStreamPv_vPv = .text:0x8042B4E0; // type:function size:0x8 +Write__Q34nw4r2ut8IOStreamFPCvUl = .text:0x8042B4F0; // type:function size:0x8 +WriteAsync__Q34nw4r2ut8IOStreamFPCvUlPFlPQ34nw4r2ut8IOStreamPv_vPv = .text:0x8042B500; // type:function size:0x8 +IsBusy__Q34nw4r2ut8IOStreamCFv = .text:0x8042B510; // type:function size:0x8 +GetBufferAlign__Q34nw4r2ut8IOStreamCFv = .text:0x8042B520; // type:function size:0x8 +GetSizeAlign__Q34nw4r2ut8IOStreamCFv = .text:0x8042B530; // type:function size:0x8 +GetOffsetAlign__Q34nw4r2ut8IOStreamCFv = .text:0x8042B540; // type:function size:0x8 +__sinit_\ut_IOStream_cpp = .text:0x8042B550; // type:function size:0xC +Cancel__Q34nw4r2ut10FileStreamFv = .text:0x8042B560; // type:function size:0x4 +CancelAsync__Q34nw4r2ut10FileStreamFPFlPQ34nw4r2ut8IOStreamPv_vPv = .text:0x8042B570; // type:function size:0x8 +Skip__Q44nw4r2ut10FileStream12FilePositionFl = .text:0x8042B580; // type:function size:0x64 +Append__Q44nw4r2ut10FileStream12FilePositionFl = .text:0x8042B5F0; // type:function size:0x50 +Seek__Q44nw4r2ut10FileStream12FilePositionFlUl = .text:0x8042B640; // type:function size:0x88 +GetRuntimeTypeInfo__Q34nw4r2ut10FileStreamCFv = .text:0x8042B6D0; // type:function size:0x8 +__sinit_\ut_FileStream_cpp = .text:0x8042B6E0; // type:function size:0xC +DvdAsyncCallback___Q34nw4r2ut13DvdFileStreamFlP11DVDFileInfo = .text:0x8042B6F0; // type:function size:0x2C +DvdCBAsyncCallback___Q34nw4r2ut13DvdFileStreamFlP15DVDCommandBlock = .text:0x8042B720; // type:function size:0x28 +__ct__Q34nw4r2ut13DvdFileStreamFl = .text:0x8042B750; // type:function size:0xBC +__ct__Q34nw4r2ut13DvdFileStreamFPC11DVDFileInfob = .text:0x8042B810; // type:function size:0x130 +__dt__Q34nw4r2ut13DvdFileStreamFv = .text:0x8042B940; // type:function size:0x78 +Close__Q34nw4r2ut13DvdFileStreamFv = .text:0x8042B9C0; // type:function size:0x50 +Read__Q34nw4r2ut13DvdFileStreamFPvUl = .text:0x8042BA10; // type:function size:0x88 +ReadAsync__Q34nw4r2ut13DvdFileStreamFPvUlPFlPQ34nw4r2ut8IOStreamPv_vPv = .text:0x8042BAA0; // type:function size:0xF4 +Peek__Q34nw4r2ut13DvdFileStreamFPvUl = .text:0x8042BBA0; // type:function size:0x3C +PeekAsync__Q34nw4r2ut13DvdFileStreamFPvUlPFlPQ34nw4r2ut8IOStreamPv_vPv = .text:0x8042BBE0; // type:function size:0x80 +Seek__Q34nw4r2ut13DvdFileStreamFlUl = .text:0x8042BC60; // type:function size:0x8 +Cancel__Q34nw4r2ut13DvdFileStreamFv = .text:0x8042BC70; // type:function size:0x8 +CancelAsync__Q34nw4r2ut13DvdFileStreamFPFlPQ34nw4r2ut8IOStreamPv_vPv = .text:0x8042BC80; // type:function size:0x5C +GetBufferAlign__Q34nw4r2ut13DvdFileStreamCFv = .text:0x8042BCE0; // type:function size:0x8 +GetSizeAlign__Q34nw4r2ut13DvdFileStreamCFv = .text:0x8042BCF0; // type:function size:0x8 +GetOffsetAlign__Q34nw4r2ut13DvdFileStreamCFv = .text:0x8042BD00; // type:function size:0x8 +CanCancel__Q34nw4r2ut13DvdFileStreamCFv = .text:0x8042BD10; // type:function size:0x8 +CanWrite__Q34nw4r2ut13DvdFileStreamCFv = .text:0x8042BD20; // type:function size:0x8 +CanRead__Q34nw4r2ut13DvdFileStreamCFv = .text:0x8042BD30; // type:function size:0x8 +CanSeek__Q34nw4r2ut13DvdFileStreamCFv = .text:0x8042BD40; // type:function size:0x8 +CanAsync__Q34nw4r2ut13DvdFileStreamCFv = .text:0x8042BD50; // type:function size:0x8 +GetSize__Q34nw4r2ut13DvdFileStreamCFv = .text:0x8042BD60; // type:function size:0x8 +Tell__Q34nw4r2ut13DvdFileStreamCFv = .text:0x8042BD70; // type:function size:0x8 +IsBusy__Q34nw4r2ut13DvdFileStreamCFv = .text:0x8042BD80; // type:function size:0x8 +GetRuntimeTypeInfo__Q34nw4r2ut13DvdFileStreamCFv = .text:0x8042BD90; // type:function size:0x8 +__sinit_\ut_DvdFileStream_cpp = .text:0x8042BDA0; // type:function size:0xC +__ct__Q34nw4r2ut19DvdLockedFileStreamFl = .text:0x8042BDB0; // type:function size:0x84 +__ct__Q34nw4r2ut19DvdLockedFileStreamFPC11DVDFileInfob = .text:0x8042BE40; // type:function size:0x84 +__dt__Q34nw4r2ut19DvdLockedFileStreamFv = .text:0x8042BED0; // type:function size:0x58 +Close__Q34nw4r2ut19DvdLockedFileStreamFv = .text:0x8042BF30; // type:function size:0x34 +Read__Q34nw4r2ut19DvdLockedFileStreamFPvUl = .text:0x8042BF70; // type:function size:0xD4 +Peek__Q34nw4r2ut19DvdLockedFileStreamFPvUl = .text:0x8042C050; // type:function size:0xD4 +Cancel__Q34nw4r2ut19DvdLockedFileStreamFv = .text:0x8042C130; // type:function size:0x58 +CanAsync__Q34nw4r2ut19DvdLockedFileStreamCFv = .text:0x8042C190; // type:function size:0x8 +PeekAsync__Q34nw4r2ut19DvdLockedFileStreamFPvUlPFlPQ34nw4r2ut8IOStreamPv_vPv = .text:0x8042C1A0; // type:function size:0x8 +ReadAsync__Q34nw4r2ut19DvdLockedFileStreamFPvUlPFlPQ34nw4r2ut8IOStreamPv_vPv = .text:0x8042C1B0; // type:function size:0x8 +GetRuntimeTypeInfo__Q34nw4r2ut19DvdLockedFileStreamCFv = .text:0x8042C1C0; // type:function size:0x8 +__sinit_\ut_DvdLockedFileStream_cpp = .text:0x8042C1D0; // type:function size:0xC +NandAsyncCallback___Q34nw4r2ut14NandFileStreamFlP16NANDCommandBlock = .text:0x8042C1E0; // type:function size:0x2C +__ct__Q34nw4r2ut14NandFileStreamFPCcUl = .text:0x8042C210; // type:function size:0x70 +__ct__Q34nw4r2ut14NandFileStreamFPC12NANDFileInfoUlb = .text:0x8042C280; // type:function size:0x70 +__dt__Q34nw4r2ut14NandFileStreamFv = .text:0x8042C2F0; // type:function size:0x78 +Open__Q34nw4r2ut14NandFileStreamFPCcUl = .text:0x8042C370; // type:function size:0xE8 +Open__Q34nw4r2ut14NandFileStreamFPC12NANDFileInfoUlb = .text:0x8042C460; // type:function size:0x258 +Close__Q34nw4r2ut14NandFileStreamFv = .text:0x8042C6C0; // type:function size:0x50 +Read__Q34nw4r2ut14NandFileStreamFPvUl = .text:0x8042C710; // type:function size:0x7C +ReadAsync__Q34nw4r2ut14NandFileStreamFPvUlPFlPQ34nw4r2ut8IOStreamPv_vPv = .text:0x8042C790; // type:function size:0xA4 +Write__Q34nw4r2ut14NandFileStreamFPCvUl = .text:0x8042C840; // type:function size:0x7C +WriteAsync__Q34nw4r2ut14NandFileStreamFPCvUlPFlPQ34nw4r2ut8IOStreamPv_vPv = .text:0x8042C8C0; // type:function size:0xA8 +Seek__Q34nw4r2ut14NandFileStreamFlUl = .text:0x8042C970; // type:function size:0x8 +GetBufferAlign__Q34nw4r2ut14NandFileStreamCFv = .text:0x8042C980; // type:function size:0x8 +GetSizeAlign__Q34nw4r2ut14NandFileStreamCFv = .text:0x8042C990; // type:function size:0x8 +GetOffsetAlign__Q34nw4r2ut14NandFileStreamCFv = .text:0x8042C9A0; // type:function size:0x8 +CanCancel__Q34nw4r2ut14NandFileStreamCFv = .text:0x8042C9B0; // type:function size:0x8 +CanWrite__Q34nw4r2ut14NandFileStreamCFv = .text:0x8042C9C0; // type:function size:0x8 +CanRead__Q34nw4r2ut14NandFileStreamCFv = .text:0x8042C9D0; // type:function size:0x8 +CanSeek__Q34nw4r2ut14NandFileStreamCFv = .text:0x8042C9E0; // type:function size:0x8 +CanAsync__Q34nw4r2ut14NandFileStreamCFv = .text:0x8042C9F0; // type:function size:0x8 +GetSize__Q34nw4r2ut14NandFileStreamCFv = .text:0x8042CA00; // type:function size:0x8 +Tell__Q34nw4r2ut14NandFileStreamCFv = .text:0x8042CA10; // type:function size:0x8 +IsBusy__Q34nw4r2ut14NandFileStreamCFv = .text:0x8042CA20; // type:function size:0x8 +GetRuntimeTypeInfo__Q34nw4r2ut14NandFileStreamCFv = .text:0x8042CA30; // type:function size:0x8 +__sinit_\ut_NandFileStream_cpp = .text:0x8042CA40; // type:function size:0xC +Enable__Q34nw4r2ut2LCFv = .text:0x8042CA50; // type:function size:0x60 +Disable__Q34nw4r2ut2LCFv = .text:0x8042CAB0; // type:function size:0x78 +Lock__Q34nw4r2ut2LCFv = .text:0x8042CB30; // type:function size:0x70 +Unlock__Q34nw4r2ut2LCFv = .text:0x8042CBA0; // type:function size:0x40 +LoadBlocks__Q34nw4r2ut2LCFPvPvUl = .text:0x8042CBE0; // type:function size:0x4 +StoreBlocks__Q34nw4r2ut2LCFPvPvUl = .text:0x8042CBF0; // type:function size:0x4 +StoreData__Q34nw4r2ut2LCFPvPvUl = .text:0x8042CC00; // type:function size:0x4 +__sinit_\ut_LockedCache_cpp = .text:0x8042CC10; // type:function size:0x18 +InitReaderFunc__Q34nw4r2ut4FontFQ34nw4r2ut12FontEncoding = .text:0x8042CC30; // type:function size:0xA4 +__dt__Q34nw4r2ut4FontFv = .text:0x8042CCE0; // type:function size:0x40 +__ct__Q44nw4r2ut6detail11ResFontBaseFv = .text:0x8042CD20; // type:function size:0x54 +__dt__Q44nw4r2ut6detail11ResFontBaseFv = .text:0x8042CD80; // type:function size:0x40 +SetResourceBuffer__Q44nw4r2ut6detail11ResFontBaseFPvPQ34nw4r2ut15FontInformation = .text:0x8042CDC0; // type:function size:0xC +RemoveResourceBuffer__Q44nw4r2ut6detail11ResFontBaseFv = .text:0x8042CDD0; // type:function size:0x18 +GetWidth__Q44nw4r2ut6detail11ResFontBaseCFv = .text:0x8042CDF0; // type:function size:0xC +GetHeight__Q44nw4r2ut6detail11ResFontBaseCFv = .text:0x8042CE00; // type:function size:0xC +GetAscent__Q44nw4r2ut6detail11ResFontBaseCFv = .text:0x8042CE10; // type:function size:0xC +GetDescent__Q44nw4r2ut6detail11ResFontBaseCFv = .text:0x8042CE20; // type:function size:0x14 +GetBaselinePos__Q44nw4r2ut6detail11ResFontBaseCFv = .text:0x8042CE40; // type:function size:0x14 +GetCellHeight__Q44nw4r2ut6detail11ResFontBaseCFv = .text:0x8042CE60; // type:function size:0x10 +GetCellWidth__Q44nw4r2ut6detail11ResFontBaseCFv = .text:0x8042CE70; // type:function size:0x10 +GetMaxCharWidth__Q44nw4r2ut6detail11ResFontBaseCFv = .text:0x8042CE80; // type:function size:0x10 +GetType__Q44nw4r2ut6detail11ResFontBaseCFv = .text:0x8042CE90; // type:function size:0x8 +GetTextureFormat__Q44nw4r2ut6detail11ResFontBaseCFv = .text:0x8042CEA0; // type:function size:0x10 +GetLineFeed__Q44nw4r2ut6detail11ResFontBaseCFv = .text:0x8042CEB0; // type:function size:0x10 +GetDefaultCharWidths__Q44nw4r2ut6detail11ResFontBaseCFv = .text:0x8042CEC0; // type:function size:0x18 +SetDefaultCharWidths__Q44nw4r2ut6detail11ResFontBaseFRCQ34nw4r2ut10CharWidths = .text:0x8042CEE0; // type:function size:0x20 +SetAlternateChar__Q44nw4r2ut6detail11ResFontBaseFUs = .text:0x8042CF00; // type:function size:0xBC +SetLineFeed__Q44nw4r2ut6detail11ResFontBaseFi = .text:0x8042CFC0; // type:function size:0xC +GetCharWidth__Q44nw4r2ut6detail11ResFontBaseCFUs = .text:0x8042CFD0; // type:function size:0x44 +GetCharWidths__Q44nw4r2ut6detail11ResFontBaseCFUs = .text:0x8042D020; // type:function size:0x114 +GetGlyph__Q44nw4r2ut6detail11ResFontBaseCFPQ34nw4r2ut5GlyphUs = .text:0x8042D140; // type:function size:0xC4 +HasGlyph__Q44nw4r2ut6detail11ResFontBaseCFUs = .text:0x8042D210; // type:function size:0xBC +GetEncoding__Q44nw4r2ut6detail11ResFontBaseCFv = .text:0x8042D2D0; // type:function size:0xC +FindGlyphIndex__Q44nw4r2ut6detail11ResFontBaseCFPCQ34nw4r2ut11FontCodeMapUs = .text:0x8042D2E0; // type:function size:0xCC +GetGlyphFromIndex__Q44nw4r2ut6detail11ResFontBaseCFPQ34nw4r2ut5GlyphUs = .text:0x8042D3B0; // type:function size:0x108 +__ct__Q34nw4r2ut7ResFontFv = .text:0x8042D4C0; // type:function size:0x3C +__dt__Q34nw4r2ut7ResFontFv = .text:0x8042D500; // type:function size:0x58 +SetResource__Q34nw4r2ut7ResFontFPv = .text:0x8042D560; // type:function size:0x148 +RemoveResource__Q34nw4r2ut7ResFontFv = .text:0x8042D6B0; // type:function size:0x4 +Rebuild__Q34nw4r2ut7ResFontFPQ34nw4r2ut16BinaryFileHeader = .text:0x8042D6C0; // type:function size:0x10C +__ct__Q34nw4r2ut10CharWriterFv = .text:0x8042D7D0; // type:function size:0x380 +__dt__Q34nw4r2ut10CharWriterFv = .text:0x8042DB50; // type:function size:0x40 +SetupGX__Q34nw4r2ut10CharWriterFv = .text:0x8042DB90; // type:function size:0x930 +SetFontSize__Q34nw4r2ut10CharWriterFff = .text:0x8042E4C0; // type:function size:0xC4 +SetFontSize__Q34nw4r2ut10CharWriterFf = .text:0x8042E590; // type:function size:0x78 +GetFontWidth__Q34nw4r2ut10CharWriterCFv = .text:0x8042E610; // type:function size:0x60 +GetFontHeight__Q34nw4r2ut10CharWriterCFv = .text:0x8042E670; // type:function size:0x60 +GetFontAscent__Q34nw4r2ut10CharWriterCFv = .text:0x8042E6D0; // type:function size:0x60 +Print__Q34nw4r2ut10CharWriterFUs = .text:0x8042E730; // type:function size:0x130 +PrintGlyph__Q34nw4r2ut10CharWriterFfffRCQ34nw4r2ut5Glyph = .text:0x8042E860; // type:function size:0x27C +UpdateVertexColor__Q34nw4r2ut10CharWriterFv = .text:0x8042EAE0; // type:function size:0x150 +SetupGXWithColorMapping__Q34nw4r2ut10CharWriterFQ34nw4r2ut5ColorQ34nw4r2ut5Color = .text:0x8042EC30; // type:function size:0x2EC +__ct__Q34nw4r2ut17TextWriterBaseFv = .text:0x8042EF20; // type:function size:0x5C +__dt__Q34nw4r2ut17TextWriterBaseFv = .text:0x8042EF80; // type:function size:0x58 +SetLineHeight__Q34nw4r2ut17TextWriterBaseFf = .text:0x8042EFE0; // type:function size:0x90 +GetLineHeight__Q34nw4r2ut17TextWriterBaseCFv = .text:0x8042F070; // type:function size:0x7C +CalcFormatStringWidth__Q34nw4r2ut17TextWriterBaseCFPCce = .text:0x8042F0F0; // type:function size:0x204 +CalcFormatStringHeight__Q34nw4r2ut17TextWriterBaseCFPCce = .text:0x8042F300; // type:function size:0x204 +CalcFormatStringRect__Q34nw4r2ut17TextWriterBaseCFPQ34nw4r2ut4RectPCce = .text:0x8042F510; // type:function size:0x1E0 +CalcVStringRect__Q34nw4r2ut17TextWriterBaseCFPQ34nw4r2ut4RectPCcP16__va_list_struct = .text:0x8042F6F0; // type:function size:0x180 +CalcStringWidth__Q34nw4r2ut17TextWriterBaseCFPCci = .text:0x8042F870; // type:function size:0x144 +CalcStringHeight__Q34nw4r2ut17TextWriterBaseCFPCci = .text:0x8042F9C0; // type:function size:0x144 +CalcStringRect__Q34nw4r2ut17TextWriterBaseCFPQ34nw4r2ut4RectPCci = .text:0x8042FB10; // type:function size:0x118 +Printf__Q34nw4r2ut17TextWriterBaseFPCce = .text:0x8042FC30; // type:function size:0x21C +VPrintf__Q34nw4r2ut17TextWriterBaseFPCcP16__va_list_struct = .text:0x8042FE50; // type:function size:0x1B8 +Print__Q34nw4r2ut17TextWriterBaseFPCci = .text:0x80430010; // type:function size:0x140 +PrintfMutable__Q34nw4r2ut17TextWriterBaseFPCce = .text:0x80430150; // type:function size:0x110 +VPrintfMutable__Q34nw4r2ut17TextWriterBaseFPCcP16__va_list_struct = .text:0x80430260; // type:function size:0xAC +PrintMutable__Q34nw4r2ut17TextWriterBaseFPCci = .text:0x80430310; // type:function size:0x8 +VSNPrintf__Q34nw4r2ut17TextWriterBaseFPcUlPCcP16__va_list_struct = .text:0x80430320; // type:function size:0x4 +CalcLineWidth__Q34nw4r2ut17TextWriterBaseFPCci = .text:0x80430330; // type:function size:0x154 +CalcLineRectImpl__Q34nw4r2ut17TextWriterBaseFPQ34nw4r2ut4RectPPCci = .text:0x80430490; // type:function size:0x5BC +GetCharSpace__Q34nw4r2ut17TextWriterBaseCFv = .text:0x80430A50; // type:function size:0x8 +CalcStringRectImpl__Q34nw4r2ut17TextWriterBaseFPQ34nw4r2ut4RectPCci = .text:0x80430A60; // type:function size:0x110 +PrintImpl__Q34nw4r2ut17TextWriterBaseFPCcib = .text:0x80430B70; // type:function size:0x804 +AdjustCursor__Q34nw4r2ut17TextWriterBaseFPfPfPCci = .text:0x80431380; // type:function size:0x4D8 +IsDrawFlagSet__Q34nw4r2ut17TextWriterBaseCFUlUl = .text:0x80431860; // type:function size:0x18 +__ct__Q34nw4r2ut17TextWriterBaseFv = .text:0x80431880; // type:function size:0x5C +__dt__Q34nw4r2ut17TextWriterBaseFv = .text:0x804318E0; // type:function size:0x58 +SetLineHeight__Q34nw4r2ut17TextWriterBaseFf = .text:0x80431940; // type:function size:0x90 +GetLineHeight__Q34nw4r2ut17TextWriterBaseCFv = .text:0x804319D0; // type:function size:0x7C +CalcFormatStringWidth__Q34nw4r2ut17TextWriterBaseCFPCwe = .text:0x80431A50; // type:function size:0x204 +CalcFormatStringHeight__Q34nw4r2ut17TextWriterBaseCFPCwe = .text:0x80431C60; // type:function size:0x204 +CalcFormatStringRect__Q34nw4r2ut17TextWriterBaseCFPQ34nw4r2ut4RectPCwe = .text:0x80431E70; // type:function size:0x1E0 +CalcVStringRect__Q34nw4r2ut17TextWriterBaseCFPQ34nw4r2ut4RectPCwP16__va_list_struct = .text:0x80432050; // type:function size:0x180 +CalcStringWidth__Q34nw4r2ut17TextWriterBaseCFPCwi = .text:0x804321D0; // type:function size:0x144 +CalcStringHeight__Q34nw4r2ut17TextWriterBaseCFPCwi = .text:0x80432320; // type:function size:0x144 +CalcStringRect__Q34nw4r2ut17TextWriterBaseCFPQ34nw4r2ut4RectPCwi = .text:0x80432470; // type:function size:0x118 +Printf__Q34nw4r2ut17TextWriterBaseFPCwe = .text:0x80432590; // type:function size:0x21C +VPrintf__Q34nw4r2ut17TextWriterBaseFPCwP16__va_list_struct = .text:0x804327B0; // type:function size:0x1B8 +Print__Q34nw4r2ut17TextWriterBaseFPCwi = .text:0x80432970; // type:function size:0x140 +PrintfMutable__Q34nw4r2ut17TextWriterBaseFPCwe = .text:0x80432AB0; // type:function size:0x110 +VPrintfMutable__Q34nw4r2ut17TextWriterBaseFPCwP16__va_list_struct = .text:0x80432BC0; // type:function size:0xAC +PrintMutable__Q34nw4r2ut17TextWriterBaseFPCwi = .text:0x80432C70; // type:function size:0x8 +VSNPrintf__Q34nw4r2ut17TextWriterBaseFPwUlPCwP16__va_list_struct = .text:0x80432C80; // type:function size:0x4 +CalcLineWidth__Q34nw4r2ut17TextWriterBaseFPCwi = .text:0x80432C90; // type:function size:0x154 +CalcLineRectImpl__Q34nw4r2ut17TextWriterBaseFPQ34nw4r2ut4RectPPCwi = .text:0x80432DF0; // type:function size:0x5BC +GetCharSpace__Q34nw4r2ut17TextWriterBaseCFv = .text:0x804333B0; // type:function size:0x8 +CalcStringRectImpl__Q34nw4r2ut17TextWriterBaseFPQ34nw4r2ut4RectPCwi = .text:0x804333C0; // type:function size:0x120 +PrintImpl__Q34nw4r2ut17TextWriterBaseFPCwib = .text:0x804334E0; // type:function size:0x828 +AdjustCursor__Q34nw4r2ut17TextWriterBaseFPfPfPCwi = .text:0x80433D10; // type:function size:0x4D8 +IsDrawFlagSet__Q34nw4r2ut17TextWriterBaseCFUlUl = .text:0x804341F0; // type:function size:0x18 +__sinit_\ut_TextWriterBase_cpp = .text:0x80434210; // type:function size:0x84 DirectPrint_Init__Q24nw4r2dbFv = .text:0x804342A0; // type:function size:0xB4 DirectPrint_IsActive__Q24nw4r2dbFv = .text:0x80434360; // type:function size:0x28 DirectPrint_EraseXfb__Q24nw4r2dbFiiii = .text:0x80434390; // type:function size:0x190 diff --git a/configure.py b/configure.py index 075220c3..5336a084 100644 --- a/configure.py +++ b/configure.py @@ -319,6 +319,20 @@ config.libs = [ [ Object(Matching, "nw4r/ut/ut_list.cpp"), Object(Matching, "nw4r/ut/ut_LinkList.cpp"), + Object(Matching, "nw4r/ut/ut_binaryFileFormat.cpp"), + Object(NonMatching, "nw4r/ut/ut_CharStrmReader.cpp"), + Object(NonMatching, "nw4r/ut/ut_TagProcessorBase.cpp"), + Object(NonMatching, "nw4r/ut/ut_IOStream.cpp"), + Object(NonMatching, "nw4r/ut/ut_FileStream.cpp"), + Object(NonMatching, "nw4r/ut/ut_DvdFileStream.cpp"), + Object(NonMatching, "nw4r/ut/ut_DvdLockedFileStream.cpp"), + Object(NonMatching, "nw4r/ut/ut_NandFileStream.cpp"), + Object(NonMatching, "nw4r/ut/ut_LockedCache.cpp"), + Object(NonMatching, "nw4r/ut/ut_Font.cpp"), + Object(NonMatching, "nw4r/ut/ut_ResFontBase.cpp"), + Object(NonMatching, "nw4r/ut/ut_ResFont.cpp"), + Object(NonMatching, "nw4r/ut/ut_CharWriter.cpp"), + Object(NonMatching, "nw4r/ut/ut_TextWriterBase.cpp"), ], ), # EGG diff --git a/src/nw4r/ut/ut_CharStrmReader.cpp b/src/nw4r/ut/ut_CharStrmReader.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/ut/ut_CharWriter.cpp b/src/nw4r/ut/ut_CharWriter.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/ut/ut_DvdFileStream.cpp b/src/nw4r/ut/ut_DvdFileStream.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/ut/ut_DvdLockedFileStream.cpp b/src/nw4r/ut/ut_DvdLockedFileStream.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/ut/ut_FileStream.cpp b/src/nw4r/ut/ut_FileStream.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/ut/ut_Font.cpp b/src/nw4r/ut/ut_Font.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/ut/ut_IOStream.cpp b/src/nw4r/ut/ut_IOStream.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/ut/ut_LockedCache.cpp b/src/nw4r/ut/ut_LockedCache.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/ut/ut_NandFileStream.cpp b/src/nw4r/ut/ut_NandFileStream.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/ut/ut_ResFont.cpp b/src/nw4r/ut/ut_ResFont.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/ut/ut_ResFontBase.cpp b/src/nw4r/ut/ut_ResFontBase.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/ut/ut_TagProcessorBase.cpp b/src/nw4r/ut/ut_TagProcessorBase.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/nw4r/ut/ut_TextWriterBase.cpp b/src/nw4r/ut/ut_TextWriterBase.cpp new file mode 100644 index 00000000..e69de29b From e1f491d2d13863434f785330b9830a63d338c3ce Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 4 May 2024 22:02:12 -0400 Subject: [PATCH 19/23] fix duplicated split oops --- config/SOUE01/splits.txt | 3 --- configure.py | 1 - 2 files changed, 4 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index cd67bf1a..bb76869b 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -222,9 +222,6 @@ nw4r/ut/ut_TextWriterBase.cpp: .text start:0x8042EF20 end:0x80434294 .ctors start:0x804DB950 end:0x804DB954 -nw4r/ut/ut_binaryFileFormat.cpp: - .text start:0x8042A9E0 end:0x8042AA54 - nw4r/db/db_directPrint.cpp: .text start:0x804342A0 end:0x80434E9C .rodata start:0x804F5D28 end:0x804F5FDC diff --git a/configure.py b/configure.py index 39cc4ffe..5336a084 100644 --- a/configure.py +++ b/configure.py @@ -333,7 +333,6 @@ config.libs = [ Object(NonMatching, "nw4r/ut/ut_ResFont.cpp"), Object(NonMatching, "nw4r/ut/ut_CharWriter.cpp"), Object(NonMatching, "nw4r/ut/ut_TextWriterBase.cpp"), - Object(Matching, "nw4r/ut/ut_binaryFileFormat.cpp"), ], ), # EGG From 498660cf6bf9420d6cb8054f02e63b945fa35e35 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 4 May 2024 23:29:06 -0400 Subject: [PATCH 20/23] match ut_TagProcessorBase. thanks ogws --- config/SOUE01/config.yml | 4 ++ config/SOUE01/splits.txt | 2 + config/SOUE01/symbols.txt | 6 +- configure.py | 3 +- include/nw4r/ut/ut_TagProcessorBase.h | 20 +++--- src/nw4r/ut/ut_TagProcessorBase.cpp | 88 +++++++++++++++++++++++++++ 6 files changed, 110 insertions(+), 13 deletions(-) diff --git a/config/SOUE01/config.yml b/config/SOUE01/config.yml index 9bd91d28..6b77249c 100644 --- a/config/SOUE01/config.yml +++ b/config/SOUE01/config.yml @@ -6,6 +6,10 @@ mw_comment_version: 8 quick_analysis: true force_active: [ "searchBaseByID__10fManager_cF9fBaseID_e", + "ProcessLinefeed__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut15PrintContext", + "ProcessTab__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut15PrintContext", + "ProcessLinefeed__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut15PrintContext", + "ProcessTab__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut15PrintContext", ] # modules: # - object: orig/SOUE01/rels/d_a_asura_bulletNP.rel diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index bb76869b..fc39b065 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -181,6 +181,8 @@ nw4r/ut/ut_CharStrmReader.cpp: nw4r/ut/ut_TagProcessorBase.cpp: .text start:0x8042AB80 end:0x8042B4D4 + .data start:0x8056BD50 end:0x8056BD78 + .sdata2 start:0x8057EB68 end:0x8057EB70 nw4r/ut/ut_IOStream.cpp: .text start:0x8042B4E0 end:0x8042B55C diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index cea99b0e..bcdb8b36 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -23946,7 +23946,7 @@ ReadNextCharCP1252__Q34nw4r2ut14CharStrmReaderFv = .text:0x8042AB00; // type:fun ReadNextCharSJIS__Q34nw4r2ut14CharStrmReaderFv = .text:0x8042AB20; // type:function size:0x60 __ct__Q34nw4r2ut19TagProcessorBaseFv = .text:0x8042AB80; // type:function size:0x10 __dt__Q34nw4r2ut19TagProcessorBaseFv = .text:0x8042AB90; // type:function size:0x40 -Process__Q34nw4r2ut19TagProcessorBase = .text:0x8042ABD0; // type:function size:0x12C +Process__Q34nw4r2ut19TagProcessorBaseFUsPQ34nw4r2ut15PrintContext = .text:0x8042ABD0; // type:function size:0x12C CalcRect__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut4RectUsPQ34nw4r2ut15PrintContext = .text:0x8042AD00; // type:function size:0x1E4 ProcessLinefeed__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut15PrintContext = .text:0x8042AEF0; // type:function size:0x64 ProcessTab__Q34nw4r2ut19TagProcessorBaseFPQ34nw4r2ut15PrintContext = .text:0x8042AF60; // type:function size:0xC4 @@ -36943,8 +36943,8 @@ jumptable_8056BCB8 = .data:0x8056BCB8; // type:object size:0x20 scope:local jumptable_8056BCD8 = .data:0x8056BCD8; // type:object size:0x20 scope:local @1687 = .data:0x8056BCF8; // type:object size:0x21 scope:local data:string lbl_8056BD20 = .data:0x8056BD20; // type:object size:0x30 -lbl_8056BD50 = .data:0x8056BD50; // type:object size:0x14 -lbl_8056BD64 = .data:0x8056BD64; // type:object size:0x14 +__vt__Q34nw4r2ut19TagProcessorBase = .data:0x8056BD50; // type:object size:0x14 scope:weak +__vt__Q34nw4r2ut19TagProcessorBase = .data:0x8056BD64; // type:object size:0x14 scope:weak lbl_8056BD78 = .data:0x8056BD78; // type:object size:0x68 lbl_8056BDE0 = .data:0x8056BDE0; // type:object size:0x68 lbl_8056BE48 = .data:0x8056BE48; // type:object size:0x60 diff --git a/configure.py b/configure.py index 5336a084..f86cf316 100644 --- a/configure.py +++ b/configure.py @@ -201,6 +201,7 @@ cflags_egg = [ cflags_nw4r = [ *cflags_base, "-ipa file", + "-fp_contract off", ] # REL flags @@ -321,7 +322,7 @@ config.libs = [ Object(Matching, "nw4r/ut/ut_LinkList.cpp"), Object(Matching, "nw4r/ut/ut_binaryFileFormat.cpp"), Object(NonMatching, "nw4r/ut/ut_CharStrmReader.cpp"), - Object(NonMatching, "nw4r/ut/ut_TagProcessorBase.cpp"), + Object(Matching, "nw4r/ut/ut_TagProcessorBase.cpp"), Object(NonMatching, "nw4r/ut/ut_IOStream.cpp"), Object(NonMatching, "nw4r/ut/ut_FileStream.cpp"), Object(NonMatching, "nw4r/ut/ut_DvdFileStream.cpp"), diff --git a/include/nw4r/ut/ut_TagProcessorBase.h b/include/nw4r/ut/ut_TagProcessorBase.h index f58ff6d7..3c8f19ea 100644 --- a/include/nw4r/ut/ut_TagProcessorBase.h +++ b/include/nw4r/ut/ut_TagProcessorBase.h @@ -10,9 +10,10 @@ enum PrintFlags { PRINTFLAGS_CHARSPACE = (1 << 0), }; -template struct PrintContext { - TextWriterBase* writer; // at 0x0 - const T* str; // at 0x4 +template +struct PrintContext { + TextWriterBase *writer; // at 0x0 + const T *str; // at 0x4 f32 x; // at 0x8 f32 y; // at 0xC u32 flags; // at 0x10 @@ -26,17 +27,18 @@ enum Operation { OPERATION_END_DRAW }; -template class TagProcessorBase { +template +class TagProcessorBase { public: TagProcessorBase(); virtual ~TagProcessorBase(); // at 0x8 - virtual Operation Process(u16 ch, PrintContext* ctx); // at 0xC - virtual Operation CalcRect(Rect* rect, u16 ch, - PrintContext* ctx); // at 0x10 + virtual Operation Process(u16 ch, PrintContext *ctx); // at 0xC + virtual Operation CalcRect(Rect *rect, u16 ch, + PrintContext *ctx); // at 0x10 - void ProcessTab(PrintContext* ctx); - void ProcessLinefeed(PrintContext* ctx); + void ProcessLinefeed(PrintContext *ctx); + void ProcessTab(PrintContext *ctx); }; } // namespace ut diff --git a/src/nw4r/ut/ut_TagProcessorBase.cpp b/src/nw4r/ut/ut_TagProcessorBase.cpp index e69de29b..dc001042 100644 --- a/src/nw4r/ut/ut_TagProcessorBase.cpp +++ b/src/nw4r/ut/ut_TagProcessorBase.cpp @@ -0,0 +1,88 @@ +#include + +namespace nw4r { +namespace ut { + +template +TagProcessorBase::TagProcessorBase() {} + +template +TagProcessorBase::~TagProcessorBase() {} + +template +Operation TagProcessorBase::Process(u16 ch, PrintContext *ctx) { + switch (ch) { + case '\n': + ProcessLinefeed(ctx); + return OPERATION_NEXT_LINE; + case '\t': + ProcessTab(ctx); + return OPERATION_NO_CHAR_SPACE; + } + + return OPERATION_DEFAULT; +} + +template +Operation TagProcessorBase::CalcRect(Rect *rect, u16 ch, PrintContext *ctx) { + switch (ch) { + case '\n': { + const TextWriterBase &writer = *ctx->writer; + rect->right = writer.GetCursorX(); + rect->top = writer.GetCursorY(); + ProcessLinefeed(ctx); + rect->left = writer.GetCursorX(); + rect->bottom = writer.GetCursorY() + ctx->writer->GetFontHeight(); + rect->Normalize(); + return OPERATION_NEXT_LINE; + } + case '\t': { + const TextWriterBase &writer = *ctx->writer; + rect->left = writer.GetCursorX(); + ProcessTab(ctx); + rect->right = writer.GetCursorX(); + rect->top = writer.GetCursorY(); + rect->bottom = rect->top + writer.GetFontHeight(); + rect->Normalize(); + return OPERATION_NO_CHAR_SPACE; + } + } + + return OPERATION_DEFAULT; +} + +template +void TagProcessorBase::ProcessTab(PrintContext *ctx) { + TextWriterBase &writer = *ctx->writer; + + int tabWidth = writer.GetTabWidth(); + if (tabWidth <= 0) { + return; + } + + f32 charWidth = writer.IsWidthFixed() ? writer.GetFixedWidth() : writer.GetFontWidth(); + + f32 dx = writer.GetCursorX() - ctx->x; + f32 tabPixel = tabWidth * charWidth; + int numTab = static_cast(dx / tabPixel) + 1; + f32 x = ctx->x + (tabPixel * numTab); + + writer.SetCursorX(x); +} + +template +void TagProcessorBase::ProcessLinefeed(PrintContext *ctx) { + TextWriterBase &writer = *ctx->writer; + + f32 x = ctx->x; + f32 y = writer.GetCursorY() + writer.GetLineHeight(); + + writer.SetCursorX(x); + writer.SetCursorY(y); +} + +template class TagProcessorBase; +template class TagProcessorBase; + +} // namespace ut +} // namespace nw4r From 20bedbfc3b007437c5e602500f5f1ca7d0e0da45 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 4 May 2024 23:47:10 -0400 Subject: [PATCH 21/23] ut_IOStream thanks ogws --- config/SOUE01/splits.txt | 1 + config/SOUE01/symbols.txt | 10 ++++----- configure.py | 2 +- include/nw4r/ut/ut_IOStream.h | 40 +++++++++++++++++++++-------------- src/nw4r/ut/ut_IOStream.cpp | 25 ++++++++++++++++++++++ 5 files changed, 56 insertions(+), 22 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index bb76869b..3c3bd3fd 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -185,6 +185,7 @@ nw4r/ut/ut_TagProcessorBase.cpp: nw4r/ut/ut_IOStream.cpp: .text start:0x8042B4E0 end:0x8042B55C .ctors start:0x804DB938 end:0x804DB93C + .sbss start:0x80576590 end:0x80576598 nw4r/ut/ut_FileStream.cpp: .text start:0x8042B560 end:0x8042B6EC diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index cea99b0e..f99c242b 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -23960,10 +23960,10 @@ ReadAsync__Q34nw4r2ut8IOStreamFPvUlPFlPQ34nw4r2ut8IOStreamPv_vPv = .text:0x8042B Write__Q34nw4r2ut8IOStreamFPCvUl = .text:0x8042B4F0; // type:function size:0x8 WriteAsync__Q34nw4r2ut8IOStreamFPCvUlPFlPQ34nw4r2ut8IOStreamPv_vPv = .text:0x8042B500; // type:function size:0x8 IsBusy__Q34nw4r2ut8IOStreamCFv = .text:0x8042B510; // type:function size:0x8 -GetBufferAlign__Q34nw4r2ut8IOStreamCFv = .text:0x8042B520; // type:function size:0x8 -GetSizeAlign__Q34nw4r2ut8IOStreamCFv = .text:0x8042B530; // type:function size:0x8 -GetOffsetAlign__Q34nw4r2ut8IOStreamCFv = .text:0x8042B540; // type:function size:0x8 -__sinit_\ut_IOStream_cpp = .text:0x8042B550; // type:function size:0xC +GetBufferAlign__Q34nw4r2ut8IOStreamCFv = .text:0x8042B520; // type:function size:0x8 scope:weak +GetSizeAlign__Q34nw4r2ut8IOStreamCFv = .text:0x8042B530; // type:function size:0x8 scope:weak +GetOffsetAlign__Q34nw4r2ut8IOStreamCFv = .text:0x8042B540; // type:function size:0x8 scope:weak +__sinit_\ut_IOStream_cpp = .text:0x8042B550; // type:function size:0xC scope:local Cancel__Q34nw4r2ut10FileStreamFv = .text:0x8042B560; // type:function size:0x4 CancelAsync__Q34nw4r2ut10FileStreamFPFlPQ34nw4r2ut8IOStreamPv_vPv = .text:0x8042B570; // type:function size:0x8 Skip__Q44nw4r2ut10FileStream12FilePositionFl = .text:0x8042B580; // type:function size:0x64 @@ -40808,7 +40808,7 @@ lbl_8057657C = .sbss:0x8057657C; // type:object size:0x4 data:4byte lbl_80576580 = .sbss:0x80576580; // type:object size:0x1 data:byte lbl_80576584 = .sbss:0x80576584; // type:object size:0x4 data:4byte lbl_80576588 = .sbss:0x80576588; // type:object size:0x8 data:4byte -lbl_80576590 = .sbss:0x80576590; // type:object size:0x8 data:4byte +typeInfo__Q34nw4r2ut8IOStream = .sbss:0x80576590; // type:object size:0x4 data:4byte lbl_80576598 = .sbss:0x80576598; // type:object size:0x8 data:4byte lbl_805765A0 = .sbss:0x805765A0; // type:object size:0x8 data:4byte lbl_805765A8 = .sbss:0x805765A8; // type:object size:0x8 data:4byte diff --git a/configure.py b/configure.py index 5336a084..67a80f00 100644 --- a/configure.py +++ b/configure.py @@ -322,7 +322,7 @@ config.libs = [ Object(Matching, "nw4r/ut/ut_binaryFileFormat.cpp"), Object(NonMatching, "nw4r/ut/ut_CharStrmReader.cpp"), Object(NonMatching, "nw4r/ut/ut_TagProcessorBase.cpp"), - Object(NonMatching, "nw4r/ut/ut_IOStream.cpp"), + Object(Matching, "nw4r/ut/ut_IOStream.cpp"), Object(NonMatching, "nw4r/ut/ut_FileStream.cpp"), Object(NonMatching, "nw4r/ut/ut_DvdFileStream.cpp"), Object(NonMatching, "nw4r/ut/ut_DvdLockedFileStream.cpp"), diff --git a/include/nw4r/ut/ut_IOStream.h b/include/nw4r/ut/ut_IOStream.h index 13467904..33545909 100644 --- a/include/nw4r/ut/ut_IOStream.h +++ b/include/nw4r/ut/ut_IOStream.h @@ -10,33 +10,41 @@ class IOStream { public: NW4R_UT_RTTI_DECL(IOStream); - typedef void (*AsyncCallback)(s32 result, IOStream* stream, void* arg); + typedef void (*AsyncCallback)(long result, IOStream *stream, void *arg); IOStream() : mIsOpen(false), mCallback(NULL), mCallbackArg(NULL) {} virtual ~IOStream() {} // at 0xC virtual void Close() = 0; // at 0x10 - virtual s32 Read(void* dst, u32 size) = 0; // at 0x14 - virtual bool ReadAsync(void* dst, u32 size, AsyncCallback callback, - void* arg); // at 0x18 - virtual void Write(const void* src, u32 size); // at 0x1C - virtual bool WriteAsync(const void* src, u32 size, AsyncCallback callback, - void* arg); // at 0x20 - virtual bool IsBusy() const; // at 0x24 - virtual bool CanAsync() const = 0; // at 0x28 - virtual bool CanRead() const = 0; // at 0x2C - virtual bool CanWrite() const = 0; // at 0x30 - virtual u32 GetOffsetAlign() const { return 1; } // at 0x34 - virtual u32 GetSizeAlign() const { return 1; } // at 0x38 - virtual u32 GetBufferAlign() const { return 1; } // at 0x3C + virtual s32 Read(void *dst, u32 size) = 0; // at 0x14 + virtual bool ReadAsync(void *dst, unsigned long size, AsyncCallback callback, + void *arg); // at 0x18 + virtual bool Write(const void *src, unsigned long size); // at 0x1C + virtual bool WriteAsync(const void *src, unsigned long size, AsyncCallback callback, + void *arg); // at 0x20 + virtual bool IsBusy() const; // at 0x24 + virtual bool CanAsync() const = 0; // at 0x28 + virtual bool CanRead() const = 0; // at 0x2C + virtual bool CanWrite() const = 0; // at 0x30 + virtual u32 GetOffsetAlign() const { + return 1; + } // at 0x34 + virtual u32 GetSizeAlign() const { + return 1; + } // at 0x38 + virtual u32 GetBufferAlign() const { + return 1; + } // at 0x3C - bool IsAvailable() const { return mIsOpen; } + bool IsAvailable() const { + return mIsOpen; + } protected: bool mIsOpen; // at 0x4 s32 mResult; // at 0x8 AsyncCallback mCallback; // at 0xC - void* mCallbackArg; // at 0x10 + void *mCallbackArg; // at 0x10 }; } // namespace ut diff --git a/src/nw4r/ut/ut_IOStream.cpp b/src/nw4r/ut/ut_IOStream.cpp index e69de29b..dec6c090 100644 --- a/src/nw4r/ut/ut_IOStream.cpp +++ b/src/nw4r/ut/ut_IOStream.cpp @@ -0,0 +1,25 @@ +#include + +namespace nw4r { +namespace ut { + +NW4R_UT_RTTI_DEF_BASE(IOStream); + +bool IOStream::ReadAsync(void *dst, unsigned long size, AsyncCallback callback, void *arg) { + return false; +} + +bool IOStream::Write(const void *src, unsigned long size) { + return false; +} + +bool IOStream::WriteAsync(const void *src, unsigned long size, AsyncCallback callback, void *arg) { + return false; +} + +bool IOStream::IsBusy() const { + return false; +} + +} // namespace ut +} // namespace nw4r From 7d76ab692f4ba75131296a2ddd5e54a0082247fd Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 5 May 2024 00:01:06 -0400 Subject: [PATCH 22/23] ut_FileStream thanks ogws --- config/SOUE01/splits.txt | 1 + config/SOUE01/symbols.txt | 6 ++-- configure.py | 2 +- include/nw4r/ut/ut_FileStream.h | 22 ++++++++----- src/nw4r/ut/ut_FileStream.cpp | 58 +++++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 12 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 0a647c7a..7fefadea 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -192,6 +192,7 @@ nw4r/ut/ut_IOStream.cpp: nw4r/ut/ut_FileStream.cpp: .text start:0x8042B560 end:0x8042B6EC .ctors start:0x804DB93C end:0x804DB940 + .sbss start:0x80576598 end:0x805765A0 nw4r/ut/ut_DvdFileStream.cpp: .text start:0x8042B6F0 end:0x8042BDAC diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 7d56a0ca..669414f7 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -23969,8 +23969,8 @@ CancelAsync__Q34nw4r2ut10FileStreamFPFlPQ34nw4r2ut8IOStreamPv_vPv = .text:0x8042 Skip__Q44nw4r2ut10FileStream12FilePositionFl = .text:0x8042B580; // type:function size:0x64 Append__Q44nw4r2ut10FileStream12FilePositionFl = .text:0x8042B5F0; // type:function size:0x50 Seek__Q44nw4r2ut10FileStream12FilePositionFlUl = .text:0x8042B640; // type:function size:0x88 -GetRuntimeTypeInfo__Q34nw4r2ut10FileStreamCFv = .text:0x8042B6D0; // type:function size:0x8 -__sinit_\ut_FileStream_cpp = .text:0x8042B6E0; // type:function size:0xC +GetRuntimeTypeInfo__Q34nw4r2ut10FileStreamCFv = .text:0x8042B6D0; // type:function size:0x8 scope:weak +__sinit_\ut_FileStream_cpp = .text:0x8042B6E0; // type:function size:0xC scope:local DvdAsyncCallback___Q34nw4r2ut13DvdFileStreamFlP11DVDFileInfo = .text:0x8042B6F0; // type:function size:0x2C DvdCBAsyncCallback___Q34nw4r2ut13DvdFileStreamFlP15DVDCommandBlock = .text:0x8042B720; // type:function size:0x28 __ct__Q34nw4r2ut13DvdFileStreamFl = .text:0x8042B750; // type:function size:0xBC @@ -40809,7 +40809,7 @@ lbl_80576580 = .sbss:0x80576580; // type:object size:0x1 data:byte lbl_80576584 = .sbss:0x80576584; // type:object size:0x4 data:4byte lbl_80576588 = .sbss:0x80576588; // type:object size:0x8 data:4byte typeInfo__Q34nw4r2ut8IOStream = .sbss:0x80576590; // type:object size:0x4 data:4byte -lbl_80576598 = .sbss:0x80576598; // type:object size:0x8 data:4byte +typeInfo__Q34nw4r2ut10FileStream = .sbss:0x80576598; // type:object size:0x4 data:4byte lbl_805765A0 = .sbss:0x805765A0; // type:object size:0x8 data:4byte lbl_805765A8 = .sbss:0x805765A8; // type:object size:0x8 data:4byte lbl_805765B0 = .sbss:0x805765B0; // type:object size:0x8 diff --git a/configure.py b/configure.py index 07061c3d..830c0c10 100644 --- a/configure.py +++ b/configure.py @@ -324,7 +324,7 @@ config.libs = [ Object(NonMatching, "nw4r/ut/ut_CharStrmReader.cpp"), Object(Matching, "nw4r/ut/ut_IOStream.cpp"), Object(Matching, "nw4r/ut/ut_TagProcessorBase.cpp"), - Object(NonMatching, "nw4r/ut/ut_FileStream.cpp"), + Object(Matching, "nw4r/ut/ut_FileStream.cpp"), Object(NonMatching, "nw4r/ut/ut_DvdFileStream.cpp"), Object(NonMatching, "nw4r/ut/ut_DvdLockedFileStream.cpp"), Object(NonMatching, "nw4r/ut/ut_NandFileStream.cpp"), diff --git a/include/nw4r/ut/ut_FileStream.h b/include/nw4r/ut/ut_FileStream.h index 99e4b336..17328c42 100644 --- a/include/nw4r/ut/ut_FileStream.h +++ b/include/nw4r/ut/ut_FileStream.h @@ -16,14 +16,20 @@ public: public: FilePosition() : mFileSize(0), mFileOffset(0) {} - u32 GetFileSize() const { return mFileSize; } - void SetFileSize(u32 fileSize) { mFileSize = fileSize; } + u32 GetFileSize() const { + return mFileSize; + } + void SetFileSize(unsigned long fileSize) { + mFileSize = fileSize; + } - u32 Tell() const { return mFileOffset; } + u32 Tell() const { + return mFileOffset; + } - u32 Skip(s32 offset); - u32 Append(s32 offset); - void Seek(s32 offset, u32 origin); + u32 Skip(long offset); + u32 Append(long offset); + void Seek(long offset, unsigned long origin); private: u32 mFileSize; // at 0x0 @@ -35,9 +41,9 @@ public: virtual ~FileStream() {} // at 0xC virtual u32 GetSize() const = 0; // at 0x40 - virtual void Seek(s32 offset, u32 origin); // at 0x44 + virtual void Seek(long offset, unsigned long origin); // at 0x44 virtual void Cancel(); // at 0x48 - virtual bool CancelAsync(AsyncCallback callback, void* arg); // at 0x4C + virtual bool CancelAsync(AsyncCallback callback, void *arg); // at 0x4C virtual bool CanSeek() const = 0; // at 0x50 virtual bool CanCancel() const = 0; // at 0x54 virtual u32 Tell() const = 0; // at 0x58 diff --git a/src/nw4r/ut/ut_FileStream.cpp b/src/nw4r/ut/ut_FileStream.cpp index e69de29b..a7b68cd0 100644 --- a/src/nw4r/ut/ut_FileStream.cpp +++ b/src/nw4r/ut/ut_FileStream.cpp @@ -0,0 +1,58 @@ +#include + +namespace nw4r { +namespace ut { + +NW4R_UT_RTTI_DEF_DERIVED(FileStream, IOStream); + +void FileStream::Cancel() {} + +bool FileStream::CancelAsync(AsyncCallback callback, void *arg) { +#pragma unused(callback) +#pragma unused(arg) + return true; +} + +u32 FileStream::FilePosition::Skip(long offset) { + if (offset != 0) { + s64 newOffset = mFileOffset + offset; + mFileOffset = Clamp(newOffset, 0, mFileSize); + } + + return mFileOffset; +} + +u32 FileStream::FilePosition::Append(long offset) { + s64 newOffset = mFileOffset + offset; + + if (newOffset < 0) { + mFileOffset = 0; + } else { + mFileOffset = newOffset; + mFileSize = Max(mFileOffset, mFileSize); + } + + return mFileOffset; +} + +void FileStream::FilePosition::Seek(long offset, unsigned long origin) { + switch (origin) { + case SEEK_BEG: + mFileOffset = 0; + break; + case SEEK_END: + mFileOffset = mFileSize; + break; + case SEEK_CUR: + default: + break; + } + + Skip(offset); +} + +// TODO: This should not be necessary. Because of nw4r::snd? still the case for ss +DECOMP_FORCEACTIVE(ut_FileStream_cpp, FileStream::GetRuntimeTypeInfo); + +} // namespace ut +} // namespace nw4r From bd4b6b3f9c9c3e9dc968d27df0faa2a615916ddc Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 5 May 2024 14:12:22 +0200 Subject: [PATCH 23/23] eggThread matching --- config/SOUE01/symbols.txt | 24 +++---- configure.py | 2 +- include/egg/core/eggThread.h | 8 ++- include/rvl/OS/OSThread.h | 4 +- src/egg/core/eggThread.cpp | 125 +++++++++++++++++++++++++++++++++++ 5 files changed, 145 insertions(+), 18 deletions(-) create mode 100644 src/egg/core/eggThread.cpp diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 669414f7..81e5f50b 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -4056,8 +4056,8 @@ fn_800BD510 = .text:0x800BD510; // type:function size:0xC fn_800BD520 = .text:0x800BD520; // type:function size:0x5C fn_800BD580 = .text:0x800BD580; // type:function size:0x5C fn_800BD5E0 = .text:0x800BD5E0; // type:function size:0xC -fn_800BD5F0 = .text:0x800BD5F0; // type:function size:0x4 -fn_800BD600 = .text:0x800BD600; // type:function size:0x4 +onExit__Q23EGG6ThreadFv = .text:0x800BD5F0; // type:function size:0x4 +onEnter__Q23EGG6ThreadFv = .text:0x800BD600; // type:function size:0x4 fn_800BD610 = .text:0x800BD610; // type:function size:0x34 fn_800BD650 = .text:0x800BD650; // type:function size:0x8 fn_800BD660 = .text:0x800BD660; // type:function size:0x5C @@ -22030,11 +22030,11 @@ fn_803AC300 = .text:0x803AC300; // type:function size:0x20 __OSSystemCallVectorEnd = .text:0x803AC31C; // type:label scope:global __OSInitSystemCall = .text:0x803AC320; // type:function size:0x60 scope:global fn_803AC380 = .text:0x803AC380; // type:function size:0x4 -fn_803AC390 = .text:0x803AC390; // type:function size:0x70 +OSSetSwitchThreadCallback = .text:0x803AC390; // type:function size:0x70 __OSThreadInit = .text:0x803AC400; // type:function size:0x284 scope:global OSInitThreadQueue = .text:0x803AC690; // type:function size:0x10 scope:global -fn_803AC6A0 = .text:0x803AC6A0; // type:function size:0xC -fn_803AC6B0 = .text:0x803AC6B0; // type:function size:0x2C +OSGetCurrentThread = .text:0x803AC6A0; // type:function size:0xC +OSIsThreadTerminated = .text:0x803AC6B0; // type:function size:0x2C OSDisableScheduler = .text:0x803AC6E0; // type:function size:0x3C scope:global OSEnableScheduler = .text:0x803AC720; // type:function size:0x3C scope:global fn_803AC760 = .text:0x803AC760; // type:function size:0x68 @@ -22044,11 +22044,11 @@ fn_803AC9C0 = .text:0x803AC9C0; // type:function size:0x50 SelectThread = .text:0x803ACA10; // type:function size:0x22C scope:local __OSReschedule = .text:0x803ACC40; // type:function size:0x18 scope:global fn_803ACC60 = .text:0x803ACC60; // type:function size:0x3C -fn_803ACCA0 = .text:0x803ACCA0; // type:function size:0x26C +OSCreateThread = .text:0x803ACCA0; // type:function size:0x26C fn_803ACF10 = .text:0x803ACF10; // type:function size:0xE4 OSCancelThread = .text:0x803AD000; // type:function size:0x1D4 scope:global fn_803AD1E0 = .text:0x803AD1E0; // type:function size:0x144 -fn_803AD330 = .text:0x803AD330; // type:function size:0xA0 +OSDetachThread = .text:0x803AD330; // type:function size:0xA0 fn_803AD3D0 = .text:0x803AD3D0; // type:function size:0x29C fn_803AD670 = .text:0x803AD670; // type:function size:0x18C OSSleepThread = .text:0x803AD800; // type:function size:0xF0 scope:global @@ -26253,7 +26253,7 @@ getSize__Q23EGG10AssertHeapFv = .text:0x80496810; // type:function size:0x8 getHeapKind__Q23EGG10AssertHeapCFv = .text:0x80496820; // type:function size:0x8 __ct__Q23EGG8DisposerFv = .text:0x80496830; // type:function size:0x54 __dt__Q23EGG8DisposerFv = .text:0x80496890; // type:function size:0x74 -__ct__Q23EGG6ThreadFUliiPQ23EGG4Heap = .text:0x80496910; // type:function size:0xD0 +__ct__Q23EGG6ThreadFUiiiPQ23EGG4Heap = .text:0x80496910; // type:function size:0xD0 __ct__Q23EGG6ThreadFP8OSThreadi = .text:0x804969E0; // type:function size:0x74 __dt__Q23EGG6ThreadFv = .text:0x80496A60; // type:function size:0xBC findThread__Q23EGG6ThreadFP8OSThread = .text:0x80496B20; // type:function size:0x64 @@ -26262,7 +26262,7 @@ setThreadCurrentHeap__Q23EGG6ThreadFPQ23EGG4Heap = .text:0x80496BD0; // type:fun switchThreadCallback__Q23EGG6ThreadFP8OSThreadP8OSThread = .text:0x80496C70; // type:function size:0xEC setCommonMesgQueue__Q23EGG6ThreadFiPQ23EGG4Heap = .text:0x80496D60; // type:function size:0x5C start__Q23EGG6ThreadFPv = .text:0x80496DC0; // type:function size:0x10 -run__Q23EGG6ThreadFPv = .text:0x80496DD0; // type:function size:0x8 +run__Q23EGG6ThreadFv = .text:0x80496DD0; // type:function size:0x8 FUN_80496de0 = .text:0x80496DE0; // type:function size:0x44 FUN_80496e30 = .text:0x80496E30; // type:function size:0xD8 FUN_80496f10 = .text:0x80496F10; // type:function size:0x1CC @@ -37103,7 +37103,7 @@ lbl_8056E9A0 = .data:0x8056E9A0; // type:object size:0x30 lbl_8056E9D0 = .data:0x8056E9D0; // type:object size:0x30 lbl_8056EA00 = .data:0x8056EA00; // type:object size:0x30 lbl_8056EA30 = .data:0x8056EA30; // type:object size:0x10 -lbl_8056EA40 = .data:0x8056EA40; // type:object size:0x18 +__vt__Q23EGG6Thread = .data:0x8056EA40; // type:object size:0x18 lbl_8056EA58 = .data:0x8056EA58; // type:object size:0x70 __vt__Q23EGG7Display = .data:0x8056EAC8; // type:object size:0x20 __vt__Q23EGG10ColorFader = .data:0x8056EAE8; // type:object size:0x24 @@ -40890,7 +40890,7 @@ lbl_8057675C = .sbss:0x8057675C; // type:object size:0x4 data:4byte lbl_80576760 = .sbss:0x80576760; // type:object size:0x4 data:4byte lbl_80576764 = .sbss:0x80576764; // type:object size:0x4 data:4byte lbl_80576768 = .sbss:0x80576768; // type:object size:0x8 data:4byte -lbl_80576770 = .sbss:0x80576770; // type:object size:0x8 data:4byte +sOldSwitchThreadCallback__Q23EGG6Thread = .sbss:0x80576770; // type:object size:0x4 data:4byte lbl_80576778 = .sbss:0x80576778; // type:object size:0x8 data:4byte mConfigData__Q23EGG10BaseSystem = .sbss:0x80576780; // type:object size:0x4 data:4byte sTickPeriod__Q23EGG7Display = .sbss:0x80576788; // type:object size:0x4 data:4byte @@ -49347,7 +49347,7 @@ lbl_80673AC8 = .bss:0x80673AC8; // type:object size:0x10 lbl_80673AD8 = .bss:0x80673AD8; // type:object size:0x10 lbl_80673AE8 = .bss:0x80673AE8; // type:object size:0x10 lbl_80673AF8 = .bss:0x80673AF8; // type:object size:0x18 -lbl_80673B10 = .bss:0x80673B10; // type:object size:0x10 +sThreadList__Q23EGG6Thread = .bss:0x80673B10; // type:object size:0xC clear_z_tobj__29@unnamed@eggAsyncDisplay_cpp@ = .bss:0x80673B20; // type:object size:0x20 scope:local lbl_80673B40 = .bss:0x80673B40; // type:object size:0x10C0 data:4byte ident__Q23EGG9Matrix34f = .bss:0x80674C00; // type:object size:0x30 diff --git a/configure.py b/configure.py index 830c0c10..ad9079a4 100644 --- a/configure.py +++ b/configure.py @@ -350,7 +350,7 @@ config.libs = [ Object(NonMatching, "egg/core/eggFrmHeap.cpp"), Object(NonMatching, "egg/core/eggAssertHeap.cpp"), Object(NonMatching, "egg/core/eggDisposer.cpp"), - Object(NonMatching, "egg/core/eggThread.cpp"), + Object(Matching, "egg/core/eggThread.cpp"), Object(NonMatching, "egg/core/eggUnk.cpp"), Object(NonMatching, "egg/core/eggSystem.cpp"), Object(Matching, "egg/core/eggDisplay.cpp"), diff --git a/include/egg/core/eggThread.h b/include/egg/core/eggThread.h index 8895b95d..048cb88e 100644 --- a/include/egg/core/eggThread.h +++ b/include/egg/core/eggThread.h @@ -11,9 +11,9 @@ namespace EGG { class Thread { public: // vtable: 0x00 | 8056ea40 /* 0x08 | 80496a60 */ virtual ~Thread(); - /* 0x0C | 80496dd0 */ virtual void *run(); - /* 0x10 | 800bd600 */ virtual void onEnter(); - /* 0x14 | 800bd5f0 */ virtual void onExit(); + /* 0x0C | 80496dd0 */ virtual void *run() { return nullptr; } + /* 0x10 | 800bd600 */ virtual void onEnter() {} + /* 0x14 | 800bd5f0 */ virtual void onExit() {} public: /* 0x04 */ Heap *mContainingHeap; @@ -24,6 +24,8 @@ public: /* 0x34 */ void *mStackMemory; /* 0x38 */ u32 mStackSize; /* 0x3C */ Heap *mAllocatableHeap; + // TODO from the usage in eggThread this really looks like + // it's stashed thread that's restored when switching threads /* 0x40 */ Heap *mCurrentHeap; /* 0x44 */ nw4r::ut::Node mLink; diff --git a/include/rvl/OS/OSThread.h b/include/rvl/OS/OSThread.h index b81078b3..dfe07d5f 100644 --- a/include/rvl/OS/OSThread.h +++ b/include/rvl/OS/OSThread.h @@ -47,8 +47,8 @@ typedef struct OSThread { OSMutexQueue mutexQueue; // at 0x2F4 struct OSThread *nextActive; // at 0x2FC struct OSThread *prevActive; // at 0x300 - u32 *stackBegin; // at 0x304 - u32 *stackEnd; // at 0x308 + void *stackBegin; // at 0x304 + void *stackEnd; // at 0x308 s32 error; // at 0x30C void *specific[2]; // at 0x310 } OSThread; diff --git a/src/egg/core/eggThread.cpp b/src/egg/core/eggThread.cpp new file mode 100644 index 00000000..36f44d4d --- /dev/null +++ b/src/egg/core/eggThread.cpp @@ -0,0 +1,125 @@ +#include + +namespace EGG { + +/* 80673b10 */ nw4r::ut::List Thread::sThreadList; +/* 80576770 */ void (*Thread::sOldSwitchThreadCallback)(OSThread *, OSThread *); + + +/* 80496910 */ Thread::Thread(u32 stackSize, int msgCount, int priority, Heap *heap) { + if (heap == nullptr) { + heap = Heap::sCurrentHeap; + } + + mContainingHeap = heap; + mStackSize = ROUND_DOWN(stackSize, 0x20); + mStackMemory = Heap::alloc(ROUND_DOWN(stackSize, 0x20), 0x20, heap); + mOSThread = Heap::alloc(mContainingHeap, 0x20); + OSCreateThread(mOSThread, start, this, (char *)mStackMemory + mStackSize, mStackSize, priority, 1); + mAllocatableHeap = nullptr; + mCurrentHeap = nullptr; + setCommonMesgQueue(msgCount, mContainingHeap); +} + +/* 804969e0 */ Thread::Thread(OSThread *osThread, int msgCount) { + mContainingHeap = nullptr; + mOSThread = osThread; + mStackSize = (u8 *)osThread->stackBegin - (u8 *)osThread->stackEnd; + mStackMemory = osThread->stackEnd; + mAllocatableHeap = nullptr; + mCurrentHeap = nullptr; + setCommonMesgQueue(msgCount, Heap::sCurrentHeap); +} + +/* 80496a60 */ Thread::~Thread() { + nw4r::ut::List_Remove(&sThreadList, this); + if (mContainingHeap != nullptr) { + if (!OSIsThreadTerminated(mOSThread)) { + OSDetachThread(mOSThread); + OSCancelThread(mOSThread); + } + Heap::free(mStackMemory, mContainingHeap); + Heap::free(mOSThread, mContainingHeap); + } + Heap::free(mMesgBuffer, nullptr); +} + +/* 80496b20 */ Thread *Thread::findThread(OSThread *thread) { + Thread *ptr = nullptr; + while ((ptr = (Thread *)nw4r::ut::List_GetNext(&sThreadList, ptr)) != nullptr) { + if (ptr->mOSThread == thread) { + return ptr; + } + } + return nullptr; +} + +/* 80496b90 */ void Thread::initialize() { + // TODO offsetof + nw4r::ut::List_Init(&sThreadList, 0x44); + sOldSwitchThreadCallback = OSSetSwitchThreadCallback(switchThreadCallback); +} + +/* 80496bd0 */ void Thread::setThreadCurrentHeap(Heap *heap) { + OSDisableScheduler(); + OSThread *myThread = mOSThread; + OSThread *currentThread = OSGetCurrentThread(); + if (currentThread != myThread) { + mCurrentHeap = heap; + } else { + if (heap != nullptr) { + if (mCurrentHeap == nullptr) { + mCurrentHeap = Heap::sCurrentHeap; + } + heap->_becomeCurrentHeapWithoutLock(); + } else { + if (mCurrentHeap != nullptr) { + mCurrentHeap->_becomeCurrentHeapWithoutLock(); + mCurrentHeap = nullptr; + } + } + } + + OSEnableScheduler(); +} + +/* 80496c70 */ void Thread::switchThreadCallback(OSThread *from, OSThread *to) { + Thread *fromThread = from != nullptr ? findThread(from) : nullptr; + Thread *toThread = to != nullptr ? findThread(to) : nullptr; + + if (fromThread != nullptr) { + fromThread->onExit(); + if (fromThread->mCurrentHeap != nullptr) { + Heap *curr = Heap::sCurrentHeap; + fromThread->mCurrentHeap->_becomeCurrentHeapWithoutLock(); + fromThread->mCurrentHeap = curr; + } + } + + if (toThread != nullptr) { + if (toThread->mCurrentHeap != nullptr) { + Heap *curr = Heap::sCurrentHeap; + toThread->mCurrentHeap->_becomeCurrentHeapWithoutLock(); + toThread->mCurrentHeap = curr; + } + toThread->onEnter(); + } + + if (sOldSwitchThreadCallback != nullptr) { + (sOldSwitchThreadCallback)(from, to); + } +} + +/* 80496d60 */ void Thread::setCommonMesgQueue(int mesgCount, Heap *heap) { + mMesgCount = mesgCount; + mMesgBuffer = Heap::alloc(mesgCount, heap); + OSInitMessageQueue(&mMesgQueue, mMesgBuffer, mMesgCount); + nw4r::ut::List_Append(&sThreadList, this); +} + +/* 80496dc0 */ void *Thread::start(void *arg) { + Thread *thread = static_cast(arg); + return thread->run(); +} + +} // namespace EGG