Fixes code according to modern code style. Fixes a few expression bugs.

This commit is contained in:
Kamron Batman 2018-09-15 09:58:51 -07:00
parent 89eea25e5f
commit 970fd563b2
3324 changed files with 441118 additions and 433755 deletions

View file

@ -23,176 +23,180 @@ using System.Runtime.CompilerServices;
namespace Server
{
public class TileMatrixPatch
{
private int m_LandBlocks, m_StaticBlocks;
public class TileMatrixPatch
{
private int m_LandBlocks, m_StaticBlocks;
public static bool Enabled { get; set; } = true;
private StaticTile[] m_TileBuffer = new StaticTile[128];
public int LandBlocks
{
get
{
lock (this)
return m_LandBlocks;
}
}
public TileMatrixPatch(TileMatrix matrix, int index)
{
if (!Enabled)
return;
public int StaticBlocks
{
get
{
lock (this)
return m_StaticBlocks;
}
}
string mapDataPath = Core.FindDataFile("mapdif{0}.mul", index);
string mapIndexPath = Core.FindDataFile("mapdifl{0}.mul", index);
public TileMatrixPatch( TileMatrix matrix, int index )
{
if ( !Enabled )
return;
if (File.Exists(mapDataPath) && File.Exists(mapIndexPath))
m_LandBlocks = PatchLand(matrix, mapDataPath, mapIndexPath);
string mapDataPath = Core.FindDataFile( "mapdif{0}.mul", index );
string mapIndexPath = Core.FindDataFile( "mapdifl{0}.mul", index );
string staDataPath = Core.FindDataFile("stadif{0}.mul", index);
string staIndexPath = Core.FindDataFile("stadifl{0}.mul", index);
string staLookupPath = Core.FindDataFile("stadifi{0}.mul", index);
if ( File.Exists( mapDataPath ) && File.Exists( mapIndexPath ) )
m_LandBlocks = PatchLand( matrix, mapDataPath, mapIndexPath );
if (File.Exists(staDataPath) && File.Exists(staIndexPath) && File.Exists(staLookupPath))
m_StaticBlocks = PatchStatics(matrix, staDataPath, staIndexPath, staLookupPath);
}
string staDataPath = Core.FindDataFile( "stadif{0}.mul", index );
string staIndexPath = Core.FindDataFile( "stadifl{0}.mul", index );
string staLookupPath = Core.FindDataFile( "stadifi{0}.mul", index );
public static bool Enabled{ get; set; } = true;
if ( File.Exists( staDataPath ) && File.Exists( staIndexPath ) && File.Exists( staLookupPath ) )
m_StaticBlocks = PatchStatics( matrix, staDataPath, staIndexPath, staLookupPath );
}
public int LandBlocks
{
get
{
lock (this)
{
return m_LandBlocks;
}
}
}
[MethodImpl(MethodImplOptions.Synchronized)]
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 );
public int StaticBlocks
{
get
{
lock (this)
{
return m_StaticBlocks;
}
}
}
int count = (int)(indexReader.BaseStream.Length / 4);
[MethodImpl(MethodImplOptions.Synchronized)]
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);
for ( int i = 0; i < count; ++i )
{
int blockID = indexReader.ReadInt32();
int x = blockID / matrix.BlockHeight;
int y = blockID % matrix.BlockHeight;
int count = (int)(indexReader.BaseStream.Length / 4);
fsData.Seek( 4, SeekOrigin.Current );
for (int i = 0; i < count; ++i)
{
int blockID = indexReader.ReadInt32();
int x = blockID / matrix.BlockHeight;
int y = blockID % matrix.BlockHeight;
LandTile[] tiles = new LandTile[64];
fsData.Seek(4, SeekOrigin.Current);
fixed ( LandTile *pTiles = tiles )
{
LandTile[] tiles = new LandTile[64];
fixed (LandTile* pTiles = tiles)
{
#if !MONO
NativeReader.Read( fsData.SafeFileHandle.DangerousGetHandle(), pTiles, 192 );
NativeReader.Read(fsData.SafeFileHandle.DangerousGetHandle(), pTiles, 192);
#else
NativeReader.Read( fsData.Handle, pTiles, 192 );
#endif
}
}
matrix.SetLandBlock( x, y, tiles );
}
indexReader.Close();
matrix.SetLandBlock(x, y, tiles);
}
return count;
}
}
}
indexReader.Close();
private StaticTile[] m_TileBuffer = new StaticTile[128];
return count;
}
}
}
[MethodImpl(MethodImplOptions.Synchronized)]
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 );
[MethodImpl(MethodImplOptions.Synchronized)]
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);
int count = (int)(indexReader.BaseStream.Length / 4);
TileList[][] lists = new TileList[8][];
TileList[][] lists = new TileList[8][];
for ( int x = 0; x < 8; ++x )
{
lists[x] = 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 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;
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
int offset = lookupReader.ReadInt32();
int length = lookupReader.ReadInt32();
lookupReader.ReadInt32(); // Extra
if ( offset < 0 || length <= 0 )
{
matrix.SetStaticBlock( blockX, blockY, matrix.EmptyStaticBlock );
continue;
}
if (offset < 0 || length <= 0)
{
matrix.SetStaticBlock(blockX, blockY, matrix.EmptyStaticBlock);
continue;
}
fsData.Seek( offset, SeekOrigin.Begin );
fsData.Seek(offset, SeekOrigin.Begin);
int tileCount = length / 7;
int tileCount = length / 7;
if ( m_TileBuffer.Length < tileCount )
m_TileBuffer = new StaticTile[tileCount];
if (m_TileBuffer.Length < tileCount)
m_TileBuffer = new StaticTile[tileCount];
StaticTile[] staTiles = m_TileBuffer;
StaticTile[] staTiles = m_TileBuffer;
fixed ( StaticTile *pTiles = staTiles )
{
fixed (StaticTile* pTiles = staTiles)
{
#if !MONO
NativeReader.Read( fsData.SafeFileHandle.DangerousGetHandle(), pTiles, length );
NativeReader.Read(fsData.SafeFileHandle.DangerousGetHandle(), pTiles, length);
#else
NativeReader.Read( fsData.Handle, pTiles, length );
#endif
StaticTile *pCur = pTiles, pEnd = pTiles + tileCount;
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;
}
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][][];
StaticTile[][][] tiles = new StaticTile[8][][];
for ( int x = 0; x < 8; ++x )
{
tiles[x] = 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();
}
for (int y = 0; y < 8; ++y)
tiles[x][y] = lists[x][y].ToArray();
}
matrix.SetStaticBlock( blockX, blockY, tiles );
}
}
matrix.SetStaticBlock(blockX, blockY, tiles);
}
}
indexReader.Close();
lookupReader.Close();
indexReader.Close();
lookupReader.Close();
return count;
}
}
}
}
}
return count;
}
}
}
}
}
}