2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-12-02 09:17:47 +00:00

Merge fixup

This commit is contained in:
LJW-Dev
2025-10-09 00:05:49 +08:00
771 changed files with 27490 additions and 14332 deletions

View File

@@ -14,9 +14,6 @@ public:
std::unique_ptr<AssetPool<IW3::XAnimParts>> m_xanim_parts;
std::unique_ptr<AssetPool<IW3::XModel>> m_xmodel;
std::unique_ptr<AssetPool<IW3::Material>> m_material;
std::unique_ptr<AssetPool<IW3::MaterialPixelShader>> m_material_pixel_shader;
std::unique_ptr<AssetPool<IW3::MaterialVertexShader>> m_material_vertex_shader;
std::unique_ptr<AssetPool<IW3::MaterialVertexDeclaration>> m_material_vertex_decl;
std::unique_ptr<AssetPool<IW3::MaterialTechniqueSet>> m_technique_set;
std::unique_ptr<AssetPool<IW3::GfxImage>> m_image;
std::unique_ptr<AssetPool<IW3::snd_alias_list_t>> m_sound;

View File

@@ -13,20 +13,24 @@ namespace T6
public:
static constexpr const char* MAGIC_SIGNED_TREYARCH = "TAff0100";
static constexpr const char* MAGIC_SIGNED_LZX_TREYARCH = "TAffx100";
static constexpr const char* MAGIC_SIGNED_OAT = "ABff0100";
static constexpr const char* MAGIC_UNSIGNED = "TAffu100";
static constexpr const char* MAGIC_UNSIGNED_SERVER = "TAsvu100";
static_assert(std::char_traits<char>::length(MAGIC_SIGNED_TREYARCH) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_SIGNED_LZX_TREYARCH) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_SIGNED_OAT) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_UNSIGNED) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_UNSIGNED_SERVER) == sizeof(ZoneHeader::m_magic));
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 unsigned ZONE_VERSION_PC = 147;
static constexpr unsigned ZONE_VERSION_XENON = 146;
static constexpr unsigned STREAM_COUNT = 4;
static constexpr unsigned XCHUNK_SIZE = 0x8000;
static constexpr unsigned XCHUNK_MAX_WRITE_SIZE = XCHUNK_SIZE - 0x40;
static constexpr unsigned VANILLA_BUFFER_SIZE = 0x80000;
static constexpr unsigned OFFSET_BLOCK_BIT_COUNT = 3u;
static constexpr block_t INSERT_BLOCK = XFILE_BLOCK_VIRTUAL;
@@ -34,10 +38,14 @@ namespace T6
static constexpr size_t FILE_SUFFIX_ZERO_ALIGN = 0x40;
static constexpr const char* MAGIC_AUTH_HEADER = "PHEEBs71";
inline static const uint8_t SALSA20_KEY_TREYARCH[]{
inline static const uint8_t SALSA20_KEY_TREYARCH_PC[]{
0x64, 0x1D, 0x8A, 0x2F, 0xE3, 0x1D, 0x3A, 0xA6, 0x36, 0x22, 0xBB, 0xC9, 0xCE, 0x85, 0x87, 0x22,
0x9D, 0x42, 0xB0, 0xF8, 0xED, 0x9B, 0x92, 0x41, 0x30, 0xBF, 0x88, 0xB6, 0x5E, 0xDC, 0x50, 0xBE,
};
inline static const uint8_t SALSA20_KEY_TREYARCH_XENON[]{
0x0E, 0x50, 0xF4, 0x9F, 0x41, 0x23, 0x17, 0x09, 0x60, 0x38, 0x66, 0x56, 0x22, 0xDD, 0x09, 0x13,
0x32, 0xA2, 0x09, 0xBA, 0x0A, 0x05, 0xA0, 0x0E, 0x13, 0x77, 0xCE, 0xDB, 0x0A, 0x3C, 0xB1, 0xD3,
};
inline static const uint8_t RSA_PUBLIC_KEY_TREYARCH[]{
0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc7, 0x9d, 0x33, 0xe0, 0x75, 0xaf, 0xef, 0x08, 0x08, 0x2b, 0x89, 0xd9, 0x3b, 0xf3,

View File

@@ -2,6 +2,7 @@
#include "Csv/CsvStream.h"
#include "Game/IGame.h"
#include "Utils/Logging/Log.h"
#include "Zone/AssetNameResolver.h"
#include <format>
@@ -35,7 +36,7 @@ namespace
const auto maybeType = m_asset_name_resolver->GetAssetTypeByName(typeName);
if (!maybeType)
{
std::cerr << std::format("Unknown asset type name \"{}\"\n", typeName);
con::error("Unknown asset type name \"{}\"", typeName);
if (failure)
*failure = true;
return false;
@@ -90,7 +91,7 @@ std::optional<AssetList> AssetListReader::ReadAssetList(const std::string& zoneN
return assetList;
}
else if (logMissing)
std::cerr << std::format("Failed to open file for assetlist: {}\n", assetListFileName);
con::error("Failed to open file for assetlist: {}", assetListFileName);
return std::nullopt;
}

View File

@@ -1,5 +1,6 @@
#include "SequenceZoneDefinitionMetaData.h"
#include "Utils/Logging/Log.h"
#include "Utils/StringUtils.h"
#include "Zone/Definition/Parsing/Matcher/ZoneDefinitionMatcherFactory.h"
@@ -114,11 +115,11 @@ namespace
}
const auto keyPos = keyToken.GetPos();
std::cerr << std::format("Warning: {} L{}: Zone definition \">type,{}\" is deprecated and should be removed. {}\n",
keyPos.m_filename.get(),
keyPos.m_line,
keyToken.FieldValue(),
deprecationSuggestedAction);
con::error("Warning: {} L{}: Zone definition \">type,{}\" is deprecated and should be removed. {}",
keyPos.m_filename.get(),
keyPos.m_line,
keyToken.FieldValue(),
deprecationSuggestedAction);
}
} // namespace

View File

@@ -4,6 +4,7 @@
#include "Parsing/Impl/DefinesStreamProxy.h"
#include "Parsing/Impl/IncludingStreamProxy.h"
#include "Parsing/Impl/ParserSingleInputStream.h"
#include "Utils/Logging/Log.h"
#include "Zone/Definition/Parsing/ZoneDefinitionLexer.h"
#include "Zone/Definition/Parsing/ZoneDefinitionParser.h"
@@ -44,7 +45,7 @@ void ZoneDefinitionInputStream::SetPreviouslySetGame(GameId game)
std::unique_ptr<ZoneDefinition> ZoneDefinitionInputStream::ReadDefinition()
{
std::cout << std::format("Reading zone definition file: {}\n", m_file_name);
con::info("Reading zone definition file: {}", m_file_name);
const auto lexer = std::make_unique<ZoneDefinitionLexer>(m_stream);
const auto parser = std::make_unique<ZoneDefinitionParser>(lexer.get(), m_target_name, m_search_path, *m_stream, m_previously_set_game);
@@ -55,7 +56,7 @@ std::unique_ptr<ZoneDefinition> ZoneDefinitionInputStream::ReadDefinition()
definition = parser->GetParsedValue();
const auto end = std::chrono::steady_clock::now();
std::cout << std::format("Processing zone definition took {}ms\n", std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count());
con::info("Processing zone definition took {}ms", std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count());
return std::move(definition);
}

View File

@@ -1,25 +1,18 @@
#include "AbstractSalsa20Processor.h"
#include <cassert>
#include <cstring>
AbstractSalsa20Processor::AbstractSalsa20Processor(const int streamCount, const std::string& zoneName, const uint8_t* salsa20Key, const size_t keySize)
AbstractSalsa20Processor::AbstractSalsa20Processor(const unsigned streamCount, const std::string& zoneName, const uint8_t* salsa20Key, const size_t keySize)
: m_stream_count(streamCount),
m_stream_contexts(std::make_unique<StreamContext[]>(streamCount)),
m_stream_block_indices(std::make_unique<unsigned int[]>(streamCount))
m_stream_contexts(streamCount),
m_block_hashes(BLOCK_HASHES_COUNT * streamCount * SHA1_HASH_SIZE),
m_stream_block_indices(streamCount)
{
m_block_hashes = std::make_unique<uint8_t[]>(BLOCK_HASHES_COUNT * streamCount * SHA1_HASH_SIZE);
InitStreams(zoneName, salsa20Key, keySize);
}
uint8_t* AbstractSalsa20Processor::GetHashBlock(const int streamNumber) const
{
const auto blockIndexOffset = m_stream_block_indices[streamNumber] * m_stream_count * SHA1_HASH_SIZE;
const auto streamOffset = static_cast<size_t>(streamNumber) * SHA1_HASH_SIZE;
return &m_block_hashes[blockIndexOffset + streamOffset];
}
void AbstractSalsa20Processor::InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, const size_t keySize) const
void AbstractSalsa20Processor::InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, const size_t keySize)
{
// Original buffer must have been 32 bytes because the zoneName can at most be 31 characters be long before being cut off
const auto zoneNameLength = std::min(zoneName.length(), 31uz);
@@ -29,14 +22,14 @@ void AbstractSalsa20Processor::InitStreams(const std::string& zoneName, const ui
assert(blockHashBufferSize % 4 == 0);
size_t zoneNameOffset = 0;
for (size_t i = 0; i < blockHashBufferSize; i += 4)
for (auto i = 0uz; i < blockHashBufferSize; i += 4)
{
*reinterpret_cast<uint32_t*>(&m_block_hashes[i]) = 0x1010101 * zoneName[zoneNameOffset++];
memset(&m_block_hashes[i], zoneName[zoneNameOffset++], 4u);
zoneNameOffset %= zoneNameLength;
}
for (auto stream = 0; stream < m_stream_count; stream++)
for (auto stream = 0u; stream < m_stream_count; stream++)
{
m_stream_block_indices[stream] = 0;
@@ -45,11 +38,19 @@ void AbstractSalsa20Processor::InitStreams(const std::string& zoneName, const ui
}
}
uint8_t* AbstractSalsa20Processor::GetHashBlock(const unsigned streamNumber)
{
const auto blockIndexOffset = m_stream_block_indices[streamNumber] * m_stream_count * SHA1_HASH_SIZE;
const auto streamOffset = static_cast<size_t>(streamNumber) * SHA1_HASH_SIZE;
return &m_block_hashes[blockIndexOffset + streamOffset];
}
void AbstractSalsa20Processor::GetCapturedData(const uint8_t** pCapturedData, size_t* pSize)
{
assert(pCapturedData != nullptr);
assert(pSize != nullptr);
*pCapturedData = m_block_hashes.get();
*pCapturedData = m_block_hashes.data();
*pSize = BLOCK_HASHES_COUNT * m_stream_count * SHA1_HASH_SIZE;
}

View File

@@ -1,40 +1,22 @@
#pragma once
#include "Cryptography.h"
#include "Utils/ClassUtils.h"
#include "Utils/ICapturedDataProvider.h"
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
class Salsa20StreamContext
{
public:
std::unique_ptr<cryptography::IStreamCipher> m_salsa20;
std::unique_ptr<cryptography::IHashFunction> m_sha1;
};
class AbstractSalsa20Processor : public ICapturedDataProvider
{
protected:
static constexpr int BLOCK_HASHES_COUNT = 200;
static constexpr int SHA1_HASH_SIZE = 20;
static constexpr int SALSA20_IV_SIZE = 8;
class StreamContext
{
public:
std::unique_ptr<cryptography::IStreamCipher> m_salsa20;
std::unique_ptr<cryptography::IHashFunction> m_sha1;
};
int m_stream_count;
std::unique_ptr<StreamContext[]> m_stream_contexts;
// m_block_hashes[BLOCK_HASHES_COUNT][numStreams][HASH_SIZE]
std::unique_ptr<uint8_t[]> m_block_hashes;
std::unique_ptr<unsigned int[]> m_stream_block_indices;
AbstractSalsa20Processor(int streamCount, const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
_NODISCARD uint8_t* GetHashBlock(int streamNumber) const;
void InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize) const;
public:
virtual ~AbstractSalsa20Processor() = default;
AbstractSalsa20Processor(const AbstractSalsa20Processor& other) = delete;
@@ -43,4 +25,21 @@ public:
AbstractSalsa20Processor& operator=(AbstractSalsa20Processor&& other) noexcept = default;
void GetCapturedData(const uint8_t** pCapturedData, size_t* pSize) override;
protected:
static constexpr auto BLOCK_HASHES_COUNT = 200u;
static constexpr auto SHA1_HASH_SIZE = 20u;
static constexpr auto SALSA20_IV_SIZE = 8u;
AbstractSalsa20Processor(unsigned streamCount, const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
void InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
[[nodiscard]] uint8_t* GetHashBlock(unsigned streamNumber);
unsigned m_stream_count;
std::vector<Salsa20StreamContext> m_stream_contexts;
// m_block_hashes[BLOCK_HASHES_COUNT][numStreams][SHA1_HASH_SIZE]
std::vector<uint8_t> m_block_hashes;
std::vector<unsigned int> m_stream_block_indices;
};

View File

@@ -6,6 +6,12 @@
class IXChunkProcessor
{
public:
IXChunkProcessor() = default;
virtual ~IXChunkProcessor() = default;
virtual size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) = 0;
IXChunkProcessor(const IXChunkProcessor& other) = default;
IXChunkProcessor(IXChunkProcessor&& other) noexcept = default;
IXChunkProcessor& operator=(const IXChunkProcessor& other) = default;
IXChunkProcessor& operator=(IXChunkProcessor&& other) noexcept = default;
virtual size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) = 0;
};

View File

@@ -6,7 +6,7 @@
#include <zlib.h>
#include <zutil.h>
size_t XChunkProcessorDeflate::Process(int streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
size_t XChunkProcessorDeflate::Process(unsigned streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
{
z_stream stream{};
stream.zalloc = Z_NULL;

View File

@@ -4,5 +4,5 @@
class XChunkProcessorDeflate final : public IXChunkProcessor
{
public:
size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
};

View File

@@ -1,11 +1,14 @@
#include "XChunkProcessorInflate.h"
#include "Utils/Logging/Log.h"
#include "XChunkException.h"
#include <format>
#include <iostream>
#include <zlib.h>
#include <zutil.h>
size_t XChunkProcessorInflate::Process(int streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
size_t XChunkProcessorInflate::Process(unsigned streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
{
z_stream stream{};
stream.zalloc = Z_NULL;
@@ -23,7 +26,10 @@ size_t XChunkProcessorInflate::Process(int streamNumber, const uint8_t* input, c
ret = inflate(&stream, Z_FULL_FLUSH);
if (ret != Z_STREAM_END)
throw XChunkException("Zone has invalid or unsupported compression. Inflate failed");
{
con::error("inflate of stream failed with error code {}: {}", streamNumber, ret, stream.msg);
throw XChunkException(std::format("Zone has invalid or unsupported compression: {}", stream.msg));
}
const size_t outputSize = stream.total_out;

View File

@@ -4,5 +4,5 @@
class XChunkProcessorInflate final : public IXChunkProcessor
{
public:
size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
};

View File

@@ -0,0 +1,134 @@
#include "XChunkProcessorLzxDecompress.h"
#include "Utils/Logging/Log.h"
#include <cstring>
#include <format>
#include <iostream>
#include <lzx.h>
namespace
{
uint8_t NextByte(const uint8_t* input, size_t& offset, size_t& remainingSize)
{
const auto value = input[offset];
offset++;
remainingSize--;
return value;
}
uint16_t CombineHighLow(const uint8_t highByte, const uint8_t lowByte)
{
return static_cast<uint16_t>(static_cast<uint16_t>(static_cast<uint16_t>(highByte) << 8u) | static_cast<uint16_t>(lowByte));
}
void LogErrorHeaderSpace(size_t remainingInputSize)
{
con::error("XMemCompress: Not enough data for header: {}", remainingInputSize);
}
} // namespace
XChunkProcessorLzxDecompress::XChunkProcessorLzxDecompress(const unsigned streamCount)
: m_lzx_states(streamCount)
{
// T6 uses 17 for window bits
for (auto& lzxState : m_lzx_states)
lzxState = lzx_init(17);
}
XChunkProcessorLzxDecompress::~XChunkProcessorLzxDecompress()
{
for (auto* lzxState : m_lzx_states)
lzx_teardown(static_cast<lzx_state*>(lzxState));
}
size_t XChunkProcessorLzxDecompress::Process(
const unsigned streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
{
auto* state = static_cast<lzx_state*>(m_lzx_states[streamNumber]);
// lzx state is reset before each chunk
lzx_reset(state);
size_t curInputOffset = 0uz;
size_t curInputSize = inputLength;
size_t curOutputOffset = 0uz;
size_t curOutputSize = outputBufferSize;
uint8_t lowByte;
uint16_t dstSize, srcSize;
while (curInputSize > 0)
{
uint8_t highByte = NextByte(input, curInputOffset, curInputSize);
uint8_t suffixSize;
if (highByte == 0xFF) // magic number: output is smaller than 0x8000
{
if (curInputSize < 4)
{
LogErrorHeaderSpace(curInputSize);
return curOutputOffset;
}
highByte = NextByte(input, curInputOffset, curInputSize);
lowByte = NextByte(input, curInputOffset, curInputSize);
dstSize = CombineHighLow(highByte, lowByte);
highByte = NextByte(input, curInputOffset, curInputSize);
lowByte = NextByte(input, curInputOffset, curInputSize);
srcSize = CombineHighLow(highByte, lowByte);
// The game seems to skip a 5 byte suffix after these blocks, not sure why.
suffixSize = 5u;
}
else
{
if (curInputSize < 1)
{
LogErrorHeaderSpace(curInputSize);
return curOutputOffset;
}
dstSize = 0x8000u;
lowByte = NextByte(input, curInputOffset, curInputSize);
srcSize = CombineHighLow(highByte, lowByte);
suffixSize = 0u;
}
if (srcSize == 0 || dstSize == 0)
{
// Other implementations do not handle this as a failure, game code suggests otherwise though
con::error("XMemCompress: EOF: {} {}, {}", srcSize, dstSize, curInputSize);
return curOutputOffset;
}
if (static_cast<size_t>(srcSize) + suffixSize > curInputSize)
{
con::error("XMemCompress: block size bigger than remaining data: {} > {}", srcSize, curInputSize);
return curOutputOffset;
}
if (dstSize > curOutputSize)
{
con::error("XMemCompress: output size bigger than remaining data: {} > {}", dstSize, curOutputSize);
return curOutputOffset;
}
auto ret = lzx_decompress(state, &input[curInputOffset], &output[curOutputOffset], srcSize, dstSize);
curInputOffset += srcSize + suffixSize;
curInputSize -= (srcSize + suffixSize);
curOutputOffset += dstSize;
curOutputSize -= srcSize;
if (ret != DECR_OK)
{
con::error("XMemCompress: lzx decompression failed: {}", ret);
return curOutputOffset;
}
}
return curOutputOffset;
}

View File

@@ -0,0 +1,16 @@
#pragma once
#include "IXChunkProcessor.h"
#include <vector>
class XChunkProcessorLzxDecompress final : public IXChunkProcessor
{
public:
explicit XChunkProcessorLzxDecompress(unsigned streamCount);
~XChunkProcessorLzxDecompress();
size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
private:
std::vector<void*> m_lzx_states;
};

View File

@@ -4,9 +4,11 @@
#include "Cryptography.h"
#include <cassert>
#include <format>
#include <iostream>
XChunkProcessorSalsa20Decryption::XChunkProcessorSalsa20Decryption(const int streamCount,
std::string& zoneName,
XChunkProcessorSalsa20Decryption::XChunkProcessorSalsa20Decryption(const unsigned streamCount,
const std::string& zoneName,
const uint8_t* salsa20Key,
const size_t keySize)
: AbstractSalsa20Processor(streamCount, zoneName, salsa20Key, keySize)
@@ -14,9 +16,9 @@ XChunkProcessorSalsa20Decryption::XChunkProcessorSalsa20Decryption(const int str
}
size_t XChunkProcessorSalsa20Decryption::Process(
const int streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
const unsigned streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
{
assert(streamNumber >= 0 && streamNumber < m_stream_count);
assert(streamNumber < m_stream_count);
assert(input != nullptr);
assert(output != nullptr);
assert(inputLength <= outputBufferSize);

View File

@@ -7,7 +7,7 @@
class XChunkProcessorSalsa20Decryption final : public IXChunkProcessor, public AbstractSalsa20Processor
{
public:
XChunkProcessorSalsa20Decryption(int streamCount, std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
XChunkProcessorSalsa20Decryption(unsigned streamCount, const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
};

View File

@@ -2,7 +2,7 @@
#include <cassert>
XChunkProcessorSalsa20Encryption::XChunkProcessorSalsa20Encryption(const int streamCount,
XChunkProcessorSalsa20Encryption::XChunkProcessorSalsa20Encryption(const unsigned streamCount,
const std::string& zoneName,
const uint8_t* salsa20Key,
const size_t keySize)
@@ -11,14 +11,14 @@ XChunkProcessorSalsa20Encryption::XChunkProcessorSalsa20Encryption(const int str
}
size_t XChunkProcessorSalsa20Encryption::Process(
const int streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
const unsigned streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
{
assert(streamNumber >= 0 && streamNumber < m_stream_count);
assert(streamNumber < m_stream_count);
assert(input != nullptr);
assert(output != nullptr);
assert(inputLength <= outputBufferSize);
auto& streamContext = m_stream_contexts[streamNumber];
const auto& streamContext = m_stream_contexts[streamNumber];
// Hash not yet encrypted XChunk
uint8_t blockSha1Hash[SHA1_HASH_SIZE];

View File

@@ -8,7 +8,7 @@
class XChunkProcessorSalsa20Encryption final : public IXChunkProcessor, public AbstractSalsa20Processor
{
public:
XChunkProcessorSalsa20Encryption(int streamCount, const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
XChunkProcessorSalsa20Encryption(unsigned streamCount, const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
};

View File

@@ -1,13 +1,14 @@
#include "Zone.h"
Zone::Zone(std::string name, const zone_priority_t priority, IGame* game)
#include "ZoneRegistry.h"
Zone::Zone(std::string name, const zone_priority_t priority, GameId gameId)
: m_name(std::move(name)),
m_priority(priority),
m_language(GameLanguage::LANGUAGE_NONE),
m_game(game),
m_pools(ZoneAssetPools::CreateForGame(game->GetId(), this, priority)),
m_memory(std::make_unique<ZoneMemory>()),
m_registered(false)
m_game_id(gameId),
m_pools(ZoneAssetPools::CreateForGame(gameId, this, priority)),
m_memory(std::make_unique<ZoneMemory>())
{
}
@@ -15,7 +16,7 @@ Zone::~Zone()
{
if (m_registered)
{
m_game->RemoveZone(this);
ZoneRegistry::GetRegistryForGame(m_game_id)->RemoveZone(this);
}
}
@@ -23,7 +24,7 @@ void Zone::Register()
{
if (!m_registered)
{
m_game->AddZone(this);
ZoneRegistry::GetRegistryForGame(m_game_id)->AddZone(this);
m_registered = true;
}
}

View File

@@ -10,20 +10,12 @@
#include <memory>
#include <string>
class IGame;
class ZoneAssetPools;
class Zone
{
public:
std::string m_name;
zone_priority_t m_priority;
GameLanguage m_language;
IGame* m_game;
ZoneScriptStrings m_script_strings;
std::unique_ptr<ZoneAssetPools> m_pools;
Zone(std::string name, zone_priority_t priority, IGame* game);
Zone(std::string name, zone_priority_t priority, GameId gameId);
~Zone();
Zone(const Zone& other) = delete;
Zone(Zone&& other) noexcept = default;
@@ -34,6 +26,13 @@ public:
[[nodiscard]] ZoneMemory& Memory() const;
std::string m_name;
zone_priority_t m_priority;
GameLanguage m_language;
GameId m_game_id;
ZoneScriptStrings m_script_strings;
std::unique_ptr<ZoneAssetPools> m_pools;
private:
std::unique_ptr<ZoneMemory> m_memory;

View File

@@ -0,0 +1,38 @@
#include "ZoneRegistry.h"
#include <algorithm>
#include <cassert>
#include <memory>
ZoneRegistry::ZoneRegistry() = default;
void ZoneRegistry::AddZone(Zone* zone)
{
assert(zone);
m_zones.emplace_back(zone);
}
void ZoneRegistry::RemoveZone(Zone* zone)
{
assert(zone);
std::erase_if(m_zones,
[zone](const Zone* existingZone)
{
return existingZone == zone;
});
}
const std::vector<Zone*>& ZoneRegistry::Zones() const
{
return m_zones;
}
ZoneRegistry* ZoneRegistry::GetRegistryForGame(GameId gameId)
{
static ZoneRegistry registries[static_cast<unsigned>(GameId::COUNT)];
assert(static_cast<unsigned>(gameId) < static_cast<unsigned>(GameId::COUNT));
return &registries[static_cast<unsigned>(gameId)];
}

View File

@@ -0,0 +1,22 @@
#pragma once
#include "Game/IGame.h"
#include "Zone.h"
#include <vector>
class ZoneRegistry
{
public:
void AddZone(Zone* zone);
void RemoveZone(Zone* zone);
const std::vector<Zone*>& Zones() const;
static ZoneRegistry* GetRegistryForGame(GameId gameId);
private:
ZoneRegistry();
std::vector<Zone*> m_zones;
};