From 91e63d3f390604154f9c5079488d45cdb6f71847 Mon Sep 17 00:00:00 2001 From: Jordan Cristiano Date: Sun, 14 Jun 2015 20:50:09 -0400 Subject: [PATCH] Copy trailing bits to output after each packet for file hash matching --- demboyz/io/conlogwriter.cpp | 4 ++-- demboyz/io/demowriter.cpp | 8 ++++++-- demboyz/io/demreader.cpp | 23 ++++++++++++++++++----- demboyz/io/idemowriter.h | 8 +++++++- demboyz/io/jsonwriter.cpp | 4 ++-- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/demboyz/io/conlogwriter.cpp b/demboyz/io/conlogwriter.cpp index 2c66070..fc0d831 100644 --- a/demboyz/io/conlogwriter.cpp +++ b/demboyz/io/conlogwriter.cpp @@ -13,7 +13,7 @@ public: virtual void EndWriting() override final; virtual void StartCommandPacket(CommandPacket& packet) override final; - virtual void EndCommandPacket() override final; + virtual void EndCommandPacket(const PacketTrailingBits& trailingBits) override final; virtual void WriteNetPacket(NetPacket& packet, SourceGameContext& context) override final; @@ -51,7 +51,7 @@ void ConLogWriter::StartCommandPacket(CommandPacket& packet) { } -void ConLogWriter::EndCommandPacket() +void ConLogWriter::EndCommandPacket(const PacketTrailingBits& trailingBits) { } diff --git a/demboyz/io/demowriter.cpp b/demboyz/io/demowriter.cpp index b432f9c..9c8af33 100644 --- a/demboyz/io/demowriter.cpp +++ b/demboyz/io/demowriter.cpp @@ -18,7 +18,7 @@ public: virtual void EndWriting() override final; virtual void StartCommandPacket(CommandPacket& packet) override final; - virtual void EndCommandPacket() override final; + virtual void EndCommandPacket(const PacketTrailingBits& trailingBits) override final; virtual void WriteNetPacket(NetPacket& packet, SourceGameContext& context) override final; @@ -56,8 +56,12 @@ void DemoWriter::StartCommandPacket(CommandPacket& packet) m_cmdPacketBuf.Reset(); } -void DemoWriter::EndCommandPacket() +void DemoWriter::EndCommandPacket(const PacketTrailingBits& trailingBits) { + if (trailingBits.numTrailingBits > 0) + { + m_cmdPacketBuf.WriteUBitLong(trailingBits.value, trailingBits.numTrailingBits); + } if (m_cmdPacketBuf.GetNumBytesWritten() > 0) { m_writer.WriteRawData(m_cmdPacketBuf.GetBasePointer(), m_cmdPacketBuf.GetNumBytesWritten()); diff --git a/demboyz/io/demreader.cpp b/demboyz/io/demreader.cpp index 36e826d..eb45ca1 100644 --- a/demboyz/io/demreader.cpp +++ b/demboyz/io/demreader.cpp @@ -111,9 +111,9 @@ static void DestroyDemMsgStructs(void* demDataStructs[9]) delete reinterpret_cast(demDataStructs[8]); } -void ParsePacket(uint8_t* packet, size_t length, - SourceGameContext& context, IDemoWriter* writer, - void* netDataStructs[32]) +PacketTrailingBits ParsePacket(uint8_t* packet, size_t length, + SourceGameContext& context, IDemoWriter* writer, + void* netDataStructs[32]) { assert(length <= NET_MAX_PAYLOAD); bf_read bitbuf(packet, length); @@ -125,6 +125,18 @@ void ParsePacket(uint8_t* packet, size_t length, NetHandlers::NetMsg_BitRead(netPacket.type, bitbuf, context, netPacket.data); writer->WriteNetPacket(netPacket, context); } + + PacketTrailingBits trailingBits; + trailingBits.numTrailingBits = bitbuf.GetNumBitsLeft(); + if (trailingBits.numTrailingBits) + { + trailingBits.value = bitbuf.ReadUBitLong(trailingBits.numTrailingBits); + } + else + { + trailingBits.value = 0; + } + return trailingBits; } void DemoReader::ProcessDem(void* inputFp, IDemoWriter* writer) @@ -151,13 +163,14 @@ void DemoReader::ProcessDem(void* inputFp, IDemoWriter* writer) packet.data = demDataStructs[packet.cmd]; DemHandlers::DemMsg_FileRead(packet.cmd, reader, packet.data); + PacketTrailingBits trailingBits = PacketTrailingBits(); writer->StartCommandPacket(packet); if (packet.cmd == dem_packet || packet.cmd == dem_signon) { Array buffer = reader.ReadRawData(NET_MAX_PAYLOAD); - ParsePacket(buffer.begin(), buffer.length(), context, writer, netDataStructs); + trailingBits = ParsePacket(buffer.begin(), buffer.length(), context, writer, netDataStructs); } - writer->EndCommandPacket(); + writer->EndCommandPacket(trailingBits); } while (packet.cmd != dem_stop); writer->EndWriting(); diff --git a/demboyz/io/idemowriter.h b/demboyz/io/idemowriter.h index 59bdfb0..0b8842d 100644 --- a/demboyz/io/idemowriter.h +++ b/demboyz/io/idemowriter.h @@ -23,6 +23,12 @@ struct NetPacket void* data; }; +struct PacketTrailingBits +{ + uint32_t numTrailingBits; + uint32_t value; +}; + class IDemoWriter { public: @@ -32,7 +38,7 @@ public: virtual void EndWriting() = 0; virtual void StartCommandPacket(CommandPacket& packet) = 0; - virtual void EndCommandPacket() = 0; + virtual void EndCommandPacket(const PacketTrailingBits& trailingBits) = 0; virtual void WriteNetPacket(NetPacket& packet, SourceGameContext& context) = 0; diff --git a/demboyz/io/jsonwriter.cpp b/demboyz/io/jsonwriter.cpp index 1b491a3..bb680e1 100644 --- a/demboyz/io/jsonwriter.cpp +++ b/demboyz/io/jsonwriter.cpp @@ -11,7 +11,7 @@ public: virtual void EndWriting() override final; virtual void StartCommandPacket(CommandPacket& packet) override final; - virtual void EndCommandPacket() override final; + virtual void EndCommandPacket(const PacketTrailingBits& trailingBits) override final; virtual void WriteNetPacket(NetPacket& packet, SourceGameContext& context) override final; }; @@ -37,7 +37,7 @@ void JsonWriter::StartCommandPacket(CommandPacket& packet) { } -void JsonWriter::EndCommandPacket() +void JsonWriter::EndCommandPacket(const PacketTrailingBits& trailingBits) { }