예제 #1
0
 void UnityElement.Read(UnityBinaryReader reader, int version)
 {
     BufferedPath = reader.ReadString();
     Guid         = new Guid128();
     Guid.Read(reader, version);
     Type      = reader.ReadInt32();
     AssetPath = reader.ReadString();
 }
예제 #2
0
            private void ReadStringTable(UnityBinaryReader reader, int stringTableLength)
            {
                var stringTableBytes = reader.ReadBytes(stringTableLength);

                Strings.Read(stringTableBytes, Encoding.ASCII);

                foreach (Field f in TypeFields)
                {
                    f.ApplyStringTable(Strings);
                }
            }
예제 #3
0
 public Field(UnityBinaryReader reader)
 {
     Version     = reader.ReadInt16();
     Depth       = reader.ReadByte();
     IsArray     = reader.ReadBool();
     _typeOffset = reader.ReadInt32();
     _nameOffset = reader.ReadInt32();
     Size        = reader.ReadInt32();
     Index       = reader.ReadInt32();
     Flags       = reader.ReadInt32();
 }
예제 #4
0
        private static uint GetAssetsFileListLength(UnityBinaryReader reader, int version)
        {
            uint sizeFiles = reader.ReadUInt32();
            uint rax;

            if (version <= 16)
            {
#warning check if this is still needed
                if (true)
                {
                    if (version < 17)
                    {
                        uint rdx3 = 25;
                        if (version >= 16)
                        {
                            rdx3 = 23;
                        }
                        rax = ((rdx3 + 3) & 0xfffffffc) * ((sizeFiles) - 1) + rdx3;
                        return(rax);
                    }
                    else
                    {
                        rax = 20 * ((sizeFiles) - 1) + 20;
                        return(rax);
                    }
                }
            }
            uint blockSize;
            if (version >= 17)
            {
                blockSize = 20;
            }
            else
            {
                if (version >= 16)
                {
                    rax = (sizeFiles) * 23;
                    return(rax);
                }
                if (version >= 15)
                {
                    rax = (sizeFiles) * 25;
                    return(rax);
                }
                blockSize = 24;
                if (version != 14)
                {
                    blockSize = 20;
                }
            }
            return((sizeFiles) * blockSize);
        }
예제 #5
0
        public void Read(UnityBinaryReader reader, int version)
        {
            bool littleEndian = reader.IsLittleEndian;

            reader.IsLittleEndian = false;
            try
            {
                Upper = reader.ReadInt64();
                Lower = reader.ReadInt64();
            }
            finally
            {
                reader.IsLittleEndian = littleEndian;
            }
        }
예제 #6
0
            private void ReadEmbedded(UnityBinaryReader reader, int version, int typeVersion)
            {
                int fieldCount        = reader.ReadInt32();
                int stringTableLength = reader.ReadInt32();

                TypeFields.Capacity = fieldCount;
                TypeFields.Clear();

                for (int i = 0; i < fieldCount; i++)
                {
                    var field = new Field(reader);
                    TypeFields.Add(field);
                }

                ReadStringTable(reader, stringTableLength);
            }
예제 #7
0
        protected void Read(UnityBinaryReader reader, int version)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            int count = reader.ReadInt32();

            Items.Capacity = count;
            Items.Clear();
            for (int i = 0; i < count; i++)
            {
                var item = new Item();
                item.Read(reader, version);
                Items.Add(item);
            }
        }
예제 #8
0
        public AssetsFile LoadFile(string name)
        {
            if (name.StartsWith(LibraryPrefix, StringComparison.OrdinalIgnoreCase))
            {
                name = Path.Combine(LibraryReplacement, name.Substring(LibraryPrefix.Length));
            }

            string path = Path.Combine(_baseDir, name);

            using (FileStream fs = File.OpenRead(path))
            {
                var reader = new UnityBinaryReader(fs);
                var file   = new AssetsFile(this, reader);
                _loadedFiles.Add(name, file);
                return(file);
            }
        }
예제 #9
0
            public Type_0D(UnityBinaryReader reader, int version, int typeVersion, bool embedded)
            {
                if (reader == null)
                {
                    throw new ArgumentNullException(nameof(reader));
                }
                if (version < 13)
                {
                    throw new ArgumentOutOfRangeException(nameof(version), "this type does not support the given format");
                }
                ClassID = reader.ReadInt32();

                if (version < 16)
                {
                    _unknown = 0;
                }
                else
                {
                    _unknown = reader.ReadByte();
                }

                if (version < 17)
                {
                    ScriptIndex = -1;
                }
                else
                {
                    ScriptIndex = reader.ReadInt16();
                }
                if (ClassID < 0 || ClassID == 114)
                {
                    ScriptID = new Hash128();
                    ScriptID.Read(reader, version);
                }
                PropertiesHash = new Hash128();
                PropertiesHash.Read(reader, version);
                if (embedded)
                {
                    ReadEmbedded(reader, version, typeVersion);
                }
            }
예제 #10
0
        private void Read(UnityBinaryReader reader, int version)
        {
            _format     = version;
            HasTypeTree = true;

            if (version <= 6)
            {
                UnityVersion = $"Unsupported Format";
                TypeVersion  = 0;
                return;
            }

            UnityVersion = reader.ReadString();
            TypeVersion  = reader.ReadInt32();
            if (version >= 13)
            {
                HasTypeTree = reader.ReadBool();
            }

            var fieldCount = reader.ReadInt32();

            if (version > 13)
            {
                for (int i = 0; i < fieldCount; i++)
                {
                    Types_0D.Add(new Type_0D(reader, version, TypeVersion, HasTypeTree));
                }
            }
            else
            {
                throw new NotImplementedException();
                for (int i = 0; i < fieldCount; i++)
                {
                    //Types_07.Add(new Type_07(reader, format, Version, HasTypeTree));
                }
            }
            if (version < 14)
            {
                _unknown = reader.ReadInt32();
            }
        }
예제 #11
0
        public AssetsFile(UnityContext context, UnityBinaryReader reader)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            Reader = reader;
            Header = new AssetsFileHeader(this);
            if (Header.Version < 9)
            {
                //Meta comes after object data
                throw new NotImplementedException();
            }
            TypeTree = new TypeTree(this);

            Files = new AssetsFileTable(this);

            PreloadList  = new PreloadList(this);
            Dependencies = new AssetsFileDependencyList(this);
        }
예제 #12
0
 public void Read(UnityBinaryReader reader, int version)
 {
     Bytes = reader.ReadBytes(16);
 }
예제 #13
0
 void UnityElement.Read(UnityBinaryReader reader, int version)
 {
     FileID = reader.ReadInt32();
     PathID = reader.ReadInt64();
 }
예제 #14
0
        public AssetFileInfo(AssetsFile file, UnityBinaryReader reader) : this()
        {
            /* Read basic info */

            if (file.Header.Version < 14)
            {
                Index = reader.ReadUInt32();
            }
            else
            {
                Index = reader.ReadUInt64();
            }

            //v1

            /*
             * DataOffset = reader.ReadUInt32();
             * FileSize = reader.ReadUInt32();
             * FileTypeOrIndex = reader.ReadInt32();
             * InheritedUnityClass = reader.ReadInt16();
             * ScriptIndex = reader.ReadInt16();
             */
            //v2
            DataOffset          = reader.ReadUInt32();
            FileSize            = reader.ReadUInt32();
            FileTypeOrIndex     = reader.ReadInt32();
            InheritedUnityClass = reader.ReadInt16();
            ScriptIndex         = reader.ReadInt16();

            //v3 (first v2)
            Unknown = reader.ReadByte();

            /* Advanced */
            if (file.Header.Version < 16)
            {
                FileType = FileTypeOrIndex;
            }
            else
            {
                if (FileTypeOrIndex < file.TypeTree.Types_0D.Count)
                {
                    var type = file.TypeTree.Types_0D[FileTypeOrIndex];

                    if (type.ScriptIndex == -1)
                    {
                        FileType            = type.ClassID;
                        InheritedUnityClass = type.ClassID;
                        ScriptIndex         = -1;
                    }
                    else
                    {
                        FileType            = -1 - type.ScriptIndex;
                        InheritedUnityClass = type.ClassID;
                        ScriptIndex         = type.ScriptIndex;
                    }
                }
                else
                {
                }
            }
            AbsolutePos = file.Header.DataOffset + DataOffset;

            if (IsKnownUnityType(FileType) || true)
            {
                long pos = reader.Position;
                try
                {
#error fix this, pls
                    reader.Position = AbsolutePos;
                    int length = reader.ReadInt32();
                    if (length > 100 && false)
                    {
                        if (Debugger.IsAttached)
                        {
                            Debugger.Break();
                        }
                    }
                    Name = reader.ReadStringFixed(length);
                }
                finally
                {
                    reader.Position = pos;
                }
            }
        }