wip event parsing
This commit is contained in:
		@@ -1,17 +1,61 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "demofile.h"
 | 
					#include "demofile.h"
 | 
				
			||||||
 | 
					#include "demofilebitbuf.h"
 | 
				
			||||||
#include <assert.h>
 | 
					#include <assert.h>
 | 
				
			||||||
#include <memory>
 | 
					#include <vector>
 | 
				
			||||||
 | 
					#include <fstream>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					std::vector<std::string> 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<std::string>& eventNames)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    using namespace std;
 | 
				
			||||||
 | 
					    ifstream eventStream(eventfile);
 | 
				
			||||||
 | 
					    if (eventStream)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        move(istream_iterator<string>(eventStream), istream_iterator<string>(), back_inserter(eventNames));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(const int argc, const char* argv[])
 | 
					int main(const int argc, const char* argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (argc < 2)
 | 
					    if (argc < 3)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ParseEventNames(argv[1], eventNames);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    CDemoFile demoFile;
 | 
					    CDemoFile demoFile;
 | 
				
			||||||
    if (!demoFile.Open(argv[1]))
 | 
					    if (!demoFile.Open(argv[2]))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -33,13 +77,15 @@ int main(const int argc, const char* argv[])
 | 
				
			|||||||
    for (int i = 0; i <= numFrames; ++i)
 | 
					    for (int i = 0; i <= numFrames; ++i)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        demoFile.ReadCmdHeader(cmd, tick);
 | 
					        demoFile.ReadCmdHeader(cmd, tick);
 | 
				
			||||||
        printf("tick: %i\n", tick);
 | 
					        //printf("tick: %i\n", tick);
 | 
				
			||||||
        switch (cmd)
 | 
					        switch (cmd)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            case dem_packet:
 | 
					            case dem_packet:
 | 
				
			||||||
                demoFile.ReadCmdInfo(cmdInfo);
 | 
					                demoFile.ReadCmdInfo(cmdInfo);
 | 
				
			||||||
                demoFile.ReadSequenceInfo(sequenceInfo1, sequenceInfo2);
 | 
					                demoFile.ReadSequenceInfo(sequenceInfo1, sequenceInfo2);
 | 
				
			||||||
 | 
					                assert(sequenceInfo1 == sequenceInfo2);
 | 
				
			||||||
                demoFile.ReadRawData(packetBuf);
 | 
					                demoFile.ReadRawData(packetBuf);
 | 
				
			||||||
 | 
					                ParsePacket(packetBuf);
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case dem_stop:
 | 
					            case dem_stop:
 | 
				
			||||||
                assert(i == numFrames && tick == numTicks);
 | 
					                assert(i == numFrames && tick == numTicks);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user