From 2cee1e45386acebc71d79f00eb57a475110e120b Mon Sep 17 00:00:00 2001 From: AXiX-official <2879710747@qq.com> Date: Mon, 20 May 2024 05:17:09 +0800 Subject: [PATCH] temp fix for 2019.4.x --- UnityAsset.NET/BundleFile/BundleFile.cs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/UnityAsset.NET/BundleFile/BundleFile.cs b/UnityAsset.NET/BundleFile/BundleFile.cs index c22c7d2..b413900 100644 --- a/UnityAsset.NET/BundleFile/BundleFile.cs +++ b/UnityAsset.NET/BundleFile/BundleFile.cs @@ -23,6 +23,8 @@ public sealed class BundleFile public bool BlocksInfoAtTheEnd = false; public bool HasBlockInfoNeedPaddingAtStart; + + private bool HeaderAligned = false; private ArchiveFlags mask; @@ -33,13 +35,28 @@ public BundleFile(Stream input, bool original = false, string? key = null) UnityCNKey = key; Header = new Header(reader); + var version = ParseVersion(); if (Header.version >= 7) { reader.AlignStream(16); + HeaderAligned = true; + } + else if (version[0] == 2019 && version[1] == 4) // temp fix for 2019.4.x + { + var p = reader.Position; + var len = 16 - p % 16; + var bytes = reader.ReadBytes((int)len); + if (bytes.Any(x => x != 0)) + { + reader.Position = p; + } + else + { + HeaderAligned = true; + } } - var version = ParseVersion(); if (version[0] < 2020 || //2020 and earlier (version[0] == 2020 && version[1] == 3 && version[2] <= 34) || //2020.3.34 and earlier (version[0] == 2021 && version[1] == 3 && version[2] <= 2) || //2021.3.2 and earlier @@ -290,7 +307,7 @@ public void Write(Stream output, string infoPacker = "none", string dataPacker = Header.Write(writer); - if (Header.version >= 7) + if (HeaderAligned) { writer.AlignStream(16); } @@ -341,7 +358,7 @@ private void calculateSize(long BlocksStreamLength, bool unityCN) DataInfo.calculateSize(ref Header.uncompressedBlocksInfoSize,ref Header.compressedBlocksInfoSize); long size = 0; size += Header.CalculateSize(); - if (Header.version >= 7) + if (HeaderAligned) { var a = size % 16; if (a != 0)