Exemple #1
0
        public UScriptMap(FAssetArchive Ar, FPropertyTagData tagData)
        {
            if (tagData.InnerType == null || tagData.ValueType == null)
            {
                throw new ParserException(Ar, "Can't serialize UScriptMap without key or value type");
            }

            var numKeysToRemove = Ar.Read <int>();

            for (var i = 0; i < numKeysToRemove; i++)
            {
                FPropertyTagType.ReadPropertyTagType(Ar, tagData.InnerType, tagData.InnerTypeData, ReadType.MAP);
            }

            var numEntries = Ar.Read <int>();

            Properties = new Dictionary <FPropertyTagType?, FPropertyTagType?>(numEntries);
            for (var i = 0; i < numEntries; i++)
            {
                var isReadingValue = false;
                try
                {
                    var key = FPropertyTagType.ReadPropertyTagType(Ar, tagData.InnerType, tagData.InnerTypeData, ReadType.MAP);
                    isReadingValue = true;
                    var value = FPropertyTagType.ReadPropertyTagType(Ar, tagData.ValueType, tagData.ValueTypeData, ReadType.MAP);
                    Properties[key] = value;
                }
                catch (ParserException e)
                {
                    throw new ParserException(Ar, $"Failed to read {(isReadingValue ? "value" : "key")} for index {i} in map", e);
                }
            }
        }
Exemple #2
0
        public UScriptArray(FAssetArchive Ar, FPropertyTagData?tagData)
        {
            InnerType = tagData?.InnerType ?? throw new ParserException(Ar, "UScriptArray needs inner type");
            var elementCount = Ar.Read <int>();

            if (Ar.HasUnversionedProperties)
            {
                InnerTagData = tagData.InnerTypeData;
            }
            else if (InnerType == "StructProperty" || InnerType == "ArrayProperty")
            {
                InnerTagData = new FPropertyTag(Ar, false).TagData;
                if (InnerTagData == null)
                {
                    throw new ParserException(Ar, $"Couldn't read ArrayProperty with inner type {InnerType}");
                }
            }

            Properties = new List <FPropertyTagType>(elementCount);
            for (int i = 0; i < elementCount; i++)
            {
                var property = FPropertyTagType.ReadPropertyTagType(Ar, InnerType, InnerTagData, ReadType.ARRAY);
                if (property != null)
                {
                    Properties.Add(property);
                }
                else
                {
                    Log.Debug(
                        $"Failed to read array property of type {InnerType} at ${Ar.Position}, index {i}");
                }
            }
        }
Exemple #3
0
        public UScriptMap(FAssetArchive Ar, FPropertyTagData tagData)
        {
            if (tagData.InnerType == null || tagData.ValueType == null)
            {
                throw new ParserException(Ar, "Can't serialize UScriptMap without key or value type");
            }

            int numKeyToRemove = Ar.Read <int>();

            for (int i = 0; i < numKeyToRemove; i++)
            {
                FPropertyTagType.ReadPropertyTagType(Ar, tagData.InnerType, tagData, ReadType.MAP);
            }

            int numEntries = Ar.Read <int>();

            Properties = new Dictionary <FPropertyTagType?, FPropertyTagType?>(numEntries);
            for (int i = 0; i < numEntries; i++)
            {
                try
                {
                    Properties[FPropertyTagType.ReadPropertyTagType(Ar, tagData.InnerType, tagData.InnerTypeData, ReadType.MAP)] = FPropertyTagType.ReadPropertyTagType(Ar, tagData.ValueType, tagData.ValueTypeData, ReadType.MAP);
                }
                catch (ParserException e)
                {
                    throw new ParserException(Ar, $"Failed to read key/value pair for index {i} in map", e);
                }
            }
        }
Exemple #4
0
        public UScriptSet(FAssetArchive Ar, FPropertyTagData?tagData)
        {
            var innerType = tagData?.InnerType ?? throw new ParserException(Ar, "UScriptSet needs inner type");

            var numElementsToRemove = Ar.Read <int>();

            for (var i = 0; i < numElementsToRemove; i++)
            {
                FPropertyTagType.ReadPropertyTagType(Ar, innerType, tagData, ReadType.ARRAY);
            }

            var num = Ar.Read <int>();

            Properties = new List <FPropertyTagType>(num);
            for (var i = 0; i < num; i++)
            {
                var property = FPropertyTagType.ReadPropertyTagType(Ar, innerType, tagData, ReadType.ARRAY);
                if (property != null)
                {
                    Properties.Add(property);
                }
                else
                {
                    Log.Debug($"Failed to read element for index {i} in set");
                }
            }
        }
Exemple #5
0
        public FPropertyTag(FAssetArchive Ar, bool readData)
        {
            Name = Ar.ReadFName();
            if (Name.IsNone)
            {
                return;
            }

            PropertyType = Ar.ReadFName();
            Size         = Ar.Read <int>();
            ArrayIndex   = Ar.Read <int>();
            TagData      = new FPropertyTagData(Ar, PropertyType.Text);
            if (Ar.Ver >= UE4Version.VER_UE4_PROPERTY_GUID_IN_PROPERTY_TAG)
            {
                HasPropertyGuid = Ar.ReadFlag();
                if (HasPropertyGuid)
                {
                    PropertyGuid = Ar.Read <FGuid>();
                }
            }

            if (readData)
            {
                var pos      = Ar.Position;
                var finalPos = pos + Size;
                try
                {
                    Tag = FPropertyTagType.ReadPropertyTagType(Ar, PropertyType.Text, TagData, ReadType.NORMAL);
#if DEBUG
                    if (finalPos != Ar.Position)
                    {
                        Log.Debug("FPropertyTagType {0} {1} was not read properly, pos {2}, calculated pos {3}", TagData?.ToString() ?? PropertyType.Text, Name.Text, Ar.Position, finalPos);
                    }
#endif
                }
                catch (ParserException e)
                {
#if DEBUG
                    if (finalPos != Ar.Position)
                    {
                        Log.Warning(e, "Failed to read FPropertyTagType {0} {1}, skipping it", TagData?.ToString() ?? PropertyType.Text, Name.Text);
                    }
#endif
                }
                finally
                {
                    // Always seek to calculated position, no need to crash
                    Ar.Position = finalPos;
                }
            }
        }
Exemple #6
0
        public FPropertyTag(FAssetArchive Ar, PropertyInfo info, ReadType type)
        {
            Name            = new FName(info.Name);
            PropertyType    = new FName(info.MappingType.Type);
            ArrayIndex      = 0;
            TagData         = new FPropertyTagData(info.MappingType);
            HasPropertyGuid = false;
            PropertyGuid    = null;

            var pos = Ar.Position;

            try
            {
                Tag = FPropertyTagType.ReadPropertyTagType(Ar, PropertyType.Text, TagData, type);
            }
            catch (ParserException e)
            {
                throw new ParserException($"Failed to read FPropertyTagType {TagData?.ToString() ?? PropertyType.Text} {Name.Text}", e);
            }

            Size = (int)(Ar.Position - pos);
        }