If you store the structures values like this:
Code:
public Data<ushort> Size = new Data<ushort>() { Value = 60, Offset = 0 }; public Data<ushort> Type = new Data<ushort>() { Value = 0x3e9, Offset = 2 }; public Data<string> Account = new Data<string>() { Offset = 4 }; public Data<string> CharName = new Data<string>() { Offset = 20 }; public Data<string> Password = new Data<string>() { Offset = 36 }; public Data<ushort> Model = new Data<ushort>() { Offset = 52 }; public Data<ushort> Job = new Data<ushort>() { Offset = 54 }; public Data<uint> UID = new Data<uint>() { Offset = 56 };
Code:
public struct Data<T> { public int Offset; public T Value; public static implicit operator T(Data<T> data) { return data.Value; } }
Code:
public static implicit operator CharacterCreationPacket(byte[] Packet) { CharacterCreationPacket packet = new CharacterCreationPacket(Packet); packet.Size.Value = packet.ReadUInt16(packet.Size.Offset); packet.Type.Value = packet.ReadUInt16(packet.Type.Offset); for (int i = 0; i < 16; i++) { byte BYTE = packet.ReadByte(packet.Account.Offset + i); if (BYTE > 0) { packet.Account.Value += Convert.ToChar(BYTE); } } for (int i = 0; i < 16; i++) { byte BYTE = packet.ReadByte(packet.CharName.Offset + i); if (BYTE > 0) { packet.CharName.Value += Convert.ToChar(BYTE); } } for (int i = 0; i < 16; i++) { byte BYTE = packet.ReadByte(packet.Password.Offset + i); if (BYTE > 0) { packet.Password.Value += Convert.ToChar(BYTE); } } packet.Model.Value = packet.ReadUInt16(packet.Model.Offset); packet.Job.Value = packet.ReadUInt16(packet.Job.Offset); packet.UID.Value = packet.ReadUInt16(packet.UID.Offset); return packet; }