Changes for TF2 demo compatibility

This commit is contained in:
Jordan Cristiano 2014-10-29 01:15:40 -04:00
parent 42b4ca87b7
commit 5e43ccfa06
3 changed files with 44 additions and 15 deletions

View File

@ -1,5 +1,6 @@
#include "demofile.h"
#include <assert.h>
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;

View File

@ -27,7 +27,9 @@
#include <assert.h>
#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();
}

View File

@ -34,7 +34,7 @@
#include <inttypes.h>
#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