Пример #1
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);
        }
Пример #2
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)//5.0 and up
            {
                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();
                    //var m_DoubleSidedGI = a_Stream.ReadBoolean();//2017.x
                    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 || sourceFile.version[0] > 5)//5.1 and up
            {
                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;
            }
        }
Пример #3
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() });
            }
        }
Пример #4
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();
                    var asize = m_Size % 4 != 0 ? m_Size + 4 - m_Size % 4 : m_Size;
                    if (m_Stream > 1 && preloadData.Size + preloadData.Offset - a_Stream.Position > asize)
                    {
                        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
            {
                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() });
            }
        }