Beispiel #1
0
        public override Task Load()
        {
            return(Task.Run(() =>
            {
                bool foundOneMap = false;

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

                    if (Client.IsUOPInstallation && 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, Constants.MAPS_COUNT, i =>
                {
                    MapBlocksSize[i, 0] = MapsDefaultSize[i, 0] >> 3;
                    MapBlocksSize[i, 1] = MapsDefaultSize[i, 1] >> 3;
                    LoadMap(i);
                });

                Entries = null;
            }));
        }
Beispiel #2
0
        public static unsafe void LoadMap(int i)
        {
            int mapblocksize       = UnsafeMemoryManager.SizeOf <MapBlock>();
            int staticidxblocksize = UnsafeMemoryManager.SizeOf <StaidxBlock>();
            int staticblocksize    = UnsafeMemoryManager.SizeOf <StaticsBlock>();
            int width         = MapBlocksSize[i, 0];
            int height        = MapBlocksSize[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);

                if (address < endmapaddress)
                {
                    realmapaddress = address;
                }
                ulong        stidxaddress = staticidxaddress + (ulong)(block * staticidxblocksize);
                StaidxBlock *bb           = (StaidxBlock *)stidxaddress;

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

                    if (address1 < endstaticaddress)
                    {
                        realstaticaddress = address1;
                        realstaticcount   = (uint)(bb->Size / staticblocksize);

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

                BlockData[i][block] = new IndexMap(realmapaddress, realstaticaddress, realstaticcount, realmapaddress, realstaticaddress, realstaticcount);
            }
        }
Beispiel #3
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);
            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))
Beispiel #4
0
        internal unsafe void LoadMap(int i)
        {
            if (i < 0 || i + 1 > Constants.MAPS_COUNT || _filesMap[i] == null)
            {
                i = 0;
            }

            if (BlockData[i] != null || _filesMap[i] == null)
            {
                return;
            }

            int mapblocksize       = UnsafeMemoryManager.SizeOf <MapBlock>();
            int staticidxblocksize = UnsafeMemoryManager.SizeOf <StaidxBlock>();
            int staticblocksize    = UnsafeMemoryManager.SizeOf <StaticsBlock>();
            int width         = MapBlocksSize[i, 0];
            int height        = MapBlocksSize[i, 1];
            int maxblockcount = width * height;

            BlockData[i] = new IndexMap[maxblockcount];
            UOFile file       = _filesMap[i];
            UOFile fileidx    = _filesIdxStatics[i];
            UOFile staticfile = _filesStatics[i];

            if (fileidx == null && i == 1)
            {
                fileidx = _filesIdxStatics[0];
            }

            if (staticfile == null && i == 1)
            {
                staticfile = _filesStatics[0];
            }

            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 < Entries[i].Length)
                        {
                            uopoffset = (ulong)Entries[i][shifted].Offset;
                        }
                    }
                }

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

                if (address < endmapaddress)
                {
                    realmapaddress = address;
                }
                ulong        stidxaddress = staticidxaddress + (ulong)(block * staticidxblocksize);
                StaidxBlock *bb           = (StaidxBlock *)stidxaddress;

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

                    if (address1 < endstaticaddress)
                    {
                        realstaticaddress = address1;
                        realstaticcount   = (uint)(bb->Size / staticblocksize);

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

                ref var data = ref BlockData[i][block];
                data.MapAddress            = realmapaddress;
                data.StaticAddress         = realstaticaddress;
                data.StaticCount           = realstaticcount;
                data.OriginalMapAddress    = realmapaddress;
                data.OriginalStaticAddress = realstaticaddress;
                data.OriginalStaticCount   = realstaticcount;
            }
Beispiel #5
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, ".dat", loadentries: false);
                        foundOneMap = true;
                    }
                    else
                    {
                        path = Path.Combine(FileManager.UoFolderPath, $"map{i}.mul");

                        if (File.Exists(path))
                        {
                            _filesMap[i] = new UOFileMul(path, false);
                            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, false);
                    }
                    path = Path.Combine(FileManager.UoFolderPath, $"staidx{i}.mul");
                    if (File.Exists(path))
                    {
                        _filesIdxStatics[i] = new UOFileMul(path, false);
                    }
                }

                if (!foundOneMap)
                {
                    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++)
                Parallel.For(0, MAPS_COUNT, i =>
                {
                    MapBlocksSize[i, 0] = MapsDefaultSize[i, 0] >> 3;
                    MapBlocksSize[i, 1] = MapsDefaultSize[i, 1] >> 3;
                    LoadMap(i);
                });
            }));
        }
Beispiel #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, 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;
            //                }

            //            }
            //        }
            //    }
            //}
        }
Beispiel #7
0
            internal unsafe void ReloadBlock(int map, int blocknum)
            {
                int    mapblocksize       = UnsafeMemoryManager.SizeOf <MapBlock>();
                int    staticidxblocksize = UnsafeMemoryManager.SizeOf <StaidxBlock>();
                int    staticblocksize    = UnsafeMemoryManager.SizeOf <StaticsBlock>();
                UOFile file = _filesMap[map];
                UOFile fileidx = _filesIdxStatics[map];
                UOFile staticfile = _filesStatics[map];
                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;
                ulong  realmapaddress = 0, realstaticaddress = 0;
                uint   realstaticcount = 0;
                int    block           = blocknum;

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

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

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

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

                if (address < endmapaddress)
                {
                    realmapaddress = address;
                }
                ulong        stidxaddress = staticidxaddress + (ulong)(block * staticidxblocksize);
                StaidxBlock *bb           = (StaidxBlock *)stidxaddress;

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

                    if (address1 < endstaticaddress)
                    {
                        realstaticaddress = address1;
                        realstaticcount   = (uint)(bb->Size / staticblocksize);

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

                ref var data = ref BlockData[map][block];
Beispiel #8
0
        public override void Load()
        {
            string path    = Path.Combine(FileManager.UoFolderPath, "multi.mul");
            string pathidx = Path.Combine(FileManager.UoFolderPath, "multi.idx");

            if (File.Exists(path) && File.Exists(pathidx))
            {
                _file = new UOFileMul(path, pathidx, Constants.MAX_MULTI_DATA_INDEX_COUNT, 14);
            }
            else
            {
                throw new FileNotFoundException();
            }

            Count = _itemOffset = FileManager.ClientVersion >= ClientVersions.CV_7090 ? UnsafeMemoryManager.SizeOf <MultiBlockNew>() : UnsafeMemoryManager.SizeOf <MultiBlock>();


            string uopPath = Path.Combine(FileManager.UoFolderPath, "MultiCollection.uop");

            if (File.Exists(uopPath))
            {
                Count    = Constants.MAX_MULTI_DATA_INDEX_COUNT;
                _fileUop = new UOFileUopNoFormat(uopPath);
                _reader  = new DataReader();

                for (int i = 0; i < _fileUop.Entries.Length; i++)
                {
                    long offset = _fileUop.Entries[i].Offset;
                    int  csize  = _fileUop.Entries[i].Length;
                    int  dsize  = _fileUop.Entries[i].DecompressedLength;

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

                    ZLib.Decompress(cdata, 0, ddata, dsize);
                    _reader.SetData(ddata, dsize);

                    uint id = _reader.ReadUInt();

                    if (id < Constants.MAX_MULTI_DATA_INDEX_COUNT && id < _file.Entries.Length)
                    {
                        ref UOFileIndex3D index = ref _file.Entries[id];
                        int count = _reader.ReadInt();

                        index = new UOFileIndex3D(offset, csize, dsize, (int)MathHelper.Combine(count, index.Extra));
                    }
                }

                _reader.ReleaseData();
            }
Beispiel #9
0
        public unsafe bool ApplyPatches(Packet reader)
        {
            ResetPatchesInBlockTable();

            PatchesCount = (int)reader.ReadUInt();

            if (PatchesCount < 0)
            {
                PatchesCount = 0;
            }

            if (PatchesCount > MAPS_COUNT)
            {
                PatchesCount = MAPS_COUNT;
            }

            MapPatchCount.ForEach(s => s    = 0);
            StaticPatchCount.ForEach(s => s = 0);

            bool result = false;

            for (int i = 0; i < PatchesCount; i++)
            {
                if (_filesMap[i] == null || _filesMap[i].StartAddress == IntPtr.Zero)
                {
                    reader.Skip(8);
                    continue;
                }

                int mapPatchesCount = (int)reader.ReadUInt();
                MapPatchCount[i] = mapPatchesCount;
                int staticPatchesCount = (int)reader.ReadUInt();
                StaticPatchCount[i] = staticPatchesCount;

                int w = MapBlocksSize[i, 0];
                int h = MapBlocksSize[i, 1];

                int maxBlockCount = w * h;

                if (mapPatchesCount != 0)
                {
                    var difl = _mapDifl[i];
                    var dif  = _mapDif[i];

                    if (difl == null || dif == null)
                    {
                        continue;
                    }

                    mapPatchesCount = Math.Min(mapPatchesCount, (int)(difl.Length / 4));

                    difl.Seek(0);
                    dif.Seek(0);

                    for (int j = 0; j < mapPatchesCount; j++)
                    {
                        uint blockIndex = difl.ReadUInt();

                        if (blockIndex < maxBlockCount)
                        {
                            BlockData[i][blockIndex].MapAddress = (ulong)dif.PositionAddress;
                            result = true;
                        }

                        dif.Skip(UnsafeMemoryManager.SizeOf <MapBlock>());
                    }
                }

                if (staticPatchesCount != 0)
                {
                    var difl = _staDifl[i];
                    var difi = _staDifi[i];

                    if (difl == null || difi == null || _staDif[i] == null)
                    {
                        continue;
                    }

                    ulong startAddress = (ulong)_staDif[i].StartAddress;

                    staticPatchesCount = Math.Min(staticPatchesCount, (int)(difl.Length / 4));

                    difl.Seek(0);
                    difi.Seek(0);

                    int sizeOfStaicsBlock = UnsafeMemoryManager.SizeOf <StaticsBlock>();

                    for (int j = 0; j < staticPatchesCount; j++)
                    {
                        uint         blockIndex = difl.ReadUInt();
                        StaidxBlock *sidx       = (StaidxBlock *)difi.PositionAddress;

                        difi.Skip(sizeof(StaidxBlock));

                        if (blockIndex < maxBlockCount)
                        {
                            ulong realStaticAddress = 0;
                            int   realStaticCount   = 0;

                            if (sidx->Size > 0 && sidx->Position != 0xFFFF_FFFF)
                            {
                                realStaticAddress = startAddress + sidx->Position;
                                realStaticCount   = (int)(sidx->Size / sizeOfStaicsBlock);

                                if (realStaticCount > 0)
                                {
                                    if (realStaticCount > 1024)
                                    {
                                        realStaticCount = 1024;
                                    }
                                }
                            }

                            BlockData[i][blockIndex].StaticAddress = realStaticAddress;
                            BlockData[i][blockIndex].StaticCount   = (uint)realStaticCount;

                            result = true;
                        }
                    }
                }
            }

            return(result);
        }
Beispiel #10
0
        public override Task Load()
        {
            return(Task.Run(() =>
            {
                string uopPath = UOFileManager.GetUOFilePath("MultiCollection.uop");

                if (Client.IsUOPInstallation && System.IO.File.Exists(uopPath))
                {
                    Count = Constants.MAX_MULTI_DATA_INDEX_COUNT;
                    _file = new UOFileUop(uopPath, "build/multicollection/{0:D6}.bin");
                    Entries = new UOFileIndex[Count];
                    _reader = new DataReader();
                    IsUOP = true;
                }
                else
                {
                    string path = UOFileManager.GetUOFilePath("multi.mul");
                    string pathidx = UOFileManager.GetUOFilePath("multi.idx");

                    if (System.IO.File.Exists(path) && System.IO.File.Exists(pathidx))
                    {
                        _file = new UOFileMul(path, pathidx, Constants.MAX_MULTI_DATA_INDEX_COUNT, 14);
                        Count = _itemOffset = Client.Version >= ClientVersion.CV_7090 ? UnsafeMemoryManager.SizeOf <MultiBlockNew>() + 2 : UnsafeMemoryManager.SizeOf <MultiBlock>();
                    }
                }

                _file.FillEntries(ref Entries);
            }));
        }
Beispiel #11
0
        public override Task Load()
        {
            return(Task.Run(() =>
            {
                string uopPath = Path.Combine(FileManager.UoFolderPath, "MultiCollection.uop");

                if (File.Exists(uopPath))
                {
                    Count = Constants.MAX_MULTI_DATA_INDEX_COUNT;
                    _file = new UOFileUop(uopPath, "build/multicollection/{0:D6}.bin");
                    Entries = new UOFileIndex[Count];
                    _reader = new DataReader();
                }
                else
                {
                    string path = Path.Combine(FileManager.UoFolderPath, "multi.mul");
                    string pathidx = Path.Combine(FileManager.UoFolderPath, "multi.idx");

                    if (File.Exists(path) && File.Exists(pathidx))
                    {
                        _file = new UOFileMul(path, pathidx, Constants.MAX_MULTI_DATA_INDEX_COUNT, 14);
                        Count = _itemOffset = FileManager.ClientVersion >= ClientVersions.CV_7090 ? UnsafeMemoryManager.SizeOf <MultiBlockNew>() : UnsafeMemoryManager.SizeOf <MultiBlock>();
                    }
                }

                _file.FillEntries(ref Entries);
            }));
        }
Beispiel #12
0
        public static void Load()
        {
            string path    = Path.Combine(FileManager.UoFolderPath, "multi.mul");
            string pathidx = Path.Combine(FileManager.UoFolderPath, "multi.idx");

            if (File.Exists(path) && File.Exists(pathidx))
            {
                _file = new UOFileMul(path, pathidx, 0x2000, 14);
            }
            else
            {
                throw new FileNotFoundException();
            }
            _itemOffset = FileManager.ClientVersion >= ClientVersions.CV_7090 ? UnsafeMemoryManager.SizeOf <MultiBlockNew>() : UnsafeMemoryManager.SizeOf <MultiBlock>();
        }