Ejemplo n.º 1
0
        // Issue 5 - End

        static TileData()
        {
            using (FileStream fileStream = FileManager.GetFile("tiledata.mul"))
            {
                BinaryReader binaryReader = new BinaryReader(fileStream);

                LandData landData;

                for (int i = 0; i < 0x4000; i++)
                {
                    landData = new LandData();

                    if ((i & 0x1F) == 0)
                    {
                        binaryReader.ReadInt32();
                    }

                    TileFlag flags = (TileFlag)binaryReader.ReadInt32();

                    int iTextureID = binaryReader.ReadInt16();

                    binaryReader.BaseStream.Seek(20, SeekOrigin.Current);

                    landData.Flags     = flags;
                    landData.TextureID = iTextureID;

                    LandData[i] = landData;
                }

                ItemData itemData;

                for (int i = 0; i < 0x4000; i++)
                {
                    itemData = new ItemData();

                    if ((i & 0x1F) == 0)
                    {
                        binaryReader.ReadInt32();
                    }

                    itemData.Flags   = (TileFlag)binaryReader.ReadInt32();
                    itemData.Weight  = binaryReader.ReadByte();
                    itemData.Quality = binaryReader.ReadByte();

                    binaryReader.BaseStream.Seek(3, SeekOrigin.Current);

                    itemData.Quantity = binaryReader.ReadByte();
                    itemData.AnimID   = binaryReader.ReadInt16();
                    binaryReader.BaseStream.Seek(3, SeekOrigin.Current);

                    itemData.Value  = binaryReader.ReadByte();
                    itemData.Height = binaryReader.ReadByte();

                    itemData.Name = System.Text.ASCIIEncoding.ASCII.GetString((binaryReader.ReadBytes(20)));
                    itemData.Name = itemData.Name.Trim('\0');
                    // binaryReader.BaseStream.Seek(20, SeekOrigin.Current);

                    // Issue 5 - Statics (bridge, stairs, etc) should be walkable - http://code.google.com/p/ultimaxna/issues/detail?id=5 - Smjert
                    if (i > 1005 && i < 7640)
                    {
                        itemData.IsStairs = !(Array.BinarySearch(m_StairsID, i) < 0);
                    }
                    // Issue 5 - End

                    ItemData[i] = itemData;
                }

                Metrics.ReportDataRead((int)binaryReader.BaseStream.Position);
            }
        }
Ejemplo n.º 2
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];
            }
        }