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