Read() публичный статический Метод

public static Read ( IntPtr ptr, void buffer, int length ) : void
ptr System.IntPtr
buffer void
length int
Результат void
Пример #1
0
        private unsafe int PatchLand(TileMatrix matrix, string dataPath, string indexPath)
        {
            using var fsData  = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read);
            using var fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
            var indexReader = new BinaryReader(fsIndex);

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

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

                fsData.Seek(4, SeekOrigin.Current);

                var tiles = new LandTile[64];

                fixed(LandTile *pTiles = tiles)
                {
                    NativeReader.Read(fsData.SafeFileHandle.DangerousGetHandle(), pTiles, 192);
                }

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

            indexReader.Close();

            return(count);
        }
Пример #2
0
        private unsafe LandTile[] ReadLandBlock(int x, int y)
        {
            try
            {
                int offset = ((x * m_BlockHeight) + y) * 196 + 4;

                if (m_MapIndex != null)
                {
                    offset = m_MapIndex.Lookup(offset);
                }

                m_Map.Seek(offset, SeekOrigin.Begin);

                var tiles = new LandTile[64];

                fixed(LandTile *pTiles = tiles)
                {
                    NativeReader.Read(m_Map.SafeFileHandle.DangerousGetHandle(), pTiles, 192);
                }

                return(tiles);
            }
            catch
            {
                if (DateTime.UtcNow >= m_NextLandWarning)
                {
                    Console.WriteLine("Warning: Land EOS for {0} ({1}, {2})", m_Owner, x, y);
                    m_NextLandWarning = DateTime.UtcNow + TimeSpan.FromMinutes(1.0);
                }

                return(m_InvalidLandBlock);
            }
        }
Пример #3
0
        private unsafe LandTile[] ReadLandBlock(int x, int y)
        {
            try
            {
                m_Map.Seek(((x * m_BlockHeight) + y) * 196 + 4, SeekOrigin.Begin);

                LandTile[] tiles = new LandTile[64];

                fixed(LandTile *pTiles = tiles)
                {
#if !MONO
                    NativeReader.Read(m_Map.SafeFileHandle.DangerousGetHandle(), pTiles, 192);
#else
                    NativeReader.Read(m_Map.Handle, pTiles, 192);
#endif
                }

                return(tiles);
            }
            catch
            {
                if (DateTime.Now >= m_NextLandWarning)
                {
                    Console.WriteLine("Warning: Land EOS for {0} ({1}, {2})", m_Owner, x, y);
                    m_NextLandWarning = DateTime.Now + TimeSpan.FromMinutes(1.0);
                }

                return(m_InvalidLandBlock);
            }
        }
Пример #4
0
        private unsafe int PatchLand(TileMatrix matrix, string dataPath, string indexPath)
        {
            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 indexReader = new BinaryReader(fsIndex);

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

            for (var i = 0; i < count; i++)
            {
                var blockID = indexReader.ReadInt32();
                var x       = Math.DivRem(blockID, matrix.BlockHeight, out var y);

                fsData.Seek(4, SeekOrigin.Current);

                var tiles = new LandTile[64];

                fixed(LandTile *pTiles = tiles)
                {
                    NativeReader.Read(fsData, pTiles, 192);
                }

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

            return(count);
        }
Пример #5
0
        public FileIndex(string idxFile, string mulFile, int entryCount)
            : this(entryCount)
        {
            do
            {
                _IdxPath = Core.FindDataFile(idxFile);
                _BinPath = Core.FindDataFile(mulFile);

                try
                {
                    if (_IdxPath != null && System.IO.File.Exists(_IdxPath))
                    {
                        FileStream index;

                        try
                        { index = new FileStream(_IdxPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); }
                        catch { index = null; }

                        if (index != null)
                        {
                            using (index)
                            {
                                IdxLength = (int)index.Length;
                                IdxCount  = IdxLength / EntryDataSize;

                                if (Index.Length != IdxCount)
                                {
                                    Index = new Entry3D[IdxCount];
                                }

                                unsafe
                                {
                                    fixed(Entry3D *buffer = Index)
                                    NativeReader.Read(index, buffer, IdxLength);
                                }
                            }

                            _IdxLoaded = true;
                        }
                    }
                }
                catch { }

                try
                {
                    if (_BinPath != null)
                    {
                        try
                        { File = new FileInfo(_BinPath); }
                        catch { File = null; }

                        _BinLoaded = File?.Exists ?? false;
                    }
                }
                catch { }
            }while (CheckRetry());
        }
Пример #6
0
        public bool Seek(int index, ref byte[] buffer, out int length, out int extra)
        {
            length = extra = 0;

            if (File == null)
            {
                return(false);
            }

            if (index < 0 || index >= Index.Length)
            {
                return(false);
            }

            var e = Index[index];

            if (e.Offset < 0 || e.Size < 0)
            {
                return(false);
            }

            length = e.Size;
            extra  = e.Data;

            try
            {
                using (var stream = new FileStream(File.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    unsafe
                    {
                        if (buffer == null || buffer.Length < length)
                            buffer = new byte[length];

                        fixed(byte *data = buffer)
                        length = NativeReader.Read(stream, e.Offset, data, length);
                    }
                }

                return(true);
            }
            catch
            {
                length = extra = 0;
                return(false);
            }
        }
Пример #7
0
        private unsafe int PatchLand(TileMatrix matrix, string dataPath, string indexPath)
        {
            using (FileStream fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (FileStream fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    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 / matrix.BlockHeight;
                        int y       = blockID % matrix.BlockHeight;

                        fsData.Seek(4, SeekOrigin.Current);

                        LandTile[] tiles = new LandTile[64];

                        fixed(LandTile *pTiles = tiles)
                        {
#if !MONO
                            NativeReader.Read(fsData.SafeFileHandle.DangerousGetHandle(), pTiles, 192);
#else
                            NativeReader.Read(fsData.SafeFileHandle.DangerousGetHandle(), pTiles, 192);
//							NativeReader.Read( fsData.Handle, pTiles, 192 );
#endif
                        }

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

                    indexReader.Close();

                    return(count);
                }
            }
        }
Пример #8
0
        private 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 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 = 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;

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

                var staTiles = m_TileBuffer;

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

                    while (pCur < pEnd)
                    {
                        lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add(pCur->m_ID, pCur->m_Z);
                        pCur = 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);
                }
            }

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

            return(count);
        }
Пример #9
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_EmptyStaticBlock);
                }
                else
                {
                    int count = length / 7;

                    m_Statics.Seek(lookup, SeekOrigin.Begin);

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

                    StaticTile[] staTiles = m_TileBuffer;                    //new StaticTile[tileCount];

                    fixed(StaticTile *pTiles = staTiles)
                    {
#if !MONO
                        NativeReader.Read(m_Statics.SafeFileHandle.DangerousGetHandle(), pTiles, length);
#else
                        NativeReader.Read(m_Statics.Handle, pTiles, length);
#endif
                        if (m_Lists == null)
                        {
                            m_Lists = new TileList[8][];

                            for (int i = 0; i < 8; ++i)
                            {
                                m_Lists[i] = new TileList[8];

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

                        TileList[][] lists = m_Lists;

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

                        while (pCur < pEnd)
                        {
                            lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add(pCur->m_ID, pCur->m_Z);
                            pCur = pCur + 1;
                        }

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

                        return(tiles);
                    }
                }
            }
            catch (EndOfStreamException)
            {
                if (DateTime.UtcNow >= m_NextStaticWarning)
                {
                    Console.WriteLine("Warning: Static EOS for {0} ({1}, {2})", m_Owner, x, y);
                    m_NextStaticWarning = DateTime.UtcNow + TimeSpan.FromMinutes(1.0);
                }

                return(m_EmptyStaticBlock);
            }
        }