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); } }
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); }
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); }
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); } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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; } } }
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); }
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); }
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); }
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); }
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); } }
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); }
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); }
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); }
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); }
public static void Serialize(this SerializingContainer2 sc, ref TerrainInfoFlags flags) { byte b = (byte)flags; sc.Serialize(ref b); flags = (TerrainInfoFlags)b; }
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]); } }
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); } } }
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]); } }
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); }
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]); } }
public static void Serialize(this SerializingContainer2 sc, ref AlphaMap map) { if (sc.IsLoading) { map = new AlphaMap(); } sc.Serialize(ref map.Data, Serialize); }
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); }