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); } }
private 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); TileList[][] lists = new TileList[8][]; for (int x = 0; x < 8; ++x) { lists[x] = new TileList[8]; for (int y = 0; y < 8; ++y) { lists[x][y] = new TileList(); } } 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; if (m_TileBuffer.Length < tileCount) { m_TileBuffer = new StaticTile[tileCount]; } StaticTile[] staTiles = m_TileBuffer; //new StaticTile[tileCount]; fixed(StaticTile *pTiles = staTiles) { if (m_Buffer == null || length > m_Buffer.Length) { m_Buffer = new byte[length]; } fsData.Read(m_Buffer, 0, length); Marshal.Copy(m_Buffer, 0, new IntPtr(pTiles), length); StaticTile *pStart = pTiles; for (int j = 0; j < tileCount; j++) { StaticTile *pCur = pStart + j; lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add((short)((pCur->m_ID & 0x3FFF) + 0x4000), pCur->m_Z); } Tile[][][] tiles = new Tile[8][][]; for (int x = 0; x < 8; ++x) { tiles[x] = new Tile[8][]; for (int y = 0; y < 8; ++y) { tiles[x][y] = lists[x][y].ToArray(); } } matrix.SetStaticBlock(blockX, blockY, tiles); } } indexReader.Close(); lookupReader.Close(); return(count); } } } }
private unsafe HuedTile[][][] ReadStaticBlock(int x, int y) { 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); StaticTile[] staTiles = new StaticTile[count]; fixed(StaticTile *pTiles = staTiles) { _lread(m_Statics.Handle, pTiles, length); if (m_Lists == null) { m_Lists = new HuedTileList[8][]; for (int i = 0; i < 8; ++i) { m_Lists[i] = new HuedTileList[8]; for (int j = 0; j < 8; ++j) { m_Lists[i][j] = new HuedTileList(); } } } HuedTileList[][] lists = m_Lists; StaticTile *pCur = pTiles, pEnd = pTiles + count; while (pCur < pEnd) { lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add((short)((pCur->m_ID & 0x3FFF) + 0x4000), pCur->m_Hue, pCur->m_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); } } }
private 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); TileList[][] lists = new TileList[8][]; for (int x = 0; x < 8; ++x) { lists[x] = new TileList[8]; for (int y = 0; y < 8; ++y) { lists[x][y] = new TileList(); } } 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; if (m_TileBuffer.Length < tileCount) { m_TileBuffer = new StaticTile[tileCount]; } StaticTile[] 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; } 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(); } } matrix.SetStaticBlock(blockX, blockY, tiles); } } indexReader.Close(); lookupReader.Close(); return(count); }
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); } } } }
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); } }
private unsafe Tile[][][] 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 (m_Buffer == null || length > m_Buffer.Length) { m_Buffer = new byte[length]; } m_Statics.Read(m_Buffer, 0, length); Marshal.Copy(m_Buffer, 0, new IntPtr(pTiles), length); 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; for (int i = 0; i < count; i++) { StaticTile *pCur = pTiles + i; lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add((short)((pCur->m_ID & 0x3FFF) + 0x4000), pCur->m_Z); } Tile[][][] tiles = new Tile[8][][]; for (int i = 0; i < 8; ++i) { tiles[i] = new Tile[8][]; for (int j = 0; j < 8; ++j) { tiles[i][j] = lists[i][j].ToArray(); } } return(tiles); } } } catch (EndOfStreamException) { if (DateTime.Now >= m_NextStaticWarning) { Console.WriteLine("Warning: Static EOS for {0} ({1}, {2})", m_Owner, x, y); m_NextStaticWarning = DateTime.Now + TimeSpan.FromMinutes(1.0); } return(m_EmptyStaticBlock); } }