From 5198e478f28487da34bde0b566e9a92d8c043cbf Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Tue, 11 Oct 2022 19:28:27 +0300 Subject: [PATCH] Add CMemoryCardDriver::BuildExistingFileSlot Former-commit-id: 8487d3751b598f8d727296dcfe76650186de85e6 --- asm/MetroidPrime/CMemoryCardDriver.s | 2 +- asm/MetroidPrime/Player/CGameState.s | 4 ++-- include/Kyoto/Streams/CMemoryStreamOut.hpp | 2 +- include/MetroidPrime/Player/CGameState.hpp | 3 +++ src/MetroidPrime/CMemoryCardDriver.cpp | 13 ++++++++++++- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/asm/MetroidPrime/CMemoryCardDriver.s b/asm/MetroidPrime/CMemoryCardDriver.s index 72386115..79c8e80a 100644 --- a/asm/MetroidPrime/CMemoryCardDriver.s +++ b/asm/MetroidPrime/CMemoryCardDriver.s @@ -664,7 +664,7 @@ lbl_8024CA74: /* 8024CA88 002499E8 48 0F 28 B5 */ bl __ct__16CMemoryStreamOutFPvUlQ216CMemoryStreamOut10EOwnerShipi /* 8024CA8C 002499EC 80 6D A0 80 */ lwz r3, gpGameState@sda21(r13) /* 8024CA90 002499F0 38 81 00 10 */ addi r4, r1, 0x10 -/* 8024CA94 002499F4 4B F8 75 89 */ bl sub_801d401c +/* 8024CA94 002499F4 4B F8 75 89 */ bl WriteSystemOptions__10CGameStateFR13COutputStream /* 8024CA98 002499F8 38 61 00 10 */ addi r3, r1, 0x10 /* 8024CA9C 002499FC 38 80 FF FF */ li r4, -1 /* 8024CAA0 00249A00 48 0F 28 21 */ bl __dt__16CMemoryStreamOutFv diff --git a/asm/MetroidPrime/Player/CGameState.s b/asm/MetroidPrime/Player/CGameState.s index abb7eeb7..db90b11a 100644 --- a/asm/MetroidPrime/Player/CGameState.s +++ b/asm/MetroidPrime/Player/CGameState.s @@ -646,8 +646,8 @@ lbl_801D3FC0: /* 801D4014 001D0F74 38 21 00 10 */ addi r1, r1, 0x10 /* 801D4018 001D0F78 4E 80 00 20 */ blr -.global sub_801d401c -sub_801d401c: +.global WriteSystemOptions__10CGameStateFR13COutputStream +WriteSystemOptions__10CGameStateFR13COutputStream: /* 801D401C 001D0F7C 94 21 FF F0 */ stwu r1, -0x10(r1) /* 801D4020 001D0F80 7C 08 02 A6 */ mflr r0 /* 801D4024 001D0F84 38 63 00 A8 */ addi r3, r3, 0xa8 diff --git a/include/Kyoto/Streams/CMemoryStreamOut.hpp b/include/Kyoto/Streams/CMemoryStreamOut.hpp index 4befd536..e2c58877 100644 --- a/include/Kyoto/Streams/CMemoryStreamOut.hpp +++ b/include/Kyoto/Streams/CMemoryStreamOut.hpp @@ -10,7 +10,7 @@ public: kOS_NotOwned, }; - CMemoryStreamOut(uchar* buffer, size_t len, EOwnerShip ownerShip = kOS_NotOwned, int blockLen = 4096); + CMemoryStreamOut(void* buffer, size_t len, EOwnerShip ownerShip = kOS_NotOwned, int blockLen = 4096); virtual ~CMemoryStreamOut(); }; diff --git a/include/MetroidPrime/Player/CGameState.hpp b/include/MetroidPrime/Player/CGameState.hpp index 9276fc77..34e2669b 100644 --- a/include/MetroidPrime/Player/CGameState.hpp +++ b/include/MetroidPrime/Player/CGameState.hpp @@ -15,12 +15,15 @@ #include "rstl/reserved_vector.hpp" #include "rstl/vector.hpp" +class CMemoryStreamOut; class CGameState { public: CGameState(); CGameState(CInputStream& in, int saveIdx); void ReadSystemOptions(CInputStream& in); + void PutTo(CMemoryStreamOut& out); + void WriteSystemOptions(COutputStream& out); rstl::rc_ptr< CPlayerState >& PlayerState(); CAssetId CurrentWorldAssetId(); diff --git a/src/MetroidPrime/CMemoryCardDriver.cpp b/src/MetroidPrime/CMemoryCardDriver.cpp index 70f60638..4a4c4f71 100644 --- a/src/MetroidPrime/CMemoryCardDriver.cpp +++ b/src/MetroidPrime/CMemoryCardDriver.cpp @@ -728,7 +728,18 @@ void CMemoryCardDriver::BuildNewFileSlot(int saveIdx) { gpGameState->SystemOptions().SetHasFusion(fusionBackup); } -void CMemoryCardDriver::BuildExistingFileSlot(int) {} +void CMemoryCardDriver::BuildExistingFileSlot(int saveIdx) { + gpGameState->SetFileIdx(saveIdx); + + rstl::auto_ptr< SGameFileSlot >& slot = xe4_fileSlots[saveIdx]; + if (slot.null()) + slot = new SGameFileSlot(); + else + slot->InitializeFromGameState(); + + CMemoryStreamOut w(x30_systemData.data(), x30_systemData.capacity()); + gpGameState->WriteSystemOptions(w); +} void CMemoryCardDriver::ImportPersistentOptions() {}