예제 #1
0
        public static UnityFile Load(string filename)
        {
            UnityFile uf = new UnityFile(filename);

            DataReader reader = DataReader.OpenFile(filename, false);

            #region Header

            int metadataSize = reader.ReadInt32();
            int fileSize     = reader.ReadInt32();
            uf.FormatVersion = reader.ReadInt32();
            int dataOffset = reader.ReadInt32();

            if (uf.FormatVersion > 8)
            {
                uf.IsLittleEndian = reader.ReadByte() == 0;
                reader.ReadBytes(3);
            }

            reader.IsLittleEndian = uf.IsLittleEndian;

            #endregion

            #region Metadata

            if (uf.FormatVersion < 9)
            {
                reader.JumpTo(fileSize - metadataSize); //Used to be 'F - M + 1'
            }

            uf.__Metadata__ = reader.ReadBytes(metadataSize);

            reader.JumpTo(16 + (uf.FormatVersion > 8 ? 4 : 0));

            if (uf.FormatVersion < 9)
            {
                reader.JumpTo(fileSize - metadataSize); //Used to be 'F - M + 1'
            }

            #region Class Hierarchy Descriptor

            if (uf.FormatVersion > 7)
            {
                uf.UnityVersion   = reader.ReadString();
                uf.RTTIAttributes = reader.ReadInt32();
            }

            int numberOfBaseClasses = reader.ReadInt32();

            for (int i = 0; i < numberOfBaseClasses; i++)
            {
                int      classId   = reader.ReadInt32();
                TypeNode classNode = TypeNode.Read(reader);
                uf.BaseClasses[classId] = classNode;
            }

            if (uf.FormatVersion > 7)
            {
                reader.ReadBytes(4);
            }

            #endregion

            int numberOfObjectDataInstances = reader.ReadInt32();

            List <ObjectInfo> objectDataPointers = new List <ObjectInfo>();
            for (int i = 0; i < numberOfObjectDataInstances; i++)
            {
                objectDataPointers.Add(ObjectInfo.Read(reader, uf.FormatVersion > 13));
            }

            uf.ObjectInfos = objectDataPointers;

            int numberOfExternalFiles = reader.ReadInt32();

            for (int i = 0; i < numberOfExternalFiles; i++)
            {
                uf.ExternalFiles.Add(FileIdentifier.Read(reader, uf.FormatVersion > 5));
            }

            #endregion

            foreach (ObjectInfo oi in objectDataPointers)
            {
                uf.Objects.Add(ObjectData.Read(reader, oi, dataOffset));
            }

            reader.Close();

            return(uf);
        }
예제 #2
0
        public static UnityFile Load(string filename)
        {
            UnityFile uf = new UnityFile(filename);

            DataReader reader = DataReader.OpenFile(filename, false);

            #region Header

            int metadataSize = reader.ReadInt32();
            int fileSize = reader.ReadInt32();
            uf.FormatVersion = reader.ReadInt32();
            int dataOffset = reader.ReadInt32();

            if (uf.FormatVersion > 8) {
                uf.IsLittleEndian = reader.ReadByte() == 0;
                reader.ReadBytes(3);
            }

            reader.IsLittleEndian = uf.IsLittleEndian;

            #endregion

            #region Metadata

            if (uf.FormatVersion < 9) {
                reader.JumpTo(fileSize - metadataSize); //Used to be 'F - M + 1'
            }

            uf.__Metadata__ = reader.ReadBytes(metadataSize);

            reader.JumpTo(16 + (uf.FormatVersion > 8 ? 4 : 0));

            if (uf.FormatVersion < 9) {
                reader.JumpTo(fileSize - metadataSize); //Used to be 'F - M + 1'
            }

            #region Class Hierarchy Descriptor

            if (uf.FormatVersion > 7) {
                uf.UnityVersion = reader.ReadString();
                uf.RTTIAttributes = reader.ReadInt32();
            }

            int numberOfBaseClasses = reader.ReadInt32();

            for (int i = 0; i < numberOfBaseClasses; i++) {
                int classId = reader.ReadInt32();
                TypeNode classNode = TypeNode.Read(reader);
                uf.BaseClasses[classId] = classNode;
            }

            if (uf.FormatVersion > 7) {
                reader.ReadBytes(4);
            }

            #endregion

            int numberOfObjectDataInstances = reader.ReadInt32();

            List<ObjectInfo> objectDataPointers = new List<ObjectInfo>();
            for (int i = 0; i < numberOfObjectDataInstances; i++) {
                objectDataPointers.Add(ObjectInfo.Read(reader, uf.FormatVersion > 13));
            }

            uf.ObjectInfos = objectDataPointers;

            int numberOfExternalFiles = reader.ReadInt32();

            for (int i = 0; i < numberOfExternalFiles; i++) {
                uf.ExternalFiles.Add(FileIdentifier.Read(reader, uf.FormatVersion > 5));
            }

            #endregion

            foreach (ObjectInfo oi in objectDataPointers) {
                uf.Objects.Add(ObjectData.Read(reader, oi, dataOffset));
            }

            reader.Close();

            return uf;
        }