private Array DeserializeArray(System.Type type, System.Type arrayType, BitBuffer data) { int num = this._data.ReadInt(); Array instance = Activator.CreateInstance(type, (object)num) as Array; for (int index = 0; index < num; ++index) { bool flag = this._data.ReadBool(); object obj = (object)null; if (flag) { if (typeof(BinaryClassChunk).IsAssignableFrom(arrayType)) { BinaryClassChunk binaryClassChunk = BinaryClassChunk.DeserializeHeader(arrayType, this._data, root: false, skipData: true); binaryClassChunk?.Deserialize(); obj = (object)binaryClassChunk; } else { obj = this._data.Read(arrayType); } } instance.SetValue(obj, index); } return(instance); }
public static BinaryClassChunk DeserializeHeader( System.Type t, BitBuffer data, BinaryClassChunk target = null, bool root = true, bool skipData = false) { if (target == null) { target = Activator.CreateInstance(t, (object[])null) as BinaryClassChunk; } try { long num1 = 0; if (root) { num1 = data.ReadLong(); if (num1 != BinaryClassChunk.MagicNumber(t) && num1 != 5033950674723417L) { target._result = DeserializeResult.InvalidMagicNumber; return(target); } target._checksum = data.ReadUInt(); } ushort num2 = data.ReadUShort(); ushort num3 = BinaryClassChunk.ChunkVersion(t); if ((int)num2 != (int)num3 && (!(target is LevelData) || num2 != (ushort)2)) { target._result = (int)num2 <= (int)num3 ? DeserializeResult.FileVersionTooOld : DeserializeResult.FileVersionTooNew; return(target); } if (num2 == (ushort)2 && target is LevelData && data.ReadBool()) { BinaryClassChunk binaryClassChunk = BinaryClassChunk.DeserializeHeader(Editor.GetType(data.ReadString()), data, root: false); if (binaryClassChunk != null && binaryClassChunk._result == DeserializeResult.HeaderDeserialized) { binaryClassChunk.Deserialize(); target._headerDictionary["metaData"] = binaryClassChunk; } } target._magicNumber = num1; target._version = num2; target._size = data.ReadUInt(); target._offset = (uint)data.position; target._data = data; target._result = DeserializeResult.HeaderDeserialized; if (skipData) { data.position = (int)target._offset + (int)target._size; } return(target); } catch (Exception ex) { target._exception = ex; target._result = DeserializeResult.ExceptionThrown; return(target); } }
public void SetData(BitBuffer data) { BinaryClassChunk.DeserializeHeader(this.GetType(), data, this); if (this._result != DeserializeResult.HeaderDeserialized) { return; } this.Deserialize(); }
public bool Deserialize() { if (this._data == null) { this._result = DeserializeResult.NoData; return(false); } if (this._result == DeserializeResult.Success) { return(true); } try { this._data.position = (int)this._offset; ushort num1 = this._data.ReadUShort(); for (int index = 0; index < (int)num1; ++index) { string str = this._data.ReadString(); ClassMember classMember = (ClassMember)null; System.Type key = (System.Type)null; if (str.StartsWith("@")) { if (this._extraProperties == null) { this._extraProperties = new MultiMap <string, object>(); } byte num2 = this._data.ReadByte(); if (((int)num2 & 1) != 0) { byte num3 = (byte)((uint)num2 >> 1); BinaryClassMember.typeMap.TryGetKey(num3, out key); } else { key = Editor.GetType(this._data.ReadString()); } str = str.Substring(1, str.Length - 1); } else { classMember = Editor.GetMember(this.GetType(), str); if (classMember != null) { key = classMember.type; } } uint num4 = this._data.ReadUInt(); if (key != (System.Type)null) { int position = this._data.position; if (typeof(BinaryClassChunk).IsAssignableFrom(key)) { BinaryClassChunk binaryClassChunk = BinaryClassChunk.DeserializeHeader(key, this._data, root: false); if (classMember == null) { this._extraProperties.Add(str, (object)binaryClassChunk); } else { this._headerDictionary[str] = binaryClassChunk; } this._data.position = position + (int)num4; } else if (key.IsArray) { Array array = this.DeserializeArray(key, key.GetElementType(), this._data); if (classMember == null) { this._extraProperties.Add(str, (object)array); } else { classMember.SetValue((object)this, (object)array); } } else if (key.IsGenericType && key.GetGenericTypeDefinition() == typeof(List <>)) { Array array = this.DeserializeArray(typeof(object[]), key.GetGenericArguments()[0], this._data); IList instance = Activator.CreateInstance(key) as IList; foreach (object obj in array) { instance.Add(obj); } if (classMember == null) { this._extraProperties.Add(str, (object)instance); } else { classMember.SetValue((object)this, (object)instance); } } else if (key.IsGenericType && key.GetGenericTypeDefinition() == typeof(HashSet <>)) { Array array = this.DeserializeArray(typeof(object[]), key.GetGenericArguments()[0], this._data); IList instance1 = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(key.GetGenericArguments()[0])); foreach (object obj in array) { instance1.Add(obj); } object instance2 = Activator.CreateInstance(key, (object)instance1); if (classMember == null) { this._extraProperties.Add(str, instance2); } else { classMember.SetValue((object)this, instance2); } } else { object element = !key.IsEnum ? this._data.Read(key, false) : (object)this._data.ReadInt(); if (classMember == null) { this._extraProperties.Add(str, element); } else { classMember.SetValue((object)this, element); } } } else { this._data.position += (int)num4; } } } catch (Exception ex) { this._exception = ex; this._result = DeserializeResult.ExceptionThrown; return(false); } this._result = DeserializeResult.Success; return(true); }