Exemplo n.º 1
0
        //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);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public byte[] GetEntryRawData(PegEntry entry)
 {
     return(GetEntryRawData(Entries.IndexOf(entry)));
 }
Exemplo n.º 3
0
 public Bitmap GetEntryBitmap(PegEntry entry)
 {
     return(GetEntryBitmap(Entries.IndexOf(entry)));
 }