mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-09-23 16:56:39 +00:00
chore: dump fastfile data when xenon t6 fastfile is detected
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "Loading/Processor/ProcessorXChunks.h"
|
||||
#include "Loading/Steps/StepAddProcessor.h"
|
||||
#include "Loading/Steps/StepAllocXBlocks.h"
|
||||
#include "Loading/Steps/StepDumpData.h"
|
||||
#include "Loading/Steps/StepLoadSignature.h"
|
||||
#include "Loading/Steps/StepLoadZoneContent.h"
|
||||
#include "Loading/Steps/StepLoadZoneSizes.h"
|
||||
@@ -16,16 +17,20 @@
|
||||
#include "Loading/Steps/StepVerifyFileName.h"
|
||||
#include "Loading/Steps/StepVerifyMagic.h"
|
||||
#include "Loading/Steps/StepVerifySignature.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Utils/Endianness.h"
|
||||
#include "Zone/XChunk/XChunkProcessorInflate.h"
|
||||
#include "Zone/XChunk/XChunkProcessorSalsa20Decryption.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
using namespace T6;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -44,46 +49,53 @@ namespace
|
||||
return GameLanguage::LANGUAGE_NONE;
|
||||
}
|
||||
|
||||
bool CanLoad(const ZoneHeader& header, bool* isSecure, bool* isOfficial, bool* isEncrypted)
|
||||
bool CanLoad(const ZoneHeader& header, bool& isBigEndian, bool& isSecure, bool& isOfficial, bool& isEncrypted)
|
||||
{
|
||||
assert(isSecure != nullptr);
|
||||
assert(isOfficial != nullptr);
|
||||
|
||||
if (header.m_version != ZoneConstants::ZONE_VERSION)
|
||||
if (endianness::FromLittleEndian(header.m_version) == ZoneConstants::ZONE_VERSION_PC)
|
||||
{
|
||||
return false;
|
||||
isBigEndian = false;
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_PC_TREYARCH, 8))
|
||||
{
|
||||
isSecure = true;
|
||||
isOfficial = true;
|
||||
isEncrypted = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_PC_OAT, 8))
|
||||
{
|
||||
isSecure = true;
|
||||
isOfficial = false;
|
||||
isEncrypted = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_UNSIGNED, 8))
|
||||
{
|
||||
isSecure = false;
|
||||
isOfficial = true;
|
||||
isEncrypted = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_UNSIGNED_SERVER, 8))
|
||||
{
|
||||
isSecure = false;
|
||||
isOfficial = true;
|
||||
isEncrypted = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_TREYARCH, 8))
|
||||
else if (endianness::FromBigEndian(header.m_version) == ZoneConstants::ZONE_VERSION_XENON)
|
||||
{
|
||||
*isSecure = true;
|
||||
*isOfficial = true;
|
||||
*isEncrypted = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_OAT, 8))
|
||||
{
|
||||
*isSecure = true;
|
||||
*isOfficial = false;
|
||||
*isEncrypted = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_UNSIGNED, 8))
|
||||
{
|
||||
*isSecure = false;
|
||||
*isOfficial = true;
|
||||
*isEncrypted = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_UNSIGNED_SERVER, 8))
|
||||
{
|
||||
*isSecure = false;
|
||||
*isOfficial = true;
|
||||
*isEncrypted = false;
|
||||
return true;
|
||||
isBigEndian = true;
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_XENON_TREYARCH, 8))
|
||||
{
|
||||
isSecure = true;
|
||||
isOfficial = true;
|
||||
isEncrypted = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -145,16 +157,21 @@ namespace
|
||||
return signatureLoadStepPtr;
|
||||
}
|
||||
|
||||
ICapturedDataProvider* AddXChunkProcessor(const bool isEncrypted, ZoneLoader& zoneLoader, std::string& fileName)
|
||||
ICapturedDataProvider* AddXChunkProcessor(const bool isBigEndian, const bool isEncrypted, ZoneLoader& zoneLoader, std::string& fileName)
|
||||
{
|
||||
ICapturedDataProvider* result = nullptr;
|
||||
auto xChunkProcessor = processor::CreateProcessorXChunks(ZoneConstants::STREAM_COUNT, ZoneConstants::XCHUNK_SIZE, ZoneConstants::VANILLA_BUFFER_SIZE);
|
||||
auto xChunkProcessor = processor::CreateProcessorXChunks(ZoneConstants::STREAM_COUNT,
|
||||
ZoneConstants::XCHUNK_SIZE,
|
||||
isBigEndian ? GameEndianness::BIG_ENDIAN : GameEndianness::LITTLE_ENDIAN,
|
||||
ZoneConstants::VANILLA_BUFFER_SIZE);
|
||||
|
||||
const uint8_t (&salsa20Key)[32] = isBigEndian ? ZoneConstants::SALSA20_KEY_TREYARCH_XENON : ZoneConstants::SALSA20_KEY_TREYARCH_PC;
|
||||
|
||||
if (isEncrypted)
|
||||
{
|
||||
// If zone is encrypted, the decryption is applied before the decompression. T6 Zones always use Salsa20.
|
||||
auto chunkProcessorSalsa20 = std::make_unique<XChunkProcessorSalsa20Decryption>(
|
||||
ZoneConstants::STREAM_COUNT, fileName, ZoneConstants::SALSA20_KEY_TREYARCH, sizeof(ZoneConstants::SALSA20_KEY_TREYARCH));
|
||||
auto chunkProcessorSalsa20 =
|
||||
std::make_unique<XChunkProcessorSalsa20Decryption>(ZoneConstants::STREAM_COUNT, fileName, salsa20Key, sizeof(salsa20Key));
|
||||
result = chunkProcessorSalsa20.get();
|
||||
xChunkProcessor->AddChunkProcessor(std::move(chunkProcessorSalsa20));
|
||||
}
|
||||
@@ -170,12 +187,10 @@ namespace
|
||||
|
||||
std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const
|
||||
{
|
||||
bool isSecure;
|
||||
bool isOfficial;
|
||||
bool isEncrypted;
|
||||
bool isBigEndian, isSecure, isOfficial, isEncrypted;
|
||||
|
||||
// Check if this file is a supported T6 zone.
|
||||
if (!CanLoad(header, &isSecure, &isOfficial, &isEncrypted))
|
||||
if (!CanLoad(header, isBigEndian, isSecure, isOfficial, isEncrypted))
|
||||
return nullptr;
|
||||
|
||||
// Create new zone
|
||||
@@ -196,26 +211,37 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader&
|
||||
ISignatureProvider* signatureProvider = AddAuthHeaderSteps(isSecure, *zoneLoader, fileName);
|
||||
|
||||
// Setup loading XChunks from the zone from this point on.
|
||||
ICapturedDataProvider* signatureDataProvider = AddXChunkProcessor(isEncrypted, *zoneLoader, fileName);
|
||||
ICapturedDataProvider* signatureDataProvider = AddXChunkProcessor(isBigEndian, isEncrypted, *zoneLoader, fileName);
|
||||
|
||||
// Start of the XFile struct
|
||||
zoneLoader->AddLoadingStep(step::CreateStepLoadZoneSizes());
|
||||
zoneLoader->AddLoadingStep(step::CreateStepAllocXBlocks());
|
||||
|
||||
// Start of the zone content
|
||||
zoneLoader->AddLoadingStep(step::CreateStepLoadZoneContent(
|
||||
[zonePtr](ZoneInputStream& stream)
|
||||
{
|
||||
return std::make_unique<ContentLoader>(*zonePtr, stream);
|
||||
},
|
||||
32u,
|
||||
ZoneConstants::OFFSET_BLOCK_BIT_COUNT,
|
||||
ZoneConstants::INSERT_BLOCK,
|
||||
zonePtr->Memory()));
|
||||
|
||||
if (isSecure)
|
||||
if (!isBigEndian)
|
||||
{
|
||||
zoneLoader->AddLoadingStep(step::CreateStepVerifySignature(std::move(rsa), signatureProvider, signatureDataProvider));
|
||||
// Start of the XFile struct
|
||||
zoneLoader->AddLoadingStep(step::CreateStepLoadZoneSizes());
|
||||
zoneLoader->AddLoadingStep(step::CreateStepAllocXBlocks());
|
||||
|
||||
// Start of the zone content
|
||||
zoneLoader->AddLoadingStep(step::CreateStepLoadZoneContent(
|
||||
[zonePtr](ZoneInputStream& stream)
|
||||
{
|
||||
return std::make_unique<ContentLoader>(*zonePtr, stream);
|
||||
},
|
||||
32u,
|
||||
ZoneConstants::OFFSET_BLOCK_BIT_COUNT,
|
||||
ZoneConstants::INSERT_BLOCK,
|
||||
zonePtr->Memory()));
|
||||
|
||||
if (isSecure)
|
||||
{
|
||||
zoneLoader->AddLoadingStep(step::CreateStepVerifySignature(std::move(rsa), signatureProvider, signatureDataProvider));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fs::path dumpFileNamePath = fs::path(fileName).filename();
|
||||
dumpFileNamePath.replace_extension(".dat");
|
||||
std::string dumpFileName = dumpFileNamePath.string();
|
||||
std::cerr << std::format("Dumping xbox assets is not supported, making a full fastfile data dump to {}\n", dumpFileName);
|
||||
zoneLoader->AddLoadingStep(step::CreateStepDumpData(dumpFileName, 0xFFFFFFFF));
|
||||
}
|
||||
|
||||
return zoneLoader;
|
||||
|
@@ -1,11 +1,14 @@
|
||||
#include "ProcessorXChunks.h"
|
||||
|
||||
#include "Loading/Exception/InvalidChunkSizeException.h"
|
||||
#include "Utils/Endianness.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <condition_variable>
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
@@ -125,8 +128,9 @@ namespace
|
||||
class ProcessorXChunks final : public processor::IProcessorXChunks
|
||||
{
|
||||
public:
|
||||
ProcessorXChunks(const int numStreams, const size_t xChunkSize, const std::optional<size_t> vanillaBufferSize)
|
||||
ProcessorXChunks(const int numStreams, const size_t xChunkSize, const GameEndianness endianness, const std::optional<size_t> vanillaBufferSize)
|
||||
: m_chunk_size(xChunkSize),
|
||||
m_endianness(endianness),
|
||||
m_vanilla_buffer_size(vanillaBufferSize),
|
||||
m_initialized_streams(false),
|
||||
m_current_stream(0),
|
||||
@@ -227,6 +231,11 @@ namespace
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_endianness == GameEndianness::LITTLE_ENDIAN)
|
||||
chunkSize = endianness::FromLittleEndian(chunkSize);
|
||||
else
|
||||
chunkSize = endianness::FromBigEndian(chunkSize);
|
||||
|
||||
if (chunkSize > m_chunk_size)
|
||||
{
|
||||
throw InvalidChunkSizeException(chunkSize, m_chunk_size);
|
||||
@@ -280,6 +289,7 @@ namespace
|
||||
|
||||
std::vector<std::unique_ptr<DbLoadStream>> m_streams;
|
||||
size_t m_chunk_size;
|
||||
GameEndianness m_endianness;
|
||||
std::optional<size_t> m_vanilla_buffer_size;
|
||||
std::vector<std::unique_ptr<IXChunkProcessor>> m_chunk_processors;
|
||||
|
||||
@@ -297,13 +307,14 @@ namespace
|
||||
|
||||
namespace processor
|
||||
{
|
||||
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(int numStreams, const size_t xChunkSize)
|
||||
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(unsigned numStreams, const size_t xChunkSize, const GameEndianness endianness)
|
||||
{
|
||||
return std::make_unique<ProcessorXChunks>(numStreams, xChunkSize, std::nullopt);
|
||||
return std::make_unique<ProcessorXChunks>(numStreams, xChunkSize, endianness, std::nullopt);
|
||||
}
|
||||
|
||||
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(int numStreams, const size_t xChunkSize, const size_t vanillaBufferSize)
|
||||
std::unique_ptr<IProcessorXChunks>
|
||||
CreateProcessorXChunks(unsigned numStreams, const size_t xChunkSize, GameEndianness endianness, const size_t vanillaBufferSize)
|
||||
{
|
||||
return std::make_unique<ProcessorXChunks>(numStreams, xChunkSize, vanillaBufferSize);
|
||||
return std::make_unique<ProcessorXChunks>(numStreams, xChunkSize, endianness, vanillaBufferSize);
|
||||
}
|
||||
} // namespace processor
|
||||
|
@@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IGame.h"
|
||||
#include "Loading/StreamProcessor.h"
|
||||
#include "Zone/XChunk/IXChunkProcessor.h"
|
||||
|
||||
@@ -12,6 +14,6 @@ namespace processor
|
||||
virtual void AddChunkProcessor(std::unique_ptr<IXChunkProcessor> chunkProcessor) = 0;
|
||||
};
|
||||
|
||||
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(int numStreams, size_t xChunkSize);
|
||||
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(int numStreams, size_t xChunkSize, size_t vanillaBufferSize);
|
||||
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(unsigned numStreams, size_t xChunkSize, GameEndianness endianness);
|
||||
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(unsigned numStreams, size_t xChunkSize, GameEndianness endianness, size_t vanillaBufferSize);
|
||||
} // namespace processor
|
||||
|
@@ -7,17 +7,18 @@ namespace
|
||||
class StepDumpData final : public ILoadingStep
|
||||
{
|
||||
public:
|
||||
explicit StepDumpData(const size_t dumpCount)
|
||||
: m_dump_count(dumpCount)
|
||||
StepDumpData(std::string fileName, const size_t dumpCount)
|
||||
: m_file_name(std::move(fileName)),
|
||||
m_dump_count(dumpCount)
|
||||
{
|
||||
}
|
||||
|
||||
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
|
||||
{
|
||||
uint8_t tempBuffer[128];
|
||||
uint8_t tempBuffer[0x1000];
|
||||
auto dumpedBytes = 0uz;
|
||||
|
||||
std::ofstream tempFile("dump.dat", std::fstream::out | std::fstream::binary);
|
||||
std::ofstream tempFile(m_file_name, std::fstream::out | std::fstream::binary);
|
||||
|
||||
while (dumpedBytes < m_dump_count)
|
||||
{
|
||||
@@ -45,14 +46,15 @@ namespace
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_file_name;
|
||||
size_t m_dump_count;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace step
|
||||
{
|
||||
std::unique_ptr<ILoadingStep> CreateStepDumpData(size_t dumpCount)
|
||||
std::unique_ptr<ILoadingStep> CreateStepDumpData(std::string fileName, size_t dumpCount)
|
||||
{
|
||||
return std::make_unique<StepDumpData>(dumpCount);
|
||||
return std::make_unique<StepDumpData>(std::move(fileName), dumpCount);
|
||||
}
|
||||
} // namespace step
|
||||
|
@@ -3,8 +3,9 @@
|
||||
#include "Loading/ILoadingStep.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace step
|
||||
{
|
||||
std::unique_ptr<ILoadingStep> CreateStepDumpData(size_t dumpCount);
|
||||
std::unique_ptr<ILoadingStep> CreateStepDumpData(std::string fileName, size_t dumpCount);
|
||||
}
|
||||
|
Reference in New Issue
Block a user