예제 #1
0
        public static void SerializeBulkData <T>(this SerializingContainer2 sc, ref T[] arr, SerializeDelegate <T> serialize)
        {
            int bulkdataflags = 0;

            sc.Serialize(ref bulkdataflags);
            int elementCount = arr?.Length ?? 0;

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

            sc.Serialize(ref sizeOnDisk); //when saving, come back and rewrite this after writing arr
            int offsetInFile = sc.FileOffset + 4;

            sc.Serialize(ref offsetInFile);
            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.WriteInt32((int)(curPos - (sizeOnDiskPosition + 8)));
                sc.ms.JumpTo(curPos);
            }
        }
예제 #2
0
        public static void Serialize(this SerializingContainer2 sc, ref PerPolyBoneCollisionData bcd)
        {
            if (sc.IsLoading)
            {
                bcd = new PerPolyBoneCollisionData();
            }
            if (sc.IsSaving)
            {
                if (sc.Game >= MEGame.ME3 && bcd.kDOPTreeME3UDK == null)
                {
                    bcd.kDOPTreeME3UDK = KDOPTreeBuilder.ToCompact(bcd.kDOPTreeME1ME2.Triangles, bcd.CollisionVerts);
                }
                else if (sc.Game <= MEGame.ME2 && bcd.kDOPTreeME1ME2 == null)
                {
                    //todo: need to convert kDOPTreeCompact to kDOPTree
                    throw new NotImplementedException("Cannot convert this SkeletalMesh to ME1 or ME2 format :(");
                }
            }
            if (sc.Game >= MEGame.ME3)
            {
                sc.Serialize(ref bcd.kDOPTreeME3UDK);
            }
            else
            {
                sc.Serialize(ref bcd.kDOPTreeME1ME2);
            }

            sc.Serialize(ref bcd.CollisionVerts, Serialize);
        }
예제 #3
0
 private static void Serialize(this SerializingContainer2 sc, LightMap_5 lmap)
 {
     sc.Serialize(ref lmap.LightGuids, Serialize);
     sc.Serialize(ref lmap.unkInt);
     sc.SerializeBulkData(ref lmap.SimpleSamples, Serialize);
     sc.Serialize(ref lmap.unkVector);
 }
예제 #4
0
        public static void Serialize(this SerializingContainer2 sc, ref Shader shader)
        {
            if (sc.IsLoading)
            {
                shader = new Shader();
            }
            sc.Serialize(ref shader.ShaderType);
            sc.Serialize(ref shader.Guid);
            int  endOffset    = 0;
            long endOffsetPos = sc.ms.Position;

            sc.Serialize(ref endOffset);
            byte platform = 0;

            sc.Serialize(ref platform);
            sc.Serialize(ref shader.Frequency);
            sc.Serialize(ref shader.ShaderByteCode, Serialize);
            sc.Serialize(ref shader.ParameterMapCRC);
            sc.Serialize(ref shader.Guid);       //intentional duplicate
            sc.Serialize(ref shader.ShaderType); //intentional duplicate
            sc.Serialize(ref shader.InstructionCount);
            if (sc.IsLoading)
            {
                shader.unkBytes = sc.ms.ReadToBuffer(endOffset - sc.FileOffset);
            }
            else
            {
                sc.ms.WriteFromBuffer(shader.unkBytes);
                endOffset = sc.FileOffset;
                long endPos = sc.ms.Position;
                sc.ms.JumpTo(endOffsetPos);
                sc.ms.WriteInt32(endOffset);
                sc.ms.JumpTo(endPos);
            }
        }
예제 #5
0
 private static void Serialize(this SerializingContainer2 sc, LightMap_3 lmap)
 {
     sc.Serialize(ref lmap.LightGuids, Serialize);
     sc.Serialize(ref lmap.unkInt);
     sc.SerializeBulkData(ref lmap.DirectionalSamples, Serialize);
     sc.Serialize(ref lmap.unkVector1);
     sc.Serialize(ref lmap.unkVector2);
 }
예제 #6
0
 public static void Serialize(this SerializingContainer2 sc, ref Sphere sphere)
 {
     if (sc.IsLoading)
     {
         sphere = new Sphere();
     }
     sc.Serialize(ref sphere.Center);
     sc.Serialize(ref sphere.W);
 }
예제 #7
0
 public static void Serialize(this SerializingContainer2 sc, ref ShaderReference shaderRef)
 {
     if (sc.IsLoading)
     {
         shaderRef = new ShaderReference();
     }
     sc.Serialize(ref shaderRef.Id);
     sc.Serialize(ref shaderRef.ShaderType);
 }
예제 #8
0
 public static void Serialize(this SerializingContainer2 sc, ref TerrainMaterialMask mask)
 {
     if (sc.IsLoading)
     {
         mask = new TerrainMaterialMask();
     }
     sc.Serialize(ref mask.NumBits);
     sc.Serialize(ref mask.BitMask);
 }
예제 #9
0
 public static void Serialize(this SerializingContainer2 sc, ref Box box)
 {
     if (sc.IsLoading)
     {
         box = new Box();
     }
     sc.Serialize(ref box.Min);
     sc.Serialize(ref box.Max);
     sc.Serialize(ref box.IsValid);
 }
예제 #10
0
 public static void Serialize(this SerializingContainer2 sc, ref BoxSphereBounds bounds)
 {
     if (sc.IsLoading)
     {
         bounds = new BoxSphereBounds();
     }
     sc.Serialize(ref bounds.Origin);
     sc.Serialize(ref bounds.BoxExtent);
     sc.Serialize(ref bounds.SphereRadius);
 }
예제 #11
0
        public static void Serialize(this SerializingContainer2 sc, ref StreamableTextureInstance texInst)
        {
            if (sc.IsLoading)
            {
                texInst = new StreamableTextureInstance();
            }

            sc.Serialize(ref texInst.BoundingSphere);
            sc.Serialize(ref texInst.TexelFactor);
        }
예제 #12
0
        public static void Serialize(this SerializingContainer2 sc, ref CachedPhysSMData smData)
        {
            if (sc.IsLoading)
            {
                smData = new CachedPhysSMData();
            }

            sc.Serialize(ref smData.Scale3D);
            sc.Serialize(ref smData.CachedDataIndex);
        }
 public static void Serialize(this SerializingContainer2 sc, ref FragmentInfo info)
 {
     if (sc.IsLoading)
     {
         info = new FragmentInfo();
     }
     sc.Serialize(ref info.Center);
     sc.Serialize(ref info.ConvexHull);
     sc.Serialize(ref info.Bounds);
     if (sc.Game >= MEGame.ME3)
     {
         sc.Serialize(ref info.Neighbours, Serialize);
         sc.Serialize(ref info.bCanBeDestroyed);
         sc.Serialize(ref info.bRootFragment);
         sc.Serialize(ref info.bNeverSpawnPhysicsChunk);
         sc.Serialize(ref info.AverageExteriorNormal);
         sc.Serialize(ref info.NeighbourDims, Serialize);
     }
     else if (sc.IsLoading)
     {
         info.Neighbours      = new byte[info.ConvexHull.FacePlaneData.Length];
         info.bCanBeDestroyed = true;
         info.NeighbourDims   = new float[info.Neighbours.Length];
         for (int i = 0; i < info.NeighbourDims.Length; i++)
         {
             info.NeighbourDims[i] = 1;
         }
     }
 }
예제 #14
0
 public static void Serialize(SerializingContainer2 sc, ref ZoneProperties zone)
 {
     if (sc.IsLoading)
     {
         zone = new ZoneProperties();
     }
     sc.Serialize(ref zone.ZoneActor);
     sc.Serialize(ref zone.LastRenderTime);
     sc.Serialize(ref zone.ConnectivityMask);
     sc.Serialize(ref zone.VisibilityMask);
 }
예제 #15
0
        public static void Serialize(this SerializingContainer2 sc, ref KCachedConvexDataElement convDataElem)
        {
            if (sc.IsLoading)
            {
                convDataElem = new KCachedConvexDataElement();
            }

            int byteSize = 1;

            sc.Serialize(ref byteSize);
            sc.Serialize(ref convDataElem.ConvexElementData, Serialize);
        }
예제 #16
0
        public static void Serialize(this SerializingContainer2 sc, ref KCachedPerTriData triData)
        {
            if (sc.IsLoading)
            {
                triData = new KCachedPerTriData();
            }

            int byteSize = 1;

            sc.Serialize(ref byteSize);
            sc.Serialize(ref triData.CachedPerTriData, Serialize);
        }
예제 #17
0
 public static void Serialize(SerializingContainer2 sc, ref ModelVertex vert)
 {
     if (sc.IsLoading)
     {
         vert = new ModelVertex();
     }
     sc.Serialize(ref vert.Position);
     sc.Serialize(ref vert.TangentX);
     sc.Serialize(ref vert.TangentZ);
     sc.Serialize(ref vert.TexCoord);
     sc.Serialize(ref vert.ShadowTexCoord);
 }
예제 #18
0
 public static void Serialize(this SerializingContainer2 sc, ref MeshShaderMap msm)
 {
     if (sc.IsLoading)
     {
         msm = new MeshShaderMap();
     }
     sc.Serialize(ref msm.Shaders, Serialize, Serialize);
     sc.Serialize(ref msm.VertexFactoryType);
     if (sc.Game == MEGame.ME1)
     {
         sc.Serialize(ref msm.unk);
     }
 }
예제 #19
0
        public static void Serialize(this SerializingContainer2 sc, ref kDOPNode kDopNode)
        {
            if (sc.IsLoading)
            {
                kDopNode = new kDOPNode();
            }

            sc.Serialize(ref kDopNode.BoundingVolume);
            sc.Serialize(ref kDopNode.bIsLeaf);
            //depending on bIsLeaf, next two are either LeftNode and RightNode, or NumTriangles and StartIndex.
            //But since it's a union, they share space in memory, so it doesn't matter for serialization purposes
            sc.Serialize(ref kDopNode.u.LeftNode);
            sc.Serialize(ref kDopNode.u.RightNode);
        }
예제 #20
0
        public static void Serialize(this SerializingContainer2 sc, ref QuantizedDirectionalLightSample samp)
        {
            if (sc.IsLoading)
            {
                samp = new QuantizedDirectionalLightSample();
            }

            if (sc.Game != MEGame.ME3)
            {
                sc.Serialize(ref samp.Coefficient1);
            }
            sc.Serialize(ref samp.Coefficient2);
            sc.Serialize(ref samp.Coefficient3);
        }
예제 #21
0
        public static void Serialize(this SerializingContainer2 sc, ref ExtrusionVertexBuffer vBuff)
        {
            if (sc.IsLoading)
            {
                vBuff = new ExtrusionVertexBuffer();
            }

            sc.Serialize(ref vBuff.Stride);
            sc.Serialize(ref vBuff.NumVertices);
            int elementsize = 4;

            sc.Serialize(ref elementsize);
            sc.Serialize(ref vBuff.VertexData, Serialize);
        }
예제 #22
0
        public static void Serialize(this SerializingContainer2 sc, ref kDOPTree kDopTree)
        {
            if (sc.IsLoading)
            {
                kDopTree = new kDOPTree();
            }

            int elementSize = 32;

            sc.Serialize(ref elementSize);
            sc.Serialize(ref kDopTree.Nodes, Serialize);
            elementSize = 8;
            sc.Serialize(ref elementSize);
            sc.Serialize(ref kDopTree.Triangles, Serialize);
        }
예제 #23
0
        public static void Serialize(this SerializingContainer2 sc, ref TerrainInfoFlags flags)
        {
            byte b = (byte)flags;

            sc.Serialize(ref b);
            flags = (TerrainInfoFlags)b;
        }
예제 #24
0
        public static void BulkSerialize <T>(this SerializingContainer2 sc, ref T[] arr, SerializeDelegate <T> serialize, int elementSize)
        {
            sc.Serialize(ref elementSize);
            int count = arr?.Length ?? 0;

            sc.Serialize(ref count);
            if (sc.IsLoading)
            {
                arr = new T[count];
            }

            for (int i = 0; i < count; i++)
            {
                serialize(sc, ref arr[i]);
            }
        }
예제 #25
0
        public static void Serialize <TKey, TValue>(this SerializingContainer2 sc, ref OrderedMultiValueDictionary <TKey, TValue> dict, SerializeDelegate <TKey> serializeKey, SerializeDelegate <TValue> serializeValue)
        {
            int count = dict?.Count ?? 0;

            sc.Serialize(ref count);
            if (sc.IsLoading)
            {
                dict = new OrderedMultiValueDictionary <TKey, TValue>(count);
                for (int i = 0; i < count; i++)
                {
                    TKey key = default;
                    serializeKey(sc, ref key);
                    TValue value = default;
                    serializeValue(sc, ref value);
                    dict.Add(key, value);
                }
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    var key = dict[i].Key;
                    serializeKey(sc, ref key);
                    var value = dict[i].Value;
                    serializeValue(sc, ref value);
                }
            }
        }
예제 #26
0
        public static void Serialize(this SerializingContainer2 sc, ref kDOP kDop)
        {
            if (sc.IsLoading)
            {
                kDop = new kDOP();
            }

            for (int i = 0; i < 3; i++)
            {
                sc.Serialize(ref kDop.Min[i]);
            }
            for (int i = 0; i < 3; i++)
            {
                sc.Serialize(ref kDop.Max[i]);
            }
        }
예제 #27
0
        public static void Serialize(this SerializingContainer2 sc, ref kDOPTreeCompact kDopTree)
        {
            if (sc.IsLoading)
            {
                kDopTree = new kDOPTreeCompact();
            }

            sc.Serialize(ref kDopTree.RootBound);
            int elementSize = 6;

            sc.Serialize(ref elementSize);
            sc.Serialize(ref kDopTree.Nodes, Serialize);
            elementSize = 8;
            sc.Serialize(ref elementSize);
            sc.Serialize(ref kDopTree.Triangles, Serialize);
        }
예제 #28
0
        public static void Serialize(this SerializingContainer2 sc, ref MeshEdge edge)
        {
            if (sc.IsLoading)
            {
                edge = new MeshEdge();
            }

            for (int i = 0; i < 2; i++)
            {
                sc.Serialize(ref edge.Vertices[i]);
            }
            for (int i = 0; i < 2; i++)
            {
                sc.Serialize(ref edge.Faces[i]);
            }
        }
예제 #29
0
 public static void Serialize(this SerializingContainer2 sc, ref AlphaMap map)
 {
     if (sc.IsLoading)
     {
         map = new AlphaMap();
     }
     sc.Serialize(ref map.Data, Serialize);
 }
예제 #30
0
        public static void Serialize(this SerializingContainer2 sc, ref GPUSkinVertex gsv)
        {
            if (sc.IsLoading)
            {
                gsv = new GPUSkinVertex();
            }

            if (sc.Game == MEGame.ME2)
            {
                sc.Serialize(ref gsv.Position);
            }
            sc.Serialize(ref gsv.TangentX);
            sc.Serialize(ref gsv.TangentZ);
            for (int i = 0; i < 4; i++)
            {
                sc.Serialize(ref gsv.InfluenceBones[i]);
            }
            for (int i = 0; i < 4; i++)
            {
                sc.Serialize(ref gsv.InfluenceWeights[i]);
            }
            if (sc.Game >= MEGame.ME3)
            {
                sc.Serialize(ref gsv.Position);
            }
            sc.Serialize(ref gsv.UV);
        }