From 1a7b2cd611cab1fb3e83bfa80ebbd04164fde0a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Mocquillon?= Date: Mon, 6 Mar 2023 15:50:45 +0100 Subject: [PATCH] Fix remaining bugs --- components/bsa/ba2dx10file.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/components/bsa/ba2dx10file.cpp b/components/bsa/ba2dx10file.cpp index 6557670bee..4ec8359b85 100644 --- a/components/bsa/ba2dx10file.cpp +++ b/components/bsa/ba2dx10file.cpp @@ -45,7 +45,7 @@ namespace Bsa in.read(reinterpret_cast(&dirHash), sizeof(uint32_t)); FileRecord file; - uint32_t unknown; + uint8_t unknown; in.read(reinterpret_cast(&unknown), sizeof(uint8_t)); uint8_t nbChunks; @@ -400,7 +400,7 @@ namespace Bsa header.mipMapCount = fileRecord.numMips; if (header.mipMapCount > 1) header.caps = header.caps | DDSCAPS_MIPMAP | DDSCAPS_COMPLEX; - header.depth = 1; + header.depth = 0; header.resourceDimension = DDS_DIMENSION_TEXTURE2D; header.arraySize = 1; @@ -631,15 +631,15 @@ namespace Bsa buff = (char*)std::memcpy(buff, &dds, sizeof(uint32_t)) + sizeof(uint32_t); std::memcpy(buff, &header, headerSize); - size_t offset = headerSize; + size_t offset = sizeof(uint32_t) + headerSize; // append chunks for (const auto& c : fileRecord.texturesChunks) { - Files::IStreamPtr streamPtr = Files::openConstrainedFileStream(mFilepath, c.offset, c.packedSize); - std::istream* fileStream = streamPtr.get(); - if (c.packedSize != 0) { + Files::IStreamPtr streamPtr = Files::openConstrainedFileStream(mFilepath, c.offset, c.packedSize); + std::istream* fileStream = streamPtr.get(); + boost::iostreams::filtering_streambuf inputStreamBuf; inputStreamBuf.push(boost::iostreams::zlib_decompressor()); inputStreamBuf.push(*fileStream); @@ -650,6 +650,9 @@ namespace Bsa // uncompressed chunk else { + Files::IStreamPtr streamPtr = Files::openConstrainedFileStream(mFilepath, c.offset, c.size); + std::istream* fileStream = streamPtr.get(); + fileStream->read(memoryStreamPtr->getRawData() + offset, c.size); } offset += c.size;