diff --git a/include/m_Do/m_Do_MemCardRWmng.h b/include/m_Do/m_Do_MemCardRWmng.h index 63b833ce7..e102c0872 100644 --- a/include/m_Do/m_Do_MemCardRWmng.h +++ b/include/m_Do/m_Do_MemCardRWmng.h @@ -1,10 +1,40 @@ #ifndef M_DO_M_DO_MEMCARDRWMNG_H #define M_DO_M_DO_MEMCARDRWMNG_H +#include "d/d_save.h" #include "dolphin/types.h" typedef struct CARDFileInfo CARDFileInfo; -struct mDoMemCdRWm_HeaderData; + +struct mDoMemCdRWm_HeaderData +{ + /* 0x0000 */ u8 banner[0x0e00]; + /* 0x0e00 */ u8 icon[0x0200]; + /* 0x1000 */ u8 field_0x1000[0x0c00]; + /* 0x1c00 */ char comment[32]; + /* 0x1c20 */ char info[32]; +}; + +struct card_pictdata +{ + u8 data[0x1ffe]; + u16 csum; +}; + +struct card_gamedata +{ + u8 data[dSv_save_c::PACKED_STRUCT_SIZE]; + u64 csum; +}; + +struct card_savedata +{ + u32 saveCount; + u32 dataVersion; + card_gamedata gamedata[3]; + u32 field_0x1658[0x269]; + u32 csum; +}; s32 mDoMemCdRWm_Store(CARDFileInfo*, void*, u32); s32 mDoMemCdRWm_Restore(CARDFileInfo*, void*, u32); diff --git a/src/d/d_save.cpp b/src/d/d_save.cpp index 3e97c2d50..c8e1aa6c4 100644 --- a/src/d/d_save.cpp +++ b/src/d/d_save.cpp @@ -7,6 +7,7 @@ #include "d/d_save_init.h" #include "d/d_com_inf_game.h" #include "d/d_item_data.h" +#include "m_Do/m_Do_MemCardRWmng.h" #if VERSION == VERSION_JPN #include "d/d_s_play.h" #endif @@ -1626,13 +1627,8 @@ BOOL dSv_info_c::isActor(int i_id, int i_roomNo) { /* 8005E780-8005EA24 .text memory_to_card__10dSv_info_cFPci */ int dSv_info_c::memory_to_card(char* i_cardPtr, int i_dataNum) { - // The size of the dSv_save_c struct in RAM (i.e. with alignment padding) is 0x778. - // The size that gets stored to the memory card (i.e. packed, without the padding) is 0x768. - // At the end of this function there's a check to ensure it doesn't copy more than 0x768 bytes. - // At the start of this function, the size the index gets multiplied by to find the slot in the card is 0x770. - // I'm not sure where 0x770 comes from, but my best guess is that it's 0x768 aligned to the next 0x10 bytes. char* buffer_start; - char* buffer = i_cardPtr + i_dataNum * ALIGN_NEXT(dSv_save_c::PACKED_STRUCT_SIZE, 0x10); + char* buffer = i_cardPtr + i_dataNum * sizeof(card_gamedata); buffer_start = buffer; memcpy(buffer, dComIfGs_getpPlayerStatusA(), sizeof(dSv_player_status_a_c)); @@ -1723,7 +1719,7 @@ int dSv_info_c::memory_to_card(char* i_cardPtr, int i_dataNum) { /* 8005EA24-8005ED00 .text card_to_memory__10dSv_info_cFPci */ int dSv_info_c::card_to_memory(char* i_cardPtr, int i_dataNum) { char* buffer_start; - char* buffer = i_cardPtr + i_dataNum * ALIGN_NEXT(dSv_save_c::PACKED_STRUCT_SIZE, 0x10); + char* buffer = i_cardPtr + i_dataNum * sizeof(card_gamedata); buffer_start = buffer; memcpy(dComIfGs_getpPlayerStatusA(), buffer, sizeof(dSv_player_status_a_c)); @@ -1810,7 +1806,7 @@ int dSv_info_c::card_to_memory(char* i_cardPtr, int i_dataNum) { /* 8005ED00-8005EF88 .text initdata_to_card__10dSv_info_cFPci */ int dSv_info_c::initdata_to_card(char* i_cardPtr, int i_dataNum) { // TODO: This function could probably be cleaned up somehow - char* buffer = i_cardPtr + i_dataNum * ALIGN_NEXT(dSv_save_c::PACKED_STRUCT_SIZE, 0x10); + char* buffer = i_cardPtr + i_dataNum * sizeof(card_gamedata); char* buffer_start = buffer; char* buffer_src; diff --git a/src/m_Do/m_Do_MemCardRWmng.cpp b/src/m_Do/m_Do_MemCardRWmng.cpp index 5498d8582..761ffe6ca 100644 --- a/src/m_Do/m_Do_MemCardRWmng.cpp +++ b/src/m_Do/m_Do_MemCardRWmng.cpp @@ -15,36 +15,6 @@ #include #include -struct mDoMemCdRWm_HeaderData -{ - /* 0x0000 */ u8 banner[0x0e00]; - /* 0x0e00 */ u8 icon[0x0200]; - /* 0x1000 */ u8 field_0x1000[0x0c00]; - /* 0x1c00 */ char comment[32]; - /* 0x1c20 */ char info[32]; -}; - -struct card_pictdata -{ - u8 data[0x1ffe]; - u16 csum; -}; - -struct card_gamedata -{ - u8 data[0x768]; - u64 csum; -}; - -struct card_savedata -{ - u32 saveCount; - u32 dataVersion; - card_gamedata gamedata[3]; - u32 field_0x1658[0x269]; - u32 csum; -}; - static u8 sTmpBuf[0x2000] ALIGN_DECL(32); static u8 sTmpBuf2[0x2000] ALIGN_DECL(32); static u32 sSaveCount;