@@ -31,7 +31,7 @@ public class BundleFile
3131
3232 public uint Crc32 ;
3333
34- public static UnityCN ? ParseUnityCnInfo ( ref DataBuffer db , Header header , string ? key )
34+ public static UnityCN ? ParseUnityCnInfo ( DataBuffer db , Header header , string ? key )
3535 {
3636 var unityCnMask = VersionJudge1 ( ParseVersion ( header ) )
3737 ? ArchiveFlags . BlockInfoNeedPaddingAtStart
@@ -42,12 +42,12 @@ public class BundleFile
4242 key ??= Setting . DefaultUnityCNKey ;
4343 if ( key == null )
4444 throw new Exception ( $ "UnityCN key is required for decryption. UnityCN Flag Mask: { unityCnMask } ") ;
45- return new UnityCN ( ref db , key ) ;
45+ return new UnityCN ( db , key ) ;
4646 }
4747 return null ;
4848 }
4949
50- public static void AlignAfterHeader ( ref DataBuffer db , Header header )
50+ public static void AlignAfterHeader ( DataBuffer db , Header header )
5151 {
5252 if ( header . Version >= 7 )
5353 db . Align ( 16 ) ;
@@ -59,21 +59,21 @@ public static void AlignAfterHeader(ref DataBuffer db, Header header)
5959 }
6060 }
6161
62- public static BlocksAndDirectoryInfo ParseDataInfo ( ref DataBuffer db , Header header )
62+ public static BlocksAndDirectoryInfo ParseDataInfo ( DataBuffer db , Header header )
6363 {
6464 Span < byte > blocksInfoBytes = ( header . Flags & ArchiveFlags . BlocksInfoAtTheEnd ) == 0
6565 ? db . ReadSpanBytes ( ( int ) header . CompressedBlocksInfoSize )
66- : db [ ( int ) ( header . Size - header . CompressedBlocksInfoSize ) ..( int ) ( header . Size ) ] ;
66+ : db [ ( int ) ( header . Size - header . CompressedBlocksInfoSize ) ..( int ) header . Size ] ;
6767 var compressionType = ( CompressionType ) ( header . Flags & ArchiveFlags . CompressionTypeMask ) ;
6868 DataBuffer blocksInfoUncompressedData = new DataBuffer ( ( int ) header . UncompressedBlocksInfoSize ) ;
6969 Compression . DecompressToBytes ( blocksInfoBytes , blocksInfoUncompressedData . AsSpan ( ) , compressionType ) ;
70- var dataInfo = BlocksAndDirectoryInfo . Parse ( ref blocksInfoUncompressedData ) ;
70+ var dataInfo = BlocksAndDirectoryInfo . Parse ( blocksInfoUncompressedData ) ;
7171 if ( ! VersionJudge1 ( ParseVersion ( header ) ) && ( header . Flags & ArchiveFlags . BlockInfoNeedPaddingAtStart ) != 0 )
7272 db . Align ( 16 ) ;
7373 return dataInfo ;
7474 }
7575
76- public static ( List < FileWrapper > , uint ) ParseFiles ( ref DataBuffer db , BlocksAndDirectoryInfo dataInfo , UnityCN ? unityCnInfo = null )
76+ public static ( List < FileWrapper > , uint ) ParseFiles ( DataBuffer db , BlocksAndDirectoryInfo dataInfo , UnityCN ? unityCnInfo = null )
7777 {
7878 DataBuffer blocksBuffer = new DataBuffer ( dataInfo . BlocksInfo . Sum ( block => ( int ) block . UncompressedSize ) ) ;
7979 if ( unityCnInfo == null )
@@ -107,12 +107,12 @@ public static (List<FileWrapper>, uint) ParseFiles(ref DataBuffer db, BlocksAndD
107107 if ( dir . Path . StartsWith ( "CAB-" ) && ! dir . Path . EndsWith ( ".resS" ) )
108108 {
109109 var cabBuffer = blocksBuffer . SliceBuffer ( ( int ) dir . Size ) ;
110- files . Add ( new FileWrapper ( SerializedFile . Parse ( ref cabBuffer ) , dir ) ) ;
110+ files . Add ( new FileWrapper ( SerializedFile . Parse ( cabBuffer ) , dir ) ) ;
111111 blocksBuffer . Advance ( ( int ) dir . Size ) ;
112112 }
113113 else
114114 {
115- files . Add ( new FileWrapper ( new HeapDataBuffer ( blocksBuffer . ReadSpanBytes ( ( int ) dir . Size ) . ToArray ( ) ) , dir ) ) ;
115+ files . Add ( new FileWrapper ( new DataBuffer ( blocksBuffer . ReadSpanBytes ( ( int ) dir . Size ) . ToArray ( ) ) , dir ) ) ;
116116 }
117117 }
118118
@@ -127,37 +127,26 @@ public BundleFile(Header header, BlocksAndDirectoryInfo dataInfo, List<FileWrapp
127127 Files = files ;
128128 }
129129
130- public BundleFile ( ref DataBuffer db , string ? key = null )
130+ public BundleFile ( DataBuffer db , string ? key = null )
131131 {
132132 UnityCnKey = key ;
133- Header = Header . Parse ( ref db ) ;
134- UnityCnInfo = ParseUnityCnInfo ( ref db , Header , UnityCnKey ) ;
135- AlignAfterHeader ( ref db , Header ) ;
136- DataInfo = ParseDataInfo ( ref db , Header ) ;
137- ( Files , Crc32 ) = ParseFiles ( ref db , DataInfo , UnityCnInfo ) ;
133+ Header = Header . Parse ( db ) ;
134+ UnityCnInfo = ParseUnityCnInfo ( db , Header , UnityCnKey ) ;
135+ AlignAfterHeader ( db , Header ) ;
136+ DataInfo = ParseDataInfo ( db , Header ) ;
137+ ( Files , Crc32 ) = ParseFiles ( db , DataInfo , UnityCnInfo ) ;
138138 }
139139
140- public BundleFile ( string path , string ? key = null )
141- {
142- var db = DataBuffer . FromFile ( path ) ;
143- UnityCnKey = key ;
144- Header = Header . Parse ( ref db ) ;
145- if ( string . IsNullOrEmpty ( Header . UnityRevision ) )
146- Header . UnityRevision = Setting . DefaultUnityVerion ;
147- UnityCnInfo = ParseUnityCnInfo ( ref db , Header , UnityCnKey ) ;
148- AlignAfterHeader ( ref db , Header ) ;
149- DataInfo = ParseDataInfo ( ref db , Header ) ;
150- ( Files , Crc32 ) = ParseFiles ( ref db , DataInfo , UnityCnInfo ) ;
151- }
140+ public BundleFile ( string path , string ? key = null ) : this ( DataBuffer . FromFile ( path ) , key ) { }
152141
153- public void Serialize ( ref DataBuffer db , CompressionType infoPacker = CompressionType . None , CompressionType dataPacker = CompressionType . None , string ? unityCnKey = null )
142+ public void Serialize ( DataBuffer db , CompressionType infoPacker = CompressionType . None , CompressionType dataPacker = CompressionType . None , string ? unityCnKey = null )
154143 {
155144 if ( Header == null || DataInfo == null || Files == null )
156145 throw new NullReferenceException ( "BundleFile has not read completely" ) ;
157146 var directoryInfo = new List < FileEntry > ( ) ;
158147 var filesCapacity = Files . Sum ( c =>
159148 {
160- if ( c . File is HeapDataBuffer hdb ) return hdb . Capacity ;
149+ if ( c . File is DataBuffer hdb ) return hdb . Capacity ;
161150 if ( c . File is SerializedFile sf ) return sf . SerializeSize ;
162151 return 0 ;
163152 } ) ;
@@ -168,13 +157,13 @@ public void Serialize(ref DataBuffer db, CompressionType infoPacker = Compressio
168157 Int64 cabSize ;
169158 switch ( file . File )
170159 {
171- case HeapDataBuffer hdb :
172- filesBuffer . WriteBytes ( hdb . AsSpan ( ) ) ;
173- cabSize = hdb . Length ;
160+ case DataBuffer dataBuffer :
161+ filesBuffer . WriteBytes ( dataBuffer . AsSpan ( ) ) ;
162+ cabSize = dataBuffer . Length ;
174163 break ;
175164 case SerializedFile sf :
176165 var subBuffer = filesBuffer . SliceBufferToEnd ( ) ;
177- sf . Serialize ( ref subBuffer ) ;
166+ sf . Serialize ( subBuffer ) ;
178167 filesBuffer . Advance ( subBuffer . Position ) ;
179168 cabSize = subBuffer . Position ;
180169 break ;
@@ -234,7 +223,7 @@ public void Serialize(ref DataBuffer db, CompressionType infoPacker = Compressio
234223
235224 var dataInfo = new BlocksAndDirectoryInfo ( DataInfo . UncompressedDataHash , blocksInfo , directoryInfo ) ;
236225 DataBuffer dataInfoBuffer = new DataBuffer ( ( int ) dataInfo . SerializeSize ) ;
237- dataInfo . Serialize ( ref dataInfoBuffer ) ;
226+ dataInfo . Serialize ( dataInfoBuffer ) ;
238227 var uncompressedBlocksInfoSize = dataInfoBuffer . Length ;
239228 DataBuffer compressedDataInfoBuffer = new DataBuffer ( uncompressedBlocksInfoSize ) ;
240229 var compressedBlocksInfoSize = Compression . CompressToBytes ( dataInfoBuffer . AsSpan ( ) , compressedDataInfoBuffer . AsSpan ( ) , infoPacker ) ;
@@ -243,9 +232,9 @@ public void Serialize(ref DataBuffer db, CompressionType infoPacker = Compressio
243232 0 , ( uint ) compressedBlocksInfoSize , ( uint ) uncompressedBlocksInfoSize ,
244233 ( Header . Flags & ~ ArchiveFlags . CompressionTypeMask ) | ( ArchiveFlags ) infoPacker ) ;
245234 db . EnsureCapacity ( ( int ) ( header . SerializeSize + 16 + compressedBlocksInfoSize + compressedBlocksDataBuffer . Length + unityCnInfo ? . SerializeSize ?? 0 ) ) ;
246- header . Serialize ( ref db ) ;
235+ header . Serialize ( db ) ;
247236 if ( unityCnInfo != null )
248- unityCnInfo . Serialize ( ref db ) ;
237+ unityCnInfo . Serialize ( db ) ;
249238 if ( header . Version >= 7 )
250239 db . Align ( 16 ) ;
251240 else // temp fix for 2019.4.x
@@ -263,14 +252,14 @@ public void Serialize(ref DataBuffer db, CompressionType infoPacker = Compressio
263252 var size = db . Position ;
264253 header . Size = size ;
265254 db . Seek ( 0 ) ;
266- header . Serialize ( ref db ) ;
255+ header . Serialize ( db ) ;
267256 }
268257
269258 public void Serialize ( string path , CompressionType infoPacker = CompressionType . None ,
270259 CompressionType dataPacker = CompressionType . None , string ? unityCnKey = null )
271260 {
272261 DataBuffer db = new DataBuffer ( 0 ) ;
273- Serialize ( ref db , infoPacker , dataPacker , unityCnKey ) ;
262+ Serialize ( db , infoPacker , dataPacker , unityCnKey ) ;
274263 db . WriteToFile ( path ) ;
275264 }
276265
0 commit comments