Example #1
0
        public static void SerializeBulkData <T>(this SerializingContainer2 sc, ref T[] arr, SerializeDelegate <T> serialize)
        {
            sc.SerializeConstInt(0);//bulkdataflags
            int elementCount = arr?.Length ?? 0;

            sc.Serialize(ref elementCount);
            long sizeOnDiskPosition = sc.ms.Position;

            sc.SerializeConstInt(0); //when saving, come back and rewrite this after writing arr
            sc.SerializeFileOffset();
            if (sc.IsLoading)
            {
                arr = new T[elementCount];
            }

            for (int i = 0; i < elementCount; i++)
            {
                serialize(sc, ref arr[i]);
            }

            if (sc.IsSaving)
            {
                long curPos = sc.ms.Position;
                sc.ms.JumpTo(sizeOnDiskPosition);
                sc.ms.Writer.WriteInt32((int)(curPos - (sizeOnDiskPosition + 8)));
                sc.ms.JumpTo(curPos);
            }
        }
Example #2
0
        public static void Serialize(this SerializingContainer2 sc, ref UTexture2D.Texture2DMipMap mip)
        {
            if (sc.IsLoading)
            {
                mip = new UTexture2D.Texture2DMipMap();
            }

            int mipStorageType = (int)mip.StorageType;

            sc.Serialize(ref mipStorageType);
            mip.StorageType = (StorageTypes)mipStorageType;
            sc.Serialize(ref mip.UncompressedSize);
            sc.Serialize(ref mip.CompressedSize);
            if (sc.IsSaving && mip.IsLocallyStored)
            {
                sc.SerializeFileOffset();
            }
            else
            {
                sc.Serialize(ref mip.DataOffset);
            }

            if (mip.IsLocallyStored)
            {
                sc.Serialize(ref mip.Mip, mip.CompressedSize);
            }
            sc.Serialize(ref mip.SizeX);
            sc.Serialize(ref mip.SizeY);
        }
Example #3
0
        protected override void Serialize(SerializingContainer2 sc)
        {
            if (sc.Game != MEGame.ME3)
            {
                int dummy = 0;
                sc.Serialize(ref dummy);
                sc.Serialize(ref dummy);
                sc.Serialize(ref dummy);
                sc.SerializeFileOffset();
            }
            sc.Serialize(ref Mips, SCExt.Serialize);
            if (sc.Game != MEGame.UDK)
            {
                sc.Serialize(ref Unk1);
            }

            if (sc.Game > MEGame.ME1)
            {
                sc.Serialize(ref TextureGuid);
            }

            if (sc.Game == MEGame.UDK)
            {
                var zeros = new byte[32];
                sc.Serialize(ref zeros, 32);
            }
            if (sc.Game == MEGame.ME3)
            {
                int dummy = 0;
                sc.Serialize(ref dummy);
            }
        }
Example #4
0
        protected override void Serialize(SerializingContainer2 sc)
        {
            if (sc.Game == MEGame.ME2)
            {
                int dummy = 0;
                sc.Serialize(ref dummy);
                sc.Serialize(ref dummy);
                sc.Serialize(ref dummy);
                sc.SerializeFileOffset();
            }

            if (sc.Game == MEGame.UDK)
            {
                if (sc.IsSaving && RawAnimationData is null)
                {
                    DecompressAnimationData();
                }
                sc.Serialize(ref RawAnimationData, SCExt.Serialize);
            }

            if (sc.IsLoading)
            {
                compressedDataSource = sc.Game;
                NumFrames            = Export.GetProperty <IntProperty>("NumFrames")?.Value ?? 0;
                RateScale            = Export.GetProperty <FloatProperty>("RateScale")?.Value ?? 1f;
                SequenceLength       = Export.GetProperty <FloatProperty>("SequenceLength")?.Value ?? 0;
                Name         = Export.GetProperty <NameProperty>("SequenceName")?.Value ?? Export.ObjectName;
                TrackOffsets = Export.GetProperty <ArrayProperty <IntProperty> >("CompressedTrackOffsets").Select(i => i.Value).ToArray();
                if (compressedDataSource == MEGame.UDK)
                {
                    Bones = ((ExportEntry)Export.Parent)?.GetProperty <ArrayProperty <NameProperty> >("TrackBoneNames")?.Select(np => $"{np}").ToList();
                }
                else
                {
                    var animsetData = Export.GetProperty <ObjectProperty>("m_pBioAnimSetData");
                    //In ME2, BioAnimSetData can sometimes be in a different package.
                    Bones = animsetData != null && Export.FileRef.IsUExport(animsetData.Value)
                        ? Export.FileRef.GetUExport(animsetData.Value)?.GetProperty <ArrayProperty <NameProperty> >("TrackBoneNames")?.Select(np => $"{np}").ToList()
                        : null;
                }

                Bones ??= Enumerable.Repeat("???", TrackOffsets.Length / 4).ToList();
                Enum.TryParse(Export.GetProperty <EnumProperty>("KeyEncodingFormat")?.Value.Name, out keyEncoding);
                Enum.TryParse(Export.GetProperty <EnumProperty>("RotationCompressionFormat")?.Value.Name, out rotCompression);
                Enum.TryParse(Export.GetProperty <EnumProperty>("TranslationCompressionFormat")?.Value.Name, out posCompression);
            }

            sc.Serialize(ref CompressedAnimationData, SCExt.Serialize);
        }
Example #5
0
        public static void SerializeBulkData(this SerializingContainer2 sc, ref byte[] arr, SerializeDelegate <byte> serialize = null)
        {
            sc.SerializeConstInt(0);//bulkdataflags
            int elementCount = arr?.Length ?? 0;

            sc.Serialize(ref elementCount);
            sc.Serialize(ref elementCount); //sizeondisk, which is equal to elementcount for a byte array
            sc.SerializeFileOffset();
            if (sc.IsLoading)
            {
                arr = sc.ms.ReadBytes(elementCount);
            }
            else if (elementCount > 0)
            {
                sc.ms.Writer.WriteBytes(arr);
            }
        }
Example #6
0
        protected override void Serialize(SerializingContainer2 sc)
        {
            if (sc.Game != MEGame.ME3 && sc.Game != MEGame.ME2)
            {
                throw new Exception($"WwiseBank is not a valid class for {sc.Game}!");
            }
            if (sc.Game == MEGame.ME2)
            {
                sc.Serialize(ref Unk1);
                sc.Serialize(ref Unk2);
                if (Unk1 == 0 && Unk2 == 0)
                {
                    return; //not sure what's going on here
                }
            }
            sc.Serialize(ref Unk3);
            var dataSizePos = sc.ms.Position; //come back to write size at the end
            int dataSize    = 0;

            sc.Serialize(ref dataSize);
            sc.Serialize(ref dataSize);
            sc.SerializeFileOffset();
            if (sc.IsLoading && dataSize == 0 || sc.IsSaving && Version == 0)
            {
                return;
            }

            if (sc.IsLoading)
            {
                sc.ms.Skip(4);
            }
            else
            {
                sc.ms.Writer.WriteUInt32(bkhd);
            }

            int bkhdLen = 8 + (bkhdUnks?.Length ?? 0) * 4;

            sc.Serialize(ref bkhdLen);
            sc.Serialize(ref Version);
            sc.Serialize(ref ID);
            if (sc.IsLoading)
            {
                bkhdUnks = new uint[(bkhdLen - 8) / 4];
            }

            for (int i = 0; i < bkhdUnks.Length; i++)
            {
                sc.Serialize(ref bkhdUnks[i]);
            }

            if (sc.IsLoading)
            {
                ReadChunks(sc);
            }
            else
            {
                WriteChunks(sc);
                var endPos = sc.ms.Position;
                sc.ms.JumpTo(dataSizePos);
                sc.ms.Writer.WriteInt32((int)(endPos - dataSizePos - 12));
                sc.ms.Writer.WriteInt32((int)(endPos - dataSizePos - 12));
                sc.ms.JumpTo(endPos);
            }
        }
Example #7
0
        public static void Serialize(this SerializingContainer2 sc, ref StaticMeshRenderData data)
        {
            if (sc.IsLoading)
            {
                data = new StaticMeshRenderData();
            }

            sc.SerializeBulkData(ref data.RawTriangles, Serialize);
            sc.Serialize(ref data.Elements, Serialize);
            sc.Serialize(ref data.PositionVertexBuffer);
            if (sc.IsSaving)
            {
                if (sc.Game >= MEGame.ME3 && data.ColorVertexBuffer == null)
                {
                    //this was read in from ME1 or ME2, we need to seperate out the color data
                    data.ColorVertexBuffer = new ColorVertexBuffer
                    {
                        VertexData  = data.VertexBuffer.VertexData.Select(vertex => vertex.Color).ToArray(),
                        NumVertices = (uint)data.VertexBuffer.VertexData.Length,
                        Stride      = 4
                    };
                }
                else if (sc.Game < MEGame.ME3 && data.ColorVertexBuffer != null)
                {
                    //this was read in from ME3 or UDK, we need to integrate the color data
                    // Why is this written backwards?
                    for (int i = data.VertexBuffer.VertexData.Length - 1; i >= 0; i--)
                    {
                        data.VertexBuffer.VertexData[i].Color = data.ColorVertexBuffer.VertexData[i];
                    }
                }
            }
            sc.Serialize(ref data.VertexBuffer);
            if (sc.Game >= MEGame.ME3)
            {
                sc.Serialize(ref data.ColorVertexBuffer);
            }

            if (sc.Game < MEGame.UDK)
            {
                sc.Serialize(ref data.ShadowExtrusionVertexBuffer);
            }
            else if (sc.IsLoading)
            {
                data.ShadowExtrusionVertexBuffer = new ExtrusionVertexBuffer
                {
                    Stride     = 4,
                    VertexData = Array.Empty <float>()
                };
            }
            sc.Serialize(ref data.NumVertices);
            int elementSize = 2;

            sc.Serialize(ref elementSize);
            sc.Serialize(ref data.IndexBuffer, SCExt.Serialize);
            elementSize = 2;
            sc.Serialize(ref elementSize);
            sc.Serialize(ref data.WireframeIndexBuffer, SCExt.Serialize);
            if (sc.Game != MEGame.UDK)
            {
                elementSize = 16;
                sc.Serialize(ref elementSize);
                sc.Serialize(ref data.Edges, Serialize);
                sc.Serialize(ref data.ShadowTriangleDoubleSided, SCExt.Serialize);
            }
            else if (sc.IsLoading)
            {
                data.Edges = Array.Empty <MeshEdge>();
                data.ShadowTriangleDoubleSided = Array.Empty <byte>();
            }
            if (sc.Game == MEGame.UDK)
            {
                sc.BulkSerialize(ref data.unkBuffer, SCExt.Serialize, 2);
            }
            if (sc.Game == MEGame.ME1)
            {
                sc.Serialize(ref data.unk1);

                int bulkDataFlags = 0;
                sc.Serialize(ref bulkDataFlags);
                int byteCount = data.xmlFile?.Length ?? 0;
                sc.Serialize(ref byteCount);
                sc.Serialize(ref byteCount);
                sc.SerializeFileOffset();
                sc.Serialize(ref data.xmlFile, byteCount);
            }
            else if (sc.IsLoading)
            {
                data.xmlFile = Array.Empty <byte>();
            }
        }