2016-04-13 06:07:23 +00:00
|
|
|
#ifndef __URDE_CMEMORYCARDSYS_HPP__
|
|
|
|
#define __URDE_CMEMORYCARDSYS_HPP__
|
2015-08-17 05:26:58 +00:00
|
|
|
|
2016-09-25 01:58:20 +00:00
|
|
|
#include "CToken.hpp"
|
|
|
|
#include "World/CWorld.hpp"
|
|
|
|
#include "CGameHintInfo.hpp"
|
2016-09-30 22:43:19 +00:00
|
|
|
#include "CSaveWorld.hpp"
|
2016-12-21 19:27:15 +00:00
|
|
|
#include "GuiSys/CStringTable.hpp"
|
2016-12-28 08:51:28 +00:00
|
|
|
#include "kabufuda/Card.hpp"
|
2016-09-25 01:58:20 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2015-08-17 22:05:00 +00:00
|
|
|
{
|
2016-09-25 01:58:20 +00:00
|
|
|
class CDummyWorld;
|
2016-09-30 22:43:19 +00:00
|
|
|
class CStringTable;
|
2016-12-23 06:41:39 +00:00
|
|
|
class CSimplePool;
|
2016-09-25 01:58:20 +00:00
|
|
|
|
|
|
|
class CSaveWorldMemory
|
|
|
|
{
|
2016-09-30 22:43:19 +00:00
|
|
|
friend class CMemoryCardSys;
|
|
|
|
ResId x0_strgId = -1;
|
|
|
|
ResId x4_savwId = -1;
|
|
|
|
u32 x8_areaCount;
|
2016-10-09 07:45:04 +00:00
|
|
|
std::vector<ResId> xc_areaIds;
|
|
|
|
std::vector<CWorldLayers::Area> x1c_defaultLayerStates;
|
2016-09-30 22:43:19 +00:00
|
|
|
TLockedToken<CStringTable> x2c_worldName; /* used to be optional */
|
|
|
|
TLockedToken<CSaveWorld> x3c_saveWorld; /* used to be optional */
|
2016-09-25 01:58:20 +00:00
|
|
|
|
|
|
|
public:
|
2016-09-30 22:43:19 +00:00
|
|
|
ResId GetSaveWorldAssetId() const { return x4_savwId; }
|
|
|
|
u32 GetAreaCount() const { return x8_areaCount; }
|
|
|
|
|
|
|
|
const TLockedToken<CStringTable>& GetWorldName() const { return x2c_worldName; }
|
|
|
|
const TLockedToken<CSaveWorld>& GetSaveWorld() const { return x3c_saveWorld; }
|
2016-09-25 01:58:20 +00:00
|
|
|
};
|
|
|
|
|
2016-09-30 22:43:19 +00:00
|
|
|
class CSaveWorldIntermediate
|
2016-09-25 01:58:20 +00:00
|
|
|
{
|
2016-09-30 22:43:19 +00:00
|
|
|
friend class CMemoryCardSys;
|
2016-10-08 20:32:36 +00:00
|
|
|
ResId x0_mlvlId;
|
|
|
|
ResId x4_strgId;
|
|
|
|
ResId x8_savwId;
|
|
|
|
std::vector<ResId> xc_areaIds;
|
2016-10-09 07:45:04 +00:00
|
|
|
std::vector<CWorldLayers::Area> x1c_defaultLayerStates;
|
2016-09-30 22:43:19 +00:00
|
|
|
std::unique_ptr<CDummyWorld> x2c_dummyWorld;
|
|
|
|
TLockedToken<CSaveWorld> x34_saveWorld; /* Used to be auto_ptr */
|
|
|
|
|
|
|
|
public:
|
|
|
|
CSaveWorldIntermediate(ResId mlvl, ResId savw);
|
|
|
|
|
|
|
|
bool InitializePump();
|
2016-09-25 01:58:20 +00:00
|
|
|
};
|
2015-08-17 22:05:00 +00:00
|
|
|
|
2015-08-17 05:26:58 +00:00
|
|
|
class CMemoryCardSys
|
|
|
|
{
|
2016-09-25 01:58:20 +00:00
|
|
|
TLockedToken<CGameHintInfo> x0_hints;
|
2016-09-30 22:43:19 +00:00
|
|
|
std::vector<std::pair<ResId, CSaveWorldMemory>> xc_memoryWorlds; /* MLVL as key */
|
|
|
|
std::experimental::optional<std::vector<CSaveWorldIntermediate>> x1c_worldInter; /* used to be auto_ptr of vector */
|
2016-12-20 21:51:50 +00:00
|
|
|
std::vector<std::pair<ResId, CSaveWorld::EScanCategory>> x20_scanStates;
|
2016-09-25 01:58:20 +00:00
|
|
|
public:
|
2016-12-28 21:39:38 +00:00
|
|
|
static kabufuda::SystemString ResolveDolphinCardPath(kabufuda::ECardSlot slot);
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
using ECardResult = kabufuda::ECardResult;
|
|
|
|
struct CardResult
|
2016-12-18 04:16:04 +00:00
|
|
|
{
|
2016-12-28 08:51:28 +00:00
|
|
|
ECardResult result;
|
|
|
|
CardResult(ECardResult res) : result(res) {}
|
|
|
|
operator ECardResult() const { return result; }
|
|
|
|
operator bool() const { return result != ECardResult::READY; }
|
2016-12-18 04:16:04 +00:00
|
|
|
};
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
struct CardFileHandle
|
2016-12-20 21:51:50 +00:00
|
|
|
{
|
2016-12-28 08:51:28 +00:00
|
|
|
kabufuda::ECardSlot slot;
|
|
|
|
std::unique_ptr<kabufuda::IFileHandle> handle;
|
|
|
|
CardFileHandle(kabufuda::ECardSlot slot) : slot(slot) {}
|
|
|
|
kabufuda::IFileHandle* operator->() const { return handle.get(); }
|
|
|
|
operator std::unique_ptr<kabufuda::IFileHandle>&() { return handle; }
|
|
|
|
operator const std::unique_ptr<kabufuda::IFileHandle>&() const { return handle; }
|
2016-12-20 21:51:50 +00:00
|
|
|
};
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
using CardStat = kabufuda::CardStat;
|
|
|
|
const std::vector<CGameHintInfo::CGameHint>& GetHints() const { return x0_hints->GetHints(); }
|
|
|
|
const std::vector<std::pair<ResId, CSaveWorldMemory>>& GetMemoryWorlds() const { return xc_memoryWorlds; }
|
|
|
|
const std::vector<std::pair<ResId, CSaveWorld::EScanCategory>>& GetScanStates() const { return x20_scanStates; }
|
|
|
|
CMemoryCardSys();
|
|
|
|
bool InitializePump();
|
2016-12-23 06:41:39 +00:00
|
|
|
|
|
|
|
struct CCardFileInfo
|
|
|
|
{
|
|
|
|
struct Icon
|
|
|
|
{
|
|
|
|
ResId x0_id;
|
2016-12-28 08:51:28 +00:00
|
|
|
kabufuda::EAnimationSpeed x4_speed;
|
2016-12-23 06:41:39 +00:00
|
|
|
TLockedToken<CTexture> x8_tex;
|
2016-12-28 08:51:28 +00:00
|
|
|
Icon(ResId id, kabufuda::EAnimationSpeed speed, CSimplePool& sp, const CVParamTransfer& cv);
|
2016-12-23 06:41:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class EStatus
|
|
|
|
{
|
|
|
|
Standby,
|
|
|
|
Transferring,
|
|
|
|
Done
|
|
|
|
};
|
|
|
|
|
|
|
|
EStatus x0_status = EStatus::Standby;
|
2016-12-28 08:51:28 +00:00
|
|
|
//CARDFileInfo x4_info;
|
|
|
|
CardFileHandle m_handle;
|
2016-12-24 00:45:51 +00:00
|
|
|
std::string x18_fileName;
|
|
|
|
std::string x28_comment;
|
2016-12-23 06:41:39 +00:00
|
|
|
ResId x3c_bannerTex = -1;
|
|
|
|
std::experimental::optional<TLockedToken<CTexture>> x40_bannerTok;
|
|
|
|
rstl::reserved_vector<Icon, 8> x50_iconToks;
|
|
|
|
std::vector<u8> xf4_saveBuffer;
|
|
|
|
std::vector<u8> x104_cardBuffer;
|
|
|
|
|
|
|
|
CVParamTransfer m_texParam = {new TObjOwnerParam<u32>(SBIG('OTEX'))};
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
CCardFileInfo(kabufuda::ECardSlot port, const std::string& name)
|
|
|
|
: m_handle(port), x18_fileName(name) {}
|
2016-12-23 06:41:39 +00:00
|
|
|
|
|
|
|
void LockBannerToken(ResId bannerTxtr, CSimplePool& sp);
|
2016-12-28 08:51:28 +00:00
|
|
|
void LockIconToken(ResId iconTxtr, kabufuda::EAnimationSpeed speed, CSimplePool& sp);
|
2016-12-23 06:41:39 +00:00
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
kabufuda::ECardSlot GetCardPort() const { return m_handle.slot; }
|
|
|
|
int GetFileNo() const { return m_handle->getFileNo(); }
|
2016-12-23 06:41:39 +00:00
|
|
|
u32 CalculateBannerDataSize() const;
|
|
|
|
u32 CalculateTotalDataSize() const;
|
|
|
|
void BuildCardBuffer();
|
|
|
|
void WriteBannerData(CMemoryOutStream& out) const;
|
|
|
|
void WriteIconData(CMemoryOutStream& out) const;
|
2016-12-24 00:45:51 +00:00
|
|
|
void SetComment(const std::string& c) { x28_comment = c; }
|
2016-12-23 06:41:39 +00:00
|
|
|
ECardResult PumpCardTransfer();
|
2016-12-28 08:51:28 +00:00
|
|
|
ECardResult GetStatus(CardStat& stat) const;
|
2016-12-23 06:41:39 +00:00
|
|
|
ECardResult CreateFile();
|
2016-12-28 08:51:28 +00:00
|
|
|
ECardResult WriteFile();
|
|
|
|
ECardResult CloseFile();
|
2016-12-24 00:45:51 +00:00
|
|
|
|
|
|
|
CMemoryOutStream BeginMemoryOut(u32 sz)
|
|
|
|
{
|
|
|
|
xf4_saveBuffer.resize(sz);
|
|
|
|
return CMemoryOutStream(xf4_saveBuffer.data(), sz);
|
|
|
|
}
|
2016-12-23 06:41:39 +00:00
|
|
|
};
|
|
|
|
|
2016-12-28 08:51:28 +00:00
|
|
|
static kabufuda::ProbeResults CardProbe(kabufuda::ECardSlot port);
|
|
|
|
static ECardResult MountCard(kabufuda::ECardSlot port);
|
2016-12-28 21:51:33 +00:00
|
|
|
static ECardResult UnmountCard(kabufuda::ECardSlot port);
|
2016-12-28 08:51:28 +00:00
|
|
|
static ECardResult CheckCard(kabufuda::ECardSlot port);
|
|
|
|
static ECardResult CreateFile(kabufuda::ECardSlot port, const char* name, u32 size, CardFileHandle& info);
|
|
|
|
static ECardResult OpenFile(kabufuda::ECardSlot port, const char* name, CardFileHandle& info);
|
|
|
|
static ECardResult FastOpenFile(kabufuda::ECardSlot port, int fileNo, CardFileHandle& info);
|
|
|
|
static ECardResult CloseFile(CardFileHandle& info);
|
|
|
|
static ECardResult ReadFile(const CardFileHandle& info, void* buf, s32 length, s32 offset);
|
|
|
|
static ECardResult WriteFile(const CardFileHandle& info, const void* buf, s32 length, s32 offset);
|
|
|
|
static ECardResult GetNumFreeBytes(kabufuda::ECardSlot port, s32& freeBytes, s32& freeFiles);
|
|
|
|
static ECardResult GetSerialNo(kabufuda::ECardSlot port, u64& serialOut);
|
|
|
|
static ECardResult GetResultCode(kabufuda::ECardSlot port);
|
2016-12-28 21:39:38 +00:00
|
|
|
static ECardResult GetStatus(const CardFileHandle& info, CardStat& statOut);
|
|
|
|
static ECardResult SetStatus(const CardFileHandle& info, const CardStat& stat);
|
2016-12-28 08:51:28 +00:00
|
|
|
static ECardResult DeleteFile(kabufuda::ECardSlot port, const char* name);
|
|
|
|
static ECardResult FastDeleteFile(kabufuda::ECardSlot port, int fileNo);
|
|
|
|
static ECardResult Rename(kabufuda::ECardSlot port, const char* oldName, const char* newName);
|
|
|
|
static ECardResult FormatCard(kabufuda::ECardSlot port);
|
2016-12-28 21:51:33 +00:00
|
|
|
|
|
|
|
static void CommitToDisk(kabufuda::ECardSlot port);
|
2015-08-17 05:26:58 +00:00
|
|
|
};
|
|
|
|
|
2015-08-17 22:05:00 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 06:07:23 +00:00
|
|
|
#endif // __URDE_CMEMORYCARDSYS_HPP__
|