From cdfda89fa6421d2d4bb74c65ce72efa4595f36d2 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Tue, 11 Oct 2022 19:08:45 +0300 Subject: [PATCH] Almost match CMemoryCardDriver::BuildNewFileSlot --- include/MetroidPrime/Player/CGameState.hpp | 4 ++++ src/MetroidPrime/CMemoryCardDriver.cpp | 28 ++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/include/MetroidPrime/Player/CGameState.hpp b/include/MetroidPrime/Player/CGameState.hpp index 16d11b58..9276fc77 100644 --- a/include/MetroidPrime/Player/CGameState.hpp +++ b/include/MetroidPrime/Player/CGameState.hpp @@ -20,6 +20,8 @@ public: CGameState(); CGameState(CInputStream& in, int saveIdx); + void ReadSystemOptions(CInputStream& in); + rstl::rc_ptr< CPlayerState >& PlayerState(); CAssetId CurrentWorldAssetId(); void WriteBackupBuf(); @@ -30,6 +32,8 @@ public: uint& SaveIdx() { return x20c_saveIdx; } u64& CardSerial() { return x210_cardSerial; } rstl::vector< uchar >& BackupBuf() { return x218_backupBuf; } + u32 GetFileIdx() const { return x20c_saveIdx; } + void SetFileIdx(u32 idx) { x20c_saveIdx = idx; } void SetCardSerial(u64 serial) { x210_cardSerial = serial; } u64 GetCardSerial() const { return x210_cardSerial; } diff --git a/src/MetroidPrime/CMemoryCardDriver.cpp b/src/MetroidPrime/CMemoryCardDriver.cpp index 7b178f14..70f60638 100644 --- a/src/MetroidPrime/CMemoryCardDriver.cpp +++ b/src/MetroidPrime/CMemoryCardDriver.cpp @@ -706,11 +706,27 @@ void CMemoryCardDriver::ReadFinished() { } } -void CMemoryCardDriver::EraseFileSlot(int saveIdx) { - xe4_fileSlots[saveIdx] = nullptr; -} +void CMemoryCardDriver::EraseFileSlot(int saveIdx) { xe4_fileSlots[saveIdx] = nullptr; } -void CMemoryCardDriver::BuildNewFileSlot(int) {} +void CMemoryCardDriver::BuildNewFileSlot(int saveIdx) { + bool fusionBackup = gpGameState->SystemOptions().GetHasFusion(); + gpGameState->SetFileIdx(saveIdx); + + rstl::auto_ptr< SGameFileSlot >& slot = xe4_fileSlots[saveIdx]; + if (slot.null()) + slot = new SGameFileSlot(); + + slot->LoadGameState(saveIdx); + + { + CMemoryInStream r(x30_systemData.data(), x30_systemData.capacity()); + gpGameState->ReadSystemOptions(r); + } + + ImportPersistentOptions(); + gpGameState->SetCardSerial(x28_cardSerial); + gpGameState->SystemOptions().SetHasFusion(fusionBackup); +} void CMemoryCardDriver::BuildExistingFileSlot(int) {} @@ -738,7 +754,9 @@ SGameFileSlot::SGameFileSlot() {} SGameFileSlot::SGameFileSlot(CMemoryInStream& in) {} -void SGameFileSlot::DoPut(CMemoryStreamOut& w) const { w.Put(x0_saveBuffer.data(), x0_saveBuffer.capacity()); } +void SGameFileSlot::DoPut(CMemoryStreamOut& w) const { + w.Put(x0_saveBuffer.data(), x0_saveBuffer.capacity()); +} void SGameFileSlot::InitializeFromGameState() {}