From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../XMainClient/ProtoBuf/Meta/AttributeMap.cs | 117 + .../XMainClient/ProtoBuf/Meta/AttributeMap.cs.meta | 12 + .../Scripts/XMainClient/ProtoBuf/Meta/BasicList.cs | 337 +++ .../XMainClient/ProtoBuf/Meta/BasicList.cs.meta | 12 + .../XMainClient/ProtoBuf/Meta/CallbackSet.cs | 160 ++ .../XMainClient/ProtoBuf/Meta/CallbackSet.cs.meta | 12 + .../ProtoBuf/Meta/LockContentedEventArgs.cs | 22 + .../ProtoBuf/Meta/LockContentedEventArgs.cs.meta | 12 + .../ProtoBuf/Meta/LockContentedEventHandler.cs | 6 + .../Meta/LockContentedEventHandler.cs.meta | 12 + .../Scripts/XMainClient/ProtoBuf/Meta/MetaType.cs | 2327 ++++++++++++++++++++ .../XMainClient/ProtoBuf/Meta/MetaType.cs.meta | 12 + .../XMainClient/ProtoBuf/Meta/MutableList.cs | 29 + .../XMainClient/ProtoBuf/Meta/MutableList.cs.meta | 12 + .../XMainClient/ProtoBuf/Meta/RuntimeTypeModel.cs | 1160 ++++++++++ .../ProtoBuf/Meta/RuntimeTypeModel.cs.meta | 12 + .../Scripts/XMainClient/ProtoBuf/Meta/SubType.cs | 117 + .../XMainClient/ProtoBuf/Meta/SubType.cs.meta | 12 + .../ProtoBuf/Meta/TypeFormatEventArgs.cs | 76 + .../ProtoBuf/Meta/TypeFormatEventArgs.cs.meta | 12 + .../ProtoBuf/Meta/TypeFormatEventHandler.cs | 6 + .../ProtoBuf/Meta/TypeFormatEventHandler.cs.meta | 12 + .../Scripts/XMainClient/ProtoBuf/Meta/TypeModel.cs | 1511 +++++++++++++ .../XMainClient/ProtoBuf/Meta/TypeModel.cs.meta | 12 + .../XMainClient/ProtoBuf/Meta/ValueMember.cs | 808 +++++++ .../XMainClient/ProtoBuf/Meta/ValueMember.cs.meta | 12 + 26 files changed, 6832 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs.meta create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/BasicList.cs create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/BasicList.cs.meta create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/CallbackSet.cs create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/CallbackSet.cs.meta create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventArgs.cs create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventArgs.cs.meta create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventHandler.cs create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventHandler.cs.meta create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MetaType.cs create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MetaType.cs.meta create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MutableList.cs create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MutableList.cs.meta create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/RuntimeTypeModel.cs create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/RuntimeTypeModel.cs.meta create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/SubType.cs create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/SubType.cs.meta create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventArgs.cs create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventArgs.cs.meta create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventHandler.cs create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventHandler.cs.meta create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeModel.cs create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeModel.cs.meta create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/ValueMember.cs create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/ValueMember.cs.meta (limited to 'Client/Assets/Scripts/XMainClient/ProtoBuf/Meta') diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs new file mode 100644 index 00000000..4fb2059b --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs @@ -0,0 +1,117 @@ +using System; +using System.Reflection; + +namespace ProtoBuf.Meta +{ + internal abstract class AttributeMap + { + public abstract Type AttributeType { get; } + + public abstract object Target { get; } + + private sealed class ReflectionAttributeMap : AttributeMap + { + public override object Target + { + get + { + return this.attribute; + } + } + + public override Type AttributeType + { + get + { + return this.attribute.GetType(); + } + } + + private readonly Attribute attribute; + + public override bool TryGet(string key, bool publicOnly, out object value) + { + foreach (MemberInfo memberInfo in Helpers.GetInstanceFieldsAndProperties(this.attribute.GetType(), publicOnly)) + { + bool flag = string.Equals(memberInfo.Name, key, StringComparison.OrdinalIgnoreCase); + if (flag) + { + PropertyInfo propertyInfo = memberInfo as PropertyInfo; + bool flag2 = propertyInfo != null; + bool result; + if (flag2) + { + value = propertyInfo.GetValue(this.attribute, null); + result = true; + } + else + { + FieldInfo fieldInfo = memberInfo as FieldInfo; + bool flag3 = fieldInfo != null; + if (!flag3) + { + throw new NotSupportedException(memberInfo.GetType().Name); + } + value = fieldInfo.GetValue(this.attribute); + result = true; + } + return result; + } + } + value = null; + return false; + } + + public ReflectionAttributeMap(Attribute attribute) + { + this.attribute = attribute; + } + } + + [Obsolete("Please use AttributeType instead")] + public new Type GetType() + { + return this.AttributeType; + } + + public abstract bool TryGet(string key, bool publicOnly, out object value); + + public bool TryGet(string key, out object value) + { + return this.TryGet(key, true, out value); + } + + public static AttributeMap[] Create(TypeModel model, Type type, bool inherit) + { + object[] customAttributes = type.GetCustomAttributes(inherit); + AttributeMap[] array = new AttributeMap[customAttributes.Length]; + for (int i = 0; i < customAttributes.Length; i++) + { + array[i] = new AttributeMap.ReflectionAttributeMap((Attribute)customAttributes[i]); + } + return array; + } + + public static AttributeMap[] Create(TypeModel model, MemberInfo member, bool inherit) + { + object[] customAttributes = member.GetCustomAttributes(inherit); + AttributeMap[] array = new AttributeMap[customAttributes.Length]; + for (int i = 0; i < customAttributes.Length; i++) + { + array[i] = new AttributeMap.ReflectionAttributeMap((Attribute)customAttributes[i]); + } + return array; + } + + public static AttributeMap[] Create(TypeModel model, Assembly assembly) + { + object[] customAttributes = assembly.GetCustomAttributes(false); + AttributeMap[] array = new AttributeMap[customAttributes.Length]; + for (int i = 0; i < customAttributes.Length; i++) + { + array[i] = new AttributeMap.ReflectionAttributeMap((Attribute)customAttributes[i]); + } + return array; + } + } +} diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs.meta b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs.meta new file mode 100644 index 00000000..484bca84 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 87e043055f5d7a44eb9f66262b09652e +timeCreated: 1611404081 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/BasicList.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/BasicList.cs new file mode 100644 index 00000000..68acbe62 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/BasicList.cs @@ -0,0 +1,337 @@ +using System; +using System.Collections; + +namespace ProtoBuf.Meta +{ + internal class BasicList : IEnumerable + { + public object this[int index] + { + get + { + return this.head[index]; + } + } + + public int Count + { + get + { + return this.head.Length; + } + } + + private static readonly BasicList.Node nil = new BasicList.Node(null, 0); + + protected BasicList.Node head = BasicList.nil; + + public struct NodeEnumerator : IEnumerator + { + public object Current + { + get + { + return this.node[this.position]; + } + } + + private int position; + + private readonly BasicList.Node node; + + internal NodeEnumerator(BasicList.Node node) + { + this.position = -1; + this.node = node; + } + + void IEnumerator.Reset() + { + this.position = -1; + } + + public bool MoveNext() + { + int length = this.node.Length; + bool result; + if (this.position <= length) + { + int num = this.position + 1; + this.position = num; + result = (num < length); + } + else + { + result = false; + } + return result; + } + } + + internal sealed class Node + { + public object this[int index] + { + get + { + bool flag = index >= 0 && index < this.length; + if (flag) + { + return this.data[index]; + } + throw new ArgumentOutOfRangeException("index"); + } + set + { + bool flag = index >= 0 && index < this.length; + if (flag) + { + this.data[index] = value; + return; + } + throw new ArgumentOutOfRangeException("index"); + } + } + + public int Length + { + get + { + return this.length; + } + } + + private readonly object[] data; + + private int length; + + internal Node(object[] data, int length) + { + Helpers.DebugAssert((data == null && length == 0) || (data != null && length > 0 && length <= data.Length)); + this.data = data; + this.length = length; + } + + public void RemoveLastWithMutate() + { + bool flag = this.length == 0; + if (flag) + { + throw new InvalidOperationException(); + } + this.length--; + } + + public BasicList.Node Append(object value) + { + int num = this.length + 1; + bool flag = this.data == null; + object[] array; + if (flag) + { + array = new object[10]; + } + else + { + bool flag2 = this.length == this.data.Length; + if (flag2) + { + array = new object[this.data.Length * 2]; + Array.Copy(this.data, array, this.length); + } + else + { + array = this.data; + } + } + array[this.length] = value; + return new BasicList.Node(array, num); + } + + public BasicList.Node Trim() + { + bool flag = this.length == 0 || this.length == this.data.Length; + BasicList.Node result; + if (flag) + { + result = this; + } + else + { + object[] destinationArray = new object[this.length]; + Array.Copy(this.data, destinationArray, this.length); + result = new BasicList.Node(destinationArray, this.length); + } + return result; + } + + internal int IndexOfString(string value) + { + for (int i = 0; i < this.length; i++) + { + bool flag = value == (string)this.data[i]; + if (flag) + { + return i; + } + } + return -1; + } + + internal int IndexOfReference(object instance) + { + for (int i = 0; i < this.length; i++) + { + bool flag = instance == this.data[i]; + if (flag) + { + return i; + } + } + return -1; + } + + internal int IndexOf(BasicList.MatchPredicate predicate, object ctx) + { + for (int i = 0; i < this.length; i++) + { + bool flag = predicate(this.data[i], ctx); + if (flag) + { + return i; + } + } + return -1; + } + + internal void CopyTo(Array array, int offset) + { + bool flag = this.length > 0; + if (flag) + { + Array.Copy(this.data, 0, array, offset, this.length); + } + } + + internal void Clear() + { + bool flag = this.data != null; + if (flag) + { + Array.Clear(this.data, 0, this.data.Length); + } + this.length = 0; + } + } + + internal delegate bool MatchPredicate(object value, object ctx); + + internal sealed class Group + { + public readonly int First; + + public readonly BasicList Items; + + public Group(int first) + { + this.First = first; + this.Items = new BasicList(); + } + } + + public void CopyTo(Array array, int offset) + { + this.head.CopyTo(array, offset); + } + + public int Add(object value) + { + return (this.head = this.head.Append(value)).Length - 1; + } + + public void Trim() + { + this.head = this.head.Trim(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return new BasicList.NodeEnumerator(this.head); + } + + public BasicList.NodeEnumerator GetEnumerator() + { + return new BasicList.NodeEnumerator(this.head); + } + + public void Clear() + { + this.head = BasicList.nil; + } + + internal int IndexOf(BasicList.MatchPredicate predicate, object ctx) + { + return this.head.IndexOf(predicate, ctx); + } + + internal int IndexOfString(string value) + { + return this.head.IndexOfString(value); + } + + internal int IndexOfReference(object instance) + { + return this.head.IndexOfReference(instance); + } + + internal bool Contains(object value) + { + foreach (object objA in this) + { + bool flag = object.Equals(objA, value); + if (flag) + { + return true; + } + } + return false; + } + + internal static BasicList GetContiguousGroups(int[] keys, object[] values) + { + bool flag = keys == null; + if (flag) + { + throw new ArgumentNullException("keys"); + } + bool flag2 = values == null; + if (flag2) + { + throw new ArgumentNullException("values"); + } + bool flag3 = values.Length < keys.Length; + if (flag3) + { + throw new ArgumentException("Not all keys are covered by values", "values"); + } + BasicList basicList = new BasicList(); + BasicList.Group group = null; + for (int i = 0; i < keys.Length; i++) + { + bool flag4 = i == 0 || keys[i] != keys[i - 1]; + if (flag4) + { + group = null; + } + bool flag5 = group == null; + if (flag5) + { + group = new BasicList.Group(keys[i]); + basicList.Add(group); + } + group.Items.Add(values[i]); + } + return basicList; + } + } +} diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/BasicList.cs.meta b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/BasicList.cs.meta new file mode 100644 index 00000000..de4e1a55 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/BasicList.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6a87ac069938105429795f2d59f09a44 +timeCreated: 1611403888 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/CallbackSet.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/CallbackSet.cs new file mode 100644 index 00000000..d0e7c11a --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/CallbackSet.cs @@ -0,0 +1,160 @@ +using System; +using System.Reflection; + +namespace ProtoBuf.Meta +{ + public class CallbackSet + { + internal MethodInfo this[TypeModel.CallbackType callbackType] + { + get + { + MethodInfo result; + switch (callbackType) + { + case TypeModel.CallbackType.BeforeSerialize: + result = this.beforeSerialize; + break; + case TypeModel.CallbackType.AfterSerialize: + result = this.afterSerialize; + break; + case TypeModel.CallbackType.BeforeDeserialize: + result = this.beforeDeserialize; + break; + case TypeModel.CallbackType.AfterDeserialize: + result = this.afterDeserialize; + break; + default: + throw new ArgumentException("Callback type not supported: " + callbackType.ToString(), "callbackType"); + } + return result; + } + } + + public MethodInfo BeforeSerialize + { + get + { + return this.beforeSerialize; + } + set + { + this.beforeSerialize = this.SanityCheckCallback(this.metaType.Model, value); + } + } + + public MethodInfo BeforeDeserialize + { + get + { + return this.beforeDeserialize; + } + set + { + this.beforeDeserialize = this.SanityCheckCallback(this.metaType.Model, value); + } + } + + public MethodInfo AfterSerialize + { + get + { + return this.afterSerialize; + } + set + { + this.afterSerialize = this.SanityCheckCallback(this.metaType.Model, value); + } + } + + public MethodInfo AfterDeserialize + { + get + { + return this.afterDeserialize; + } + set + { + this.afterDeserialize = this.SanityCheckCallback(this.metaType.Model, value); + } + } + + public bool NonTrivial + { + get + { + return this.beforeSerialize != null || this.beforeDeserialize != null || this.afterSerialize != null || this.afterDeserialize != null; + } + } + + private readonly MetaType metaType; + + private MethodInfo beforeSerialize; + + private MethodInfo afterSerialize; + + private MethodInfo beforeDeserialize; + + private MethodInfo afterDeserialize; + + internal CallbackSet(MetaType metaType) + { + bool flag = metaType == null; + if (flag) + { + throw new ArgumentNullException("metaType"); + } + this.metaType = metaType; + } + + internal static bool CheckCallbackParameters(TypeModel model, MethodInfo method) + { + ParameterInfo[] parameters = method.GetParameters(); + for (int i = 0; i < parameters.Length; i++) + { + Type parameterType = parameters[i].ParameterType; + bool flag = parameterType == model.MapType(typeof(SerializationContext)); + if (!flag) + { + bool flag2 = parameterType == model.MapType(typeof(Type)); + if (!flag2) + { + return false; + } + } + } + return true; + } + + private MethodInfo SanityCheckCallback(TypeModel model, MethodInfo callback) + { + this.metaType.ThrowIfFrozen(); + bool flag = callback == null; + MethodInfo result; + if (flag) + { + result = callback; + } + else + { + bool isStatic = callback.IsStatic; + if (isStatic) + { + throw new ArgumentException("Callbacks cannot be static", "callback"); + } + bool flag2 = callback.ReturnType != model.MapType(typeof(void)) || !CallbackSet.CheckCallbackParameters(model, callback); + if (flag2) + { + throw CallbackSet.CreateInvalidCallbackSignature(callback); + } + result = callback; + } + return result; + } + + internal static Exception CreateInvalidCallbackSignature(MethodInfo method) + { + return new NotSupportedException("Invalid callback signature in " + method.DeclaringType.FullName + "." + method.Name); + } + } +} diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/CallbackSet.cs.meta b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/CallbackSet.cs.meta new file mode 100644 index 00000000..ce94d50b --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/CallbackSet.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 7760448d52303f54b8f3541b6ffa032b +timeCreated: 1611403953 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventArgs.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventArgs.cs new file mode 100644 index 00000000..f787bb96 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventArgs.cs @@ -0,0 +1,22 @@ +using System; + +namespace ProtoBuf.Meta +{ + public sealed class LockContentedEventArgs : EventArgs + { + public string OwnerStackTrace + { + get + { + return this.ownerStackTrace; + } + } + + private readonly string ownerStackTrace; + + internal LockContentedEventArgs(string ownerStackTrace) + { + this.ownerStackTrace = ownerStackTrace; + } + } +} diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventArgs.cs.meta b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventArgs.cs.meta new file mode 100644 index 00000000..29208e95 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventArgs.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: a2e0f668b28069e42964cccec0290fb9 +timeCreated: 1611404258 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventHandler.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventHandler.cs new file mode 100644 index 00000000..fa01dd00 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventHandler.cs @@ -0,0 +1,6 @@ +using System; + +namespace ProtoBuf.Meta +{ + public delegate void LockContentedEventHandler(object sender, LockContentedEventArgs args); +} diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventHandler.cs.meta b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventHandler.cs.meta new file mode 100644 index 00000000..abafbdb1 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/LockContentedEventHandler.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 4bf547271692e3a4db4f971055c6f2a1 +timeCreated: 1611403689 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MetaType.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MetaType.cs new file mode 100644 index 00000000..e65ee2f3 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MetaType.cs @@ -0,0 +1,2327 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using System.Text; +using ProtoBuf.Serializers; + +namespace ProtoBuf.Meta +{ + public class MetaType : ISerializerProxy + { + IProtoSerializer ISerializerProxy.Serializer + { + get + { + return this.Serializer; + } + } + + public MetaType BaseType + { + get + { + return this.baseType; + } + } + + internal TypeModel Model + { + get + { + return this.model; + } + } + + public bool IncludeSerializerMethod + { + get + { + return !this.HasFlag(8); + } + set + { + this.SetFlag(8, !value, true); + } + } + + public bool AsReferenceDefault + { + get + { + return this.HasFlag(32); + } + set + { + this.SetFlag(32, value, true); + } + } + + public bool HasCallbacks + { + get + { + return this.callbacks != null && this.callbacks.NonTrivial; + } + } + + public bool HasSubtypes + { + get + { + return this.subTypes != null && this.subTypes.Count != 0; + } + } + + public CallbackSet Callbacks + { + get + { + bool flag = this.callbacks == null; + if (flag) + { + this.callbacks = new CallbackSet(this); + } + return this.callbacks; + } + } + + private bool IsValueType + { + get + { + return this.type.IsValueType; + } + } + + public string Name + { + get + { + return this.name; + } + set + { + this.ThrowIfFrozen(); + this.name = value; + } + } + + public Type Type + { + get + { + return this.type; + } + } + + internal IProtoTypeSerializer Serializer + { + get + { + bool flag = this.serializer == null; + if (flag) + { + int opaqueToken = 0; + try + { + this.model.TakeLock(ref opaqueToken); + bool flag2 = this.serializer == null; + if (flag2) + { + this.SetFlag(4, true, false); + this.serializer = this.BuildSerializer(); + } + } + finally + { + this.model.ReleaseLock(opaqueToken); + } + } + return this.serializer; + } + } + + internal bool IsList + { + get + { + Type type = this.IgnoreListHandling ? null : TypeModel.GetListItemType(this.model, this.type); + return type != null; + } + } + + public bool UseConstructor + { + get + { + return !this.HasFlag(16); + } + set + { + this.SetFlag(16, !value, true); + } + } + + public Type ConstructType + { + get + { + return this.constructType; + } + set + { + this.ThrowIfFrozen(); + this.constructType = value; + } + } + + public ValueMember this[int fieldNumber] + { + get + { + foreach (object obj in this.fields) + { + ValueMember valueMember = (ValueMember)obj; + bool flag = valueMember.FieldNumber == fieldNumber; + if (flag) + { + return valueMember; + } + } + return null; + } + } + + public ValueMember this[MemberInfo member] + { + get + { + bool flag = member == null; + ValueMember result; + if (flag) + { + result = null; + } + else + { + foreach (object obj in this.fields) + { + ValueMember valueMember = (ValueMember)obj; + bool flag2 = valueMember.Member == member; + if (flag2) + { + return valueMember; + } + } + result = null; + } + return result; + } + } + + public bool EnumPassthru + { + get + { + return this.HasFlag(2); + } + set + { + this.SetFlag(2, value, true); + } + } + + public bool IgnoreListHandling + { + get + { + return this.HasFlag(128); + } + set + { + this.SetFlag(128, value, true); + } + } + + internal bool Pending + { + get + { + return this.HasFlag(1); + } + set + { + this.SetFlag(1, value, false); + } + } + + internal IEnumerable Fields + { + get + { + return this.fields; + } + } + + internal bool IsAutoTuple + { + get + { + return this.HasFlag(64); + } + } + + private MetaType baseType; + + private BasicList subTypes; + + internal static readonly Type ienumerable = typeof(IEnumerable); + + private CallbackSet callbacks; + + private string name; + + private MethodInfo factory; + + private readonly RuntimeTypeModel model; + + private readonly Type type; + + private IProtoTypeSerializer serializer; + + private Type constructType; + + private Type surrogate; + + private readonly BasicList fields = new BasicList(); + + private const byte OPTIONS_Pending = 1; + + private const byte OPTIONS_EnumPassThru = 2; + + private const byte OPTIONS_Frozen = 4; + + private const byte OPTIONS_PrivateOnApi = 8; + + private const byte OPTIONS_SkipConstructor = 16; + + private const byte OPTIONS_AsReferenceDefault = 32; + + private const byte OPTIONS_AutoTuple = 64; + + private const byte OPTIONS_IgnoreListHandling = 128; + + private volatile byte flags; + + internal sealed class Comparer : IComparer, IComparer + { + public static readonly MetaType.Comparer Default = new MetaType.Comparer(); + + public int Compare(object x, object y) + { + return this.Compare(x as MetaType, y as MetaType); + } + + public int Compare(MetaType x, MetaType y) + { + bool flag = x == y; + int result; + if (flag) + { + result = 0; + } + else + { + bool flag2 = x == null; + if (flag2) + { + result = -1; + } + else + { + bool flag3 = y == null; + if (flag3) + { + result = 1; + } + else + { + result = string.Compare(x.GetSchemaTypeName(), y.GetSchemaTypeName(), StringComparison.Ordinal); + } + } + } + return result; + } + } + + [Flags] + internal enum AttributeFamily + { + None = 0, + ProtoBuf = 1, + DataContractSerialier = 2, + XmlSerializer = 4, + AutoTuple = 8 + } + + public override string ToString() + { + return this.type.ToString(); + } + + private bool IsValidSubType(Type subType) + { + return this.type.IsAssignableFrom(subType); + } + + public MetaType AddSubType(int fieldNumber, Type derivedType) + { + return this.AddSubType(fieldNumber, derivedType, DataFormat.Default); + } + + public MetaType AddSubType(int fieldNumber, Type derivedType, DataFormat dataFormat) + { + bool flag = derivedType == null; + if (flag) + { + throw new ArgumentNullException("derivedType"); + } + bool flag2 = fieldNumber < 1; + if (flag2) + { + throw new ArgumentOutOfRangeException("fieldNumber"); + } + bool flag3 = (!this.type.IsClass && !this.type.IsInterface) || this.type.IsSealed; + if (flag3) + { + throw new InvalidOperationException("Sub-types can only be added to non-sealed classes"); + } + bool flag4 = !this.IsValidSubType(derivedType); + if (flag4) + { + throw new ArgumentException(derivedType.Name + " is not a valid sub-type of " + this.type.Name, "derivedType"); + } + MetaType metaType = this.model[derivedType]; + this.ThrowIfFrozen(); + metaType.ThrowIfFrozen(); + SubType value = new SubType(fieldNumber, metaType, dataFormat); + this.ThrowIfFrozen(); + metaType.SetBaseType(this); + bool flag5 = this.subTypes == null; + if (flag5) + { + this.subTypes = new BasicList(); + } + this.subTypes.Add(value); + return this; + } + + private void SetBaseType(MetaType baseType) + { + bool flag = baseType == null; + if (flag) + { + throw new ArgumentNullException("baseType"); + } + bool flag2 = this.baseType == baseType; + if (!flag2) + { + bool flag3 = this.baseType != null; + if (flag3) + { + throw new InvalidOperationException("A type can only participate in one inheritance hierarchy"); + } + for (MetaType metaType = baseType; metaType != null; metaType = metaType.baseType) + { + bool flag4 = metaType == this; + if (flag4) + { + throw new InvalidOperationException("Cyclic inheritance is not allowed"); + } + } + this.baseType = baseType; + } + } + + public MetaType SetCallbacks(MethodInfo beforeSerialize, MethodInfo afterSerialize, MethodInfo beforeDeserialize, MethodInfo afterDeserialize) + { + CallbackSet callbackSet = this.Callbacks; + callbackSet.BeforeSerialize = beforeSerialize; + callbackSet.AfterSerialize = afterSerialize; + callbackSet.BeforeDeserialize = beforeDeserialize; + callbackSet.AfterDeserialize = afterDeserialize; + return this; + } + + public MetaType SetCallbacks(string beforeSerialize, string afterSerialize, string beforeDeserialize, string afterDeserialize) + { + bool isValueType = this.IsValueType; + if (isValueType) + { + throw new InvalidOperationException(); + } + CallbackSet callbackSet = this.Callbacks; + callbackSet.BeforeSerialize = this.ResolveMethod(beforeSerialize, true); + callbackSet.AfterSerialize = this.ResolveMethod(afterSerialize, true); + callbackSet.BeforeDeserialize = this.ResolveMethod(beforeDeserialize, true); + callbackSet.AfterDeserialize = this.ResolveMethod(afterDeserialize, true); + return this; + } + + internal string GetSchemaTypeName() + { + bool flag = this.surrogate != null; + string result; + if (flag) + { + result = this.model[this.surrogate].GetSchemaTypeName(); + } + else + { + bool flag2 = !Helpers.IsNullOrEmpty(this.name); + if (flag2) + { + result = this.name; + } + else + { + string text = this.type.Name; + bool isGenericType = this.type.IsGenericType; + if (isGenericType) + { + StringBuilder stringBuilder = new StringBuilder(text); + int num = text.IndexOf('`'); + bool flag3 = num >= 0; + if (flag3) + { + stringBuilder.Length = num; + } + foreach (Type type in this.type.GetGenericArguments()) + { + stringBuilder.Append('_'); + Type type2 = type; + int key = this.model.GetKey(ref type2); + MetaType metaType = null; + bool flag4 = key >= 0 && (metaType = this.model[type2]) != null && metaType.surrogate == null; + if (flag4) + { + stringBuilder.Append(metaType.GetSchemaTypeName()); + } + else + { + stringBuilder.Append(type2.Name); + } + } + result = stringBuilder.ToString(); + } + else + { + result = text; + } + } + } + return result; + } + + public MetaType SetFactory(MethodInfo factory) + { + this.model.VerifyFactory(factory, this.type); + this.ThrowIfFrozen(); + this.factory = factory; + return this; + } + + public MetaType SetFactory(string factory) + { + return this.SetFactory(this.ResolveMethod(factory, false)); + } + + private MethodInfo ResolveMethod(string name, bool instance) + { + bool flag = Helpers.IsNullOrEmpty(name); + MethodInfo result; + if (flag) + { + result = null; + } + else + { + result = (instance ? Helpers.GetInstanceMethod(this.type, name) : Helpers.GetStaticMethod(this.type, name)); + } + return result; + } + + internal static Exception InbuiltType(Type type) + { + return new ArgumentException("Data of this type has inbuilt behaviour, and cannot be added to a model in this way: " + type.FullName); + } + + internal MetaType(RuntimeTypeModel model, Type type, MethodInfo factory) + { + this.factory = factory; + bool flag = model == null; + if (flag) + { + throw new ArgumentNullException("model"); + } + bool flag2 = type == null; + if (flag2) + { + throw new ArgumentNullException("type"); + } + IProtoSerializer protoSerializer = model.TryGetBasicTypeSerializer(type); + bool flag3 = protoSerializer != null; + if (flag3) + { + throw MetaType.InbuiltType(type); + } + this.type = type; + this.model = model; + bool flag4 = Helpers.IsEnum(type); + if (flag4) + { + this.EnumPassthru = type.IsDefined(model.MapType(typeof(FlagsAttribute)), false); + } + } + + protected internal void ThrowIfFrozen() + { + bool flag = (this.flags & 4) > 0; + if (flag) + { + throw new InvalidOperationException("The type cannot be changed once a serializer has been generated for " + this.type.FullName); + } + } + + private IProtoTypeSerializer BuildSerializer() + { + bool flag = Helpers.IsEnum(this.type); + IProtoTypeSerializer result; + if (flag) + { + result = new TagDecorator(1, WireType.Variant, false, new EnumSerializer(this.type, this.GetEnumMap())); + } + else + { + Type type = this.IgnoreListHandling ? null : TypeModel.GetListItemType(this.model, this.type); + bool flag2 = type != null; + if (flag2) + { + bool flag3 = this.surrogate != null; + if (flag3) + { + throw new ArgumentException("Repeated data (a list, collection, etc) has inbuilt behaviour and cannot use a surrogate"); + } + bool flag4 = this.subTypes != null && this.subTypes.Count != 0; + if (flag4) + { + throw new ArgumentException("Repeated data (a list, collection, etc) has inbuilt behaviour and cannot be subclassed"); + } + Type defaultType = null; + MetaType.ResolveListTypes(this.model, this.type, ref type, ref defaultType); + ValueMember valueMember = new ValueMember(this.model, 1, this.type, type, defaultType, DataFormat.Default); + result = new TypeSerializer(this.model, this.type, new int[] + { + 1 + }, new IProtoSerializer[] + { + valueMember.Serializer + }, null, true, true, null, this.constructType, this.factory); + } + else + { + bool flag5 = this.surrogate != null; + if (flag5) + { + MetaType metaType = this.model[this.surrogate]; + MetaType metaType2; + while ((metaType2 = metaType.baseType) != null) + { + metaType = metaType2; + } + result = new SurrogateSerializer(this.model, this.type, this.surrogate, metaType.Serializer); + } + else + { + bool isAutoTuple = this.IsAutoTuple; + if (isAutoTuple) + { + MemberInfo[] members; + ConstructorInfo constructorInfo = MetaType.ResolveTupleConstructor(this.type, out members); + bool flag6 = constructorInfo == null; + if (flag6) + { + throw new InvalidOperationException(); + } + result = new TupleSerializer(this.model, constructorInfo, members); + } + else + { + this.fields.Trim(); + int count = this.fields.Count; + int num = (this.subTypes == null) ? 0 : this.subTypes.Count; + int[] array = new int[count + num]; + IProtoSerializer[] array2 = new IProtoSerializer[count + num]; + int num2 = 0; + bool flag7 = num != 0; + if (flag7) + { + foreach (object obj in this.subTypes) + { + SubType subType = (SubType)obj; + bool flag8 = !subType.DerivedType.IgnoreListHandling && this.model.MapType(MetaType.ienumerable).IsAssignableFrom(subType.DerivedType.Type); + if (flag8) + { + throw new ArgumentException("Repeated data (a list, collection, etc) has inbuilt behaviour and cannot be used as a subclass"); + } + array[num2] = subType.FieldNumber; + array2[num2++] = subType.Serializer; + } + } + bool flag9 = count != 0; + if (flag9) + { + foreach (object obj2 in this.fields) + { + ValueMember valueMember2 = (ValueMember)obj2; + array[num2] = valueMember2.FieldNumber; + array2[num2++] = valueMember2.Serializer; + } + } + BasicList basicList = null; + for (MetaType metaType3 = this.BaseType; metaType3 != null; metaType3 = metaType3.BaseType) + { + MethodInfo methodInfo = metaType3.HasCallbacks ? metaType3.Callbacks.BeforeDeserialize : null; + bool flag10 = methodInfo != null; + if (flag10) + { + bool flag11 = basicList == null; + if (flag11) + { + basicList = new BasicList(); + } + basicList.Add(methodInfo); + } + } + MethodInfo[] array3 = null; + bool flag12 = basicList != null; + if (flag12) + { + array3 = new MethodInfo[basicList.Count]; + basicList.CopyTo(array3, 0); + Array.Reverse(array3); + } + result = new TypeSerializer(this.model, this.type, array, array2, array3, this.baseType == null, this.UseConstructor, this.callbacks, this.constructType, this.factory); + } + } + } + } + return result; + } + + private static Type GetBaseType(MetaType type) + { + return type.type.BaseType; + } + + internal static bool GetAsReferenceDefault(RuntimeTypeModel model, Type type) + { + bool flag = type == null; + if (flag) + { + throw new ArgumentNullException("type"); + } + bool flag2 = Helpers.IsEnum(type); + bool result; + if (flag2) + { + result = false; + } + else + { + AttributeMap[] array = AttributeMap.Create(model, type, false); + for (int i = 0; i < array.Length; i++) + { + bool flag3 = array[i].AttributeType.FullName == "ProtoBuf.ProtoContractAttribute"; + if (flag3) + { + object obj; + bool flag4 = array[i].TryGet("AsReferenceDefault", out obj); + if (flag4) + { + return (bool)obj; + } + } + } + result = false; + } + return result; + } + + internal void ApplyDefaultBehaviour() + { + Type type = MetaType.GetBaseType(this); + bool flag = type != null && this.model.FindWithoutAdd(type) == null && MetaType.GetContractFamily(this.model, type, null) > MetaType.AttributeFamily.None; + if (flag) + { + this.model.FindOrAddAuto(type, true, false, false); + } + AttributeMap[] array = AttributeMap.Create(this.model, this.type, false); + MetaType.AttributeFamily attributeFamily = MetaType.GetContractFamily(this.model, this.type, array); + bool flag2 = attributeFamily == MetaType.AttributeFamily.AutoTuple; + if (flag2) + { + this.SetFlag(64, true, true); + } + bool flag3 = !this.EnumPassthru && Helpers.IsEnum(this.type); + bool flag4 = attributeFamily == MetaType.AttributeFamily.None && !flag3; + if (!flag4) + { + BasicList basicList = null; + BasicList basicList2 = null; + int dataMemberOffset = 0; + int num = 1; + bool flag5 = this.model.InferTagFromNameDefault; + ImplicitFields implicitFields = ImplicitFields.None; + string text = null; + foreach (AttributeMap attributeMap in array) + { + string fullName = attributeMap.AttributeType.FullName; + bool flag6 = !flag3 && fullName == "ProtoBuf.ProtoIncludeAttribute"; + object obj = null; + if (flag6) + { + int fieldNumber = 0; + bool flag7 = attributeMap.TryGet("tag", out obj); + if (flag7) + { + fieldNumber = (int)obj; + } + DataFormat dataFormat = DataFormat.Default; + bool flag8 = attributeMap.TryGet("DataFormat", out obj); + if (flag8) + { + dataFormat = (DataFormat)((int)obj); + } + Type type2 = null; + try + { + bool flag9 = attributeMap.TryGet("knownTypeName", out obj); + if (flag9) + { + type2 = this.model.GetType((string)obj, this.type.Assembly); + } + else + { + bool flag10 = attributeMap.TryGet("knownType", out obj); + if (flag10) + { + type2 = (Type)obj; + } + } + } + catch (Exception innerException) + { + throw new InvalidOperationException("Unable to resolve sub-type of: " + this.type.FullName, innerException); + } + bool flag11 = type2 == null; + if (flag11) + { + throw new InvalidOperationException("Unable to resolve sub-type of: " + this.type.FullName); + } + bool flag12 = this.IsValidSubType(type2); + if (flag12) + { + this.AddSubType(fieldNumber, type2, dataFormat); + } + } + bool flag13 = fullName == "ProtoBuf.ProtoPartialIgnoreAttribute"; + if (flag13) + { + bool flag14 = attributeMap.TryGet("MemberName", out obj) && obj != null; + if (flag14) + { + bool flag15 = basicList == null; + if (flag15) + { + basicList = new BasicList(); + } + basicList.Add((string)obj); + } + } + bool flag16 = !flag3 && fullName == "ProtoBuf.ProtoPartialMemberAttribute"; + if (flag16) + { + bool flag17 = basicList2 == null; + if (flag17) + { + basicList2 = new BasicList(); + } + basicList2.Add(attributeMap); + } + bool flag18 = fullName == "ProtoBuf.ProtoContractAttribute"; + if (flag18) + { + bool flag19 = attributeMap.TryGet("Name", out obj); + if (flag19) + { + text = (string)obj; + } + bool flag20 = Helpers.IsEnum(this.type); + if (flag20) + { + bool flag21 = attributeMap.TryGet("EnumPassthruHasValue", false, out obj) && (bool)obj; + if (flag21) + { + bool flag22 = attributeMap.TryGet("EnumPassthru", out obj); + if (flag22) + { + this.EnumPassthru = (bool)obj; + bool enumPassthru = this.EnumPassthru; + if (enumPassthru) + { + flag3 = false; + } + } + } + } + else + { + bool flag23 = attributeMap.TryGet("DataMemberOffset", out obj); + if (flag23) + { + dataMemberOffset = (int)obj; + } + bool flag24 = attributeMap.TryGet("InferTagFromNameHasValue", false, out obj) && (bool)obj; + if (flag24) + { + bool flag25 = attributeMap.TryGet("InferTagFromName", out obj); + if (flag25) + { + flag5 = (bool)obj; + } + } + bool flag26 = attributeMap.TryGet("ImplicitFields", out obj) && obj != null; + if (flag26) + { + implicitFields = (ImplicitFields)((int)obj); + } + bool flag27 = attributeMap.TryGet("SkipConstructor", out obj); + if (flag27) + { + this.UseConstructor = !(bool)obj; + } + bool flag28 = attributeMap.TryGet("IgnoreListHandling", out obj); + if (flag28) + { + this.IgnoreListHandling = (bool)obj; + } + bool flag29 = attributeMap.TryGet("AsReferenceDefault", out obj); + if (flag29) + { + this.AsReferenceDefault = (bool)obj; + } + bool flag30 = attributeMap.TryGet("ImplicitFirstTag", out obj) && (int)obj > 0; + if (flag30) + { + num = (int)obj; + } + } + } + bool flag31 = fullName == "System.Runtime.Serialization.DataContractAttribute"; + if (flag31) + { + bool flag32 = text == null && attributeMap.TryGet("Name", out obj); + if (flag32) + { + text = (string)obj; + } + } + bool flag33 = fullName == "System.Xml.Serialization.XmlTypeAttribute"; + if (flag33) + { + bool flag34 = text == null && attributeMap.TryGet("TypeName", out obj); + if (flag34) + { + text = (string)obj; + } + } + } + bool flag35 = !Helpers.IsNullOrEmpty(text); + if (flag35) + { + this.Name = text; + } + bool flag36 = implicitFields > ImplicitFields.None; + if (flag36) + { + attributeFamily &= MetaType.AttributeFamily.ProtoBuf; + } + MethodInfo[] array2 = null; + BasicList basicList3 = new BasicList(); + MemberInfo[] members = this.type.GetMembers(flag3 ? (BindingFlags.Static | BindingFlags.Public) : (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)); + foreach (MemberInfo memberInfo in members) + { + bool flag37 = memberInfo.DeclaringType != this.type; + if (!flag37) + { + bool flag38 = !ProtoBuf.Serializer.isSkipProtoIgnore; + if (flag38) + { + bool flag39 = memberInfo.IsDefined(this.model.MapType(typeof(ProtoIgnoreAttribute)), true); + if (flag39) + { + goto IL_756; + } + } + bool flag40 = basicList != null && basicList.Contains(memberInfo.Name); + if (!flag40) + { + bool flag41 = false; + PropertyInfo propertyInfo; + bool flag42 = (propertyInfo = (memberInfo as PropertyInfo)) != null; + if (flag42) + { + bool flag43 = flag3; + if (!flag43) + { + Type type3 = propertyInfo.PropertyType; + bool isPublic = Helpers.GetGetMethod(propertyInfo, false, false) != null; + bool isField = false; + MetaType.ApplyDefaultBehaviour_AddMembers(this.model, attributeFamily, flag3, basicList2, dataMemberOffset, flag5, implicitFields, basicList3, memberInfo, ref flag41, isPublic, isField, ref type3); + } + } + else + { + FieldInfo fieldInfo; + bool flag44 = (fieldInfo = (memberInfo as FieldInfo)) != null; + if (flag44) + { + Type type3 = fieldInfo.FieldType; + bool isPublic = fieldInfo.IsPublic; + bool isField = true; + bool flag45 = flag3 && !fieldInfo.IsStatic; + if (!flag45) + { + MetaType.ApplyDefaultBehaviour_AddMembers(this.model, attributeFamily, flag3, basicList2, dataMemberOffset, flag5, implicitFields, basicList3, memberInfo, ref flag41, isPublic, isField, ref type3); + } + } + else + { + MethodInfo methodInfo; + bool flag46 = (methodInfo = (memberInfo as MethodInfo)) != null; + if (flag46) + { + bool flag47 = flag3; + if (!flag47) + { + AttributeMap[] array4 = AttributeMap.Create(this.model, methodInfo, false); + bool flag48 = array4 != null && array4.Length != 0; + if (flag48) + { + MetaType.CheckForCallback(methodInfo, array4, "ProtoBuf.ProtoBeforeSerializationAttribute", ref array2, 0); + MetaType.CheckForCallback(methodInfo, array4, "ProtoBuf.ProtoAfterSerializationAttribute", ref array2, 1); + MetaType.CheckForCallback(methodInfo, array4, "ProtoBuf.ProtoBeforeDeserializationAttribute", ref array2, 2); + MetaType.CheckForCallback(methodInfo, array4, "ProtoBuf.ProtoAfterDeserializationAttribute", ref array2, 3); + MetaType.CheckForCallback(methodInfo, array4, "System.Runtime.Serialization.OnSerializingAttribute", ref array2, 4); + MetaType.CheckForCallback(methodInfo, array4, "System.Runtime.Serialization.OnSerializedAttribute", ref array2, 5); + MetaType.CheckForCallback(methodInfo, array4, "System.Runtime.Serialization.OnDeserializingAttribute", ref array2, 6); + MetaType.CheckForCallback(methodInfo, array4, "System.Runtime.Serialization.OnDeserializedAttribute", ref array2, 7); + } + } + } + } + } + } + } + IL_756:; + } + ProtoMemberAttribute[] array5 = new ProtoMemberAttribute[basicList3.Count]; + basicList3.CopyTo(array5, 0); + bool flag49 = flag5 || implicitFields > ImplicitFields.None; + if (flag49) + { + Array.Sort(array5); + int num2 = num; + foreach (ProtoMemberAttribute protoMemberAttribute in array5) + { + bool flag50 = !protoMemberAttribute.TagIsPinned; + if (flag50) + { + protoMemberAttribute.Rebase(num2++); + } + } + } + foreach (ProtoMemberAttribute normalizedAttribute in array5) + { + ValueMember valueMember = this.ApplyDefaultBehaviour(flag3, normalizedAttribute); + bool flag51 = valueMember != null; + if (flag51) + { + this.Add(valueMember); + } + } + bool flag52 = array2 != null; + if (flag52) + { + this.SetCallbacks(MetaType.Coalesce(array2, 0, 4), MetaType.Coalesce(array2, 1, 5), MetaType.Coalesce(array2, 2, 6), MetaType.Coalesce(array2, 3, 7)); + } + } + } + + private static void ApplyDefaultBehaviour_AddMembers(TypeModel model, MetaType.AttributeFamily family, bool isEnum, BasicList partialMembers, int dataMemberOffset, bool inferTagByName, ImplicitFields implicitMode, BasicList members, MemberInfo member, ref bool forced, bool isPublic, bool isField, ref Type effectiveType) + { + if (implicitMode != ImplicitFields.AllPublic) + { + if (implicitMode == ImplicitFields.AllFields) + { + if (isField) + { + forced = true; + } + } + } + else if (isPublic) + { + forced = true; + } + bool flag = effectiveType.IsSubclassOf(model.MapType(typeof(Delegate))); + if (flag) + { + effectiveType = null; + } + bool flag2 = effectiveType != null; + if (flag2) + { + ProtoMemberAttribute protoMemberAttribute = MetaType.NormalizeProtoMember(model, member, family, forced, isEnum, partialMembers, dataMemberOffset, inferTagByName); + bool flag3 = protoMemberAttribute != null; + if (flag3) + { + members.Add(protoMemberAttribute); + } + } + } + + private static MethodInfo Coalesce(MethodInfo[] arr, int x, int y) + { + MethodInfo methodInfo = arr[x]; + bool flag = methodInfo == null; + if (flag) + { + methodInfo = arr[y]; + } + return methodInfo; + } + + internal static MetaType.AttributeFamily GetContractFamily(RuntimeTypeModel model, Type type, AttributeMap[] attributes) + { + MetaType.AttributeFamily attributeFamily = MetaType.AttributeFamily.None; + bool flag = attributes == null; + if (flag) + { + attributes = AttributeMap.Create(model, type, false); + } + for (int i = 0; i < attributes.Length; i++) + { + string fullName = attributes[i].AttributeType.FullName; + if (!(fullName == "ProtoBuf.ProtoContractAttribute")) + { + if (!(fullName == "System.Xml.Serialization.XmlTypeAttribute")) + { + if (fullName == "System.Runtime.Serialization.DataContractAttribute") + { + bool flag2 = !model.AutoAddProtoContractTypesOnly; + if (flag2) + { + attributeFamily |= MetaType.AttributeFamily.DataContractSerialier; + } + } + } + else + { + bool flag3 = !model.AutoAddProtoContractTypesOnly; + if (flag3) + { + attributeFamily |= MetaType.AttributeFamily.XmlSerializer; + } + } + } + else + { + bool flag4 = false; + MetaType.GetFieldBoolean(ref flag4, attributes[i], "UseProtoMembersOnly"); + bool flag5 = flag4; + if (flag5) + { + return MetaType.AttributeFamily.ProtoBuf; + } + attributeFamily |= MetaType.AttributeFamily.ProtoBuf; + } + } + bool flag6 = attributeFamily == MetaType.AttributeFamily.None; + if (flag6) + { + MemberInfo[] array; + bool flag7 = MetaType.ResolveTupleConstructor(type, out array) != null; + if (flag7) + { + attributeFamily |= MetaType.AttributeFamily.AutoTuple; + } + } + return attributeFamily; + } + + internal static ConstructorInfo ResolveTupleConstructor(Type type, out MemberInfo[] mappedMembers) + { + mappedMembers = null; + bool flag = type == null; + if (flag) + { + throw new ArgumentNullException("type"); + } + bool isAbstract = type.IsAbstract; + ConstructorInfo result; + if (isAbstract) + { + result = null; + } + else + { + ConstructorInfo[] constructors = Helpers.GetConstructors(type, false); + bool flag2 = constructors.Length == 0 || (constructors.Length == 1 && constructors[0].GetParameters().Length == 0); + if (flag2) + { + result = null; + } + else + { + MemberInfo[] instanceFieldsAndProperties = Helpers.GetInstanceFieldsAndProperties(type, true); + BasicList basicList = new BasicList(); + for (int i = 0; i < instanceFieldsAndProperties.Length; i++) + { + PropertyInfo propertyInfo = instanceFieldsAndProperties[i] as PropertyInfo; + bool flag3 = propertyInfo != null; + if (flag3) + { + bool flag4 = !propertyInfo.CanRead; + if (flag4) + { + return null; + } + bool flag5 = propertyInfo.CanWrite && Helpers.GetSetMethod(propertyInfo, false, false) != null; + if (flag5) + { + return null; + } + basicList.Add(propertyInfo); + } + else + { + FieldInfo fieldInfo = instanceFieldsAndProperties[i] as FieldInfo; + bool flag6 = fieldInfo != null; + if (flag6) + { + bool flag7 = !fieldInfo.IsInitOnly; + if (flag7) + { + return null; + } + basicList.Add(fieldInfo); + } + } + } + bool flag8 = basicList.Count == 0; + if (flag8) + { + result = null; + } + else + { + MemberInfo[] array = new MemberInfo[basicList.Count]; + basicList.CopyTo(array, 0); + int[] array2 = new int[array.Length]; + int num = 0; + ConstructorInfo constructorInfo = null; + mappedMembers = new MemberInfo[array2.Length]; + for (int j = 0; j < constructors.Length; j++) + { + ParameterInfo[] parameters = constructors[j].GetParameters(); + bool flag9 = parameters.Length != array.Length; + if (!flag9) + { + for (int k = 0; k < array2.Length; k++) + { + array2[k] = -1; + } + for (int l = 0; l < parameters.Length; l++) + { + string b = parameters[l].Name.ToLower(); + for (int m = 0; m < array.Length; m++) + { + bool flag10 = array[m].Name.ToLower() != b; + if (!flag10) + { + Type memberType = Helpers.GetMemberType(array[m]); + bool flag11 = memberType != parameters[l].ParameterType; + if (!flag11) + { + array2[l] = m; + } + } + } + } + bool flag12 = false; + for (int n = 0; n < array2.Length; n++) + { + bool flag13 = array2[n] < 0; + if (flag13) + { + flag12 = true; + break; + } + mappedMembers[n] = array[array2[n]]; + } + bool flag14 = flag12; + if (!flag14) + { + num++; + constructorInfo = constructors[j]; + } + } + } + result = ((num == 1) ? constructorInfo : null); + } + } + } + return result; + } + + private static void CheckForCallback(MethodInfo method, AttributeMap[] attributes, string callbackTypeName, ref MethodInfo[] callbacks, int index) + { + for (int i = 0; i < attributes.Length; i++) + { + bool flag = attributes[i].AttributeType.FullName == callbackTypeName; + if (flag) + { + bool flag2 = callbacks == null; + if (flag2) + { + callbacks = new MethodInfo[8]; + } + else + { + bool flag3 = callbacks[index] != null; + if (flag3) + { + Type reflectedType = method.ReflectedType; + throw new ProtoException("Duplicate " + callbackTypeName + " callbacks on " + reflectedType.FullName); + } + } + callbacks[index] = method; + } + } + } + + private static bool HasFamily(MetaType.AttributeFamily value, MetaType.AttributeFamily required) + { + return (value & required) == required; + } + + private static ProtoMemberAttribute NormalizeProtoMember(TypeModel model, MemberInfo member, MetaType.AttributeFamily family, bool forced, bool isEnum, BasicList partialMembers, int dataMemberOffset, bool inferByTagName) + { + bool flag = member == null || (family == MetaType.AttributeFamily.None && !isEnum); + ProtoMemberAttribute result; + if (flag) + { + result = null; + } + else + { + int num = int.MinValue; + int num2 = inferByTagName ? -1 : 1; + string text = null; + bool isPacked = false; + bool flag2 = false; + bool flag3 = false; + bool isRequired = false; + bool asReference = false; + bool flag4 = false; + bool dynamicType = false; + bool tagIsPinned = false; + bool overwriteList = false; + DataFormat dataFormat = DataFormat.Default; + if (isEnum) + { + forced = true; + } + AttributeMap[] attribs = AttributeMap.Create(model, member, true); + if (isEnum) + { + AttributeMap attribute = MetaType.GetAttribute(attribs, "ProtoBuf.ProtoIgnoreAttribute"); + bool flag5 = attribute != null; + if (flag5) + { + flag2 = true; + } + else + { + attribute = MetaType.GetAttribute(attribs, "ProtoBuf.ProtoEnumAttribute"); + num = Convert.ToInt32(((FieldInfo)member).GetRawConstantValue()); + bool flag6 = attribute != null; + if (flag6) + { + MetaType.GetFieldName(ref text, attribute, "Name"); + bool flag7 = (bool)Helpers.GetInstanceMethod(attribute.AttributeType, "HasValue").Invoke(attribute.Target, null); + if (flag7) + { + object obj; + bool flag8 = attribute.TryGet("Value", out obj); + if (flag8) + { + num = (int)obj; + } + } + } + } + flag3 = true; + } + bool flag9 = !flag2 && !flag3; + if (flag9) + { + AttributeMap attribute = MetaType.GetAttribute(attribs, "ProtoBuf.ProtoMemberAttribute"); + MetaType.GetIgnore(ref flag2, attribute, attribs, "ProtoBuf.ProtoIgnoreAttribute"); + bool flag10 = !flag2 && attribute != null; + if (flag10) + { + MetaType.GetFieldNumber(ref num, attribute, "Tag"); + MetaType.GetFieldName(ref text, attribute, "Name"); + MetaType.GetFieldBoolean(ref isRequired, attribute, "IsRequired"); + MetaType.GetFieldBoolean(ref isPacked, attribute, "IsPacked"); + MetaType.GetFieldBoolean(ref overwriteList, attribute, "OverwriteList"); + MetaType.GetDataFormat(ref dataFormat, attribute, "DataFormat"); + MetaType.GetFieldBoolean(ref flag4, attribute, "AsReferenceHasValue", false); + bool flag11 = flag4; + if (flag11) + { + flag4 = MetaType.GetFieldBoolean(ref asReference, attribute, "AsReference", true); + } + MetaType.GetFieldBoolean(ref dynamicType, attribute, "DynamicType"); + tagIsPinned = (flag3 = (num > 0)); + } + bool flag12 = !flag3 && partialMembers != null; + if (flag12) + { + foreach (object obj2 in partialMembers) + { + AttributeMap attributeMap = (AttributeMap)obj2; + object obj3; + bool flag13 = attributeMap.TryGet("MemberName", out obj3) && (string)obj3 == member.Name; + if (flag13) + { + MetaType.GetFieldNumber(ref num, attributeMap, "Tag"); + MetaType.GetFieldName(ref text, attributeMap, "Name"); + MetaType.GetFieldBoolean(ref isRequired, attributeMap, "IsRequired"); + MetaType.GetFieldBoolean(ref isPacked, attributeMap, "IsPacked"); + MetaType.GetFieldBoolean(ref overwriteList, attribute, "OverwriteList"); + MetaType.GetDataFormat(ref dataFormat, attributeMap, "DataFormat"); + MetaType.GetFieldBoolean(ref flag4, attribute, "AsReferenceHasValue", false); + bool flag14 = flag4; + if (flag14) + { + flag4 = MetaType.GetFieldBoolean(ref asReference, attributeMap, "AsReference", true); + } + MetaType.GetFieldBoolean(ref dynamicType, attributeMap, "DynamicType"); + bool flag15; + flag3 = (flag15 = (tagIsPinned = (num > 0))); + if (flag15) + { + break; + } + } + } + } + } + bool flag16 = !flag2 && !flag3 && MetaType.HasFamily(family, MetaType.AttributeFamily.DataContractSerialier); + if (flag16) + { + AttributeMap attribute = MetaType.GetAttribute(attribs, "System.Runtime.Serialization.DataMemberAttribute"); + bool flag17 = attribute != null; + if (flag17) + { + MetaType.GetFieldNumber(ref num, attribute, "Order"); + MetaType.GetFieldName(ref text, attribute, "Name"); + MetaType.GetFieldBoolean(ref isRequired, attribute, "IsRequired"); + flag3 = (num >= num2); + bool flag18 = flag3; + if (flag18) + { + num += dataMemberOffset; + } + } + } + bool flag19 = !flag2 && !flag3 && MetaType.HasFamily(family, MetaType.AttributeFamily.XmlSerializer); + if (flag19) + { + AttributeMap attribute = MetaType.GetAttribute(attribs, "System.Xml.Serialization.XmlElementAttribute"); + bool flag20 = attribute == null; + if (flag20) + { + attribute = MetaType.GetAttribute(attribs, "System.Xml.Serialization.XmlArrayAttribute"); + } + MetaType.GetIgnore(ref flag2, attribute, attribs, "System.Xml.Serialization.XmlIgnoreAttribute"); + bool flag21 = attribute != null && !flag2; + if (flag21) + { + MetaType.GetFieldNumber(ref num, attribute, "Order"); + MetaType.GetFieldName(ref text, attribute, "ElementName"); + flag3 = (num >= num2); + } + } + bool flag22 = !flag2 && !flag3; + if (flag22) + { + bool flag23 = MetaType.GetAttribute(attribs, "System.NonSerializedAttribute") != null; + if (flag23) + { + flag2 = true; + } + } + bool flag24 = flag2 || (num < num2 && !forced); + if (flag24) + { + result = null; + } + else + { + result = new ProtoMemberAttribute(num, forced || inferByTagName) + { + AsReference = asReference, + AsReferenceHasValue = flag4, + DataFormat = dataFormat, + DynamicType = dynamicType, + IsPacked = isPacked, + OverwriteList = overwriteList, + IsRequired = isRequired, + Name = (Helpers.IsNullOrEmpty(text) ? member.Name : text), + Member = member, + TagIsPinned = tagIsPinned + }; + } + } + return result; + } + + private ValueMember ApplyDefaultBehaviour(bool isEnum, ProtoMemberAttribute normalizedAttribute) + { + MemberInfo member= null; + bool flag = normalizedAttribute == null || (member = normalizedAttribute.Member) == null; + ValueMember result; + if (flag) + { + result = null; + } + else + { + Type memberType = Helpers.GetMemberType(member); + Type type = null; + Type defaultType = null; + MetaType.ResolveListTypes(this.model, memberType, ref type, ref defaultType); + bool flag2 = type != null; + if (flag2) + { + int num = this.model.FindOrAddAuto(memberType, false, true, false); + bool flag3 = num >= 0 && this.model[memberType].IgnoreListHandling; + if (flag3) + { + type = null; + defaultType = null; + } + } + AttributeMap[] attribs = AttributeMap.Create(this.model, member, true); + object defaultValue = null; + bool useImplicitZeroDefaults = this.model.UseImplicitZeroDefaults; + if (useImplicitZeroDefaults) + { + ProtoTypeCode typeCode = Helpers.GetTypeCode(memberType); + switch (typeCode) + { + case ProtoTypeCode.Boolean: + defaultValue = false; + break; + case ProtoTypeCode.Char: + defaultValue = '\0'; + break; + case ProtoTypeCode.SByte: + defaultValue = 0; + break; + case ProtoTypeCode.Byte: + defaultValue = 0; + break; + case ProtoTypeCode.Int16: + defaultValue = 0; + break; + case ProtoTypeCode.UInt16: + defaultValue = 0; + break; + case ProtoTypeCode.Int32: + defaultValue = 0; + break; + case ProtoTypeCode.UInt32: + defaultValue = 0u; + break; + case ProtoTypeCode.Int64: + defaultValue = 0L; + break; + case ProtoTypeCode.UInt64: + defaultValue = 0UL; + break; + case ProtoTypeCode.Single: + defaultValue = 0f; + break; + case ProtoTypeCode.Double: + defaultValue = 0.0; + break; + case ProtoTypeCode.Decimal: + defaultValue = 0m; + break; + default: + if (typeCode != ProtoTypeCode.TimeSpan) + { + if (typeCode == ProtoTypeCode.Guid) + { + defaultValue = Guid.Empty; + } + } + else + { + defaultValue = TimeSpan.Zero; + } + break; + } + } + AttributeMap attribute; + bool flag4 = (attribute = MetaType.GetAttribute(attribs, "System.ComponentModel.DefaultValueAttribute")) != null; + if (flag4) + { + object obj; + bool flag5 = attribute.TryGet("Value", out obj); + if (flag5) + { + defaultValue = obj; + } + } + ValueMember valueMember = (isEnum || normalizedAttribute.Tag > 0) ? new ValueMember(this.model, this.type, normalizedAttribute.Tag, member, memberType, type, defaultType, normalizedAttribute.DataFormat, defaultValue) : null; + bool flag6 = valueMember != null; + if (flag6) + { + Type declaringType = this.type; + PropertyInfo propertyInfo = Helpers.GetProperty(declaringType, member.Name + "Specified", true); + MethodInfo getMethod = Helpers.GetGetMethod(propertyInfo, true, true); + bool flag7 = getMethod == null || getMethod.IsStatic; + if (flag7) + { + propertyInfo = null; + } + bool flag8 = propertyInfo != null; + if (flag8) + { + valueMember.SetSpecified(getMethod, Helpers.GetSetMethod(propertyInfo, true, true)); + } + else + { + MethodInfo instanceMethod = Helpers.GetInstanceMethod(declaringType, "ShouldSerialize" + member.Name, Helpers.EmptyTypes); + bool flag9 = instanceMethod != null && instanceMethod.ReturnType == this.model.MapType(typeof(bool)); + if (flag9) + { + valueMember.SetSpecified(instanceMethod, null); + } + } + bool flag10 = !Helpers.IsNullOrEmpty(normalizedAttribute.Name); + if (flag10) + { + valueMember.SetName(normalizedAttribute.Name); + } + valueMember.IsPacked = normalizedAttribute.IsPacked; + valueMember.IsRequired = normalizedAttribute.IsRequired; + valueMember.OverwriteList = normalizedAttribute.OverwriteList; + bool asReferenceHasValue = normalizedAttribute.AsReferenceHasValue; + if (asReferenceHasValue) + { + valueMember.AsReference = normalizedAttribute.AsReference; + } + valueMember.DynamicType = normalizedAttribute.DynamicType; + } + result = valueMember; + } + return result; + } + + private static void GetDataFormat(ref DataFormat value, AttributeMap attrib, string memberName) + { + bool flag = attrib == null || value > DataFormat.Default; + if (!flag) + { + object obj; + bool flag2 = attrib.TryGet(memberName, out obj) && obj != null; + if (flag2) + { + value = (DataFormat)obj; + } + } + } + + private static void GetIgnore(ref bool ignore, AttributeMap attrib, AttributeMap[] attribs, string fullName) + { + bool flag = ignore || attrib == null; + if (!flag) + { + ignore = (MetaType.GetAttribute(attribs, fullName) != null); + } + } + + private static void GetFieldBoolean(ref bool value, AttributeMap attrib, string memberName) + { + MetaType.GetFieldBoolean(ref value, attrib, memberName, true); + } + + private static bool GetFieldBoolean(ref bool value, AttributeMap attrib, string memberName, bool publicOnly) + { + bool flag = attrib == null; + bool result; + if (flag) + { + result = false; + } + else + { + bool flag2 = value; + if (flag2) + { + result = true; + } + else + { + object obj; + bool flag3 = attrib.TryGet(memberName, publicOnly, out obj) && obj != null; + if (flag3) + { + value = (bool)obj; + result = true; + } + else + { + result = false; + } + } + } + return result; + } + + private static void GetFieldNumber(ref int value, AttributeMap attrib, string memberName) + { + bool flag = attrib == null || value > 0; + if (!flag) + { + object obj; + bool flag2 = attrib.TryGet(memberName, out obj) && obj != null; + if (flag2) + { + value = (int)obj; + } + } + } + + private static void GetFieldName(ref string name, AttributeMap attrib, string memberName) + { + bool flag = attrib == null || !Helpers.IsNullOrEmpty(name); + if (!flag) + { + object obj; + bool flag2 = attrib.TryGet(memberName, out obj) && obj != null; + if (flag2) + { + name = (string)obj; + } + } + } + + private static AttributeMap GetAttribute(AttributeMap[] attribs, string fullName) + { + foreach (AttributeMap attributeMap in attribs) + { + bool flag = attributeMap != null && attributeMap.AttributeType.FullName == fullName; + if (flag) + { + return attributeMap; + } + } + return null; + } + + public MetaType Add(int fieldNumber, string memberName) + { + this.AddField(fieldNumber, memberName, null, null, null); + return this; + } + + public ValueMember AddField(int fieldNumber, string memberName) + { + return this.AddField(fieldNumber, memberName, null, null, null); + } + + public MetaType Add(string memberName) + { + this.Add(this.GetNextFieldNumber(), memberName); + return this; + } + + public void SetSurrogate(Type surrogateType) + { + bool flag = surrogateType == this.type; + if (flag) + { + surrogateType = null; + } + bool flag2 = surrogateType != null; + if (flag2) + { + bool flag3 = surrogateType != null && Helpers.IsAssignableFrom(this.model.MapType(typeof(IEnumerable)), surrogateType); + if (flag3) + { + throw new ArgumentException("Repeated data (a list, collection, etc) has inbuilt behaviour and cannot be used as a surrogate"); + } + } + this.ThrowIfFrozen(); + this.surrogate = surrogateType; + } + + internal MetaType GetSurrogateOrSelf() + { + bool flag = this.surrogate != null; + MetaType result; + if (flag) + { + result = this.model[this.surrogate]; + } + else + { + result = this; + } + return result; + } + + internal MetaType GetSurrogateOrBaseOrSelf(bool deep) + { + bool flag = this.surrogate != null; + MetaType result; + if (flag) + { + result = this.model[this.surrogate]; + } + else + { + MetaType metaType = this.baseType; + bool flag2 = metaType != null; + if (flag2) + { + if (deep) + { + MetaType metaType2; + do + { + metaType2 = metaType; + metaType = metaType.baseType; + } + while (metaType != null); + result = metaType2; + } + else + { + result = metaType; + } + } + else + { + result = this; + } + } + return result; + } + + private int GetNextFieldNumber() + { + int num = 0; + foreach (object obj in this.fields) + { + ValueMember valueMember = (ValueMember)obj; + bool flag = valueMember.FieldNumber > num; + if (flag) + { + num = valueMember.FieldNumber; + } + } + bool flag2 = this.subTypes != null; + if (flag2) + { + foreach (object obj2 in this.subTypes) + { + SubType subType = (SubType)obj2; + bool flag3 = subType.FieldNumber > num; + if (flag3) + { + num = subType.FieldNumber; + } + } + } + return num + 1; + } + + public MetaType Add(params string[] memberNames) + { + bool flag = memberNames == null; + if (flag) + { + throw new ArgumentNullException("memberNames"); + } + int nextFieldNumber = this.GetNextFieldNumber(); + for (int i = 0; i < memberNames.Length; i++) + { + this.Add(nextFieldNumber++, memberNames[i]); + } + return this; + } + + public MetaType Add(int fieldNumber, string memberName, object defaultValue) + { + this.AddField(fieldNumber, memberName, null, null, defaultValue); + return this; + } + + public MetaType Add(int fieldNumber, string memberName, Type itemType, Type defaultType) + { + this.AddField(fieldNumber, memberName, itemType, defaultType, null); + return this; + } + + public ValueMember AddField(int fieldNumber, string memberName, Type itemType, Type defaultType) + { + return this.AddField(fieldNumber, memberName, itemType, defaultType, null); + } + + private ValueMember AddField(int fieldNumber, string memberName, Type itemType, Type defaultType, object defaultValue) + { + MemberInfo memberInfo = null; + MemberInfo[] member = this.type.GetMember(memberName, Helpers.IsEnum(this.type) ? (BindingFlags.Static | BindingFlags.Public) : (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)); + bool flag = member != null && member.Length == 1; + if (flag) + { + memberInfo = member[0]; + } + bool flag2 = memberInfo == null; + if (flag2) + { + throw new ArgumentException("Unable to determine member: " + memberName, "memberName"); + } + MemberTypes memberType = memberInfo.MemberType; + Type memberType2; + if (memberType != MemberTypes.Field) + { + if (memberType != MemberTypes.Property) + { + throw new NotSupportedException(memberInfo.MemberType.ToString()); + } + memberType2 = ((PropertyInfo)memberInfo).PropertyType; + } + else + { + memberType2 = ((FieldInfo)memberInfo).FieldType; + } + MetaType.ResolveListTypes(this.model, memberType2, ref itemType, ref defaultType); + ValueMember valueMember = new ValueMember(this.model, this.type, fieldNumber, memberInfo, memberType2, itemType, defaultType, DataFormat.Default, defaultValue); + this.Add(valueMember); + return valueMember; + } + + internal static void ResolveListTypes(TypeModel model, Type type, ref Type itemType, ref Type defaultType) + { + bool flag = type == null; + if (!flag) + { + bool isArray = type.IsArray; + if (isArray) + { + bool flag2 = type.GetArrayRank() != 1; + if (flag2) + { + throw new NotSupportedException("Multi-dimension arrays are supported"); + } + itemType = type.GetElementType(); + bool flag3 = itemType == model.MapType(typeof(byte)); + if (flag3) + { + Type type2; + itemType = (type2 = null); + defaultType = type2; + } + else + { + defaultType = type; + } + } + bool flag4 = itemType == null; + if (flag4) + { + itemType = TypeModel.GetListItemType(model, type); + } + bool flag5 = itemType != null; + if (flag5) + { + Type type3 = null; + Type type4 = null; + MetaType.ResolveListTypes(model, itemType, ref type3, ref type4); + bool flag6 = type3 != null; + if (flag6) + { + throw TypeModel.CreateNestedListsNotSupported(); + } + } + bool flag7 = itemType != null && defaultType == null; + if (flag7) + { + bool flag8 = type.IsClass && !type.IsAbstract && Helpers.GetConstructor(type, Helpers.EmptyTypes, true) != null; + if (flag8) + { + defaultType = type; + } + bool flag9 = defaultType == null; + if (flag9) + { + bool isInterface = type.IsInterface; + if (isInterface) + { + Type[] genericArguments = null; + bool flag10 = type.IsGenericType && type.GetGenericTypeDefinition() == model.MapType(typeof(IDictionary<, >)) && itemType == model.MapType(typeof(KeyValuePair<, >)).MakeGenericType(genericArguments = type.GetGenericArguments()); + if (flag10) + { + defaultType = model.MapType(typeof(Dictionary<, >)).MakeGenericType(genericArguments); + } + else + { + defaultType = model.MapType(typeof(List<>)).MakeGenericType(new Type[] + { + itemType + }); + } + } + } + bool flag11 = defaultType != null && !Helpers.IsAssignableFrom(type, defaultType); + if (flag11) + { + defaultType = null; + } + } + } + } + + private void Add(ValueMember member) + { + int opaqueToken = 0; + try + { + this.model.TakeLock(ref opaqueToken); + this.ThrowIfFrozen(); + this.fields.Add(member); + } + finally + { + this.model.ReleaseLock(opaqueToken); + } + } + + public ValueMember[] GetFields() + { + ValueMember[] array = new ValueMember[this.fields.Count]; + this.fields.CopyTo(array, 0); + Array.Sort(array, ValueMember.Comparer.Default); + return array; + } + + public SubType[] GetSubtypes() + { + bool flag = this.subTypes == null || this.subTypes.Count == 0; + SubType[] result; + if (flag) + { + result = new SubType[0]; + } + else + { + SubType[] array = new SubType[this.subTypes.Count]; + this.subTypes.CopyTo(array, 0); + Array.Sort(array, SubType.Comparer.Default); + result = array; + } + return result; + } + + internal bool IsDefined(int fieldNumber) + { + foreach (object obj in this.fields) + { + ValueMember valueMember = (ValueMember)obj; + bool flag = valueMember.FieldNumber == fieldNumber; + if (flag) + { + return true; + } + } + return false; + } + + internal int GetKey(bool demand, bool getBaseKey) + { + return this.model.GetKey(this.type, demand, getBaseKey); + } + + internal EnumSerializer.EnumPair[] GetEnumMap() + { + bool flag = this.HasFlag(2); + EnumSerializer.EnumPair[] result; + if (flag) + { + result = null; + } + else + { + EnumSerializer.EnumPair[] array = new EnumSerializer.EnumPair[this.fields.Count]; + for (int i = 0; i < array.Length; i++) + { + ValueMember valueMember = (ValueMember)this.fields[i]; + int fieldNumber = valueMember.FieldNumber; + object rawEnumValue = valueMember.GetRawEnumValue(); + array[i] = new EnumSerializer.EnumPair(fieldNumber, rawEnumValue, valueMember.MemberType); + } + result = array; + } + return result; + } + + private bool HasFlag(byte flag) + { + return (this.flags & flag) == flag; + } + + private void SetFlag(byte flag, bool value, bool throwIfFrozen) + { + bool flag2 = throwIfFrozen && this.HasFlag(flag) != value; + if (flag2) + { + this.ThrowIfFrozen(); + } + if (value) + { + this.flags |= flag; + } + else + { + this.flags &= (byte)~flag; + } + } + + internal static MetaType GetRootType(MetaType source) + { + MetaType result; + while (source.serializer != null) + { + MetaType metaType = source.baseType; + bool flag = metaType == null; + if (flag) + { + result = source; + return result; + } + source = metaType; + } + RuntimeTypeModel runtimeTypeModel = source.model; + int opaqueToken = 0; + try + { + runtimeTypeModel.TakeLock(ref opaqueToken); + MetaType metaType2; + while ((metaType2 = source.baseType) != null) + { + source = metaType2; + } + result = source; + } + finally + { + runtimeTypeModel.ReleaseLock(opaqueToken); + } + return result; + } + + internal bool IsPrepared() + { + return false; + } + + internal static StringBuilder NewLine(StringBuilder builder, int indent) + { + return Helpers.AppendLine(builder).Append(' ', indent * 3); + } + + internal void WriteSchema(StringBuilder builder, int indent, ref bool requiresBclImport) + { + bool flag = this.surrogate != null; + if (!flag) + { + ValueMember[] array = new ValueMember[this.fields.Count]; + this.fields.CopyTo(array, 0); + Array.Sort(array, ValueMember.Comparer.Default); + bool isList = this.IsList; + if (isList) + { + string schemaTypeName = this.model.GetSchemaTypeName(TypeModel.GetListItemType(this.model, this.type), DataFormat.Default, false, false, ref requiresBclImport); + MetaType.NewLine(builder, indent).Append("message ").Append(this.GetSchemaTypeName()).Append(" {"); + MetaType.NewLine(builder, indent + 1).Append("repeated ").Append(schemaTypeName).Append(" items = 1;"); + MetaType.NewLine(builder, indent).Append('}'); + } + else + { + bool isAutoTuple = this.IsAutoTuple; + if (isAutoTuple) + { + MemberInfo[] array2; + bool flag2 = MetaType.ResolveTupleConstructor(this.type, out array2) != null; + if (flag2) + { + MetaType.NewLine(builder, indent).Append("message ").Append(this.GetSchemaTypeName()).Append(" {"); + for (int i = 0; i < array2.Length; i++) + { + bool flag3 = array2[i] is PropertyInfo; + Type effectiveType; + if (flag3) + { + effectiveType = ((PropertyInfo)array2[i]).PropertyType; + } + else + { + bool flag4 = array2[i] is FieldInfo; + if (!flag4) + { + throw new NotSupportedException("Unknown member type: " + array2[i].GetType().Name); + } + effectiveType = ((FieldInfo)array2[i]).FieldType; + } + MetaType.NewLine(builder, indent + 1).Append("optional ").Append(this.model.GetSchemaTypeName(effectiveType, DataFormat.Default, false, false, ref requiresBclImport).Replace('.', '_')).Append(' ').Append(array2[i].Name).Append(" = ").Append(i + 1).Append(';'); + } + MetaType.NewLine(builder, indent).Append('}'); + } + } + else + { + bool flag5 = Helpers.IsEnum(this.type); + if (flag5) + { + MetaType.NewLine(builder, indent).Append("enum ").Append(this.GetSchemaTypeName()).Append(" {"); + bool flag6 = array.Length == 0 && this.EnumPassthru; + if (flag6) + { + bool flag7 = this.type.IsDefined(this.model.MapType(typeof(FlagsAttribute)), false); + if (flag7) + { + MetaType.NewLine(builder, indent + 1).Append("// this is a composite/flags enumeration"); + } + else + { + MetaType.NewLine(builder, indent + 1).Append("// this enumeration will be passed as a raw value"); + } + foreach (FieldInfo fieldInfo in this.type.GetFields()) + { + bool flag8 = fieldInfo.IsStatic && fieldInfo.IsLiteral; + if (flag8) + { + object rawConstantValue = fieldInfo.GetRawConstantValue(); + MetaType.NewLine(builder, indent + 1).Append(fieldInfo.Name).Append(" = ").Append(rawConstantValue).Append(";"); + } + } + } + else + { + foreach (ValueMember valueMember in array) + { + MetaType.NewLine(builder, indent + 1).Append(valueMember.Name).Append(" = ").Append(valueMember.FieldNumber).Append(';'); + } + } + MetaType.NewLine(builder, indent).Append('}'); + } + else + { + MetaType.NewLine(builder, indent).Append("message ").Append(this.GetSchemaTypeName()).Append(" {"); + foreach (ValueMember valueMember2 in array) + { + string value = (valueMember2.ItemType != null) ? "repeated" : (valueMember2.IsRequired ? "required" : "optional"); + MetaType.NewLine(builder, indent + 1).Append(value).Append(' '); + bool flag9 = valueMember2.DataFormat == DataFormat.Group; + if (flag9) + { + builder.Append("group "); + } + string schemaTypeName2 = valueMember2.GetSchemaTypeName(true, ref requiresBclImport); + builder.Append(schemaTypeName2).Append(" ").Append(valueMember2.Name).Append(" = ").Append(valueMember2.FieldNumber); + bool flag10 = valueMember2.DefaultValue != null; + if (flag10) + { + bool flag11 = valueMember2.DefaultValue is string; + if (flag11) + { + builder.Append(" [default = \"").Append(valueMember2.DefaultValue).Append("\"]"); + } + else + { + bool flag12 = valueMember2.DefaultValue is bool; + if (flag12) + { + builder.Append(((bool)valueMember2.DefaultValue) ? " [default = true]" : " [default = false]"); + } + else + { + builder.Append(" [default = ").Append(valueMember2.DefaultValue).Append(']'); + } + } + } + bool flag13 = valueMember2.ItemType != null && valueMember2.IsPacked; + if (flag13) + { + builder.Append(" [packed=true]"); + } + builder.Append(';'); + bool flag14 = schemaTypeName2 == "bcl.NetObjectProxy" && valueMember2.AsReference && !valueMember2.DynamicType; + if (flag14) + { + builder.Append(" // reference-tracked ").Append(valueMember2.GetSchemaTypeName(false, ref requiresBclImport)); + } + } + bool flag15 = this.subTypes != null && this.subTypes.Count != 0; + if (flag15) + { + MetaType.NewLine(builder, indent + 1).Append("// the following represent sub-types; at most 1 should have a value"); + SubType[] array6 = new SubType[this.subTypes.Count]; + this.subTypes.CopyTo(array6, 0); + Array.Sort(array6, SubType.Comparer.Default); + foreach (SubType subType in array6) + { + string schemaTypeName3 = subType.DerivedType.GetSchemaTypeName(); + MetaType.NewLine(builder, indent + 1).Append("optional ").Append(schemaTypeName3).Append(" ").Append(schemaTypeName3).Append(" = ").Append(subType.FieldNumber).Append(';'); + } + } + MetaType.NewLine(builder, indent).Append('}'); + } + } + } + } + } + } +} diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MetaType.cs.meta b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MetaType.cs.meta new file mode 100644 index 00000000..4dcc0567 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MetaType.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9896348409133c84db5b167634c43101 +timeCreated: 1611404191 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MutableList.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MutableList.cs new file mode 100644 index 00000000..3afa5609 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MutableList.cs @@ -0,0 +1,29 @@ +using System; + +namespace ProtoBuf.Meta +{ + internal sealed class MutableList : BasicList + { + public new object this[int index] + { + get + { + return this.head[index]; + } + set + { + this.head[index] = value; + } + } + + public void RemoveLast() + { + this.head.RemoveLastWithMutate(); + } + + public new void Clear() + { + this.head.Clear(); + } + } +} diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MutableList.cs.meta b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MutableList.cs.meta new file mode 100644 index 00000000..0ee40320 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/MutableList.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9075f746967b13049b559b21f9ba847f +timeCreated: 1611404139 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/RuntimeTypeModel.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/RuntimeTypeModel.cs new file mode 100644 index 00000000..2975c163 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/RuntimeTypeModel.cs @@ -0,0 +1,1160 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using System.Text; +using System.Threading; +using ProtoBuf.Serializers; + +namespace ProtoBuf.Meta +{ + public sealed class RuntimeTypeModel : TypeModel + { + public bool InferTagFromNameDefault + { + get + { + return this.GetOption(1); + } + set + { + this.SetOption(1, value); + } + } + + public bool AutoAddProtoContractTypesOnly + { + get + { + return this.GetOption(128); + } + set + { + this.SetOption(128, value); + } + } + + public bool UseImplicitZeroDefaults + { + get + { + return this.GetOption(32); + } + set + { + bool flag = !value && this.GetOption(2); + if (flag) + { + throw new InvalidOperationException("UseImplicitZeroDefaults cannot be disabled on the default model"); + } + this.SetOption(32, value); + } + } + + public bool AllowParseableTypes + { + get + { + return this.GetOption(64); + } + set + { + this.SetOption(64, value); + } + } + + public static RuntimeTypeModel Default + { + get + { + return RuntimeTypeModel.Singleton.Value; + } + } + + public static RuntimeTypeModel ThreadDefault + { + get + { + return RuntimeTypeModel.Singleton.DefaultValue; + } + } + + public MetaType this[Type type] + { + get + { + return (MetaType)this.types[this.FindOrAddAuto(type, true, false, false)]; + } + } + + public bool AutoAddMissingTypes + { + get + { + return this.GetOption(8); + } + set + { + bool flag = !value && this.GetOption(2); + if (flag) + { + throw new InvalidOperationException("The default model must allow missing types"); + } + this.ThrowIfFrozen(); + this.SetOption(8, value); + } + } + + public int MetadataTimeoutMilliseconds + { + get + { + return this.metadataTimeoutMilliseconds; + } + set + { + bool flag = value <= 0; + if (flag) + { + throw new ArgumentOutOfRangeException("MetadataTimeoutMilliseconds"); + } + this.metadataTimeoutMilliseconds = value; + } + } + + public int LockCount + { + get + { + return this.lockCount; + } + } + + public event LockContentedEventHandler LockContended; + + private byte options; + + private const byte OPTIONS_InferTagFromNameDefault = 1; + + private const byte OPTIONS_IsDefaultModel = 2; + + private const byte OPTIONS_Frozen = 4; + + private const byte OPTIONS_AutoAddMissingTypes = 8; + + private const byte OPTIONS_UseImplicitZeroDefaults = 32; + + private const byte OPTIONS_AllowParseableTypes = 64; + + private const byte OPTIONS_AutoAddProtoContractTypesOnly = 128; + + private static readonly BasicList.MatchPredicate MetaTypeFinder = new BasicList.MatchPredicate(RuntimeTypeModel.MetaTypeFinderImpl); + + private static readonly BasicList.MatchPredicate BasicTypeFinder = new BasicList.MatchPredicate(RuntimeTypeModel.BasicTypeFinderImpl); + + private BasicList basicTypes = new BasicList(); + + private readonly BasicList types = new BasicList(); + + private int metadataTimeoutMilliseconds = 5000; + + private int lockCount; + + private int contentionCounter = 1; + + private MethodInfo defaultFactory; + + private sealed class Singleton + { + internal static readonly RuntimeTypeModel Value = new RuntimeTypeModel(true); + + private static RuntimeTypeModel ThreadValue = null; + + internal static RuntimeTypeModel DefaultValue = null; + + private Singleton() + { + } + + public static void SetMultiThread(bool multiThread) + { + if (multiThread) + { + RuntimeTypeModel.Singleton.ThreadValue = new RuntimeTypeModel(true); + RuntimeTypeModel.Singleton.DefaultValue = RuntimeTypeModel.Singleton.ThreadValue; + } + else + { + RuntimeTypeModel.Singleton.DefaultValue = RuntimeTypeModel.Singleton.Value; + } + } + } + + private sealed class BasicType + { + public Type Type + { + get + { + return this.type; + } + } + + public IProtoSerializer Serializer + { + get + { + return this.serializer; + } + } + + private readonly Type type; + + private readonly IProtoSerializer serializer; + + public BasicType(Type type, IProtoSerializer serializer) + { + this.type = type; + this.serializer = serializer; + } + } + + private bool GetOption(byte option) + { + return (this.options & option) == option; + } + + private void SetOption(byte option, bool value) + { + if (value) + { + this.options |= option; + } + else + { + this.options &=(byte) ~option; + } + } + + public static void SetMultiThread(bool multiThread) + { + RuntimeTypeModel.Singleton.SetMultiThread(multiThread); + } + + public IEnumerable GetTypes() + { + return this.types; + } + + public override string GetSchema(Type type) + { + BasicList basicList = new BasicList(); + MetaType metaType = null; + bool flag = false; + bool flag2 = type == null; + if (flag2) + { + foreach (object obj in this.types) + { + MetaType metaType2 = (MetaType)obj; + MetaType surrogateOrBaseOrSelf = metaType2.GetSurrogateOrBaseOrSelf(false); + bool flag3 = !basicList.Contains(surrogateOrBaseOrSelf); + if (flag3) + { + basicList.Add(surrogateOrBaseOrSelf); + this.CascadeDependents(basicList, surrogateOrBaseOrSelf); + } + } + } + else + { + Type underlyingType = Helpers.GetUnderlyingType(type); + bool flag4 = underlyingType != null; + if (flag4) + { + type = underlyingType; + } + WireType wireType; + flag = (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out wireType, false, false, false, false) != null); + bool flag5 = !flag; + if (flag5) + { + int num = this.FindOrAddAuto(type, false, false, false); + bool flag6 = num < 0; + if (flag6) + { + throw new ArgumentException("The type specified is not a contract-type", "type"); + } + metaType = ((MetaType)this.types[num]).GetSurrogateOrBaseOrSelf(false); + basicList.Add(metaType); + this.CascadeDependents(basicList, metaType); + } + } + StringBuilder stringBuilder = new StringBuilder(); + string text = null; + bool flag7 = !flag; + if (flag7) + { + IEnumerable enumerable = (metaType == null) ? this.types : basicList; + foreach (object obj2 in enumerable) + { + MetaType metaType3 = (MetaType)obj2; + bool isList = metaType3.IsList; + if (!isList) + { + string @namespace = metaType3.Type.Namespace; + bool flag8 = !Helpers.IsNullOrEmpty(@namespace); + if (flag8) + { + bool flag9 = @namespace.StartsWith("System."); + if (!flag9) + { + bool flag10 = text == null; + if (flag10) + { + text = @namespace; + } + else + { + bool flag11 = text == @namespace; + if (!flag11) + { + text = null; + break; + } + } + } + } + } + } + } + bool flag12 = !Helpers.IsNullOrEmpty(text); + if (flag12) + { + stringBuilder.Append("package ").Append(text).Append(';'); + Helpers.AppendLine(stringBuilder); + } + bool flag13 = false; + StringBuilder stringBuilder2 = new StringBuilder(); + MetaType[] array = new MetaType[basicList.Count]; + basicList.CopyTo(array, 0); + Array.Sort(array, MetaType.Comparer.Default); + bool flag14 = flag; + if (flag14) + { + Helpers.AppendLine(stringBuilder2).Append("message ").Append(type.Name).Append(" {"); + MetaType.NewLine(stringBuilder2, 1).Append("optional ").Append(this.GetSchemaTypeName(type, DataFormat.Default, false, false, ref flag13)).Append(" value = 1;"); + Helpers.AppendLine(stringBuilder2).Append('}'); + } + else + { + foreach (MetaType metaType4 in array) + { + bool flag15 = metaType4.IsList && metaType4 != metaType; + if (!flag15) + { + metaType4.WriteSchema(stringBuilder2, 0, ref flag13); + } + } + } + bool flag16 = flag13; + if (flag16) + { + stringBuilder.Append("import \"bcl.proto\"; // schema for protobuf-net's handling of core .NET types"); + Helpers.AppendLine(stringBuilder); + } + return Helpers.AppendLine(stringBuilder.Append(stringBuilder2)).ToString(); + } + + private void CascadeDependents(BasicList list, MetaType metaType) + { + bool isList = metaType.IsList; + if (isList) + { + Type listItemType = TypeModel.GetListItemType(this, metaType.Type); + WireType wireType; + IProtoSerializer protoSerializer = ValueMember.TryGetCoreSerializer(this, DataFormat.Default, listItemType, out wireType, false, false, false, false); + bool flag = protoSerializer == null; + if (flag) + { + int num = this.FindOrAddAuto(listItemType, false, false, false); + bool flag2 = num >= 0; + if (flag2) + { + MetaType metaType2 = ((MetaType)this.types[num]).GetSurrogateOrBaseOrSelf(false); + bool flag3 = !list.Contains(metaType2); + if (flag3) + { + list.Add(metaType2); + this.CascadeDependents(list, metaType2); + } + } + } + } + else + { + bool isAutoTuple = metaType.IsAutoTuple; + MetaType metaType2; + if (isAutoTuple) + { + MemberInfo[] array; + bool flag4 = MetaType.ResolveTupleConstructor(metaType.Type, out array) != null; + if (flag4) + { + for (int i = 0; i < array.Length; i++) + { + Type type = null; + bool flag5 = array[i] is PropertyInfo; + if (flag5) + { + type = ((PropertyInfo)array[i]).PropertyType; + } + else + { + bool flag6 = array[i] is FieldInfo; + if (flag6) + { + type = ((FieldInfo)array[i]).FieldType; + } + } + WireType wireType2; + IProtoSerializer protoSerializer2 = ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out wireType2, false, false, false, false); + bool flag7 = protoSerializer2 == null; + if (flag7) + { + int num2 = this.FindOrAddAuto(type, false, false, false); + bool flag8 = num2 >= 0; + if (flag8) + { + metaType2 = ((MetaType)this.types[num2]).GetSurrogateOrBaseOrSelf(false); + bool flag9 = !list.Contains(metaType2); + if (flag9) + { + list.Add(metaType2); + this.CascadeDependents(list, metaType2); + } + } + } + } + } + } + else + { + foreach (object obj in metaType.Fields) + { + ValueMember valueMember = (ValueMember)obj; + Type type2 = valueMember.ItemType; + bool flag10 = type2 == null; + if (flag10) + { + type2 = valueMember.MemberType; + } + WireType wireType3; + IProtoSerializer protoSerializer3 = ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type2, out wireType3, false, false, false, false); + bool flag11 = protoSerializer3 == null; + if (flag11) + { + int num3 = this.FindOrAddAuto(type2, false, false, false); + bool flag12 = num3 >= 0; + if (flag12) + { + metaType2 = ((MetaType)this.types[num3]).GetSurrogateOrBaseOrSelf(false); + bool flag13 = !list.Contains(metaType2); + if (flag13) + { + list.Add(metaType2); + this.CascadeDependents(list, metaType2); + } + } + } + } + } + bool hasSubtypes = metaType.HasSubtypes; + if (hasSubtypes) + { + foreach (SubType subType in metaType.GetSubtypes()) + { + metaType2 = subType.DerivedType.GetSurrogateOrSelf(); + bool flag14 = !list.Contains(metaType2); + if (flag14) + { + list.Add(metaType2); + this.CascadeDependents(list, metaType2); + } + } + } + metaType2 = metaType.BaseType; + bool flag15 = metaType2 != null; + if (flag15) + { + metaType2 = metaType2.GetSurrogateOrSelf(); + } + bool flag16 = metaType2 != null && !list.Contains(metaType2); + if (flag16) + { + list.Add(metaType2); + this.CascadeDependents(list, metaType2); + } + } + } + + internal RuntimeTypeModel(bool isDefault) + { + this.AutoAddMissingTypes = true; + this.UseImplicitZeroDefaults = true; + this.SetOption(2, isDefault); + } + + internal MetaType FindWithoutAdd(Type type) + { + foreach (object obj in this.types) + { + MetaType metaType = (MetaType)obj; + bool flag = metaType.Type == type; + if (flag) + { + bool pending = metaType.Pending; + if (pending) + { + this.WaitOnLock(metaType); + } + return metaType; + } + } + Type type2 = TypeModel.ResolveProxies(type); + return (type2 == null) ? null : this.FindWithoutAdd(type2); + } + + private static bool MetaTypeFinderImpl(object value, object ctx) + { + return ((MetaType)value).Type == (Type)ctx; + } + + private static bool BasicTypeFinderImpl(object value, object ctx) + { + return ((RuntimeTypeModel.BasicType)value).Type == (Type)ctx; + } + + private void WaitOnLock(MetaType type) + { + int opaqueToken = 0; + try + { + this.TakeLock(ref opaqueToken); + } + finally + { + this.ReleaseLock(opaqueToken); + } + } + + internal IProtoSerializer TryGetBasicTypeSerializer(Type type) + { + int num = this.basicTypes.IndexOf(RuntimeTypeModel.BasicTypeFinder, type); + bool flag = num >= 0; + IProtoSerializer result; + if (flag) + { + result = ((RuntimeTypeModel.BasicType)this.basicTypes[num]).Serializer; + } + else + { + BasicList obj = this.basicTypes; + lock (obj) + { + num = this.basicTypes.IndexOf(RuntimeTypeModel.BasicTypeFinder, type); + bool flag2 = num >= 0; + if (flag2) + { + result = ((RuntimeTypeModel.BasicType)this.basicTypes[num]).Serializer; + } + else + { + MetaType.AttributeFamily contractFamily = MetaType.GetContractFamily(this, type, null); + WireType wireType; + IProtoSerializer protoSerializer = (contractFamily == MetaType.AttributeFamily.None) ? ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out wireType, false, false, false, false) : null; + bool flag3 = protoSerializer != null; + if (flag3) + { + this.basicTypes.Add(new RuntimeTypeModel.BasicType(type, protoSerializer)); + } + result = protoSerializer; + } + } + } + return result; + } + + public void Clear() + { + this.types.Clear(); + } + + internal int FindOrAddAuto(Type type, bool demand, bool addWithContractOnly, bool addEvenIfAutoDisabled) + { + int num = this.types.IndexOf(RuntimeTypeModel.MetaTypeFinder, type); + bool flag = num >= 0; + int result; + if (flag) + { + MetaType metaType = (MetaType)this.types[num]; + bool pending = metaType.Pending; + if (pending) + { + this.WaitOnLock(metaType); + } + result = num; + } + else + { + bool flag2 = this.AutoAddMissingTypes || addEvenIfAutoDisabled; + bool flag3 = !Helpers.IsEnum(type) && this.TryGetBasicTypeSerializer(type) != null; + if (flag3) + { + bool flag4 = flag2 && !addWithContractOnly; + if (flag4) + { + throw MetaType.InbuiltType(type); + } + result = -1; + } + else + { + Type type2 = TypeModel.ResolveProxies(type); + bool flag5 = type2 != null; + if (flag5) + { + num = this.types.IndexOf(RuntimeTypeModel.MetaTypeFinder, type2); + type = type2; + } + bool flag6 = num < 0; + if (flag6) + { + int opaqueToken = 0; + try + { + this.TakeLock(ref opaqueToken); + MetaType metaType; + bool flag7 = (metaType = this.RecogniseCommonTypes(type)) == null; + if (flag7) + { + MetaType.AttributeFamily contractFamily = MetaType.GetContractFamily(this, type, null); + bool flag8 = contractFamily == MetaType.AttributeFamily.AutoTuple; + if (flag8) + { + addEvenIfAutoDisabled = (flag2 = true); + } + bool flag9 = !flag2 || (!Helpers.IsEnum(type) && addWithContractOnly && contractFamily == MetaType.AttributeFamily.None); + if (flag9) + { + if (demand) + { + TypeModel.ThrowUnexpectedType(type); + } + return num; + } + metaType = this.Create(type); + } + metaType.Pending = true; + bool flag10 = false; + int num2 = this.types.IndexOf(RuntimeTypeModel.MetaTypeFinder, type); + bool flag11 = num2 < 0; + if (flag11) + { + this.ThrowIfFrozen(); + num = this.types.Add(metaType); + flag10 = true; + } + else + { + num = num2; + } + bool flag12 = flag10; + if (flag12) + { + metaType.ApplyDefaultBehaviour(); + metaType.Pending = false; + } + } + finally + { + this.ReleaseLock(opaqueToken); + } + } + result = num; + } + } + return result; + } + + private MetaType RecogniseCommonTypes(Type type) + { + return null; + } + + private MetaType Create(Type type) + { + this.ThrowIfFrozen(); + return new MetaType(this, type, this.defaultFactory); + } + + public MetaType Add(Type type, bool applyDefaultBehaviour) + { + bool flag = type == null; + if (flag) + { + throw new ArgumentNullException("type"); + } + MetaType metaType = this.FindWithoutAdd(type); + bool flag2 = metaType != null; + MetaType result; + if (flag2) + { + result = metaType; + } + else + { + int opaqueToken = 0; + bool flag3 = type.IsInterface && base.MapType(MetaType.ienumerable).IsAssignableFrom(type) && TypeModel.GetListItemType(this, type) == null; + if (flag3) + { + throw new ArgumentException("IEnumerable[] data cannot be used as a meta-type unless an Add method can be resolved"); + } + try + { + metaType = this.RecogniseCommonTypes(type); + bool flag4 = metaType != null; + if (flag4) + { + bool flag5 = !applyDefaultBehaviour; + if (flag5) + { + throw new ArgumentException("Default behaviour must be observed for certain types with special handling; " + type.FullName, "applyDefaultBehaviour"); + } + applyDefaultBehaviour = false; + } + bool flag6 = metaType == null; + if (flag6) + { + metaType = this.Create(type); + } + metaType.Pending = true; + this.TakeLock(ref opaqueToken); + bool flag7 = this.FindWithoutAdd(type) != null; + if (flag7) + { + throw new ArgumentException("Duplicate type", "type"); + } + this.ThrowIfFrozen(); + this.types.Add(metaType); + bool flag8 = applyDefaultBehaviour; + if (flag8) + { + metaType.ApplyDefaultBehaviour(); + } + metaType.Pending = false; + } + finally + { + this.ReleaseLock(opaqueToken); + } + result = metaType; + } + return result; + } + + private void ThrowIfFrozen() + { + bool option = this.GetOption(4); + if (option) + { + throw new InvalidOperationException("The model cannot be changed once frozen"); + } + } + + public void Freeze() + { + bool option = this.GetOption(2); + if (option) + { + throw new InvalidOperationException("The default model cannot be frozen"); + } + this.SetOption(4, true); + } + + protected override int GetKeyImpl(Type type) + { + return this.GetKey(type, false, true); + } + + internal int GetKey(Type type, bool demand, bool getBaseKey) + { + Helpers.DebugAssert(type != null); + int result; + try + { + int num = this.FindOrAddAuto(type, demand, true, false); + bool flag = num >= 0; + if (flag) + { + MetaType metaType = (MetaType)this.types[num]; + if (getBaseKey) + { + metaType = MetaType.GetRootType(metaType); + num = this.FindOrAddAuto(metaType.Type, true, true, false); + } + } + result = num; + } + catch (NotSupportedException) + { + throw; + } + catch (Exception ex) + { + bool flag2 = ex.Message.IndexOf(type.FullName) >= 0; + if (flag2) + { + throw; + } + throw new ProtoException(ex.Message + " (" + type.FullName + ")", ex); + } + return result; + } + + protected internal override void Serialize(int key, object value, ProtoWriter dest) + { + ((MetaType)this.types[key]).Serializer.Write(value, dest); + } + + protected internal override object Deserialize(int key, object value, ProtoReader source) + { + IProtoSerializer serializer = ((MetaType)this.types[key]).Serializer; + bool flag = value == null && Helpers.IsValueType(serializer.ExpectedType); + object result; + if (flag) + { + bool requiresOldValue = serializer.RequiresOldValue; + if (requiresOldValue) + { + value = Activator.CreateInstance(serializer.ExpectedType); + } + result = serializer.Read(value, source); + } + else + { + result = serializer.Read(value, source); + } + return result; + } + + internal bool IsPrepared(Type type) + { + MetaType metaType = this.FindWithoutAdd(type); + return metaType != null && metaType.IsPrepared(); + } + + internal EnumSerializer.EnumPair[] GetEnumMap(Type type) + { + int num = this.FindOrAddAuto(type, false, false, false); + return (num < 0) ? null : ((MetaType)this.types[num]).GetEnumMap(); + } + + internal void TakeLock(ref int opaqueToken) + { + opaqueToken = 0; + bool flag = Monitor.TryEnter(this.types, this.metadataTimeoutMilliseconds); + if (flag) + { + opaqueToken = this.GetContention(); + this.lockCount++; + return; + } + this.AddContention(); + throw new TimeoutException("Timeout while inspecting metadata; this may indicate a deadlock. This can often be avoided by preparing necessary serializers during application initialization, rather than allowing multiple threads to perform the initial metadata inspection; please also see the LockContended event"); + } + + private int GetContention() + { + return Interlocked.CompareExchange(ref this.contentionCounter, 0, 0); + } + + private void AddContention() + { + Interlocked.Increment(ref this.contentionCounter); + } + + internal void ReleaseLock(int opaqueToken) + { + bool flag = opaqueToken != 0; + if (flag) + { + Monitor.Exit(this.types); + bool flag2 = opaqueToken != this.GetContention(); + if (flag2) + { + LockContentedEventHandler lockContended = this.LockContended; + bool flag3 = lockContended != null; + if (flag3) + { + string stackTrace; + try + { + throw new ProtoException(); + } + catch (Exception ex) + { + stackTrace = ex.StackTrace; + } + lockContended(this, new LockContentedEventArgs(stackTrace)); + } + } + } + } + + internal void ResolveListTypes(Type type, ref Type itemType, ref Type defaultType) + { + bool flag = type == null; + if (!flag) + { + bool flag2 = Helpers.GetTypeCode(type) != ProtoTypeCode.Unknown; + if (!flag2) + { + bool ignoreListHandling = this[type].IgnoreListHandling; + if (!ignoreListHandling) + { + bool isArray = type.IsArray; + if (isArray) + { + bool flag3 = type.GetArrayRank() != 1; + if (flag3) + { + throw new NotSupportedException("Multi-dimension arrays are supported"); + } + itemType = type.GetElementType(); + bool flag4 = itemType == base.MapType(typeof(byte)); + if (flag4) + { + Type type2; + itemType = (type2 = null); + defaultType = type2; + } + else + { + defaultType = type; + } + } + bool flag5 = itemType == null; + if (flag5) + { + itemType = TypeModel.GetListItemType(this, type); + } + bool flag6 = itemType != null; + if (flag6) + { + Type type3 = null; + Type type4 = null; + this.ResolveListTypes(itemType, ref type3, ref type4); + bool flag7 = type3 != null; + if (flag7) + { + throw TypeModel.CreateNestedListsNotSupported(); + } + } + bool flag8 = itemType != null && defaultType == null; + if (flag8) + { + bool flag9 = type.IsClass && !type.IsAbstract && Helpers.GetConstructor(type, Helpers.EmptyTypes, true) != null; + if (flag9) + { + defaultType = type; + } + bool flag10 = defaultType == null; + if (flag10) + { + bool isInterface = type.IsInterface; + if (isInterface) + { + Type[] genericArguments = null; + bool flag11 = type.IsGenericType && type.GetGenericTypeDefinition() == base.MapType(typeof(IDictionary<, >)) && itemType == base.MapType(typeof(KeyValuePair<, >)).MakeGenericType(genericArguments = type.GetGenericArguments()); + if (flag11) + { + defaultType = base.MapType(typeof(Dictionary<, >)).MakeGenericType(genericArguments); + } + else + { + defaultType = base.MapType(typeof(List<>)).MakeGenericType(new Type[] + { + itemType + }); + } + } + } + bool flag12 = defaultType != null && !Helpers.IsAssignableFrom(type, defaultType); + if (flag12) + { + defaultType = null; + } + } + } + } + } + } + + internal string GetSchemaTypeName(Type effectiveType, DataFormat dataFormat, bool asReference, bool dynamicType, ref bool requiresBclImport) + { + Type underlyingType = Helpers.GetUnderlyingType(effectiveType); + bool flag = underlyingType != null; + if (flag) + { + effectiveType = underlyingType; + } + bool flag2 = effectiveType == base.MapType(typeof(byte[])); + string result; + if (flag2) + { + result = "bytes"; + } + else + { + WireType wireType; + IProtoSerializer protoSerializer = ValueMember.TryGetCoreSerializer(this, dataFormat, effectiveType, out wireType, false, false, false, false); + bool flag3 = protoSerializer == null; + if (flag3) + { + bool flag4 = asReference || dynamicType; + if (flag4) + { + requiresBclImport = true; + result = "bcl.NetObjectProxy"; + } + else + { + result = this[effectiveType].GetSurrogateOrBaseOrSelf(true).GetSchemaTypeName(); + } + } + else + { + bool flag5 = protoSerializer is ParseableSerializer; + if (!flag5) + { + ProtoTypeCode typeCode = Helpers.GetTypeCode(effectiveType); + switch (typeCode) + { + case ProtoTypeCode.Boolean: + return "bool"; + case ProtoTypeCode.Char: + case ProtoTypeCode.Byte: + case ProtoTypeCode.UInt16: + case ProtoTypeCode.UInt32: + if (dataFormat != DataFormat.FixedSize) + { + return "uint32"; + } + return "fixed32"; + case ProtoTypeCode.SByte: + case ProtoTypeCode.Int16: + case ProtoTypeCode.Int32: + if (dataFormat == DataFormat.ZigZag) + { + return "sint32"; + } + if (dataFormat != DataFormat.FixedSize) + { + return "int32"; + } + return "sfixed32"; + case ProtoTypeCode.Int64: + if (dataFormat == DataFormat.ZigZag) + { + return "sint64"; + } + if (dataFormat != DataFormat.FixedSize) + { + return "int64"; + } + return "sfixed64"; + case ProtoTypeCode.UInt64: + if (dataFormat != DataFormat.FixedSize) + { + return "uint64"; + } + return "fixed64"; + case ProtoTypeCode.Single: + return "float"; + case ProtoTypeCode.Double: + return "double"; + case ProtoTypeCode.Decimal: + requiresBclImport = true; + return "bcl.Decimal"; + case ProtoTypeCode.DateTime: + requiresBclImport = true; + return "bcl.DateTime"; + case (ProtoTypeCode)17: + break; + case ProtoTypeCode.String: + if (asReference) + { + requiresBclImport = true; + } + return asReference ? "bcl.NetObjectProxy" : "string"; + default: + if (typeCode == ProtoTypeCode.TimeSpan) + { + requiresBclImport = true; + return "bcl.TimeSpan"; + } + if (typeCode == ProtoTypeCode.Guid) + { + requiresBclImport = true; + return "bcl.Guid"; + } + break; + } + throw new NotSupportedException("No .proto map found for: " + effectiveType.FullName); + } + if (asReference) + { + requiresBclImport = true; + } + result = (asReference ? "bcl.NetObjectProxy" : "string"); + } + } + return result; + } + + public void SetDefaultFactory(MethodInfo methodInfo) + { + this.VerifyFactory(methodInfo, null); + this.defaultFactory = methodInfo; + } + + internal void VerifyFactory(MethodInfo factory, Type type) + { + bool flag = factory != null; + if (flag) + { + bool flag2 = type != null && Helpers.IsValueType(type); + if (flag2) + { + throw new InvalidOperationException(); + } + bool flag3 = !factory.IsStatic; + if (flag3) + { + throw new ArgumentException("A factory-method must be static", "factory"); + } + bool flag4 = type != null && factory.ReturnType != type && factory.ReturnType != base.MapType(typeof(object)); + if (flag4) + { + throw new ArgumentException("The factory-method must return object" + ((type == null) ? "" : (" or " + type.FullName)), "factory"); + } + bool flag5 = !CallbackSet.CheckCallbackParameters(this, factory); + if (flag5) + { + throw new ArgumentException("Invalid factory signature in " + factory.DeclaringType.FullName + "." + factory.Name, "factory"); + } + } + } + } +} diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/RuntimeTypeModel.cs.meta b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/RuntimeTypeModel.cs.meta new file mode 100644 index 00000000..547e89c2 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/RuntimeTypeModel.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 05191c47ba04cdf4e9b086621a0fb424 +timeCreated: 1611402962 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/SubType.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/SubType.cs new file mode 100644 index 00000000..6686ab73 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/SubType.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using ProtoBuf.Serializers; + +namespace ProtoBuf.Meta +{ + public sealed class SubType + { + public int FieldNumber + { + get + { + return this.fieldNumber; + } + } + + public MetaType DerivedType + { + get + { + return this.derivedType; + } + } + + internal IProtoSerializer Serializer + { + get + { + bool flag = this.serializer == null; + if (flag) + { + this.serializer = this.BuildSerializer(); + } + return this.serializer; + } + } + + private readonly int fieldNumber; + + private readonly MetaType derivedType; + + private readonly DataFormat dataFormat; + + private IProtoSerializer serializer; + + internal sealed class Comparer : IComparer, IComparer + { + public static readonly SubType.Comparer Default = new SubType.Comparer(); + + public int Compare(object x, object y) + { + return this.Compare(x as SubType, y as SubType); + } + + public int Compare(SubType x, SubType y) + { + bool flag = x == y; + int result; + if (flag) + { + result = 0; + } + else + { + bool flag2 = x == null; + if (flag2) + { + result = -1; + } + else + { + bool flag3 = y == null; + if (flag3) + { + result = 1; + } + else + { + result = x.FieldNumber.CompareTo(y.FieldNumber); + } + } + } + return result; + } + } + + public SubType(int fieldNumber, MetaType derivedType, DataFormat format) + { + bool flag = derivedType == null; + if (flag) + { + throw new ArgumentNullException("derivedType"); + } + bool flag2 = fieldNumber <= 0; + if (flag2) + { + throw new ArgumentOutOfRangeException("fieldNumber"); + } + this.fieldNumber = fieldNumber; + this.derivedType = derivedType; + this.dataFormat = format; + } + + private IProtoSerializer BuildSerializer() + { + WireType wireType = WireType.String; + bool flag = this.dataFormat == DataFormat.Group; + if (flag) + { + wireType = WireType.StartGroup; + } + IProtoSerializer tail = new SubItemSerializer(this.derivedType.Type, this.derivedType.GetKey(false, false), this.derivedType, false); + return new TagDecorator(this.fieldNumber, wireType, false, tail); + } + } +} diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/SubType.cs.meta b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/SubType.cs.meta new file mode 100644 index 00000000..dd423340 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/SubType.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: c96bdfea838c34b4c8d995ee6bd2940f +timeCreated: 1611404538 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventArgs.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventArgs.cs new file mode 100644 index 00000000..ec466502 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventArgs.cs @@ -0,0 +1,76 @@ +using System; + +namespace ProtoBuf.Meta +{ + public class TypeFormatEventArgs : EventArgs + { + public Type Type + { + get + { + return this.type; + } + set + { + bool flag = this.type != value; + if (flag) + { + bool flag2 = this.typeFixed; + if (flag2) + { + throw new InvalidOperationException("The type is fixed and cannot be changed"); + } + this.type = value; + } + } + } + + public string FormattedName + { + get + { + return this.formattedName; + } + set + { + bool flag = this.formattedName != value; + if (flag) + { + bool flag2 = !this.typeFixed; + if (flag2) + { + throw new InvalidOperationException("The formatted-name is fixed and cannot be changed"); + } + this.formattedName = value; + } + } + } + + private Type type; + + private string formattedName; + + private readonly bool typeFixed; + + internal TypeFormatEventArgs(string formattedName) + { + bool flag = Helpers.IsNullOrEmpty(formattedName); + if (flag) + { + throw new ArgumentNullException("formattedName"); + } + this.formattedName = formattedName; + } + + internal TypeFormatEventArgs(Type type) + { + bool flag = type == null; + if (flag) + { + throw new ArgumentNullException("type"); + } + this.type = type; + this.typeFixed = true; + } + } +} diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventArgs.cs.meta b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventArgs.cs.meta new file mode 100644 index 00000000..3699b0eb --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventArgs.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 22ffb555f8ce6f64aaf7b82ffbe091a3 +timeCreated: 1611403425 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventHandler.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventHandler.cs new file mode 100644 index 00000000..54e34016 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventHandler.cs @@ -0,0 +1,6 @@ +using System; + +namespace ProtoBuf.Meta +{ + public delegate void TypeFormatEventHandler(object sender, TypeFormatEventArgs args); +} diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventHandler.cs.meta b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventHandler.cs.meta new file mode 100644 index 00000000..47deaaff --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeFormatEventHandler.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 0741ed768de0a8d429019e070d73a230 +timeCreated: 1611402967 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeModel.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeModel.cs new file mode 100644 index 00000000..018d47c0 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeModel.cs @@ -0,0 +1,1511 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Runtime.CompilerServices; +using ProtoBuf.Serializers; + +namespace ProtoBuf.Meta +{ + public abstract class TypeModel + { + public bool ForwardsOnly + { + get + { + return this.forwardsOnly; + } + set + { + this.forwardsOnly = value; + } + } + + public event TypeFormatEventHandler DynamicTypeFormatting; + + private static readonly Type ilist = typeof(IList); + + private bool forwardsOnly; + + private sealed class DeserializeItemsIterator : TypeModel.DeserializeItemsIterator, IEnumerator, IEnumerator, IDisposable, IEnumerable, IEnumerable + { + public new T Current + { + get + { + return (T)((object)base.Current); + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return this; + } + + void IDisposable.Dispose() + { + } + + public DeserializeItemsIterator(TypeModel model, Stream source, PrefixStyle style, int expectedField, SerializationContext context) : base(model, source, model.MapType(typeof(T)), style, expectedField, null, context) + { + } + } + + private class DeserializeItemsIterator : IEnumerator, IEnumerable + { + public object Current + { + get + { + return this.current; + } + } + + private bool haveObject; + + private object current; + + private readonly Stream source; + + private readonly Type type; + + private readonly PrefixStyle style; + + private readonly int expectedField; + + private readonly Serializer.TypeResolver resolver; + + private readonly TypeModel model; + + private readonly SerializationContext context; + + IEnumerator IEnumerable.GetEnumerator() + { + return this; + } + + public bool MoveNext() + { + bool flag = this.haveObject; + if (flag) + { + int num; + this.current = this.model.DeserializeWithLengthPrefix(this.source, null, this.type, this.style, this.expectedField, this.resolver, out num, out this.haveObject, this.context); + } + return this.haveObject; + } + + void IEnumerator.Reset() + { + throw new NotSupportedException(); + } + + public DeserializeItemsIterator(TypeModel model, Stream source, Type type, PrefixStyle style, int expectedField, Serializer.TypeResolver resolver, SerializationContext context) + { + this.haveObject = true; + this.source = source; + this.type = type; + this.style = style; + this.expectedField = expectedField; + this.resolver = resolver; + this.model = model; + this.context = context; + } + } + + protected internal enum CallbackType + { + BeforeSerialize, + AfterSerialize, + BeforeDeserialize, + AfterDeserialize + } + + protected internal Type MapType(Type type) + { + return this.MapType(type, true); + } + + protected internal virtual Type MapType(Type type, bool demand) + { + return type; + } + + private WireType GetWireType(ProtoTypeCode code, DataFormat format, ref Type type, out int modelKey) + { + modelKey = -1; + bool flag = Helpers.IsEnum(type); + WireType result = WireType.None;//! + if (flag) + { + modelKey = this.GetKey(ref type); + result = WireType.Variant; + } + else + { + switch (code) + { + case ProtoTypeCode.Boolean: + case ProtoTypeCode.Char: + case ProtoTypeCode.SByte: + case ProtoTypeCode.Byte: + case ProtoTypeCode.Int16: + case ProtoTypeCode.UInt16: + case ProtoTypeCode.Int32: + case ProtoTypeCode.UInt32: + return (format == DataFormat.FixedSize) ? WireType.Fixed32 : WireType.Variant; + case ProtoTypeCode.Int64: + case ProtoTypeCode.UInt64: + return (format == DataFormat.FixedSize) ? WireType.Fixed64 : WireType.Variant; + case ProtoTypeCode.Single: + return WireType.Fixed32; + case ProtoTypeCode.Double: + return WireType.Fixed64; + case ProtoTypeCode.Decimal: + case ProtoTypeCode.DateTime: + case ProtoTypeCode.String: + break; + case (ProtoTypeCode)17: + goto IL_99; + default: + if (code - ProtoTypeCode.TimeSpan > 3) + { + goto IL_99; + } + break; + } + return WireType.String; + IL_99: + bool flag2 = (modelKey = this.GetKey(ref type)) >= 0; + if (flag2) + { + result = WireType.String; + } + else + { + result = WireType.None; + } + } + return result; + } + + internal bool TrySerializeAuxiliaryType(ProtoWriter writer, Type type, DataFormat format, int tag, object value, bool isInsideList) + { + bool flag = type == null; + if (flag) + { + type = value.GetType(); + } + ProtoTypeCode typeCode = Helpers.GetTypeCode(type); + int num; + WireType wireType = this.GetWireType(typeCode, format, ref type, out num); + bool flag2 = num >= 0; + bool result; + if (flag2) + { + bool flag3 = Helpers.IsEnum(type); + if (flag3) + { + this.Serialize(num, value, writer); + result = true; + } + else + { + ProtoWriter.WriteFieldHeader(tag, wireType, writer); + WireType wireType2 = wireType; + if (wireType2 == WireType.None) + { + throw ProtoWriter.CreateException(writer); + } + if (wireType2 - WireType.String > 1) + { + this.Serialize(num, value, writer); + result = true; + } + else + { + SubItemToken token = ProtoWriter.StartSubItem(value, writer); + this.Serialize(num, value, writer); + ProtoWriter.EndSubItem(token, writer); + result = true; + } + } + } + else + { + bool flag4 = wireType != WireType.None; + if (flag4) + { + ProtoWriter.WriteFieldHeader(tag, wireType, writer); + } + ProtoTypeCode protoTypeCode = typeCode; + switch (protoTypeCode) + { + case ProtoTypeCode.Boolean: + ProtoWriter.WriteBoolean((bool)value, writer); + return true; + case ProtoTypeCode.Char: + ProtoWriter.WriteUInt16((ushort)((char)value), writer); + return true; + case ProtoTypeCode.SByte: + ProtoWriter.WriteSByte((sbyte)value, writer); + return true; + case ProtoTypeCode.Byte: + ProtoWriter.WriteByte((byte)value, writer); + return true; + case ProtoTypeCode.Int16: + ProtoWriter.WriteInt16((short)value, writer); + return true; + case ProtoTypeCode.UInt16: + ProtoWriter.WriteUInt16((ushort)value, writer); + return true; + case ProtoTypeCode.Int32: + ProtoWriter.WriteInt32((int)value, writer); + return true; + case ProtoTypeCode.UInt32: + ProtoWriter.WriteUInt32((uint)value, writer); + return true; + case ProtoTypeCode.Int64: + ProtoWriter.WriteInt64((long)value, writer); + return true; + case ProtoTypeCode.UInt64: + ProtoWriter.WriteUInt64((ulong)value, writer); + return true; + case ProtoTypeCode.Single: + ProtoWriter.WriteSingle((float)value, writer); + return true; + case ProtoTypeCode.Double: + ProtoWriter.WriteDouble((double)value, writer); + return true; + case ProtoTypeCode.Decimal: + BclHelpers.WriteDecimal((decimal)value, writer); + return true; + case ProtoTypeCode.DateTime: + BclHelpers.WriteDateTime((DateTime)value, writer); + return true; + case (ProtoTypeCode)17: + break; + case ProtoTypeCode.String: + ProtoWriter.WriteString((string)value, writer); + return true; + default: + switch (protoTypeCode) + { + case ProtoTypeCode.TimeSpan: + BclHelpers.WriteTimeSpan((TimeSpan)value, writer); + return true; + case ProtoTypeCode.ByteArray: + ProtoWriter.WriteBytes((byte[])value, writer); + return true; + case ProtoTypeCode.Guid: + BclHelpers.WriteGuid((Guid)value, writer); + return true; + case ProtoTypeCode.Uri: + ProtoWriter.WriteString(((Uri)value).AbsoluteUri, writer); + return true; + } + break; + } + Helpers.DebugAssert(wireType == WireType.None); + IEnumerable enumerable = value as IEnumerable; + bool flag5 = enumerable != null; + if (flag5) + { + if (isInsideList) + { + throw TypeModel.CreateNestedListsNotSupported(); + } + foreach (object obj in enumerable) + { + bool flag6 = obj == null; + if (flag6) + { + throw new NullReferenceException(); + } + bool flag7 = !this.TrySerializeAuxiliaryType(writer, null, format, tag, obj, true); + if (flag7) + { + TypeModel.ThrowUnexpectedType(obj.GetType()); + } + } + result = true; + } + else + { + result = false; + } + } + return result; + } + + private void SerializeCore(ProtoWriter writer, object value) + { + bool flag = value == null; + if (flag) + { + throw new ArgumentNullException("value"); + } + Type type = value.GetType(); + int key = this.GetKey(ref type); + bool flag2 = key >= 0; + if (flag2) + { + this.Serialize(key, value, writer); + } + else + { + bool flag3 = !this.TrySerializeAuxiliaryType(writer, type, DataFormat.Default, 1, value, false); + if (flag3) + { + TypeModel.ThrowUnexpectedType(type); + } + } + } + + public void Serialize(Stream dest, object value) + { + this.Serialize(dest, value, null); + } + + public void Serialize(Stream dest, object value, SerializationContext context) + { + using (ProtoWriter protoWriter = new ProtoWriter(dest, this, context)) + { + protoWriter.SetRootObject(value); + this.SerializeCore(protoWriter, value); + protoWriter.Close(); + } + } + + public void Serialize(ProtoWriter dest, object value) + { + bool flag = dest == null; + if (flag) + { + throw new ArgumentNullException("dest"); + } + dest.CheckDepthFlushlock(); + dest.SetRootObject(value); + this.SerializeCore(dest, value); + dest.CheckDepthFlushlock(); + ProtoWriter.Flush(dest); + } + + public object DeserializeWithLengthPrefix(Stream source, object value, Type type, PrefixStyle style, int fieldNumber) + { + int num; + return this.DeserializeWithLengthPrefix(source, value, type, style, fieldNumber, null, out num); + } + + public object DeserializeWithLengthPrefix(Stream source, object value, Type type, PrefixStyle style, int expectedField, Serializer.TypeResolver resolver) + { + int num; + return this.DeserializeWithLengthPrefix(source, value, type, style, expectedField, resolver, out num); + } + + public object DeserializeWithLengthPrefix(Stream source, object value, Type type, PrefixStyle style, int expectedField, Serializer.TypeResolver resolver, out int bytesRead) + { + bool flag; + return this.DeserializeWithLengthPrefix(source, value, type, style, expectedField, resolver, out bytesRead, out flag, null); + } + + private object DeserializeWithLengthPrefix(Stream source, object value, Type type, PrefixStyle style, int expectedField, Serializer.TypeResolver resolver, out int bytesRead, out bool haveObject, SerializationContext context) + { + haveObject = false; + bytesRead = 0; + bool flag = type == null && (style != PrefixStyle.Base128 || resolver == null); + if (flag) + { + throw new InvalidOperationException("A type must be provided unless base-128 prefixing is being used in combination with a resolver"); + } + for (;;) + { + bool flag2 = expectedField > 0 || resolver != null; + int num2; + int num3; + int num = ProtoReader.ReadLengthPrefix(source, flag2, style, out num2, out num3); + bool flag3 = num3 == 0; + if (flag3) + { + break; + } + bytesRead += num3; + bool flag4 = num < 0; + if (flag4) + { + goto Block_6; + } + bool flag5; + if (style != PrefixStyle.Base128) + { + flag5 = false; + } + else + { + bool flag6 = flag2 && expectedField == 0 && type == null && resolver != null; + if (flag6) + { + type = resolver(num2); + flag5 = (type == null); + } + else + { + flag5 = (expectedField != num2); + } + } + bool flag7 = flag5; + if (flag7) + { + bool flag8 = num == int.MaxValue; + if (flag8) + { + goto Block_13; + } + ProtoReader.Seek(source, num, null); + bytesRead += num; + } + if (!flag5) + { + goto Block_14; + } + } + return value; + Block_6: + return value; + Block_13: + throw new InvalidOperationException(); + Block_14: + ProtoReader protoReader = null; + object result; + try + { + int num = 0;//! + //int num;//! + protoReader = ProtoReader.Create(source, this, context, num); + int key = this.GetKey(ref type); + bool flag9 = key >= 0 && !Helpers.IsEnum(type); + if (flag9) + { + value = this.Deserialize(key, value, protoReader); + } + else + { + bool flag10 = !this.TryDeserializeAuxiliaryType(protoReader, DataFormat.Default, 1, type, ref value, true, false, true, false) && num != 0; + if (flag10) + { + TypeModel.ThrowUnexpectedType(type); + } + } + bytesRead += protoReader.Position; + haveObject = true; + result = value; + } + finally + { + ProtoReader.Recycle(protoReader); + } + return result; + } + + public IEnumerable DeserializeItems(Stream source, Type type, PrefixStyle style, int expectedField, Serializer.TypeResolver resolver) + { + return this.DeserializeItems(source, type, style, expectedField, resolver, null); + } + + public IEnumerable DeserializeItems(Stream source, Type type, PrefixStyle style, int expectedField, Serializer.TypeResolver resolver, SerializationContext context) + { + return new TypeModel.DeserializeItemsIterator(this, source, type, style, expectedField, resolver, context); + } + + public IEnumerable DeserializeItems(Stream source, PrefixStyle style, int expectedField) + { + return this.DeserializeItems(source, style, expectedField, null); + } + + public IEnumerable DeserializeItems(Stream source, PrefixStyle style, int expectedField, SerializationContext context) + { + return new TypeModel.DeserializeItemsIterator(this, source, style, expectedField, context); + } + + public void SerializeWithLengthPrefix(Stream dest, object value, Type type, PrefixStyle style, int fieldNumber) + { + this.SerializeWithLengthPrefix(dest, value, type, style, fieldNumber, null); + } + + public void SerializeWithLengthPrefix(Stream dest, object value, Type type, PrefixStyle style, int fieldNumber, SerializationContext context) + { + bool flag = type == null; + if (flag) + { + bool flag2 = value == null; + if (flag2) + { + throw new ArgumentNullException("value"); + } + type = this.MapType(value.GetType()); + } + int key = this.GetKey(ref type); + using (ProtoWriter protoWriter = new ProtoWriter(dest, this, context)) + { + if (style != PrefixStyle.None) + { + if (style - PrefixStyle.Base128 > 2) + { + throw new ArgumentOutOfRangeException("style"); + } + ProtoWriter.WriteObject(value, key, protoWriter, style, fieldNumber); + } + else + { + this.Serialize(key, value, protoWriter); + } + protoWriter.Close(); + } + } + + public object Deserialize(Stream source, object value, Type type) + { + return this.Deserialize(source, value, type, null); + } + + public object Deserialize(Stream source, object value, Type type, SerializationContext context) + { + bool noAutoCreate = this.PrepareDeserialize(value, ref type); + ProtoReader protoReader = null; + object result; + try + { + protoReader = ProtoReader.Create(source, this, context, -1); + bool flag = value != null; + if (flag) + { + protoReader.SetRootObject(value); + } + object obj = this.DeserializeCore(protoReader, type, value, noAutoCreate); + protoReader.CheckFullyConsumed(); + result = obj; + } + finally + { + ProtoReader.Recycle(protoReader); + } + return result; + } + + private bool PrepareDeserialize(object value, ref Type type) + { + bool flag = type == null; + if (flag) + { + bool flag2 = value == null; + if (flag2) + { + throw new ArgumentNullException("type"); + } + type = this.MapType(value.GetType()); + } + bool result = true; + Type underlyingType = Helpers.GetUnderlyingType(type); + bool flag3 = underlyingType != null; + if (flag3) + { + type = underlyingType; + result = false; + } + return result; + } + + public object Deserialize(Stream source, object value, Type type, int length) + { + return this.Deserialize(source, value, type, length, null); + } + + public object Deserialize(Stream source, object value, Type type, int length, SerializationContext context) + { + bool noAutoCreate = this.PrepareDeserialize(value, ref type); + ProtoReader protoReader = null; + object result; + try + { + protoReader = ProtoReader.Create(source, this, context, length); + bool flag = value != null; + if (flag) + { + protoReader.SetRootObject(value); + } + object obj = this.DeserializeCore(protoReader, type, value, noAutoCreate); + protoReader.CheckFullyConsumed(); + result = obj; + } + finally + { + ProtoReader.Recycle(protoReader); + } + return result; + } + + public object Deserialize(ProtoReader source, object value, Type type) + { + bool flag = source == null; + if (flag) + { + throw new ArgumentNullException("source"); + } + bool noAutoCreate = this.PrepareDeserialize(value, ref type); + bool flag2 = value != null; + if (flag2) + { + source.SetRootObject(value); + } + object result = this.DeserializeCore(source, type, value, noAutoCreate); + source.CheckFullyConsumed(); + return result; + } + + private object DeserializeCore(ProtoReader reader, Type type, object value, bool noAutoCreate) + { + int key = this.GetKey(ref type); + bool flag = key >= 0 && !Helpers.IsEnum(type); + object result; + if (flag) + { + result = this.Deserialize(key, value, reader); + } + else + { + this.TryDeserializeAuxiliaryType(reader, DataFormat.Default, 1, type, ref value, true, false, noAutoCreate, false); + result = value; + } + return result; + } + + internal static MethodInfo ResolveListAdd(TypeModel model, Type listType, Type itemType, out bool isList) + { + isList = model.MapType(TypeModel.ilist).IsAssignableFrom(listType); + Type[] array = new Type[] + { + itemType + }; + MethodInfo instanceMethod = Helpers.GetInstanceMethod(listType, "Add", array); + bool flag = instanceMethod == null; + if (flag) + { + bool flag2 = listType.IsInterface && listType == model.MapType(typeof(IEnumerable<>)).MakeGenericType(array); + Type type = model.MapType(typeof(ICollection<>)).MakeGenericType(array); + bool flag3 = flag2 || type.IsAssignableFrom(listType); + if (flag3) + { + instanceMethod = Helpers.GetInstanceMethod(type, "Add", array); + } + } + bool flag4 = instanceMethod == null; + if (flag4) + { + foreach (Type type2 in listType.GetInterfaces()) + { + bool flag5 = type2.Name == "IProducerConsumerCollection`1" && type2.IsGenericType && type2.GetGenericTypeDefinition().FullName == "System.Collections.Concurrent.IProducerConsumerCollection`1"; + if (flag5) + { + instanceMethod = Helpers.GetInstanceMethod(type2, "TryAdd", array); + bool flag6 = instanceMethod != null; + if (flag6) + { + break; + } + } + } + } + bool flag7 = instanceMethod == null; + if (flag7) + { + array[0] = model.MapType(typeof(object)); + instanceMethod = Helpers.GetInstanceMethod(listType, "Add", array); + } + bool flag8 = instanceMethod == null & isList; + if (flag8) + { + instanceMethod = Helpers.GetInstanceMethod(model.MapType(TypeModel.ilist), "Add", array); + } + return instanceMethod; + } + + internal static Type GetListItemType(TypeModel model, Type listType) + { + Helpers.DebugAssert(listType != null); + bool flag = listType == model.MapType(typeof(string)) || listType.IsArray || !model.MapType(typeof(IEnumerable)).IsAssignableFrom(listType); + Type result; + if (flag) + { + result = null; + } + else + { + BasicList basicList = new BasicList(); + foreach (MethodInfo methodInfo in listType.GetMethods()) + { + bool flag2 = methodInfo.IsStatic || methodInfo.Name != "Add"; + if (!flag2) + { + ParameterInfo[] parameters = methodInfo.GetParameters(); + Type parameterType = null; + bool flag3 = parameters.Length == 1 && !basicList.Contains(parameterType = parameters[0].ParameterType); + if (flag3) + { + basicList.Add(parameterType); + } + } + } + string name = listType.Name; + bool flag4 = name != null && (name.IndexOf("Queue") >= 0 || name.IndexOf("Stack") >= 0); + bool flag5 = !flag4; + if (flag5) + { + TypeModel.TestEnumerableListPatterns(model, basicList, listType); + foreach (Type iType in listType.GetInterfaces()) + { + TypeModel.TestEnumerableListPatterns(model, basicList, iType); + } + } + foreach (PropertyInfo propertyInfo in listType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) + { + bool flag6 = propertyInfo.Name != "Item" || basicList.Contains(propertyInfo.PropertyType); + if (!flag6) + { + ParameterInfo[] indexParameters = propertyInfo.GetIndexParameters(); + bool flag7 = indexParameters.Length != 1 || indexParameters[0].ParameterType != model.MapType(typeof(int)); + if (!flag7) + { + basicList.Add(propertyInfo.PropertyType); + } + } + } + switch (basicList.Count) + { + case 0: + return null; + case 1: + return (Type)basicList[0]; + case 2: + { + bool flag8 = TypeModel.CheckDictionaryAccessors(model, (Type)basicList[0], (Type)basicList[1]); + if (flag8) + { + return (Type)basicList[0]; + } + bool flag9 = TypeModel.CheckDictionaryAccessors(model, (Type)basicList[1], (Type)basicList[0]); + if (flag9) + { + return (Type)basicList[1]; + } + break; + } + } + result = null; + } + return result; + } + + private static void TestEnumerableListPatterns(TypeModel model, BasicList candidates, Type iType) + { + bool isGenericType = iType.IsGenericType; + if (isGenericType) + { + Type genericTypeDefinition = iType.GetGenericTypeDefinition(); + bool flag = genericTypeDefinition == model.MapType(typeof(IEnumerable<>)) || genericTypeDefinition == model.MapType(typeof(ICollection<>)) || genericTypeDefinition.FullName == "System.Collections.Concurrent.IProducerConsumerCollection`1"; + if (flag) + { + Type[] genericArguments = iType.GetGenericArguments(); + bool flag2 = !candidates.Contains(genericArguments[0]); + if (flag2) + { + candidates.Add(genericArguments[0]); + } + } + } + } + + private static bool CheckDictionaryAccessors(TypeModel model, Type pair, Type value) + { + return pair.IsGenericType && pair.GetGenericTypeDefinition() == model.MapType(typeof(KeyValuePair<, >)) && pair.GetGenericArguments()[1] == value; + } + + private bool TryDeserializeList(TypeModel model, ProtoReader reader, DataFormat format, int tag, Type listType, Type itemType, ref object value) + { + bool flag; + MethodInfo methodInfo = TypeModel.ResolveListAdd(model, listType, itemType, out flag); + bool flag2 = methodInfo == null; + if (flag2) + { + throw new NotSupportedException("Unknown list variant: " + listType.FullName); + } + bool result = false; + object obj = null; + IList list = value as IList; + object[] array = flag ? null : ProtoDecoratorBase.s_argsRead; + BasicList basicList = listType.IsArray ? new BasicList() : null; + while (this.TryDeserializeAuxiliaryType(reader, format, tag, itemType, ref obj, true, true, true, true)) + { + result = true; + bool flag3 = value == null && basicList == null; + if (flag3) + { + value = TypeModel.CreateListInstance(listType, itemType); + list = (value as IList); + } + bool flag4 = list != null; + if (flag4) + { + list.Add(obj); + } + else + { + bool flag5 = basicList != null; + if (flag5) + { + basicList.Add(obj); + } + else + { + array[0] = obj; + methodInfo.Invoke(value, array); + } + } + obj = null; + } + bool flag6 = basicList != null; + if (flag6) + { + bool flag7 = value != null; + if (flag7) + { + bool flag8 = basicList.Count == 0; + if (!flag8) + { + Array array2 = (Array)value; + Array array3 = Array.CreateInstance(itemType, array2.Length + basicList.Count); + Array.Copy(array2, array3, array2.Length); + basicList.CopyTo(array3, array2.Length); + value = array3; + } + } + else + { + Array array3 = Array.CreateInstance(itemType, basicList.Count); + basicList.CopyTo(array3, 0); + value = array3; + } + } + return result; + } + + private static object CreateListInstance(Type listType, Type itemType) + { + Type type = listType; + bool isArray = listType.IsArray; + object result; + if (isArray) + { + result = Array.CreateInstance(itemType, 0); + } + else + { + bool flag = !listType.IsClass || listType.IsAbstract || Helpers.GetConstructor(listType, Helpers.EmptyTypes, true) == null; + if (flag) + { + bool flag2 = false; + string fullName; + bool flag3 = listType.IsInterface && (fullName = listType.FullName) != null && fullName.IndexOf("Dictionary") >= 0; + if (flag3) + { + bool flag4 = listType.IsGenericType && listType.GetGenericTypeDefinition() == typeof(IDictionary<, >); + if (flag4) + { + Type[] genericArguments = listType.GetGenericArguments(); + type = typeof(Dictionary<, >).MakeGenericType(genericArguments); + flag2 = true; + } + bool flag5 = !flag2 && listType == typeof(IDictionary); + if (flag5) + { + type = typeof(Hashtable); + flag2 = true; + } + } + bool flag6 = !flag2; + if (flag6) + { + type = typeof(List<>).MakeGenericType(new Type[] + { + itemType + }); + flag2 = true; + } + bool flag7 = !flag2; + if (flag7) + { + type = typeof(ArrayList); + } + } + result = Activator.CreateInstance(type); + } + return result; + } + + internal bool TryDeserializeAuxiliaryType(ProtoReader reader, DataFormat format, int tag, Type type, ref object value, bool skipOtherFields, bool asListItem, bool autoCreate, bool insideList) + { + bool flag = type == null; + if (flag) + { + throw new ArgumentNullException("type"); + } + ProtoTypeCode typeCode = Helpers.GetTypeCode(type); + int num; + WireType wireType = this.GetWireType(typeCode, format, ref type, out num); + bool flag2 = false; + bool flag3 = wireType == WireType.None; + if (flag3) + { + Type type2 = TypeModel.GetListItemType(this, type); + bool flag4 = type2 == null && type.IsArray && type.GetArrayRank() == 1 && type != typeof(byte[]); + if (flag4) + { + type2 = type.GetElementType(); + } + bool flag5 = type2 != null; + if (flag5) + { + if (insideList) + { + throw TypeModel.CreateNestedListsNotSupported(); + } + flag2 = this.TryDeserializeList(this, reader, format, tag, type, type2, ref value); + bool flag6 = !flag2 && autoCreate; + if (flag6) + { + value = TypeModel.CreateListInstance(type, type2); + } + return flag2; + } + else + { + TypeModel.ThrowUnexpectedType(type); + } + } + int num2; + for (;;) + { + bool flag7 = flag2 && asListItem; + if (flag7) + { + break; + } + num2 = reader.ReadFieldHeader(); + bool flag8 = num2 <= 0; + if (flag8) + { + break; + } + bool flag9 = num2 != tag; + if (flag9) + { + if (!skipOtherFields) + { + goto IL_12E; + } + reader.SkipField(); + } + else + { + flag2 = true; + reader.Hint(wireType); + bool flag10 = num >= 0; + if (flag10) + { + WireType wireType2 = wireType; + if (wireType2 - WireType.String > 1) + { + value = this.Deserialize(num, value, reader); + } + else + { + SubItemToken token = ProtoReader.StartSubItem(reader); + value = this.Deserialize(num, value, reader); + ProtoReader.EndSubItem(token, reader); + } + } + else + { + ProtoTypeCode protoTypeCode = typeCode; + switch (protoTypeCode) + { + case ProtoTypeCode.Boolean: + value = reader.ReadBoolean(); + break; + case ProtoTypeCode.Char: + value = (char)reader.ReadUInt16(); + break; + case ProtoTypeCode.SByte: + value = reader.ReadSByte(); + break; + case ProtoTypeCode.Byte: + value = reader.ReadByte(); + break; + case ProtoTypeCode.Int16: + value = reader.ReadInt16(); + break; + case ProtoTypeCode.UInt16: + value = reader.ReadUInt16(); + break; + case ProtoTypeCode.Int32: + value = reader.ReadInt32(); + break; + case ProtoTypeCode.UInt32: + value = reader.ReadUInt32(); + break; + case ProtoTypeCode.Int64: + value = reader.ReadInt64(); + break; + case ProtoTypeCode.UInt64: + value = reader.ReadUInt64(); + break; + case ProtoTypeCode.Single: + value = reader.ReadSingle(); + break; + case ProtoTypeCode.Double: + value = reader.ReadDouble(); + break; + case ProtoTypeCode.Decimal: + value = BclHelpers.ReadDecimal(reader); + break; + case ProtoTypeCode.DateTime: + value = BclHelpers.ReadDateTime(reader); + break; + case (ProtoTypeCode)17: + break; + case ProtoTypeCode.String: + value = reader.ReadString(); + break; + default: + switch (protoTypeCode) + { + case ProtoTypeCode.TimeSpan: + value = BclHelpers.ReadTimeSpan(reader); + break; + case ProtoTypeCode.ByteArray: + value = ProtoReader.AppendBytes((byte[])value, reader); + break; + case ProtoTypeCode.Guid: + value = BclHelpers.ReadGuid(reader); + break; + case ProtoTypeCode.Uri: + value = new Uri(reader.ReadString()); + break; + } + break; + } + } + } + } + goto IL_375; + IL_12E: + throw ProtoReader.AddErrorData(new InvalidOperationException("Expected field " + tag.ToString() + ", but found " + num2.ToString()), reader); + IL_375: + bool flag11 = !flag2 && !asListItem && autoCreate; + if (flag11) + { + bool flag12 = type != typeof(string); + if (flag12) + { + value = Activator.CreateInstance(type); + } + } + return flag2; + } + + public static RuntimeTypeModel Create() + { + return new RuntimeTypeModel(false); + } + + protected internal static Type ResolveProxies(Type type) + { + bool flag = type == null; + Type result; + if (flag) + { + result = null; + } + else + { + bool isGenericParameter = type.IsGenericParameter; + if (isGenericParameter) + { + result = null; + } + else + { + Type underlyingType = Helpers.GetUnderlyingType(type); + bool flag2 = underlyingType != null; + if (flag2) + { + result = underlyingType; + } + else + { + string fullName = type.FullName; + bool flag3 = fullName != null && fullName.StartsWith("System.Data.Entity.DynamicProxies."); + if (flag3) + { + result = type.BaseType; + } + else + { + Type[] interfaces = type.GetInterfaces(); + for (int i = 0; i < interfaces.Length; i++) + { + string fullName2 = interfaces[i].FullName; + if (fullName2 == "NHibernate.Proxy.INHibernateProxy" || fullName2 == "NHibernate.Proxy.DynamicProxy.IProxy" || fullName2 == "NHibernate.Intercept.IFieldInterceptorAccessor") + { + return type.BaseType; + } + } + result = null; + } + } + } + } + return result; + } + + public bool IsDefined(Type type) + { + return this.GetKey(ref type) >= 0; + } + + protected internal int GetKey(ref Type type) + { + bool flag = type == null; + int result; + if (flag) + { + result = -1; + } + else + { + int keyImpl = this.GetKeyImpl(type); + bool flag2 = keyImpl < 0; + if (flag2) + { + Type type2 = TypeModel.ResolveProxies(type); + bool flag3 = type2 != null; + if (flag3) + { + type = type2; + keyImpl = this.GetKeyImpl(type); + } + } + result = keyImpl; + } + return result; + } + + protected abstract int GetKeyImpl(Type type); + + protected internal abstract void Serialize(int key, object value, ProtoWriter dest); + + protected internal abstract object Deserialize(int key, object value, ProtoReader source); + + public object DeepClone(object value) + { + bool flag = value == null; + object result; + if (flag) + { + result = null; + } + else + { + Type type = value.GetType(); + int key = this.GetKey(ref type); + bool flag2 = key >= 0 && !Helpers.IsEnum(type); + if (flag2) + { + using (MemoryStream memoryStream = new MemoryStream()) + { + using (ProtoWriter protoWriter = new ProtoWriter(memoryStream, this, null)) + { + protoWriter.SetRootObject(value); + this.Serialize(key, value, protoWriter); + protoWriter.Close(); + } + memoryStream.Position = 0L; + ProtoReader protoReader = null; + try + { + protoReader = ProtoReader.Create(memoryStream, this, null, -1); + return this.Deserialize(key, null, protoReader); + } + finally + { + ProtoReader.Recycle(protoReader); + } + } + } + bool flag3 = type == typeof(byte[]); + if (flag3) + { + byte[] array = (byte[])value; + byte[] array2 = new byte[array.Length]; + Helpers.BlockCopy(array, 0, array2, 0, array.Length); + result = array2; + } + else + { + int num; + bool flag4 = this.GetWireType(Helpers.GetTypeCode(type), DataFormat.Default, ref type, out num) != WireType.None && num < 0; + if (flag4) + { + result = value; + } + else + { + using (MemoryStream memoryStream2 = new MemoryStream()) + { + using (ProtoWriter protoWriter2 = new ProtoWriter(memoryStream2, this, null)) + { + bool flag5 = !this.TrySerializeAuxiliaryType(protoWriter2, type, DataFormat.Default, 1, value, false); + if (flag5) + { + TypeModel.ThrowUnexpectedType(type); + } + protoWriter2.Close(); + } + memoryStream2.Position = 0L; + ProtoReader reader = null; + try + { + reader = ProtoReader.Create(memoryStream2, this, null, -1); + value = null; + this.TryDeserializeAuxiliaryType(reader, DataFormat.Default, 1, type, ref value, true, false, true, false); + result = value; + } + finally + { + ProtoReader.Recycle(reader); + } + } + } + } + } + return result; + } + + protected internal static void ThrowUnexpectedSubtype(Type expected, Type actual) + { + bool flag = expected != TypeModel.ResolveProxies(actual); + if (flag) + { + throw new InvalidOperationException("Unexpected sub-type: " + actual.FullName); + } + } + + protected internal static void ThrowUnexpectedType(Type type) + { + string str = (type == null) ? "(unknown)" : type.FullName; + bool flag = type != null; + if (flag) + { + Type baseType = type.BaseType; + bool flag2 = baseType != null && baseType.IsGenericType && baseType.GetGenericTypeDefinition().Name == "GeneratedMessage`2"; + if (flag2) + { + throw new InvalidOperationException("Are you mixing protobuf-net and protobuf-csharp-port? See http://stackoverflow.com/q/11564914; type: " + str); + } + } + throw new InvalidOperationException("Type is not expected, and no contract can be inferred: " + str); + } + + internal static Exception CreateNestedListsNotSupported() + { + return new NotSupportedException("Nested or jagged lists and arrays are not supported"); + } + + public static void ThrowCannotCreateInstance(Type type) + { + throw new ProtoException("No parameterless constructor found for " + ((type == null) ? "(null)" : type.Name)); + } + + internal static string SerializeType(TypeModel model, Type type) + { + bool flag = model != null; + if (flag) + { + TypeFormatEventHandler dynamicTypeFormatting = model.DynamicTypeFormatting; + bool flag2 = dynamicTypeFormatting != null; + if (flag2) + { + TypeFormatEventArgs typeFormatEventArgs = new TypeFormatEventArgs(type); + dynamicTypeFormatting(model, typeFormatEventArgs); + bool flag3 = !Helpers.IsNullOrEmpty(typeFormatEventArgs.FormattedName); + if (flag3) + { + return typeFormatEventArgs.FormattedName; + } + } + } + return type.AssemblyQualifiedName; + } + + internal static Type DeserializeType(TypeModel model, string value) + { + bool flag = model != null; + if (flag) + { + TypeFormatEventHandler dynamicTypeFormatting = model.DynamicTypeFormatting; + bool flag2 = dynamicTypeFormatting != null; + if (flag2) + { + TypeFormatEventArgs typeFormatEventArgs = new TypeFormatEventArgs(value); + dynamicTypeFormatting(model, typeFormatEventArgs); + bool flag3 = typeFormatEventArgs.Type != null; + if (flag3) + { + return typeFormatEventArgs.Type; + } + } + } + return Type.GetType(value); + } + + public bool CanSerializeContractType(Type type) + { + return this.CanSerialize(type, false, true, true); + } + + public bool CanSerialize(Type type) + { + return this.CanSerialize(type, true, true, true); + } + + public bool CanSerializeBasicType(Type type) + { + return this.CanSerialize(type, true, false, true); + } + + private bool CanSerialize(Type type, bool allowBasic, bool allowContract, bool allowLists) + { + bool flag = type == null; + if (flag) + { + throw new ArgumentNullException("type"); + } + Type underlyingType = Helpers.GetUnderlyingType(type); + bool flag2 = underlyingType != null; + if (flag2) + { + type = underlyingType; + } + ProtoTypeCode typeCode = Helpers.GetTypeCode(type); + ProtoTypeCode protoTypeCode = typeCode; + bool result; + if (protoTypeCode > ProtoTypeCode.Unknown) + { + result = allowBasic; + } + else + { + int key = this.GetKey(ref type); + bool flag3 = key >= 0; + if (flag3) + { + result = allowContract; + } + else + { + if (allowLists) + { + Type type2 = null; + bool isArray = type.IsArray; + if (isArray) + { + bool flag4 = type.GetArrayRank() == 1; + if (flag4) + { + type2 = type.GetElementType(); + } + } + else + { + type2 = TypeModel.GetListItemType(this, type); + } + bool flag5 = type2 != null; + if (flag5) + { + return this.CanSerialize(type2, allowBasic, allowContract, false); + } + } + result = false; + } + } + return result; + } + + public virtual string GetSchema(Type type) + { + throw new NotSupportedException(); + } + + internal virtual Type GetType(string fullName, Assembly context) + { + return TypeModel.ResolveKnownType(fullName, this, context); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + internal static Type ResolveKnownType(string name, TypeModel model, Assembly assembly) + { + bool flag = Helpers.IsNullOrEmpty(name); + Type result; + if (flag) + { + result = null; + } + else + { + try + { + Type type = Type.GetType(name); + bool flag2 = type != null; + if (flag2) + { + return type; + } + } + catch + { + } + try + { + int num = name.IndexOf(','); + string name2 = ((num > 0) ? name.Substring(0, num) : name).Trim(); + bool flag3 = assembly == null; + if (flag3) + { + assembly = Assembly.GetCallingAssembly(); + } + Type type2 = (assembly == null) ? null : assembly.GetType(name2); + bool flag4 = type2 != null; + if (flag4) + { + return type2; + } + } + catch + { + } + result = null; + } + return result; + } + } +} diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeModel.cs.meta b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeModel.cs.meta new file mode 100644 index 00000000..71fa0af1 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/TypeModel.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: dbb3d0ca7c570e0439827efde10650ea +timeCreated: 1611404654 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/ValueMember.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/ValueMember.cs new file mode 100644 index 00000000..ec50b41a --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/ValueMember.cs @@ -0,0 +1,808 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.Reflection; +using ProtoBuf.Serializers; + +namespace ProtoBuf.Meta +{ + public class ValueMember + { + public int FieldNumber + { + get + { + return this.fieldNumber; + } + } + + public MemberInfo Member + { + get + { + return this.member; + } + } + + public Type ItemType + { + get + { + return this.itemType; + } + } + + public Type MemberType + { + get + { + return this.memberType; + } + } + + public Type DefaultType + { + get + { + return this.defaultType; + } + } + + public Type ParentType + { + get + { + return this.parentType; + } + } + + public object DefaultValue + { + get + { + return this.defaultValue; + } + set + { + this.ThrowIfFrozen(); + this.defaultValue = value; + } + } + + internal IProtoSerializer Serializer + { + get + { + bool flag = this.serializer == null; + if (flag) + { + this.serializer = this.BuildSerializer(); + } + return this.serializer; + } + } + + public DataFormat DataFormat + { + get + { + return this.dataFormat; + } + set + { + this.ThrowIfFrozen(); + this.dataFormat = value; + } + } + + public bool IsStrict + { + get + { + return this.HasFlag(1); + } + set + { + this.SetFlag(1, value, true); + } + } + + public bool IsPacked + { + get + { + return this.HasFlag(2); + } + set + { + this.SetFlag(2, value, true); + } + } + + public bool OverwriteList + { + get + { + return this.HasFlag(8); + } + set + { + this.SetFlag(8, value, true); + } + } + + public bool IsRequired + { + get + { + return this.HasFlag(4); + } + set + { + this.SetFlag(4, value, true); + } + } + + public bool AsReference + { + get + { + return this.asReference; + } + set + { + this.ThrowIfFrozen(); + this.asReference = value; + } + } + + public bool DynamicType + { + get + { + return this.dynamicType; + } + set + { + this.ThrowIfFrozen(); + this.dynamicType = value; + } + } + + public string Name + { + get + { + return Helpers.IsNullOrEmpty(this.name) ? this.member.Name : this.name; + } + } + + public bool SupportNull + { + get + { + return this.HasFlag(16); + } + set + { + this.SetFlag(16, value, true); + } + } + + private readonly int fieldNumber; + + private readonly MemberInfo member; + + private readonly Type parentType; + + private readonly Type itemType; + + private readonly Type defaultType; + + private readonly Type memberType; + + private object defaultValue; + + private readonly RuntimeTypeModel model; + + private IProtoSerializer serializer; + + private DataFormat dataFormat; + + private bool asReference; + + private bool dynamicType; + + private MethodInfo getSpecified; + + private MethodInfo setSpecified; + + private string name; + + private const byte OPTIONS_IsStrict = 1; + + private const byte OPTIONS_IsPacked = 2; + + private const byte OPTIONS_IsRequired = 4; + + private const byte OPTIONS_OverwriteList = 8; + + private const byte OPTIONS_SupportNull = 16; + + private byte flags; + + internal sealed class Comparer : IComparer, IComparer + { + public static readonly ValueMember.Comparer Default = new ValueMember.Comparer(); + + public int Compare(object x, object y) + { + return this.Compare(x as ValueMember, y as ValueMember); + } + + public int Compare(ValueMember x, ValueMember y) + { + bool flag = x == y; + int result; + if (flag) + { + result = 0; + } + else + { + bool flag2 = x == null; + if (flag2) + { + result = -1; + } + else + { + bool flag3 = y == null; + if (flag3) + { + result = 1; + } + else + { + result = x.FieldNumber.CompareTo(y.FieldNumber); + } + } + } + return result; + } + } + + public ValueMember(RuntimeTypeModel model, Type parentType, int fieldNumber, MemberInfo member, Type memberType, Type itemType, Type defaultType, DataFormat dataFormat, object defaultValue) : this(model, fieldNumber, memberType, itemType, defaultType, dataFormat) + { + bool flag = member == null; + if (flag) + { + throw new ArgumentNullException("member"); + } + bool flag2 = parentType == null; + if (flag2) + { + throw new ArgumentNullException("parentType"); + } + bool flag3 = fieldNumber < 1 && !Helpers.IsEnum(parentType); + if (flag3) + { + throw new ArgumentOutOfRangeException("fieldNumber"); + } + this.member = member; + this.parentType = parentType; + bool flag4 = fieldNumber < 1 && !Helpers.IsEnum(parentType); + if (flag4) + { + throw new ArgumentOutOfRangeException("fieldNumber"); + } + bool flag5 = defaultValue != null && model.MapType(defaultValue.GetType()) != memberType; + if (flag5) + { + defaultValue = ValueMember.ParseDefaultValue(memberType, defaultValue); + } + this.defaultValue = defaultValue; + MetaType metaType = model.FindWithoutAdd(memberType); + bool flag6 = metaType != null; + if (flag6) + { + this.asReference = metaType.AsReferenceDefault; + } + else + { + this.asReference = MetaType.GetAsReferenceDefault(model, memberType); + } + } + + internal ValueMember(RuntimeTypeModel model, int fieldNumber, Type memberType, Type itemType, Type defaultType, DataFormat dataFormat) + { + bool flag = memberType == null; + if (flag) + { + throw new ArgumentNullException("memberType"); + } + bool flag2 = model == null; + if (flag2) + { + throw new ArgumentNullException("model"); + } + this.fieldNumber = fieldNumber; + this.memberType = memberType; + this.itemType = itemType; + this.defaultType = defaultType; + this.model = model; + this.dataFormat = dataFormat; + } + + internal object GetRawEnumValue() + { + return ((FieldInfo)this.member).GetRawConstantValue(); + } + + private static object ParseDefaultValue(Type type, object value) + { + Type underlyingType = Helpers.GetUnderlyingType(type); + bool flag = underlyingType != null; + if (flag) + { + type = underlyingType; + } + bool flag2 = value is string; + if (flag2) + { + string text = (string)value; + bool flag3 = Helpers.IsEnum(type); + if (flag3) + { + return Helpers.ParseEnum(type, text); + } + ProtoTypeCode typeCode = Helpers.GetTypeCode(type); + switch (typeCode) + { + case ProtoTypeCode.Boolean: + return bool.Parse(text); + case ProtoTypeCode.Char: + { + bool flag4 = text.Length == 1; + if (flag4) + { + return text[0]; + } + throw new FormatException("Single character expected: \"" + text + "\""); + } + case ProtoTypeCode.SByte: + return sbyte.Parse(text, NumberStyles.Integer, CultureInfo.InvariantCulture); + case ProtoTypeCode.Byte: + return byte.Parse(text, NumberStyles.Integer, CultureInfo.InvariantCulture); + case ProtoTypeCode.Int16: + return short.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture); + case ProtoTypeCode.UInt16: + return ushort.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture); + case ProtoTypeCode.Int32: + return int.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture); + case ProtoTypeCode.UInt32: + return uint.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture); + case ProtoTypeCode.Int64: + return long.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture); + case ProtoTypeCode.UInt64: + return ulong.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture); + case ProtoTypeCode.Single: + return float.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture); + case ProtoTypeCode.Double: + return double.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture); + case ProtoTypeCode.Decimal: + return decimal.Parse(text, NumberStyles.Any, CultureInfo.InvariantCulture); + case ProtoTypeCode.DateTime: + return DateTime.Parse(text, CultureInfo.InvariantCulture); + case (ProtoTypeCode)17: + break; + case ProtoTypeCode.String: + return text; + default: + switch (typeCode) + { + case ProtoTypeCode.TimeSpan: + return TimeSpan.Parse(text); + case ProtoTypeCode.Guid: + return new Guid(text); + case ProtoTypeCode.Uri: + return text; + } + break; + } + } + bool flag5 = Helpers.IsEnum(type); + object result; + if (flag5) + { + result = Enum.ToObject(type, value); + } + else + { + result = Convert.ChangeType(value, type, CultureInfo.InvariantCulture); + } + return result; + } + + public void SetSpecified(MethodInfo getSpecified, MethodInfo setSpecified) + { + bool flag = getSpecified != null; + if (flag) + { + bool flag2 = getSpecified.ReturnType != this.model.MapType(typeof(bool)) || getSpecified.IsStatic || getSpecified.GetParameters().Length != 0; + if (flag2) + { + throw new ArgumentException("Invalid pattern for checking member-specified", "getSpecified"); + } + } + bool flag3 = setSpecified != null; + if (flag3) + { + ParameterInfo[] parameters; + bool flag4 = setSpecified.ReturnType != this.model.MapType(typeof(void)) || setSpecified.IsStatic || (parameters = setSpecified.GetParameters()).Length != 1 || parameters[0].ParameterType != this.model.MapType(typeof(bool)); + if (flag4) + { + throw new ArgumentException("Invalid pattern for setting member-specified", "setSpecified"); + } + } + this.ThrowIfFrozen(); + this.getSpecified = getSpecified; + this.setSpecified = setSpecified; + } + + private void ThrowIfFrozen() + { + bool flag = this.serializer != null; + if (flag) + { + throw new InvalidOperationException("The type cannot be changed once a serializer has been generated"); + } + } + + private IProtoSerializer BuildSerializer() + { + int opaqueToken = 0; + IProtoSerializer result; + try + { + this.model.TakeLock(ref opaqueToken); + Type type = (this.itemType == null) ? this.memberType : this.itemType; + WireType wireType; + IProtoSerializer protoSerializer = ValueMember.TryGetCoreSerializer(this.model, this.dataFormat, type, out wireType, this.asReference, this.dynamicType, this.OverwriteList, true); + bool flag = protoSerializer == null; + if (flag) + { + throw new InvalidOperationException("No serializer defined for type: " + type.FullName); + } + bool flag2 = this.itemType != null && this.SupportNull; + if (flag2) + { + bool isPacked = this.IsPacked; + if (isPacked) + { + throw new NotSupportedException("Packed encodings cannot support null values"); + } + protoSerializer = new TagDecorator(1, wireType, this.IsStrict, protoSerializer); + protoSerializer = new NullDecorator(this.model, protoSerializer); + protoSerializer = new TagDecorator(this.fieldNumber, WireType.StartGroup, false, protoSerializer); + } + else + { + protoSerializer = new TagDecorator(this.fieldNumber, wireType, this.IsStrict, protoSerializer); + } + bool flag3 = this.itemType != null; + if (flag3) + { + Type type2 = this.SupportNull ? this.itemType : (Helpers.GetUnderlyingType(this.itemType) ?? this.itemType); + Helpers.DebugAssert(type2 == protoSerializer.ExpectedType, "Wrong type in the tail; expected {0}, received {1}", new object[] + { + protoSerializer.ExpectedType, + type2 + }); + bool isArray = this.memberType.IsArray; + if (isArray) + { + protoSerializer = new ArrayDecorator(this.model, protoSerializer, this.fieldNumber, this.IsPacked, wireType, this.memberType, this.OverwriteList, this.SupportNull); + } + else + { + protoSerializer = ListDecorator.Create(this.model, this.memberType, this.defaultType, protoSerializer, this.fieldNumber, this.IsPacked, wireType, this.member != null && PropertyDecorator.CanWrite(this.model, this.member), this.OverwriteList, this.SupportNull); + } + } + else + { + bool flag4 = this.defaultValue != null && !this.IsRequired && this.getSpecified == null; + if (flag4) + { + protoSerializer = new DefaultValueDecorator(this.model, this.defaultValue, protoSerializer); + } + } + bool flag5 = this.memberType == this.model.MapType(typeof(Uri)); + if (flag5) + { + protoSerializer = new UriDecorator(this.model, protoSerializer); + } + bool flag6 = this.member != null; + if (flag6) + { + PropertyInfo propertyInfo = this.member as PropertyInfo; + bool flag7 = propertyInfo != null; + if (flag7) + { + protoSerializer = new PropertyDecorator(this.model, this.parentType, (PropertyInfo)this.member, protoSerializer); + } + else + { + FieldInfo fieldInfo = this.member as FieldInfo; + bool flag8 = fieldInfo != null; + if (!flag8) + { + throw new InvalidOperationException(); + } + protoSerializer = new FieldDecorator(this.parentType, (FieldInfo)this.member, protoSerializer); + } + bool flag9 = this.getSpecified != null || this.setSpecified != null; + if (flag9) + { + protoSerializer = new MemberSpecifiedDecorator(this.getSpecified, this.setSpecified, protoSerializer); + } + } + result = protoSerializer; + } + finally + { + this.model.ReleaseLock(opaqueToken); + } + return result; + } + + private static WireType GetIntWireType(DataFormat format, int width) + { + WireType result; + switch (format) + { + case DataFormat.Default: + case DataFormat.TwosComplement: + result = WireType.Variant; + break; + case DataFormat.ZigZag: + result = WireType.SignedVariant; + break; + case DataFormat.FixedSize: + result = ((width == 32) ? WireType.Fixed32 : WireType.Fixed64); + break; + default: + throw new InvalidOperationException(); + } + return result; + } + + private static WireType GetDateTimeWireType(DataFormat format) + { + switch (format) + { + case DataFormat.Default: + return WireType.String; + case DataFormat.FixedSize: + return WireType.Fixed64; + case DataFormat.Group: + return WireType.StartGroup; + } + throw new InvalidOperationException(); + } + + internal static IProtoSerializer TryGetCoreSerializer(RuntimeTypeModel model, DataFormat dataFormat, Type type, out WireType defaultWireType, bool asReference, bool dynamicType, bool overwriteList, bool allowComplexTypes) + { + Type underlyingType = Helpers.GetUnderlyingType(type); + bool flag = underlyingType != null; + if (flag) + { + type = underlyingType; + } + bool flag2 = Helpers.IsEnum(type); + IProtoSerializer result; + if (flag2) + { + bool flag3 = allowComplexTypes && model != null; + if (flag3) + { + defaultWireType = WireType.Variant; + result = new EnumSerializer(type, model.GetEnumMap(type)); + } + else + { + defaultWireType = WireType.None; + result = null; + } + } + else + { + ProtoTypeCode typeCode = Helpers.GetTypeCode(type); + ProtoTypeCode protoTypeCode = typeCode; + switch (protoTypeCode) + { + case ProtoTypeCode.Boolean: + defaultWireType = WireType.Variant; + return new BooleanSerializer(model); + case ProtoTypeCode.Char: + defaultWireType = WireType.Variant; + return new CharSerializer(model); + case ProtoTypeCode.SByte: + defaultWireType = ValueMember.GetIntWireType(dataFormat, 32); + return new SByteSerializer(model); + case ProtoTypeCode.Byte: + defaultWireType = ValueMember.GetIntWireType(dataFormat, 32); + return new ByteSerializer(model); + case ProtoTypeCode.Int16: + defaultWireType = ValueMember.GetIntWireType(dataFormat, 32); + return new Int16Serializer(model); + case ProtoTypeCode.UInt16: + defaultWireType = ValueMember.GetIntWireType(dataFormat, 32); + return new UInt16Serializer(model); + case ProtoTypeCode.Int32: + defaultWireType = ValueMember.GetIntWireType(dataFormat, 32); + return new Int32Serializer(model); + case ProtoTypeCode.UInt32: + defaultWireType = ValueMember.GetIntWireType(dataFormat, 32); + return new UInt32Serializer(model); + case ProtoTypeCode.Int64: + defaultWireType = ValueMember.GetIntWireType(dataFormat, 64); + return new Int64Serializer(model); + case ProtoTypeCode.UInt64: + defaultWireType = ValueMember.GetIntWireType(dataFormat, 64); + return new UInt64Serializer(model); + case ProtoTypeCode.Single: + defaultWireType = WireType.Fixed32; + return new SingleSerializer(model); + case ProtoTypeCode.Double: + defaultWireType = WireType.Fixed64; + return new DoubleSerializer(model); + case ProtoTypeCode.Decimal: + defaultWireType = WireType.String; + return new DecimalSerializer(model); + case ProtoTypeCode.DateTime: + defaultWireType = ValueMember.GetDateTimeWireType(dataFormat); + return new DateTimeSerializer(model); + case (ProtoTypeCode)17: + break; + case ProtoTypeCode.String: + defaultWireType = WireType.String; + if (asReference) + { + return new NetObjectSerializer(model, model.MapType(typeof(string)), 0, BclHelpers.NetObjectOptions.AsReference); + } + return new StringSerializer(model); + default: + switch (protoTypeCode) + { + case ProtoTypeCode.TimeSpan: + defaultWireType = ValueMember.GetDateTimeWireType(dataFormat); + return new TimeSpanSerializer(model); + case ProtoTypeCode.ByteArray: + defaultWireType = WireType.String; + return new BlobSerializer(model, overwriteList); + case ProtoTypeCode.Guid: + defaultWireType = WireType.String; + return new GuidSerializer(model); + case ProtoTypeCode.Uri: + defaultWireType = WireType.String; + return new StringSerializer(model); + case ProtoTypeCode.Type: + defaultWireType = WireType.String; + return new SystemTypeSerializer(model); + } + break; + } + IProtoSerializer protoSerializer = model.AllowParseableTypes ? ParseableSerializer.TryCreate(type, model) : null; + bool flag4 = protoSerializer != null; + if (flag4) + { + defaultWireType = WireType.String; + result = protoSerializer; + } + else + { + bool flag5 = allowComplexTypes && model != null; + if (flag5) + { + int key = model.GetKey(type, false, true); + bool flag6 = asReference || dynamicType; + if (flag6) + { + defaultWireType = ((dataFormat == DataFormat.Group) ? WireType.StartGroup : WireType.String); + BclHelpers.NetObjectOptions netObjectOptions = BclHelpers.NetObjectOptions.None; + if (asReference) + { + netObjectOptions |= BclHelpers.NetObjectOptions.AsReference; + } + if (dynamicType) + { + netObjectOptions |= BclHelpers.NetObjectOptions.DynamicType; + } + bool flag7 = key >= 0; + if (flag7) + { + bool flag8 = asReference && Helpers.IsValueType(type); + if (flag8) + { + string text = "AsReference cannot be used with value-types"; + bool flag9 = type.Name == "KeyValuePair`2"; + if (flag9) + { + text += "; please see http://stackoverflow.com/q/14436606/"; + } + else + { + text = text + ": " + type.FullName; + } + throw new InvalidOperationException(text); + } + MetaType metaType = model[type]; + bool flag10 = asReference && metaType.IsAutoTuple; + if (flag10) + { + netObjectOptions |= BclHelpers.NetObjectOptions.LateSet; + } + bool useConstructor = metaType.UseConstructor; + if (useConstructor) + { + netObjectOptions |= BclHelpers.NetObjectOptions.UseConstructor; + } + } + return new NetObjectSerializer(model, type, key, netObjectOptions); + } + bool flag11 = key >= 0; + if (flag11) + { + defaultWireType = ((dataFormat == DataFormat.Group) ? WireType.StartGroup : WireType.String); + return new SubItemSerializer(type, key, model[type], true); + } + } + defaultWireType = WireType.None; + result = null; + } + } + return result; + } + + internal void SetName(string name) + { + this.ThrowIfFrozen(); + this.name = name; + } + + private bool HasFlag(byte flag) + { + return (this.flags & flag) == flag; + } + + private void SetFlag(byte flag, bool value, bool throwIfFrozen) + { + bool flag2 = throwIfFrozen && this.HasFlag(flag) != value; + if (flag2) + { + this.ThrowIfFrozen(); + } + if (value) + { + this.flags |= flag; + } + else + { + this.flags &= (byte) ~flag; + } + } + + internal string GetSchemaTypeName(bool applyNetObjectProxy, ref bool requiresBclImport) + { + Type type = this.ItemType; + bool flag = type == null; + if (flag) + { + type = this.MemberType; + } + return this.model.GetSchemaTypeName(type, this.DataFormat, applyNetObjectProxy && this.asReference, applyNetObjectProxy && this.dynamicType, ref requiresBclImport); + } + } +} diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/ValueMember.cs.meta b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/ValueMember.cs.meta new file mode 100644 index 00000000..a92dffc3 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/ValueMember.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 20dcdd655bb536f4198cd99e27b58ded +timeCreated: 1611403409 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.1-26-g67d0