-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathshared.h
440 lines (368 loc) · 14.6 KB
/
shared.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
#include "common.h"
#include <assert.h>
#define CVAR_ARCHIVE 1 // set to cause it to be saved to vars.rc
// used for system variables, not for player
// specific configurations
#define CVAR_USERINFO 2 // sent to server on connect or change
#define CVAR_SERVERINFO 4 // sent in response to front end requests
#define CVAR_SYSTEMINFO 8 // these cvars will be duplicated on all clients
#define CVAR_INIT 16 // don't allow change from console at all,
// but can be set from the command line
#define CVAR_LATCH 32 // will only change when C code next does
// a Cvar_Get(), so it can't be changed
// without proper initialization. modified
// will be set, even though the value hasn't
// changed yet
#define CVAR_ROM 64 // display only, cannot be set by user at all
#define CVAR_USER_CREATED 128 // created by a set command
#define CVAR_TEMP 256 // can be set even when cheats are disabled, but is not archived
#define CVAR_CHEAT 512 // can not be changed if cheats are disabled
#define CVAR_NORESTART 1024 // do not clear when a cvar_restart is issued
#define CVAR_WOLFINFO 2048 // DHM - NERVE :: Like userinfo, but for wolf multiplayer info
#define CVAR_UNSAFE 4096 // ydnar: unsafe system cvars (renderer, sound settings, anything that might cause a crash)
#define CVAR_SERVERINFO_NOUPDATE 8192 // gordon: WONT automatically send this to clients, but server browsers will see it
#define MAX_STRING_CHARS 1024 // max length of a string passed to Cmd_TokenizeString
#define MAX_STRING_TOKENS 256 // max tokens resulting from Cmd_TokenizeString
#define MAX_TOKEN_CHARS 1024 // max length of an individual token
#define MAX_RELIABLE_COMMANDS 64
#define MAX_INFO_STRING 1024
#define MAX_INFO_KEY 1024
#define MAX_INFO_VALUE 1024
#define BIG_INFO_STRING 8192 // used for system info key only
#define BIG_INFO_KEY 8192
#define BIG_INFO_VALUE 8192
#define MAX_NAME_LENGTH 36 // max length of a client name
#define MAX_QPATH 64
#define MAX_OSPATH 256
typedef enum { qfalse, qtrue } qboolean;
typedef struct cvar_s {
char *name;
char *string;
char *resetString; // cvar_restart will reset to this value
char *latchedString; // for CVAR_LATCH vars
int flags;
qboolean modified; // set each time the cvar is changed
int modificationCount; // incremented each time the cvar is changed
float value; // atof( string )
int integer; // atoi( string )
struct cvar_s *next;
struct cvar_s *hashNext;
} cvar_t;
typedef enum {
ET_GENERAL,
ET_PLAYER,
ET_CORPSE,
ET_ITEM,
ET_MISSILE,
ET_MOVER,
ET_PORTAL,
ET_INVISIBLE,
ET_SCRIPTMOVER,
ET_TURRET //???
} entityTypes;
typedef struct {
int unknown; //0
byte* data; //4
int maxsize; //8 (most likely maxsize value 16384)
int cursize; //12 //value 129
int readcount; //16 //value 16
int bit; //20 //value 0
} msg_t; //size is 0x18 (24)
typedef enum {
STEREO_CENTER,
STEREO_LEFT,
STEREO_RIGHT
} stereoFrame_t;
typedef enum {
CA_UNINITIALIZED,
CA_DISCONNECTED = 0,
CA_CONNECTING,
CA_CHALLENGING,
CA_CONNECTED,
} connstate_t;
#if 0
typedef enum {
CA_UNINITIALIZED,
CA_DISCONNECTED, // not talking to a server
CA_AUTHORIZING, // not used any more, was checking cd key
CA_CONNECTING, // sending request packets to the server
CA_CHALLENGING, // sending challenge packets to the server
CA_CONNECTED, // netchan_t established, getting gamestate
CA_LOADING, // only during cgame initialization, never during main loop
CA_PRIMED, // got gamestate, waiting for first frame
CA_ACTIVE, // game views should be displayed
CA_CINEMATIC // playing a cinematic or a static pic, not connected to a server
} connstate_t;
#endif
#define Q_COLOR_ESCAPE '^'
#define Q_IsColorString( p ) ( p && *( p ) == Q_COLOR_ESCAPE && *( ( p ) + 1 ) && *( ( p ) + 1 ) != Q_COLOR_ESCAPE )
#define COLOR_BLACK '0'
#define COLOR_RED '1'
#define COLOR_GREEN '2'
#define COLOR_YELLOW '3'
#define COLOR_BLUE '4'
#define COLOR_CYAN '5'
#define COLOR_MAGENTA '6'
#define COLOR_WHITE '7'
#define COLOR_ORANGE '8'
#define COLOR_MDGREY '9'
#define COLOR_LTGREY ':'
//#define COLOR_LTGREY ';'
#define COLOR_MDGREEN '<'
#define COLOR_MDYELLOW '='
#define COLOR_MDBLUE '>'
#define COLOR_MDRED '?'
#define COLOR_LTORANGE 'A'
#define COLOR_MDCYAN 'B'
#define COLOR_MDPURPLE 'C'
#define COLOR_NULL '*'
#define COLOR_BITS 31
#define ColorIndex( c ) ( ( ( c ) - '0' ) & COLOR_BITS )
#define S_COLOR_BLACK "^0"
#define S_COLOR_RED "^1"
#define S_COLOR_GREEN "^2"
#define S_COLOR_YELLOW "^3"
#define S_COLOR_BLUE "^4"
#define S_COLOR_CYAN "^5"
#define S_COLOR_MAGENTA "^6"
#define S_COLOR_WHITE "^7"
#define S_COLOR_ORANGE "^8"
#define S_COLOR_MDGREY "^9"
#define S_COLOR_LTGREY "^:"
//#define S_COLOR_LTGREY "^;"
#define S_COLOR_MDGREEN "^<"
#define S_COLOR_MDYELLOW "^="
#define S_COLOR_MDBLUE "^>"
#define S_COLOR_MDRED "^?"
#define S_COLOR_LTORANGE "^A"
#define S_COLOR_MDCYAN "^B"
#define S_COLOR_MDPURPLE "^C"
#define S_COLOR_NULL "^*"
typedef int qhandle_t;
typedef int sfxHandle_t;
typedef int fileHandle_t;
typedef int clipHandle_t;
typedef float vec_t;
typedef vec_t vec2_t[2];
typedef vec_t vec3_t[3];
typedef vec_t vec4_t[4];
typedef vec_t vec5_t[5];
#define DotProduct( x,y ) ( ( x )[0] * ( y )[0] + ( x )[1] * ( y )[1] + ( x )[2] * ( y )[2] )
#define VectorSubtract( a,b,c ) ( ( c )[0] = ( a )[0] - ( b )[0],( c )[1] = ( a )[1] - ( b )[1],( c )[2] = ( a )[2] - ( b )[2] )
#define VectorAdd( a,b,c ) ( ( c )[0] = ( a )[0] + ( b )[0],( c )[1] = ( a )[1] + ( b )[1],( c )[2] = ( a )[2] + ( b )[2] )
#define VectorCopy( a,b ) ( ( b )[0] = ( a )[0],( b )[1] = ( a )[1],( b )[2] = ( a )[2] )
#define VectorScale( v, s, o ) ( ( o )[0] = ( v )[0] * ( s ),( o )[1] = ( v )[1] * ( s ),( o )[2] = ( v )[2] * ( s ) )
#define VectorMA( v, s, b, o ) ( ( o )[0] = ( v )[0] + ( b )[0] * ( s ),( o )[1] = ( v )[1] + ( b )[1] * ( s ),( o )[2] = ( v )[2] + ( b )[2] * ( s ) )
#define VectorClear( a ) ( ( a )[0] = ( a )[1] = ( a )[2] = 0 )
#define VectorNegate( a,b ) ( ( b )[0] = -( a )[0],( b )[1] = -( a )[1],( b )[2] = -( a )[2] )
#define VectorSet( v, x, y, z ) ( ( v )[0] = ( x ), ( v )[1] = ( y ), ( v )[2] = ( z ) )
#define Vector2Set( v, x, y ) ( ( v )[0] = ( x ),( v )[1] = ( y ) )
#define Vector2Copy( a,b ) ( ( b )[0] = ( a )[0],( b )[1] = ( a )[1] )
#define Vector2Subtract( a,b,c ) ( ( c )[0] = ( a )[0] - ( b )[0],( c )[1] = ( a )[1] - ( b )[1] )
#define Vector4Set( v, x, y, z, n ) ( ( v )[0] = ( x ),( v )[1] = ( y ),( v )[2] = ( z ),( v )[3] = ( n ) )
#define Vector4Copy( a,b ) ( ( b )[0] = ( a )[0],( b )[1] = ( a )[1],( b )[2] = ( a )[2],( b )[3] = ( a )[3] )
#define Vector4MA( v, s, b, o ) ( ( o )[0] = ( v )[0] + ( b )[0] * ( s ),( o )[1] = ( v )[1] + ( b )[1] * ( s ),( o )[2] = ( v )[2] + ( b )[2] * ( s ),( o )[3] = ( v )[3] + ( b )[3] * ( s ) )
#define Vector4Average( v, b, s, o ) ( ( o )[0] = ( ( v )[0] * ( 1 - ( s ) ) ) + ( ( b )[0] * ( s ) ),( o )[1] = ( ( v )[1] * ( 1 - ( s ) ) ) + ( ( b )[1] * ( s ) ),( o )[2] = ( ( v )[2] * ( 1 - ( s ) ) ) + ( ( b )[2] * ( s ) ),( o )[3] = ( ( v )[3] * ( 1 - ( s ) ) ) + ( ( b )[3] * ( s ) ) )
#define SnapVector( v ) {v[0] = ( (int)( v[0] ) ); v[1] = ( (int)( v[1] ) ); v[2] = ( (int)( v[2] ) );}
typedef struct {
netsrc_t sock;
int dropped; // between last packet and previous
netadr_t remoteAddress;
int qport; // qport value to write when transmitting
// sequencing variables
int incomingSequence;
int outgoingSequence;
// incoming fragment assembly buffer
int fragmentSequence;
int fragmentLength;
byte fragmentBuffer[MAX_MSGLEN];
// outgoing fragment buffer
// we need to space out the sending of large fragmented messages
qboolean unsentFragments;
int unsentFragmentStart;
int unsentLength;
byte unsentBuffer[MAX_MSGLEN];
} netchan_t;
typedef struct {
int clientNum;
int lastPacketSentTime; // for retransmits during connection
int lastPacketTime; // for timeouts
netadr_t serverAddress;
int connectTime; // for connection retransmits
int connectPacketCount; // for display on connection dialog
char serverMessage[MAX_STRING_TOKENS]; // for display on connection dialog
int challenge; // from the server to use for connecting
int checksumFeed; // from the server for checksum calculations
// these are our reliable messages that go to the server
int reliableSequence;
int reliableAcknowledge; // the last one the server has executed
char reliableCommands[MAX_RELIABLE_COMMANDS][MAX_STRING_CHARS];
// server message (unreliable) and command (reliable) sequence
// numbers are NOT cleared at level changes, but continue to
// increase as long as the connection is valid
// message sequence is used by both the network layer and the
// delta compression layer
int serverMessageSequence;
// reliable messages received from server
int serverCommandSequence;
int lastExecutedServerCommand; // last server command grabbed or executed with CL_GetServerCommand
char serverCommands[MAX_RELIABLE_COMMANDS][MAX_STRING_CHARS];
// file transfer from server
fileHandle_t download;
char downloadTempName[MAX_OSPATH];
char downloadName[MAX_OSPATH];
int downloadNumber;
int downloadBlock; // block we are waiting for
int downloadCount; // how many bytes we got
int downloadSize; // how many bytes we got
char downloadList[MAX_INFO_STRING]; // list of paks we need to download
qboolean downloadRestart; // if true, we need to do another FS_Restart because we downloaded a pak
// demo information
char demoName[MAX_QPATH];
qboolean spDemoRecording;
qboolean demorecording;
qboolean demoplaying;
qboolean demowaiting; // don't record until a non-delta message is received
qboolean firstDemoFrameSkipped;
fileHandle_t demofile;
int timeDemoFrames; // counter of rendered frames
int timeDemoStart; // cls.realtime before first frame
int timeDemoBaseTime; // each frame will be at this time + frameNum * 50
// big stuff at end of structure so most offsets are 15 bits or less
netchan_t netchan;
} clientConnection_t;
typedef struct vidmode_s
{
const char* description;
int width, height;
float pixelAspect;
} vidmode_t;
#pragma pack(push, 1)
typedef struct playerState_s
{
int commandTime;
int pm_type;
int bobCycle;
int pm_flags;
int pm_time;
vec3_t origin;
vec3_t velocity;
char gap_2C[20];
float leanf;
int speed;
char gap_48[12];
int groundEntityNum;
char gap_58[12];
int jumpTime;
int field_68;
int legsTime;
int legsAnim;
int torsoTime;
int torsoAnim;
int movementDir;
int eFlags;
char gap_84[24];
int field_9C;
int field_A0;
int field_A4;
int field_A8;
int clientNum;
int weapon;
int field_B4;
char gap_B8;
char gap_B9;
char gap_BA[2];
int field_BC;
vec3_t viewangles;
char gap_CC[40];
int health;
char gap_F8[556];
vec3_t mins;
vec3_t maxs;
float viewheight_prone;
int viewheight_crouched;
float viewheight_standing;
int field_348;
float runSpeedScale;
float sprintSpeedScale;
char gap_354[40];
float friction;
char gap_380[68];
float fTorsoHeight;
float fTorsoPitch;
float fWaistPitch;
char rest[7416];
int end;
} playerState_t;
#pragma pack(pop)
typedef struct usercmd_s {
int serverTime;
byte buttons; //console,chat talking, aim down the sight, attackbutton, usebutton
byte wbuttons; //lean right,left,reload
byte weapon;
byte flags;
int angles[3];
signed char forwardmove, rightmove, upmove;
byte unknown; //could be doubleTap or client
} usercmd_t;
typedef struct { //usercmd_s i defined in server.h mmmmmmm
playerState_t* ps;
usercmd_t cmd;
//other stuff
} pmove_t;
typedef void(*Cvar_Set_t)(const char*, const char*);
typedef cvar_t* (*Cvar_Get_t)(const char*, const char*, int);
typedef cvar_t* (*Cvar_FindVar_t)(const char*);
extern Cvar_Set_t Cvar_Set;
extern Cvar_Get_t Cvar_Get;
extern Cvar_FindVar_t Cvar_FindVar;
char* Cvar_VariableString(const char*);
char* Cvar_VariableStringBuffer(const char* var_name, char* buffer, int bufsize);
int Cvar_VariableIntegerValue(const char* var_name);
void Q_strncpyz(char *dest, const char *src, int destsize);
void Com_sprintf(char *dest, int size, const char *fmt, ...);
static void(*Cmd_ArgvBuffer)(int, char*, int) = (void(*)(int, char*, int))0x4285E0;
char* Cmd_Argv(int index);
int Cmd_Argc();
void Info_SetValueForKey(char *s, const char *key, const char *value);
char *Info_ValueForKey(const char *s, const char *key);
void Info_NextPair(const char** head, char* key, char* value);
extern DWORD game_mp;
extern DWORD cgame_mp;
#define GAME_OFF(x) (game_mp + (x - 0x20000000))
#define CGAME_OFF(x) (cgame_mp + (x - 0x30000000))
/* net stuff */
#define EX_MASTER_NAME "xtnded.org"
extern netadr_t ex_master;
bool ex_master_resolve();
typedef void(*NET_OutOfBandPrint_t)(netsrc_t, netadr_t, const char*, ...);
extern NET_OutOfBandPrint_t NET_OutOfBandPrint;
typedef void(*NET_SendPacket_t)(netsrc_t,int,void*,netadr_t);
extern NET_SendPacket_t NET_SendPacket;
typedef void(__fastcall *Sys_SendPacket_t)(void*, int, netadr_t);
//typedef void (*Sys_SendPacket_t)( int length, const void *data, netadr_t to );
extern Sys_SendPacket_t Sys_SendPackett;
void Sys_SendPacket(int packet_size, void *packet, netadr_t to);
qboolean NET_StringToAdr(const char *s, netadr_t *a);
const char *NET_AdrToString(netadr_t a);
typedef void(__fastcall *CL_Netchan_Encode_t)(msg_t*);
extern CL_Netchan_Encode_t CL_Netchan_Encode;
typedef void(*Netchan_Transmit_t)(int chan, int length, const BYTE *data);
extern Netchan_Transmit_t Netchan_Transmit;
typedef void(*Netchan_TransmitNextFragment_t)(int chan);
extern Netchan_TransmitNextFragment_t Netchan_TransmitNextFragment;
typedef void(*CL_NextDownload_t)(void);
static CL_NextDownload_t CL_NextDownload = (CL_NextDownload_t)0x410190;
typedef void(*CL_BeginDownload_t)(const char*, const char*);
static CL_BeginDownload_t CL_BeginDownload = (CL_BeginDownload_t)0x4100D0;
typedef void(*MSG_initHuffman_t)(void);
extern MSG_initHuffman_t MSG_initHuffman;
void MSG_Init(msg_t *buf, byte *data, int length);
char* trimSpaces(char* str);
char* Q_CleanStr(char* string, bool colors = false);
char* Com_CleanHostname(char* hostname, bool colors);
char* Com_CleanMapname(char* mapname);
const char* Com_GametypeName(char* gt, bool colors = false);
bool GetDesktopResolution(int* pHorizontal, int* pVertical);
int Q_stricmp(const char* s1, const char* s2);
int I_stricmp(const char* s0, const char* s1);