Merge pull request #292 from Laupetin/refactor/global-game-state

refactor: get rid of global game variables
This commit is contained in:
Jan 2024-10-19 22:29:46 +02:00 committed by GitHub
commit 242bf64576
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
59 changed files with 819 additions and 937 deletions

26
src/Common/Game/IGame.cpp Normal file
View File

@ -0,0 +1,26 @@
#include "IGame.h"
#include "IW3/GameIW3.h"
#include "IW4/GameIW4.h"
#include "IW5/GameIW5.h"
#include "T5/GameT5.h"
#include "T6/GameT6.h"
#include <cassert>
IGame* IGame::GetGameById(GameId gameId)
{
static IGame* games[static_cast<unsigned>(GameId::COUNT)]{
new IW3::Game(),
new IW4::Game(),
new IW5::Game(),
new T5::Game(),
new T6::Game(),
};
assert(static_cast<unsigned>(gameId) < static_cast<unsigned>(GameId::COUNT));
auto* result = games[static_cast<unsigned>(gameId)];
assert(result);
return result;
}

View File

@ -36,11 +36,13 @@ public:
IGame& operator=(const IGame& other) = default; IGame& operator=(const IGame& other) = default;
IGame& operator=(IGame&& other) noexcept = default; IGame& operator=(IGame&& other) noexcept = default;
virtual GameId GetId() = 0; [[nodiscard]] virtual GameId GetId() const = 0;
virtual std::string GetFullName() = 0; [[nodiscard]] virtual const std::string& GetFullName() const = 0;
virtual std::string GetShortName() = 0; [[nodiscard]] virtual const std::string& GetShortName() const = 0;
virtual void AddZone(Zone* zone) = 0; virtual void AddZone(Zone* zone) = 0;
virtual void RemoveZone(Zone* zone) = 0; virtual void RemoveZone(Zone* zone) = 0;
virtual std::vector<Zone*> GetZones() = 0; [[nodiscard]] virtual const std::vector<Zone*>& GetZones() const = 0;
virtual std::vector<GameLanguagePrefix> GetLanguagePrefixes() = 0; [[nodiscard]] virtual const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const = 0;
static IGame* GetGameById(GameId gameId);
}; };

View File

@ -1,34 +1,32 @@
#include "GameIW3.h" #include "GameIW3.h"
#include "IW3.h"
#include <algorithm> #include <algorithm>
using namespace IW3; using namespace IW3;
GameIW3 g_GameIW3; GameId Game::GetId() const
GameId GameIW3::GetId()
{ {
return GameId::IW3; return GameId::IW3;
} }
std::string GameIW3::GetFullName() const std::string& Game::GetFullName() const
{ {
return "Call Of Duty 4: Modern Warfare"; static std::string fullName = "Call Of Duty 4: Modern Warfare";
return fullName;
} }
std::string GameIW3::GetShortName() const std::string& Game::GetShortName() const
{ {
return "IW3"; static std::string shortName = "IW3";
return shortName;
} }
void GameIW3::AddZone(Zone* zone) void Game::AddZone(Zone* zone)
{ {
m_zones.push_back(zone); m_zones.push_back(zone);
} }
void GameIW3::RemoveZone(Zone* zone) void Game::RemoveZone(Zone* zone)
{ {
const auto foundEntry = std::ranges::find(m_zones, zone); const auto foundEntry = std::ranges::find(m_zones, zone);
@ -36,13 +34,13 @@ void GameIW3::RemoveZone(Zone* zone)
m_zones.erase(foundEntry); m_zones.erase(foundEntry);
} }
std::vector<Zone*> GameIW3::GetZones() const std::vector<Zone*>& Game::GetZones() const
{ {
return m_zones; return m_zones;
} }
std::vector<GameLanguagePrefix> GameIW3::GetLanguagePrefixes() const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const
{ {
std::vector<GameLanguagePrefix> prefixes; static std::vector<GameLanguagePrefix> prefixes;
return prefixes; return prefixes;
} }

View File

@ -1,19 +1,20 @@
#pragma once #pragma once
#include "Game/IGame.h" #include "Game/IGame.h"
class GameIW3 final : public IGame namespace IW3
{ {
public: class Game final : public IGame
GameId GetId() override; {
std::string GetFullName() override; public:
std::string GetShortName() override; [[nodiscard]] GameId GetId() const override;
void AddZone(Zone* zone) override; [[nodiscard]] const std::string& GetFullName() const override;
void RemoveZone(Zone* zone) override; [[nodiscard]] const std::string& GetShortName() const override;
std::vector<Zone*> GetZones() override; void AddZone(Zone* zone) override;
std::vector<GameLanguagePrefix> GetLanguagePrefixes() override; void RemoveZone(Zone* zone) override;
[[nodiscard]] const std::vector<Zone*>& GetZones() const override;
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
private: private:
std::vector<Zone*> m_zones; std::vector<Zone*> m_zones;
}; };
} // namespace IW3
extern GameIW3 g_GameIW3;

View File

@ -1,34 +1,32 @@
#include "GameIW4.h" #include "GameIW4.h"
#include "IW4.h"
#include <algorithm> #include <algorithm>
using namespace IW4; using namespace IW4;
GameIW4 g_GameIW4; GameId Game::GetId() const
GameId GameIW4::GetId()
{ {
return GameId::IW4; return GameId::IW4;
} }
std::string GameIW4::GetFullName() const std::string& Game::GetFullName() const
{ {
return "Call Of Duty: Modern Warfare 2"; static std::string fullName = "Call Of Duty: Modern Warfare 2";
return fullName;
} }
std::string GameIW4::GetShortName() const std::string& Game::GetShortName() const
{ {
return "IW4"; static std::string shortName = "IW4";
return shortName;
} }
void GameIW4::AddZone(Zone* zone) void Game::AddZone(Zone* zone)
{ {
m_zones.push_back(zone); m_zones.push_back(zone);
} }
void GameIW4::RemoveZone(Zone* zone) void Game::RemoveZone(Zone* zone)
{ {
const auto foundEntry = std::ranges::find(m_zones, zone); const auto foundEntry = std::ranges::find(m_zones, zone);
@ -36,13 +34,13 @@ void GameIW4::RemoveZone(Zone* zone)
m_zones.erase(foundEntry); m_zones.erase(foundEntry);
} }
std::vector<Zone*> GameIW4::GetZones() const std::vector<Zone*>& Game::GetZones() const
{ {
return m_zones; return m_zones;
} }
std::vector<GameLanguagePrefix> GameIW4::GetLanguagePrefixes() const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const
{ {
std::vector<GameLanguagePrefix> prefixes; static std::vector<GameLanguagePrefix> prefixes;
return prefixes; return prefixes;
} }

View File

@ -1,19 +1,20 @@
#pragma once #pragma once
#include "Game/IGame.h" #include "Game/IGame.h"
class GameIW4 final : public IGame namespace IW4
{ {
public: class Game final : public IGame
GameId GetId() override; {
std::string GetFullName() override; public:
std::string GetShortName() override; [[nodiscard]] GameId GetId() const override;
void AddZone(Zone* zone) override; [[nodiscard]] const std::string& GetFullName() const override;
void RemoveZone(Zone* zone) override; [[nodiscard]] const std::string& GetShortName() const override;
std::vector<Zone*> GetZones() override; void AddZone(Zone* zone) override;
std::vector<GameLanguagePrefix> GetLanguagePrefixes() override; void RemoveZone(Zone* zone) override;
[[nodiscard]] const std::vector<Zone*>& GetZones() const override;
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
private: private:
std::vector<Zone*> m_zones; std::vector<Zone*> m_zones;
}; };
} // namespace IW4
extern GameIW4 g_GameIW4;

View File

@ -1,34 +1,32 @@
#include "GameIW5.h" #include "GameIW5.h"
#include "IW5.h"
#include <algorithm> #include <algorithm>
using namespace IW5; using namespace IW5;
GameIW5 g_GameIW5; GameId Game::GetId() const
GameId GameIW5::GetId()
{ {
return GameId::IW5; return GameId::IW5;
} }
std::string GameIW5::GetFullName() const std::string& Game::GetFullName() const
{ {
return "Call Of Duty: Modern Warfare 3"; static std::string fullName = "Call Of Duty: Modern Warfare 3";
return fullName;
} }
std::string GameIW5::GetShortName() const std::string& Game::GetShortName() const
{ {
return "IW5"; static std::string shortName = "IW5";
return shortName;
} }
void GameIW5::AddZone(Zone* zone) void Game::AddZone(Zone* zone)
{ {
m_zones.push_back(zone); m_zones.push_back(zone);
} }
void GameIW5::RemoveZone(Zone* zone) void Game::RemoveZone(Zone* zone)
{ {
const auto foundEntry = std::ranges::find(m_zones, zone); const auto foundEntry = std::ranges::find(m_zones, zone);
@ -36,13 +34,13 @@ void GameIW5::RemoveZone(Zone* zone)
m_zones.erase(foundEntry); m_zones.erase(foundEntry);
} }
std::vector<Zone*> GameIW5::GetZones() const std::vector<Zone*>& Game::GetZones() const
{ {
return m_zones; return m_zones;
} }
std::vector<GameLanguagePrefix> GameIW5::GetLanguagePrefixes() const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const
{ {
std::vector<GameLanguagePrefix> prefixes; static std::vector<GameLanguagePrefix> prefixes;
return prefixes; return prefixes;
} }

View File

@ -1,19 +1,20 @@
#pragma once #pragma once
#include "Game/IGame.h" #include "Game/IGame.h"
class GameIW5 final : public IGame namespace IW5
{ {
public: class Game final : public IGame
GameId GetId() override; {
std::string GetFullName() override; public:
std::string GetShortName() override; [[nodiscard]] GameId GetId() const override;
void AddZone(Zone* zone) override; [[nodiscard]] const std::string& GetFullName() const override;
void RemoveZone(Zone* zone) override; [[nodiscard]] const std::string& GetShortName() const override;
std::vector<Zone*> GetZones() override; void AddZone(Zone* zone) override;
std::vector<GameLanguagePrefix> GetLanguagePrefixes() override; void RemoveZone(Zone* zone) override;
[[nodiscard]] const std::vector<Zone*>& GetZones() const override;
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
private: private:
std::vector<Zone*> m_zones; std::vector<Zone*> m_zones;
}; };
} // namespace IW5
extern GameIW5 g_GameIW5;

View File

@ -1,34 +1,32 @@
#include "GameT5.h" #include "GameT5.h"
#include "T5.h"
#include <algorithm> #include <algorithm>
using namespace T5; using namespace T5;
GameT5 g_GameT5; GameId Game::GetId() const
GameId GameT5::GetId()
{ {
return GameId::T5; return GameId::T5;
} }
std::string GameT5::GetFullName() const std::string& Game::GetFullName() const
{ {
return "Call Of Duty: Black Ops"; static std::string fullName = "Call Of Duty: Black Ops";
return fullName;
} }
std::string GameT5::GetShortName() const std::string& Game::GetShortName() const
{ {
return "T5"; static std::string shortName = "T5";
return shortName;
} }
void GameT5::AddZone(Zone* zone) void Game::AddZone(Zone* zone)
{ {
m_zones.push_back(zone); m_zones.push_back(zone);
} }
void GameT5::RemoveZone(Zone* zone) void Game::RemoveZone(Zone* zone)
{ {
const auto foundEntry = std::ranges::find(m_zones, zone); const auto foundEntry = std::ranges::find(m_zones, zone);
@ -36,28 +34,28 @@ void GameT5::RemoveZone(Zone* zone)
m_zones.erase(foundEntry); m_zones.erase(foundEntry);
} }
std::vector<Zone*> GameT5::GetZones() const std::vector<Zone*>& Game::GetZones() const
{ {
return m_zones; return m_zones;
} }
std::vector<GameLanguagePrefix> GameT5::GetLanguagePrefixes() const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const
{ {
std::vector<GameLanguagePrefix> prefixes; static std::vector<GameLanguagePrefix> prefixes{
{GameLanguage::LANGUAGE_ENGLISH, "en_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_ENGLISH, "en_"); {GameLanguage::LANGUAGE_FRENCH, "fr_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_FRENCH, "fr_"); {GameLanguage::LANGUAGE_FRENCH_CAN, "fc_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_FRENCH_CAN, "fc_"); {GameLanguage::LANGUAGE_GERMAN, "ge_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_GERMAN, "ge_"); {GameLanguage::LANGUAGE_AUSTRIAN, "ge_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_AUSTRIAN, "ge_"); {GameLanguage::LANGUAGE_ITALIAN, "it_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_ITALIAN, "it_"); {GameLanguage::LANGUAGE_SPANISH, "sp_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_SPANISH, "sp_"); {GameLanguage::LANGUAGE_BRITISH, "br_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_BRITISH, "br_"); {GameLanguage::LANGUAGE_RUSSIAN, "ru_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_RUSSIAN, "ru_"); {GameLanguage::LANGUAGE_POLISH, "po_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_POLISH, "po_"); {GameLanguage::LANGUAGE_KOREAN, "ko_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_KOREAN, "ko_"); {GameLanguage::LANGUAGE_JAPANESE, "ja_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_JAPANESE, "ja_"); {GameLanguage::LANGUAGE_CZECH, "cz_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_CZECH, "cz_"); };
return prefixes; return prefixes;
} }

View File

@ -1,19 +1,20 @@
#pragma once #pragma once
#include "Game/IGame.h" #include "Game/IGame.h"
class GameT5 final : public IGame namespace T5
{ {
public: class Game final : public IGame
GameId GetId() override; {
std::string GetFullName() override; public:
std::string GetShortName() override; [[nodiscard]] GameId GetId() const override;
void AddZone(Zone* zone) override; [[nodiscard]] const std::string& GetFullName() const override;
void RemoveZone(Zone* zone) override; [[nodiscard]] const std::string& GetShortName() const override;
std::vector<Zone*> GetZones() override; void AddZone(Zone* zone) override;
std::vector<GameLanguagePrefix> GetLanguagePrefixes() override; void RemoveZone(Zone* zone) override;
[[nodiscard]] const std::vector<Zone*>& GetZones() const override;
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
private: private:
std::vector<Zone*> m_zones; std::vector<Zone*> m_zones;
}; };
} // namespace T5
extern GameT5 g_GameT5;

View File

@ -1,34 +1,32 @@
#include "GameT6.h" #include "GameT6.h"
#include "T6.h"
#include <algorithm> #include <algorithm>
using namespace T6; using namespace T6;
GameT6 g_GameT6; GameId Game::GetId() const
GameId GameT6::GetId()
{ {
return GameId::T6; return GameId::T6;
} }
std::string GameT6::GetFullName() const std::string& Game::GetFullName() const
{ {
return "Call Of Duty: Black Ops II"; static std::string fullName = "Call Of Duty: Black Ops II";
return fullName;
} }
std::string GameT6::GetShortName() const std::string& Game::GetShortName() const
{ {
return "T6"; static std::string shortName = "T6";
return shortName;
} }
void GameT6::AddZone(Zone* zone) void Game::AddZone(Zone* zone)
{ {
m_zones.push_back(zone); m_zones.push_back(zone);
} }
void GameT6::RemoveZone(Zone* zone) void Game::RemoveZone(Zone* zone)
{ {
const auto foundEntry = std::ranges::find(m_zones, zone); const auto foundEntry = std::ranges::find(m_zones, zone);
@ -36,31 +34,31 @@ void GameT6::RemoveZone(Zone* zone)
m_zones.erase(foundEntry); m_zones.erase(foundEntry);
} }
std::vector<Zone*> GameT6::GetZones() const std::vector<Zone*>& Game::GetZones() const
{ {
return m_zones; return m_zones;
} }
std::vector<GameLanguagePrefix> GameT6::GetLanguagePrefixes() const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const
{ {
std::vector<GameLanguagePrefix> prefixes; static std::vector<GameLanguagePrefix> prefixes{
{GameLanguage::LANGUAGE_ENGLISH, "en_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_ENGLISH, "en_"); {GameLanguage::LANGUAGE_FRENCH, "fr_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_FRENCH, "fr_"); {GameLanguage::LANGUAGE_FRENCH_CAN, "fc_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_FRENCH_CAN, "fc_"); {GameLanguage::LANGUAGE_GERMAN, "ge_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_GERMAN, "ge_"); {GameLanguage::LANGUAGE_AUSTRIAN, "as_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_AUSTRIAN, "as_"); {GameLanguage::LANGUAGE_ITALIAN, "it_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_ITALIAN, "it_"); {GameLanguage::LANGUAGE_SPANISH, "sp_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_SPANISH, "sp_"); {GameLanguage::LANGUAGE_BRITISH, "br_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_BRITISH, "br_"); {GameLanguage::LANGUAGE_RUSSIAN, "ru_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_RUSSIAN, "ru_"); {GameLanguage::LANGUAGE_POLISH, "po_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_POLISH, "po_"); {GameLanguage::LANGUAGE_KOREAN, "ko_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_KOREAN, "ko_"); {GameLanguage::LANGUAGE_JAPANESE, "ja_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_JAPANESE, "ja_"); {GameLanguage::LANGUAGE_CZECH, "cz_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_CZECH, "cz_"); {GameLanguage::LANGUAGE_FULL_JAPANESE, "fj_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_FULL_JAPANESE, "fj_"); {GameLanguage::LANGUAGE_PORTUGUESE, "bp_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_PORTUGUESE, "bp_"); {GameLanguage::LANGUAGE_MEXICAN_SPANISH, "ms_"},
prefixes.emplace_back(GameLanguage::LANGUAGE_MEXICAN_SPANISH, "ms_"); };
return prefixes; return prefixes;
} }

View File

@ -1,19 +1,20 @@
#pragma once #pragma once
#include "Game/IGame.h" #include "Game/IGame.h"
class GameT6 final : public IGame namespace T6
{ {
public: class Game final : public IGame
GameId GetId() override; {
std::string GetFullName() override; public:
std::string GetShortName() override; [[nodiscard]] GameId GetId() const override;
void AddZone(Zone* zone) override; [[nodiscard]] const std::string& GetFullName() const override;
void RemoveZone(Zone* zone) override; [[nodiscard]] const std::string& GetShortName() const override;
std::vector<Zone*> GetZones() override; void AddZone(Zone* zone) override;
std::vector<GameLanguagePrefix> GetLanguagePrefixes() override; void RemoveZone(Zone* zone) override;
[[nodiscard]] const std::vector<Zone*>& GetZones() const override;
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
private: private:
std::vector<Zone*> m_zones; std::vector<Zone*> m_zones;
}; };
} // namespace T6
extern GameT6 g_GameT6;

View File

@ -40,7 +40,7 @@ GameId ZoneCreator::GetGameId() const
std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{ {
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, &g_GameIW3); auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, IGame::GetGameById(GameId::IW3));
CreateZoneAssetPools(zone.get()); CreateZoneAssetPools(zone.get());
for (const auto& assetEntry : context.m_definition->m_assets) for (const auto& assetEntry : context.m_definition->m_assets)

View File

@ -39,7 +39,7 @@ GameId ZoneCreator::GetGameId() const
std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{ {
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, &g_GameIW4); auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, IGame::GetGameById(GameId::IW4));
CreateZoneAssetPools(zone.get()); CreateZoneAssetPools(zone.get());
for (const auto& assetEntry : context.m_definition->m_assets) for (const auto& assetEntry : context.m_definition->m_assets)

View File

@ -39,7 +39,7 @@ GameId ZoneCreator::GetGameId() const
std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{ {
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, &g_GameIW5); auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, IGame::GetGameById(GameId::IW5));
CreateZoneAssetPools(zone.get()); CreateZoneAssetPools(zone.get());
for (const auto& assetEntry : context.m_definition->m_assets) for (const auto& assetEntry : context.m_definition->m_assets)

View File

@ -40,7 +40,7 @@ GameId ZoneCreator::GetGameId() const
std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{ {
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, &g_GameT5); auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, IGame::GetGameById(GameId::T5));
CreateZoneAssetPools(zone.get()); CreateZoneAssetPools(zone.get());
for (const auto& assetEntry : context.m_definition->m_assets) for (const auto& assetEntry : context.m_definition->m_assets)

View File

@ -91,7 +91,7 @@ GameId ZoneCreator::GetGameId() const
std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{ {
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, &g_GameT6); auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, IGame::GetGameById(GameId::T6));
CreateZoneAssetPools(zone.get()); CreateZoneAssetPools(zone.get());
for (const auto& assetEntry : context.m_definition->m_assets) for (const auto& assetEntry : context.m_definition->m_assets)

View File

@ -288,7 +288,7 @@ namespace T6
std::cout << std::format("Loading common ipaks for zone \"{}\"\n", zone.m_name); std::cout << std::format("Loading common ipaks for zone \"{}\"\n", zone.m_name);
LoadIPakForZone(searchPath, "base", zone); LoadIPakForZone(searchPath, "base", zone);
const auto languagePrefixes = g_GameT6.GetLanguagePrefixes(); const auto& languagePrefixes = IGame::GetGameById(GameId::T6)->GetLanguagePrefixes();
for (const auto& languagePrefix : languagePrefixes) for (const auto& languagePrefix : languagePrefixes)
LoadIPakForZone(searchPath, std::format("{}base", languagePrefix.m_prefix), zone); LoadIPakForZone(searchPath, std::format("{}base", languagePrefix.m_prefix), zone);

View File

@ -199,7 +199,7 @@ namespace IW5
void MaterialConstantZoneState::ExtractNamesFromZoneInternal() void MaterialConstantZoneState::ExtractNamesFromZoneInternal()
{ {
for (const auto* zone : g_GameIW5.GetZones()) for (const auto* zone : IGame::GetGameById(GameId::IW5)->GetZones())
{ {
const auto* iw5AssetPools = dynamic_cast<const GameAssetPoolIW5*>(zone->m_pools.get()); const auto* iw5AssetPools = dynamic_cast<const GameAssetPoolIW5*>(zone->m_pools.get());
if (!iw5AssetPools) if (!iw5AssetPools)

View File

@ -201,7 +201,7 @@ namespace
public: public:
void Initialize() void Initialize()
{ {
for (const auto& zone : g_GameT6.GetZones()) for (const auto& zone : IGame::GetGameById(GameId::T6)->GetZones())
{ {
auto& sndBankPool = *dynamic_cast<GameAssetPoolT6*>(zone->m_pools.get())->m_sound_bank; auto& sndBankPool = *dynamic_cast<GameAssetPoolT6*>(zone->m_pools.get())->m_sound_bank;
for (auto* entry : sndBankPool) for (auto* entry : sndBankPool)

View File

@ -473,7 +473,7 @@ namespace T6
void MaterialConstantZoneState::ExtractNamesFromZoneInternal() void MaterialConstantZoneState::ExtractNamesFromZoneInternal()
{ {
for (const auto* zone : g_GameT6.GetZones()) for (const auto* zone : IGame::GetGameById(GameId::T6)->GetZones())
{ {
const auto* t6AssetPools = dynamic_cast<const GameAssetPoolT6*>(zone->m_pools.get()); const auto* t6AssetPools = dynamic_cast<const GameAssetPoolT6*>(zone->m_pools.get());
if (!t6AssetPools) if (!t6AssetPools)

View File

@ -2,7 +2,7 @@
#include <cassert> #include <cassert>
AbstractSalsa20Processor::AbstractSalsa20Processor(const int streamCount, std::string& zoneName, const uint8_t* salsa20Key, size_t keySize) AbstractSalsa20Processor::AbstractSalsa20Processor(const int streamCount, const std::string& zoneName, const uint8_t* salsa20Key, const size_t keySize)
: m_stream_count(streamCount), : m_stream_count(streamCount),
m_stream_contexts(std::make_unique<StreamContext[]>(streamCount)), m_stream_contexts(std::make_unique<StreamContext[]>(streamCount)),
m_stream_block_indices(std::make_unique<unsigned int[]>(streamCount)) m_stream_block_indices(std::make_unique<unsigned int[]>(streamCount))
@ -19,9 +19,9 @@ uint8_t* AbstractSalsa20Processor::GetHashBlock(const int streamNumber) const
return &m_block_hashes[blockIndexOffset + streamOffset]; return &m_block_hashes[blockIndexOffset + streamOffset];
} }
void AbstractSalsa20Processor::InitStreams(std::string& zoneName, const uint8_t* salsa20Key, size_t keySize) const void AbstractSalsa20Processor::InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, const size_t keySize) const
{ {
const int zoneNameLength = zoneName.length(); const auto zoneNameLength = zoneName.length();
const size_t blockHashBufferSize = BLOCK_HASHES_COUNT * m_stream_count * SHA1_HASH_SIZE; const size_t blockHashBufferSize = BLOCK_HASHES_COUNT * m_stream_count * SHA1_HASH_SIZE;
assert(blockHashBufferSize % 4 == 0); assert(blockHashBufferSize % 4 == 0);

View File

@ -28,11 +28,11 @@ protected:
std::unique_ptr<uint8_t[]> m_block_hashes; std::unique_ptr<uint8_t[]> m_block_hashes;
std::unique_ptr<unsigned int[]> m_stream_block_indices; std::unique_ptr<unsigned int[]> m_stream_block_indices;
AbstractSalsa20Processor(int streamCount, std::string& zoneName, const uint8_t* salsa20Key, size_t keySize); AbstractSalsa20Processor(int streamCount, const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
_NODISCARD uint8_t* GetHashBlock(int streamNumber) const; _NODISCARD uint8_t* GetHashBlock(int streamNumber) const;
void InitStreams(std::string& zoneName, const uint8_t* salsa20Key, size_t keySize) const; void InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize) const;
public: public:
virtual ~AbstractSalsa20Processor() = default; virtual ~AbstractSalsa20Processor() = default;

View File

@ -3,7 +3,7 @@
#include <cassert> #include <cassert>
XChunkProcessorSalsa20Encryption::XChunkProcessorSalsa20Encryption(const int streamCount, XChunkProcessorSalsa20Encryption::XChunkProcessorSalsa20Encryption(const int streamCount,
std::string& zoneName, const std::string& zoneName,
const uint8_t* salsa20Key, const uint8_t* salsa20Key,
const size_t keySize) const size_t keySize)
: AbstractSalsa20Processor(streamCount, zoneName, salsa20Key, keySize) : AbstractSalsa20Processor(streamCount, zoneName, salsa20Key, keySize)

View File

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

View File

@ -19,22 +19,15 @@
using namespace IW3; using namespace IW3;
class ZoneLoaderFactory::Impl namespace
{ {
static GameLanguage GetZoneLanguage(std::string& zoneName) bool CanLoad(const ZoneHeader& header, bool* isSecure, bool* isOfficial)
{
return GameLanguage::LANGUAGE_NONE;
}
static bool CanLoad(ZoneHeader& header, bool* isSecure, bool* isOfficial)
{ {
assert(isSecure != nullptr); assert(isSecure != nullptr);
assert(isOfficial != nullptr); assert(isOfficial != nullptr);
if (header.m_version != ZoneConstants::ZONE_VERSION) if (header.m_version != ZoneConstants::ZONE_VERSION)
{
return false; return false;
}
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_UNSIGNED, std::char_traits<char>::length(ZoneConstants::MAGIC_UNSIGNED))) if (!memcmp(header.m_magic, ZoneConstants::MAGIC_UNSIGNED, std::char_traits<char>::length(ZoneConstants::MAGIC_UNSIGNED)))
{ {
@ -46,61 +39,54 @@ class ZoneLoaderFactory::Impl
return false; return false;
} }
static void SetupBlock(ZoneLoader* zoneLoader) void SetupBlock(ZoneLoader& zoneLoader)
{ {
#define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type) #define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type)
zoneLoader->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP)); zoneLoader.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
zoneLoader->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME)); zoneLoader.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
zoneLoader->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_LARGE_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME)); zoneLoader.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_LARGE_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
zoneLoader->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_PHYSICAL_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME)); zoneLoader.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_PHYSICAL_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
zoneLoader->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL));
zoneLoader->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL));
zoneLoader->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL));
zoneLoader->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_VERTEX, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_VERTEX, XBlock::Type::BLOCK_TYPE_NORMAL));
zoneLoader->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_INDEX, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_INDEX, XBlock::Type::BLOCK_TYPE_NORMAL));
#undef XBLOCK_DEF #undef XBLOCK_DEF
} }
} // namespace
public: std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const
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_GameIW3);
auto* zonePtr = zone.get();
zone->m_pools = std::make_unique<GameAssetPoolIW3>(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);
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); 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, IGame::GetGameById(GameId::IW3));
auto* zonePtr = zone.get();
zone->m_pools = std::make_unique<GameAssetPoolIW3>(zonePtr, 0);
zone->m_language = GameLanguage::LANGUAGE_NONE;
// File is supported. Now setup all required steps for loading this file.
auto zoneLoader = std::make_unique<ZoneLoader>(std::move(zone));
SetupBlock(*zoneLoader);
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 zoneLoader;
} }

View File

@ -8,9 +8,7 @@ namespace IW3
{ {
class ZoneLoaderFactory final : public IZoneLoaderFactory class ZoneLoaderFactory final : public IZoneLoaderFactory
{ {
class Impl;
public: public:
ZoneLoader* CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) override; std::unique_ptr<ZoneLoader> CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const override;
}; };
} // namespace IW3 } // namespace IW3

View File

@ -25,18 +25,14 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <iostream>
#include <type_traits> #include <type_traits>
using namespace IW4; using namespace IW4;
class ZoneLoaderFactory::Impl namespace
{ {
static GameLanguage GetZoneLanguage(std::string& zoneName) bool CanLoad(ZoneHeader& header, bool* isSecure, bool* isOfficial, bool* isIw4x)
{
return GameLanguage::LANGUAGE_NONE;
}
static bool CanLoad(ZoneHeader& header, bool* isSecure, bool* isOfficial, bool* isIw4x)
{ {
assert(isSecure != nullptr); assert(isSecure != nullptr);
assert(isOfficial != nullptr); assert(isOfficial != nullptr);
@ -79,23 +75,23 @@ class ZoneLoaderFactory::Impl
return false; return false;
} }
static void SetupBlock(ZoneLoader* zoneLoader) void SetupBlock(ZoneLoader& zoneLoader)
{ {
#define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type) #define XBLOCK_DEF(name, type) std::make_unique<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_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_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_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_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_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_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_VERTEX, XBlock::Type::BLOCK_TYPE_NORMAL));
zoneLoader->AddXBlock(XBLOCK_DEF(IW4::XFILE_BLOCK_INDEX, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(IW4::XFILE_BLOCK_INDEX, XBlock::Type::BLOCK_TYPE_NORMAL));
#undef XBLOCK_DEF #undef XBLOCK_DEF
} }
static std::unique_ptr<IPublicKeyAlgorithm> SetupRSA(const bool isOfficial) std::unique_ptr<IPublicKeyAlgorithm> SetupRSA(const bool isOfficial)
{ {
if (isOfficial) if (isOfficial)
{ {
@ -103,7 +99,7 @@ class ZoneLoaderFactory::Impl
if (!rsa->SetKey(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD, sizeof(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD))) if (!rsa->SetKey(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD, sizeof(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD)))
{ {
printf("Invalid public key for signature checking\n"); std::cerr << "Invalid public key for signature checking\n";
return nullptr; return nullptr;
} }
@ -118,7 +114,7 @@ class ZoneLoaderFactory::Impl
} }
} }
static void AddAuthHeaderSteps(const bool isSecure, const bool isOfficial, ZoneLoader* zoneLoader, std::string& fileName) void AddAuthHeaderSteps(const bool isSecure, const bool isOfficial, ZoneLoader& zoneLoader, std::string& fileName)
{ {
// Unsigned zones do not have an auth header // Unsigned zones do not have an auth header
if (!isSecure) if (!isSecure)
@ -127,99 +123,92 @@ class ZoneLoaderFactory::Impl
// If file is signed setup a RSA instance. // If file is signed setup a RSA instance.
auto rsa = SetupRSA(isOfficial); auto rsa = SetupRSA(isOfficial);
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER)); zoneLoader.AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER));
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), 1); auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), 1);
auto* subHeaderHashPtr = subHeaderHash.get(); auto* subHeaderHashPtr = subHeaderHash.get();
zoneLoader->AddLoadingStep(std::move(subHeaderHash)); zoneLoader.AddLoadingStep(std::move(subHeaderHash));
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof(DB_AuthSignature::bytes)); auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof(DB_AuthSignature::bytes));
auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get(); auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get();
zoneLoader->AddLoadingStep(std::move(subHeaderHashSignature)); zoneLoader.AddLoadingStep(std::move(subHeaderHashSignature));
zoneLoader->AddLoadingStep(std::make_unique<StepVerifySignature>(std::move(rsa), subHeaderHashSignaturePtr, subHeaderHashPtr)); zoneLoader.AddLoadingStep(std::make_unique<StepVerifySignature>(std::move(rsa), subHeaderHashSignaturePtr, subHeaderHashPtr));
auto subHeaderCapture = std::make_unique<ProcessorCaptureData>(sizeof(DB_AuthSubHeader)); auto subHeaderCapture = std::make_unique<ProcessorCaptureData>(sizeof(DB_AuthSubHeader));
auto* subHeaderCapturePtr = subHeaderCapture.get(); auto* subHeaderCapturePtr = subHeaderCapture.get();
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::move(subHeaderCapture))); 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<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>); auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>);
auto* masterBlockHashesPtr = masterBlockHashes.get(); auto* masterBlockHashesPtr = masterBlockHashes.get();
zoneLoader->AddLoadingStep(std::move(masterBlockHashes)); zoneLoader.AddLoadingStep(std::move(masterBlockHashes));
zoneLoader->AddLoadingStep( zoneLoader.AddLoadingStep(
std::make_unique<StepVerifyHash>(std::unique_ptr<IHashFunction>(Crypto::CreateSHA256()), 0, subHeaderHashPtr, subHeaderCapturePtr)); std::make_unique<StepVerifyHash>(std::unique_ptr<IHashFunction>(Crypto::CreateSHA256()), 0, subHeaderHashPtr, subHeaderCapturePtr));
zoneLoader->AddLoadingStep(std::make_unique<StepRemoveProcessor>(subHeaderCapturePtr)); zoneLoader.AddLoadingStep(std::make_unique<StepRemoveProcessor>(subHeaderCapturePtr));
// Skip the rest of the first chunk // 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<StepSkipBytes>(ZoneConstants::AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader)));
zoneLoader->AddLoadingStep( zoneLoader.AddLoadingStep(
std::make_unique<StepAddProcessor>(std::make_unique<ProcessorAuthedBlocks>(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP, std::make_unique<StepAddProcessor>(std::make_unique<ProcessorAuthedBlocks>(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP,
ZoneConstants::AUTHED_CHUNK_SIZE, ZoneConstants::AUTHED_CHUNK_SIZE,
std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>, std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>,
std::unique_ptr<IHashFunction>(Crypto::CreateSHA256()), Crypto::CreateSHA256(),
masterBlockHashesPtr))); masterBlockHashesPtr)));
} }
} // namespace
public: std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const
static ZoneLoader* CreateLoaderForHeader(ZoneHeader& header, std::string& fileName)
{
bool isSecure;
bool isOfficial;
bool isIw4x;
// Check if this file is a supported IW4 zone.
if (!CanLoad(header, &isSecure, &isOfficial, &isIw4x))
return nullptr;
// Create new zone
auto zone = std::make_unique<Zone>(fileName, 0, &g_GameIW4);
auto* zonePtr = zone.get();
zone->m_pools = std::make_unique<GameAssetPoolIW4>(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)));
if (isIw4x) // IW4x has one extra byte of padding here for protection purposes
{
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::make_unique<ProcessorIW4xDecryption>()));
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(1));
}
// 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); bool isSecure;
bool isOfficial;
bool isIw4x;
// Check if this file is a supported IW4 zone.
if (!CanLoad(header, &isSecure, &isOfficial, &isIw4x))
return nullptr;
// Create new zone
auto zone = std::make_unique<Zone>(fileName, 0, IGame::GetGameById(GameId::IW4));
auto* zonePtr = zone.get();
zone->m_pools = std::make_unique<GameAssetPoolIW4>(zonePtr, 0);
zone->m_language = GameLanguage::LANGUAGE_NONE;
// File is supported. Now setup all required steps for loading this file.
auto zoneLoader = std::make_unique<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)));
if (isIw4x) // IW4x has one extra byte of padding here for protection purposes
{
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::make_unique<ProcessorIW4xDecryption>()));
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(1));
}
// 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 zoneLoader;
} }

View File

@ -8,9 +8,7 @@ namespace IW4
{ {
class ZoneLoaderFactory final : public IZoneLoaderFactory class ZoneLoaderFactory final : public IZoneLoaderFactory
{ {
class Impl;
public: public:
ZoneLoader* CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) override; std::unique_ptr<ZoneLoader> CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const override;
}; };
} // namespace IW4 } // namespace IW4

View File

@ -24,18 +24,14 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <iostream>
#include <type_traits> #include <type_traits>
using namespace IW5; using namespace IW5;
class ZoneLoaderFactory::Impl namespace
{ {
static GameLanguage GetZoneLanguage(std::string& zoneName) bool CanLoad(const ZoneHeader& header, bool* isSecure, bool* isOfficial)
{
return GameLanguage::LANGUAGE_NONE;
}
static bool CanLoad(ZoneHeader& header, bool* isSecure, bool* isOfficial)
{ {
assert(isSecure != nullptr); assert(isSecure != nullptr);
assert(isOfficial != nullptr); assert(isOfficial != nullptr);
@ -62,24 +58,24 @@ class ZoneLoaderFactory::Impl
return false; return false;
} }
static void SetupBlock(ZoneLoader* zoneLoader) void SetupBlock(ZoneLoader& zoneLoader)
{ {
#define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type) #define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type)
zoneLoader->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP)); zoneLoader.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
zoneLoader->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL));
zoneLoader->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME)); zoneLoader.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
zoneLoader->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL));
zoneLoader->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL));
zoneLoader->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_CALLBACK, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_CALLBACK, XBlock::Type::BLOCK_TYPE_NORMAL));
zoneLoader->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_VERTEX, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_VERTEX, XBlock::Type::BLOCK_TYPE_NORMAL));
zoneLoader->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_INDEX, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_INDEX, XBlock::Type::BLOCK_TYPE_NORMAL));
zoneLoader->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_SCRIPT, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_SCRIPT, XBlock::Type::BLOCK_TYPE_NORMAL));
#undef XBLOCK_DEF #undef XBLOCK_DEF
} }
static std::unique_ptr<IPublicKeyAlgorithm> SetupRSA(const bool isOfficial) std::unique_ptr<IPublicKeyAlgorithm> SetupRSA(const bool isOfficial)
{ {
if (isOfficial) if (isOfficial)
{ {
@ -87,7 +83,7 @@ class ZoneLoaderFactory::Impl
if (!rsa->SetKey(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD, sizeof(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD))) if (!rsa->SetKey(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD, sizeof(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD)))
{ {
printf("Invalid public key for signature checking\n"); std::cerr << "Invalid public key for signature checking\n";
return nullptr; return nullptr;
} }
@ -102,7 +98,7 @@ class ZoneLoaderFactory::Impl
} }
} }
static void AddAuthHeaderSteps(const bool isSecure, const bool isOfficial, ZoneLoader* zoneLoader, std::string& fileName) void AddAuthHeaderSteps(const bool isSecure, const bool isOfficial, ZoneLoader& zoneLoader, std::string& fileName)
{ {
// Unsigned zones do not have an auth header // Unsigned zones do not have an auth header
if (!isSecure) if (!isSecure)
@ -111,92 +107,85 @@ class ZoneLoaderFactory::Impl
// If file is signed setup a RSA instance. // If file is signed setup a RSA instance.
auto rsa = SetupRSA(isOfficial); auto rsa = SetupRSA(isOfficial);
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER)); zoneLoader.AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER));
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), 1); auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), 1);
auto* subHeaderHashPtr = subHeaderHash.get(); auto* subHeaderHashPtr = subHeaderHash.get();
zoneLoader->AddLoadingStep(std::move(subHeaderHash)); zoneLoader.AddLoadingStep(std::move(subHeaderHash));
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof(DB_AuthSignature::bytes)); auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof(DB_AuthSignature::bytes));
auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get(); auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get();
zoneLoader->AddLoadingStep(std::move(subHeaderHashSignature)); zoneLoader.AddLoadingStep(std::move(subHeaderHashSignature));
zoneLoader->AddLoadingStep(std::make_unique<StepVerifySignature>(std::move(rsa), subHeaderHashSignaturePtr, subHeaderHashPtr)); zoneLoader.AddLoadingStep(std::make_unique<StepVerifySignature>(std::move(rsa), subHeaderHashSignaturePtr, subHeaderHashPtr));
auto subHeaderCapture = std::make_unique<ProcessorCaptureData>(sizeof(DB_AuthSubHeader)); auto subHeaderCapture = std::make_unique<ProcessorCaptureData>(sizeof(DB_AuthSubHeader));
auto* subHeaderCapturePtr = subHeaderCapture.get(); auto* subHeaderCapturePtr = subHeaderCapture.get();
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::move(subHeaderCapture))); 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<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>); auto masterBlockHashes = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>);
auto* masterBlockHashesPtr = masterBlockHashes.get(); auto* masterBlockHashesPtr = masterBlockHashes.get();
zoneLoader->AddLoadingStep(std::move(masterBlockHashes)); zoneLoader.AddLoadingStep(std::move(masterBlockHashes));
zoneLoader->AddLoadingStep( zoneLoader.AddLoadingStep(
std::make_unique<StepVerifyHash>(std::unique_ptr<IHashFunction>(Crypto::CreateSHA256()), 0, subHeaderHashPtr, subHeaderCapturePtr)); std::make_unique<StepVerifyHash>(std::unique_ptr<IHashFunction>(Crypto::CreateSHA256()), 0, subHeaderHashPtr, subHeaderCapturePtr));
zoneLoader->AddLoadingStep(std::make_unique<StepRemoveProcessor>(subHeaderCapturePtr)); zoneLoader.AddLoadingStep(std::make_unique<StepRemoveProcessor>(subHeaderCapturePtr));
// Skip the rest of the first chunk // 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<StepSkipBytes>(ZoneConstants::AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader)));
zoneLoader->AddLoadingStep( zoneLoader.AddLoadingStep(
std::make_unique<StepAddProcessor>(std::make_unique<ProcessorAuthedBlocks>(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP, std::make_unique<StepAddProcessor>(std::make_unique<ProcessorAuthedBlocks>(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP,
ZoneConstants::AUTHED_CHUNK_SIZE, ZoneConstants::AUTHED_CHUNK_SIZE,
std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>, std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>,
std::unique_ptr<IHashFunction>(Crypto::CreateSHA256()), Crypto::CreateSHA256(),
masterBlockHashesPtr))); masterBlockHashesPtr)));
} }
} // namespace
public: std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const
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); 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, IGame::GetGameById(GameId::IW5));
auto* zonePtr = zone.get();
zone->m_pools = std::make_unique<GameAssetPoolIW5>(zonePtr, 0);
zone->m_language = GameLanguage::LANGUAGE_NONE;
// File is supported. Now setup all required steps for loading this file.
auto zoneLoader = std::make_unique<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 zoneLoader;
} }

View File

@ -8,9 +8,7 @@ namespace IW5
{ {
class ZoneLoaderFactory final : public IZoneLoaderFactory class ZoneLoaderFactory final : public IZoneLoaderFactory
{ {
class Impl;
public: public:
ZoneLoader* CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) override; std::unique_ptr<ZoneLoader> CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const override;
}; };
} // namespace IW5 } // namespace IW5

View File

@ -19,14 +19,9 @@
using namespace T5; using namespace T5;
class ZoneLoaderFactory::Impl namespace
{ {
static GameLanguage GetZoneLanguage(std::string& zoneName) bool CanLoad(const ZoneHeader& header, bool* isSecure, bool* isOfficial)
{
return GameLanguage::LANGUAGE_NONE;
}
static bool CanLoad(ZoneHeader& header, bool* isSecure, bool* isOfficial)
{ {
assert(isSecure != nullptr); assert(isSecure != nullptr);
assert(isOfficial != nullptr); assert(isOfficial != nullptr);
@ -46,59 +41,52 @@ class ZoneLoaderFactory::Impl
return false; return false;
} }
static void SetupBlock(ZoneLoader* zoneLoader) void SetupBlock(ZoneLoader& zoneLoader)
{ {
#define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type) #define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type)
zoneLoader->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP)); zoneLoader.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
zoneLoader->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME)); zoneLoader.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
zoneLoader->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_LARGE_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME)); zoneLoader.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_LARGE_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
zoneLoader->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_PHYSICAL_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME)); zoneLoader.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_PHYSICAL_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
zoneLoader->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL));
zoneLoader->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL));
zoneLoader->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL));
#undef XBLOCK_DEF #undef XBLOCK_DEF
} }
} // namespace
public: std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const
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_GameT5);
auto* zonePtr = zone.get();
zone->m_pools = std::make_unique<GameAssetPoolT5>(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);
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); 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, IGame::GetGameById(GameId::T5));
auto* zonePtr = zone.get();
zone->m_pools = std::make_unique<GameAssetPoolT5>(zonePtr, 0);
zone->m_language = GameLanguage::LANGUAGE_NONE;
// File is supported. Now setup all required steps for loading this file.
auto zoneLoader = std::make_unique<ZoneLoader>(std::move(zone));
SetupBlock(*zoneLoader);
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 zoneLoader;
} }

View File

@ -8,9 +8,7 @@ namespace T5
{ {
class ZoneLoaderFactory final : public IZoneLoaderFactory class ZoneLoaderFactory final : public IZoneLoaderFactory
{ {
class Impl;
public: public:
ZoneLoader* CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) override; std::unique_ptr<ZoneLoader> CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const override;
}; };
} // namespace T5 } // namespace T5

View File

@ -22,15 +22,16 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <iostream>
#include <memory> #include <memory>
using namespace T6; using namespace T6;
class ZoneLoaderFactory::Impl namespace
{ {
static GameLanguage GetZoneLanguage(std::string& zoneName) GameLanguage GetZoneLanguage(const std::string& zoneName)
{ {
auto languagePrefixes = g_GameT6.GetLanguagePrefixes(); const auto& languagePrefixes = IGame::GetGameById(GameId::T6)->GetLanguagePrefixes();
for (const auto& languagePrefix : languagePrefixes) for (const auto& languagePrefix : languagePrefixes)
{ {
@ -43,7 +44,7 @@ class ZoneLoaderFactory::Impl
return GameLanguage::LANGUAGE_NONE; return GameLanguage::LANGUAGE_NONE;
} }
static bool CanLoad(ZoneHeader& header, bool* isSecure, bool* isOfficial, bool* isEncrypted) bool CanLoad(const ZoneHeader& header, bool* isSecure, bool* isOfficial, bool* isEncrypted)
{ {
assert(isSecure != nullptr); assert(isSecure != nullptr);
assert(isOfficial != nullptr); assert(isOfficial != nullptr);
@ -88,23 +89,23 @@ class ZoneLoaderFactory::Impl
return false; return false;
} }
static void SetupBlock(ZoneLoader* zoneLoader) void SetupBlock(ZoneLoader& zoneLoader)
{ {
#define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type) #define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type)
zoneLoader->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP)); zoneLoader.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
zoneLoader->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_RUNTIME_VIRTUAL, XBlock::Type::BLOCK_TYPE_RUNTIME)); zoneLoader.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_RUNTIME_VIRTUAL, XBlock::Type::BLOCK_TYPE_RUNTIME));
zoneLoader->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_RUNTIME_PHYSICAL, XBlock::Type::BLOCK_TYPE_RUNTIME)); zoneLoader.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_RUNTIME_PHYSICAL, XBlock::Type::BLOCK_TYPE_RUNTIME));
zoneLoader->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_DELAY_VIRTUAL, XBlock::Type::BLOCK_TYPE_DELAY)); zoneLoader.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_DELAY_VIRTUAL, XBlock::Type::BLOCK_TYPE_DELAY));
zoneLoader->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_DELAY_PHYSICAL, XBlock::Type::BLOCK_TYPE_DELAY)); zoneLoader.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_DELAY_PHYSICAL, XBlock::Type::BLOCK_TYPE_DELAY));
zoneLoader->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL));
zoneLoader->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL));
zoneLoader->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_STREAMER_RESERVE, XBlock::Type::BLOCK_TYPE_NORMAL)); zoneLoader.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_STREAMER_RESERVE, XBlock::Type::BLOCK_TYPE_NORMAL));
#undef XBLOCK_DEF #undef XBLOCK_DEF
} }
static std::unique_ptr<IPublicKeyAlgorithm> SetupRSA(const bool isOfficial) std::unique_ptr<IPublicKeyAlgorithm> SetupRSA(const bool isOfficial)
{ {
if (isOfficial) if (isOfficial)
{ {
@ -112,7 +113,7 @@ class ZoneLoaderFactory::Impl
if (!rsa->SetKey(ZoneConstants::RSA_PUBLIC_KEY_TREYARCH, sizeof(ZoneConstants::RSA_PUBLIC_KEY_TREYARCH))) if (!rsa->SetKey(ZoneConstants::RSA_PUBLIC_KEY_TREYARCH, sizeof(ZoneConstants::RSA_PUBLIC_KEY_TREYARCH)))
{ {
printf("Invalid public key for signature checking\n"); std::cerr << "Invalid public key for signature checking\n";
return nullptr; return nullptr;
} }
@ -127,24 +128,24 @@ class ZoneLoaderFactory::Impl
} }
} }
static ISignatureProvider* AddAuthHeaderSteps(const bool isSecure, ZoneLoader* zoneLoader, std::string& fileName) ISignatureProvider* AddAuthHeaderSteps(const bool isSecure, ZoneLoader& zoneLoader, std::string& fileName)
{ {
// Unsigned zones do not have an auth header // Unsigned zones do not have an auth header
if (!isSecure) if (!isSecure)
return nullptr; return nullptr;
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER)); zoneLoader.AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER));
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Loading Flags which are always zero zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Loading Flags which are always zero
zoneLoader->AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, 32)); zoneLoader.AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, 32));
auto signatureLoadStep = std::make_unique<StepLoadSignature>(256); auto signatureLoadStep = std::make_unique<StepLoadSignature>(256);
auto* signatureLoadStepPtr = signatureLoadStep.get(); auto* signatureLoadStepPtr = signatureLoadStep.get();
zoneLoader->AddLoadingStep(std::move(signatureLoadStep)); zoneLoader.AddLoadingStep(std::move(signatureLoadStep));
return signatureLoadStepPtr; return signatureLoadStepPtr;
} }
static ICapturedDataProvider* AddXChunkProcessor(bool isEncrypted, ZoneLoader* zoneLoader, std::string& fileName) ICapturedDataProvider* AddXChunkProcessor(const bool isEncrypted, ZoneLoader& zoneLoader, std::string& fileName)
{ {
ICapturedDataProvider* result = nullptr; ICapturedDataProvider* result = nullptr;
auto xChunkProcessor = std::make_unique<ProcessorXChunks>(ZoneConstants::STREAM_COUNT, ZoneConstants::XCHUNK_SIZE, ZoneConstants::VANILLA_BUFFER_SIZE); auto xChunkProcessor = std::make_unique<ProcessorXChunks>(ZoneConstants::STREAM_COUNT, ZoneConstants::XCHUNK_SIZE, ZoneConstants::VANILLA_BUFFER_SIZE);
@ -160,62 +161,55 @@ class ZoneLoaderFactory::Impl
// Decompress the chunks using zlib // Decompress the chunks using zlib
xChunkProcessor->AddChunkProcessor(std::make_unique<XChunkProcessorInflate>()); xChunkProcessor->AddChunkProcessor(std::make_unique<XChunkProcessorInflate>());
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::move(xChunkProcessor))); zoneLoader.AddLoadingStep(std::make_unique<StepAddProcessor>(std::move(xChunkProcessor)));
// If there is encryption, the signed data of the zone is the final hash blocks provided by the Salsa20 IV adaption algorithm // If there is encryption, the signed data of the zone is the final hash blocks provided by the Salsa20 IV adaption algorithm
return result; return result;
} }
} // namespace
public: std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const
static ZoneLoader* CreateLoaderForHeader(ZoneHeader& header, std::string& fileName)
{
bool isSecure;
bool isOfficial;
bool isEncrypted;
// Check if this file is a supported T6 zone.
if (!CanLoad(header, &isSecure, &isOfficial, &isEncrypted))
return nullptr;
// Create new zone
auto zone = std::make_unique<Zone>(fileName, 0, &g_GameT6);
auto* zonePtr = zone.get();
zone->m_pools = std::make_unique<GameAssetPoolT6>(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);
// If file is signed setup a RSA instance.
auto rsa = isSecure ? SetupRSA(isOfficial) : nullptr;
// Add steps for loading the auth header which also contain the signature of the zone if it is signed.
ISignatureProvider* signatureProvider = AddAuthHeaderSteps(isSecure, zoneLoader, fileName);
// Setup loading XChunks from the zone from this point on.
ICapturedDataProvider* signatureDataProvider = AddXChunkProcessor(isEncrypted, zoneLoader, fileName);
// Start of the XFile struct
zoneLoader->AddLoadingStep(std::make_unique<StepLoadZoneSizes>());
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));
if (isSecure)
{
zoneLoader->AddLoadingStep(std::make_unique<StepVerifySignature>(std::move(rsa), signatureProvider, signatureDataProvider));
}
// Return the fully setup zoneloader
return zoneLoader;
}
};
ZoneLoader* ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader& header, std::string& fileName)
{ {
return Impl::CreateLoaderForHeader(header, fileName); bool isSecure;
bool isOfficial;
bool isEncrypted;
// Check if this file is a supported T6 zone.
if (!CanLoad(header, &isSecure, &isOfficial, &isEncrypted))
return nullptr;
// Create new zone
auto zone = std::make_unique<Zone>(fileName, 0, IGame::GetGameById(GameId::T6));
auto* zonePtr = zone.get();
zone->m_pools = std::make_unique<GameAssetPoolT6>(zonePtr, 0);
zone->m_language = GetZoneLanguage(fileName);
// File is supported. Now setup all required steps for loading this file.
auto zoneLoader = std::make_unique<ZoneLoader>(std::move(zone));
SetupBlock(*zoneLoader);
// If file is signed setup a RSA instance.
auto rsa = isSecure ? SetupRSA(isOfficial) : nullptr;
// Add steps for loading the auth header which also contain the signature of the zone if it is signed.
ISignatureProvider* signatureProvider = AddAuthHeaderSteps(isSecure, *zoneLoader, fileName);
// Setup loading XChunks from the zone from this point on.
ICapturedDataProvider* signatureDataProvider = AddXChunkProcessor(isEncrypted, *zoneLoader, fileName);
// Start of the XFile struct
zoneLoader->AddLoadingStep(std::make_unique<StepLoadZoneSizes>());
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));
if (isSecure)
{
zoneLoader->AddLoadingStep(std::make_unique<StepVerifySignature>(std::move(rsa), signatureProvider, signatureDataProvider));
}
return zoneLoader;
} }

View File

@ -8,9 +8,7 @@ namespace T6
{ {
class ZoneLoaderFactory final : public IZoneLoaderFactory class ZoneLoaderFactory final : public IZoneLoaderFactory
{ {
class Impl;
public: public:
ZoneLoader* CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) override; std::unique_ptr<ZoneLoader> CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const override;
}; };
} // namespace T6 } // namespace T6

View File

@ -0,0 +1,27 @@
#include "IZoneLoaderFactory.h"
#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 <cassert>
const IZoneLoaderFactory* IZoneLoaderFactory::GetZoneLoaderFactoryForGame(GameId game)
{
static const IZoneLoaderFactory* zoneCreators[static_cast<unsigned>(GameId::COUNT)]{
new IW3::ZoneLoaderFactory(),
new IW4::ZoneLoaderFactory(),
new IW5::ZoneLoaderFactory(),
new T5::ZoneLoaderFactory(),
new T6::ZoneLoaderFactory(),
};
static_assert(std::extent_v<decltype(zoneCreators)> == static_cast<unsigned>(GameId::COUNT));
assert(static_cast<unsigned>(game) < static_cast<unsigned>(GameId::COUNT));
const auto* result = zoneCreators[static_cast<unsigned>(game)];
assert(result);
return result;
}

View File

@ -3,6 +3,8 @@
#include "Zone/ZoneTypes.h" #include "Zone/ZoneTypes.h"
#include "ZoneLoader.h" #include "ZoneLoader.h"
#include <memory>
class IZoneLoaderFactory class IZoneLoaderFactory
{ {
public: public:
@ -13,5 +15,7 @@ public:
IZoneLoaderFactory& operator=(const IZoneLoaderFactory& other) = default; IZoneLoaderFactory& operator=(const IZoneLoaderFactory& other) = default;
IZoneLoaderFactory& operator=(IZoneLoaderFactory&& other) noexcept = default; IZoneLoaderFactory& operator=(IZoneLoaderFactory&& other) noexcept = default;
virtual ZoneLoader* CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) = 0; virtual std::unique_ptr<ZoneLoader> CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const = 0;
static const IZoneLoaderFactory* GetZoneLoaderFactoryForGame(GameId game);
}; };

View File

@ -1,34 +1,24 @@
#include "ZoneLoading.h" #include "ZoneLoading.h"
#include "Game/IW3/ZoneLoaderFactoryIW3.h" #include "Loading/IZoneLoaderFactory.h"
#include "Game/IW4/ZoneLoaderFactoryIW4.h" #include "Loading/ZoneLoader.h"
#include "Game/IW5/ZoneLoaderFactoryIW5.h"
#include "Game/T5/ZoneLoaderFactoryT5.h"
#include "Game/T6/ZoneLoaderFactoryT6.h"
#include "Utils/ObjFileStream.h" #include "Utils/ObjFileStream.h"
#include <filesystem> #include <filesystem>
#include <format>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
namespace fs = std::filesystem; namespace fs = std::filesystem;
IZoneLoaderFactory* ZoneLoaderFactories[]{
new IW3::ZoneLoaderFactory(),
new IW4::ZoneLoaderFactory(),
new IW5::ZoneLoaderFactory(),
new T5::ZoneLoaderFactory(),
new T6::ZoneLoaderFactory(),
};
std::unique_ptr<Zone> ZoneLoading::LoadZone(const std::string& path) std::unique_ptr<Zone> ZoneLoading::LoadZone(const std::string& path)
{ {
auto zoneName = fs::path(path).filename().replace_extension("").string(); auto zoneName = fs::path(path).filename().replace_extension().string();
std::ifstream file(path, std::fstream::in | std::fstream::binary); std::ifstream file(path, std::fstream::in | std::fstream::binary);
if (!file.is_open()) if (!file.is_open())
{ {
printf("Could not open file '%s'.\n", path.c_str()); std::cerr << std::format("Could not open file '{}'.\n", path);
return nullptr; return nullptr;
} }
@ -36,27 +26,27 @@ std::unique_ptr<Zone> ZoneLoading::LoadZone(const std::string& path)
file.read(reinterpret_cast<char*>(&header), sizeof(header)); file.read(reinterpret_cast<char*>(&header), sizeof(header));
if (file.gcount() != sizeof(header)) if (file.gcount() != sizeof(header))
{ {
std::cout << "Failed to read zone header from file '" << path << "'.\n"; std::cerr << std::format("Failed to read zone header from file '{}'.\n", path);
return nullptr; return nullptr;
} }
ZoneLoader* zoneLoader = nullptr; std::unique_ptr<ZoneLoader> zoneLoader;
for (auto* factory : ZoneLoaderFactories) for (auto game = 0u; game < static_cast<unsigned>(GameId::COUNT); game++)
{ {
const auto* factory = IZoneLoaderFactory::GetZoneLoaderFactoryForGame(static_cast<GameId>(game));
zoneLoader = factory->CreateLoaderForHeader(header, zoneName); zoneLoader = factory->CreateLoaderForHeader(header, zoneName);
if (zoneLoader != nullptr) if (zoneLoader)
break; break;
} }
if (zoneLoader == nullptr) if (!zoneLoader)
{ {
printf("Could not create factory for zone '%s'.\n", zoneName.c_str()); std::cerr << std::format("Could not create factory for zone '{}'.\n", zoneName);
return nullptr; return nullptr;
} }
auto loadedZone = zoneLoader->LoadZone(file); auto loadedZone = zoneLoader->LoadZone(file);
delete zoneLoader;
file.close(); file.close();
return std::move(loadedZone); return std::move(loadedZone);

View File

@ -16,36 +16,26 @@
using namespace IW3; using namespace IW3;
class ZoneWriterFactory::Impl namespace
{ {
Zone* m_zone; void SetupBlocks(ZoneWriter& writer)
std::unique_ptr<ZoneWriter> m_writer;
public:
explicit Impl(Zone* zone)
: m_zone(zone),
m_writer(std::make_unique<ZoneWriter>())
{
}
void SetupBlocks() const
{ {
#define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type) #define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type)
m_writer->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP)); writer.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
m_writer->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME)); writer.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
m_writer->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_LARGE_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME)); writer.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_LARGE_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
m_writer->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_PHYSICAL_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME)); writer.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_PHYSICAL_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
m_writer->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_VERTEX, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_VERTEX, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_INDEX, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(IW3::XFILE_BLOCK_INDEX, XBlock::Type::BLOCK_TYPE_NORMAL));
#undef XBLOCK_DEF #undef XBLOCK_DEF
} }
static ZoneHeader CreateHeaderForParams() ZoneHeader CreateHeaderForParams()
{ {
ZoneHeader header{}; ZoneHeader header{};
header.m_version = ZoneConstants::ZONE_VERSION; header.m_version = ZoneConstants::ZONE_VERSION;
@ -53,40 +43,30 @@ public:
return header; return header;
} }
} // namespace
std::unique_ptr<ZoneWriter> CreateWriter()
{
SetupBlocks();
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
std::make_unique<ContentWriter>(), m_zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
auto* contentInMemoryPtr = contentInMemory.get();
m_writer->AddWritingStep(std::move(contentInMemory));
// Write zone header
m_writer->AddWritingStep(std::make_unique<StepWriteZoneHeader>(CreateHeaderForParams()));
m_writer->AddWritingStep(std::make_unique<StepAddOutputProcessor>(std::make_unique<OutputProcessorDeflate>()));
// Start of the XFile struct
m_writer->AddWritingStep(std::make_unique<StepWriteZoneSizes>(contentInMemoryPtr));
m_writer->AddWritingStep(std::make_unique<StepWriteXBlockSizes>(m_zone));
// Start of the zone content
m_writer->AddWritingStep(std::make_unique<StepWriteZoneContentToFile>(contentInMemoryPtr));
// Return the fully setup zoneloader
return std::move(m_writer);
}
};
bool ZoneWriterFactory::SupportsZone(Zone* zone) const
{
return zone->m_game == &g_GameIW3;
}
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
{ {
Impl impl(zone); auto writer = std::make_unique<ZoneWriter>();
return impl.CreateWriter();
SetupBlocks(*writer);
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
std::make_unique<ContentWriter>(), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
auto* contentInMemoryPtr = contentInMemory.get();
writer->AddWritingStep(std::move(contentInMemory));
// Write zone header
writer->AddWritingStep(std::make_unique<StepWriteZoneHeader>(CreateHeaderForParams()));
writer->AddWritingStep(std::make_unique<StepAddOutputProcessor>(std::make_unique<OutputProcessorDeflate>()));
// Start of the XFile struct
writer->AddWritingStep(std::make_unique<StepWriteZoneSizes>(contentInMemoryPtr));
writer->AddWritingStep(std::make_unique<StepWriteXBlockSizes>(zone));
// Start of the zone content
writer->AddWritingStep(std::make_unique<StepWriteZoneContentToFile>(contentInMemoryPtr));
return std::move(writer);
} }

View File

@ -8,10 +8,7 @@ namespace IW3
{ {
class ZoneWriterFactory final : public IZoneWriterFactory class ZoneWriterFactory final : public IZoneWriterFactory
{ {
class Impl;
public: public:
_NODISCARD bool SupportsZone(Zone* zone) const override;
_NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override; _NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override;
}; };
} // namespace IW3 } // namespace IW3

View File

@ -18,35 +18,25 @@
using namespace IW4; using namespace IW4;
class ZoneWriterFactory::Impl namespace
{ {
Zone* m_zone; void SetupBlocks(ZoneWriter& writer)
std::unique_ptr<ZoneWriter> m_writer;
public:
explicit Impl(Zone* zone)
: m_zone(zone),
m_writer(std::make_unique<ZoneWriter>())
{
}
void SetupBlocks() const
{ {
#define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type) #define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type)
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_CALLBACK, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_CALLBACK, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_VERTEX, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_VERTEX, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_INDEX, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_INDEX, XBlock::Type::BLOCK_TYPE_NORMAL));
#undef XBLOCK_DEF #undef XBLOCK_DEF
} }
static ZoneHeader CreateHeaderForParams(const bool isSecure, const bool isOfficial) ZoneHeader CreateHeaderForParams(const bool isSecure, const bool isOfficial)
{ {
ZoneHeader header{}; ZoneHeader header{};
header.m_version = ZoneConstants::ZONE_VERSION; header.m_version = ZoneConstants::ZONE_VERSION;
@ -65,49 +55,39 @@ public:
return header; return header;
} }
}; // namespace
std::unique_ptr<ZoneWriter> CreateWriter()
{
// TODO Support signed fastfiles
bool isSecure = false;
SetupBlocks();
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
std::make_unique<ContentWriter>(), m_zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
auto* contentInMemoryPtr = contentInMemory.get();
m_writer->AddWritingStep(std::move(contentInMemory));
// Write zone header
m_writer->AddWritingStep(std::make_unique<StepWriteZoneHeader>(CreateHeaderForParams(isSecure, false)));
// Write dummy byte that the game ignores as well. No clue what it means.
m_writer->AddWritingStep(std::make_unique<StepWriteZero>(1));
// Write timestamp
m_writer->AddWritingStep(std::make_unique<StepWriteTimestamp>());
m_writer->AddWritingStep(std::make_unique<StepAddOutputProcessor>(std::make_unique<OutputProcessorDeflate>()));
// Start of the XFile struct
m_writer->AddWritingStep(std::make_unique<StepWriteZoneSizes>(contentInMemoryPtr));
m_writer->AddWritingStep(std::make_unique<StepWriteXBlockSizes>(m_zone));
// Start of the zone content
m_writer->AddWritingStep(std::make_unique<StepWriteZoneContentToFile>(contentInMemoryPtr));
// Return the fully setup zoneloader
return std::move(m_writer);
}
};
bool ZoneWriterFactory::SupportsZone(Zone* zone) const
{
return zone->m_game == &g_GameIW4;
}
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
{ {
Impl impl(zone); auto writer = std::make_unique<ZoneWriter>();
return impl.CreateWriter();
// TODO Support signed fastfiles
bool isSecure = false;
SetupBlocks(*writer);
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
std::make_unique<ContentWriter>(), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
auto* contentInMemoryPtr = contentInMemory.get();
writer->AddWritingStep(std::move(contentInMemory));
// Write zone header
writer->AddWritingStep(std::make_unique<StepWriteZoneHeader>(CreateHeaderForParams(isSecure, false)));
// Write dummy byte that the game ignores as well. No clue what it means.
writer->AddWritingStep(std::make_unique<StepWriteZero>(1));
// Write timestamp
writer->AddWritingStep(std::make_unique<StepWriteTimestamp>());
writer->AddWritingStep(std::make_unique<StepAddOutputProcessor>(std::make_unique<OutputProcessorDeflate>()));
// Start of the XFile struct
writer->AddWritingStep(std::make_unique<StepWriteZoneSizes>(contentInMemoryPtr));
writer->AddWritingStep(std::make_unique<StepWriteXBlockSizes>(zone));
// Start of the zone content
writer->AddWritingStep(std::make_unique<StepWriteZoneContentToFile>(contentInMemoryPtr));
return std::move(writer);
} }

View File

@ -8,10 +8,7 @@ namespace IW4
{ {
class ZoneWriterFactory final : public IZoneWriterFactory class ZoneWriterFactory final : public IZoneWriterFactory
{ {
class Impl;
public: public:
_NODISCARD bool SupportsZone(Zone* zone) const override;
_NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override; _NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override;
}; };
} // namespace IW4 } // namespace IW4

View File

@ -18,36 +18,26 @@
using namespace IW5; using namespace IW5;
class ZoneWriterFactory::Impl namespace
{ {
Zone* m_zone; void SetupBlocks(ZoneWriter& writer)
std::unique_ptr<ZoneWriter> m_writer;
public:
explicit Impl(Zone* zone)
: m_zone(zone),
m_writer(std::make_unique<ZoneWriter>())
{
}
void SetupBlocks() const
{ {
#define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type) #define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type)
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_CALLBACK, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_CALLBACK, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_VERTEX, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_VERTEX, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_INDEX, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_INDEX, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(XFILE_BLOCK_SCRIPT, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(XFILE_BLOCK_SCRIPT, XBlock::Type::BLOCK_TYPE_NORMAL));
#undef XBLOCK_DEF #undef XBLOCK_DEF
} }
static ZoneHeader CreateHeaderForParams(const bool isSecure, const bool isOfficial) ZoneHeader CreateHeaderForParams(const bool isSecure, const bool isOfficial)
{ {
ZoneHeader header{}; ZoneHeader header{};
header.m_version = ZoneConstants::ZONE_VERSION; header.m_version = ZoneConstants::ZONE_VERSION;
@ -66,49 +56,39 @@ public:
return header; return header;
} }
}; // namespace
std::unique_ptr<ZoneWriter> CreateWriter()
{
// TODO Support signed fastfiles
bool isSecure = false;
SetupBlocks();
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
std::make_unique<ContentWriter>(), m_zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
auto* contentInMemoryPtr = contentInMemory.get();
m_writer->AddWritingStep(std::move(contentInMemory));
// Write zone header
m_writer->AddWritingStep(std::make_unique<StepWriteZoneHeader>(CreateHeaderForParams(isSecure, false)));
// Write dummy byte that the game ignores as well. No clue what it means.
m_writer->AddWritingStep(std::make_unique<StepWriteZero>(1));
// Write timestamp
m_writer->AddWritingStep(std::make_unique<StepWriteTimestamp>());
m_writer->AddWritingStep(std::make_unique<StepAddOutputProcessor>(std::make_unique<OutputProcessorDeflate>()));
// Start of the XFile struct
m_writer->AddWritingStep(std::make_unique<StepWriteZoneSizes>(contentInMemoryPtr));
m_writer->AddWritingStep(std::make_unique<StepWriteXBlockSizes>(m_zone));
// Start of the zone content
m_writer->AddWritingStep(std::make_unique<StepWriteZoneContentToFile>(contentInMemoryPtr));
// Return the fully setup zoneloader
return std::move(m_writer);
}
};
bool ZoneWriterFactory::SupportsZone(Zone* zone) const
{
return zone->m_game == &g_GameIW5;
}
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
{ {
Impl impl(zone); auto writer = std::make_unique<ZoneWriter>();
return impl.CreateWriter();
// TODO Support signed fastfiles
bool isSecure = false;
SetupBlocks(*writer);
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
std::make_unique<ContentWriter>(), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
auto* contentInMemoryPtr = contentInMemory.get();
writer->AddWritingStep(std::move(contentInMemory));
// Write zone header
writer->AddWritingStep(std::make_unique<StepWriteZoneHeader>(CreateHeaderForParams(isSecure, false)));
// Write dummy byte that the game ignores as well. No clue what it means.
writer->AddWritingStep(std::make_unique<StepWriteZero>(1));
// Write timestamp
writer->AddWritingStep(std::make_unique<StepWriteTimestamp>());
writer->AddWritingStep(std::make_unique<StepAddOutputProcessor>(std::make_unique<OutputProcessorDeflate>()));
// Start of the XFile struct
writer->AddWritingStep(std::make_unique<StepWriteZoneSizes>(contentInMemoryPtr));
writer->AddWritingStep(std::make_unique<StepWriteXBlockSizes>(zone));
// Start of the zone content
writer->AddWritingStep(std::make_unique<StepWriteZoneContentToFile>(contentInMemoryPtr));
return std::move(writer);
} }

View File

@ -8,10 +8,7 @@ namespace IW5
{ {
class ZoneWriterFactory final : public IZoneWriterFactory class ZoneWriterFactory final : public IZoneWriterFactory
{ {
class Impl;
public: public:
_NODISCARD bool SupportsZone(Zone* zone) const override;
_NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override; _NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override;
}; };
} // namespace IW5 } // namespace IW5

View File

@ -16,34 +16,24 @@
using namespace T5; using namespace T5;
class ZoneWriterFactory::Impl namespace
{ {
Zone* m_zone; void SetupBlocks(ZoneWriter& writer)
std::unique_ptr<ZoneWriter> m_writer;
public:
explicit Impl(Zone* zone)
: m_zone(zone),
m_writer(std::make_unique<ZoneWriter>())
{
}
void SetupBlocks() const
{ {
#define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type) #define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type)
m_writer->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP)); writer.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
m_writer->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME)); writer.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
m_writer->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_LARGE_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME)); writer.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_LARGE_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
m_writer->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_PHYSICAL_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME)); writer.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_PHYSICAL_RUNTIME, XBlock::Type::BLOCK_TYPE_RUNTIME));
m_writer->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_LARGE, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(T5::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL));
#undef XBLOCK_DEF #undef XBLOCK_DEF
} }
static ZoneHeader CreateHeaderForParams() ZoneHeader CreateHeaderForParams()
{ {
ZoneHeader header{}; ZoneHeader header{};
header.m_version = ZoneConstants::ZONE_VERSION; header.m_version = ZoneConstants::ZONE_VERSION;
@ -51,40 +41,30 @@ public:
return header; return header;
} }
} // namespace
std::unique_ptr<ZoneWriter> CreateWriter()
{
SetupBlocks();
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
std::make_unique<ContentWriter>(), m_zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
auto* contentInMemoryPtr = contentInMemory.get();
m_writer->AddWritingStep(std::move(contentInMemory));
// Write zone header
m_writer->AddWritingStep(std::make_unique<StepWriteZoneHeader>(CreateHeaderForParams()));
m_writer->AddWritingStep(std::make_unique<StepAddOutputProcessor>(std::make_unique<OutputProcessorDeflate>()));
// Start of the XFile struct
m_writer->AddWritingStep(std::make_unique<StepWriteZoneSizes>(contentInMemoryPtr));
m_writer->AddWritingStep(std::make_unique<StepWriteXBlockSizes>(m_zone));
// Start of the zone content
m_writer->AddWritingStep(std::make_unique<StepWriteZoneContentToFile>(contentInMemoryPtr));
// Return the fully setup zoneloader
return std::move(m_writer);
}
};
bool ZoneWriterFactory::SupportsZone(Zone* zone) const
{
return zone->m_game == &g_GameT5;
}
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
{ {
Impl impl(zone); auto writer = std::make_unique<ZoneWriter>();
return impl.CreateWriter();
SetupBlocks(*writer);
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
std::make_unique<ContentWriter>(), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
auto* contentInMemoryPtr = contentInMemory.get();
writer->AddWritingStep(std::move(contentInMemory));
// Write zone header
writer->AddWritingStep(std::make_unique<StepWriteZoneHeader>(CreateHeaderForParams()));
writer->AddWritingStep(std::make_unique<StepAddOutputProcessor>(std::make_unique<OutputProcessorDeflate>()));
// Start of the XFile struct
writer->AddWritingStep(std::make_unique<StepWriteZoneSizes>(contentInMemoryPtr));
writer->AddWritingStep(std::make_unique<StepWriteXBlockSizes>(zone));
// Start of the zone content
writer->AddWritingStep(std::make_unique<StepWriteZoneContentToFile>(contentInMemoryPtr));
return std::move(writer);
} }

View File

@ -11,7 +11,6 @@ namespace T5
class Impl; class Impl;
public: public:
_NODISCARD bool SupportsZone(Zone* zone) const override;
_NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override; _NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override;
}; };
} // namespace T5 } // namespace T5

View File

@ -23,35 +23,25 @@
using namespace T6; using namespace T6;
class ZoneWriterFactory::Impl namespace
{ {
Zone* m_zone; void SetupBlocks(ZoneWriter& writer)
std::unique_ptr<ZoneWriter> m_writer;
public:
explicit Impl(Zone* zone)
: m_zone(zone),
m_writer(std::make_unique<ZoneWriter>())
{
}
void SetupBlocks() const
{ {
#define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type) #define XBLOCK_DEF(name, type) std::make_unique<XBlock>(STR(name), name, type)
m_writer->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP)); writer.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_TEMP, XBlock::Type::BLOCK_TYPE_TEMP));
m_writer->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_RUNTIME_VIRTUAL, XBlock::Type::BLOCK_TYPE_RUNTIME)); writer.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_RUNTIME_VIRTUAL, XBlock::Type::BLOCK_TYPE_RUNTIME));
m_writer->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_RUNTIME_PHYSICAL, XBlock::Type::BLOCK_TYPE_RUNTIME)); writer.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_RUNTIME_PHYSICAL, XBlock::Type::BLOCK_TYPE_RUNTIME));
m_writer->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_DELAY_VIRTUAL, XBlock::Type::BLOCK_TYPE_DELAY)); writer.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_DELAY_VIRTUAL, XBlock::Type::BLOCK_TYPE_DELAY));
m_writer->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_DELAY_PHYSICAL, XBlock::Type::BLOCK_TYPE_DELAY)); writer.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_DELAY_PHYSICAL, XBlock::Type::BLOCK_TYPE_DELAY));
m_writer->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_VIRTUAL, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_PHYSICAL, XBlock::Type::BLOCK_TYPE_NORMAL));
m_writer->AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_STREAMER_RESERVE, XBlock::Type::BLOCK_TYPE_NORMAL)); writer.AddXBlock(XBLOCK_DEF(T6::XFILE_BLOCK_STREAMER_RESERVE, XBlock::Type::BLOCK_TYPE_NORMAL));
#undef XBLOCK_DEF #undef XBLOCK_DEF
} }
static ZoneHeader CreateHeaderForParams(const bool isSecure, const bool isOfficial, const bool isEncrypted) ZoneHeader CreateHeaderForParams(const bool isSecure, const bool isOfficial, const bool isEncrypted)
{ {
ZoneHeader header{}; ZoneHeader header{};
header.m_version = ZoneConstants::ZONE_VERSION; header.m_version = ZoneConstants::ZONE_VERSION;
@ -74,7 +64,11 @@ public:
return header; return header;
} }
void AddXChunkProcessor(const bool isEncrypted, ICapturedDataProvider** dataToSignProviderPtr, OutputProcessorXChunks** xChunkProcessorPtr) const void AddXChunkProcessor(ZoneWriter& writer,
const Zone& zone,
const bool isEncrypted,
ICapturedDataProvider** dataToSignProviderPtr,
OutputProcessorXChunks** xChunkProcessorPtr)
{ {
auto xChunkProcessor = std::make_unique<OutputProcessorXChunks>( auto xChunkProcessor = std::make_unique<OutputProcessorXChunks>(
ZoneConstants::STREAM_COUNT, ZoneConstants::XCHUNK_SIZE, ZoneConstants::XCHUNK_MAX_WRITE_SIZE, ZoneConstants::VANILLA_BUFFER_SIZE); ZoneConstants::STREAM_COUNT, ZoneConstants::XCHUNK_SIZE, ZoneConstants::XCHUNK_MAX_WRITE_SIZE, ZoneConstants::VANILLA_BUFFER_SIZE);
@ -88,7 +82,7 @@ public:
{ {
// If zone is encrypted, the decryption is applied before the decompression. T6 Zones always use Salsa20. // If zone is encrypted, the decryption is applied before the decompression. T6 Zones always use Salsa20.
auto chunkProcessorSalsa20 = std::make_unique<XChunkProcessorSalsa20Encryption>( auto chunkProcessorSalsa20 = std::make_unique<XChunkProcessorSalsa20Encryption>(
ZoneConstants::STREAM_COUNT, m_zone->m_name, ZoneConstants::SALSA20_KEY_TREYARCH, sizeof(ZoneConstants::SALSA20_KEY_TREYARCH)); ZoneConstants::STREAM_COUNT, zone.m_name, ZoneConstants::SALSA20_KEY_TREYARCH, sizeof(ZoneConstants::SALSA20_KEY_TREYARCH));
// If there is encryption, the signed data of the zone is the final hash blocks provided by the Salsa20 IV adaption algorithm // If there is encryption, the signed data of the zone is the final hash blocks provided by the Salsa20 IV adaption algorithm
if (dataToSignProviderPtr) if (dataToSignProviderPtr)
@ -97,58 +91,48 @@ public:
xChunkProcessor->AddChunkProcessor(std::move(chunkProcessorSalsa20)); xChunkProcessor->AddChunkProcessor(std::move(chunkProcessorSalsa20));
} }
m_writer->AddWritingStep(std::make_unique<StepAddOutputProcessor>(std::move(xChunkProcessor))); writer.AddWritingStep(std::make_unique<StepAddOutputProcessor>(std::move(xChunkProcessor)));
} }
}; // namespace
std::unique_ptr<ZoneWriter> CreateWriter()
{
// TODO Support signed fastfiles
bool isSecure = false;
bool isEncrypted = true;
SetupBlocks();
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
std::make_unique<ContentWriter>(), m_zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
auto* contentInMemoryPtr = contentInMemory.get();
m_writer->AddWritingStep(std::move(contentInMemory));
// Write zone header
m_writer->AddWritingStep(std::make_unique<StepWriteZoneHeader>(CreateHeaderForParams(isSecure, false, isEncrypted)));
// Setup loading XChunks from the zone from this point on.
ICapturedDataProvider* dataToSignProvider;
OutputProcessorXChunks* xChunksProcessor;
AddXChunkProcessor(isEncrypted, &dataToSignProvider, &xChunksProcessor);
// Start of the XFile struct
// m_writer->AddWritingStep(std::make_unique<StepSkipBytes>(8)); // Skip size and externalSize fields since they are not interesting for us
m_writer->AddWritingStep(std::make_unique<StepWriteZoneSizes>(contentInMemoryPtr));
m_writer->AddWritingStep(std::make_unique<StepWriteXBlockSizes>(m_zone));
// Start of the zone content
m_writer->AddWritingStep(std::make_unique<StepWriteZoneContentToFile>(contentInMemoryPtr));
// Stop writing in XChunks
m_writer->AddWritingStep(std::make_unique<StepRemoveOutputProcessor>(xChunksProcessor));
// Pad ending with zeros like the original linker does it. The game's reader needs it for some reason.
// From my observations this is most likely the logic behind the amount of bytes: At least 0x40 bytes and aligned to the next 0x40
m_writer->AddWritingStep(std::make_unique<StepWriteZero>(ZoneConstants::FILE_SUFFIX_ZERO_MIN_SIZE));
m_writer->AddWritingStep(std::make_unique<StepAlign>(ZoneConstants::FILE_SUFFIX_ZERO_ALIGN, '\0'));
// Return the fully setup zoneloader
return std::move(m_writer);
}
};
bool ZoneWriterFactory::SupportsZone(Zone* zone) const
{
return zone->m_game == &g_GameT6;
}
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
{ {
Impl impl(zone); auto writer = std::make_unique<ZoneWriter>();
return impl.CreateWriter();
// TODO Support signed fastfiles
bool isSecure = false;
bool isEncrypted = true;
SetupBlocks(*writer);
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
std::make_unique<ContentWriter>(), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
auto* contentInMemoryPtr = contentInMemory.get();
writer->AddWritingStep(std::move(contentInMemory));
// Write zone header
writer->AddWritingStep(std::make_unique<StepWriteZoneHeader>(CreateHeaderForParams(isSecure, false, isEncrypted)));
// Setup loading XChunks from the zone from this point on.
ICapturedDataProvider* dataToSignProvider;
OutputProcessorXChunks* xChunksProcessor;
AddXChunkProcessor(*writer, *zone, isEncrypted, &dataToSignProvider, &xChunksProcessor);
// Start of the XFile struct
// m_writer->AddWritingStep(std::make_unique<StepSkipBytes>(8)); // Skip size and externalSize fields since they are not interesting for us
writer->AddWritingStep(std::make_unique<StepWriteZoneSizes>(contentInMemoryPtr));
writer->AddWritingStep(std::make_unique<StepWriteXBlockSizes>(zone));
// Start of the zone content
writer->AddWritingStep(std::make_unique<StepWriteZoneContentToFile>(contentInMemoryPtr));
// Stop writing in XChunks
writer->AddWritingStep(std::make_unique<StepRemoveOutputProcessor>(xChunksProcessor));
// Pad ending with zeros like the original linker does it. The game's reader needs it for some reason.
// From my observations this is most likely the logic behind the amount of bytes: At least 0x40 bytes and aligned to the next 0x40
writer->AddWritingStep(std::make_unique<StepWriteZero>(ZoneConstants::FILE_SUFFIX_ZERO_MIN_SIZE));
writer->AddWritingStep(std::make_unique<StepAlign>(ZoneConstants::FILE_SUFFIX_ZERO_ALIGN, '\0'));
return std::move(writer);
} }

View File

@ -11,7 +11,6 @@ namespace T6
class Impl; class Impl;
public: public:
_NODISCARD bool SupportsZone(Zone* zone) const override;
_NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override; _NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override;
}; };
} // namespace T6 } // namespace T6

View File

@ -0,0 +1,27 @@
#include "IZoneWriterFactory.h"
#include "Game/IW3/ZoneWriterFactoryIW3.h"
#include "Game/IW4/ZoneWriterFactoryIW4.h"
#include "Game/IW5/ZoneWriterFactoryIW5.h"
#include "Game/T5/ZoneWriterFactoryT5.h"
#include "Game/T6/ZoneWriterFactoryT6.h"
#include <cassert>
const IZoneWriterFactory* IZoneWriterFactory::GetZoneWriterFactoryForGame(GameId game)
{
static const IZoneWriterFactory* zoneCreators[static_cast<unsigned>(GameId::COUNT)]{
new IW3::ZoneWriterFactory(),
new IW4::ZoneWriterFactory(),
new IW5::ZoneWriterFactory(),
new T5::ZoneWriterFactory(),
new T6::ZoneWriterFactory(),
};
static_assert(std::extent_v<decltype(zoneCreators)> == static_cast<unsigned>(GameId::COUNT));
assert(static_cast<unsigned>(game) < static_cast<unsigned>(GameId::COUNT));
const auto* result = zoneCreators[static_cast<unsigned>(game)];
assert(result);
return result;
}

View File

@ -14,6 +14,7 @@ public:
IZoneWriterFactory& operator=(const IZoneWriterFactory& other) = default; IZoneWriterFactory& operator=(const IZoneWriterFactory& other) = default;
IZoneWriterFactory& operator=(IZoneWriterFactory&& other) noexcept = default; IZoneWriterFactory& operator=(IZoneWriterFactory&& other) noexcept = default;
_NODISCARD virtual bool SupportsZone(Zone* zone) const = 0;
_NODISCARD virtual std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const = 0; _NODISCARD virtual std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const = 0;
static const IZoneWriterFactory* GetZoneWriterFactoryForGame(GameId game);
}; };

View File

@ -3,6 +3,7 @@
#include "WritingException.h" #include "WritingException.h"
#include "WritingFileStream.h" #include "WritingFileStream.h"
#include <format>
#include <iostream> #include <iostream>
#include <stdexcept> #include <stdexcept>
@ -42,7 +43,7 @@ void ZoneWriter::AddStreamProcessor(std::unique_ptr<OutputStreamProcessor> strea
m_processor_chain_dirty = true; m_processor_chain_dirty = true;
} }
void ZoneWriter::RemoveStreamProcessor(OutputStreamProcessor* streamProcessor) void ZoneWriter::RemoveStreamProcessor(const OutputStreamProcessor* streamProcessor)
{ {
for (auto i = m_processors.begin(); i < m_processors.end(); ++i) for (auto i = m_processors.begin(); i < m_processors.end(); ++i)
{ {
@ -72,12 +73,12 @@ bool ZoneWriter::WriteZone(std::ostream& stream)
} }
catch (WritingException& e) catch (WritingException& e)
{ {
std::cout << "Writing fastfile failed: " << e.Message() << "\n"; std::cout << std::format("Writing fastfile failed: {}\n", e.Message());
return false; return false;
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
std::cout << "Writing fastfile failed: " << e.what() << "\n"; std::cout << std::format("Writing fastfile failed: {}\n", e.what());
return false; return false;
} }

View File

@ -27,7 +27,7 @@ public:
void AddWritingStep(std::unique_ptr<IWritingStep> step); void AddWritingStep(std::unique_ptr<IWritingStep> step);
void AddStreamProcessor(std::unique_ptr<OutputStreamProcessor> streamProcessor); void AddStreamProcessor(std::unique_ptr<OutputStreamProcessor> streamProcessor);
void RemoveStreamProcessor(OutputStreamProcessor* streamProcessor); void RemoveStreamProcessor(const OutputStreamProcessor* streamProcessor);
bool WriteZone(std::ostream& stream); bool WriteZone(std::ostream& stream);
}; };

View File

@ -1,38 +1,18 @@
#include "ZoneWriting.h" #include "ZoneWriting.h"
#include "Game/IW3/ZoneWriterFactoryIW3.h"
#include "Game/IW4/ZoneWriterFactoryIW4.h"
#include "Game/IW5/ZoneWriterFactoryIW5.h"
#include "Game/T5/ZoneWriterFactoryT5.h"
#include "Game/T6/ZoneWriterFactoryT6.h"
#include "Writing/IZoneWriterFactory.h" #include "Writing/IZoneWriterFactory.h"
#include <chrono> #include <chrono>
#include <format> #include <format>
#include <iostream> #include <iostream>
IZoneWriterFactory* ZoneWriterFactories[]{
new IW3::ZoneWriterFactory(),
new IW4::ZoneWriterFactory(),
new IW5::ZoneWriterFactory(),
new T5::ZoneWriterFactory(),
new T6::ZoneWriterFactory(),
};
bool ZoneWriting::WriteZone(std::ostream& stream, Zone* zone) bool ZoneWriting::WriteZone(std::ostream& stream, Zone* zone)
{ {
const auto start = std::chrono::high_resolution_clock::now(); const auto start = std::chrono::high_resolution_clock::now();
std::unique_ptr<ZoneWriter> zoneWriter; const auto factory = IZoneWriterFactory::GetZoneWriterFactoryForGame(zone->m_game->GetId());
for (auto* factory : ZoneWriterFactories)
{
if (factory->SupportsZone(zone))
{
zoneWriter = factory->CreateWriter(zone);
break;
}
}
const auto zoneWriter = factory->CreateWriter(zone);
if (zoneWriter == nullptr) if (zoneWriter == nullptr)
{ {
std::cerr << std::format("Could not create ZoneWriter for zone \"{}\".\n", zone->m_name); std::cerr << std::format("Could not create ZoneWriter for zone \"{}\".\n", zone->m_name);

View File

@ -20,7 +20,7 @@ namespace
"test,data,lol\n" "test,data,lol\n"
"lorem,ipsum"); "lorem,ipsum");
Zone zone("MockZone", 0, &g_GameIW3); Zone zone("MockZone", 0, IGame::GetGameById(GameId::IW3));
MockAssetLoadingManager assetLoadingManager(zone, searchPath); MockAssetLoadingManager assetLoadingManager(zone, searchPath);
AssetLoaderStringTable assetLoader; AssetLoaderStringTable assetLoader;

View File

@ -21,7 +21,7 @@ namespace
"test,data,lol\n" "test,data,lol\n"
"lorem,ipsum"); "lorem,ipsum");
Zone zone("MockZone", 0, &g_GameIW4); Zone zone("MockZone", 0, IGame::GetGameById(GameId::IW4));
MockAssetLoadingManager assetLoadingManager(zone, searchPath); MockAssetLoadingManager assetLoadingManager(zone, searchPath);
AssetLoaderStringTable assetLoader; AssetLoaderStringTable assetLoader;

View File

@ -28,7 +28,7 @@ namespace test::game::iw4::menu::parsing::it
public: public:
MenuParsingItHelper() MenuParsingItHelper()
: m_zone("MockZone", 0, &g_GameIW4), : m_zone("MockZone", 0, IGame::GetGameById(GameId::IW4)),
m_manager(m_zone, m_search_path) m_manager(m_zone, m_search_path)
{ {
} }

View File

@ -20,7 +20,7 @@ namespace
"test,data,lol\n" "test,data,lol\n"
"lorem,ipsum"); "lorem,ipsum");
Zone zone("MockZone", 0, &g_GameIW5); Zone zone("MockZone", 0, IGame::GetGameById(GameId::IW5));
MockAssetLoadingManager assetLoadingManager(zone, searchPath); MockAssetLoadingManager assetLoadingManager(zone, searchPath);
AssetLoaderStringTable assetLoader; AssetLoaderStringTable assetLoader;

View File

@ -20,7 +20,7 @@ namespace
"test,data,lol\n" "test,data,lol\n"
"lorem,ipsum"); "lorem,ipsum");
Zone zone("MockZone", 0, &g_GameT5); Zone zone("MockZone", 0, IGame::GetGameById(GameId::T5));
MockAssetLoadingManager assetLoadingManager(zone, searchPath); MockAssetLoadingManager assetLoadingManager(zone, searchPath);
AssetLoaderStringTable assetLoader; AssetLoaderStringTable assetLoader;

View File

@ -20,7 +20,7 @@ namespace
"test,data,lol\n" "test,data,lol\n"
"lorem,ipsum"); "lorem,ipsum");
Zone zone("MockZone", 0, &g_GameT6); Zone zone("MockZone", 0, IGame::GetGameById(GameId::T6));
MockAssetLoadingManager assetLoadingManager(zone, searchPath); MockAssetLoadingManager assetLoadingManager(zone, searchPath);
AssetLoaderStringTable assetLoader; AssetLoaderStringTable assetLoader;