Пример #1
0
        private PropertyData MapTypeToClass(string type, string name, AssetReader asset, BinaryReader reader, long leng, bool includeHeader)
        {
            switch (type)
            {
            case "StructProperty":
                StructPropertyData data = new StructPropertyData(name, asset, "Generic");
                data.Read(reader, false, leng);
                return(data);

            default:
                var res = MainSerializer.TypeToClass(type, name, asset, null, leng);
                res.Read(reader, includeHeader, leng);
                return(res);
            }
        }
Пример #2
0
        private PropertyData MapTypeToClass(FName type, FName name, AssetBinaryReader reader, int leng, bool includeHeader, bool isKey)
        {
            switch (type.Value.Value)
            {
            case "StructProperty":
                FName strucType = null;

                if (reader.Asset.MapStructTypeOverride.ContainsKey(name.Value.Value))
                {
                    if (isKey)
                    {
                        strucType = reader.Asset.MapStructTypeOverride[name.Value.Value].Item1;
                    }
                    else
                    {
                        strucType = reader.Asset.MapStructTypeOverride[name.Value.Value].Item2;
                    }
                }

                if (strucType == null)
                {
                    strucType = new FName("Generic");
                }

                StructPropertyData data = new StructPropertyData(name, strucType);
                data.Offset = reader.BaseStream.Position;
                data.Read(reader, false, 1);
                return(data);

            default:
                var res = MainSerializer.TypeToClass(type, name, reader.Asset, null, leng);
                res.Offset = reader.BaseStream.Position;
                res.Read(reader, includeHeader, leng);
                return(res);
            }
        }
Пример #3
0
        public override void Read(AssetBinaryReader reader, bool includeHeader, long leng1, long leng2 = 0)
        {
            if (includeHeader)
            {
                ArrayType    = reader.ReadFName();
                PropertyGuid = reader.ReadPropertyGuid();
            }

            int numEntries = reader.ReadInt32();

            if (ArrayType.Value.Value == "StructProperty" && ShouldSerializeStructsDifferently)
            {
                var results = new PropertyData[numEntries];

                FName name         = this.Name;
                long  structLength = 1;
                FName fullType     = new FName("Generic");
                Guid  structGUID   = new Guid();

                if (reader.Asset.EngineVersion >= UE4Version.VER_UE4_INNER_ARRAY_TAG_INFO)
                {
                    name = reader.ReadFName();
                    if (name.Value.Value.Equals("None"))
                    {
                        Value = results;
                        return;
                    }

                    FName thisArrayType = reader.ReadFName();
                    if (thisArrayType.Value.Value.Equals("None"))
                    {
                        Value = results;
                        return;
                    }

                    if (thisArrayType.Value.Value != ArrayType.Value.Value)
                    {
                        throw new FormatException("Invalid array type: " + thisArrayType.ToString() + " vs " + ArrayType.ToString());
                    }

                    structLength = reader.ReadInt64(); // length value
                    fullType     = reader.ReadFName();
                    structGUID   = new Guid(reader.ReadBytes(16));
                    reader.ReadPropertyGuid();
                }

                if (numEntries == 0)
                {
                    DummyStruct = new StructPropertyData(name, fullType)
                    {
                        StructGUID = structGUID
                    };
                }
                else
                {
                    for (int i = 0; i < numEntries; i++)
                    {
                        var data = new StructPropertyData(name, fullType);
                        data.Offset = reader.BaseStream.Position;
                        data.Read(reader, false, structLength);
                        data.StructGUID = structGUID;
                        results[i]      = data;
                    }
                    DummyStruct = (StructPropertyData)results[0];
                }
                Value = results;
            }
            else
            {
                var results = new PropertyData[numEntries];
                if (numEntries > 0)
                {
                    int averageSizeEstimate1 = (int)(leng1 / numEntries);
                    int averageSizeEstimate2 = (int)((leng1 - 4) / numEntries);
                    for (int i = 0; i < numEntries; i++)
                    {
                        results[i]        = MainSerializer.TypeToClass(ArrayType, new FName(i.ToString(), int.MinValue), reader.Asset);
                        results[i].Offset = reader.BaseStream.Position;
                        if (results[i] is StructPropertyData)
                        {
                            ((StructPropertyData)results[i]).StructType = new FName("Generic");
                        }
                        results[i].Read(reader, false, averageSizeEstimate1, averageSizeEstimate2);
                    }
                }
                Value = results;
            }
        }
Пример #4
0
        public override void Read(BinaryReader reader, bool includeHeader, long leng)
        {
            if (includeHeader)
            {
                ArrayType = Asset.GetHeaderReference((int)reader.ReadInt64());
                reader.ReadByte(); // null byte
            }

            int numEntries = reader.ReadInt32();

            if (ArrayType == "StructProperty")
            {
                var    results = new PropertyData[numEntries];
                string name    = Asset.GetHeaderReference((int)reader.ReadInt64());
                if (name.Equals("None"))
                {
                    Value = results;
                    return;
                }

                if (Asset.GetHeaderReference((int)reader.ReadInt64()) != ArrayType)
                {
                    throw new FormatException("Invalid array type");
                }
                reader.ReadInt64(); // length value

                string fullType   = Asset.GetHeaderReference((int)reader.ReadInt64());
                Guid   structGUID = new Guid(reader.ReadBytes(16));
                reader.ReadByte();

                if (numEntries == 0)
                {
                    DummyStruct = new StructPropertyData(name, Asset, fullType)
                    {
                        StructGUID = structGUID
                    };
                }
                else
                {
                    for (int i = 0; i < numEntries; i++)
                    {
                        var data = new StructPropertyData(name, Asset, fullType);
                        data.Read(reader, false, 0);
                        data.StructGUID = structGUID;
                        results[i]      = data;
                    }
                }
                Value = results;
            }
            else
            {
                var results = new PropertyData[numEntries];
                if (numEntries > 0)
                {
                    int averageSize = (int)(leng / numEntries);
                    for (int i = 0; i < numEntries; i++)
                    {
                        results[i] = MainSerializer.TypeToClass(ArrayType, Name, Asset);
                        results[i].Read(reader, false, averageSize);
                    }
                }
                Value = results;
            }
        }