Copy trailing bits to output after each packet for file hash matching

This commit is contained in:
Jordan Cristiano 2015-06-14 20:50:09 -04:00
parent 361119f19f
commit 91e63d3f39
5 changed files with 35 additions and 12 deletions

View File

@ -13,7 +13,7 @@ public:
virtual void EndWriting() override final; virtual void EndWriting() override final;
virtual void StartCommandPacket(CommandPacket& packet) 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; 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)
{ {
} }

View File

@ -18,7 +18,7 @@ public:
virtual void EndWriting() override final; virtual void EndWriting() override final;
virtual void StartCommandPacket(CommandPacket& packet) 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; virtual void WriteNetPacket(NetPacket& packet, SourceGameContext& context) override final;
@ -56,8 +56,12 @@ void DemoWriter::StartCommandPacket(CommandPacket& packet)
m_cmdPacketBuf.Reset(); 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) if (m_cmdPacketBuf.GetNumBytesWritten() > 0)
{ {
m_writer.WriteRawData(m_cmdPacketBuf.GetBasePointer(), m_cmdPacketBuf.GetNumBytesWritten()); m_writer.WriteRawData(m_cmdPacketBuf.GetBasePointer(), m_cmdPacketBuf.GetNumBytesWritten());

View File

@ -111,9 +111,9 @@ static void DestroyDemMsgStructs(void* demDataStructs[9])
delete reinterpret_cast<DemMsg::Dem_StringTables*>(demDataStructs[8]); delete reinterpret_cast<DemMsg::Dem_StringTables*>(demDataStructs[8]);
} }
void ParsePacket(uint8_t* packet, size_t length, PacketTrailingBits ParsePacket(uint8_t* packet, size_t length,
SourceGameContext& context, IDemoWriter* writer, SourceGameContext& context, IDemoWriter* writer,
void* netDataStructs[32]) void* netDataStructs[32])
{ {
assert(length <= NET_MAX_PAYLOAD); assert(length <= NET_MAX_PAYLOAD);
bf_read bitbuf(packet, length); 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); NetHandlers::NetMsg_BitRead(netPacket.type, bitbuf, context, netPacket.data);
writer->WriteNetPacket(netPacket, context); 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) void DemoReader::ProcessDem(void* inputFp, IDemoWriter* writer)
@ -151,13 +163,14 @@ void DemoReader::ProcessDem(void* inputFp, IDemoWriter* writer)
packet.data = demDataStructs[packet.cmd]; packet.data = demDataStructs[packet.cmd];
DemHandlers::DemMsg_FileRead(packet.cmd, reader, packet.data); DemHandlers::DemMsg_FileRead(packet.cmd, reader, packet.data);
PacketTrailingBits trailingBits = PacketTrailingBits();
writer->StartCommandPacket(packet); writer->StartCommandPacket(packet);
if (packet.cmd == dem_packet || packet.cmd == dem_signon) if (packet.cmd == dem_packet || packet.cmd == dem_signon)
{ {
Array<uint8_t> buffer = reader.ReadRawData(NET_MAX_PAYLOAD); Array<uint8_t> 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); } while (packet.cmd != dem_stop);
writer->EndWriting(); writer->EndWriting();

View File

@ -23,6 +23,12 @@ struct NetPacket
void* data; void* data;
}; };
struct PacketTrailingBits
{
uint32_t numTrailingBits;
uint32_t value;
};
class IDemoWriter class IDemoWriter
{ {
public: public:
@ -32,7 +38,7 @@ public:
virtual void EndWriting() = 0; virtual void EndWriting() = 0;
virtual void StartCommandPacket(CommandPacket& packet) = 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; virtual void WriteNetPacket(NetPacket& packet, SourceGameContext& context) = 0;

View File

@ -11,7 +11,7 @@ public:
virtual void EndWriting() override final; virtual void EndWriting() override final;
virtual void StartCommandPacket(CommandPacket& packet) 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; 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)
{ {
} }