public void Serialize(Stream stream) { List<byte> part1Bytes = new List<byte>(); part1Bytes.AddRange(BitConverter.GetBytes(VersionMajor)); part1Bytes.AddRange(BitConverter.GetBytes(VersionMinor)); part1Bytes.AddRange(Unknown5.Serialize()); part1Bytes.AddRange(Properties.Serialize()); var bytes = part1Bytes.ToArray(); stream.Write(BitConverter.GetBytes(part1Bytes.Count), 0, 4); var crc = Crc32.CalculateCrc(bytes, 0, bytes.Length, CRC_SEED); stream.Write(BitConverter.GetBytes(crc), 0, 4); stream.Write(bytes, 0, part1Bytes.Count); List<byte> part2Bytes = new List<byte>(); part2Bytes.AddRange(BitConverter.GetBytes(Levels.Count)); foreach (var level in Levels) { part2Bytes.AddRange(level.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(KeyFrames.Count)); foreach (var keyFrame in KeyFrames) { part2Bytes.AddRange(keyFrame.Serialize()); } var bw = new BitWriter(8 * 1024 * 1024); // 1MB is a decent starting point Dictionary<UInt32, ActorState> newActorsById = new Dictionary<uint, ActorState>(); var maxChannels = MaxChannels(); foreach (Frame f in Frames) { f.Serialize(maxChannels, ref newActorsById, VersionMajor, VersionMinor, bw); } var networkStreamBytes = bw.GetBytes(); part2Bytes.AddRange(BitConverter.GetBytes(networkStreamBytes.Length)); part2Bytes.AddRange(networkStreamBytes); part2Bytes.AddRange(BitConverter.GetBytes(DebugStrings.Count)); foreach (var debugString in DebugStrings) { part2Bytes.AddRange(debugString.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(TickMarks.Count)); foreach (var tickMark in TickMarks) { part2Bytes.AddRange(tickMark.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(Packages.Count)); foreach (var packages in Packages) { part2Bytes.AddRange(packages.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(Objects.Length)); foreach (var obj in Objects) { part2Bytes.AddRange(obj.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(Names.Length)); foreach (var name in Names) { part2Bytes.AddRange(name.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(ClassIndexes.Count)); foreach (var classIndex in ClassIndexes) { part2Bytes.AddRange(classIndex.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(ClassNetCaches.Length)); foreach (var classNetCache in ClassNetCaches) { part2Bytes.AddRange(classNetCache.Serialize()); } bytes = part2Bytes.ToArray(); stream.Write(BitConverter.GetBytes(part2Bytes.Count), 0, 4); crc = Crc32.CalculateCrc(bytes, 0, bytes.Length, CRC_SEED); stream.Write(BitConverter.GetBytes(crc), 0, 4); stream.Write(bytes, 0, part2Bytes.Count); }
public void Serialize(Stream stream) { List <byte> part1Bytes = new List <byte>(); part1Bytes.AddRange(BitConverter.GetBytes(EngineVersion)); part1Bytes.AddRange(BitConverter.GetBytes(LicenseeVersion)); part1Bytes.AddRange(TAGame_Replay_Soccar_TA.Serialize()); part1Bytes.AddRange(Properties.Serialize()); var bytes = part1Bytes.ToArray(); stream.Write(BitConverter.GetBytes(part1Bytes.Count), 0, 4); var crc = Crc32.CalculateCrc(bytes, 0, bytes.Length, CRC_SEED); stream.Write(BitConverter.GetBytes(crc), 0, 4); stream.Write(bytes, 0, part1Bytes.Count); List <byte> part2Bytes = new List <byte>(); part2Bytes.AddRange(BitConverter.GetBytes(Levels.Count)); foreach (var level in Levels) { part2Bytes.AddRange(level.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(KeyFrames.Count)); foreach (var keyFrame in KeyFrames) { part2Bytes.AddRange(keyFrame.Serialize()); } var bw = new BitWriter(8 * 1024 * 1024); // 1MB is a decent starting point Dictionary <UInt32, ActorState> newActorsById = new Dictionary <uint, ActorState>(); var maxChannels = MaxChannels(); foreach (Frame f in Frames) { f.Serialize(maxChannels, ref newActorsById, EngineVersion, LicenseeVersion, bw); } var networkStreamBytes = bw.GetBytes(); part2Bytes.AddRange(BitConverter.GetBytes(networkStreamBytes.Length)); part2Bytes.AddRange(networkStreamBytes); part2Bytes.AddRange(BitConverter.GetBytes(DebugStrings.Count)); foreach (var debugString in DebugStrings) { part2Bytes.AddRange(debugString.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(TickMarks.Count)); foreach (var tickMark in TickMarks) { part2Bytes.AddRange(tickMark.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(Packages.Count)); foreach (var packages in Packages) { part2Bytes.AddRange(packages.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(Objects.Length)); foreach (var obj in Objects) { part2Bytes.AddRange(obj.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(Names.Length)); foreach (var name in Names) { part2Bytes.AddRange(name.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(ClassIndexes.Count)); foreach (var classIndex in ClassIndexes) { part2Bytes.AddRange(classIndex.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(ClassNetCaches.Length)); foreach (var classNetCache in ClassNetCaches) { part2Bytes.AddRange(classNetCache.Serialize()); } bytes = part2Bytes.ToArray(); stream.Write(BitConverter.GetBytes(part2Bytes.Count), 0, 4); crc = Crc32.CalculateCrc(bytes, 0, bytes.Length, CRC_SEED); stream.Write(BitConverter.GetBytes(crc), 0, 4); stream.Write(bytes, 0, part2Bytes.Count); }
public void Serialize(Stream stream) { List<byte> part1Bytes = new List<byte>(); part1Bytes.AddRange(BitConverter.GetBytes(EngineVersion)); part1Bytes.AddRange(BitConverter.GetBytes(LicenseeVersion)); if (EngineVersion >= 868 && LicenseeVersion >= 18) { part1Bytes.AddRange(BitConverter.GetBytes(NetVersion)); } part1Bytes.AddRange(TAGame_Replay_Soccar_TA.Serialize()); part1Bytes.AddRange(Properties.Serialize()); var bytes = part1Bytes.ToArray(); stream.Write(BitConverter.GetBytes(part1Bytes.Count), 0, 4); var crc = Crc32.CalculateCrc(bytes, 0, bytes.Length, CRC_SEED); stream.Write(BitConverter.GetBytes(crc), 0, 4); stream.Write(bytes, 0, part1Bytes.Count); List<byte> part2Bytes = new List<byte>(); part2Bytes.AddRange(BitConverter.GetBytes(Levels.Count)); foreach (var level in Levels) { part2Bytes.AddRange(level.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(KeyFrames.Count)); foreach (var keyFrame in KeyFrames) { part2Bytes.AddRange(keyFrame.Serialize()); } var bw = new BitWriter(8 * 1024 * 1024); // 1MB is a decent starting point var maxChannels = MaxChannels(); foreach (Frame f in Frames) { f.Serialize(maxChannels, Objects, EngineVersion, LicenseeVersion, NetVersion, bw); } var networkStreamBytes = bw.GetBytes(); var paddingSize = 512 - (networkStreamBytes.Length % 512); // Padding needed to match original replay files, but dont think it's necessary to produce good replay if ( paddingSize == 512 ) { paddingSize = 0; } part2Bytes.AddRange(BitConverter.GetBytes(networkStreamBytes.Length + paddingSize)); part2Bytes.AddRange(networkStreamBytes); for (int i = 0; i < paddingSize; ++i) { part2Bytes.Add(0); } part2Bytes.AddRange(BitConverter.GetBytes(DebugStrings.Count)); foreach (var debugString in DebugStrings) { part2Bytes.AddRange(debugString.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(TickMarks.Count)); foreach (var tickMark in TickMarks) { part2Bytes.AddRange(tickMark.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(Packages.Count)); foreach (var packages in Packages) { part2Bytes.AddRange(packages.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(Objects.Length)); foreach (var obj in Objects) { part2Bytes.AddRange(obj.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(Names.Length)); foreach (var name in Names) { part2Bytes.AddRange(name.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(ClassIndexes.Count)); foreach (var classIndex in ClassIndexes) { part2Bytes.AddRange(classIndex.Serialize()); } part2Bytes.AddRange(BitConverter.GetBytes(ClassNetCaches.Length)); foreach (var classNetCache in ClassNetCaches) { part2Bytes.AddRange(classNetCache.Serialize()); } if (NetVersion >= 10) { part2Bytes.AddRange(BitConverter.GetBytes(Unknown)); } bytes = part2Bytes.ToArray(); stream.Write(BitConverter.GetBytes(part2Bytes.Count), 0, 4); crc = Crc32.CalculateCrc(bytes, 0, bytes.Length, CRC_SEED); stream.Write(BitConverter.GetBytes(crc), 0, 4); stream.Write(bytes, 0, part2Bytes.Count); }