From e13608fcd696765c1bafc5c3dd7edd2d879f3e3e Mon Sep 17 00:00:00 2001 From: Jordan Cristiano Date: Thu, 14 May 2015 22:02:29 -0400 Subject: [PATCH] Linking fixes, added game context var --- demboyz/demreader.cpp | 28 +++++++++++++--------------- demboyz/netmessages/nethandlers.h | 13 +++++-------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/demboyz/demreader.cpp b/demboyz/demreader.cpp index eb3ae04..c1545aa 100644 --- a/demboyz/demreader.cpp +++ b/demboyz/demreader.cpp @@ -15,7 +15,7 @@ typedef bool (*NetMsgReadFn)(bf_read& bitbuf, SourceGameContext& context, void* static const NetMsgReadFn netHandlers[] = DECLARE_NET_HANDLER_ARRAY(BitRead); //static const void* netDataStructs[] = DECLARE_NET_DATA_ARRAY; -void ParsePacket(uint8_t* packet, size_t length, IDemoWriter* writer) +void ParsePacket(uint8_t* packet, size_t length, SourceGameContext& context, IDemoWriter* writer) { assert(length <= NET_MAX_PAYLOAD); bf_read bitbuf(packet, length); @@ -24,12 +24,21 @@ void ParsePacket(uint8_t* packet, size_t length, IDemoWriter* writer) { netPacket.type = bitbuf.ReadUBitLong(NETMSG_TYPE_BITS); //netPacket.data = netDataStructs[netPacket.type]; - //netHandlers[netPacket.type](bitbuf, context, ); + netHandlers[netPacket.type](bitbuf, context, nullptr); } } -void ParseDemo(DemoFileReader& reader, IDemoWriter* writer) +void DemoReader::ProcessDem(void* inputFp, IDemoWriter* writer) { + SourceGameContext context; + DemoFileReader reader(reinterpret_cast(inputFp)); + { + demoheader_t header; + reader.ReadDemoHeader(header); + writer->StartWriting(header); + context.protocol = header.networkprotocol; + } + democmdinfo_t cmdInfo; CommandPacket packet; packet.cmdInfo = &cmdInfo; @@ -77,20 +86,9 @@ void ParseDemo(DemoFileReader& reader, IDemoWriter* writer) writer->StartCommandPacket(packet); if (packet.cmd == dem_packet || packet.cmd == dem_signon) { - ParsePacket(buffer.data(), buffer.size(), writer); + ParsePacket(buffer.data(), buffer.size(), context, writer); } writer->EndCommandPacket(); } while (packet.cmd != dem_stop); -} - -void DemoReader::ProcessDem(void* inputFp, IDemoWriter* writer) -{ - DemoFileReader demoFile(reinterpret_cast(inputFp)); - { - demoheader_t header; - demoFile.ReadDemoHeader(header); - writer->StartWriting(header); - } - ParseDemo(demoFile, writer); writer->EndWriting(); } diff --git a/demboyz/netmessages/nethandlers.h b/demboyz/netmessages/nethandlers.h index 44fbc10..b1842b2 100644 --- a/demboyz/netmessages/nethandlers.h +++ b/demboyz/netmessages/nethandlers.h @@ -21,14 +21,11 @@ struct SourceGameContext #define DECLARE_NET_HANDLERS(msgname) \ namespace NetHandlers \ { \ - namespace \ - { \ - bool msgname##_BitRead_Internal(bf_read& bitbuf, SourceGameContext& context, NetMsg::##msgname* data); \ - bool msgname##_BitWrite_Internal(bf_write& bitbuf, SourceGameContext& context, NetMsg::##msgname* data); \ - bool msgname##_JsonRead_Internal(JsonRead& jsonbuf, SourceGameContext& context, NetMsg::##msgname* data); \ - bool msgname##_JsonWrite_Internal(JsonWrite& jsonbuf, SourceGameContext& context, NetMsg::##msgname* data); \ - void msgname##_ToString_Internal(std::ostringstream& out, NetMsg::##msgname* data); \ - } \ + bool msgname##_BitRead_Internal(bf_read& bitbuf, SourceGameContext& context, NetMsg::##msgname* data); \ + bool msgname##_BitWrite_Internal(bf_write& bitbuf, SourceGameContext& context, NetMsg::##msgname* data); \ + bool msgname##_JsonRead_Internal(JsonRead& jsonbuf, SourceGameContext& context, NetMsg::##msgname* data); \ + bool msgname##_JsonWrite_Internal(JsonWrite& jsonbuf, SourceGameContext& context, NetMsg::##msgname* data); \ + void msgname##_ToString_Internal(std::ostringstream& out, NetMsg::##msgname* data); \ inline bool msgname##_BitRead(bf_read& bitbuf, SourceGameContext& context, void* data) \ { \ return msgname##_BitRead_Internal(bitbuf, context, reinterpret_cast(data)); \