Beispiel #1
0
        private unsafe byte[] readStaticBlock_Bytes(int x, int y)
        {
            try
            {
                m_IndexReader.BaseStream.Seek(((x * m_BlockHeight) + y) * 12, SeekOrigin.Begin);

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

                if (lookup < 0 || length <= 0)
                {
                    return(m_EmptyStaticsBlock);
                }
                else
                {
                    m_Statics.Seek(lookup, SeekOrigin.Begin);

                    byte[] staticTiles = new byte[length];

                    fixed(byte *pStaticTiles = staticTiles)
                    {
                        SharedMethods.Read(m_Statics.SafeFileHandle, pStaticTiles, length);
                    }
                    return(staticTiles);
                }
            }
            catch (EndOfStreamException)
            {
                throw new Exception("End of stream in static block!");
                // return m_EmptyStaticsBlock;
            }
        }
Beispiel #2
0
        private unsafe int PatchLand(TileMatrix tileMatrix, string dataPath, string indexPath)
        {
            using (FileStream fsData = FileManager.GetFile(dataPath))
            {
                using (FileStream fsIndex = FileManager.GetFile(indexPath))
                {
                    BinaryReader indexReader = new BinaryReader(fsIndex);

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

                    for (int i = 0; i < count; ++i)
                    {
                        int blockID = indexReader.ReadInt32();
                        int x       = blockID / tileMatrix.BlockHeight;
                        int y       = blockID % tileMatrix.BlockHeight;

                        fsData.Seek(4, SeekOrigin.Current);

                        Tile[] tiles = new Tile[64];

                        fixed(Tile *pTiles = tiles)
                        {
                            SharedMethods.Read(fsData.SafeFileHandle, pTiles, 192);
                        }

                        tileMatrix.SetLandBlock(x, y, tiles);
                    }

                    indexReader.Close();

                    return(count);
                }
            }
        }
Beispiel #3
0
        private unsafe byte[] readLandBlock_Bytes(int x, int y)
        {
            if (x < 0)
            {
                x += Width;
            }
            if (x >= Width)
            {
                x -= Width;
            }
            if (y < 0)
            {
                y += Height;
            }
            if (y >= Height)
            {
                y -= Height;
            }

            int key   = (x << 16) + y;
            int index = x % 16 + (y % 16) * 16;

            if (m_bufferedLandBlocks_Keys[index] == key)
            {
                return(m_bufferedLandBlocks[index]);
            }

            m_bufferedLandBlocks_Keys[index] = key;

            m_MapStream.Seek(((x * m_BlockHeight) + y) * m_size_LandBlock + 4, SeekOrigin.Begin);
            int streamStart = (int)m_MapStream.Position;

            fixed(byte *pData = m_bufferedLandBlocks[index])
            {
                SharedMethods.Read(m_MapStream.SafeFileHandle, pData, m_size_LandBlockData);
            }

            Metrics.ReportDataRead((int)m_MapStream.Position - streamStart);

            return(m_bufferedLandBlocks[index]);
        }
Beispiel #4
0
        private unsafe Tile[] ReadLandBlock(int x, int y)
        {
            try
            {
                m_MapStream.Seek(((x * m_BlockHeight) + y) * 196 + 4, SeekOrigin.Begin);

                int streamStart = (int)m_MapStream.Position;

                Tile[] tiles = new Tile[64];

                fixed(Tile *pTiles = tiles)
                {
                    SharedMethods.Read(m_MapStream.SafeFileHandle, pTiles, 192);
                }

                Metrics.ReportDataRead((int)m_MapStream.Position - streamStart);

                return(tiles);
            }
            catch
            {
                return(m_InvalidLandBlock);
            }
        }
Beispiel #5
0
        private unsafe StaticTile[][][] ReadStaticBlock(int x, int y)
        {
            try
            {
                m_IndexReader.BaseStream.Seek(((x * m_BlockHeight) + y) * 12, SeekOrigin.Begin);

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

                if (lookup < 0 || length <= 0)
                {
                    return(m_EmptyStaticsBlock);
                }
                else
                {
                    int count = length / 7;

                    m_Statics.Seek(lookup, SeekOrigin.Begin);

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

                    StaticTile[] staticTiles = m_StaticTileBuffer;

                    fixed(StaticTile *pStaticTiles = staticTiles)
                    {
                        SharedMethods.Read(m_Statics.SafeFileHandle, pStaticTiles, length);

                        if (m_StaticTileLists == null)
                        {
                            m_StaticTileLists = new StaticTileList[8][];

                            for (int i = 0; i < 8; ++i)
                            {
                                m_StaticTileLists[i] = new StaticTileList[8];

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

                        StaticTileList[][] staticTileLists = m_StaticTileLists;

                        StaticTile *pCurrent = pStaticTiles;
                        StaticTile *pEnd     = pStaticTiles + count;

                        while (pCurrent < pEnd)
                        {
                            staticTileLists[pCurrent->X & 0x07][pCurrent->Y & 0x07].Add((short)((pCurrent->ID & 0x3FFF) + 0x4000), pCurrent->Z);

                            pCurrent++;
                        }

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

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

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

                        return(tiles);
                    }
                }
            }
            catch (EndOfStreamException)
            {
                return(m_EmptyStaticsBlock);
            }
        }
Beispiel #6
0
        private unsafe int PatchStatics(TileMatrix tileMatrix, string dataPath, string indexPath, string lookupPath)
        {
            using (FileStream fsData = FileManager.GetFile(dataPath))
            {
                using (FileStream fsIndex = FileManager.GetFile(indexPath))
                {
                    using (FileStream fsLookup = FileManager.GetFile(lookupPath))
                    {
                        BinaryReader indexReader  = new BinaryReader(fsIndex);
                        BinaryReader lookupReader = new BinaryReader(fsLookup);

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

                        StaticTileList[][] lists = new StaticTileList[8][];

                        for (int x = 0; x < 8; ++x)
                        {
                            lists[x] = new StaticTileList[8];

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

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

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

                            if (offset < 0 || length <= 0)
                            {
                                tileMatrix.SetStaticBlock(blockX, blockY, tileMatrix.EmptyStaticsBlock);

                                continue;
                            }

                            fsData.Seek(offset, SeekOrigin.Begin);

                            int tileCount = length / 7;

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

                            StaticTile[] staticTiles = m_TileBuffer;

                            fixed(StaticTile *pStaticTiles = staticTiles)
                            {
                                SharedMethods.Read(fsData.SafeFileHandle, pStaticTiles, length);

                                StaticTile *pCur = pStaticTiles, pEnd = pStaticTiles + tileCount;

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

                                    pCur = pCur + 1;
                                }

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

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

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

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

                        indexReader.Close();
                        lookupReader.Close();

                        return(count);
                    }
                }
            }
        }