Ejemplo n.º 1
0
        public void Read(SerializedFileReader reader)
        {
            Hierarchy.Read(reader);

            int count = reader.ReadInt32();
            Dictionary <long, AssetEntry> entries = new Dictionary <long, AssetEntry>(count);

            for (int i = 0; i < count; i++)
            {
                AssetEntry entry = new AssetEntry();
                entry.Read(reader, Hierarchy);
                entries.Add(entry.PathID, entry);
            }
            Entries = entries;

            if (IsReadPreload(reader.Generation))
            {
                Preloads = reader.ReadSerializedArray <ObjectPtr>();
            }
            Dependencies = reader.ReadSerializedArray <FileIdentifier>();
            if (IsReadUnknown(reader.Generation))
            {
                Unknown = reader.ReadStringZeroTerm();
            }
        }
Ejemplo n.º 2
0
        public void Read(SerializedFileReader reader)
        {
            if (IsRead5Format(reader.Generation))
            {
                int nodesCount = reader.ReadInt32();
                if (nodesCount < 0)
                {
                    throw new Exception($"Invalid type tree's node count {nodesCount}");
                }

                int stringSize = reader.ReadInt32();
                if (stringSize < 0)
                {
                    throw new Exception($"Invalid type tree's string size {stringSize}");
                }

                TypeTreeNode[] nodes          = new TypeTreeNode[nodesCount];
                long           stringPosition = reader.BaseStream.Position + nodesCount * TypeTreeNode.GetNodeSize(reader.Generation);
                for (int i = 0; i < nodesCount; i++)
                {
                    TypeTreeNode node = new TypeTreeNode();
                    node.Read(reader, stringPosition);
                    nodes[i] = node;
                }
                Nodes = nodes;
                reader.BaseStream.Position += stringSize;
            }
            else
            {
                List <TypeTreeNode> nodes = new List <TypeTreeNode>();
                ReadTreeNode(reader, nodes, 0);
                Nodes = nodes.ToArray();
            }
        }
Ejemplo n.º 3
0
        private void ReadScheme()
        {
            using (PartialStream stream = new PartialStream(m_stream, m_offset, m_size))
            {
                using (EndianReader reader = new EndianReader(stream, EndianType.BigEndian))
                {
                    Header.Read(reader);
                }

                EndianType endianess = Header.SwapEndianess ? EndianType.BigEndian : EndianType.LittleEndian;
                using (SerializedFileReader reader = new SerializedFileReader(stream, endianess, Header.Generation))
                {
                    if (IsMetadataAtTheEnd(reader.Generation))
                    {
                        reader.BaseStream.Position = Header.FileSize - Header.MetadataSize;
                        reader.BaseStream.Position++;
                    }

                    Metadata.Read(reader);
                }
            }

#warning TEMP HACK
            Flags = Metadata.Hierarchy.Platform == Platform.NoTarget ? TransferInstructionFlags.NoTransferInstructionFlags : Flags;
            if (FilenameUtils.IsEngineResource(Name) || Header.Generation < FileGeneration.FG_500a1 && FilenameUtils.IsBuiltinExtra(Name))
            {
                Flags |= TransferInstructionFlags.IsBuiltinResourcesFile;
            }
            Flags |= Header.SwapEndianess ? TransferInstructionFlags.SwapEndianess : TransferInstructionFlags.NoTransferInstructionFlags;
        }
        public void Read(SerializedFileReader reader)
        {
            if (IsReadSignature(reader.Generation))
            {
                string signature = reader.ReadStringZeroTerm();
                Version.Parse(signature);
            }
            if (IsReadAttributes(reader.Generation))
            {
                Platform = (Platform)reader.ReadUInt32();
                if (!Enum.IsDefined(typeof(Platform), Platform))
                {
                    throw new Exception($"Unsuported platform {Platform} for asset file '{Name}'");
                }
            }
            if (IsReadSerializeTypeTrees(reader.Generation))
            {
                SerializeTypeTrees = reader.ReadBoolean();
            }
            else
            {
                SerializeTypeTrees = true;
            }
            m_types = reader.ReadArray(() => new RTTIBaseClassDescriptor(SerializeTypeTrees));

            if (IsReadUnknown(reader.Generation))
            {
                Unknown = reader.ReadInt32();
            }
        }
Ejemplo n.º 5
0
        public void Read(SerializedFileReader reader)
        {
            ClassID = (ClassIDType)reader.ReadInt32();
            if (IsReadScriptType(reader.Generation))
            {
                IsStrippedType = reader.ReadBoolean();
                ScriptID       = reader.ReadInt16();
            }
            else
            {
                // For old version it specifies ClassIDType or -ScriptID for MonoBehaviour
                int uniqueTypeID = (int)ClassID;
                if (uniqueTypeID < 0)
                {
                    ClassID  = ClassIDType.MonoBehaviour;
                    ScriptID = (short)(-uniqueTypeID - 1);
                }
            }

            if (IsReadHash(reader.Generation))
            {
                if (ClassID == ClassIDType.MonoBehaviour)
                {
                    ScriptHash.Read(reader);
                }
                TypeHash.Read(reader);
            }

            // isSerializeTypeTrees
            if (Tree != null)
            {
                Tree.Read(reader);
            }
        }
        public void Read(SerializedFileReader reader)
        {
            ClassID = (ClassIDType)reader.ReadInt32();
            if (IsReadUnknown(reader.Generation))
            {
                Unknown  = reader.ReadByte();
                ScriptID = reader.ReadInt16();
            }

            if (IsReadHash(reader.Generation))
            {
                if (IsOldHashType(reader.Generation))
                {
                    if ((int)ClassID <= -1)
                    {
                        ScriptHash.Read(reader);
                    }
                }
                else
                {
                    if (ClassID == ClassIDType.MonoBehaviour)
                    {
                        ScriptHash.Read(reader);
                    }
                }
                TypeHash.Read(reader);
            }

            // isSerializeTypeTrees
            if (Tree != null)
            {
                Tree.Read(reader);
            }
        }
Ejemplo n.º 7
0
 public void Read(SerializedFileReader reader)
 {
     Type     = reader.ReadStringZeroTerm();
     Name     = reader.ReadStringZeroTerm();
     ByteSize = reader.ReadInt32();
     Index    = reader.ReadInt32();
     IsArray  = reader.ReadInt32() != 0;
     Version  = reader.ReadInt32();
     MetaFlag = reader.ReadUInt32();
 }
Ejemplo n.º 8
0
 public void Read(SerializedFileReader reader)
 {
     if (IsReadAssetName(reader.Generation))
     {
         AssetPath = reader.ReadStringZeroTerm();
     }
     if (IsReadHash(reader.Generation))
     {
         Hash.Read(reader);
         Type = (AssetType)reader.ReadInt32();
     }
     FilePathOrigin = reader.ReadStringZeroTerm();
     FilePath       = FilenameUtils.FixFileIdentifier(FilePathOrigin);
 }
Ejemplo n.º 9
0
        private static void ReadTreeNode(SerializedFileReader reader, ICollection <TypeTreeNode> nodes, byte depth)
        {
            TypeTreeNode node = new TypeTreeNode(depth);

            node.Read(reader);
            nodes.Add(node);

            int childCount = reader.ReadInt32();

            for (int i = 0; i < childCount; i++)
            {
                ReadTreeNode(reader, nodes, (byte)(depth + 1));
            }
        }
Ejemplo n.º 10
0
        public void Read(SerializedFileReader reader, long stringPosition)
        {
            Version = reader.ReadUInt16();
            Depth   = reader.ReadByte();
            IsArray = reader.ReadBoolean();
            uint type = reader.ReadUInt32();
            uint name = reader.ReadUInt32();

            ByteSize = reader.ReadInt32();
            Index    = reader.ReadInt32();
            MetaFlag = reader.ReadUInt32();

            Type = ReadString(reader, stringPosition, type);
            Name = ReadString(reader, stringPosition, name);
        }
Ejemplo n.º 11
0
        public void Read(SerializedFileReader reader, long stringPosition)
        {
            Version = reader.ReadUInt16();
            Depth   = reader.ReadByte();
            IsArray = reader.ReadBoolean();
            uint type = reader.ReadUInt32();
            uint name = reader.ReadUInt32();

            ByteSize = reader.ReadInt32();
            Index    = reader.ReadInt32();
            MetaFlag = (TransferMetaFlags)reader.ReadUInt32();
            if (IsReadUnknown(reader.Generation))
            {
                Unknown1 = reader.ReadUInt32();
                Unknown2 = reader.ReadUInt32();
            }

            Type = ReadString(reader, stringPosition, type);
            Name = ReadString(reader, stringPosition, name);
        }
        public void Read(SerializedFileReader reader)
        {
            if (IsReadSignature(reader.Generation))
            {
                string signature = reader.ReadStringZeroTerm();
                Version.Parse(signature);

#warning HACK: TEMP:
                if (Version == new Version(5, 6, 4, VersionType.Patch, 1))
                {
                    if (FilenameUtils.IsDefaultResource(Name))
                    {
                        Version = new Version(5, 6, 5, VersionType.Final);
                    }
                }
            }
            if (IsReadAttributes(reader.Generation))
            {
                Platform = (Platform)reader.ReadUInt32();
                if (!Enum.IsDefined(typeof(Platform), Platform))
                {
                    throw new Exception($"Unsuported platform {Platform} for asset file '{Name}'");
                }
            }
            if (IsReadSerializeTypeTrees(reader.Generation))
            {
                SerializeTypeTrees = reader.ReadBoolean();
            }
            else
            {
                SerializeTypeTrees = true;
            }
            Types = reader.ReadSerializedArray(() => new RTTIBaseClassDescriptor(SerializeTypeTrees));

            if (IsReadUnknown(reader.Generation))
            {
                Unknown = reader.ReadInt32();
            }
        }
Ejemplo n.º 13
0
        private static string ReadString(SerializedFileReader reader, long stringPosition, uint value)
        {
            bool isCustomType = (value & 0x80000000) == 0;

            if (isCustomType)
            {
                long position = reader.BaseStream.Position;
                reader.BaseStream.Position = stringPosition + value;
                string stringValue = reader.ReadStringZeroTerm();
                reader.BaseStream.Position = position;
                return(stringValue);
            }
            else
            {
                uint         type     = value & 0x7FFFFFFF;
                TreeNodeType nodeType = (TreeNodeType)type;
                if (!Enum.IsDefined(typeof(TreeNodeType), nodeType))
                {
                    throw new Exception($"Unsupported asset class type name '{nodeType}''");
                }
                return(nodeType.ToTypeString());
            }
        }
Ejemplo n.º 14
0
        public void Read(SerializedFileReader reader)
        {
            Hierarchy.Read(reader);

            int count = reader.ReadInt32();

            m_objects = new Dictionary <long, AssetEntry>(count);
            for (int i = 0; i < count; i++)
            {
                AssetEntry objectInfo = new AssetEntry();
                objectInfo.Read(reader);
                m_objects.Add(objectInfo.PathID, objectInfo);
            }

            if (IsReadPreload(reader.Generation))
            {
                m_preloads = reader.ReadArray <ObjectPtr>();
            }
            m_dependencies = reader.ReadArray <FileIdentifier>();
            if (IsReadUnknown(reader.Generation))
            {
                Unknown = reader.ReadStringZeroTerm();
            }
        }
Ejemplo n.º 15
0
        private void Read(Stream stream, Action <string> dependencyCallback)
        {
            long startPosition = stream.Position;

            using (EndianReader reader = new EndianReader(stream, stream.Position, EndianType.BigEndian))
            {
                Header.Read(reader);
            }

            EndianType endianess = Header.SwapEndianess ? EndianType.BigEndian : EndianType.LittleEndian;

            using (EndianReader reader = new EndianReader(stream, stream.Position, endianess))
            {
                if (IsTableAtTheEnd(Header.Generation))
                {
                    reader.BaseStream.Position = startPosition + Header.FileSize - Header.MetadataSize;
                    reader.BaseStream.Position++;
                }

                using (SerializedFileReader fileReader = new SerializedFileReader(reader, Header.Generation))
                {
                    Metadata.Read(fileReader);
                }

#warning TEMP HACK
                Flags  = Platform == Platform.NoTarget ? TransferInstructionFlags.NoTransferInstructionFlags : Flags;
                Flags |= Header.SwapEndianess ? TransferInstructionFlags.SwapEndianess : TransferInstructionFlags.NoTransferInstructionFlags;

                foreach (FileIdentifier dependency in Dependencies)
                {
                    dependencyCallback?.Invoke(dependency.FilePath);
                }

                if (RTTIClassHierarchyDescriptor.IsReadSignature(Header.Generation))
                {
                    ReadAssets(reader, startPosition);
                }
                else
                {
                    Logger.Log(LogType.Warning, LogCategory.Import, $"Can't determine file version for generation {Header.Generation} for file '{Name}'");
                    string[] versions = GetGenerationVersions(Header.Generation);
                    for (int i = 0; i < versions.Length; i++)
                    {
                        string version = versions[i];
                        Logger.Log(LogType.Debug, LogCategory.Import, $"Try parse {Name} as {version} version");
                        Metadata.Hierarchy.Version.Parse(version);
                        m_assets.Clear();
                        try
                        {
                            ReadAssets(reader, startPosition);
                            break;
                        }
                        catch
                        {
                            Logger.Log(LogType.Debug, LogCategory.Import, "Faild");
                            if (i == versions.Length - 1)
                            {
                                throw;
                            }
                        }
                    }
                }
            }
        }