152 lines
3.8 KiB
C++
152 lines
3.8 KiB
C++
#include "fastfile_cod11_360.h"
|
|
#include "zonefile_cod11_360.h"
|
|
|
|
#include "utils.h"
|
|
#include "compression.h"
|
|
#include "encryption.h"
|
|
|
|
#include <QFile>
|
|
#include <QDebug>
|
|
|
|
FastFile_COD11_360::FastFile_COD11_360()
|
|
: FastFile() {
|
|
SetCompany(COMPANY_INFINITY_WARD);
|
|
SetType(FILETYPE_FAST_FILE);
|
|
SetSignage(SIGNAGE_UNSIGNED);
|
|
SetMagic(0);
|
|
SetVersion(0);
|
|
SetGame("COD11");
|
|
SetPlatform("PC");
|
|
}
|
|
|
|
FastFile_COD11_360::FastFile_COD11_360(const QByteArray& aData)
|
|
: FastFile_COD11_360() {
|
|
|
|
if (!aData.isEmpty()) {
|
|
Load(aData);
|
|
}
|
|
}
|
|
|
|
FastFile_COD11_360::FastFile_COD11_360(const QString aFilePath)
|
|
: FastFile_COD11_360() {
|
|
if (!aFilePath.isEmpty()) {
|
|
Load(aFilePath);
|
|
}
|
|
}
|
|
|
|
FastFile_COD11_360::~FastFile_COD11_360() {
|
|
|
|
}
|
|
|
|
QByteArray FastFile_COD11_360::GetBinaryData() const {
|
|
return QByteArray();
|
|
}
|
|
|
|
bool FastFile_COD11_360::Load(const QString aFilePath) {
|
|
if (aFilePath.isEmpty()) {
|
|
return false;
|
|
}
|
|
|
|
// Check fastfile can be read
|
|
QFile *file = new QFile(aFilePath);
|
|
if (!file->open(QIODevice::ReadOnly)) {
|
|
qDebug() << QString("Error: Failed to open FastFile: %1!").arg(aFilePath);
|
|
return false;
|
|
}
|
|
|
|
// Decompress fastfile and close
|
|
const QString fastFileStem = aFilePath.section("/", -1, -1).split('.').first();
|
|
SetStem(fastFileStem);
|
|
if (!Load(file->readAll())) {
|
|
qDebug() << "Error: Failed to load fastfile: " << fastFileStem;
|
|
return false;
|
|
}
|
|
|
|
file->close();
|
|
|
|
// Open zone file after decompressing ff and writing
|
|
return true;
|
|
}
|
|
|
|
enum DB_CompressorType : qint32
|
|
{
|
|
DB_COMPRESSOR_INVALID = 0x0,
|
|
DB_COMPRESSOR_ZLIB = 0x1,
|
|
DB_COMPRESSOR_LZX = 0x2,
|
|
DB_COMPRESSOR_PASSTHROUGH = 0x3,
|
|
};
|
|
|
|
bool FastFile_COD11_360::Load(const QByteArray aData) {
|
|
QByteArray decompressedData;
|
|
|
|
// Prepare data stream for parsing
|
|
XDataStream fastFileStream(aData);
|
|
fastFileStream.setByteOrder(XDataStream::BigEndian);
|
|
|
|
// Verify magic header
|
|
QByteArray fileMagic(8, Qt::Uninitialized);
|
|
fastFileStream.readRawData(fileMagic.data(), 8);
|
|
quint32 version = fastFileStream.ParseUInt32();
|
|
|
|
fastFileStream.skipRawData(1);
|
|
|
|
DB_CompressorType compressorType = (DB_CompressorType)fastFileStream.ParseInt8();
|
|
|
|
fastFileStream.skipRawData(10);
|
|
|
|
qint32 blockCount = fastFileStream.ParseInt32();
|
|
|
|
if (version != 1838)
|
|
{
|
|
qWarning() << "Invalid fast file version:" << version << "!";
|
|
return false;
|
|
}
|
|
|
|
if (blockCount > 17280)
|
|
{
|
|
qWarning() << "Fast file has too many blocks:" << blockCount << "> 17280!";
|
|
return false;
|
|
}
|
|
fastFileStream.skipRawData(12 * blockCount);
|
|
|
|
qint32 startPos = fastFileStream.ParseInt32();
|
|
Q_UNUSED(startPos);
|
|
|
|
qint32 endPos = fastFileStream.ParseInt32();
|
|
Q_UNUSED(endPos);
|
|
|
|
if (fileMagic == "S1ffu100")
|
|
{
|
|
QByteArray compressedData = aData.mid(fastFileStream.device()->pos());
|
|
if (compressorType == DB_COMPRESSOR_ZLIB)
|
|
{
|
|
decompressedData = Compression::DecompressZLIB(compressedData);
|
|
}
|
|
else if (compressorType == DB_COMPRESSOR_LZX)
|
|
{
|
|
decompressedData = Compression::DecompressXMem(compressedData, 0, 0x80000, 0);
|
|
}
|
|
}
|
|
else if (fileMagic == "S1ff0100")
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
qWarning() << "Invalid fast file magic:" << fileMagic << "!";
|
|
return false;
|
|
}
|
|
Utils::ExportData(GetBaseStem() + ".zone", decompressedData);
|
|
|
|
// Load the zone file with decompressed data
|
|
ZoneFile_COD11_360* zoneFile = new ZoneFile_COD11_360();
|
|
zoneFile->SetStem(GetBaseStem() + ".zone");
|
|
if (!zoneFile->Load(decompressedData)) {
|
|
qWarning() << "Failed to load ZoneFile!";
|
|
return false;
|
|
}
|
|
SetZoneFile(zoneFile);
|
|
|
|
return true;
|
|
}
|