Skip to content

Commit

Permalink
Merge branch 'ba2' into 'master'
Browse files Browse the repository at this point in the history
BA2 support fixes

See merge request OpenMW/openmw!4055
  • Loading branch information
psi29a committed Apr 28, 2024
2 parents 1eb6b32 + a5d9369 commit e4fd852
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 27 deletions.
28 changes: 19 additions & 9 deletions components/bsa/ba2dx10file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,29 @@ namespace Bsa
input.read(reinterpret_cast<char*>(header), 16);
input.read(reinterpret_cast<char*>(&fileTableOffset), 8);

if (header[0] == 0x00415342) /*"BSA\x00"*/
fail("Unrecognized compressed BSA format");
if (header[0] != ESM::fourCC("BTDX"))
fail("Unrecognized BA2 signature");
mVersion = header[1];
if (mVersion != 0x01 /*FO4*/ && mVersion != 0x02 /*Starfield*/)
fail("Unrecognized compressed BSA version");
switch (static_cast<BA2Version>(mVersion))
{
case BA2Version::Fallout4:
case BA2Version::Fallout4NextGen_v7:
case BA2Version::Fallout4NextGen_v8:
break;
case BA2Version::StarfieldDDS:
uint64_t dummy;
input.read(reinterpret_cast<char*>(&dummy), 8);
uint32_t compressionMethod;
input.read(reinterpret_cast<char*>(&compressionMethod), 4);
if (compressionMethod == 3)
fail("Unsupported LZ4-compressed DDS BA2");
break;
default:
fail("Unrecognized DDS BA2 version");
}

type = header[2];
fileCount = header[3];
if (mVersion == 0x02)
{
uint64_t dummy;
input.read(reinterpret_cast<char*>(&dummy), 8);
}
}

if (type == ESM::fourCC("DX10"))
Expand Down
9 changes: 9 additions & 0 deletions components/bsa/ba2file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ namespace Bsa
{
uint32_t generateHash(const std::string& name);
uint32_t generateExtensionHash(std::string_view extension);

enum class BA2Version : std::uint32_t
{
Fallout4 = 1,
StarfieldGeneral = 2,
StarfieldDDS = 3,
Fallout4NextGen_v7 = 7,
Fallout4NextGen_v8 = 8,
};
}

#endif
24 changes: 15 additions & 9 deletions components/bsa/ba2gnrlfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,25 @@ namespace Bsa
input.read(reinterpret_cast<char*>(header), 16);
input.read(reinterpret_cast<char*>(&fileTableOffset), 8);

if (header[0] == 0x00415342) /*"BSA\x00"*/
fail("Unrecognized compressed BSA format");
if (header[0] != ESM::fourCC("BTDX"))
fail("Unrecognized BA2 signature");
mVersion = header[1];
if (mVersion != 0x01 /*FO4*/ && mVersion != 0x02 /*Starfield*/)
fail("Unrecognized compressed BSA version");
switch (static_cast<BA2Version>(mVersion))
{
case BA2Version::Fallout4:
case BA2Version::Fallout4NextGen_v7:
case BA2Version::Fallout4NextGen_v8:
break;
case BA2Version::StarfieldGeneral:
uint64_t dummy;
input.read(reinterpret_cast<char*>(&dummy), 8);
break;
default:
fail("Unrecognized general BA2 version");
}

type = header[2];
fileCount = header[3];
if (mVersion == 0x02)
{
uint64_t dummy;
input.read(reinterpret_cast<char*>(&dummy), 8);
}
}

if (type == ESM::fourCC("GNRL"))
Expand Down
18 changes: 9 additions & 9 deletions components/bsa/bsa_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,18 @@ BsaVersion Bsa::BSAFile::detectVersion(const std::filesystem::path& filePath)
return BsaVersion::Uncompressed;
}

if (head[0] == static_cast<uint32_t>(BsaVersion::Compressed) || head[0] == ESM::fourCC("BTDX"))
if (head[0] == static_cast<uint32_t>(BsaVersion::Compressed))
{
if (head[1] == static_cast<uint32_t>(0x01))
{
if (head[2] == ESM::fourCC("GNRL"))
return BsaVersion::BA2GNRL;
if (head[2] == ESM::fourCC("DX10"))
return BsaVersion::BA2DX10;
return BsaVersion::Unknown;
}
return BsaVersion::Compressed;
}

if (head[0] == ESM::fourCC("BTDX"))
{
if (head[2] == ESM::fourCC("GNRL"))
return BsaVersion::BA2GNRL;
if (head[2] == ESM::fourCC("DX10"))
return BsaVersion::BA2DX10;
}

return BsaVersion::Unknown;
}

0 comments on commit e4fd852

Please sign in to comment.