XPlor/libs/fastfile/fastfile_cod2.cpp

84 lines
2.2 KiB
C++
Raw Normal View History

2025-02-14 16:06:27 -05:00
#include "fastfile_cod2.h"
2025-02-19 19:17:31 -05:00
#include "utils.h"
2025-04-04 20:36:58 -04:00
#include "compression.h"
2025-02-19 19:17:31 -05:00
#include "zonefile_cod2.h"
2025-02-14 16:06:27 -05:00
#include <QFile>
#include <QDebug>
FastFile_COD2::FastFile_COD2() {
}
FastFile_COD2::~FastFile_COD2() {
}
2025-04-04 20:36:58 -04:00
QByteArray FastFile_COD2::GetBinaryData() {
return QByteArray();
}
2025-02-14 16:06:27 -05:00
bool FastFile_COD2::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
2025-03-01 20:38:52 -05:00
const QString fastFileStem = aFilePath.section("/", -1, -1).section(".", 0, 0);
qDebug() << "fastFileStem: " << fastFileStem;
2025-02-14 16:06:27 -05:00
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;
}
bool FastFile_COD2::Load(const QByteArray aData) {
// Create a QDataStream on the input data.
QDataStream fastFileStream(aData);
fastFileStream.setByteOrder(QDataStream::LittleEndian);
// Parse header values.
SetCompany(COMPANY_INFINITY_WARD);
SetType(FILETYPE_FAST_FILE);
SetSignage(SIGNAGE_UNSIGNED);
SetMagic(0);
SetVersion(0);
SetPlatform("360");
SetGame("COD2");
Utils::ReadUntilHex(&fastFileStream, "78");
QByteArray compressedData = aData.mid(fastFileStream.device()->pos());
2025-04-04 20:36:58 -04:00
QByteArray decompressedData = Compression::DecompressZLIB(compressedData);
2025-02-14 16:06:27 -05:00
2025-02-19 19:17:31 -05:00
QDir exportsDir(QDir::currentPath());
exportsDir.mkdir("exports");
2025-03-01 20:38:52 -05:00
QFile testFile("exports/" + GetStem() + ".zone");
2025-02-14 16:06:27 -05:00
if(testFile.open(QIODevice::WriteOnly)) {
testFile.write(decompressedData);
testFile.close();
}
// Load the zone file with the decompressed data (using an Xbox platform flag).
2025-02-19 19:17:31 -05:00
ZoneFile_COD2 zoneFile;
2025-04-04 20:36:58 -04:00
zoneFile.SetStem(GetStem());
zoneFile.Load(decompressedData, FF_PLATFORM_XBOX);
2025-02-19 19:17:31 -05:00
SetZoneFile(std::make_shared<ZoneFile_COD2>(zoneFile));
return true;
2025-02-14 16:06:27 -05:00
}