示例#1
0
        public Renderer(AssetPreloadData preloadData)
        {
            var sourceFile = preloadData.sourceFile;
            var a_Stream = preloadData.sourceFile.a_Stream;
            a_Stream.Position = preloadData.Offset;

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags = a_Stream.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal = sourceFile.ReadPPtr();
            }

            m_GameObject = sourceFile.ReadPPtr();
            m_Enabled = a_Stream.ReadBoolean();
            m_CastShadows = a_Stream.ReadByte();
            m_ReceiveShadows = a_Stream.ReadBoolean();
            if (sourceFile.version[0] < 5) { m_LightmapIndex = a_Stream.ReadByte(); }
            else
            {
                a_Stream.Position += 5; //suspicious alignment, could be 2 alignments between bools
                m_LightmapIndex = a_Stream.ReadUInt16();
                m_LightmapIndexDynamic = a_Stream.ReadUInt16();
            }

            if (sourceFile.version[0] >= 3) { a_Stream.Position += 16; } //Vector4f m_LightmapTilingOffset
            if (sourceFile.version[0] >= 5) { a_Stream.Position += 16; } //Vector4f m_LightmapTilingOffsetDynamic

            m_Materials = new PPtr[a_Stream.ReadInt32()];
            for (int m = 0; m < m_Materials.Length; m++)
            {
                m_Materials[m] = sourceFile.ReadPPtr();
            }
        }
示例#2
0
        public string uniqueID = "0";//this way file and folder TreeNodes will be treated as FBX scene

        public GameObject(AssetPreloadData preloadData)
        {
            if (preloadData != null)
            {
                var sourceFile = preloadData.sourceFile;
                var a_Stream = preloadData.sourceFile.a_Stream;
                a_Stream.Position = preloadData.Offset;

                uniqueID = preloadData.uniqueID;

                if (sourceFile.platform == -2)
                {
                    uint m_ObjectHideFlags = a_Stream.ReadUInt32();
                    PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                    PPtr m_PrefabInternal = sourceFile.ReadPPtr();
                }

                int m_Component_size = a_Stream.ReadInt32();
                for (int j = 0; j < m_Component_size; j++)
                {
                    int m_Component_type = a_Stream.ReadInt32();

                    switch (m_Component_type)
                    {
                        case 4:
                            m_Transform = sourceFile.ReadPPtr();
                            break;
                        case 23:
                            m_Renderer = sourceFile.ReadPPtr();
                            break;
                        case 33:
                            m_MeshFilter = sourceFile.ReadPPtr();
                            break;
                        case 137:
                            m_SkinnedMeshRenderer = sourceFile.ReadPPtr();
                            break;
                        default:
                            PPtr m_Component = sourceFile.ReadPPtr();
                            break;
                    }
                }

                m_Layer = a_Stream.ReadInt32();
                int namesize = a_Stream.ReadInt32();
                m_Name = a_Stream.ReadAlignedString(namesize);
                if (m_Name == "") { m_Name = "GameObject #" + uniqueID; }
                m_Tag = a_Stream.ReadUInt16();
                m_IsActive = a_Stream.ReadBoolean();
                
                base.Text = m_Name;
                //name should be unique
                base.Name = uniqueID;
            }
        }
示例#3
0
        public static bool TryGetGameObject(this List<AssetsFile> assetsfileList, PPtr m_elm, out GameObject m_GameObject)
        {
            m_GameObject = null;

            if (m_elm != null && m_elm.m_FileID >= 0 && m_elm.m_FileID < assetsfileList.Count)
            {
                AssetsFile sourceFile = assetsfileList[m_elm.m_FileID];

                if (sourceFile.GameObjectList.TryGetValue(m_elm.m_PathID, out m_GameObject)) { return true; }
            }

            return false;
        }
示例#4
0
        public static bool TryGetTransform(this List<AssetsFile> assetsfileList, PPtr m_elm, out Transform m_Transform)
        {
            m_Transform = null;

            if (m_elm != null && m_elm.m_FileID >= 0 && m_elm.m_FileID < assetsfileList.Count)
            {
                AssetsFile sourceFile = assetsfileList[m_elm.m_FileID];

                if (sourceFile.TransformList.TryGetValue(m_elm.m_PathID, out m_Transform)) { return true; }
            }

            return false;
        }
示例#5
0
        public static bool TryGetPD(this List<AssetsFile> assetsfileList, PPtr m_elm, out AssetPreloadData result)
        {
            result = null;

            if (m_elm != null && m_elm.m_FileID >= 0 && m_elm.m_FileID < assetsfileList.Count)
            {
                AssetsFile sourceFile = assetsfileList[m_elm.m_FileID];

                //TryGetValue should be safe because m_PathID is 0 when initialized and PathID values range from 1
                if (sourceFile.preloadTable.TryGetValue(m_elm.m_PathID, out result)) { return true; }
            }

            return false;
        }
示例#6
0
        public static PPtr ReadPPtr(this AssetsFile sourceFile)
        {
            PPtr result = new PPtr();
            var a_Stream = sourceFile.a_Stream;

            int FileID = a_Stream.ReadInt32();
            if (FileID >= 0 && FileID < sourceFile.sharedAssetsList.Count)
            { result.m_FileID = sourceFile.sharedAssetsList[FileID].Index; }

            if (sourceFile.fileGen < 14) { result.m_PathID = a_Stream.ReadInt32(); }
            else { result.m_PathID = a_Stream.ReadInt64(); }

            return result;
        }
示例#7
0
        public static bool TryGetGameObject(this List<AssetsFile> assetsfileList, PPtr m_elm, out GameObject m_GameObject)
        {
            m_GameObject = null;

            AssetPreloadData GameObjectPD;
            if (assetsfileList.TryGetPD(m_elm, out GameObjectPD))
            {
                if (GameObjectPD.specificIndex >= 0 && GameObjectPD.specificIndex < GameObjectPD.sourceFile.GameObjectList.Count)
                {
                    m_GameObject = GameObjectPD.sourceFile.GameObjectList[GameObjectPD.specificIndex];
                    return true;
                }
            }

            return false;
        }
示例#8
0
        public static bool TryGetTransform(this List<AssetsFile> assetsfileList, PPtr m_elm, out Transform m_Transform)
        {
            m_Transform = null;

            AssetPreloadData TransformPD;
            if (assetsfileList.TryGetPD(m_elm, out TransformPD))
            {
                if (TransformPD.specificIndex >= 0 && TransformPD.specificIndex < TransformPD.sourceFile.TransformList.Count)
                {
                    m_Transform = TransformPD.sourceFile.TransformList[TransformPD.specificIndex];
                    return true;
                }
            }

            return false;
        }
示例#9
0
        public MeshFilter(AssetPreloadData preloadData)
        {
            var sourceFile = preloadData.sourceFile;
            var a_Stream = preloadData.sourceFile.a_Stream;
            a_Stream.Position = preloadData.Offset;

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags = a_Stream.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal = sourceFile.ReadPPtr();
            }

            m_GameObject = sourceFile.ReadPPtr();
            m_Mesh = sourceFile.ReadPPtr();
        }
示例#10
0
        public static PPtr ReadPPtr(this AssetsFile sourceFile)
        {
            PPtr result   = new PPtr();
            var  a_Stream = sourceFile.a_Stream;

            int FileID = a_Stream.ReadInt32();

            if (FileID >= 0 && FileID < sourceFile.sharedAssetsList.Count)
            {
                result.m_FileID = sourceFile.sharedAssetsList[FileID].Index;
            }

            if (sourceFile.fileGen < 14)
            {
                result.m_PathID = a_Stream.ReadInt32();
            }
            else
            {
                result.m_PathID = a_Stream.ReadInt64();
            }

            return(result);
        }
示例#11
0
        public PPtr m_Father = new PPtr();//can be transform or type 224 (as seen in Minions)

        public Transform(AssetPreloadData preloadData)
        {
            var sourceFile = preloadData.sourceFile;
            var a_Stream = preloadData.sourceFile.a_Stream;
            a_Stream.Position = preloadData.Offset;

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags = a_Stream.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal = sourceFile.ReadPPtr();
            }

            m_GameObject = sourceFile.ReadPPtr();
            m_LocalRotation = new float[] { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() };
            m_LocalPosition = new float[] { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() };
            m_LocalScale = new float[] { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() };
            int m_ChildrenCount = a_Stream.ReadInt32();
            for (int j = 0; j < m_ChildrenCount; j++)
            {
                m_Children.Add(sourceFile.ReadPPtr());
            }
            m_Father = sourceFile.ReadPPtr();
        }
示例#12
0
        public SkinnedMeshRenderer(AssetPreloadData preloadData)
        {
            var sourceFile = preloadData.sourceFile;
            var version    = preloadData.sourceFile.version;
            var a_Stream   = preloadData.sourceFile.a_Stream;

            a_Stream.Position = preloadData.Offset;

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags    = a_Stream.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal     = sourceFile.ReadPPtr();
            }

            m_GameObject = sourceFile.ReadPPtr();
            if (sourceFile.version[0] < 5)
            {
                m_Enabled        = a_Stream.ReadBoolean();
                m_CastShadows    = a_Stream.ReadByte();//bool
                m_ReceiveShadows = a_Stream.ReadBoolean();
                m_LightmapIndex  = a_Stream.ReadByte();
            }
            else
            {
                m_Enabled = a_Stream.ReadBoolean();
                a_Stream.AlignStream(4);
                m_CastShadows    = a_Stream.ReadByte();
                m_ReceiveShadows = a_Stream.ReadBoolean();
                a_Stream.AlignStream(4);

                m_LightmapIndex        = a_Stream.ReadUInt16();
                m_LightmapIndexDynamic = a_Stream.ReadUInt16();
            }

            if (version[0] >= 3)
            {
                a_Stream.Position += 16;
            }                                                 //m_LightmapTilingOffset vector4d
            if (sourceFile.version[0] >= 5)
            {
                a_Stream.Position += 16;
            }                                                            //Vector4f m_LightmapTilingOffsetDynamic

            m_Materials = new PPtr[a_Stream.ReadInt32()];
            for (int m = 0; m < m_Materials.Length; m++)
            {
                m_Materials[m] = sourceFile.ReadPPtr();
            }

            if (version[0] < 3)
            {
                a_Stream.Position += 16;//m_LightmapTilingOffset vector4d
            }
            else
            {
                if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 5) || sourceFile.version[0] > 5) //5.5.0 and up
                {
                    a_Stream.Position += 4;                                                                  //m_StaticBatchInfo
                }
                else
                {
                    int m_SubsetIndices_size = a_Stream.ReadInt32();
                    a_Stream.Position += m_SubsetIndices_size * 4;
                }
                PPtr m_StaticBatchRoot = sourceFile.ReadPPtr();

                if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 4) || sourceFile.version[0] > 5)//5.4.0 and up
                {
                    PPtr m_ProbeAnchor = sourceFile.ReadPPtr();
                    PPtr m_LightProbeVolumeOverride = sourceFile.ReadPPtr();
                }
                else if (version[0] >= 4 || (version[0] == 3 && version[1] >= 5))
                {
                    bool m_UseLightProbes = a_Stream.ReadBoolean();
                    a_Stream.Position += 3; //alignment
                    if (version[0] == 5)
                    {
                        int m_ReflectionProbeUsage = a_Stream.ReadInt32();
                    }
                    //did I ever check if the anchor is conditioned by the bool?
                    PPtr m_LightProbeAnchor = sourceFile.ReadPPtr();
                }

                if (version[0] >= 5 || (version[0] == 4 && version[1] >= 3))
                {
                    if (version[0] == 4 && version[1] <= 3)
                    {
                        int m_SortingLayer = a_Stream.ReadInt16();
                    }
                    else
                    {
                        int m_SortingLayer = a_Stream.ReadInt32();
                    }

                    int m_SortingOrder = a_Stream.ReadInt16();
                    a_Stream.AlignStream(4);
                }
            }

            int  m_Quality             = a_Stream.ReadInt32();
            bool m_UpdateWhenOffscreen = a_Stream.ReadBoolean();
            bool m_SkinNormals         = a_Stream.ReadBoolean(); //3.1.0 and below

            a_Stream.Position += 2;

            if (version[0] == 2 && version[1] < 6)
            {
                //this would be the only error if mainVersion is not read in time for a unity 2.x game
                PPtr m_DisableAnimationWhenOffscreen = sourceFile.ReadPPtr();
            }

            m_Mesh = sourceFile.ReadPPtr();

            m_Bones = new PPtr[a_Stream.ReadInt32()];
            for (int b = 0; b < m_Bones.Length; b++)
            {
                m_Bones[b] = sourceFile.ReadPPtr();
            }

            if (version[0] < 3)
            {
                int m_BindPose = a_Stream.ReadInt32();
                a_Stream.Position += m_BindPose * 16 * 4;//Matrix4x4f
            }
            else
            {
                if (version[0] > 4 || (version[0] == 4 && version[1] >= 3))
                {
                    int m_BlendShapeWeights = a_Stream.ReadInt32();
                    a_Stream.Position += m_BlendShapeWeights * 4; //floats
                }

                if (version[0] > 4 || (version[0] >= 3 && version[1] >= 5))
                {
                    PPtr m_RootBone = sourceFile.ReadPPtr();
                }

                if (version[0] > 4 || (version[0] == 3 && version[1] >= 4))
                {
                    //AABB
                    float[] m_Center    = { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() };
                    float[] m_Extent    = { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() };
                    bool    m_DirtyAABB = a_Stream.ReadBoolean();
                }
            }
        }
示例#13
0
        public unityFont(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var a_Stream   = preloadData.sourceFile.a_Stream;

            a_Stream.Position = preloadData.Offset;

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags    = a_Stream.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal     = sourceFile.ReadPPtr();
            }

            m_Name = a_Stream.ReadAlignedString(a_Stream.ReadInt32());

            if (readSwitch)
            {
                if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 5) || sourceFile.version[0] > 5)
                {
                    var m_LineSpacing         = a_Stream.ReadSingle();
                    var m_DefaultMaterial     = sourceFile.ReadPPtr();
                    var m_FontSize            = a_Stream.ReadSingle();
                    var m_Texture             = sourceFile.ReadPPtr();
                    int m_AsciiStartOffset    = a_Stream.ReadInt32();
                    var m_Tracking            = a_Stream.ReadSingle();
                    var m_CharacterSpacing    = a_Stream.ReadInt32();
                    var m_CharacterPadding    = a_Stream.ReadInt32();
                    var m_ConvertCase         = a_Stream.ReadInt32();
                    int m_CharacterRects_size = a_Stream.ReadInt32();
                    for (int i = 0; i < m_CharacterRects_size; i++)
                    {
                        int index = a_Stream.ReadInt32();
                        //Rectf uv
                        float uvx      = a_Stream.ReadSingle();
                        float uvy      = a_Stream.ReadSingle();
                        float uvwidth  = a_Stream.ReadSingle();
                        float uvheight = a_Stream.ReadSingle();
                        //Rectf vert
                        float vertx      = a_Stream.ReadSingle();
                        float verty      = a_Stream.ReadSingle();
                        float vertwidth  = a_Stream.ReadSingle();
                        float vertheight = a_Stream.ReadSingle();
                        float width      = a_Stream.ReadSingle();

                        if (sourceFile.version[0] >= 4)
                        {
                            bool flipped = a_Stream.ReadBoolean();
                            a_Stream.Position += 3;
                        }
                    }
                    int m_KerningValues_size = a_Stream.ReadInt32();
                    for (int i = 0; i < m_KerningValues_size; i++)
                    {
                        int   pairfirst  = a_Stream.ReadInt16();
                        int   pairsecond = a_Stream.ReadInt16();
                        float second     = a_Stream.ReadSingle();
                    }
                    var m_PixelScale    = a_Stream.ReadSingle();
                    int m_FontData_size = a_Stream.ReadInt32();
                    if (m_FontData_size > 0)
                    {
                        m_FontData = new byte[m_FontData_size];
                        a_Stream.Read(m_FontData, 0, m_FontData_size);

                        if (m_FontData[0] == 79 && m_FontData[1] == 84 && m_FontData[2] == 84 && m_FontData[3] == 79)
                        {
                            preloadData.extension = ".otf";
                        }
                        else
                        {
                            preloadData.extension = ".ttf";
                        }
                    }
                }
                else
                {
                    int m_AsciiStartOffset = a_Stream.ReadInt32();

                    if (sourceFile.version[0] <= 3)
                    {
                        int m_FontCountX = a_Stream.ReadInt32();
                        int m_FontCountY = a_Stream.ReadInt32();
                    }

                    float m_Kerning     = a_Stream.ReadSingle();
                    float m_LineSpacing = a_Stream.ReadSingle();

                    if (sourceFile.version[0] <= 3)
                    {
                        int m_PerCharacterKerning_size = a_Stream.ReadInt32();
                        for (int i = 0; i < m_PerCharacterKerning_size; i++)
                        {
                            int   first  = a_Stream.ReadInt32();
                            float second = a_Stream.ReadSingle();
                        }
                    }
                    else
                    {
                        int m_CharacterSpacing = a_Stream.ReadInt32();
                        int m_CharacterPadding = a_Stream.ReadInt32();
                    }

                    int  m_ConvertCase     = a_Stream.ReadInt32();
                    PPtr m_DefaultMaterial = sourceFile.ReadPPtr();

                    int m_CharacterRects_size = a_Stream.ReadInt32();
                    for (int i = 0; i < m_CharacterRects_size; i++)
                    {
                        int index = a_Stream.ReadInt32();
                        //Rectf uv
                        float uvx      = a_Stream.ReadSingle();
                        float uvy      = a_Stream.ReadSingle();
                        float uvwidth  = a_Stream.ReadSingle();
                        float uvheight = a_Stream.ReadSingle();
                        //Rectf vert
                        float vertx      = a_Stream.ReadSingle();
                        float verty      = a_Stream.ReadSingle();
                        float vertwidth  = a_Stream.ReadSingle();
                        float vertheight = a_Stream.ReadSingle();
                        float width      = a_Stream.ReadSingle();

                        if (sourceFile.version[0] >= 4)
                        {
                            bool flipped = a_Stream.ReadBoolean();
                            a_Stream.Position += 3;
                        }
                    }

                    PPtr m_Texture = sourceFile.ReadPPtr();

                    int m_KerningValues_size = a_Stream.ReadInt32();
                    for (int i = 0; i < m_KerningValues_size; i++)
                    {
                        int   pairfirst  = a_Stream.ReadInt16();
                        int   pairsecond = a_Stream.ReadInt16();
                        float second     = a_Stream.ReadSingle();
                    }

                    if (sourceFile.version[0] <= 3)
                    {
                        bool m_GridFont = a_Stream.ReadBoolean();
                        a_Stream.Position += 3; //4 byte alignment
                    }
                    else
                    {
                        float m_PixelScale = a_Stream.ReadSingle();
                    }

                    int m_FontData_size = a_Stream.ReadInt32();
                    if (m_FontData_size > 0)
                    {
                        m_FontData = new byte[m_FontData_size];
                        a_Stream.Read(m_FontData, 0, m_FontData_size);

                        if (m_FontData[0] == 79 && m_FontData[1] == 84 && m_FontData[2] == 84 && m_FontData[3] == 79)
                        {
                            preloadData.extension = ".otf";
                        }
                        else
                        {
                            preloadData.extension = ".ttf";
                        }
                    }

                    float m_FontSize     = a_Stream.ReadSingle();//problem here in minifootball
                    float m_Ascent       = a_Stream.ReadSingle();
                    uint  m_DefaultStyle = a_Stream.ReadUInt32();

                    int m_FontNames = a_Stream.ReadInt32();
                    for (int i = 0; i < m_FontNames; i++)
                    {
                        string m_FontName = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
                    }

                    if (sourceFile.version[0] >= 4)
                    {
                        int m_FallbackFonts = a_Stream.ReadInt32();
                        for (int i = 0; i < m_FallbackFonts; i++)
                        {
                            PPtr m_FallbackFont = sourceFile.ReadPPtr();
                        }

                        int m_FontRenderingMode = a_Stream.ReadInt32();
                    }
                }
            }
            else
            {
                if (m_Name != "")
                {
                    preloadData.Text = m_Name;
                }
                else
                {
                    preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID;
                }
                preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() });
            }
        }
示例#14
0
        public AudioClip(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var a_Stream   = preloadData.sourceFile.a_Stream;

            a_Stream.Position = preloadData.Offset;

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags    = a_Stream.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal     = sourceFile.ReadPPtr();
            }

            m_Name   = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
            version5 = sourceFile.version[0] >= 5;
            if (sourceFile.version[0] < 5)
            {
                m_Format           = a_Stream.ReadInt32(); //channels?
                m_Type             = (AudioType)a_Stream.ReadInt32();
                m_3D               = a_Stream.ReadBoolean();
                m_UseHardware      = a_Stream.ReadBoolean();
                a_Stream.Position += 2;                                                                       //4 byte alignment

                if (sourceFile.version[0] >= 4 || (sourceFile.version[0] == 3 && sourceFile.version[1] >= 2)) //3.2.0 to 5
                {
                    int m_Stream = a_Stream.ReadInt32();
                    m_Size = a_Stream.ReadInt32();
                    var tsize = m_Size % 4 != 0 ? m_Size + 4 - m_Size % 4 : m_Size;
                    //TODO: Need more test
                    if (preloadData.Size + preloadData.Offset - a_Stream.Position != tsize)
                    {
                        m_Offset = a_Stream.ReadInt32();
                        m_Source = sourceFile.filePath + ".resS";
                    }
                }
                else
                {
                    m_Size = a_Stream.ReadInt32();
                }
            }
            else
            {
                m_LoadType         = a_Stream.ReadInt32(); //Decompress on load, Compressed in memory, Streaming
                m_Channels         = a_Stream.ReadInt32();
                m_Frequency        = a_Stream.ReadInt32();
                m_BitsPerSample    = a_Stream.ReadInt32();
                m_Length           = a_Stream.ReadSingle();
                m_IsTrackerFormat  = a_Stream.ReadBoolean();
                a_Stream.Position += 3;
                m_SubsoundIndex    = a_Stream.ReadInt32();
                m_PreloadAudioData = a_Stream.ReadBoolean();
                m_LoadInBackground = a_Stream.ReadBoolean();
                m_Legacy3D         = a_Stream.ReadBoolean();
                a_Stream.Position += 1;
                m_3D = m_Legacy3D;

                m_Source = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
                if (m_Source != "")
                {
                    m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), m_Source.Replace("archive:/", ""));
                }
                m_Offset            = a_Stream.ReadInt64();
                m_Size              = a_Stream.ReadInt64();
                m_CompressionFormat = (AudioCompressionFormat)a_Stream.ReadInt32();
            }

            if (readSwitch)
            {
                if (string.IsNullOrEmpty(m_Source))
                {
                    if (m_Size > 0)
                    {
                        m_AudioData = a_Stream.ReadBytes((int)m_Size);
                    }
                }
                else if (File.Exists(m_Source) ||
                         File.Exists(m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), Path.GetFileName(m_Source))))
                {
                    BinaryReader reader = new BinaryReader(File.OpenRead(m_Source));
                    reader.BaseStream.Position = m_Offset;
                    m_AudioData = reader.ReadBytes((int)m_Size);
                    reader.Close();
                }
                else
                {
                    if (UnityStudio.assetsfileandstream.TryGetValue(Path.GetFileName(m_Source), out var estream))
                    {
                        estream.Position = m_Offset;
                        m_AudioData      = estream.ReadBytes((int)m_Size);
                    }
                    else
                    {
                        MessageBox.Show($"can't find the resource file {Path.GetFileName(m_Source)}");
                    }
                }
            }
            else
            {
                preloadData.InfoText = "Compression format: ";

                if (sourceFile.version[0] < 5)
                {
                    switch (m_Type)
                    {
                    case AudioType.ACC:
                        preloadData.extension = ".m4a";
                        preloadData.InfoText += "Acc";
                        break;

                    case AudioType.AIFF:
                        preloadData.extension = ".aif";
                        preloadData.InfoText += "AIFF";
                        break;

                    case AudioType.IT:
                        preloadData.extension = ".it";
                        preloadData.InfoText += "Impulse tracker";
                        break;

                    case AudioType.MOD:
                        preloadData.extension = ".mod";
                        preloadData.InfoText += "Protracker / Fasttracker MOD";
                        break;

                    case AudioType.MPEG:
                        preloadData.extension = ".mp3";
                        preloadData.InfoText += "MP2/MP3 MPEG";
                        break;

                    case AudioType.OGGVORBIS:
                        preloadData.extension = ".ogg";
                        preloadData.InfoText += "Ogg vorbis";
                        break;

                    case AudioType.S3M:
                        preloadData.extension = ".s3m";
                        preloadData.InfoText += "ScreamTracker 3";
                        break;

                    case AudioType.WAV:
                        preloadData.extension = ".wav";
                        preloadData.InfoText += "Microsoft WAV";
                        break;

                    case AudioType.XM:
                        preloadData.extension = ".xm";
                        preloadData.InfoText += "FastTracker 2 XM";
                        break;

                    case AudioType.XMA:
                        preloadData.extension = ".wav";
                        preloadData.InfoText += "Xbox360 XMA";
                        break;

                    case AudioType.VAG:
                        preloadData.extension = ".vag";
                        preloadData.InfoText += "PlayStation Portable ADPCM";
                        break;

                    case AudioType.AUDIOQUEUE:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "iPhone";
                        break;
                    }
                }
                else
                {
                    switch (m_CompressionFormat)
                    {
                    case AudioCompressionFormat.PCM:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "PCM";
                        break;

                    case AudioCompressionFormat.Vorbis:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "Vorbis";
                        break;

                    case AudioCompressionFormat.ADPCM:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "ADPCM";
                        break;

                    case AudioCompressionFormat.MP3:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "MP3";
                        break;

                    case AudioCompressionFormat.VAG:
                        preloadData.extension = ".vag";
                        preloadData.InfoText += "PlayStation Portable ADPCM";
                        break;

                    case AudioCompressionFormat.HEVAG:
                        preloadData.extension = ".vag";
                        preloadData.InfoText += "PSVita ADPCM";
                        break;

                    case AudioCompressionFormat.XMA:
                        preloadData.extension = ".wav";
                        preloadData.InfoText += "Xbox360 XMA";
                        break;

                    case AudioCompressionFormat.AAC:
                        preloadData.extension = ".m4a";
                        preloadData.InfoText += "Acc";
                        break;

                    case AudioCompressionFormat.GCADPCM:
                        preloadData.extension = ".fsb";
                        preloadData.InfoText += "Nintendo 3DS/Wii DSP";
                        break;

                    case AudioCompressionFormat.ATRAC9:
                        preloadData.extension = ".at9";
                        preloadData.InfoText += "PSVita ATRAC9";
                        break;
                    }
                }

                if (preloadData.extension == null)
                {
                    preloadData.extension = ".AudioClip";
                    preloadData.InfoText += "Unknown";
                }

                preloadData.InfoText += "\n3D: " + m_3D;

                preloadData.Text = m_Name;
                if (m_Source != null)
                {
                    preloadData.fullSize = preloadData.Size + (int)m_Size;
                }
            }
        }
示例#15
0
        public Texture2D(AssetPreloadData preloadData, bool readSwitch)
        {
            AssetsFile   sourceFile = preloadData.sourceFile;
            EndianStream stream     = preloadData.sourceFile.a_Stream;

            stream.Position = preloadData.Offset;
            if (sourceFile.platform == -2)
            {
                uint num  = stream.ReadUInt32();
                PPtr ptr  = sourceFile.ReadPPtr();
                PPtr ptr2 = sourceFile.ReadPPtr();
            }
            this.m_Name              = stream.ReadAlignedString(stream.ReadInt32());
            this.m_Width             = stream.ReadInt32();
            this.m_Height            = stream.ReadInt32();
            this.m_CompleteImageSize = stream.ReadInt32();
            this.m_TextureFormat     = stream.ReadInt32();
            this.getExtension(preloadData, this.m_TextureFormat);
            if (this.m_Name != "")
            {
                preloadData.Name = this.m_Name;
            }
            else
            {
                preloadData.Name = preloadData.TypeString + " #" + preloadData.uniqueID;
            }
            if ((sourceFile.version[0] < 5) || ((sourceFile.version[0] == 5) && (sourceFile.version[1] < 2)))
            {
                this.m_MipMap = stream.ReadBoolean();
            }
            else
            {
                this.dwFlags      += 0x20000;
                this.dwMipMapCount = stream.ReadInt32();
                this.dwCaps       += 0x400008;
            }
            this.m_IsReadable  = stream.ReadBoolean();
            this.m_ReadAllowed = stream.ReadBoolean();
            stream.AlignStream(4);
            this.m_ImageCount       = stream.ReadInt32();
            this.m_TextureDimension = stream.ReadInt32();
            this.m_FilterMode       = stream.ReadInt32();
            this.m_Aniso            = stream.ReadInt32();
            this.m_MipBias          = stream.ReadSingle();
            this.m_WrapMode         = stream.ReadInt32();
            if (sourceFile.version[0] >= 3)
            {
                this.m_LightmapFormat = stream.ReadInt32();
                if ((sourceFile.version[0] >= 4) || (sourceFile.version[1] >= 5))
                {
                    this.m_ColorSpace = stream.ReadInt32();
                }
            }
            this.image_data_size = stream.ReadInt32();
            if (this.m_MipMap)
            {
                this.dwFlags      += 0x20000;
                this.dwMipMapCount = Convert.ToInt32((double)(Math.Log((double)Math.Max(this.m_Width, this.m_Height)) / Math.Log(2.0)));
                this.dwCaps       += 0x400008;
            }
            if (!readSwitch)
            {
                string[] textArray1 = new string[] { "Width: ", this.m_Width.ToString(), "\nHeight: ", this.m_Height.ToString(), "\nFormat: " };
                preloadData.InfoText   = string.Concat(textArray1);
                preloadData.exportSize = this.image_data_size;
                switch (this.m_TextureFormat)
                {
                case 1:
                    preloadData.InfoText    = preloadData.InfoText + "Alpha8";
                    preloadData.extension   = ".dds";
                    preloadData.exportSize += 0x80;
                    goto Label_0E7B;

                case 2:
                    preloadData.InfoText    = preloadData.InfoText + "ARGB 4.4.4.4";
                    preloadData.extension   = ".dds";
                    preloadData.exportSize += 0x80;
                    goto Label_0E7B;

                case 3:
                    preloadData.InfoText    = preloadData.InfoText + "BGR 8.8.8";
                    preloadData.extension   = ".dds";
                    preloadData.exportSize += 0x80;
                    goto Label_0E7B;

                case 4:
                    preloadData.InfoText    = preloadData.InfoText + "GRAB 8.8.8.8";
                    preloadData.extension   = ".dds";
                    preloadData.exportSize += 0x80;
                    goto Label_0E7B;

                case 5:
                    preloadData.InfoText    = preloadData.InfoText + "BGRA 8.8.8.8";
                    preloadData.extension   = ".dds";
                    preloadData.exportSize += 0x80;
                    goto Label_0E7B;

                case 7:
                    preloadData.InfoText    = preloadData.InfoText + "RGB 5.6.5";
                    preloadData.extension   = ".dds";
                    preloadData.exportSize += 0x80;
                    goto Label_0E7B;

                case 10:
                    preloadData.InfoText    = preloadData.InfoText + "DXT1";
                    preloadData.extension   = ".dds";
                    preloadData.exportSize += 0x80;
                    goto Label_0E7B;

                case 12:
                    preloadData.InfoText    = preloadData.InfoText + "DXT5";
                    preloadData.extension   = ".dds";
                    preloadData.exportSize += 0x80;
                    goto Label_0E7B;

                case 13:
                    preloadData.InfoText    = preloadData.InfoText + "RGBA 4.4.4.4";
                    preloadData.extension   = ".dds";
                    preloadData.exportSize += 0x80;
                    goto Label_0E7B;

                case 0x1c:
                    preloadData.InfoText  = preloadData.InfoText + "DXT1 Crunched";
                    preloadData.extension = ".crn";
                    goto Label_0E7B;

                case 0x1d:
                    preloadData.InfoText  = preloadData.InfoText + "DXT5 Crunched";
                    preloadData.extension = ".crn";
                    goto Label_0E7B;

                case 30:
                    preloadData.InfoText    = preloadData.InfoText + "PVRTC_RGB2";
                    preloadData.extension   = ".pvr";
                    preloadData.exportSize += 0x34;
                    goto Label_0E7B;

                case 0x1f:
                    preloadData.InfoText    = preloadData.InfoText + "PVRTC_RGBA2";
                    preloadData.extension   = ".pvr";
                    preloadData.exportSize += 0x34;
                    goto Label_0E7B;

                case 0x20:
                    preloadData.InfoText    = preloadData.InfoText + "PVRTC_RGB4";
                    preloadData.extension   = ".pvr";
                    preloadData.exportSize += 0x34;
                    goto Label_0E7B;

                case 0x21:
                    preloadData.InfoText    = preloadData.InfoText + "PVRTC_RGBA4";
                    preloadData.extension   = ".pvr";
                    preloadData.exportSize += 0x34;
                    goto Label_0E7B;

                case 0x22:
                    preloadData.InfoText    = preloadData.InfoText + "ETC_RGB4";
                    preloadData.extension   = ".pvr";
                    preloadData.exportSize += 0x34;
                    goto Label_0E7B;
                }
                preloadData.InfoText  = preloadData.InfoText + "unknown";
                preloadData.extension = ".tex";
            }
            else
            {
                this.image_data = new byte[this.image_data_size];
                stream.Read(this.image_data, 0, this.image_data_size);
                switch (this.m_TextureFormat)
                {
                case 1:
                    this.dwFlags2      = 2;
                    this.dwRGBBitCount = 8;
                    this.dwRBitMask    = 0;
                    this.dwGBitMask    = 0;
                    this.dwBBitMask    = 0;
                    this.dwABitMask    = 0xff;
                    return;

                case 2:
                    if (sourceFile.platform != 11)
                    {
                        if (sourceFile.platform == 13)
                        {
                            for (int j = 0; j < (this.image_data_size / 2); j++)
                            {
                                byte[] buffer1 = new byte[] { this.image_data[j * 2], this.image_data[(j * 2) + 1], this.image_data[j * 2], this.image_data[(j * 2) + 1] };
                                byte[] bytes   = BitConverter.GetBytes((int)(BitConverter.ToInt32(buffer1, 0) >> 4));
                                this.image_data[j * 2]       = bytes[0];
                                this.image_data[(j * 2) + 1] = bytes[1];
                            }
                        }
                        break;
                    }
                    for (int i = 0; i < (this.image_data_size / 2); i++)
                    {
                        byte num4 = this.image_data[i * 2];
                        this.image_data[i * 2]       = this.image_data[(i * 2) + 1];
                        this.image_data[(i * 2) + 1] = num4;
                    }
                    break;

                case 3:
                    for (int k = 0; k < (this.image_data_size / 3); k++)
                    {
                        byte num7 = this.image_data[k * 3];
                        this.image_data[k * 3]       = this.image_data[(k * 3) + 2];
                        this.image_data[(k * 3) + 2] = num7;
                    }
                    this.dwFlags2      = 0x40;
                    this.dwRGBBitCount = 0x18;
                    this.dwRBitMask    = 0xff0000;
                    this.dwGBitMask    = 0xff00;
                    this.dwBBitMask    = 0xff;
                    this.dwABitMask    = 0;
                    return;

                case 4:
                    for (int m = 0; m < (this.image_data_size / 4); m++)
                    {
                        byte num9 = this.image_data[m * 4];
                        this.image_data[m * 4]       = this.image_data[(m * 4) + 2];
                        this.image_data[(m * 4) + 2] = num9;
                    }
                    this.dwFlags2      = 0x41;
                    this.dwRGBBitCount = 0x20;
                    this.dwRBitMask    = 0xff0000;
                    this.dwGBitMask    = 0xff00;
                    this.dwBBitMask    = 0xff;
                    this.dwABitMask    = -16777216;
                    return;

                case 5:
                    for (int n = 0; n < (this.image_data_size / 4); n++)
                    {
                        byte num11 = this.image_data[n * 4];
                        byte num12 = this.image_data[(n * 4) + 1];
                        this.image_data[n * 4]       = this.image_data[(n * 4) + 3];
                        this.image_data[(n * 4) + 1] = this.image_data[(n * 4) + 2];
                        this.image_data[(n * 4) + 2] = num12;
                        this.image_data[(n * 4) + 3] = num11;
                    }
                    this.dwFlags2      = 0x41;
                    this.dwRGBBitCount = 0x20;
                    this.dwRBitMask    = 0xff0000;
                    this.dwGBitMask    = 0xff00;
                    this.dwBBitMask    = 0xff;
                    this.dwABitMask    = -16777216;
                    return;

                case 6:
                case 8:
                case 9:
                case 11:
                case 0x1c:
                case 0x1d:
                    return;

                case 7:
                    if (sourceFile.platform == 11)
                    {
                        for (int num13 = 0; num13 < (this.image_data_size / 2); num13++)
                        {
                            byte num14 = this.image_data[num13 * 2];
                            this.image_data[num13 * 2]       = this.image_data[(num13 * 2) + 1];
                            this.image_data[(num13 * 2) + 1] = num14;
                        }
                    }
                    this.dwFlags2      = 0x40;
                    this.dwRGBBitCount = 0x10;
                    this.dwRBitMask    = 0xf800;
                    this.dwGBitMask    = 0x7e0;
                    this.dwBBitMask    = 0x1f;
                    this.dwABitMask    = 0;
                    return;

                case 10:
                    if (sourceFile.platform == 11)
                    {
                        for (int num15 = 0; num15 < (this.image_data_size / 2); num15++)
                        {
                            byte num16 = this.image_data[num15 * 2];
                            this.image_data[num15 * 2]       = this.image_data[(num15 * 2) + 1];
                            this.image_data[(num15 * 2) + 1] = num16;
                        }
                    }
                    if (this.m_MipMap)
                    {
                        this.dwPitchOrLinearSize = (this.m_Height * this.m_Width) / 2;
                    }
                    this.dwFlags2      = 4;
                    this.dwFourCC      = 0x31545844;
                    this.dwRGBBitCount = 0;
                    this.dwRBitMask    = 0;
                    this.dwGBitMask    = 0;
                    this.dwBBitMask    = 0;
                    this.dwABitMask    = 0;
                    return;

                case 12:
                    if (sourceFile.platform == 11)
                    {
                        for (int num17 = 0; num17 < (this.image_data_size / 2); num17++)
                        {
                            byte num18 = this.image_data[num17 * 2];
                            this.image_data[num17 * 2]       = this.image_data[(num17 * 2) + 1];
                            this.image_data[(num17 * 2) + 1] = num18;
                        }
                    }
                    if (this.m_MipMap)
                    {
                        this.dwPitchOrLinearSize = (this.m_Height * this.m_Width) / 2;
                    }
                    this.dwFlags2      = 4;
                    this.dwFourCC      = 0x35545844;
                    this.dwRGBBitCount = 0;
                    this.dwRBitMask    = 0;
                    this.dwGBitMask    = 0;
                    this.dwBBitMask    = 0;
                    this.dwABitMask    = 0;
                    return;

                case 13:
                    for (int num19 = 0; num19 < (this.image_data_size / 2); num19++)
                    {
                        byte[] buffer3 = new byte[] { this.image_data[num19 * 2], this.image_data[(num19 * 2) + 1], this.image_data[num19 * 2], this.image_data[(num19 * 2) + 1] };
                        byte[] buffer2 = BitConverter.GetBytes((int)(BitConverter.ToInt32(buffer3, 0) >> 4));
                        this.image_data[num19 * 2]       = buffer2[0];
                        this.image_data[(num19 * 2) + 1] = buffer2[1];
                    }
                    this.dwFlags2      = 0x41;
                    this.dwRGBBitCount = 0x10;
                    this.dwRBitMask    = 0xf00;
                    this.dwGBitMask    = 240;
                    this.dwBBitMask    = 15;
                    this.dwABitMask    = 0xf000;
                    return;

                case 30:
                    this.pvrPixelFormat = 0L;
                    return;

                case 0x1f:
                    this.pvrPixelFormat = 1L;
                    return;

                case 0x20:
                    this.pvrPixelFormat = 2L;
                    return;

                case 0x21:
                    this.pvrPixelFormat = 3L;
                    return;

                case 0x22:
                    this.pvrPixelFormat = 0x16L;
                    return;

                default:
                    return;
                }
                this.dwFlags2      = 0x41;
                this.dwRGBBitCount = 0x10;
                this.dwRBitMask    = 0xf00;
                this.dwGBitMask    = 240;
                this.dwBBitMask    = 15;
                this.dwABitMask    = 0xf000;
                return;
            }
Label_0E7B:
            switch (this.m_FilterMode)
            {
            case 0:
                preloadData.InfoText = preloadData.InfoText + "\nFilter Mode: Point ";
                break;

            case 1:
                preloadData.InfoText = preloadData.InfoText + "\nFilter Mode: Bilinear ";
                break;

            case 2:
                preloadData.InfoText = preloadData.InfoText + "\nFilter Mode: Trilinear ";
                break;
            }
            AssetPreloadData data = preloadData;

            string[] textArray2 = new string[] { data.InfoText, "\nAnisotropic level: ", this.m_Aniso.ToString(), "\nMip map bias: ", this.m_MipBias.ToString() };
            data.InfoText = string.Concat(textArray2);
            switch (this.m_WrapMode)
            {
            case 0:
                preloadData.InfoText = preloadData.InfoText + "\nWrap mode: Repeat";
                break;

            case 1:
                preloadData.InfoText = preloadData.InfoText + "\nWrap mode: Clamp";
                break;
            }
        }
示例#16
0
        public Sprite(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var reader     = preloadData.sourceFile.a_Stream;

            reader.Position = preloadData.Offset;
            var version = sourceFile.version;

            m_Name = reader.ReadAlignedString(reader.ReadInt32());
            if (readSwitch)
            {
                //Rectf m_Rect
                m_Rect = new RectangleF(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                //Vector2f m_Offset
                reader.Position += 8;
                if (version[0] > 4 || (version[0] == 4 && version[1] >= 2)) //4.2 and up
                {
                    //m_Border
                    m_Border = new Vector4f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                }

                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 = new PointF(reader.ReadSingle(), reader.ReadSingle());
                }

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

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

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

                //SpriteRenderData m_RD
                //  PPtr<Texture2D> texture
                texture = sourceFile.ReadPPtr();

                //  PPtr<Texture2D> alphaTexture
                if (version[0] >= 5) //5.0 and up
                {
                    var alphaTexture = sourceFile.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
                    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);
                }
                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] <= 1)) //4.1 and down
                        {
                            reader.Position += 8;                                   //Vector2f uv
                        }
                    }

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

                //  Rectf textureRect
                textureRect = new RectangleF(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                //  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
                reader.Position += 4;
                //  Vector4f uvTransform - 4.2 and up
                if (version[0] > 4 || (version[0] == 4 && version[1] >= 2)) //4.2 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());
                        }
                    }
                }
            }
            else
            {
                preloadData.extension = ".png";
                preloadData.Text      = m_Name;
            }
        }
示例#17
0
        public Texture2D(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var a_Stream   = preloadData.sourceFile.a_Stream;

            a_Stream.Position = preloadData.Offset;
            version           = sourceFile.version;

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags    = a_Stream.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal     = sourceFile.ReadPPtr();
            }

            m_Name = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
            if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 3))//2017.3 and up
            {
                var m_ForcedFallbackFormat = a_Stream.ReadInt32();
                var m_DownscaleFallback    = a_Stream.ReadBoolean();
                a_Stream.AlignStream(4);
            }
            m_Width             = a_Stream.ReadInt32();
            m_Height            = a_Stream.ReadInt32();
            m_CompleteImageSize = a_Stream.ReadInt32();
            m_TextureFormat     = (TextureFormat)a_Stream.ReadInt32();

            if (version[0] < 5 || (version[0] == 5 && version[1] < 2))
            {
                m_MipMap = a_Stream.ReadBoolean();
            }
            else
            {
                dwFlags      += 0x20000;
                dwMipMapCount = a_Stream.ReadInt32();//is this with or without main image?
                dwCaps       += 0x400008;
            }

            m_IsReadable  = a_Stream.ReadBoolean(); //2.6.0 and up
            m_ReadAllowed = a_Stream.ReadBoolean(); //3.0.0 - 5.4
            a_Stream.AlignStream(4);

            m_ImageCount       = a_Stream.ReadInt32();
            m_TextureDimension = a_Stream.ReadInt32();
            //m_TextureSettings
            m_FilterMode = a_Stream.ReadInt32();
            m_Aniso      = a_Stream.ReadInt32();
            m_MipBias    = a_Stream.ReadSingle();
            m_WrapMode   = a_Stream.ReadInt32();
            if (version[0] >= 2017)//2017.x and up
            {
                int m_WrapV = a_Stream.ReadInt32();
                int m_WrapW = a_Stream.ReadInt32();
            }
            if (version[0] >= 3)
            {
                m_LightmapFormat = a_Stream.ReadInt32();
                if (version[0] >= 4 || version[1] >= 5)
                {
                    m_ColorSpace = a_Stream.ReadInt32();
                }                                                                                //3.5.0 and up
            }

            image_data_size = a_Stream.ReadInt32();

            if (m_MipMap)
            {
                dwFlags      += 0x20000;
                dwMipMapCount = Convert.ToInt32(Math.Log(Math.Max(m_Width, m_Height)) / Math.Log(2));
                dwCaps       += 0x400008;
            }

            if (image_data_size == 0 && ((version[0] == 5 && version[1] >= 3) || version[0] > 5))//5.3.0 and up
            {
                offset          = a_Stream.ReadUInt32();
                size            = a_Stream.ReadUInt32();
                image_data_size = (int)size;
                path            = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
            }

            if (readSwitch)
            {
                if (!string.IsNullOrEmpty(path))
                {
                    var resourceFileName = Path.GetFileName(path);
                    var resourceFilePath = Path.GetDirectoryName(sourceFile.filePath) + "\\" + resourceFileName;
                    if (!File.Exists(resourceFilePath))
                    {
                        var findFiles = Directory.GetFiles(Path.GetDirectoryName(sourceFile.filePath), resourceFileName, SearchOption.AllDirectories);
                        if (findFiles.Length > 0)
                        {
                            resourceFilePath = findFiles[0];
                        }
                    }
                    if (File.Exists(resourceFilePath))
                    {
                        using (var reader = new BinaryReader(File.OpenRead(resourceFilePath)))
                        {
                            reader.BaseStream.Position = offset;
                            image_data = reader.ReadBytes(image_data_size);
                        }
                    }
                    else
                    {
                        if (UnityStudio.assetsfileandstream.TryGetValue(resourceFileName, out var reader))
                        {
                            reader.Position = offset;
                            image_data      = reader.ReadBytes(image_data_size);
                        }
                        else
                        {
                            MessageBox.Show($"can't find the resource file {resourceFileName}");
                        }
                    }
                }
                else
                {
                    image_data = a_Stream.ReadBytes(image_data_size);
                }

                switch (m_TextureFormat)
                {
                //TODO 导出到DDS容器时应该用原像素还是转换以后的像素?
                case TextureFormat.Alpha8:     //test pass
                {
                    /*dwFlags2 = 0x2;
                     * dwRGBBitCount = 0x8;
                     * dwRBitMask = 0x0;
                     * dwGBitMask = 0x0;
                     * dwBBitMask = 0x0;
                     * dwABitMask = 0xFF; */

                    //转BGRA32
                    var BGRA32 = Enumerable.Repeat <byte>(0xFF, image_data_size * 4).ToArray();
                    for (var i = 0; i < image_data_size; i++)
                    {
                        BGRA32[i * 4 + 3] = image_data[i];
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.ARGB4444:     //test pass
                {
                    SwapBytesForXbox(sourceFile.platform);

                    /*dwFlags2 = 0x41;
                     * dwRGBBitCount = 0x10;
                     * dwRBitMask = 0xF00;
                     * dwGBitMask = 0xF0;
                     * dwBBitMask = 0xF;
                     * dwABitMask = 0xF000;*/

                    //转BGRA32
                    var BGRA32 = new byte[image_data_size * 2];
                    for (var i = 0; i < image_data_size / 2; i++)
                    {
                        var pixelNew      = new byte[4];
                        var pixelOldShort = BitConverter.ToUInt16(image_data, i * 2);
                        pixelNew[0] = (byte)(pixelOldShort & 0x000f);
                        pixelNew[1] = (byte)((pixelOldShort & 0x00f0) >> 4);
                        pixelNew[2] = (byte)((pixelOldShort & 0x0f00) >> 8);
                        pixelNew[3] = (byte)((pixelOldShort & 0xf000) >> 12);
                        // convert range
                        for (var j = 0; j < 4; j++)
                        {
                            pixelNew[j] = (byte)((pixelNew[j] << 4) | pixelNew[j]);
                        }
                        pixelNew.CopyTo(BGRA32, i * 4);
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.RGB24:     //test pass
                {
                    /*dwFlags2 = 0x40;
                     * dwRGBBitCount = 0x18;
                     * dwRBitMask = 0xFF;
                     * dwGBitMask = 0xFF00;
                     * dwBBitMask = 0xFF0000;
                     * dwABitMask = 0x0;*/

                    //转BGRA32
                    var BGRA32 = new byte[image_data_size / 3 * 4];
                    for (var i = 0; i < image_data_size / 3; i++)
                    {
                        BGRA32[i * 4]     = image_data[i * 3 + 2];
                        BGRA32[i * 4 + 1] = image_data[i * 3 + 1];
                        BGRA32[i * 4 + 2] = image_data[i * 3 + 0];
                        BGRA32[i * 4 + 3] = 255;
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.RGBA32:     //test pass
                {
                    /*dwFlags2 = 0x41;
                     * dwRGBBitCount = 0x20;
                     * dwRBitMask = 0xFF;
                     * dwGBitMask = 0xFF00;
                     * dwBBitMask = 0xFF0000;
                     * dwABitMask = -16777216;*/

                    //转BGRA32
                    var BGRA32 = new byte[image_data_size];
                    for (var i = 0; i < image_data_size; i += 4)
                    {
                        BGRA32[i]     = image_data[i + 2];
                        BGRA32[i + 1] = image_data[i + 1];
                        BGRA32[i + 2] = image_data[i + 0];
                        BGRA32[i + 3] = image_data[i + 3];
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.ARGB32:    //test pass
                {
                    /*dwFlags2 = 0x41;
                     * dwRGBBitCount = 0x20;
                     * dwRBitMask = 0xFF00;
                     * dwGBitMask = 0xFF0000;
                     * dwBBitMask = -16777216;
                     * dwABitMask = 0xFF;*/

                    //转BGRA32
                    var BGRA32 = new byte[image_data_size];
                    for (var i = 0; i < image_data_size; i += 4)
                    {
                        BGRA32[i]     = image_data[i + 3];
                        BGRA32[i + 1] = image_data[i + 2];
                        BGRA32[i + 2] = image_data[i + 1];
                        BGRA32[i + 3] = image_data[i + 0];
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.RGB565:     //test pass
                {
                    SwapBytesForXbox(sourceFile.platform);

                    dwFlags2      = 0x40;
                    dwRGBBitCount = 0x10;
                    dwRBitMask    = 0xF800;
                    dwGBitMask    = 0x7E0;
                    dwBBitMask    = 0x1F;
                    dwABitMask    = 0x0;
                    break;
                }

                case TextureFormat.R16:     //test pass
                {
                    //转BGRA32
                    var BGRA32 = new byte[image_data_size * 2];
                    for (var i = 0; i < image_data_size; i += 2)
                    {
                        float f = Half.ToHalf(image_data, i);
                        BGRA32[i * 2 + 2] = (byte)Math.Ceiling(f * 255); //R
                        BGRA32[i * 2 + 3] = 255;                         //A
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.DXT1:         //test pass
                case TextureFormat.DXT1Crunched: //test pass
                {
                    SwapBytesForXbox(sourceFile.platform);

                    if (m_MipMap)
                    {
                        dwPitchOrLinearSize = m_Height * m_Width / 2;
                    }
                    dwFlags2      = 0x4;
                    dwFourCC      = 0x31545844;
                    dwRGBBitCount = 0x0;
                    dwRBitMask    = 0x0;
                    dwGBitMask    = 0x0;
                    dwBBitMask    = 0x0;
                    dwABitMask    = 0x0;

                    q_format = QFORMAT.Q_FORMAT_S3TC_DXT1_RGB;
                    break;
                }

                case TextureFormat.DXT5:         //test pass
                case TextureFormat.DXT5Crunched: //test pass
                {
                    SwapBytesForXbox(sourceFile.platform);

                    if (m_MipMap)
                    {
                        dwPitchOrLinearSize = m_Height * m_Width / 2;
                    }
                    dwFlags2      = 0x4;
                    dwFourCC      = 0x35545844;
                    dwRGBBitCount = 0x0;
                    dwRBitMask    = 0x0;
                    dwGBitMask    = 0x0;
                    dwBBitMask    = 0x0;
                    dwABitMask    = 0x0;

                    q_format = QFORMAT.Q_FORMAT_S3TC_DXT5_RGBA;
                    break;
                }

                case TextureFormat.RGBA4444:     //test pass
                {
                    /*dwFlags2 = 0x41;
                     * dwRGBBitCount = 0x10;
                     * dwRBitMask = 0xF000;
                     * dwGBitMask = 0xF00;
                     * dwBBitMask = 0xF0;
                     * dwABitMask = 0xF;*/

                    //转BGRA32
                    var BGRA32 = new byte[image_data_size * 2];
                    for (var i = 0; i < image_data_size / 2; i++)
                    {
                        var pixelNew      = new byte[4];
                        var pixelOldShort = BitConverter.ToUInt16(image_data, i * 2);
                        pixelNew[0] = (byte)((pixelOldShort & 0x00f0) >> 4);
                        pixelNew[1] = (byte)((pixelOldShort & 0x0f00) >> 8);
                        pixelNew[2] = (byte)((pixelOldShort & 0xf000) >> 12);
                        pixelNew[3] = (byte)(pixelOldShort & 0x000f);
                        // convert range
                        for (var j = 0; j < 4; j++)
                        {
                            pixelNew[j] = (byte)((pixelNew[j] << 4) | pixelNew[j]);
                        }
                        pixelNew.CopyTo(BGRA32, i * 4);
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.BGRA32:     //test pass
                {
                    dwFlags2      = 0x41;
                    dwRGBBitCount = 0x20;
                    dwRBitMask    = 0xFF0000;
                    dwGBitMask    = 0xFF00;
                    dwBBitMask    = 0xFF;
                    dwABitMask    = -16777216;
                    break;
                }

                case TextureFormat.RHalf:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_R_16F;
                    glInternalFormat     = KTXHeader.GL_R16F;
                    glBaseInternalFormat = KTXHeader.GL_RED;
                    break;
                }

                case TextureFormat.RGHalf:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_RG_HF;
                    glInternalFormat     = KTXHeader.GL_RG16F;
                    glBaseInternalFormat = KTXHeader.GL_RG;
                    break;
                }

                case TextureFormat.RGBAHalf:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_RGBA_HF;
                    glInternalFormat     = KTXHeader.GL_RGBA16F;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.RFloat:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_R_F;
                    glInternalFormat     = KTXHeader.GL_R32F;
                    glBaseInternalFormat = KTXHeader.GL_RED;
                    break;
                }

                case TextureFormat.RGFloat:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_RG_F;
                    glInternalFormat     = KTXHeader.GL_RG32F;
                    glBaseInternalFormat = KTXHeader.GL_RG;
                    break;
                }

                case TextureFormat.RGBAFloat:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_RGBA_F;
                    glInternalFormat     = KTXHeader.GL_RGBA32F;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.YUY2:     //test pass
                {
                    pvrPixelFormat = 17;
                    break;
                }

                case TextureFormat.RGB9e5Float:
                {
                    q_format = QFORMAT.Q_FORMAT_RGB9_E5;
                    break;
                }

                case TextureFormat.BC4:     //test pass
                {
                    texturetype          = texgenpack_texturetype.RGTC1;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RED_RGTC1;
                    glBaseInternalFormat = KTXHeader.GL_RED;
                    break;
                }

                case TextureFormat.BC5:     //test pass
                {
                    texturetype          = texgenpack_texturetype.RGTC2;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RG_RGTC2;
                    glBaseInternalFormat = KTXHeader.GL_RG;
                    break;
                }

                case TextureFormat.BC6H:     //test pass
                {
                    texturetype          = texgenpack_texturetype.BPTC_FLOAT;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
                    glBaseInternalFormat = KTXHeader.GL_RGB;
                    break;
                }

                case TextureFormat.BC7:     //test pass
                {
                    texturetype          = texgenpack_texturetype.BPTC;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGBA_BPTC_UNORM;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.PVRTC_RGB2:     //test pass
                {
                    pvrPixelFormat       = 0;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
                    glBaseInternalFormat = KTXHeader.GL_RGB;
                    break;
                }

                case TextureFormat.PVRTC_RGBA2:     //test pass
                {
                    pvrPixelFormat       = 1;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.PVRTC_RGB4:     //test pass
                {
                    pvrPixelFormat       = 2;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
                    glBaseInternalFormat = KTXHeader.GL_RGB;
                    break;
                }

                case TextureFormat.PVRTC_RGBA4:     //test pass
                {
                    pvrPixelFormat       = 3;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.ETC_RGB4Crunched:
                case TextureFormat.ETC_RGB4_3DS: //test pass
                case TextureFormat.ETC_RGB4:     //test pass
                {
                    pvrPixelFormat       = 6;
                    glInternalFormat     = KTXHeader.GL_ETC1_RGB8_OES;
                    glBaseInternalFormat = KTXHeader.GL_RGB;
                    break;
                }

                case TextureFormat.ATC_RGB4:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_ATITC_RGB;
                    glInternalFormat     = KTXHeader.GL_ATC_RGB_AMD;
                    glBaseInternalFormat = KTXHeader.GL_RGB;
                    break;
                }

                case TextureFormat.ATC_RGBA8:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_ATC_RGBA_INTERPOLATED_ALPHA;
                    glInternalFormat     = KTXHeader.GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.EAC_R:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_EAC_R_UNSIGNED;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_R11_EAC;
                    glBaseInternalFormat = KTXHeader.GL_RED;
                    break;
                }

                case TextureFormat.EAC_R_SIGNED:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_EAC_R_SIGNED;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_SIGNED_R11_EAC;
                    glBaseInternalFormat = KTXHeader.GL_RED;
                    break;
                }

                case TextureFormat.EAC_RG:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_EAC_RG_UNSIGNED;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RG11_EAC;
                    glBaseInternalFormat = KTXHeader.GL_RG;
                    break;
                }

                case TextureFormat.EAC_RG_SIGNED:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_EAC_RG_SIGNED;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_SIGNED_RG11_EAC;
                    glBaseInternalFormat = KTXHeader.GL_RG;
                    break;
                }

                case TextureFormat.ETC2_RGB:      //test pass
                {
                    pvrPixelFormat       = 22;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGB8_ETC2;
                    glBaseInternalFormat = KTXHeader.GL_RGB;
                    break;
                }

                case TextureFormat.ETC2_RGBA1:      //test pass
                {
                    pvrPixelFormat       = 24;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.ETC2_RGBA8Crunched:
                case TextureFormat.ETC_RGBA8_3DS:   //test pass
                case TextureFormat.ETC2_RGBA8:      //test pass
                {
                    pvrPixelFormat       = 23;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGBA8_ETC2_EAC;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.ASTC_RGB_4x4:     //test pass
                case TextureFormat.ASTC_RGBA_4x4:    //test pass
                {
                    pvrPixelFormat = 27;
                    break;
                }

                case TextureFormat.ASTC_RGB_5x5:     //test pass
                case TextureFormat.ASTC_RGBA_5x5:    //test pass
                {
                    pvrPixelFormat = 29;
                    break;
                }

                case TextureFormat.ASTC_RGB_6x6:     //test pass
                case TextureFormat.ASTC_RGBA_6x6:    //test pass
                {
                    pvrPixelFormat = 31;
                    break;
                }

                case TextureFormat.ASTC_RGB_8x8:     //test pass
                case TextureFormat.ASTC_RGBA_8x8:    //test pass
                {
                    pvrPixelFormat = 34;
                    break;
                }

                case TextureFormat.ASTC_RGB_10x10:     //test pass
                case TextureFormat.ASTC_RGBA_10x10:    //test pass
                {
                    pvrPixelFormat = 38;
                    break;
                }

                case TextureFormat.ASTC_RGB_12x12:     //test pass
                case TextureFormat.ASTC_RGBA_12x12:    //test pass
                {
                    pvrPixelFormat = 40;
                    break;
                }

                case TextureFormat.RG16:     //test pass
                {
                    //转BGRA32
                    var BGRA32 = new byte[image_data_size * 2];
                    for (var i = 0; i < image_data_size; i += 2)
                    {
                        BGRA32[i * 2 + 1] = image_data[i + 1]; //G
                        BGRA32[i * 2 + 2] = image_data[i];     //R
                        BGRA32[i * 2 + 3] = 255;               //A
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.R8:     //test pass
                {
                    //转BGRA32
                    var BGRA32 = new byte[image_data_size * 4];
                    for (var i = 0; i < image_data_size; i++)
                    {
                        BGRA32[i * 4 + 2] = image_data[i]; //R
                        BGRA32[i * 4 + 3] = 255;           //A
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }
                }
            }
            else
            {
                preloadData.InfoText = $"Width: {m_Width}\nHeight: {m_Height}\nFormat: ";

                string type = m_TextureFormat.ToString();
                preloadData.InfoText += type;

                switch (m_TextureFormat)
                {
                case TextureFormat.Alpha8:
                case TextureFormat.ARGB4444:
                case TextureFormat.RGB24:
                case TextureFormat.RGBA32:
                case TextureFormat.ARGB32:
                case TextureFormat.RGB565:
                case TextureFormat.R16:
                case TextureFormat.DXT1:
                case TextureFormat.DXT5:
                case TextureFormat.RGBA4444:
                case TextureFormat.BGRA32:
                case TextureFormat.RG16:
                case TextureFormat.R8:
                    preloadData.extension = ".dds"; break;

                case TextureFormat.DXT1Crunched:
                case TextureFormat.DXT5Crunched:
                case TextureFormat.ETC_RGB4Crunched:
                case TextureFormat.ETC2_RGBA8Crunched:
                    preloadData.extension = ".crn"; break;

                case TextureFormat.YUY2:
                case TextureFormat.PVRTC_RGB2:
                case TextureFormat.PVRTC_RGBA2:
                case TextureFormat.PVRTC_RGB4:
                case TextureFormat.PVRTC_RGBA4:
                case TextureFormat.ETC_RGB4:
                case TextureFormat.ETC2_RGB:
                case TextureFormat.ETC2_RGBA1:
                case TextureFormat.ETC2_RGBA8:
                case TextureFormat.ASTC_RGB_4x4:
                case TextureFormat.ASTC_RGB_5x5:
                case TextureFormat.ASTC_RGB_6x6:
                case TextureFormat.ASTC_RGB_8x8:
                case TextureFormat.ASTC_RGB_10x10:
                case TextureFormat.ASTC_RGB_12x12:
                case TextureFormat.ASTC_RGBA_4x4:
                case TextureFormat.ASTC_RGBA_5x5:
                case TextureFormat.ASTC_RGBA_6x6:
                case TextureFormat.ASTC_RGBA_8x8:
                case TextureFormat.ASTC_RGBA_10x10:
                case TextureFormat.ASTC_RGBA_12x12:
                case TextureFormat.ETC_RGB4_3DS:
                case TextureFormat.ETC_RGBA8_3DS:
                    preloadData.extension = ".pvr"; break;

                case TextureFormat.RHalf:
                case TextureFormat.RGHalf:
                case TextureFormat.RGBAHalf:
                case TextureFormat.RFloat:
                case TextureFormat.RGFloat:
                case TextureFormat.RGBAFloat:
                case TextureFormat.BC4:
                case TextureFormat.BC5:
                case TextureFormat.BC6H:
                case TextureFormat.BC7:
                case TextureFormat.ATC_RGB4:
                case TextureFormat.ATC_RGBA8:
                case TextureFormat.EAC_R:
                case TextureFormat.EAC_R_SIGNED:
                case TextureFormat.EAC_RG:
                case TextureFormat.EAC_RG_SIGNED:
                    preloadData.extension = ".ktx"; break;

                default:
                    preloadData.extension = ".tex"; break;
                }

                switch (m_FilterMode)
                {
                case 0: preloadData.InfoText += "\nFilter Mode: Point "; break;

                case 1: preloadData.InfoText += "\nFilter Mode: Bilinear "; break;

                case 2: preloadData.InfoText += "\nFilter Mode: Trilinear "; break;
                }

                preloadData.InfoText += $"\nAnisotropic level: {m_Aniso}\nMip map bias: {m_MipBias}";

                switch (m_WrapMode)
                {
                case 0: preloadData.InfoText += "\nWrap mode: Repeat"; break;

                case 1: preloadData.InfoText += "\nWrap mode: Clamp"; break;
                }

                preloadData.Text = m_Name;
                if (!string.IsNullOrEmpty(path))
                {
                    preloadData.fullSize = preloadData.Size + (int)size;
                }
            }
        }
示例#18
0
        public AudioClip(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var a_Stream   = preloadData.sourceFile.a_Stream;

            a_Stream.Position = preloadData.Offset;

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags    = a_Stream.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal     = sourceFile.ReadPPtr();
            }

            m_Name = a_Stream.ReadAlignedString(a_Stream.ReadInt32());

            if (sourceFile.version[0] < 5)
            {
                m_Format           = a_Stream.ReadInt32(); //channels?
                m_Type             = a_Stream.ReadInt32();
                m_3D               = a_Stream.ReadBoolean();
                m_UseHardware      = a_Stream.ReadBoolean();
                a_Stream.Position += 2;                                                                       //4 byte alignment

                if (sourceFile.version[0] >= 4 || (sourceFile.version[0] == 3 && sourceFile.version[1] >= 2)) //3.2.0 to 5
                {
                    int m_Stream = a_Stream.ReadInt32();
                    m_Size = a_Stream.ReadInt32();

                    if (m_Stream > 1)
                    {
                        m_Offset = a_Stream.ReadInt32();
                        m_Source = sourceFile.filePath + ".resS";
                    }
                }
                else
                {
                    m_Size = a_Stream.ReadInt32();
                }
            }
            else
            {
                m_LoadType         = a_Stream.ReadInt32();//Decompress on load, Compressed in memory, Streaming
                m_Channels         = a_Stream.ReadInt32();
                m_Frequency        = a_Stream.ReadInt32();
                m_BitsPerSample    = a_Stream.ReadInt32();
                m_Length           = a_Stream.ReadSingle();
                m_IsTrackerFormat  = a_Stream.ReadBoolean();
                a_Stream.Position += 3;
                m_SubsoundIndex    = a_Stream.ReadInt32();
                m_PreloadAudioData = a_Stream.ReadBoolean();
                m_LoadInBackground = a_Stream.ReadBoolean();
                m_Legacy3D         = a_Stream.ReadBoolean();
                a_Stream.Position += 1;
                m_3D = m_Legacy3D;

                m_Source            = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
                m_Source            = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), m_Source.Replace("archive:/", ""));
                m_Offset            = a_Stream.ReadInt64();
                m_Size              = a_Stream.ReadInt64();
                m_CompressionFormat = a_Stream.ReadInt32();
            }

            if (readSwitch)
            {
                if (m_Source == null)
                {
                    m_AudioData = a_Stream.ReadBytes((int)m_Size);
                }
                else if (File.Exists(m_Source) ||
                         File.Exists(m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), Path.GetFileName(m_Source))))
                {
                    BinaryReader reader = new BinaryReader(File.OpenRead(m_Source));
                    reader.BaseStream.Position = m_Offset;
                    m_AudioData = reader.ReadBytes((int)m_Size);
                    reader.Close();
                }
                else
                {
                    EndianStream estream;
                    if (UnityStudio.assetsfileandstream.TryGetValue(Path.GetFileName(m_Source), out estream))
                    {
                        estream.Position = m_Offset;
                        m_AudioData      = estream.ReadBytes((int)m_Size);
                    }
                }
            }
            else
            {
                preloadData.InfoText = "Compression format: ";

                switch (m_Type)
                {
                case 2:
                    preloadData.extension = ".aif";
                    preloadData.InfoText += "AIFF";
                    break;

                case 13:
                    preloadData.extension = ".mp3";
                    preloadData.InfoText += "MP3";
                    break;

                case 14:
                    preloadData.extension = ".ogg";
                    preloadData.InfoText += "Ogg Vorbis";
                    break;

                case 20:
                    preloadData.extension = ".wav";
                    preloadData.InfoText += "WAV";
                    break;

                case 22:     //xbox encoding
                    preloadData.extension = ".wav";
                    preloadData.InfoText += "Xbox360 WAV";
                    break;
                }

                switch (m_CompressionFormat)
                {
                case 0:
                    preloadData.extension = ".fsb";
                    preloadData.InfoText += "PCM";
                    break;

                case 1:
                    preloadData.extension = ".fsb";
                    preloadData.InfoText += "Vorbis";
                    break;

                case 2:
                    preloadData.extension = ".fsb";
                    preloadData.InfoText += "ADPCM";
                    break;

                case 3:
                    preloadData.extension = ".fsb";
                    preloadData.InfoText += "MP3";    //not sure
                    break;

                case 7:
                    preloadData.extension = ".m4a";
                    preloadData.InfoText += "M4a";
                    break;
                }

                if (preloadData.extension == null)
                {
                    preloadData.extension = ".AudioClip";
                    preloadData.InfoText += "Unknown";
                }
                preloadData.InfoText += "\n3D: " + m_3D;

                if (m_Name != "")
                {
                    preloadData.Text = m_Name;
                }
                else
                {
                    preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID;
                }
                preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() });
            }
        }
示例#19
0
        public SkinnedMeshRenderer(AssetPreloadData preloadData)
        {
            var sourceFile = preloadData.sourceFile;
            var version = preloadData.sourceFile.version;
            var a_Stream = preloadData.sourceFile.a_Stream;
            a_Stream.Position = preloadData.Offset;

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags = a_Stream.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal = sourceFile.ReadPPtr();
            }

            m_GameObject = sourceFile.ReadPPtr();
            m_Enabled = a_Stream.ReadBoolean();
            m_CastShadows = a_Stream.ReadBoolean();
            m_ReceiveShadows = a_Stream.ReadBoolean();
            if (sourceFile.version[0] < 5) { m_LightmapIndex = a_Stream.ReadByte(); }
            else
            {
                a_Stream.Position += 5; //suspicious alignment, could be 2 alignments between bools
                m_LightmapIndex = a_Stream.ReadUInt16();
                m_LightmapIndexDynamic = a_Stream.ReadUInt16();
            }

            if (version[0] >= 3) { a_Stream.Position += 16; } //m_LightmapTilingOffset vector4d

            m_Materials = new PPtr[a_Stream.ReadInt32()];
            for (int m = 0; m < m_Materials.Length; m++)
            {
                m_Materials[m] = sourceFile.ReadPPtr();
            }

            if (version[0] < 3) { a_Stream.Position += 16; } //m_LightmapTilingOffset vector4d
            else
            {
                int m_SubsetIndices_size = a_Stream.ReadInt32();
                a_Stream.Position += m_SubsetIndices_size * 4;
                PPtr m_StaticBatchRoot = sourceFile.ReadPPtr();

                if ((version[0] == 3 && version[1] >= 5) || version[0] >= 4)
                {
                    bool m_UseLightProbes = a_Stream.ReadBoolean();
                    a_Stream.Position += 3; //alignment
                    if (version[0] == 5) { int m_ReflectionProbeUsage = a_Stream.ReadInt32(); }
                    //did I ever check if the anchor is conditioned by the bool?
                    PPtr m_LightProbeAnchor = sourceFile.ReadPPtr();
                }

                if (version[0] >= 4 && version[1] >= 3)
                {
                    if (version[1] >= 5) { int m_SortingLayer = a_Stream.ReadInt32(); }
                    else { int m_SortingLayer = a_Stream.ReadInt16(); }
                    int m_SortingOrder = a_Stream.ReadInt16();
                    a_Stream.AlignStream(4);
                }
            }

            int m_Quality = a_Stream.ReadInt32();
            bool m_UpdateWhenOffscreen = a_Stream.ReadBoolean();
            bool m_SkinNormals = a_Stream.ReadBoolean(); //3.1.0 and below
            a_Stream.Position += 2;

            if (version[0] == 2 && version[1] < 6)
            {
                //this would be the only error if mainVersion is not read in time for a unity 2.x game
                PPtr m_DisableAnimationWhenOffscreen = sourceFile.ReadPPtr();
            }

            m_Mesh = sourceFile.ReadPPtr();

            int m_Bones_size = a_Stream.ReadInt32();
            for (int b = 0; b < m_Bones_size; b++)
            {
                PPtr aBone = sourceFile.ReadPPtr();
            }

            if (version[0] < 3)
            {
                int m_BindPose_size = a_Stream.ReadInt32();
                a_Stream.Position += m_BindPose_size * 16 * 4;//Matrix4x4f
            }
            else if (version[0] >= 3 && version[1] >= 4)
            {
                if (version[1] >= 5)
                {
                    PPtr m_RootBone = sourceFile.ReadPPtr();
                }
                //AABB
                float[] m_Center = new float[] { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() };
                float[] m_Extent = new float[] { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() };
                bool m_DirtyAABB = a_Stream.ReadBoolean();
            }
        }
示例#20
0
        public Material(AssetPreloadData preloadData)
        {
            var sourceFile = preloadData.sourceFile;
            var a_Stream   = preloadData.sourceFile.a_Stream;

            a_Stream.Position = preloadData.Offset;

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags    = a_Stream.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal     = sourceFile.ReadPPtr();
            }

            m_Name   = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
            m_Shader = sourceFile.ReadPPtr();

            if (sourceFile.version[0] == 4 && (sourceFile.version[1] >= 2 || (sourceFile.version[1] == 1 && sourceFile.buildType[0] != "a")))
            {
                m_ShaderKeywords = new string[a_Stream.ReadInt32()];
                for (int i = 0; i < m_ShaderKeywords.Length; i++)
                {
                    m_ShaderKeywords[i] = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
                }
            }
            else if (sourceFile.version[0] == 5)
            {
                m_ShaderKeywords = new string[1] {
                    a_Stream.ReadAlignedString(a_Stream.ReadInt32())
                };
                uint m_LightmapFlags = a_Stream.ReadUInt32();
                if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 6) || sourceFile.version[0] > 5)//5.6.0 and up
                {
                    var m_EnableInstancingVariants = a_Stream.ReadBoolean();
                    a_Stream.AlignStream(4);
                }
            }

            if (sourceFile.version[0] > 4 || (sourceFile.version[0] == 4 && sourceFile.version[1] >= 3))
            {
                m_CustomRenderQueue = a_Stream.ReadInt32();
            }

            if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 1)
            {
                string[][] stringTagMap = new string[a_Stream.ReadInt32()][];
                for (int i = 0; i < stringTagMap.Length; i++)
                {
                    stringTagMap[i] = new string[2] {
                        a_Stream.ReadAlignedString(a_Stream.ReadInt32()), a_Stream.ReadAlignedString(a_Stream.ReadInt32())
                    };
                }
            }
            //disabledShaderPasses
            if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 6) || sourceFile.version[0] > 5)//5.6.0 and up
            {
                var size = a_Stream.ReadInt32();
                for (int i = 0; i < size; i++)
                {
                    a_Stream.ReadAlignedString(a_Stream.ReadInt32());
                }
            }
            //m_SavedProperties
            m_TexEnvs = new TexEnv[a_Stream.ReadInt32()];
            for (int i = 0; i < m_TexEnvs.Length; i++)
            {
                TexEnv m_TexEnv = new TexEnv()
                {
                    name      = a_Stream.ReadAlignedString(a_Stream.ReadInt32()),
                    m_Texture = sourceFile.ReadPPtr(),
                    m_Scale   = new float[2] {
                        a_Stream.ReadSingle(), a_Stream.ReadSingle()
                    },
                    m_Offset = new float[2] {
                        a_Stream.ReadSingle(), a_Stream.ReadSingle()
                    }
                };
                m_TexEnvs[i] = m_TexEnv;
            }

            m_Floats = new strFloatPair[a_Stream.ReadInt32()];
            for (int i = 0; i < m_Floats.Length; i++)
            {
                strFloatPair m_Float = new strFloatPair()
                {
                    first  = a_Stream.ReadAlignedString(a_Stream.ReadInt32()),
                    second = a_Stream.ReadSingle()
                };
                m_Floats[i] = m_Float;
            }

            m_Colors = new strColorPair[a_Stream.ReadInt32()];
            for (int i = 0; i < m_Colors.Length; i++)
            {
                strColorPair m_Color = new strColorPair()
                {
                    first  = a_Stream.ReadAlignedString(a_Stream.ReadInt32()),
                    second = new float[4] {
                        a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle()
                    }
                };
                m_Colors[i] = m_Color;
            }
        }
示例#21
0
        public Sprite(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var a_Stream   = preloadData.sourceFile.a_Stream;

            a_Stream.Position = preloadData.Offset;

            m_Name = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
            if (readSwitch)
            {
                //Rectf m_Rect
                var m_Rect = new RectangleF(a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle());
                //Vector2f m_Offset
                a_Stream.Position += 8;
                if (sourceFile.version[0] > 4 || (sourceFile.version[0] == 4 && sourceFile.version[1] >= 2)) //4.2 and up
                {
                    //Vector4f m_Border
                    a_Stream.Position += 16;
                }

                var m_PixelsToUnits = a_Stream.ReadSingle();
                if (sourceFile.version[0] > 5 || (sourceFile.version[0] == 5 && sourceFile.version[1] >= 5)) //5.5 and up
                {
                    //Vector2f m_Pivot
                    a_Stream.Position += 8;
                }

                var m_Extrude = a_Stream.ReadUInt32();
                if (sourceFile.version[0] > 5 || (sourceFile.version[0] == 5 && sourceFile.version[1] >= 1)) //5.1 and up
                {
                    var m_IsPolygon = a_Stream.ReadBoolean();
                    a_Stream.AlignStream(4);
                }

                if (sourceFile.version[0] >= 2017) //2017 and up
                {
                    //pair m_RenderDataKey
                    a_Stream.Position += 24;
                    //vector m_AtlasTags
                    var size = a_Stream.ReadInt32();
                    for (int i = 0; i < size; i++)
                    {
                        var data = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
                    }

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

                //SpriteRenderData m_RD
                //  PPtr<Texture2D> texture
                texture = sourceFile.ReadPPtr();
                //  PPtr<Texture2D> alphaTexture
                if (sourceFile.version[0] >= 5) //5.0 and up
                {
                    var alphaTexture = sourceFile.ReadPPtr();
                }

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

                    //  vector m_IndexBuffer
                    size = a_Stream.ReadInt32();
                    a_Stream.Position += size; //UInt8 data
                    a_Stream.AlignStream(4);
                    //  VertexData m_VertexData
                    var m_CurrentChannels = a_Stream.ReadInt32();
                    var m_VertexCount     = a_Stream.ReadUInt32();
                    //      vector m_Channels
                    size = a_Stream.ReadInt32();
                    a_Stream.Position += size * 4; //ChannelInfo data
                    //      TypelessData m_DataSize
                    size = a_Stream.ReadInt32();
                    a_Stream.Position += size; //UInt8 data
                    a_Stream.AlignStream(4);
                }
                else
                {
                    //  vector vertices
                    var size = a_Stream.ReadInt32();
                    for (int i = 0; i < size; i++)
                    {
                        //SpriteVertex data
                        a_Stream.Position += 12;                                                                     //Vector3f pos
                        if (sourceFile.version[0] < 4 || (sourceFile.version[0] == 4 && sourceFile.version[1] <= 1)) //4.1 and down
                        {
                            a_Stream.Position += 8;                                                                  //Vector2f uv
                        }
                    }

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

                //  Rectf textureRect
                textureRect = new RectangleF(a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle());
                //  Vector2f textureRectOffset
                //  Vector2f atlasRectOffset - 5.6 and up
                //  unsigned int settingsRaw
                //  Vector4f uvTransform - 4.2 and up
                //  float downscaleMultiplier - 2017 and up
                //vector m_PhysicsShape - 2017 and up
            }
            else
            {
                preloadData.extension = ".png";
                preloadData.Text      = m_Name;
            }
        }
示例#22
0
        public Shader(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var a_Stream   = preloadData.sourceFile.a_Stream;

            a_Stream.Position = preloadData.Offset;

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags    = a_Stream.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal     = sourceFile.ReadPPtr();
            }

            m_Name = a_Stream.ReadAlignedString(a_Stream.ReadInt32());

            if (readSwitch)
            {
                if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 5 || sourceFile.version[0] > 5)//5.5.0 and up
                {
                    var str = (string)ShaderResource.ResourceManager.GetObject($"Shader{sourceFile.version[0]}{sourceFile.version[1]}");
                    if (str == null)
                    {
                        str = preloadData.ViewStruct();
                        if (str == null)
                        {
                            m_Script = Encoding.UTF8.GetBytes("Serialized Shader can't be read");
                        }
                        else
                        {
                            m_Script = Encoding.UTF8.GetBytes(str);
                        }
                    }
                    else
                    {
                        a_Stream.Position = preloadData.Offset;
                        var sb      = new StringBuilder();
                        var members = new JavaScriptSerializer().Deserialize <List <ClassMember> >(str);
                        ClassStructHelper.ReadClassStruct(sb, members, a_Stream);
                        m_Script = Encoding.UTF8.GetBytes(sb.ToString());
                        //m_Script = ReadSerializedShader(members, a_Stream);
                    }
                }
                else
                {
                    m_Script = a_Stream.ReadBytes(a_Stream.ReadInt32());
                    if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 3) //5.3 - 5.4
                    {
                        a_Stream.AlignStream(4);
                        a_Stream.ReadAlignedString(a_Stream.ReadInt32());//m_PathName
                        var decompressedSize  = a_Stream.ReadUInt32();
                        var m_SubProgramBlob  = a_Stream.ReadBytes(a_Stream.ReadInt32());
                        var decompressedBytes = new byte[decompressedSize];
                        using (var mstream = new MemoryStream(m_SubProgramBlob))
                        {
                            var decoder = new Lz4DecoderStream(mstream);
                            decoder.Read(decompressedBytes, 0, (int)decompressedSize);
                            decoder.Dispose();
                        }
                        m_Script = m_Script.Concat(decompressedBytes.ToArray()).ToArray();
                    }
                }
            }
            else
            {
                preloadData.extension = ".txt";
                preloadData.Text      = m_Name;
            }
        }
示例#23
0
        public Shader(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var a_Stream   = preloadData.sourceFile.a_Stream;

            a_Stream.Position = preloadData.Offset;

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags    = a_Stream.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal     = sourceFile.ReadPPtr();
            }

            m_Name = a_Stream.ReadAlignedString(a_Stream.ReadInt32());

            if (readSwitch)
            {
                if (true)
                {
                    //Assume as unity 5.6 or greater.
                    var str1 = preloadData.ViewStruct();
                    if (str1 == null)
                    {
                        m_Script = Encoding.UTF8.GetBytes("Serialized Shader can't be read");
                    }
                    else
                    {
                        m_Script = Encoding.UTF8.GetBytes(str1);
                    }
                    return;
                }

                /**
                 * SHORTCUT:
                 * System.Resources.MissingManifestResourceException: Could not find
                 * any resources appropriate for the specified culture or the neutral
                 * culture.  Make sure "Unity_Studio.ShaderResource.resources" was
                 * correctly embedded or linked into assembly "adebug" at compile
                 * time, or that all the satellite assemblies required are loadable
                 * and fully signed.
                 */
                if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 5 || sourceFile.version[0] > 5)//5.5.0 and up
                {
                    var str = (string)ShaderResource.ResourceManager.GetObject($"Shader{sourceFile.version[0]}{sourceFile.version[1]}");
                    if (str == null)
                    {
                        str = preloadData.ViewStruct();
                        if (str == null)
                        {
                            m_Script = Encoding.UTF8.GetBytes("Serialized Shader can't be read");
                        }
                        else
                        {
                            m_Script = Encoding.UTF8.GetBytes(str);
                        }
                    }
                    else
                    {
                        a_Stream.Position = preloadData.Offset;
                        var sb      = new StringBuilder();
                        var members = new JavaScriptSerializer().Deserialize <List <ClassMember> >(str);
                        ClassStructHelper.ReadClassStruct(sb, members, a_Stream);
                        m_Script = Encoding.UTF8.GetBytes(sb.ToString());
                        //m_Script = ReadSerializedShader(members, a_Stream);
                    }
                }
                else
                {
                    m_Script = a_Stream.ReadBytes(a_Stream.ReadInt32());
                    if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 3) //5.3 - 5.4
                    {
                        a_Stream.AlignStream(4);
                        a_Stream.ReadAlignedString(a_Stream.ReadInt32());//m_PathName
                        var decompressedSize  = a_Stream.ReadUInt32();
                        var m_SubProgramBlob  = a_Stream.ReadBytes(a_Stream.ReadInt32());
                        var decompressedBytes = new byte[decompressedSize];
                        using (var mstream = new MemoryStream(m_SubProgramBlob))
                        {
                            var decoder = new Lz4DecoderStream(mstream);
                            decoder.Read(decompressedBytes, 0, (int)decompressedSize);
                            decoder.Dispose();
                        }
                        m_Script = m_Script.Concat(decompressedBytes.ToArray()).ToArray();
                    }
                }
            }
            else
            {
                preloadData.extension = ".txt";
                preloadData.Text      = m_Name;
            }
        }
示例#24
0
        public string uniqueID = "0";//this way file and folder TreeNodes will be treated as FBX scene

        public GameObject(AssetPreloadData preloadData)
        {
            if (preloadData != null)
            {
                var sourceFile = preloadData.sourceFile;
                var a_Stream   = preloadData.sourceFile.a_Stream;
                a_Stream.Position = preloadData.Offset;

                uniqueID = preloadData.uniqueID;

                if (sourceFile.platform == -2)
                {
                    a_Stream.ReadUInt32();
                    sourceFile.ReadPPtr();
                    sourceFile.ReadPPtr();
                }

                int m_Component_size = a_Stream.ReadInt32();
                for (int j = 0; j < m_Component_size; j++)
                {
                    int m_Component_type = a_Stream.ReadInt32();

                    switch (m_Component_type)
                    {
                    case 4:
                        m_Transform = sourceFile.ReadPPtr();
                        break;

                    case 23:
                        m_Renderer = sourceFile.ReadPPtr();
                        break;

                    case 33:
                        m_MeshFilter = sourceFile.ReadPPtr();
                        break;

                    case 137:
                        m_SkinnedMeshRenderer = sourceFile.ReadPPtr();
                        break;

                    default:
                        sourceFile.ReadPPtr();
                        break;
                    }
                }

                m_Layer = a_Stream.ReadInt32();
                int namesize = a_Stream.ReadInt32();
                m_Name = a_Stream.ReadAlignedString(namesize);
                if (m_Name == "")
                {
                    m_Name = "GameObject #" + uniqueID;
                }
                m_Tag      = a_Stream.ReadUInt16();
                m_IsActive = a_Stream.ReadBoolean();

                Text = m_Name;
                //name should be unique
                Name = uniqueID;
            }
        }
示例#25
0
        public Material(AssetPreloadData preloadData)
        {
            var sourceFile = preloadData.sourceFile;
            var a_Stream = preloadData.sourceFile.a_Stream;
            a_Stream.Position = preloadData.Offset;

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags = a_Stream.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal = sourceFile.ReadPPtr();
            }

            m_Name = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
            m_Shader = sourceFile.ReadPPtr();

            if (sourceFile.version[0] == 4 && (sourceFile.version[1] >= 2 || (sourceFile.version[1] == 1 && sourceFile.buildType[0] != "a")))
            {
                m_ShaderKeywords = new string[a_Stream.ReadInt32()];
                for (int i = 0; i < m_ShaderKeywords.Length; i++)
                {
                    m_ShaderKeywords[i] = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
                }
            }
            else if (sourceFile.version[0] == 5)
            {
                m_ShaderKeywords = new string[1] { a_Stream.ReadAlignedString(a_Stream.ReadInt32()) };
                uint m_LightmapFlags = a_Stream.ReadUInt32();
            }

            if (sourceFile.version[0] > 4 || (sourceFile.version[0] == 4 && sourceFile.version[1] >= 3)) { m_CustomRenderQueue = a_Stream.ReadInt32(); }

            if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 1)
            {
                string[][] stringTagMap = new string[a_Stream.ReadInt32()][];
                for (int i = 0; i < stringTagMap.Length; i++)
                {
                    stringTagMap[i] = new string[2] { a_Stream.ReadAlignedString(a_Stream.ReadInt32()), a_Stream.ReadAlignedString(a_Stream.ReadInt32()) };
                }
            }

                //m_SavedProperties
                m_TexEnvs = new TexEnv[a_Stream.ReadInt32()];
            for (int i = 0; i < m_TexEnvs.Length; i++)
            {
                TexEnv m_TexEnv = new TexEnv()
                {
                    name = a_Stream.ReadAlignedString(a_Stream.ReadInt32()),
                    m_Texture = sourceFile.ReadPPtr(),
                    m_Scale = new float[2] { a_Stream.ReadSingle(), a_Stream.ReadSingle() },
                    m_Offset = new float[2] { a_Stream.ReadSingle(), a_Stream.ReadSingle() }
                };
                m_TexEnvs[i] = m_TexEnv;
            }

            m_Floats = new strFloatPair[a_Stream.ReadInt32()];
            for (int i = 0; i < m_Floats.Length; i++)
            {
                strFloatPair m_Float = new strFloatPair()
                {
                    first = a_Stream.ReadAlignedString(a_Stream.ReadInt32()),
                    second = a_Stream.ReadSingle()
                };
                m_Floats[i] = m_Float;
            }

            m_Colors = new strColorPair[a_Stream.ReadInt32()];
            for (int i = 0; i < m_Colors.Length; i++)
            {
                strColorPair m_Color = new strColorPair()
                {
                    first = a_Stream.ReadAlignedString(a_Stream.ReadInt32()),
                    second = new float[4] { a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle(), a_Stream.ReadSingle() }
                };
                m_Colors[i] = m_Color;
            }
        }
示例#26
0
        public Shader(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var a_Stream   = preloadData.sourceFile.a_Stream;

            a_Stream.Position     = preloadData.Offset;
            preloadData.extension = ".txt";

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags    = a_Stream.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal     = sourceFile.ReadPPtr();
            }

            m_Name = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
            if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 5) || sourceFile.version[0] > 5)
            {
                if (readSwitch)
                {
                    string str;
                    if ((str = preloadData.ViewStruct()) != null)
                    {
                        m_Script = Encoding.UTF8.GetBytes(preloadData.ViewStruct());
                    }
                    else
                    {
                        m_Script = Encoding.UTF8.GetBytes("Serialized Shader can't be read");
                    }
                }
                else
                {
                    if (m_Name != "")
                    {
                        preloadData.Text = m_Name;
                    }
                    else
                    {
                        preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID;
                    }
                    preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() });
                }
            }
            else
            {
                int m_Script_size = a_Stream.ReadInt32();

                if (readSwitch) //asset is read for preview or export
                {
                    m_Script = new byte[m_Script_size];
                    a_Stream.Read(m_Script, 0, m_Script_size);

                    if (m_Script[0] == 93)
                    {
                        m_Script = SevenZip.Compression.LZMA.SevenZipHelper.Decompress(m_Script);
                    }
                    if (m_Script[0] == 60 || (m_Script[0] == 239 && m_Script[1] == 187 && m_Script[2] == 191 && m_Script[3] == 60))
                    {
                        preloadData.extension = ".xml";
                    }
                }
                else
                {
                    byte lzmaTest = a_Stream.ReadByte();

                    a_Stream.Position += m_Script_size - 1;

                    if (m_Name != "")
                    {
                        preloadData.Text = m_Name;
                    }
                    else
                    {
                        preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID;
                    }
                    preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() });
                }
                a_Stream.AlignStream(4);
                m_PathName = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
            }
        }