2016-08-26 22:23:59 +00:00
|
|
|
#include "CFBStreamedCompression.hpp"
|
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2016-08-27 01:02:12 +00:00
|
|
|
CFBStreamedCompression::CFBStreamedCompression(CInputStream& in, IObjectStore& objStore, bool pc)
|
|
|
|
: m_pc(pc)
|
2016-08-26 22:23:59 +00:00
|
|
|
{
|
|
|
|
x0_scratchSize = in.readUint32Big();
|
|
|
|
x4_evnt = in.readUint32Big();
|
|
|
|
|
|
|
|
xc_rotsAndOffs = GetRotationsAndOffsets(x0_scratchSize / 4 + 1, in);
|
|
|
|
|
|
|
|
if (x4_evnt)
|
|
|
|
x8_evntToken = objStore.GetObj(SObjectTag{FOURCC('EVNT'), x4_evnt});
|
|
|
|
}
|
|
|
|
|
2016-08-28 19:57:55 +00:00
|
|
|
const u32* CFBStreamedCompression::GetTimes() const
|
|
|
|
{
|
|
|
|
return reinterpret_cast<const u32*>(xc_rotsAndOffs.get() + 9);
|
|
|
|
}
|
|
|
|
|
2016-08-28 04:45:45 +00:00
|
|
|
const u8* CFBStreamedCompression::GetPerChannelHeaders() const
|
|
|
|
{
|
|
|
|
const u32* bitmap = reinterpret_cast<const u32*>(xc_rotsAndOffs.get() + 9);
|
|
|
|
u32 bitmapWordCount = (bitmap[0] + 31) / 32;
|
|
|
|
return reinterpret_cast<const u8*>(bitmap + bitmapWordCount + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const u8* CFBStreamedCompression::GetBitstreamPointer() const
|
|
|
|
{
|
|
|
|
const u32* bitmap = reinterpret_cast<const u32*>(xc_rotsAndOffs.get() + 9);
|
|
|
|
u32 bitmapWordCount = (bitmap[0] + 31) / 32;
|
|
|
|
|
|
|
|
const u8* chans = reinterpret_cast<const u8*>(bitmap + bitmapWordCount + 1);
|
|
|
|
u32 boneChanCount = *reinterpret_cast<const u32*>(chans);
|
|
|
|
chans += 4;
|
|
|
|
|
|
|
|
if (m_pc)
|
|
|
|
{
|
|
|
|
for (int b=0 ; b<boneChanCount ; ++b)
|
|
|
|
{
|
|
|
|
chans += 20;
|
|
|
|
|
|
|
|
u32 tCount = *reinterpret_cast<const u32*>(chans);
|
|
|
|
chans += 4;
|
|
|
|
if (tCount)
|
|
|
|
chans += 12;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int b=0 ; b<boneChanCount ; ++b)
|
|
|
|
{
|
|
|
|
chans += 15;
|
|
|
|
|
|
|
|
u16 tCount = *reinterpret_cast<const u16*>(chans);
|
|
|
|
chans += 2;
|
|
|
|
if (tCount)
|
|
|
|
chans += 9;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return chans;
|
|
|
|
}
|
|
|
|
|
2016-08-26 22:23:59 +00:00
|
|
|
std::unique_ptr<u32[]> CFBStreamedCompression::GetRotationsAndOffsets(u32 words, CInputStream& in)
|
|
|
|
{
|
|
|
|
std::unique_ptr<u32[]> ret(new u32[words]);
|
|
|
|
|
|
|
|
Header head;
|
|
|
|
head.read(in);
|
|
|
|
*reinterpret_cast<Header*>(ret.get()) = head;
|
|
|
|
|
|
|
|
u32* bitmapOut = &ret[9];
|
|
|
|
u32 bitmapBitCount = in.readUint32Big();
|
|
|
|
bitmapOut[0] = bitmapBitCount;
|
|
|
|
u32 bitmapWordCount = (bitmapBitCount + 31) / 32;
|
|
|
|
for (u32 i=0 ; i<bitmapWordCount ; ++i)
|
|
|
|
bitmapOut[i+1] = in.readUint32Big();
|
|
|
|
|
|
|
|
in.readUint32Big();
|
|
|
|
u8* chans = reinterpret_cast<u8*>(bitmapOut + bitmapWordCount + 1);
|
|
|
|
u8* bs = ReadBoneChannelDescriptors(chans, in);
|
|
|
|
u32 bsWords = ComputeBitstreamWords(chans);
|
|
|
|
|
|
|
|
u32* bsPtr = reinterpret_cast<u32*>(bs);
|
|
|
|
for (u32 w=0 ; w<bsWords ; ++w)
|
|
|
|
bsPtr[w] = in.readUint32Big();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8* CFBStreamedCompression::ReadBoneChannelDescriptors(u8* out, CInputStream& in)
|
|
|
|
{
|
|
|
|
u32 boneChanCount = in.readUint32Big();
|
|
|
|
*reinterpret_cast<u32*>(out) = boneChanCount;
|
|
|
|
out += 4;
|
|
|
|
|
2016-08-27 01:02:12 +00:00
|
|
|
if (m_pc)
|
2016-08-26 22:23:59 +00:00
|
|
|
{
|
2016-08-27 01:02:12 +00:00
|
|
|
for (int b=0 ; b<boneChanCount ; ++b)
|
|
|
|
{
|
|
|
|
*reinterpret_cast<u32*>(out) = in.readUint32Big();
|
|
|
|
out += 4;
|
2016-08-26 22:23:59 +00:00
|
|
|
|
2016-08-27 01:02:12 +00:00
|
|
|
*reinterpret_cast<u32*>(out) = in.readUint32Big();
|
|
|
|
out += 4;
|
2016-08-26 22:23:59 +00:00
|
|
|
|
2016-08-27 01:02:12 +00:00
|
|
|
for (int i=0 ; i<3 ; ++i)
|
|
|
|
{
|
|
|
|
*reinterpret_cast<u32*>(out) = in.readUint32Big();
|
|
|
|
out += 4;
|
|
|
|
}
|
2016-08-26 22:23:59 +00:00
|
|
|
|
2016-08-27 01:02:12 +00:00
|
|
|
u32 tCount = in.readUint32Big();
|
|
|
|
*reinterpret_cast<u32*>(out) = tCount;
|
|
|
|
out += 4;
|
2016-08-26 22:23:59 +00:00
|
|
|
|
2016-08-27 01:02:12 +00:00
|
|
|
if (tCount)
|
|
|
|
{
|
|
|
|
for (int i=0 ; i<3 ; ++i)
|
|
|
|
{
|
|
|
|
*reinterpret_cast<u32*>(out) = in.readUint32Big();
|
|
|
|
out += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int b=0 ; b<boneChanCount ; ++b)
|
2016-08-26 22:23:59 +00:00
|
|
|
{
|
2016-08-27 01:02:12 +00:00
|
|
|
*reinterpret_cast<u32*>(out) = in.readUint32Big();
|
|
|
|
out += 4;
|
|
|
|
|
|
|
|
*reinterpret_cast<u16*>(out) = in.readUint16Big();
|
|
|
|
out += 2;
|
|
|
|
|
2016-08-26 22:23:59 +00:00
|
|
|
for (int i=0 ; i<3 ; ++i)
|
|
|
|
{
|
|
|
|
*reinterpret_cast<s16*>(out) = in.readInt16Big();
|
|
|
|
out += 2;
|
|
|
|
*reinterpret_cast<u8*>(out) = in.readUByte();
|
|
|
|
out += 1;
|
|
|
|
}
|
2016-08-27 01:02:12 +00:00
|
|
|
|
|
|
|
u16 tCount = in.readUint16Big();
|
|
|
|
*reinterpret_cast<u16*>(out) = tCount;
|
|
|
|
out += 2;
|
|
|
|
|
|
|
|
if (tCount)
|
|
|
|
{
|
|
|
|
for (int i=0 ; i<3 ; ++i)
|
|
|
|
{
|
|
|
|
*reinterpret_cast<s16*>(out) = in.readInt16Big();
|
|
|
|
out += 2;
|
|
|
|
*reinterpret_cast<u8*>(out) = in.readUByte();
|
|
|
|
out += 1;
|
|
|
|
}
|
|
|
|
}
|
2016-08-26 22:23:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 CFBStreamedCompression::ComputeBitstreamWords(const u8* chans)
|
|
|
|
{
|
|
|
|
u32 boneChanCount = *reinterpret_cast<const u32*>(chans);
|
|
|
|
chans += 4;
|
|
|
|
|
2016-08-27 01:02:12 +00:00
|
|
|
u32 keyCount;
|
2016-08-26 22:23:59 +00:00
|
|
|
|
|
|
|
u32 totalBits = 0;
|
2016-08-27 01:02:12 +00:00
|
|
|
if (m_pc)
|
|
|
|
{
|
|
|
|
keyCount = *reinterpret_cast<const u32*>(chans + 0x4);
|
|
|
|
for (u32 c=0 ; c<boneChanCount ; ++c)
|
|
|
|
{
|
|
|
|
chans += 0x8;
|
|
|
|
totalBits += *reinterpret_cast<const u32*>(chans) & 0xff;
|
|
|
|
totalBits += *reinterpret_cast<const u32*>(chans + 0x4) & 0xff;
|
|
|
|
totalBits += *reinterpret_cast<const u32*>(chans + 0x8) & 0xff;
|
|
|
|
u32 tKeyCount = *reinterpret_cast<const u32*>(chans + 0xc);
|
|
|
|
chans += 0x10;
|
|
|
|
if (tKeyCount)
|
|
|
|
{
|
|
|
|
totalBits += *reinterpret_cast<const u32*>(chans) & 0xff;
|
|
|
|
totalBits += *reinterpret_cast<const u32*>(chans + 0x4) & 0xff;
|
|
|
|
totalBits += *reinterpret_cast<const u32*>(chans + 0x8) & 0xff;
|
|
|
|
chans += 0xc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-08-26 22:23:59 +00:00
|
|
|
{
|
2016-08-27 01:02:12 +00:00
|
|
|
keyCount = *reinterpret_cast<const u16*>(chans + 0x4);
|
|
|
|
for (u32 c=0 ; c<boneChanCount ; ++c)
|
2016-08-26 22:23:59 +00:00
|
|
|
{
|
2016-08-27 01:02:12 +00:00
|
|
|
chans += 0x6;
|
2016-08-26 22:23:59 +00:00
|
|
|
totalBits += *reinterpret_cast<const u8*>(chans + 0x2);
|
|
|
|
totalBits += *reinterpret_cast<const u8*>(chans + 0x5);
|
|
|
|
totalBits += *reinterpret_cast<const u8*>(chans + 0x8);
|
2016-08-27 01:02:12 +00:00
|
|
|
u16 tKeyCount = *reinterpret_cast<const u16*>(chans + 0x9);
|
|
|
|
chans += 0xb;
|
|
|
|
if (tKeyCount)
|
|
|
|
{
|
|
|
|
totalBits += *reinterpret_cast<const u8*>(chans + 0x2);
|
|
|
|
totalBits += *reinterpret_cast<const u8*>(chans + 0x5);
|
|
|
|
totalBits += *reinterpret_cast<const u8*>(chans + 0x8);
|
|
|
|
chans += 0x9;
|
|
|
|
}
|
2016-08-26 22:23:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (totalBits * keyCount + 31) / 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|