Ejemplo n.º 1
0
        public static TextureFile ReadTextureFile(AssetTypeValueField baseField)
        {
            TextureFile         texture = new TextureFile();
            AssetTypeValueField tempField;

            texture.m_Name = baseField.Get("m_Name").GetValue().AsString();

            if (!(tempField = baseField.Get("m_ForcedFallbackFormat")).IsDummy())
            {
                texture.m_ForcedFallbackFormat = tempField.GetValue().AsInt();
            }

            if (!(tempField = baseField.Get("m_DownscaleFallback")).IsDummy())
            {
                texture.m_DownscaleFallback = tempField.GetValue().AsBool();
            }

            texture.m_Width = baseField.Get("m_Width").GetValue().AsInt();

            texture.m_Height = baseField.Get("m_Height").GetValue().AsInt();

            if (!(tempField = baseField.Get("m_CompleteImageSize")).IsDummy())
            {
                texture.m_CompleteImageSize = tempField.GetValue().AsInt();
            }

            texture.m_TextureFormat = baseField.Get("m_TextureFormat").GetValue().AsInt();

            if (!(tempField = baseField.Get("m_MipCount")).IsDummy())
            {
                texture.m_MipCount = tempField.GetValue().AsInt();
            }

            if (!(tempField = baseField.Get("m_MipMap")).IsDummy())
            {
                texture.m_MipMap = tempField.GetValue().AsBool();
            }

            texture.m_IsReadable = baseField.Get("m_IsReadable").GetValue().AsBool();

            if (!(tempField = baseField.Get("m_ReadAllowed")).IsDummy())
            {
                texture.m_ReadAllowed = tempField.GetValue().AsBool();
            }

            if (!(tempField = baseField.Get("m_StreamingMipmaps")).IsDummy())
            {
                texture.m_StreamingMipmaps = tempField.GetValue().AsBool();
            }

            if (!(tempField = baseField.Get("m_StreamingMipmapsPriority")).IsDummy())
            {
                texture.m_StreamingMipmapsPriority = tempField.GetValue().AsInt();
            }

            texture.m_ImageCount = baseField.Get("m_ImageCount").GetValue().AsInt();

            texture.m_TextureDimension = baseField.Get("m_TextureDimension").GetValue().AsInt();

            AssetTypeValueField textureSettings = baseField.Get("m_TextureSettings");

            texture.m_TextureSettings.m_FilterMode = textureSettings.Get("m_FilterMode").GetValue().AsInt();

            texture.m_TextureSettings.m_Aniso = textureSettings.Get("m_Aniso").GetValue().AsInt();

            texture.m_TextureSettings.m_MipBias = textureSettings.Get("m_MipBias").GetValue().AsFloat();

            if (!(tempField = textureSettings.Get("m_WrapMode")).IsDummy())
            {
                texture.m_TextureSettings.m_WrapMode = tempField.GetValue().AsInt();
            }

            if (!(tempField = textureSettings.Get("m_WrapU")).IsDummy())
            {
                texture.m_TextureSettings.m_WrapU = tempField.GetValue().AsInt();
            }

            if (!(tempField = textureSettings.Get("m_WrapV")).IsDummy())
            {
                texture.m_TextureSettings.m_WrapV = tempField.GetValue().AsInt();
            }

            if (!(tempField = textureSettings.Get("m_WrapW")).IsDummy())
            {
                texture.m_TextureSettings.m_WrapW = tempField.GetValue().AsInt();
            }

            if (!(tempField = baseField.Get("m_LightmapFormat")).IsDummy())
            {
                texture.m_LightmapFormat = tempField.GetValue().AsInt();
            }

            if (!(tempField = baseField.Get("m_ColorSpace")).IsDummy())
            {
                texture.m_ColorSpace = tempField.GetValue().AsInt();
            }

            AssetTypeValueField imageData = baseField.Get("image data");

            if (imageData.templateField.valueType == EnumValueTypes.ByteArray)
            {
                texture.pictureData = imageData.GetValue().AsByteArray().data;
            }
            else
            {
                int imageDataSize = imageData.GetValue().AsArray().size;
                texture.pictureData = new byte[imageDataSize];
                for (int i = 0; i < imageDataSize; i++)
                {
                    texture.pictureData[i] = (byte)imageData[i].GetValue().AsInt();
                }
            }

            AssetTypeValueField streamData;

            if (!(streamData = baseField.Get("m_StreamData")).IsDummy())
            {
                texture.m_StreamData.offset = streamData.Get("offset").GetValue().AsUInt64();
                texture.m_StreamData.size   = streamData.Get("size").GetValue().AsUInt();
                texture.m_StreamData.path   = streamData.Get("path").GetValue().AsString();
            }

            return(texture);
        }
        public AssetTypeValueField ReadType(AssetsFileReader reader, AssetTypeValueField valueField)
        {
            if (valueField.templateField.isArray)
            {
                if (valueField.templateField.childrenCount == 2)
                {
                    EnumValueTypes sizeType = valueField.templateField.children[0].valueType;
                    if (sizeType == EnumValueTypes.Int32 ||
                        sizeType == EnumValueTypes.UInt32)
                    {
                        if (valueField.templateField.valueType == EnumValueTypes.ByteArray)
                        {
                            valueField.childrenCount = 0;
                            valueField.children      = new AssetTypeValueField[0];
                            int    size = reader.ReadInt32();
                            byte[] data = reader.ReadBytes(size);
                            if (valueField.templateField.align)
                            {
                                reader.Align();
                            }
                            AssetTypeByteArray atba = new AssetTypeByteArray();
                            atba.size        = (uint)size;
                            atba.data        = data;
                            valueField.value = new AssetTypeValue(EnumValueTypes.ByteArray, atba);
                        }
                        else
                        {
                            valueField.childrenCount = reader.ReadInt32();
                            valueField.children      = new AssetTypeValueField[valueField.childrenCount];
                            for (int i = 0; i < valueField.childrenCount; i++)
                            {
                                valueField.children[i] = new AssetTypeValueField();
                                valueField.children[i].templateField = valueField.templateField.children[1];
                                valueField.children[i] = ReadType(reader, valueField.children[i]);
                            }
                            if (valueField.templateField.align)
                            {
                                reader.Align();
                            }
                            AssetTypeArray ata = new AssetTypeArray();
                            ata.size         = valueField.childrenCount;
                            valueField.value = new AssetTypeValue(EnumValueTypes.Array, ata);
                        }
                    }
                    else
                    {
                        throw new Exception("Invalid array value type! Found an unexpected " + sizeType.ToString() + " type instead!");
                    }
                }
                else
                {
                    throw new Exception("Invalid array!");
                }
            }
            else
            {
                EnumValueTypes type = valueField.templateField.valueType;
                if (type != 0)
                {
                    valueField.value = new AssetTypeValue(type, null);
                }
                if (type == EnumValueTypes.String)
                {
                    int length = reader.ReadInt32();
                    valueField.value.Set(reader.ReadBytes(length));
                    reader.Align();
                }
                else
                {
                    valueField.childrenCount = valueField.templateField.childrenCount;
                    if (valueField.childrenCount == 0)
                    {
                        valueField.children = new AssetTypeValueField[0];
                        switch (valueField.templateField.valueType)
                        {
                        case EnumValueTypes.Int8:
                            valueField.value.Set(reader.ReadSByte());
                            if (valueField.templateField.align)
                            {
                                reader.Align();
                            }
                            break;

                        case EnumValueTypes.UInt8:
                        case EnumValueTypes.Bool:
                            valueField.value.Set(reader.ReadByte());
                            if (valueField.templateField.align)
                            {
                                reader.Align();
                            }
                            break;

                        case EnumValueTypes.Int16:
                            valueField.value.Set(reader.ReadInt16());
                            if (valueField.templateField.align)
                            {
                                reader.Align();
                            }
                            break;

                        case EnumValueTypes.UInt16:
                            valueField.value.Set(reader.ReadUInt16());
                            if (valueField.templateField.align)
                            {
                                reader.Align();
                            }
                            break;

                        case EnumValueTypes.Int32:
                            valueField.value.Set(reader.ReadInt32());
                            break;

                        case EnumValueTypes.UInt32:
                            valueField.value.Set(reader.ReadUInt32());
                            break;

                        case EnumValueTypes.Int64:
                            valueField.value.Set(reader.ReadInt64());
                            break;

                        case EnumValueTypes.UInt64:
                            valueField.value.Set(reader.ReadUInt64());
                            break;

                        case EnumValueTypes.Float:
                            valueField.value.Set(reader.ReadSingle());
                            break;

                        case EnumValueTypes.Double:
                            valueField.value.Set(reader.ReadDouble());
                            break;
                        }
                    }
                    else
                    {
                        valueField.children = new AssetTypeValueField[valueField.childrenCount];
                        for (int i = 0; i < valueField.childrenCount; i++)
                        {
                            valueField.children[i] = new AssetTypeValueField();
                            valueField.children[i].templateField = valueField.templateField.children[i];
                            valueField.children[i] = ReadType(reader, valueField.children[i]);
                        }
                        if (valueField.templateField.align)
                        {
                            reader.Align();
                        }
                    }
                }
            }
            return(valueField);
        }
Ejemplo n.º 3
0
        public void WriteTo(AssetTypeValueField baseField)
        {
            AssetTypeValueField tempField;

            baseField.Get("m_Name").GetValue().Set(m_Name);

            if (!(tempField = baseField.Get("m_ForcedFallbackFormat")).IsDummy())
            {
                tempField.GetValue().Set(m_ForcedFallbackFormat);
            }

            if (!(tempField = baseField.Get("m_DownscaleFallback")).IsDummy())
            {
                tempField.GetValue().Set(m_DownscaleFallback);
            }

            baseField.Get("m_Width").GetValue().Set(m_Width);

            baseField.Get("m_Height").GetValue().Set(m_Height);

            if (!(tempField = baseField.Get("m_CompleteImageSize")).IsDummy())
            {
                tempField.GetValue().Set(m_CompleteImageSize);
            }

            baseField.Get("m_TextureFormat").GetValue().Set(m_TextureFormat);

            if (!(tempField = baseField.Get("m_MipCount")).IsDummy())
            {
                tempField.GetValue().Set(m_MipCount);
            }

            if (!(tempField = baseField.Get("m_MipMap")).IsDummy())
            {
                tempField.GetValue().Set(m_MipMap);
            }

            baseField.Get("m_IsReadable").GetValue().Set(m_IsReadable);

            if (!(tempField = baseField.Get("m_ReadAllowed")).IsDummy())
            {
                tempField.GetValue().Set(m_ReadAllowed);
            }

            if (!(tempField = baseField.Get("m_StreamingMipmaps")).IsDummy())
            {
                tempField.GetValue().Set(m_StreamingMipmaps);
            }

            if (!(tempField = baseField.Get("m_StreamingMipmapsPriority")).IsDummy())
            {
                tempField.GetValue().Set(m_StreamingMipmapsPriority);
            }

            baseField.Get("m_ImageCount").GetValue().Set(m_ImageCount);

            baseField.Get("m_TextureDimension").GetValue().Set(m_TextureDimension);

            AssetTypeValueField textureSettings = baseField.Get("m_TextureSettings");

            textureSettings.Get("m_FilterMode").GetValue().Set(m_TextureSettings.m_FilterMode);
            textureSettings.Get("m_Aniso").GetValue().Set(m_TextureSettings.m_Aniso);
            textureSettings.Get("m_MipBias").GetValue().Set(m_TextureSettings.m_MipBias);

            if (!(tempField = textureSettings.Get("m_WrapMode")).IsDummy())
            {
                tempField.GetValue().Set(m_TextureSettings.m_WrapMode);
            }

            if (!(tempField = textureSettings.Get("m_WrapU")).IsDummy())
            {
                tempField.GetValue().Set(m_TextureSettings.m_WrapU);
            }

            if (!(tempField = textureSettings.Get("m_WrapV")).IsDummy())
            {
                tempField.GetValue().Set(m_TextureSettings.m_WrapV);
            }

            if (!(tempField = textureSettings.Get("m_WrapW")).IsDummy())
            {
                tempField.GetValue().Set(m_TextureSettings.m_WrapW);
            }

            if (!(tempField = baseField.Get("m_LightmapFormat")).IsDummy())
            {
                tempField.GetValue().Set(m_LightmapFormat);
            }

            if (!(tempField = baseField.Get("m_ColorSpace")).IsDummy())
            {
                tempField.GetValue().Set(m_ColorSpace);
            }

            AssetTypeValueField imageData = baseField.Get("image data");

            if (imageData.templateField.valueType == EnumValueTypes.ByteArray)
            {
                imageData.GetValue().Set(pictureData);
            }
            else
            {
                imageData.GetValue().Set(new AssetTypeArray(pictureData.Length));

                AssetTypeValueField[] children = new AssetTypeValueField[pictureData.Length];
                for (int i = 0; i < pictureData.Length; i++)
                {
                    AssetTypeValueField child = ValueBuilder.DefaultValueFieldFromArrayTemplate(imageData);
                    child.GetValue().Set(pictureData[i]);
                    children[i] = child;
                }

                imageData.SetChildrenList(children);
            }

            AssetTypeValueField streamData;

            if (!(streamData = baseField.Get("m_StreamData")).IsDummy())
            {
                streamData.Get("offset").GetValue().Set(m_StreamData.offset);
                streamData.Get("size").GetValue().Set(m_StreamData.size);
                streamData.Get("path").GetValue().Set(m_StreamData.path);
            }
        }
        public AssetTypeValueField ReadType(AssetsFileReader reader, ulong filePos, AssetTypeValueField valueField, bool bigEndian)
        {
            if (valueField.templateField.isArray)
            {
                if (valueField.templateField.childrenCount == 2)
                {
                    EnumValueTypes sizeType = valueField.templateField.children[0].valueType;
                    if (sizeType == EnumValueTypes.ValueType_Int32 ||
                        sizeType == EnumValueTypes.ValueType_UInt32)
                    {
                        valueField.childrenCount = reader.ReadUInt32();
                        valueField.pChildren     = new AssetTypeValueField[valueField.childrenCount];
                        for (int i = 0; i < valueField.childrenCount; i++)
                        {
                            valueField.pChildren[i] = new AssetTypeValueField();
                            valueField.pChildren[i].templateField = valueField.templateField.children[1];
                            valueField.pChildren[i] = ReadType(reader, reader.Position, valueField.pChildren[i], bigEndian);
                        }
                        if (valueField.templateField.align)
                        {
                            reader.Align();
                        }
                        AssetTypeArray ata = new AssetTypeArray();
                        ata.size         = valueField.childrenCount;
                        valueField.value = new AssetTypeValue(EnumValueTypes.ValueType_Array, 0);
                        valueField.value.Set(ata);
                    }
                    else
                    {
                        Debug.WriteLine("Invalid array value type! Found an unexpected " + sizeType.ToString() + " type instead!");
                    }
                }
                else
                {
                    Debug.WriteLine("Invalid array!");
                }
            }
            else
            {
                EnumValueTypes type = valueField.templateField.valueType;
                if (type != 0)
                {
                    valueField.value = new AssetTypeValue(type, 0);
                }
                if (type == EnumValueTypes.ValueType_String)
                {
                    valueField.value.Set(reader.ReadCountStringInt32());
                    reader.Align();
                }
                else
                {
                    valueField.childrenCount = valueField.templateField.childrenCount;
                    if (valueField.childrenCount == 0)
                    {
                        valueField.pChildren = new AssetTypeValueField[0];
                        switch (valueField.templateField.valueType)
                        {
                        case EnumValueTypes.ValueType_Int8:
                            valueField.value.Set(reader.ReadSByte());
                            if (valueField.templateField.align)
                            {
                                reader.Align();
                            }
                            break;

                        case EnumValueTypes.ValueType_UInt8:
                        case EnumValueTypes.ValueType_Bool:
                            valueField.value.Set(reader.ReadByte());
                            if (valueField.templateField.align)
                            {
                                reader.Align();
                            }
                            break;

                        case EnumValueTypes.ValueType_Int16:
                            valueField.value.Set(reader.ReadInt16());
                            if (valueField.templateField.align)
                            {
                                reader.Align();
                            }
                            break;

                        case EnumValueTypes.ValueType_UInt16:
                            valueField.value.Set(reader.ReadUInt16());
                            break;

                        case EnumValueTypes.ValueType_Int32:
                            valueField.value.Set(reader.ReadInt32());
                            break;

                        case EnumValueTypes.ValueType_UInt32:
                            valueField.value.Set(reader.ReadUInt32());
                            break;

                        case EnumValueTypes.ValueType_Int64:
                            valueField.value.Set(reader.ReadInt64());
                            break;

                        case EnumValueTypes.ValueType_UInt64:
                            valueField.value.Set(reader.ReadUInt64());
                            break;

                        case EnumValueTypes.ValueType_Float:
                            valueField.value.Set(reader.ReadSingle());
                            break;

                        case EnumValueTypes.ValueType_Double:
                            valueField.value.Set(reader.ReadDouble());
                            break;
                        }
                    }
                    else
                    {
                        valueField.pChildren = new AssetTypeValueField[valueField.childrenCount];
                        for (int i = 0; i < valueField.childrenCount; i++)
                        {
                            valueField.pChildren[i] = new AssetTypeValueField();
                            valueField.pChildren[i].templateField = valueField.templateField.children[i];
                            valueField.pChildren[i] = ReadType(reader, reader.Position, valueField.pChildren[i], bigEndian);
                        }
                        if (valueField.templateField.align)
                        {
                            reader.Align();
                        }
                    }
                }
            }
            return(valueField);
        }