mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-09-02 06:57:26 +00:00
chore: recognize when xenon fastfile use lzx compression
This commit is contained in:
@@ -16,10 +16,14 @@ enum class GameId
|
||||
COUNT
|
||||
};
|
||||
|
||||
// The full uppercase names are macros in the standard lib
|
||||
// So unfortunately not usable as values in the enum
|
||||
enum class GameEndianness
|
||||
{
|
||||
LITTLE_ENDIAN,
|
||||
BIG_ENDIAN
|
||||
/* Little endian */
|
||||
LE,
|
||||
/* Big endian */
|
||||
BE
|
||||
};
|
||||
|
||||
enum class GameWordSize
|
||||
|
@@ -12,15 +12,15 @@ namespace T6
|
||||
ZoneConstants() = default;
|
||||
|
||||
public:
|
||||
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_SIGNED_TREYARCH = "TAff0100";
|
||||
static constexpr const char* MAGIC_SIGNED_LZX_TREYARCH = "TAffx100";
|
||||
static constexpr const char* MAGIC_SIGNED_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_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_SIGNED_TREYARCH) == sizeof(ZoneHeader::m_magic));
|
||||
static_assert(std::char_traits<char>::length(MAGIC_SIGNED_LZX_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_UNSIGNED) == sizeof(ZoneHeader::m_magic));
|
||||
static_assert(std::char_traits<char>::length(MAGIC_UNSIGNED_SERVER) == sizeof(ZoneHeader::m_magic));
|
||||
|
||||
|
@@ -1,8 +1,9 @@
|
||||
#include "AbstractSalsa20Processor.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
AbstractSalsa20Processor::AbstractSalsa20Processor(const unsigned streamCount, const std::string& zoneName, const uint8_t* salsa20Key, const unsigned keySize)
|
||||
AbstractSalsa20Processor::AbstractSalsa20Processor(const unsigned streamCount, const std::string& zoneName, const uint8_t* salsa20Key, const size_t keySize)
|
||||
: m_stream_count(streamCount),
|
||||
m_stream_contexts(streamCount),
|
||||
m_block_hashes(BLOCK_HASHES_COUNT * streamCount * SHA1_HASH_SIZE),
|
||||
|
@@ -31,7 +31,7 @@ protected:
|
||||
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);
|
||||
AbstractSalsa20Processor(unsigned streamCount, const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
|
||||
void InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
|
||||
|
||||
[[nodiscard]] uint8_t* GetHashBlock(unsigned streamNumber);
|
||||
|
12
src/ZoneCommon/Zone/XChunk/XChunkProcessorLzxDecompress.cpp
Normal file
12
src/ZoneCommon/Zone/XChunk/XChunkProcessorLzxDecompress.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "XChunkProcessorLzxDecompress.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
size_t
|
||||
XChunkProcessorLzxDecompress::Process(unsigned streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
|
||||
{
|
||||
// TODO: Implement
|
||||
|
||||
memcpy(output, input, inputLength);
|
||||
return inputLength;
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "IXChunkProcessor.h"
|
||||
|
||||
class XChunkProcessorLzxDecompress final : public IXChunkProcessor
|
||||
{
|
||||
public:
|
||||
size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
|
||||
};
|
@@ -19,6 +19,7 @@
|
||||
#include "Loading/Steps/StepVerifySignature.h"
|
||||
#include "Utils/Endianness.h"
|
||||
#include "Zone/XChunk/XChunkProcessorInflate.h"
|
||||
#include "Zone/XChunk/XChunkProcessorLzxDecompress.h"
|
||||
#include "Zone/XChunk/XChunkProcessorSalsa20Decryption.h"
|
||||
|
||||
#include <cassert>
|
||||
@@ -49,12 +50,13 @@ namespace
|
||||
return GameLanguage::LANGUAGE_NONE;
|
||||
}
|
||||
|
||||
bool CanLoad(const ZoneHeader& header, bool& isBigEndian, bool& isSecure, bool& isOfficial, bool& isEncrypted)
|
||||
bool CanLoad(const ZoneHeader& header, bool& isBigEndian, bool& isSecure, bool& isOfficial, bool& isEncrypted, bool& isLzxCompressed)
|
||||
{
|
||||
if (endianness::FromLittleEndian(header.m_version) == ZoneConstants::ZONE_VERSION_PC)
|
||||
{
|
||||
isBigEndian = false;
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_PC_TREYARCH, 8))
|
||||
isLzxCompressed = false;
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_TREYARCH, 8))
|
||||
{
|
||||
isSecure = true;
|
||||
isOfficial = true;
|
||||
@@ -62,7 +64,7 @@ namespace
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_PC_OAT, 8))
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_OAT, 8))
|
||||
{
|
||||
isSecure = true;
|
||||
isOfficial = false;
|
||||
@@ -89,11 +91,20 @@ namespace
|
||||
else if (endianness::FromBigEndian(header.m_version) == ZoneConstants::ZONE_VERSION_XENON)
|
||||
{
|
||||
isBigEndian = true;
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_XENON_TREYARCH, 8))
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_TREYARCH, 8))
|
||||
{
|
||||
isSecure = true;
|
||||
isOfficial = true;
|
||||
isEncrypted = true;
|
||||
isLzxCompressed = false;
|
||||
return true;
|
||||
}
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_LZX_TREYARCH, 8))
|
||||
{
|
||||
isSecure = true;
|
||||
isOfficial = true;
|
||||
isEncrypted = true;
|
||||
isLzxCompressed = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -157,13 +168,12 @@ namespace
|
||||
return signatureLoadStepPtr;
|
||||
}
|
||||
|
||||
ICapturedDataProvider* AddXChunkProcessor(const bool isBigEndian, const bool isEncrypted, ZoneLoader& zoneLoader, std::string& fileName)
|
||||
ICapturedDataProvider*
|
||||
AddXChunkProcessor(const bool isBigEndian, const bool isEncrypted, const bool isLzxCompressed, ZoneLoader& zoneLoader, std::string& fileName)
|
||||
{
|
||||
ICapturedDataProvider* result = nullptr;
|
||||
auto xChunkProcessor = processor::CreateProcessorXChunks(ZoneConstants::STREAM_COUNT,
|
||||
ZoneConstants::XCHUNK_SIZE,
|
||||
isBigEndian ? GameEndianness::BIG_ENDIAN : GameEndianness::LITTLE_ENDIAN,
|
||||
ZoneConstants::VANILLA_BUFFER_SIZE);
|
||||
auto xChunkProcessor = processor::CreateProcessorXChunks(
|
||||
ZoneConstants::STREAM_COUNT, ZoneConstants::XCHUNK_SIZE, isBigEndian ? GameEndianness::BE : GameEndianness::LE, ZoneConstants::VANILLA_BUFFER_SIZE);
|
||||
|
||||
const uint8_t (&salsa20Key)[32] = isBigEndian ? ZoneConstants::SALSA20_KEY_TREYARCH_XENON : ZoneConstants::SALSA20_KEY_TREYARCH_PC;
|
||||
|
||||
@@ -176,8 +186,17 @@ namespace
|
||||
xChunkProcessor->AddChunkProcessor(std::move(chunkProcessorSalsa20));
|
||||
}
|
||||
|
||||
// Decompress the chunks using zlib
|
||||
xChunkProcessor->AddChunkProcessor(std::make_unique<XChunkProcessorInflate>());
|
||||
if (isLzxCompressed)
|
||||
{
|
||||
// Decompress the chunks using lzx
|
||||
xChunkProcessor->AddChunkProcessor(std::make_unique<XChunkProcessorLzxDecompress>());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Decompress the chunks using zlib
|
||||
xChunkProcessor->AddChunkProcessor(std::make_unique<XChunkProcessorInflate>());
|
||||
}
|
||||
|
||||
zoneLoader.AddLoadingStep(step::CreateStepAddProcessor(std::move(xChunkProcessor)));
|
||||
|
||||
// If there is encryption, the signed data of the zone is the final hash blocks provided by the Salsa20 IV adaption algorithm
|
||||
@@ -187,10 +206,10 @@ namespace
|
||||
|
||||
std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const
|
||||
{
|
||||
bool isBigEndian, isSecure, isOfficial, isEncrypted;
|
||||
bool isBigEndian, isSecure, isOfficial, isEncrypted, isLzxCompressed;
|
||||
|
||||
// Check if this file is a supported T6 zone.
|
||||
if (!CanLoad(header, isBigEndian, isSecure, isOfficial, isEncrypted))
|
||||
if (!CanLoad(header, isBigEndian, isSecure, isOfficial, isEncrypted, isLzxCompressed))
|
||||
return nullptr;
|
||||
|
||||
// Create new zone
|
||||
@@ -211,7 +230,7 @@ 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(isBigEndian, isEncrypted, *zoneLoader, fileName);
|
||||
ICapturedDataProvider* signatureDataProvider = AddXChunkProcessor(isBigEndian, isEncrypted, isLzxCompressed, *zoneLoader, fileName);
|
||||
|
||||
if (!isBigEndian)
|
||||
{
|
||||
|
@@ -231,7 +231,7 @@ namespace
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_endianness == GameEndianness::LITTLE_ENDIAN)
|
||||
if (m_endianness == GameEndianness::LE)
|
||||
chunkSize = endianness::FromLittleEndian(chunkSize);
|
||||
else
|
||||
chunkSize = endianness::FromBigEndian(chunkSize);
|
||||
|
@@ -49,9 +49,9 @@ namespace
|
||||
if (isSecure)
|
||||
{
|
||||
if (isOfficial)
|
||||
memcpy(header.m_magic, ZoneConstants::MAGIC_SIGNED_PC_TREYARCH, sizeof(ZoneHeader::m_magic));
|
||||
memcpy(header.m_magic, ZoneConstants::MAGIC_SIGNED_TREYARCH, sizeof(ZoneHeader::m_magic));
|
||||
else
|
||||
memcpy(header.m_magic, ZoneConstants::MAGIC_SIGNED_PC_OAT, sizeof(ZoneHeader::m_magic));
|
||||
memcpy(header.m_magic, ZoneConstants::MAGIC_SIGNED_OAT, sizeof(ZoneHeader::m_magic));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user