Esempio n. 1
0
        public override void Deserialize(FAssetArchive Ar, long validPos)
        {
            base.Deserialize(Ar, validPos);
            _parent = GetOrDefault <ResolvedObject>(nameof(Parent));
            bHasStaticPermutationResource = GetOrDefault <bool>("bHasStaticPermutationResource");
            BasePropertyOverrides         = GetOrDefault <FMaterialInstanceBasePropertyOverrides>(nameof(BasePropertyOverrides));
            StaticParameters = GetOrDefault <FStaticParameterSet>(nameof(StaticParameters));

            var bSavedCachedData = FUE5MainStreamObjectVersion.Get(Ar) >= FUE5MainStreamObjectVersion.Type.MaterialSavedCachedData && Ar.ReadBoolean();

            if (bSavedCachedData)
            {
                CachedData = new FStructFallback(Ar, "MaterialInstanceCachedData");
            }

            if (bHasStaticPermutationResource)
            {
                if (Ar.Ver >= EUnrealEngineObjectUE4Version.PURGED_FMATERIAL_COMPILE_OUTPUTS)
                {
                    if (FRenderingObjectVersion.Get(Ar) < FRenderingObjectVersion.Type.MaterialAttributeLayerParameters)
                    {
                        StaticParameters = new FStaticParameterSet(Ar);
                    }

#if READ_SHADER_MAPS
                    DeserializeInlineShaderMaps(Ar, LoadedMaterialResources);
#else
                    Ar.Position = validPos; // TODO This skips every data after the inline shader map data, find a way to properly skip it
#endif
                }
            }

#if !READ_SHADER_MAPS
            Ar.Position = validPos;
#endif
        }
Esempio n. 2
0
        public override void Deserialize(FAssetArchive Ar, long validPos)
        {
            base.Deserialize(Ar, validPos);

            NumFrames = GetOrDefault <int>(nameof(NumFrames));
            BoneCompressionSettings          = GetOrDefault <ResolvedObject>(nameof(BoneCompressionSettings));
            CurveCompressionSettings         = GetOrDefault <ResolvedObject>(nameof(CurveCompressionSettings));
            AdditiveAnimType                 = GetOrDefault <EAdditiveAnimationType>(nameof(AdditiveAnimType));
            RetargetSource                   = GetOrDefault <FName>(nameof(RetargetSource));
            RetargetSourceAssetReferencePose = GetOrDefault <FTransform[]>(nameof(RetargetSourceAssetReferencePose));

            if (BoneCompressionSettings == null && Ar.Game == EGame.GAME_RogueCompany)
            {
                BoneCompressionSettings = new ResolvedLoadedObject(Owner !.Provider !.LoadObject("/Game/Animation/KSAnimBoneCompressionSettings.KSAnimBoneCompressionSettings"));
            }

            var stripFlags = new FStripDataFlags(Ar);

            if (!stripFlags.IsEditorDataStripped())
            {
                RawAnimationData = Ar.ReadArray(() => new FRawAnimSequenceTrack(Ar));
                if (Ar.Ver >= EUnrealEngineObjectUE4Version.ANIMATION_ADD_TRACKCURVES)
                {
                    if (FUE5MainStreamObjectVersion.Get(Ar) < FUE5MainStreamObjectVersion.Type.RemovingSourceAnimationData)
                    {
                        var sourceRawAnimationData = Ar.ReadArray(() => new FRawAnimSequenceTrack(Ar));
                        if (sourceRawAnimationData.Length > 0)
                        {
                            // Set RawAnimationData to Source
                            RawAnimationData = sourceRawAnimationData;
                        }
                    }
                }
            }

            if (FFrameworkObjectVersion.Get(Ar) < FFrameworkObjectVersion.Type.MoveCompressedAnimDataToTheDDC)
            {
                var compressedData = new FUECompressedAnimData();
                CompressedDataStructure = compressedData;

                // Part of data were serialized as properties
                compressedData.CompressedByteStream = Ar.ReadBytes(Ar.Read <int>());
                if (Ar.Game == EGame.GAME_SeaOfThieves && compressedData.CompressedByteStream.Length == 1 && Ar.Length - Ar.Position > 0)
                {
                    // Sea of Thieves has extra int32 == 1 before the CompressedByteStream
                    Ar.Position -= 1;
                    compressedData.CompressedByteStream = Ar.ReadBytes(Ar.Read <int>());
                }

                // Fix layout of "byte swapped" data (workaround for UE4 bug)
                if (compressedData.KeyEncodingFormat == AnimationKeyFormat.AKF_PerTrackCompression && compressedData.CompressedScaleOffsets.OffsetData.Length > 0)
                {
                    compressedData.CompressedByteStream = TransferPerTrackData(compressedData.CompressedByteStream);
                }
            }
            else
            {
                // UE4.12+
                var bSerializeCompressedData = Ar.ReadBoolean();

                if (bSerializeCompressedData)
                {
                    if (Ar.Game < EGame.GAME_UE4_23)
                    {
                        SerializeCompressedData(Ar);
                    }
                    else if (Ar.Game < EGame.GAME_UE4_25)
                    {
                        SerializeCompressedData2(Ar);
                    }
                    else
                    {
                        SerializeCompressedData3(Ar);
                    }

                    bUseRawDataOnly = Ar.ReadBoolean();
                }
            }
        }