Beispiel #1
0
        static Versioning()
        {
            string path = FileManager.GetFilePath("verdata.mul");

            if (!File.Exists(path))
            {
                m_Patches = new Entry5D[0];
                m_Stream  = Stream.Null;
            }
            else
            {
                m_Stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                BinaryReader bin = new BinaryReader(m_Stream);

                m_Patches = new Entry5D[bin.ReadInt32()];

                for (int i = 0; i < m_Patches.Length; ++i)
                {
                    m_Patches[i].file   = bin.ReadInt32();
                    m_Patches[i].index  = bin.ReadInt32();
                    m_Patches[i].lookup = bin.ReadInt32();
                    m_Patches[i].length = bin.ReadInt32();
                    m_Patches[i].extra  = bin.ReadInt32();
                }
            }
        }
Beispiel #2
0
        static BodyTable()
        {
            m_Entries = new Hashtable();

            string filePath = FileManager.GetFilePath("body.def");

            if (filePath == null)
            {
                return;
            }

            StreamReader def = new StreamReader(filePath);

            string line;
            int    totalDataRead = 0;

            while ((line = def.ReadLine()) != null)
            {
                totalDataRead += line.Length;

                if ((line = line.Trim()).Length == 0 || line.StartsWith("#"))
                {
                    continue;
                }

                try
                {
                    int index1 = line.IndexOf(" {");
                    int index2 = line.IndexOf("} ");

                    string param1 = line.Substring(0, index1);
                    string param2 = line.Substring(index1 + 2, index2 - index1 - 2);
                    string param3 = line.Substring(index2 + 2);

                    int indexOf = param2.IndexOf(',');

                    if (indexOf > -1)
                    {
                        param2 = param2.Substring(0, indexOf).Trim();
                    }

                    int iParam1 = Convert.ToInt32(param1);
                    int iParam2 = Convert.ToInt32(param2);
                    int iParam3 = Convert.ToInt32(param3);

                    m_Entries[iParam1] = new BodyTableEntry(iParam2, iParam1, iParam3);
                }
                catch
                {
                }
            }
            Metrics.ReportDataRead(totalDataRead);
        }
Beispiel #3
0
        static List <Dictionary <int, SpeechEntry> > LoadSpeechFile()
        {
            List <Dictionary <int, SpeechEntry> > tables = new List <Dictionary <int, SpeechEntry> >();
            int lastIndex = -1;

            Dictionary <int, SpeechEntry> table = null;

            string path = FileManager.GetFilePath("speech.mul");

            using (BinaryReader bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                while (bin.PeekChar() >= 0)
                {
                    int    index  = (bin.ReadByte() << 8) | bin.ReadByte();
                    int    length = (bin.ReadByte() << 8) | bin.ReadByte();
                    string text   = Encoding.UTF8.GetString(bin.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;

                    SpeechEntry entry = null;
                    table.TryGetValue(index, out 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);
            }
        }
Beispiel #4
0
 static RadarColorData()
 {
     using (FileStream index = new FileStream(FileManager.GetFilePath("Radarcol.mul"), FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         BinaryReader bin = new BinaryReader(index);
         for (int i = 0; i < Colors.Length; i++)
         {
             uint c = bin.ReadUInt16();
             Colors[i] = 0xFF000000 | (
                 ((((c >> 10) & 0x1F) * multiplier)) |
                 ((((c >> 5) & 0x1F) * multiplier) << 8) |
                 (((c & 0x1F) * multiplier) << 16)
                 );
         }
         Metrics.ReportDataRead((int)bin.BaseStream.Position);
     }
 }
Beispiel #5
0
 static Mobtypes()
 {
     string path = FileManager.GetFilePath("mobtypes.txt");
     {
         StreamReader stream = new StreamReader(path);
         while (!stream.EndOfStream)
         {
             string line = stream.ReadLine();
             Metrics.ReportDataRead(line.Length);
             if ((line != string.Empty) && (line.Substring(0, 1) != "#"))
             {
                 string[] data   = line.Split('\t');
                 int      bodyID = Int32.Parse(data[0]);
                 if (m_entries.ContainsKey(bodyID))
                 {
                     m_entries.Remove(bodyID);
                 }
                 m_entries.Add(bodyID, new MobtypeEntry(data[1], data[2]));
             }
         }
     }
 }
Beispiel #6
0
        public static void LoadStringList(string language)
        {
            m_Language = language;
            m_Table    = new Hashtable();

            string path = FileManager.GetFilePath(String.Format("cliloc.{0}", language));

            if (path == null)
            {
                m_Entries = new StringEntry[0];
                return;
            }

            ArrayList list = new ArrayList();

            byte[] buffer;

            using (BinaryReader bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                buffer = bin.ReadBytes((int)bin.BaseStream.Length);
                Metrics.ReportDataRead((int)bin.BaseStream.Position);
            }

            int pos   = 6;
            int count = buffer.Length;

            while (pos < count)
            {
                int    number = BitConverter.ToInt32(buffer, pos);
                int    length = BitConverter.ToInt16(buffer, pos + 5);
                string text   = Encoding.UTF8.GetString(buffer, pos + 7, length);
                pos += length + 7;
                list.Add(new StringEntry(number, text));
                m_Table[number] = text;
            }

            m_Entries = (StringEntry[])list.ToArray(typeof(StringEntry));
        }
Beispiel #7
0
        private static void setupFiles()
        {
            try
            {
                m_Index         = new BinaryReader(new FileStream(FileManager.GetFilePath("soundidx.mul"), FileMode.Open));
                m_Stream        = new FileStream(FileManager.GetFilePath("sound.mul"), FileMode.Open);
                m_filesPrepared = true;
            }
            catch
            {
                m_filesPrepared = false;
                return;
            }

            Regex reg = new Regex(@"(\d{1,3}) \x7B(\d{1,3})\x7D (\d{1,3})", RegexOptions.Compiled);

            m_Translations = new Dictionary <int, int>();

            string line;

            using (StreamReader reader = new StreamReader(FileManager.GetFilePath("Sound.def")))
            {
                while ((line = reader.ReadLine()) != null)
                {
                    if (((line = line.Trim()).Length != 0) && !line.StartsWith("#"))
                    {
                        Match match = reg.Match(line);

                        if (match.Success)
                        {
                            m_Translations.Add(int.Parse(match.Groups[1].Value), int.Parse(match.Groups[2].Value));
                        }
                    }
                }
            }

            m_Sounds = new Dictionary <int, UOSound>();
        }
Beispiel #8
0
        static HueData()
        {
            string path  = FileManager.GetFilePath("hues.mul");
            int    index = 0;

            m_List = new Hue[3000];

            if (path != null)
            {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader bin = new BinaryReader(fs);

                    int blockCount = (int)fs.Length / 708;

                    if (blockCount > 375)
                    {
                        blockCount = 375;
                    }

                    for (int i = 0; i < blockCount; ++i)
                    {
                        bin.ReadInt32();

                        for (int j = 0; j < 8; ++j, ++index)
                        {
                            m_List[index] = new Hue(index, bin);
                        }
                    }
                }
            }

            for (; index < 3000; ++index)
            {
                m_List[index] = new Hue(index);
            }
        }
Beispiel #9
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 FileIndex(string idxFile, string mulFile, int length, int patch_file)
        {
            m_Index = new Entry3D[length];

            string idxPath = FileManager.GetFilePath(idxFile);
            string mulPath = FileManager.GetFilePath(mulFile);

            if (idxPath != null && mulPath != null)
            {
                using (FileStream index = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader bin = new BinaryReader(index);
                    m_Stream = new FileStream(mulPath, FileMode.Open, FileAccess.Read, FileShare.Read);

                    int count = (int)(index.Length / 12);
                    int max   = (count < length) ? count : length;

                    unsafe
                    {
                        byte[] data = bin.ReadBytes(max * 12);
                        fixed(byte *pBuff = data)
                        {
                            byte *pBuffRef = pBuff;

                            for (int i = 0; i < max; i++)
                            {
                                m_Index[i] = *((Entry3D *)pBuffRef);
                                pBuffRef  += 12;
                            }
                        }

                        int[] empty = new int[3] {
                            -1, -1, -1
                        };
                        fixed(byte *pBuff = data)
                        {
                            byte *pBuffRef = pBuff;

                            for (int i = max; i < length; i++)
                            {
                                m_Index[i] = *((Entry3D *)pBuffRef);
                            }
                        }
                    }
                }
            }

            Entry5D[] patches = Versioning.Patches;

            for (int i = 0; i < patches.Length; ++i)
            {
                Entry5D patch = patches[i];

                if (patch.file == patch_file && patch.index >= 0 && patch.index < length)
                {
                    m_Index[patch.index].lookup = patch.lookup;
                    m_Index[patch.index].length = patch.length | (1 << 31);
                    m_Index[patch.index].extra  = patch.extra;
                }
            }
        }
Beispiel #10
0
        static BodyConverter()
        {
            string path = FileManager.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 (StreamReader ip = new StreamReader(path))
            {
                string line;
                int    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');
                    string[] split    = Regex.Split(line, @"\t|\s+", RegexOptions.IgnoreCase);
                    int      original = System.Convert.ToInt32(split[0]);
                    int      anim2    = System.Convert.ToInt32(split[1]);
                    int      anim3;
                    int      anim4;
                    int      anim5;
                    // Int32.TryParse(split[0], out original);
                    // Int32.TryParse(split[1], out anim2);

                    // The control here was wrong, previously it was always putting -1 without parsing the file - Smjert
                    if (split.Length < 3 || !int.TryParse(split[2], out anim3))
                    {
                        anim3 = -1;
                    }

                    if (split.Length < 4 || !int.TryParse(split[3], out anim4))
                    {
                        anim4 = -1;
                    }

                    if (split.Length < 5 || !int.TryParse(split[4], out anim5))
                    {
                        anim5 = -1;
                    }
                    // End Mod - Smjert

                    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);
            }

            m_Table1 = new int[max1 + 1];
            m_Table2 = new int[max2 + 1];
            m_Table3 = new int[max3 + 1];
            m_Table4 = new int[max4 + 1];

            for (int i = 0; i < m_Table1.Length; ++i)
            {
                m_Table1[i] = -1;
            }

            for (int i = 0; i < list1.Count; i += 2)
            {
                m_Table1[(int)list1[i]] = (int)list1[i + 1];
            }

            for (int i = 0; i < m_Table2.Length; ++i)
            {
                m_Table2[i] = -1;
            }

            for (int i = 0; i < list2.Count; i += 2)
            {
                m_Table2[(int)list2[i]] = (int)list2[i + 1];
            }

            for (int i = 0; i < m_Table3.Length; ++i)
            {
                m_Table3[i] = -1;
            }

            for (int i = 0; i < list3.Count; i += 2)
            {
                m_Table3[(int)list3[i]] = (int)list3[i + 1];
            }

            for (int i = 0; i < m_Table4.Length; ++i)
            {
                m_Table4[i] = -1;
            }

            for (int i = 0; i < list4.Count; i += 2)
            {
                m_Table4[(int)list4[i]] = (int)list4[i + 1];
            }
        }