Esempio n. 1
0
        public UObject(IoPackageReader reader, string type, bool structFallback = false)
        {
            Dict = new Dictionary <string, object>();
            var header = new FUnversionedHeader(reader);

            if (header.HasValues)
            {
                using var it = new FIterator(header);
                if (header.HasNonZeroValues)
                {
                    FUnversionedType unversionedType = reader.GetOrCreateSchema(type);
                    var num = 1;
                    do
                    {
                        var(val, isNonZero) = it.Current;
                        if (unversionedType.Properties.TryGetValue(val, out var props))
                        {
                            var propertyTag = new FPropertyTag(props);
                            if (isNonZero)
                            {
                                var key = Dict.ContainsKey(props.Name) ? $"{props.Name}_NK{num++:00}" : props.Name;
                                var obj = BaseProperty.ReadAsObject(reader, propertyTag, propertyTag.Type, ReadType.NORMAL);
                                Dict[key] = obj;
                            }
                            else
                            {
                                var key = Dict.ContainsKey(props.Name) ? $"{props.Name}_NK{num++:00}" : props.Name;
                                var obj = BaseProperty.ReadAsZeroObject(reader, propertyTag, propertyTag.Type);
                                Dict[key] = obj;
                            }
                        }
                        else
                        {
                            Dict[val.ToString()] = null;
                        }
                    } while (it.MoveNext());
                }
                else
                {
#if DEBUG
                    FConsole.AppendText(string.Concat("\n", type ?? "Unknown", ": ", reader.Summary.Name.String), "#CA6C6C", true);
                    do
                    {
                        FConsole.AppendText($"Val: {it.Current.Val} (IsNonZero: {it.Current.IsNonZero})", FColors.Yellow, true);
                    }while (it.MoveNext());
#endif
                }
            }

            if (!structFallback && reader.ReadInt32() != 0 /* && reader.Position + 16 <= maxSize*/)
            {
                reader.Position += FGuid.SIZE;
            }
        }
Esempio n. 2
0
        public UObject(IoPackageReader reader, IReadOnlyDictionary <int, PropertyInfo> properties, bool structFallback = false, string type = null)
        {
            Dict = new Dictionary <string, object>();
            var header = new FUnversionedHeader(reader);

            using var it = new FIterator(header);

#if DEBUG
            var headerWritten = false;

            do
            {
                if (properties.ContainsKey(it.Current.Val))
                {
                    continue;
                }

                if (!headerWritten)
                {
                    headerWritten = true;
                    FConsole.AppendText(string.Concat("\n", type ?? "Unknown", ": ", reader.Summary.Name.String), "#CA6C6C", true);
                }

                FConsole.AppendText($"Val: {it.Current.Val} (IsNonZero: {it.Current.IsNonZero})", FColors.Yellow, true);
            }while (it.MoveNext());
            it.Reset();
#endif

            var num = 1;
            do
            {
                var(val, isNonZero) = it.Current;
                if (properties.TryGetValue(val, out var propertyInfo))
                {
                    if (propertyInfo.Name == "AuthoredVFXData_ByPart" || propertyInfo.Name == "RequestedDataStores")
                    {
                        continue;
                    }

                    if (isNonZero)
                    {
                        var obj = BaseProperty.ReadAsObject(reader, new FPropertyTag(propertyInfo), new FName(propertyInfo.Type), ReadType.NORMAL);
                        var key = Dict.ContainsKey(propertyInfo.Name) ? $"{propertyInfo.Name}_NK{num++:00}" : propertyInfo.Name;
                        Dict[key] = obj;
                    }
                    else
                    {
                        var obj = BaseProperty.ReadAsZeroObject(reader, new FPropertyTag(propertyInfo), new FName(propertyInfo.Type));
                        var key = Dict.ContainsKey(propertyInfo.Name) ? $"{propertyInfo.Name}_NK{num++:00}" : propertyInfo.Name;
                        Dict[key] = obj;
                    }
                }
                else
                {
                    Dict[val.ToString()] = null;
                }
            } while (it.MoveNext());

            if (!structFallback && reader.ReadInt32() != 0 /* && reader.Position + 16 <= maxSize*/)
            {
                new FGuid(reader);
            }
        }
Esempio n. 3
0
        internal static List <FPropertyTag> DeserializePropertiesUnversioned(FAssetArchive Ar, UStruct struc)
        {
            var properties = new List <FPropertyTag>();
            var header     = new FUnversionedHeader(Ar);

            if (!header.HasValues)
            {
                return(properties);
            }
            var type = struc.Name;

            Struct?propMappings = null;

            if (struc is UScriptClass)
            {
                Ar.Owner.Mappings?.Types.TryGetValue(type, out propMappings);
            }
            else
            {
                propMappings = new SerializedStruct(Ar.Owner.Mappings, struc);
            }

            if (propMappings == null)
            {
                throw new ParserException(Ar, "Missing prop mappings for type " + type);
            }

            using var it = new FIterator(header);
            do
            {
                var(val, isNonZero) = it.Current;
                // The value has content and needs to be serialized normally
                if (isNonZero)
                {
                    if (propMappings.TryGetValue(val, out var propertyInfo))
                    {
                        var tag = new FPropertyTag(Ar, propertyInfo, ReadType.NORMAL);
                        if (tag.Tag != null)
                        {
                            properties.Add(tag);
                        }
                        else
                        {
                            throw new ParserException(Ar, $"{type}: Failed to serialize property {propertyInfo.MappingType.Type} {propertyInfo.Name}. Can't proceed with serialization (Serialized {properties.Count} properties until now)");
                        }
                    }
                    else
                    {
                        throw new ParserException(Ar, $"{type}: Unknown property with value {val}. Can't proceed with serialization (Serialized {properties.Count} properties until now)");
                    }
                }
                // The value is serialized as zero meaning we don't have to read any bytes here
                else
                {
                    if (propMappings.TryGetValue(val, out var propertyInfo))
                    {
                        properties.Add(new FPropertyTag(Ar, propertyInfo, ReadType.ZERO));
                    }
                    else
                    {
                        Log.Warning(
                            "{0}: Unknown property with value {1} but it's zero so we are good",
                            type, val);
                    }
                }
            } while (it.MoveNext());
            return(properties);
        }
Esempio n. 4
0
        public UObject(IoPackageReader reader, IReadOnlyDictionary <int, PropertyInfo> properties, bool structFallback = false, string type = null)
        {
            Dict = new Dictionary <string, object>();
            var header = new FUnversionedHeader(reader);

            using var it = new FIterator(header);

#if DEBUG
            var headerWritten = false;

            do
            {
                if (properties.ContainsKey(it.Current.Val))
                {
                    continue;
                }

                if (!headerWritten)
                {
                    headerWritten = true;
                    FConsole.AppendText(string.Concat("\n", type ?? "Unknown", ": ", reader.Summary.Name.String), "#CA6C6C", true);
                }

                FConsole.AppendText($"Val: {it.Current.Val} (IsNonZero: {it.Current.IsNonZero})", FColors.Yellow, true);
            }while (it.MoveNext());
            it.Reset();
#endif

            var num = 1;

            do
            {
                var(val, isNonZero) = it.Current;
                if (properties.TryGetValue(val, out var propertyInfo))
                {
                    if (isNonZero)
                    {
                        var obj = BaseProperty.ReadAsObject(reader, new FPropertyTag(propertyInfo), new FName(propertyInfo.Type), ReadType.NORMAL);
                        var key = Dict.ContainsKey(propertyInfo.Name) ? $"{propertyInfo.Name}_NK{num++:00}" : propertyInfo.Name;
                        Dict[key] = obj;
                    }
                    else
                    {
                        var obj = BaseProperty.ReadAsZeroObject(reader, new FPropertyTag(propertyInfo), new FName(propertyInfo.Type));
                        var key = Dict.ContainsKey(propertyInfo.Name) ? $"{propertyInfo.Name}_NK{num++:00}" : propertyInfo.Name;
                        Dict[key] = obj;
                    }
                }
                else
                {
                    Dict[val.ToString()] = null;
                    if (!isNonZero)
                    {
                        // We are lucky: We don't know this property but it also has no content
                        DebugHelper.WriteLine($"{type ?? "Unknown"}: Unknown property for {GetType().Name} with value {val} but it's zero so we are good");
                    }
                    else
                    {
                        DebugHelper.WriteLine($"{type ?? "Unknown"}: Unknown property for {GetType().Name} with value {val}. Can't proceed serialization (Serialized {Dict.Count} properties till now)");
                        //throw new FileLoadException($"Unknown property for {GetType().Name} with value {val}. Can't proceed serialization");
                    }
                }
            } while (it.MoveNext());

            if (!structFallback && reader.ReadInt32() != 0 /* && reader.Position + 16 <= maxSize*/)
            {
                new FGuid(reader);
            }
        }