Skip to content

Commit fef0261

Browse files
committed
Some Fix
1 parent b112e14 commit fef0261

7 files changed

Lines changed: 53 additions & 36 deletions

File tree

UnityAsset.NET/BundleFile/BlocksAndDirectoryInfo.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace UnityAsset.NET.BundleFile;
55

6-
public class BlocksAndDirectoryInfo
6+
public sealed class BlocksAndDirectoryInfo
77
{
88
public byte[] UncompressedDataHash;
99

@@ -115,6 +115,11 @@ public void merge()
115115
newBlocksInfo.Add(block);
116116
}
117117
}
118+
119+
if (DirectoryInfo.Sum(x => x.size) != newBlocksInfo.Sum(x => x.uncompressedSize))
120+
{
121+
throw new Exception("Expected all blocks size bigger than CAB size");
122+
}
118123

119124
BlocksInfo = newBlocksInfo;
120125
Update();

UnityAsset.NET/BundleFile/BundleFile.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public BundleFile(Stream input, bool original = false, string? key = null)
115115
ReadBlocks(reader);
116116

117117
DataInfo.uncompresseFlags();
118+
DataInfo.merge();
118119
Header.flags &= (ArchiveFlags)~StorageBlockFlags.CompressionTypeMask;
119120
DataInfo.calculateSize(ref Header.uncompressedBlocksInfoSize,ref Header.compressedBlocksInfoSize);
120121

@@ -272,11 +273,7 @@ public void Write(Stream output, string infoPacker = "none", string dataPacker =
272273
throw new Exception("UnityCN encryption requires lz4 or lz4hc compression type");
273274
}
274275

275-
if (dataPacker == "none")
276-
{
277-
DataInfo.merge();
278-
}
279-
else
276+
if (dataPacker != "none")
280277
{
281278
DataInfo.Split();
282279
}
@@ -336,16 +333,16 @@ public void Write(Stream output, string infoPacker = "none", string dataPacker =
336333
using AssetWriter writer = new AssetWriter(output);
337334

338335
Header.Write(writer);
339-
340-
if (HeaderAligned)
341-
{
342-
writer.AlignStream(16);
343-
}
344336

345337
if (unityCN && UnityCNInfo != null)
346338
{
347339
UnityCNInfo.Write(writer);
348340
}
341+
342+
if (HeaderAligned)
343+
{
344+
writer.AlignStream(16);
345+
}
349346

350347
if (!BlocksInfoAtTheEnd)
351348
{

UnityAsset.NET/BundleFile/CABInfo.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnityAsset.NET.IO;
1+
using System.Text;
2+
using UnityAsset.NET.IO;
23

34
namespace UnityAsset.NET.BundleFile;
45

@@ -27,11 +28,12 @@ public void Write(AssetWriter writer)
2728

2829
public override string ToString()
2930
{
30-
return
31-
$"offset: 0x{offset:X8} | " +
32-
$"size: 0x{size:X8} | " +
33-
$"flags: {flags} | " +
34-
$"path: {path}";
31+
StringBuilder sb = new StringBuilder();
32+
sb.AppendFormat("offset: 0x{0:X8} | ", offset);
33+
sb.AppendFormat("size: 0x{0:X8} | ", size);
34+
sb.AppendFormat("flags: {0} | ", flags);
35+
sb.AppendFormat("path: {0}", path);
36+
return sb.ToString();
3537
}
3638

3739
public long CalculateSize()

UnityAsset.NET/BundleFile/Header.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnityAsset.NET.Enums;
1+
using System.Text;
2+
using UnityAsset.NET.Enums;
23
using UnityAsset.NET.IO;
34

45
namespace UnityAsset.NET.BundleFile;
@@ -47,15 +48,16 @@ public void Write(AssetWriter writer)
4748

4849
public override string ToString()
4950
{
50-
return
51-
$"signature: {signature} | " +
52-
$"version: {version} | " +
53-
$"unityVersion: {unityVersion} | " +
54-
$"unityRevision: {unityRevision} | " +
55-
$"size: 0x{size:X8} | " +
56-
$"compressedBlocksInfoSize: 0x{compressedBlocksInfoSize:X8} | " +
57-
$"uncompressedBlocksInfoSize: 0x{uncompressedBlocksInfoSize:X8} | " +
58-
$"flags: 0x{(int)flags:X8}";
51+
StringBuilder sb = new StringBuilder();
52+
sb.AppendFormat("signature: {0} | ", signature);
53+
sb.AppendFormat("version: {0} | ", version);
54+
sb.AppendFormat("unityVersion: {0} | ", unityVersion);
55+
sb.AppendFormat("unityRevision: {0} | ", unityRevision);
56+
sb.AppendFormat("size: 0x{0:X8} | ", size);
57+
sb.AppendFormat("compressedBlocksInfoSize: 0x{0:X8} | ", compressedBlocksInfoSize);
58+
sb.AppendFormat("uncompressedBlocksInfoSize: 0x{0:X8} | ", uncompressedBlocksInfoSize);
59+
sb.AppendFormat("flags: 0x{0:X8}", (int)flags);
60+
return sb.ToString();
5961
}
6062

6163
public long CalculateSize()

UnityAsset.NET/BundleFile/StorageBlockInfo.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnityAsset.NET.Enums;
1+
using System.Text;
2+
using UnityAsset.NET.Enums;
23
using UnityAsset.NET.IO;
34

45
namespace UnityAsset.NET.BundleFile;
@@ -32,9 +33,10 @@ public void Write(AssetWriter writer)
3233

3334
public override string ToString()
3435
{
35-
return
36-
$"compressedSize: 0x{compressedSize:X8} | " +
37-
$"uncompressedSize: 0x{uncompressedSize:X8} | " +
38-
$"flags: 0x{(int)flags:X8}";
36+
StringBuilder sb = new StringBuilder();
37+
sb.AppendFormat("compressedSize: 0x{0:X8} | ", compressedSize);
38+
sb.AppendFormat("uncompressedSize: 0x{0:X8} | ", uncompressedSize);
39+
sb.AppendFormat("flags: 0x{0:X8}", (int)flags);
40+
return sb.ToString();
3941
}
4042
}

UnityAsset.NET/IO/AssetReader.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace UnityAsset.NET.IO;
55

6-
public class AssetReader : BinaryReader
6+
public sealed class AssetReader : BinaryReader
77
{
88
public bool BigEndian;
99

@@ -92,8 +92,17 @@ public override uint ReadUInt32()
9292
return base.ReadUInt32();
9393
}
9494
}
95-
96-
95+
96+
public string ReadNullTerminated()
97+
{
98+
string output = "";
99+
char curChar;
100+
while ((curChar = ReadChar()) != 0x00)
101+
{
102+
output += curChar;
103+
}
104+
return output;
105+
}
97106

98107
public string ReadStringToNull(int maxLength = 32767)
99108
{

UnityAsset.NET/IO/AssetWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace UnityAsset.NET.IO;
55

6-
public class AssetWriter : BinaryWriter
6+
public sealed class AssetWriter : BinaryWriter
77
{
88
public bool BigEndian;
99

0 commit comments

Comments
 (0)