2016-07-11 11:37:36 -04:00
|
|
|
#include <STDInclude.hpp>
|
|
|
|
|
|
|
|
namespace Assets
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
void IMapEnts::load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
|
2016-07-11 11:37:36 -04:00
|
|
|
{
|
2016-12-29 14:14:55 -05:00
|
|
|
Utils::String::Replace(name, "maps/", "");
|
|
|
|
Utils::String::Replace(name, "mp/", "");
|
|
|
|
Utils::String::Replace(name, ".d3dbsp", "");
|
2016-12-28 21:30:34 -05:00
|
|
|
|
2016-12-29 14:14:55 -05:00
|
|
|
Components::FileSystem::File ents(Utils::String::VA("mapents/%s.ents", name.c_str()));
|
2016-11-20 08:09:07 -05:00
|
|
|
if (ents.exists())
|
2016-07-11 11:37:36 -04:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
Game::MapEnts* entites = builder->getAllocator()->allocate<Game::MapEnts>();
|
|
|
|
Game::MapEnts* orgEnts = Components::AssetHandler::FindOriginalAsset(this->getType(), name.data()).mapEnts;
|
2016-07-11 11:37:36 -04:00
|
|
|
|
2016-12-29 17:52:23 -05:00
|
|
|
// TODO: Get rid of that
|
|
|
|
if (!orgEnts)
|
|
|
|
{
|
2016-12-31 09:53:48 -05:00
|
|
|
orgEnts = Components::AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_MAP_ENTS, "maps/iw4_credits.d3dbsp").mapEnts;
|
|
|
|
|
|
|
|
if (!orgEnts)
|
2016-12-29 17:52:23 -05:00
|
|
|
{
|
2016-12-31 09:53:48 -05:00
|
|
|
Game::DB_EnumXAssets(Game::XAssetType::ASSET_TYPE_MAP_ENTS, [](Game::XAssetHeader header, void* mapEnts)
|
2016-12-29 17:52:23 -05:00
|
|
|
{
|
2016-12-31 09:53:48 -05:00
|
|
|
if (!*reinterpret_cast<void**>(mapEnts))
|
|
|
|
{
|
|
|
|
*reinterpret_cast<Game::MapEnts**>(mapEnts) = header.mapEnts;
|
|
|
|
}
|
|
|
|
}, &orgEnts, false);
|
|
|
|
}
|
2016-12-29 17:52:23 -05:00
|
|
|
}
|
|
|
|
|
2016-07-11 11:37:36 -04:00
|
|
|
if (orgEnts)
|
|
|
|
{
|
|
|
|
std::memcpy(entites, orgEnts, sizeof Game::MapEnts);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-29 14:51:42 -05:00
|
|
|
entites->name = builder->getAllocator()->duplicateString(Utils::String::VA("maps/mp/%s.d3dbsp", name));
|
2016-12-29 19:29:35 -05:00
|
|
|
entites->stageCount = 1;
|
|
|
|
entites->stages = builder->getAllocator()->allocate<Game::Stage>();
|
|
|
|
entites->stages[0].stageName = "stage 0";
|
|
|
|
entites->stages[0].flags = 0x10400;
|
2016-07-11 11:37:36 -04:00
|
|
|
}
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
entites->entityString = builder->getAllocator()->duplicateString(ents.getBuffer());
|
|
|
|
entites->numEntityChars = ents.getBuffer().size() + 1;
|
2016-07-11 11:37:36 -04:00
|
|
|
|
|
|
|
header->mapEnts = entites;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
void IMapEnts::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
2016-07-11 11:37:36 -04:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::MapEnts, 44);
|
2016-07-11 11:37:36 -04:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
Utils::Stream* buffer = builder->getBuffer();
|
2016-07-11 11:37:36 -04:00
|
|
|
Game::MapEnts* asset = header.mapEnts;
|
2016-11-20 08:09:07 -05:00
|
|
|
Game::MapEnts* dest = buffer->dest<Game::MapEnts>();
|
|
|
|
buffer->save(asset);
|
2016-07-11 11:37:36 -04:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
|
2016-07-11 11:37:36 -04:00
|
|
|
|
|
|
|
if (asset->name)
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
|
2016-07-11 11:37:36 -04:00
|
|
|
Utils::Stream::ClearPointer(&dest->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->entityString)
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->save(asset->entityString, asset->numEntityChars);
|
2016-07-11 11:37:36 -04:00
|
|
|
Utils::Stream::ClearPointer(&dest->entityString);
|
|
|
|
}
|
|
|
|
|
2016-12-22 17:21:20 -05:00
|
|
|
AssertSize(Game::MapTriggers, 24);
|
|
|
|
|
2016-07-11 11:37:36 -04:00
|
|
|
if (asset->trigger.models)
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::TriggerModel, 8);
|
2016-07-11 11:37:36 -04:00
|
|
|
|
2016-12-22 17:21:20 -05:00
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->saveArray(asset->trigger.models, asset->trigger.modelCount);
|
2016-07-11 11:37:36 -04:00
|
|
|
Utils::Stream::ClearPointer(&dest->trigger.models);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->trigger.hulls)
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::TriggerHull, 32);
|
2016-07-11 11:37:36 -04:00
|
|
|
|
2016-12-22 17:21:20 -05:00
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->saveArray(asset->trigger.hulls, asset->trigger.hullCount);
|
2016-07-11 11:37:36 -04:00
|
|
|
Utils::Stream::ClearPointer(&dest->trigger.hulls);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->trigger.slabs)
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::TriggerSlab, 20);
|
2016-07-11 11:37:36 -04:00
|
|
|
|
2016-12-22 17:21:20 -05:00
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->saveArray(asset->trigger.slabs, asset->trigger.slabCount);
|
2016-07-11 11:37:36 -04:00
|
|
|
Utils::Stream::ClearPointer(&dest->trigger.slabs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->stages)
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::Stage, 20);
|
2016-07-11 11:37:36 -04:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
2016-07-11 11:37:36 -04:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
Game::Stage* destStages = buffer->dest<Game::Stage>();
|
|
|
|
buffer->saveArray(asset->stages, asset->stageCount);
|
2016-07-11 11:37:36 -04:00
|
|
|
|
2016-12-22 17:21:20 -05:00
|
|
|
for (char i = 0; i < asset->stageCount; ++i)
|
2016-07-11 11:37:36 -04:00
|
|
|
{
|
|
|
|
Game::Stage* destStage = &destStages[i];
|
|
|
|
Game::Stage* stage = &asset->stages[i];
|
|
|
|
|
2016-12-22 17:21:20 -05:00
|
|
|
if (stage->stageName)
|
|
|
|
{
|
|
|
|
buffer->saveString(stage->stageName);
|
|
|
|
Utils::Stream::ClearPointer(&destStage->stageName);
|
|
|
|
}
|
2016-07-11 11:37:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Utils::Stream::ClearPointer(&dest->stages);
|
|
|
|
}
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->popBlock();
|
2016-07-11 11:37:36 -04:00
|
|
|
}
|
|
|
|
}
|