Example #1
0
 public static void AssertProperty <T>(UStruct unrealStruct, string name) where T : UProperty
 {
     Assert(unrealStruct.FindPropertyByName(new FName(name)) as T != null, unrealStruct.GetName() + "." + name);
 }
Example #2
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);
        }
Example #3
0
 public static void AssertNotNull <T>(T value, UStruct unrealStruct, string message) where T : class
 {
     Debug.Assert(value != null, unrealStruct + GetFullMessage(message));
 }
Example #4
0
 public static void AssertEqual <T>(T value, T expected, UStruct unrealStruct, string message)
 {
     Debug.Assert(Object.Equals(value, expected), unrealStruct + GetFullMessage(message));
 }
Example #5
0
 public static void AssertDefault <T>(T value, UStruct unrealStruct, string message)
 {
     Debug.Assert(Object.Equals(value, default(T)), unrealStruct + GetFullMessage(message));
 }
Example #6
0
 public static void Assert(bool condition, UStruct unrealStruct, string message)
 {
     Debug.Assert(condition, unrealStruct.GetName() + GetFullMessage(message));
 }
Example #7
0
        public override void Read(IOMemoryStream ms, UAssetFile f)
        {
            //Is we're in an array, this will **ALWAYS** be a prop list struct.
            UStruct st;

            if (isArray)
            {
                structType = "(array)";
                unknown    = 0;
                st         = new PropListStruct();
                f.Debug("Read Array", $"====READ STRUCT BEGIN @ {ms.position} ({structType}, {unknown})====", ConsoleColor.Yellow);
            }
            else
            {
                structType = ms.ReadNameTableEntry(f);
                unknown    = ms.ReadInt();
                f.Debug("Read Array", $"====READ STRUCT BEGIN @ {ms.position} ({structType}, {unknown})====", ConsoleColor.Yellow);

                //Find the struct type. Unknown if real: ItemStatInfo
                if (structType == "ItemStatInfo" || structType == "ItemNetID" || structType == "ItemNetInfo" || structType == "Transform" || structType == "PrimalPlayerDataStruct" || structType == "PrimalPlayerCharacterConfigStruct" || structType == "PrimalPersistentCharacterStatsStruct" || structType == "TribeData" || structType == "TribeGovernment" || structType == "TerrainInfo" || structType == "ArkInventoryData" || structType == "DinoOrderGroup" || structType == "ARKDinoData")
                {
                    //Open this as a struct property list.
                    st = new PropListStruct();
                }
                else if (structType == "Vector" || structType == "Rotator")
                {
                    //3d vector or rotor
                    st = new Vector3Struct();
                }
                else if (structType == "Vector2D")
                {
                    //2d vector
                    st = new Vector2Struct();
                }
                else if (structType == "Quat")
                {
                    //Quat
                    st = new QuatStruct();
                }
                else if (structType == "Color")
                {
                    //Color
                    st = new ColorStruct();
                }
                else if (structType == "LinearColor")
                {
                    //Linear color
                    st = new LinearColorStruct();
                }
                else if (structType == "UniqueNetIdRepl")
                {
                    //Some net stuff
                    st = new UniqueNetIdStruct();
                }
                else if (structType == "Guid")
                {
                    //Some net stuff
                    st = new GuidStruct();
                }
                else if (structType == "IntPoint")
                {
                    //Some net stuff
                    st = new IntPointStruct();
                }
                else if (structType == "StringAssetReference")
                {
                    st = new StringAssetReferenceStruct();
                }
                else
                {
                    //Interpet this as a struct property list. Maybe raise a warning later?
                    f.Warn("Struct Warning", $"Unknown type '{structType}'. Interpeting as a struct property list...");
                    st = new PropListStruct();
                }
            }

            //Read
            st.ReadStruct(ms, f, this);
            data = st;

            f.Debug("Read Struct", $"====READ STRUCT END @ {ms.position}====", ConsoleColor.Yellow);
        }