Exemplo n.º 1
0
        void LoadFonts()
        {
            // load Ascii fonts
            using (var r = new BinaryReader(new FileStream(UltimaFileManager.GetFilePath("fonts.mul"), FileMode.Open, FileAccess.Read)))
                for (var i = 0; i < AsciiFontCount; i++)
                {
                    _asciiFonts[i] = new FontAscii();
                    _asciiFonts[i].Initialize(r);
                    _asciiFonts[i].HasBuiltInOutline = true;
                }
            // load Unicode fonts
            var maxHeight = 0; // because all unifonts are designed to be used together, they must all share a single maxheight value.

            for (var i = 0; i < UniFontCount; i++)
            {
                var path = UltimaFileManager.GetFilePath($"unifont{(i == 0 ? string.Empty : i.ToString())}.mul");
                if (path != null)
                {
                    _unicodeFonts[i] = new FontUnicode();
                    _unicodeFonts[i].Initialize(new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read)));
                    if (_unicodeFonts[i].Height > maxHeight)
                    {
                        maxHeight = _unicodeFonts[i].Height;
                    }
                }
            }
            for (var i = 0; i < UniFontCount; i++)
            {
                if (_unicodeFonts[i] == null)
                {
                    continue;
                }
                _unicodeFonts[i].Height = maxHeight;
            }
        }
Exemplo n.º 2
0
        static void SetupFiles()
        {
            try
            {
                _index = ClientVersion.InstallationIsUopFormat ?
                         UltimaFileManager.CreateFileIndex("soundLegacyMUL.uop", 0xFFF, false, ".dat") :
                         UltimaFileManager.CreateFileIndex("soundidx.mul", "sound.mul", 0x1000, -1); // new BinaryReader(new FileStream(FileManager.GetFilePath("soundidx.mul"), FileMode.Open));
                _filesPrepared = true;
            }
            catch
            {
                _filesPrepared = false;
                return;
            }
            var reg = new Regex(@"(\d{1,3}) \x7B(\d{1,3})\x7D (\d{1,3})", RegexOptions.Compiled);

            _translations = new Dictionary <int, int>();
            string line;

            using (var r = new StreamReader(UltimaFileManager.GetFilePath("Sound.def")))
                while ((line = r.ReadLine()) != null)
                {
                    if (((line = line.Trim()).Length != 0) && !line.StartsWith("#"))
                    {
                        var match = reg.Match(line);
                        if (match.Success)
                        {
                            _translations.Add(int.Parse(match.Groups[1].Value), int.Parse(match.Groups[2].Value));
                        }
                    }
                }
        }
Exemplo n.º 3
0
        void LoadCliloc(string path)
        {
            path = UltimaFileManager.GetFilePath(path);
            if (path == null)
            {
                return;
            }
            byte[] buffer;
            using (var r = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                buffer = r.ReadBytes((int)r.BaseStream.Length);
                Metrics.ReportDataRead((int)r.BaseStream.Position);
            }
            var pos   = 6;
            var count = buffer.Length;

            while (pos < count)
            {
                var number = BitConverter.ToInt32(buffer, pos);
                var length = BitConverter.ToInt16(buffer, pos + 5);
                var text   = Encoding.UTF8.GetString(buffer, pos + 7, length);
                pos           += length + 7;
                _table[number] = text; // auto replace with updates.
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a reference to an index file. (Ex: anim.idx)
 /// </summary>
 /// <param name="idxFile">Name of .idx file in UO base directory.</param>
 /// <param name="mulFile">Name of .mul file that this index file provides an index for.</param>
 /// <param name="length">Number of indexes in this index file.</param>
 /// <param name="patch_file">Index to patch data in Versioning.</param>
 public MulFileIndex(string idxFile, string mulFile, int length, int patch_file) : base(mulFile)
 {
     IndexPath = UltimaFileManager.GetFilePath(idxFile);
     Length    = length;
     patchFile = patch_file;
     Open();
 }
Exemplo n.º 5
0
        bool LoadStaticsStream(uint index, out FileStream dataStream, out BinaryReader indexReader)
        {
            dataStream  = null;
            indexReader = null;
            var pathData  = UltimaFileManager.GetFilePath($"statics{index}.mul");
            var pathIndex = UltimaFileManager.GetFilePath($"staidx{index}.mul");

            if (File.Exists(pathData) && File.Exists(pathIndex))
            {
                dataStream  = new FileStream(pathData, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                indexReader = new BinaryReader(new FileStream(pathIndex, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
        static unsafe SkillCategory[] LoadCategories()
        {
            var list    = new SkillCategory[0];
            var grpPath = UltimaFileManager.GetFilePath("skillgrp.mul");

            if (grpPath == null)
            {
                return(new SkillCategory[0]);
            }
            else
            {
                var toAdd = new List <SkillCategory>();
                using (var stream = new FileStream(grpPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var r     = new BinaryReader(stream);
                    var start = new byte[4]; //File Start Offset
                    r.Read(start, 0, 4);
                    var  index = 0;
                    long x = stream.Length, y = 0;
                    while (y < x) //Position < Length
                    {
                        var name      = ParseName(stream);
                        var fileIndex = stream.Position - name.Length;
                        if (name.Length > 0)
                        {
                            toAdd.Add(new SkillCategory(new SkillCategoryData(fileIndex, index, name)));
                            y = stream.Position;
                            ++index;
                        }
                    }
                }
                if (toAdd.Count > 0)
                {
                    list = new SkillCategory[toAdd.Count];
                    for (var i = 0; i < toAdd.Count; i++)
                    {
                        list[i] = toAdd[i];
                    }
                    toAdd.Clear();
                }
            }
            return(list);
        }
Exemplo n.º 7
0
        bool LoadMapStream(uint index, out FileStream mapDataStream, out UOPIndex uopIndex)
        {
            mapDataStream = null;
            uopIndex      = null;
            var path = UltimaFileManager.GetFilePath($"map{index}.mul");

            if (File.Exists(path))
            {
                mapDataStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                return(true);
            }
            path = UltimaFileManager.GetFilePath($"map{index}LegacyMUL.uop");
            if (File.Exists(path))
            {
                mapDataStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                uopIndex      = new UOPIndex(_mapDataStream);
                return(true);
            }
            return(false);
        }
Exemplo n.º 8
0
        static BodyDef()
        {
            _entries = new Dictionary <int, BodyTableEntry>();
            var filePath = UltimaFileManager.GetFilePath("body.def");

            if (filePath == null)
            {
                return;
            }
            var    def = new StreamReader(filePath);
            string line;
            var    totalDataRead = 0;

            while ((line = def.ReadLine()) != null)
            {
                totalDataRead += line.Length;
                if ((line = line.Trim()).Length == 0 || line.StartsWith("#"))
                {
                    continue;
                }
                try
                {
                    var index1   = line.IndexOf("{");
                    var index2   = line.IndexOf("}");
                    var origBody = line.Substring(0, index1);
                    var newBody  = line.Substring(index1 + 1, index2 - index1 - 1);
                    var newHue   = line.Substring(index2 + 1);
                    var indexOf  = newBody.IndexOf(',');
                    if (indexOf > -1)
                    {
                        newBody = newBody.Substring(0, indexOf).Trim();
                    }
                    var iParam1 = Convert.ToInt32(origBody);
                    var iParam2 = Convert.ToInt32(newBody);
                    var iParam3 = Convert.ToInt32(newHue);
                    _entries[iParam1] = new BodyTableEntry(iParam1, iParam2, iParam3);
                }
                catch { }
            }
            Metrics.ReportDataRead(totalDataRead);
        }
Exemplo n.º 9
0
        static List <Dictionary <int, SpeechEntry> > LoadSpeechFile()
        {
            var tables    = new List <Dictionary <int, SpeechEntry> >();
            var lastIndex = -1;
            Dictionary <int, SpeechEntry> table = null;
            var path = UltimaFileManager.GetFilePath("speech.mul");

            using (var r = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                while (r.PeekChar() >= 0)
                {
                    var index  = (r.ReadByte() << 8) | r.ReadByte();
                    var length = (r.ReadByte() << 8) | r.ReadByte();
                    var text   = Encoding.UTF8.GetString(r.ReadBytes(length)).Trim();
                    if (text.Length == 0)
                    {
                        continue;
                    }
                    if (table == null || lastIndex > index)
                    {
                        if (index == 0 && text == "*withdraw*")
                        {
                            tables.Insert(0, table = new Dictionary <int, SpeechEntry>());
                        }
                        else
                        {
                            tables.Add(table = new Dictionary <int, SpeechEntry>());
                        }
                    }
                    lastIndex = index;
                    table.TryGetValue(index, out SpeechEntry entry);
                    if (entry == null)
                    {
                        table[index] = entry = new SpeechEntry(index);
                    }
                    entry.Strings.Add(text);
                    entry.Regex.Add(new Regex(text.Replace("*", @".*"), RegexOptions.IgnoreCase));
                }
                return(tables);
            }
        }
Exemplo n.º 10
0
 static MobtypeData()
 {
     var path = UltimaFileManager.GetFilePath("mobtypes.txt");
     {
         var r = new StreamReader(path);
         while (!r.EndOfStream)
         {
             var line = r.ReadLine();
             Metrics.ReportDataRead(line.Length);
             if ((line != string.Empty) && (line.Substring(0, 1) != "#"))
             {
                 var data   = line.Split('\t');
                 var bodyId = int.Parse(data[0]);
                 if (_entries.ContainsKey(bodyId))
                 {
                     _entries.Remove(bodyId);
                 }
                 _entries.Add(bodyId, new MobtypeEntry(data[1], data[2]));
             }
         }
     }
 }
Exemplo n.º 11
0
 static RadarColorData()
 {
     using (var index = new FileStream(UltimaFileManager.GetFilePath("Radarcol.mul"), FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         var r = new BinaryReader(index);
         // Prior to 7.0.7.1, all clients have 0x10000 colors. Newer clients have fewer colors.
         var colorCount = (int)index.Length / 2;
         for (var i = 0; i < colorCount; i++)
         {
             var c = (uint)r.ReadUInt16();
             Colors[i] = 0xFF000000 | (
                 ((((c >> 10) & 0x1F) * multiplier)) |
                 ((((c >> 5) & 0x1F) * multiplier) << 8) |
                 (((c & 0x1F) * multiplier) << 16)
                 );
         }
         // fill the remainder of the color table with non-transparent magenta.
         for (var i = colorCount; i < Colors.Length; i++)
         {
             Colors[i] = 0xFFFF00FF;
         }
         Metrics.ReportDataRead((int)r.BaseStream.Position);
     }
 }
Exemplo n.º 12
0
        static VerData()
        {
            var path = UltimaFileManager.GetFilePath("verdata.mul");

            if (!File.Exists(path))
            {
                Patches = new FileIndexEntry5D[0];
                Stream  = Stream.Null;
            }
            else
            {
                Stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                var bin = new BinaryReader(Stream);
                Patches = new FileIndexEntry5D[bin.ReadInt32()];
                for (var i = 0; i < Patches.Length; ++i)
                {
                    Patches[i].file   = bin.ReadInt32();
                    Patches[i].index  = bin.ReadInt32();
                    Patches[i].lookup = bin.ReadInt32();
                    Patches[i].length = bin.ReadInt32();
                    Patches[i].extra  = bin.ReadInt32();
                }
            }
        }
Exemplo n.º 13
0
        static BodyConverter()
        {
            var path = UltimaFileManager.GetFilePath("bodyconv.def");

            if (path == null)
            {
                return;
            }
            ArrayList list1 = new ArrayList(), list2 = new ArrayList(), list3 = new ArrayList(), list4 = new ArrayList();
            int       max1 = 0, max2 = 0, max3 = 0, max4 = 0;

            using (var ip = new StreamReader(path))
            {
                string line;
                var    totalDataRead = 0;
                while ((line = ip.ReadLine()) != null)
                {
                    totalDataRead += line.Length;
                    if ((line = line.Trim()).Length == 0 || line.StartsWith("#") || line.StartsWith("\"#"))
                    {
                        continue;
                    }
                    // string[] split = line.Split('\t');
                    var split    = Regex.Split(line, @"\t|\s+", RegexOptions.IgnoreCase);
                    var original = System.Convert.ToInt32(split[0]);
                    var anim2    = System.Convert.ToInt32(split[1]);
                    if (split.Length < 3 || !int.TryParse(split[2], out int anim3))
                    {
                        anim3 = -1;
                    }
                    if (split.Length < 4 || !int.TryParse(split[3], out int anim4))
                    {
                        anim4 = -1;
                    }
                    if (split.Length < 5 || !int.TryParse(split[4], out int anim5))
                    {
                        anim5 = -1;
                    }
                    if (anim2 != -1)
                    {
                        if (anim2 == 68)
                        {
                            anim2 = 122;
                        }
                        if (original > max1)
                        {
                            max1 = original;
                        }
                        list1.Add(original);
                        list1.Add(anim2);
                    }
                    if (anim3 != -1)
                    {
                        if (original > max2)
                        {
                            max2 = original;
                        }
                        list2.Add(original);
                        list2.Add(anim3);
                    }
                    if (anim4 != -1)
                    {
                        if (original > max3)
                        {
                            max3 = original;
                        }
                        list3.Add(original);
                        list3.Add(anim4);
                    }
                    if (anim5 != -1)
                    {
                        if (original > max4)
                        {
                            max4 = original;
                        }
                        list4.Add(original);
                        list4.Add(anim5);
                    }
                }
                Metrics.ReportDataRead(totalDataRead);
            }
            _table1 = new int[max1 + 1];
            _table2 = new int[max2 + 1];
            _table3 = new int[max3 + 1];
            _table4 = new int[max4 + 1];
            for (var i = 0; i < _table1.Length; ++i)
            {
                _table1[i] = -1;
            }
            for (var i = 0; i < list1.Count; i += 2)
            {
                _table1[(int)list1[i]] = (int)list1[i + 1];
            }
            for (var i = 0; i < _table2.Length; ++i)
            {
                _table2[i] = -1;
            }
            for (var i = 0; i < list2.Count; i += 2)
            {
                _table2[(int)list2[i]] = (int)list2[i + 1];
            }
            for (var i = 0; i < _table3.Length; ++i)
            {
                _table3[i] = -1;
            }
            for (var i = 0; i < list3.Count; i += 2)
            {
                _table3[(int)list3[i]] = (int)list3[i + 1];
            }
            for (var i = 0; i < _table4.Length; ++i)
            {
                _table4[i] = -1;
            }
            for (var i = 0; i < list4.Count; i += 2)
            {
                _table4[(int)list4[i]] = (int)list4[i + 1];
            }
        }