From 4ac2f273b474d966b65137b677219423ec050ed4 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Mon, 10 Oct 2022 22:44:11 +0300 Subject: [PATCH] Add CMemoryCardDriver Former-commit-id: e7e54730a35087a4defdbaf353210f293882dc36 --- include/MetroidPrime/CMemoryCardDriver.hpp | 109 +++++++++++++++++++ include/MetroidPrime/Player/CGameOptions.hpp | 1 + include/MetroidPrime/Player/CGameState.hpp | 12 ++ include/MetroidPrime/Player/CHintOptions.hpp | 1 + src/MetroidPrime/CMemoryCardDriver.cpp | 93 ++++++++++++++++ 5 files changed, 216 insertions(+) create mode 100644 include/MetroidPrime/CMemoryCardDriver.hpp create mode 100644 src/MetroidPrime/CMemoryCardDriver.cpp diff --git a/include/MetroidPrime/CMemoryCardDriver.hpp b/include/MetroidPrime/CMemoryCardDriver.hpp new file mode 100644 index 00000000..ece602a1 --- /dev/null +++ b/include/MetroidPrime/CMemoryCardDriver.hpp @@ -0,0 +1,109 @@ +#ifndef _CMEMORYCARDDRIVER +#define _CMEMORYCARDDRIVER + +#include "MetroidPrime/Player/CGameState.hpp" + +class CMemoryCardDriver { +public: + enum EState { + kS_Initial = 0, + kS_Ready = 1, + kS_NoCard = 2, + kS_DriverClosed = 3, + kS_CardFormatted = 4, + kS_CardProbeDone = 5, + kS_CardMountDone = 6, + kS_CardCheckDone = 7, + kS_FileCreateDone = 8, + kS_FileCreateTransactionalDone = 9, + kS_FileWriteTransactionalDone = 10, + kS_FileDeleteAltTransactionalDone = 11, + kS_CardProbeFailed = 12, + kS_CardMountFailed = 13, + kS_CardCheckFailed = 14, + kS_FileDeleteBadFailed = 15, + kS_FileDeleteAltFailed = 16, + kS_FileBad = 17, + kS_FileCreateFailed = 18, + kS_FileWriteFailed = 19, + kS_FileCreateTransactionalFailed = 20, + kS_FileWriteTransactionalFailed = 21, + kS_FileDeleteAltTransactionalFailed = 22, + kS_FileRenameBtoAFailed = 23, + kS_CardFormatFailed = 24, + kS_CardProbe = 25, + kS_CardMount = 26, + kS_CardCheck = 27, + kS_FileDeleteBad = 28, + kS_FileRead = 29, + kS_FileDeleteAlt = 30, + kS_FileCreate = 31, + kS_FileWrite = 32, + kS_FileCreateTransactional = 33, + kS_FileWriteTransactional = 34, + kS_FileDeleteAltTransactional = 35, + kS_FileRenameBtoA = 36, + kS_CardFormat = 37 + }; + + enum EError { + kE_OK, + kE_CardBroken, + kE_CardWrongCharacterSet, + kE_CardIOError, + kE_CardWrongDevice, + kE_CardFull, + kE_CardStillFull, /* After attempting alt-delete (if needed) */ + kE_CardNon8KSectors, + kE_FileMissing, + kE_FileCorrupted + }; + + static bool IsCardBusy(EState); + static bool IsCardWriting(EState); + CMemoryCardDriver(); + void ClearFileInfo(); + ~CMemoryCardDriver(); + void Update(); + void HandleCardError(int); + void UpdateMountCard(int); + void UpdateCardCheck(); + void UpdateFileRead(); + void UpdateFileDeleteAlt(); + void UpdateFileDeleteBad(); + void UpdateFileCreate(); + void UpdateFileWrite(); + void UpdateFileCreateTransactional(); + void UpdateFileWriteTransactional(); + void UpdateFileRenameBtoA(); + void StartFileRenameBtoA(); + void WriteBackupBuf(); + void UpdateFileAltDeleteTransactional(); + void UpdateCardFormat(); + void StartCardProbe(); + void UpdateCardProbe(); + void StartMountCard(); + void StartCardCheck(); + void ClearError(); + void CheckCardCapacity(); + void NoCardFound(); + void IndexFiles(); + void StartFileDeleteBad(); + void StartFileCreate(); + void StartFileWrite(); + void StartFileCreateTransactional(); + void StartFileWriteTransactional(); + void StartFileDeleteAltTransactional(); + void StartCardFormat(); + void InitializeFileInfo(); + void ReadFinished(); + void EraseFileSlot(int); + void BuildNewFileSlot(int); + void BuildExistingFileSlot(int); + void ImportPersistentOptions(); + void ExportPersistentOptions(); + const CGameState::GameFileStateInfo* GetGameFileStateInfo(int); + bool GetCardFreeBytes(); +}; + +#endif // _CMEMORYCARDDRIVER diff --git a/include/MetroidPrime/Player/CGameOptions.hpp b/include/MetroidPrime/Player/CGameOptions.hpp index 41e83a46..77c403b0 100644 --- a/include/MetroidPrime/Player/CGameOptions.hpp +++ b/include/MetroidPrime/Player/CGameOptions.hpp @@ -7,6 +7,7 @@ #include "rstl/reserved_vector.hpp" #include "rstl/vector.hpp" +#include "Kyoto/SObjectTag.hpp" #include "Kyoto/Streams/CInputStream.hpp" #include "MetroidPrime/TGameTypes.hpp" diff --git a/include/MetroidPrime/Player/CGameState.hpp b/include/MetroidPrime/Player/CGameState.hpp index 44c189f6..e75defc6 100644 --- a/include/MetroidPrime/Player/CGameState.hpp +++ b/include/MetroidPrime/Player/CGameState.hpp @@ -30,6 +30,18 @@ public: u64& CardSerial() { return x210_cardSerial; } rstl::vector< uchar >& BackupBuf() { return x218_backupBuf; } + struct GameFileStateInfo { + double x0_playTime; + CAssetId x8_mlvlId; + float xc_health; + uint x10_energyTanks; + uint x14_timestamp; + uint x18_itemPercent; + float x1c_scanPercent; + bool x20_hardMode; + }; + static GameFileStateInfo LoadGameFileState(const uchar* data); + private: rstl::reserved_vector< bool, 128 > x0_; CAssetId x84_mlvlId; diff --git a/include/MetroidPrime/Player/CHintOptions.hpp b/include/MetroidPrime/Player/CHintOptions.hpp index c2ea6b2e..ab0aae55 100644 --- a/include/MetroidPrime/Player/CHintOptions.hpp +++ b/include/MetroidPrime/Player/CHintOptions.hpp @@ -4,6 +4,7 @@ #include "types.h" #include "rstl/vector.hpp" +#include "rstl/string.hpp" enum EHintState { kHS_Zero, kHS_Waiting, kHS_Displaying, kHS_Delayed }; diff --git a/src/MetroidPrime/CMemoryCardDriver.cpp b/src/MetroidPrime/CMemoryCardDriver.cpp new file mode 100644 index 00000000..622ebe31 --- /dev/null +++ b/src/MetroidPrime/CMemoryCardDriver.cpp @@ -0,0 +1,93 @@ +#include "MetroidPrime/CMemoryCardDriver.hpp" + +bool CMemoryCardDriver::IsCardBusy(EState) { return false; } + +bool CMemoryCardDriver::IsCardWriting(EState) { return false; } + +CMemoryCardDriver::CMemoryCardDriver() {} + +void CMemoryCardDriver::ClearFileInfo() {} + +CMemoryCardDriver::~CMemoryCardDriver() {} + +void CMemoryCardDriver::Update() {} + +void CMemoryCardDriver::HandleCardError(int) {} + +void CMemoryCardDriver::UpdateMountCard(int) {} + +void CMemoryCardDriver::UpdateCardCheck() {} + +void CMemoryCardDriver::UpdateFileRead() {} + +void CMemoryCardDriver::UpdateFileDeleteAlt() {} + +void CMemoryCardDriver::UpdateFileDeleteBad() {} + +void CMemoryCardDriver::UpdateFileCreate() {} + +void CMemoryCardDriver::UpdateFileWrite() {} + +void CMemoryCardDriver::UpdateFileCreateTransactional() {} + +void CMemoryCardDriver::UpdateFileWriteTransactional() {} + +void CMemoryCardDriver::UpdateFileRenameBtoA() {} + +void CMemoryCardDriver::StartFileRenameBtoA() {} + +void CMemoryCardDriver::WriteBackupBuf() {} + +void CMemoryCardDriver::UpdateFileAltDeleteTransactional() {} + +void CMemoryCardDriver::UpdateCardFormat() {} + +void CMemoryCardDriver::StartCardProbe() {} + +void CMemoryCardDriver::UpdateCardProbe() {} + +void CMemoryCardDriver::StartMountCard() {} + +void CMemoryCardDriver::StartCardCheck() {} + +void CMemoryCardDriver::ClearError() {} + +void CMemoryCardDriver::CheckCardCapacity() {} + +void CMemoryCardDriver::NoCardFound() {} + +void CMemoryCardDriver::IndexFiles() {} + +void CMemoryCardDriver::StartFileDeleteBad() {} + +void CMemoryCardDriver::StartFileCreate() {} + +void CMemoryCardDriver::StartFileWrite() {} + +void CMemoryCardDriver::StartFileCreateTransactional() {} + +void CMemoryCardDriver::StartFileWriteTransactional() {} + +void CMemoryCardDriver::StartFileDeleteAltTransactional() {} + +void CMemoryCardDriver::StartCardFormat() {} + +void CMemoryCardDriver::InitializeFileInfo() {} + +void CMemoryCardDriver::ReadFinished() {} + +void CMemoryCardDriver::EraseFileSlot(int) {} + +void CMemoryCardDriver::BuildNewFileSlot(int) {} + +void CMemoryCardDriver::BuildExistingFileSlot(int) {} + +void CMemoryCardDriver::ImportPersistentOptions() {} + +void CMemoryCardDriver::ExportPersistentOptions() {} + +const CGameState::GameFileStateInfo* CMemoryCardDriver::GetGameFileStateInfo(int) { + return nullptr; +}; + +bool CMemoryCardDriver::GetCardFreeBytes() { return false; }