2016-09-25 01:58:20 +00:00
|
|
|
#include "CMemoryCardSys.hpp"
|
|
|
|
#include "GameGlobalObjects.hpp"
|
|
|
|
#include "CSimplePool.hpp"
|
2016-09-30 22:43:19 +00:00
|
|
|
#include "CGameState.hpp"
|
2016-09-25 01:58:20 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2016-09-30 22:43:19 +00:00
|
|
|
CSaveWorldIntermediate::CSaveWorldIntermediate(ResId mlvl, ResId savw)
|
2016-09-25 01:58:20 +00:00
|
|
|
: x0_mlvlId(mlvl), x8_savwId(savw)
|
|
|
|
{
|
|
|
|
if (savw == -1)
|
|
|
|
x2c_dummyWorld = std::make_unique<CDummyWorld>(mlvl, false);
|
|
|
|
else
|
2016-09-30 22:43:19 +00:00
|
|
|
x34_saveWorld = g_SimplePool->GetObj(SObjectTag{FOURCC('SAVW'), savw});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CSaveWorldIntermediate::InitializePump()
|
|
|
|
{
|
|
|
|
if (x2c_dummyWorld)
|
|
|
|
{
|
|
|
|
CDummyWorld& wld = *x2c_dummyWorld;
|
|
|
|
if (!wld.ICheckWorldComplete())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
x4_strgId = wld.IGetStringTableAssetId();
|
|
|
|
x8_savwId = wld.IGetSaveWorldAssetId();
|
|
|
|
u32 areaCount = wld.IGetAreaCount();
|
|
|
|
|
|
|
|
xc_areaIds.reserve(areaCount);
|
|
|
|
for (u32 i=0 ; i<areaCount ; ++i)
|
|
|
|
{
|
|
|
|
const IGameArea* area = wld.IGetAreaAlways(i);
|
|
|
|
xc_areaIds.push_back(area->IGetAreaId());
|
|
|
|
}
|
|
|
|
|
|
|
|
ResId mlvlId = wld.IGetWorldAssetId();
|
|
|
|
CWorldState& mlvlState = g_GameState->StateForWorld(mlvlId);
|
2016-10-09 07:45:04 +00:00
|
|
|
x1c_defaultLayerStates = mlvlState.GetLayerState()->x0_areaLayers;
|
2016-09-30 22:43:19 +00:00
|
|
|
|
|
|
|
x34_saveWorld = g_SimplePool->GetObj(SObjectTag{FOURCC('SAVW'), x8_savwId});
|
|
|
|
x2c_dummyWorld.reset();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!x34_saveWorld)
|
|
|
|
return true;
|
|
|
|
if (x34_saveWorld.IsLoaded() && x34_saveWorld.GetObj())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2016-09-25 01:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CMemoryCardSys::CMemoryCardSys()
|
|
|
|
{
|
2016-10-08 20:32:36 +00:00
|
|
|
x0_hints = g_SimplePool->GetObj("HINT_Hints");
|
2016-09-25 01:58:20 +00:00
|
|
|
xc_memoryWorlds.reserve(16);
|
2016-09-30 22:43:19 +00:00
|
|
|
x1c_worldInter.emplace();
|
|
|
|
x1c_worldInter->reserve(16);
|
2016-09-25 01:58:20 +00:00
|
|
|
g_ResFactory->EnumerateNamedResources([&](const std::string& name, const SObjectTag& tag) -> bool
|
|
|
|
{
|
|
|
|
if (tag.type == FOURCC('MLVL'))
|
|
|
|
{
|
|
|
|
auto existingSearch =
|
2016-09-30 22:43:19 +00:00
|
|
|
std::find_if(xc_memoryWorlds.cbegin(), xc_memoryWorlds.cend(), [&](const auto& wld)
|
|
|
|
{ return wld.first == tag.id; });
|
2016-09-25 01:58:20 +00:00
|
|
|
if (existingSearch == xc_memoryWorlds.cend())
|
2016-09-30 22:43:19 +00:00
|
|
|
{
|
|
|
|
xc_memoryWorlds.emplace_back(tag.id, CSaveWorldMemory{});
|
|
|
|
x1c_worldInter->emplace_back(tag.id, -1);
|
|
|
|
}
|
2016-09-25 01:58:20 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-30 22:43:19 +00:00
|
|
|
bool CMemoryCardSys::InitializePump()
|
|
|
|
{
|
|
|
|
if (!x1c_worldInter)
|
|
|
|
{
|
|
|
|
for (const auto& world : xc_memoryWorlds)
|
|
|
|
{
|
|
|
|
const CSaveWorldMemory& wld = world.second;
|
2016-10-08 20:32:36 +00:00
|
|
|
if (!wld.GetWorldName())
|
|
|
|
continue;
|
2016-09-30 22:43:19 +00:00
|
|
|
if (!wld.GetWorldName().IsLoaded() ||
|
|
|
|
!wld.GetWorldName().GetObj())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!x0_hints.IsLoaded() || !x0_hints.GetObj())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool done = true;
|
|
|
|
for (CSaveWorldIntermediate& world : *x1c_worldInter)
|
|
|
|
{
|
|
|
|
if (world.InitializePump())
|
|
|
|
{
|
|
|
|
if (!world.x34_saveWorld)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto existingSearch =
|
|
|
|
std::find_if(xc_memoryWorlds.begin(), xc_memoryWorlds.end(), [&](const auto& test)
|
|
|
|
{ return test.first == world.x0_mlvlId; });
|
|
|
|
CSaveWorldMemory& wldMemOut = existingSearch->second;
|
|
|
|
wldMemOut.x4_savwId = world.x8_savwId;
|
|
|
|
wldMemOut.x0_strgId = world.x4_strgId;
|
|
|
|
wldMemOut.xc_areaIds = world.xc_areaIds;
|
2016-10-09 07:45:04 +00:00
|
|
|
wldMemOut.x1c_defaultLayerStates = world.x1c_defaultLayerStates;
|
2016-09-30 22:43:19 +00:00
|
|
|
|
|
|
|
CSaveWorld& savw = *world.x34_saveWorld;
|
|
|
|
wldMemOut.x8_areaCount = savw.GetAreaCount();
|
|
|
|
|
|
|
|
x20_scanStates.reserve(x20_scanStates.size() + savw.GetScans().size());
|
|
|
|
for (const CSaveWorld::SScanState& scan : savw.GetScans())
|
2016-12-20 21:51:50 +00:00
|
|
|
x20_scanStates.emplace_back(scan.x0_id, scan.x4_category);
|
2016-09-30 22:43:19 +00:00
|
|
|
|
|
|
|
wldMemOut.x3c_saveWorld = std::move(world.x34_saveWorld);
|
|
|
|
wldMemOut.x2c_worldName = g_SimplePool->GetObj(SObjectTag{FOURCC('STRG'), wldMemOut.x0_strgId});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
done = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (done)
|
|
|
|
x1c_worldInter = std::experimental::nullopt;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-18 04:16:04 +00:00
|
|
|
CMemoryCardSys::CardProbeResults CMemoryCardSys::CardProbe(EMemoryCardPort port)
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
CMemoryCardSys::ECardResult CMemoryCardSys::MountCard(EMemoryCardPort port)
|
|
|
|
{
|
|
|
|
return ECardResult::CARD_RESULT_READY;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMemoryCardSys::ECardResult CMemoryCardSys::CheckCard(EMemoryCardPort port)
|
|
|
|
{
|
|
|
|
return ECardResult::CARD_RESULT_READY;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMemoryCardSys::ECardResult CMemoryCardSys::GetNumFreeBytes(EMemoryCardPort port, s32& freeBytes, s32& freeFiles)
|
|
|
|
{
|
|
|
|
return ECardResult::CARD_RESULT_READY;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMemoryCardSys::ECardResult CMemoryCardSys::GetSerialNo(EMemoryCardPort port, u64& serialOut)
|
|
|
|
{
|
|
|
|
return ECardResult::CARD_RESULT_READY;
|
|
|
|
}
|
|
|
|
|
2016-12-20 21:51:50 +00:00
|
|
|
CMemoryCardSys::ECardResult CMemoryCardSys::GetResultCode(EMemoryCardPort port)
|
|
|
|
{
|
|
|
|
return ECardResult::CARD_RESULT_READY;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMemoryCardSys::ECardResult CMemoryCardSys::GetStatus(EMemoryCardPort port, int fileNo, CARDStat& statOut)
|
|
|
|
{
|
|
|
|
return ECardResult::CARD_RESULT_READY;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMemoryCardSys::ECardResult CMemoryCardSys::DeleteFile(EMemoryCardPort port, const char* name)
|
|
|
|
{
|
|
|
|
return ECardResult::CARD_RESULT_READY;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMemoryCardSys::ECardResult CMemoryCardSys::FastDeleteFile(EMemoryCardPort port, int fileNo)
|
|
|
|
{
|
|
|
|
return ECardResult::CARD_RESULT_READY;
|
|
|
|
}
|
|
|
|
|
2016-09-25 01:58:20 +00:00
|
|
|
}
|