diff --git a/DataSpec/DNACommon/ANIM.cpp b/DataSpec/DNACommon/ANIM.cpp index 099e204af..ea81fa3f7 100644 --- a/DataSpec/DNACommon/ANIM.cpp +++ b/DataSpec/DNACommon/ANIM.cpp @@ -479,7 +479,7 @@ BitstreamWriter::write(const std::vector>& chanKeys, vit = lastVals.begin(); for (const Channel& chan : channels) { - const Value& val = (*kit)[f]; + const Value& val = (*kit++)[f]; QuantizedValue& last = *vit++; switch (chan.type) { @@ -517,7 +517,6 @@ BitstreamWriter::write(const std::vector>& chanKeys, } default: break; } - ++kit; } } return newData; diff --git a/DataSpec/DNACommon/DNACommon.hpp b/DataSpec/DNACommon/DNACommon.hpp index fc456e993..b001ebdc9 100644 --- a/DataSpec/DNACommon/DNACommon.hpp +++ b/DataSpec/DNACommon/DNACommon.hpp @@ -416,7 +416,7 @@ public: void write(athena::io::IStreamWriter& writer) const { for (atUint32 word : m_words) - writer.writeUint32(word); + writer.writeUint32Big(word); } size_t binarySize(size_t __isz) const { diff --git a/DataSpec/DNAMP1/ANIM.cpp b/DataSpec/DNAMP1/ANIM.cpp index dd9ba945d..67f8b3d5d 100644 --- a/DataSpec/DNAMP1/ANIM.cpp +++ b/DataSpec/DNAMP1/ANIM.cpp @@ -404,8 +404,30 @@ void ANIM::ANIM2::write(athena::io::IStreamWriter& writer) const m_version == 3 ? 0x7fffff : 0x7fff, head.rotDiv, head.translationMult, scaleMult, bsSize); - /* TODO: Figure out proper scratch size computation */ - head.scratchSize = keyframeCount * channels.size() * 16; + /* Tally up buffer size */ + head.scratchSize = head.binarySize(0) + keyBmp.binarySize(0) + bsSize; + if (m_version == 3) + { + for (const std::pair& bone : bones) + { + ChannelDescPC desc; + desc.keyCount1 = keyframeCount; + if (bone.second) + desc.keyCount2 = keyframeCount; + head.scratchSize = desc.binarySize(head.scratchSize); + } + } + else + { + for (const std::pair& bone : bones) + { + ChannelDesc desc; + desc.keyCount1 = keyframeCount; + if (bone.second) + desc.keyCount2 = keyframeCount; + head.scratchSize = desc.binarySize(head.scratchSize); + } + } head.write(writer); keyBmp.write(writer); diff --git a/DataSpec/DNAMP2/ANIM.cpp b/DataSpec/DNAMP2/ANIM.cpp index 6abacdb4d..12fd86ed1 100644 --- a/DataSpec/DNAMP2/ANIM.cpp +++ b/DataSpec/DNAMP2/ANIM.cpp @@ -473,6 +473,7 @@ void ANIM::ANIM2::read(athena::io::IStreamReader& reader) void ANIM::ANIM2::write(athena::io::IStreamWriter& writer) const { + /* TODO: conform to MP1 ANIM3 */ Header head; head.unk1 = 1; head.looping = 1;