示例#1
0
        public SpriteAtlas(ObjectReader reader) : base(reader)
        {
            var m_PackedSpritesSize = reader.ReadInt32();

            m_PackedSprites = new PPtr <Sprite> [m_PackedSpritesSize];
            for (int i = 0; i < m_PackedSpritesSize; i++)
            {
                m_PackedSprites[i] = new PPtr <Sprite>(reader);
            }

            var m_PackedSpriteNamesToIndex = reader.ReadStringArray();

            var m_RenderDataMapSize = reader.ReadInt32();

            m_RenderDataMap = new Dictionary <KeyValuePair <Guid, long>, SpriteAtlasData>(m_RenderDataMapSize);
            for (int i = 0; i < m_RenderDataMapSize; i++)
            {
                var first  = new Guid(reader.ReadBytes(16));
                var second = reader.ReadInt64();
                var value  = new SpriteAtlasData(reader);
                m_RenderDataMap.Add(new KeyValuePair <Guid, long>(first, second), value);
            }
            var m_Tag = reader.ReadAlignedString();

            m_IsVariant = reader.ReadBoolean();
            reader.AlignStream();
        }
示例#2
0
        public AudioClip(ObjectReader reader) : base(reader)
        {
            if (version[0] < 5)
            {
                m_Format      = reader.ReadInt32();
                m_Type        = (AudioType)reader.ReadInt32();
                m_3D          = reader.ReadBoolean();
                m_UseHardware = reader.ReadBoolean();
                reader.AlignStream();

                if (version[0] >= 4 || (version[0] == 3 && version[1] >= 2)) //3.2.0 to 5
                {
                    var m_Stream = reader.ReadInt32();
                    m_Size = reader.ReadInt32();
                    var tsize = m_Size % 4 != 0 ? m_Size + 4 - m_Size % 4 : m_Size;
                    if (reader.byteSize + reader.byteStart - reader.Position != tsize)
                    {
                        m_Offset = reader.ReadUInt32();
                        m_Source = assetsFile.fullName + ".resS";
                    }
                }
                else
                {
                    m_Size = reader.ReadInt32();
                }
            }
            else
            {
                m_LoadType        = reader.ReadInt32();
                m_Channels        = reader.ReadInt32();
                m_Frequency       = reader.ReadInt32();
                m_BitsPerSample   = reader.ReadInt32();
                m_Length          = reader.ReadSingle();
                m_IsTrackerFormat = reader.ReadBoolean();
                reader.AlignStream();
                m_SubsoundIndex    = reader.ReadInt32();
                m_PreloadAudioData = reader.ReadBoolean();
                m_LoadInBackground = reader.ReadBoolean();
                m_Legacy3D         = reader.ReadBoolean();
                reader.AlignStream();

                //StreamedResource m_Resource
                m_Source            = reader.ReadAlignedString();
                m_Offset            = reader.ReadUInt64();
                m_Size              = reader.ReadInt64();
                m_CompressionFormat = (AudioCompressionFormat)reader.ReadInt32();
            }

            ResourceReader resourceReader;

            if (!string.IsNullOrEmpty(m_Source))
            {
                resourceReader = new ResourceReader(m_Source, assetsFile, m_Offset, (int)m_Size);
            }
            else
            {
                resourceReader = new ResourceReader(reader, reader.BaseStream.Position, (int)m_Size);
            }
            m_AudioData = resourceReader;
        }
示例#3
0
        public SpriteAtlas(ObjectReader reader) : base(reader)
        {
            var m_PackedSpritesSize = reader.ReadInt32();

            for (int i = 0; i < m_PackedSpritesSize; i++)
            {
                reader.ReadPPtr(); //PPtr<Sprite> data
            }

            var m_PackedSpriteNamesToIndexSize = reader.ReadInt32();

            for (int i = 0; i < m_PackedSpriteNamesToIndexSize; i++)
            {
                reader.ReadAlignedString();
            }

            var m_RenderDataMapSize = reader.ReadInt32();

            m_RenderDataMap = new Dictionary <Tuple <Guid, long>, SpriteAtlasData>(m_RenderDataMapSize);
            for (int i = 0; i < m_RenderDataMapSize; i++)
            {
                var first  = new Guid(reader.ReadBytes(16));
                var second = reader.ReadInt64();
                var value  = new SpriteAtlasData(reader);
                m_RenderDataMap.Add(new Tuple <Guid, long>(first, second), value);
            }
            //string m_Tag
            //bool m_IsVariant
        }
示例#4
0
        public SkinnedMeshRenderer(ObjectReader reader) : base(reader, true)
        {
            int m_Quality             = reader.ReadInt32();
            var m_UpdateWhenOffscreen = reader.ReadBoolean();
            var m_SkinNormals         = reader.ReadBoolean(); //3.1.0 and below

            reader.AlignStream();

            if (version[0] == 2 && version[1] < 6) //2.6 down
            {
                var m_DisableAnimationWhenOffscreen = new PPtr <Animation>(reader);
            }

            // ???
            var unk1 = reader.ReadInt64();

            m_Mesh = new PPtr <Mesh>(reader);

            m_Bones = new PPtr <Transform> [reader.ReadInt32()];
            for (int b = 0; b < m_Bones.Length; b++)
            {
                m_Bones[b] = new PPtr <Transform>(reader);
            }

            if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up
            {
                m_BlendShapeWeights = reader.ReadSingleArray();
            }
        }
示例#5
0
        public Sprite(ObjectReader reader) : base(reader)
        {
            m_Rect   = reader.ReadRectangleF();
            m_Offset = reader.ReadVector2();
            if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up
            {
                m_Border = reader.ReadVector4();
            }

            m_PixelsToUnits = reader.ReadSingle();
            if (version[0] > 5 ||
                (version[0] == 5 && version[1] > 4) ||
                (version[0] == 5 && version[1] == 4 && version[2] >= 2))    //5.4.2 and up
            {
                m_Pivot = reader.ReadVector2();
            }

            m_Extrude = reader.ReadUInt32();
            if (version[0] > 5 || (version[0] == 5 && version[1] >= 3)) //5.3 and up
            {
                m_IsPolygon = reader.ReadBoolean();
                reader.AlignStream(4);
            }

            if (version[0] >= 2017) //2017 and up
            {
                var first  = new Guid(reader.ReadBytes(16));
                var second = reader.ReadInt64();
                m_RenderDataKey = new KeyValuePair <Guid, long>(first, second);

                var m_AtlasTagsSize = reader.ReadInt32();
                m_AtlasTags = new string[m_AtlasTagsSize];
                for (int i = 0; i < m_AtlasTagsSize; i++)
                {
                    m_AtlasTags[i] = reader.ReadAlignedString();
                }

                m_SpriteAtlas = new PPtr <SpriteAtlas>(reader);
            }

            m_RD = new SpriteRenderData(reader);

            if (version[0] >= 2017) //2017 and up
            {
                var m_PhysicsShapeSize = reader.ReadInt32();
                m_PhysicsShape = new Vector2[m_PhysicsShapeSize][];
                for (int i = 0; i < m_PhysicsShapeSize; i++)
                {
                    m_PhysicsShape[i] = reader.ReadVector2Array(reader.ReadInt32());
                }
            }

            //vector m_Bones 2018 and up
        }
示例#6
0
        public StreamingInfo(ObjectReader reader)
        {
            var version = reader.version;

            if (version[0] >= 2020) //2020.1 and up
            {
                offset = reader.ReadInt64();
            }
            else
            {
                offset = reader.ReadUInt32();
            }
            size = reader.ReadUInt32();
            path = reader.ReadAlignedString();
        }
示例#7
0
        private int index = -2; //-2 - Prepare, -1 - Missing

        public PPtr(ObjectReader reader)
        {
            m_FileID   = reader.ReadInt32();
            m_PathID   = reader.m_Version < 14 ? reader.ReadInt32() : reader.ReadInt64();
            assetsFile = reader.assetsFile;
        }
示例#8
0
        private int index = -2; //-2 - Prepare, -1 - Missing

        public PPtr(ObjectReader reader)
        {
            m_FileID   = reader.ReadInt32();
            m_PathID   = reader.m_Version < SerializedFileFormatVersion.Unknown_14 ? reader.ReadInt32() : reader.ReadInt64();
            assetsFile = reader.assetsFile;
        }
示例#9
0
        private static void DumpType(TypeSig typeSig, StringBuilder sb, ObjectReader reader, string name, int indent, bool isRoot = false)
        {
            var typeDef = typeSig.ToTypeDefOrRef().ResolveTypeDefThrow();

            if (typeSig.IsPrimitive)
            {
                object value = null;
                switch (typeSig.TypeName)
                {
                case "Boolean":
                    value = reader.ReadBoolean();
                    break;

                case "Byte":
                    value = reader.ReadByte();
                    break;

                case "SByte":
                    value = reader.ReadSByte();
                    break;

                case "Int16":
                    value = reader.ReadInt16();
                    break;

                case "UInt16":
                    value = reader.ReadUInt16();
                    break;

                case "Int32":
                    value = reader.ReadInt32();
                    break;

                case "UInt32":
                    value = reader.ReadUInt32();
                    break;

                case "Int64":
                    value = reader.ReadInt64();
                    break;

                case "UInt64":
                    value = reader.ReadUInt64();
                    break;

                case "Single":
                    value = reader.ReadSingle();
                    break;

                case "Double":
                    value = reader.ReadDouble();
                    break;

                case "Char":
                    value = reader.ReadChar();
                    break;
                }
                reader.AlignStream(4);
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name} = {value}");
                return;
            }
            if (typeSig.FullName == "System.String")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name} = \"{reader.ReadAlignedString()}\"");
                return;
            }
            if (typeSig.FullName == "System.Object")
            {
                return;
            }
            if (typeDef.IsDelegate)
            {
                return;
            }
            if (typeSig is ArraySigBase)
            {
                if (!typeDef.IsEnum && !IsBaseType(typeDef) && !IsAssignFromUnityObject(typeDef) && !IsEngineType(typeDef) && !typeDef.IsSerializable)
                {
                    return;
                }
                var size = reader.ReadInt32();
                sb.AppendLine($"{new string('\t', indent)}{typeSig.TypeName} {name}");
                sb.AppendLine($"{new string('\t', indent + 1)}Array Array");
                sb.AppendLine($"{new string('\t', indent + 1)}int size = {size}");
                for (int i = 0; i < size; i++)
                {
                    sb.AppendLine($"{new string('\t', indent + 2)}[{i}]");
                    DumpType(typeDef.ToTypeSig(), sb, reader, "data", indent + 2);
                }
                return;
            }
            if (!isRoot && typeSig is GenericInstSig genericInstSig)
            {
                if (genericInstSig.GenericArguments.Count == 1)
                {
                    var type = genericInstSig.GenericArguments[0].ToTypeDefOrRef().ResolveTypeDefThrow();
                    if (!type.IsEnum && !IsBaseType(type) && !IsAssignFromUnityObject(type) && !IsEngineType(type) && !type.IsSerializable)
                    {
                        return;
                    }
                    var size = reader.ReadInt32();
                    sb.AppendLine($"{new string('\t', indent)}{typeSig.TypeName} {name}");
                    sb.AppendLine($"{new string('\t', indent + 1)}Array Array");
                    sb.AppendLine($"{new string('\t', indent + 1)}int size = {size}");
                    for (int i = 0; i < size; i++)
                    {
                        sb.AppendLine($"{new string('\t', indent + 2)}[{i}]");
                        DumpType(genericInstSig.GenericArguments[0], sb, reader, "data", indent + 2);
                    }
                }
                return;
            }
            if (indent != -1 && IsAssignFromUnityObject(typeDef))
            {
                var pptr = reader.ReadPPtr();
                sb.AppendLine($"{new string('\t', indent)}PPtr<{typeDef.Name}> {name} = {{fileID: {pptr.m_FileID}, pathID: {pptr.m_PathID}}}");
                return;
            }
            if (typeDef.IsEnum)
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name} = {reader.ReadUInt32()}");
                return;
            }
            if (indent != -1 && !IsEngineType(typeDef) && !typeDef.IsSerializable)
            {
                return;
            }
            if (typeDef.FullName == "UnityEngine.Rect")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                var rect = reader.ReadSingleArray(4);
                return;
            }
            if (typeDef.FullName == "UnityEngine.LayerMask")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                var value = reader.ReadInt32();
                return;
            }
            if (typeDef.FullName == "UnityEngine.AnimationCurve")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                var animationCurve = new AnimationCurve <float>(reader, reader.ReadSingle);
                return;
            }
            if (typeDef.FullName == "UnityEngine.Gradient")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                if (reader.version[0] == 5 && reader.version[1] < 5)
                {
                    reader.Position += 68;
                }
                else if (reader.version[0] == 5 && reader.version[1] < 6)
                {
                    reader.Position += 72;
                }
                else
                {
                    reader.Position += 168;
                }
                return;
            }
            if (typeDef.FullName == "UnityEngine.RectOffset")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                var left   = reader.ReadSingle();
                var right  = reader.ReadSingle();
                var top    = reader.ReadSingle();
                var bottom = reader.ReadSingle();
                return;
            }
            if (typeDef.FullName == "UnityEngine.GUIStyle") //TODO
            {
                throw new NotSupportedException();
            }
            if (typeDef.IsClass || typeDef.IsValueType)
            {
                if (name != null && indent != -1)
                {
                    sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                }
                if (indent == -1 && typeDef.BaseType.FullName != "UnityEngine.Object")
                {
                    DumpType(typeDef.BaseType.ToTypeSig(), sb, reader, null, indent, true);
                }
                if (indent != -1 && typeDef.BaseType.FullName != "System.Object")
                {
                    DumpType(typeDef.BaseType.ToTypeSig(), sb, reader, null, indent, true);
                }
                foreach (var fieldDef in typeDef.Fields)
                {
                    var access = fieldDef.Access & FieldAttributes.FieldAccessMask;
                    if (access != FieldAttributes.Public)
                    {
                        if (fieldDef.CustomAttributes.Any(x => x.TypeFullName.Contains("SerializeField")))
                        {
                            DumpType(fieldDef.FieldType, sb, reader, fieldDef.Name, indent + 1);
                        }
                    }
                    else if ((fieldDef.Attributes & FieldAttributes.Static) == 0 && (fieldDef.Attributes & FieldAttributes.InitOnly) == 0 && (fieldDef.Attributes & FieldAttributes.NotSerialized) == 0)
                    {
                        DumpType(fieldDef.FieldType, sb, reader, fieldDef.Name, indent + 1);
                    }
                }
            }
        }
示例#10
0
        public AudioClip(ObjectReader reader, bool readData) : base(reader)
        {
            if (version[0] < 5)
            {
                m_Format      = reader.ReadInt32();
                m_Type        = (AudioType)reader.ReadInt32();
                m_3D          = reader.ReadBoolean();
                m_UseHardware = reader.ReadBoolean();
                reader.AlignStream(4);

                if (version[0] >= 4 || (version[0] == 3 && version[1] >= 2)) //3.2.0 to 5
                {
                    int m_Stream = reader.ReadInt32();
                    m_Size = reader.ReadInt32();
                    var tsize = m_Size % 4 != 0 ? m_Size + 4 - m_Size % 4 : m_Size;
                    if (reader.byteSize + reader.byteStart - reader.Position != tsize)
                    {
                        m_Offset = reader.ReadInt32();
                        m_Source = sourceFile.filePath + ".resS";
                    }
                }
                else
                {
                    m_Size = reader.ReadInt32();
                }
            }
            else
            {
                m_LoadType        = reader.ReadInt32();
                m_Channels        = reader.ReadInt32();
                m_Frequency       = reader.ReadInt32();
                m_BitsPerSample   = reader.ReadInt32();
                m_Length          = reader.ReadSingle();
                m_IsTrackerFormat = reader.ReadBoolean();
                reader.AlignStream(4);
                m_SubsoundIndex    = reader.ReadInt32();
                m_PreloadAudioData = reader.ReadBoolean();
                m_LoadInBackground = reader.ReadBoolean();
                m_Legacy3D         = reader.ReadBoolean();
                reader.AlignStream(4);
                m_3D = m_Legacy3D;

                m_Source            = reader.ReadAlignedString();
                m_Offset            = reader.ReadInt64();
                m_Size              = reader.ReadInt64();
                m_CompressionFormat = (AudioCompressionFormat)reader.ReadInt32();
            }

            if (readData)
            {
                if (!string.IsNullOrEmpty(m_Source))
                {
                    m_AudioData = ResourcesHelper.GetData(m_Source, sourceFile.filePath, m_Offset, (int)m_Size);
                }
                else
                {
                    if (m_Size > 0)
                    {
                        m_AudioData = reader.ReadBytes((int)m_Size);
                    }
                }
            }
        }
示例#11
0
        public SerializedSubProgram(ObjectReader reader)
        {
            var version = reader.version;

            m_BlobIndex = reader.ReadUInt32();
            m_Channels  = new ParserBindChannels(reader);

            if ((version[0] >= 2019 && version[0] < 2021) || (version[0] == 2021 && version[1] < 2)) //2019 ~2021.1
            {
                var m_GlobalKeywordIndices = reader.ReadUInt16Array();
                reader.AlignStream();
                var m_LocalKeywordIndices = reader.ReadUInt16Array();
                reader.AlignStream();
            }
            else
            {
                m_KeywordIndices = reader.ReadUInt16Array();
                if (version[0] >= 2017) //2017 and up
                {
                    reader.AlignStream();
                }
            }

            m_ShaderHardwareTier = reader.ReadSByte();
            m_GpuProgramType     = (ShaderGpuProgramType)reader.ReadSByte();
            reader.AlignStream();

            if ((version[0] == 2020 && version[1] > 3) ||
                (version[0] == 2020 && version[1] == 3 && version[2] >= 2) || //2020.3.2f1 and up
                (version[0] == 2021 && version[1] > 1) ||
                (version[0] == 2021 && version[1] == 1 && version[2] >= 4))   //2021.1.4f1 and up
            {
                m_Parameters = new SerializedProgramParameters(reader);
            }
            else
            {
                int numVectorParams = reader.ReadInt32();
                m_VectorParams = new VectorParameter[numVectorParams];
                for (int i = 0; i < numVectorParams; i++)
                {
                    m_VectorParams[i] = new VectorParameter(reader);
                }

                int numMatrixParams = reader.ReadInt32();
                m_MatrixParams = new MatrixParameter[numMatrixParams];
                for (int i = 0; i < numMatrixParams; i++)
                {
                    m_MatrixParams[i] = new MatrixParameter(reader);
                }

                int numTextureParams = reader.ReadInt32();
                m_TextureParams = new TextureParameter[numTextureParams];
                for (int i = 0; i < numTextureParams; i++)
                {
                    m_TextureParams[i] = new TextureParameter(reader);
                }

                int numBufferParams = reader.ReadInt32();
                m_BufferParams = new BufferBinding[numBufferParams];
                for (int i = 0; i < numBufferParams; i++)
                {
                    m_BufferParams[i] = new BufferBinding(reader);
                }

                int numConstantBuffers = reader.ReadInt32();
                m_ConstantBuffers = new ConstantBuffer[numConstantBuffers];
                for (int i = 0; i < numConstantBuffers; i++)
                {
                    m_ConstantBuffers[i] = new ConstantBuffer(reader);
                }

                int numConstantBufferBindings = reader.ReadInt32();
                m_ConstantBufferBindings = new BufferBinding[numConstantBufferBindings];
                for (int i = 0; i < numConstantBufferBindings; i++)
                {
                    m_ConstantBufferBindings[i] = new BufferBinding(reader);
                }

                int numUAVParams = reader.ReadInt32();
                m_UAVParams = new UAVParameter[numUAVParams];
                for (int i = 0; i < numUAVParams; i++)
                {
                    m_UAVParams[i] = new UAVParameter(reader);
                }

                if (version[0] >= 2017) //2017 and up
                {
                    int numSamplers = reader.ReadInt32();
                    m_Samplers = new SamplerParameter[numSamplers];
                    for (int i = 0; i < numSamplers; i++)
                    {
                        m_Samplers[i] = new SamplerParameter(reader);
                    }
                }
            }

            if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 2)) //2017.2 and up
            {
                if (version[0] >= 2021)                                       //2021.1 and up
                {
                    var m_ShaderRequirements = reader.ReadInt64();
                }
                else
                {
                    var m_ShaderRequirements = reader.ReadInt32();
                }
            }
        }
示例#12
0
        private static void DumpType(TypeSig typeSig, StringBuilder sb, ObjectReader reader, string name, int indent, bool isRoot = false, bool align = true)
        {
            var typeDef = typeSig.ToTypeDefOrRef().ResolveTypeDefThrow();

            if (typeSig.IsPrimitive)
            {
                object value = null;
                switch (typeSig.TypeName)
                {
                case "Boolean":
                    value = reader.ReadBoolean();
                    break;

                case "Byte":
                    value = reader.ReadByte();
                    break;

                case "SByte":
                    value = reader.ReadSByte();
                    break;

                case "Int16":
                    value = reader.ReadInt16();
                    break;

                case "UInt16":
                    value = reader.ReadUInt16();
                    break;

                case "Int32":
                    value = reader.ReadInt32();
                    break;

                case "UInt32":
                    value = reader.ReadUInt32();
                    break;

                case "Int64":
                    value = reader.ReadInt64();
                    break;

                case "UInt64":
                    value = reader.ReadUInt64();
                    break;

                case "Single":
                    value = reader.ReadSingle();
                    break;

                case "Double":
                    value = reader.ReadDouble();
                    break;

                case "Char":
                    value = reader.ReadChar();
                    break;
                }
                if (align)
                {
                    reader.AlignStream();
                }
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name} = {value}");
                return;
            }
            if (typeSig.FullName == "System.String")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name} = \"{reader.ReadAlignedString()}\"");
                return;
            }
            if (typeSig.FullName == "System.Object")
            {
                return;
            }
            if (typeDef.IsDelegate)
            {
                return;
            }
            if (typeSig is ArraySigBase)
            {
                if (!typeDef.IsEnum && !IsBaseType(typeDef) && !IsAssignFromUnityObject(typeDef) && !IsEngineType(typeDef) && !typeDef.IsSerializable)
                {
                    return;
                }
                var size = reader.ReadInt32();
                sb.AppendLine($"{new string('\t', indent)}{typeSig.TypeName} {name}");
                sb.AppendLine($"{new string('\t', indent + 1)}int size = {size}");
                for (int i = 0; i < size; i++)
                {
                    sb.AppendLine($"{new string('\t', indent + 2)}[{i}]");
                    DumpType(typeDef.ToTypeSig(), sb, reader, "data", indent + 2);
                }
                return;
            }
            if (!isRoot && typeSig is GenericInstSig genericInstSig)
            {
                if (genericInstSig.GenericArguments.Count == 1)
                {
                    var genericType = genericInstSig.GenericType.ToTypeDefOrRef().ResolveTypeDefThrow();
                    var type        = genericInstSig.GenericArguments[0].ToTypeDefOrRef().ResolveTypeDefThrow();
                    if (genericInstSig.GenericArguments[0] is ArraySigBase)
                    {
                        return;
                    }
                    if (!type.IsEnum && !IsBaseType(type) && !IsAssignFromUnityObject(type) && !IsEngineType(type) && !type.IsSerializable)
                    {
                        return;
                    }
                    sb.AppendLine($"{new string('\t', indent)}{typeSig.TypeName} {name}");
                    if (genericType.Interfaces.Any(x => x.Interface.FullName == "System.Collections.Generic.ICollection`1<T>")) //System.Collections.Generic.IEnumerable`1<T>
                    {
                        var size = reader.ReadInt32();
                        sb.AppendLine($"{new string('\t', indent + 1)}int size = {size}");
                        for (int i = 0; i < size; i++)
                        {
                            sb.AppendLine($"{new string('\t', indent + 2)}[{i}]");
                            DumpType(genericInstSig.GenericArguments[0], sb, reader, "data", indent + 2, false, false);
                        }
                        reader.AlignStream();
                    }
                    else
                    {
                        DumpType(genericType.ToTypeSig(), sb, reader, "data", indent + 1);
                    }
                }
                return;
            }
            if (indent != -1 && IsAssignFromUnityObject(typeDef))
            {
                var pptr = new PPtr <Object>(reader);
                sb.AppendLine($"{new string('\t', indent)}PPtr<{typeDef.Name}> {name} = {{fileID: {pptr.m_FileID}, pathID: {pptr.m_PathID}}}");
                return;
            }
            if (typeDef.IsEnum)
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name} = {reader.ReadUInt32()}");
                return;
            }
            if (!isRoot && !IsEngineType(typeDef) && !typeDef.IsSerializable)
            {
                return;
            }
            if (typeDef.FullName == "UnityEngine.Rect")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                var prefix = new string('\t', indent + 1);
                sb.AppendLine($"{prefix}float x = {reader.ReadSingle()}");
                sb.AppendLine($"{prefix}float y = {reader.ReadSingle()}");
                sb.AppendLine($"{prefix}float width = {reader.ReadSingle()}");
                sb.AppendLine($"{prefix}float height = {reader.ReadSingle()}");
                return;
            }
            if (typeDef.FullName == "UnityEngine.LayerMask")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                sb.AppendLine($"{new string('\t', indent + 1)}uint m_Bits = {reader.ReadUInt32()}");
                return;
            }
            if (typeDef.FullName == "UnityEngine.AnimationCurve")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                sb.AppendLine($"{new string('\t', indent + 1)}<truncated>");
                var animationCurve = new AnimationCurve <float>(reader, reader.ReadSingle);
                return;
            }
            if (typeDef.FullName == "UnityEngine.Gradient")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                sb.AppendLine($"{new string('\t', indent + 1)}<truncated>");
                if (reader.version[0] == 5 && reader.version[1] < 5)
                {
                    reader.Position += 68;
                }
                else if (reader.version[0] == 5 && reader.version[1] < 6)
                {
                    reader.Position += 72;
                }
                else
                {
                    reader.Position += 168;
                }
                return;
            }
            if (typeDef.FullName == "UnityEngine.RectOffset")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                var prefix = new string('\t', indent + 1);
                sb.AppendLine($"{prefix}float left = {reader.ReadSingle()}");
                sb.AppendLine($"{prefix}float right = {reader.ReadSingle()}");
                sb.AppendLine($"{prefix}float top = {reader.ReadSingle()}");
                sb.AppendLine($"{prefix}float bottom = {reader.ReadSingle()}");
                return;
            }
            if (typeDef.FullName == "UnityEngine.PropertyName")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                sb.AppendLine($"{new string('\t', indent + 1)}int id = {reader.ReadInt32()}");
                return;
            }
            if (typeDef.FullName == "UnityEngine.Color32")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                var prefix = new string('\t', indent + 1);
                sb.AppendLine($"{prefix}byte r = {reader.ReadByte()}");
                sb.AppendLine($"{prefix}byte g = {reader.ReadByte()}");
                sb.AppendLine($"{prefix}byte b = {reader.ReadByte()}");
                sb.AppendLine($"{prefix}byte a = {reader.ReadByte()}");
                reader.AlignStream();
                return;
            }
            if (typeDef.FullName == "UnityEngine.Vector2Int")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                var prefix = new string('\t', indent + 1);
                sb.AppendLine($"{prefix}int x = {reader.ReadInt32()}");
                sb.AppendLine($"{prefix}int y = {reader.ReadInt32()}");
                return;
            }
            if (typeDef.FullName == "UnityEngine.Vector3Int")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                var prefix = new string('\t', indent + 1);
                sb.AppendLine($"{prefix}int x = {reader.ReadInt32()}");
                sb.AppendLine($"{prefix}int y = {reader.ReadInt32()}");
                sb.AppendLine($"{prefix}int z = {reader.ReadInt32()}");
                return;
            }
            if (typeDef.FullName == "UnityEngine.Bounds")
            {
                sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                sb.AppendLine($"{new string('\t', indent + 1)}<truncated>");
                new AABB(reader);
                return;
            }
            if (typeDef.FullName == "UnityEngine.GUIStyle") //TODO
            {
                throw new NotSupportedException();
            }
            if (typeDef.IsClass || typeDef.IsValueType)
            {
                if (name != null && indent != -1)
                {
                    sb.AppendLine($"{new string('\t', indent)}{typeDef.Name} {name}");
                }
                if (indent == -1 && typeDef.BaseType.FullName != "UnityEngine.Object")
                {
                    DumpType(typeDef.BaseType.ToTypeSig(), sb, reader, null, indent, true);
                }
                if (indent != -1 && typeDef.BaseType.FullName != "System.Object")
                {
                    DumpType(typeDef.BaseType.ToTypeSig(), sb, reader, null, indent, true);
                }
                foreach (var fieldDef in typeDef.Fields)
                {
                    var flag   = false;
                    var access = fieldDef.Access & FieldAttributes.FieldAccessMask;
                    if (access != FieldAttributes.Public)
                    {
                        if (fieldDef.CustomAttributes.Any(x => x.TypeFullName == "UnityEngine.SerializeField"))
                        {
                            flag = true;
                        }
                    }
                    else if ((fieldDef.Attributes & FieldAttributes.Static) == 0 && (fieldDef.Attributes & FieldAttributes.InitOnly) == 0 && (fieldDef.Attributes & FieldAttributes.NotSerialized) == 0)
                    {
                        flag = true;
                    }

                    if (flag)
                    {
                        if (fieldDef.FieldType.IsGenericParameter)
                        {
                            for (var i = 0; i < typeDef.GenericParameters.Count; i++)
                            {
                                var g = typeDef.GenericParameters[i];
                                if (g.FullName == fieldDef.FieldType.FullName)
                                {
                                    var type = ((GenericInstSig)typeSig).GenericArguments[i];
                                    DumpType(type, sb, reader, fieldDef.Name, indent + 1);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            DumpType(fieldDef.FieldType, sb, reader, fieldDef.Name, indent + 1);
                        }
                    }
                }
            }
        }
示例#13
0
        public PointF[][] m_PhysicsShape; //Vector2[][]

        public Sprite(ObjectReader reader) : base(reader)
        {
            //Rectf m_Rect
            m_Rect = reader.ReadRectangleF();
            //Vector2f m_Offset
            reader.Position += 8;
            if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up
            {
                //Vector4f m_Border
                reader.Position += 16;
            }

            m_PixelsToUnits = reader.ReadSingle();
            if (version[0] > 5 ||
                (version[0] == 5 && version[1] > 4) ||
                (version[0] == 5 && version[1] == 4 && version[2] >= 2))    //5.4.2 and up
            {
                //Vector2f m_Pivot
                m_Pivot = reader.ReadVector2();
            }

            var m_Extrude = reader.ReadUInt32();

            if (version[0] > 5 || (version[0] == 5 && version[1] >= 3)) //5.3 and up
            {
                var m_IsPolygon = reader.ReadBoolean();
                reader.AlignStream(4);
            }

            if (version[0] >= 2017) //2017 and up
            {
                //pair m_RenderDataKey
                var first  = new Guid(reader.ReadBytes(16));
                var second = reader.ReadInt64();
                m_RenderDataKey = new Tuple <Guid, long>(first, second);
                //vector m_AtlasTags
                var size = reader.ReadInt32();
                for (int i = 0; i < size; i++)
                {
                    var data = reader.ReadAlignedString();
                }

                //PPtr<SpriteAtlas> m_SpriteAtlas
                m_SpriteAtlas = reader.ReadPPtr();
            }

            //SpriteRenderData m_RD
            //  PPtr<Texture2D> texture
            texture = reader.ReadPPtr();
            //  PPtr<Texture2D> alphaTexture
            if (version[0] > 5 || (version[0] == 5 && version[1] >= 2)) //5.2 and up
            {
                var alphaTexture = reader.ReadPPtr();
            }

            if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up
            {
                //  vector m_SubMeshes
                var size = reader.ReadInt32();
                //      SubMesh data
                if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 3)) //2017.3 and up
                {
                    reader.Position += 48 * size;
                }
                else
                {
                    reader.Position += 44 * size;
                }

                //  vector m_IndexBuffer
                size             = reader.ReadInt32();
                reader.Position += size; //UInt8 data
                reader.AlignStream(4);
                //  VertexData m_VertexData
                if (version[0] < 2018)//2018 down
                {
                    var m_CurrentChannels = reader.ReadInt32();
                }
                var m_VertexCount = reader.ReadUInt32();
                //      vector m_Channels
                size             = reader.ReadInt32();
                reader.Position += size * 4; //ChannelInfo data
                                             //      TypelessData m_DataSize
                size             = reader.ReadInt32();
                reader.Position += size;     //UInt8 data
                reader.AlignStream(4);

                if (version[0] >= 2018)//2018 and up
                {
                    //	vector m_Bindpose
                    //			Matrix4x4f data
                    size             = reader.ReadInt32();
                    reader.Position += size * 64;
                    if (version[0] == 2018 && version[1] < 2) //2018.2 down
                    {
                        //	vector m_SourceSkin
                        //			BoneWeights4 data
                        size             = reader.ReadInt32();
                        reader.Position += size * 32;
                    }
                }
            }
            else
            {
                //  vector vertices
                var size = reader.ReadInt32();
                for (int i = 0; i < size; i++)
                {
                    //SpriteVertex data
                    reader.Position += 12;                                      //Vector3f pos
                    if (version[0] < 4 || (version[0] == 4 && version[1] <= 3)) //4.3 and down
                    {
                        reader.Position += 8;                                   //Vector2f uv
                    }
                }

                //  vector indices
                size             = reader.ReadInt32();
                reader.Position += 2 * size; //UInt16 data
                reader.AlignStream(4);
            }

            //  Rectf textureRect
            textureRect = reader.ReadRectangleF();
            //  Vector2f textureRectOffset
            reader.Position += 8;
            //  Vector2f atlasRectOffset - 5.6 and up
            if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up
            {
                reader.Position += 8;
            }
            //  unsigned int settingsRaw
            settingsRaw = new SpriteSettings(reader);
            //  Vector4f uvTransform - 4.5 and up
            if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up
            {
                reader.Position += 16;
            }
            if (version[0] >= 2017) //2017 and up
            {
                //  float downscaleMultiplier - 2017 and up
                reader.Position += 4;
                //vector m_PhysicsShape - 2017 and up
                var m_PhysicsShape_size = reader.ReadInt32();
                m_PhysicsShape = new PointF[m_PhysicsShape_size][];
                for (int i = 0; i < m_PhysicsShape_size; i++)
                {
                    var data_size = reader.ReadInt32();
                    //Vector2f
                    m_PhysicsShape[i] = new PointF[data_size];
                    for (int j = 0; j < data_size; j++)
                    {
                        m_PhysicsShape[i][j] = new PointF(reader.ReadSingle(), reader.ReadSingle());
                    }
                }
            }
            //vector m_Bones 2018 and up
        }