private void WriteHeader(BinaryWriter writer, GpkPackage package, bool reserveChunkheaderSize) { writer.Write(package.Header.Tag); writer.Write(package.Header.FileVersion); writer.Write(package.Header.LicenseVersion); writer.Write(package.Header.HeaderSize); WriteString(writer, package.Header.PackageName, true); writer.Write(package.Header.PackageFlags); if (package.x64) { writer.Write(package.Header.NameCount); } else { writer.Write(package.Header.NameCount + package.Header.NameOffset); //tera thing } offsetNamePos = writer.BaseStream.Position; writer.Write(package.Header.NameOffset); writer.Write(package.Header.ExportCount); offsetExportPos = writer.BaseStream.Position; writer.Write(package.Header.ExportOffset); writer.Write(package.Header.ImportCount); offsetImportPos = writer.BaseStream.Position; writer.Write(package.Header.ImportOffset); offsetDependsPos = writer.BaseStream.Position; writer.Write(package.Header.DependsOffset); headerSizeOffset = writer.BaseStream.Position; if (package.x64) { writer.Write(package.Header.HeaderSize); } if (package.x64) { writer.Write(package.Header.Unk1); } writer.Write(package.Header.FGUID); writer.Write(package.Header.Generations.Count); for (int i = 0; i < package.Header.Generations.Count; i++) { GpkGeneration tmpgen = package.Header.Generations[i]; writer.Write(tmpgen.ExportCount); writer.Write(tmpgen.NameCount); writer.Write(tmpgen.NetObjectCount); } //24 writer.Write(package.Header.EngineVersion); writer.Write(package.Header.CookerVersion); if (CoreSettings.Default.EnableCompression) { writer.Write(package.Header.CompressionFlags); //compressionFlags if (reserveChunkheaderSize) { int headerCount = package.EstimateChunkHeaderCount(); //16 bytes per chunkheader writer.Write((int)0); //chunkcount; //writer.Write(new byte[16 * headerCount]); } else { writer.Write(package.Header.ChunkHeaders.Count); //chunkcount; foreach (var chunk in package.Header.ChunkHeaders) { writer.Write(chunk.UncompressedOffset); writer.Write(chunk.UncompressedSize); writer.Write(chunk.CompressedOffset); writer.Write(chunk.CompressedSize); } } } else { writer.Write((int)0); //compressionFlags writer.Write((int)0); //chunkheadercount } writer.Write(package.Header.HeaderPadding); //unk stuff logger.Debug("Wrote header pos " + writer.BaseStream.Position); }