2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-02 15:07:26 +00:00

chore: dump fastfile data when xenon t6 fastfile is detected

This commit is contained in:
Jan Laupetin
2025-08-19 13:22:39 +02:00
parent facb95f1cb
commit 802b0f244a
19 changed files with 226 additions and 152 deletions

View File

@@ -16,6 +16,18 @@ enum class GameId
COUNT
};
enum class GameEndianness
{
LITTLE_ENDIAN,
BIG_ENDIAN
};
enum class GameWordSize
{
ARCH_32,
ARCH_64
};
static constexpr const char* GameId_Names[]{
"IW3",
"IW4",

View File

@@ -12,21 +12,25 @@ namespace T6
ZoneConstants() = default;
public:
static constexpr const char* MAGIC_SIGNED_TREYARCH = "TAff0100";
static constexpr const char* MAGIC_SIGNED_OAT = "ABff0100";
static constexpr const char* MAGIC_SIGNED_PC_TREYARCH = "TAff0100";
static constexpr const char* MAGIC_SIGNED_XENON_TREYARCH = "TAffx100";
static constexpr const char* MAGIC_SIGNED_PC_OAT = "ABff0100";
static constexpr const char* MAGIC_UNSIGNED = "TAffu100";
static constexpr const char* MAGIC_UNSIGNED_SERVER = "TAsvu100";
static_assert(std::char_traits<char>::length(MAGIC_SIGNED_TREYARCH) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_SIGNED_OAT) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_SIGNED_PC_TREYARCH) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_SIGNED_XENON_TREYARCH) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_SIGNED_PC_OAT) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_UNSIGNED) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_UNSIGNED_SERVER) == sizeof(ZoneHeader::m_magic));
static constexpr int ZONE_VERSION = 147;
static constexpr int STREAM_COUNT = 4;
static constexpr int XCHUNK_SIZE = 0x8000;
static constexpr int XCHUNK_MAX_WRITE_SIZE = XCHUNK_SIZE - 0x40;
static constexpr int VANILLA_BUFFER_SIZE = 0x80000;
static constexpr unsigned ZONE_VERSION_PC = 147;
static constexpr unsigned ZONE_VERSION_XENON = 146;
static constexpr unsigned STREAM_COUNT = 4;
static constexpr unsigned XCHUNK_SIZE = 0x8000;
static constexpr unsigned XCHUNK_MAX_WRITE_SIZE = XCHUNK_SIZE - 0x40;
static constexpr unsigned VANILLA_BUFFER_SIZE = 0x80000;
static constexpr unsigned OFFSET_BLOCK_BIT_COUNT = 3u;
static constexpr block_t INSERT_BLOCK = XFILE_BLOCK_VIRTUAL;
@@ -34,10 +38,14 @@ namespace T6
static constexpr size_t FILE_SUFFIX_ZERO_ALIGN = 0x40;
static constexpr const char* MAGIC_AUTH_HEADER = "PHEEBs71";
inline static const uint8_t SALSA20_KEY_TREYARCH[]{
inline static const uint8_t SALSA20_KEY_TREYARCH_PC[]{
0x64, 0x1D, 0x8A, 0x2F, 0xE3, 0x1D, 0x3A, 0xA6, 0x36, 0x22, 0xBB, 0xC9, 0xCE, 0x85, 0x87, 0x22,
0x9D, 0x42, 0xB0, 0xF8, 0xED, 0x9B, 0x92, 0x41, 0x30, 0xBF, 0x88, 0xB6, 0x5E, 0xDC, 0x50, 0xBE,
};
inline static const uint8_t SALSA20_KEY_TREYARCH_XENON[]{
0x0E, 0x50, 0xF4, 0x9F, 0x41, 0x23, 0x17, 0x09, 0x60, 0x38, 0x66, 0x56, 0x22, 0xDD, 0x09, 0x13,
0x32, 0xA2, 0x09, 0xBA, 0x0A, 0x05, 0xA0, 0x0E, 0x13, 0x77, 0xCE, 0xDB, 0x0A, 0x3C, 0xB1, 0xD3,
};
inline static const uint8_t RSA_PUBLIC_KEY_TREYARCH[]{
0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc7, 0x9d, 0x33, 0xe0, 0x75, 0xaf, 0xef, 0x08, 0x08, 0x2b, 0x89, 0xd9, 0x3b, 0xf3,

View File

@@ -2,24 +2,16 @@
#include <cassert>
AbstractSalsa20Processor::AbstractSalsa20Processor(const int streamCount, const std::string& zoneName, const uint8_t* salsa20Key, const size_t keySize)
AbstractSalsa20Processor::AbstractSalsa20Processor(const unsigned streamCount, const std::string& zoneName, const uint8_t* salsa20Key, const unsigned keySize)
: m_stream_count(streamCount),
m_stream_contexts(std::make_unique<StreamContext[]>(streamCount)),
m_stream_block_indices(std::make_unique<unsigned int[]>(streamCount))
m_stream_contexts(streamCount),
m_block_hashes(BLOCK_HASHES_COUNT * streamCount * SHA1_HASH_SIZE),
m_stream_block_indices(streamCount)
{
m_block_hashes = std::make_unique<uint8_t[]>(BLOCK_HASHES_COUNT * streamCount * SHA1_HASH_SIZE);
InitStreams(zoneName, salsa20Key, keySize);
}
uint8_t* AbstractSalsa20Processor::GetHashBlock(const int streamNumber) const
{
const auto blockIndexOffset = m_stream_block_indices[streamNumber] * m_stream_count * SHA1_HASH_SIZE;
const auto streamOffset = static_cast<size_t>(streamNumber) * SHA1_HASH_SIZE;
return &m_block_hashes[blockIndexOffset + streamOffset];
}
void AbstractSalsa20Processor::InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, const size_t keySize) const
void AbstractSalsa20Processor::InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, const size_t keySize)
{
// Original buffer must have been 32 bytes because the zoneName can at most be 31 characters be long before being cut off
const auto zoneNameLength = std::min(zoneName.length(), 31uz);
@@ -29,14 +21,14 @@ void AbstractSalsa20Processor::InitStreams(const std::string& zoneName, const ui
assert(blockHashBufferSize % 4 == 0);
size_t zoneNameOffset = 0;
for (size_t i = 0; i < blockHashBufferSize; i += 4)
for (auto i = 0uz; i < blockHashBufferSize; i += 4)
{
*reinterpret_cast<uint32_t*>(&m_block_hashes[i]) = 0x1010101 * zoneName[zoneNameOffset++];
memset(&m_block_hashes[i], zoneName[zoneNameOffset++], 4u);
zoneNameOffset %= zoneNameLength;
}
for (auto stream = 0; stream < m_stream_count; stream++)
for (auto stream = 0u; stream < m_stream_count; stream++)
{
m_stream_block_indices[stream] = 0;
@@ -45,11 +37,19 @@ void AbstractSalsa20Processor::InitStreams(const std::string& zoneName, const ui
}
}
uint8_t* AbstractSalsa20Processor::GetHashBlock(const unsigned streamNumber)
{
const auto blockIndexOffset = m_stream_block_indices[streamNumber] * m_stream_count * SHA1_HASH_SIZE;
const auto streamOffset = static_cast<size_t>(streamNumber) * SHA1_HASH_SIZE;
return &m_block_hashes[blockIndexOffset + streamOffset];
}
void AbstractSalsa20Processor::GetCapturedData(const uint8_t** pCapturedData, size_t* pSize)
{
assert(pCapturedData != nullptr);
assert(pSize != nullptr);
*pCapturedData = m_block_hashes.get();
*pCapturedData = m_block_hashes.data();
*pSize = BLOCK_HASHES_COUNT * m_stream_count * SHA1_HASH_SIZE;
}

View File

@@ -1,40 +1,22 @@
#pragma once
#include "Cryptography.h"
#include "Utils/ClassUtils.h"
#include "Utils/ICapturedDataProvider.h"
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
class Salsa20StreamContext
{
public:
std::unique_ptr<cryptography::IStreamCipher> m_salsa20;
std::unique_ptr<cryptography::IHashFunction> m_sha1;
};
class AbstractSalsa20Processor : public ICapturedDataProvider
{
protected:
static constexpr int BLOCK_HASHES_COUNT = 200;
static constexpr int SHA1_HASH_SIZE = 20;
static constexpr int SALSA20_IV_SIZE = 8;
class StreamContext
{
public:
std::unique_ptr<cryptography::IStreamCipher> m_salsa20;
std::unique_ptr<cryptography::IHashFunction> m_sha1;
};
int m_stream_count;
std::unique_ptr<StreamContext[]> m_stream_contexts;
// m_block_hashes[BLOCK_HASHES_COUNT][numStreams][HASH_SIZE]
std::unique_ptr<uint8_t[]> m_block_hashes;
std::unique_ptr<unsigned int[]> m_stream_block_indices;
AbstractSalsa20Processor(int streamCount, const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
_NODISCARD uint8_t* GetHashBlock(int streamNumber) const;
void InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize) const;
public:
virtual ~AbstractSalsa20Processor() = default;
AbstractSalsa20Processor(const AbstractSalsa20Processor& other) = delete;
@@ -43,4 +25,21 @@ public:
AbstractSalsa20Processor& operator=(AbstractSalsa20Processor&& other) noexcept = default;
void GetCapturedData(const uint8_t** pCapturedData, size_t* pSize) override;
protected:
static constexpr auto BLOCK_HASHES_COUNT = 200u;
static constexpr auto SHA1_HASH_SIZE = 20u;
static constexpr auto SALSA20_IV_SIZE = 8u;
AbstractSalsa20Processor(unsigned streamCount, const std::string& zoneName, const uint8_t* salsa20Key, unsigned keySize);
void InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
[[nodiscard]] uint8_t* GetHashBlock(unsigned streamNumber);
unsigned m_stream_count;
std::vector<Salsa20StreamContext> m_stream_contexts;
// m_block_hashes[BLOCK_HASHES_COUNT][numStreams][SHA1_HASH_SIZE]
std::vector<uint8_t> m_block_hashes;
std::vector<unsigned int> m_stream_block_indices;
};

View File

@@ -6,6 +6,12 @@
class IXChunkProcessor
{
public:
IXChunkProcessor() = default;
virtual ~IXChunkProcessor() = default;
virtual size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) = 0;
IXChunkProcessor(const IXChunkProcessor& other) = default;
IXChunkProcessor(IXChunkProcessor&& other) noexcept = default;
IXChunkProcessor& operator=(const IXChunkProcessor& other) = default;
IXChunkProcessor& operator=(IXChunkProcessor&& other) noexcept = default;
virtual size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) = 0;
};

View File

@@ -6,7 +6,7 @@
#include <zlib.h>
#include <zutil.h>
size_t XChunkProcessorDeflate::Process(int streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
size_t XChunkProcessorDeflate::Process(unsigned streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
{
z_stream stream{};
stream.zalloc = Z_NULL;

View File

@@ -4,5 +4,5 @@
class XChunkProcessorDeflate final : public IXChunkProcessor
{
public:
size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
};

View File

@@ -2,10 +2,12 @@
#include "XChunkException.h"
#include <format>
#include <iostream>
#include <zlib.h>
#include <zutil.h>
size_t XChunkProcessorInflate::Process(int streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
size_t XChunkProcessorInflate::Process(unsigned streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
{
z_stream stream{};
stream.zalloc = Z_NULL;
@@ -23,7 +25,10 @@ size_t XChunkProcessorInflate::Process(int streamNumber, const uint8_t* input, c
ret = inflate(&stream, Z_FULL_FLUSH);
if (ret != Z_STREAM_END)
throw XChunkException("Zone has invalid or unsupported compression. Inflate failed");
{
std::cerr << std::format("inflate of stream failed with error code {}: {}\n", streamNumber, ret, stream.msg);
throw XChunkException(std::format("Zone has invalid or unsupported compression: {}", stream.msg));
}
const size_t outputSize = stream.total_out;

View File

@@ -4,5 +4,5 @@
class XChunkProcessorInflate final : public IXChunkProcessor
{
public:
size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
};

View File

@@ -4,9 +4,11 @@
#include "Cryptography.h"
#include <cassert>
#include <format>
#include <iostream>
XChunkProcessorSalsa20Decryption::XChunkProcessorSalsa20Decryption(const int streamCount,
std::string& zoneName,
XChunkProcessorSalsa20Decryption::XChunkProcessorSalsa20Decryption(const unsigned streamCount,
const std::string& zoneName,
const uint8_t* salsa20Key,
const size_t keySize)
: AbstractSalsa20Processor(streamCount, zoneName, salsa20Key, keySize)
@@ -14,9 +16,9 @@ XChunkProcessorSalsa20Decryption::XChunkProcessorSalsa20Decryption(const int str
}
size_t XChunkProcessorSalsa20Decryption::Process(
const int streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
const unsigned streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
{
assert(streamNumber >= 0 && streamNumber < m_stream_count);
assert(streamNumber < m_stream_count);
assert(input != nullptr);
assert(output != nullptr);
assert(inputLength <= outputBufferSize);

View File

@@ -7,7 +7,7 @@
class XChunkProcessorSalsa20Decryption final : public IXChunkProcessor, public AbstractSalsa20Processor
{
public:
XChunkProcessorSalsa20Decryption(int streamCount, std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
XChunkProcessorSalsa20Decryption(unsigned streamCount, const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
};

View File

@@ -2,7 +2,7 @@
#include <cassert>
XChunkProcessorSalsa20Encryption::XChunkProcessorSalsa20Encryption(const int streamCount,
XChunkProcessorSalsa20Encryption::XChunkProcessorSalsa20Encryption(const unsigned streamCount,
const std::string& zoneName,
const uint8_t* salsa20Key,
const size_t keySize)
@@ -11,14 +11,14 @@ XChunkProcessorSalsa20Encryption::XChunkProcessorSalsa20Encryption(const int str
}
size_t XChunkProcessorSalsa20Encryption::Process(
const int streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
const unsigned streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
{
assert(streamNumber >= 0 && streamNumber < m_stream_count);
assert(streamNumber < m_stream_count);
assert(input != nullptr);
assert(output != nullptr);
assert(inputLength <= outputBufferSize);
auto& streamContext = m_stream_contexts[streamNumber];
const auto& streamContext = m_stream_contexts[streamNumber];
// Hash not yet encrypted XChunk
uint8_t blockSha1Hash[SHA1_HASH_SIZE];

View File

@@ -8,7 +8,7 @@
class XChunkProcessorSalsa20Encryption final : public IXChunkProcessor, public AbstractSalsa20Processor
{
public:
XChunkProcessorSalsa20Encryption(int streamCount, const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
XChunkProcessorSalsa20Encryption(unsigned streamCount, const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
};

View File

@@ -9,6 +9,7 @@
#include "Loading/Processor/ProcessorXChunks.h"
#include "Loading/Steps/StepAddProcessor.h"
#include "Loading/Steps/StepAllocXBlocks.h"
#include "Loading/Steps/StepDumpData.h"
#include "Loading/Steps/StepLoadSignature.h"
#include "Loading/Steps/StepLoadZoneContent.h"
#include "Loading/Steps/StepLoadZoneSizes.h"
@@ -16,16 +17,20 @@
#include "Loading/Steps/StepVerifyFileName.h"
#include "Loading/Steps/StepVerifyMagic.h"
#include "Loading/Steps/StepVerifySignature.h"
#include "Utils/ClassUtils.h"
#include "Utils/Endianness.h"
#include "Zone/XChunk/XChunkProcessorInflate.h"
#include "Zone/XChunk/XChunkProcessorSalsa20Decryption.h"
#include <cassert>
#include <cstdio>
#include <cstring>
#include <filesystem>
#include <format>
#include <iostream>
#include <memory>
using namespace T6;
namespace fs = std::filesystem;
namespace
{
@@ -44,46 +49,53 @@ namespace
return GameLanguage::LANGUAGE_NONE;
}
bool CanLoad(const ZoneHeader& header, bool* isSecure, bool* isOfficial, bool* isEncrypted)
bool CanLoad(const ZoneHeader& header, bool& isBigEndian, bool& isSecure, bool& isOfficial, bool& isEncrypted)
{
assert(isSecure != nullptr);
assert(isOfficial != nullptr);
if (header.m_version != ZoneConstants::ZONE_VERSION)
if (endianness::FromLittleEndian(header.m_version) == ZoneConstants::ZONE_VERSION_PC)
{
return false;
isBigEndian = false;
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_PC_TREYARCH, 8))
{
isSecure = true;
isOfficial = true;
isEncrypted = true;
return true;
}
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_PC_OAT, 8))
{
isSecure = true;
isOfficial = false;
isEncrypted = true;
return true;
}
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_UNSIGNED, 8))
{
isSecure = false;
isOfficial = true;
isEncrypted = true;
return true;
}
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_UNSIGNED_SERVER, 8))
{
isSecure = false;
isOfficial = true;
isEncrypted = false;
return true;
}
}
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_TREYARCH, 8))
else if (endianness::FromBigEndian(header.m_version) == ZoneConstants::ZONE_VERSION_XENON)
{
*isSecure = true;
*isOfficial = true;
*isEncrypted = true;
return true;
}
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_OAT, 8))
{
*isSecure = true;
*isOfficial = false;
*isEncrypted = true;
return true;
}
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_UNSIGNED, 8))
{
*isSecure = false;
*isOfficial = true;
*isEncrypted = true;
return true;
}
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_UNSIGNED_SERVER, 8))
{
*isSecure = false;
*isOfficial = true;
*isEncrypted = false;
return true;
isBigEndian = true;
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_XENON_TREYARCH, 8))
{
isSecure = true;
isOfficial = true;
isEncrypted = true;
return true;
}
}
return false;
@@ -145,16 +157,21 @@ namespace
return signatureLoadStepPtr;
}
ICapturedDataProvider* AddXChunkProcessor(const bool isEncrypted, ZoneLoader& zoneLoader, std::string& fileName)
ICapturedDataProvider* AddXChunkProcessor(const bool isBigEndian, const bool isEncrypted, ZoneLoader& zoneLoader, std::string& fileName)
{
ICapturedDataProvider* result = nullptr;
auto xChunkProcessor = processor::CreateProcessorXChunks(ZoneConstants::STREAM_COUNT, ZoneConstants::XCHUNK_SIZE, ZoneConstants::VANILLA_BUFFER_SIZE);
auto xChunkProcessor = processor::CreateProcessorXChunks(ZoneConstants::STREAM_COUNT,
ZoneConstants::XCHUNK_SIZE,
isBigEndian ? GameEndianness::BIG_ENDIAN : GameEndianness::LITTLE_ENDIAN,
ZoneConstants::VANILLA_BUFFER_SIZE);
const uint8_t (&salsa20Key)[32] = isBigEndian ? ZoneConstants::SALSA20_KEY_TREYARCH_XENON : ZoneConstants::SALSA20_KEY_TREYARCH_PC;
if (isEncrypted)
{
// If zone is encrypted, the decryption is applied before the decompression. T6 Zones always use Salsa20.
auto chunkProcessorSalsa20 = std::make_unique<XChunkProcessorSalsa20Decryption>(
ZoneConstants::STREAM_COUNT, fileName, ZoneConstants::SALSA20_KEY_TREYARCH, sizeof(ZoneConstants::SALSA20_KEY_TREYARCH));
auto chunkProcessorSalsa20 =
std::make_unique<XChunkProcessorSalsa20Decryption>(ZoneConstants::STREAM_COUNT, fileName, salsa20Key, sizeof(salsa20Key));
result = chunkProcessorSalsa20.get();
xChunkProcessor->AddChunkProcessor(std::move(chunkProcessorSalsa20));
}
@@ -170,12 +187,10 @@ namespace
std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const
{
bool isSecure;
bool isOfficial;
bool isEncrypted;
bool isBigEndian, isSecure, isOfficial, isEncrypted;
// Check if this file is a supported T6 zone.
if (!CanLoad(header, &isSecure, &isOfficial, &isEncrypted))
if (!CanLoad(header, isBigEndian, isSecure, isOfficial, isEncrypted))
return nullptr;
// Create new zone
@@ -196,26 +211,37 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader&
ISignatureProvider* signatureProvider = AddAuthHeaderSteps(isSecure, *zoneLoader, fileName);
// Setup loading XChunks from the zone from this point on.
ICapturedDataProvider* signatureDataProvider = AddXChunkProcessor(isEncrypted, *zoneLoader, fileName);
ICapturedDataProvider* signatureDataProvider = AddXChunkProcessor(isBigEndian, isEncrypted, *zoneLoader, fileName);
// Start of the XFile struct
zoneLoader->AddLoadingStep(step::CreateStepLoadZoneSizes());
zoneLoader->AddLoadingStep(step::CreateStepAllocXBlocks());
// Start of the zone content
zoneLoader->AddLoadingStep(step::CreateStepLoadZoneContent(
[zonePtr](ZoneInputStream& stream)
{
return std::make_unique<ContentLoader>(*zonePtr, stream);
},
32u,
ZoneConstants::OFFSET_BLOCK_BIT_COUNT,
ZoneConstants::INSERT_BLOCK,
zonePtr->Memory()));
if (isSecure)
if (!isBigEndian)
{
zoneLoader->AddLoadingStep(step::CreateStepVerifySignature(std::move(rsa), signatureProvider, signatureDataProvider));
// Start of the XFile struct
zoneLoader->AddLoadingStep(step::CreateStepLoadZoneSizes());
zoneLoader->AddLoadingStep(step::CreateStepAllocXBlocks());
// Start of the zone content
zoneLoader->AddLoadingStep(step::CreateStepLoadZoneContent(
[zonePtr](ZoneInputStream& stream)
{
return std::make_unique<ContentLoader>(*zonePtr, stream);
},
32u,
ZoneConstants::OFFSET_BLOCK_BIT_COUNT,
ZoneConstants::INSERT_BLOCK,
zonePtr->Memory()));
if (isSecure)
{
zoneLoader->AddLoadingStep(step::CreateStepVerifySignature(std::move(rsa), signatureProvider, signatureDataProvider));
}
}
else
{
fs::path dumpFileNamePath = fs::path(fileName).filename();
dumpFileNamePath.replace_extension(".dat");
std::string dumpFileName = dumpFileNamePath.string();
std::cerr << std::format("Dumping xbox assets is not supported, making a full fastfile data dump to {}\n", dumpFileName);
zoneLoader->AddLoadingStep(step::CreateStepDumpData(dumpFileName, 0xFFFFFFFF));
}
return zoneLoader;

View File

@@ -1,11 +1,14 @@
#include "ProcessorXChunks.h"
#include "Loading/Exception/InvalidChunkSizeException.h"
#include "Utils/Endianness.h"
#include "Zone/ZoneTypes.h"
#include <cassert>
#include <condition_variable>
#include <cstring>
#include <format>
#include <iostream>
#include <memory>
#include <mutex>
#include <optional>
@@ -125,8 +128,9 @@ namespace
class ProcessorXChunks final : public processor::IProcessorXChunks
{
public:
ProcessorXChunks(const int numStreams, const size_t xChunkSize, const std::optional<size_t> vanillaBufferSize)
ProcessorXChunks(const int numStreams, const size_t xChunkSize, const GameEndianness endianness, const std::optional<size_t> vanillaBufferSize)
: m_chunk_size(xChunkSize),
m_endianness(endianness),
m_vanilla_buffer_size(vanillaBufferSize),
m_initialized_streams(false),
m_current_stream(0),
@@ -227,6 +231,11 @@ namespace
return;
}
if (m_endianness == GameEndianness::LITTLE_ENDIAN)
chunkSize = endianness::FromLittleEndian(chunkSize);
else
chunkSize = endianness::FromBigEndian(chunkSize);
if (chunkSize > m_chunk_size)
{
throw InvalidChunkSizeException(chunkSize, m_chunk_size);
@@ -280,6 +289,7 @@ namespace
std::vector<std::unique_ptr<DbLoadStream>> m_streams;
size_t m_chunk_size;
GameEndianness m_endianness;
std::optional<size_t> m_vanilla_buffer_size;
std::vector<std::unique_ptr<IXChunkProcessor>> m_chunk_processors;
@@ -297,13 +307,14 @@ namespace
namespace processor
{
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(int numStreams, const size_t xChunkSize)
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(unsigned numStreams, const size_t xChunkSize, const GameEndianness endianness)
{
return std::make_unique<ProcessorXChunks>(numStreams, xChunkSize, std::nullopt);
return std::make_unique<ProcessorXChunks>(numStreams, xChunkSize, endianness, std::nullopt);
}
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(int numStreams, const size_t xChunkSize, const size_t vanillaBufferSize)
std::unique_ptr<IProcessorXChunks>
CreateProcessorXChunks(unsigned numStreams, const size_t xChunkSize, GameEndianness endianness, const size_t vanillaBufferSize)
{
return std::make_unique<ProcessorXChunks>(numStreams, xChunkSize, vanillaBufferSize);
return std::make_unique<ProcessorXChunks>(numStreams, xChunkSize, endianness, vanillaBufferSize);
}
} // namespace processor

View File

@@ -1,4 +1,6 @@
#pragma once
#include "Game/IGame.h"
#include "Loading/StreamProcessor.h"
#include "Zone/XChunk/IXChunkProcessor.h"
@@ -12,6 +14,6 @@ namespace processor
virtual void AddChunkProcessor(std::unique_ptr<IXChunkProcessor> chunkProcessor) = 0;
};
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(int numStreams, size_t xChunkSize);
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(int numStreams, size_t xChunkSize, size_t vanillaBufferSize);
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(unsigned numStreams, size_t xChunkSize, GameEndianness endianness);
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(unsigned numStreams, size_t xChunkSize, GameEndianness endianness, size_t vanillaBufferSize);
} // namespace processor

View File

@@ -7,17 +7,18 @@ namespace
class StepDumpData final : public ILoadingStep
{
public:
explicit StepDumpData(const size_t dumpCount)
: m_dump_count(dumpCount)
StepDumpData(std::string fileName, const size_t dumpCount)
: m_file_name(std::move(fileName)),
m_dump_count(dumpCount)
{
}
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
{
uint8_t tempBuffer[128];
uint8_t tempBuffer[0x1000];
auto dumpedBytes = 0uz;
std::ofstream tempFile("dump.dat", std::fstream::out | std::fstream::binary);
std::ofstream tempFile(m_file_name, std::fstream::out | std::fstream::binary);
while (dumpedBytes < m_dump_count)
{
@@ -45,14 +46,15 @@ namespace
}
private:
std::string m_file_name;
size_t m_dump_count;
};
} // namespace
namespace step
{
std::unique_ptr<ILoadingStep> CreateStepDumpData(size_t dumpCount)
std::unique_ptr<ILoadingStep> CreateStepDumpData(std::string fileName, size_t dumpCount)
{
return std::make_unique<StepDumpData>(dumpCount);
return std::make_unique<StepDumpData>(std::move(fileName), dumpCount);
}
} // namespace step

View File

@@ -3,8 +3,9 @@
#include "Loading/ILoadingStep.h"
#include <memory>
#include <string>
namespace step
{
std::unique_ptr<ILoadingStep> CreateStepDumpData(size_t dumpCount);
std::unique_ptr<ILoadingStep> CreateStepDumpData(std::string fileName, size_t dumpCount);
}

View File

@@ -44,14 +44,14 @@ namespace
ZoneHeader CreateHeaderForParams(const bool isSecure, const bool isOfficial, const bool isEncrypted)
{
ZoneHeader header{};
header.m_version = ZoneConstants::ZONE_VERSION;
header.m_version = ZoneConstants::ZONE_VERSION_PC;
if (isSecure)
{
if (isOfficial)
memcpy(header.m_magic, ZoneConstants::MAGIC_SIGNED_TREYARCH, sizeof(ZoneHeader::m_magic));
memcpy(header.m_magic, ZoneConstants::MAGIC_SIGNED_PC_TREYARCH, sizeof(ZoneHeader::m_magic));
else
memcpy(header.m_magic, ZoneConstants::MAGIC_SIGNED_OAT, sizeof(ZoneHeader::m_magic));
memcpy(header.m_magic, ZoneConstants::MAGIC_SIGNED_PC_OAT, sizeof(ZoneHeader::m_magic));
}
else
{
@@ -82,7 +82,7 @@ namespace
{
// If zone is encrypted, the decryption is applied before the decompression. T6 Zones always use Salsa20.
auto chunkProcessorSalsa20 = std::make_unique<XChunkProcessorSalsa20Encryption>(
ZoneConstants::STREAM_COUNT, zone.m_name, ZoneConstants::SALSA20_KEY_TREYARCH, sizeof(ZoneConstants::SALSA20_KEY_TREYARCH));
ZoneConstants::STREAM_COUNT, zone.m_name, ZoneConstants::SALSA20_KEY_TREYARCH_PC, sizeof(ZoneConstants::SALSA20_KEY_TREYARCH_PC));
// If there is encryption, the signed data of the zone is the final hash blocks provided by the Salsa20 IV adaption algorithm
if (dataToSignProviderPtr)