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); } }
protected override void Serialize(SerializingContainer2 sc) { if (sc.IsLoading) { IsIndexed = !sc.ms.ReadBoolInt(); sc.ms.Skip(-4); } else { //If there are no cells, IsIndexed has to be true, since there is no way to differentiate between //a cell count of zero and the extra zero that is present when IsIndexed is true. IsIndexed |= Cells.IsEmpty(); } if (IsIndexed) { sc.SerializeConstInt(0); } int cellIndex = 0; //If IsIndexed, the index needs to be read and written, so just use the normal Serialize for ints. //If it's not indexed, we don't need to write anything, but the Dictionary still needs to be populated with a value sc.Serialize(ref Cells, IsIndexed ? (SCExt.SerializeDelegate <int>)SCExt.Serialize : (SerializingContainer2 sc2, ref int idx) => idx = cellIndex++, SCExt.Serialize); if (!IsIndexed) { sc.SerializeConstInt(0); } int count = ColumnNames?.Count ?? 0; sc.Serialize(ref count); if (sc.IsLoading) { int index = 0; ColumnNames = new List <NameReference>(count); for (int i = 0; i < count; i++) { NameReference tmp = default; sc.Serialize(ref tmp); sc.Serialize(ref index); ColumnNames.Add(tmp); } } else { for (int i = 0; i < count; i++) { NameReference tmp = ColumnNames[i]; sc.Serialize(ref tmp); sc.Serialize(ref i); } } }
protected override void Serialize(SerializingContainer2 sc) { if (sc.Pcc.Platform == MEPackage.GamePlatform.PS3) { // Unknown items sc.SerializeConstInt(0); sc.SerializeConstInt(0); } sc.SerializeBulkData(ref RawData, SCExt.Serialize); sc.SerializeBulkData(ref CompressedPCData, SCExt.Serialize); sc.SerializeBulkData(ref CompressedXbox360Data, SCExt.Serialize); sc.SerializeBulkData(ref CompressedPS3Data, SCExt.Serialize); }
protected override void Serialize(SerializingContainer2 sc) { if (sc.Game == MEGame.ME3) { sc.SerializeConstInt(4); } sc.Serialize(ref Samples, SCExt.Serialize); sc.Serialize(ref LightGuid); }
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); } }