iw4x-client/src/Components/Modules/ZoneBuilder.cpp

624 lines
18 KiB
C++
Raw Normal View History

2016-07-11 11:14:58 -04:00
#include "STDInclude.hpp"
namespace Components
{
std::string ZoneBuilder::TraceZone;
std::vector<std::pair<Game::XAssetType, std::string>> ZoneBuilder::TraceAssets;
ZoneBuilder::Zone::Zone(std::string name) : dataMap("zone_source/" + name + ".csv"), zoneName(name), indexStart(0), externalSize(0), branding { 0 },
2016-07-11 11:14:58 -04:00
// Reserve 100MB by default.
// That's totally fine, as the dedi doesn't load images and therefore doesn't need much memory.
// That way we can be sure it won't need to reallocate memory.
// Side note: if you need a fastfile larger than 100MB, you're doing it wrong-
// Well, decompressed maps can get way larger than 100MB, so let's increase that.
buffer(0xC800000)
2016-07-11 11:14:58 -04:00
{}
ZoneBuilder::Zone::~Zone()
{
// Unload our fastfiles
Game::XZoneInfo info;
info.name = nullptr;
info.allocFlags = 0;
2016-10-26 13:15:18 -04:00
info.freeFlags = 0x20;
2016-07-11 11:14:58 -04:00
Game::DB_LoadXAssets(&info, 1, true);
AssetHandler::ClearTemporaryAssets();
Localization::ClearTemp();
this->loadedAssets.clear();
this->scriptStrings.clear();
this->scriptStringMap.clear();
2016-07-11 11:14:58 -04:00
}
Utils::Stream* ZoneBuilder::Zone::getBuffer()
2016-07-11 11:14:58 -04:00
{
return &this->buffer;
2016-07-11 11:14:58 -04:00
}
Utils::Memory::Allocator* ZoneBuilder::Zone::getAllocator()
2016-07-11 11:14:58 -04:00
{
return &this->memAllocator;
2016-07-11 11:14:58 -04:00
}
void ZoneBuilder::Zone::Zone::build()
2016-07-11 11:14:58 -04:00
{
this->loadFastFiles();
2016-07-11 11:14:58 -04:00
Logger::Print("Linking assets...\n");
if (!this->loadAssets()) return;
2016-07-11 11:14:58 -04:00
this->addBranding();
2016-07-11 11:14:58 -04:00
Logger::Print("Saving...\n");
this->saveData();
2016-07-11 11:14:58 -04:00
Logger::Print("Compressing...\n");
this->writeZone();
2016-07-11 11:14:58 -04:00
}
void ZoneBuilder::Zone::loadFastFiles()
2016-07-11 11:14:58 -04:00
{
Logger::Print("Loading required FastFiles...\n");
for (int i = 0; i < this->dataMap.getRows(); ++i)
2016-07-11 11:14:58 -04:00
{
if (this->dataMap.getElementAt(i, 0) == "require")
2016-07-11 11:14:58 -04:00
{
std::string fastfile = this->dataMap.getElementAt(i, 1);
2016-07-11 11:14:58 -04:00
if (!Game::DB_IsZoneLoaded(fastfile.data()))
{
Game::XZoneInfo info;
info.name = fastfile.data();
2016-10-26 13:15:18 -04:00
info.allocFlags = 0x20;
2016-07-11 11:14:58 -04:00
info.freeFlags = 0;
Game::DB_LoadXAssets(&info, 1, true);
}
else
{
Logger::Print("Zone '%s' already loaded\n", fastfile.data());
}
}
}
}
bool ZoneBuilder::Zone::loadAssets()
2016-07-11 11:14:58 -04:00
{
for (int i = 0; i < this->dataMap.getRows(); ++i)
2016-07-11 11:14:58 -04:00
{
if (this->dataMap.getElementAt(i, 0) != "require")
2016-07-11 11:14:58 -04:00
{
if (this->dataMap.getColumns(i) > 2)
2016-07-11 11:14:58 -04:00
{
if (this->dataMap.getElementAt(i, 0) == "localize")
2016-07-11 11:14:58 -04:00
{
std::string stringOverride = this->dataMap.getElementAt(i, 2);
2016-07-11 11:14:58 -04:00
Utils::String::Replace(stringOverride, "\\n", "\n");
Localization::SetTemp(this->dataMap.getElementAt(i, 1), stringOverride);
2016-07-11 11:14:58 -04:00
}
else
{
std::string oldName = this->dataMap.getElementAt(i, 1);
std::string newName = this->dataMap.getElementAt(i, 2);
std::string typeName = this->dataMap.getElementAt(i, 0).data();
2016-10-26 15:50:57 -04:00
Game::XAssetType type = Game::DB_GetXAssetNameType(typeName.data());
if (type < Game::XAssetType::ASSET_TYPE_COUNT && type >= 0)
{
this->renameAsset(type, oldName, newName);
2016-10-26 15:50:57 -04:00
}
else
{
Logger::Error("Unable to rename '%s' to '%s' as the asset type '%s' is invalid!", oldName.data(), newName.data(), typeName.data());
}
2016-07-11 11:14:58 -04:00
}
}
if (!this->loadAsset(this->dataMap.getElementAt(i, 0), this->dataMap.getElementAt(i, 1)))
2016-07-11 11:14:58 -04:00
{
return false;
}
}
}
return true;
}
bool ZoneBuilder::Zone::loadAsset(Game::XAssetType type, std::string name)
2016-07-11 11:14:58 -04:00
{
return this->loadAsset(Game::DB_GetXAssetTypeName(type), name);
2016-07-11 11:14:58 -04:00
}
bool ZoneBuilder::Zone::loadAsset(std::string typeName, std::string name)
2016-07-11 11:14:58 -04:00
{
Game::XAssetType type = Game::DB_GetXAssetNameType(typeName.data());
if (this->findAsset(type, name) != -1) return true;
2016-07-11 11:14:58 -04:00
if (type == Game::XAssetType::ASSET_TYPE_INVALID || type >= Game::XAssetType::ASSET_TYPE_COUNT)
{
Logger::Error("Error: Invalid asset type '%s'\n", typeName.data());
return false;
}
Game::XAssetHeader assetHeader = AssetHandler::FindAssetForZone(type, name, this);
if (!assetHeader.data)
{
Logger::Error("Error: Missing asset '%s' of type '%s'\n", name.data(), Game::DB_GetXAssetTypeName(type));
return false;
}
Game::XAsset asset;
asset.type = type;
asset.header = assetHeader;
// Handle script strings and referenced assets
AssetHandler::ZoneMark(asset, this);
this->loadedAssets.push_back(asset);
2016-07-11 11:14:58 -04:00
return true;
}
int ZoneBuilder::Zone::findAsset(Game::XAssetType type, std::string name)
2016-07-11 11:14:58 -04:00
{
for (unsigned int i = 0; i < this->loadedAssets.size(); ++i)
2016-07-11 11:14:58 -04:00
{
Game::XAsset* asset = &this->loadedAssets[i];
2016-07-11 11:14:58 -04:00
if (asset->type != type) continue;
const char* assetName = DB_GetXAssetName(asset);
if (name == assetName)
{
return i;
}
}
return -1;
}
Game::XAsset* ZoneBuilder::Zone::getAsset(int index)
2016-07-11 11:14:58 -04:00
{
if (static_cast<uint32_t>(index) < this->loadedAssets.size())
2016-07-11 11:14:58 -04:00
{
return &this->loadedAssets[index];
2016-07-11 11:14:58 -04:00
}
return nullptr;
}
uint32_t ZoneBuilder::Zone::getAssetOffset(int index)
2016-07-11 11:14:58 -04:00
{
Utils::Stream::Offset offset;
offset.block = Game::XFILE_BLOCK_VIRTUAL;
offset.offset = (this->indexStart + (index * sizeof(Game::XAsset)) + 4);
return offset.getPackedOffset();
2016-07-11 11:14:58 -04:00
}
Game::XAssetHeader ZoneBuilder::Zone::requireAsset(Game::XAssetType type, const char* name)
2016-07-11 11:14:58 -04:00
{
Game::XAssetHeader header;
Utils::Stream::ClearPointer(&header.data);
int assetIndex = this->findAsset(type, name);
2016-07-11 11:14:58 -04:00
if (assetIndex != -1)
{
header.data = reinterpret_cast<void*>(this->getAssetOffset(assetIndex));
2016-07-11 11:14:58 -04:00
}
else
{
Logger::Error("Missing required asset '%s' (%s). Export failed!", name, Game::DB_GetXAssetTypeName(type));
}
return header;
}
void ZoneBuilder::Zone::writeZone()
2016-07-11 11:14:58 -04:00
{
FILETIME fileTime;
GetSystemTimeAsFileTime(&fileTime);
Game::XFileHeader header = { XFILE_MAGIC_UNSIGNED, XFILE_VERSION_IW4X, Game::XFileLanguage::XLANG_NONE, fileTime.dwHighDateTime, fileTime.dwLowDateTime };
std::string outBuffer;
outBuffer.append(reinterpret_cast<char*>(&header), sizeof(header));
std::string zoneBuffer = this->buffer.toBuffer();
2016-07-11 11:14:58 -04:00
zoneBuffer = Utils::Compression::ZLib::Compress(zoneBuffer);
outBuffer.append(zoneBuffer);
std::string outFile = "zone/" + this->zoneName + ".ff";
2016-07-11 11:14:58 -04:00
Utils::IO::WriteFile(outFile, outBuffer);
Logger::Print("done.\n");
Logger::Print("Zone '%s' written with %d assets\n", outFile.data(), this->loadedAssets.size());
2016-07-11 11:14:58 -04:00
}
void ZoneBuilder::Zone::saveData()
2016-07-11 11:14:58 -04:00
{
// Add header
Game::ZoneHeader zoneHeader = { 0 };
zoneHeader.assetList.assetCount = this->loadedAssets.size();
2016-07-11 11:14:58 -04:00
Utils::Stream::ClearPointer(&zoneHeader.assetList.assets);
// Increment ScriptStrings count (for empty script string) if available
if (!this->scriptStrings.empty())
2016-07-11 11:14:58 -04:00
{
zoneHeader.assetList.stringList.count = this->scriptStrings.size() + 1;
2016-07-11 11:14:58 -04:00
Utils::Stream::ClearPointer(&zoneHeader.assetList.stringList.strings);
}
// Write header
this->buffer.save(&zoneHeader, sizeof(Game::ZoneHeader));
this->buffer.pushBlock(Game::XFILE_BLOCK_VIRTUAL); // Push main stream onto the stream stack
2016-07-11 11:14:58 -04:00
// Write ScriptStrings, if available
if (!this->scriptStrings.empty())
2016-07-11 11:14:58 -04:00
{
this->buffer.saveNull(4); // Empty script string?
// This actually represents a NULL string, but as scriptString.
// So scriptString loading for NULL scriptStrings from fastfile results in a NULL scriptString.
// That's the reason why the count is incremented by 1, if scriptStrings are available.
2016-07-11 11:14:58 -04:00
// Write ScriptString pointer table
for (size_t i = 0; i < this->scriptStrings.size(); ++i)
2016-07-11 11:14:58 -04:00
{
this->buffer.saveMax(4);
2016-07-11 11:14:58 -04:00
}
this->buffer.align(Utils::Stream::ALIGN_4);
2016-07-11 11:14:58 -04:00
// Write ScriptStrings
for (auto ScriptString : this->scriptStrings)
2016-07-11 11:14:58 -04:00
{
this->buffer.saveString(ScriptString.data());
2016-07-11 11:14:58 -04:00
}
}
// Align buffer (4 bytes) to get correct offsets for pointers
this->buffer.align(Utils::Stream::ALIGN_4);
this->indexStart = this->buffer.getBlockSize(Game::XFILE_BLOCK_VIRTUAL); // Mark AssetTable offset
2016-07-11 11:14:58 -04:00
// AssetTable
for (auto asset : this->loadedAssets)
2016-07-11 11:14:58 -04:00
{
Game::XAsset entry = { asset.type, 0 };
Utils::Stream::ClearPointer(&entry.header.data);
this->buffer.save(&entry);
2016-07-11 11:14:58 -04:00
}
// Assets
for (auto asset : this->loadedAssets)
2016-07-11 11:14:58 -04:00
{
this->buffer.pushBlock(Game::XFILE_BLOCK_TEMP);
this->buffer.align(Utils::Stream::ALIGN_4);
2016-07-11 11:14:58 -04:00
#ifdef DEBUG
Components::Logger::Print("Saving (%s): %s\n", Game::DB_GetXAssetTypeName(asset.type), Game::DB_GetXAssetName(&asset));
#endif
this->store(asset.header);
2016-07-11 11:14:58 -04:00
AssetHandler::ZoneSave(asset, this);
this->buffer.popBlock();
2016-07-11 11:14:58 -04:00
}
// Adapt header
this->buffer.enterCriticalSection();
Game::XFile* header = reinterpret_cast<Game::XFile*>(this->buffer.data());
header->size = this->buffer.length() - sizeof(Game::XFile); // Write correct data size
header->externalSize = this->externalSize; // This actually stores how much external data has to be loaded. It's used to calculate the loadscreen progress
2016-07-11 11:14:58 -04:00
// Write stream sizes
for (int i = 0; i < Game::MAX_XFILE_COUNT; ++i)
{
header->blockSize[i] = this->buffer.getBlockSize(static_cast<Game::XFILE_BLOCK_TYPES>(i));
2016-07-11 11:14:58 -04:00
}
this->buffer.leaveCriticalSection();
this->buffer.popBlock();
2016-07-11 11:14:58 -04:00
}
// Add branding asset
void ZoneBuilder::Zone::addBranding()
2016-07-11 11:14:58 -04:00
{
char* data = "FastFile built using IW4x ZoneTool!";
this->branding = { this->zoneName.data(), (int)strlen(data), 0, data };
2016-07-11 11:14:58 -04:00
if (this->findAsset(Game::XAssetType::ASSET_TYPE_RAWFILE, this->branding.name) != -1)
2016-07-11 11:14:58 -04:00
{
Logger::Error("Unable to add branding. Asset '%s' already exists!", this->branding.name);
2016-07-11 11:14:58 -04:00
}
Game::XAssetHeader header = { &this->branding };
2016-07-11 11:14:58 -04:00
Game::XAsset brandingAsset = { Game::XAssetType::ASSET_TYPE_RAWFILE, header };
this->loadedAssets.push_back(brandingAsset);
2016-07-11 11:14:58 -04:00
}
// Check if the given pointer has already been mapped
bool ZoneBuilder::Zone::hasPointer(const void* pointer)
2016-07-11 11:14:58 -04:00
{
return (this->pointerMap.find(pointer) != this->pointerMap.end());
2016-07-11 11:14:58 -04:00
}
// Get stored offset for given file pointer
uint32_t ZoneBuilder::Zone::safeGetPointer(const void* pointer)
2016-07-11 11:14:58 -04:00
{
if (this->hasPointer(pointer))
2016-07-11 11:14:58 -04:00
{
return this->pointerMap[pointer];
2016-07-11 11:14:58 -04:00
}
return NULL;
}
void ZoneBuilder::Zone::storePointer(const void* pointer)
2016-07-11 11:14:58 -04:00
{
this->pointerMap[pointer] = this->buffer.getPackedOffset();
2016-07-11 11:14:58 -04:00
}
int ZoneBuilder::Zone::addScriptString(std::string str)
2016-07-11 11:14:58 -04:00
{
return this->addScriptString(Game::SL_GetString(str.data(), 0));
2016-07-11 11:14:58 -04:00
}
// Mark a scriptString for writing and map it.
int ZoneBuilder::Zone::addScriptString(unsigned short gameIndex)
2016-07-11 11:14:58 -04:00
{
// Handle NULL scriptStrings
// Might optimize that later
if (!gameIndex)
{
if (this->scriptStrings.empty())
2016-07-11 11:14:58 -04:00
{
this->scriptStrings.push_back("");
2016-07-11 11:14:58 -04:00
}
return 0;
}
std::string str = Game::SL_ConvertToString(gameIndex);
int prev = this->findScriptString(str);
2016-07-11 11:14:58 -04:00
if (prev > 0)
{
this->scriptStringMap[gameIndex] = prev;
2016-07-11 11:14:58 -04:00
return prev;
}
this->scriptStrings.push_back(str);
this->scriptStringMap[gameIndex] = this->scriptStrings.size();
return this->scriptStrings.size();
2016-07-11 11:14:58 -04:00
}
// Find a local scriptString
int ZoneBuilder::Zone::findScriptString(std::string str)
2016-07-11 11:14:58 -04:00
{
for (unsigned int i = 0; i < this->scriptStrings.size(); ++i)
2016-07-11 11:14:58 -04:00
{
if (this->scriptStrings[i] == str)
2016-07-11 11:14:58 -04:00
{
return (i + 1);
}
}
return -1;
}
// Remap a scriptString to it's corresponding value in the local scriptString table.
void ZoneBuilder::Zone::mapScriptString(unsigned short* gameIndex)
2016-07-11 11:14:58 -04:00
{
*gameIndex = 0xFFFF & this->scriptStringMap[*gameIndex];
2016-07-11 11:14:58 -04:00
}
// Store a new name for a given asset
void ZoneBuilder::Zone::renameAsset(Game::XAssetType type, std::string asset, std::string newName)
2016-07-11 11:14:58 -04:00
{
2016-10-26 15:50:57 -04:00
if (type < Game::XAssetType::ASSET_TYPE_COUNT && type >= 0)
2016-07-11 11:14:58 -04:00
{
this->renameMap[type][asset] = newName;
2016-07-11 11:14:58 -04:00
}
2016-10-26 15:50:57 -04:00
else
{
Logger::Error("Unable to rename '%s' to '%s' as the asset type is invalid!", asset.data(), newName.data());
}
2016-07-11 11:14:58 -04:00
}
// Return the new name for a given asset
std::string ZoneBuilder::Zone::getAssetName(Game::XAssetType type, std::string asset)
2016-07-11 11:14:58 -04:00
{
2016-10-26 15:50:57 -04:00
if (type < Game::XAssetType::ASSET_TYPE_COUNT && type >= 0)
2016-07-11 11:14:58 -04:00
{
if (this->renameMap[type].find(asset) != this->renameMap[type].end())
2016-07-11 11:14:58 -04:00
{
return this->renameMap[type][asset];
2016-07-11 11:14:58 -04:00
}
}
2016-10-26 15:50:57 -04:00
else
{
Logger::Error("Unable to get name for '%s' as the asset type is invalid!", asset.data());
}
2016-07-11 11:14:58 -04:00
return asset;
}
void ZoneBuilder::Zone::store(Game::XAssetHeader header)
2016-07-11 11:14:58 -04:00
{
if (!this->hasPointer(header.data)) // We should never have to restore a pointer, so this expression should always resolve into false
2016-07-11 11:14:58 -04:00
{
this->storePointer(header.data);
2016-07-11 11:14:58 -04:00
}
}
void ZoneBuilder::Zone::incrementExternalSize(unsigned int size)
{
this->externalSize += size;
}
2016-07-11 11:14:58 -04:00
bool ZoneBuilder::IsEnabled()
{
return (Flags::HasFlag("zonebuilder") && !Dedicated::IsEnabled());
2016-07-11 11:14:58 -04:00
}
void ZoneBuilder::BeginAssetTrace(std::string zone)
{
ZoneBuilder::TraceZone = zone;
}
std::vector<std::pair<Game::XAssetType, std::string>> ZoneBuilder::EndAssetTrace()
{
ZoneBuilder::TraceZone.clear();
std::vector<std::pair<Game::XAssetType, std::string>> AssetTrace;
Utils::Merge(&AssetTrace, ZoneBuilder::TraceAssets);
ZoneBuilder::TraceAssets.clear();
return AssetTrace;
}
ZoneBuilder::ZoneBuilder()
{
AssertSize(Game::XFileHeader, 21);
AssertSize(Game::XFile, 40);
2016-07-11 11:14:58 -04:00
static_assert(Game::MAX_XFILE_COUNT == 8, "XFile block enum is invalid!");
ZoneBuilder::EndAssetTrace();
if (ZoneBuilder::IsEnabled())
{
// Prevent loading textures (preserves loaddef)
Utils::Hook::Set<BYTE>(0x51F4E0, 0xC3);
//r_loadForrenderer = 0
Utils::Hook::Set<BYTE>(0x519DDF, 0);
//r_delayloadimage retn
Utils::Hook::Set<BYTE>(0x51F450, 0xC3);
// r_registerDvars hack
Utils::Hook::Set<BYTE>(0x51B1CD, 0xC3);
// Prevent destroying textures
Utils::Hook::Set<BYTE>(0x51F03D, 0xEB);
// Don't create default assets
Utils::Hook::Set<BYTE>(0x407BAA, 0xEB);
// Don't load sounds
Utils::Hook::Set<BYTE>(0x334D41, 0xC3);
2016-07-11 11:14:58 -04:00
// Don't display errors when assets are missing (we might manually build those)
Utils::Hook::Nop(0x5BB3F2, 5);
Utils::Hook::Nop(0x5BB422, 5);
Utils::Hook::Nop(0x5BB43A, 5);
2016-10-21 16:50:17 -04:00
2016-07-11 11:14:58 -04:00
// Increase asset pools
Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_MAP_ENTS, 10);
2016-10-21 16:50:17 -04:00
Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_XMODELSURFS, 8192);
Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_IMAGE, 14336);
2016-10-31 08:15:46 -04:00
Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_TECHSET, 1536);
2016-07-11 11:14:58 -04:00
// hunk size (was 300 MiB)
Utils::Hook::Set<DWORD>(0x64A029, 0x38400000); // 900 MiB
Utils::Hook::Set<DWORD>(0x64A057, 0x38400000);
2016-08-17 20:18:45 -04:00
AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader /*asset*/, std::string name, bool* /*restrict*/)
2016-07-11 11:14:58 -04:00
{
if (!ZoneBuilder::TraceZone.empty() && ZoneBuilder::TraceZone == FastFiles::Current())
{
ZoneBuilder::TraceAssets.push_back({ type, name });
}
});
Command::Add("verifyzone", [] (Command::Params params)
{
if (params.length() < 2) return;
2016-07-11 11:14:58 -04:00
2016-11-12 14:41:20 -05:00
std::string zone = params[1];
2016-07-11 11:14:58 -04:00
ZoneBuilder::BeginAssetTrace(zone);
Game::XZoneInfo info;
info.name = zone.data();
2016-10-26 13:15:18 -04:00
info.allocFlags = 0x20;
2016-07-11 11:14:58 -04:00
info.freeFlags = 0;
Logger::Print("Loading zone '%s'...\n", zone.data());
Game::DB_LoadXAssets(&info, 1, true);
AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_RAWFILE, zone.data()); // Lock until zone is loaded
auto assets = ZoneBuilder::EndAssetTrace();
Logger::Print("Unloading zone '%s'...\n", zone.data());
2016-10-26 13:15:18 -04:00
info.freeFlags = 0x20;
2016-07-11 11:14:58 -04:00
info.allocFlags = 0;
info.name = nullptr;
Game::DB_LoadXAssets(&info, 1, true);
AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_RAWFILE, "default"); // Lock until zone is unloaded
Logger::Print("Zone '%s' loaded with %d assets:\n", zone.data(), assets.size());
int count = 0;
for (auto i = assets.begin(); i != assets.end(); ++i, ++count)
{
Logger::Print(" %d: %s: %s\n", count, Game::DB_GetXAssetTypeName(i->first), i->second.data());
}
Logger::Print("\n");
});
Command::Add("buildzone", [] (Command::Params params)
{
if (params.length() < 2) return;
2016-07-11 11:14:58 -04:00
std::string zoneName = params[1];
Logger::Print("Building zone '%s'...\n", zoneName.data());
Zone(zoneName).build();
2016-07-11 11:14:58 -04:00
});
2016-11-13 14:53:44 -05:00
Command::Add("buildall", [] (Command::Params)
{
auto zoneSources = FileSystem::GetSysFileList(Dvar::Var("fs_basepath").get<std::string>() + "\\zone_source", "csv", false);
2016-11-13 14:53:44 -05:00
for (auto source : zoneSources)
{
if (Utils::String::EndsWith(source, ".csv"))
{
source = source.substr(0, source.find(".csv"));
}
Command::Execute(fmt::sprintf("buildzone %s", source.data()), true);
}
});
2016-07-11 11:14:58 -04:00
Command::Add("listassets", [] (Command::Params params)
{
if (params.length() < 2) return;
2016-07-11 11:14:58 -04:00
Game::XAssetType type = Game::DB_GetXAssetNameType(params[1]);
if (type != Game::XAssetType::ASSET_TYPE_INVALID)
{
Game::DB_EnumXAssets(type, [] (Game::XAssetHeader header, void* data)
{
Game::XAsset asset = { *reinterpret_cast<Game::XAssetType*>(data), header };
Logger::Print("%s\n", Game::DB_GetXAssetName(&asset));
}, &type, false);
}
});
}
}
}