From 5fc4c592452a68ed0fcc947e27c86b60f4fbd4fc Mon Sep 17 00:00:00 2001 From: Jordan Cristiano Date: Thu, 30 Apr 2015 16:03:22 -0400 Subject: [PATCH] wip event parsing --- demboyz/demboyz.cpp | 54 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/demboyz/demboyz.cpp b/demboyz/demboyz.cpp index e0d5c47..d585f70 100644 --- a/demboyz/demboyz.cpp +++ b/demboyz/demboyz.cpp @@ -1,17 +1,61 @@ #include "demofile.h" +#include "demofilebitbuf.h" #include -#include +#include +#include + +std::vector eventNames; + +void ParseGameEvent(const std::string& eventBuf) +{ + CBitRead bitBuf(eventBuf.data(), eventBuf.size()); + uint32 eventId = bitBuf.ReadUBitLong(9); + printf("%s\n", eventNames[eventId-1].c_str()); +} + +void ParsePacket(const std::string& packetBuf) +{ + auto data = packetBuf.data(); + CBitRead bitBuf(packetBuf.data(), packetBuf.size()); + uint32 typeId = bitBuf.ReadUBitLong(5); + printf("%i\n", typeId); + if (typeId != 25) + { + return; + } + + uint32 length = bitBuf.ReadUBitLong(11); + int numBytes = (length / 8) + (length % 8 > 0); + + std::string subpacket; + subpacket.resize(numBytes); + + bitBuf.ReadBits(&subpacket[0], length); + ParseGameEvent(subpacket); +} + +void ParseEventNames(const char* eventfile, std::vector& eventNames) +{ + using namespace std; + ifstream eventStream(eventfile); + if (eventStream) + { + move(istream_iterator(eventStream), istream_iterator(), back_inserter(eventNames)); + } +} int main(const int argc, const char* argv[]) { - if (argc < 2) + if (argc < 3) { return -1; } + ParseEventNames(argv[1], eventNames); + CDemoFile demoFile; - if (!demoFile.Open(argv[1])) + if (!demoFile.Open(argv[2])) { return -1; } @@ -33,13 +77,15 @@ int main(const int argc, const char* argv[]) for (int i = 0; i <= numFrames; ++i) { demoFile.ReadCmdHeader(cmd, tick); - printf("tick: %i\n", tick); + //printf("tick: %i\n", tick); switch (cmd) { case dem_packet: demoFile.ReadCmdInfo(cmdInfo); demoFile.ReadSequenceInfo(sequenceInfo1, sequenceInfo2); + assert(sequenceInfo1 == sequenceInfo2); demoFile.ReadRawData(packetBuf); + ParsePacket(packetBuf); break; case dem_stop: assert(i == numFrames && tick == numTicks);