DDraceNetwork Docs
ghost.h
Go to the documentation of this file.
1#ifndef ENGINE_CLIENT_GHOST_H
2#define ENGINE_CLIENT_GHOST_H
3
4#include <engine/ghost.h>
5
6#include <cstdint>
7
8enum
9{
13};
14static_assert(MAX_CHUNK_SIZE % sizeof(uint32_t) == 0, "Chunk size must be aligned with uint32_t");
15
16// version 4-6
18{
19 unsigned char m_aMarker[8];
20 unsigned char m_Version;
22 char m_aMap[64];
23 unsigned char m_aZeroes[sizeof(int32_t)]; // Crc before version 6
24 unsigned char m_aNumTicks[sizeof(int32_t)];
25 unsigned char m_aTime[sizeof(int32_t)];
27
28 int GetTicks() const;
29 int GetTime() const;
30 CGhostInfo ToGhostInfo() const;
31};
32
34{
35public:
36 alignas(uint32_t) unsigned char m_aData[MAX_ITEM_SIZE];
37 int m_Type;
38
40 m_Type(-1) {}
41 CGhostItem(int Type) :
42 m_Type(Type) {}
43 void Reset() { m_Type = -1; }
44};
45
47{
51
52 alignas(uint32_t) char m_aBuffer[MAX_CHUNK_SIZE];
53 alignas(uint32_t) char m_aBufferTemp[MAX_CHUNK_SIZE];
55 const char *m_pBufferEnd;
58
59 void ResetBuffer();
60 void FlushChunk();
61
62public:
64
65 void Init();
66
67 int Start(const char *pFilename, const char *pMap, const SHA256_DIGEST &MapSha256, const char *pName) override;
68 void Stop(int Ticks, int Time) override;
69
70 void WriteData(int Type, const void *pData, size_t Size) override;
71 bool IsRecording() const override { return m_File != nullptr; }
72};
73
75{
79
82
83 alignas(uint32_t) char m_aBuffer[MAX_CHUNK_SIZE];
84 alignas(uint32_t) char m_aBufferTemp[MAX_CHUNK_SIZE];
86 const char *m_pBufferEnd;
91
92 void ResetBuffer();
93 IOHANDLE ReadHeader(CGhostHeader &Header, const char *pFilename, const char *pMap, const SHA256_DIGEST &MapSha256, unsigned MapCrc, bool LogMapMismatch) const;
94 bool ValidateHeader(const CGhostHeader &Header, const char *pFilename) const;
95 bool CheckHeaderMap(const CGhostHeader &Header, const char *pFilename, const char *pMap, const SHA256_DIGEST &MapSha256, unsigned MapCrc, bool LogMapMismatch) const;
96 bool ReadChunk(int *pType);
97
98public:
100
101 void Init();
102
103 bool Load(const char *pFilename, const char *pMap, const SHA256_DIGEST &MapSha256, unsigned MapCrc) override;
104 void Close() override;
105 const CGhostInfo *GetInfo() const override { return &m_Info; }
106
107 bool ReadNextType(int *pType) override;
108 bool ReadData(int Type, void *pData, size_t Size) override;
109
110 bool GetGhostInfo(const char *pFilename, CGhostInfo *pGhostInfo, const char *pMap, const SHA256_DIGEST &MapSha256, unsigned MapCrc) override;
111};
112#endif
Definition: ghost.h:10
Definition: ghost.h:34
CGhostItem()
Definition: ghost.h:39
void Reset()
Definition: ghost.h:43
CGhostItem(int Type)
Definition: ghost.h:41
int m_Type
Definition: ghost.h:37
unsigned char m_aData[MAX_ITEM_SIZE]
Definition: ghost.h:36
Definition: ghost.h:75
bool ReadData(int Type, void *pData, size_t Size) override
Definition: ghost.cpp:441
const char * m_pBufferEnd
Definition: ghost.h:86
CGhostLoader()
Definition: ghost.cpp:207
CGhostItem m_LastItem
Definition: ghost.h:90
const CGhostInfo * GetInfo() const override
Definition: ghost.h:105
CGhostInfo m_Info
Definition: ghost.h:81
class IStorage * m_pStorage
Definition: ghost.h:78
bool CheckHeaderMap(const CGhostHeader &Header, const char *pFilename, const char *pMap, const SHA256_DIGEST &MapSha256, unsigned MapCrc, bool LogMapMismatch) const
Definition: ghost.cpp:297
int m_BufferCurItem
Definition: ghost.h:88
bool GetGhostInfo(const char *pFilename, CGhostInfo *pGhostInfo, const char *pMap, const SHA256_DIGEST &MapSha256, unsigned MapCrc) override
Definition: ghost.cpp:483
void Close() override
Definition: ghost.cpp:471
char * m_pBufferPos
Definition: ghost.h:85
void ResetBuffer()
Definition: ghost.cpp:219
int m_BufferPrevItem
Definition: ghost.h:89
bool ReadNextType(int *pType) override
Definition: ghost.cpp:412
bool ValidateHeader(const CGhostHeader &Header, const char *pFilename) const
Definition: ghost.cpp:254
void Init()
Definition: ghost.cpp:214
bool ReadChunk(int *pType)
Definition: ghost.cpp:364
IOHANDLE m_File
Definition: ghost.h:76
char m_aFilename[IO_MAX_PATH_LENGTH]
Definition: ghost.h:77
int m_BufferNumItems
Definition: ghost.h:87
IOHANDLE ReadHeader(CGhostHeader &Header, const char *pFilename, const char *pMap, const SHA256_DIGEST &MapSha256, unsigned MapCrc, bool LogMapMismatch) const
Definition: ghost.cpp:228
CGhostHeader m_Header
Definition: ghost.h:80
char m_aBuffer[MAX_CHUNK_SIZE]
Definition: ghost.h:83
bool Load(const char *pFilename, const char *pMap, const SHA256_DIGEST &MapSha256, unsigned MapCrc) override
Definition: ghost.cpp:339
char m_aBufferTemp[MAX_CHUNK_SIZE]
Definition: ghost.h:84
Definition: ghost.h:47
void WriteData(int Type, const void *pData, size_t Size) override
Definition: ghost.cpp:96
IOHANDLE m_File
Definition: ghost.h:48
void FlushChunk()
Definition: ghost.cpp:128
int m_BufferNumItems
Definition: ghost.h:56
void Init()
Definition: ghost.cpp:43
CGhostRecorder()
Definition: ghost.cpp:36
void ResetBuffer()
Definition: ghost.cpp:77
class IStorage * m_pStorage
Definition: ghost.h:50
bool IsRecording() const override
Definition: ghost.h:71
const char * m_pBufferEnd
Definition: ghost.h:55
char * m_pBufferPos
Definition: ghost.h:54
char m_aFilename[IO_MAX_PATH_LENGTH]
Definition: ghost.h:49
void Stop(int Ticks, int Time) override
Definition: ghost.cpp:170
char m_aBuffer[MAX_CHUNK_SIZE]
Definition: ghost.h:52
CGhostItem m_LastItem
Definition: ghost.h:57
char m_aBufferTemp[MAX_CHUNK_SIZE]
Definition: ghost.h:53
int Start(const char *pFilename, const char *pMap, const SHA256_DIGEST &MapSha256, const char *pName) override
Definition: ghost.cpp:48
Definition: ghost.h:32
Definition: ghost.h:19
Definition: storage.h:20
@ NUM_ITEMS_PER_CHUNK
Definition: ghost.h:11
@ MAX_ITEM_SIZE
Definition: ghost.h:10
@ MAX_CHUNK_SIZE
Definition: ghost.h:12
@ MAX_NAME_LENGTH
Definition: protocol.h:97
void * IOHANDLE
Definition: logger.h:11
Definition: ghost.h:18
unsigned char m_Version
Definition: ghost.h:20
SHA256_DIGEST m_MapSha256
Definition: ghost.h:26
unsigned char m_aZeroes[sizeof(int32_t)]
Definition: ghost.h:23
int GetTicks() const
Definition: ghost.cpp:16
char m_aMap[64]
Definition: ghost.h:22
char m_aOwner[MAX_NAME_LENGTH]
Definition: ghost.h:21
int GetTime() const
Definition: ghost.cpp:21
unsigned char m_aNumTicks[sizeof(int32_t)]
Definition: ghost.h:24
CGhostInfo ToGhostInfo() const
Definition: ghost.cpp:26
unsigned char m_aMarker[8]
Definition: ghost.h:19
unsigned char m_aTime[sizeof(int32_t)]
Definition: ghost.h:25
Definition: hash.h:15
@ IO_MAX_PATH_LENGTH
Definition: types.h:43