示例#1
0
        public static unsafe void Load()
        {
            string path = Path.Combine(FileManager.UoFolderPath, "speech.mul");

            if (!File.Exists(path))
            {
                throw new FileNotFoundException();
            }

            UOFileMul file = new UOFileMul(path, false);

            List <SpeechEntry> entries = new List <SpeechEntry>();

            while (file.Position < file.Length)
            {
                int id     = (file.ReadByte() << 8) | file.ReadByte();
                int length = (file.ReadByte() << 8) | file.ReadByte();

                if (length > 0)
                {
                    entries.Add(new SpeechEntry(id, string.Intern(Encoding.UTF8.GetString((byte *)file.PositionAddress, length))));

                    file.Skip(length);
                }
            }

            _speech = entries.ToArray();
            file.Dispose();
        }
示例#2
0
        public static void Load()
        {
            string path = Path.Combine(FileManager.UoFolderPath, "tiledata.mul");

            if (!File.Exists(path))
            {
                throw new FileNotFoundException();
            }

            UOFileMul tiledata = new UOFileMul(path);


            bool isold = FileManager.ClientVersion < ClientVersions.CV_7090;

            int staticscount = !isold ?
                               (int)(tiledata.Length - (512 * Marshal.SizeOf <LandGroupNew>())) / Marshal.SizeOf <StaticGroupNew>()
                :
                               (int)(tiledata.Length - (512 * Marshal.SizeOf <LandGroupOld>())) / Marshal.SizeOf <StaticGroupOld>();

            if (staticscount > 2048)
            {
                staticscount = 2048;
            }

            tiledata.Seek(0);

            _landData   = new LandTiles[512 * 32];
            _staticData = new StaticTiles[staticscount * 32];

            for (int i = 0; i < 512; i++)
            {
                tiledata.Skip(4);
                for (int j = 0; j < 32; j++)
                {
                    int idx = (i * 32) + j;
                    _landData[idx].Flags = (TileFlag)(isold ? tiledata.ReadUInt() : tiledata.ReadULong());
                    _landData[idx].TexID = tiledata.ReadUShort();
                    _landData[idx].Name  = Encoding.UTF8.GetString(tiledata.ReadArray(20));
                }
            }

            for (int i = 0; i < staticscount; i++)
            {
                tiledata.Skip(4);
                for (int j = 0; j < 32; j++)
                {
                    int idx = (i * 32) + j;
                    _staticData[idx].Flags      = (TileFlag)(isold ? tiledata.ReadUInt() : tiledata.ReadULong());
                    _staticData[idx].Weight     = tiledata.ReadByte();
                    _staticData[idx].Layer      = tiledata.ReadByte();
                    _staticData[idx].Count      = tiledata.ReadInt();
                    _staticData[idx].AnimID     = tiledata.ReadUShort();
                    _staticData[idx].Hue        = tiledata.ReadUShort();
                    _staticData[idx].LightIndex = tiledata.ReadUShort();
                    _staticData[idx].Height     = tiledata.ReadByte();
                    _staticData[idx].Name       = Encoding.UTF8.GetString(tiledata.ReadArray(20));
                }
            }
        }
示例#3
0
        public static void Load()
        {
            if (_speeches.Count > 0)
            {
                return;
            }
            string path = Path.Combine(FileManager.UoFolderPath, "speech.mul");

            if (!File.Exists(path))
            {
                throw new FileNotFoundException();
            }
            UOFileMul file = new UOFileMul(path);
            Dictionary <int, List <Regex> > table = null;
            int lastIndex = -1;

            while (file.Position < file.Length)
            {
                ushort id     = (ushort)((file.ReadByte() << 8) | file.ReadByte());
                ushort length = (ushort)((file.ReadByte() << 8) | file.ReadByte());

                if (length > 128)
                {
                    length = 128;
                }
                string text = Encoding.UTF8.GetString(file.ReadArray <byte>(length)).Trim();

                if (text.Length == 0)
                {
                    continue;
                }

                if (table == null || lastIndex > id)
                {
                    if (id == 0 && text == "*withdraw*")
                    {
                        _speeches.Insert(0, table = new Dictionary <int, List <Regex> >());
                    }
                    else
                    {
                        _speeches.Add(table = new Dictionary <int, List <Regex> >());
                    }
                }

                lastIndex = id;
                table.TryGetValue(id, out List <Regex> regex);

                if (regex == null)
                {
                    table[id] = regex = new List <Regex>();
                }
                regex.Add(new Regex(text.Replace("*", @".*"), RegexOptions.IgnoreCase));

                //_keywords.Add(new KeywordEntry
                //    {Code = id, Text = Encoding.UTF8.GetString(_file.ReadArray<byte>(length)).Trim()});
            }

            file.Unload();
        }
示例#4
0
        private ushort[] GetLight(uint idx, out int width, out int height)
        {
            (int length, int extra, bool patched) = _file.SeekByEntryIndex((int)idx);
            width  = extra & 0xFFFF;
            height = (extra >> 16) & 0xFFFF;
            ushort[] pixels = new ushort[width * height];

            for (int i = 0; i < height; i++)
            {
                int pos = i * width;

                for (int j = 0; j < width; j++)
                {
                    ushort val = _file.ReadByte();
                    val             = (ushort)((val << 10) | (val << 5) | val);
                    pixels[pos + j] = (ushort)((val != 0 ? 0x8000 : 0) | val);
                }
            }

            return(pixels);
        }
示例#5
0
        public static void Load()
        {
            string path = Path.Combine(FileManager.UoFolderPath, "tiledata.mul");

            if (!File.Exists(path))
            {
                throw new FileNotFoundException();
            }
            UOFileMul tiledata     = new UOFileMul(path, false);
            bool      isold        = FileManager.ClientVersion < ClientVersions.CV_7090;
            int       staticscount = !isold ? (int)(tiledata.Length - 512 * UnsafeMemoryManager.SizeOf <LandGroupNew>()) / UnsafeMemoryManager.SizeOf <StaticGroupNew>() : (int)(tiledata.Length - 512 * UnsafeMemoryManager.SizeOf <LandGroupOld>()) / UnsafeMemoryManager.SizeOf <StaticGroupOld>();

            if (staticscount > 2048)
            {
                staticscount = 2048;
            }
            tiledata.Seek(0);
            LandData   = new LandTiles[512 * 32];
            StaticData = new StaticTiles[staticscount * 32];
            byte[] bufferString = new byte[20];

            for (int i = 0; i < 512; i++)
            {
                tiledata.Skip(4);

                for (int j = 0; j < 32; j++)
                {
                    if (tiledata.Position + (isold ? 4 : 8) + 2 + 20 > tiledata.Length)
                    {
                        goto END;
                    }
                    int idx = i * 32 + j;
                    LandData[idx].Flags = isold ? tiledata.ReadUInt() : tiledata.ReadULong();
                    LandData[idx].TexID = tiledata.ReadUShort();
                    tiledata.Fill(bufferString, 20);
                    LandData[idx].Name = string.Intern(Encoding.UTF8.GetString(bufferString).TrimEnd('\0'));
                }
            }

END:

            for (int i = 0; i < staticscount; i++)
            {
                if (tiledata.Position >= tiledata.Length)
                {
                    goto END_2;
                }
                tiledata.Skip(4);

                for (int j = 0; j < 32; j++)
                {
                    if (tiledata.Position + (isold ? 4 : 8) + 13 + 20 > tiledata.Length)
                    {
                        goto END_2;
                    }
                    int idx = i * 32 + j;
                    StaticData[idx].Flags      = isold ? tiledata.ReadUInt() : tiledata.ReadULong();
                    StaticData[idx].Weight     = tiledata.ReadByte();
                    StaticData[idx].Layer      = tiledata.ReadByte();
                    StaticData[idx].Count      = tiledata.ReadInt();
                    StaticData[idx].AnimID     = tiledata.ReadUShort();
                    StaticData[idx].Hue        = tiledata.ReadUShort();
                    StaticData[idx].LightIndex = tiledata.ReadUShort();
                    StaticData[idx].Height     = tiledata.ReadByte();
                    tiledata.Fill(bufferString, 20);
                    StaticData[idx].Name = string.Intern(Encoding.UTF8.GetString(bufferString).TrimEnd('\0'));
                }
            }

END_2:
            tiledata.Dispose();

            //string pathdef = Path.Combine(FileManager.UoFolderPath, "art.def");
            //if (!File.Exists(pathdef))
            //    return;

            //using (StreamReader reader = new StreamReader(File.OpenRead(pathdef)))
            //{
            //    string line;
            //    while ((line = reader.ReadLine()) != null)
            //    {
            //        line = line.Trim();
            //        if (line.Length <= 0 || line[0] == '#')
            //            continue;
            //        string[] defs = line.Split(new[] { '\t', ' ', '#' }, StringSplitOptions.RemoveEmptyEntries);
            //        if (defs.Length < 2)
            //            continue;

            //        int index = int.Parse(defs[0]);

            //        if (index < 0 || index >= MAX_LAND_DATA_INDEX_COUNT + StaticData.Length)
            //            continue;

            //        int first = defs[1].IndexOf("{");
            //        int last = defs[1].IndexOf("}");

            //        string[] newdef = defs[1].Substring(first + 1, last - 1).Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);

            //        foreach (string s in newdef)
            //        {
            //            int checkindex = int.Parse(s);

            //            if (checkindex < 0 || checkindex >= MAX_LAND_DATA_INDEX_COUNT + StaticData.Length)
            //                continue;

            //            //_file.Entries[index] = _file.Entries[checkindex];

            //            if (index < MAX_LAND_DATA_INDEX_COUNT && checkindex < MAX_LAND_DATA_INDEX_COUNT && LandData.Length > checkindex && !LandData[checkindex].Equals(default) && (LandData.Length <= index  || LandData[index].Equals(default)))
            //            {
            //                LandData[index] = LandData[checkindex];
            //            }
            //            else if (index >= MAX_LAND_DATA_INDEX_COUNT && checkindex >= MAX_LAND_DATA_INDEX_COUNT)
            //            {
            //                checkindex -= MAX_LAND_DATA_INDEX_COUNT;
            //                checkindex &= 0x3FFF;
            //                index -= MAX_LAND_DATA_INDEX_COUNT;

            //                if ( (StaticData.Length <= index || StaticData[index].Equals(default)) &&
            //                    StaticData.Length > checkindex && !StaticData[checkindex].Equals(default))
            //                {

            //                    StaticData[index] = StaticData[checkindex];

            //                    break;
            //                }

            //            }
            //        }
            //    }
            //}
        }
示例#6
0
        public override void Load()
        {
            string path = Path.Combine(FileManager.UoFolderPath, "tiledata.mul");

            if (!File.Exists(path))
            {
                throw new FileNotFoundException();
            }
            UOFileMul tiledata     = new UOFileMul(path, true);
            bool      isold        = FileManager.ClientVersion < ClientVersions.CV_7090;
            int       staticscount = !isold ? (int)(tiledata.Length - 512 * UnsafeMemoryManager.SizeOf <LandGroupNew>()) / UnsafeMemoryManager.SizeOf <StaticGroupNew>() : (int)(tiledata.Length - 512 * UnsafeMemoryManager.SizeOf <LandGroupOld>()) / UnsafeMemoryManager.SizeOf <StaticGroupOld>();

            if (staticscount > 2048)
            {
                staticscount = 2048;
            }
            tiledata.Seek(0);
            _landData   = new LandTiles[Constants.MAX_LAND_DATA_INDEX_COUNT];
            _staticData = new StaticTiles[staticscount * 32];
            byte[] bufferString = new byte[20];

            for (int i = 0; i < 512; i++)
            {
                tiledata.Skip(4);

                for (int j = 0; j < 32; j++)
                {
                    if (tiledata.Position + (isold ? 4 : 8) + 2 + 20 > tiledata.Length)
                    {
                        goto END;
                    }
                    int    idx    = i * 32 + j;
                    ulong  flags  = isold ? tiledata.ReadUInt() : tiledata.ReadULong();
                    ushort textId = tiledata.ReadUShort();
                    tiledata.Fill(ref bufferString, 20);
                    string name = string.Intern(Encoding.UTF8.GetString(bufferString).TrimEnd('\0'));
                    LandData[idx] = new LandTiles(flags, textId, name);
                }
            }

END:

            for (int i = 0; i < staticscount; i++)
            {
                if (tiledata.Position >= tiledata.Length)
                {
                    break;
                }
                tiledata.Skip(4);

                for (int j = 0; j < 32; j++)
                {
                    if (tiledata.Position + (isold ? 4 : 8) + 13 + 20 > tiledata.Length)
                    {
                        goto END_2;
                    }
                    int idx = i * 32 + j;

                    ulong  flags      = isold ? tiledata.ReadUInt() : tiledata.ReadULong();
                    byte   weight     = tiledata.ReadByte();
                    byte   layer      = tiledata.ReadByte();
                    int    count      = tiledata.ReadInt();
                    ushort animId     = tiledata.ReadUShort();
                    ushort hue        = tiledata.ReadUShort();
                    ushort lightIndex = tiledata.ReadUShort();
                    byte   height     = tiledata.ReadByte();
                    tiledata.Fill(ref bufferString, 20);
                    string name = string.Intern(Encoding.UTF8.GetString(bufferString).TrimEnd('\0'));

                    StaticData[idx] = new StaticTiles(flags, weight, layer, count, animId, hue, lightIndex, height, name);
                }
            }



            //path = Path.Combine(FileManager.UoFolderPath, "tileart.uop");

            //if (File.Exists(path))
            //{
            //    UOFileUop uop = new UOFileUop(path, ".bin");
            //    DataReader reader = new DataReader();
            //    for (int i = 0; i < uop.Entries.Length; i++)
            //    {
            //        long offset = uop.Entries[i].Offset;
            //        int csize = uop.Entries[i].Length;
            //        int dsize = uop.Entries[i].DecompressedLength;

            //        if (offset == 0)
            //            continue;

            //        uop.Seek(offset);
            //        byte[] cdata = uop.ReadArray<byte>(csize);
            //        byte[] ddata = new byte[dsize];

            //        ZLib.Decompress(cdata, 0, ddata, dsize);

            //        reader.SetData(ddata, dsize);

            //        ushort version = reader.ReadUShort();
            //        uint stringDicOffset = reader.ReadUInt();
            //        uint tileID = reader.ReadUInt();

            //        reader.Skip(1 + // bool unk
            //                    1 + // unk
            //                    4 + // float unk
            //                    4 + // float unk
            //                    4 + // fixed zero ?
            //                    4 + // old id ?
            //                    4 + // unk
            //                    4 + // unk
            //                    1 + // unk
            //                    4 + // 3F800000
            //                    4 + // unk
            //                    4 + // float light
            //                    4 + // float light
            //                    4   // unk
            //                    );

            //        ulong flags = reader.ReadULong();
            //        ulong flags2 = reader.ReadULong();

            //        reader.Skip(4); // unk

            //        reader.Skip(24); // EC IMAGE OFFSET
            //        byte[] imageOffset = reader.ReadArray(24); // 2D IMAGE OFFSET


            //        if (tileID + 0x4000 == 0xa28d)
            //        {
            //            TileFlag f = (TileFlag) flags;

            //        }

            //        int count = reader.ReadByte();
            //        for (int j = 0; j < count; j++)
            //        {
            //            byte prop = reader.ReadByte();
            //            uint value = reader.ReadUInt();
            //        }

            //        count = reader.ReadByte();
            //        for (int j = 0; j < count; j++)
            //        {
            //            byte prop = reader.ReadByte();
            //            uint value = reader.ReadUInt();
            //        }

            //        count = reader.ReadInt(); // Gold Silver
            //        for (int j = 0; j < count; j++)
            //        {
            //            uint amount = reader.ReadUInt();
            //            uint id = reader.ReadUInt();
            //        }

            //        count = reader.ReadInt();

            //        for (int j = 0; j < count; j++)
            //        {
            //            byte val = reader.ReadByte();

            //            if (val != 0)
            //            {
            //                if (val == 1)
            //                {
            //                    byte unk = reader.ReadByte();
            //                    uint unk1 = reader.ReadUInt();
            //                }

            //            }
            //            else
            //            {
            //                int subCount = reader.ReadInt();

            //                for (int k = 0; k < subCount; k++)
            //                {
            //                    uint unk = reader.ReadUInt();
            //                    uint unk1 = reader.ReadUInt();
            //                }
            //            }
            //        }

            //        count = reader.ReadByte();

            //        if (count != 0)
            //        {
            //            uint unk = reader.ReadUInt();
            //            uint unk1 = reader.ReadUInt();
            //            uint unk2 = reader.ReadUInt();
            //            uint unk3 = reader.ReadUInt();
            //        }



            //        if (StaticData[tileID].AnimID == 0)
            //        {
            //            //StaticData[tileID] = new StaticTiles(flags, 0, 0, 0, );
            //        }


            //    }

            //    uop.Dispose();
            //    reader.ReleaseData();
            //}

            string pathdef = Path.Combine(FileManager.UoFolderPath, "art.def");

            if (File.Exists(pathdef))
            {
                using (DefReader reader = new DefReader(pathdef, 1))
                {
                    while (reader.Next())
                    {
                        int index = reader.ReadInt();

                        if (index < 0 || index >= Constants.MAX_LAND_DATA_INDEX_COUNT + StaticData.Length)
                        {
                            continue;
                        }

                        int[] group = reader.ReadGroup();

                        for (int i = 0; i < group.Length; i++)
                        {
                            int checkIndex = group[i];

                            if (checkIndex < 0 || checkIndex >= Constants.MAX_LAND_DATA_INDEX_COUNT + StaticData.Length)
                            {
                                continue;
                            }

                            if (index < Constants.MAX_LAND_DATA_INDEX_COUNT && checkIndex < Constants.MAX_LAND_DATA_INDEX_COUNT && checkIndex < LandData.Length && index < LandData.Length && !LandData[checkIndex].Equals(default) && LandData[index].Equals(default))
        public override Task Load()
        {
            return(Task.Run
                   (
                       () =>
            {
                string path = UOFileManager.GetUOFilePath("tiledata.mul");

                FileSystemHelper.EnsureFileExists(path);

                UOFileMul tileData = new UOFileMul(path);


                bool isold = Client.Version < ClientVersion.CV_7090;
                const int LAND_SIZE = 512;

                int land_group = isold ? Marshal.SizeOf <LandGroupOld>() : Marshal.SizeOf <LandGroupNew>();
                int static_group = isold ? Marshal.SizeOf <StaticGroupOld>() : Marshal.SizeOf <StaticGroupNew>();
                int staticscount = (int)((tileData.Length - LAND_SIZE * land_group) / static_group);

                if (staticscount > 2048)
                {
                    staticscount = 2048;
                }

                tileData.Seek(0);

                _landData = new LandTiles[Constants.MAX_LAND_DATA_INDEX_COUNT];
                _staticData = new StaticTiles[staticscount * 32];
                byte[] bufferString = new byte[20];

                for (int i = 0; i < 512; i++)
                {
                    tileData.Skip(4);

                    for (int j = 0; j < 32; j++)
                    {
                        if (tileData.Position + (isold ? 4 : 8) + 2 + 20 > tileData.Length)
                        {
                            goto END;
                        }

                        int idx = i * 32 + j;
                        ulong flags = isold ? tileData.ReadUInt() : tileData.ReadULong();
                        ushort textId = tileData.ReadUShort();
                        tileData.Fill(ref bufferString, 20);

                        string name = string.Intern(Encoding.UTF8.GetString(bufferString).TrimEnd('\0'));

                        LandData[idx] = new LandTiles(flags, textId, name);
                    }
                }

                END:

                for (int i = 0; i < staticscount; i++)
                {
                    if (tileData.Position >= tileData.Length)
                    {
                        break;
                    }

                    tileData.Skip(4);

                    for (int j = 0; j < 32; j++)
                    {
                        if (tileData.Position + (isold ? 4 : 8) + 13 + 20 > tileData.Length)
                        {
                            goto END_2;
                        }

                        int idx = i * 32 + j;

                        ulong flags = isold ? tileData.ReadUInt() : tileData.ReadULong();
                        byte weight = tileData.ReadByte();
                        byte layer = tileData.ReadByte();
                        int count = tileData.ReadInt();
                        ushort animId = tileData.ReadUShort();
                        ushort hue = tileData.ReadUShort();
                        ushort lightIndex = tileData.ReadUShort();
                        byte height = tileData.ReadByte();
                        tileData.Fill(ref bufferString, 20);

                        string name = string.Intern(Encoding.UTF8.GetString(bufferString).TrimEnd('\0'));

                        StaticData[idx] = new StaticTiles
                                          (
                            flags,
                            weight,
                            layer,
                            count,
                            animId,
                            hue,
                            lightIndex,
                            height,
                            name
                                          );
                    }
                }


                //path = Path.Combine(FileManager.UoFolderPath, "tileart.uop");

                //if (File.Exists(path))
                //{
                //    UOFileUop uop = new UOFileUop(path, ".bin");
                //    DataReader reader = new DataReader();
                //    for (int i = 0; i < uop.Entries.Length; i++)
                //    {
                //        long offset = uop.Entries[i].Offset;
                //        int csize = uop.Entries[i].Length;
                //        int dsize = uop.Entries[i].DecompressedLength;

                //        if (offset == 0)
                //            continue;

                //        uop.Seek(offset);
                //        byte[] cdata = uop.ReadArray<byte>(csize);
                //        byte[] ddata = new byte[dsize];

                //        ZLib.Decompress(cdata, 0, ddata, dsize);

                //        reader.SetData(ddata, dsize);

                //        ushort version = reader.ReadUShort();
                //        uint stringDicOffset = reader.ReadUInt();
                //        uint tileID = reader.ReadUInt();

                //        reader.Skip(1 + // bool unk
                //                    1 + // unk
                //                    4 + // float unk
                //                    4 + // float unk
                //                    4 + // fixed zero ?
                //                    4 + // old id ?
                //                    4 + // unk
                //                    4 + // unk
                //                    1 + // unk
                //                    4 + // 3F800000
                //                    4 + // unk
                //                    4 + // float light
                //                    4 + // float light
                //                    4   // unk
                //                    );

                //        ulong flags = reader.ReadULong();
                //        ulong flags2 = reader.ReadULong();

                //        reader.Skip(4); // unk

                //        reader.Skip(24); // EC IMAGE OFFSET
                //        byte[] imageOffset = reader.ReadArray(24); // 2D IMAGE OFFSET


                //        if (tileID + 0x4000 == 0xa28d)
                //        {
                //            TileFlag f = (TileFlag) flags;

                //        }

                //        int count = reader.ReadByte();
                //        for (int j = 0; j < count; j++)
                //        {
                //            byte prop = reader.ReadByte();
                //            uint value = reader.ReadUInt();
                //        }

                //        count = reader.ReadByte();
                //        for (int j = 0; j < count; j++)
                //        {
                //            byte prop = reader.ReadByte();
                //            uint value = reader.ReadUInt();
                //        }

                //        count = reader.ReadInt(); // Gold Silver
                //        for (int j = 0; j < count; j++)
                //        {
                //            uint amount = reader.ReadUInt();
                //            uint id = reader.ReadUInt();
                //        }

                //        count = reader.ReadInt();

                //        for (int j = 0; j < count; j++)
                //        {
                //            byte val = reader.ReadByte();

                //            if (val != 0)
                //            {
                //                if (val == 1)
                //                {
                //                    byte unk = reader.ReadByte();
                //                    uint unk1 = reader.ReadUInt();
                //                }

                //            }
                //            else
                //            {
                //                int subCount = reader.ReadInt();

                //                for (int k = 0; k < subCount; k++)
                //                {
                //                    uint unk = reader.ReadUInt();
                //                    uint unk1 = reader.ReadUInt();
                //                }
                //            }
                //        }

                //        count = reader.ReadByte();

                //        if (count != 0)
                //        {
                //            uint unk = reader.ReadUInt();
                //            uint unk1 = reader.ReadUInt();
                //            uint unk2 = reader.ReadUInt();
                //            uint unk3 = reader.ReadUInt();
                //        }


                //        if (StaticData[tileID].AnimID == 0)
                //        {
                //            //StaticData[tileID] = new StaticTiles(flags, 0, 0, 0, );
                //        }


                //    }

                //    uop.Dispose();
                //    reader.ReleaseData();
                //}



                END_2:
                tileData.Dispose();
            }
                   ));
        }
示例#8
0
        public override void Load()
        {
            string path = Path.Combine(FileManager.UoFolderPath, "tiledata.mul");

            if (!File.Exists(path))
            {
                throw new FileNotFoundException();
            }
            UOFileMul tiledata     = new UOFileMul(path, false);
            bool      isold        = FileManager.ClientVersion < ClientVersions.CV_7090;
            int       staticscount = !isold ? (int)(tiledata.Length - 512 * UnsafeMemoryManager.SizeOf <LandGroupNew>()) / UnsafeMemoryManager.SizeOf <StaticGroupNew>() : (int)(tiledata.Length - 512 * UnsafeMemoryManager.SizeOf <LandGroupOld>()) / UnsafeMemoryManager.SizeOf <StaticGroupOld>();

            if (staticscount > 2048)
            {
                staticscount = 2048;
            }
            tiledata.Seek(0);
            LandData   = new LandTiles[Constants.MAX_LAND_DATA_INDEX_COUNT];
            StaticData = new StaticTiles[staticscount * 32];
            byte[] bufferString = new byte[20];

            for (int i = 0; i < 512; i++)
            {
                tiledata.Skip(4);

                for (int j = 0; j < 32; j++)
                {
                    if (tiledata.Position + (isold ? 4 : 8) + 2 + 20 > tiledata.Length)
                    {
                        goto END;
                    }
                    int    idx    = i * 32 + j;
                    ulong  flags  = isold ? tiledata.ReadUInt() : tiledata.ReadULong();
                    ushort textId = tiledata.ReadUShort();
                    tiledata.Fill(ref bufferString, 20);
                    string name = string.Intern(Encoding.UTF8.GetString(bufferString).TrimEnd('\0'));
                    LandData[idx] = new LandTiles(flags, textId, name);
                }
            }

END:

            for (int i = 0; i < staticscount; i++)
            {
                if (tiledata.Position >= tiledata.Length)
                {
                    goto END_2;
                }
                tiledata.Skip(4);

                for (int j = 0; j < 32; j++)
                {
                    if (tiledata.Position + (isold ? 4 : 8) + 13 + 20 > tiledata.Length)
                    {
                        goto END_2;
                    }
                    int idx = i * 32 + j;

                    ulong  flags      = isold ? tiledata.ReadUInt() : tiledata.ReadULong();
                    byte   weight     = tiledata.ReadByte();
                    byte   layer      = tiledata.ReadByte();
                    int    count      = tiledata.ReadInt();
                    ushort animId     = tiledata.ReadUShort();
                    ushort hue        = tiledata.ReadUShort();
                    ushort lightIndex = tiledata.ReadUShort();
                    byte   height     = tiledata.ReadByte();
                    tiledata.Fill(ref bufferString, 20);
                    string name = string.Intern(Encoding.UTF8.GetString(bufferString).TrimEnd('\0'));

                    StaticData[idx] = new StaticTiles(flags, weight, layer, count, animId, hue, lightIndex, height, name);
                }
            }

END_2:
            tiledata.Dispose();



            //path = Path.Combine(FileManager.UoFolderPath, "tileart.uop");

            //if (File.Exists(path))
            //{
            //    UOFileUop uop = new UOFileUop(path, ".bin");
            //    DataReader reader = new DataReader();
            //    for (int i = 0; i < uop.Entries.Length; i++)
            //    {
            //        long offset = uop.Entries[i].Offset;
            //        int csize = uop.Entries[i].Length;
            //        int dsize = uop.Entries[i].DecompressedLength;

            //        if (offset == 0)
            //            continue;

            //        uop.Seek(offset);
            //        byte[] cdata = uop.ReadArray<byte>(csize);
            //        byte[] ddata = new byte[dsize];

            //        ZLib.Decompress(cdata, 0, ddata, dsize);

            //        reader.SetData(ddata, dsize);

            //        ushort version = reader.ReadUShort();
            //        uint stringDicOffset = reader.ReadUInt();
            //        uint tileID = reader.ReadUInt();

            //        reader.Skip(1 + // bool unk
            //                    1 + // unk
            //                    4 + // float unk
            //                    4 + // float unk
            //                    4 + // fixed zero ?
            //                    4 + // old id ?
            //                    4 + // unk
            //                    4 + // unk
            //                    1 + // unk
            //                    4 + // 3F800000
            //                    4 + // unk
            //                    4 + // float light
            //                    4 + // float light
            //                    4   // unk
            //                    );

            //        ulong flags = reader.ReadULong();
            //        ulong flags2 = reader.ReadULong();

            //        reader.Skip(4); // unk

            //        reader.Skip(24); // EC IMAGE OFFSET
            //        byte[] imageOffset = reader.ReadArray(24); // 2D IMAGE OFFSET


            //        if (tileID + 0x4000 == 0xa28d)
            //        {
            //            TileFlag f = (TileFlag) flags;

            //        }

            //        int count = reader.ReadByte();
            //        for (int j = 0; j < count; j++)
            //        {
            //            byte prop = reader.ReadByte();
            //            uint value = reader.ReadUInt();
            //        }

            //        count = reader.ReadByte();
            //        for (int j = 0; j < count; j++)
            //        {
            //            byte prop = reader.ReadByte();
            //            uint value = reader.ReadUInt();
            //        }

            //        count = reader.ReadInt(); // Gold Silver
            //        for (int j = 0; j < count; j++)
            //        {
            //            uint amount = reader.ReadUInt();
            //            uint id = reader.ReadUInt();
            //        }

            //        count = reader.ReadInt();

            //        for (int j = 0; j < count; j++)
            //        {
            //            byte val = reader.ReadByte();

            //            if (val != 0)
            //            {
            //                if (val == 1)
            //                {
            //                    byte unk = reader.ReadByte();
            //                    uint unk1 = reader.ReadUInt();
            //                }

            //            }
            //            else
            //            {
            //                int subCount = reader.ReadInt();

            //                for (int k = 0; k < subCount; k++)
            //                {
            //                    uint unk = reader.ReadUInt();
            //                    uint unk1 = reader.ReadUInt();
            //                }
            //            }
            //        }

            //        count = reader.ReadByte();

            //        if (count != 0)
            //        {
            //            uint unk = reader.ReadUInt();
            //            uint unk1 = reader.ReadUInt();
            //            uint unk2 = reader.ReadUInt();
            //            uint unk3 = reader.ReadUInt();
            //        }



            //        if (StaticData[tileID].AnimID == 0)
            //        {
            //            //StaticData[tileID] = new StaticTiles(flags, 0, 0, 0, );
            //        }


            //    }

            //    uop.Dispose();
            //    reader.ReleaseData();
            //}

            //string pathdef = Path.Combine(FileManager.UoFolderPath, "FileManager.Art.def");
            //if (!File.Exists(pathdef))
            //    return;

            //using (StreamReader reader = new StreamReader(File.OpenRead(pathdef)))
            //{
            //    string line;
            //    while ((line = reader.ReadLine()) != null)
            //    {
            //        line = line.Trim();
            //        if (line.Length <= 0 || line[0] == '#')
            //            continue;
            //        string[] defs = line.Split(new[] { '\t', ' ', '#' }, StringSplitOptions.RemoveEmptyEntries);
            //        if (defs.Length < 2)
            //            continue;

            //        int index = int.Parse(defs[0]);

            //        if (index < 0 || index >= MAX_LAND_DATA_INDEX_COUNT + StaticData.Length)
            //            continue;

            //        int first = defs[1].IndexOf("{");
            //        int last = defs[1].IndexOf("}");

            //        string[] newdef = defs[1].Substring(first + 1, last - 1).Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);

            //        foreach (string s in newdef)
            //        {
            //            int checkindex = int.Parse(s);

            //            if (checkindex < 0 || checkindex >= MAX_LAND_DATA_INDEX_COUNT + StaticData.Length)
            //                continue;

            //            //_file.Entries[index] = _file.Entries[checkindex];

            //            if (index < MAX_LAND_DATA_INDEX_COUNT && checkindex < MAX_LAND_DATA_INDEX_COUNT && LandData.Length > checkindex && !LandData[checkindex].Equals(default) && (LandData.Length <= index  || LandData[index].Equals(default)))
            //            {
            //                LandData[index] = LandData[checkindex];
            //            }
            //            else if (index >= MAX_LAND_DATA_INDEX_COUNT && checkindex >= MAX_LAND_DATA_INDEX_COUNT)
            //            {
            //                checkindex -= MAX_LAND_DATA_INDEX_COUNT;
            //                checkindex &= 0x3FFF;
            //                index -= MAX_LAND_DATA_INDEX_COUNT;

            //                if ( (StaticData.Length <= index || StaticData[index].Equals(default)) &&
            //                    StaticData.Length > checkindex && !StaticData[checkindex].Equals(default))
            //                {

            //                    StaticData[index] = StaticData[checkindex];

            //                    break;
            //                }

            //            }
            //        }
            //    }
            //}
        }
示例#9
0
        private int PatchStatics(TileMatrix matrix, string path, string pathidx, string pathlookup)
        {
            UOFileMul file   = new UOFileMul(path, pathidx, 0);
            UOFileMul lookup = new UOFileMul(pathlookup);

            int count = Math.Min((int)file.IdxFile.Length / 4, (int)lookup.Length / 12);

            file.Seek(0);
            file.IdxFile.Seek(0);
            lookup.Seek(0);

            HuedTileList[][] lists = new HuedTileList[8][];

            for (int x = 0; x < 8; x++)
            {
                lists[x] = new HuedTileList[8];
                for (int y = 0; y < 8; y++)
                {
                    lists[x][y] = new HuedTileList();
                }
            }

            for (int i = 0; i < count; i++)
            {
                int blockID = file.IdxFile.ReadInt();
                int blockX  = blockID / matrix.BlockHeight;
                int blockY  = blockID % matrix.BlockHeight;

                int offset = lookup.ReadInt();
                int length = lookup.ReadInt();

                lookup.Skip(4);

                if (offset < 0 || length < 0)
                {
                    if (StaticBlocks[blockX] == null)
                    {
                        StaticBlocks[blockX] = new HuedTile[matrix.BlockHeight][][][];
                    }
                    StaticBlocks[blockX][blockY] = TileMatrix.EmptyStaticBlock;
                    continue;
                }

                file.Seek(offset);

                int tileCount = length / 7;
                if (_tileBuffer.Length < tileCount)
                {
                    _tileBuffer = new StaticTile[tileCount];
                }

                StaticTile[] statiles = _tileBuffer;

                for (int j = 0; j < tileCount; j++)
                {
                    statiles[j].ID  = file.ReadUShort();
                    statiles[j].X   = file.ReadByte();
                    statiles[j].Y   = file.ReadByte();
                    statiles[j].Z   = file.ReadSByte();
                    statiles[j].Hue = file.ReadUShort();

                    lists[statiles[j].X & 0x7][statiles[j].Y & 0x7].Add(statiles[j].ID, statiles[j].Hue, statiles[j].Z);
                }

                HuedTile[][][] tiles = new HuedTile[8][][];

                for (int x = 0; x < 8; x++)
                {
                    tiles[x] = new HuedTile[8][];
                    for (int y = 0; y < 8; y++)
                    {
                        tiles[x][y] = lists[x][y].ToArray();
                    }
                }

                if (StaticBlocks[blockX] == null)
                {
                    StaticBlocks[blockX] = new HuedTile[matrix.BlockHeight][][][];
                }
                StaticBlocks[blockX][blockY] = tiles;
            }

            return(count);
        }