void DeserializeObject(GameBinaryReader reader, object target) { foreach (var info in GetPacketInfo(target.GetType()).Fields.Cast <ReflectionPacketFieldInfo>()) { if (info.IsByteArray) { var offset = reader.ReadOffset(); var count = reader.ReadUInt16(); var list = (List <byte>)info.Property.GetValue(target); list.Clear(); if (count == 0) { continue; } reader.Seek(offset, (r, op) => list.AddRange(r.ReadBytes(count))); } else if (info.IsArray) { var count = reader.ReadUInt16(); var offset = reader.ReadOffset(); var list = (IList)info.Property.GetValue(target); list.Clear(); if (count == 0) { continue; } var next = offset; for (var i = 0; i < count; i++) { reader.Seek(next, (r, op) => { r.ReadOffset(); next = r.ReadOffset(); var elem = info.ElementConstructor(); DeserializeObject(r, elem); list.Add(elem); }); } } else if (info.IsString) { var offset = reader.ReadOffset(); info.Property.SetValue(target, reader.Seek(offset, (r, op) => r.ReadString())); } else { var val = info.PrimitiveDeserializer(reader); info.EnumValidator?.Invoke(val); info.Property.SetValue(target, val); } } }