//Todo: Consider adding warnings for unusual, problematic, or unsupported values. Maybe change some existing exceptions to warnings. public void Read() { using (var cpuFileStream = new FileStream(_cpuFilePath, FileMode.Open)) { using (var gpuFileStream = new FileStream(_gpuFilePath, FileMode.Open)) { Entries.Clear(); var header = new BinaryReader(cpuFileStream); Signature = header.ReadUInt32(); if (Signature != 1447773511) //Equals GEKV as a string { throw new Exception("Header signature must be GEKV. Invalid peg file. Make sure that your packfile extractor didn't incorrectly extract the peg file you're trying to open."); } Version = header.ReadUInt16(); if (Version != 10) { throw new Exception($"Unsupported peg format version detected! Only peg version 10 is supported. Version {Version} was detected"); } Platform = header.ReadUInt16(); //Todo: Add exception or warning for unknown or unsupported platform. DirectoryBlockSize = header.ReadUInt32(); if (header.BaseStream.Length != DirectoryBlockSize) { throw new Exception($"Error, the size of the header file (cpeg_pc or cvbm_pc) does not match the size value stored in the header! Actual size: {header.BaseStream.Length} bytes, stored size: {DirectoryBlockSize} bytes."); } DataBlockSize = header.ReadUInt32(); NumberOfBitmaps = header.ReadUInt16(); Flags = header.ReadUInt16(); TotalEntries = header.ReadUInt16(); AlignValue = header.ReadUInt16(); //Read peg entries for (int i = 0; i < NumberOfBitmaps; i++) { var entry = new PegEntry(); entry.Read(header); Entries.Add(entry); } //Read peg entry names foreach (var entry in Entries) { entry.Name = Util.ReadNullTerminatedString(header); } } } }
public byte[] GetEntryRawData(PegEntry entry) { return(GetEntryRawData(Entries.IndexOf(entry))); }
public Bitmap GetEntryBitmap(PegEntry entry) { return(GetEntryBitmap(Entries.IndexOf(entry))); }