public static void 懒得起名(Stream output, UE_Reader reader, PakEntry entry) { if (entry.Encrypted || entry.Position < 0) { throw new Exception("把这个判断句复制到 caller"); } if (entry.Compression == CompressionMethod.None) { reader.BaseStream.Position = entry.Position + entry.HeaderSize; var _R = reader.ReadBytes((int)(entry.UncompressedSize)); output.Write(_R, 0, _R.Length); } else if (entry.Compression == CompressionMethod.Zlib) { for (int i = 0; i < entry.Blocks.Length; i++) { byte[] cnt = ReadBlock(reader, entry, entry.Blocks[i]); var _R = ZlibStream.UncompressBuffer(cnt); output.Write(_R, 0, _R.Length); } } else { throw new NotImplementedException($"Compression Method {entry.Compression} is not implemented."); } }
public PakEntry(UE_Reader reader, PakIndex index) { Index = index; Filename = reader.ReadString(); long start_position = reader.BaseStream.Position; Position = reader.ReadInt64(); if (Position < 0) { reader.BaseStream.Position += 0x2A; HeaderSize = reader.BaseStream.Position - start_position; return; } Size = reader.ReadInt64(); UncompressedSize = reader.ReadInt64(); CompressionMethodIndex = reader.ReadByte(); Hash = reader.ReadBytes(20); PakCompressedBlockCount = reader.ReadInt32(); Blocks = new PakCompressedBlock[PakCompressedBlockCount]; for (int i = 0; i < Blocks.Length; i++) { Blocks[i] = new PakCompressedBlock(reader); } Encrypted = reader.ReadByte() > 0; // need UE Viewer source reference if (PakCompressedBlockCount > 0) { CompressionBlockSize = reader.ReadInt32(); } HeaderSize = reader.BaseStream.Position - start_position; }
public PakFile(UE_Reader reader) { reader.BaseStream.Position = reader.BaseStream.Length - 189; Info = new PakInfo(reader, this); reader.BaseStream.Position = Info.IndexOffset; Index = new PakIndex(reader, this); }
static byte[] ReadBlock(UE_Reader reader, PakEntry entry, PakCompressedBlock b_info) { reader.BaseStream.Position = entry.Position + b_info.CompressedStart; long length = b_info.CompressedEnd - b_info.CompressedStart; return(reader.ReadBytes((int)length)); }
static void DecompressPak(string pak_file, string out_directory) { Directory.CreateDirectory(out_directory); PakFile pak = PakFile.ReadFromFile(pak_file); using (var fs = File.OpenRead(pak_file)) using (var reader = new UE_Reader(fs, true)) { foreach (var entry in pak.Index.Entries) { Console.WriteLine($"Processing {entry.Filename}"); if (entry.Encrypted || entry.Position < 0) { Console.WriteLine("Encrypted or not present, pass."); continue; } string out_p = Path.Combine(out_directory, entry.Filename); Directory.CreateDirectory(Path.GetDirectoryName(out_p)); using (var fs_w = File.Create(out_p)) { Decompress.懒得起名(fs_w, reader, entry); } } } }
public static PakFile ReadFromFile(string path) { PakFile pak; using (var fs = File.OpenRead(path)) using (var reader = new UE_Reader(fs, true)) { pak = new PakFile(reader); } return(pak); }
public PakIndex(UE_Reader reader, PakFile pak) { Pak = pak; MountPoint = reader.ReadString(); PakEntryCount = reader.ReadInt32(); Entries = new PakEntry[PakEntryCount]; for (int i = 0; i < Entries.Length; i++) { Entries[i] = new PakEntry(reader, this); } }
public PakInfo(UE_Reader reader, PakFile pak) { Pak = pak; EncryptionKeyGuid = reader.ReadBytes(16); EncryptedIndex = reader.ReadByte() > 0; // need UE Viewer source reference Magic = reader.ReadUInt32(); Version = reader.ReadInt32(); IndexOffset = reader.ReadInt64(); IndexSize = reader.ReadInt64(); IndexHash = reader.ReadBytes(20); CompressionMethods = new string[4]; for (int i = 0; i < CompressionMethods.Length; i++) { CompressionMethods[i] = GetString(reader.ReadBytes(32)); } }
public PakCompressedBlock(UE_Reader reader) { CompressedStart = reader.ReadInt64(); CompressedEnd = reader.ReadInt64(); }