mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-12-27 12:31:50 +00:00
chore: move ZoneDefinitionWriter from Unlinker to ZoneCommon
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
#include "ZoneDefWriter.h"
|
||||
|
||||
#include "Game/IW3/ZoneDefWriterIW3.h"
|
||||
#include "Game/IW4/ZoneDefWriterIW4.h"
|
||||
#include "Game/IW5/ZoneDefWriterIW5.h"
|
||||
#include "Game/T5/ZoneDefWriterT5.h"
|
||||
#include "Game/T6/ZoneDefWriterT6.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
const IZoneDefWriter* IZoneDefWriter::GetZoneDefWriterForGame(GameId game)
|
||||
{
|
||||
static const IZoneDefWriter* zoneDefWriters[static_cast<unsigned>(GameId::COUNT)]{
|
||||
new IW3::ZoneDefWriter(),
|
||||
new IW4::ZoneDefWriter(),
|
||||
new IW5::ZoneDefWriter(),
|
||||
new T5::ZoneDefWriter(),
|
||||
new T6::ZoneDefWriter(),
|
||||
};
|
||||
|
||||
assert(static_cast<unsigned>(game) < static_cast<unsigned>(GameId::COUNT));
|
||||
const auto* result = zoneDefWriters[static_cast<unsigned>(game)];
|
||||
assert(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void AbstractZoneDefWriter::WriteZoneDef(std::ostream& stream, const UnlinkerArgs& args, const Zone& zone) const
|
||||
{
|
||||
ZoneDefinitionOutputStream out(stream);
|
||||
const auto* game = IGame::GetGameById(zone.m_game_id);
|
||||
|
||||
out.WriteComment(game->GetFullName());
|
||||
out.WriteMetaData(META_DATA_KEY_GAME, game->GetShortName());
|
||||
out.EmptyLine();
|
||||
|
||||
if (args.m_use_gdt)
|
||||
{
|
||||
out.WriteComment("Load asset gdt files");
|
||||
out.WriteMetaData(META_DATA_KEY_GDT, zone.m_name);
|
||||
out.EmptyLine();
|
||||
}
|
||||
|
||||
WriteMetaData(out, args, zone);
|
||||
WriteContent(out, args, zone);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "UnlinkerArgs.h"
|
||||
#include "Zone/Definition/ZoneDefinitionStream.h"
|
||||
|
||||
class IZoneDefWriter
|
||||
{
|
||||
public:
|
||||
IZoneDefWriter() = default;
|
||||
virtual ~IZoneDefWriter() = default;
|
||||
IZoneDefWriter(const IZoneDefWriter& other) = default;
|
||||
IZoneDefWriter(IZoneDefWriter&& other) noexcept = default;
|
||||
IZoneDefWriter& operator=(const IZoneDefWriter& other) = default;
|
||||
IZoneDefWriter& operator=(IZoneDefWriter&& other) noexcept = default;
|
||||
|
||||
virtual void WriteZoneDef(std::ostream& stream, const UnlinkerArgs& args, const Zone& zone) const = 0;
|
||||
|
||||
static const IZoneDefWriter* GetZoneDefWriterForGame(GameId game);
|
||||
};
|
||||
|
||||
class AbstractZoneDefWriter : public IZoneDefWriter
|
||||
{
|
||||
protected:
|
||||
static constexpr auto META_DATA_KEY_GAME = "game";
|
||||
static constexpr auto META_DATA_KEY_GDT = "gdt";
|
||||
|
||||
virtual void WriteMetaData(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const = 0;
|
||||
virtual void WriteContent(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const = 0;
|
||||
|
||||
public:
|
||||
void WriteZoneDef(std::ostream& stream, const UnlinkerArgs& args, const Zone& zone) const override;
|
||||
};
|
||||
@@ -1,35 +0,0 @@
|
||||
#include "ZoneDefWriterIW3.h"
|
||||
|
||||
#include "Game/IW3/GameAssetPoolIW3.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const {}
|
||||
|
||||
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const
|
||||
{
|
||||
const auto* pools = dynamic_cast<GameAssetPoolIW3*>(zone.m_pools.get());
|
||||
|
||||
assert(pools);
|
||||
if (!pools)
|
||||
return;
|
||||
|
||||
// Localized strings are all collected in one string file. So only add this to the zone file.
|
||||
if (!pools->m_localize->m_asset_lookup.empty())
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
case ASSET_TYPE_LOCALIZE_ENTRY:
|
||||
break;
|
||||
|
||||
default:
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "ContentLister/ZoneDefWriter.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class ZoneDefWriter final : public AbstractZoneDefWriter
|
||||
{
|
||||
protected:
|
||||
void WriteMetaData(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const override;
|
||||
void WriteContent(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const override;
|
||||
};
|
||||
} // namespace IW3
|
||||
@@ -1,35 +0,0 @@
|
||||
#include "ZoneDefWriterIW4.h"
|
||||
|
||||
#include "Game/IW4/GameAssetPoolIW4.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const {}
|
||||
|
||||
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const
|
||||
{
|
||||
const auto* pools = dynamic_cast<GameAssetPoolIW4*>(zone.m_pools.get());
|
||||
|
||||
assert(pools);
|
||||
if (!pools)
|
||||
return;
|
||||
|
||||
// Localized strings are all collected in one string file. So only add this to the zone file.
|
||||
if (!pools->m_localize->m_asset_lookup.empty())
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
case ASSET_TYPE_LOCALIZE_ENTRY:
|
||||
break;
|
||||
|
||||
default:
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "ContentLister/ZoneDefWriter.h"
|
||||
|
||||
namespace IW4
|
||||
{
|
||||
class ZoneDefWriter final : public AbstractZoneDefWriter
|
||||
{
|
||||
protected:
|
||||
void WriteMetaData(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const override;
|
||||
void WriteContent(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const override;
|
||||
};
|
||||
} // namespace IW4
|
||||
@@ -1,35 +0,0 @@
|
||||
#include "ZoneDefWriterIW5.h"
|
||||
|
||||
#include "Game/IW5/GameAssetPoolIW5.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const {}
|
||||
|
||||
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const
|
||||
{
|
||||
const auto* pools = dynamic_cast<GameAssetPoolIW5*>(zone.m_pools.get());
|
||||
|
||||
assert(pools);
|
||||
if (!pools)
|
||||
return;
|
||||
|
||||
// Localized strings are all collected in one string file. So only add this to the zone file.
|
||||
if (!pools->m_localize->m_asset_lookup.empty())
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
case ASSET_TYPE_LOCALIZE_ENTRY:
|
||||
break;
|
||||
|
||||
default:
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "ContentLister/ZoneDefWriter.h"
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
class ZoneDefWriter final : public AbstractZoneDefWriter
|
||||
{
|
||||
protected:
|
||||
void WriteMetaData(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const override;
|
||||
void WriteContent(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const override;
|
||||
};
|
||||
} // namespace IW5
|
||||
@@ -1,35 +0,0 @@
|
||||
#include "ZoneDefWriterT5.h"
|
||||
|
||||
#include "Game/T5/GameAssetPoolT5.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace T5;
|
||||
|
||||
void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const {}
|
||||
|
||||
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const
|
||||
{
|
||||
const auto* pools = dynamic_cast<GameAssetPoolT5*>(zone.m_pools.get());
|
||||
|
||||
assert(pools);
|
||||
if (!pools)
|
||||
return;
|
||||
|
||||
// Localized strings are all collected in one string file. So only add this to the zone file.
|
||||
if (!pools->m_localize->m_asset_lookup.empty())
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
case ASSET_TYPE_LOCALIZE_ENTRY:
|
||||
break;
|
||||
|
||||
default:
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "ContentLister/ZoneDefWriter.h"
|
||||
|
||||
namespace T5
|
||||
{
|
||||
class ZoneDefWriter final : public AbstractZoneDefWriter
|
||||
{
|
||||
protected:
|
||||
void WriteMetaData(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const override;
|
||||
void WriteContent(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const override;
|
||||
};
|
||||
} // namespace T5
|
||||
@@ -1,92 +0,0 @@
|
||||
#include "ZoneDefWriterT6.h"
|
||||
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/GameAssetPoolT6.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
using namespace T6;
|
||||
|
||||
namespace
|
||||
{
|
||||
class KeyValuePairKnownKey
|
||||
{
|
||||
public:
|
||||
std::string m_key;
|
||||
int m_hash;
|
||||
|
||||
explicit KeyValuePairKnownKey(std::string key)
|
||||
{
|
||||
m_key = std::move(key);
|
||||
m_hash = Common::Com_HashKey(m_key.c_str(), 64);
|
||||
}
|
||||
};
|
||||
|
||||
const KeyValuePairKnownKey KEY_VALUE_PAIR_KNOWN_KEYS[]{
|
||||
KeyValuePairKnownKey("ipak_read"),
|
||||
KeyValuePairKnownKey("ipak_write"),
|
||||
KeyValuePairKnownKey("initial_xmodels"),
|
||||
KeyValuePairKnownKey("initial_materials"),
|
||||
};
|
||||
|
||||
void WriteKeyValuePair(ZoneDefinitionOutputStream& stream, const KeyValuePair& kvp)
|
||||
{
|
||||
for (const auto& knownKey : KEY_VALUE_PAIR_KNOWN_KEYS)
|
||||
{
|
||||
if (knownKey.m_hash == kvp.keyHash)
|
||||
{
|
||||
stream.WriteMetaData("level." + knownKey.m_key, kvp.value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostringstream str;
|
||||
str << "level.@" << std::setfill('0') << std::setw(sizeof(int) * 2) << std::hex << kvp.keyHash;
|
||||
stream.WriteMetaData(str.str(), kvp.value);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const
|
||||
{
|
||||
const auto* assetPoolT6 = dynamic_cast<GameAssetPoolT6*>(zone.m_pools.get());
|
||||
if (assetPoolT6 && !assetPoolT6->m_key_value_pairs->m_asset_lookup.empty())
|
||||
{
|
||||
for (const auto* kvpAsset : *assetPoolT6->m_key_value_pairs)
|
||||
{
|
||||
const auto* keyValuePairs = kvpAsset->Asset();
|
||||
for (auto varIndex = 0u; varIndex < keyValuePairs->numVariables; varIndex++)
|
||||
WriteKeyValuePair(stream, keyValuePairs->keyValuePairs[varIndex]);
|
||||
}
|
||||
|
||||
stream.EmptyLine();
|
||||
}
|
||||
}
|
||||
|
||||
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const
|
||||
{
|
||||
const auto* pools = dynamic_cast<GameAssetPoolT6*>(zone.m_pools.get());
|
||||
|
||||
assert(pools);
|
||||
if (!pools)
|
||||
return;
|
||||
|
||||
// Localized strings are all collected in one string file. So only add this to the zone file.
|
||||
if (!pools->m_localize->m_asset_lookup.empty())
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
case ASSET_TYPE_LOCALIZE_ENTRY:
|
||||
case ASSET_TYPE_KEYVALUEPAIRS: // KeyValuePairs should be included as zone file metadata and not as content
|
||||
break;
|
||||
|
||||
default:
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "ContentLister/ZoneDefWriter.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
class ZoneDefWriter final : public AbstractZoneDefWriter
|
||||
{
|
||||
protected:
|
||||
void WriteMetaData(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const override;
|
||||
void WriteContent(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const override;
|
||||
};
|
||||
} // namespace T6
|
||||
@@ -1,19 +1,17 @@
|
||||
#include "Unlinker.h"
|
||||
|
||||
#include "ContentLister/ContentPrinter.h"
|
||||
#include "ContentLister/ZoneDefWriter.h"
|
||||
#include "IObjLoader.h"
|
||||
#include "IObjWriter.h"
|
||||
#include "ObjWriting.h"
|
||||
#include "SearchPath/IWD.h"
|
||||
#include "SearchPath/OutputPathFilesystem.h"
|
||||
#include "SearchPath/SearchPathFilesystem.h"
|
||||
#include "SearchPath/SearchPaths.h"
|
||||
#include "UnlinkerArgs.h"
|
||||
#include "UnlinkerPaths.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
#include "Utils/ObjFileStream.h"
|
||||
#include "Zone/Definition/ZoneDefWriter.h"
|
||||
#include "ZoneLoading.h"
|
||||
|
||||
#include <cassert>
|
||||
@@ -21,7 +19,6 @@
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <regex>
|
||||
#include <set>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -54,12 +51,12 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
_NODISCARD bool ShouldLoadObj() const
|
||||
[[nodiscard]] bool ShouldLoadObj() const
|
||||
{
|
||||
return m_args.m_task != UnlinkerArgs::ProcessingTask::LIST && !m_args.m_skip_obj;
|
||||
}
|
||||
|
||||
bool WriteZoneDefinitionFile(const Zone& zone, const fs::path& zoneDefinitionFileFolder) const
|
||||
[[nodiscard]] bool WriteZoneDefinitionFile(const Zone& zone, const fs::path& zoneDefinitionFileFolder) const
|
||||
{
|
||||
auto zoneDefinitionFilePath(zoneDefinitionFileFolder);
|
||||
zoneDefinitionFilePath.append(zone.m_name);
|
||||
@@ -73,7 +70,7 @@ private:
|
||||
}
|
||||
|
||||
const auto* zoneDefWriter = IZoneDefWriter::GetZoneDefWriterForGame(zone.m_game_id);
|
||||
zoneDefWriter->WriteZoneDef(zoneDefinitionFile, m_args, zone);
|
||||
zoneDefWriter->WriteZoneDef(zoneDefinitionFile, zone, m_args.m_use_gdt);
|
||||
|
||||
zoneDefinitionFile.close();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user