public static long GetSize(PAK_VERSION version, uint CompressionMethodIndex = 0, uint CompressionBlocksCount = 0) { long SerializedSize = sizeof(long) + sizeof(long) + sizeof(long) + 20; if (version >= PAK_VERSION.PAK_FNAME_BASED_COMPRESSION_METHOD) { SerializedSize += sizeof(uint); } else { SerializedSize += sizeof(int); // Old CompressedMethod var from pre-fname based compression methods } if (version >= PAK_VERSION.PAK_COMPRESSION_ENCRYPTION) { SerializedSize += sizeof(byte) + sizeof(uint); if (CompressionMethodIndex != 0) { SerializedSize += sizeof(long) * 2 * CompressionBlocksCount + sizeof(int); } } if (version < PAK_VERSION.PAK_NO_TIMESTAMPS) { // Timestamp SerializedSize += sizeof(long); } return(SerializedSize); }
internal FPakEntry(BinaryReader reader, string mountPoint, PAK_VERSION Version) { CompressionBlocks = null; CompressionBlockSize = 0; Flags = 0; Name = mountPoint + reader.ReadFString(FPakInfo.MAX_PACKAGE_PATH).Replace(".umap", ".uasset"); var StartOffset = reader.BaseStream.Position; Offset = reader.ReadInt64(); Size = reader.ReadInt64(); UncompressedSize = reader.ReadInt64(); if (Version < PAK_VERSION.PAK_FNAME_BASED_COMPRESSION_METHOD) { var LegacyCompressionMethod = reader.ReadInt32(); if (LegacyCompressionMethod == (int)ECompressionFlags.COMPRESS_None) { CompressionMethodIndex = 0; } else if ((LegacyCompressionMethod & (int)ECompressionFlags.COMPRESS_ZLIB) != 0) { CompressionMethodIndex = 1; } else if ((LegacyCompressionMethod & (int)ECompressionFlags.COMPRESS_GZIP) != 0) { CompressionMethodIndex = 2; } else if ((LegacyCompressionMethod & (int)ECompressionFlags.COMPRESS_Custom) != 0) { CompressionMethodIndex = 3; } else { // https://github.com/EpicGames/UnrealEngine/blob/8b6414ae4bca5f93b878afadcc41ab518b09984f/Engine/Source/Runtime/PakFile/Public/IPlatformFilePak.h#L441 throw new FileLoadException(@"Found an unknown compression type in pak file, will need to be supported for legacy files"); } } else { CompressionMethodIndex = reader.ReadUInt32(); } if (Version <= PAK_VERSION.PAK_INITIAL) { // Timestamp of type FDateTime, but the serializer only reads to the Ticks property (int64) reader.ReadInt64(); } Hash = reader.ReadBytes(20); if (Version >= PAK_VERSION.PAK_COMPRESSION_ENCRYPTION) { if (CompressionMethodIndex != 0) { CompressionBlocks = reader.ReadTArray(() => new FPakCompressedBlock(reader)); } Flags = reader.ReadByte(); CompressionBlockSize = reader.ReadUInt32(); } // Used to seek ahead to the file data instead of parsing the entry again StructSize = (int)(reader.BaseStream.Position - StartOffset); }