示例#1
0
 public static Palette256 FromArchive(string file, bool ignoreCase, DATArchive archive)
 {
     if (!archive.Contains(file, ignoreCase))
     {
         return((Palette256)null);
     }
     return(Palette256.FromRawData(archive.ExtractFile(file, ignoreCase)));
 }
示例#2
0
 public static EPFImage FromArchive(string file, bool ignoreCase, DATArchive archive)
 {
     if (!archive.Contains(file, ignoreCase))
     {
         return((EPFImage)null);
     }
     return(EPFImage.FromRawData(archive.ExtractFile(file, ignoreCase), file));
 }
示例#3
0
文件: EPF.cs 项目: FallenDev/editor
        /// <summary>
        /// Loads an EPF image file from an archive.
        /// </summary>
        /// <param name="file">EPF image to load.</param>
        /// <param name="ignoreCase">Ignore case (noncase-sensitive).</param>
        /// <param name="archive">Data archive to load from.</param>
        /// <returns>EPF image.</returns>
        public static EPFImage FromArchive(string file, bool ignoreCase, DATArchive archive)
        {
            // Check if File Exists
            if (!archive.Contains(file, ignoreCase))
            {
                return(null);
            }

            // Extract and Create File
            return(FromRawData(archive.ExtractFile(file, ignoreCase)));
        }
示例#4
0
        /// <summary>
        /// Loads a palette file from an archive (case-sensitive).
        /// </summary>
        /// <param name="file">Palette file to load.</param>
        /// <param name="archive">Data archive to load from.</param>
        /// <returns>256 color palette.</returns>
        public static Palette256 FromArchive(string file, DATArchive archive)
        {
            // Check if File Exists
            if (!archive.Contains(file))
            {
                return(null);
            }

            // Extract and Create File
            return(FromRawData(archive.ExtractFile(file)));
        }
示例#5
0
        /// <summary>
        /// Loads a tileset from an archive.
        /// </summary>
        /// <param name="file">Tileset to load.</param>
        /// <param name="ignoreCase">Ignore case (noncase-sensitive).</param>
        /// <param name="archive">Data archive to load from.</param>
        /// <returns>Number of tiles loaded.</returns>
        public static Tileset FromArchive(string file, bool ignoreCase, DATArchive archive)
        {
            // Check if File Exists
            if (!archive.Contains(file, ignoreCase))
            {
                return(null);
            }

            // Extract and Create File
            Tileset tileset = LoadTiles(new MemoryStream(archive.ExtractFile(file, ignoreCase)));

            tileset.name     = Path.GetFileNameWithoutExtension(file).ToUpper();
            tileset.filename = file;

            // Return Tileset
            return(tileset);
        }
示例#6
0
 public int LoadTables(string pattern, DATArchive archive)
 {
     this.entries.Clear();
     foreach (DATFileEntry file in archive.Files)
     {
         if (file.Name.ToUpper().EndsWith(".TBL") && file.Name.ToUpper().StartsWith(pattern.ToUpper()))
         {
             string s = Path.GetFileNameWithoutExtension(file.Name).Remove(0, pattern.Length);
             if (s != "ani")
             {
                 StreamReader streamReader = new StreamReader((Stream) new MemoryStream(archive.ExtractFile(file)));
                 while (!streamReader.EndOfStream)
                 {
                     string[] strArray = streamReader.ReadLine().Split(' ');
                     if (strArray.Length == 3)
                     {
                         int int32_1 = Convert.ToInt32(strArray[0]);
                         int int32_2 = Convert.ToInt32(strArray[1]);
                         int int32_3 = Convert.ToInt32(strArray[2]);
                         int result  = 0;
                         if (int.TryParse(s, out result))
                         {
                             this.overrides.Add(new PaletteTableEntry(int32_1, int32_2, int32_3));
                         }
                         else
                         {
                             this.entries.Add(new PaletteTableEntry(int32_1, int32_2, int32_3));
                         }
                     }
                     else if (strArray.Length == 2)
                     {
                         int int32_1 = Convert.ToInt32(strArray[0]);
                         int max     = int32_1;
                         int int32_2 = Convert.ToInt32(strArray[1]);
                         int result  = 0;
                         if (int.TryParse(s, out result))
                         {
                             this.overrides.Add(new PaletteTableEntry(int32_1, max, int32_2));
                         }
                         else
                         {
                             this.entries.Add(new PaletteTableEntry(int32_1, max, int32_2));
                         }
                     }
                 }
                 streamReader.Close();
             }
         }
     }
     return(this.entries.Count);
 }
示例#7
0
        public static SPFImage FromArchive(string file, DATArchive archive)
        {
            if (!archive.Contains(file))
            {
                return(null);
            }

            var stream = new MemoryStream(archive.ExtractFile(file));
            var reader = new BinaryReader(stream);

            var spf = new SPFImage();

            int unknown1 = reader.ReadInt32();
            int unknown2 = reader.ReadInt32();

            spf.colorFormat = reader.ReadInt32();

            if (spf.colorFormat == 0)
            {
                var    palette = new Palette256();
                byte[] alpha   = reader.ReadBytes(512);
                byte[] color   = reader.ReadBytes(512);
                for (int i = 0; i < 256; ++i)
                {
                    ushort val = BitConverter.ToUInt16(color, i * 2);
                    int    b   = 8 * ((int)val % 32);
                    int    g   = 8 * ((int)val / 32 % 32);
                    int    r   = 8 * ((int)val / 32 / 32 % 32);
                    palette[i] = Color.FromArgb(r, g, b);
                }
                spf.palette = palette;
            }

            spf.expectedFrames = reader.ReadInt32();
            spf.frames         = new SPFFrame[spf.expectedFrames];

            for (int i = 0; i < spf.expectedFrames; ++i)
            {
                int left         = reader.ReadInt16();
                int top          = reader.ReadInt16();
                int width        = reader.ReadInt16();
                int height       = reader.ReadInt16();
                int unknown3     = reader.ReadInt32();
                int unknown4     = reader.ReadInt32();
                int startAddress = reader.ReadInt32();
                int byteWidth    = reader.ReadInt32();
                int length       = reader.ReadInt32();
                int semiLength   = reader.ReadInt32();

                spf.frames[i] = new SPFFrame(left, top, width, height, startAddress, byteWidth, length, semiLength);
            }

            spf.length = reader.ReadInt32();

            for (int i = 0; i < spf.expectedFrames; ++i)
            {
                int    length = spf.frames[i].Length;
                byte[] data   = reader.ReadBytes(length);
                spf.frames[i].SetData(data);
            }

            reader.Close();

            return(spf);
        }
示例#8
0
        /// <summary>
        /// Loads the default tables from the specified archive.
        /// </summary>
        /// <param name="pattern">Pattern to check for (prefix string).</param>
        /// <param name="archive">Data archive.</param>
        /// <returns>Number of table entries loaded.</returns>
        public int LoadTables(string pattern, DATArchive archive)
        {
            entries.Clear();
            foreach (DATFileEntry file in archive.Files)
            {
                // Check for Palette
                if (file.Name.ToUpper().EndsWith(".TBL") && file.Name.ToUpper().StartsWith(pattern.ToUpper()))
                {
                    // Get Index
                    string tableName =
                        Path.GetFileNameWithoutExtension(file.Name).Remove(0, pattern.Length);

                    if (tableName != "ani")
                    {
                        // Get Stream and Reader for Data
                        MemoryStream stream = new MemoryStream(archive.ExtractFile(file));
                        StreamReader reader = new StreamReader(stream);

                        #region Read Lines and Parse Values
                        while (!reader.EndOfStream)
                        {
                            string   line      = reader.ReadLine();
                            string[] lineSplit = line.Split(' ');

                            if (lineSplit.Length == 3)
                            {
                                int min = Convert.ToInt32(lineSplit[0]);
                                int max = Convert.ToInt32(lineSplit[1]);
                                int pal = Convert.ToInt32(lineSplit[2]);

                                int index = 0;
                                if (int.TryParse(tableName, out index))
                                {
                                    overrides.Add(new PaletteTableEntry(min, max, pal));
                                }
                                else
                                {
                                    entries.Add(new PaletteTableEntry(min, max, pal));
                                }
                            }
                            else if (lineSplit.Length == 2)
                            {
                                int min = Convert.ToInt32(lineSplit[0]);
                                int max = min;
                                int pal = Convert.ToInt32(lineSplit[1]);

                                int index = 0;
                                if (int.TryParse(tableName, out index))
                                {
                                    overrides.Add(new PaletteTableEntry(min, max, pal));
                                }
                                else
                                {
                                    entries.Add(new PaletteTableEntry(min, max, pal));
                                }
                            }
                        }
                        reader.Close();
                        #endregion
                    }
                }
            }

            return(entries.Count);
        }