Beispiel #1
0
        public TileMatrix(InstallLocation install, int fileIndex, int mapID, int width, int height)
        {
            _width       = width;
            _height      = height;
            _blockWidth  = width >> 3;
            _blockHeight = height >> 3;

            if (fileIndex != 0x7F)
            {
                var mapPath = install.GetPath("map{0}.mul", fileIndex);

                if (File.Exists(mapPath))
                {
                    _map = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                }
                else
                {
                    mapPath = install.GetPath("map{0}LegacyMUL.uop", fileIndex);

                    if (File.Exists(mapPath))
                    {
                        _map      = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        _mapIndex = new UOPIndex(_map);
                    }
                }

                var indexPath = install.GetPath("staidx{0}.mul", fileIndex);

                if (File.Exists(indexPath))
                {
                    _fileIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    _reader    = new BinaryReader(_fileIndex);
                }

                var staticsPath = install.GetPath("statics{0}.mul", fileIndex);

                if (File.Exists(staticsPath))
                {
                    _staticsStream = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                }
            }

            _emptyStaticBlock = new HuedTile[8][][];

            for (var i = 0; i < 8; ++i)
            {
                _emptyStaticBlock[i] = new HuedTile[8][];

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

            _invalidLandBlock = new Tile[196];
        }
Beispiel #2
0
        public TileMatrix(InstallLocation install, int fileIndex, int mapID, int width, int height)
        {
            _install     = install;
            _width       = width;
            _height      = height;
            _blockWidth  = width >> 3;
            _blockHeight = height >> 3;

            if (fileIndex != 0x7F)
            {
                string mapPath     = install.GetPath("map{0}.mul", fileIndex);
                string indexPath   = install.GetPath("staidx{0}.mul", fileIndex);
                string staticsPath = install.GetPath("statics{0}.mul", fileIndex);

                if (!File.Exists(mapPath))
                {
                    mapPath = install.GetPath("map{0}LegacyMUL.uop", fileIndex);
                }

                _map           = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                _fileIndex     = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                _staticsStream = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read);

                _reader = new BinaryReader(_fileIndex);
            }

            _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, install, mapID);

            /*for ( int i = 0; i < m_BlockWidth; ++i )
             * {
             *  m_LandTiles[i] = new Tile[m_BlockHeight][];
             *  m_StaticTiles[i] = new Tile[m_BlockHeight][][][];
             * }*/
        }
Beispiel #3
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;
        }
Beispiel #4
0
        public TileMatrix(InstallLocation install, int fileIndex, int mapID, int width, int height)
        {
            _install = install;
            _width = width;
            _height = height;
            _blockWidth = width >> 3;
            _blockHeight = height >> 3;

            if (fileIndex != 0x7F)
            {
                string mapPath = install.GetPath("map{0}.mul", fileIndex);
                string indexPath = install.GetPath("staidx{0}.mul", fileIndex);
                string staticsPath = install.GetPath("statics{0}.mul", fileIndex);

                if (!File.Exists(mapPath))
                    mapPath = install.GetPath("map{0}LegacyMUL.uop", fileIndex);

                _map = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                _fileIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                _staticsStream = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read);

                _reader = new BinaryReader(_fileIndex);
            }

            _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, install, mapID);

            /*for ( int i = 0; i < m_BlockWidth; ++i )
            {
                m_LandTiles[i] = new Tile[m_BlockHeight][];
                m_StaticTiles[i] = new Tile[m_BlockHeight][][][];
            }*/
        }
Beispiel #5
0
        public HuedTile[][][] GetStaticBlock(int x, int y)
        {
            if (x < 0 || y < 0 || x >= _blockWidth || y >= _blockHeight || _staticsStream == null || _fileIndex == null)
            {
                return(_emptyStaticBlock);
            }

            if (_staticTiles[x] == null)
            {
                _staticTiles[x] = new HuedTile[_blockHeight][][][];
            }

            HuedTile[][][] tiles = _staticTiles[x][y] ?? (_staticTiles[x][y] = ReadStaticBlock(x, y));

            return(tiles);
        }
Beispiel #6
0
        private unsafe HuedTile[][][] ReadStaticBlock(int x, int y)
        {
            _reader.BaseStream.Seek(((x * _blockHeight) + y) * 12, SeekOrigin.Begin);

            var lookup = _reader.ReadInt32();
            var length = _reader.ReadInt32();

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

            var count = length / 7;

            _staticsStream.Seek(lookup, SeekOrigin.Begin);

            var staTiles = new StaticTileData[count];

            fixed(StaticTileData *pTiles = staTiles)
            {
                NativeMethods._lread(_staticsStream.SafeFileHandle, pTiles, length);

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

                    for (var i = 0; i < 8; ++i)
                    {
                        _hueTileLists[i] = new HuedTileList[8];

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

                var lists = _hueTileLists;

                StaticTileData *pCur = pTiles, pEnd = pTiles + count;

                while (pCur < pEnd)
                {
                    lists[pCur->X & 0x7][pCur->Y & 0x7].Add((short)((pCur->Id & 0x3FFF) + 0x4000), pCur->Hue, pCur->Z);
                    ++pCur;
                }

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

                for (var i = 0; i < 8; ++i)
                {
                    tiles[i] = new HuedTile[8][];

                    for (var j = 0; j < 8; ++j)
                    {
                        tiles[i][j] = lists[i][j].ToArray();
                    }
                }

                return(tiles);
            }
        }
Beispiel #7
0
        private static unsafe int PatchStatics(TileMatrix matrix, string dataPath, string indexPath, string lookupPath)
        {
            using(var fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using(var fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using(var fsLookup = new FileStream(lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        var indexReader = new BinaryReader(fsIndex);
                        var lookupReader = new BinaryReader(fsLookup);

                        var count = (int)(indexReader.BaseStream.Length / 4);

                        var lists = new HuedTileList[8][];

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

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

                        for(var i = 0; i < count; ++i)
                        {
                            var blockID = indexReader.ReadInt32();
                            var blockX = blockID / matrix.BlockHeight;
                            var blockY = blockID % matrix.BlockHeight;

                            var offset = lookupReader.ReadInt32();
                            var length = lookupReader.ReadInt32();
                            lookupReader.ReadInt32(); // Extra

                            if(offset < 0 || length <= 0)
                            {
                                //matrix.SetStaticBlock(blockX, blockY, matrix.EmptyStaticBlock);
                                continue;
                            }

                            fsData.Seek(offset, SeekOrigin.Begin);

                            var tileCount = length / 7;

                            var staTiles = new StaticTileData[tileCount];

                            fixed(StaticTileData* pTiles = staTiles)
                            {
                                NativeMethods._lread(fsData.SafeFileHandle, pTiles, length);

                                StaticTileData* pCur = pTiles, pEnd = pTiles + tileCount;

                                while(pCur < pEnd)
                                {
                                    lists[pCur->X & 0x7][pCur->Y & 0x7].Add((short)((pCur->Id & 0x3FFF) + 0x4000), pCur->Hue, pCur->Z);
                                    ++pCur;
                                }

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

                                for(var x = 0; x < 8; ++x)
                                {
                                    tiles[x] = new HuedTile[8][];

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

                                //matrix.SetStaticBlock(blockX, blockY, tiles);
                            }
                        }

                        return count;
                    }
                }
            }
        }
Beispiel #8
0
        private unsafe HuedTile[][][] ReadStaticBlock(int x, int y)
        {
            _reader.BaseStream.Seek(((x * _blockHeight) + y) * 12, SeekOrigin.Begin);

            int lookup = _reader.ReadInt32();
            int length = _reader.ReadInt32();

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

            int count = length / 7;

            _staticsStream.Seek(lookup, SeekOrigin.Begin);

            StaticTile[] staTiles = new StaticTile[count];

            fixed (StaticTile* pTiles = staTiles)
            {
                NativeMethods._lread(_staticsStream.SafeFileHandle, pTiles, length);

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

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

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

                HuedTileList[][] lists = _hueTileLists;

                StaticTile* pCur = pTiles, pEnd = pTiles + count;

                while (pCur < pEnd)
                {
                    lists[pCur->X & 0x7][pCur->Y & 0x7].Add((short)((pCur->Id & 0x3FFF) + 0x4000), pCur->Hue, pCur->Z);
                    ++pCur;
                }

                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] = lists[i][j].ToArray();
                }

                return tiles;
            }
        }
Beispiel #9
0
        public HuedTile[][][] GetStaticBlock(int x, int y)
        {
            if (x < 0 || y < 0 || x >= _blockWidth || y >= _blockHeight || _staticsStream == null || _fileIndex == null)
                return _emptyStaticBlock;

            if (_staticTiles[x] == null)
                _staticTiles[x] = new HuedTile[_blockHeight][][][];

            HuedTile[][][] tiles = _staticTiles[x][y] ?? (_staticTiles[x][y] = ReadStaticBlock(x, y));

            return tiles;
        }
Beispiel #10
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;
        }
Beispiel #11
0
        private static unsafe int PatchStatics(TileMatrix matrix, string dataPath, string indexPath, string lookupPath)
        {
            using (FileStream fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (FileStream fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (FileStream fsLookup = new FileStream(lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        BinaryReader indexReader  = new BinaryReader(fsIndex);
                        BinaryReader lookupReader = new BinaryReader(fsLookup);

                        int count = (int)(indexReader.BaseStream.Length / 4);

                        var 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 = indexReader.ReadInt32();
                            int blockX  = blockID / matrix.BlockHeight;
                            int blockY  = blockID % matrix.BlockHeight;

                            int offset = lookupReader.ReadInt32();
                            int length = lookupReader.ReadInt32();
                            lookupReader.ReadInt32();                             // Extra

                            if (offset < 0 || length <= 0)
                            {
                                //matrix.SetStaticBlock(blockX, blockY, matrix.EmptyStaticBlock);
                                continue;
                            }

                            fsData.Seek(offset, SeekOrigin.Begin);

                            int tileCount = length / 7;

                            var staTiles = new StaticTileData[tileCount];

                            fixed(StaticTileData *pTiles = staTiles)
                            {
                                NativeMethods._lread(fsData.SafeFileHandle, pTiles, length);

                                StaticTileData *pCur = pTiles, pEnd = pTiles + tileCount;

                                while (pCur < pEnd)
                                {
                                    lists[pCur->X & 0x7][pCur->Y & 0x7].Add((short)((pCur->Id & 0x3FFF) + 0x4000), pCur->Hue, pCur->Z);
                                    ++pCur;
                                }

                                var 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();
                                    }
                                }

                                //matrix.SetStaticBlock(blockX, blockY, tiles);
                            }
                        }

                        return(count);
                    }
                }
            }
        }