示例#1
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;
            //                }

            //            }
            //        }
            //    }
            //}
        }
示例#2
0
        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();
                //}

                string pathdef = UOFileManager.GetUOFilePath("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();

                            if (group == null)
                            {
                                continue;
                            }

                            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))
示例#3
0
        public override Task Load()
        {
            return(Task.Run(() =>
            {
                bool foundOneMap = false;

                for (int i = 0; i < MAPS_COUNT; i++)
                {
                    string path = UOFileManager.GetUOFilePath($"map{i}LegacyMUL.uop");

                    if (File.Exists(path))
                    {
                        _filesMap[i] = new UOFileUop(path, $"build/map{i}legacymul/{{0:D8}}.dat");
                        Entries[i] = new UOFileIndex[((UOFileUop)_filesMap[i]).TotalEntriesCount];
                        ((UOFileUop)_filesMap[i]).FillEntries(ref Entries[i], false);
                        foundOneMap = true;
                    }
                    else
                    {
                        path = UOFileManager.GetUOFilePath($"map{i}.mul");

                        if (File.Exists(path))
                        {
                            _filesMap[i] = new UOFileMul(path);

                            foundOneMap = true;
                        }

                        path = UOFileManager.GetUOFilePath($"mapdifl{i}.mul");

                        if (File.Exists(path))
                        {
                            _mapDifl[i] = new UOFileMul(path);
                            _mapDif[i] = new UOFileMul(UOFileManager.GetUOFilePath($"mapdif{i}.mul"));
                            _staDifl[i] = new UOFileMul(UOFileManager.GetUOFilePath($"stadifl{i}.mul"));
                            _staDifi[i] = new UOFileMul(UOFileManager.GetUOFilePath($"stadifi{i}.mul"));
                            _staDif[i] = new UOFileMul(UOFileManager.GetUOFilePath($"stadif{i}.mul"));
                        }
                    }

                    path = UOFileManager.GetUOFilePath($"statics{i}.mul");
                    if (File.Exists(path))
                    {
                        _filesStatics[i] = new UOFileMul(path);
                    }
                    path = UOFileManager.GetUOFilePath($"staidx{i}.mul");
                    if (File.Exists(path))
                    {
                        _filesIdxStatics[i] = new UOFileMul(path);
                    }
                }

                if (!foundOneMap)
                {
                    throw new FileNotFoundException("No maps found.");
                }

                int mapblocksize = UnsafeMemoryManager.SizeOf <MapBlock>();

                if (_filesMap[0].Length / mapblocksize == 393216 || Client.Version < ClientVersion.CV_4011D)
                {
                    MapsDefaultSize[0, 0] = MapsDefaultSize[1, 0] = 6144;
                }

                // This is an hack to patch correctly all maps when you have to fake map1
                if (_filesMap[1] == null || _filesMap[1].StartAddress == IntPtr.Zero)
                {
                    _filesMap[1] = _filesMap[0];
                    _filesStatics[1] = _filesStatics[0];
                    _filesIdxStatics[1] = _filesIdxStatics[0];
                }

                //for (int i = 0; i < MAPS_COUNT; i++)
                Parallel.For(0, MAPS_COUNT, i =>
                {
                    MapBlocksSize[i, 0] = MapsDefaultSize[i, 0] >> 3;
                    MapBlocksSize[i, 1] = MapsDefaultSize[i, 1] >> 3;
                    LoadMap(i);
                });

                Entries = null;
            }));
        }
示例#4
0
 public override void ClearResources()
 {
     _file?.Dispose();
     _file     = null;
     _instance = null;
 }
示例#5
0
        public override void Load()
        {
            bool foundedOneMap = false;

            for (int i = 0; i < MAPS_COUNT; i++)
            {
                string path = Path.Combine(FileManager.UoFolderPath, $"map{i}LegacyMUL.uop");

                if (File.Exists(path))
                {
                    _filesMap[i]  = new UOFileUop(path, ".dat", loadentries: false);
                    foundedOneMap = true;
                }
                else
                {
                    path = Path.Combine(FileManager.UoFolderPath, $"map{i}.mul");

                    if (File.Exists(path))
                    {
                        _filesMap[i]  = new UOFileMul(path, false);
                        foundedOneMap = true;
                    }

                    path = Path.Combine(FileManager.UoFolderPath, $"mapdifl{i}.mul");

                    if (File.Exists(path))
                    {
                        _mapDifl[i] = new UOFileMul(path);
                        _mapDif[i]  = new UOFileMul(Path.Combine(FileManager.UoFolderPath, $"mapdif{i}.mul"));

                        _staDifl[i] = new UOFileMul(Path.Combine(FileManager.UoFolderPath, $"stadifl{i}.mul"));
                        _staDifi[i] = new UOFileMul(Path.Combine(FileManager.UoFolderPath, $"stadifi{i}.mul"));
                        _staDif[i]  = new UOFileMul(Path.Combine(FileManager.UoFolderPath, $"stadif{i}.mul"));
                    }
                }

                path = Path.Combine(FileManager.UoFolderPath, $"statics{i}.mul");
                if (File.Exists(path))
                {
                    _filesStatics[i] = new UOFileMul(path, false);
                }
                path = Path.Combine(FileManager.UoFolderPath, $"staidx{i}.mul");
                if (File.Exists(path))
                {
                    _filesIdxStatics[i] = new UOFileMul(path, false);
                }
            }

            if (!foundedOneMap)
            {
                throw new FileNotFoundException("No maps founded.");
            }
            int mapblocksize = UnsafeMemoryManager.SizeOf <MapBlock>();

            if (_filesMap[0].Length / mapblocksize == 393216 || FileManager.ClientVersion < ClientVersions.CV_4011D)
            {
                MapsDefaultSize[0, 0] = MapsDefaultSize[1, 0] = 6144;
            }

            for (int i = 0; i < MAPS_COUNT; i++)
            {
                MapBlocksSize[i, 0] = MapsDefaultSize[i, 0] >> 3;
                MapBlocksSize[i, 1] = MapsDefaultSize[i, 1] >> 3;

                if (Engine.GlobalSettings.PreloadMaps)
                {
                    LoadMap(i);
                }
            }
        }
示例#6
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 * 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];
            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;
            //                }

            //            }
            //        }
            //    }
            //}
        }
示例#7
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);
        }
示例#8
0
        public override Task Load()
        {
            return(Task.Run(() =>
            {
                bool foundOneMap = false;

                for (int i = 0; i < MAPS_COUNT; i++)
                {
                    string path = Path.Combine(FileManager.UoFolderPath, $"map{i}LegacyMUL.uop");

                    if (File.Exists(path))
                    {
                        _filesMap[i] = new UOFileUop(path, $"build/map{i}legacymul/{{0:D8}}.dat");
                        Entries[i] = new UOFileIndex[((UOFileUop)_filesMap[i]).TotalEntriesCount];
                        ((UOFileUop)_filesMap[i]).FillEntries(ref Entries[i], false);
                        foundOneMap = true;
                    }
                    else
                    {
                        path = Path.Combine(FileManager.UoFolderPath, $"map{i}.mul");

                        if (File.Exists(path))
                        {
                            _filesMap[i] = new UOFileMul(path);

                            foundOneMap = true;
                        }

                        path = Path.Combine(FileManager.UoFolderPath, $"mapdifl{i}.mul");

                        if (File.Exists(path))
                        {
                            _mapDifl[i] = new UOFileMul(path);
                            _mapDif[i] = new UOFileMul(Path.Combine(FileManager.UoFolderPath, $"mapdif{i}.mul"));
                            _staDifl[i] = new UOFileMul(Path.Combine(FileManager.UoFolderPath, $"stadifl{i}.mul"));
                            _staDifi[i] = new UOFileMul(Path.Combine(FileManager.UoFolderPath, $"stadifi{i}.mul"));
                            _staDif[i] = new UOFileMul(Path.Combine(FileManager.UoFolderPath, $"stadif{i}.mul"));
                        }
                    }

                    path = Path.Combine(FileManager.UoFolderPath, $"statics{i}.mul");
                    if (File.Exists(path))
                    {
                        _filesStatics[i] = new UOFileMul(path);
                    }
                    path = Path.Combine(FileManager.UoFolderPath, $"staidx{i}.mul");
                    if (File.Exists(path))
                    {
                        _filesIdxStatics[i] = new UOFileMul(path);
                    }
                }

                if (!foundOneMap)
                {
                    throw new FileNotFoundException("No maps found.");
                }

                int mapblocksize = UnsafeMemoryManager.SizeOf <MapBlock>();

                if (_filesMap[0].Length / mapblocksize == 393216 || FileManager.ClientVersion < ClientVersions.CV_4011D)
                {
                    MapsDefaultSize[0, 0] = MapsDefaultSize[1, 0] = 6144;
                }

                //for (int i = 0; i < MAPS_COUNT; i++)
                Parallel.For(0, MAPS_COUNT, i =>
                {
                    MapBlocksSize[i, 0] = MapsDefaultSize[i, 0] >> 3;
                    MapBlocksSize[i, 1] = MapsDefaultSize[i, 1] >> 3;
                    LoadMap(i);
                });

                Entries = null;
            }));
        }
示例#9
0
        public unsafe static void Load()
        {
            string path = string.Empty;

            for (int i = 0; i < MAPS_COUNT; i++)
            {
                path = Path.Combine(FileManager.UoFolderPath, string.Format("map{0}LegacyMUL.uop", i));
                if (File.Exists(path))
                {
                    _filesMap[i] = new UOFileUop(path, ".dat");
                }
                else
                {
                    path = Path.Combine(FileManager.UoFolderPath, string.Format("map{0}.mul", i));
                    if (!File.Exists(path))
                    {
                        throw new FileNotFoundException();
                    }

                    _filesMap[i] = new UOFileMul(path);
                }


                path = Path.Combine(FileManager.UoFolderPath, string.Format("statics{0}.mul", i));
                if (File.Exists(path))
                {
                    _filesStatics[i] = new UOFileMul(path);
                }

                path = Path.Combine(FileManager.UoFolderPath, string.Format("staidx{0}.mul", i));
                if (File.Exists(path))
                {
                    _filesIdxStatics[i] = new UOFileMul(path);
                }
            }


            if (FileManager.ClientVersion < ClientVersions.CV_4011D)
            {
                _mapsDefaultSize[0][0] = _mapsDefaultSize[1][0] = 6144;
            }

            int mapblocksize       = Marshal.SizeOf <MapBlock>();
            int staticidxblocksize = Marshal.SizeOf <StaidxBlock>();
            int staticblocksize    = Marshal.SizeOf <StaticsBlock>();

            for (int i = 0; i < MAPS_COUNT; i++)
            {
                _mapsBlockSize[i] = new int[2] {
                    _mapsDefaultSize[i][0] / 8, _mapsDefaultSize[i][1] / 8
                };


                int width  = _mapsBlockSize[i][0];
                int height = _mapsBlockSize[i][1];

                int maxblockcount = width * height;

                _blockData[i] = new IndexMap[maxblockcount];

                UOFile file       = _filesMap[i];
                UOFile fileidx    = _filesIdxStatics[i];
                UOFile staticfile = _filesStatics[i];

                ulong staticidxaddress    = (ulong)fileidx.StartAddress;
                ulong endstaticidxaddress = staticidxaddress + (ulong)fileidx.Length;

                ulong staticaddress    = (ulong)staticfile.StartAddress;
                ulong endstaticaddress = staticaddress + (ulong)staticfile.Length;

                ulong mapddress     = (ulong)file.StartAddress;
                ulong endmapaddress = mapddress + (ulong)file.Length;

                ulong uopoffset  = 0;
                int   fileNumber = -1;

                bool isuop = file is UOFileUop;

                for (int block = 0; block < maxblockcount; block++)
                {
                    ulong realmapaddress = 0, realstaticaddress = 0;
                    uint  realstaticcount = 0;

                    int blocknum = block;

                    if (isuop)
                    {
                        blocknum &= 4095;
                        int shifted = block >> 12;

                        if (fileNumber != shifted)
                        {
                            fileNumber = shifted;

                            if (shifted < file.Entries.Length)
                            {
                                uopoffset = (ulong)file.Entries[shifted].Offset;
                            }
                        }
                    }

                    ulong address = mapddress + uopoffset + (ulong)(blocknum * mapblocksize);

                    MapBlock mapblock = Marshal.PtrToStructure <MapBlock>((IntPtr)address);

                    if (address < endmapaddress)
                    {
                        realmapaddress = address;
                    }


                    ulong       stidxaddress = (staticidxaddress + (ulong)(block * staticidxblocksize));
                    StaidxBlock bb           = Marshal.PtrToStructure <StaidxBlock>((IntPtr)stidxaddress);

                    if (stidxaddress < endstaticidxaddress &&
                        bb.Size > 0 && bb.Position != 0xFFFFFFFF)
                    {
                        ulong address1 = staticaddress + bb.Position;

                        if (address1 < endstaticaddress)
                        {
                            StaticsBlock sss = Marshal.PtrToStructure <StaticsBlock>((IntPtr)address1);

                            realstaticaddress = address1;
                            realstaticcount   = (uint)(bb.Size / staticblocksize);

                            if (realstaticcount > 1024)
                            {
                                realstaticcount = 1024;
                            }
                        }
                    }


                    _blockData[i][block].OriginalMapAddress    = realmapaddress;
                    _blockData[i][block].OriginalStaticAddress = realstaticaddress;
                    _blockData[i][block].OriginalStaticCount   = realstaticcount;

                    _blockData[i][block].MapAddress    = realmapaddress;
                    _blockData[i][block].StaticAddress = realstaticaddress;
                    _blockData[i][block].StaticCount   = realstaticcount;
                }
            }
        }