mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-11 07:18:11 -05:00
Dump a few iw4 assets
This commit is contained in:
70
src/Unlinker/Game/IW4/ZoneDefWriterIW4.cpp
Normal file
70
src/Unlinker/Game/IW4/ZoneDefWriterIW4.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
#include "ZoneDefWriterIW4.h"
|
||||
#include "Game/IW4/GameIW4.h"
|
||||
#include "Game/IW4/CommonIW4.h"
|
||||
#include "Game/IW4/GameAssetPoolIW4.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <cassert>
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
namespace IW4
|
||||
{
|
||||
class ZoneDefWriterInternal final : public AbstractZoneDefWriter
|
||||
{
|
||||
void WriteContent() const
|
||||
{
|
||||
const auto* pools = dynamic_cast<GameAssetPoolIW4*>(m_zone->GetPools());
|
||||
|
||||
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())
|
||||
{
|
||||
WriteEntry(pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), m_zone->m_name);
|
||||
}
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
case ASSET_TYPE_LOCALIZE_ENTRY:
|
||||
break;
|
||||
|
||||
default:
|
||||
WriteEntry(pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
ZoneDefWriterInternal(Zone* zone, FileAPI::IFile* file)
|
||||
: AbstractZoneDefWriter(zone, file)
|
||||
{
|
||||
}
|
||||
|
||||
void WriteZoneDef() override
|
||||
{
|
||||
WriteComment("Call Of Duty: Modern Warfare 2");
|
||||
WriteMetaData(META_DATA_KEY_GAME, "iw4");
|
||||
EmptyLine();
|
||||
|
||||
WriteContent();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
bool ZoneDefWriter::CanHandleZone(Zone* zone) const
|
||||
{
|
||||
return zone->m_game == &g_GameIW4;
|
||||
}
|
||||
|
||||
void ZoneDefWriter::WriteZoneDef(Zone* zone, FileAPI::IFile* file) const
|
||||
{
|
||||
ZoneDefWriterInternal writer(zone, file);
|
||||
writer.WriteZoneDef();
|
||||
}
|
13
src/Unlinker/Game/IW4/ZoneDefWriterIW4.h
Normal file
13
src/Unlinker/Game/IW4/ZoneDefWriterIW4.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "ContentLister/ZoneDefWriter.h"
|
||||
|
||||
namespace IW4
|
||||
{
|
||||
class ZoneDefWriter final : public IZoneDefWriter
|
||||
{
|
||||
public:
|
||||
bool CanHandleZone(Zone* zone) const override;
|
||||
void WriteZoneDef(Zone* zone, FileAPI::IFile* file) const override;
|
||||
};
|
||||
}
|
@ -9,113 +9,116 @@
|
||||
|
||||
using namespace T6;
|
||||
|
||||
class ZoneDefWriterT6Impl final : public AbstractZoneDefWriter
|
||||
namespace T6
|
||||
{
|
||||
class KnownKey
|
||||
class ZoneDefWriterInternal final : public AbstractZoneDefWriter
|
||||
{
|
||||
public:
|
||||
std::string m_key;
|
||||
int m_hash;
|
||||
|
||||
explicit KnownKey(std::string key)
|
||||
class KnownKey
|
||||
{
|
||||
m_key = std::move(key);
|
||||
m_hash = CommonT6::Com_HashKey(m_key.c_str(), 64);
|
||||
}
|
||||
};
|
||||
public:
|
||||
std::string m_key;
|
||||
int m_hash;
|
||||
|
||||
inline static const KnownKey KNOWN_KEYS[]
|
||||
{
|
||||
KnownKey("ipak_read"),
|
||||
KnownKey("ipak_write"),
|
||||
KnownKey("initial_xmodels"),
|
||||
KnownKey("initial_materials"),
|
||||
};
|
||||
|
||||
void WriteKeyValuePair(KeyValuePair* kvp) const
|
||||
{
|
||||
for (const auto& knownKey : KNOWN_KEYS)
|
||||
{
|
||||
if(knownKey.m_hash == kvp->keyHash)
|
||||
explicit KnownKey(std::string key)
|
||||
{
|
||||
WriteMetaData("level." + knownKey.m_key, kvp->value);
|
||||
return;
|
||||
m_key = std::move(key);
|
||||
m_hash = CommonT6::Com_HashKey(m_key.c_str(), 64);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
std::ostringstream str;
|
||||
str << "level.@" << std::setfill('0') << std::setw(sizeof(int) * 2) << std::hex << kvp->keyHash;
|
||||
WriteMetaData(str.str(), kvp->value);
|
||||
}
|
||||
|
||||
void WriteContent() const
|
||||
{
|
||||
const auto* pools = dynamic_cast<GameAssetPoolT6*>(m_zone->GetPools());
|
||||
|
||||
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())
|
||||
inline static const KnownKey KNOWN_KEYS[]
|
||||
{
|
||||
WriteEntry(pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), m_zone->m_name);
|
||||
}
|
||||
KnownKey("ipak_read"),
|
||||
KnownKey("ipak_write"),
|
||||
KnownKey("initial_xmodels"),
|
||||
KnownKey("initial_materials"),
|
||||
};
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
void WriteKeyValuePair(KeyValuePair* kvp) const
|
||||
{
|
||||
switch (asset->m_type)
|
||||
for (const auto& knownKey : KNOWN_KEYS)
|
||||
{
|
||||
case ASSET_TYPE_LOCALIZE_ENTRY:
|
||||
case ASSET_TYPE_KEYVALUEPAIRS: // KeyValuePairs should be included as zone file metadata and not as content
|
||||
break;
|
||||
|
||||
default:
|
||||
WriteEntry(pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
ZoneDefWriterT6Impl(Zone* zone, FileAPI::IFile* file)
|
||||
: AbstractZoneDefWriter(zone, file)
|
||||
{
|
||||
}
|
||||
|
||||
void WriteZoneDef() override
|
||||
{
|
||||
WriteComment("Call Of Duty: Black Ops II");
|
||||
WriteMetaData(META_DATA_KEY_GAME, "t6");
|
||||
EmptyLine();
|
||||
|
||||
auto* assetPoolT6 = dynamic_cast<GameAssetPoolT6*>(m_zone->GetPools());
|
||||
|
||||
if(assetPoolT6 && !assetPoolT6->m_key_value_pairs->m_asset_lookup.empty())
|
||||
{
|
||||
for (auto kvpAsset : *assetPoolT6->m_key_value_pairs)
|
||||
{
|
||||
KeyValuePairs* keyValuePairs = kvpAsset->Asset();
|
||||
for(int varIndex = 0; varIndex < keyValuePairs->numVariables; varIndex++)
|
||||
if (knownKey.m_hash == kvp->keyHash)
|
||||
{
|
||||
WriteKeyValuePair(&keyValuePairs->keyValuePairs[varIndex]);
|
||||
WriteMetaData("level." + knownKey.m_key, kvp->value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
EmptyLine();
|
||||
std::ostringstream str;
|
||||
str << "level.@" << std::setfill('0') << std::setw(sizeof(int) * 2) << std::hex << kvp->keyHash;
|
||||
WriteMetaData(str.str(), kvp->value);
|
||||
}
|
||||
|
||||
WriteContent();
|
||||
}
|
||||
};
|
||||
void WriteContent() const
|
||||
{
|
||||
const auto* pools = dynamic_cast<GameAssetPoolT6*>(m_zone->GetPools());
|
||||
|
||||
bool ZoneDefWriterT6::CanHandleZone(Zone* zone) const
|
||||
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())
|
||||
{
|
||||
WriteEntry(pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), m_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:
|
||||
WriteEntry(pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
ZoneDefWriterInternal(Zone* zone, FileAPI::IFile* file)
|
||||
: AbstractZoneDefWriter(zone, file)
|
||||
{
|
||||
}
|
||||
|
||||
void WriteZoneDef() override
|
||||
{
|
||||
WriteComment("Call Of Duty: Black Ops II");
|
||||
WriteMetaData(META_DATA_KEY_GAME, "t6");
|
||||
EmptyLine();
|
||||
|
||||
auto* assetPoolT6 = dynamic_cast<GameAssetPoolT6*>(m_zone->GetPools());
|
||||
|
||||
if (assetPoolT6 && !assetPoolT6->m_key_value_pairs->m_asset_lookup.empty())
|
||||
{
|
||||
for (auto kvpAsset : *assetPoolT6->m_key_value_pairs)
|
||||
{
|
||||
KeyValuePairs* keyValuePairs = kvpAsset->Asset();
|
||||
for (int varIndex = 0; varIndex < keyValuePairs->numVariables; varIndex++)
|
||||
{
|
||||
WriteKeyValuePair(&keyValuePairs->keyValuePairs[varIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
EmptyLine();
|
||||
}
|
||||
|
||||
WriteContent();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
bool ZoneDefWriter::CanHandleZone(Zone* zone) const
|
||||
{
|
||||
return zone->m_game == &g_GameT6;
|
||||
}
|
||||
|
||||
void ZoneDefWriterT6::WriteZoneDef(Zone* zone, FileAPI::IFile* file) const
|
||||
void ZoneDefWriter::WriteZoneDef(Zone* zone, FileAPI::IFile* file) const
|
||||
{
|
||||
ZoneDefWriterT6Impl writer(zone, file);
|
||||
ZoneDefWriterInternal writer(zone, file);
|
||||
writer.WriteZoneDef();
|
||||
}
|
||||
|
@ -2,9 +2,12 @@
|
||||
|
||||
#include "ContentLister/ZoneDefWriter.h"
|
||||
|
||||
class ZoneDefWriterT6 final : public IZoneDefWriter
|
||||
namespace T6
|
||||
{
|
||||
public:
|
||||
bool CanHandleZone(Zone* zone) const override;
|
||||
void WriteZoneDef(Zone* zone, FileAPI::IFile* file) const override;
|
||||
};
|
||||
class ZoneDefWriter final : public IZoneDefWriter
|
||||
{
|
||||
public:
|
||||
bool CanHandleZone(Zone* zone) const override;
|
||||
void WriteZoneDef(Zone* zone, FileAPI::IFile* file) const override;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user