Exemplo n.º 1
0
        public void StartDeserializing()
        {
            UnitySerializer.KtStack.Push(UnitySerializer.KnownTypes);
            UnitySerializer.PiStack.Push(UnitySerializer.PropertyIds);

            var stream  = new MemoryStream(Data);
            var reader  = new BinaryReader(stream);
            var version = reader.ReadString();

            UnitySerializer.currentVersion = int.Parse(version.Substring(4));
            if (UnitySerializer.currentVersion >= 3)
            {
                UnitySerializer.Verbose = reader.ReadBoolean();
            }

            UnitySerializer.PropertyIds = new List <string>();
            UnitySerializer.KnownTypes  = new List <RuntimeTypeHandle>();
            var count = reader.ReadInt32();

            for (var i = 0; i < count; i++)
            {
                var typeName = reader.ReadString();
                var tp       = Type.GetType(typeName);
                if (tp == null)
                {
                    var map = new UnitySerializer.TypeMappingEventArgs
                    {
                        TypeName = typeName
                    };
                    UnitySerializer.InvokeMapMissingType(map);
                    tp = map.UseType;
                }
                if (tp == null)
                {
                    throw new ArgumentException(string.Format("Cannot reference type {0} in this context", typeName));
                }
                UnitySerializer.KnownTypes.Add(tp.TypeHandle);
            }
            count = reader.ReadInt32();
            for (var i = 0; i < count; i++)
            {
                UnitySerializer.PropertyIds.Add(reader.ReadString());
            }

            var data = reader.ReadBytes(reader.ReadInt32());

            _myStream = new MemoryStream(data);
            _reader   = new BinaryReader(_myStream);
            reader.Close();
            stream.Close();
        }
Exemplo n.º 2
0
        public void StartDeserializing()
        {
            UnitySerializer.PushKnownTypes();
            UnitySerializer.PushPropertyNames();
            MemoryStream memoryStream = new MemoryStream(this.Data);
            BinaryReader binaryReader = new BinaryReader(memoryStream);
            string       text         = binaryReader.ReadString();

            UnitySerializer.currentVersion = int.Parse(text.Substring(4));
            if (UnitySerializer.currentVersion >= 3)
            {
                UnitySerializer.Verbose = binaryReader.ReadBoolean();
            }
            int num = binaryReader.ReadInt32();

            for (int i = 0; i < num; i++)
            {
                string text2 = binaryReader.ReadString();
                Type   type  = UnitySerializer.GetTypeEx(text2);
                if (type == null)
                {
                    UnitySerializer.TypeMappingEventArgs typeMappingEventArgs = new UnitySerializer.TypeMappingEventArgs
                    {
                        TypeName = text2
                    };
                    UnitySerializer.InvokeMapMissingType(typeMappingEventArgs);
                    type = typeMappingEventArgs.UseType;
                }
                if (type == null)
                {
                    throw new ArgumentException(string.Format("Cannot reference type {0} in this context", text2));
                }
                UnitySerializer._knownTypesList.Add(type);
            }
            num = binaryReader.ReadInt32();
            for (int j = 0; j < num; j++)
            {
                UnitySerializer._propertyList.Add(binaryReader.ReadString());
            }
            byte[] buffer = binaryReader.ReadBytes(binaryReader.ReadInt32());
            this._myStream = new MemoryStream(buffer);
            this._reader   = new BinaryReader(this._myStream);
            binaryReader.Close();
            memoryStream.Close();
        }