using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Text; namespace ExitGames.Client.Photon { // Token: 0x02000028 RID: 40 public class Protocol16 : IProtocol { // Token: 0x17000069 RID: 105 // (get) Token: 0x060001D7 RID: 471 RVA: 0x0000F738 File Offset: 0x0000D938 internal override string protocolType { get { return "GpBinaryV16"; } } // Token: 0x1700006A RID: 106 // (get) Token: 0x060001D8 RID: 472 RVA: 0x0000F750 File Offset: 0x0000D950 internal override byte[] VersionBytes { get { return this.versionBytes; } } // Token: 0x060001D9 RID: 473 RVA: 0x0000F768 File Offset: 0x0000D968 private bool SerializeCustom(StreamBuffer dout, object serObject) { CustomType customType; bool flag = Protocol.TypeDict.TryGetValue(serObject.GetType(), out customType); bool flag3; if (flag) { bool flag2 = customType.SerializeStreamFunction == null; if (flag2) { byte[] array = customType.SerializeFunction(serObject); dout.WriteByte(99); dout.WriteByte(customType.Code); this.SerializeShort(dout, (short)array.Length, false); dout.Write(array, 0, array.Length); flag3 = true; } else { dout.WriteByte(99); dout.WriteByte(customType.Code); long position = dout.Position; dout.Position += 2L; short num = customType.SerializeStreamFunction(dout, serObject); long position2 = dout.Position; dout.Position = position; this.SerializeShort(dout, num, false); dout.Position += (long)num; bool flag4 = dout.Position != position2; if (flag4) { throw new Exception(string.Concat(new object[] { "Serialization failed. Stream position corrupted. Should be ", position2, " is now: ", dout.Position, " serializedLength: ", num })); } flag3 = true; } } else { flag3 = false; } return flag3; } // Token: 0x060001DA RID: 474 RVA: 0x0000F8B8 File Offset: 0x0000DAB8 private object DeserializeCustom(StreamBuffer din, byte customTypeCode) { short num = this.DeserializeShort(din); CustomType customType; bool flag = Protocol.CodeDict.TryGetValue(customTypeCode, out customType); object obj; if (flag) { bool flag2 = customType.DeserializeStreamFunction == null; if (flag2) { byte[] array = new byte[(int)num]; din.Read(array, 0, (int)num); obj = customType.DeserializeFunction(array); } else { long position = din.Position; object obj2 = customType.DeserializeStreamFunction(din, num); int num2 = (int)(din.Position - position); bool flag3 = num2 != (int)num; if (flag3) { din.Position = position + (long)num; } obj = obj2; } } else { byte[] array2 = new byte[(int)num]; din.Read(array2, 0, (int)num); obj = array2; } return obj; } // Token: 0x060001DB RID: 475 RVA: 0x0000F974 File Offset: 0x0000DB74 private Type GetTypeOfCode(byte typeCode) { if (typeCode <= 42) { if (typeCode == 0 || typeCode == 42) { return typeof(object); } } else { if (typeCode == 68) { return typeof(IDictionary); } switch (typeCode) { case 97: return typeof(string[]); case 98: return typeof(byte); case 99: return typeof(CustomType); case 100: return typeof(double); case 101: return typeof(EventData); case 102: return typeof(float); case 104: return typeof(Hashtable); case 105: return typeof(int); case 107: return typeof(short); case 108: return typeof(long); case 110: return typeof(int[]); case 111: return typeof(bool); case 112: return typeof(OperationResponse); case 113: return typeof(OperationRequest); case 115: return typeof(string); case 120: return typeof(byte[]); case 121: return typeof(Array); case 122: return typeof(object[]); } } Debug.WriteLine("missing type: " + typeCode); throw new Exception("deserialize(): " + typeCode); } // Token: 0x060001DC RID: 476 RVA: 0x0000FB78 File Offset: 0x0000DD78 private Protocol16.GpType GetCodeOfType(Type type) { TypeCode typeCode = Type.GetTypeCode(type); TypeCode typeCode2 = typeCode; switch (typeCode2) { case TypeCode.Boolean: return Protocol16.GpType.Boolean; case TypeCode.Char: case TypeCode.SByte: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: break; case TypeCode.Byte: return Protocol16.GpType.Byte; case TypeCode.Int16: return Protocol16.GpType.Short; case TypeCode.Int32: return Protocol16.GpType.Integer; case TypeCode.Int64: return Protocol16.GpType.Long; case TypeCode.Single: return Protocol16.GpType.Float; case TypeCode.Double: return Protocol16.GpType.Double; default: if (typeCode2 == TypeCode.String) { return Protocol16.GpType.String; } break; } bool isArray = type.IsArray; Protocol16.GpType gpType; if (isArray) { bool flag = type == typeof(byte[]); if (flag) { gpType = Protocol16.GpType.ByteArray; } else { gpType = Protocol16.GpType.Array; } } else { bool flag2 = type == typeof(Hashtable); if (flag2) { gpType = Protocol16.GpType.Hashtable; } else { bool flag3 = type.IsGenericType && typeof(Dictionary<, >) == type.GetGenericTypeDefinition(); if (flag3) { gpType = Protocol16.GpType.Dictionary; } else { bool flag4 = type == typeof(EventData); if (flag4) { gpType = Protocol16.GpType.EventData; } else { bool flag5 = type == typeof(OperationRequest); if (flag5) { gpType = Protocol16.GpType.OperationRequest; } else { bool flag6 = type == typeof(OperationResponse); if (flag6) { gpType = Protocol16.GpType.OperationResponse; } else { gpType = Protocol16.GpType.Unknown; } } } } } } return gpType; } // Token: 0x060001DD RID: 477 RVA: 0x0000FCD4 File Offset: 0x0000DED4 private Array CreateArrayByType(byte arrayType, short length) { return Array.CreateInstance(this.GetTypeOfCode(arrayType), (int)length); } // Token: 0x060001DE RID: 478 RVA: 0x0000FCF3 File Offset: 0x0000DEF3 private void SerializeOperationRequest(StreamBuffer stream, OperationRequest serObject, bool setType) { this.SerializeOperationRequest(stream, serObject.OperationCode, serObject.Parameters, setType); } // Token: 0x060001DF RID: 479 RVA: 0x0000FD0C File Offset: 0x0000DF0C public override void SerializeOperationRequest(StreamBuffer stream, byte operationCode, Dictionary parameters, bool setType) { if (setType) { stream.WriteByte(113); } stream.WriteByte(operationCode); this.SerializeParameterTable(stream, parameters); } // Token: 0x060001E0 RID: 480 RVA: 0x0000FD3C File Offset: 0x0000DF3C public override OperationRequest DeserializeOperationRequest(StreamBuffer din) { return new OperationRequest { OperationCode = this.DeserializeByte(din), Parameters = this.DeserializeParameterTable(din) }; } // Token: 0x060001E1 RID: 481 RVA: 0x0000FD70 File Offset: 0x0000DF70 public override void SerializeOperationResponse(StreamBuffer stream, OperationResponse serObject, bool setType) { if (setType) { stream.WriteByte(112); } stream.WriteByte(serObject.OperationCode); this.SerializeShort(stream, serObject.ReturnCode, false); bool flag = string.IsNullOrEmpty(serObject.DebugMessage); if (flag) { stream.WriteByte(42); } else { this.SerializeString(stream, serObject.DebugMessage, false); } this.SerializeParameterTable(stream, serObject.Parameters); } // Token: 0x060001E2 RID: 482 RVA: 0x0000FDE8 File Offset: 0x0000DFE8 public override OperationResponse DeserializeOperationResponse(StreamBuffer stream) { return new OperationResponse { OperationCode = this.DeserializeByte(stream), ReturnCode = this.DeserializeShort(stream), DebugMessage = (this.Deserialize(stream, this.DeserializeByte(stream)) as string), Parameters = this.DeserializeParameterTable(stream) }; } // Token: 0x060001E3 RID: 483 RVA: 0x0000FE44 File Offset: 0x0000E044 public override void SerializeEventData(StreamBuffer stream, EventData serObject, bool setType) { if (setType) { stream.WriteByte(101); } stream.WriteByte(serObject.Code); this.SerializeParameterTable(stream, serObject.Parameters); } // Token: 0x060001E4 RID: 484 RVA: 0x0000FE80 File Offset: 0x0000E080 public override EventData DeserializeEventData(StreamBuffer din) { return new EventData { Code = this.DeserializeByte(din), Parameters = this.DeserializeParameterTable(din) }; } // Token: 0x060001E5 RID: 485 RVA: 0x0000FEB4 File Offset: 0x0000E0B4 private void SerializeParameterTable(StreamBuffer stream, Dictionary parameters) { bool flag = parameters == null || parameters.Count == 0; if (flag) { this.SerializeShort(stream, 0, false); } else { this.SerializeShort(stream, (short)parameters.Count, false); foreach (KeyValuePair keyValuePair in parameters) { stream.WriteByte(keyValuePair.Key); this.Serialize(stream, keyValuePair.Value, true); } } } // Token: 0x060001E6 RID: 486 RVA: 0x0000FF50 File Offset: 0x0000E150 private Dictionary DeserializeParameterTable(StreamBuffer stream) { short num = this.DeserializeShort(stream); Dictionary dictionary = new Dictionary((int)num); for (int i = 0; i < (int)num; i++) { byte b = (byte)stream.ReadByte(); object obj = this.Deserialize(stream, (byte)stream.ReadByte()); dictionary[b] = obj; } return dictionary; } // Token: 0x060001E7 RID: 487 RVA: 0x0000FFAC File Offset: 0x0000E1AC public override void Serialize(StreamBuffer dout, object serObject, bool setType) { bool flag = serObject == null; if (flag) { if (setType) { dout.WriteByte(42); } } else { Protocol16.GpType codeOfType = this.GetCodeOfType(serObject.GetType()); Protocol16.GpType gpType = codeOfType; if (gpType != Protocol16.GpType.Dictionary) { switch (gpType) { case Protocol16.GpType.Byte: this.SerializeByte(dout, (byte)serObject, setType); return; case Protocol16.GpType.Double: this.SerializeDouble(dout, (double)serObject, setType); return; case Protocol16.GpType.EventData: this.SerializeEventData(dout, (EventData)serObject, setType); return; case Protocol16.GpType.Float: this.SerializeFloat(dout, (float)serObject, setType); return; case Protocol16.GpType.Hashtable: this.SerializeHashTable(dout, (Hashtable)serObject, setType); return; case Protocol16.GpType.Integer: this.SerializeInteger(dout, (int)serObject, setType); return; case Protocol16.GpType.Short: this.SerializeShort(dout, (short)serObject, setType); return; case Protocol16.GpType.Long: this.SerializeLong(dout, (long)serObject, setType); return; case Protocol16.GpType.Boolean: this.SerializeBoolean(dout, (bool)serObject, setType); return; case Protocol16.GpType.OperationResponse: this.SerializeOperationResponse(dout, (OperationResponse)serObject, setType); return; case Protocol16.GpType.OperationRequest: this.SerializeOperationRequest(dout, (OperationRequest)serObject, setType); return; case Protocol16.GpType.String: this.SerializeString(dout, (string)serObject, setType); return; case Protocol16.GpType.ByteArray: this.SerializeByteArray(dout, (byte[])serObject, setType); return; case Protocol16.GpType.Array: { bool flag2 = serObject is int[]; if (flag2) { this.SerializeIntArrayOptimized(dout, (int[])serObject, setType); } else { bool flag3 = serObject.GetType().GetElementType() == typeof(object); if (flag3) { this.SerializeObjectArray(dout, serObject as object[], setType); } else { this.SerializeArray(dout, (Array)serObject, setType); } } return; } } bool flag4 = serObject is ArraySegment; if (flag4) { ArraySegment arraySegment = (ArraySegment)serObject; this.SerializeByteArraySegment(dout, arraySegment.Array, arraySegment.Offset, arraySegment.Count, setType); } else { bool flag5 = !this.SerializeCustom(dout, serObject); if (flag5) { throw new Exception("cannot serialize(): " + serObject.GetType()); } } } else { this.SerializeDictionary(dout, (IDictionary)serObject, setType); } } } // Token: 0x060001E8 RID: 488 RVA: 0x0001023C File Offset: 0x0000E43C private void SerializeByte(StreamBuffer dout, byte serObject, bool setType) { if (setType) { dout.WriteByte(98); } dout.WriteByte(serObject); } // Token: 0x060001E9 RID: 489 RVA: 0x00010264 File Offset: 0x0000E464 private void SerializeBoolean(StreamBuffer dout, bool serObject, bool setType) { if (setType) { dout.WriteByte(111); } dout.WriteByte(serObject ? 1 : 0); } // Token: 0x060001EA RID: 490 RVA: 0x00010290 File Offset: 0x0000E490 public override void SerializeShort(StreamBuffer dout, short serObject, bool setType) { if (setType) { dout.WriteByte(107); } byte[] array = this.memShort; lock (array) { byte[] array2 = this.memShort; array2[0] = (byte)(serObject >> 8); array2[1] = (byte)serObject; dout.Write(array2, 0, 2); } } // Token: 0x060001EB RID: 491 RVA: 0x000102F8 File Offset: 0x0000E4F8 private void SerializeInteger(StreamBuffer dout, int serObject, bool setType) { if (setType) { dout.WriteByte(105); } byte[] array = this.memInteger; lock (array) { byte[] array2 = this.memInteger; array2[0] = (byte)(serObject >> 24); array2[1] = (byte)(serObject >> 16); array2[2] = (byte)(serObject >> 8); array2[3] = (byte)serObject; dout.Write(array2, 0, 4); } } // Token: 0x060001EC RID: 492 RVA: 0x00010370 File Offset: 0x0000E570 private void SerializeLong(StreamBuffer dout, long serObject, bool setType) { if (setType) { dout.WriteByte(108); } long[] array = this.memLongBlock; lock (array) { this.memLongBlock[0] = serObject; Buffer.BlockCopy(this.memLongBlock, 0, this.memLongBlockBytes, 0, 8); byte[] array2 = this.memLongBlockBytes; bool isLittleEndian = BitConverter.IsLittleEndian; if (isLittleEndian) { byte b = array2[0]; byte b2 = array2[1]; byte b3 = array2[2]; byte b4 = array2[3]; array2[0] = array2[7]; array2[1] = array2[6]; array2[2] = array2[5]; array2[3] = array2[4]; array2[4] = b4; array2[5] = b3; array2[6] = b2; array2[7] = b; } dout.Write(array2, 0, 8); } } // Token: 0x060001ED RID: 493 RVA: 0x00010434 File Offset: 0x0000E634 private void SerializeFloat(StreamBuffer dout, float serObject, bool setType) { if (setType) { dout.WriteByte(102); } byte[] array = Protocol16.memFloatBlockBytes; lock (array) { Protocol16.memFloatBlock[0] = serObject; Buffer.BlockCopy(Protocol16.memFloatBlock, 0, Protocol16.memFloatBlockBytes, 0, 4); bool isLittleEndian = BitConverter.IsLittleEndian; if (isLittleEndian) { byte b = Protocol16.memFloatBlockBytes[0]; byte b2 = Protocol16.memFloatBlockBytes[1]; Protocol16.memFloatBlockBytes[0] = Protocol16.memFloatBlockBytes[3]; Protocol16.memFloatBlockBytes[1] = Protocol16.memFloatBlockBytes[2]; Protocol16.memFloatBlockBytes[2] = b2; Protocol16.memFloatBlockBytes[3] = b; } dout.Write(Protocol16.memFloatBlockBytes, 0, 4); } } // Token: 0x060001EE RID: 494 RVA: 0x000104F0 File Offset: 0x0000E6F0 private void SerializeDouble(StreamBuffer dout, double serObject, bool setType) { if (setType) { dout.WriteByte(100); } byte[] array = this.memDoubleBlockBytes; lock (array) { this.memDoubleBlock[0] = serObject; Buffer.BlockCopy(this.memDoubleBlock, 0, this.memDoubleBlockBytes, 0, 8); byte[] array2 = this.memDoubleBlockBytes; bool isLittleEndian = BitConverter.IsLittleEndian; if (isLittleEndian) { byte b = array2[0]; byte b2 = array2[1]; byte b3 = array2[2]; byte b4 = array2[3]; array2[0] = array2[7]; array2[1] = array2[6]; array2[2] = array2[5]; array2[3] = array2[4]; array2[4] = b4; array2[5] = b3; array2[6] = b2; array2[7] = b; } dout.Write(array2, 0, 8); } } // Token: 0x060001EF RID: 495 RVA: 0x000105B4 File Offset: 0x0000E7B4 public override void SerializeString(StreamBuffer dout, string serObject, bool setType) { if (setType) { dout.WriteByte(115); } byte[] bytes = Encoding.UTF8.GetBytes(serObject); bool flag = bytes.Length > 32767; if (flag) { throw new NotSupportedException("Strings that exceed a UTF8-encoded byte-length of 32767 (short.MaxValue) are not supported. Yours is: " + bytes.Length); } this.SerializeShort(dout, (short)bytes.Length, false); dout.Write(bytes, 0, bytes.Length); } // Token: 0x060001F0 RID: 496 RVA: 0x00010620 File Offset: 0x0000E820 private void SerializeArray(StreamBuffer dout, Array serObject, bool setType) { if (setType) { dout.WriteByte(121); } bool flag = serObject.Length > 32767; if (flag) { throw new NotSupportedException("String[] that exceed 32767 (short.MaxValue) entries are not supported. Yours is: " + serObject.Length); } this.SerializeShort(dout, (short)serObject.Length, false); Type elementType = serObject.GetType().GetElementType(); Protocol16.GpType codeOfType = this.GetCodeOfType(elementType); bool flag2 = codeOfType > Protocol16.GpType.Unknown; if (flag2) { dout.WriteByte((byte)codeOfType); bool flag3 = codeOfType == Protocol16.GpType.Dictionary; if (flag3) { bool flag4; bool flag5; this.SerializeDictionaryHeader(dout, serObject, out flag4, out flag5); for (int i = 0; i < serObject.Length; i++) { object value = serObject.GetValue(i); this.SerializeDictionaryElements(dout, value, flag4, flag5); } } else { for (int j = 0; j < serObject.Length; j++) { object value2 = serObject.GetValue(j); this.Serialize(dout, value2, false); } } } else { CustomType customType; bool flag6 = Protocol.TypeDict.TryGetValue(elementType, out customType); if (!flag6) { throw new NotSupportedException("cannot serialize array of type " + elementType); } dout.WriteByte(99); dout.WriteByte(customType.Code); for (int k = 0; k < serObject.Length; k++) { object value3 = serObject.GetValue(k); bool flag7 = customType.SerializeStreamFunction == null; if (flag7) { byte[] array = customType.SerializeFunction(value3); this.SerializeShort(dout, (short)array.Length, false); dout.Write(array, 0, array.Length); } else { long position = dout.Position; dout.Position += 2L; short num = customType.SerializeStreamFunction(dout, value3); long position2 = dout.Position; dout.Position = position; this.SerializeShort(dout, num, false); dout.Position += (long)num; bool flag8 = dout.Position != position2; if (flag8) { throw new Exception(string.Concat(new object[] { "Serialization failed. Stream position corrupted. Should be ", position2, " is now: ", dout.Position, " serializedLength: ", num })); } } } } } // Token: 0x060001F1 RID: 497 RVA: 0x0001089C File Offset: 0x0000EA9C private void SerializeByteArray(StreamBuffer dout, byte[] serObject, bool setType) { if (setType) { dout.WriteByte(120); } this.SerializeInteger(dout, serObject.Length, false); dout.Write(serObject, 0, serObject.Length); } // Token: 0x060001F2 RID: 498 RVA: 0x000108D4 File Offset: 0x0000EAD4 private void SerializeByteArraySegment(StreamBuffer dout, byte[] serObject, int offset, int count, bool setType) { if (setType) { dout.WriteByte(120); } this.SerializeInteger(dout, count, false); dout.Write(serObject, offset, count); } // Token: 0x060001F3 RID: 499 RVA: 0x0001090C File Offset: 0x0000EB0C private void SerializeIntArrayOptimized(StreamBuffer inWriter, int[] serObject, bool setType) { if (setType) { inWriter.WriteByte(121); } this.SerializeShort(inWriter, (short)serObject.Length, false); inWriter.WriteByte(105); byte[] array = new byte[serObject.Length * 4]; int num = 0; for (int i = 0; i < serObject.Length; i++) { array[num++] = (byte)(serObject[i] >> 24); array[num++] = (byte)(serObject[i] >> 16); array[num++] = (byte)(serObject[i] >> 8); array[num++] = (byte)serObject[i]; } inWriter.Write(array, 0, array.Length); } // Token: 0x060001F4 RID: 500 RVA: 0x000109A4 File Offset: 0x0000EBA4 private void SerializeStringArray(StreamBuffer dout, string[] serObject, bool setType) { if (setType) { dout.WriteByte(97); } this.SerializeShort(dout, (short)serObject.Length, false); for (int i = 0; i < serObject.Length; i++) { this.SerializeString(dout, serObject[i], false); } } // Token: 0x060001F5 RID: 501 RVA: 0x000109F0 File Offset: 0x0000EBF0 private void SerializeObjectArray(StreamBuffer dout, object[] objects, bool setType) { if (setType) { dout.WriteByte(122); } this.SerializeShort(dout, (short)objects.Length, false); foreach (object obj in objects) { this.Serialize(dout, obj, true); } } // Token: 0x060001F6 RID: 502 RVA: 0x00010A40 File Offset: 0x0000EC40 private void SerializeHashTable(StreamBuffer dout, Hashtable serObject, bool setType) { if (setType) { dout.WriteByte(104); } this.SerializeShort(dout, (short)serObject.Count, false); Dictionary.KeyCollection keys = serObject.Keys; foreach (object obj in keys) { this.Serialize(dout, obj, true); this.Serialize(dout, serObject[obj], true); } } // Token: 0x060001F7 RID: 503 RVA: 0x00010AD0 File Offset: 0x0000ECD0 private void SerializeDictionary(StreamBuffer dout, IDictionary serObject, bool setType) { if (setType) { dout.WriteByte(68); } bool flag; bool flag2; this.SerializeDictionaryHeader(dout, serObject, out flag, out flag2); this.SerializeDictionaryElements(dout, serObject, flag, flag2); } // Token: 0x060001F8 RID: 504 RVA: 0x00010B08 File Offset: 0x0000ED08 private void SerializeDictionaryHeader(StreamBuffer writer, Type dictType) { bool flag; bool flag2; this.SerializeDictionaryHeader(writer, dictType, out flag, out flag2); } // Token: 0x060001F9 RID: 505 RVA: 0x00010B24 File Offset: 0x0000ED24 private void SerializeDictionaryHeader(StreamBuffer writer, object dict, out bool setKeyType, out bool setValueType) { Type[] genericArguments = dict.GetType().GetGenericArguments(); setKeyType = genericArguments[0] == typeof(object); setValueType = genericArguments[1] == typeof(object); bool flag = setKeyType; if (flag) { writer.WriteByte(0); } else { Protocol16.GpType codeOfType = this.GetCodeOfType(genericArguments[0]); bool flag2 = codeOfType == Protocol16.GpType.Unknown || codeOfType == Protocol16.GpType.Dictionary; if (flag2) { throw new Exception("Unexpected - cannot serialize Dictionary with key type: " + genericArguments[0]); } writer.WriteByte((byte)codeOfType); } bool flag3 = setValueType; if (flag3) { writer.WriteByte(0); } else { Protocol16.GpType codeOfType2 = this.GetCodeOfType(genericArguments[1]); bool flag4 = codeOfType2 == Protocol16.GpType.Unknown; if (flag4) { throw new Exception("Unexpected - cannot serialize Dictionary with value type: " + genericArguments[0]); } writer.WriteByte((byte)codeOfType2); bool flag5 = codeOfType2 == Protocol16.GpType.Dictionary; if (flag5) { this.SerializeDictionaryHeader(writer, genericArguments[1]); } } } // Token: 0x060001FA RID: 506 RVA: 0x00010C10 File Offset: 0x0000EE10 private void SerializeDictionaryElements(StreamBuffer writer, object dict, bool setKeyType, bool setValueType) { IDictionary dictionary = (IDictionary)dict; this.SerializeShort(writer, (short)dictionary.Count, false); foreach (object obj in dictionary) { DictionaryEntry dictionaryEntry = (DictionaryEntry)obj; bool flag = !setValueType && dictionaryEntry.Value == null; if (flag) { throw new Exception("Can't serialize null in Dictionary with specific value-type."); } bool flag2 = !setKeyType && dictionaryEntry.Key == null; if (flag2) { throw new Exception("Can't serialize null in Dictionary with specific key-type."); } this.Serialize(writer, dictionaryEntry.Key, setKeyType); this.Serialize(writer, dictionaryEntry.Value, setValueType); } } // Token: 0x060001FB RID: 507 RVA: 0x00010CE0 File Offset: 0x0000EEE0 public override object Deserialize(StreamBuffer din, byte type) { if (type <= 42) { if (type == 0 || type == 42) { return null; } } else { if (type == 68) { return this.DeserializeDictionary(din); } switch (type) { case 97: return this.DeserializeStringArray(din); case 98: return this.DeserializeByte(din); case 99: { byte b = (byte)din.ReadByte(); return this.DeserializeCustom(din, b); } case 100: return this.DeserializeDouble(din); case 101: return this.DeserializeEventData(din); case 102: return this.DeserializeFloat(din); case 104: return this.DeserializeHashTable(din); case 105: return this.DeserializeInteger(din); case 107: return this.DeserializeShort(din); case 108: return this.DeserializeLong(din); case 110: return this.DeserializeIntArray(din); case 111: return this.DeserializeBoolean(din); case 112: return this.DeserializeOperationResponse(din); case 113: return this.DeserializeOperationRequest(din); case 115: return this.DeserializeString(din); case 120: return this.DeserializeByteArray(din); case 121: return this.DeserializeArray(din); case 122: return this.DeserializeObjectArray(din); } } throw new Exception(string.Concat(new object[] { "Deserialize(): ", type, " pos: ", din.Position, " bytes: ", din.Length, ". ", SupportClass.ByteArrayToString(din.GetBuffer()) })); } // Token: 0x060001FC RID: 508 RVA: 0x00010F10 File Offset: 0x0000F110 public override byte DeserializeByte(StreamBuffer din) { return (byte)din.ReadByte(); } // Token: 0x060001FD RID: 509 RVA: 0x00010F2C File Offset: 0x0000F12C private bool DeserializeBoolean(StreamBuffer din) { return din.ReadByte() != 0; } // Token: 0x060001FE RID: 510 RVA: 0x00010F48 File Offset: 0x0000F148 public override short DeserializeShort(StreamBuffer din) { byte[] array = this.memShort; short num; lock (array) { byte[] array2 = this.memShort; din.Read(array2, 0, 2); num = (short)(((int)array2[0] << 8) | (int)array2[1]); } return num; } // Token: 0x060001FF RID: 511 RVA: 0x00010F9C File Offset: 0x0000F19C private int DeserializeInteger(StreamBuffer din) { byte[] array = this.memInteger; int num; lock (array) { byte[] array2 = this.memInteger; din.Read(array2, 0, 4); num = ((int)array2[0] << 24) | ((int)array2[1] << 16) | ((int)array2[2] << 8) | (int)array2[3]; } return num; } // Token: 0x06000200 RID: 512 RVA: 0x00011000 File Offset: 0x0000F200 private long DeserializeLong(StreamBuffer din) { byte[] array = this.memLong; long num; lock (array) { byte[] array2 = this.memLong; din.Read(array2, 0, 8); bool isLittleEndian = BitConverter.IsLittleEndian; if (isLittleEndian) { num = (long)(((ulong)array2[0] << 56) | ((ulong)array2[1] << 48) | ((ulong)array2[2] << 40) | ((ulong)array2[3] << 32) | ((ulong)array2[4] << 24) | ((ulong)array2[5] << 16) | ((ulong)array2[6] << 8) | (ulong)array2[7]); } else { num = BitConverter.ToInt64(array2, 0); } } return num; } // Token: 0x06000201 RID: 513 RVA: 0x0001109C File Offset: 0x0000F29C private float DeserializeFloat(StreamBuffer din) { byte[] array = this.memFloat; float num; lock (array) { byte[] array2 = this.memFloat; din.Read(array2, 0, 4); bool isLittleEndian = BitConverter.IsLittleEndian; if (isLittleEndian) { byte b = array2[0]; byte b2 = array2[1]; array2[0] = array2[3]; array2[1] = array2[2]; array2[2] = b2; array2[3] = b; } num = BitConverter.ToSingle(array2, 0); } return num; } // Token: 0x06000202 RID: 514 RVA: 0x00011118 File Offset: 0x0000F318 private double DeserializeDouble(StreamBuffer din) { byte[] array = this.memDouble; double num; lock (array) { byte[] array2 = this.memDouble; din.Read(array2, 0, 8); bool isLittleEndian = BitConverter.IsLittleEndian; if (isLittleEndian) { byte b = array2[0]; byte b2 = array2[1]; byte b3 = array2[2]; byte b4 = array2[3]; array2[0] = array2[7]; array2[1] = array2[6]; array2[2] = array2[5]; array2[3] = array2[4]; array2[4] = b4; array2[5] = b3; array2[6] = b2; array2[7] = b; } num = BitConverter.ToDouble(array2, 0); } return num; } // Token: 0x06000203 RID: 515 RVA: 0x000111B4 File Offset: 0x0000F3B4 private string DeserializeString(StreamBuffer din) { short num = this.DeserializeShort(din); bool flag = num == 0; string text; if (flag) { text = string.Empty; } else { bool flag2 = this.memString == null || this.memString.Length < (int)num; if (flag2) { this.memString = new byte[(int)num]; } din.Read(this.memString, 0, (int)num); text = Encoding.UTF8.GetString(this.memString, 0, (int)num); } return text; } // Token: 0x06000204 RID: 516 RVA: 0x00011228 File Offset: 0x0000F428 private Array DeserializeArray(StreamBuffer din) { short num = this.DeserializeShort(din); byte b = (byte)din.ReadByte(); bool flag = b == 121; Array array2; if (flag) { Array array = this.DeserializeArray(din); Type type = array.GetType(); array2 = Array.CreateInstance(type, (int)num); array2.SetValue(array, 0); for (short num2 = 1; num2 < num; num2 += 1) { array = this.DeserializeArray(din); array2.SetValue(array, (int)num2); } } else { bool flag2 = b == 120; if (flag2) { array2 = Array.CreateInstance(typeof(byte[]), (int)num); for (short num3 = 0; num3 < num; num3 += 1) { Array array3 = this.DeserializeByteArray(din); array2.SetValue(array3, (int)num3); } } else { bool flag3 = b == 99; if (flag3) { byte b2 = (byte)din.ReadByte(); CustomType customType; bool flag4 = Protocol.CodeDict.TryGetValue(b2, out customType); if (!flag4) { throw new Exception("Cannot find deserializer for custom type: " + b2); } array2 = Array.CreateInstance(customType.Type, (int)num); for (int i = 0; i < (int)num; i++) { short num4 = this.DeserializeShort(din); bool flag5 = customType.DeserializeStreamFunction == null; if (flag5) { byte[] array4 = new byte[(int)num4]; din.Read(array4, 0, (int)num4); array2.SetValue(customType.DeserializeFunction(array4), i); } else { array2.SetValue(customType.DeserializeStreamFunction(din, num4), i); } } } else { bool flag6 = b == 68; if (flag6) { Array array5 = null; this.DeserializeDictionaryArray(din, num, out array5); return array5; } array2 = this.CreateArrayByType(b, num); for (short num5 = 0; num5 < num; num5 += 1) { array2.SetValue(this.Deserialize(din, b), (int)num5); } } } } return array2; } // Token: 0x06000205 RID: 517 RVA: 0x0001142C File Offset: 0x0000F62C private byte[] DeserializeByteArray(StreamBuffer din) { int num = this.DeserializeInteger(din); byte[] array = new byte[num]; din.Read(array, 0, num); return array; } // Token: 0x06000206 RID: 518 RVA: 0x00011458 File Offset: 0x0000F658 private int[] DeserializeIntArray(StreamBuffer din) { int num = this.DeserializeInteger(din); int[] array = new int[num]; for (int i = 0; i < num; i++) { array[i] = this.DeserializeInteger(din); } return array; } // Token: 0x06000207 RID: 519 RVA: 0x00011498 File Offset: 0x0000F698 private string[] DeserializeStringArray(StreamBuffer din) { int num = (int)this.DeserializeShort(din); string[] array = new string[num]; for (int i = 0; i < num; i++) { array[i] = this.DeserializeString(din); } return array; } // Token: 0x06000208 RID: 520 RVA: 0x000114D8 File Offset: 0x0000F6D8 private object[] DeserializeObjectArray(StreamBuffer din) { short num = this.DeserializeShort(din); object[] array = new object[(int)num]; for (int i = 0; i < (int)num; i++) { byte b = (byte)din.ReadByte(); array[i] = this.Deserialize(din, b); } return array; } // Token: 0x06000209 RID: 521 RVA: 0x00011524 File Offset: 0x0000F724 private Hashtable DeserializeHashTable(StreamBuffer din) { int num = (int)this.DeserializeShort(din); Hashtable hashtable = new Hashtable(num); for (int i = 0; i < num; i++) { object obj = this.Deserialize(din, (byte)din.ReadByte()); object obj2 = this.Deserialize(din, (byte)din.ReadByte()); hashtable[obj] = obj2; } return hashtable; } // Token: 0x0600020A RID: 522 RVA: 0x00011588 File Offset: 0x0000F788 private IDictionary DeserializeDictionary(StreamBuffer din) { byte b = (byte)din.ReadByte(); byte b2 = (byte)din.ReadByte(); int num = (int)this.DeserializeShort(din); bool flag = b == 0 || b == 42; bool flag2 = b2 == 0 || b2 == 42; Type typeOfCode = this.GetTypeOfCode(b); Type typeOfCode2 = this.GetTypeOfCode(b2); Type type = typeof(Dictionary<, >).MakeGenericType(new Type[] { typeOfCode, typeOfCode2 }); IDictionary dictionary = Activator.CreateInstance(type) as IDictionary; for (int i = 0; i < num; i++) { object obj = this.Deserialize(din, flag ? ((byte)din.ReadByte()) : b); object obj2 = this.Deserialize(din, flag2 ? ((byte)din.ReadByte()) : b2); dictionary.Add(obj, obj2); } return dictionary; } // Token: 0x0600020B RID: 523 RVA: 0x00011664 File Offset: 0x0000F864 private bool DeserializeDictionaryArray(StreamBuffer din, short size, out Array arrayResult) { byte b; byte b2; Type type = this.DeserializeDictionaryType(din, out b, out b2); arrayResult = Array.CreateInstance(type, (int)size); for (short num = 0; num < size; num += 1) { IDictionary dictionary = Activator.CreateInstance(type) as IDictionary; bool flag = dictionary == null; if (flag) { return false; } short num2 = this.DeserializeShort(din); for (int i = 0; i < (int)num2; i++) { bool flag2 = b > 0; object obj; if (flag2) { obj = this.Deserialize(din, b); } else { byte b3 = (byte)din.ReadByte(); obj = this.Deserialize(din, b3); } bool flag3 = b2 > 0; object obj2; if (flag3) { obj2 = this.Deserialize(din, b2); } else { byte b4 = (byte)din.ReadByte(); obj2 = this.Deserialize(din, b4); } dictionary.Add(obj, obj2); } arrayResult.SetValue(dictionary, (int)num); } return true; } // Token: 0x0600020C RID: 524 RVA: 0x00011760 File Offset: 0x0000F960 private Type DeserializeDictionaryType(StreamBuffer reader, out byte keyTypeCode, out byte valTypeCode) { keyTypeCode = (byte)reader.ReadByte(); valTypeCode = (byte)reader.ReadByte(); Protocol16.GpType gpType = (Protocol16.GpType)keyTypeCode; Protocol16.GpType gpType2 = (Protocol16.GpType)valTypeCode; bool flag = gpType == Protocol16.GpType.Unknown; Type type; if (flag) { type = typeof(object); } else { type = this.GetTypeOfCode(keyTypeCode); } bool flag2 = gpType2 == Protocol16.GpType.Unknown; Type type2; if (flag2) { type2 = typeof(object); } else { type2 = this.GetTypeOfCode(valTypeCode); } return typeof(Dictionary<, >).MakeGenericType(new Type[] { type, type2 }); } // Token: 0x04000120 RID: 288 private readonly byte[] versionBytes = new byte[] { 1, 6 }; // Token: 0x04000121 RID: 289 private readonly byte[] memShort = new byte[2]; // Token: 0x04000122 RID: 290 private readonly long[] memLongBlock = new long[1]; // Token: 0x04000123 RID: 291 private readonly byte[] memLongBlockBytes = new byte[8]; // Token: 0x04000124 RID: 292 private static readonly float[] memFloatBlock = new float[1]; // Token: 0x04000125 RID: 293 private static readonly byte[] memFloatBlockBytes = new byte[4]; // Token: 0x04000126 RID: 294 private readonly double[] memDoubleBlock = new double[1]; // Token: 0x04000127 RID: 295 private readonly byte[] memDoubleBlockBytes = new byte[8]; // Token: 0x04000128 RID: 296 private readonly byte[] memInteger = new byte[4]; // Token: 0x04000129 RID: 297 private readonly byte[] memLong = new byte[8]; // Token: 0x0400012A RID: 298 private readonly byte[] memFloat = new byte[4]; // Token: 0x0400012B RID: 299 private readonly byte[] memDouble = new byte[8]; // Token: 0x0400012C RID: 300 private byte[] memString; // Token: 0x02000049 RID: 73 public enum GpType : byte { // Token: 0x040001B0 RID: 432 Unknown, // Token: 0x040001B1 RID: 433 Array = 121, // Token: 0x040001B2 RID: 434 Boolean = 111, // Token: 0x040001B3 RID: 435 Byte = 98, // Token: 0x040001B4 RID: 436 ByteArray = 120, // Token: 0x040001B5 RID: 437 ObjectArray = 122, // Token: 0x040001B6 RID: 438 Short = 107, // Token: 0x040001B7 RID: 439 Float = 102, // Token: 0x040001B8 RID: 440 Dictionary = 68, // Token: 0x040001B9 RID: 441 Double = 100, // Token: 0x040001BA RID: 442 Hashtable = 104, // Token: 0x040001BB RID: 443 Integer, // Token: 0x040001BC RID: 444 IntegerArray = 110, // Token: 0x040001BD RID: 445 Long = 108, // Token: 0x040001BE RID: 446 String = 115, // Token: 0x040001BF RID: 447 StringArray = 97, // Token: 0x040001C0 RID: 448 Custom = 99, // Token: 0x040001C1 RID: 449 Null = 42, // Token: 0x040001C2 RID: 450 EventData = 101, // Token: 0x040001C3 RID: 451 OperationRequest = 113, // Token: 0x040001C4 RID: 452 OperationResponse = 112 } } }