From 2c151a0f3bcdbb26c39d9c8bf76cd4efb1965902 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 27 May 2018 15:54:55 -1000 Subject: [PATCH] Ensure *all* EVNT resources are extracted --- DataSpec/DNACommon/ANCS.cpp | 2 +- DataSpec/DNAMP1/ANCS.cpp | 24 ++++++++++++++- DataSpec/DNAMP1/ANCS.hpp | 61 +++++++++++++++++-------------------- DataSpec/DNAMP1/ANIM.cpp | 22 +++++++++++++ DataSpec/DNAMP1/ANIM.hpp | 2 ++ DataSpec/DNAMP1/DNAMP1.cpp | 2 +- DataSpec/DNAMP2/ANCS.hpp | 9 +++--- DataSpec/DNAMP3/CHAR.hpp | 3 +- 8 files changed, 84 insertions(+), 41 deletions(-) diff --git a/DataSpec/DNACommon/ANCS.cpp b/DataSpec/DNACommon/ANCS.cpp index 9d42dc941..f217f2ccf 100644 --- a/DataSpec/DNACommon/ANCS.cpp +++ b/DataSpec/DNACommon/ANCS.cpp @@ -164,7 +164,7 @@ bool ReadANCSToBlender(hecl::blender::Connection& conn, /* Get animation primitives */ std::map> animResInfo; - ancs.getAnimationResInfo(animResInfo); + ancs.getAnimationResInfo(&pakRouter, animResInfo); for (const auto& id : animResInfo) { typename ANCSDNA::ANIMType anim; diff --git a/DataSpec/DNAMP1/ANCS.cpp b/DataSpec/DNAMP1/ANCS.cpp index dfbf1fd10..1ff56337b 100644 --- a/DataSpec/DNAMP1/ANCS.cpp +++ b/DataSpec/DNAMP1/ANCS.cpp @@ -1053,6 +1053,28 @@ void ANCS::AnimationSet::Enumerate(athena::io::YAMLDocWriter& } } +void ANCS::AnimationSet::MetaAnimPrimitive:: +gatherPrimitives(PAKRouter* pakRouter, + std::map>& out) +{ + if (!pakRouter) + { + out[animIdx] = {animName, animId, UniqueID32(), false}; + return; + } + + const nod::Node* node; + const PAK::Entry* entry = pakRouter->lookupEntry(animId, &node, true); + if (!entry) + { + out[animIdx] = {animName, animId, UniqueID32(), false}; + return; + } + + PAKEntryReadStream rs = entry->beginReadStream(*node); + out[animIdx] = {animName, animId, ANIM::GetEVNTId(rs), false}; +} + const char* ANCS::AnimationSet::DNAType() { return "urde::DNAMP1::ANCS::AnimationSet"; @@ -1095,7 +1117,7 @@ bool ANCS::Extract(const SpecBase& dataSpec, /* Extract EVNTs */ std::map> animRes; - ancs.getAnimationResInfo(animRes); + ancs.getAnimationResInfo(&pakRouter, animRes); for (const auto& res : animRes) { if (res.second.evntId) diff --git a/DataSpec/DNAMP1/ANCS.hpp b/DataSpec/DNAMP1/ANCS.hpp index 152d1c2fa..7373267a4 100644 --- a/DataSpec/DNAMP1/ANCS.hpp +++ b/DataSpec/DNAMP1/ANCS.hpp @@ -168,7 +168,8 @@ struct ANCS : BigDNA const char* m_typeStr; IMetaAnim(Type type, const char* typeStr) : m_type(type), m_typeStr(typeStr) {} - virtual void gatherPrimitives(std::map>& out)=0; + virtual void gatherPrimitives(PAKRouter* pakRouter, + std::map>& out)=0; virtual bool enumeratePrimitives(const std::function& func)=0; }; struct MetaAnimFactory : BigDNA @@ -188,10 +189,8 @@ struct ANCS : BigDNA Value unk1; Value unk2; - void gatherPrimitives(std::map>& out) - { - out[animIdx] = {animName, animId, UniqueID32(), false}; - } + void gatherPrimitives(PAKRouter* pakRouter, + std::map>& out); bool enumeratePrimitives(const std::function& func) { @@ -209,10 +208,11 @@ struct ANCS : BigDNA Value unkFloat; Value unk; - void gatherPrimitives(std::map>& out) + void gatherPrimitives(PAKRouter* pakRouter, + std::map>& out) { - animA.m_anim->gatherPrimitives(out); - animB.m_anim->gatherPrimitives(out); + animA.m_anim->gatherPrimitives(pakRouter, out); + animB.m_anim->gatherPrimitives(pakRouter, out); } bool enumeratePrimitives(const std::function& func) @@ -235,10 +235,11 @@ struct ANCS : BigDNA Value unkFloat; Value unk; - void gatherPrimitives(std::map>& out) + void gatherPrimitives(PAKRouter* pakRouter, + std::map>& out) { - animA.m_anim->gatherPrimitives(out); - animB.m_anim->gatherPrimitives(out); + animA.m_anim->gatherPrimitives(pakRouter, out); + animB.m_anim->gatherPrimitives(pakRouter, out); } bool enumeratePrimitives(const std::function& func) @@ -264,10 +265,11 @@ struct ANCS : BigDNA }; Vector children; - void gatherPrimitives(std::map>& out) + void gatherPrimitives(PAKRouter* pakRouter, + std::map>& out) { for (const auto& child : children) - child.anim.m_anim->gatherPrimitives(out); + child.anim.m_anim->gatherPrimitives(pakRouter, out); } bool enumeratePrimitives(const std::function& func) @@ -286,10 +288,11 @@ struct ANCS : BigDNA Value animCount; Vector children; - void gatherPrimitives(std::map>& out) + void gatherPrimitives(PAKRouter* pakRouter, + std::map>& out) { for (const auto& child : children) - child.m_anim->gatherPrimitives(out); + child.m_anim->gatherPrimitives(pakRouter, out); } bool enumeratePrimitives(const std::function& func) @@ -322,7 +325,8 @@ struct ANCS : BigDNA const char* m_typeStr; IMetaTrans(Type type, const char* typeStr) : m_type(type), m_typeStr(typeStr) {} - virtual void gatherPrimitives(std::map>& out) {} + virtual void gatherPrimitives(PAKRouter* pakRouter, + std::map>& out) {} virtual bool enumeratePrimitives(const std::function& func) {return true;} }; struct MetaTransFactory : BigDNA @@ -339,9 +343,10 @@ struct ANCS : BigDNA AT_DECL_DNAV MetaAnimFactory anim; - void gatherPrimitives(std::map>& out) + void gatherPrimitives(PAKRouter* pakRouter, + std::map>& out) { - anim.m_anim->gatherPrimitives(out); + anim.m_anim->gatherPrimitives(pakRouter, out); } bool enumeratePrimitives(const std::function& func) @@ -432,28 +437,18 @@ struct ANCS : BigDNA } } - void getAnimationResInfo(std::map>& out) const + void getAnimationResInfo(PAKRouter* pakRouter, + std::map>& out) const { out.clear(); for (const AnimationSet::Animation& ai : animationSet.animations) if (AnimationSet::IMetaAnim* anim = ai.metaAnim.m_anim.get()) - anim->gatherPrimitives(out); + anim->gatherPrimitives(pakRouter, out); for (const AnimationSet::Transition& ti : animationSet.transitions) if (AnimationSet::IMetaTrans* trans = ti.metaTrans.m_trans.get()) - trans->gatherPrimitives(out); + trans->gatherPrimitives(pakRouter, out); if (AnimationSet::IMetaTrans* trans = animationSet.defaultTransition.m_trans.get()) - trans->gatherPrimitives(out); - for (auto& anim : out) - { - for (const AnimationSet::AnimationResources& res : animationSet.animResources) - { - if (res.animId == anim.second.animId) - { - anim.second.evntId = res.evntId; - break; - } - } - } + trans->gatherPrimitives(pakRouter, out); } void enumeratePrimitives(const std::function& func) diff --git a/DataSpec/DNAMP1/ANIM.cpp b/DataSpec/DNAMP1/ANIM.cpp index 61d69d622..bd840ad56 100644 --- a/DataSpec/DNAMP1/ANIM.cpp +++ b/DataSpec/DNAMP1/ANIM.cpp @@ -94,6 +94,28 @@ void ANIM::IANIM::sendANIMToBlender(hecl::blender::PyOutStream& os, const DNAANI } } +UniqueID32 ANIM::GetEVNTId(athena::io::IStreamReader& reader) +{ + atUint32 version = reader.readUint32Big(); + switch (version) + { + case 0: + { + ANIM0 anim0; + anim0.read(reader); + return anim0.evnt; + } + case 2: + case 3: + reader.seek(4); + return reader.readUint32Big(); + default: + Log.report(logvisor::Error, "unrecognized ANIM version"); + break; + } + return {}; +} + template <> void ANIM::Enumerate(typename Read::StreamT& reader) { diff --git a/DataSpec/DNAMP1/ANIM.hpp b/DataSpec/DNAMP1/ANIM.hpp index 2e454c2d0..43e741421 100644 --- a/DataSpec/DNAMP1/ANIM.hpp +++ b/DataSpec/DNAMP1/ANIM.hpp @@ -13,6 +13,8 @@ struct ANIM : BigDNA { AT_DECL_EXPLICIT_DNA + static UniqueID32 GetEVNTId(athena::io::IStreamReader& r); + struct IANIM : BigDNAV { Delete expl; diff --git a/DataSpec/DNAMP1/DNAMP1.cpp b/DataSpec/DNAMP1/DNAMP1.cpp index c8e0ad406..41399066d 100644 --- a/DataSpec/DNAMP1/DNAMP1.cpp +++ b/DataSpec/DNAMP1/DNAMP1.cpp @@ -249,7 +249,7 @@ void PAKBridge::addCMDLRigPairs(PAKRouter& pakRouter, } } std::map> animInfo; - ancs.getAnimationResInfo(animInfo); + ancs.getAnimationResInfo(&pakRouter, animInfo); for (auto& ae : animInfo) { PAK::Entry* animEnt = (PAK::Entry*)m_pak.lookupEntry(ae.second.animId); diff --git a/DataSpec/DNAMP2/ANCS.hpp b/DataSpec/DNAMP2/ANCS.hpp index 6103562e6..ebaa4ad46 100644 --- a/DataSpec/DNAMP2/ANCS.hpp +++ b/DataSpec/DNAMP2/ANCS.hpp @@ -204,16 +204,17 @@ struct ANCS : BigDNA } } - void getAnimationResInfo(std::map>& out) const + void getAnimationResInfo(PAKRouter* pakRouter, + std::map>& out) const { out.clear(); for (const DNAMP1::ANCS::AnimationSet::Animation& ai : animationSet.animations) - ai.metaAnim.m_anim->gatherPrimitives(out); + ai.metaAnim.m_anim->gatherPrimitives(nullptr, out); for (const DNAMP1::ANCS::AnimationSet::Transition& ti : animationSet.transitions) if (ti.metaTrans.m_trans) - ti.metaTrans.m_trans->gatherPrimitives(out); + ti.metaTrans.m_trans->gatherPrimitives(nullptr, out); if (animationSet.defaultTransition.m_trans) - animationSet.defaultTransition.m_trans->gatherPrimitives(out); + animationSet.defaultTransition.m_trans->gatherPrimitives(nullptr, out); } static bool Extract(const SpecBase& dataSpec, diff --git a/DataSpec/DNAMP3/CHAR.hpp b/DataSpec/DNAMP3/CHAR.hpp index 8a01f8fa8..dfd042148 100644 --- a/DataSpec/DNAMP3/CHAR.hpp +++ b/DataSpec/DNAMP3/CHAR.hpp @@ -298,7 +298,8 @@ struct CHAR : BigDNA chOut.overlays.emplace_back(overlay.type, std::make_pair(overlay.cmdl, overlay.cskr)); } - void getAnimationResInfo(std::map>& out) const + void getAnimationResInfo(PAKRouter* pakRouter, + std::map>& out) const { out.clear(); for (const AnimationInfo::Animation& ai : animationInfo.animations)