mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-09 00:27:42 +00:00
Explicit Asset ID refactor
This commit is contained in:
@@ -25,80 +25,6 @@ static logvisor::Module Log("urde::SpecMP2");
|
||||
extern hecl::Database::DataSpecEntry SpecEntMP2;
|
||||
extern hecl::Database::DataSpecEntry SpecEntMP2ORIG;
|
||||
|
||||
static const std::unordered_set<uint32_t> IndividualOrigIDs = {
|
||||
0xB7BBD0B4, 0x1F9DA858, 0x2A13C23E, 0xF13452F8, 0xA91A7703, 0xC042EC91, 0x12A12131, 0x5F556002, 0xA9798329,
|
||||
0xB306E26F, 0xCD7B1ACA, 0x8ADA8184, 0x1A29C0E6, 0x5D9F9796, 0x951546A8, 0x7946C4C5, 0x409AA72E,
|
||||
};
|
||||
|
||||
struct OriginalIDs {
|
||||
static void Generate(PAKRouter<DNAMP2::PAKBridge>& pakRouter, hecl::Database::Project& project) {
|
||||
std::unordered_set<UniqueID32> addedIDs;
|
||||
std::vector<UniqueID32> originalIDs;
|
||||
|
||||
pakRouter.enumerateResources([&](const DNAMP2::PAK::Entry* ent) {
|
||||
if (ent->type == FOURCC('MLVL') || ent->type == FOURCC('SCAN') || ent->type == FOURCC('MREA') ||
|
||||
IndividualOrigIDs.find(ent->id.toUint32()) != IndividualOrigIDs.end()) {
|
||||
if (addedIDs.find(ent->id) == addedIDs.cend()) {
|
||||
addedIDs.insert(ent->id);
|
||||
originalIDs.push_back(ent->id);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
std::sort(originalIDs.begin(), originalIDs.end());
|
||||
|
||||
athena::io::YAMLDocWriter yamlW("MP2OriginalIDs");
|
||||
for (const UniqueID32& id : originalIDs) {
|
||||
hecl::ProjectPath path = pakRouter.getWorking(id);
|
||||
yamlW.writeString(id.toString().c_str(), path.getRelativePathUTF8());
|
||||
}
|
||||
hecl::ProjectPath path(project.getProjectWorkingPath(), "MP2/!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) {
|
||||
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) {
|
||||
return a.second < b.second;
|
||||
});
|
||||
for (const auto& idPair : originalIDs) {
|
||||
idPair.second.write(w);
|
||||
idPair.first.write(w);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct SpecMP2 : SpecBase {
|
||||
bool checkStandaloneID(const char* id) const override {
|
||||
if (!memcmp(id, "G2M", 3))
|
||||
@@ -113,19 +39,12 @@ struct SpecMP2 : SpecBase {
|
||||
hecl::ProjectPath m_workPath;
|
||||
hecl::ProjectPath m_cookPath;
|
||||
PAKRouter<DNAMP2::PAKBridge> m_pakRouter;
|
||||
IDRestorer<UniqueID32> m_idRestorer;
|
||||
|
||||
void setThreadProject() override {
|
||||
SpecBase::setThreadProject();
|
||||
UniqueIDBridge::SetIDRestorer(&m_idRestorer);
|
||||
}
|
||||
|
||||
SpecMP2(const hecl::Database::DataSpecEntry* specEntry, hecl::Database::Project& project, bool pc)
|
||||
: SpecBase(specEntry, project, pc)
|
||||
, m_workPath(project.getProjectWorkingPath(), _SYS_STR("MP2"))
|
||||
, m_cookPath(project.getProjectCookedPath(SpecEntMP2), _SYS_STR("MP2"))
|
||||
, m_pakRouter(*this, m_workPath, m_cookPath)
|
||||
, m_idRestorer({project.getProjectWorkingPath(), "MP2/!original_ids.yaml"}, project) {
|
||||
, m_pakRouter(*this, m_workPath, m_cookPath) {
|
||||
setThreadProject();
|
||||
}
|
||||
|
||||
@@ -139,7 +58,7 @@ struct SpecMP2 : SpecBase {
|
||||
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), tolower);
|
||||
if (name.size() > 4) {
|
||||
std::string::iterator extit = lowerName.end() - 4;
|
||||
if (!std::string(extit, lowerName.end()).compare(".pak")) {
|
||||
if (std::string(extit, lowerName.end()) == ".pak") {
|
||||
/* This is a pak */
|
||||
isPak = true;
|
||||
std::string lowerBase(lowerName.begin(), extit);
|
||||
@@ -329,9 +248,6 @@ struct SpecMP2 : SpecBase {
|
||||
|
||||
process.waitUntilComplete();
|
||||
|
||||
/* Generate original ID mapping for MLVL and SCAN entries - marks complete project */
|
||||
OriginalIDs::Generate(m_pakRouter, m_project);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -348,12 +264,12 @@ struct SpecMP2 : SpecBase {
|
||||
bool validateYAMLDNAType(athena::io::IStreamReader& fp) const override {
|
||||
athena::io::YAMLDocReader reader;
|
||||
yaml_parser_set_input(reader.getParser(), (yaml_read_handler_t*)athena::io::YAMLAthenaReader, &fp);
|
||||
return reader.ClassTypeOperation([](const char* classType) {
|
||||
if (!strcmp(classType, DNAMP2::MLVL::DNAType()))
|
||||
return reader.ClassTypeOperation([](std::string_view classType) {
|
||||
if (classType == DNAMP2::MLVL::DNAType())
|
||||
return true;
|
||||
else if (!strcmp(classType, DNAMP2::STRG::DNAType()))
|
||||
else if (classType == DNAMP2::STRG::DNAType())
|
||||
return true;
|
||||
else if (!strcmp(classType, "ATBL"))
|
||||
else if (classType == "ATBL")
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
@@ -367,6 +283,9 @@ struct SpecMP2 : SpecBase {
|
||||
void cookColMesh(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast,
|
||||
hecl::blender::Token& btok, FCookProgress progress) override {}
|
||||
|
||||
void cookArmature(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast,
|
||||
hecl::blender::Token& btok, FCookProgress progress) override {}
|
||||
|
||||
void cookPathMesh(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast,
|
||||
hecl::blender::Token& btok, FCookProgress progress) override {}
|
||||
|
||||
@@ -383,7 +302,7 @@ struct SpecMP2 : SpecBase {
|
||||
hecl::blender::Token& btok, FCookProgress progress) override {}
|
||||
|
||||
void cookYAML(const hecl::ProjectPath& out, const hecl::ProjectPath& in, athena::io::IStreamReader& fin,
|
||||
FCookProgress progress) override {}
|
||||
hecl::blender::Token& btok, FCookProgress progress) override {}
|
||||
|
||||
void flattenDependenciesYAML(athena::io::IStreamReader& fin, std::vector<hecl::ProjectPath>& pathsOut) override {}
|
||||
|
||||
@@ -415,20 +334,6 @@ struct SpecMP2 : SpecBase {
|
||||
DNAMAPU::MAPU::Cook(mapu, out);
|
||||
progress(_SYS_STR("Done"));
|
||||
}
|
||||
|
||||
UniqueID32 newToOriginal(urde::CAssetId id) const {
|
||||
UniqueID32 origId = m_idRestorer.newToOriginal({uint32_t(id.Value()), true});
|
||||
if (origId.isValid())
|
||||
return {origId.toUint32(), true};
|
||||
return {uint32_t(id.Value()), true};
|
||||
}
|
||||
|
||||
urde::CAssetId originalToNew(UniqueID32 id) const {
|
||||
UniqueID32 newId = m_idRestorer.originalToNew(id);
|
||||
if (newId.isValid())
|
||||
return newId.toUint32();
|
||||
return id.toUint32();
|
||||
}
|
||||
};
|
||||
|
||||
hecl::Database::DataSpecEntry SpecEntMP2(
|
||||
|
||||
Reference in New Issue
Block a user