示例#1
0
 public void Init()
 {
     Verdata       = new Verdata(this);
     RadarCol      = new RadarCol(this);
     Hues          = new Hues(this);
     Gumps         = new Gumps(this);
     Art           = new Art(this);
     TileData      = new TileData(this);
     Skills        = new Skills(this);
     Light         = new Light(this);
     Sound         = new Sounds(this);
     Textures      = new Textures(this);
     Multis        = new Multis(this);
     AnimationEdit = new AnimationEdit(this);
     ASCIIText     = new ASCIIText(this);
     Maps          = new Dictionary <MapNames, Map>
     {
         { MapNames.Felucca, Map.Felucca(this) },
         { MapNames.Ilshenar, Map.Ilshenar(this) },
         { MapNames.Malas, Map.Malas(this) },
         { MapNames.Trammel, Map.Trammel(this) },
         { MapNames.Tokuno, Map.Tokuno(this) },
         { MapNames.TerMur, Map.TerMur(this) }
     };
     MultiMap   = new Ultima.MultiMap(this);
     Animations = new Animations(this);
 }
示例#2
0
        public static MultiComponentList GetComponents(int index)
        {
            index &= 16383;
            MultiComponentList multiComponentList;

            if (index >= 0 && index < Multis.m_Components.Length)
            {
                multiComponentList = Multis.m_Components[index];
                if (multiComponentList == null)
                {
                    Multis.m_Components[index] = multiComponentList = Multis.Load(index);
                }
            }
            else
            {
                multiComponentList = MultiComponentList.Empty;
            }
            return(multiComponentList);
        }
示例#3
0
        public static MultiComponentList GetComponents(int index)
        {
            MultiComponentList empty;

            index = index & 16383;
            if (index < 0 || index >= (int)Multis.m_Components.Length)
            {
                empty = MultiComponentList.Empty;
            }
            else
            {
                empty = Multis.m_Components[index];
                if (empty == null)
                {
                    MultiComponentList[] mComponents        = Multis.m_Components;
                    MultiComponentList   multiComponentList = Multis.Load(index);
                    empty = multiComponentList;
                    mComponents[index] = multiComponentList;
                }
            }
            return(empty);
        }
示例#4
0
文件: Multis.cs 项目: credzba/Razor
        public MultiComponentList(string FileName, Multis.ImportType Type)
        {
            m_Min = m_Max = Point.Empty;
            int itemcount;

            switch (Type)
            {
            case Multis.ImportType.TXT:
                itemcount = 0;
                using (StreamReader ip = new StreamReader(FileName))
                {
                    string line;
                    while ((line = ip.ReadLine()) != null)
                    {
                        itemcount++;
                    }
                }

                m_SortedTiles = new MultiTileEntry[itemcount];
                itemcount     = 0;
                m_Min.X       = 10000;
                m_Min.Y       = 10000;
                using (StreamReader ip = new StreamReader(FileName))
                {
                    string line;
                    while ((line = ip.ReadLine()) != null)
                    {
                        string[] split = line.Split(' ');

                        string tmp = split[0];
                        tmp = tmp.Replace("0x", "");

                        m_SortedTiles[itemcount].m_ItemID =
                            ushort.Parse(tmp, System.Globalization.NumberStyles.HexNumber);
                        m_SortedTiles[itemcount].m_OffsetX = Convert.ToInt16(split[1]);
                        m_SortedTiles[itemcount].m_OffsetY = Convert.ToInt16(split[2]);
                        m_SortedTiles[itemcount].m_OffsetZ = Convert.ToInt16(split[3]);
                        m_SortedTiles[itemcount].m_Flags   = Convert.ToInt32(split[4]);
                        m_SortedTiles[itemcount].m_Unk1    = 0;

                        MultiTileEntry e = m_SortedTiles[itemcount];

                        if (e.m_OffsetX < m_Min.X)
                        {
                            m_Min.X = e.m_OffsetX;
                        }

                        if (e.m_OffsetY < m_Min.Y)
                        {
                            m_Min.Y = e.m_OffsetY;
                        }

                        if (e.m_OffsetX > m_Max.X)
                        {
                            m_Max.X = e.m_OffsetX;
                        }

                        if (e.m_OffsetY > m_Max.Y)
                        {
                            m_Max.Y = e.m_OffsetY;
                        }

                        if (e.m_OffsetZ > m_maxHeight)
                        {
                            m_maxHeight = e.m_OffsetZ;
                        }

                        itemcount++;
                    }

                    int centerx = m_Max.X - (int)(Math.Round((m_Max.X - m_Min.X) / 2.0));
                    int centery = m_Max.Y - (int)(Math.Round((m_Max.Y - m_Min.Y) / 2.0));

                    m_Min = m_Max = Point.Empty;
                    int i = 0;
                    for (; i < m_SortedTiles.Length; i++)
                    {
                        m_SortedTiles[i].m_OffsetX -= (short)centerx;
                        m_SortedTiles[i].m_OffsetY -= (short)centery;
                        if (m_SortedTiles[i].m_OffsetX < m_Min.X)
                        {
                            m_Min.X = m_SortedTiles[i].m_OffsetX;
                        }
                        if (m_SortedTiles[i].m_OffsetX > m_Max.X)
                        {
                            m_Max.X = m_SortedTiles[i].m_OffsetX;
                        }

                        if (m_SortedTiles[i].m_OffsetY < m_Min.Y)
                        {
                            m_Min.Y = m_SortedTiles[i].m_OffsetY;
                        }
                        if (m_SortedTiles[i].m_OffsetY > m_Max.Y)
                        {
                            m_Max.Y = m_SortedTiles[i].m_OffsetY;
                        }
                    }
                }

                break;

            case Multis.ImportType.UOA:
                itemcount = 0;

                using (StreamReader ip = new StreamReader(FileName))
                {
                    string line;
                    while ((line = ip.ReadLine()) != null)
                    {
                        ++itemcount;
                        if (itemcount == 4)
                        {
                            string[] split = line.Split(' ');
                            itemcount = Convert.ToInt32(split[0]);
                            break;
                        }
                    }
                }

                m_SortedTiles = new MultiTileEntry[itemcount];
                itemcount     = 0;
                m_Min.X       = 10000;
                m_Min.Y       = 10000;
                using (StreamReader ip = new StreamReader(FileName))
                {
                    string line;
                    int    i = -1;
                    while ((line = ip.ReadLine()) != null)
                    {
                        ++i;
                        if (i < 4)
                        {
                            continue;
                        }
                        string[] split = line.Split(' ');

                        m_SortedTiles[itemcount].m_ItemID  = Convert.ToUInt16(split[0]);
                        m_SortedTiles[itemcount].m_OffsetX = Convert.ToInt16(split[1]);
                        m_SortedTiles[itemcount].m_OffsetY = Convert.ToInt16(split[2]);
                        m_SortedTiles[itemcount].m_OffsetZ = Convert.ToInt16(split[3]);
                        m_SortedTiles[itemcount].m_Flags   = Convert.ToInt32(split[4]);
                        m_SortedTiles[itemcount].m_Unk1    = 0;

                        MultiTileEntry e = m_SortedTiles[itemcount];

                        if (e.m_OffsetX < m_Min.X)
                        {
                            m_Min.X = e.m_OffsetX;
                        }

                        if (e.m_OffsetY < m_Min.Y)
                        {
                            m_Min.Y = e.m_OffsetY;
                        }

                        if (e.m_OffsetX > m_Max.X)
                        {
                            m_Max.X = e.m_OffsetX;
                        }

                        if (e.m_OffsetY > m_Max.Y)
                        {
                            m_Max.Y = e.m_OffsetY;
                        }

                        if (e.m_OffsetZ > m_maxHeight)
                        {
                            m_maxHeight = e.m_OffsetZ;
                        }

                        ++itemcount;
                    }

                    int centerx = m_Max.X - (int)(Math.Round((m_Max.X - m_Min.X) / 2.0));
                    int centery = m_Max.Y - (int)(Math.Round((m_Max.Y - m_Min.Y) / 2.0));

                    m_Min = m_Max = Point.Empty;
                    i     = 0;
                    for (; i < m_SortedTiles.Length; ++i)
                    {
                        m_SortedTiles[i].m_OffsetX -= (short)centerx;
                        m_SortedTiles[i].m_OffsetY -= (short)centery;
                        if (m_SortedTiles[i].m_OffsetX < m_Min.X)
                        {
                            m_Min.X = m_SortedTiles[i].m_OffsetX;
                        }
                        if (m_SortedTiles[i].m_OffsetX > m_Max.X)
                        {
                            m_Max.X = m_SortedTiles[i].m_OffsetX;
                        }

                        if (m_SortedTiles[i].m_OffsetY < m_Min.Y)
                        {
                            m_Min.Y = m_SortedTiles[i].m_OffsetY;
                        }
                        if (m_SortedTiles[i].m_OffsetY > m_Max.Y)
                        {
                            m_Max.Y = m_SortedTiles[i].m_OffsetY;
                        }
                    }
                }

                break;

            case Multis.ImportType.UOAB:
                using (FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (BinaryReader reader = new BinaryReader(fs))
                    {
                        if (reader.ReadInt16() != 1) //Version check
                        {
                            return;
                        }
                        string tmp;
                        tmp = Multis.ReadUOAString(reader); //Name
                        tmp = Multis.ReadUOAString(reader); //Category
                        tmp = Multis.ReadUOAString(reader); //Subsection
                        int width   = reader.ReadInt32();
                        int height  = reader.ReadInt32();
                        int uwidth  = reader.ReadInt32();
                        int uheight = reader.ReadInt32();

                        int count = reader.ReadInt32();
                        itemcount     = count;
                        m_SortedTiles = new MultiTileEntry[itemcount];
                        itemcount     = 0;
                        m_Min.X       = 10000;
                        m_Min.Y       = 10000;
                        for (; itemcount < count; ++itemcount)
                        {
                            m_SortedTiles[itemcount].m_ItemID  = (ushort)reader.ReadInt16();
                            m_SortedTiles[itemcount].m_OffsetX = reader.ReadInt16();
                            m_SortedTiles[itemcount].m_OffsetY = reader.ReadInt16();
                            m_SortedTiles[itemcount].m_OffsetZ = reader.ReadInt16();
                            reader.ReadInt16(); // level
                            m_SortedTiles[itemcount].m_Flags = 1;
                            reader.ReadInt16(); // hue
                            m_SortedTiles[itemcount].m_Unk1 = 0;

                            MultiTileEntry e = m_SortedTiles[itemcount];

                            if (e.m_OffsetX < m_Min.X)
                            {
                                m_Min.X = e.m_OffsetX;
                            }

                            if (e.m_OffsetY < m_Min.Y)
                            {
                                m_Min.Y = e.m_OffsetY;
                            }

                            if (e.m_OffsetX > m_Max.X)
                            {
                                m_Max.X = e.m_OffsetX;
                            }

                            if (e.m_OffsetY > m_Max.Y)
                            {
                                m_Max.Y = e.m_OffsetY;
                            }

                            if (e.m_OffsetZ > m_maxHeight)
                            {
                                m_maxHeight = e.m_OffsetZ;
                            }
                        }

                        int centerx = m_Max.X - (int)(Math.Round((m_Max.X - m_Min.X) / 2.0));
                        int centery = m_Max.Y - (int)(Math.Round((m_Max.Y - m_Min.Y) / 2.0));

                        m_Min     = m_Max = Point.Empty;
                        itemcount = 0;
                        for (; itemcount < m_SortedTiles.Length; ++itemcount)
                        {
                            m_SortedTiles[itemcount].m_OffsetX -= (short)centerx;
                            m_SortedTiles[itemcount].m_OffsetY -= (short)centery;
                            if (m_SortedTiles[itemcount].m_OffsetX < m_Min.X)
                            {
                                m_Min.X = m_SortedTiles[itemcount].m_OffsetX;
                            }
                            if (m_SortedTiles[itemcount].m_OffsetX > m_Max.X)
                            {
                                m_Max.X = m_SortedTiles[itemcount].m_OffsetX;
                            }

                            if (m_SortedTiles[itemcount].m_OffsetY < m_Min.Y)
                            {
                                m_Min.Y = m_SortedTiles[itemcount].m_OffsetY;
                            }
                            if (m_SortedTiles[itemcount].m_OffsetY > m_Max.Y)
                            {
                                m_Max.Y = m_SortedTiles[itemcount].m_OffsetY;
                            }
                        }
                    }

                break;

            case Multis.ImportType.WSC:
                itemcount = 0;
                using (StreamReader ip = new StreamReader(FileName))
                {
                    string line;
                    while ((line = ip.ReadLine()) != null)
                    {
                        line = line.Trim();
                        if (line.StartsWith("SECTION WORLDITEM"))
                        {
                            ++itemcount;
                        }
                    }
                }

                m_SortedTiles = new MultiTileEntry[itemcount];
                itemcount     = 0;
                m_Min.X       = 10000;
                m_Min.Y       = 10000;
                using (StreamReader ip = new StreamReader(FileName))
                {
                    string         line;
                    MultiTileEntry tempitem = new MultiTileEntry();
                    tempitem.m_ItemID = 0xFFFF;
                    tempitem.m_Flags  = 1;
                    tempitem.m_Unk1   = 0;
                    while ((line = ip.ReadLine()) != null)
                    {
                        line = line.Trim();
                        if (line.StartsWith("SECTION WORLDITEM"))
                        {
                            if (tempitem.m_ItemID != 0xFFFF)
                            {
                                m_SortedTiles[itemcount] = tempitem;
                                ++itemcount;
                            }

                            tempitem.m_ItemID = 0xFFFF;
                        }
                        else if (line.StartsWith("ID"))
                        {
                            line = line.Remove(0, 2);
                            line = line.Trim();
                            tempitem.m_ItemID = Convert.ToUInt16(line);
                        }
                        else if (line.StartsWith("X"))
                        {
                            line = line.Remove(0, 1);
                            line = line.Trim();
                            tempitem.m_OffsetX = Convert.ToInt16(line);
                            if (tempitem.m_OffsetX < m_Min.X)
                            {
                                m_Min.X = tempitem.m_OffsetX;
                            }
                            if (tempitem.m_OffsetX > m_Max.X)
                            {
                                m_Max.X = tempitem.m_OffsetX;
                            }
                        }
                        else if (line.StartsWith("Y"))
                        {
                            line = line.Remove(0, 1);
                            line = line.Trim();
                            tempitem.m_OffsetY = Convert.ToInt16(line);
                            if (tempitem.m_OffsetY < m_Min.Y)
                            {
                                m_Min.Y = tempitem.m_OffsetY;
                            }
                            if (tempitem.m_OffsetY > m_Max.Y)
                            {
                                m_Max.Y = tempitem.m_OffsetY;
                            }
                        }
                        else if (line.StartsWith("Z"))
                        {
                            line = line.Remove(0, 1);
                            line = line.Trim();
                            tempitem.m_OffsetZ = Convert.ToInt16(line);
                            if (tempitem.m_OffsetZ > m_maxHeight)
                            {
                                m_maxHeight = tempitem.m_OffsetZ;
                            }
                        }
                    }

                    if (tempitem.m_ItemID != 0xFFFF)
                    {
                        m_SortedTiles[itemcount] = tempitem;
                    }

                    int centerx = m_Max.X - (int)(Math.Round((m_Max.X - m_Min.X) / 2.0));
                    int centery = m_Max.Y - (int)(Math.Round((m_Max.Y - m_Min.Y) / 2.0));

                    m_Min = m_Max = Point.Empty;
                    int i = 0;
                    for (; i < m_SortedTiles.Length; i++)
                    {
                        m_SortedTiles[i].m_OffsetX -= (short)centerx;
                        m_SortedTiles[i].m_OffsetY -= (short)centery;
                        if (m_SortedTiles[i].m_OffsetX < m_Min.X)
                        {
                            m_Min.X = m_SortedTiles[i].m_OffsetX;
                        }
                        if (m_SortedTiles[i].m_OffsetX > m_Max.X)
                        {
                            m_Max.X = m_SortedTiles[i].m_OffsetX;
                        }

                        if (m_SortedTiles[i].m_OffsetY < m_Min.Y)
                        {
                            m_Min.Y = m_SortedTiles[i].m_OffsetY;
                        }
                        if (m_SortedTiles[i].m_OffsetY > m_Max.Y)
                        {
                            m_Max.Y = m_SortedTiles[i].m_OffsetY;
                        }
                    }
                }

                break;
            }

            ConvertList();
        }
示例#5
0
        public MultiComponentList(string fileName, Multis.ImportType type)
        {
            _min = _max = Point.Empty;

            int itemCount;

            switch (type)
            {
            case Multis.ImportType.TXT:
            {
                itemCount = 0;
                using (var ip = new StreamReader(fileName))
                {
                    while (ip.ReadLine() != null)
                    {
                        itemCount++;
                    }
                }
                SortedTiles = new MultiTileEntry[itemCount];
                itemCount   = 0;
                _min.X      = 10000;
                _min.Y      = 10000;
                using (var ip = new StreamReader(fileName))
                {
                    string line;
                    while ((line = ip.ReadLine()) != null)
                    {
                        string[] split = line.Split(' ');

                        string tmp = split[0];
                        tmp = tmp.Replace("0x", "");

                        SortedTiles[itemCount].m_ItemID  = ushort.Parse(tmp, System.Globalization.NumberStyles.HexNumber);
                        SortedTiles[itemCount].m_OffsetX = Convert.ToInt16(split[1]);
                        SortedTiles[itemCount].m_OffsetY = Convert.ToInt16(split[2]);
                        SortedTiles[itemCount].m_OffsetZ = Convert.ToInt16(split[3]);
                        SortedTiles[itemCount].m_Flags   = Convert.ToInt32(split[4]);
                        SortedTiles[itemCount].m_Unk1    = 0;

                        MultiTileEntry e = SortedTiles[itemCount];

                        if (e.m_OffsetX < _min.X)
                        {
                            _min.X = e.m_OffsetX;
                        }

                        if (e.m_OffsetY < _min.Y)
                        {
                            _min.Y = e.m_OffsetY;
                        }

                        if (e.m_OffsetX > _max.X)
                        {
                            _max.X = e.m_OffsetX;
                        }

                        if (e.m_OffsetY > _max.Y)
                        {
                            _max.Y = e.m_OffsetY;
                        }

                        if (e.m_OffsetZ > MaxHeight)
                        {
                            MaxHeight = e.m_OffsetZ;
                        }

                        itemCount++;
                    }
                    int centerX = _max.X - (int)(Math.Round((_max.X - _min.X) / 2.0));
                    int centerY = _max.Y - (int)(Math.Round((_max.Y - _min.Y) / 2.0));

                    _min = _max = Point.Empty;
                    int i = 0;
                    for (; i < SortedTiles.Length; i++)
                    {
                        SortedTiles[i].m_OffsetX -= (short)centerX;
                        SortedTiles[i].m_OffsetY -= (short)centerY;
                        if (SortedTiles[i].m_OffsetX < _min.X)
                        {
                            _min.X = SortedTiles[i].m_OffsetX;
                        }

                        if (SortedTiles[i].m_OffsetX > _max.X)
                        {
                            _max.X = SortedTiles[i].m_OffsetX;
                        }

                        if (SortedTiles[i].m_OffsetY < _min.Y)
                        {
                            _min.Y = SortedTiles[i].m_OffsetY;
                        }

                        if (SortedTiles[i].m_OffsetY > _max.Y)
                        {
                            _max.Y = SortedTiles[i].m_OffsetY;
                        }
                    }
                }
                break;
            }

            case Multis.ImportType.UOA:
            {
                itemCount = 0;

                using (var ip = new StreamReader(fileName))
                {
                    string line;
                    while ((line = ip.ReadLine()) != null)
                    {
                        ++itemCount;

                        if (itemCount != 4)
                        {
                            continue;
                        }

                        string[] split = line.Split(' ');
                        itemCount = Convert.ToInt32(split[0]);
                        break;
                    }
                }
                SortedTiles = new MultiTileEntry[itemCount];
                itemCount   = 0;
                _min.X      = 10000;
                _min.Y      = 10000;
                using (var ip = new StreamReader(fileName))
                {
                    string line;
                    int    i = -1;
                    while ((line = ip.ReadLine()) != null)
                    {
                        ++i;
                        if (i < 4)
                        {
                            continue;
                        }

                        string[] split = line.Split(' ');

                        SortedTiles[itemCount].m_ItemID  = Convert.ToUInt16(split[0]);
                        SortedTiles[itemCount].m_OffsetX = Convert.ToInt16(split[1]);
                        SortedTiles[itemCount].m_OffsetY = Convert.ToInt16(split[2]);
                        SortedTiles[itemCount].m_OffsetZ = Convert.ToInt16(split[3]);
                        SortedTiles[itemCount].m_Flags   = Convert.ToInt32(split[4]);
                        SortedTiles[itemCount].m_Unk1    = 0;

                        MultiTileEntry e = SortedTiles[itemCount];

                        if (e.m_OffsetX < _min.X)
                        {
                            _min.X = e.m_OffsetX;
                        }

                        if (e.m_OffsetY < _min.Y)
                        {
                            _min.Y = e.m_OffsetY;
                        }

                        if (e.m_OffsetX > _max.X)
                        {
                            _max.X = e.m_OffsetX;
                        }

                        if (e.m_OffsetY > _max.Y)
                        {
                            _max.Y = e.m_OffsetY;
                        }

                        if (e.m_OffsetZ > MaxHeight)
                        {
                            MaxHeight = e.m_OffsetZ;
                        }

                        ++itemCount;
                    }

                    int centerX = _max.X - (int)(Math.Round((_max.X - _min.X) / 2.0));
                    int centerY = _max.Y - (int)(Math.Round((_max.Y - _min.Y) / 2.0));

                    _min = _max = Point.Empty;
                    i    = 0;
                    for (; i < SortedTiles.Length; ++i)
                    {
                        SortedTiles[i].m_OffsetX -= (short)centerX;
                        SortedTiles[i].m_OffsetY -= (short)centerY;
                        if (SortedTiles[i].m_OffsetX < _min.X)
                        {
                            _min.X = SortedTiles[i].m_OffsetX;
                        }

                        if (SortedTiles[i].m_OffsetX > _max.X)
                        {
                            _max.X = SortedTiles[i].m_OffsetX;
                        }

                        if (SortedTiles[i].m_OffsetY < _min.Y)
                        {
                            _min.Y = SortedTiles[i].m_OffsetY;
                        }

                        if (SortedTiles[i].m_OffsetY > _max.Y)
                        {
                            _max.Y = SortedTiles[i].m_OffsetY;
                        }
                    }
                }

                break;
            }

            case Multis.ImportType.UOAB:
            {
                using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (var reader = new BinaryReader(fs))
                    {
                        if (reader.ReadInt16() != 1) // Version check
                        {
                            return;
                        }

                        _ = Multis.ReadUOAString(reader);
                        _ = Multis.ReadUOAString(reader); // Category
                        _ = Multis.ReadUOAString(reader); // Subsection

                        _ = reader.ReadInt32();
                        _ = reader.ReadInt32();
                        _ = reader.ReadInt32();
                        _ = reader.ReadInt32();

                        int count = reader.ReadInt32();
                        itemCount   = count;
                        SortedTiles = new MultiTileEntry[itemCount];
                        itemCount   = 0;
                        _min.X      = 10000;
                        _min.Y      = 10000;
                        for (; itemCount < count; ++itemCount)
                        {
                            SortedTiles[itemCount].m_ItemID  = (ushort)reader.ReadInt16();
                            SortedTiles[itemCount].m_OffsetX = reader.ReadInt16();
                            SortedTiles[itemCount].m_OffsetY = reader.ReadInt16();
                            SortedTiles[itemCount].m_OffsetZ = reader.ReadInt16();
                            reader.ReadInt16(); // level
                            SortedTiles[itemCount].m_Flags = 1;
                            reader.ReadInt16(); // hue
                            SortedTiles[itemCount].m_Unk1 = 0;

                            MultiTileEntry e = SortedTiles[itemCount];

                            if (e.m_OffsetX < _min.X)
                            {
                                _min.X = e.m_OffsetX;
                            }

                            if (e.m_OffsetY < _min.Y)
                            {
                                _min.Y = e.m_OffsetY;
                            }

                            if (e.m_OffsetX > _max.X)
                            {
                                _max.X = e.m_OffsetX;
                            }

                            if (e.m_OffsetY > _max.Y)
                            {
                                _max.Y = e.m_OffsetY;
                            }

                            if (e.m_OffsetZ > MaxHeight)
                            {
                                MaxHeight = e.m_OffsetZ;
                            }
                        }
                        int centerx = _max.X - (int)(Math.Round((_max.X - _min.X) / 2.0));
                        int centery = _max.Y - (int)(Math.Round((_max.Y - _min.Y) / 2.0));

                        _min      = _max = Point.Empty;
                        itemCount = 0;
                        for (; itemCount < SortedTiles.Length; ++itemCount)
                        {
                            SortedTiles[itemCount].m_OffsetX -= (short)centerx;
                            SortedTiles[itemCount].m_OffsetY -= (short)centery;
                            if (SortedTiles[itemCount].m_OffsetX < _min.X)
                            {
                                _min.X = SortedTiles[itemCount].m_OffsetX;
                            }

                            if (SortedTiles[itemCount].m_OffsetX > _max.X)
                            {
                                _max.X = SortedTiles[itemCount].m_OffsetX;
                            }

                            if (SortedTiles[itemCount].m_OffsetY < _min.Y)
                            {
                                _min.Y = SortedTiles[itemCount].m_OffsetY;
                            }

                            if (SortedTiles[itemCount].m_OffsetY > _max.Y)
                            {
                                _max.Y = SortedTiles[itemCount].m_OffsetY;
                            }
                        }
                    }
                break;
            }

            case Multis.ImportType.WSC:
            {
                itemCount = 0;
                using (var ip = new StreamReader(fileName))
                {
                    string line;
                    while ((line = ip.ReadLine()) != null)
                    {
                        line = line.Trim();
                        if (line.StartsWith("SECTION WORLDITEM"))
                        {
                            ++itemCount;
                        }
                    }
                }
                SortedTiles = new MultiTileEntry[itemCount];
                itemCount   = 0;
                _min.X      = 10000;
                _min.Y      = 10000;
                using (var ip = new StreamReader(fileName))
                {
                    string line;
                    var    tempItem = new MultiTileEntry
                    {
                        m_ItemID = 0xFFFF,
                        m_Flags  = 1,
                        m_Unk1   = 0
                    };

                    while ((line = ip.ReadLine()) != null)
                    {
                        line = line.Trim();
                        if (line.StartsWith("SECTION WORLDITEM"))
                        {
                            if (tempItem.m_ItemID != 0xFFFF)
                            {
                                SortedTiles[itemCount] = tempItem;
                                ++itemCount;
                            }
                            tempItem.m_ItemID = 0xFFFF;
                        }
                        else if (line.StartsWith("ID"))
                        {
                            line = line.Remove(0, 2);
                            line = line.Trim();
                            tempItem.m_ItemID = Convert.ToUInt16(line);
                        }
                        else if (line.StartsWith("X"))
                        {
                            line = line.Remove(0, 1);
                            line = line.Trim();
                            tempItem.m_OffsetX = Convert.ToInt16(line);
                            if (tempItem.m_OffsetX < _min.X)
                            {
                                _min.X = tempItem.m_OffsetX;
                            }

                            if (tempItem.m_OffsetX > _max.X)
                            {
                                _max.X = tempItem.m_OffsetX;
                            }
                        }
                        else if (line.StartsWith("Y"))
                        {
                            line = line.Remove(0, 1);
                            line = line.Trim();
                            tempItem.m_OffsetY = Convert.ToInt16(line);
                            if (tempItem.m_OffsetY < _min.Y)
                            {
                                _min.Y = tempItem.m_OffsetY;
                            }

                            if (tempItem.m_OffsetY > _max.Y)
                            {
                                _max.Y = tempItem.m_OffsetY;
                            }
                        }
                        else if (line.StartsWith("Z"))
                        {
                            line = line.Remove(0, 1);
                            line = line.Trim();
                            tempItem.m_OffsetZ = Convert.ToInt16(line);
                            if (tempItem.m_OffsetZ > MaxHeight)
                            {
                                MaxHeight = tempItem.m_OffsetZ;
                            }
                        }
                    }
                    if (tempItem.m_ItemID != 0xFFFF)
                    {
                        SortedTiles[itemCount] = tempItem;
                    }

                    int centerX = _max.X - (int)(Math.Round((_max.X - _min.X) / 2.0));
                    int centerY = _max.Y - (int)(Math.Round((_max.Y - _min.Y) / 2.0));

                    _min = _max = Point.Empty;
                    int i = 0;
                    for (; i < SortedTiles.Length; i++)
                    {
                        SortedTiles[i].m_OffsetX -= (short)centerX;
                        SortedTiles[i].m_OffsetY -= (short)centerY;
                        if (SortedTiles[i].m_OffsetX < _min.X)
                        {
                            _min.X = SortedTiles[i].m_OffsetX;
                        }

                        if (SortedTiles[i].m_OffsetX > _max.X)
                        {
                            _max.X = SortedTiles[i].m_OffsetX;
                        }

                        if (SortedTiles[i].m_OffsetY < _min.Y)
                        {
                            _min.Y = SortedTiles[i].m_OffsetY;
                        }

                        if (SortedTiles[i].m_OffsetY > _max.Y)
                        {
                            _max.Y = SortedTiles[i].m_OffsetY;
                        }
                    }
                }
                break;
            }
            }
            ConvertList();
        }
示例#6
0
 public static MultiComponentList ImportFromFile(int index, string FileName, Multis.ImportType type)
 {
     try
     {
         return m_Components[index] = new MultiComponentList(FileName, type);
     }
     catch
     {
         return m_Components[index] = MultiComponentList.Empty;
     }
 }
示例#7
0
        public MultiComponentList(string FileName, Multis.ImportType Type)
        {
            m_Min = m_Max = Point.Empty;
            int itemcount;
            switch (Type)
            {
                case Multis.ImportType.TXT:
                    itemcount = 0;
                    using (StreamReader ip = new StreamReader(FileName))
                    {
                        string line;
                        while ((line = ip.ReadLine()) != null)
                        {
                            itemcount++;
                        }
                    }
                    m_SortedTiles = new MultiTileEntry[itemcount];
                    itemcount = 0;
                    m_Min.X = 10000;
                    m_Min.Y = 10000;
                    using (StreamReader ip = new StreamReader(FileName))
                    {
                        string line;
                        while ((line = ip.ReadLine()) != null)
                        {
                            string[] split = line.Split(' ');

                            string tmp = split[0];
                            tmp = tmp.Replace("0x", "");

                            m_SortedTiles[itemcount].m_ItemID = ushort.Parse(split[0]);
                            m_SortedTiles[itemcount].m_OffsetX = Convert.ToInt16(split[1]);
                            m_SortedTiles[itemcount].m_OffsetY = Convert.ToInt16(split[2]);
                            m_SortedTiles[itemcount].m_OffsetZ = Convert.ToInt16(split[3]);
                            m_SortedTiles[itemcount].m_Flags = Convert.ToInt32(split[4]);
                            m_SortedTiles[itemcount].m_Unk1 = 0;

                            MultiTileEntry e = m_SortedTiles[itemcount];

                            if (e.m_OffsetX < m_Min.X)
                                m_Min.X = e.m_OffsetX;

                            if (e.m_OffsetY < m_Min.Y)
                                m_Min.Y = e.m_OffsetY;

                            if (e.m_OffsetX > m_Max.X)
                                m_Max.X = e.m_OffsetX;

                            if (e.m_OffsetY > m_Max.Y)
                                m_Max.Y = e.m_OffsetY;

                            if (e.m_OffsetZ > m_maxHeight)
                                m_maxHeight = e.m_OffsetZ;

                            itemcount++;
                        }
                        int centerx = m_Max.X - (int)(Math.Round((m_Max.X - m_Min.X) / 2.0));
                        int centery = m_Max.Y - (int)(Math.Round((m_Max.Y - m_Min.Y) / 2.0));

                        m_Min = m_Max = Point.Empty;
                        int i = 0;
                        for (; i < m_SortedTiles.Length; i++)
                        {
                            m_SortedTiles[i].m_OffsetX -= (short)centerx;
                            m_SortedTiles[i].m_OffsetY -= (short)centery;
                            if (m_SortedTiles[i].m_OffsetX < m_Min.X)
                                m_Min.X = m_SortedTiles[i].m_OffsetX;
                            if (m_SortedTiles[i].m_OffsetX > m_Max.X)
                                m_Max.X = m_SortedTiles[i].m_OffsetX;

                            if (m_SortedTiles[i].m_OffsetY < m_Min.Y)
                                m_Min.Y = m_SortedTiles[i].m_OffsetY;
                            if (m_SortedTiles[i].m_OffsetY > m_Max.Y)
                                m_Max.Y = m_SortedTiles[i].m_OffsetY;
                        }
                    }
                    break;
                case Multis.ImportType.UOA:
                    itemcount = 0;

                    using (StreamReader ip = new StreamReader(FileName))
                    {
                        string line;
                        while ((line = ip.ReadLine()) != null)
                        {
                            ++itemcount;
                            if (itemcount == 4)
                            {
                                string[] split = line.Split(' ');
                                itemcount = Convert.ToInt32(split[0]);
                                break;
                            }
                        }
                    }
                    m_SortedTiles = new MultiTileEntry[itemcount];
                    itemcount = 0;
                    m_Min.X = 10000;
                    m_Min.Y = 10000;
                    using (StreamReader ip = new StreamReader(FileName))
                    {
                        string line;
                        int i = -1;
                        while ((line = ip.ReadLine()) != null)
                        {
                            ++i;
                            if (i < 4)
                                continue;
                            string[] split = line.Split(' ');

                            m_SortedTiles[itemcount].m_ItemID = Convert.ToUInt16(split[0]);
                            m_SortedTiles[itemcount].m_OffsetX = Convert.ToInt16(split[1]);
                            m_SortedTiles[itemcount].m_OffsetY = Convert.ToInt16(split[2]);
                            m_SortedTiles[itemcount].m_OffsetZ = Convert.ToInt16(split[3]);
                            m_SortedTiles[itemcount].m_Flags = Convert.ToInt32(split[4]);
                            m_SortedTiles[itemcount].m_Unk1 = 0;

                            MultiTileEntry e = m_SortedTiles[itemcount];

                            if (e.m_OffsetX < m_Min.X)
                                m_Min.X = e.m_OffsetX;

                            if (e.m_OffsetY < m_Min.Y)
                                m_Min.Y = e.m_OffsetY;

                            if (e.m_OffsetX > m_Max.X)
                                m_Max.X = e.m_OffsetX;

                            if (e.m_OffsetY > m_Max.Y)
                                m_Max.Y = e.m_OffsetY;

                            if (e.m_OffsetZ > m_maxHeight)
                                m_maxHeight = e.m_OffsetZ;

                            ++itemcount;
                        }
                        int centerx = m_Max.X - (int)(Math.Round((m_Max.X - m_Min.X) / 2.0));
                        int centery = m_Max.Y - (int)(Math.Round((m_Max.Y - m_Min.Y) / 2.0));

                        m_Min = m_Max = Point.Empty;
                        i = 0;
                        for (; i < m_SortedTiles.Length; ++i)
                        {
                            m_SortedTiles[i].m_OffsetX -= (short)centerx;
                            m_SortedTiles[i].m_OffsetY -= (short)centery;
                            if (m_SortedTiles[i].m_OffsetX < m_Min.X)
                                m_Min.X = m_SortedTiles[i].m_OffsetX;
                            if (m_SortedTiles[i].m_OffsetX > m_Max.X)
                                m_Max.X = m_SortedTiles[i].m_OffsetX;

                            if (m_SortedTiles[i].m_OffsetY < m_Min.Y)
                                m_Min.Y = m_SortedTiles[i].m_OffsetY;
                            if (m_SortedTiles[i].m_OffsetY > m_Max.Y)
                                m_Max.Y = m_SortedTiles[i].m_OffsetY;
                        }
                    }

                    break;
                case Multis.ImportType.UOAB:
                    using (FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (BinaryReader reader = new BinaryReader(fs))
                    {
                        if (reader.ReadInt16() != 1) //Version check
                            return;
                        string tmp;
                        tmp = Multis.ReadUOAString(reader); //Name
                        tmp = Multis.ReadUOAString(reader); //Category
                        tmp = Multis.ReadUOAString(reader); //Subsection
                        int width = reader.ReadInt32();
                        int height = reader.ReadInt32();
                        int uwidth = reader.ReadInt32();
                        int uheight = reader.ReadInt32();

                        int count = reader.ReadInt32();
                        itemcount = count;
                        m_SortedTiles = new MultiTileEntry[itemcount];
                        itemcount = 0;
                        m_Min.X = 10000;
                        m_Min.Y = 10000;
                        for (; itemcount < count; ++itemcount)
                        {
                            m_SortedTiles[itemcount].m_ItemID = (ushort)reader.ReadInt16();
                            m_SortedTiles[itemcount].m_OffsetX = reader.ReadInt16();
                            m_SortedTiles[itemcount].m_OffsetY = reader.ReadInt16();
                            m_SortedTiles[itemcount].m_OffsetZ = reader.ReadInt16();
                            reader.ReadInt16(); // level
                            m_SortedTiles[itemcount].m_Flags = 1;
                            reader.ReadInt16(); // hue
                            m_SortedTiles[itemcount].m_Unk1 = 0;

                            MultiTileEntry e = m_SortedTiles[itemcount];

                            if (e.m_OffsetX < m_Min.X)
                                m_Min.X = e.m_OffsetX;

                            if (e.m_OffsetY < m_Min.Y)
                                m_Min.Y = e.m_OffsetY;

                            if (e.m_OffsetX > m_Max.X)
                                m_Max.X = e.m_OffsetX;

                            if (e.m_OffsetY > m_Max.Y)
                                m_Max.Y = e.m_OffsetY;

                            if (e.m_OffsetZ > m_maxHeight)
                                m_maxHeight = e.m_OffsetZ;
                        }
                        int centerx = m_Max.X - (int)(Math.Round((m_Max.X - m_Min.X) / 2.0));
                        int centery = m_Max.Y - (int)(Math.Round((m_Max.Y - m_Min.Y) / 2.0));

                        m_Min = m_Max = Point.Empty;
                        itemcount = 0;
                        for (; itemcount < m_SortedTiles.Length; ++itemcount)
                        {
                            m_SortedTiles[itemcount].m_OffsetX -= (short)centerx;
                            m_SortedTiles[itemcount].m_OffsetY -= (short)centery;
                            if (m_SortedTiles[itemcount].m_OffsetX < m_Min.X)
                                m_Min.X = m_SortedTiles[itemcount].m_OffsetX;
                            if (m_SortedTiles[itemcount].m_OffsetX > m_Max.X)
                                m_Max.X = m_SortedTiles[itemcount].m_OffsetX;

                            if (m_SortedTiles[itemcount].m_OffsetY < m_Min.Y)
                                m_Min.Y = m_SortedTiles[itemcount].m_OffsetY;
                            if (m_SortedTiles[itemcount].m_OffsetY > m_Max.Y)
                                m_Max.Y = m_SortedTiles[itemcount].m_OffsetY;
                        }
                    }
                    break;

                case Multis.ImportType.WSC:
                    itemcount = 0;
                    using (StreamReader ip = new StreamReader(FileName))
                    {
                        string line;
                        while ((line = ip.ReadLine()) != null)
                        {
                            line = line.Trim();
                            if (line.StartsWith("SECTION WORLDITEM"))
                                ++itemcount;
                        }
                    }
                    m_SortedTiles = new MultiTileEntry[itemcount];
                    itemcount = 0;
                    m_Min.X = 10000;
                    m_Min.Y = 10000;
                    using (StreamReader ip = new StreamReader(FileName))
                    {
                        string line;
                        MultiTileEntry tempitem = new MultiTileEntry();
                        tempitem.m_ItemID = 0xFFFF;
                        tempitem.m_Flags = 1;
                        tempitem.m_Unk1 = 0;
                        while ((line = ip.ReadLine()) != null)
                        {
                            line = line.Trim();
                            if (line.StartsWith("SECTION WORLDITEM"))
                            {
                                if (tempitem.m_ItemID != 0xFFFF)
                                {
                                    m_SortedTiles[itemcount] = tempitem;
                                    ++itemcount;
                                }
                                tempitem.m_ItemID = 0xFFFF;
                            }
                            else if (line.StartsWith("ID"))
                            {
                                line = line.Remove(0, 2);
                                line = line.Trim();
                                tempitem.m_ItemID = Convert.ToUInt16(line);
                            }
                            else if (line.StartsWith("X"))
                            {
                                line = line.Remove(0, 1);
                                line = line.Trim();
                                tempitem.m_OffsetX = Convert.ToInt16(line);
                                if (tempitem.m_OffsetX < m_Min.X)
                                    m_Min.X = tempitem.m_OffsetX;
                                if (tempitem.m_OffsetX > m_Max.X)
                                    m_Max.X = tempitem.m_OffsetX;
                            }
                            else if (line.StartsWith("Y"))
                            {
                                line = line.Remove(0, 1);
                                line = line.Trim();
                                tempitem.m_OffsetY = Convert.ToInt16(line);
                                if (tempitem.m_OffsetY < m_Min.Y)
                                    m_Min.Y = tempitem.m_OffsetY;
                                if (tempitem.m_OffsetY > m_Max.Y)
                                    m_Max.Y = tempitem.m_OffsetY;
                            }
                            else if (line.StartsWith("Z"))
                            {
                                line = line.Remove(0, 1);
                                line = line.Trim();
                                tempitem.m_OffsetZ = Convert.ToInt16(line);
                                if (tempitem.m_OffsetZ > m_maxHeight)
                                    m_maxHeight = tempitem.m_OffsetZ;

                            }
                        }
                        if (tempitem.m_ItemID != 0xFFFF)
                            m_SortedTiles[itemcount] = tempitem;

                        int centerx = m_Max.X - (int)(Math.Round((m_Max.X - m_Min.X) / 2.0));
                        int centery = m_Max.Y - (int)(Math.Round((m_Max.Y - m_Min.Y) / 2.0));

                        m_Min = m_Max = Point.Empty;
                        int i = 0;
                        for (; i < m_SortedTiles.Length; i++)
                        {
                            m_SortedTiles[i].m_OffsetX -= (short)centerx;
                            m_SortedTiles[i].m_OffsetY -= (short)centery;
                            if (m_SortedTiles[i].m_OffsetX < m_Min.X)
                                m_Min.X = m_SortedTiles[i].m_OffsetX;
                            if (m_SortedTiles[i].m_OffsetX > m_Max.X)
                                m_Max.X = m_SortedTiles[i].m_OffsetX;

                            if (m_SortedTiles[i].m_OffsetY < m_Min.Y)
                                m_Min.Y = m_SortedTiles[i].m_OffsetY;
                            if (m_SortedTiles[i].m_OffsetY > m_Max.Y)
                                m_Max.Y = m_SortedTiles[i].m_OffsetY;
                        }
                    }
                    break;
            }
            ConvertList();
        }
示例#8
0
 public static MultiComponentList LoadFromFile(string FileName, Multis.ImportType type)
 {
     try
     {
         return new MultiComponentList(FileName, type);
     }
     catch
     {
         return MultiComponentList.Empty;
     }
 }
示例#9
0
 private void treeViewMultiList_LoadFromFile(Multis.ImportType importtype)
 {
     OpenFileDialog dialog = new OpenFileDialog();
     dialog.Multiselect = false;
     string type = "";
     switch (importtype)
     {
         case Multis.ImportType.TXT: type = "txt"; break;
         case Multis.ImportType.UOA: type = "uoa"; break;
         case Multis.ImportType.UOAB: type = "uoab"; break;
         case Multis.ImportType.WSC: type = "wsc"; break;
         case Multis.ImportType.MULTICACHE: type = "Multicache.dat"; break;
         case Multis.ImportType.UOADESIGN: type = "Designs"; break;
         default: return;
     }
     dialog.Title = String.Format("Choose {0} file to import", type);
     dialog.CheckFileExists = true;
     if (importtype == Multis.ImportType.MULTICACHE)
         dialog.Filter = String.Format("{0} file ({0})|{0}", type);
     else if (importtype == Multis.ImportType.UOADESIGN)
         dialog.Filter = String.Format("{0} file ({0}.*)|{0}.*", type);
     else if (importtype == Multis.ImportType.UOAB)
         dialog.Filter = String.Format("{0} file (*.{0})|*.{0}", "uoa");
     else
         dialog.Filter = String.Format("{0} file (*.{0})|*.{0}", type);
     if (dialog.ShowDialog() == DialogResult.OK)
     {
         if (importtype == Multis.ImportType.MULTICACHE)
         {
             List<MultiComponentList> list = Ultima.Multis.LoadFromCache(dialog.FileName);
             TreeNode node = treeViewMultiList.Nodes[1].Nodes[4];
             node.Nodes.Clear();
             for (int i = 0; i < list.Count; ++i)
             {
                 TreeNode child = new TreeNode("Entry " + i);
                 child.Tag = list[i];
                 node.Nodes.Add(child);
             }
         }
         else if (importtype == Multis.ImportType.UOADESIGN)
         {
             List<Object[]> list = Ultima.Multis.LoadFromDesigner(dialog.FileName);
             TreeNode node = treeViewMultiList.Nodes[1].Nodes[5];
             node.Nodes.Clear();
             for (int i = 0; i < list.Count; ++i)
             {
                 Object[] data = list[i];
                 TreeNode child = new TreeNode(data[0] + "(" + i + ")");
                 child.Tag = data[1];
                 node.Nodes.Add(child);
             }
         }
         else
         {
             MultiComponentList multi = Ultima.Multis.LoadFromFile(dialog.FileName, importtype);
             compList = new MultiEditorComponentList(multi, this);
             UndoList_Clear();
             MaxHeightTrackBar.Minimum = compList.zMin;
             MaxHeightTrackBar.Maximum = compList.zMax;
             MaxHeightTrackBar.Value = compList.zMax;
             textBox_SaveToID.Text = "0";
             numericUpDown_Size_Width.Value = compList.Width;
             numericUpDown_Size_Height.Value = compList.Height;
             numericUpDown_Selected_X.Maximum = compList.Width - 1;
             numericUpDown_Selected_Y.Maximum = compList.Height - 1;
             vScrollBar.Value = 0;
             hScrollBar.Value = 0;
             ScrollbarsSetValue();
             ForceRefresh = true;
             pictureBoxMulti.Invalidate();
         }
     }
     dialog.Dispose();
 }