Пример #1
0
        public HuedTile[][][] GetStaticBlock(int x, int y, bool patch)
        {
            if (x < 0 || y < 0 || x >= BlockWidth || y >= BlockHeight)
            {
                return(EmptyStaticBlock);
            }
            if (_staticTiles[x] == null)
            {
                _staticTiles[x] = new HuedTile[BlockHeight][][][];
            }

            HuedTile[][][] tiles = _staticTiles[x][y];

            if (tiles == null)
            {
                tiles = _staticTiles[x][y] = ReadStaticBlock(x, y);
            }

            if (patch) // Use DIFF?????!?!??
            {
                if (Patch.StaticBlocksCount > 0)
                {
                    if (Patch.StaticBlocks[x] != null)
                    {
                        if (Patch.StaticBlocks[x][y] != null)
                        {
                            tiles = Patch.StaticBlocks[x][y];
                        }
                    }
                }
            }

            return(tiles);
        }
Пример #2
0
        public TileMatrixPatch(TileMatrix matrix, int index)
        {
            _blockWidth  = matrix.BlockWidth;
            _blockHeight = matrix.BlockHeight;

            LandBlocksCount = StaticBlocksCount = 0;

            string pathmapdifl    = Path.Combine(FileManager.UoFolderPath, string.Format("mapdif{0}.mul", index));
            string pathmapdiflidx = Path.Combine(FileManager.UoFolderPath, string.Format("mapdifl{0}.mul", index));

            if (File.Exists(pathmapdifl) && File.Exists(pathmapdiflidx))
            {
                LandBlocks      = new Tile[matrix.BlockWidth][][];
                LandBlocksCount = PatchLand(matrix, pathmapdifl, pathmapdiflidx);
            }

            string pathstadata   = Path.Combine(FileManager.UoFolderPath, string.Format("stadif{0}.mul", index));
            string pathindexdata = Path.Combine(FileManager.UoFolderPath, string.Format("stadifl{0}.mul", index));
            string pathlookup    = Path.Combine(FileManager.UoFolderPath, string.Format("stadifi{0}.mul", index));

            if (File.Exists(pathstadata) && File.Exists(pathindexdata) && File.Exists(pathlookup))
            {
                StaticBlocks      = new HuedTile[matrix.BlockWidth][][][][];
                StaticBlocksCount = PatchStatics(matrix, pathstadata, pathindexdata, pathlookup);
            }
        }
Пример #3
0
        /// <summary>
        /// Important: x >> 3, y >> 3
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        private HuedTile[][][] ReadStaticBlock(int x, int y)
        {
            int lookup = (int)_staticIndex[(x * BlockHeight) + y].Offset;
            int length = _staticIndex[(x * BlockHeight) + y].Length;

            if (lookup < 0 || length <= 0)
            {
                return(EmptyStaticBlock);
            }

            int count = length / 7;

            _filestatics.Seek(lookup);

            if (_list == null)
            {
                _list = new HuedTileList[8][];

                for (int i = 0; i < 8; i++)
                {
                    _list[i] = new HuedTileList[8];
                    for (int j = 0; j < 8; j++)
                    {
                        _list[i][j] = new HuedTileList();
                    }
                }
            }

            HuedTileList[][] list = _list;

            for (int i = 0; i < count; i++)
            {
                StaticTile tile = new StaticTile()
                {
                    ID  = _filestatics.ReadUShort(),
                    X   = _filestatics.ReadByte(),
                    Y   = _filestatics.ReadByte(),
                    Z   = _filestatics.ReadSByte(),
                    Hue = _filestatics.ReadUShort()
                };

                list[tile.X & 0x7][tile.Y & 0x7].Add(tile.ID, tile.Hue, tile.Z);
            }

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

            for (int i = 0; i < 8; i++)
            {
                tiles[i] = new HuedTile[8][];
                for (int j = 0; j < 8; j++)
                {
                    tiles[i][j] = list[i][j].ToArray();
                }
            }

            return(tiles);
        }
Пример #4
0
 public HuedTile[] ToArray()
 {
     HuedTile[] tiles = new HuedTile[Count];
     if (_tiles.Count > 0)
     {
         _tiles.CopyTo(tiles);
     }
     _tiles.Clear();
     return(tiles);
 }
Пример #5
0
        public void SetStaticBlock(int x, int y, HuedTile[][][] value)
        {
            if (x < 0 || y < 0 || x >= BlockWidth || y >= BlockHeight)
            {
                return;
            }

            if (_staticTiles[x] == null)
            {
                _staticTiles[x] = new HuedTile[BlockHeight][][][];
            }
            _staticTiles[x][y] = value;
        }
Пример #6
0
 public void RemoveStaticBlock(int x, int y)
 {
     if (_removedStaticBlock == null)
     {
         _removedStaticBlock = new bool[BlockWidth][];
     }
     if (_removedStaticBlock[x] == null)
     {
         _removedStaticBlock[x] = new bool[BlockHeight];
     }
     _removedStaticBlock[x][y] = true;
     if (_staticTiles[x] == null)
     {
         _staticTiles[x] = new HuedTile[BlockHeight][][][];
     }
     _staticTiles[x][y] = EmptyStaticBlock;
 }
Пример #7
0
        public TileMatrix(int map, int width, int height)
        {
            Width       = width; Height = height;
            BlockWidth  = width >> 3;
            BlockHeight = height >> 3;

            string pathmap = Path.Combine(FileManager.UoFolderPath, string.Format("map{0}LegacyMUL.uop", map));

            if (File.Exists(pathmap))
            {
                _file = new UOFileUop(pathmap, ".dat");
            }
            else
            {
                pathmap = Path.Combine(FileManager.UoFolderPath, string.Format("map{0}.mul", map));
                if (!File.Exists(pathmap))
                {
                    throw new FileNotFoundException();
                }
                _file = new UOFileMul(pathmap);
            }

            string pathstaidx = Path.Combine(FileManager.UoFolderPath, string.Format("staidx{0}.mul", map));

            if (!File.Exists(pathstaidx))
            {
                throw new FileNotFoundException();
            }
            _filestaidx = new UOFileMul(pathstaidx);


            string pathstatics = Path.Combine(FileManager.UoFolderPath, string.Format("statics{0}.mul", map));

            if (!File.Exists(pathstatics))
            {
                throw new FileNotFoundException();
            }
            _filestatics = new UOFileMul(pathstatics);


            EmptyStaticBlock = new HuedTile[8][][];

            for (int i = 0; i < 8; i++)
            {
                EmptyStaticBlock[i] = new HuedTile[8][];
                for (int j = 0; j < 8; j++)
                {
                    EmptyStaticBlock[i][j] = new HuedTile[0];
                }
            }

            InvalidLandBlock = new Tile[196];

            _landTiles   = new Tile[BlockWidth][][];
            _staticTiles = new HuedTile[BlockWidth][][][][];

            Patch = new TileMatrixPatch(this, map);


            _staticIndex = new UOFileIndex3D[BlockHeight * BlockWidth];

            int count  = (int)_filestaidx.Length / 12;
            int minlen = (int)Math.Min(_filestaidx.Length, BlockHeight * BlockWidth);

            for (int i = 0; i < count; i++)
            {
                _staticIndex[i].Offset = _filestaidx.ReadInt();
                _staticIndex[i].Length = _filestaidx.ReadInt();
                _staticIndex[i].Extra  = _filestaidx.ReadInt();
            }

            for (int i = minlen; i < BlockHeight * BlockWidth; i++)
            {
                _staticIndex[i].Offset = -1;
                _staticIndex[i].Length = -1;
                _staticIndex[i].Extra  = -1;
            }
        }
Пример #8
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);
        }