2025-02-14 16:06:27 -05:00
|
|
|
#include "fastfile_cod5.h"
|
2025-02-19 19:17:31 -05:00
|
|
|
#include "zonefile_cod5.h"
|
|
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
#include "compressor.h"
|
|
|
|
|
#include "statusbarmanager.h"
|
2025-02-14 16:06:27 -05:00
|
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
FastFile_COD5::FastFile_COD5() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FastFile_COD5::~FastFile_COD5() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FastFile_COD5::Load(const QString aFilePath) {
|
2025-02-19 19:17:31 -05:00
|
|
|
StatusBarManager::instance().updateStatus("Loading COD5 Fast File w/path", 1000);
|
|
|
|
|
|
2025-02-14 16:06:27 -05:00
|
|
|
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);
|
|
|
|
|
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_COD5::Load(const QByteArray aData) {
|
2025-02-19 19:17:31 -05:00
|
|
|
StatusBarManager::instance().updateStatus("Loading COD5 Fast File w/data", 1000);
|
2025-02-14 16:06:27 -05:00
|
|
|
QByteArray decompressedData;
|
|
|
|
|
|
|
|
|
|
// Create a QDataStream on the input data.
|
|
|
|
|
QDataStream fastFileStream(aData);
|
|
|
|
|
fastFileStream.setByteOrder(QDataStream::LittleEndian);
|
|
|
|
|
|
|
|
|
|
// Parse header values.
|
|
|
|
|
SetCompany(pParseFFCompany(&fastFileStream));
|
2025-02-19 19:17:31 -05:00
|
|
|
SetType(pParseFFFileType(&fastFileStream));
|
|
|
|
|
SetSignage(pParseFFSignage(&fastFileStream));
|
|
|
|
|
SetMagic(pParseFFMagic(&fastFileStream));
|
|
|
|
|
quint32 version = pParseFFVersion(&fastFileStream);
|
|
|
|
|
SetVersion(version);
|
|
|
|
|
const QString platformStr = pCalculateFFPlatform(version);
|
|
|
|
|
SetPlatform(platformStr);
|
|
|
|
|
SetGame("COD5");
|
2025-02-14 16:06:27 -05:00
|
|
|
|
|
|
|
|
// For COD5, simply decompress from offset 12.
|
|
|
|
|
decompressedData = Compressor::DecompressZLIB(aData.mid(12));
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-19 19:17:31 -05:00
|
|
|
FF_PLATFORM platform = FF_PLATFORM_NONE;
|
|
|
|
|
if (platformStr == "PC") {
|
|
|
|
|
platform = FF_PLATFORM_PC;
|
|
|
|
|
} else if (platformStr == "360") {
|
|
|
|
|
platform = FF_PLATFORM_XBOX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ZoneFile_COD5 zoneFile;
|
2025-03-01 20:38:52 -05:00
|
|
|
zoneFile.Load(decompressedData, GetStem() + ".zone", platform);
|
2025-02-19 19:17:31 -05:00
|
|
|
SetZoneFile(std::make_shared<ZoneFile_COD5>(zoneFile));
|
2025-02-14 16:06:27 -05:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|