Exemple #1
0
        private unsafe StaticTile[][][] ReadStaticBlock(int x, int y)
        {
            try
            {
                _staticsIndexReader.BaseStream.Seek((x * BlockHeight + y) * 12, SeekOrigin.Begin);

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

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

                var count = length / 7;

                StaticsDataStream.Seek(lookup, SeekOrigin.Begin);

                if (_tileBuffer.Length < count)
                {
                    _tileBuffer = new StaticTile[count];
                }

                var staTiles = _tileBuffer; // new StaticTile[tileCount];

                fixed(StaticTile *pTiles = staTiles)
                {
                    NativeReader.Read(StaticsDataStream.SafeFileHandle.DangerousGetHandle(), pTiles, length);
                    if (_lists == null)
                    {
                        _lists = new TileList[8][];

                        for (var i = 0; i < 8; ++i)
                        {
                            _lists[i] = new TileList[8];

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

                    var lists = _lists;

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

                    while (pCur < pEnd)
                    {
                        lists[pCur->_x & 0x7][pCur->_y & 0x7].Add(pCur->_id, pCur->_z);
                        pCur += 1;
                    }

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

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

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

                    return(tiles);
                }
            }
            catch (EndOfStreamException)
            {
                return(EmptyStaticBlock);
            }
        }
Exemple #2
0
        private unsafe int PatchStatics(TileMatrix matrix, string dataPath, string indexPath, string lookupPath)
        {
            using var staticsDataStream   = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read);
            using var staticsIndexStream  = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
            using var staticsLookupStream = new FileStream(lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read);
            var staticsIndexReader  = new BinaryReader(staticsIndexStream);
            var staticsLookupReader = new BinaryReader(staticsLookupStream);

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

            var lists = new TileList[8][];

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

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

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

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

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

                staticsDataStream.Seek(offset, SeekOrigin.Begin);

                var tileCount = length / 7;

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

                var staTiles = _tileBuffer;

                fixed(StaticTile *pTiles = staTiles)
                {
                    NativeReader.Read(staticsDataStream.SafeFileHandle.DangerousGetHandle(), pTiles, length);
                    StaticTile *pCur = pTiles, pEnd = pTiles + tileCount;

                    while (pCur < pEnd)
                    {
                        lists[pCur->X & 0x7][pCur->Y & 0x7].Add(pCur->Id, (sbyte)pCur->Z);
                        pCur += 1;
                    }

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

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

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

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

            staticsIndexReader.Close();
            staticsLookupReader.Close();

            return(count);
        }