Move XChunk processors to ZoneCommon

This commit is contained in:
Jan
2021-03-16 20:42:48 +01:00
parent ca1329323b
commit f22012d282
33 changed files with 383 additions and 317 deletions

View File

@ -8,8 +8,8 @@
#include "Game/T6/GameT6.h"
#include "Game/T6/ZoneConstantsT6.h"
#include "Writing/Processor/OutputProcessorXChunks.h"
#include "Writing/Processor/XChunks/XChunkOutputProcessorDeflate.h"
#include "Writing/Processor/XChunks/XChunkOutputProcessorSalsa20.h"
#include "Zone/XChunk/XChunkProcessorDeflate.h"
#include "Zone/XChunk/XChunkProcessorSalsa20Encryption.h"
#include "Writing/Steps/StepAddOutputProcessor.h"
#include "Writing/Steps/StepWriteXBlockSizes.h"
#include "Writing/Steps/StepWriteZoneContentToFile.h"
@ -77,14 +77,14 @@ public:
if (isEncrypted)
{
// If zone is encrypted, the decryption is applied before the decompression. T6 Zones always use Salsa20.
auto chunkProcessorSalsa20 = std::make_unique<XChunkOutputProcessorSalsa20>(ZoneConstants::STREAM_COUNT, m_zone->m_name, ZoneConstants::SALSA20_KEY_TREYARCH,
auto chunkProcessorSalsa20 = std::make_unique<XChunkProcessorSalsa20Encryption>(ZoneConstants::STREAM_COUNT, m_zone->m_name, ZoneConstants::SALSA20_KEY_TREYARCH,
sizeof(ZoneConstants::SALSA20_KEY_TREYARCH));
result = chunkProcessorSalsa20.get();
xChunkProcessor->AddChunkProcessor(std::move(chunkProcessorSalsa20));
}
// Decompress the chunks using zlib
xChunkProcessor->AddChunkProcessor(std::make_unique<XChunkOutputProcessorDeflate>());
xChunkProcessor->AddChunkProcessor(std::make_unique<XChunkProcessorDeflate>());
m_writer->AddWritingStep(std::make_unique<StepAddOutputProcessor>(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

View File

@ -32,7 +32,7 @@ OutputProcessorXChunks& OutputProcessorXChunks::operator=(OutputProcessorXChunks
return *this;
}
void OutputProcessorXChunks::AddChunkProcessor(std::unique_ptr<IXChunkOutputProcessor> chunkProcessor) const
void OutputProcessorXChunks::AddChunkProcessor(std::unique_ptr<IXChunkProcessor> chunkProcessor) const
{
}

View File

@ -2,7 +2,7 @@
#include <memory>
#include "Writing/OutputStreamProcessor.h"
#include "XChunks/IXChunkOutputProcessor.h"
#include "Zone/XChunk/IXChunkProcessor.h"
class OutputProcessorXChunks final : public OutputStreamProcessor
{
@ -19,7 +19,7 @@ public:
OutputProcessorXChunks& operator=(const OutputProcessorXChunks& other) = delete;
OutputProcessorXChunks& operator=(OutputProcessorXChunks&& other) noexcept;
void AddChunkProcessor(std::unique_ptr<IXChunkOutputProcessor> chunkProcessor) const;
void AddChunkProcessor(std::unique_ptr<IXChunkProcessor> chunkProcessor) const;
void Write(const void* buffer, size_t length) override;
int64_t Pos() override;

View File

@ -1,17 +0,0 @@
#pragma once
#include <cstdint>
#include <cstddef>
class IXChunkOutputProcessor
{
public:
IXChunkOutputProcessor() = default;
virtual ~IXChunkOutputProcessor() = default;
IXChunkOutputProcessor(const IXChunkOutputProcessor& other) = default;
IXChunkOutputProcessor(IXChunkOutputProcessor&& other) noexcept = default;
IXChunkOutputProcessor& operator=(const IXChunkOutputProcessor& other) = default;
IXChunkOutputProcessor& operator=(IXChunkOutputProcessor&& other) noexcept = default;
virtual size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) = 0;
};

View File

@ -1,8 +0,0 @@
#pragma once
#include "IXChunkOutputProcessor.h"
class XChunkOutputProcessorDeflate final : public IXChunkOutputProcessor
{
public:
size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
};

View File

@ -1,20 +0,0 @@
#pragma once
#include "IXChunkOutputProcessor.h"
#include "Utils/ICapturedDataProvider.h"
class XChunkOutputProcessorSalsa20 final : public IXChunkOutputProcessor, public ICapturedDataProvider
{
class Impl;
Impl* m_impl;
public:
XChunkOutputProcessorSalsa20(int streamCount, std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
~XChunkOutputProcessorSalsa20() override;
XChunkOutputProcessorSalsa20(const XChunkOutputProcessorSalsa20& other) = delete;
XChunkOutputProcessorSalsa20(XChunkOutputProcessorSalsa20&& other) noexcept = default;
XChunkOutputProcessorSalsa20& operator=(const XChunkOutputProcessorSalsa20& other) = delete;
XChunkOutputProcessorSalsa20& operator=(XChunkOutputProcessorSalsa20&& other) noexcept = default;
size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
void GetCapturedData(const uint8_t** pCapturedData, size_t* pSize) override;
};

View File

@ -12,5 +12,21 @@ IZoneWriterFactory* ZoneWriterFactories[]
bool ZoneWriting::WriteZone(std::ostream& stream, Zone* zone)
{
return true;
std::unique_ptr<ZoneWriter> zoneWriter;
for (auto* factory : ZoneWriterFactories)
{
if(factory->SupportsZone(zone))
{
zoneWriter = factory->CreateWriter(zone);
break;
}
}
if (zoneWriter == nullptr)
{
printf("Could not create ZoneWriter for zone '%s'.\n", zone->m_name.c_str());
return false;
}
return zoneWriter->WriteZone(stream);
}