mirror of https://github.com/AxioDL/metaforce.git
Add OIDS resource for translating against original IDs
This commit is contained in:
parent
1c7c9caef9
commit
0ed44f1cdc
|
@ -48,6 +48,82 @@ extern hecl::Database::DataSpecEntry SpecEntMP1;
|
|||
extern hecl::Database::DataSpecEntry SpecEntMP1PC;
|
||||
extern hecl::Database::DataSpecEntry SpecEntMP1ORIG;
|
||||
|
||||
struct OriginalIDs
|
||||
{
|
||||
static void Generate(PAKRouter<DNAMP1::PAKBridge>& pakRouter,
|
||||
hecl::Database::Project& project)
|
||||
{
|
||||
std::vector<UniqueID32> originalIDs;
|
||||
pakRouter.enumerateResources([&](const DNAMP1::PAK::Entry* ent) -> bool
|
||||
{
|
||||
if (ent->type == FOURCC('MLVL') || ent->type == FOURCC('SCAN'))
|
||||
originalIDs.push_back(ent->id);
|
||||
return true;
|
||||
});
|
||||
std::sort(originalIDs.begin(), originalIDs.end());
|
||||
|
||||
athena::io::YAMLDocWriter yamlW("MP1OriginalIDs");
|
||||
for (const UniqueID32& id : originalIDs)
|
||||
{
|
||||
hecl::ProjectPath path = pakRouter.getWorking(id);
|
||||
yamlW.writeString(id.toString().c_str(), path.getRelativePathUTF8());
|
||||
}
|
||||
hecl::ProjectPath path(project.getProjectWorkingPath(), "MP1/!original_ids.yaml");
|
||||
path.makeDirChain(false);
|
||||
athena::io::FileWriter fileW(path.getAbsolutePath());
|
||||
yamlW.finish(&fileW);
|
||||
}
|
||||
|
||||
static void Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPath)
|
||||
{
|
||||
hecl::Database::Project& project = inPath.getProject();
|
||||
athena::io::YAMLDocReader r;
|
||||
athena::io::FileReader fr(inPath.getAbsolutePath());
|
||||
if (!fr.isOpen() || !r.parse(&fr))
|
||||
return;
|
||||
|
||||
std::vector<std::pair<UniqueID32, UniqueID32>> originalIDs;
|
||||
originalIDs.reserve(r.getRootNode()->m_mapChildren.size());
|
||||
for (const auto& node : r.getRootNode()->m_mapChildren)
|
||||
{
|
||||
char* end = const_cast<char*>(node.first.c_str());
|
||||
u32 id = strtoul(end, &end, 16);
|
||||
if (end != node.first.c_str() + 8)
|
||||
continue;
|
||||
|
||||
hecl::ProjectPath path(project.getProjectWorkingPath(),
|
||||
node.second->m_scalarString.c_str());
|
||||
originalIDs.push_back(std::make_pair(id, path.hash().val32()));
|
||||
}
|
||||
std::sort(originalIDs.begin(), originalIDs.end(),
|
||||
[](const std::pair<UniqueID32, UniqueID32>& a,
|
||||
const std::pair<UniqueID32, UniqueID32>& b) -> bool
|
||||
{
|
||||
return a.first < b.first;
|
||||
});
|
||||
|
||||
athena::io::FileWriter w(outPath.getAbsolutePath());
|
||||
w.writeUint32Big(originalIDs.size());
|
||||
for (const auto& idPair : originalIDs)
|
||||
{
|
||||
idPair.first.write(w);
|
||||
idPair.second.write(w);
|
||||
}
|
||||
|
||||
std::sort(originalIDs.begin(), originalIDs.end(),
|
||||
[](const std::pair<UniqueID32, UniqueID32>& a,
|
||||
const std::pair<UniqueID32, UniqueID32>& b) -> bool
|
||||
{
|
||||
return a.second < b.second;
|
||||
});
|
||||
for (const auto& idPair : originalIDs)
|
||||
{
|
||||
idPair.second.write(w);
|
||||
idPair.first.write(w);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct SpecMP1 : SpecBase
|
||||
{
|
||||
bool checkStandaloneID(const char* id) const
|
||||
|
@ -264,27 +340,7 @@ struct SpecMP1 : SpecBase
|
|||
mp1OutPath.makeDir();
|
||||
|
||||
/* Generate original ID mapping for MLVL and SCAN entries */
|
||||
{
|
||||
std::vector<UniqueID32> originalIDs;
|
||||
m_pakRouter.enumerateResources([&](const DNAMP1::PAK::Entry* ent) -> bool
|
||||
{
|
||||
if (ent->type == FOURCC('MLVL') || ent->type == FOURCC('SCAN'))
|
||||
originalIDs.push_back(ent->id);
|
||||
return true;
|
||||
});
|
||||
std::sort(originalIDs.begin(), originalIDs.end());
|
||||
|
||||
athena::io::YAMLDocWriter yamlW("MP1OriginalIDs");
|
||||
for (const UniqueID32& id : originalIDs)
|
||||
{
|
||||
hecl::ProjectPath path = m_pakRouter.getWorking(id);
|
||||
yamlW.writeString(id.toString().c_str(), path.getRelativePathUTF8());
|
||||
}
|
||||
hecl::ProjectPath path(m_project.getProjectWorkingPath(), "MP1/original_ids.yaml");
|
||||
path.makeDirChain(false);
|
||||
athena::io::FileWriter fileW(path.getAbsolutePath());
|
||||
yamlW.finish(&fileW);
|
||||
}
|
||||
OriginalIDs::Generate(m_pakRouter, m_project);
|
||||
|
||||
/* Extract non-pak files */
|
||||
progress(_S("MP1 Root"), _S(""), 3, 0.0);
|
||||
|
@ -426,6 +482,8 @@ struct SpecMP1 : SpecBase
|
|||
return true;
|
||||
else if (!strcmp(classType, "ATBL"))
|
||||
return true;
|
||||
else if (!strcmp(classType, "MP1OriginalIDs"))
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
@ -597,6 +655,11 @@ struct SpecMP1 : SpecBase
|
|||
resTag.type = SBIG('ATBL');
|
||||
return true;
|
||||
}
|
||||
else if (!strcmp(className, "MP1OriginalIDs"))
|
||||
{
|
||||
resTag.type = SBIG('OIDS');
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}))
|
||||
|
@ -859,6 +922,10 @@ struct SpecMP1 : SpecBase
|
|||
{
|
||||
DNAAudio::ATBL::Cook(in, out);
|
||||
}
|
||||
else if (!classStr.compare("MP1OriginalIDs"))
|
||||
{
|
||||
OriginalIDs::Cook(in, out);
|
||||
}
|
||||
}
|
||||
progress(_S("Done"));
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ makeProj:
|
|||
else
|
||||
m_vm.SetupEditorView();
|
||||
|
||||
m_factoryMP1.IndexMP1Resources(*m_proj);
|
||||
m_factoryMP1.IndexMP1Resources(*m_proj, m_objStore);
|
||||
m_mainMP1.emplace(m_factoryMP1, m_objStore, m_vm.m_mainBooFactory,
|
||||
m_vm.m_mainCommandQueue, m_vm.m_renderTex);
|
||||
m_vm.InitMP1(*m_mainMP1);
|
||||
|
|
|
@ -375,6 +375,12 @@ void ProjectResourceFactoryBase::BackgroundIndexProc()
|
|||
}
|
||||
}
|
||||
|
||||
/* Add special original IDs resource if exists (not name-cached to disk) */
|
||||
hecl::ProjectPath oidsPath(specRoot, "!original_ids.yaml");
|
||||
SObjectTag oidsTag = BuildTagFromPath(oidsPath, m_backgroundBlender);
|
||||
if (oidsTag)
|
||||
m_catalogNameToTag["mp1originalids"] = oidsTag;
|
||||
|
||||
Log.report(logvisor::Info, _S("Background index of '%s' started"), m_origSpec->m_name);
|
||||
BackgroundIndexRecursiveProc(specRoot, cacheWriter, nameWriter, 0);
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "Audio/CSfxManager.hpp"
|
||||
#include "Runtime/CDependencyGroup.hpp"
|
||||
#include "DataSpec/DNACommon/TXTR.hpp"
|
||||
#include "CSimplePool.hpp"
|
||||
#include "GameGlobalObjects.hpp"
|
||||
|
||||
namespace DataSpec
|
||||
{
|
||||
|
@ -33,6 +35,57 @@ extern hecl::Database::DataSpecEntry SpecEntMP1PC;
|
|||
namespace urde
|
||||
{
|
||||
|
||||
class MP1OriginalIDs
|
||||
{
|
||||
std::vector<std::pair<ResId, ResId>> m_origToNew;
|
||||
std::vector<std::pair<ResId, ResId>> m_newToOrig;
|
||||
|
||||
public:
|
||||
MP1OriginalIDs(CInputStream& in)
|
||||
{
|
||||
u32 count = in.readUint32Big();
|
||||
m_origToNew.reserve(count);
|
||||
for (u32 i=0 ; i<count ; ++i)
|
||||
{
|
||||
ResId a = in.readUint32Big();
|
||||
ResId b = in.readUint32Big();
|
||||
m_origToNew.push_back(std::make_pair(a, b));
|
||||
}
|
||||
m_newToOrig.reserve(count);
|
||||
for (u32 i=0 ; i<count ; ++i)
|
||||
{
|
||||
ResId a = in.readUint32Big();
|
||||
ResId b = in.readUint32Big();
|
||||
m_newToOrig.push_back(std::make_pair(a, b));
|
||||
}
|
||||
}
|
||||
|
||||
ResId TranslateOriginalToNew(ResId id) const
|
||||
{
|
||||
auto search = std::lower_bound(m_origToNew.cbegin(), m_origToNew.cend(),
|
||||
std::make_pair(id, ResId(0)));
|
||||
if (search == m_origToNew.cend() || search->first != id)
|
||||
return -1;
|
||||
return search->second;
|
||||
}
|
||||
|
||||
ResId TranslateNewToOriginal(ResId id) const
|
||||
{
|
||||
auto search = std::lower_bound(m_newToOrig.cbegin(), m_newToOrig.cend(),
|
||||
std::make_pair(id, ResId(0)));
|
||||
if (search == m_newToOrig.cend() || search->first != id)
|
||||
return -1;
|
||||
return search->second;
|
||||
}
|
||||
};
|
||||
|
||||
CFactoryFnReturn FMP1OriginalIDsFactory(const SObjectTag& tag, CInputStream& in,
|
||||
const CVParamTransfer& param,
|
||||
CObjectReference* selfRef)
|
||||
{
|
||||
return TToken<MP1OriginalIDs>::GetIObjObjectFor(std::make_unique<MP1OriginalIDs>(in));
|
||||
}
|
||||
|
||||
ProjectResourceFactoryMP1::ProjectResourceFactoryMP1(hecl::ClientProcess& clientProc)
|
||||
: ProjectResourceFactoryBase(clientProc)
|
||||
{
|
||||
|
@ -54,11 +107,29 @@ ProjectResourceFactoryMP1::ProjectResourceFactoryMP1(hecl::ClientProcess& client
|
|||
m_factoryMgr.AddFactory(FOURCC('HINT'), FFactoryFunc(FHintFactory));
|
||||
m_factoryMgr.AddFactory(FOURCC('SAVW'), FFactoryFunc(FSaveWorldFactory));
|
||||
m_factoryMgr.AddFactory(FOURCC('MAPW'), FFactoryFunc(FMapWorldFactory));
|
||||
m_factoryMgr.AddFactory(FOURCC('OIDS'), FFactoryFunc(FMP1OriginalIDsFactory));
|
||||
}
|
||||
|
||||
void ProjectResourceFactoryMP1::IndexMP1Resources(hecl::Database::Project& proj)
|
||||
void ProjectResourceFactoryMP1::IndexMP1Resources(hecl::Database::Project& proj, CSimplePool& sp)
|
||||
{
|
||||
BeginBackgroundIndex(proj, DataSpec::SpecEntMP1, DataSpec::SpecEntMP1PC);
|
||||
m_origIds = sp.GetObj("MP1OriginalIDs");
|
||||
}
|
||||
|
||||
void ProjectResourceFactoryMP1::Shutdown()
|
||||
{
|
||||
m_origIds = TLockedToken<MP1OriginalIDs>();
|
||||
ProjectResourceFactoryBase::Shutdown();
|
||||
}
|
||||
|
||||
ResId ProjectResourceFactoryMP1::TranslateOriginalToNew(ResId id) const
|
||||
{
|
||||
return m_origIds->TranslateOriginalToNew(id);
|
||||
}
|
||||
|
||||
ResId ProjectResourceFactoryMP1::TranslateNewToOriginal(ResId id) const
|
||||
{
|
||||
return m_origIds->TranslateNewToOriginal(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,15 +2,23 @@
|
|||
#define URDE_PROJECT_RESOURCE_FACTORY_MP1_HPP
|
||||
|
||||
#include "ProjectResourceFactoryBase.hpp"
|
||||
#include "CToken.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
class MP1OriginalIDs;
|
||||
class CSimplePool;
|
||||
|
||||
class ProjectResourceFactoryMP1 : public ProjectResourceFactoryBase
|
||||
{
|
||||
TLockedToken<MP1OriginalIDs> m_origIds;
|
||||
public:
|
||||
ProjectResourceFactoryMP1(hecl::ClientProcess& clientProc);
|
||||
void IndexMP1Resources(hecl::Database::Project& proj);
|
||||
void IndexMP1Resources(hecl::Database::Project& proj, CSimplePool& sp);
|
||||
void Shutdown();
|
||||
|
||||
ResId TranslateOriginalToNew(ResId id) const;
|
||||
ResId TranslateNewToOriginal(ResId id) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ CGameState::GameFileStateInfo CGameState::LoadGameFileState(const u8* data)
|
|||
|
||||
ret.x20_hardMode = stream.ReadEncoded(1);
|
||||
stream.ReadEncoded(1);
|
||||
ret.x8_mlvlId = stream.ReadEncoded(32);
|
||||
ret.x8_mlvlId = g_ResFactory->TranslateOriginalToNew(stream.ReadEncoded(32));
|
||||
|
||||
BitsToDouble conv;
|
||||
conv.low = stream.ReadEncoded(32);
|
||||
|
@ -158,7 +158,7 @@ CGameState::CGameState(CBitStreamReader& stream, u32 saveIdx)
|
|||
|
||||
x228_24_hardMode = stream.ReadEncoded(1);
|
||||
x228_25_deferPowerupInit = stream.ReadEncoded(1);
|
||||
x84_mlvlId = stream.ReadEncoded(32);
|
||||
x84_mlvlId = g_ResFactory->TranslateOriginalToNew(stream.ReadEncoded(32));
|
||||
EnsureWorldPakReady(x84_mlvlId);
|
||||
|
||||
BitsToDouble conv;
|
||||
|
@ -227,7 +227,7 @@ void CGameState::PutTo(CBitStreamWriter& writer) const
|
|||
writer.WriteEncoded(CBasics::ToWiiTime(std::chrono::system_clock::now()) / CBasics::TICKS_PER_SECOND, 32);
|
||||
writer.WriteEncoded(x228_24_hardMode, 1);
|
||||
writer.WriteEncoded(x228_25_deferPowerupInit, 1);
|
||||
writer.WriteEncoded(x84_mlvlId, 32);
|
||||
writer.WriteEncoded(g_ResFactory->TranslateNewToOriginal(x84_mlvlId), 32);
|
||||
|
||||
BitsToDouble conv;
|
||||
conv.doub = xa0_playTime;
|
||||
|
|
|
@ -40,6 +40,9 @@ public:
|
|||
//virtual bool LoadResourcePartAsync(const urde::SObjectTag& tag, u32 size, u32 off, std::unique_ptr<u8[]>& target)=0;
|
||||
virtual std::unique_ptr<u8[]> LoadResourceSync(const urde::SObjectTag& tag)=0;
|
||||
virtual std::unique_ptr<u8[]> LoadResourcePartSync(const urde::SObjectTag& tag, u32 size, u32 off)=0;
|
||||
|
||||
virtual ResId TranslateOriginalToNew(ResId id) const { return -1; }
|
||||
virtual ResId TranslateNewToOriginal(ResId id) const { return -1; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue