Пример #1
0
 public override void DeSerialize(DataReader data)
 {
     header.DeSerialize(data);
     uint n1 = BitConverter.ToUInt32(new byte[] { 1, 0, 0, 0 }, 0);
     data.byteOrder = DataReader.ByteOrder.Little;
     //compress with lzma
     if (!header.signature.Contains("UnityRaw")) {
         SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();
         data.position = header.headerSize;
         byte[] properties = data.ReadBytes(5);
         long uncompressFileSize = data.ReadInt64();
         decoder.SetDecoderProperties(properties);
         MemoryStream outMs = new MemoryStream((int)uncompressFileSize);
         decoder.Code(data.BaseStream,outMs,data.BaseStream.Length-header.headerSize,uncompressFileSize,null);
         data.Close();
         data = new DataReader(outMs);
         data.position = 0;
     }
     data.byteOrder = DataReader.ByteOrder.Big;
     numOfEntryCount = data.ReadInt32();
     entrys = new SerializeBundleEntry[numOfEntryCount];
     for (int i = 0; i < numOfEntryCount; i++) {
         entrys[i] = new SerializeBundleEntry();
         entrys[i].DeSerialize(data);
     }
 }
 public override void DeSerialize(DataReader data)
 {
     data.byteOrder = DataReader.ByteOrder.Big;
     MetaDataSize = data.ReadInt32();
     FileSize = data.ReadUint32();
     Version = data.ReadInt32();
     DataOffset = data.ReadUint32();
     endianness = data.ReadByte();
     reserved = data.ReadBytes(3);
 }
        public override void DeSerialize(DataReader br)
        {
            br.byteOrder = DataReader.ByteOrder.Big;
            signature = br.ReadStringNull();
            streamVersion = br.ReadInt32();
            unityVersion = br.ReadStringNull();
            unityRevision = br.ReadStringNull();
            minimumStreamedBytes = br.ReadUInt32();
            headerSize = br.ReadInt32();

            numberOfLevelsToDownload = br.ReadInt32();
            numberOfLevels = br.ReadInt32();
            levelByteEnd.Clear();
            for (int i = 0; i < numberOfLevels; i++) {
                levelByteEnd.Add(new KeyValuePair<uint, uint>(br.ReadUInt32(), br.ReadUInt32()));
            }
            completeFileSize = br.ReadUInt32();
            dataHeaderSize = br.ReadUInt32();
            resvers = br.ReadBytes(1);
        }
        public object readArrayValue(TypeTree typeTree, DataReader data)
        {            
            var elementType = typeTree.GetChildren()[1];
            arrayLength = data.ReadInt32();
            arrayElementType = typeStr2PropertyType(elementType.type);
            object ret = null;
            switch (arrayElementType) {
                case SerializePropertyType.Bool:
                ret = data.ReadBool(arrayLength);
                break;
                case SerializePropertyType.Byte:
                ret = data.ReadBytes(arrayLength);
                break;
                case SerializePropertyType.Double:
                ret = data.ReadDouble(arrayLength);
                break;
                case SerializePropertyType.Float:
                ret = data.ReadFloat(arrayLength);
                break;
                case SerializePropertyType.Int:
                ret = data.ReadInt32(arrayLength);
                break;
                case SerializePropertyType.Long:
                ret = data.ReadInt64(arrayLength);
                break;
                case SerializePropertyType.SByte:
                ret = data.ReadSbytes(arrayLength);
                break;
                case SerializePropertyType.Short:
                ret = data.ReadInt16(arrayLength);
                break;
                case SerializePropertyType.String:
                string[] stringArray = new string[arrayLength];
                for (int i = 0; i < arrayLength; i++) {
                    int strSize = data.ReadInt32();
                    stringArray[i] = UnicodeEncoding.UTF8.GetString(data.ReadBytes(strSize));
                    data.Align(4);
                }
                ret = stringArray;
                break;
                case SerializePropertyType.UInt:
                ret = data.ReadUint32(arrayLength);
                break;
                case SerializePropertyType.ULong:
                ret = data.ReadUInt64(arrayLength);
                break;
                case SerializePropertyType.UShort:
                ret = data.ReadUInt16(arrayLength);
                break;
                default:
                SerializeProperty[] properArray = new SerializeProperty[arrayLength];
                for (int i = 0; i < arrayLength; i++) {
                    SerializeProperty value = null;
                    if (arrayElementType == SerializePropertyType.Property || arrayElementType == SerializePropertyType.Array) {
                        var sp = new SerializeProperty(elementType);
                        sp.DeSerialize(data);
                        value = sp;
                    }
                    properArray[i] = value;
                }
                ret = properArray;
                break;
            }

            data.Align(4);
            return ret;
        }
        private object readValue(SerializePropertyType ptype,TypeTree typeTree, DataReader data)
        {
            
            object ret = null;
            switch (ptype) {
                case SerializePropertyType.Bool:
                ret = data.ReadBool();
                break;
                case SerializePropertyType.SByte:
                ret = data.ReadSbyte();
                break;
                case SerializePropertyType.Byte:
                ret = data.ReadByte();
                break;
                case SerializePropertyType.Short:
                ret = data.ReadInt16();
                break;
                case SerializePropertyType.UShort:
                ret = data.ReadUInt16();
                break;
                case SerializePropertyType.Int:
                ret = data.ReadInt32();
                break;
                case SerializePropertyType.UInt:
                ret = data.ReadUint32();
                break;
                case SerializePropertyType.Long:
                ret = data.ReadInt64();
                break;
                case SerializePropertyType.ULong:
                ret = data.ReadUInt64();
                break;
                case SerializePropertyType.Float:
                ret = data.ReadFloat();
                break;
                case SerializePropertyType.Double:
                ret = data.ReadDouble();
                break;
                case SerializePropertyType.String:
                int strSize = data.ReadInt32();
                ret = UnicodeEncoding.UTF8.GetString(data.ReadBytes(strSize));
                //ret = UTF8Encoding.Default.GetString();
                break;
                default:
                break;
            }

            if (((typeTree.metaFlag & TypeTree.FLAG_FORCE_ALIGN) != 0)  || propertyType == SerializePropertyType.String) {
                data.Align(4);
            }

            return ret;
        }
 public override void DeSerialize(DataReader br)
 {
     ClassID = br.ReadInt32();
     if (ClassID < 0) {
         hash = br.ReadBytes(16);
     } 
     oldhash = br.ReadBytes(16);
     if (isEmbedded) {
         fildsCount = br.ReadInt32();
         strTableSize = br.ReadInt32();
         types = new SerializeTypeData[fildsCount];
         for (int i = 0; i < fildsCount; i++) {
             types[i] = new SerializeTypeData();
             types[i].DeSerialize(br);
         }
         stringTable = br.ReadBytes(strTableSize);
     }
 }