mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-12-27 20:41:49 +00:00
tidy
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
#include "Loading/Steps/StepLoadZoneSizes.h"
|
#include "Loading/Steps/StepLoadZoneSizes.h"
|
||||||
#include "Loading/Steps/StepRemoveProcessor.h"
|
#include "Loading/Steps/StepRemoveProcessor.h"
|
||||||
#include "Loading/Steps/StepSkipBytes.h"
|
#include "Loading/Steps/StepSkipBytes.h"
|
||||||
|
#include "Loading/Steps/StepSkipZoneImageHeaders.h"
|
||||||
#include "Loading/Steps/StepVerifyFileName.h"
|
#include "Loading/Steps/StepVerifyFileName.h"
|
||||||
#include "Loading/Steps/StepVerifyHash.h"
|
#include "Loading/Steps/StepVerifyHash.h"
|
||||||
#include "Loading/Steps/StepVerifyMagic.h"
|
#include "Loading/Steps/StepVerifyMagic.h"
|
||||||
@@ -280,63 +281,7 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(const ZoneH
|
|||||||
|
|
||||||
if (inspectResult->m_generic_result.m_platform == GamePlatform::XBOX)
|
if (inspectResult->m_generic_result.m_platform == GamePlatform::XBOX)
|
||||||
{
|
{
|
||||||
|
zoneLoader->AddLoadingStep(step::CreateStepSkipZoneImageHeaders());
|
||||||
// Xbox fastfiles have additional header data before the auth header:
|
|
||||||
// - 4 bytes: language flags bitmask
|
|
||||||
// - 4 bytes: image count
|
|
||||||
// - sizeof(XAssetStreamFile) * image count (for each language in the bitmask)
|
|
||||||
// - 4 bytes: unknown
|
|
||||||
// - 4 bytes: unknown
|
|
||||||
// struct XAssetStreamFile // sizeof=0xC
|
|
||||||
// {
|
|
||||||
// unsigned int fileIndex;
|
|
||||||
// unsigned int offset;
|
|
||||||
// unsigned int offsetEnd;
|
|
||||||
// };
|
|
||||||
|
|
||||||
struct SkipXAssetStreamFiles : public ILoadingStep
|
|
||||||
{
|
|
||||||
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
|
|
||||||
{
|
|
||||||
uint32_t languageFlags;
|
|
||||||
stream.Load(&languageFlags, sizeof(languageFlags));
|
|
||||||
languageFlags = endianness::FromBigEndian(languageFlags);
|
|
||||||
|
|
||||||
uint32_t imageCount;
|
|
||||||
stream.Load(&imageCount, sizeof(imageCount));
|
|
||||||
imageCount = endianness::FromBigEndian(imageCount);
|
|
||||||
|
|
||||||
// Count how many languages are set in the bitmask
|
|
||||||
uint32_t languageCount = 0;
|
|
||||||
for (int i = 0; i < 15; i++)
|
|
||||||
{
|
|
||||||
if (languageFlags & (1 << i))
|
|
||||||
{
|
|
||||||
languageCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip image stream file data (12 bytes per image per language)
|
|
||||||
const size_t imageDataSize = 12 * imageCount * languageCount;
|
|
||||||
if (imageDataSize > 0)
|
|
||||||
{
|
|
||||||
std::vector<uint8_t> tempBuffer(std::min(imageDataSize, size_t(8192)));
|
|
||||||
size_t skipped = 0;
|
|
||||||
while (skipped < imageDataSize)
|
|
||||||
{
|
|
||||||
const size_t toSkip = std::min(imageDataSize - skipped, tempBuffer.size());
|
|
||||||
stream.Load(tempBuffer.data(), toSkip);
|
|
||||||
skipped += toSkip;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip the final 8 bytes (2 unknown 4-byte values)
|
|
||||||
uint8_t finalBytes[8];
|
|
||||||
stream.Load(finalBytes, sizeof(finalBytes));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
zoneLoader->AddLoadingStep(std::make_unique<SkipXAssetStreamFiles>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
|
|||||||
75
src/ZoneLoading/Loading/Steps/StepSkipZoneImageHeaders.cpp
Normal file
75
src/ZoneLoading/Loading/Steps/StepSkipZoneImageHeaders.cpp
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#include "StepSkipZoneImageHeaders.h"
|
||||||
|
|
||||||
|
#include "Utils/Endianness.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
class StepSkipZoneImageHeaders final : public ILoadingStep
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
|
||||||
|
{
|
||||||
|
|
||||||
|
// Xbox fastfiles have additional header data before the auth header:
|
||||||
|
// - 4 bytes: language flags bitmask
|
||||||
|
// - 4 bytes: image count
|
||||||
|
// - sizeof(XAssetStreamFile) * image count (for each language in the bitmask)
|
||||||
|
// - 4 bytes: unknown
|
||||||
|
// - 4 bytes: unknown
|
||||||
|
// struct XAssetStreamFile // sizeof=0xC
|
||||||
|
// {
|
||||||
|
// unsigned int fileIndex;
|
||||||
|
// unsigned int offset;
|
||||||
|
// unsigned int offsetEnd;
|
||||||
|
// };
|
||||||
|
|
||||||
|
uint32_t languageFlags;
|
||||||
|
stream.Load(&languageFlags, sizeof(languageFlags));
|
||||||
|
languageFlags = endianness::FromBigEndian(languageFlags);
|
||||||
|
|
||||||
|
uint32_t imageCount;
|
||||||
|
stream.Load(&imageCount, sizeof(imageCount));
|
||||||
|
imageCount = endianness::FromBigEndian(imageCount);
|
||||||
|
|
||||||
|
// Count how many languages are set in the bitmask
|
||||||
|
uint32_t languageCount = 0;
|
||||||
|
for (int i = 0; i < 15; i++)
|
||||||
|
{
|
||||||
|
if (languageFlags & (1 << i))
|
||||||
|
{
|
||||||
|
languageCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip image stream file data (12 bytes per image per language)
|
||||||
|
const size_t imageDataSize = 12 * imageCount * languageCount;
|
||||||
|
if (imageDataSize > 0)
|
||||||
|
{
|
||||||
|
std::vector<uint8_t> tempBuffer(std::min(imageDataSize, size_t(8192)));
|
||||||
|
size_t skipped = 0;
|
||||||
|
while (skipped < imageDataSize)
|
||||||
|
{
|
||||||
|
const size_t toSkip = std::min(imageDataSize - skipped, tempBuffer.size());
|
||||||
|
stream.Load(tempBuffer.data(), toSkip);
|
||||||
|
skipped += toSkip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip the final 8 bytes (2 unknown 4-byte values)
|
||||||
|
uint8_t finalBytes[8];
|
||||||
|
stream.Load(finalBytes, sizeof(finalBytes));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
namespace step
|
||||||
|
{
|
||||||
|
std::unique_ptr<ILoadingStep> CreateStepSkipZoneImageHeaders()
|
||||||
|
{
|
||||||
|
return std::make_unique<StepSkipZoneImageHeaders>();
|
||||||
|
}
|
||||||
|
} // namespace step
|
||||||
10
src/ZoneLoading/Loading/Steps/StepSkipZoneImageHeaders.h
Normal file
10
src/ZoneLoading/Loading/Steps/StepSkipZoneImageHeaders.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Loading/ILoadingStep.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace step
|
||||||
|
{
|
||||||
|
std::unique_ptr<ILoadingStep> CreateStepSkipZoneImageHeaders();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user