diff --git a/demboyz/demboyz.cpp b/demboyz/demboyz.cpp index c415d47..6644166 100644 --- a/demboyz/demboyz.cpp +++ b/demboyz/demboyz.cpp @@ -1,5 +1,6 @@ #include "demofile.h" +#include int main(const int argc, const char* argv[]) { @@ -14,6 +15,14 @@ int main(const int argc, const char* argv[]) return -1; } + auto demoHeader = demoFile.GetDemoHeader(); + + unsigned char cmd; + int32 tick; + demoFile.ReadCmdHeader(cmd, tick); + + assert(cmd == dem_synctick && tick == 0); + demoFile.Close(); return 0; diff --git a/demboyz/demofile.cpp b/demboyz/demofile.cpp index 166ddcb..7e1f74e 100644 --- a/demboyz/demofile.cpp +++ b/demboyz/demofile.cpp @@ -27,7 +27,9 @@ #include #include "demofile.h" -CDemoFile::CDemoFile() +CDemoFile::CDemoFile(): + m_DemoHeader(), + m_fileBufferPos(0) { } @@ -56,7 +58,7 @@ void CDemoFile::ReadCmdInfo( democmdinfo_t& info ) m_fileBufferPos += sizeof( democmdinfo_t ); } -void CDemoFile::ReadCmdHeader( unsigned char& cmd, int32& tick, unsigned char& playerSlot ) +void CDemoFile::ReadCmdHeader( unsigned char& cmd, int32& tick ) { if ( !m_fileBuffer.size() ) return; @@ -77,10 +79,6 @@ void CDemoFile::ReadCmdHeader( unsigned char& cmd, int32& tick, unsigned char& p // Read the timestamp tick = *( int32 * )( &m_fileBuffer[ m_fileBufferPos ] ); m_fileBufferPos += sizeof( int32 ); - - // read playerslot - playerSlot = *( unsigned char * )( &m_fileBuffer[ m_fileBufferPos ] ); - m_fileBufferPos += sizeof( unsigned char ); } int32 CDemoFile::ReadUserCmd( char *buffer, int32 &size ) @@ -164,6 +162,14 @@ bool CDemoFile::Open( const char *name ) return false; } + const int32 signOnLength = m_DemoHeader.signonlength; + if (signOnLength > 0) + { + m_signOnData.resize(signOnLength); + fread(&m_signOnData[0], 1, signOnLength, fp); + Length -= signOnLength; + } + m_fileBuffer.resize( Length ); fread( &m_fileBuffer[ 0 ], 1, Length, fp ); @@ -186,7 +192,8 @@ bool CDemoFile::Open( const char *name ) void CDemoFile::Close() { m_szFileName.clear(); + m_signOnData.clear(); + m_fileBuffer.clear(); m_fileBufferPos = 0; - m_fileBuffer.clear(); } diff --git a/demboyz/demofile.h b/demboyz/demofile.h index eb5202e..7c6c226 100644 --- a/demboyz/demofile.h +++ b/demboyz/demofile.h @@ -34,7 +34,7 @@ #include #define DEMO_HEADER_ID "HL2DEMO" -#define DEMO_PROTOCOL 4 +#define DEMO_PROTOCOL 3 #if !defined( MAX_OSPATH ) #define MAX_OSPATH 260 // max length of a filesystem pathname @@ -92,7 +92,7 @@ struct demoheader_t #define FDEMO_USE_ANGLES2 ( 1 << 1 ) #define FDEMO_NOINTERP ( 1 << 2 ) // don't interpolate between this an last view -#define MAX_SPLITSCREEN_CLIENTS 2 +#define MAX_SPLITSCREEN_CLIENTS 1 struct QAngle { @@ -218,11 +218,11 @@ struct democmdinfo_t Split_t u[ MAX_SPLITSCREEN_CLIENTS ]; }; -class CDemoFile +class CDemoFile { public: CDemoFile(); - virtual ~CDemoFile(); + ~CDemoFile(); bool Open( const char *name ); void Close(); @@ -233,19 +233,32 @@ public: void ReadCmdInfo( democmdinfo_t& info ); - void ReadCmdHeader( unsigned char &cmd, int32 &tick, unsigned char& playerSlot ); + void ReadCmdHeader( unsigned char &cmd, int32 &tick ); int32 ReadUserCmd( char *buffer, int32 &size ); - demoheader_t *ReadDemoHeader(); + const demoheader_t *GetDemoHeader() const; -public: + const std::string& GetSignOnData() const; + +private: demoheader_t m_DemoHeader; //general demo info std::string m_szFileName; + std::string m_signOnData; + std::string m_fileBuffer; size_t m_fileBufferPos; - std::string m_fileBuffer; }; +inline const demoheader_t *CDemoFile::GetDemoHeader() const +{ + return &m_DemoHeader; +} + +inline const std::string& CDemoFile::GetSignOnData() const +{ + return m_signOnData; +} + #endif // DEMOFILE_H