Example #1
0
        public static List <PvmxTextureInfo> GetTextures(byte[] file)
        {
            if (!Is(file))
            {
                throw new FormatException("File is not a PVMX archive.");
            }
            if (file[4] != Version)
            {
                throw new FormatException("Incorrect PVMX archive version.");
            }
            int off = 5;
            List <PvmxTextureInfo> textures = new List <PvmxTextureInfo>();
            dictionary_field       type;

            for (type = (dictionary_field)file[off++]; type != dictionary_field.none; type = (dictionary_field)file[off++])
            {
                PvmxTextureInfo tex = new PvmxTextureInfo();
                while (type != dictionary_field.none)
                {
                    switch (type)
                    {
                    case dictionary_field.global_index:
                        tex.GlobalIndex = BitConverter.ToUInt32(file, off);
                        off            += sizeof(uint);
                        break;

                    case dictionary_field.name:
                        int count = 0;
                        while (file[off + count] != 0)
                        {
                            count++;
                        }
                        tex.Name = Path.ChangeExtension(Encoding.UTF8.GetString(file, off, count), null);
                        off     += count + 1;
                        break;

                    case dictionary_field.dimensions:
                        System.Drawing.Size size = new System.Drawing.Size();
                        size.Width  = BitConverter.ToInt32(file, off);
                        off        += sizeof(int);
                        size.Height = BitConverter.ToInt32(file, off);
                        off        += sizeof(int);
                        break;

                    default:
                        break;
                    }

                    type = (dictionary_field)file[off++];
                }

                ulong offset = BitConverter.ToUInt64(file, off);
                off += sizeof(ulong);
                ulong length = BitConverter.ToUInt64(file, off);
                off += sizeof(ulong);

                using (MemoryStream ms = new MemoryStream(file, (int)offset, (int)length))
                    tex.Image = new System.Drawing.Bitmap(ms);

                textures.Add(tex);
            }
            return(textures);
        }
Example #2
0
 public PvmxTextureInfo(PvmxTextureInfo tex)
     : this((TextureInfo)tex)
 {
     Dimensions = tex.Dimensions;
 }