mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 23:08:05 -05:00
IW5 support initial commit
This commit is contained in:
203
src/ZoneLoading/Game/IW5/ContentLoaderIW5.cpp
Normal file
203
src/ZoneLoading/Game/IW5/ContentLoaderIW5.cpp
Normal file
@ -0,0 +1,203 @@
|
||||
#include "ContentLoaderIW5.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "Loading/Exception/UnsupportedAssetTypeException.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "Game/IW5/XAssets/addonmapents/addonmapents_load_db.h"
|
||||
#include "Game/IW5/XAssets/clipmap_t/clipmap_t_load_db.h"
|
||||
#include "Game/IW5/XAssets/comworld/comworld_load_db.h"
|
||||
#include "Game/IW5/XAssets/font_s/font_s_load_db.h"
|
||||
#include "Game/IW5/XAssets/fxeffectdef/fxeffectdef_load_db.h"
|
||||
#include "Game/IW5/XAssets/fximpacttable/fximpacttable_load_db.h"
|
||||
#include "Game/IW5/XAssets/fxworld/fxworld_load_db.h"
|
||||
#include "Game/IW5/XAssets/gfximage/gfximage_load_db.h"
|
||||
#include "Game/IW5/XAssets/gfxlightdef/gfxlightdef_load_db.h"
|
||||
#include "Game/IW5/XAssets/gfxworld/gfxworld_load_db.h"
|
||||
#include "Game/IW5/XAssets/glassworld/glassworld_load_db.h"
|
||||
#include "Game/IW5/XAssets/leaderboarddef/leaderboarddef_load_db.h"
|
||||
#include "Game/IW5/XAssets/loadedsound/loadedsound_load_db.h"
|
||||
#include "Game/IW5/XAssets/localizeentry/localizeentry_load_db.h"
|
||||
#include "Game/IW5/XAssets/mapents/mapents_load_db.h"
|
||||
#include "Game/IW5/XAssets/material/material_load_db.h"
|
||||
#include "Game/IW5/XAssets/materialpixelshader/materialpixelshader_load_db.h"
|
||||
#include "Game/IW5/XAssets/materialtechniqueset/materialtechniqueset_load_db.h"
|
||||
#include "Game/IW5/XAssets/materialvertexdeclaration/materialvertexdeclaration_load_db.h"
|
||||
#include "Game/IW5/XAssets/materialvertexshader/materialvertexshader_load_db.h"
|
||||
#include "Game/IW5/XAssets/menudef_t/menudef_t_load_db.h"
|
||||
#include "Game/IW5/XAssets/menulist/menulist_load_db.h"
|
||||
#include "Game/IW5/XAssets/pathdata/pathdata_load_db.h"
|
||||
#include "Game/IW5/XAssets/physcollmap/physcollmap_load_db.h"
|
||||
#include "Game/IW5/XAssets/physpreset/physpreset_load_db.h"
|
||||
#include "Game/IW5/XAssets/rawfile/rawfile_load_db.h"
|
||||
#include "Game/IW5/XAssets/scriptfile/scriptfile_load_db.h"
|
||||
#include "Game/IW5/XAssets/snd_alias_list_t/snd_alias_list_t_load_db.h"
|
||||
#include "Game/IW5/XAssets/sndcurve/sndcurve_load_db.h"
|
||||
#include "Game/IW5/XAssets/stringtable/stringtable_load_db.h"
|
||||
#include "Game/IW5/XAssets/structureddatadefset/structureddatadefset_load_db.h"
|
||||
#include "Game/IW5/XAssets/surfacefxtable/surfacefxtable_load_db.h"
|
||||
#include "Game/IW5/XAssets/tracerdef/tracerdef_load_db.h"
|
||||
#include "Game/IW5/XAssets/vehicledef/vehicledef_load_db.h"
|
||||
#include "Game/IW5/XAssets/vehicletrack/vehicletrack_load_db.h"
|
||||
#include "Game/IW5/XAssets/weaponattachment/weaponattachment_load_db.h"
|
||||
#include "Game/IW5/XAssets/weaponcompletedef/weaponcompletedef_load_db.h"
|
||||
#include "Game/IW5/XAssets/xanimparts/xanimparts_load_db.h"
|
||||
#include "Game/IW5/XAssets/xmodel/xmodel_load_db.h"
|
||||
#include "Game/IW5/XAssets/xmodelsurfs/xmodelsurfs_load_db.h"
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
ContentLoader::ContentLoader()
|
||||
{
|
||||
varXAsset = nullptr;
|
||||
varScriptStringList = nullptr;
|
||||
}
|
||||
|
||||
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
||||
{
|
||||
assert(m_zone->m_script_strings.Empty());
|
||||
|
||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||
|
||||
if (atStreamStart)
|
||||
m_stream->Load<ScriptStringList>(varScriptStringList);
|
||||
|
||||
if (varScriptStringList->strings != nullptr)
|
||||
{
|
||||
assert(varScriptStringList->strings == PTR_FOLLOWING);
|
||||
|
||||
varScriptStringList->strings = m_stream->Alloc<const char*>(alignof(const char*));
|
||||
varXString = varScriptStringList->strings;
|
||||
LoadXStringArray(true, varScriptStringList->count);
|
||||
|
||||
for (int i = 0; i < varScriptStringList->count; i++)
|
||||
{
|
||||
if (varScriptStringList->strings[i])
|
||||
{
|
||||
m_zone->m_script_strings.AddScriptString(varScriptStringList->strings[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_zone->m_script_strings.AddScriptString("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_stream->PopBlock();
|
||||
|
||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||
}
|
||||
|
||||
void ContentLoader::LoadXAsset(const bool atStreamStart)
|
||||
{
|
||||
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
||||
case type_index: \
|
||||
{ \
|
||||
Loader_##typeName loader(m_zone, m_stream); \
|
||||
loader.Load(&varXAsset->header.headerEntry); \
|
||||
break; \
|
||||
}
|
||||
#define SKIP_ASSET(type_index, typeName, headerEntry) \
|
||||
case type_index: \
|
||||
break;
|
||||
|
||||
assert(varXAsset != nullptr);
|
||||
|
||||
if (atStreamStart)
|
||||
m_stream->Load<XAsset>(varXAsset);
|
||||
|
||||
switch (varXAsset->type)
|
||||
{
|
||||
LOAD_ASSET(ASSET_TYPE_PHYSPRESET, PhysPreset, physPreset)
|
||||
LOAD_ASSET(ASSET_TYPE_PHYSCOLLMAP, PhysCollmap, physCollmap)
|
||||
LOAD_ASSET(ASSET_TYPE_XANIMPARTS, XAnimParts, parts)
|
||||
LOAD_ASSET(ASSET_TYPE_XMODEL_SURFS, XModelSurfs, modelSurfs)
|
||||
LOAD_ASSET(ASSET_TYPE_XMODEL, XModel, model)
|
||||
LOAD_ASSET(ASSET_TYPE_MATERIAL, Material, material)
|
||||
LOAD_ASSET(ASSET_TYPE_PIXELSHADER, MaterialPixelShader, pixelShader)
|
||||
LOAD_ASSET(ASSET_TYPE_VERTEXSHADER, MaterialVertexShader, vertexShader)
|
||||
LOAD_ASSET(ASSET_TYPE_VERTEXDECL, MaterialVertexDeclaration, vertexDecl)
|
||||
LOAD_ASSET(ASSET_TYPE_TECHNIQUE_SET, MaterialTechniqueSet, techniqueSet)
|
||||
LOAD_ASSET(ASSET_TYPE_IMAGE, GfxImage, image)
|
||||
LOAD_ASSET(ASSET_TYPE_SOUND, snd_alias_list_t, sound)
|
||||
LOAD_ASSET(ASSET_TYPE_SOUND_CURVE, SndCurve, sndCurve)
|
||||
LOAD_ASSET(ASSET_TYPE_LOADED_SOUND, LoadedSound, loadSnd)
|
||||
LOAD_ASSET(ASSET_TYPE_CLIPMAP, clipMap_t, clipMap)
|
||||
LOAD_ASSET(ASSET_TYPE_COMWORLD, ComWorld, comWorld)
|
||||
LOAD_ASSET(ASSET_TYPE_GLASSWORLD, GlassWorld, glassWorld)
|
||||
LOAD_ASSET(ASSET_TYPE_PATHDATA, PathData, pathData)
|
||||
LOAD_ASSET(ASSET_TYPE_VEHICLE_TRACK, VehicleTrack, vehicleTrack)
|
||||
LOAD_ASSET(ASSET_TYPE_MAP_ENTS, MapEnts, mapEnts)
|
||||
LOAD_ASSET(ASSET_TYPE_FXWORLD, FxWorld, fxWorld)
|
||||
LOAD_ASSET(ASSET_TYPE_GFXWORLD, GfxWorld, gfxWorld)
|
||||
LOAD_ASSET(ASSET_TYPE_LIGHT_DEF, GfxLightDef, lightDef)
|
||||
LOAD_ASSET(ASSET_TYPE_FONT, Font_s, font)
|
||||
LOAD_ASSET(ASSET_TYPE_MENULIST, MenuList, menuList)
|
||||
LOAD_ASSET(ASSET_TYPE_MENU, menuDef_t, menu)
|
||||
LOAD_ASSET(ASSET_TYPE_LOCALIZE_ENTRY, LocalizeEntry, localize)
|
||||
LOAD_ASSET(ASSET_TYPE_ATTACHMENT, WeaponAttachment, attachment)
|
||||
LOAD_ASSET(ASSET_TYPE_WEAPON, WeaponCompleteDef, weapon)
|
||||
LOAD_ASSET(ASSET_TYPE_FX, FxEffectDef, fx)
|
||||
LOAD_ASSET(ASSET_TYPE_IMPACT_FX, FxImpactTable, impactFx)
|
||||
LOAD_ASSET(ASSET_TYPE_SURFACE_FX, SurfaceFxTable, surfaceFx)
|
||||
LOAD_ASSET(ASSET_TYPE_RAWFILE, RawFile, rawfile)
|
||||
LOAD_ASSET(ASSET_TYPE_SCRIPTFILE, ScriptFile, scriptfile)
|
||||
LOAD_ASSET(ASSET_TYPE_STRINGTABLE, StringTable, stringTable)
|
||||
LOAD_ASSET(ASSET_TYPE_LEADERBOARD, LeaderboardDef, leaderboardDef)
|
||||
LOAD_ASSET(ASSET_TYPE_STRUCTURED_DATA_DEF, StructuredDataDefSet, structuredDataDefSet)
|
||||
LOAD_ASSET(ASSET_TYPE_TRACER, TracerDef, tracerDef)
|
||||
LOAD_ASSET(ASSET_TYPE_VEHICLE, VehicleDef, vehDef)
|
||||
LOAD_ASSET(ASSET_TYPE_ADDON_MAP_ENTS, AddonMapEnts, addonMapEnts)
|
||||
|
||||
default:
|
||||
{
|
||||
throw UnsupportedAssetTypeException(varXAsset->type);
|
||||
}
|
||||
}
|
||||
|
||||
#undef LOAD_ASSET
|
||||
}
|
||||
|
||||
void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count)
|
||||
{
|
||||
assert(varXAsset != nullptr);
|
||||
|
||||
if (atStreamStart)
|
||||
m_stream->Load<XAsset>(varXAsset, count);
|
||||
|
||||
for (asset_type_t assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
|
||||
{
|
||||
m_zone->m_pools->InitPoolDynamic(assetType);
|
||||
}
|
||||
|
||||
for (size_t index = 0; index < count; index++)
|
||||
{
|
||||
LoadXAsset(false);
|
||||
varXAsset++;
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
|
||||
{
|
||||
m_zone = zone;
|
||||
m_stream = stream;
|
||||
|
||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||
|
||||
XAssetList assetList{};
|
||||
m_stream->LoadDataRaw(&assetList, sizeof assetList);
|
||||
|
||||
varScriptStringList = &assetList.stringList;
|
||||
LoadScriptStringList(false);
|
||||
|
||||
if (assetList.assets != nullptr)
|
||||
{
|
||||
assert(assetList.assets == PTR_FOLLOWING);
|
||||
|
||||
assetList.assets = m_stream->Alloc<XAsset>(alignof(XAsset));
|
||||
varXAsset = assetList.assets;
|
||||
LoadXAssetArray(true, assetList.assetCount);
|
||||
}
|
||||
|
||||
m_stream->PopBlock();
|
||||
}
|
23
src/ZoneLoading/Game/IW5/ContentLoaderIW5.h
Normal file
23
src/ZoneLoading/Game/IW5/ContentLoaderIW5.h
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include "Loading/ContentLoaderBase.h"
|
||||
#include "Loading/IContentLoadingEntryPoint.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint
|
||||
{
|
||||
XAsset* varXAsset;
|
||||
ScriptStringList* varScriptStringList;
|
||||
|
||||
void LoadScriptStringList(bool atStreamStart);
|
||||
|
||||
void LoadXAsset(bool atStreamStart);
|
||||
void LoadXAssetArray(bool atStreamStart, size_t count);
|
||||
|
||||
public:
|
||||
ContentLoader();
|
||||
|
||||
void Load(Zone* zone, IZoneInputStream* stream) override;
|
||||
};
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
#include "gfximage_actions.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
Actions_GfxImage::Actions_GfxImage(Zone* zone)
|
||||
: AssetLoadingActions(zone)
|
||||
{
|
||||
}
|
||||
|
||||
void Actions_GfxImage::OnImageLoaded(GfxImage* image) const
|
||||
{
|
||||
image->cardMemory.platform[0] = 0;
|
||||
}
|
||||
|
||||
void Actions_GfxImage::LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) const
|
||||
{
|
||||
const size_t loadDefSize = offsetof(IW5::GfxImageLoadDef, data) + loadDef->resourceSize;
|
||||
|
||||
image->texture.loadDef = static_cast<GfxImageLoadDef*>(m_zone->GetMemory()->Alloc(loadDefSize));
|
||||
memcpy(image->texture.loadDef, loadDef, loadDefSize);
|
||||
}
|
16
src/ZoneLoading/Game/IW5/XAssets/gfximage/gfximage_actions.h
Normal file
16
src/ZoneLoading/Game/IW5/XAssets/gfximage/gfximage_actions.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/AssetLoadingActions.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
class Actions_GfxImage final : public AssetLoadingActions
|
||||
{
|
||||
public:
|
||||
explicit Actions_GfxImage(Zone* zone);
|
||||
|
||||
void OnImageLoaded(GfxImage* image) const;
|
||||
void LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) const;
|
||||
};
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
#include "loadedsound_actions.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
Actions_LoadedSound::Actions_LoadedSound(Zone* zone)
|
||||
: AssetLoadingActions(zone)
|
||||
{
|
||||
}
|
||||
|
||||
void Actions_LoadedSound::SetSoundData(MssSound* sound) const
|
||||
{
|
||||
if (sound->info.data_len > 0)
|
||||
{
|
||||
char* tempData = sound->data;
|
||||
sound->data = static_cast<char*>(m_zone->GetMemory()->Alloc(sound->info.data_len));
|
||||
memcpy(sound->data, tempData, sound->info.data_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
sound->data = nullptr;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/AssetLoadingActions.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
class Actions_LoadedSound final : public AssetLoadingActions
|
||||
{
|
||||
public:
|
||||
explicit Actions_LoadedSound(Zone* zone);
|
||||
|
||||
void SetSoundData(MssSound* sound) const;
|
||||
};
|
||||
}
|
19
src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.cpp
Normal file
19
src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "xmodel_actions.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
Actions_XModel::Actions_XModel(Zone* zone)
|
||||
: AssetLoadingActions(zone)
|
||||
{
|
||||
}
|
||||
|
||||
void Actions_XModel::SetModelSurfs(XModelLodInfo* lodInfo, XModelSurfs* modelSurfs) const
|
||||
{
|
||||
if(modelSurfs)
|
||||
{
|
||||
lodInfo->modelSurfs = m_zone->GetMemory()->Create<XModelSurfs>();
|
||||
memcpy(lodInfo->modelSurfs, modelSurfs, sizeof(XModelSurfs));
|
||||
}
|
||||
}
|
15
src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.h
Normal file
15
src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/AssetLoadingActions.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
class Actions_XModel final : public AssetLoadingActions
|
||||
{
|
||||
public:
|
||||
explicit Actions_XModel(Zone* zone);
|
||||
|
||||
void SetModelSurfs(XModelLodInfo* lodInfo, XModelSurfs* modelSurfs) const;
|
||||
};
|
||||
}
|
198
src/ZoneLoading/Game/IW5/ZoneLoaderFactoryIW5.cpp
Normal file
198
src/ZoneLoading/Game/IW5/ZoneLoaderFactoryIW5.cpp
Normal file
@ -0,0 +1,198 @@
|
||||
#include "ZoneLoaderFactoryIW5.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
|
||||
#include "Game/IW5/IW5.h"
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "ContentLoaderIW5.h"
|
||||
#include "Game/IW5/GameAssetPoolIW5.h"
|
||||
#include "Game/IW5/GameIW5.h"
|
||||
#include "Game/GameLanguage.h"
|
||||
#include "Game/IW5/ZoneConstantsIW5.h"
|
||||
#include "Loading/Processor/ProcessorAuthedBlocks.h"
|
||||
#include "Loading/Processor/ProcessorCaptureData.h"
|
||||
#include "Loading/Processor/ProcessorInflate.h"
|
||||
#include "Loading/Steps/StepVerifyMagic.h"
|
||||
#include "Loading/Steps/StepSkipBytes.h"
|
||||
#include "Loading/Steps/StepVerifyFileName.h"
|
||||
#include "Loading/Steps/StepLoadSignature.h"
|
||||
#include "Loading/Steps/StepVerifySignature.h"
|
||||
#include "Loading/Steps/StepAddProcessor.h"
|
||||
#include "Loading/Steps/StepAllocXBlocks.h"
|
||||
#include "Loading/Steps/StepLoadZoneContent.h"
|
||||
#include "Loading/Steps/StepLoadHash.h"
|
||||
#include "Loading/Steps/StepRemoveProcessor.h"
|
||||
#include "Loading/Steps/StepVerifyHash.h"
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
class ZoneLoaderFactory::Impl
|
||||
{
|
||||
static GameLanguage GetZoneLanguage(std::string& zoneName)
|
||||
{
|
||||
return GameLanguage::LANGUAGE_NONE;
|
||||
}
|
||||
|
||||
static bool CanLoad(ZoneHeader& header, bool* isSecure, bool* isOfficial)
|
||||
{
|
||||
assert(isSecure != nullptr);
|
||||
assert(isOfficial != nullptr);
|
||||
|
||||
if (header.m_version != ZoneConstants::ZONE_VERSION)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED_INFINITY_WARD, std::char_traits<char>::length(ZoneConstants::MAGIC_SIGNED_INFINITY_WARD)))
|
||||
{
|
||||
*isSecure = true;
|
||||
*isOfficial = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_UNSIGNED, std::char_traits<char>::length(ZoneConstants::MAGIC_UNSIGNED)))
|
||||
{
|
||||
*isSecure = false;
|
||||
*isOfficial = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void SetupBlock(ZoneLoader* zoneLoader)
|
||||
{
|
||||
#define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type)
|
||||
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW5::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW5::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW5::XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW5::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW5::XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW5::XFILE_BLOCK_CALLBACK, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW5::XFILE_BLOCK_SCRIPT, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
|
||||
#undef XBLOCK_DEF
|
||||
}
|
||||
|
||||
static std::unique_ptr<IPublicKeyAlgorithm> SetupRSA(const bool isOfficial)
|
||||
{
|
||||
if (isOfficial)
|
||||
{
|
||||
auto rsa = Crypto::CreateRSA(IPublicKeyAlgorithm::HashingAlgorithm::RSA_HASH_SHA256,
|
||||
Crypto::RSAPaddingMode::RSA_PADDING_PSS);
|
||||
|
||||
if (!rsa->SetKey(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD, sizeof(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD)))
|
||||
{
|
||||
printf("Invalid public key for signature checking\n");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return rsa;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
|
||||
// TODO: Load custom RSA key here
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void AddAuthHeaderSteps(const bool isSecure, const bool isOfficial, ZoneLoader* zoneLoader,
|
||||
std::string& fileName)
|
||||
{
|
||||
// Unsigned zones do not have an auth header
|
||||
if (!isSecure)
|
||||
return;
|
||||
|
||||
// If file is signed setup a RSA instance.
|
||||
auto rsa = SetupRSA(isOfficial);
|
||||
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER));
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
||||
|
||||
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof DB_AuthHash::bytes, 1);
|
||||
auto* subHeaderHashPtr = subHeaderHash.get();
|
||||
zoneLoader->AddLoadingStep(std::move(subHeaderHash));
|
||||
|
||||
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof DB_AuthSignature::bytes);
|
||||
auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get();
|
||||
zoneLoader->AddLoadingStep(std::move(subHeaderHashSignature));
|
||||
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepVerifySignature>(std::move(rsa), subHeaderHashSignaturePtr, subHeaderHashPtr));
|
||||
|
||||
auto subHeaderCapture = std::make_unique<ProcessorCaptureData>(sizeof(DB_AuthSubHeader));
|
||||
auto* subHeaderCapturePtr = subHeaderCapture.get();
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::move(subHeaderCapture)));
|
||||
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
||||
|
||||
auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof DB_AuthHash::bytes, std::extent<decltype(DB_AuthSubHeader::masterBlockHashes)>::value);
|
||||
auto* masterBlockHashesPtr = masterBlockHashes.get();
|
||||
zoneLoader->AddLoadingStep(std::move(masterBlockHashes));
|
||||
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyHash>(std::unique_ptr<IHashFunction>(Crypto::CreateSHA256()), 0, subHeaderHashPtr, subHeaderCapturePtr));
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepRemoveProcessor>(subHeaderCapturePtr));
|
||||
|
||||
// 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<StepAddProcessor>(std::make_unique<ProcessorAuthedBlocks>(
|
||||
ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP, ZoneConstants::AUTHED_CHUNK_SIZE, std::extent<decltype(DB_AuthSubHeader::masterBlockHashes)>::value,
|
||||
std::unique_ptr<IHashFunction>(Crypto::CreateSHA256()), masterBlockHashesPtr)));
|
||||
}
|
||||
|
||||
public:
|
||||
static ZoneLoader* CreateLoaderForHeader(ZoneHeader& header, std::string& fileName)
|
||||
{
|
||||
bool isSecure;
|
||||
bool isOfficial;
|
||||
|
||||
// Check if this file is a supported IW4 zone.
|
||||
if (!CanLoad(header, &isSecure, &isOfficial))
|
||||
return nullptr;
|
||||
|
||||
// Create new zone
|
||||
auto zone = std::make_unique<Zone>(fileName, 0, &g_GameIW5);
|
||||
auto* zonePtr = zone.get();
|
||||
zone->m_pools = std::make_unique<GameAssetPoolIW5>(zonePtr, 0);
|
||||
zone->m_language = GetZoneLanguage(fileName);
|
||||
|
||||
// File is supported. Now setup all required steps for loading this file.
|
||||
auto* zoneLoader = new ZoneLoader(std::move(zone));
|
||||
|
||||
SetupBlock(zoneLoader);
|
||||
|
||||
// Skip unknown 1 byte field that the game ignores as well
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(1));
|
||||
|
||||
// Skip timestamp
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8));
|
||||
|
||||
// Add steps for loading the auth header which also contain the signature of the zone if it is signed.
|
||||
AddAuthHeaderSteps(isSecure, isOfficial, zoneLoader, fileName);
|
||||
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::make_unique<ProcessorInflate>(ZoneConstants::AUTHED_CHUNK_SIZE)));
|
||||
|
||||
// Start of the XFile struct
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8));
|
||||
// Skip size and externalSize fields since they are not interesting for us
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>());
|
||||
|
||||
// Start of the zone content
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepLoadZoneContent>(std::make_unique<ContentLoader>(), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
|
||||
|
||||
// Return the fully setup zoneloader
|
||||
return zoneLoader;
|
||||
}
|
||||
};
|
||||
|
||||
ZoneLoader* ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& header, std::string& fileName)
|
||||
{
|
||||
return Impl::CreateLoaderForHeader(header, fileName);
|
||||
}
|
15
src/ZoneLoading/Game/IW5/ZoneLoaderFactoryIW5.h
Normal file
15
src/ZoneLoading/Game/IW5/ZoneLoaderFactoryIW5.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/IZoneLoaderFactory.h"
|
||||
#include <string>
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
class ZoneLoaderFactory final : public IZoneLoaderFactory
|
||||
{
|
||||
class Impl;
|
||||
|
||||
public:
|
||||
ZoneLoader* CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) override;
|
||||
};
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "Game/IW3/ZoneLoaderFactoryIW3.h"
|
||||
#include "Game/IW4/ZoneLoaderFactoryIW4.h"
|
||||
#include "Game/IW5/ZoneLoaderFactoryIW5.h"
|
||||
#include "Game/T5/ZoneLoaderFactoryT5.h"
|
||||
#include "Game/T6/ZoneLoaderFactoryT6.h"
|
||||
#include "Utils/ObjFileStream.h"
|
||||
@ -16,6 +17,7 @@ IZoneLoaderFactory* ZoneLoaderFactories[]
|
||||
{
|
||||
new IW3::ZoneLoaderFactory(),
|
||||
new IW4::ZoneLoaderFactory(),
|
||||
new IW5::ZoneLoaderFactory(),
|
||||
new T5::ZoneLoaderFactory(),
|
||||
new T6::ZoneLoaderFactory()
|
||||
};
|
||||
|
Reference in New Issue
Block a user