Changes properties to use automatic property initializers

This commit is contained in:
Kamron Batman 2018-09-14 15:23:29 -07:00
parent f0a48ad431
commit 06fa31a7bf
623 changed files with 13072 additions and 19304 deletions

View file

@ -26,20 +26,18 @@ namespace Server.Network
{
public class PacketReader
{
private byte[] m_Data;
private int m_Size;
private int m_Index;
public PacketReader( byte[] data, int size, bool fixedSize )
{
m_Data = data;
m_Size = size;
Buffer = data;
Size = size;
m_Index = fixedSize ? 1 : 3;
}
public byte[] Buffer => m_Data;
public byte[] Buffer { get; }
public int Size => m_Size;
public int Size { get; }
public void Trace( NetState state )
{
@ -47,7 +45,7 @@ namespace Server.Network
{
using ( StreamWriter sw = new StreamWriter( "Packets.log", true ) )
{
byte[] buffer = m_Data;
byte[] buffer = Buffer;
if ( buffer.Length > 0 )
sw.WriteLine( "Client: {0}: Unhandled packet 0x{1:X2}", state, buffer[0] );
@ -70,7 +68,7 @@ namespace Server.Network
{
case SeekOrigin.Begin: m_Index = offset; break;
case SeekOrigin.Current: m_Index += offset; break;
case SeekOrigin.End: m_Index = m_Size - offset; break;
case SeekOrigin.End: m_Index = Size - offset; break;
}
return m_Index;
@ -78,61 +76,61 @@ namespace Server.Network
public int ReadInt32()
{
if ( (m_Index + 4) > m_Size )
if ( (m_Index + 4) > Size )
return 0;
return (m_Data[m_Index++] << 24)
| (m_Data[m_Index++] << 16)
| (m_Data[m_Index++] << 8)
| m_Data[m_Index++];
return (Buffer[m_Index++] << 24)
| (Buffer[m_Index++] << 16)
| (Buffer[m_Index++] << 8)
| Buffer[m_Index++];
}
public short ReadInt16()
{
if ( (m_Index + 2) > m_Size )
if ( (m_Index + 2) > Size )
return 0;
return (short)((m_Data[m_Index++] << 8) | m_Data[m_Index++]);
return (short)((Buffer[m_Index++] << 8) | Buffer[m_Index++]);
}
public byte ReadByte()
{
if ( (m_Index + 1) > m_Size )
if ( (m_Index + 1) > Size )
return 0;
return m_Data[m_Index++];
return Buffer[m_Index++];
}
public uint ReadUInt32()
{
if ( (m_Index + 4) > m_Size )
if ( (m_Index + 4) > Size )
return 0;
return (uint)((m_Data[m_Index++] << 24) | (m_Data[m_Index++] << 16) | (m_Data[m_Index++] << 8) | m_Data[m_Index++]);
return (uint)((Buffer[m_Index++] << 24) | (Buffer[m_Index++] << 16) | (Buffer[m_Index++] << 8) | Buffer[m_Index++]);
}
public ushort ReadUInt16()
{
if ( (m_Index + 2) > m_Size )
if ( (m_Index + 2) > Size )
return 0;
return (ushort)((m_Data[m_Index++] << 8) | m_Data[m_Index++]);
return (ushort)((Buffer[m_Index++] << 8) | Buffer[m_Index++]);
}
public sbyte ReadSByte()
{
if ( (m_Index + 1) > m_Size )
if ( (m_Index + 1) > Size )
return 0;
return (sbyte)m_Data[m_Index++];
return (sbyte)Buffer[m_Index++];
}
public bool ReadBoolean()
{
if ( (m_Index + 1) > m_Size )
if ( (m_Index + 1) > Size )
return false;
return ( m_Data[m_Index++] != 0 );
return ( Buffer[m_Index++] != 0 );
}
public string ReadUnicodeStringLE()
@ -141,7 +139,7 @@ namespace Server.Network
int c;
while ( (m_Index + 1) < m_Size && (c = (m_Data[m_Index++] | (m_Data[m_Index++] << 8))) != 0 )
while ( (m_Index + 1) < Size && (c = (Buffer[m_Index++] | (Buffer[m_Index++] << 8))) != 0 )
sb.Append( (char)c );
return sb.ToString();
@ -152,14 +150,14 @@ namespace Server.Network
int bound = m_Index + (fixedLength << 1);
int end = bound;
if ( bound > m_Size )
bound = m_Size;
if ( bound > Size )
bound = Size;
StringBuilder sb = new StringBuilder();
int c;
while ( (m_Index + 1) < bound && (c = (m_Data[m_Index++] | (m_Data[m_Index++] << 8))) != 0 )
while ( (m_Index + 1) < bound && (c = (Buffer[m_Index++] | (Buffer[m_Index++] << 8))) != 0 )
{
if ( IsSafeChar( c ) )
sb.Append( (char)c );
@ -176,7 +174,7 @@ namespace Server.Network
int c;
while ( (m_Index + 1) < m_Size && (c = (m_Data[m_Index++] | (m_Data[m_Index++] << 8))) != 0 )
while ( (m_Index + 1) < Size && (c = (Buffer[m_Index++] | (Buffer[m_Index++] << 8))) != 0 )
{
if ( IsSafeChar( c ) )
sb.Append( (char)c );
@ -191,7 +189,7 @@ namespace Server.Network
int c;
while ( (m_Index + 1) < m_Size && (c = ((m_Data[m_Index++] << 8) | m_Data[m_Index++])) != 0 )
while ( (m_Index + 1) < Size && (c = ((Buffer[m_Index++] << 8) | Buffer[m_Index++])) != 0 )
{
if ( IsSafeChar( c ) )
sb.Append( (char)c );
@ -206,7 +204,7 @@ namespace Server.Network
int c;
while ( (m_Index + 1) < m_Size && (c = ((m_Data[m_Index++] << 8) | m_Data[m_Index++])) != 0 )
while ( (m_Index + 1) < Size && (c = ((Buffer[m_Index++] << 8) | Buffer[m_Index++])) != 0 )
sb.Append( (char)c );
return sb.ToString();
@ -219,7 +217,7 @@ namespace Server.Network
public string ReadUTF8StringSafe( int fixedLength )
{
if ( m_Index >= m_Size )
if ( m_Index >= Size )
{
m_Index += fixedLength;
return string.Empty;
@ -228,14 +226,14 @@ namespace Server.Network
int bound = m_Index + fixedLength;
//int end = bound;
if ( bound > m_Size )
bound = m_Size;
if ( bound > Size )
bound = Size;
int count = 0;
int index = m_Index;
int start = m_Index;
while ( index < bound && m_Data[index++] != 0 )
while ( index < bound && Buffer[index++] != 0 )
++count;
index = 0;
@ -243,7 +241,7 @@ namespace Server.Network
byte[] buffer = new byte[count];
int value = 0;
while ( m_Index < bound && (value = m_Data[m_Index++]) != 0 )
while ( m_Index < bound && (value = Buffer[m_Index++]) != 0 )
buffer[index++] = (byte)value;
string s = Utility.UTF8.GetString( buffer );
@ -269,13 +267,13 @@ namespace Server.Network
public string ReadUTF8StringSafe()
{
if ( m_Index >= m_Size )
if ( m_Index >= Size )
return string.Empty;
int count = 0;
int index = m_Index;
while ( index < m_Size && m_Data[index++] != 0 )
while ( index < Size && Buffer[index++] != 0 )
++count;
index = 0;
@ -283,7 +281,7 @@ namespace Server.Network
byte[] buffer = new byte[count];
int value = 0;
while ( m_Index < m_Size && (value = m_Data[m_Index++]) != 0 )
while ( m_Index < Size && (value = Buffer[m_Index++]) != 0 )
buffer[index++] = (byte)value;
string s = Utility.UTF8.GetString( buffer );
@ -309,13 +307,13 @@ namespace Server.Network
public string ReadUTF8String()
{
if ( m_Index >= m_Size )
if ( m_Index >= Size )
return string.Empty;
int count = 0;
int index = m_Index;
while ( index < m_Size && m_Data[index++] != 0 )
while ( index < Size && Buffer[index++] != 0 )
++count;
index = 0;
@ -323,7 +321,7 @@ namespace Server.Network
byte[] buffer = new byte[count];
int value = 0;
while ( m_Index < m_Size && (value = m_Data[m_Index++]) != 0 )
while ( m_Index < Size && (value = Buffer[m_Index++]) != 0 )
buffer[index++] = (byte)value;
return Utility.UTF8.GetString( buffer );
@ -335,7 +333,7 @@ namespace Server.Network
int c;
while ( m_Index < m_Size && (c = m_Data[m_Index++]) != 0 )
while ( m_Index < Size && (c = Buffer[m_Index++]) != 0 )
sb.Append( (char)c );
return sb.ToString();
@ -347,7 +345,7 @@ namespace Server.Network
int c;
while ( m_Index < m_Size && (c = m_Data[m_Index++]) != 0 )
while ( m_Index < Size && (c = Buffer[m_Index++]) != 0 )
{
if ( IsSafeChar( c ) )
sb.Append( (char)c );
@ -361,14 +359,14 @@ namespace Server.Network
int bound = m_Index + (fixedLength << 1);
int end = bound;
if ( bound > m_Size )
bound = m_Size;
if ( bound > Size )
bound = Size;
StringBuilder sb = new StringBuilder();
int c;
while ( (m_Index + 1) < bound && (c = ((m_Data[m_Index++] << 8) | m_Data[m_Index++])) != 0 )
while ( (m_Index + 1) < bound && (c = ((Buffer[m_Index++] << 8) | Buffer[m_Index++])) != 0 )
{
if ( IsSafeChar( c ) )
sb.Append( (char)c );
@ -384,14 +382,14 @@ namespace Server.Network
int bound = m_Index + (fixedLength << 1);
int end = bound;
if ( bound > m_Size )
bound = m_Size;
if ( bound > Size )
bound = Size;
StringBuilder sb = new StringBuilder();
int c;
while ( (m_Index + 1) < bound && (c = ((m_Data[m_Index++] << 8) | m_Data[m_Index++])) != 0 )
while ( (m_Index + 1) < bound && (c = ((Buffer[m_Index++] << 8) | Buffer[m_Index++])) != 0 )
sb.Append( (char)c );
m_Index = end;
@ -404,14 +402,14 @@ namespace Server.Network
int bound = m_Index + fixedLength;
int end = bound;
if ( bound > m_Size )
bound = m_Size;
if ( bound > Size )
bound = Size;
StringBuilder sb = new StringBuilder();
int c;
while ( m_Index < bound && (c = m_Data[m_Index++]) != 0 )
while ( m_Index < bound && (c = Buffer[m_Index++]) != 0 )
{
if ( IsSafeChar( c ) )
sb.Append( (char)c );
@ -427,14 +425,14 @@ namespace Server.Network
int bound = m_Index + fixedLength;
int end = bound;
if ( bound > m_Size )
bound = m_Size;
if ( bound > Size )
bound = Size;
StringBuilder sb = new StringBuilder();
int c;
while ( m_Index < bound && (c = m_Data[m_Index++]) != 0 )
while ( m_Index < bound && (c = Buffer[m_Index++]) != 0 )
sb.Append( (char)c );
m_Index = end;