[Zone🅱️uilder]: Fix rawfiles (#614)

This commit is contained in:
Edo 2022-12-01 14:04:30 +00:00 committed by GitHub
parent 874a8027af
commit 7778798f17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 649 additions and 644 deletions

View File

@ -18,18 +18,21 @@ namespace Assets
return; return;
} }
const auto data = Utils::Compression::ZLib::Compress(rawFile.getBuffer()); auto compressed_size = compressBound(rawFile.getBuffer().size());
asset->name = builder->getAllocator()->duplicateString(name); asset->name = builder->getAllocator()->duplicateString(name);
asset->len = static_cast<int>(rawFile.getBuffer().size());
if (data.size() < rawFile.getBuffer().size()) if (asset->len < static_cast<int>(compressed_size))
{ {
asset->buffer = builder->getAllocator()->duplicateString(data); asset->buffer = builder->getAllocator()->allocateArray<char>(compressed_size);
asset->compressedLen = static_cast<int>(data.size()); compress2((Bytef*)(asset->buffer), &compressed_size, (const Bytef*)(rawFile.getBuffer().data()), rawFile.getBuffer().size(), Z_BEST_COMPRESSION);
asset->compressedLen = static_cast<int>(compressed_size);
} }
else else
{ {
asset->buffer = builder->getAllocator()->duplicateString(rawFile.getBuffer()); asset->buffer = builder->getAllocator()->allocateArray<char>(rawFile.getBuffer().size() + 1);
std::memcpy(const_cast<char*>(asset->buffer), rawFile.getBuffer().data(), rawFile.getBuffer().size());
asset->compressedLen = 0; asset->compressedLen = 0;
} }

View File

@ -518,8 +518,10 @@ namespace Components
// Add branding asset // Add branding asset
void ZoneBuilder::Zone::addBranding() void ZoneBuilder::Zone::addBranding()
{ {
const char* data = "FastFile built using the IW4x ZoneBuilder!"; constexpr auto* data = "Built using the IW4x Zone:B:uilder Version 4";
this->branding = { this->zoneName.data(), static_cast<int>(strlen(data)), 0, data }; auto dataLen = std::strlen(data) + 1;
this->branding = { this->zoneName.data(), 0, static_cast<int>(dataLen), data };
if (this->findAsset(Game::XAssetType::ASSET_TYPE_RAWFILE, this->branding.name) != -1) if (this->findAsset(Game::XAssetType::ASSET_TYPE_RAWFILE, this->branding.name) != -1)
{ {

File diff suppressed because it is too large Load Diff