Example #1
0
        /// <summary>
        /// Loads Art data from files.
        /// </summary>
        /// <param name="idxFile">Path to index file.</param>
        /// <param name="mulFile">Path to data file.</param>
        /// <param name="access">Access mode to data file.</param>
        /// <returns>New object encapsulating loaded data.</returns>
        public static Art Load(string idxFile, string mulFile, MulFileAccessMode access)
        {
            Stream dataStream = null;

            try {
                switch (access)
                {
                case MulFileAccessMode.RequestWrite:
                    dataStream = File.Open(mulFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
                    break;

                case MulFileAccessMode.TryWrite:
                    try {
                        dataStream = File.Open(mulFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
                    }
                    catch {
                        goto case MulFileAccessMode.ReadOnly;
                    }
                    break;

                case MulFileAccessMode.ReadOnly:
                    dataStream = File.Open(mulFile, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);
                    break;
                }

                IndexFile indexFile = IndexFile.Load(idxFile);

                Art art = new Art(Path.GetFullPath(mulFile), indexFile, dataStream);

                Trace.WriteLine(String.Format("Art: File \"{0}\" succesfully loaded.", mulFile), "MulLib");
                return(art);
            }
            catch (Exception e) {
                if (dataStream != null)
                {
                    dataStream.Close();
                }

                throw new Exception("Error loading Art.", e);
            }
        }
Example #2
0
        /// <summary>
        /// Static function that writes Art data to specified file at current location.
        /// </summary>
        /// <param name="writer">Stream to write to.</param>
        /// <param name="art">Object to write.</param>
        public static void WriteArt(BinaryWriter writer, Art art)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            writer.Write((uint)art.Flags);
            writer.Write(art.Weight);
            writer.Write(art.Layer);
            writer.Write(art.Unknown1);
            writer.Write(art.Unknown2);
            writer.Write(art.Quantity);
            writer.Write(art.Animation);
            writer.Write(art.Unknown3);
            writer.Write(art.Hue);
            writer.Write(art.Unknown4);
            writer.Write(art.Value);
            writer.Write(art.Height);
            writer.Write(art.NameBytes, 0, 20);
        }
Example #3
0
 public ItemsData(Art art)
     : base(art)
 {
 }
Example #4
0
 protected DataBase(Art art)
 {
     this.art = art;
 }
Example #5
0
 public AnimationsData(Art art)
     : base(art)
 {
 }
Example #6
0
        /// <summary>
        /// Loads Art data from files.
        /// </summary>
        /// <param name="idxFile">Path to index file.</param>
        /// <param name="mulFile">Path to data file.</param>
        /// <param name="access">Access mode to data file.</param>
        /// <returns>New object encapsulating loaded data.</returns>
        public static Art Load(string idxFile, string mulFile, MulFileAccessMode access)
        {
            Stream dataStream = null;

            try {
                switch (access) {
                    case MulFileAccessMode.RequestWrite:
                        dataStream = File.Open(mulFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
                        break;

                    case MulFileAccessMode.TryWrite:
                        try {
                            dataStream = File.Open(mulFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
                        }
                        catch {
                            goto case MulFileAccessMode.ReadOnly;
                        }
                        break;

                    case MulFileAccessMode.ReadOnly:
                        dataStream = File.Open(mulFile, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);
                        break;
                }

                IndexFile indexFile = IndexFile.Load(idxFile);

                Art art = new Art(Path.GetFullPath(mulFile), indexFile, dataStream);

                Trace.WriteLine(String.Format("Art: File \"{0}\" succesfully loaded.", mulFile), "MulLib");
                return art;
            }
            catch (Exception e) {
                if (dataStream != null)
                    dataStream.Close();

                throw new Exception("Error loading Art.", e);
            }
        }
Example #7
0
        /// <summary>
        /// Writes an Art with specified index.
        /// </summary>
        /// <param name="index">Index between 0 and MaxIndex.</param>
        /// <param name="art">Data to write</param>
        /// <exception cref="System.ObjectDisposedException">Object has been disposed.</exception>
        public void SetArt(int index, Art art)
        {
            lock (syncRoot)
            {
                if (Disposed)
                    throw new ObjectDisposedException("TileData");

                arts[index] = art;
            }
        }
Example #8
0
        /// <summary>
        /// Static function that writes Art data to specified file at current location.
        /// </summary>
        /// <param name="writer">Stream to write to.</param>
        /// <param name="art">Object to write.</param>
        public static void WriteArt(BinaryWriter writer, Art art)
        {
            if (writer == null) throw new ArgumentNullException("writer");

            writer.Write((uint)art.Flags);
            writer.Write(art.Weight);
            writer.Write(art.Layer);
            writer.Write(art.Unknown1);
            writer.Write(art.Unknown2);
            writer.Write(art.Quantity);
            writer.Write(art.Animation);
            writer.Write(art.Unknown3);
            writer.Write(art.Hue);
            writer.Write(art.Unknown4);
            writer.Write(art.Value);
            writer.Write(art.Height);
            writer.Write(art.NameBytes, 0, 20);
        }
Example #9
0
 public ItemsData(Art art)
     : base(art)
 {
 }
Example #10
0
 protected DataBase(Art art)
 {
     this.art = art;
 }
Example #11
0
        /// <summary>
        /// Saves object to specified files.
        /// </summary>
        /// <param name="idxFile">Index file path.</param>
        /// <param name="mulFile">Data file path.</param>
        /// <remarks>
        /// If mulFile differs from currently loaded file, new file is optimized (data file is sorted and without empty entries).
        /// Otherwise file must be loaded with write access.
        /// </remarks>
        public void Save(string idxFile, string mulFile)
        {
            lock (syncRoot) {
                if (Disposed)
                {
                    throw new ObjectDisposedException("Art");
                }

                Stream indexStream = null;

                try {
                    indexStream = File.Open(idxFile, FileMode.Create, FileAccess.Write, FileShare.None);

                    if (String.Compare(mulFile, this.mulFile, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        // Target data file is same as source file. File will not be optimized.
                        Stream dataStream = this.dataStream;

                        if (!dataStream.CanWrite)
                        {
                            throw new InvalidOperationException("Trying to save data to source file, that is not opened for Write access.");
                        }

                        foreach (KeyValuePair <int, Bitmap> pair in changeList)
                        {
                            if (pair.Key < 16384)
                            {
                                // Tile, can be saved to same location in data stream
                                IndexData indexData = indexFile.Get(pair.Key, true);
                                if (indexData.IsValid)
                                {
                                    dataStream.Seek(indexData.Lookup, SeekOrigin.Begin);
                                    IndexData writtenData = Art.WriteTile(dataStream, pair.Value);

                                    Debug.Assert(writtenData.Lookup == indexData.Lookup, "writtenData.Lookup == indexData.Lookup");
                                    Debug.Assert(writtenData.Lenght == indexData.Lenght, "writtenData.Lenght == indexData.Lenght");
                                }
                                else
                                {
                                    dataStream.Seek(0, SeekOrigin.End);
                                    IndexData writtenData = Art.WriteTile(dataStream, pair.Value);
                                    indexFile.Set(pair.Key, writtenData, true);
                                }
                            }
                            else
                            {
                                // Run, will be saved to end of data stream
                                dataStream.Seek(0, SeekOrigin.End);
                                IndexData writtenData = Art.WriteRun(dataStream, pair.Value);
                                indexFile.Set(pair.Key, writtenData, true);
                            }
                        }

                        dataStream.Flush();
                        Trace.WriteLine(String.Format("Art: File \"{0}\" succesfully updated.", mulFile), "MulLib");

                        indexFile.Save(indexStream);
                        Trace.WriteLine(String.Format("IndexFile: File \"{0}\" succesfully saved.", idxFile), "MulLib");

                        changeList.Clear();
                    }
                    else
                    {
                        // Target data file differs from source file. Optimization will be performed.
                        try {
                            Stream    dataStream   = File.Open(mulFile, FileMode.Create, FileAccess.Write, FileShare.None);
                            IndexFile newIndexFile = new IndexFile();

                            for (int i = 0; i < indexFile.Count; i++)
                            {
                                if (changeList.ContainsKey(i))
                                {
                                    IndexData writtenData;

                                    if (i < 16384)
                                    {
                                        writtenData = Art.WriteTile(dataStream, changeList[i]);
                                    }
                                    else
                                    {
                                        writtenData = Art.WriteRun(dataStream, changeList[i]);
                                    }

                                    newIndexFile.Set(i, writtenData, true);
                                }
                                else
                                {
                                    IndexData indexData = indexFile.Get(i, false);
                                    if (indexData.IsValid)
                                    {
                                        byte[] data = new byte[indexData.Lenght];

                                        this.dataStream.Seek(indexData.Lookup, SeekOrigin.Begin);
                                        this.dataStream.Read(data, 0, (int)indexData.Lenght);

                                        IndexData writtenData = new IndexData();
                                        writtenData.Lookup = (uint)dataStream.Position;
                                        writtenData.Lenght = indexData.Lenght;
                                        writtenData.Extra  = indexData.Extra;

                                        dataStream.Write(data, 0, (int)writtenData.Lenght);
                                    }
                                }
                            }

                            dataStream.Flush();
                            Trace.WriteLine(String.Format("Art: File \"{0}\" succesfully saved.", mulFile), "MulLib");

                            newIndexFile.Save(indexStream);
                            Trace.WriteLine(String.Format("IndexFile: File \"{0}\" succesfully saved.", idxFile), "MulLib");
                        }
                        finally {
                            if (dataStream != null)
                            {
                                dataStream.Close();
                            }
                        }
                    }
                }
                catch (Exception e) {
                    throw new Exception("Error saving Art.", e);
                }
                finally {
                    if (indexStream != null)
                    {
                        indexStream.Close();
                    }
                }
            }
        }
Example #12
0
 public AnimationsData(Art art)
     : base(art)
 {
 }
Example #13
0
 protected override Bitmap ReadFromStream(IndexData indexData)
 {
     art.dataStream.Seek(indexData.Lookup, SeekOrigin.Begin);
     return(Art.ReadRun(art.dataStream));
 }
Example #14
0
 public LandscapeData(Art art)
     : base(art)
 {
 }
Example #15
0
        /// <summary>
        /// Static function that reads Art data from specified file at current location.
        /// </summary>
        /// <param name="reader">Stream to read from.</param>
        /// <returns>Read data.</returns>
        public static Art ReadArt(BinaryReader reader)
        {
            if (reader == null) throw new ArgumentNullException("reader");

            Art art = new Art();

            art.Flags = (Flags)reader.ReadUInt32();
            art.Weight = reader.ReadByte();
            art.Layer = reader.ReadByte();
            art.Unknown1 = reader.ReadUInt16();
            art.Unknown2 = reader.ReadByte();
            art.Quantity = reader.ReadByte();
            art.Animation = reader.ReadUInt16();
            art.Unknown3 = reader.ReadByte();
            art.Hue = reader.ReadByte();
            art.Unknown4 = reader.ReadByte();
            art.Value = reader.ReadByte();
            art.Height = reader.ReadByte();
            art.NameBytes = reader.ReadBytes(20);

            return art;
        }
Example #16
0
        /// <summary>
        /// Called by Phoenix.Initialize().
        /// </summary>
        /// <param name="param">Client directory.</param>
        internal static void Load(object param)
        {
            string dir = param.ToString();

            try {
                Trace.WriteLine("Loading ultima data files started..", "MulLib");

                tiledata = TileData.Load(Path.Combine(dir, "tiledata.mul"));
                hues = Hues.Load(Path.Combine(dir, "hues.mul"));
                radarCol = RadarCol.Load(Path.Combine(dir, "radarcol.mul"));
                skills = Skills.Load(Path.Combine(dir, "skills.idx"), Path.Combine(dir, "skills.mul"));
                art = Art.Load(Path.Combine(dir, "artidx.mul"), Path.Combine(dir, "art.mul"), MulFileAccessMode.ReadOnly);
                multi = Multi.Load(Path.Combine(dir, "multi.idx"), Path.Combine(dir, "multi.mul"), MulFileAccessMode.ReadOnly);

                Trace.WriteLine("Loading ultima data files finished.", "MulLib");
            }
            catch (Exception e) {
                string msg = String.Format("Unable to load ultima data files. Program will be terminated. Exception:\r\n{0}", e);
                Trace.WriteLine(msg, "MulLib");
                MessageBox.Show(msg, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Core.Terminate();
            }

            try {
                SyncEvent.Invoke(Loaded, null, EventArgs.Empty);
            }
            catch (Exception e) {
                Trace.WriteLine("Unhandled exception in DataFiles.Loaded event. Exception:\r\n" + e.ToString(), "MulLib");
            }
        }
Example #17
0
 public LandscapeData(Art art)
     : base(art)
 {
 }