-
Notifications
You must be signed in to change notification settings - Fork 4
/
dt_recv.h
480 lines (383 loc) · 13.3 KB
/
dt_recv.h
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
#pragma once
#include "dt_common.h"
#define ADDRESSPROXY_NONE -1
class RecvTable;
class RecvProp;
/*
// This is passed into RecvProxy functions.
class CRecvProxyData
{
public:
const RecvProp* m_pRecvProp; // The property it's receiving.
DVariant m_Value; // The value given to you to store.
int m_iElement; // Which array element you're getting.
int m_ObjectID; // The object being referred to.
};
*/
struct CRecvProxyData
{
const RecvProp* m_pRecvProp;
DVariant m_Value;
int m_iElement;
int m_ObjectID;
};
//-----------------------------------------------------------------------------
// pStruct = the base structure of the datatable this variable is in (like C_BaseEntity)
// pOut = the variable that this this proxy represents (like C_BaseEntity::m_SomeValue).
//
// Convert the network-standard-type value in m_Value into your own format in pStruct/pOut.
//-----------------------------------------------------------------------------
typedef void( *RecvVarProxyFn )( const CRecvProxyData* pData, void* pStruct, void* pOut );
// ------------------------------------------------------------------------ //
// ArrayLengthRecvProxies are optionally used to get the length of the
// incoming array when it changes.
// ------------------------------------------------------------------------ //
typedef void( *ArrayLengthRecvProxyFn )( void* pStruct, int objectID, int currentArrayLength );
// NOTE: DataTable receive proxies work differently than the other proxies.
// pData points at the object + the recv table's offset.
// pOut should be set to the location of the object to unpack the data table into.
// If the parent object just contains the child object, the default proxy just does *pOut = pData.
// If the parent object points at the child object, you need to dereference the pointer here.
// NOTE: don't ever return null from a DataTable receive proxy function. Bad things will happen.
typedef void( *DataTableRecvVarProxyFn )( const RecvProp* pProp, void** pOut, void* pData, int objectID );
// This is used to fork over the standard proxy functions to the engine so it can
// make some optimizations.
class CStandardRecvProxies
{
public:
CStandardRecvProxies( );
RecvVarProxyFn m_Int32ToInt8;
RecvVarProxyFn m_Int32ToInt16;
RecvVarProxyFn m_Int32ToInt32;
RecvVarProxyFn m_FloatToFloat;
RecvVarProxyFn m_VectorToVector;
};
extern CStandardRecvProxies g_StandardRecvProxies;
class CRecvDecoder;
class RecvProp
{
// This info comes from the receive data table.
public:
RecvProp( );
void InitArray( int nElements, int elementStride );
int GetNumElements( ) const;
void SetNumElements( int nElements );
int GetElementStride( ) const;
void SetElementStride( int stride );
int GetFlags( ) const;
const char* GetName( ) const;
SendPropType GetType( ) const;
RecvTable* GetDataTable( ) const;
void SetDataTable( RecvTable* pTable );
RecvVarProxyFn GetProxyFn( ) const;
void SetProxyFn( RecvVarProxyFn fn );
DataTableRecvVarProxyFn GetDataTableProxyFn( ) const;
void SetDataTableProxyFn( DataTableRecvVarProxyFn fn );
int GetOffset( ) const;
void SetOffset( int o );
// Arrays only.
RecvProp* GetArrayProp( ) const;
void SetArrayProp( RecvProp* pProp );
// Arrays only.
void SetArrayLengthProxy( ArrayLengthRecvProxyFn proxy );
ArrayLengthRecvProxyFn GetArrayLengthProxy( ) const;
bool IsInsideArray( ) const;
void SetInsideArray( );
// Some property types bind more data to the prop in here.
const void* GetExtraData( ) const;
void SetExtraData( const void* pData );
// If it's one of the numbered "000", "001", etc properties in an array, then
// these can be used to get its array property name for debugging.
const char* GetParentArrayPropName( );
void SetParentArrayPropName( const char* pArrayPropName );
public:
const char* m_pVarName;
SendPropType m_RecvType;
int m_Flags;
int m_StringBufferSize;
bool m_bInsideArray; // Set to true by the engine if this property sits inside an array.
// Extra data that certain special property types bind to the property here.
const void* m_pExtraData;
// If this is an array (DPT_Array).
RecvProp* m_pArrayProp;
ArrayLengthRecvProxyFn m_ArrayLengthProxy;
RecvVarProxyFn m_ProxyFn;
DataTableRecvVarProxyFn m_DataTableProxyFn; // For RDT_DataTable.
RecvTable* m_pDataTable; // For RDT_DataTable.
int m_Offset;
int m_ElementStride;
int m_nElements;
// If it's one of the numbered "000", "001", etc properties in an array, then
// these can be used to get its array property name for debugging.
const char* m_pParentArrayPropName;
};
class RecvTable
{
public:
using PropType = RecvProp;
RecvTable( );
RecvTable( RecvProp* pProps, int nProps, const char* pNetTableName );
~RecvTable( );
void Construct( RecvProp* pProps, int nProps, const char* pNetTableName );
int GetNumProps( );
RecvProp* GetProp( int i );
const char* GetName( );
// Used by the engine while initializing array props.
void SetInitialized( bool bInitialized );
bool IsInitialized( ) const;
// Used by the engine.
void SetInMainList( bool bInList );
bool IsInMainList( ) const;
public:
// Properties described in a table.
RecvProp* m_pProps;
int m_nProps;
// The decoder. NOTE: this covers each RecvTable AND all its children (ie: its children
// will have their own decoders that include props for all their children).
CRecvDecoder* m_pDecoder;
const char* m_pNetTableName; // The name matched between client and server.
private:
bool m_bInitialized;
bool m_bInMainList;
};
inline int RecvTable::GetNumProps( )
{
return m_nProps;
}
inline RecvProp* RecvTable::GetProp( int i )
{
// Assert( i >= 0 && i < m_nProps );
return &m_pProps[i];
}
inline const char* RecvTable::GetName( )
{
return m_pNetTableName;
}
inline void RecvTable::SetInitialized( bool bInitialized )
{
m_bInitialized = bInitialized;
}
inline bool RecvTable::IsInitialized( ) const
{
return m_bInitialized;
}
inline void RecvTable::SetInMainList( bool bInList )
{
m_bInMainList = bInList;
}
inline bool RecvTable::IsInMainList( ) const
{
return m_bInMainList;
}
#define RECVINFO(varName) #varName, offsetof(currentRecvDTClass, varName), sizeof(((currentRecvDTClass*)0)->varName)
#define RECVINFO_NAME(varName, remoteVarName) #remoteVarName, offsetof(currentRecvDTClass, varName), sizeof(((currentRecvDTClass*)0)->varName)
#define RECVINFO_STRING(varName) #varName, offsetof(currentRecvDTClass, varName), STRINGBUFSIZE(currentRecvDTClass, varName)
#define RECVINFO_BASECLASS(tableName) RecvPropDataTable("this", 0, 0, &REFERENCE_RECV_TABLE(tableName))
#define RECVINFO_ARRAY(varName) #varName, offsetof(currentRecvDTClass, varName), sizeof(((currentRecvDTClass*)0)->varName[0]), sizeof(((currentRecvDTClass*)0)->varName)/sizeof(((currentRecvDTClass*)0)->varName[0])
// Just specify the name and offset. Used for strings and data tables.
#define RECVINFO_NOSIZE(varName) #varName, offsetof(currentRecvDTClass, varName)
#define RECVINFO_DT(varName) RECVINFO_NOSIZE(varName)
#define RECVINFO_DTNAME(varName,remoteVarName) #remoteVarName, offsetof(currentRecvDTClass, varName)
void RecvProxy_FloatToFloat( const CRecvProxyData* pData, void* pStruct, void* pOut );
void RecvProxy_VectorToVector( const CRecvProxyData* pData, void* pStruct, void* pOut );
void RecvProxy_QuaternionToQuaternion( const CRecvProxyData* pData, void* pStruct, void* pOut );
void RecvProxy_Int32ToInt8( const CRecvProxyData* pData, void* pStruct, void* pOut );
void RecvProxy_Int32ToInt16( const CRecvProxyData* pData, void* pStruct, void* pOut );
void RecvProxy_StringToString( const CRecvProxyData* pData, void* pStruct, void* pOut );
void RecvProxy_Int32ToInt32( const CRecvProxyData* pData, void* pStruct, void* pOut );
// StaticDataTable does *pOut = pData.
void DataTableRecvProxy_StaticDataTable( const RecvProp* pProp, void** pOut, void* pData, int objectID );
// PointerDataTable does *pOut = *((void**)pData) (ie: pData is a pointer to the object to decode into).
void DataTableRecvProxy_PointerDataTable( const RecvProp* pProp, void** pOut, void* pData, int objectID );
RecvProp RecvPropFloat(
const char* pVarName,
int offset,
int sizeofVar = SIZEOF_IGNORE, // Handled by RECVINFO macro, but set to SIZEOF_IGNORE if you don't want to bother.
int flags = 0,
RecvVarProxyFn varProxy = RecvProxy_FloatToFloat
);
RecvProp RecvPropVector(
const char* pVarName,
int offset,
int sizeofVar = SIZEOF_IGNORE, // Handled by RECVINFO macro, but set to SIZEOF_IGNORE if you don't want to bother.
int flags = 0,
RecvVarProxyFn varProxy = RecvProxy_VectorToVector
);
// This is here so the RecvTable can look more like the SendTable.
#define RecvPropQAngles RecvPropVector
RecvProp RecvPropInt(
const char* pVarName,
int offset,
int sizeofVar = SIZEOF_IGNORE, // Handled by RECVINFO macro, but set to SIZEOF_IGNORE if you don't want to bother.
int flags = 0,
RecvVarProxyFn varProxy = nullptr
);
RecvProp RecvPropString(
const char* pVarName,
int offset,
int bufferSize,
int flags = 0,
RecvVarProxyFn varProxy = RecvProxy_StringToString
);
RecvProp RecvPropDataTable(
const char* pVarName,
int offset,
int flags,
RecvTable* pTable,
DataTableRecvVarProxyFn varProxy = DataTableRecvProxy_StaticDataTable
);
RecvProp RecvPropArray3(
const char* pVarName,
int offset,
int sizeofVar,
int elements,
RecvProp pArrayProp,
DataTableRecvVarProxyFn varProxy = DataTableRecvProxy_StaticDataTable
);
// Use the macro to let it automatically generate a table name. You shouldn't
// ever need to reference the table name. If you want to exclude this array, then
// reference the name of the variable in varTemplate.
RecvProp InternalRecvPropArray(
const int elementCount,
const int elementStride,
const char* pName,
ArrayLengthRecvProxyFn proxy
);
//
// Use this if you want to completely manage the way the array data is stored.
// You'll need to provide a proxy inside varTemplate that looks for 'iElement'
// to figure out where to store the specified element.
//
#define RecvPropVirtualArray( arrayLengthProxy, maxArrayLength, varTemplate, propertyName ) \
varTemplate, \
InternalRecvPropArray( \
maxArrayLength, \
0, \
#propertyName, \
arrayLengthProxy \
)
// Use this and pass the array name and it will figure out the count and stride automatically.
#define RecvPropVariableLengthArray( arrayLengthProxy, varTemplate, arrayName ) \
varTemplate, \
InternalRecvPropArray( \
sizeof(((currentRecvDTClass*)0)->arrayName) / PROPSIZEOF(currentRecvDTClass, arrayName[0]), \
PROPSIZEOF(currentRecvDTClass, arrayName[0]), \
#arrayName, \
arrayLengthProxy \
)
// Use this and pass the array name and it will figure out the count and stride automatically.
#define RecvPropArray( varTemplate, arrayName ) \
RecvPropVariableLengthArray( 0, varTemplate, arrayName )
// Use this one to specify the element count and stride manually.
#define RecvPropArray2( arrayLengthProxy, varTemplate, elementCount, elementStride, arrayName ) \
varTemplate, \
InternalRecvPropArray( elementCount, elementStride, #arrayName, arrayLengthProxy )
// ---------------------------------------------------------------------------------------- //
// Inlines.
// ---------------------------------------------------------------------------------------- //
inline void RecvProp::InitArray( int nElements, int elementStride )
{
m_RecvType = DPT_Array;
m_nElements = nElements;
m_ElementStride = elementStride;
}
inline int RecvProp::GetNumElements( ) const
{
return m_nElements;
}
inline void RecvProp::SetNumElements( int nElements )
{
m_nElements = nElements;
}
inline int RecvProp::GetElementStride( ) const
{
return m_ElementStride;
}
inline void RecvProp::SetElementStride( int stride )
{
m_ElementStride = stride;
}
inline int RecvProp::GetFlags( ) const
{
return m_Flags;
}
inline const char* RecvProp::GetName( ) const
{
return m_pVarName;
}
inline SendPropType RecvProp::GetType( ) const
{
return m_RecvType;
}
inline RecvTable* RecvProp::GetDataTable( ) const
{
return m_pDataTable;
}
inline void RecvProp::SetDataTable( RecvTable* pTable )
{
m_pDataTable = pTable;
}
inline RecvVarProxyFn RecvProp::GetProxyFn( ) const
{
return m_ProxyFn;
}
inline void RecvProp::SetProxyFn( RecvVarProxyFn fn )
{
m_ProxyFn = fn;
}
inline DataTableRecvVarProxyFn RecvProp::GetDataTableProxyFn( ) const
{
return m_DataTableProxyFn;
}
inline void RecvProp::SetDataTableProxyFn( DataTableRecvVarProxyFn fn )
{
m_DataTableProxyFn = fn;
}
inline int RecvProp::GetOffset( ) const
{
return m_Offset;
}
inline void RecvProp::SetOffset( int o )
{
m_Offset = o;
}
inline RecvProp* RecvProp::GetArrayProp( ) const
{
return m_pArrayProp;
}
inline void RecvProp::SetArrayProp( RecvProp* pProp )
{
m_pArrayProp = pProp;
}
inline void RecvProp::SetArrayLengthProxy( ArrayLengthRecvProxyFn proxy )
{
m_ArrayLengthProxy = proxy;
}
inline ArrayLengthRecvProxyFn RecvProp::GetArrayLengthProxy( ) const
{
return m_ArrayLengthProxy;
}
inline bool RecvProp::IsInsideArray( ) const
{
return m_bInsideArray;
}
inline void RecvProp::SetInsideArray( )
{
m_bInsideArray = true;
}
inline const void* RecvProp::GetExtraData( ) const
{
return m_pExtraData;
}
inline void RecvProp::SetExtraData( const void* pData )
{
m_pExtraData = pData;
}
inline const char* RecvProp::GetParentArrayPropName( )
{
return m_pParentArrayPropName;
}
inline void RecvProp::SetParentArrayPropName( const char* pArrayPropName )
{
m_pParentArrayPropName = pArrayPropName;
}