#include #include "IRawFile.hpp" namespace Assets { void IRawFile::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) { Components::FileSystem::File rawFile(name); if (!rawFile.exists()) { return; } auto* asset = builder->getAllocator()->allocate(); if (!asset) { return; } asset->name = builder->getAllocator()->duplicateString(name); asset->len = static_cast(rawFile.getBuffer().size()); const auto compressedData = Utils::Compression::ZLib::Compress(rawFile.getBuffer()); // Only save the compressed buffer if we gained space if (compressedData.size() < rawFile.getBuffer().size()) { asset->buffer = builder->getAllocator()->allocateArray(compressedData.size()); std::memcpy(const_cast(asset->buffer), compressedData.data(), compressedData.size()); asset->compressedLen = static_cast(compressedData.size()); } else { asset->buffer = builder->getAllocator()->allocateArray(rawFile.getBuffer().size() + 1); std::memcpy(const_cast(asset->buffer), rawFile.getBuffer().data(), rawFile.getBuffer().size()); asset->compressedLen = 0; } header->rawfile = asset; } void IRawFile::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) { AssertSize(Game::RawFile, 16); auto* buffer = builder->getBuffer(); auto* asset = header.rawfile; auto* dest = buffer->dest(); buffer->save(asset); buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL); if (asset->name) { buffer->saveString(builder->getAssetName(this->getType(), asset->name)); Utils::Stream::ClearPointer(&dest->name); } if (asset->buffer) { if (asset->compressedLen) { buffer->save(asset->buffer, asset->compressedLen); } else { buffer->save(asset->buffer, asset->len + 1); } Utils::Stream::ClearPointer(&dest->buffer); } buffer->popBlock(); } }