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());
                            if (valueField.templateField.align)
                            {
                                reader.Align();
                            }
                            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);
        }
        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);
        }