public static void Serialize(this SerializingContainer2 sc, ref StaticReceiverData dat) { if (sc.IsLoading) { dat = new StaticReceiverData(); } sc.Serialize(ref dat.PrimitiveComponent); sc.BulkSerialize(ref dat.Vertices, Serialize, sc.Game == MEGame.ME3 ? 28 : 52); sc.BulkSerialize(ref dat.Indices, Serialize, 2); sc.Serialize(ref dat.NumTriangles); sc.Serialize(ref dat.LightMap); if (sc.Game == MEGame.ME3) { sc.Serialize(ref dat.ShadowMap1D, Serialize); sc.Serialize(ref dat.Data); sc.Serialize(ref dat.InstanceIndex); } }
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 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, Serialize); elementSize = 2; sc.Serialize(ref elementSize); sc.Serialize(ref data.WireframeIndexBuffer, Serialize); if (sc.Game != MEGame.UDK) { elementSize = 16; sc.Serialize(ref elementSize); sc.Serialize(ref data.Edges, Serialize); sc.Serialize(ref data.ShadowTriangleDoubleSided, 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, 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); int xmlOffsetInFile = sc.FileOffset + 4; sc.Serialize(ref xmlOffsetInFile); sc.Serialize(ref data.xmlFile, byteCount); } else if (sc.IsLoading) { data.xmlFile = Array.Empty <byte>(); } }