diff --git a/src/ZoneCommon/Game/T6/ZoneConstantsT6.h b/src/ZoneCommon/Game/T6/ZoneConstantsT6.h index d872093f..9e057b4f 100644 --- a/src/ZoneCommon/Game/T6/ZoneConstantsT6.h +++ b/src/ZoneCommon/Game/T6/ZoneConstantsT6.h @@ -25,6 +25,7 @@ namespace T6 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 int OFFSET_BLOCK_BIT_COUNT = 3; static constexpr block_t INSERT_BLOCK = XFILE_BLOCK_VIRTUAL; diff --git a/src/ZoneWriting/Game/T6/ZoneWriterFactoryT6.cpp b/src/ZoneWriting/Game/T6/ZoneWriterFactoryT6.cpp index b44833fb..e62ecbe4 100644 --- a/src/ZoneWriting/Game/T6/ZoneWriterFactoryT6.cpp +++ b/src/ZoneWriting/Game/T6/ZoneWriterFactoryT6.cpp @@ -74,7 +74,7 @@ public: ICapturedDataProvider* AddXChunkProcessor(const bool isEncrypted) { ICapturedDataProvider* result = nullptr; - auto xChunkProcessor = std::make_unique(ZoneConstants::STREAM_COUNT, ZoneConstants::XCHUNK_SIZE, ZoneConstants::VANILLA_BUFFER_SIZE); + auto xChunkProcessor = std::make_unique(ZoneConstants::STREAM_COUNT, ZoneConstants::XCHUNK_SIZE, ZoneConstants::XCHUNK_MAX_WRITE_SIZE, ZoneConstants::VANILLA_BUFFER_SIZE); // Decompress the chunks using zlib xChunkProcessor->AddChunkProcessor(std::make_unique()); diff --git a/src/ZoneWriting/Writing/Processor/OutputProcessorXChunks.cpp b/src/ZoneWriting/Writing/Processor/OutputProcessorXChunks.cpp index f73e325e..5dd0d689 100644 --- a/src/ZoneWriting/Writing/Processor/OutputProcessorXChunks.cpp +++ b/src/ZoneWriting/Writing/Processor/OutputProcessorXChunks.cpp @@ -55,9 +55,10 @@ void OutputProcessorXChunks::WriteChunk() m_current_stream = (m_current_stream + 1) % m_stream_count; } -OutputProcessorXChunks::OutputProcessorXChunks(const int numStreams, const size_t xChunkSize) +OutputProcessorXChunks::OutputProcessorXChunks(const int numStreams, const size_t xChunkSize, const size_t xChunkWriteSize) : m_stream_count(numStreams), m_chunk_size(xChunkSize), + m_chunk_write_size(xChunkWriteSize), m_vanilla_buffer_size(0), m_initialized(false), m_current_stream(0), @@ -68,6 +69,7 @@ OutputProcessorXChunks::OutputProcessorXChunks(const int numStreams, const size_ { assert(numStreams > 0); assert(xChunkSize > 0); + assert(m_chunk_size >= m_chunk_write_size); for (auto i = 0u; i < 2u; i++) m_buffers.emplace_back(std::make_unique(xChunkSize)); @@ -76,8 +78,8 @@ OutputProcessorXChunks::OutputProcessorXChunks(const int numStreams, const size_ m_output_buffer = m_buffers[1].get(); } -OutputProcessorXChunks::OutputProcessorXChunks(const int numStreams, const size_t xChunkSize, const size_t vanillaBufferSize) - : OutputProcessorXChunks(numStreams, xChunkSize) +OutputProcessorXChunks::OutputProcessorXChunks(const int numStreams, const size_t xChunkSize, const size_t xChunkWriteSize, const size_t vanillaBufferSize) + : OutputProcessorXChunks(numStreams, xChunkSize, xChunkWriteSize) { m_vanilla_buffer_size = vanillaBufferSize; } @@ -99,11 +101,11 @@ void OutputProcessorXChunks::Write(const void* buffer, const size_t length) auto sizeRemaining = length; while (sizeRemaining > 0) { - const auto toWrite = std::min(m_chunk_size - m_input_size, sizeRemaining); + const auto toWrite = std::min(m_chunk_write_size - m_input_size, sizeRemaining); memcpy(&m_input_buffer[m_input_size], &static_cast(buffer)[length - sizeRemaining], toWrite); m_input_size += toWrite; - if (m_input_size >= m_chunk_size) + if (m_input_size >= m_chunk_write_size) WriteChunk(); sizeRemaining -= toWrite; diff --git a/src/ZoneWriting/Writing/Processor/OutputProcessorXChunks.h b/src/ZoneWriting/Writing/Processor/OutputProcessorXChunks.h index 827fecb6..83ff8715 100644 --- a/src/ZoneWriting/Writing/Processor/OutputProcessorXChunks.h +++ b/src/ZoneWriting/Writing/Processor/OutputProcessorXChunks.h @@ -13,6 +13,7 @@ class OutputProcessorXChunks final : public OutputStreamProcessor int m_stream_count; size_t m_chunk_size; + size_t m_chunk_write_size; size_t m_vanilla_buffer_size; bool m_initialized; @@ -28,8 +29,8 @@ class OutputProcessorXChunks final : public OutputStreamProcessor void WriteChunk(); public: - OutputProcessorXChunks(int numStreams, size_t xChunkSize); - OutputProcessorXChunks(int numStreams, size_t xChunkSize, size_t vanillaBufferSize); + OutputProcessorXChunks(int numStreams, size_t xChunkSize, size_t xChunkWriteSize); + OutputProcessorXChunks(int numStreams, size_t xChunkSize, size_t xChunkWriteSize, size_t vanillaBufferSize); ~OutputProcessorXChunks() override = default; OutputProcessorXChunks(const OutputProcessorXChunks& other) = delete;