summaryrefslogtreecommitdiff
path: root/engine/demofile.h
blob: e93c91334532dbd7dba29b15e98bad82f2da2708 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//===========================================================================//

#ifndef DEMOFILE_H
#define DEMOFILE_H
#ifdef _WIN32
#pragma once
#endif

#define DEMO_FILE_UTLBUFFER 1
#define DEMO_FILE_MAX_STRINGTABLE_SIZE 5000000 // 5 mb

#include "demo.h"

#ifdef DEMO_FILE_UTLBUFFER
#include "tier2/utlstreambuffer.h"
#else
#include <filesystem.h>
#endif


#include "tier1/bitbuf.h"

//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class IDemoBuffer;

//-----------------------------------------------------------------------------
// Demo file 
//-----------------------------------------------------------------------------
class CDemoFile  
{
public:
	CDemoFile();
	~CDemoFile();

	bool	Open(const char *name, bool bReadOnly, bool bMemoryBuffer = false, int nBufferSize = 0, bool bAllowHeaderWrite = true);
	bool	IsOpen();
	void	Close();

	void	SeekTo( int position, bool bRead );
	unsigned int GetCurPos( bool bRead );
	int		GetSize();

	void	WriteRawData( const char *buffer, int length );
	int		ReadRawData( char *buffer, int length );

	void	WriteSequenceInfo(int nSeqNrIn, int nSeqNrOutAck);
	void	ReadSequenceInfo(int &nSeqNrIn, int &nSeqNrOutAck);

	void	WriteCmdInfo( democmdinfo_t& info );
	void	ReadCmdInfo( democmdinfo_t& info );

	void	WriteCmdHeader( unsigned char cmd, int tick );
	void	ReadCmdHeader( unsigned char& cmd, int& tick );
	
	void	WriteConsoleCommand( const char *cmd, int tick );
	const char *ReadConsoleCommand( void );

	void	WriteNetworkDataTables( bf_write *buf, int tick );
	int		ReadNetworkDataTables( bf_read *buf );
	
	void	WriteStringTables( bf_write *buf, int tick );
	int		ReadStringTables( bf_read *buf );

	void	WriteUserCmd( int cmdnumber, const char *buffer, unsigned char bytes, int tick );
	int		ReadUserCmd( char *buffer, int &size );

	void	WriteDemoHeader();
	demoheader_t *ReadDemoHeader();

	void	WriteFileBytes( FileHandle_t fh, int length );

	// Returns the PROTOCOL_VERSION used when .dem was recorded
	int		GetProtocolVersion();
public:
	char			m_szFileName[MAX_PATH];	//name of current demo file
	demoheader_t    m_DemoHeader;  //general demo info
	CUtlBuffer		*m_pBuffer;
	bool			m_bAllowHeaderWrite;
	bool			m_bIsStreamBuffer;
};

#endif // DEMOFILE_H