Exemple #1
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");
            }
        }
Exemple #2
0
        /// <summary>
        /// Loads TileData object from file.
        /// </summary>
        /// <param name="file">Path to "tiledata.mul" file.</param>
        public static TileData Load(string file)
        {
            Stream stream = null;
            BinaryReader reader = null;

            try
            {
                stream = File.OpenRead(file);
                reader = new BinaryReader(stream);

                if (stream.Length < TileData.DefaultFileLenght)
                {
                    throw new Exception("Invalid TileData file size. Expected: " + TileData.DefaultFileLenght.ToString());
                }

                TileData tileData = new TileData();

                for (int i = 0; i < MaxIndex; i++)
                {
                    if (i % 32 == 0) stream.Seek(4, SeekOrigin.Current);
                    tileData.lands[i] = TileData.ReadLand(reader);
                }

                for (int i = 0; i < MaxIndex; i++)
                {
                    if (i % 32 == 0) stream.Seek(4, SeekOrigin.Current);
                    tileData.arts[i] = TileData.ReadArt(reader);
                }

                Trace.WriteLine(String.Format("TileData: File \"{0}\" succesfully loaded.", file), "MulLib");
                return tileData;
            }
            catch (Exception e)
            {
                throw new Exception("Error loading TileData.", e);
            }
            finally
            {
                if (reader != null)
                    reader.Close();

                if (stream != null)
                    stream.Close();
            }
        }