Beispiel #1
0
        public Bitmap GetEntryBitmap(int entryIndex)
        {
            if (entryIndex >= Entries.Count)
            {
                return(null);
            }

            var entry = Entries[entryIndex];

            if (entry.Edited)
            {
                return(entry.Bitmap);
            }
            else
            {
                var gpuFileStream = new FileStream(_gpuFilePath, FileMode.Open);
                var rawData       = new byte[entry.frame_size];

                gpuFileStream.Skip(entry.data);
                gpuFileStream.Read(rawData, 0, (int)entry.frame_size);
                var bitmap = PegUtil.RawDataToBitmap(rawData, entry.bitmap_format, entry.width, entry.height);
                gpuFileStream.Dispose();

                return(bitmap);
            }
        }
Beispiel #2
0
        //Todo: Consider adding warnings for unusual, problematic, or unsupported values. Maybe change some existing exceptions to warnings.
        public void Read(Stream cpuFileStream, Stream gpuFileStream)
        {
            Entries.Clear();
            var header = new BinaryReader(cpuFileStream);
            var data   = new BinaryReader(gpuFileStream);

            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
            int currentDataOffset = 0;

            for (int i = 0; i < NumberOfBitmaps; i++)
            {
                var entry = new PegEntry();
                entry.Read(header);
                Entries.Add(entry);

                //entry.GpuFileDataOffset = currentDataOffset;
                //currentDataOffset += (int)entry.frame_size;
                //currentDataOffset +=
            }

            //Read peg entry names
            foreach (var entry in Entries)
            {
                entry.Name = PegUtil.ReadNullTerminatedString(header);
            }

            //Load raw texture data from gpu file, convert to bitmaps for easy handling
            //foreach (var entry in Entries)
            //{
            //    entry.RawData = new byte[entry.frame_size];
            //    data.Read(entry.RawData, 0, (int)entry.frame_size);
            //    entry.Bitmap = PegUtil.EntryDataToBitmap(entry);
            //}
        }