Compatibility/memory fixes for BA2 parsing

This commit is contained in:
Silarn
2018-04-17 16:26:02 -05:00
parent a63633e249
commit 1873797497
2 changed files with 31 additions and 14 deletions
+19 -2
View File
@@ -178,10 +178,27 @@ EErrorCode Archive::read(const char* fileName, bool testHashes)
} else if (strcmp(header.archType, "DX10") == 0) {
m_File.seekg(24, std::ios::beg);
for (unsigned int i = 0; i < header.fileCount; ++i) {
FO4TextureHeader texHeader = readType<FO4TextureHeader>(m_File);
FO4TextureHeader texHeader;
texHeader.nameHash = readType<BSAUInt>(m_File);
m_File.read(texHeader.extension, 4);
texHeader.dirHash = readType<BSAUInt>(m_File);
texHeader.unknown1 = readType<BSAUChar>(m_File);
texHeader.chunkNumber = readType<BSAUChar>(m_File);
texHeader.chunkHeaderSize = readType<BSAUShort>(m_File);
texHeader.height = readType<BSAUShort>(m_File);
texHeader.width = readType<BSAUShort>(m_File);
texHeader.mipCount = readType<BSAUChar>(m_File);
texHeader.format = static_cast<DXGI_FORMAT>(readType<BSAUShort>(m_File));
texHeader.unknown2 = readType<BSAUChar>(m_File);
std::vector<FO4TextureChunk> chunks;
for (unsigned int j = 0; j < texHeader.chunkNumber; ++j) {
FO4TextureChunk chunk = readType<FO4TextureChunk>(m_File);
FO4TextureChunk chunk;
chunk.offset = readType<BSAHash>(m_File);
chunk.packedSize = readType<BSAUInt>(m_File);
chunk.unpackedSize = readType<BSAUInt>(m_File);
chunk.startMip = readType<BSAUShort>(m_File);
chunk.endMip = readType<BSAUShort>(m_File);
chunk.unknown = readType<BSAUInt>(m_File);
chunks.push_back(chunk);
}
Folder::Ptr newDir = m_RootFolder->addFolderFromFile(fileNames[i], chunks[0].packedSize, chunks[0].offset, chunks[0].unpackedSize, texHeader, chunks);
+12 -12
View File
@@ -37,6 +37,17 @@ typedef unsigned int BSAUInt;
typedef unsigned long BSAULong;
typedef unsigned long long BSAHash;
#else // WIN32
#include <stdint.h>
typedef unsigned char BSAUChar;
typedef unsigned short BSAUShort;
typedef unsigned int BSAUInt;
typedef unsigned long BSAULong;
typedef unsigned long long BSAHash;
#endif // WIN32
enum ArchiveType {
TYPE_MORROWIND,
TYPE_OBLIVION,
@@ -65,7 +76,7 @@ struct FO4TextureHeader
BSAUShort width;
BSAUChar mipCount;
DXGI_FORMAT format;
BSAUShort unknown2;
BSAUChar unknown2;
};
struct FO4TextureChunk
@@ -78,17 +89,6 @@ struct FO4TextureChunk
BSAUInt unknown;
};
#else // WIN32
#include <stdint.h>
typedef uint32_t BSAULong;
typedef uint64_t BSAHash;
#endif // WIN32
template <typename T> static T readType(std::fstream &file)
{
union {