diff --git a/src/Common/Game/IGame.h b/src/Common/Game/IGame.h index d9868724..d8021ee2 100644 --- a/src/Common/Game/IGame.h +++ b/src/Common/Game/IGame.h @@ -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 diff --git a/src/ZoneCommon/Game/T6/ZoneConstantsT6.h b/src/ZoneCommon/Game/T6/ZoneConstantsT6.h index 785c3742..37ea4224 100644 --- a/src/ZoneCommon/Game/T6/ZoneConstantsT6.h +++ b/src/ZoneCommon/Game/T6/ZoneConstantsT6.h @@ -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::length(MAGIC_SIGNED_PC_TREYARCH) == sizeof(ZoneHeader::m_magic)); - static_assert(std::char_traits::length(MAGIC_SIGNED_XENON_TREYARCH) == sizeof(ZoneHeader::m_magic)); - static_assert(std::char_traits::length(MAGIC_SIGNED_PC_OAT) == sizeof(ZoneHeader::m_magic)); + static_assert(std::char_traits::length(MAGIC_SIGNED_TREYARCH) == sizeof(ZoneHeader::m_magic)); + static_assert(std::char_traits::length(MAGIC_SIGNED_LZX_TREYARCH) == sizeof(ZoneHeader::m_magic)); + static_assert(std::char_traits::length(MAGIC_SIGNED_OAT) == sizeof(ZoneHeader::m_magic)); static_assert(std::char_traits::length(MAGIC_UNSIGNED) == sizeof(ZoneHeader::m_magic)); static_assert(std::char_traits::length(MAGIC_UNSIGNED_SERVER) == sizeof(ZoneHeader::m_magic)); diff --git a/src/ZoneCommon/Zone/XChunk/AbstractSalsa20Processor.cpp b/src/ZoneCommon/Zone/XChunk/AbstractSalsa20Processor.cpp index 63018e4c..01968187 100644 --- a/src/ZoneCommon/Zone/XChunk/AbstractSalsa20Processor.cpp +++ b/src/ZoneCommon/Zone/XChunk/AbstractSalsa20Processor.cpp @@ -1,8 +1,9 @@ #include "AbstractSalsa20Processor.h" #include +#include -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), diff --git a/src/ZoneCommon/Zone/XChunk/AbstractSalsa20Processor.h b/src/ZoneCommon/Zone/XChunk/AbstractSalsa20Processor.h index b5045c54..d4b3775d 100644 --- a/src/ZoneCommon/Zone/XChunk/AbstractSalsa20Processor.h +++ b/src/ZoneCommon/Zone/XChunk/AbstractSalsa20Processor.h @@ -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); diff --git a/src/ZoneCommon/Zone/XChunk/XChunkProcessorLzxDecompress.cpp b/src/ZoneCommon/Zone/XChunk/XChunkProcessorLzxDecompress.cpp new file mode 100644 index 00000000..512a2a53 --- /dev/null +++ b/src/ZoneCommon/Zone/XChunk/XChunkProcessorLzxDecompress.cpp @@ -0,0 +1,12 @@ +#include "XChunkProcessorLzxDecompress.h" + +#include + +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; +} diff --git a/src/ZoneCommon/Zone/XChunk/XChunkProcessorLzxDecompress.h b/src/ZoneCommon/Zone/XChunk/XChunkProcessorLzxDecompress.h new file mode 100644 index 00000000..7e79c367 --- /dev/null +++ b/src/ZoneCommon/Zone/XChunk/XChunkProcessorLzxDecompress.h @@ -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; +}; diff --git a/src/ZoneLoading/Game/T6/ZoneLoaderFactoryT6.cpp b/src/ZoneLoading/Game/T6/ZoneLoaderFactoryT6.cpp index 7c0a9718..caa9b1c2 100644 --- a/src/ZoneLoading/Game/T6/ZoneLoaderFactoryT6.cpp +++ b/src/ZoneLoading/Game/T6/ZoneLoaderFactoryT6.cpp @@ -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 @@ -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()); + if (isLzxCompressed) + { + // Decompress the chunks using lzx + xChunkProcessor->AddChunkProcessor(std::make_unique()); + } + else + { + // Decompress the chunks using zlib + xChunkProcessor->AddChunkProcessor(std::make_unique()); + } + 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 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 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) { diff --git a/src/ZoneLoading/Loading/Processor/ProcessorXChunks.cpp b/src/ZoneLoading/Loading/Processor/ProcessorXChunks.cpp index cb57c662..af4f2c51 100644 --- a/src/ZoneLoading/Loading/Processor/ProcessorXChunks.cpp +++ b/src/ZoneLoading/Loading/Processor/ProcessorXChunks.cpp @@ -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); diff --git a/src/ZoneWriting/Game/T6/ZoneWriterFactoryT6.cpp b/src/ZoneWriting/Game/T6/ZoneWriterFactoryT6.cpp index 5edf9dcf..536e08b6 100644 --- a/src/ZoneWriting/Game/T6/ZoneWriterFactoryT6.cpp +++ b/src/ZoneWriting/Game/T6/ZoneWriterFactoryT6.cpp @@ -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 {