Skip to content

Commit

Permalink
AssetBundleFile: Support alignment flag 0x200
Browse files Browse the repository at this point in the history
  • Loading branch information
SeriousCache committed Mar 15, 2023
1 parent 3b5ed80 commit 58c1c57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions AssetsTools/AssetBundleFileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,7 @@ ASSETSTOOLS_API bool AssetBundleFile::Unpack(IAssetsReader *pReader, IAssetsWrit
bundleHeader6.compressedSize = bundleHeader6.decompressedSize;
curUpFilePos = 0;
bundleHeader6.flags &= ~(0x3F);
bundleHeader6.flags &= ~(0x200); //No additional 16 byte data alignment.

if (bundleHeader6.flags & 0x100) //originally was UnityWeb
strcpy(bundleHeader6.signature, "UnityWeb");
Expand Down Expand Up @@ -2346,9 +2347,10 @@ ASSETSTOOLS_API bool AssetBundleFile::Write(IAssetsReader *pReader,
std::vector<AssetBundleBlockInfo06> blocks;
QWORD curFilePos = 0;
AssetBundleHeader06 header = this->bundleHeader6;
if (header.flags & 0x100)
strcpy(header.signature, "UnityWeb");
if ((header.flags & 0x100) && header.fileVersion == 6)
strcpy(header.signature, "UnityWeb"); //Is this accurate for all versions?
header.flags &= ~0x3F; //No directory/block list compression.
header.flags &= ~0x200; //No alignment of first block.
header.flags |= 0x40; //Has directory info.
header.Write(pWriter, curFilePos);
//Create dummy block info (we don't have exact sizes but have to assume that <= or > 4 GiB can be differentiated).
Expand Down
18 changes: 12 additions & 6 deletions AssetsTools/AssetBundleFileFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,29 @@ struct AssetBundleHeader06
return ret;
}
}
inline uint32_t GetFileDataOffset()
inline QWORD GetFileDataOffset()
{
uint32_t ret = 0;
QWORD ret = 0;
if (!strcmp(this->signature, "UnityArchive"))
return this->compressedSize;
else if (!strcmp(this->signature, "UnityFS") || !strcmp(this->signature, "UnityWeb"))
if (!strcmp(this->signature, "UnityFS") || !strcmp(this->signature, "UnityWeb"))
{
ret = (uint32_t)strlen(minPlayerVersion) + (uint32_t)strlen(fileEngineVersion) + 0x1A;
ret = (QWORD)strlen(minPlayerVersion) + (QWORD)strlen(fileEngineVersion) + 0x1A;
if (this->flags & 0x100)
ret += 0x0A;
else
ret += (uint32_t)strlen(signature) + 1;
ret += (QWORD)strlen(signature) + 1;
if (this->fileVersion >= 7)
ret = (ret + 15) & ~15; //16 byte alignment
{
ret = (ret + 15) & ~15; //16 byte alignment of list
}
}
if (!(this->flags & 0x80))
{
ret += this->compressedSize;
if (this->flags & 0x200)
ret = (ret + 15) & ~15; //16 byte alignment of first block
}
return ret;
}
};
Expand Down

0 comments on commit 58c1c57

Please sign in to comment.