From 9529fad78f03d2abcf6345aa8568d4e52e160283 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 17 Oct 2015 18:08:45 -1000 Subject: [PATCH] Added binarySize method to DNA implementations --- DataSpec/DNACommon/DNACommon.hpp | 12 +++ DataSpec/DNAMP1/ANCS.cpp | 163 ++++++++++++++++++++++++++++++ DataSpec/DNAMP1/ANIM.cpp | 48 +++++++++ DataSpec/DNAMP1/ANIM.hpp | 12 +++ DataSpec/DNAMP1/CMDLMaterials.cpp | 12 +-- DataSpec/DNAMP1/CMDLMaterials.hpp | 12 +-- DataSpec/DNAMP1/PAK.cpp | 17 +++- DataSpec/DNAMP1/SCLY.cpp | 18 ++++ DataSpec/DNAMP1/SCLY.hpp | 2 + DataSpec/DNAMP1/STRG.cpp | 22 ++++ DataSpec/DNAMP2/ANCS.cpp | 138 +++++++++++++++++++++++++ DataSpec/DNAMP2/ANIM.cpp | 55 ++++++++++ DataSpec/DNAMP2/ANIM.hpp | 16 +++ DataSpec/DNAMP2/STRG.cpp | 29 ++++++ DataSpec/DNAMP3/ANIM.cpp | 31 ++++++ DataSpec/DNAMP3/ANIM.hpp | 5 + DataSpec/DNAMP3/CHAR.cpp | 20 ++++ DataSpec/DNAMP3/CMDLMaterials.hpp | 11 ++ DataSpec/DNAMP3/PAK.cpp | 26 +++++ DataSpec/DNAMP3/STRG.cpp | 32 ++++++ hecl | 2 +- 21 files changed, 668 insertions(+), 15 deletions(-) diff --git a/DataSpec/DNACommon/DNACommon.hpp b/DataSpec/DNACommon/DNACommon.hpp index 554907359..ab37c27bd 100644 --- a/DataSpec/DNACommon/DNACommon.hpp +++ b/DataSpec/DNACommon/DNACommon.hpp @@ -38,6 +38,8 @@ public: {std::string rs = reader.readString(nullptr); strncpy(fcc, rs.c_str(), 4);} void toYAML(Athena::io::YAMLDocWriter& writer) const {writer.writeString(nullptr, std::string(fcc, 4));} + size_t binarySize(size_t __isz) const + {return __isz + 4;} }; using FourCC = HECL::FourCC; @@ -57,6 +59,8 @@ public: {m_id = reader.readUint32(nullptr);} void toYAML(Athena::io::YAMLDocWriter& writer) const {writer.writeUint32(nullptr, m_id);} + size_t binarySize(size_t __isz) const + {return __isz + 4;} bool operator!=(const UniqueID32& other) const {return m_id != other.m_id;} bool operator==(const UniqueID32& other) const {return m_id == other.m_id;} @@ -84,6 +88,8 @@ public: {m_id = reader.readUint64(nullptr);} void toYAML(Athena::io::YAMLDocWriter& writer) const {writer.writeUint64(nullptr, m_id);} + size_t binarySize(size_t __isz) const + {return __isz + 8;} bool operator!=(const UniqueID64& other) const {return m_id != other.m_id;} bool operator==(const UniqueID64& other) const {return m_id == other.m_id;} @@ -135,6 +141,8 @@ public: { writer.writeString(nullptr, toString().c_str()); } + size_t binarySize(size_t __isz) const + {return __isz + 16;} bool operator!=(const UniqueID128& other) const { @@ -210,6 +218,10 @@ public: for (atUint32 word : m_words) writer.writeUint32(word); } + size_t binarySize(size_t __isz) const + { + return __isz + m_words.size() * 4; + } size_t getBitCount() const {return m_bitCount;} bool getBit(size_t idx) const { diff --git a/DataSpec/DNAMP1/ANCS.cpp b/DataSpec/DNAMP1/ANCS.cpp index 5e9fd49f5..b1bbdde2f 100644 --- a/DataSpec/DNAMP1/ANCS.cpp +++ b/DataSpec/DNAMP1/ANCS.cpp @@ -59,6 +59,24 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::ParmInfo::write( } } +size_t ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::ParmInfo::binarySize(size_t __isz) const +{ + __isz += 12; + switch (DataType(parmType)) + { + case DataType::DTInt32: + case DataType::DTUInt32: + case DataType::DTEnum: + case DataType::DTFloat: + __isz += 8; + break; + case DataType::DTBool: + __isz += 2; + break; + } + return __isz; +} + void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::ParmInfo::fromYAML(Athena::io::YAMLDocReader& reader) { parmType = reader.readUint32("parmType"); @@ -200,6 +218,32 @@ void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::write(Athena::io } } +size_t ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::binarySize(size_t __isz) const +{ + __isz += 12; + __isz = __EnumerateSize(__isz, parmInfos); + + __isz += animInfos.size() * 4; + for (const ParmInfo& pi : parmInfos) + { + switch (ParmInfo::DataType(pi.parmType)) + { + case ParmInfo::DTInt32: + case ParmInfo::DTUInt32: + case ParmInfo::DTEnum: + case ParmInfo::DTFloat: + __isz += animInfos.size() * 4; + break; + case ParmInfo::DTBool: + __isz += animInfos.size(); + break; + default: break; + } + } + + return __isz; +} + void ANCS::CharacterSet::CharacterInfo::PASDatabase::AnimState::fromYAML(Athena::io::YAMLDocReader& reader) { id = reader.readUint32("id"); @@ -416,6 +460,70 @@ void ANCS::CharacterSet::CharacterInfo::write(Athena::io::IStreamWriter& writer) } } +size_t ANCS::CharacterSet::CharacterInfo::binarySize(size_t __isz) const +{ + __isz += 6; + + atUint16 sectionCount; + if (partResData.elsc.size()) + sectionCount = 6; + else if (animIdxs.size()) + sectionCount = 5; + else if (cmdlOverlay) + sectionCount = 4; + else if (effects.size()) + sectionCount = 3; + else if (animAABBs.size()) + sectionCount = 2; + else + sectionCount = 1; + + __isz += name.size() + 1; + __isz += 12; + + __isz += 4; + __isz = __EnumerateSize(__isz, animations); + + __isz = pasDatabase.binarySize(__isz); + + __isz += 4; + __isz = __EnumerateSize(__isz, partResData.part); + + __isz += 4; + __isz = __EnumerateSize(__isz, partResData.swhc); + + __isz += 4; + __isz = __EnumerateSize(__isz, partResData.unk); + + if (sectionCount > 5) + { + __isz += 4; + __isz = __EnumerateSize(__isz, partResData.elsc); + } + + __isz += 4; + + if (sectionCount > 1) + { + __isz += 4; + __isz = __EnumerateSize(__isz, animAABBs); + } + + if (sectionCount > 2) + { + __isz += 4; + __isz = __EnumerateSize(__isz, effects); + } + + if (sectionCount > 3) + __isz += 8; + + if (sectionCount > 4) + __isz += 4 + animIdxs.size() * 4; + + return __isz; +} + void ANCS::CharacterSet::CharacterInfo::fromYAML(Athena::io::YAMLDocReader& reader) { idx = reader.readUint32("idx"); @@ -591,6 +699,13 @@ void ANCS::AnimationSet::MetaAnimFactory::write(Athena::io::IStreamWriter& write m_anim->write(writer); } +size_t ANCS::AnimationSet::MetaAnimFactory::binarySize(size_t __isz) const +{ + if (!m_anim) + return __isz; + return m_anim->binarySize(__isz + 4); +} + void ANCS::AnimationSet::MetaAnimFactory::fromYAML(Athena::io::YAMLDocReader& reader) { std::string type = reader.readString("type"); @@ -675,6 +790,13 @@ void ANCS::AnimationSet::MetaTransFactory::write(Athena::io::IStreamWriter& writ m_trans->write(writer); } +size_t ANCS::AnimationSet::MetaTransFactory::binarySize(size_t __isz) const +{ + if (!m_trans) + return __isz + 4; + return m_trans->binarySize(__isz + 4); +} + void ANCS::AnimationSet::MetaTransFactory::fromYAML(Athena::io::YAMLDocReader& reader) { std::string type = reader.readString("type"); @@ -794,6 +916,47 @@ void ANCS::AnimationSet::write(Athena::io::IStreamWriter& writer) const } } +size_t ANCS::AnimationSet::binarySize(size_t __isz) const +{ + atUint16 sectionCount; + if (animResources.size()) + sectionCount = 4; + else if (halfTransitions.size()) + sectionCount = 3; + else if (additiveAnims.size()) + sectionCount = 2; + else + sectionCount = 1; + + __isz += 6; + __isz = __EnumerateSize(__isz, animations); + + __isz += 4; + __isz = __EnumerateSize(__isz, transitions); + __isz = defaultTransition.binarySize(__isz); + + if (sectionCount > 1) + { + __isz += 4; + __isz = __EnumerateSize(__isz, additiveAnims); + __isz += 8; + } + + if (sectionCount > 2) + { + __isz += 4; + __isz = __EnumerateSize(__isz, halfTransitions); + } + + if (sectionCount > 3) + { + __isz += 4; + __isz = __EnumerateSize(__isz, animResources); + } + + return __isz; +} + void ANCS::AnimationSet::fromYAML(Athena::io::YAMLDocReader& reader) { atUint16 sectionCount = reader.readUint16("sectionCount"); diff --git a/DataSpec/DNAMP1/ANIM.cpp b/DataSpec/DNAMP1/ANIM.cpp index b38d0cf58..63210566a 100644 --- a/DataSpec/DNAMP1/ANIM.cpp +++ b/DataSpec/DNAMP1/ANIM.cpp @@ -216,6 +216,29 @@ void ANIM::ANIM0::write(Athena::io::IStreamWriter& writer) const evnt.write(writer); } +size_t ANIM::ANIM0::binarySize(size_t __isz) const +{ + Header head; + + atUint32 maxId = 0; + for (const std::pair& bone : bones) + maxId = std::max(maxId, bone.first); + + __isz = head.binarySize(__isz); + __isz += maxId + 1; + __isz += bones.size() + 4; + + __isz += 8; + for (const std::pair& bone : bones) + { + __isz += head.keyCount * 16; + if (bone.second) + __isz += head.keyCount * 12; + } + + return __isz + 4; +} + void ANIM::ANIM2::read(Athena::io::IStreamReader& reader) { Header head; @@ -347,5 +370,30 @@ void ANIM::ANIM2::write(Athena::io::IStreamWriter& writer) const writer.writeUBytes(bsData.get(), bsSize); } +size_t ANIM::ANIM2::binarySize(size_t __isz) const +{ + Header head; + + WordBitmap keyBmp; + for (atUint32 frame : frames) + { + while (keyBmp.getBit(frame)) + ++frame; + keyBmp.setBit(frame); + } + + __isz = head.binarySize(__isz); + __isz = keyBmp.binarySize(__isz); + __isz += 8; + for (const std::pair& bone : bones) + { + __isz += 17; + if (bone.second) + __isz += 9; + } + + return __isz + DNAANIM::ComputeBitstreamSize(frames.size(), channels); +} + } } diff --git a/DataSpec/DNAMP1/ANIM.hpp b/DataSpec/DNAMP1/ANIM.hpp index 100758426..248f7aa89 100644 --- a/DataSpec/DNAMP1/ANIM.hpp +++ b/DataSpec/DNAMP1/ANIM.hpp @@ -132,6 +132,13 @@ struct ANIM : BigDNA writer.writeUByte(qTZ); } } + size_t binarySize(size_t __isz) const + { + __isz += 17; + if (keyCount2) + __isz += 9; + return __isz; + } }; }; @@ -161,6 +168,11 @@ struct ANIM : BigDNA m_anim->write(writer); } + size_t binarySize(size_t __isz) const + { + return m_anim->binarySize(__isz + 4); + } + void sendANIMToBlender(HECL::BlenderConnection::PyOutStream& os, const CINF& cinf, bool) const { m_anim->sendANIMToBlender(os, cinf); diff --git a/DataSpec/DNAMP1/CMDLMaterials.cpp b/DataSpec/DNAMP1/CMDLMaterials.cpp index 0f82c06f8..2a7e49fdd 100644 --- a/DataSpec/DNAMP1/CMDLMaterials.cpp +++ b/DataSpec/DNAMP1/CMDLMaterials.cpp @@ -1083,7 +1083,7 @@ MaterialSet::Material::Material(const HECL::Backend::GX& gx, found = true; ++uvAnimsCount; uvAnims.emplace_back(tcg); - uvAnimsSize += uvAnims.back().binarySize(); + uvAnimsSize = uvAnims.back().binarySize(uvAnimsSize); break; } } @@ -1101,12 +1101,12 @@ MaterialSet::Material::UVAnimation::UVAnimation(const HECL::Backend::GX::TexCoor else if (!tcg.m_gameFunction.compare("RetroUVMode2Node")) { mode = ANIM_SCROLL; - if (tcg.m_gameArgs.size() < 4) - Log.report(LogVisor::FatalError, "Mode2 UV anim requires 4 arguments"); + if (tcg.m_gameArgs.size() < 2) + Log.report(LogVisor::FatalError, "Mode2 UV anim requires 2 vector arguments"); vals[0] = tcg.m_gameArgs[0].vec[0]; - vals[1] = tcg.m_gameArgs[1].vec[0]; - vals[2] = tcg.m_gameArgs[2].vec[0]; - vals[3] = tcg.m_gameArgs[3].vec[0]; + vals[1] = tcg.m_gameArgs[0].vec[1]; + vals[2] = tcg.m_gameArgs[1].vec[0]; + vals[3] = tcg.m_gameArgs[1].vec[1]; } else if (!tcg.m_gameFunction.compare("RetroUVMode3Node")) { diff --git a/DataSpec/DNAMP1/CMDLMaterials.hpp b/DataSpec/DNAMP1/CMDLMaterials.hpp index f0c65767a..05f8c3061 100644 --- a/DataSpec/DNAMP1/CMDLMaterials.hpp +++ b/DataSpec/DNAMP1/CMDLMaterials.hpp @@ -320,26 +320,26 @@ struct MaterialSet : BigDNA break; } } - atUint32 binarySize() const + size_t binarySize(size_t __isz) const { switch (mode) { case ANIM_MV_INV_NOTRANS: case ANIM_MV_INV: case ANIM_MODEL: - return 4; + return __isz + 4; case ANIM_SCROLL: case ANIM_HSTRIP: case ANIM_VSTRIP: - return 20; + return __isz + 20; break; case ANIM_ROTATION: case ANIM_MODE_WHO_MUST_NOT_BE_NAMED: - return 12; + return __isz + 12; case ANIM_MODE_8: - return 40; + return __isz + 40; } - return 4; + return __isz + 4; } UVAnimation() = default; diff --git a/DataSpec/DNAMP1/PAK.cpp b/DataSpec/DNAMP1/PAK.cpp index e3c99d103..c12605445 100644 --- a/DataSpec/DNAMP1/PAK.cpp +++ b/DataSpec/DNAMP1/PAK.cpp @@ -58,8 +58,9 @@ void PAK::write(Athena::io::IStreamWriter& writer) const writer.writeUint32Big((atUint32)m_nameEntries.size()); for (const NameEntry& entry : m_nameEntries) { - ((NameEntry&)entry).nameLen = entry.name.size(); - entry.write(writer); + NameEntry copy = entry; + copy.nameLen = copy.name.size(); + copy.write(writer); } writer.writeUint32Big(m_entries.size()); @@ -72,6 +73,18 @@ void PAK::write(Athena::io::IStreamWriter& writer) const } } +size_t PAK::binarySize(size_t __isz) const +{ + __isz += 12; + + for (const NameEntry& entry : m_nameEntries) + __isz += 12 + entry.name.size(); + + __isz += m_entries.size() * 20 + 4; + + return __isz; +} + std::unique_ptr PAK::Entry::getBuffer(const NOD::Node& pak, atUint64& szOut) const { diff --git a/DataSpec/DNAMP1/SCLY.cpp b/DataSpec/DNAMP1/SCLY.cpp index 09c3dcb2f..4ea658cd6 100644 --- a/DataSpec/DNAMP1/SCLY.cpp +++ b/DataSpec/DNAMP1/SCLY.cpp @@ -29,6 +29,13 @@ void SCLY::write(Athena::io::IStreamWriter& ws) const ws.enumerate(layers); } +size_t SCLY::binarySize(size_t __isz) const +{ + __isz += 12; + __isz += layerSizes.size() * 4; + return __EnumerateSize(__isz, layers); +} + void SCLY::exportToLayerDirectories(const PAK::Entry& entry, PAKRouter &pakRouter, bool force) { for (atUint32 i = 0; i < layerCount; i++) @@ -139,6 +146,17 @@ void SCLY::ScriptLayer::write(Athena::io::IStreamWriter& ws) const } } +size_t SCLY::ScriptLayer::binarySize(size_t __isz) const +{ + __isz += 5; + for (const std::shared_ptr& obj : objects) + { + __isz += 1; + __isz = obj->binarySize(__isz); + } + return __isz; +} + void SCLY::ScriptLayer::toYAML(Athena::io::YAMLDocWriter& ws) const { ws.writeUByte("unknown", unknown); diff --git a/DataSpec/DNAMP1/SCLY.hpp b/DataSpec/DNAMP1/SCLY.hpp index ac550cda1..929447290 100644 --- a/DataSpec/DNAMP1/SCLY.hpp +++ b/DataSpec/DNAMP1/SCLY.hpp @@ -28,11 +28,13 @@ struct SCLY : BigYAML Vector, DNA_COUNT(objectCount)> objects; void read(Athena::io::IStreamReader &rs); void write(Athena::io::IStreamWriter &ws) const; + size_t binarySize(size_t __isz) const; }; Vector layers; void read(Athena::io::IStreamReader &rs); void write(Athena::io::IStreamWriter &ws) const; + size_t binarySize(size_t __isz) const; void exportToLayerDirectories(const PAK::Entry &, PAKRouter&, bool); }; diff --git a/DataSpec/DNAMP1/STRG.cpp b/DataSpec/DNAMP1/STRG.cpp index 42931c9c7..71a165a80 100644 --- a/DataSpec/DNAMP1/STRG.cpp +++ b/DataSpec/DNAMP1/STRG.cpp @@ -109,6 +109,28 @@ void STRG::write(Athena::io::IStreamWriter& writer) const } } +size_t STRG::binarySize(size_t __isz) const +{ + __isz += 16; + __isz += langs.size() * 12; + + size_t strCount = STRG::count(); + __isz += langs.size() * strCount * 4; + for (const std::pair>& lang : langs) + { + atUint32 langStrCount = lang.second.size(); + for (atUint32 s=0 ; s 1) + { + __isz += 4; + __isz = __EnumerateSize(__isz, animAABBs); + } + + if (sectionCount > 2) + { + __isz += 4; + __isz = __EnumerateSize(__isz, effects); + } + + if (sectionCount > 3) + __isz += 8; + + if (sectionCount > 4) + __isz += 4 + animIdxs.size() * 4; + + if (sectionCount > 9) + { + __isz += 9; + __isz = __EnumerateSize(__isz, extents); + } + + return __isz; +} + void ANCS::CharacterSet::CharacterInfo::fromYAML(Athena::io::YAMLDocReader& reader) { idx = reader.readUint32("idx"); @@ -400,6 +475,47 @@ void ANCS::AnimationSet::write(Athena::io::IStreamWriter& writer) const } } +size_t ANCS::AnimationSet::binarySize(size_t __isz) const +{ + atUint16 sectionCount; + if (evnts.size()) + sectionCount = 4; + else if (halfTransitions.size()) + sectionCount = 3; + else if (additiveAnims.size()) + sectionCount = 2; + else + sectionCount = 1; + + __isz += 6; + __isz = __EnumerateSize(__isz, animations); + + __isz += 4; + __isz = __EnumerateSize(__isz, transitions); + __isz = defaultTransition.binarySize(__isz); + + if (sectionCount > 1) + { + __isz += 4; + __isz = __EnumerateSize(__isz, additiveAnims); + __isz += 8; + } + + if (sectionCount > 2) + { + __isz += 4; + __isz = __EnumerateSize(__isz, halfTransitions); + } + + if (sectionCount > 3) + { + __isz += 4; + __isz = __EnumerateSize(__isz, evnts); + } + + return __isz; +} + void ANCS::AnimationSet::fromYAML(Athena::io::YAMLDocReader& reader) { atUint16 sectionCount = reader.readUint16("sectionCount"); @@ -523,6 +639,28 @@ void ANCS::AnimationSet::EVNT::write(Athena::io::IStreamWriter& writer) const writer.enumerate(sfxEvents); } +size_t ANCS::AnimationSet::EVNT::binarySize(size_t __isz) const +{ + __isz += 4; + + __isz += 4; + __isz = __EnumerateSize(__isz, loopEvents); + + if (version == 2) + { + __isz += 4; + __isz = __EnumerateSize(__isz, uevtEvents); + } + + __isz += 4; + __isz = __EnumerateSize(__isz, effectEvents); + + __isz += 4; + __isz = __EnumerateSize(__isz, sfxEvents); + + return __isz; +} + void ANCS::AnimationSet::EVNT::fromYAML(Athena::io::YAMLDocReader& reader) { version = reader.readUint32("version"); diff --git a/DataSpec/DNAMP2/ANIM.cpp b/DataSpec/DNAMP2/ANIM.cpp index 09b10c57c..4b40e4b32 100644 --- a/DataSpec/DNAMP2/ANIM.cpp +++ b/DataSpec/DNAMP2/ANIM.cpp @@ -346,6 +346,32 @@ void ANIM::ANIM0::write(Athena::io::IStreamWriter& writer) const } } +size_t ANIM::ANIM0::binarySize(size_t __isz) const +{ + Header head; + + atUint32 maxId = 0; + for (const std::pair>& bone : bones) + maxId = std::max(maxId, bone.first); + + __isz = head.binarySize(__isz); + __isz += maxId + 1; + __isz += bones.size() * 3 + 12; + + __isz += 12; + for (const std::pair>& bone : bones) + { + if (std::get<0>(bone.second)) + __isz += head.keyCount * 16; + if (std::get<1>(bone.second)) + __isz += head.keyCount * 12; + if (std::get<2>(bone.second)) + __isz += head.keyCount * 12; + } + + return __isz; +} + void ANIM::ANIM2::read(Athena::io::IStreamReader& reader) { Header head; @@ -503,5 +529,34 @@ void ANIM::ANIM2::write(Athena::io::IStreamWriter& writer) const writer.writeUBytes(bsData.get(), bsSize); } +size_t ANIM::ANIM2::binarySize(size_t __isz) const +{ + Header head; + + WordBitmap keyBmp; + for (atUint32 frame : frames) + { + while (keyBmp.getBit(frame)) + ++frame; + keyBmp.setBit(frame); + } + + __isz = head.binarySize(__isz); + __isz = keyBmp.binarySize(__isz); + __isz += 4; + for (const std::pair>& bone : bones) + { + __isz += 7; + if (std::get<0>(bone.second)) + __isz += 9; + if (std::get<1>(bone.second)) + __isz += 9; + if (std::get<2>(bone.second)) + __isz += 9; + } + + return __isz + DNAANIM::ComputeBitstreamSize(frames.size(), channels); +} + } } diff --git a/DataSpec/DNAMP2/ANIM.hpp b/DataSpec/DNAMP2/ANIM.hpp index 5db0ece82..f55f5bfd0 100644 --- a/DataSpec/DNAMP2/ANIM.hpp +++ b/DataSpec/DNAMP2/ANIM.hpp @@ -165,6 +165,17 @@ struct ANIM : BigDNA writer.writeUByte(qSZ); } } + size_t binarySize(size_t __isz) const + { + __isz += 7; + if (keyCount1) + __isz += 9; + if (keyCount2) + __isz += 9; + if (keyCount3) + __isz += 9; + return __isz; + } }; }; @@ -194,6 +205,11 @@ struct ANIM : BigDNA m_anim->write(writer); } + size_t binarySize(size_t __isz) const + { + return m_anim->binarySize(__isz + 4); + } + void sendANIMToBlender(HECL::BlenderConnection::PyOutStream& os, const CINF& cinf, bool) const { m_anim->sendANIMToBlender(os, cinf); diff --git a/DataSpec/DNAMP2/STRG.cpp b/DataSpec/DNAMP2/STRG.cpp index 20899763a..69214a504 100644 --- a/DataSpec/DNAMP2/STRG.cpp +++ b/DataSpec/DNAMP2/STRG.cpp @@ -137,6 +137,35 @@ void STRG::write(Athena::io::IStreamWriter& writer) const } } +size_t STRG::binarySize(size_t __isz) const +{ + __isz += 16; + + __isz += langs.size() * 12; + + __isz += 8; + __isz += names.size() * 8; + for (const std::pair& name : names) + __isz += name.first.size() + 1; + + size_t strCount = STRG::count(); + for (const std::pair>& lang : langs) + { + atUint32 langStrCount = lang.second.size(); + __isz += strCount * 4; + + for (atUint32 s=0 ; s>& bone : bones) + maxId = std::max(maxId, bone.first); + + __isz = head.binarySize(__isz); + __isz += maxId + 1; + __isz += bones.size() * 3 + 12; + + __isz += 12; + for (const std::pair>& bone : bones) + { + if (std::get<0>(bone.second)) + __isz += head.keyCount * 16; + if (std::get<1>(bone.second)) + __isz += head.keyCount * 12; + if (std::get<2>(bone.second)) + __isz += head.keyCount * 12; + } + + return __isz; +} + static float ComputeFrames(const std::vector& keyTimes, std::vector& framesOut) { if (keyTimes.size() <= 1) @@ -500,5 +526,10 @@ void ANIM::ANIM1::write(Athena::io::IStreamWriter& writer) const { } +size_t ANIM::ANIM1::binarySize(size_t __isz) const +{ + return __isz; +} + } } diff --git a/DataSpec/DNAMP3/ANIM.hpp b/DataSpec/DNAMP3/ANIM.hpp index c9bec742a..8df2fef27 100644 --- a/DataSpec/DNAMP3/ANIM.hpp +++ b/DataSpec/DNAMP3/ANIM.hpp @@ -105,6 +105,11 @@ struct ANIM : BigDNA m_anim->write(writer); } + size_t binarySize(size_t __isz) const + { + return m_anim->binarySize(__isz + 4); + } + void sendANIMToBlender(HECL::BlenderConnection::PyOutStream& os, const CINF& cinf, bool additive) const { m_anim->sendANIMToBlender(os, cinf, additive); diff --git a/DataSpec/DNAMP3/CHAR.cpp b/DataSpec/DNAMP3/CHAR.cpp index 224221735..4ebe5ec4a 100644 --- a/DataSpec/DNAMP3/CHAR.cpp +++ b/DataSpec/DNAMP3/CHAR.cpp @@ -35,6 +35,19 @@ void CHAR::AnimationInfo::EVNT::SFXEvent::write(Athena::io::IStreamWriter& write writer.seek(35, Athena::Current); } +size_t CHAR::AnimationInfo::EVNT::SFXEvent::binarySize(size_t __isz) const +{ + __isz = EventBase::binarySize(__isz); + __isz = caudId.binarySize(__isz); + __isz += 16; + __isz += unk3Vals.size() * 4; + if (extraType == 1) + __isz += 4; + else if (extraType == 2) + __isz += 35; + return __isz; +} + void CHAR::AnimationInfo::EVNT::SFXEvent::fromYAML(Athena::io::YAMLDocReader& reader) { EventBase::fromYAML(reader); @@ -105,6 +118,13 @@ void CHAR::AnimationInfo::MetaAnimFactory::write(Athena::io::IStreamWriter& writ m_anim->write(writer); } +size_t CHAR::AnimationInfo::MetaAnimFactory::binarySize(size_t __isz) const +{ + if (!m_anim) + return __isz; + return m_anim->binarySize(__isz + 4); +} + void CHAR::AnimationInfo::MetaAnimFactory::fromYAML(Athena::io::YAMLDocReader& reader) { std::string type = reader.readString("type"); diff --git a/DataSpec/DNAMP3/CMDLMaterials.hpp b/DataSpec/DNAMP3/CMDLMaterials.hpp index 53325224a..58b3de8df 100644 --- a/DataSpec/DNAMP3/CMDLMaterials.hpp +++ b/DataSpec/DNAMP3/CMDLMaterials.hpp @@ -199,6 +199,10 @@ struct MaterialSet : BigDNA writer.writeUBytes((atUint8*)§ion->m_type, 4); section->write(writer); } + size_t binarySize(size_t __isz) const + { + return section->binarySize(__isz + 4); + } }; std::vector sections; void read(Athena::io::IStreamReader& reader) @@ -218,6 +222,13 @@ struct MaterialSet : BigDNA section.write(writer); writer.writeUBytes((atUint8*)"END ", 4); } + size_t binarySize(size_t __isz) const + { + __isz = header.binarySize(__isz); + for (const SectionFactory& section : sections) + __isz = section.binarySize(__isz); + return __isz + 4; + } }; Vector materials; diff --git a/DataSpec/DNAMP3/PAK.cpp b/DataSpec/DNAMP3/PAK.cpp index 7c554c93a..0f4affa96 100644 --- a/DataSpec/DNAMP3/PAK.cpp +++ b/DataSpec/DNAMP3/PAK.cpp @@ -97,6 +97,32 @@ void PAK::write(Athena::io::IStreamWriter& writer) const } writer.seek(rshdPad, Athena::Current); } +size_t PAK::binarySize(size_t __isz) const +{ + __isz = m_header.binarySize(__isz); + + size_t strgSz = 4; + for (const NameEntry& entry : m_nameEntries) + strgSz += entry.name.size() + 13; + size_t strgPad = ((strgSz + 63) & ~63) - strgSz; + + size_t rshdSz = 4 + 24 * m_entries.size(); + size_t rshdPad = ((rshdSz + 63) & ~63) - rshdSz; + + __isz += 60; + + __isz += 4; + for (const NameEntry& entry : m_nameEntries) + __isz = entry.binarySize(__isz); + __isz += strgPad; + + __isz += 4; + for (const Entry& entry : m_entries) + __isz = entry.binarySize(__isz); + __isz += rshdPad; + + return __isz; +} std::unique_ptr PAK::Entry::getBuffer(const NOD::Node& pak, atUint64& szOut) const { diff --git a/DataSpec/DNAMP3/STRG.cpp b/DataSpec/DNAMP3/STRG.cpp index 61b6c69eb..61fbcb016 100644 --- a/DataSpec/DNAMP3/STRG.cpp +++ b/DataSpec/DNAMP3/STRG.cpp @@ -211,6 +211,38 @@ void STRG::write(Athena::io::IStreamWriter& writer) const } } +size_t STRG::binarySize(size_t __isz) const +{ + __isz += 24; + __isz += names.size() * 8; + for (const auto& name : names) + __isz += name.first.size() + 1; + + __isz += langs.size() * 4; + + for (const auto& lang : langs) + __isz += 4 + lang.second.size() * 4; + + size_t strCount = STRG::count(); + for (atUint32 s=0 ; s= lang.second.size()) + { + __isz += 5; + } + else + { + const std::string& str = lang.second[s]; + __isz += str.size() + 5; + } + } + } + + return __isz; +} + void STRG::toYAML(Athena::io::YAMLDocWriter& writer) const { for (const auto& item : langs) diff --git a/hecl b/hecl index 8604f4050..641d5b17d 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit 8604f405026cd53774b7dac524badd2a5e0884b5 +Subproject commit 641d5b17db1e244c565a0c431cb62fb7650db89b