mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-07-11 13:41:50 +00:00
Rename ZoneLoader and ZoneWriter components to ZoneLoading and ZoneWriting to make a difference between the executive class and the component class
This commit is contained in:
22
src/ZoneLoading/Loading/Steps/StepAddProcessor.cpp
Normal file
22
src/ZoneLoading/Loading/Steps/StepAddProcessor.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "StepAddProcessor.h"
|
||||
#include <cassert>
|
||||
|
||||
StepAddProcessor::StepAddProcessor(StreamProcessor* streamProcessor)
|
||||
{
|
||||
m_stream_processor = streamProcessor;
|
||||
}
|
||||
|
||||
StepAddProcessor::~StepAddProcessor()
|
||||
{
|
||||
delete m_stream_processor;
|
||||
m_stream_processor = nullptr;
|
||||
}
|
||||
|
||||
void StepAddProcessor::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
assert(zoneLoader != nullptr);
|
||||
assert(m_stream_processor != nullptr);
|
||||
|
||||
zoneLoader->AddStreamProcessor(m_stream_processor);
|
||||
m_stream_processor = nullptr;
|
||||
}
|
14
src/ZoneLoading/Loading/Steps/StepAddProcessor.h
Normal file
14
src/ZoneLoading/Loading/Steps/StepAddProcessor.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/ILoadingStep.h"
|
||||
|
||||
class StepAddProcessor final : public ILoadingStep
|
||||
{
|
||||
StreamProcessor* m_stream_processor;
|
||||
|
||||
public:
|
||||
explicit StepAddProcessor(StreamProcessor* streamProcessor);
|
||||
~StepAddProcessor() override;
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
};
|
30
src/ZoneLoading/Loading/Steps/StepAllocXBlocks.cpp
Normal file
30
src/ZoneLoading/Loading/Steps/StepAllocXBlocks.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include "StepAllocXBlocks.h"
|
||||
#include "Loading/Exception/InvalidXBlockSizeException.h"
|
||||
|
||||
const uint64_t StepAllocXBlocks::MAX_XBLOCK_SIZE = 0x3C000000;
|
||||
|
||||
void StepAllocXBlocks::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
const unsigned int blockCount = zoneLoader->m_blocks.size();
|
||||
|
||||
auto* blockSizes = new xblock_size_t[blockCount];
|
||||
stream->Load(blockSizes, sizeof(xblock_size_t) * blockCount);
|
||||
|
||||
uint64_t totalMemory = 0;
|
||||
for(unsigned int block = 0; block < blockCount; block++)
|
||||
{
|
||||
totalMemory += blockSizes[block];
|
||||
}
|
||||
|
||||
if(totalMemory > MAX_XBLOCK_SIZE)
|
||||
{
|
||||
throw InvalidXBlockSizeException(totalMemory, MAX_XBLOCK_SIZE);
|
||||
}
|
||||
|
||||
for(unsigned int block = 0; block < blockCount; block++)
|
||||
{
|
||||
zoneLoader->m_blocks[block]->Alloc(blockSizes[block]);
|
||||
}
|
||||
|
||||
delete[] blockSizes;
|
||||
}
|
11
src/ZoneLoading/Loading/Steps/StepAllocXBlocks.h
Normal file
11
src/ZoneLoading/Loading/Steps/StepAllocXBlocks.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/ILoadingStep.h"
|
||||
|
||||
class StepAllocXBlocks final : public ILoadingStep
|
||||
{
|
||||
static const uint64_t MAX_XBLOCK_SIZE;
|
||||
|
||||
public:
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
};
|
34
src/ZoneLoading/Loading/Steps/StepLoadSignature.cpp
Normal file
34
src/ZoneLoading/Loading/Steps/StepLoadSignature.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include "StepLoadSignature.h"
|
||||
#include "Loading/Exception/UnexpectedEndOfFileException.h"
|
||||
#include <cassert>
|
||||
|
||||
StepLoadSignature::StepLoadSignature(const size_t signatureSize)
|
||||
{
|
||||
m_signature_size = signatureSize;
|
||||
m_signature = new uint8_t[signatureSize];
|
||||
}
|
||||
|
||||
StepLoadSignature::~StepLoadSignature()
|
||||
{
|
||||
delete[] m_signature;
|
||||
m_signature = nullptr;
|
||||
}
|
||||
|
||||
void StepLoadSignature::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
assert(stream != nullptr);
|
||||
|
||||
if(stream->Load(m_signature, m_signature_size) != m_signature_size)
|
||||
throw UnexpectedEndOfFileException();
|
||||
}
|
||||
|
||||
void StepLoadSignature::GetSignature(const uint8_t** pSignature, size_t* pSize)
|
||||
{
|
||||
assert(pSignature != nullptr);
|
||||
assert(pSize != nullptr);
|
||||
|
||||
assert(m_signature != nullptr);
|
||||
|
||||
*pSignature = m_signature;
|
||||
*pSize = m_signature_size;
|
||||
}
|
17
src/ZoneLoading/Loading/Steps/StepLoadSignature.h
Normal file
17
src/ZoneLoading/Loading/Steps/StepLoadSignature.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/ILoadingStep.h"
|
||||
#include "Loading/ISignatureProvider.h"
|
||||
|
||||
class StepLoadSignature final : public ILoadingStep, public ISignatureProvider
|
||||
{
|
||||
uint8_t* m_signature;
|
||||
size_t m_signature_size;
|
||||
|
||||
public:
|
||||
explicit StepLoadSignature(size_t signatureSize);
|
||||
~StepLoadSignature() override;
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
void GetSignature(const uint8_t** pSignature, size_t* pSize) override;
|
||||
};
|
26
src/ZoneLoading/Loading/Steps/StepLoadZoneContent.cpp
Normal file
26
src/ZoneLoading/Loading/Steps/StepLoadZoneContent.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "StepLoadZoneContent.h"
|
||||
#include "Zone/Stream/Impl/XBlockInputStream.h"
|
||||
#include <cassert>
|
||||
|
||||
StepLoadZoneContent::StepLoadZoneContent(IContentLoadingEntryPoint* entryPoint, Zone* zone, const int offsetBlockBitCount, const block_t 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)
|
||||
{
|
||||
auto* inputStream = new XBlockInputStream(zoneLoader->m_blocks, stream, m_offset_block_bit_count, m_insert_block);
|
||||
|
||||
m_content_loader->Load(m_zone, inputStream);
|
||||
|
||||
delete inputStream;
|
||||
}
|
18
src/ZoneLoading/Loading/Steps/StepLoadZoneContent.h
Normal file
18
src/ZoneLoading/Loading/Steps/StepLoadZoneContent.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/ILoadingStep.h"
|
||||
#include "Loading/IContentLoadingEntryPoint.h"
|
||||
|
||||
class StepLoadZoneContent final : public ILoadingStep
|
||||
{
|
||||
IContentLoadingEntryPoint* m_content_loader;
|
||||
Zone* m_zone;
|
||||
int m_offset_block_bit_count;
|
||||
block_t m_insert_block;
|
||||
|
||||
public:
|
||||
StepLoadZoneContent(IContentLoadingEntryPoint* entryPoint, Zone* zone, int offsetBlockBitCount, block_t insertBlock);
|
||||
~StepLoadZoneContent();
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
};
|
30
src/ZoneLoading/Loading/Steps/StepSkipBytes.cpp
Normal file
30
src/ZoneLoading/Loading/Steps/StepSkipBytes.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include "StepSkipBytes.h"
|
||||
|
||||
StepSkipBytes::StepSkipBytes(const unsigned int skipCount)
|
||||
{
|
||||
m_skip_count = skipCount;
|
||||
}
|
||||
|
||||
void StepSkipBytes::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
uint8_t tempBuffer[128];
|
||||
unsigned int skippedBytes = 0;
|
||||
|
||||
while(skippedBytes < m_skip_count)
|
||||
{
|
||||
unsigned int toSkip;
|
||||
|
||||
if(m_skip_count - skippedBytes < sizeof(tempBuffer))
|
||||
{
|
||||
toSkip = m_skip_count - skippedBytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
toSkip = sizeof(tempBuffer);
|
||||
}
|
||||
|
||||
stream->Load(tempBuffer, toSkip);
|
||||
|
||||
skippedBytes += toSkip;
|
||||
}
|
||||
}
|
13
src/ZoneLoading/Loading/Steps/StepSkipBytes.h
Normal file
13
src/ZoneLoading/Loading/Steps/StepSkipBytes.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/ILoadingStep.h"
|
||||
|
||||
class StepSkipBytes final : public ILoadingStep
|
||||
{
|
||||
unsigned int m_skip_count;
|
||||
|
||||
public:
|
||||
explicit StepSkipBytes(unsigned int skipCount);
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
};
|
42
src/ZoneLoading/Loading/Steps/StepVerifyFileName.cpp
Normal file
42
src/ZoneLoading/Loading/Steps/StepVerifyFileName.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include "StepVerifyFileName.h"
|
||||
#include "Loading/Exception/InvalidFileNameException.h"
|
||||
|
||||
StepVerifyFileName::StepVerifyFileName(std::string fileName, const size_t fileNameBufferSize)
|
||||
{
|
||||
m_file_name = std::move(fileName);
|
||||
m_file_name_buffer_size = fileNameBufferSize;
|
||||
|
||||
if(m_file_name.length() > m_file_name_buffer_size)
|
||||
m_file_name.erase(m_file_name_buffer_size);
|
||||
}
|
||||
|
||||
void StepVerifyFileName::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
std::string originalFileName;
|
||||
unsigned bufferOffset = 0;
|
||||
char c;
|
||||
|
||||
for(; bufferOffset < m_file_name_buffer_size; bufferOffset++)
|
||||
{
|
||||
|
||||
stream->Load(&c, sizeof(char));
|
||||
|
||||
if(c == '\00')
|
||||
{
|
||||
bufferOffset++;
|
||||
break;
|
||||
}
|
||||
|
||||
originalFileName += c;
|
||||
}
|
||||
|
||||
// Skip the rest of the buffer which should be null bytes
|
||||
while(bufferOffset < m_file_name_buffer_size)
|
||||
{
|
||||
stream->Load(&c, sizeof(char));
|
||||
bufferOffset++;
|
||||
}
|
||||
|
||||
if(originalFileName != m_file_name)
|
||||
throw InvalidFileNameException(m_file_name, originalFileName);
|
||||
}
|
14
src/ZoneLoading/Loading/Steps/StepVerifyFileName.h
Normal file
14
src/ZoneLoading/Loading/Steps/StepVerifyFileName.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/ILoadingStep.h"
|
||||
|
||||
class StepVerifyFileName final : public ILoadingStep
|
||||
{
|
||||
std::string m_file_name;
|
||||
size_t m_file_name_buffer_size;
|
||||
|
||||
public:
|
||||
explicit StepVerifyFileName(std::string fileName, size_t fileNameBufferSize);
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
};
|
21
src/ZoneLoading/Loading/Steps/StepVerifyMagic.cpp
Normal file
21
src/ZoneLoading/Loading/Steps/StepVerifyMagic.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "StepVerifyMagic.h"
|
||||
#include "Loading/Exception/InvalidMagicException.h"
|
||||
|
||||
StepVerifyMagic::StepVerifyMagic(const char* magic)
|
||||
{
|
||||
m_magic = magic;
|
||||
}
|
||||
|
||||
void StepVerifyMagic::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
const size_t magicLength = strlen(m_magic);
|
||||
char currentCharacter;
|
||||
|
||||
for(unsigned i = 0; i < magicLength; i++)
|
||||
{
|
||||
stream->Load(¤tCharacter, sizeof(char));
|
||||
|
||||
if(currentCharacter != m_magic[i])
|
||||
throw InvalidMagicException(m_magic);
|
||||
}
|
||||
}
|
13
src/ZoneLoading/Loading/Steps/StepVerifyMagic.h
Normal file
13
src/ZoneLoading/Loading/Steps/StepVerifyMagic.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/ILoadingStep.h"
|
||||
|
||||
class StepVerifyMagic final : public ILoadingStep
|
||||
{
|
||||
const char* m_magic;
|
||||
|
||||
public:
|
||||
explicit StepVerifyMagic(const char* magic);
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
};
|
36
src/ZoneLoading/Loading/Steps/StepVerifySignature.cpp
Normal file
36
src/ZoneLoading/Loading/Steps/StepVerifySignature.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "StepVerifySignature.h"
|
||||
#include "Loading/Exception/InvalidSignatureException.h"
|
||||
#include <cassert>
|
||||
|
||||
StepVerifySignature::StepVerifySignature(IPublicKeyAlgorithm* signatureAlgorithm, ISignatureProvider* signatureProvider, ISignatureDataProvider* signatureDataProvider)
|
||||
{
|
||||
m_algorithm = signatureAlgorithm;
|
||||
m_signature_provider = signatureProvider;
|
||||
m_signature_data_provider = signatureDataProvider;
|
||||
}
|
||||
|
||||
StepVerifySignature::~StepVerifySignature()
|
||||
{
|
||||
delete m_algorithm;
|
||||
m_algorithm = nullptr;
|
||||
}
|
||||
|
||||
void StepVerifySignature::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
assert(m_algorithm != nullptr);
|
||||
assert(m_signature_provider != nullptr);
|
||||
assert(m_signature_data_provider != nullptr);
|
||||
|
||||
const uint8_t* signature;
|
||||
size_t signatureSize;
|
||||
m_signature_provider->GetSignature(&signature, &signatureSize);
|
||||
|
||||
const uint8_t* signatureData;
|
||||
size_t signatureDataSize;
|
||||
m_signature_data_provider->GetSignatureData(&signatureData, &signatureDataSize);
|
||||
|
||||
if(!m_algorithm->Verify(signatureData, signatureDataSize, signature, signatureSize))
|
||||
{
|
||||
throw InvalidSignatureException();
|
||||
}
|
||||
}
|
19
src/ZoneLoading/Loading/Steps/StepVerifySignature.h
Normal file
19
src/ZoneLoading/Loading/Steps/StepVerifySignature.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/ILoadingStep.h"
|
||||
#include "Crypto.h"
|
||||
#include "Loading/ISignatureProvider.h"
|
||||
#include "Loading/ISignatureDataProvider.h"
|
||||
|
||||
class StepVerifySignature final : public ILoadingStep
|
||||
{
|
||||
IPublicKeyAlgorithm* m_algorithm;
|
||||
ISignatureProvider* m_signature_provider;
|
||||
ISignatureDataProvider* m_signature_data_provider;
|
||||
|
||||
public:
|
||||
StepVerifySignature(IPublicKeyAlgorithm* signatureAlgorithm, ISignatureProvider* signatureProvider, ISignatureDataProvider* signatureDataProvider);
|
||||
~StepVerifySignature();
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
};
|
Reference in New Issue
Block a user