From 8b62bc0bc0fe0b72bbbe1f6d3dfcfccff5fdda17 Mon Sep 17 00:00:00 2001 From: JezuzLizard Date: Thu, 14 Dec 2023 13:48:44 -0800 Subject: [PATCH] Address review comments. --- .../T6/AssetLoaders/AssetLoaderRawFile.cpp | 11 +++++------ .../T6/AssetDumpers/AssetDumperRawFile.cpp | 18 ++++-------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderRawFile.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderRawFile.cpp index a4e97edd..0257177f 100644 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderRawFile.cpp +++ b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderRawFile.cpp @@ -29,13 +29,12 @@ bool AssetLoaderRawFile::CanLoadFromRaw() const bool AssetLoaderRawFile::LoadAnimtree( const SearchPathOpenFile& file, const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager) { - const auto uncompressedBuffer = std::make_unique(static_cast(file.m_length + 1)); + const auto uncompressedBuffer = std::make_unique(static_cast(file.m_length)); file.m_stream->read(uncompressedBuffer.get(), file.m_length); if (file.m_stream->gcount() != file.m_length) return false; - uncompressedBuffer[static_cast(file.m_length)] = '\0'; - const auto compressionBufferSize = static_cast(file.m_length + 1 + sizeof(uint32_t) + COMPRESSED_BUFFER_SIZE_PADDING); + const auto compressionBufferSize = static_cast(file.m_length + sizeof(uint32_t) + COMPRESSED_BUFFER_SIZE_PADDING); auto* compressedBuffer = static_cast(memory->Alloc(compressionBufferSize)); z_stream_s zs{}; @@ -43,7 +42,7 @@ bool AssetLoaderRawFile::LoadAnimtree( zs.zalloc = Z_NULL; zs.zfree = Z_NULL; zs.opaque = Z_NULL; - zs.avail_in = static_cast(file.m_length + 1); + zs.avail_in = static_cast(file.m_length); zs.avail_out = compressionBufferSize; zs.next_in = reinterpret_cast(uncompressedBuffer.get()); zs.next_out = reinterpret_cast(&compressedBuffer[sizeof(uint32_t)]); @@ -59,14 +58,14 @@ bool AssetLoaderRawFile::LoadAnimtree( if (ret != Z_STREAM_END) { - std::cout << "Deflate failed for loading animtree file \"" << assetName << "\"" << std::endl; + std::cerr << "Deflate failed for loading animtree file \"" << assetName << "\"" << std::endl; deflateEnd(&zs); return false; } const auto compressedSize = compressionBufferSize + sizeof(uint32_t) - zs.avail_out; - reinterpret_cast(compressedBuffer)[0] = static_cast(file.m_length + 1); // outLen + reinterpret_cast(compressedBuffer)[0] = static_cast(file.m_length); // outLen auto* rawFile = memory->Create(); rawFile->name = memory->Dup(assetName.c_str()); diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperRawFile.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperRawFile.cpp index 5440c69f..6a9ebd3c 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperRawFile.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperRawFile.cpp @@ -19,7 +19,7 @@ void AssetDumperRawFile::DumpAnimtree(AssetDumpingContext& context, XAssetInfolen <= 4) { - std::cout << "Invalid len of animtree file \"" << rawFile->name << "\"" << std::endl; + std::cerr << "Invalid len of animtree file \"" << rawFile->name << "\"" << std::endl; return; } @@ -28,7 +28,7 @@ void AssetDumperRawFile::DumpAnimtree(AssetDumpingContext& context, XAssetInfo ANIMTREE_MAX_SIZE) { - std::cout << "Invalid size of animtree file \"" << rawFile->name << "\": " << outLen << std::endl; + std::cerr << "Invalid size of animtree file \"" << rawFile->name << "\": " << outLen << std::endl; return; } @@ -52,7 +52,6 @@ void AssetDumperRawFile::DumpAnimtree(AssetDumpingContext& context, XAssetInfo 0) { zs.next_out = buffer; @@ -61,23 +60,14 @@ void AssetDumperRawFile::DumpAnimtree(AssetDumpingContext& context, XAssetInfoname << "\"" << std::endl; + std::cerr << "Inflate failed for dumping animtree file \"" << rawFile->name << "\"" << std::endl; inflateEnd(&zs); return; } const auto inflateOutSize = sizeof buffer - zs.avail_out; - if (writtenSize + inflateOutSize >= outLen) - { - // Last byte is a \0 byte. Skip it. - stream.write(reinterpret_cast(buffer), inflateOutSize - 1); - } - else - { - stream.write(reinterpret_cast(buffer), inflateOutSize); - } - writtenSize += inflateOutSize; + stream.write(reinterpret_cast(buffer), inflateOutSize); } inflateEnd(&zs);