mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-05-07 13:04:58 +00:00
refactor: fix x64 compilation for ZoneLoading
This commit is contained in:
parent
de43e33dcd
commit
3b00c1d45b
@ -14,6 +14,6 @@ typedef uint32_t xblock_size_t;
|
|||||||
|
|
||||||
constexpr uint16_t SCR_STRING_MAX = std::numeric_limits<scr_string_t>::max();
|
constexpr uint16_t SCR_STRING_MAX = std::numeric_limits<scr_string_t>::max();
|
||||||
|
|
||||||
typedef int block_t;
|
typedef unsigned block_t;
|
||||||
typedef int asset_type_t;
|
typedef unsigned asset_type_t;
|
||||||
typedef unsigned int zone_priority_t;
|
typedef unsigned int zone_priority_t;
|
||||||
|
@ -14,7 +14,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
int m_index;
|
unsigned m_index;
|
||||||
Type m_type;
|
Type m_type;
|
||||||
|
|
||||||
uint8_t* m_buffer;
|
uint8_t* m_buffer;
|
||||||
|
@ -143,7 +143,8 @@ namespace
|
|||||||
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
|
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
|
||||||
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
||||||
|
|
||||||
auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>);
|
auto masterBlockHashes =
|
||||||
|
std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>));
|
||||||
auto* masterBlockHashesPtr = masterBlockHashes.get();
|
auto* masterBlockHashesPtr = masterBlockHashes.get();
|
||||||
zoneLoader.AddLoadingStep(std::move(masterBlockHashes));
|
zoneLoader.AddLoadingStep(std::move(masterBlockHashes));
|
||||||
|
|
||||||
@ -153,12 +154,12 @@ namespace
|
|||||||
// Skip the rest of the first chunk
|
// Skip the rest of the first chunk
|
||||||
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(ZoneConstants::AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader)));
|
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(ZoneConstants::AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader)));
|
||||||
|
|
||||||
zoneLoader.AddLoadingStep(
|
zoneLoader.AddLoadingStep(std::make_unique<StepAddProcessor>(
|
||||||
std::make_unique<StepAddProcessor>(std::make_unique<ProcessorAuthedBlocks>(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP,
|
std::make_unique<ProcessorAuthedBlocks>(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP,
|
||||||
ZoneConstants::AUTHED_CHUNK_SIZE,
|
ZoneConstants::AUTHED_CHUNK_SIZE,
|
||||||
std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>,
|
static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>),
|
||||||
cryptography::CreateSha256(),
|
cryptography::CreateSha256(),
|
||||||
masterBlockHashesPtr)));
|
masterBlockHashesPtr)));
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -127,7 +127,8 @@ namespace
|
|||||||
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
|
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
|
||||||
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
||||||
|
|
||||||
auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>);
|
auto masterBlockHashes =
|
||||||
|
std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>));
|
||||||
auto* masterBlockHashesPtr = masterBlockHashes.get();
|
auto* masterBlockHashesPtr = masterBlockHashes.get();
|
||||||
zoneLoader.AddLoadingStep(std::move(masterBlockHashes));
|
zoneLoader.AddLoadingStep(std::move(masterBlockHashes));
|
||||||
|
|
||||||
@ -137,12 +138,12 @@ namespace
|
|||||||
// Skip the rest of the first chunk
|
// Skip the rest of the first chunk
|
||||||
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(ZoneConstants::AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader)));
|
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(ZoneConstants::AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader)));
|
||||||
|
|
||||||
zoneLoader.AddLoadingStep(
|
zoneLoader.AddLoadingStep(std::make_unique<StepAddProcessor>(
|
||||||
std::make_unique<StepAddProcessor>(std::make_unique<ProcessorAuthedBlocks>(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP,
|
std::make_unique<ProcessorAuthedBlocks>(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP,
|
||||||
ZoneConstants::AUTHED_CHUNK_SIZE,
|
ZoneConstants::AUTHED_CHUNK_SIZE,
|
||||||
std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>,
|
static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>),
|
||||||
cryptography::CreateSha256(),
|
cryptography::CreateSha256(),
|
||||||
masterBlockHashesPtr)));
|
masterBlockHashesPtr)));
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -50,20 +50,20 @@ public:
|
|||||||
size_t Load(void* buffer, const size_t length)
|
size_t Load(void* buffer, const size_t length)
|
||||||
{
|
{
|
||||||
m_stream.next_out = static_cast<Bytef*>(buffer);
|
m_stream.next_out = static_cast<Bytef*>(buffer);
|
||||||
m_stream.avail_out = length;
|
m_stream.avail_out = static_cast<unsigned>(length);
|
||||||
|
|
||||||
while (m_stream.avail_out > 0)
|
while (m_stream.avail_out > 0)
|
||||||
{
|
{
|
||||||
if (m_stream.avail_in == 0)
|
if (m_stream.avail_in == 0)
|
||||||
{
|
{
|
||||||
m_stream.avail_in = m_base->m_base_stream->Load(m_buffer.get(), m_buffer_size);
|
m_stream.avail_in = static_cast<unsigned>(m_base->m_base_stream->Load(m_buffer.get(), m_buffer_size));
|
||||||
m_stream.next_in = m_buffer.get();
|
m_stream.next_in = m_buffer.get();
|
||||||
|
|
||||||
if (m_stream.avail_in == 0) // EOF
|
if (m_stream.avail_in == 0) // EOF
|
||||||
return length - m_stream.avail_out;
|
return length - m_stream.avail_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ret = inflate(&m_stream, Z_SYNC_FLUSH);
|
const auto ret = inflate(&m_stream, Z_SYNC_FLUSH);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
throw InvalidCompressionException();
|
throw InvalidCompressionException();
|
||||||
|
@ -78,7 +78,7 @@ public:
|
|||||||
m_is_loading = false;
|
m_is_loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* GetInputBuffer() const
|
[[nodiscard]] uint8_t* GetInputBuffer() const
|
||||||
{
|
{
|
||||||
return m_input_buffer;
|
return m_input_buffer;
|
||||||
}
|
}
|
||||||
@ -140,9 +140,9 @@ class ProcessorXChunks::ProcessorXChunksImpl
|
|||||||
bool m_eof_reached;
|
bool m_eof_reached;
|
||||||
unsigned int m_eof_stream;
|
unsigned int m_eof_stream;
|
||||||
|
|
||||||
void AdvanceStream(const unsigned int streamNum)
|
void AdvanceStream(const unsigned streamNum)
|
||||||
{
|
{
|
||||||
assert(streamNum >= 0 && streamNum < m_streams.size());
|
assert(streamNum < m_streams.size());
|
||||||
|
|
||||||
if (m_eof_reached)
|
if (m_eof_reached)
|
||||||
return;
|
return;
|
||||||
@ -203,8 +203,8 @@ class ProcessorXChunks::ProcessorXChunksImpl
|
|||||||
m_initialized_streams = true;
|
m_initialized_streams = true;
|
||||||
m_vanilla_buffer_offset = static_cast<size_t>(m_base->m_base_stream->Pos());
|
m_vanilla_buffer_offset = static_cast<size_t>(m_base->m_base_stream->Pos());
|
||||||
|
|
||||||
const unsigned int streamCount = m_streams.size();
|
const auto streamCount = static_cast<unsigned>(m_streams.size());
|
||||||
for (unsigned int streamNum = 0; streamNum < streamCount; streamNum++)
|
for (auto streamNum = 0u; streamNum < streamCount; streamNum++)
|
||||||
{
|
{
|
||||||
AdvanceStream(streamNum);
|
AdvanceStream(streamNum);
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ class ProcessorXChunks::ProcessorXChunksImpl
|
|||||||
m_streams[0]->GetOutput(&m_current_chunk, &m_current_chunk_size);
|
m_streams[0]->GetOutput(&m_current_chunk, &m_current_chunk_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EndOfStream() const
|
[[nodiscard]] bool EndOfStream() const
|
||||||
{
|
{
|
||||||
return m_eof_reached && m_eof_stream == m_current_stream;
|
return m_eof_reached && m_eof_stream == m_current_stream;
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@ const uint64_t StepAllocXBlocks::MAX_XBLOCK_SIZE = 0x3C000000;
|
|||||||
|
|
||||||
void StepAllocXBlocks::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
void StepAllocXBlocks::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||||
{
|
{
|
||||||
const unsigned int blockCount = zoneLoader->m_blocks.size();
|
const auto blockCount = static_cast<unsigned>(zoneLoader->m_blocks.size());
|
||||||
|
|
||||||
auto* blockSizes = new xblock_size_t[blockCount];
|
const auto blockSizes = std::make_unique<xblock_size_t[]>(blockCount);
|
||||||
stream->Load(blockSizes, sizeof(xblock_size_t) * blockCount);
|
stream->Load(blockSizes.get(), sizeof(xblock_size_t) * blockCount);
|
||||||
|
|
||||||
uint64_t totalMemory = 0;
|
uint64_t totalMemory = 0;
|
||||||
for (unsigned int block = 0; block < blockCount; block++)
|
for (unsigned int block = 0; block < blockCount; block++)
|
||||||
@ -26,6 +26,4 @@ void StepAllocXBlocks::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* strea
|
|||||||
{
|
{
|
||||||
zoneLoader->m_blocks[block]->Alloc(blockSizes[block]);
|
zoneLoader->m_blocks[block]->Alloc(blockSizes[block]);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] blockSizes;
|
|
||||||
}
|
}
|
||||||
|
@ -2,21 +2,21 @@
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
StepDumpData::StepDumpData(const unsigned int dumpCount)
|
StepDumpData::StepDumpData(const size_t dumpCount)
|
||||||
|
: m_dump_count(dumpCount)
|
||||||
{
|
{
|
||||||
m_dump_count = dumpCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StepDumpData::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
void StepDumpData::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||||
{
|
{
|
||||||
uint8_t tempBuffer[128];
|
uint8_t tempBuffer[128];
|
||||||
unsigned int dumpedBytes = 0;
|
auto dumpedBytes = 0uz;
|
||||||
|
|
||||||
std::ofstream tempFile("dump.dat", std::fstream::out | std::fstream::binary);
|
std::ofstream tempFile("dump.dat", std::fstream::out | std::fstream::binary);
|
||||||
|
|
||||||
while (dumpedBytes < m_dump_count)
|
while (dumpedBytes < m_dump_count)
|
||||||
{
|
{
|
||||||
unsigned int toDump;
|
size_t toDump;
|
||||||
|
|
||||||
if (m_dump_count - dumpedBytes < sizeof(tempBuffer))
|
if (m_dump_count - dumpedBytes < sizeof(tempBuffer))
|
||||||
{
|
{
|
||||||
@ -33,7 +33,7 @@ void StepDumpData::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
|||||||
if (loadedSize == 0)
|
if (loadedSize == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
tempFile.write(reinterpret_cast<char*>(tempBuffer), loadedSize);
|
tempFile.write(reinterpret_cast<char*>(tempBuffer), static_cast<std::streamsize>(loadedSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
tempFile.close();
|
tempFile.close();
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
|
|
||||||
class StepDumpData final : public ILoadingStep
|
class StepDumpData final : public ILoadingStep
|
||||||
{
|
{
|
||||||
unsigned int m_dump_count;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit StepDumpData(unsigned int dumpCount);
|
explicit StepDumpData(size_t dumpCount);
|
||||||
|
|
||||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
size_t m_dump_count;
|
||||||
};
|
};
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
#include "StepSkipBytes.h"
|
#include "StepSkipBytes.h"
|
||||||
|
|
||||||
StepSkipBytes::StepSkipBytes(const unsigned int skipCount)
|
StepSkipBytes::StepSkipBytes(const size_t skipCount)
|
||||||
|
: m_skip_count(skipCount)
|
||||||
{
|
{
|
||||||
m_skip_count = skipCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StepSkipBytes::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
void StepSkipBytes::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||||
{
|
{
|
||||||
uint8_t tempBuffer[128];
|
uint8_t tempBuffer[128];
|
||||||
unsigned int skippedBytes = 0;
|
auto skippedBytes = 0uz;
|
||||||
|
|
||||||
while (skippedBytes < m_skip_count)
|
while (skippedBytes < m_skip_count)
|
||||||
{
|
{
|
||||||
unsigned int toSkip;
|
size_t toSkip;
|
||||||
|
|
||||||
if (m_skip_count - skippedBytes < sizeof(tempBuffer))
|
if (m_skip_count - skippedBytes < sizeof(tempBuffer))
|
||||||
{
|
{
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
|
|
||||||
class StepSkipBytes final : public ILoadingStep
|
class StepSkipBytes final : public ILoadingStep
|
||||||
{
|
{
|
||||||
unsigned int m_skip_count;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit StepSkipBytes(unsigned int skipCount);
|
explicit StepSkipBytes(size_t skipCount);
|
||||||
|
|
||||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
size_t m_skip_count;
|
||||||
};
|
};
|
||||||
|
@ -13,23 +13,16 @@ XBlockInputStream::XBlockInputStream(std::vector<XBlock*>& blocks, ILoadingStrea
|
|||||||
{
|
{
|
||||||
m_stream = stream;
|
m_stream = stream;
|
||||||
|
|
||||||
const unsigned int blockCount = blocks.size();
|
const auto blockCount = static_cast<unsigned>(blocks.size());
|
||||||
m_block_offsets = new size_t[blockCount]{0};
|
m_block_offsets = std::make_unique<size_t[]>(blockCount);
|
||||||
|
std::memset(m_block_offsets.get(), 0, sizeof(size_t) * blockCount);
|
||||||
|
|
||||||
m_block_bit_count = blockBitCount;
|
m_block_bit_count = blockBitCount;
|
||||||
|
|
||||||
assert(insertBlock >= 0 && insertBlock < static_cast<block_t>(blocks.size()));
|
assert(insertBlock < static_cast<block_t>(blocks.size()));
|
||||||
m_insert_block = blocks[insertBlock];
|
m_insert_block = blocks[insertBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
XBlockInputStream::~XBlockInputStream()
|
|
||||||
{
|
|
||||||
delete[] m_block_offsets;
|
|
||||||
m_block_offsets = nullptr;
|
|
||||||
|
|
||||||
assert(m_block_stack.empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
void XBlockInputStream::Align(const unsigned align)
|
void XBlockInputStream::Align(const unsigned align)
|
||||||
{
|
{
|
||||||
assert(!m_block_stack.empty());
|
assert(!m_block_stack.empty());
|
||||||
@ -37,13 +30,13 @@ void XBlockInputStream::Align(const unsigned align)
|
|||||||
if (align > 0)
|
if (align > 0)
|
||||||
{
|
{
|
||||||
const block_t blockIndex = m_block_stack.top()->m_index;
|
const block_t blockIndex = m_block_stack.top()->m_index;
|
||||||
m_block_offsets[blockIndex] = (m_block_offsets[blockIndex] + align - 1) / align * align;
|
m_block_offsets[blockIndex] = (m_block_offsets[blockIndex] + align - 1u) / align * align;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XBlockInputStream::PushBlock(const block_t block)
|
void XBlockInputStream::PushBlock(const block_t block)
|
||||||
{
|
{
|
||||||
assert(block >= 0 && block < static_cast<block_t>(m_blocks.size()));
|
assert(block < static_cast<block_t>(m_blocks.size()));
|
||||||
|
|
||||||
XBlock* newBlock = m_blocks[block];
|
XBlock* newBlock = m_blocks[block];
|
||||||
|
|
||||||
@ -150,7 +143,7 @@ void XBlockInputStream::IncBlockPos(const size_t size)
|
|||||||
if (m_block_stack.empty())
|
if (m_block_stack.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
XBlock* block = m_block_stack.top();
|
const XBlock* block = m_block_stack.top();
|
||||||
m_block_offsets[block->m_index] += size;
|
m_block_offsets[block->m_index] += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +165,7 @@ void XBlockInputStream::LoadNullTerminated(void* dst)
|
|||||||
assert(dst == &block->m_buffer[m_block_offsets[block->m_index]]);
|
assert(dst == &block->m_buffer[m_block_offsets[block->m_index]]);
|
||||||
|
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
size_t offset = reinterpret_cast<uint8_t*>(dst) - block->m_buffer;
|
size_t offset = static_cast<uint8_t*>(dst) - block->m_buffer;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (offset >= block->m_buffer_size)
|
if (offset >= block->m_buffer_size)
|
||||||
@ -198,7 +191,7 @@ void** XBlockInputStream::InsertPointer()
|
|||||||
throw BlockOverflowException(m_insert_block);
|
throw BlockOverflowException(m_insert_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
void** ptr = reinterpret_cast<void**>(&m_insert_block->m_buffer[m_block_offsets[m_insert_block->m_index]]);
|
auto* ptr = reinterpret_cast<void**>(&m_insert_block->m_buffer[m_block_offsets[m_insert_block->m_index]]);
|
||||||
|
|
||||||
IncBlockPos(sizeof(void*));
|
IncBlockPos(sizeof(void*));
|
||||||
|
|
||||||
@ -211,9 +204,9 @@ void* XBlockInputStream::ConvertOffsetToPointer(const void* offset)
|
|||||||
{
|
{
|
||||||
// -1 because otherwise Block 0 Offset 0 would be just 0 which is already used to signalize a nullptr.
|
// -1 because otherwise Block 0 Offset 0 would be just 0 which is already used to signalize a nullptr.
|
||||||
// So all offsets are moved by 1.
|
// So all offsets are moved by 1.
|
||||||
auto offsetInt = reinterpret_cast<uintptr_t>(offset) - 1;
|
const auto offsetInt = reinterpret_cast<uintptr_t>(offset) - 1u;
|
||||||
|
|
||||||
const block_t blockNum = offsetInt >> (sizeof(offsetInt) * 8 - m_block_bit_count);
|
const block_t blockNum = static_cast<block_t>(offsetInt >> (sizeof(offsetInt) * 8u - m_block_bit_count));
|
||||||
const size_t blockOffset = offsetInt & (UINTPTR_MAX >> m_block_bit_count);
|
const size_t blockOffset = offsetInt & (UINTPTR_MAX >> m_block_bit_count);
|
||||||
|
|
||||||
if (blockNum < 0 || blockNum >= static_cast<block_t>(m_blocks.size()))
|
if (blockNum < 0 || blockNum >= static_cast<block_t>(m_blocks.size()))
|
||||||
@ -234,9 +227,9 @@ void* XBlockInputStream::ConvertOffsetToPointer(const void* offset)
|
|||||||
void* XBlockInputStream::ConvertOffsetToAlias(const void* offset)
|
void* XBlockInputStream::ConvertOffsetToAlias(const void* offset)
|
||||||
{
|
{
|
||||||
// For details see ConvertOffsetToPointer
|
// For details see ConvertOffsetToPointer
|
||||||
auto offsetInt = reinterpret_cast<uintptr_t>(offset) - 1;
|
const auto offsetInt = reinterpret_cast<uintptr_t>(offset) - 1;
|
||||||
|
|
||||||
const block_t blockNum = offsetInt >> (sizeof(offsetInt) * 8 - m_block_bit_count);
|
const block_t blockNum = static_cast<block_t>(offsetInt >> (sizeof(offsetInt) * 8 - m_block_bit_count));
|
||||||
const size_t blockOffset = offsetInt & (UINTPTR_MAX >> m_block_bit_count);
|
const size_t blockOffset = offsetInt & (UINTPTR_MAX >> m_block_bit_count);
|
||||||
|
|
||||||
if (blockNum < 0 || blockNum >= static_cast<block_t>(m_blocks.size()))
|
if (blockNum < 0 || blockNum >= static_cast<block_t>(m_blocks.size()))
|
||||||
|
@ -4,26 +4,14 @@
|
|||||||
#include "Zone/Stream/IZoneInputStream.h"
|
#include "Zone/Stream/IZoneInputStream.h"
|
||||||
#include "Zone/XBlock.h"
|
#include "Zone/XBlock.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class XBlockInputStream final : public IZoneInputStream
|
class XBlockInputStream final : public IZoneInputStream
|
||||||
{
|
{
|
||||||
std::vector<XBlock*>& m_blocks;
|
|
||||||
size_t* m_block_offsets;
|
|
||||||
|
|
||||||
std::stack<XBlock*> m_block_stack;
|
|
||||||
std::stack<size_t> m_temp_offsets;
|
|
||||||
ILoadingStream* m_stream;
|
|
||||||
|
|
||||||
int m_block_bit_count;
|
|
||||||
XBlock* m_insert_block;
|
|
||||||
|
|
||||||
void Align(unsigned align);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
XBlockInputStream(std::vector<XBlock*>& blocks, ILoadingStream* stream, int blockBitCount, block_t insertBlock);
|
XBlockInputStream(std::vector<XBlock*>& blocks, ILoadingStream* stream, int blockBitCount, block_t insertBlock);
|
||||||
~XBlockInputStream() override;
|
|
||||||
|
|
||||||
void PushBlock(block_t block) override;
|
void PushBlock(block_t block) override;
|
||||||
block_t PopBlock() override;
|
block_t PopBlock() override;
|
||||||
@ -39,4 +27,17 @@ public:
|
|||||||
|
|
||||||
void* ConvertOffsetToPointer(const void* offset) override;
|
void* ConvertOffsetToPointer(const void* offset) override;
|
||||||
void* ConvertOffsetToAlias(const void* offset) override;
|
void* ConvertOffsetToAlias(const void* offset) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Align(unsigned align);
|
||||||
|
|
||||||
|
std::vector<XBlock*>& m_blocks;
|
||||||
|
std::unique_ptr<size_t[]> m_block_offsets;
|
||||||
|
|
||||||
|
std::stack<XBlock*> m_block_stack;
|
||||||
|
std::stack<size_t> m_temp_offsets;
|
||||||
|
ILoadingStream* m_stream;
|
||||||
|
|
||||||
|
unsigned m_block_bit_count;
|
||||||
|
XBlock* m_insert_block;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user