diff options
Diffstat (limited to 'lyt')
-rw-r--r-- | lyt/animation.cpp | 220 | ||||
-rw-r--r-- | lyt/animation.h | 68 | ||||
-rw-r--r-- | lyt/materials/tevswaptable.cpp | 8 | ||||
-rw-r--r-- | lyt/textbox.cpp | 13 | ||||
-rw-r--r-- | lyt/textbox.h | 4 |
5 files changed, 302 insertions, 11 deletions
diff --git a/lyt/animation.cpp b/lyt/animation.cpp new file mode 100644 index 0000000..d5e87d3 --- /dev/null +++ b/lyt/animation.cpp @@ -0,0 +1,220 @@ +#include "animation.h" +#include "lyt/binaryfile.h" + +LYTAnimation::~LYTAnimation() { + +} + +LYTAnimation::LYTAnimation(QByteArray data) { + LYTBinaryFile file(data); + + foreach (const LYTBinaryFileSection §ion, file.sections) { + switch (section.magic.value) { + case 'pat1': { + // Info + QDataStream in(section.data); + InitDataStream(in); + + quint16 groupCount; + quint32 nameOffset, groupOffset; + quint8 flag; + + in >> sourceTagNumber; + in >> groupCount; + in >> nameOffset; + in >> groupOffset; + in >> sourceStartFrame; + in >> sourceEndFrame; + in >> flag; + + qDebug() << "Source: Tag:" << sourceTagNumber << "- Frames:" << sourceStartFrame << "to" << sourceEndFrame; + qDebug() << "Groups: Offset" << groupOffset << ", count" << groupCount << "- Name offset:" << nameOffset; + + recursiveBind = ((flag & 1) != 0); + qDebug() << "Flag:" << flag << "; Recursive bind:" << recursiveBind; + + in.device()->seek(nameOffset - 8); + // a royal hack + name = ReadFixedLengthASCII(in, groupOffset-nameOffset); + qDebug() << "Rlan name:" << name; + + groups.reserve(groupCount); + in.device()->seek(groupOffset - 8); + + for (int i = 0; i < groupCount; i++) { + LYTAnimGroupInfo info; + info.name = ReadFixedLengthASCII(in, 17); + in >> info.unusedFlag; + in.skipRawData(2); + groups.append(info); + + qDebug() << "Group name:" << info.name; + } + + break; + } + + case 'pai1': { + // Bits + QDataStream in(section.data); + InitDataStream(in); + + quint8 loop; + quint16 fileCount, blockCount; + quint32 offsetOffset; + + in >> frameSize; + in >> loop; + in.skipRawData(1); + in >> fileCount; + in >> blockCount; + in >> offsetOffset; + + qDebug() << "Loop:" << loop << "- File count:" << fileCount << ", Block count:" << blockCount; + qDebug() << "Offset Offset:" << offsetOffset; + + this->loop = (loop & 1); + + importedFiles.reserve(fileCount); + + for (int i = 0; i < fileCount; i++) { + quint32 offs; + in >> offs; + + qint64 saveMe = in.device()->pos(); + in.device()->seek(offs-8); + importedFiles.append(ReadVariableLengthASCII(in)); + in.device()->seek(saveMe); + + qDebug() << "Imported file:" << importedFiles.last(); + } + + // Now, each block + in.device()->seek(offsetOffset-8); + blocks.reserve(blockCount); + + for (int i = 0; i < blockCount; i++) { + quint32 blockOffs; + in >> blockOffs; + qint64 saveInList = in.device()->pos(); + in.device()->seek(blockOffs - 8); + + // Block. + LYTAnimBlock block; + block.name = ReadFixedLengthASCII(in, 20); + quint8 pieceCount, type; + in >> pieceCount; + in >> type; + in.skipRawData(2); + + block.isMaterial = (type == 1); + + qDebug() << "Block @ " << QString::number(blockOffs,16) << ":" << block.name << "- Piece Count:" << pieceCount << "- Type:" << type << "IsMaterial:" << block.isMaterial; + + // Now, the piece list + block.pieces.reserve(pieceCount); + + for (int j = 0; j < pieceCount; j++) { + quint32 pieceOffs; + in >> pieceOffs; + qint64 saveInList2 = in.device()->pos(); + in.device()->seek(blockOffs + pieceOffs - 8); + + // Piece + LYTAnimPiece piece; + Magic pieceMagic(0); + in >> pieceMagic.value; + + switch (pieceMagic.value) { + case 'RLPA': piece.type = piece.PaneAnim; break; + case 'RLTS': piece.type = piece.TexSRTAnim; break; + case 'RLVI': piece.type = piece.VisAnim; break; + case 'RLVC': piece.type = piece.VtxClrAnim; break; + case 'RLMC': piece.type = piece.MatClrAnim; break; + case 'RLTP': piece.type = piece.TexPatAnim; break; + case 'RLIM': piece.type = piece.IndTexSRTAnim; break; + } + + quint8 entryCount; + in >> entryCount; + in.skipRawData(3); + qDebug("Piece: %c%c%c%c, Entry Count: %d", pieceMagic.str[3], pieceMagic.str[2], pieceMagic.str[1], pieceMagic.str[0], entryCount); + + piece.entries.reserve(entryCount); + + // ANOTHER LIST ARGHHHH + for (int k = 0; k < entryCount; k++) { + quint32 entryOffs; + in >> entryOffs; + qint64 saveInList3 = in.device()->pos(); + in.device()->seek(blockOffs + pieceOffs + entryOffs - 8); + + // Entry + LYTAnimEntry entry; + in >> entry.id; + in >> entry.target; + in >> entry.curveType; + in.skipRawData(1); + + quint16 keyCount; + quint32 keyOffset; + + in >> keyCount; + in.skipRawData(2); + in >> keyOffset; + + qDebug() << "Entry ID:" << entry.id << "Target:" << entry.target << "CurveType:" << entry.curveType << "KeyCount:" << keyCount << "KeyOffset:" << keyOffset; + + in.device()->seek(blockOffs + pieceOffs + entryOffs + keyOffset - 8); + + if (piece.type == piece.TexPatAnim || piece.type == piece.VisAnim) { + entry.stepKeys.reserve(keyCount); + + for (int l = 0; l < keyCount; l++) { + // Step Key + LYTAnimStepKey key; + in >> key.frame; + in >> key.value; + in.skipRawData(2); + qDebug() << "Step Key:" << key.frame << key.value; + + entry.stepKeys.append(key); + } + + } else { + entry.keys.reserve(keyCount); + + for (int l = 0; l < keyCount; l++) { + // Key + LYTAnimHermiteKey key; + in >> key.frame; + in >> key.value; + in >> key.slope; + qDebug() << "Key:" << key.frame << key.value << key.slope; + + entry.keys.append(key); + } + } + + piece.entries.append(entry); + in.device()->seek(saveInList3); + } + + block.pieces.append(piece); + in.device()->seek(saveInList2); + } + + blocks.append(block); + in.device()->seek(saveInList); + } + + break; + } + + case 'pah1': + // Share + qFatal("AnimShare unsupported"); + break; + } + } +} diff --git a/lyt/animation.h b/lyt/animation.h new file mode 100644 index 0000000..efd626a --- /dev/null +++ b/lyt/animation.h @@ -0,0 +1,68 @@ +#ifndef LYTANIMATION_H +#define LYTANIMATION_H + +#include <QString> +#include <QVector> +#include <QList> +#include <QStringList> + +struct LYTAnimGroupInfo { + QString name; + quint8 unusedFlag; +}; + +struct LYTAnimStepKey { + float frame; + quint16 value; +}; + +struct LYTAnimHermiteKey { + float frame, value, slope; +}; + +struct LYTAnimEntry { + quint8 id, target, curveType; + QVector<LYTAnimHermiteKey> keys; + QVector<LYTAnimStepKey> stepKeys; +}; + +struct LYTAnimPiece { + enum Type { + PaneAnim = 0, + TexSRTAnim, + VisAnim, + VtxClrAnim, + MatClrAnim, + TexPatAnim, + IndTexSRTAnim + }; + + Type type; + QList<LYTAnimEntry> entries; +}; + +struct LYTAnimBlock { + QString name; + bool isMaterial; + QList<LYTAnimPiece> pieces; +}; + +class LYTAnimation { +public: + LYTAnimation(QByteArray data); + ~LYTAnimation(); + + QString name; + quint16 sourceTagNumber; + quint16 sourceStartFrame, sourceEndFrame; + bool recursiveBind; + + QList<LYTAnimGroupInfo> groups; + + quint16 frameSize; + bool loop; + QStringList importedFiles; + QList<LYTAnimBlock> blocks; +}; + +#endif // LYTANIMATION_H diff --git a/lyt/materials/tevswaptable.cpp b/lyt/materials/tevswaptable.cpp index a13a491..9121b78 100644 --- a/lyt/materials/tevswaptable.cpp +++ b/lyt/materials/tevswaptable.cpp @@ -50,10 +50,10 @@ void LYTTevSwapTable::readFromDataStream(QDataStream &in) { quint8 val; in >> (quint8&)val; - mode[i].red = BitExtract(val, 2, 32 - 8); - mode[i].green = BitExtract(val, 2, 32 - 6); - mode[i].blue = BitExtract(val, 2, 32 - 4); - mode[i].alpha = BitExtract(val, 2, 32 - 2); + mode[i].red = BitExtract(val, 2, 32 - 2); + mode[i].green = BitExtract(val, 2, 32 - 4); + mode[i].blue = BitExtract(val, 2, 32 - 6); + mode[i].alpha = BitExtract(val, 2, 32 - 8); } } diff --git a/lyt/textbox.cpp b/lyt/textbox.cpp index e943963..c845618 100644 --- a/lyt/textbox.cpp +++ b/lyt/textbox.cpp @@ -39,7 +39,7 @@ void LYTTextBox::dumpToDebug(bool showHeading) const { qDebug() << "- Text:" << text; qDebug() << "- Buffer Length:" << bufferLength; qDebug() << "- Material:" << materialName << "- Font:" << fontName; - qDebug() << "- Alignment:" << alignment << "- Alignment Override:" << alignmentOverride; + //qDebug() << "- Alignment:" << alignment << "- Alignment Override:" << alignmentOverride; qDebug() << "- Colours:" << colour1 << "--" << colour2; qDebug() << "- Font Size:" << fontSizeX << "x" << fontSizeY; qDebug() << "- Char Space:" << charSpace << "- Line Space:" << lineSpace; @@ -61,8 +61,8 @@ void LYTTextBox::writeToDataStream(QDataStream &out) const { out << (quint16)materialNum; out << (quint16)fontNum; - out << (quint8)alignment; - out << (quint8)alignmentOverride; + out << (quint8)(((int)textHorzPos) + (((int)textVertPos) * 3)); + out << (quint8)alignment; WritePadding(2, out); @@ -110,8 +110,11 @@ void LYTTextBox::readFromDataStream(QDataStream &in) { materialName = m_layout.materials.getNameOfIndex(materialNum); fontName = m_layout.m_fontRefs.at(fontNum); - in >> (quint8&)alignment; - in >> (quint8&)alignmentOverride; + quint8 whatpos; + in >> (quint8&)whatpos; + textHorzPos = (OriginType)(whatpos % 3); + textVertPos = (OriginType)(whatpos / 3); + in >> (quint8&)alignment; in.skipRawData(2); // padding diff --git a/lyt/textbox.h b/lyt/textbox.h index c61ef3a..564325d 100644 --- a/lyt/textbox.h +++ b/lyt/textbox.h @@ -42,8 +42,8 @@ public: QString materialName; QString fontName; - quint8 alignment; - quint8 alignmentOverride; + OriginType textHorzPos, textVertPos; + quint8 alignment; QColor colour1; QColor colour2; |