Beispiel #1
0
        public AnimatorController(ObjectReader reader) : base(reader)
        {
            var m_ControllerSize = reader.ReadUInt32();
            var m_Controller     = new ControllerConstant(reader);

            int tosSize = reader.ReadInt32();
            var m_TOS   = new List <KeyValuePair <uint, string> >(tosSize);

            for (int i = 0; i < tosSize; i++)
            {
                m_TOS.Add(new KeyValuePair <uint, string>(reader.ReadUInt32(), reader.ReadAlignedString()));
            }

            int numClips = reader.ReadInt32();

            m_AnimationClips = new PPtr <AnimationClip> [numClips];
            for (int i = 0; i < numClips; i++)
            {
                m_AnimationClips[i] = new PPtr <AnimationClip>(reader);
            }
        }
Beispiel #2
0
        public SkinnedMeshRenderer(ObjectReader reader) : base(reader)
        {
            int m_Quality             = reader.ReadInt32();
            var m_UpdateWhenOffscreen = reader.ReadBoolean();
            var m_SkinNormals         = reader.ReadBoolean(); //3.1.0 and below

            reader.AlignStream(4);

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

            m_Mesh = new PPtr <Mesh>(reader);

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

            if (version[0] < 3)
            {
                int m_BindPose = reader.ReadInt32();
                reader.Position += m_BindPose * 16 * 4;//Matrix4x4f
            }
            else
            {
                if (version[0] > 4 || (version[0] == 4 && version[1] >= 3))//4.3 and up
                {
                    int numBSWeights = reader.ReadInt32();
                    m_BlendShapeWeights = new List <float>(numBSWeights);
                    for (int i = 0; i < numBSWeights; i++)
                    {
                        m_BlendShapeWeights.Add(reader.ReadSingle());
                    }
                }
            }
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public GenericBinding(ObjectReader reader)
        {
            var version = reader.version;

            path      = reader.ReadUInt32();
            attribute = reader.ReadUInt32();
            script    = new PPtr <Object>(reader);
            if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up
            {
                typeID = (ClassIDType)reader.ReadInt32();
            }
            else
            {
                typeID = (ClassIDType)reader.ReadUInt16();
            }
            customType  = reader.ReadByte();
            isPPtrCurve = reader.ReadByte();
            if (version[0] > 2022 || (version[0] == 2022 && version[1] >= 1)) //2022.1 and up
            {
                isIntCurve = reader.ReadByte();
            }
            reader.AlignStream();
        }
Beispiel #5
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 reader     = preloadData.Reader;

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

            m_GameObject    = sourceFile.ReadPPtr();
            m_LocalRotation = new[] { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() };
            m_LocalPosition = new[] { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() };
            m_LocalScale    = new[] { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() };
            int m_ChildrenCount = reader.ReadInt32();

            for (int j = 0; j < m_ChildrenCount; j++)
            {
                m_Children.Add(sourceFile.ReadPPtr());
            }
            m_Father = sourceFile.ReadPPtr();
        }
Beispiel #6
0
        public TextAsset(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var reader     = preloadData.Reader;

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

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

            if (readSwitch)
            {
                m_Script = reader.ReadBytes(reader.ReadInt32());
            }
            else
            {
                preloadData.extension = ".txt";
                preloadData.Text      = m_Name;
            }
        }
Beispiel #7
0
 protected Component(ObjectReader reader) : base(reader)
 {
     m_GameObject = reader.ReadPPtr();
 }
Beispiel #8
0
 public PPtrKeyframe(ObjectReader reader)
 {
     time  = reader.ReadSingle();
     value = reader.ReadPPtr();
 }
Beispiel #9
0
        public Texture2D(AssetPreloadData preloadData, bool readSwitch)
        {
            this.preloadData = preloadData;
            var sourceFile = preloadData.sourceFile;
            var reader     = preloadData.InitReader();
            var version    = sourceFile.version;

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

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

            if (version[0] < 5 || (version[0] == 5 && version[1] < 2))
            {
                m_MipMap = reader.ReadBoolean();
            }
            else
            {
                m_MipCount = reader.ReadInt32();
            }

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

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

            image_data_size = reader.ReadInt32();

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

            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 resourceReader = new BinaryReader(File.OpenRead(resourceFilePath)))
                        {
                            resourceReader.BaseStream.Position = offset;
                            image_data = resourceReader.ReadBytes(image_data_size);
                        }
                    }
                    else
                    {
                        if (Studio.resourceFileReaders.TryGetValue(resourceFileName.ToUpper(), out var resourceReader))
                        {
                            resourceReader.Position = offset;
                            image_data = resourceReader.ReadBytes(image_data_size);
                        }
                        else
                        {
                            MessageBox.Show($"can't find the resource file {resourceFileName}");
                        }
                    }
                }
                else
                {
                    image_data = reader.ReadBytes(image_data_size);
                }
            }
            else
            {
                preloadData.InfoText = $"Width: {m_Width}\nHeight: {m_Height}\nFormat: {m_TextureFormat}";

                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;
                }
            }
        }
Beispiel #10
0
        private static void DumpType(TypeSig typeSig, StringBuilder sb, ObjectReader reader, string name, int indent, bool isRoot = false, bool align = true)
        {
            var typeDef = typeSig.ToTypeDefOrRef().ResolveTypeDefThrow();

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

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

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

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

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

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

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

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

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

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

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

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

                    if (flag)
                    {
                        if (fieldDef.FieldType.IsGenericParameter)
                        {
                            for (var i = 0; i < typeDef.GenericParameters.Count; i++)
                            {
                                var g = typeDef.GenericParameters[i];
                                if (g.FullName == fieldDef.FieldType.FullName)
                                {
                                    var type = ((GenericInstSig)typeSig).GenericArguments[i];
                                    DumpType(type, sb, reader, fieldDef.Name, indent + 1);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            DumpType(fieldDef.FieldType, sb, reader, fieldDef.Name, indent + 1);
                        }
                    }
                }
            }
        }
Beispiel #11
0
        public SpriteRenderData(ObjectReader reader)
        {
            var version = reader.version;

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

            if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up
            {
                var m_SubMeshesSize = reader.ReadInt32();
                m_SubMeshes = new SubMesh[m_SubMeshesSize];
                for (int i = 0; i < m_SubMeshesSize; i++)
                {
                    m_SubMeshes[i] = new SubMesh(reader);
                }

                m_IndexBuffer = reader.ReadBytes(reader.ReadInt32());
                reader.AlignStream(4);

                m_VertexData = new VertexData(reader);
            }
            else
            {
                var verticesSize = reader.ReadInt32();
                vertices = new SpriteVertex[verticesSize];
                for (int i = 0; i < verticesSize; i++)
                {
                    vertices[i] = new SpriteVertex(reader);
                }

                indices = reader.ReadUInt16Array(reader.ReadInt32());
                reader.AlignStream(4);
            }

            if (version[0] >= 2018) //2018 and up
            {
                m_Bindpose = reader.ReadMatrixArray(reader.ReadInt32());

                if (version[0] == 2018 && version[1] < 2) //2018.2 down
                {
                    var m_SourceSkinSize = reader.ReadInt32();
                    for (int i = 0; i < m_SourceSkinSize; i++)
                    {
                        m_SourceSkin[i] = new BoneWeights4(reader);
                    }
                }
            }

            textureRect       = reader.ReadRectangleF();
            textureRectOffset = reader.ReadVector2();
            if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up
            {
                atlasRectOffset = reader.ReadVector2();
            }

            settingsRaw = new SpriteSettings(reader);
            if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up
            {
                uvTransform = reader.ReadVector4();
            }

            if (version[0] >= 2017) //2017 and up
            {
                downscaleMultiplier = reader.ReadSingle();
            }
        }
Beispiel #12
0
 public MonoBehaviour(AssetPreloadData preloadData) : base(preloadData)
 {
     m_Script = sourceFile.ReadPPtr();
     m_Name   = reader.ReadAlignedString();
 }
 public AnimationClipOverride(ObjectReader reader)
 {
     m_OriginalClip = new PPtr <AnimationClip>(reader);
     m_OverrideClip = new PPtr <AnimationClip>(reader);
 }
Beispiel #14
0
 public PPtrKeyframe(ObjectReader reader)
 {
     time  = reader.ReadSingle();
     value = new PPtr <Object>(reader);
 }
Beispiel #15
0
        public Material(ObjectReader reader) : base(reader)
        {
            m_Shader = reader.ReadPPtr();

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

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

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

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

            m_Colors = new strColorPair[reader.ReadInt32()];
            for (int i = 0; i < m_Colors.Length; i++)
            {
                strColorPair m_Color = new strColorPair()
                {
                    first  = reader.ReadAlignedString(),
                    second = new[] { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }
                };
                m_Colors[i] = m_Color;
            }
        }
Beispiel #16
0
 public MonoBehaviour(ObjectReader reader) : base(reader)
 {
     m_Script = reader.ReadPPtr();
     m_Name   = reader.ReadAlignedString();
 }
Beispiel #17
0
        public Sprite(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var reader     = preloadData.InitReader();
            var version    = sourceFile.version;

            m_Name = reader.ReadAlignedString();
            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] >= 5)) //4.5 and up
                {
                    //Vector4f m_Border
                    reader.Position += 16;
                }

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

                    //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
                    if (version[0] < 2018)//2018 down
                    {
                        var m_CurrentChannels = reader.ReadInt32();
                    }
                    var m_VertexCount = reader.ReadUInt32();
                    //      vector m_Channels
                    size             = reader.ReadInt32();
                    reader.Position += size * 4; //ChannelInfo data
                    //      TypelessData m_DataSize
                    size             = reader.ReadInt32();
                    reader.Position += size; //UInt8 data
                    reader.AlignStream(4);

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

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

                //  Rectf textureRect
                textureRect = 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.5 and up
                if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up
                {
                    reader.Position += 16;
                }
                if (version[0] >= 2017) //2017 and up
                {
                    //  float downscaleMultiplier - 2017 and up
                    reader.Position += 4;
                    //vector m_PhysicsShape - 2017 and up
                    var m_PhysicsShape_size = reader.ReadInt32();
                    m_PhysicsShape = new PointF[m_PhysicsShape_size][];
                    for (int i = 0; i < m_PhysicsShape_size; i++)
                    {
                        var data_size = reader.ReadInt32();
                        //Vector2f
                        m_PhysicsShape[i] = new PointF[data_size];
                        for (int j = 0; j < data_size; j++)
                        {
                            m_PhysicsShape[i][j] = new PointF(reader.ReadSingle(), reader.ReadSingle());
                        }
                    }
                }
                //vector m_Bones 2018 and up
            }
            else
            {
                preloadData.Text = m_Name;
            }
        }
        public Font(ObjectReader reader) : base(reader)
        {
            if ((version[0] == 5 && version[1] >= 5) || version[0] > 5)//5.5 and up
            {
                var m_LineSpacing         = reader.ReadSingle();
                var m_DefaultMaterial     = new PPtr <Material>(reader);
                var m_FontSize            = reader.ReadSingle();
                var m_Texture             = new PPtr <Texture>(reader);
                var m_AsciiStartOffset    = reader.ReadInt32();
                var m_Tracking            = reader.ReadSingle();
                var m_CharacterSpacing    = reader.ReadInt32();
                var m_CharacterPadding    = reader.ReadInt32();
                var m_ConvertCase         = reader.ReadInt32();
                var m_CharacterRects_size = reader.ReadInt32();
                for (var i = 0; i < m_CharacterRects_size; i++)
                {
                    reader.Position += 44;//CharacterInfo data 41
                }
                var m_KerningValues_size = reader.ReadInt32();
                for (var i = 0; i < m_KerningValues_size; i++)
                {
                    reader.Position += 8;
                }
                var m_PixelScale    = reader.ReadSingle();
                var m_FontData_size = reader.ReadInt32();
                if (m_FontData_size > 0)
                {
                    m_FontData = reader.ReadBytes(m_FontData_size);
                }
            }
            else
            {
                var m_AsciiStartOffset = reader.ReadInt32();

                if (version[0] <= 3)
                {
                    var m_FontCountX = reader.ReadInt32();
                    var m_FontCountY = reader.ReadInt32();
                }

                var m_Kerning     = reader.ReadSingle();
                var m_LineSpacing = reader.ReadSingle();

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

                var m_ConvertCase     = reader.ReadInt32();
                var m_DefaultMaterial = new PPtr <Material>(reader);

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

                    if (version[0] >= 4)
                    {
                        var flipped = reader.ReadBoolean();
                        reader.AlignStream();
                    }
                }

                var m_Texture = new PPtr <Texture>(reader);

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

                if (version[0] <= 3)
                {
                    var m_GridFont = reader.ReadBoolean();
                    reader.AlignStream();
                }
                else
                {
                    var m_PixelScale = reader.ReadSingle();
                }

                var m_FontData_size = reader.ReadInt32();
                if (m_FontData_size > 0)
                {
                    m_FontData = reader.ReadBytes(m_FontData_size);
                }
            }
        }
Beispiel #19
0
        public Texture2D(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());
            m_Width             = a_Stream.ReadInt32();
            m_Height            = a_Stream.ReadInt32();
            m_CompleteImageSize = a_Stream.ReadInt32();
            m_TextureFormat     = a_Stream.ReadInt32();

            if (sourceFile.version[0] < 5 || (sourceFile.version[0] == 5 && sourceFile.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 and up
            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 (sourceFile.version[0] >= 3)
            {
                m_LightmapFormat = a_Stream.ReadInt32();
                if (sourceFile.version[0] >= 4 || sourceFile.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 (readSwitch)
            {
                image_data = new byte[image_data_size];
                a_Stream.Read(image_data, 0, image_data_size);

                switch (m_TextureFormat)
                {
                case 1:     //Alpha8
                {
                    dwFlags2      = 0x2;
                    dwRGBBitCount = 0x8;
                    dwRBitMask    = 0x0;
                    dwGBitMask    = 0x0;
                    dwBBitMask    = 0x0;
                    dwABitMask    = 0xFF;
                    break;
                }

                case 2:                            //A4R4G4B4
                {
                    if (sourceFile.platform == 11) //swap bytes for Xbox confirmed, PS3 not encountered
                    {
                        for (int i = 0; i < (image_data_size / 2); i++)
                        {
                            byte b0 = image_data[i * 2];
                            image_data[i * 2]     = image_data[i * 2 + 1];
                            image_data[i * 2 + 1] = b0;
                        }
                    }
                    else if (sourceFile.platform == 13)         //swap bits for android
                    {
                        for (int i = 0; i < (image_data_size / 2); i++)
                        {
                            byte[] argb = BitConverter.GetBytes((BitConverter.ToInt32((new byte[4] {
                                    image_data[i * 2], image_data[i * 2 + 1], image_data[i * 2], image_data[i * 2 + 1]
                                }), 0)) >> 4);
                            image_data[i * 2]     = argb[0];
                            image_data[i * 2 + 1] = argb[1];
                        }
                    }

                    dwFlags2      = 0x41;
                    dwRGBBitCount = 0x10;
                    dwRBitMask    = 0xF00;
                    dwGBitMask    = 0xF0;
                    dwBBitMask    = 0xF;
                    dwABitMask    = 0xF000;
                    break;
                }

                case 3:     //B8G8R8 //confirmed on X360, iOS //PS3 unsure
                {
                    for (int i = 0; i < (image_data_size / 3); i++)
                    {
                        byte b0 = image_data[i * 3];
                        image_data[i * 3] = image_data[i * 3 + 2];
                        //image_data[i * 3 + 1] stays the same
                        image_data[i * 3 + 2] = b0;
                    }

                    dwFlags2      = 0x40;
                    dwRGBBitCount = 0x18;
                    dwRBitMask    = 0xFF0000;
                    dwGBitMask    = 0xFF00;
                    dwBBitMask    = 0xFF;
                    dwABitMask    = 0x0;
                    break;
                }

                case 4:     //G8R8A8B8 //confirmed on X360, iOS
                {
                    for (int i = 0; i < (image_data_size / 4); i++)
                    {
                        byte b0 = image_data[i * 4];
                        image_data[i * 4] = image_data[i * 4 + 2];
                        //image_data[i * 4 + 1] stays the same
                        image_data[i * 4 + 2] = b0;
                        //image_data[i * 4 + 3] stays the same
                    }

                    dwFlags2      = 0x41;
                    dwRGBBitCount = 0x20;
                    dwRBitMask    = 0xFF0000;
                    dwGBitMask    = 0xFF00;
                    dwBBitMask    = 0xFF;
                    dwABitMask    = -16777216;
                    break;
                }

                case 5:     //B8G8R8A8 //confirmed on X360, PS3, Web, iOS
                {
                    for (int i = 0; i < (image_data_size / 4); i++)
                    {
                        byte b0 = image_data[i * 4];
                        byte b1 = image_data[i * 4 + 1];
                        image_data[i * 4]     = image_data[i * 4 + 3];
                        image_data[i * 4 + 1] = image_data[i * 4 + 2];
                        image_data[i * 4 + 2] = b1;
                        image_data[i * 4 + 3] = b0;
                    }

                    dwFlags2      = 0x41;
                    dwRGBBitCount = 0x20;
                    dwRBitMask    = 0xFF0000;
                    dwGBitMask    = 0xFF00;
                    dwBBitMask    = 0xFF;
                    dwABitMask    = -16777216;
                    break;
                }

                case 7:     //R5G6B5 //confirmed switched on X360; confirmed on iOS
                {
                    if (sourceFile.platform == 11)
                    {
                        for (int i = 0; i < (image_data_size / 2); i++)
                        {
                            byte b0 = image_data[i * 2];
                            image_data[i * 2]     = image_data[i * 2 + 1];
                            image_data[i * 2 + 1] = b0;
                        }
                    }

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

                case 10:                           //DXT1
                {
                    if (sourceFile.platform == 11) //X360 only, PS3 not
                    {
                        for (int i = 0; i < (image_data_size / 2); i++)
                        {
                            byte b0 = image_data[i * 2];
                            image_data[i * 2]     = image_data[i * 2 + 1];
                            image_data[i * 2 + 1] = b0;
                        }
                    }

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

                case 12:                           //DXT5
                {
                    if (sourceFile.platform == 11) //X360, PS3 not
                    {
                        for (int i = 0; i < (image_data_size / 2); i++)
                        {
                            byte b0 = image_data[i * 2];
                            image_data[i * 2]     = image_data[i * 2 + 1];
                            image_data[i * 2 + 1] = b0;
                        }
                    }

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

                case 13:     //R4G4B4A4, iOS (only?)
                {
                    for (int i = 0; i < (image_data_size / 2); i++)
                    {
                        byte[] argb = BitConverter.GetBytes((BitConverter.ToInt32((new byte[4] {
                                image_data[i * 2], image_data[i * 2 + 1], image_data[i * 2], image_data[i * 2 + 1]
                            }), 0)) >> 4);
                        image_data[i * 2]     = argb[0];
                        image_data[i * 2 + 1] = argb[1];
                    }

                    dwFlags2      = 0x41;
                    dwRGBBitCount = 0x10;
                    dwRBitMask    = 0xF00;
                    dwGBitMask    = 0xF0;
                    dwBBitMask    = 0xF;
                    dwABitMask    = 0xF000;
                    break;
                }

                case 28:     //DXT1 Crunched
                case 29:     //DXT1 Crunched
                    break;

                case 30:     //PVRTC_RGB2
                {
                    pvrPixelFormat = 0x0;
                    break;
                }

                case 31:     //PVRTC_RGBA2
                {
                    pvrPixelFormat = 0x1;
                    break;
                }

                case 32:     //PVRTC_RGB4
                {
                    pvrPixelFormat = 0x2;
                    break;
                }

                case 33:     //PVRTC_RGBA4
                {
                    pvrPixelFormat = 0x3;
                    break;
                }

                case 34:     //ETC_RGB4
                {
                    pvrPixelFormat = 0x16;
                    break;
                }
                }
            }
            else
            {
                preloadData.InfoText   = "Width: " + m_Width.ToString() + "\nHeight: " + m_Height.ToString() + "\nFormat: ";
                preloadData.exportSize = image_data_size;

                switch (m_TextureFormat)
                {
                case 1: preloadData.InfoText += "Alpha8"; preloadData.extension = ".dds"; preloadData.exportSize += 128; break;

                case 2: preloadData.InfoText += "ARGB 4.4.4.4"; preloadData.extension = ".dds"; preloadData.exportSize += 128; break;

                case 3: preloadData.InfoText += "BGR 8.8.8"; preloadData.extension = ".dds"; preloadData.exportSize += 128; break;

                case 4: preloadData.InfoText += "GRAB 8.8.8.8"; preloadData.extension = ".dds"; preloadData.exportSize += 128; break;

                case 5: preloadData.InfoText += "BGRA 8.8.8.8"; preloadData.extension = ".dds"; preloadData.exportSize += 128; break;

                case 7: preloadData.InfoText += "RGB 5.6.5"; preloadData.extension = ".dds"; preloadData.exportSize += 128; break;

                case 10: preloadData.InfoText += "DXT1"; preloadData.extension = ".dds"; preloadData.exportSize += 128; break;

                case 12: preloadData.InfoText += "DXT5"; preloadData.extension = ".dds"; preloadData.exportSize += 128; break;

                case 13: preloadData.InfoText += "RGBA 4.4.4.4"; preloadData.extension = ".dds"; preloadData.exportSize += 128; break;

                case 28: preloadData.InfoText += "DXT1 Crunched"; preloadData.extension = ".crn"; break;

                case 29: preloadData.InfoText += "DXT5 Crunched"; preloadData.extension = ".crn"; break;

                case 30: preloadData.InfoText += "PVRTC_RGB2"; preloadData.extension = ".pvr"; preloadData.exportSize += 52; break;

                case 31: preloadData.InfoText += "PVRTC_RGBA2"; preloadData.extension = ".pvr"; preloadData.exportSize += 52; break;

                case 32: preloadData.InfoText += "PVRTC_RGB4"; preloadData.extension = ".pvr"; preloadData.exportSize += 52; break;

                case 33: preloadData.InfoText += "PVRTC_RGBA4"; preloadData.extension = ".pvr"; preloadData.exportSize += 52; break;

                case 34: preloadData.InfoText += "ETC_RGB4"; preloadData.extension = ".pvr"; preloadData.exportSize += 52; break;

                default: preloadData.InfoText += "unknown"; 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.ToString() + "\nMip map bias: " + m_MipBias.ToString();

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

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

                if (m_Name != "")
                {
                    preloadData.Text = m_Name;
                }
                else
                {
                    preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID;
                }
                preloadData.SubItems.AddRange(new string[] { preloadData.TypeString, preloadData.exportSize.ToString() });
            }
        }
Beispiel #20
0
 public SecondarySpriteTexture(ObjectReader reader)
 {
     texture = new PPtr <Texture2D>(reader);
     name    = reader.ReadStringToNull();
 }
Beispiel #21
0
 protected Component(ObjectReader reader) : base(reader)
 {
     m_GameObject = new PPtr <GameObject>(reader);
 }
Beispiel #22
0
        public Material(AssetPreloadData preloadData)
        {
            var sourceFile = preloadData.sourceFile;
            var reader     = preloadData.Reader;

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

            m_Name   = reader.ReadAlignedString(reader.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[reader.ReadInt32()];
                for (int i = 0; i < m_ShaderKeywords.Length; i++)
                {
                    m_ShaderKeywords[i] = reader.ReadAlignedString(reader.ReadInt32());
                }
            }
            else if (sourceFile.version[0] >= 5)//5.0 and up
            {
                m_ShaderKeywords = new[] { reader.ReadAlignedString(reader.ReadInt32()) };
                uint m_LightmapFlags = reader.ReadUInt32();
                if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 6 || sourceFile.version[0] > 5)//5.6.0 and up
                {
                    var m_EnableInstancingVariants = reader.ReadBoolean();
                    //var m_DoubleSidedGI = a_Stream.ReadBoolean();//2017.x
                    reader.AlignStream(4);
                }
            }

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

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

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

            m_Colors = new strColorPair[reader.ReadInt32()];
            for (int i = 0; i < m_Colors.Length; i++)
            {
                strColorPair m_Color = new strColorPair()
                {
                    first  = reader.ReadAlignedString(reader.ReadInt32()),
                    second = new[] { reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() }
                };
                m_Colors[i] = m_Color;
            }
        }
Beispiel #23
0
        public UFont(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var reader     = preloadData.InitReader();

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

            m_Name = reader.ReadAlignedString();

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

                        if (sourceFile.version[0] >= 4)
                        {
                            bool flipped = reader.ReadBoolean();
                            reader.Position += 3;
                        }
                    }
                    int m_KerningValues_size = reader.ReadInt32();
                    for (int i = 0; i < m_KerningValues_size; i++)
                    {
                        int   pairfirst  = reader.ReadInt16();
                        int   pairsecond = reader.ReadInt16();
                        float second     = reader.ReadSingle();
                    }
                    var m_PixelScale    = reader.ReadSingle();
                    int m_FontData_size = reader.ReadInt32();
                    if (m_FontData_size > 0)
                    {
                        m_FontData = reader.ReadBytes(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 = reader.ReadInt32();

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

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

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

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

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

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

                    PPtr m_Texture = sourceFile.ReadPPtr();

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

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

                    int m_FontData_size = reader.ReadInt32();
                    if (m_FontData_size > 0)
                    {
                        m_FontData = reader.ReadBytes(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     = reader.ReadSingle();//problem here in minifootball
                    float m_Ascent       = reader.ReadSingle();
                    uint  m_DefaultStyle = reader.ReadUInt32();

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

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

                        int m_FontRenderingMode = reader.ReadInt32();
                    }
                }
            }
            else
            {
                preloadData.Text = m_Name;
            }
        }
Beispiel #24
0
        public TextAsset(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());

            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();
                if (lzmaTest == 93)
                {
                    a_Stream.Position     += 4;
                    preloadData.exportSize = a_Stream.ReadInt32(); //actualy int64
                    a_Stream.Position     -= 8;
                }
                else
                {
                    preloadData.exportSize = m_Script_size;
                }

                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 string[] { preloadData.TypeString, preloadData.exportSize.ToString() });
            }
            a_Stream.AlignStream(4);

            m_PathName = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
        }
Beispiel #25
0
        protected Renderer(ObjectReader reader) : base(reader)
        {
            if (version[0] < 5) //5.0 down
            {
                var m_Enabled        = reader.ReadBoolean();
                var m_CastShadows    = reader.ReadBoolean();
                var m_ReceiveShadows = reader.ReadBoolean();
                var m_LightmapIndex  = reader.ReadByte();
            }
            else //5.0 and up
            {
                if (version[0] > 5 || (version[0] == 5 && version[1] >= 4)) //5.4 and up
                {
                    var m_Enabled        = reader.ReadBoolean();
                    var m_CastShadows    = reader.ReadByte();
                    var m_ReceiveShadows = reader.ReadByte();
                    if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 2)) //2017.2 and up
                    {
                        var m_DynamicOccludee = reader.ReadByte();
                    }
                    var m_MotionVectors        = reader.ReadByte();
                    var m_LightProbeUsage      = reader.ReadByte();
                    var m_ReflectionProbeUsage = reader.ReadByte();
                    if (version[0] > 2019 || (version[0] == 2019 && version[1] >= 3)) //2019.3 and up
                    {
                        var m_RayTracingMode = reader.ReadByte();
                    }
                    reader.AlignStream();
                }
                else
                {
                    var m_Enabled = reader.ReadBoolean();
                    reader.AlignStream();
                    var m_CastShadows    = reader.ReadByte();
                    var m_ReceiveShadows = reader.ReadBoolean();
                    reader.AlignStream();
                }

                if (version[0] >= 2018) //2018 and up
                {
                    var m_RenderingLayerMask = reader.ReadUInt32();
                }

                if (version[0] > 2018 || (version[0] == 2018 && version[1] >= 3)) //2018.3 and up
                {
                    var m_RendererPriority = reader.ReadInt32();
                }

                var m_LightmapIndex        = reader.ReadUInt16();
                var m_LightmapIndexDynamic = reader.ReadUInt16();
            }

            if (version[0] >= 3) //3.0 and up
            {
                var m_LightmapTilingOffset = reader.ReadVector4();
            }

            if (version[0] >= 5) //5.0 and up
            {
                var m_LightmapTilingOffsetDynamic = reader.ReadVector4();
            }

            var m_MaterialsSize = reader.ReadInt32();

            m_Materials = new PPtr <Material> [m_MaterialsSize];
            for (int i = 0; i < m_MaterialsSize; i++)
            {
                m_Materials[i] = new PPtr <Material>(reader);
            }

            if (version[0] < 3) //3.0 down
            {
                var m_LightmapTilingOffset = reader.ReadVector4();
            }
            else //3.0 and up
            {
                if (version[0] > 5 || (version[0] == 5 && version[1] >= 5)) //5.5 and up
                {
                    m_StaticBatchInfo = new StaticBatchInfo(reader);
                }
                else
                {
                    m_SubsetIndices = reader.ReadUInt32Array();
                }

                var m_StaticBatchRoot = new PPtr <Transform>(reader);
            }

            if (version[0] > 5 || (version[0] == 5 && version[1] >= 4)) //5.4 and up
            {
                var m_ProbeAnchor = new PPtr <Transform>(reader);
                var m_LightProbeVolumeOverride = new PPtr <GameObject>(reader);
            }
            else if (version[0] > 3 || (version[0] == 3 && version[1] >= 5)) //3.5 - 5.3
            {
                var m_UseLightProbes = reader.ReadBoolean();
                reader.AlignStream();

                if (version[0] >= 5)//5.0 and up
                {
                    var m_ReflectionProbeUsage = reader.ReadInt32();
                }

                var m_LightProbeAnchor = new PPtr <Transform>(reader); //5.0 and up m_ProbeAnchor
            }

            if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up
            {
                if (version[0] == 4 && version[1] == 3)                 //4.3
                {
                    var m_SortingLayer = reader.ReadInt16();
                }
                else
                {
                    var m_SortingLayerID = reader.ReadUInt32();
                }

                //SInt16 m_SortingLayer 5.6 and up
                var m_SortingOrder = reader.ReadInt16();
                reader.AlignStream();
            }
        }
Beispiel #26
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)
            {
                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 string[] { preloadData.TypeString, preloadData.exportSize.ToString() });
            }
        }
Beispiel #27
0
        public Texture2D(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var reader     = preloadData.InitReader();

            version = sourceFile.version;

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

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

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

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

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

            image_data_size = reader.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          = reader.ReadUInt32();
                size            = reader.ReadUInt32();
                image_data_size = (int)size;
                path            = reader.ReadAlignedString();
            }

            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 resourceReader = new BinaryReader(File.OpenRead(resourceFilePath)))
                        {
                            resourceReader.BaseStream.Position = offset;
                            image_data = resourceReader.ReadBytes(image_data_size);
                        }
                    }
                    else
                    {
                        if (Studio.resourceFileReaders.TryGetValue(resourceFileName.ToUpper(), out var resourceReader))
                        {
                            resourceReader.Position = offset;
                            image_data = resourceReader.ReadBytes(image_data_size);
                        }
                        else
                        {
                            MessageBox.Show($"can't find the resource file {resourceFileName}");
                        }
                    }
                }
                else
                {
                    image_data = reader.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;
                }
            }
        }
Beispiel #28
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;
            }
        }
Beispiel #29
0
 public UnityTexEnv(ObjectReader reader)
 {
     m_Texture = new PPtr <Texture>(reader);
     m_Scale   = reader.ReadVector2();
     m_Offset  = reader.ReadVector2();
 }
Beispiel #30
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.GetFileName(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 = a_Stream.ReadInt32();
            }

            if (readSwitch)
            {
                m_AudioData = new byte[m_Size];

                if (m_Source == null)
                {
                    a_Stream.Read(m_AudioData, 0, (int)m_Size);
                }
                else if (File.Exists(m_Source))
                {
                    using (BinaryReader reader = new BinaryReader(File.OpenRead(m_Source)))
                    {
                        reader.BaseStream.Position = m_Offset;
                        reader.Read(m_AudioData, 0, (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;
                }

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

                if (m_Name != "")
                {
                    preloadData.Text = m_Name;
                }
                else
                {
                    preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID;
                }
                preloadData.exportSize = (int)m_Size;
                preloadData.SubItems.AddRange(new string[] { preloadData.TypeString, m_Size.ToString() });
            }
        }