static void ConvertFromPK3(int TargetVer, ZipArchive In, ZipArchive Out) { int EntryNum = 0; int Count = In.Entries.Count; foreach (var Entry in In.Entries) { Console.Title = string.Format("{0:0}%", ((float)EntryNum / Count) * 100); EntryNum++; if (Entry.Length == 0) { continue; } string EntryExt = Path.GetExtension(Entry.FullName); ZipArchiveEntry OutEntry = Out.CreateEntry(Entry.FullName, CompressionLevel.Optimal); OpenEntry(Entry, true, (InStream) => { if (EntryExt == ".bsp") { Console.WriteLine("Converting {0}", Entry.FullName); BSP Map = BSP.FromStream(InStream); Map.Version = TargetVer; OpenEntry(OutEntry, false, (OutStream) => Map.Serialize(OutStream)); } else { OpenEntry(OutEntry, false, (OutStream) => InStream.CopyTo(OutStream)); } }); } }
static void Main(string[] args) { Console.Title = "Test3"; if (args.Length == 0) { args = new string[] { "maps_q3.pk3" } } ; int TargetVer = 0; int StartIdx = 0; if (args.Length > 1 && int.TryParse(args[0], out TargetVer)) { StartIdx = 1; } else { TargetVer = 47; StartIdx = 0; } Console.WriteLine("Converting to IBSP {0}", TargetVer); for (int i = StartIdx; i < args.Length; i++) { string FileNameExt = args[i]; if (!File.Exists(FileNameExt)) { Console.WriteLine("Could not find {0}", FileNameExt); continue; } string FileName = Path.GetFileNameWithoutExtension(FileNameExt); string Extension = Path.GetExtension(FileNameExt); string OutName = FileName + "_IBSP" + TargetVer + Extension; if (Extension == ".bsp") { Console.WriteLine("Converting {0}", FileNameExt); BSP Map = BSP.FromFile(FileNameExt); Map.Version = TargetVer; File.WriteAllBytes(OutName, Map.ToByteArray()); } else if (Extension == ".pk3") { OpenZip(FileNameExt, true, (In) => { OpenZip(OutName, false, (Out) => { int EntryNum = 0; int Count = In.Entries.Count; foreach (var Entry in In.Entries) { Console.Title = string.Format("{0:0}%", ((float)EntryNum / Count) * 100); EntryNum++; if (Entry.Length == 0) { continue; } string EntryExt = Path.GetExtension(Entry.FullName); ZipArchiveEntry OutEntry = Out.CreateEntry(Entry.FullName, CompressionLevel.Optimal); OpenEntry(Entry, true, (InStream) => { if (EntryExt == ".bsp") { Console.WriteLine("Converting {0}", Entry.FullName); BSP Map = BSP.FromStream(InStream); Map.Version = TargetVer; OpenEntry(OutEntry, false, (OutStream) => Map.Serialize(OutStream)); } else { OpenEntry(OutEntry, false, (OutStream) => InStream.CopyTo(OutStream)); } }); } }); }); } else { Console.WriteLine("Skipping {0}, unknown extension type {1}", FileNameExt, Extension); } } }