mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-11 07:18:11 -05:00
Read IW4 signed headers
This commit is contained in:
228
src/ZoneLoading/Game/IW4/ContentLoaderIW4.cpp
Normal file
228
src/ZoneLoading/Game/IW4/ContentLoaderIW4.cpp
Normal file
@ -0,0 +1,228 @@
|
||||
#include "ContentLoaderIW4.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Loading/Exception/UnsupportedAssetTypeException.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
//#include "Game/T6/XAssets/addonmapents/addonmapents_load_db.h"
|
||||
//#include "Game/T6/XAssets/clipmap_t/clipmap_t_load_db.h"
|
||||
//#include "Game/T6/XAssets/comworld/comworld_load_db.h"
|
||||
//#include "Game/T6/XAssets/ddlroot_t/ddlroot_t_load_db.h"
|
||||
//#include "Game/T6/XAssets/destructibledef/destructibledef_load_db.h"
|
||||
//#include "Game/T6/XAssets/emblemset/emblemset_load_db.h"
|
||||
//#include "Game/T6/XAssets/font_s/font_s_load_db.h"
|
||||
//#include "Game/T6/XAssets/fonticon/fonticon_load_db.h"
|
||||
//#include "Game/T6/XAssets/footstepfxtabledef/footstepfxtabledef_load_db.h"
|
||||
//#include "Game/T6/XAssets/footsteptabledef/footsteptabledef_load_db.h"
|
||||
//#include "Game/T6/XAssets/fxeffectdef/fxeffectdef_load_db.h"
|
||||
//#include "Game/T6/XAssets/fximpacttable/fximpacttable_load_db.h"
|
||||
//#include "Game/T6/XAssets/gameworldmp/gameworldmp_load_db.h"
|
||||
//#include "Game/T6/XAssets/gameworldsp/gameworldsp_load_db.h"
|
||||
//#include "Game/T6/XAssets/gfximage/gfximage_load_db.h"
|
||||
//#include "Game/T6/XAssets/gfxlightdef/gfxlightdef_load_db.h"
|
||||
//#include "Game/T6/XAssets/gfxworld/gfxworld_load_db.h"
|
||||
//#include "Game/T6/XAssets/glasses/glasses_load_db.h"
|
||||
//#include "Game/T6/XAssets/keyvaluepairs/keyvaluepairs_load_db.h"
|
||||
//#include "Game/T6/XAssets/leaderboarddef/leaderboarddef_load_db.h"
|
||||
//#include "Game/T6/XAssets/localizeentry/localizeentry_load_db.h"
|
||||
//#include "Game/T6/XAssets/mapents/mapents_load_db.h"
|
||||
//#include "Game/T6/XAssets/material/material_load_db.h"
|
||||
//#include "Game/T6/XAssets/materialtechniqueset/materialtechniqueset_load_db.h"
|
||||
//#include "Game/T6/XAssets/memoryblock/memoryblock_load_db.h"
|
||||
//#include "Game/T6/XAssets/menudef_t/menudef_t_load_db.h"
|
||||
//#include "Game/T6/XAssets/menulist/menulist_load_db.h"
|
||||
//#include "Game/T6/XAssets/physconstraints/physconstraints_load_db.h"
|
||||
//#include "Game/T6/XAssets/physpreset/physpreset_load_db.h"
|
||||
//#include "Game/T6/XAssets/qdb/qdb_load_db.h"
|
||||
//#include "Game/T6/XAssets/rawfile/rawfile_load_db.h"
|
||||
//#include "Game/T6/XAssets/scriptparsetree/scriptparsetree_load_db.h"
|
||||
//#include "Game/T6/XAssets/skinnedvertsdef/skinnedvertsdef_load_db.h"
|
||||
//#include "Game/T6/XAssets/slug/slug_load_db.h"
|
||||
//#include "Game/T6/XAssets/sndbank/sndbank_load_db.h"
|
||||
//#include "Game/T6/XAssets/snddriverglobals/snddriverglobals_load_db.h"
|
||||
//#include "Game/T6/XAssets/sndpatch/sndpatch_load_db.h"
|
||||
//#include "Game/T6/XAssets/stringtable/stringtable_load_db.h"
|
||||
//#include "Game/T6/XAssets/tracerdef/tracerdef_load_db.h"
|
||||
//#include "Game/T6/XAssets/vehicledef/vehicledef_load_db.h"
|
||||
//#include "Game/T6/XAssets/weaponattachment/weaponattachment_load_db.h"
|
||||
//#include "Game/T6/XAssets/weaponattachmentunique/weaponattachmentunique_load_db.h"
|
||||
//#include "Game/T6/XAssets/weaponcamo/weaponcamo_load_db.h"
|
||||
//#include "Game/T6/XAssets/weaponvariantdef/weaponvariantdef_load_db.h"
|
||||
//#include "Game/T6/XAssets/xanimparts/xanimparts_load_db.h"
|
||||
//#include "Game/T6/XAssets/xglobals/xglobals_load_db.h"
|
||||
//#include "Game/T6/XAssets/xmodel/xmodel_load_db.h"
|
||||
//#include "Game/T6/XAssets/zbarrierdef/zbarrierdef_load_db.h"
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
ContentLoaderIW4::ContentLoaderIW4()
|
||||
{
|
||||
varXAsset = nullptr;
|
||||
varScriptStringList = nullptr;
|
||||
|
||||
// Script String 0 is always empty string
|
||||
m_script_strings.emplace_back("");
|
||||
}
|
||||
|
||||
void ContentLoaderIW4::LoadScriptStringList(const bool atStreamStart)
|
||||
{
|
||||
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_script_strings.emplace_back(varScriptStringList->strings[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_script_strings.emplace_back("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_stream->PopBlock();
|
||||
}
|
||||
|
||||
void ContentLoaderIW4::LoadXAsset(const bool atStreamStart)
|
||||
{
|
||||
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
||||
case type_index: \
|
||||
{ \
|
||||
Loader_##typeName loader(this, m_zone, m_stream); \
|
||||
loader.Load(&varXAsset->header.headerEntry); \
|
||||
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_PHYSCONSTRAINTS, PhysConstraints, physConstraints);
|
||||
//LOAD_ASSET(ASSET_TYPE_DESTRUCTIBLEDEF, DestructibleDef, destructibleDef);
|
||||
//LOAD_ASSET(ASSET_TYPE_XANIMPARTS, XAnimParts, parts);
|
||||
//LOAD_ASSET(ASSET_TYPE_XMODEL, XModel, model);
|
||||
//LOAD_ASSET(ASSET_TYPE_MATERIAL, Material, material);
|
||||
//LOAD_ASSET(ASSET_TYPE_TECHNIQUE_SET, MaterialTechniqueSet, techniqueSet);
|
||||
//LOAD_ASSET(ASSET_TYPE_IMAGE, GfxImage, image);
|
||||
//LOAD_ASSET(ASSET_TYPE_SOUND, SndBank, sound);
|
||||
//LOAD_ASSET(ASSET_TYPE_SOUND_PATCH, SndPatch, soundPatch);
|
||||
//LOAD_ASSET(ASSET_TYPE_CLIPMAP, clipMap_t, clipMap);
|
||||
//LOAD_ASSET(ASSET_TYPE_CLIPMAP_PVS, clipMap_t, clipMap);
|
||||
//LOAD_ASSET(ASSET_TYPE_COMWORLD, ComWorld, comWorld);
|
||||
//LOAD_ASSET(ASSET_TYPE_GAMEWORLD_SP, GameWorldSp, gameWorldSp);
|
||||
//LOAD_ASSET(ASSET_TYPE_GAMEWORLD_MP, GameWorldMp, gameWorldMp);
|
||||
//LOAD_ASSET(ASSET_TYPE_MAP_ENTS, MapEnts, mapEnts);
|
||||
//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_FONTICON, FontIcon, fontIcon);
|
||||
//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_WEAPON, WeaponVariantDef, weapon);
|
||||
//LOAD_ASSET(ASSET_TYPE_ATTACHMENT, WeaponAttachment, attachment);
|
||||
//LOAD_ASSET(ASSET_TYPE_ATTACHMENT_UNIQUE, WeaponAttachmentUnique, attachmentUnique);
|
||||
//LOAD_ASSET(ASSET_TYPE_WEAPON_CAMO, WeaponCamo, weaponCamo);
|
||||
//LOAD_ASSET(ASSET_TYPE_SNDDRIVER_GLOBALS, SndDriverGlobals, sndDriverGlobals);
|
||||
//LOAD_ASSET(ASSET_TYPE_FX, FxEffectDef, fx);
|
||||
//LOAD_ASSET(ASSET_TYPE_IMPACT_FX, FxImpactTable, impactFx);
|
||||
//LOAD_ASSET(ASSET_TYPE_RAWFILE, RawFile, rawfile);
|
||||
//LOAD_ASSET(ASSET_TYPE_STRINGTABLE, StringTable, stringTable);
|
||||
//LOAD_ASSET(ASSET_TYPE_LEADERBOARD, LeaderboardDef, leaderboardDef);
|
||||
//LOAD_ASSET(ASSET_TYPE_XGLOBALS, XGlobals, xGlobals);
|
||||
//LOAD_ASSET(ASSET_TYPE_DDL, ddlRoot_t, ddlRoot);
|
||||
//LOAD_ASSET(ASSET_TYPE_GLASSES, Glasses, glasses);
|
||||
//LOAD_ASSET(ASSET_TYPE_EMBLEMSET, EmblemSet, emblemSet);
|
||||
//LOAD_ASSET(ASSET_TYPE_SCRIPTPARSETREE, ScriptParseTree, scriptParseTree);
|
||||
//LOAD_ASSET(ASSET_TYPE_KEYVALUEPAIRS, KeyValuePairs, keyValuePairs);
|
||||
//LOAD_ASSET(ASSET_TYPE_VEHICLEDEF, VehicleDef, vehicleDef);
|
||||
//// LOAD_ASSET(ASSET_TYPE_MEMORYBLOCK, MemoryBlock, memoryBlock);
|
||||
//LOAD_ASSET(ASSET_TYPE_ADDON_MAP_ENTS, AddonMapEnts, addonMapEnts);
|
||||
//LOAD_ASSET(ASSET_TYPE_TRACER, TracerDef, tracerDef);
|
||||
//LOAD_ASSET(ASSET_TYPE_SKINNEDVERTS, SkinnedVertsDef, skinnedVertsDef);
|
||||
//LOAD_ASSET(ASSET_TYPE_QDB, Qdb, qdb);
|
||||
//LOAD_ASSET(ASSET_TYPE_SLUG, Slug, slug);
|
||||
//LOAD_ASSET(ASSET_TYPE_FOOTSTEP_TABLE, FootstepTableDef, footstepTableDef);
|
||||
//LOAD_ASSET(ASSET_TYPE_FOOTSTEPFX_TABLE, FootstepFXTableDef, footstepFXTableDef);
|
||||
//LOAD_ASSET(ASSET_TYPE_ZBARRIER, ZBarrierDef, zbarrierDef);
|
||||
|
||||
default:
|
||||
{
|
||||
throw UnsupportedAssetTypeException(varXAsset->type);
|
||||
}
|
||||
}
|
||||
|
||||
#undef LOAD_ASSET
|
||||
}
|
||||
|
||||
void ContentLoaderIW4::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->GetPools()->InitPoolDynamic(assetType);
|
||||
}
|
||||
|
||||
for (size_t index = 0; index < count; index++)
|
||||
{
|
||||
LoadXAsset(false);
|
||||
varXAsset++;
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoaderIW4::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();
|
||||
}
|
||||
|
||||
std::string& ContentLoaderIW4::GetZoneScriptString(const scr_string_t scrString)
|
||||
{
|
||||
assert(scrString >= 0 && scrString < m_script_strings.size());
|
||||
|
||||
if (scrString < 0 || scrString >= m_script_strings.size())
|
||||
{
|
||||
return m_script_strings[0];
|
||||
}
|
||||
|
||||
return m_script_strings[scrString];
|
||||
}
|
23
src/ZoneLoading/Game/IW4/ContentLoaderIW4.h
Normal file
23
src/ZoneLoading/Game/IW4/ContentLoaderIW4.h
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include "Loading/ContentLoader.h"
|
||||
#include "Loading/IContentLoadingEntryPoint.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Loading/IZoneScriptStringProvider.h"
|
||||
|
||||
class ContentLoaderIW4 final : public ContentLoader, public IContentLoadingEntryPoint, public IZoneScriptStringProvider
|
||||
{
|
||||
std::vector<std::string> m_script_strings;
|
||||
IW4::XAsset* varXAsset;
|
||||
IW4::ScriptStringList* varScriptStringList;
|
||||
|
||||
void LoadScriptStringList(bool atStreamStart);
|
||||
|
||||
void LoadXAsset(bool atStreamStart);
|
||||
void LoadXAssetArray(bool atStreamStart, size_t count);
|
||||
|
||||
public:
|
||||
ContentLoaderIW4();
|
||||
|
||||
void Load(Zone* zone, IZoneInputStream* stream) override;
|
||||
std::string& GetZoneScriptString(scr_string_t scrString) override;
|
||||
};
|
234
src/ZoneLoading/Game/IW4/ZoneLoaderFactoryIW4.cpp
Normal file
234
src/ZoneLoading/Game/IW4/ZoneLoaderFactoryIW4.cpp
Normal file
@ -0,0 +1,234 @@
|
||||
#include "ZoneLoaderFactoryIW4.h"
|
||||
#include "Game/IW4/IW4.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 "Utils/ClassUtils.h"
|
||||
#include <cassert>
|
||||
#include "Loading/Steps/StepLoadZoneContent.h"
|
||||
#include "ContentLoaderIW4.h"
|
||||
#include "Game/IW4/GameAssetPoolIW4.h"
|
||||
#include "Game/IW4/GameIW4.h"
|
||||
#include "Game/GameLanguage.h"
|
||||
#include "Loading/Processor/ProcessorCaptureData.h"
|
||||
#include "Loading/Steps/StepLoadHash.h"
|
||||
#include "Loading/Steps/StepRemoveProcessor.h"
|
||||
#include "Loading/Steps/StepVerifyHash.h"
|
||||
|
||||
const std::string ZoneLoaderFactoryIW4::MAGIC_SIGNED_INFINITY_WARD = "IWff0100";
|
||||
const std::string ZoneLoaderFactoryIW4::MAGIC_UNSIGNED = "IWffu100";
|
||||
const int ZoneLoaderFactoryIW4::VERSION = 276;
|
||||
|
||||
const int ZoneLoaderFactoryIW4::STREAM_COUNT = 4;
|
||||
const int ZoneLoaderFactoryIW4::VANILLA_BUFFER_SIZE = 0x80000;
|
||||
const int ZoneLoaderFactoryIW4::OFFSET_BLOCK_BIT_COUNT = 4;
|
||||
const block_t ZoneLoaderFactoryIW4::INSERT_BLOCK = IW4::XFILE_BLOCK_VIRTUAL;
|
||||
|
||||
const std::string ZoneLoaderFactoryIW4::MAGIC_AUTH_HEADER = "IWffs100";
|
||||
|
||||
const uint8_t ZoneLoaderFactoryIW4::RSA_PUBLIC_KEY_INFINITY_WARD[]
|
||||
{
|
||||
0x30, 0x82, 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01,
|
||||
0x00, 0xA5, 0x86, 0xCC, 0x18, 0xA9, 0x12, 0x17,
|
||||
0x4F, 0x3A, 0xC9, 0x0C, 0xD2, 0x38, 0x5D, 0xDB,
|
||||
0x67, 0x62, 0xA4, 0xE3, 0xD4, 0x42, 0x05, 0x8A,
|
||||
0x57, 0x0C, 0x31, 0x4E, 0x19, 0xE4, 0xBA, 0x89,
|
||||
0x73, 0x13, 0xDB, 0x72, 0x25, 0x63, 0xB1, 0x2F,
|
||||
0xD7, 0xF1, 0x08, 0x48, 0x34, 0x06, 0xD7, 0x84,
|
||||
0x5F, 0xC8, 0xCF, 0x2F, 0xB6, 0xA3, 0x5A, 0x8F,
|
||||
0x7E, 0xAA, 0x9D, 0x51, 0xE7, 0x0F, 0xB9, 0x07,
|
||||
0xB7, 0x30, 0x91, 0x04, 0x39, 0x9C, 0xDC, 0x1C,
|
||||
0xF1, 0x16, 0xCB, 0x96, 0x10, 0xEB, 0x38, 0xB1,
|
||||
0x3B, 0xBA, 0x42, 0xE3, 0xE2, 0x78, 0xBD, 0x77,
|
||||
0x82, 0x1A, 0x2B, 0x54, 0x27, 0x0A, 0xF7, 0x66,
|
||||
0x06, 0xAD, 0x46, 0x39, 0xC0, 0xEB, 0xB5, 0xC2,
|
||||
0x27, 0xDD, 0x2C, 0x08, 0x62, 0x2C, 0x0B, 0xC4,
|
||||
0x00, 0x0D, 0xCB, 0xAD, 0x22, 0x67, 0x01, 0xA6,
|
||||
0x92, 0x9C, 0x00, 0xAF, 0x9D, 0x55, 0xCC, 0x68,
|
||||
0xEC, 0x39, 0x49, 0x85, 0x7E, 0x2C, 0x98, 0xCF,
|
||||
0x4C, 0x12, 0x8D, 0xED, 0xC7, 0x1D, 0x21, 0x54,
|
||||
0x9C, 0x2F, 0xC9, 0x54, 0x36, 0x08, 0xA9, 0x67,
|
||||
0xEE, 0x91, 0xE6, 0xD9, 0xB1, 0xFA, 0xA9, 0x2B,
|
||||
0x88, 0xAD, 0x2A, 0xD0, 0xAA, 0x28, 0xF9, 0x47,
|
||||
0xA6, 0x0F, 0xCF, 0x55, 0x4C, 0x9B, 0x26, 0x41,
|
||||
0x89, 0x76, 0x11, 0xFD, 0x1B, 0x83, 0xE4, 0xE8,
|
||||
0x8E, 0x7E, 0xB4, 0x03, 0xA3, 0x29, 0xDD, 0x4F,
|
||||
0xAC, 0x99, 0xBE, 0x7C, 0xD3, 0xFD, 0x14, 0x28,
|
||||
0x1C, 0x59, 0x69, 0xE0, 0x79, 0x5F, 0x4B, 0xDA,
|
||||
0x6B, 0xAB, 0x48, 0x4E, 0x28, 0x39, 0x84, 0xC6,
|
||||
0x2B, 0xC6, 0x20, 0x05, 0xDB, 0x05, 0x21, 0xC3,
|
||||
0xE1, 0xD4, 0x20, 0x28, 0xDD, 0x3A, 0x4D, 0x51,
|
||||
0xE7, 0x49, 0x8A, 0x49, 0xEF, 0xF5, 0xDA, 0xDA,
|
||||
0x7D, 0x5D, 0xA8, 0x0B, 0xA1, 0x77, 0xCD, 0x62,
|
||||
0x7D, 0x9D, 0x40, 0x26, 0x44, 0x4B, 0x3B, 0x0A,
|
||||
0x89, 0x02, 0x03, 0x01, 0x00, 0x01
|
||||
};
|
||||
|
||||
class ZoneLoaderFactoryIW4::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 != VERSION)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!memcmp(header.m_magic, MAGIC_SIGNED_INFINITY_WARD.c_str(), 8))
|
||||
{
|
||||
*isSecure = true;
|
||||
*isOfficial = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!memcmp(header.m_magic, MAGIC_UNSIGNED.c_str(), 8))
|
||||
{
|
||||
*isSecure = false;
|
||||
*isOfficial = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void SetupBlock(ZoneLoader* zoneLoader)
|
||||
{
|
||||
#define XBLOCK_DEF(name, type) new XBlock(STR(name), name, type)
|
||||
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW4::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW4::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW4::XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW4::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW4::XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW4::XFILE_BLOCK_CALLBACK, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW4::XFILE_BLOCK_VERTEX, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
zoneLoader->AddXBlock(XBLOCK_DEF(IW4::XFILE_BLOCK_INDEX, XBlock::Type::BLOCK_TYPE_NORMAL));
|
||||
|
||||
#undef XBLOCK_DEF
|
||||
}
|
||||
|
||||
static IPublicKeyAlgorithm* SetupRSA(const bool isOfficial)
|
||||
{
|
||||
if (isOfficial)
|
||||
{
|
||||
auto* rsa = Crypto::CreateRSA(IPublicKeyAlgorithm::HashingAlgorithm::RSA_HASH_SHA256,
|
||||
Crypto::RSAPaddingMode::RSA_PADDING_PSS);
|
||||
|
||||
if (!rsa->SetKey(RSA_PUBLIC_KEY_INFINITY_WARD, sizeof(RSA_PUBLIC_KEY_INFINITY_WARD)))
|
||||
{
|
||||
printf("Invalid public key for signature checking\n");
|
||||
|
||||
delete rsa;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return rsa;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
|
||||
// TODO: Load custom RSA key here
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static IHashProvider* AddAuthHeaderSteps(const bool isSecure, const bool isOfficial, ZoneLoader* zoneLoader, std::string& fileName)
|
||||
{
|
||||
// Unsigned zones do not have an auth header
|
||||
if (!isSecure)
|
||||
return nullptr;
|
||||
|
||||
// If file is signed setup a RSA instance.
|
||||
IPublicKeyAlgorithm* rsa = SetupRSA(isOfficial);
|
||||
auto sha256 = std::unique_ptr<IHashFunction>(Crypto::CreateSHA256());
|
||||
|
||||
zoneLoader->AddLoadingStep(new StepVerifyMagic(MAGIC_AUTH_HEADER.c_str()));
|
||||
zoneLoader->AddLoadingStep(new StepSkipBytes(4)); // Skip reserved
|
||||
|
||||
auto* subheaderHash = new StepLoadHash(sizeof IW4::DB_AuthHash::bytes, 1);
|
||||
zoneLoader->AddLoadingStep(subheaderHash);
|
||||
|
||||
auto* subheaderHashSignature = new StepLoadSignature(sizeof IW4::DB_AuthSignature::bytes);
|
||||
zoneLoader->AddLoadingStep(subheaderHashSignature);
|
||||
|
||||
zoneLoader->AddLoadingStep(new StepVerifySignature(rsa, subheaderHashSignature, subheaderHash));
|
||||
|
||||
auto* subHeaderCapture = new ProcessorCaptureData(sizeof(IW4::DB_AuthSubHeader));
|
||||
zoneLoader->AddLoadingStep(new StepAddProcessor(subHeaderCapture));
|
||||
|
||||
zoneLoader->AddLoadingStep(new StepVerifyFileName(fileName, sizeof IW4::DB_AuthSubHeader::fastfileName));
|
||||
zoneLoader->AddLoadingStep(new StepSkipBytes(4)); // Skip reserved
|
||||
auto* masterBlockHashes = new StepLoadHash(sizeof IW4::DB_AuthHash::bytes, _countof(IW4::DB_AuthSubHeader::masterBlockHashes));
|
||||
zoneLoader->AddLoadingStep(masterBlockHashes);
|
||||
|
||||
zoneLoader->AddLoadingStep(new StepRemoveProcessor(subHeaderCapture));
|
||||
zoneLoader->AddLoadingStep(new StepVerifyHash(std::move(sha256), 0, subheaderHash, subHeaderCapture));
|
||||
|
||||
return masterBlockHashes;
|
||||
}
|
||||
|
||||
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 = new Zone(fileName, 0, new GameAssetPoolIW4(0), &g_GameIW4);
|
||||
zone->m_language = GetZoneLanguage(fileName);
|
||||
|
||||
// File is supported. Now setup all required steps for loading this file.
|
||||
auto* zoneLoader = new ZoneLoader(zone);
|
||||
|
||||
SetupBlock(zoneLoader);
|
||||
|
||||
// Skip unknown 1 byte field that the game ignores as well
|
||||
zoneLoader->AddLoadingStep(new StepSkipBytes(1));
|
||||
|
||||
// Skip timestamp
|
||||
zoneLoader->AddLoadingStep(new StepSkipBytes(8));
|
||||
|
||||
// Add steps for loading the auth header which also contain the signature of the zone if it is signed.
|
||||
IHashProvider* masterBlockHashProvider = AddAuthHeaderSteps(isSecure, isOfficial, zoneLoader, fileName);
|
||||
|
||||
// Start of the XFile struct
|
||||
zoneLoader->AddLoadingStep(new StepSkipBytes(8));
|
||||
// Skip size and externalSize fields since they are not interesting for us
|
||||
zoneLoader->AddLoadingStep(new StepAllocXBlocks());
|
||||
|
||||
// Start of the zone content
|
||||
zoneLoader->AddLoadingStep(
|
||||
new StepLoadZoneContent(new ContentLoaderIW4(), zone, OFFSET_BLOCK_BIT_COUNT, INSERT_BLOCK));
|
||||
|
||||
/*if (isSecure)
|
||||
{
|
||||
zoneLoader->AddLoadingStep(new StepVerifySignature(rsa, signatureProvider, signatureDataProvider));
|
||||
}*/
|
||||
|
||||
// Return the fully setup zoneloader
|
||||
return zoneLoader;
|
||||
}
|
||||
};
|
||||
|
||||
ZoneLoader* ZoneLoaderFactoryIW4::CreateLoaderForHeader(ZoneHeader& header, std::string& fileName)
|
||||
{
|
||||
return Impl::CreateLoaderForHeader(header, fileName);
|
||||
}
|
24
src/ZoneLoading/Game/IW4/ZoneLoaderFactoryIW4.h
Normal file
24
src/ZoneLoading/Game/IW4/ZoneLoaderFactoryIW4.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/IZoneLoaderFactory.h"
|
||||
#include <string>
|
||||
|
||||
class ZoneLoaderFactoryIW4 final : public IZoneLoaderFactory
|
||||
{
|
||||
static const std::string MAGIC_SIGNED_INFINITY_WARD;
|
||||
static const std::string MAGIC_UNSIGNED;
|
||||
static const int VERSION;
|
||||
|
||||
static const int STREAM_COUNT;
|
||||
static const int VANILLA_BUFFER_SIZE;
|
||||
static const int OFFSET_BLOCK_BIT_COUNT;
|
||||
static const block_t INSERT_BLOCK;
|
||||
|
||||
static const std::string MAGIC_AUTH_HEADER;
|
||||
static const uint8_t RSA_PUBLIC_KEY_INFINITY_WARD[];
|
||||
|
||||
class Impl;
|
||||
|
||||
public:
|
||||
ZoneLoader* CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) override;
|
||||
};
|
@ -203,9 +203,9 @@ class ZoneLoaderFactoryT6::ZoneLoaderFactoryT6Impl
|
||||
return signatureLoadStep;
|
||||
}
|
||||
|
||||
static ISignatureDataProvider* AddXChunkProcessor(bool isEncrypted, ZoneLoader* zoneLoader, std::string& fileName)
|
||||
static ICapturedDataProvider* AddXChunkProcessor(bool isEncrypted, ZoneLoader* zoneLoader, std::string& fileName)
|
||||
{
|
||||
ISignatureDataProvider* result = nullptr;
|
||||
ICapturedDataProvider* result = nullptr;
|
||||
auto* xChunkProcessor = new ProcessorXChunks(STREAM_COUNT, XCHUNK_SIZE, VANILLA_BUFFER_SIZE);
|
||||
|
||||
if(isEncrypted)
|
||||
@ -251,7 +251,7 @@ public:
|
||||
ISignatureProvider* signatureProvider = AddAuthHeaderSteps(isSecure, zoneLoader, fileName);
|
||||
|
||||
// Setup loading XChunks from the zone from this point on.
|
||||
ISignatureDataProvider* signatureDataProvider = AddXChunkProcessor(isEncrypted, zoneLoader, fileName);
|
||||
ICapturedDataProvider* signatureDataProvider = AddXChunkProcessor(isEncrypted, zoneLoader, fileName);
|
||||
|
||||
// Start of the XFile struct
|
||||
zoneLoader->AddLoadingStep(new StepSkipBytes(8)); // Skip size and externalSize fields since they are not interesting for us
|
||||
|
Reference in New Issue
Block a user