Sure Here is it
BigEndianWriter
Cliquez pour révéler
Cliquez pour masquer
public class BigEndianWriter : IDisposable, IDataWriter
{
private BinaryWriter m_writer;
public Stream BaseStream
{
get
{
return this.m_writer.BaseStream;
}
}
public long BytesAvailable
{
get
{
return this.m_writer.BaseStream.Length - this.m_writer.BaseStream.Position;
}
}
public int Position
{
get
{
return (int)m_writer.BaseStream.Position;
}
set
{
this.m_writer.BaseStream.Position = value;
}
}
public byte[] Data
{
get
{
long position = this.m_writer.BaseStream.Position;
byte[] array = new byte[this.m_writer.BaseStream.Length];
this.m_writer.BaseStream.Position = 0L;
this.m_writer.BaseStream.Read(array, 0, (int)this.m_writer.BaseStream.Length);
this.m_writer.BaseStream.Position = position;
return array;
}
}
public BigEndianWriter()
{
this.m_writer = new BinaryWriter(new MemoryStream(), Encoding.UTF8);
}
public BigEndianWriter(Stream stream)
{
this.m_writer = new BinaryWriter(stream, Encoding.UTF8);
}
public BigEndianWriter(byte[] buffer)
{
m_writer = new BinaryWriter(new MemoryStream(buffer));
}
private void WriteBigEndianBytes(byte[] endianBytes)
{
for (int i = endianBytes.Length - 1; i >= 0; i--)
{
this.m_writer.Write(endianBytes);
}
}
public void WriteShort(short @short)
{
this.WriteBigEndianBytes(BitConverter.GetBytes(@short));
}
public void WriteInt(int @int)
{
this.WriteBigEndianBytes(BitConverter.GetBytes(@int));
}
public void WriteLong(long @long)
{
this.WriteBigEndianBytes(BitConverter.GetBytes(@long));
}
public void WriteUShort(ushort @ushort)
{
this.WriteBigEndianBytes(BitConverter.GetBytes(@ushort));
}
public void WriteUInt(uint @uint)
{
this.WriteBigEndianBytes(BitConverter.GetBytes(@uint));
}
public void WriteULong(ulong @ulong)
{
this.WriteBigEndianBytes(BitConverter.GetBytes(@ulong));
}
public void WriteByte(byte @byte)
{
this.m_writer.Write(@byte);
}
public void WriteSByte(sbyte @byte)
{
this.m_writer.Write(@byte);
}
public void WriteFloat(float @float)
{
this.m_writer.Write(@float);
}
public void WriteBoolean(bool @bool)
{
if (@bool)
{
this.m_writer.Write((byte)1);
}
else
{
this.m_writer.Write((byte)0);
}
}
public void WriteChar(char @char)
{
this.WriteBigEndianBytes(BitConverter.GetBytes(@char));
}
public void WriteDouble(double @double)
{
this.WriteBigEndianBytes(BitConverter.GetBytes(@double));
}
public void WriteSingle(float single)
{
this.WriteBigEndianBytes(BitConverter.GetBytes(single));
}
public void WriteUTF(string str)
{
byte[] bytes = Encoding.UTF8.GetBytes(str);
ushort num = (ushort)bytes.Length;
this.WriteUShort(num);
for (int i = 0; i < (int)num; i++)
{
this.m_writer.Write(bytes);
}
}
public void WriteUTFBytes(string str)
{
byte[] bytes = Encoding.UTF8.GetBytes(str);
int num = bytes.Length;
for (int i = 0; i < num; i++)
{
this.m_writer.Write(bytes);
}
}
public void WriteBytes(byte[] data)
{
this.m_writer.Write(data);
}
/// <summary>
/// Write a bytes array into the buffer
/// </summary>
/// <returns></returns>
public void WriteBytes(byte[] data, uint offset, uint length)
{
byte[] array = new byte[length];
Array.Copy(data, offset, array, 0, length);
m_writer.Write(array);
}
public void Seek(int offset)
{
this.Seek(offset, SeekOrigin.Begin);
}
public void Seek(int offset, SeekOrigin seekOrigin)
{
this.m_writer.BaseStream.Seek((long)offset, seekOrigin);
}
public void Clear()
{
this.m_writer = new BinaryWriter(new MemoryStream(), Encoding.UTF8);
}
public void Dispose()
{
this.m_writer.Flush();
this.m_writer.Dispose();
this.m_writer = null;
}
}
BigEndianReader
Cliquez pour révéler
Cliquez pour masquer
public class BigEndianReader : IDisposable, IDataReader
{
private BinaryReader m_reader;
public long BytesAvailable
{
get
{
return (int)(this.m_reader.BaseStream.Length - this.m_reader.BaseStream.Position);
}
}
public long Position
{
get
{
return (int)this.m_reader.BaseStream.Position;
}
}
public Stream BaseStream
{
get
{
return this.m_reader.BaseStream;
}
}
public BigEndianReader()
{
this.m_reader = new BinaryReader(new MemoryStream(), Encoding.UTF8);
}
public BigEndianReader(Stream stream)
{
this.m_reader = new BinaryReader(stream, Encoding.UTF8);
}
public BigEndianReader(byte[] tab)
{
this.m_reader = new BinaryReader(new MemoryStream(tab), Encoding.UTF8);
}
private byte[] ReadBigEndianBytes(int count)
{
byte[] array = new byte[count];
for (int i = count - 1; i >= 0; i--)
{
array = (byte)this.BaseStream.ReadByte();
}
return array;
}
public short ReadShort()
{
return BitConverter.ToInt16(this.ReadBigEndianBytes(2), 0);
}
public int ReadInt()
{
return BitConverter.ToInt32(this.ReadBigEndianBytes(4), 0);
}
public long ReadLong()
{
return BitConverter.ToInt64(this.ReadBigEndianBytes(8), 0);
}
public float ReadFloat()
{
return BitConverter.ToSingle(this.ReadBigEndianBytes(4), 0);
}
public ushort ReadUShort()
{
return BitConverter.ToUInt16(this.ReadBigEndianBytes(2), 0);
}
public uint ReadUInt()
{
return BitConverter.ToUInt32(this.ReadBigEndianBytes(4), 0);
}
public ulong ReadULong()
{
return BitConverter.ToUInt64(this.ReadBigEndianBytes(8), 0);
}
public byte ReadByte()
{
return this.m_reader.ReadByte();
}
public sbyte ReadSByte()
{
return this.m_reader.ReadSByte();
}
public byte[] ReadBytes(int n)
{
return this.m_reader.ReadBytes(n);
}
public BigEndianReader ReadBytesInNewBigEndianReader(int n)
{
return new BigEndianReader(this.m_reader.ReadBytes(n));
}
public bool ReadBoolean()
{
return this.m_reader.ReadByte() == 1;
}
public char ReadChar()
{
return (char)this.ReadUShort();
}
public double ReadDouble()
{
return BitConverter.ToDouble(this.ReadBigEndianBytes(8), 0);
}
public float ReadSingle()
{
return BitConverter.ToSingle(this.ReadBigEndianBytes(4), 0);
}
public string ReadUTF()
{
ushort n = this.ReadUShort();
byte[] bytes = this.ReadBytes((int)n);
return Encoding.UTF8.GetString(bytes);
}
public string ReadUTF7BitLength()
{
int n = this.ReadInt();
byte[] bytes = this.ReadBytes(n);
return Encoding.UTF8.GetString(bytes);
}
public string ReadUTFBytes(ushort len)
{
byte[] bytes = this.ReadBytes((int)len);
return Encoding.UTF8.GetString(bytes);
}
public void SkipBytes(int n)
{
for (int i = 0; i < n; i++)
{
this.m_reader.ReadByte();
}
}
public void Seek(int offset, SeekOrigin seekOrigin = SeekOrigin.Begin)
{
this.m_reader.BaseStream.Seek((long)offset, seekOrigin);
}
public void Add(byte[] data, int offset, int count)
{
long position = this.m_reader.BaseStream.Position;
this.m_reader.BaseStream.Position = this.m_reader.BaseStream.Length;
this.m_reader.BaseStream.Write(data, offset, count);
this.m_reader.BaseStream.Position = position;
}
public void Dispose()
{
this.m_reader.Dispose();
this.m_reader = null;
}
}
HelloConnectMessage
Cliquez pour révéler
Cliquez pour masquer
public class HelloConnectMessage : NetworkMessage
{
public const int ProtocolId = 3;
public override int MessageID { get { return ProtocolId; } }
public string Salt;
public sbyte[] Key;
public HelloConnectMessage() { }
public HelloConnectMessage(string salt, sbyte[] key)
{
this.Salt = salt;
this.Key = key;
}
public override void Serialize(ICustomDataOutput writer)
{
writer.WriteUTF(this.Salt);
writer.WriteVarInt((int)(ushort)this.Key.Length);
foreach (sbyte @byte in this.Key)
writer.WriteSByte(@byte);
}
public override void Deserialize(ICustomDataInput reader)
{
this.Salt = reader.ReadUTF();
ushort num = (ushort)reader.ReadVarInt();
this.Key = new sbyte[(int)num];
for (int index = 0; index < (int)num; ++index)
this.Key[index] = reader.ReadSByte();
}
}
IdentificationMessage
Cliquez pour révéler
Cliquez pour masquer
public class IdentificationMessage : NetworkMessage
{
public const int ProtocolId = 4;
public override int MessageID { get { return ProtocolId; } }
public bool Autoconnect { get; set; }
public bool UseCertificate { get; set; }
public bool UseLoginToken { get; set; }
public VersionExtended Version { get; set; }
public string Lang { get; set; }
public sbyte[] Credentials { get; set; }
public short ServerId { get; set; }
public long SessionOptionalSalt { get; set; }
public ushort[] FailedAttempts { get; set; }
public IdentificationMessage() { }
public IdentificationMessage(bool autoconnect, bool useCertificate, bool useLoginToken, VersionExtended version, string lang, sbyte[] credentials, short serverId, long sessionOptionalSalt, ushort[] failedAttempts)
{
Autoconnect = autoconnect;
UseCertificate = useCertificate;
UseLoginToken = useLoginToken;
Version = version;
Lang = lang;
Credentials = credentials;
ServerId = serverId;
SessionOptionalSalt = sessionOptionalSalt;
FailedAttempts = failedAttempts;
}
public override void Serialize(ICustomDataOutput writer)
{
byte flag1 = 0;
flag1 = BooleanByteWrapper.SetFlag(flag1, 0, Autoconnect);
flag1 = BooleanByteWrapper.SetFlag(flag1, 1, UseCertificate);
flag1 = BooleanByteWrapper.SetFlag(flag1, 2, UseLoginToken);
writer.WriteByte(flag1);
Version.Serialize(writer);
writer.WriteUTF(Lang);
writer.WriteVarInt(Credentials.Length);
foreach (var entry in Credentials)
{
writer.WriteSByte(entry);
}
writer.WriteShort(ServerId);
writer.WriteDouble(SessionOptionalSalt);
writer.WriteShort((short)this.FailedAttempts.Length);
foreach (short s in FailedAttempts)
writer.WriteShort(s);
}
public override void Deserialize(ICustomDataInput reader)
{
byte flag1 = reader.ReadByte();
Autoconnect = BooleanByteWrapper.GetFlag(flag1, 0);
UseCertificate = BooleanByteWrapper.GetFlag(flag1, 1);
UseLoginToken = BooleanByteWrapper.GetFlag(flag1, 2);
Version = new VersionExtended();
Version.Deserialize(reader);
Lang = reader.ReadUTF();
var limit = reader.ReadVarInt();
Credentials = new sbyte[limit];
for (int i = 0; i < limit; i++)
{
Credentials = reader.ReadSByte();
}
ServerId = reader.ReadShort();
SessionOptionalSalt = reader.ReadVarLong();
if (SessionOptionalSalt < -9.007199254740992E15 || SessionOptionalSalt > 9.007199254740992E15)
throw new Exception("Forbidden value on sessionOptionalSalt = " + SessionOptionalSalt + ", it doesn't respect the following condition : sessionOptionalSalt < -9.007199254740992E15 || sessionOptionalSalt > 9.007199254740992E15");
ushort length = reader.ReadUShort();
FailedAttempts = new ushort[limit];
for (int i = 0; i < length; i++)
{
FailedAttempts = reader.ReadVarUhShort();
}
}
}
i think the code i'm using is outdated or something i'm using an open source unfinished bot project could that be problem ?