@@ -44,8 +44,11 @@ public class SerializedFileInfo
4444public static class SerializedFileDetector
4545{
4646 // Version boundaries for format changes
47- private const uint NewLayoutVersion = 9 ; // kUnknown_9: Changed from [header][data][metadata] to [header][metadata][data]
48- private const uint LargeFilesSupportVersion = 22 ; // kLargeFilesSupport: Changed to 64-bit header
47+ // NOTE: This version is so old that it is extremely unlikely it will work with modern versions of Unity,
48+ // we handle it just for the purpose of trying to report accurate information about the file.
49+ private const uint NewLayoutVersion = 9 ; // Changed from [header][data][metadata] to [header][metadata][data]
50+
51+ private const uint LargeFilesSupportVersion = 22 ; // Changed to 64-bit header
4952
5053 // Reasonable version range for SerializedFiles
5154 // Unity versions currently use values in the 20s-30s range
@@ -105,7 +108,7 @@ public static bool TryDetectSerializedFile(string filePath, out SerializedFileIn
105108
106109 // Determine which interpretation gives us a valid version number
107110 uint version ;
108- bool needsSwap ; // Whether header fields need byte swapping
111+ bool needsSwap ; // Whether header fields need byte swapping (expected to be true when running on most modern systems, which are little-endian)
109112
110113 if ( versionLE >= MinVersion && versionLE <= MaxVersion )
111114 {
@@ -250,13 +253,8 @@ public static bool TryDetectSerializedFile(string filePath, out SerializedFileIn
250253 // Allow some tolerance for "stream files" which can have padding
251254 if ( fileSize != ulong . MaxValue )
252255 {
253- // File size should not exceed actual file size by more than 1MB (arbitrary tolerance)
254- if ( fileSize > ( ulong ) fileLength + 1024 * 1024 )
255- return false ;
256-
257- // File size should be reasonably close to actual size (within 10% or 1MB)
258- ulong tolerance = Math . Max ( fileSize / 10 , 1024 * 1024 ) ;
259- if ( ( ulong ) fileLength > fileSize + tolerance )
256+ // File size should not exceed actual file size by more than 1KB (arbitrary tolerance)
257+ if ( fileSize > ( ulong ) fileLength + 1024 )
260258 return false ;
261259 }
262260
@@ -305,9 +303,6 @@ private static ulong ReadUInt64(byte[] buffer, int offset, bool swap)
305303 return swap ? SwapUInt64 ( value ) : value ;
306304 }
307305
308- /// <summary>
309- /// Swaps the byte order of a UInt32 value.
310- /// </summary>
311306 private static uint SwapUInt32 ( uint value )
312307 {
313308 return ( ( value & 0x000000FFU ) << 24 ) |
@@ -316,9 +311,6 @@ private static uint SwapUInt32(uint value)
316311 ( ( value & 0xFF000000U ) >> 24 ) ;
317312 }
318313
319- /// <summary>
320- /// Swaps the byte order of a UInt64 value.
321- /// </summary>
322314 private static ulong SwapUInt64 ( ulong value )
323315 {
324316 return ( ( value & 0x00000000000000FFUL ) << 56 ) |
0 commit comments