mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
Use unique_ptr for ZoneLoading
This commit is contained in:
parent
94230cefb0
commit
301f6e3e7a
@ -3,16 +3,7 @@
|
|||||||
ZoneMemory::ZoneMemory()
|
ZoneMemory::ZoneMemory()
|
||||||
= default;
|
= default;
|
||||||
|
|
||||||
ZoneMemory::~ZoneMemory()
|
void ZoneMemory::AddBlock(std::unique_ptr<XBlock> block)
|
||||||
{
|
{
|
||||||
for (auto block : m_blocks)
|
m_blocks.emplace_back(std::move(block));
|
||||||
{
|
|
||||||
delete block;
|
|
||||||
}
|
|
||||||
m_blocks.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ZoneMemory::AddBlock(XBlock* block)
|
|
||||||
{
|
|
||||||
m_blocks.push_back(block);
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "Utils/MemoryManager.h"
|
#include "Utils/MemoryManager.h"
|
||||||
#include "Zone/XBlock.h"
|
#include "Zone/XBlock.h"
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class ZoneMemory : public MemoryManager
|
class ZoneMemory : public MemoryManager
|
||||||
{
|
{
|
||||||
std::vector<XBlock*> m_blocks;
|
std::vector<std::unique_ptr<XBlock>> m_blocks;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ZoneMemory();
|
ZoneMemory();
|
||||||
~ZoneMemory() override;
|
|
||||||
|
|
||||||
void AddBlock(XBlock* block);
|
void AddBlock(std::unique_ptr<XBlock> block);
|
||||||
};
|
};
|
||||||
|
@ -76,7 +76,7 @@ const size_t ZoneLoaderFactory::AUTHED_CHUNK_SIZE = 0x2000;
|
|||||||
const size_t ZoneLoaderFactory::AUTHED_CHUNK_COUNT_PER_GROUP = 256;
|
const size_t ZoneLoaderFactory::AUTHED_CHUNK_COUNT_PER_GROUP = 256;
|
||||||
|
|
||||||
const int ZoneLoaderFactory::OFFSET_BLOCK_BIT_COUNT = 4;
|
const int ZoneLoaderFactory::OFFSET_BLOCK_BIT_COUNT = 4;
|
||||||
const block_t ZoneLoaderFactory::INSERT_BLOCK = IW4::XFILE_BLOCK_VIRTUAL;
|
const block_t ZoneLoaderFactory::INSERT_BLOCK = XFILE_BLOCK_VIRTUAL;
|
||||||
|
|
||||||
class ZoneLoaderFactory::Impl
|
class ZoneLoaderFactory::Impl
|
||||||
{
|
{
|
||||||
@ -114,7 +114,7 @@ class ZoneLoaderFactory::Impl
|
|||||||
|
|
||||||
static void SetupBlock(ZoneLoader* zoneLoader)
|
static void SetupBlock(ZoneLoader* zoneLoader)
|
||||||
{
|
{
|
||||||
#define XBLOCK_DEF(name, type) new XBlock(STR(name), name, type)
|
#define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type)
|
||||||
|
|
||||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW4::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
|
zoneLoader->AddXBlock(XBLOCK_DEF(IW4::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
|
||||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW4::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL));
|
zoneLoader->AddXBlock(XBLOCK_DEF(IW4::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||||
@ -164,35 +164,39 @@ class ZoneLoaderFactory::Impl
|
|||||||
// If file is signed setup a RSA instance.
|
// If file is signed setup a RSA instance.
|
||||||
IPublicKeyAlgorithm* rsa = SetupRSA(isOfficial);
|
IPublicKeyAlgorithm* rsa = SetupRSA(isOfficial);
|
||||||
|
|
||||||
zoneLoader->AddLoadingStep(new StepVerifyMagic(MAGIC_AUTH_HEADER.c_str()));
|
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyMagic>(MAGIC_AUTH_HEADER.c_str()));
|
||||||
zoneLoader->AddLoadingStep(new StepSkipBytes(4)); // Skip reserved
|
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
||||||
|
|
||||||
auto* subheaderHash = new StepLoadHash(sizeof IW4::DB_AuthHash::bytes, 1);
|
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof DB_AuthHash::bytes, 1);
|
||||||
zoneLoader->AddLoadingStep(subheaderHash);
|
auto* subHeaderHashPtr = subHeaderHash.get();
|
||||||
|
zoneLoader->AddLoadingStep(std::move(subHeaderHash));
|
||||||
|
|
||||||
auto* subheaderHashSignature = new StepLoadSignature(sizeof IW4::DB_AuthSignature::bytes);
|
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof DB_AuthSignature::bytes);
|
||||||
zoneLoader->AddLoadingStep(subheaderHashSignature);
|
auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get();
|
||||||
|
zoneLoader->AddLoadingStep(std::move(subHeaderHashSignature));
|
||||||
|
|
||||||
zoneLoader->AddLoadingStep(new StepVerifySignature(rsa, subheaderHashSignature, subheaderHash));
|
zoneLoader->AddLoadingStep(std::make_unique<StepVerifySignature>(rsa, subHeaderHashSignaturePtr, subHeaderHashPtr));
|
||||||
|
|
||||||
auto* subHeaderCapture = new ProcessorCaptureData(sizeof(IW4::DB_AuthSubHeader));
|
auto subHeaderCapture = std::make_unique<ProcessorCaptureData>(sizeof(DB_AuthSubHeader));
|
||||||
zoneLoader->AddLoadingStep(new StepAddProcessor(subHeaderCapture));
|
auto* subHeaderCapturePtr = subHeaderCapture.get();
|
||||||
|
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::move(subHeaderCapture)));
|
||||||
|
|
||||||
zoneLoader->AddLoadingStep(new StepVerifyFileName(fileName, sizeof IW4::DB_AuthSubHeader::fastfileName));
|
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
|
||||||
zoneLoader->AddLoadingStep(new StepSkipBytes(4)); // Skip reserved
|
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
||||||
auto* masterBlockHashes = new StepLoadHash(sizeof IW4::DB_AuthHash::bytes, std::extent<decltype(IW4::DB_AuthSubHeader::masterBlockHashes)>::value);
|
|
||||||
zoneLoader->AddLoadingStep(masterBlockHashes);
|
|
||||||
|
|
||||||
zoneLoader->AddLoadingStep(new StepRemoveProcessor(subHeaderCapture));
|
auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof DB_AuthHash::bytes, std::extent<decltype(DB_AuthSubHeader::masterBlockHashes)>::value);
|
||||||
zoneLoader->AddLoadingStep(new StepVerifyHash(std::unique_ptr<IHashFunction>(Crypto::CreateSHA256()), 0,
|
auto* masterBlockHashesPtr = masterBlockHashes.get();
|
||||||
subheaderHash, subHeaderCapture));
|
zoneLoader->AddLoadingStep(std::move(masterBlockHashes));
|
||||||
|
|
||||||
|
zoneLoader->AddLoadingStep(std::make_unique<StepRemoveProcessor>(subHeaderCapturePtr));
|
||||||
|
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyHash>(std::unique_ptr<IHashFunction>(Crypto::CreateSHA256()), 0, subHeaderHashPtr, subHeaderCapturePtr));
|
||||||
|
|
||||||
// Skip the rest of the first chunk
|
// Skip the rest of the first chunk
|
||||||
zoneLoader->AddLoadingStep(new StepSkipBytes(AUTHED_CHUNK_SIZE - sizeof(IW4::DB_AuthHeader)));
|
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader)));
|
||||||
|
|
||||||
zoneLoader->AddLoadingStep(new StepAddProcessor(new ProcessorAuthedBlocks(
|
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::make_unique<ProcessorAuthedBlocks>(
|
||||||
AUTHED_CHUNK_COUNT_PER_GROUP, AUTHED_CHUNK_SIZE, std::extent<decltype(IW4::DB_AuthSubHeader::masterBlockHashes)>::value,
|
AUTHED_CHUNK_COUNT_PER_GROUP, AUTHED_CHUNK_SIZE, std::extent<decltype(DB_AuthSubHeader::masterBlockHashes)>::value,
|
||||||
std::unique_ptr<IHashFunction>(Crypto::CreateSHA256()), masterBlockHashes)));
|
std::unique_ptr<IHashFunction>(Crypto::CreateSHA256()), masterBlockHashesPtr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -216,24 +220,23 @@ public:
|
|||||||
SetupBlock(zoneLoader);
|
SetupBlock(zoneLoader);
|
||||||
|
|
||||||
// Skip unknown 1 byte field that the game ignores as well
|
// Skip unknown 1 byte field that the game ignores as well
|
||||||
zoneLoader->AddLoadingStep(new StepSkipBytes(1));
|
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(1));
|
||||||
|
|
||||||
// Skip timestamp
|
// Skip timestamp
|
||||||
zoneLoader->AddLoadingStep(new StepSkipBytes(8));
|
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8));
|
||||||
|
|
||||||
// Add steps for loading the auth header which also contain the signature of the zone if it is signed.
|
// Add steps for loading the auth header which also contain the signature of the zone if it is signed.
|
||||||
AddAuthHeaderSteps(isSecure, isOfficial, zoneLoader, fileName);
|
AddAuthHeaderSteps(isSecure, isOfficial, zoneLoader, fileName);
|
||||||
|
|
||||||
zoneLoader->AddLoadingStep(new StepAddProcessor(new ProcessorInflate(AUTHED_CHUNK_SIZE)));
|
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::make_unique<ProcessorInflate>(AUTHED_CHUNK_SIZE)));
|
||||||
|
|
||||||
// Start of the XFile struct
|
// Start of the XFile struct
|
||||||
zoneLoader->AddLoadingStep(new StepSkipBytes(8));
|
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8));
|
||||||
// Skip size and externalSize fields since they are not interesting for us
|
// Skip size and externalSize fields since they are not interesting for us
|
||||||
zoneLoader->AddLoadingStep(new StepAllocXBlocks());
|
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>());
|
||||||
|
|
||||||
// Start of the zone content
|
// Start of the zone content
|
||||||
zoneLoader->AddLoadingStep(
|
zoneLoader->AddLoadingStep(std::make_unique<StepLoadZoneContent>(std::make_unique<ContentLoader>(), zone, OFFSET_BLOCK_BIT_COUNT, INSERT_BLOCK));
|
||||||
new StepLoadZoneContent(new ContentLoader(), zone, OFFSET_BLOCK_BIT_COUNT, INSERT_BLOCK));
|
|
||||||
|
|
||||||
// Return the fully setup zoneloader
|
// Return the fully setup zoneloader
|
||||||
return zoneLoader;
|
return zoneLoader;
|
||||||
|
@ -151,7 +151,7 @@ class ZoneLoaderFactory::Impl
|
|||||||
|
|
||||||
static void SetupBlock(ZoneLoader* zoneLoader)
|
static void SetupBlock(ZoneLoader* zoneLoader)
|
||||||
{
|
{
|
||||||
#define XBLOCK_DEF(name, type) new XBlock(STR(name), name, type)
|
#define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type)
|
||||||
|
|
||||||
zoneLoader->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
|
zoneLoader->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
|
||||||
zoneLoader->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_RUNTIME_VIRTUAL, XBlock::Type::BLOCK_TYPE_RUNTIME));
|
zoneLoader->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_RUNTIME_VIRTUAL, XBlock::Type::BLOCK_TYPE_RUNTIME));
|
||||||
@ -196,32 +196,33 @@ class ZoneLoaderFactory::Impl
|
|||||||
if(!isSecure)
|
if(!isSecure)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
zoneLoader->AddLoadingStep(new StepVerifyMagic(MAGIC_AUTH_HEADER.c_str()));
|
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyMagic>(MAGIC_AUTH_HEADER.c_str()));
|
||||||
zoneLoader->AddLoadingStep(new StepSkipBytes(4)); // Loading Flags which are always zero
|
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Loading Flags which are always zero
|
||||||
zoneLoader->AddLoadingStep(new StepVerifyFileName(fileName, 32));
|
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, 32));
|
||||||
|
|
||||||
auto* signatureLoadStep = new StepLoadSignature(256);
|
auto signatureLoadStep = std::make_unique<StepLoadSignature>(256);
|
||||||
zoneLoader->AddLoadingStep(signatureLoadStep);
|
auto* signatureLoadStepPtr = signatureLoadStep.get();
|
||||||
|
zoneLoader->AddLoadingStep(std::move(signatureLoadStep));
|
||||||
|
|
||||||
return signatureLoadStep;
|
return signatureLoadStepPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ICapturedDataProvider* AddXChunkProcessor(bool isEncrypted, ZoneLoader* zoneLoader, std::string& fileName)
|
static ICapturedDataProvider* AddXChunkProcessor(bool isEncrypted, ZoneLoader* zoneLoader, std::string& fileName)
|
||||||
{
|
{
|
||||||
ICapturedDataProvider* result = nullptr;
|
ICapturedDataProvider* result = nullptr;
|
||||||
auto* xChunkProcessor = new ProcessorXChunks(STREAM_COUNT, XCHUNK_SIZE, VANILLA_BUFFER_SIZE);
|
auto xChunkProcessor = std::make_unique<ProcessorXChunks>(STREAM_COUNT, XCHUNK_SIZE, VANILLA_BUFFER_SIZE);
|
||||||
|
|
||||||
if(isEncrypted)
|
if(isEncrypted)
|
||||||
{
|
{
|
||||||
// If zone is encrypted, the decryption is applied before the decompression. T6 Zones always use Salsa20.
|
// If zone is encrypted, the decryption is applied before the decompression. T6 Zones always use Salsa20.
|
||||||
auto* chunkProcessorSalsa20 = new ChunkProcessorSalsa20(STREAM_COUNT, fileName, SALSA20_KEY_TREYARCH, sizeof(SALSA20_KEY_TREYARCH));
|
auto chunkProcessorSalsa20 = std::make_unique<ChunkProcessorSalsa20>(STREAM_COUNT, fileName, SALSA20_KEY_TREYARCH, sizeof(SALSA20_KEY_TREYARCH));
|
||||||
xChunkProcessor->AddChunkProcessor(chunkProcessorSalsa20);
|
result = chunkProcessorSalsa20.get();
|
||||||
result = chunkProcessorSalsa20;
|
xChunkProcessor->AddChunkProcessor(std::move(chunkProcessorSalsa20));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decompress the chunks using zlib
|
// Decompress the chunks using zlib
|
||||||
xChunkProcessor->AddChunkProcessor(new ChunkProcessorInflate());
|
xChunkProcessor->AddChunkProcessor(std::make_unique<ChunkProcessorInflate>());
|
||||||
zoneLoader->AddLoadingStep(new StepAddProcessor(xChunkProcessor));
|
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(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
|
// If there is encryption, the signed data of the zone is the final hash blocks provided by the Salsa20 IV adaption algorithm
|
||||||
return result;
|
return result;
|
||||||
@ -258,15 +259,15 @@ public:
|
|||||||
ICapturedDataProvider* signatureDataProvider = AddXChunkProcessor(isEncrypted, zoneLoader, fileName);
|
ICapturedDataProvider* signatureDataProvider = AddXChunkProcessor(isEncrypted, zoneLoader, fileName);
|
||||||
|
|
||||||
// Start of the XFile struct
|
// Start of the XFile struct
|
||||||
zoneLoader->AddLoadingStep(new StepSkipBytes(8)); // Skip size and externalSize fields since they are not interesting for us
|
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8)); // Skip size and externalSize fields since they are not interesting for us
|
||||||
zoneLoader->AddLoadingStep(new StepAllocXBlocks());
|
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>());
|
||||||
|
|
||||||
// Start of the zone content
|
// Start of the zone content
|
||||||
zoneLoader->AddLoadingStep(new StepLoadZoneContent(new ContentLoader(), zone, OFFSET_BLOCK_BIT_COUNT, INSERT_BLOCK));
|
zoneLoader->AddLoadingStep(std::make_unique<StepLoadZoneContent>(std::make_unique<ContentLoader>(), zone, OFFSET_BLOCK_BIT_COUNT, INSERT_BLOCK));
|
||||||
|
|
||||||
if(isSecure)
|
if(isSecure)
|
||||||
{
|
{
|
||||||
zoneLoader->AddLoadingStep(new StepVerifySignature(rsa, signatureProvider, signatureDataProvider));
|
zoneLoader->AddLoadingStep(std::make_unique<StepVerifySignature>(rsa, signatureProvider, signatureDataProvider));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the fully setup zoneloader
|
// Return the fully setup zoneloader
|
||||||
|
@ -6,7 +6,12 @@
|
|||||||
class IZoneLoaderFactory
|
class IZoneLoaderFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
IZoneLoaderFactory() = default;
|
||||||
virtual ~IZoneLoaderFactory() = default;
|
virtual ~IZoneLoaderFactory() = default;
|
||||||
|
IZoneLoaderFactory(const IZoneLoaderFactory& other) = default;
|
||||||
|
IZoneLoaderFactory(IZoneLoaderFactory&& other) noexcept = default;
|
||||||
|
IZoneLoaderFactory& operator=(const IZoneLoaderFactory& other) = default;
|
||||||
|
IZoneLoaderFactory& operator=(IZoneLoaderFactory&& other) noexcept = default;
|
||||||
|
|
||||||
virtual ZoneLoader* CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) = 0;
|
virtual ZoneLoader* CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) = 0;
|
||||||
};
|
};
|
@ -26,7 +26,7 @@ class DBLoadStream
|
|||||||
std::condition_variable m_loading_finished;
|
std::condition_variable m_loading_finished;
|
||||||
std::thread m_load_thread;
|
std::thread m_load_thread;
|
||||||
|
|
||||||
std::vector<IXChunkProcessor*>& m_processors;
|
std::vector<std::unique_ptr<IXChunkProcessor>>& m_processors;
|
||||||
|
|
||||||
void Load()
|
void Load()
|
||||||
{
|
{
|
||||||
@ -34,7 +34,7 @@ class DBLoadStream
|
|||||||
|
|
||||||
bool firstProcessor = true;
|
bool firstProcessor = true;
|
||||||
|
|
||||||
for (auto processor : m_processors)
|
for (const auto& processor : m_processors)
|
||||||
{
|
{
|
||||||
if (!firstProcessor)
|
if (!firstProcessor)
|
||||||
{
|
{
|
||||||
@ -57,7 +57,7 @@ class DBLoadStream
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
DBLoadStream(const int streamIndex, const size_t chunkSize,
|
DBLoadStream(const int streamIndex, const size_t chunkSize,
|
||||||
std::vector<IXChunkProcessor*>& chunkProcessors) : m_processors(chunkProcessors)
|
std::vector<std::unique_ptr<IXChunkProcessor>>& chunkProcessors) : m_processors(chunkProcessors)
|
||||||
{
|
{
|
||||||
m_index = streamIndex;
|
m_index = streamIndex;
|
||||||
m_chunk_size = chunkSize;
|
m_chunk_size = chunkSize;
|
||||||
@ -127,10 +127,10 @@ class ProcessorXChunks::ProcessorXChunksImpl
|
|||||||
{
|
{
|
||||||
ProcessorXChunks* m_base;
|
ProcessorXChunks* m_base;
|
||||||
|
|
||||||
std::vector<DBLoadStream*> m_streams;
|
std::vector<std::unique_ptr<DBLoadStream>> m_streams;
|
||||||
size_t m_chunk_size;
|
size_t m_chunk_size;
|
||||||
size_t m_vanilla_buffer_size;
|
size_t m_vanilla_buffer_size;
|
||||||
std::vector<IXChunkProcessor*> m_chunk_processors;
|
std::vector<std::unique_ptr<IXChunkProcessor>> m_chunk_processors;
|
||||||
|
|
||||||
bool m_initialized_streams;
|
bool m_initialized_streams;
|
||||||
unsigned int m_current_stream;
|
unsigned int m_current_stream;
|
||||||
@ -175,7 +175,7 @@ class ProcessorXChunks::ProcessorXChunksImpl
|
|||||||
throw InvalidChunkSizeException(chunkSize, m_chunk_size);
|
throw InvalidChunkSizeException(chunkSize, m_chunk_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* stream = m_streams[streamNum];
|
const auto& stream = m_streams[streamNum];
|
||||||
const size_t loadedChunkSize = m_base->m_base_stream->Load(stream->GetInputBuffer(), chunkSize);
|
const size_t loadedChunkSize = m_base->m_base_stream->Load(stream->GetInputBuffer(), chunkSize);
|
||||||
|
|
||||||
if (loadedChunkSize != chunkSize)
|
if (loadedChunkSize != chunkSize)
|
||||||
@ -232,7 +232,7 @@ public:
|
|||||||
|
|
||||||
for (int streamIndex = 0; streamIndex < numStreams; streamIndex++)
|
for (int streamIndex = 0; streamIndex < numStreams; streamIndex++)
|
||||||
{
|
{
|
||||||
m_streams.push_back(new DBLoadStream(streamIndex, xChunkSize, m_chunk_processors));
|
m_streams.emplace_back(std::make_unique<DBLoadStream>(streamIndex, xChunkSize, m_chunk_processors));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_chunk_size = xChunkSize;
|
m_chunk_size = xChunkSize;
|
||||||
@ -255,26 +255,11 @@ public:
|
|||||||
m_vanilla_buffer_size = vanillaBufferSize;
|
m_vanilla_buffer_size = vanillaBufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
~ProcessorXChunksImpl()
|
void AddChunkProcessor(std::unique_ptr<IXChunkProcessor> streamProcessor)
|
||||||
{
|
|
||||||
for (auto* stream : m_streams)
|
|
||||||
{
|
|
||||||
delete stream;
|
|
||||||
}
|
|
||||||
m_streams.clear();
|
|
||||||
|
|
||||||
for (auto* processor : m_chunk_processors)
|
|
||||||
{
|
|
||||||
delete processor;
|
|
||||||
}
|
|
||||||
m_chunk_processors.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddChunkProcessor(IXChunkProcessor* streamProcessor)
|
|
||||||
{
|
{
|
||||||
assert(streamProcessor != nullptr);
|
assert(streamProcessor != nullptr);
|
||||||
|
|
||||||
m_chunk_processors.push_back(streamProcessor);
|
m_chunk_processors.emplace_back(std::move(streamProcessor));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Load(void* buffer, const size_t length)
|
size_t Load(void* buffer, const size_t length)
|
||||||
@ -339,9 +324,9 @@ ProcessorXChunks::~ProcessorXChunks()
|
|||||||
m_impl = nullptr;
|
m_impl = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessorXChunks::AddChunkProcessor(IXChunkProcessor* chunkProcessor) const
|
void ProcessorXChunks::AddChunkProcessor(std::unique_ptr<IXChunkProcessor> chunkProcessor) const
|
||||||
{
|
{
|
||||||
m_impl->AddChunkProcessor(chunkProcessor);
|
m_impl->AddChunkProcessor(std::move(chunkProcessor));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ProcessorXChunks::Load(void* buffer, const size_t length)
|
size_t ProcessorXChunks::Load(void* buffer, const size_t length)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "Loading/StreamProcessor.h"
|
#include "Loading/StreamProcessor.h"
|
||||||
#include "XChunks/IXChunkProcessor.h"
|
#include "XChunks/IXChunkProcessor.h"
|
||||||
|
|
||||||
@ -15,5 +17,5 @@ public:
|
|||||||
size_t Load(void* buffer, size_t length) override;
|
size_t Load(void* buffer, size_t length) override;
|
||||||
int64_t Pos() override;
|
int64_t Pos() override;
|
||||||
|
|
||||||
void AddChunkProcessor(IXChunkProcessor* chunkProcessor) const;
|
void AddChunkProcessor(std::unique_ptr<IXChunkProcessor> chunkProcessor) const;
|
||||||
};
|
};
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
#include "StepAddProcessor.h"
|
#include "StepAddProcessor.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
StepAddProcessor::StepAddProcessor(StreamProcessor* streamProcessor)
|
StepAddProcessor::StepAddProcessor(std::unique_ptr<StreamProcessor> streamProcessor)
|
||||||
|
: m_stream_processor(std::move(streamProcessor))
|
||||||
{
|
{
|
||||||
m_stream_processor = streamProcessor;
|
|
||||||
}
|
|
||||||
|
|
||||||
StepAddProcessor::~StepAddProcessor()
|
|
||||||
{
|
|
||||||
delete m_stream_processor;
|
|
||||||
m_stream_processor = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StepAddProcessor::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
void StepAddProcessor::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||||
@ -17,6 +11,6 @@ void StepAddProcessor::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* strea
|
|||||||
assert(zoneLoader != nullptr);
|
assert(zoneLoader != nullptr);
|
||||||
assert(m_stream_processor != nullptr);
|
assert(m_stream_processor != nullptr);
|
||||||
|
|
||||||
zoneLoader->AddStreamProcessor(m_stream_processor);
|
zoneLoader->AddStreamProcessor(std::move(m_stream_processor));
|
||||||
m_stream_processor = nullptr;
|
m_stream_processor = nullptr;
|
||||||
}
|
}
|
@ -1,14 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "Loading/ILoadingStep.h"
|
#include "Loading/ILoadingStep.h"
|
||||||
|
|
||||||
class StepAddProcessor final : public ILoadingStep
|
class StepAddProcessor final : public ILoadingStep
|
||||||
{
|
{
|
||||||
StreamProcessor* m_stream_processor;
|
std::unique_ptr<StreamProcessor> m_stream_processor;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit StepAddProcessor(StreamProcessor* streamProcessor);
|
explicit StepAddProcessor(std::unique_ptr<StreamProcessor> streamProcessor);
|
||||||
~StepAddProcessor() override;
|
|
||||||
|
|
||||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||||
};
|
};
|
||||||
|
@ -2,18 +2,12 @@
|
|||||||
#include "Zone/Stream/Impl/XBlockInputStream.h"
|
#include "Zone/Stream/Impl/XBlockInputStream.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
StepLoadZoneContent::StepLoadZoneContent(IContentLoadingEntryPoint* entryPoint, Zone* zone, const int offsetBlockBitCount, const block_t insertBlock)
|
StepLoadZoneContent::StepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint, Zone* zone, const int offsetBlockBitCount, const block_t insertBlock)
|
||||||
|
: m_content_loader(std::move(entryPoint)),
|
||||||
|
m_zone(zone),
|
||||||
|
m_offset_block_bit_count(offsetBlockBitCount),
|
||||||
|
m_insert_block(insertBlock)
|
||||||
{
|
{
|
||||||
m_content_loader = entryPoint;
|
|
||||||
m_zone = zone;
|
|
||||||
m_offset_block_bit_count = offsetBlockBitCount;
|
|
||||||
m_insert_block = insertBlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
StepLoadZoneContent::~StepLoadZoneContent()
|
|
||||||
{
|
|
||||||
delete m_content_loader;
|
|
||||||
m_content_loader = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StepLoadZoneContent::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
void StepLoadZoneContent::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||||
@ -23,4 +17,4 @@ void StepLoadZoneContent::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* st
|
|||||||
m_content_loader->Load(m_zone, inputStream);
|
m_content_loader->Load(m_zone, inputStream);
|
||||||
|
|
||||||
delete inputStream;
|
delete inputStream;
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "Loading/ILoadingStep.h"
|
#include "Loading/ILoadingStep.h"
|
||||||
#include "Loading/IContentLoadingEntryPoint.h"
|
#include "Loading/IContentLoadingEntryPoint.h"
|
||||||
|
|
||||||
class StepLoadZoneContent final : public ILoadingStep
|
class StepLoadZoneContent final : public ILoadingStep
|
||||||
{
|
{
|
||||||
IContentLoadingEntryPoint* m_content_loader;
|
std::unique_ptr<IContentLoadingEntryPoint> m_content_loader;
|
||||||
Zone* m_zone;
|
Zone* m_zone;
|
||||||
int m_offset_block_bit_count;
|
int m_offset_block_bit_count;
|
||||||
block_t m_insert_block;
|
block_t m_insert_block;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StepLoadZoneContent(IContentLoadingEntryPoint* entryPoint, Zone* zone, int offsetBlockBitCount, block_t insertBlock);
|
StepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint, Zone* zone, int offsetBlockBitCount, block_t insertBlock);
|
||||||
~StepLoadZoneContent();
|
|
||||||
|
|
||||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||||
};
|
};
|
||||||
|
@ -10,67 +10,54 @@ ZoneLoader::ZoneLoader(Zone* zone)
|
|||||||
m_processor_chain_dirty = false;
|
m_processor_chain_dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoneLoader::~ZoneLoader()
|
|
||||||
{
|
|
||||||
for(auto* step : m_steps)
|
|
||||||
{
|
|
||||||
delete step;
|
|
||||||
}
|
|
||||||
m_steps.clear();
|
|
||||||
|
|
||||||
for(auto* processor : m_processors)
|
|
||||||
{
|
|
||||||
delete processor;
|
|
||||||
}
|
|
||||||
m_processors.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
ILoadingStream* ZoneLoader::BuildLoadingChain(ILoadingStream* rootStream)
|
ILoadingStream* ZoneLoader::BuildLoadingChain(ILoadingStream* rootStream)
|
||||||
{
|
{
|
||||||
auto* currentStream = rootStream;
|
auto* currentStream = rootStream;
|
||||||
|
|
||||||
for(auto* processor : m_processors)
|
for(const auto& processor : m_processors)
|
||||||
{
|
{
|
||||||
processor->SetBaseStream(currentStream);
|
processor->SetBaseStream(currentStream);
|
||||||
|
|
||||||
currentStream = processor;
|
currentStream = processor.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_processor_chain_dirty = false;
|
m_processor_chain_dirty = false;
|
||||||
return currentStream;
|
return currentStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneLoader::AddXBlock(XBlock* block)
|
void ZoneLoader::AddXBlock(std::unique_ptr<XBlock> block)
|
||||||
{
|
{
|
||||||
m_blocks.push_back(block);
|
m_blocks.push_back(block.get());
|
||||||
|
|
||||||
std::sort(m_blocks.begin(), m_blocks.end(), [](XBlock* b1, XBlock* b2) -> bool
|
std::sort(m_blocks.begin(), m_blocks.end(), [](XBlock* b1, XBlock* b2) -> bool
|
||||||
{
|
{
|
||||||
return b1->m_index < b2->m_index;
|
return b1->m_index < b2->m_index;
|
||||||
});
|
});
|
||||||
|
|
||||||
m_zone->GetMemory()->AddBlock(block);
|
m_zone->GetMemory()->AddBlock(std::move(block));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneLoader::AddLoadingStep(ILoadingStep* step)
|
void ZoneLoader::AddLoadingStep(std::unique_ptr<ILoadingStep> step)
|
||||||
{
|
{
|
||||||
m_steps.push_back(step);
|
m_steps.emplace_back(std::move(step));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneLoader::AddStreamProcessor(StreamProcessor* streamProcessor)
|
void ZoneLoader::AddStreamProcessor(std::unique_ptr<StreamProcessor> streamProcessor)
|
||||||
{
|
{
|
||||||
m_processors.push_back(streamProcessor);
|
m_processors.push_back(std::move(streamProcessor));
|
||||||
m_processor_chain_dirty = true;
|
m_processor_chain_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneLoader::RemoveStreamProcessor(StreamProcessor* streamProcessor)
|
void ZoneLoader::RemoveStreamProcessor(StreamProcessor* streamProcessor)
|
||||||
{
|
{
|
||||||
const auto foundEntry = std::find(m_processors.begin(), m_processors.end(), streamProcessor);
|
for(auto i = m_processors.begin(); i < m_processors.end(); ++i)
|
||||||
|
|
||||||
if(foundEntry != m_processors.end())
|
|
||||||
{
|
{
|
||||||
m_processors.erase(foundEntry);
|
if(i->get() == streamProcessor)
|
||||||
m_processor_chain_dirty = true;
|
{
|
||||||
|
m_processors.erase(i);
|
||||||
|
m_processor_chain_dirty = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +68,7 @@ Zone* ZoneLoader::LoadZone(std::istream& stream)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for(auto* step : m_steps)
|
for(const auto& step : m_steps)
|
||||||
{
|
{
|
||||||
step->PerformStep(this, endStream);
|
step->PerformStep(this, endStream);
|
||||||
|
|
||||||
@ -93,7 +80,7 @@ Zone* ZoneLoader::LoadZone(std::istream& stream)
|
|||||||
}
|
}
|
||||||
catch (LoadingException& e)
|
catch (LoadingException& e)
|
||||||
{
|
{
|
||||||
const std::string detailedMessage = e.DetailedMessage();
|
const auto detailedMessage = e.DetailedMessage();
|
||||||
printf("Loading fastfile failed: %s\n", detailedMessage.c_str());
|
printf("Loading fastfile failed: %s\n", detailedMessage.c_str());
|
||||||
|
|
||||||
delete m_zone;
|
delete m_zone;
|
||||||
|
@ -12,8 +12,8 @@ class ILoadingStep;
|
|||||||
|
|
||||||
class ZoneLoader
|
class ZoneLoader
|
||||||
{
|
{
|
||||||
std::vector<ILoadingStep*> m_steps;
|
std::vector<std::unique_ptr<ILoadingStep>> m_steps;
|
||||||
std::vector<StreamProcessor*> m_processors;
|
std::vector<std::unique_ptr<StreamProcessor>> m_processors;
|
||||||
|
|
||||||
bool m_processor_chain_dirty;
|
bool m_processor_chain_dirty;
|
||||||
|
|
||||||
@ -25,11 +25,10 @@ public:
|
|||||||
std::vector<XBlock*> m_blocks;
|
std::vector<XBlock*> m_blocks;
|
||||||
|
|
||||||
explicit ZoneLoader(Zone* zone);
|
explicit ZoneLoader(Zone* zone);
|
||||||
~ZoneLoader();
|
|
||||||
|
|
||||||
void AddXBlock(XBlock* block);
|
void AddXBlock(std::unique_ptr<XBlock> block);
|
||||||
void AddLoadingStep(ILoadingStep* step);
|
void AddLoadingStep(std::unique_ptr<ILoadingStep> step);
|
||||||
void AddStreamProcessor(StreamProcessor* streamProcessor);
|
void AddStreamProcessor(std::unique_ptr<StreamProcessor> streamProcessor);
|
||||||
|
|
||||||
void RemoveStreamProcessor(StreamProcessor* streamProcessor);
|
void RemoveStreamProcessor(StreamProcessor* streamProcessor);
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Zone/Zone.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "Zone/Zone.h"
|
||||||
|
|
||||||
class ZoneLoading
|
class ZoneLoading
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user