public static XPacket Serialize(byte type, byte subtype, object obj, bool strict = false) { var fields = GetFields(obj.GetType()); if (strict) { var usedUp = new List <byte>(); foreach (var field in fields) { if (usedUp.Contains(field.Item2)) { throw new Exception("One field used two times."); } usedUp.Add(field.Item2); } } var packet = XPacket.Create(type, subtype); foreach (var field in fields) { packet.SetValue(field.Item2, field.Item1.GetValue(obj)); } return(packet); }
private static void Main() { Console.Title = ""; Console.ForegroundColor = ConsoleColor.White; var packet = XPacket.Create(0, 0); packet.SetValue(0, 12345); var encr = packet.Encrypt().ToPacket(); var decr = XPacket.Parse(encr); Console.WriteLine(decr.GetValue <int>(0)); Console.ReadLine(); }