Debian Codegraph @

code/qcommon/qcommon.h

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 // qcommon.h -- definitions common between client and server, but not game.or ref modules
23 #ifndef _QCOMMON_H_
24 #define _QCOMMON_H_
25
26 #include "../qcommon/cm_public.h"
27
28 //#define PRE_RELEASE_DEMO
29
30 //============================================================================
31
32 //
33 // msg.c
34 //
35 typedef struct {
36 qboolean allowoverflow; // if false, do a Com_Error
37 qboolean overflowed; // set to true if the buffer size failed (with allowoverflow set)
38 qboolean oob; // set to true if the buffer size failed (with allowoverflow set)
39 byte *data;
40 int maxsize;
41 int cursize;
42 int readcount;
43 int bit; // for bitwise reads and writes
44 } msg_t;
45
46 void MSG_Init (msg_t *buf, byte *data, int length);
47 void MSG_InitOOB( msg_t *buf, byte *data, int length );
48 void MSG_Clear (msg_t *buf);
49 void MSG_WriteData (msg_t *buf, const void *data, int length);
50 void MSG_Bitstream( msg_t *buf );
51
52 // TTimo
53 // copy a msg_t in case we need to store it as is for a bit
54 // (as I needed this to keep an msg_t from a static var for later use)
55 // sets data buffer as MSG_Init does prior to do the copy
56 void MSG_Copy(msg_t *buf, byte *data, int length, msg_t *src);
57
58 struct usercmd_s;
59 struct entityState_s;
60 struct playerState_s;
61
62 void MSG_WriteBits( msg_t *msg, int value, int bits );
63
64 void MSG_WriteChar (msg_t *sb, int c);
65 void MSG_WriteByte (msg_t *sb, int c);
66 void MSG_WriteShort (msg_t *sb, int c);
67 void MSG_WriteLong (msg_t *sb, int c);
68 void MSG_WriteFloat (msg_t *sb, float f);
69 void MSG_WriteString (msg_t *sb, const char *s);
70 void MSG_WriteBigString (msg_t *sb, const char *s);
71 void MSG_WriteAngle16 (msg_t *sb, float f);
72 int MSG_HashKey(const char *string, int maxlen);
73
74 void MSG_BeginReading (msg_t *sb);
75 void MSG_BeginReadingOOB(msg_t *sb);
76
77 int MSG_ReadBits( msg_t *msg, int bits );
78
79 int MSG_ReadChar (msg_t *sb);
80 int MSG_ReadByte (msg_t *sb);
81 int MSG_ReadShort (msg_t *sb);
82 int MSG_ReadLong (msg_t *sb);
83 float MSG_ReadFloat (msg_t *sb);
84 char *MSG_ReadString (msg_t *sb);
85 char *MSG_ReadBigString (msg_t *sb);
86 char *MSG_ReadStringLine (msg_t *sb);
87 float MSG_ReadAngle16 (msg_t *sb);
88 void MSG_ReadData (msg_t *sb, void *buffer, int size);
89 int MSG_LookaheadByte (msg_t *msg);
90
91 void MSG_WriteDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
92 void MSG_ReadDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
93
94 void MSG_WriteDeltaEntity( msg_t *msg, struct entityState_s *from, struct entityState_s *to
95 , qboolean force );
96 void MSG_ReadDeltaEntity( msg_t *msg, entityState_t *from, entityState_t *to,
97 int number );
98
99 void MSG_WriteDeltaPlayerstate( msg_t *msg, struct playerState_s *from, struct playerState_s *to );
100 void MSG_ReadDeltaPlayerstate( msg_t *msg, struct playerState_s *from, struct playerState_s *to );
101
102
103 void MSG_ReportChangeVectors_f( void );
104
105 //============================================================================
106
107 /*
108 ==============================================================
109
110 NET
111
112 ==============================================================
113 */
114
115 #define NET_ENABLEV4 0x01
116 #define NET_ENABLEV6 0x02
117 // if this flag is set, always attempt ipv6 connections instead of ipv4 if a v6 address is found.
118 #define NET_PRIOV6 0x04
119 // disables ipv6 multicast support if set.
120 #define NET_DISABLEMCAST 0x08
121
122
123 #define PACKET_BACKUP 32 // number of old messages that must be kept on client and
124 // server for delta comrpession and ping estimation
125 #define PACKET_MASK (PACKET_BACKUP-1)
126
127 #define MAX_PACKET_USERCMDS 32 // max number of usercmd_t in a packet
128
129 #define MAX_SNAPSHOT_ENTITIES 256
130
131 #define PORT_ANY -1
132
133 #define MAX_RELIABLE_COMMANDS 64 // max string commands buffered for restransmit
134
135 typedef enum {
136 NA_BAD = 0, // an address lookup failed
137 NA_BOT,
138 NA_LOOPBACK,
139 NA_BROADCAST,
140 NA_IP,
141 NA_IP6,
142 NA_MULTICAST6,
143 NA_UNSPEC
144 } netadrtype_t;
145
146 typedef enum {
147 NS_CLIENT,
148 NS_SERVER
149 } netsrc_t;
150
151 #define NET_ADDRSTRMAXLEN 48 // maximum length of an IPv6 address string including trailing '\0'
152 typedef struct {
153 netadrtype_t type;
154
155 byte ip[4];
156 byte ip6[16];
157
158 unsigned short port;
159 unsigned long scope_id; // Needed for IPv6 link-local addresses
160 } netadr_t;
161
162 void NET_Init( void );
163 void NET_Shutdown( void );
164 void NET_Restart_f( void );
165 void NET_Config( qboolean enableNetworking );
166 void NET_FlushPacketQueue(void);
167 void NET_SendPacket (netsrc_t sock, int length, const void *data, netadr_t to);
168 void QDECL NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...) Q_PRINTF_FUNC(3, 4);
169 void QDECL NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len );
170
171 qboolean NET_CompareAdr (netadr_t a, netadr_t b);
172 qboolean NET_CompareBaseAdrMask(netadr_t a, netadr_t b, int netmask);
173 qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b);
174 qboolean NET_IsLocalAddress (netadr_t adr);
175 const char *NET_AdrToString (netadr_t a);
176 const char *NET_AdrToStringwPort (netadr_t a);
177 int NET_StringToAdr ( const char *s, netadr_t *a, netadrtype_t family);
178 qboolean NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_message);
179 void NET_JoinMulticast6(void);
180 void NET_LeaveMulticast6(void);
181 void NET_Sleep(int msec);
182
183
184 #define MAX_MSGLEN 16384 // max length of a message, which may
185 // be fragmented into multiple packets
186
187 #define MAX_DOWNLOAD_WINDOW 48 // ACK window of 48 download chunks. Cannot set this higher, or clients
188 // will overflow the reliable commands buffer
189 #define MAX_DOWNLOAD_BLKSIZE 1024 // 896 byte block chunks
190
191 #define NETCHAN_GENCHECKSUM(challenge, sequence) ((challenge) ^ ((sequence) * (challenge)))
192
193 /*
194 Netchan handles packet fragmentation and out of order / duplicate suppression
195 */
196
197 typedef struct {
198 netsrc_t sock;
199
200 int dropped; // between last packet and previous
201
202 netadr_t remoteAddress;
203 int qport; // qport value to write when transmitting
204
205 // sequencing variables
206 int incomingSequence;
207 int outgoingSequence;
208
209 // incoming fragment assembly buffer
210 int fragmentSequence;
211 int fragmentLength;
212 byte fragmentBuffer[MAX_MSGLEN];
213
214 // outgoing fragment buffer
215 // we need to space out the sending of large fragmented messages
216 qboolean unsentFragments;
217 int unsentFragmentStart;
218 int unsentLength;
219 byte unsentBuffer[MAX_MSGLEN];
220
221 int challenge;
222 int lastSentTime;
223 int lastSentSize;
224
225 #ifdef LEGACY_PROTOCOL
226 qboolean compat;
227 #endif
228 } netchan_t;
229
230 void Netchan_Init( int qport );
231 void Netchan_Setup(netsrc_t sock, netchan_t *chan, netadr_t adr, int qport, int challenge, qboolean compat);
232
233 void Netchan_Transmit( netchan_t *chan, int length, const byte *data );
234 void Netchan_TransmitNextFragment( netchan_t *chan );
235
236 qboolean Netchan_Process( netchan_t *chan, msg_t *msg );
237
238
239 /*
240 ==============================================================
241
242 PROTOCOL
243
244 ==============================================================
245 */
246
247 #define PROTOCOL_VERSION 71
248 #define PROTOCOL_LEGACY_VERSION 68
249 // 1.31 - 67
250
251 // maintain a list of compatible protocols for demo playing
252 // NOTE: that stuff only works with two digits protocols
253 extern int demo_protocols[];
254
255 #if !defined UPDATE_SERVER_NAME && !defined STANDALONE
256 #define UPDATE_SERVER_NAME "update.quake3arena.com"
257 #endif
258 // override on command line, config files etc.
259 #ifndef MASTER_SERVER_NAME
260 #define MASTER_SERVER_NAME "master.quake3arena.com"
261 #endif
262
263 #ifndef STANDALONE
264 #ifndef AUTHORIZE_SERVER_NAME
265 #define AUTHORIZE_SERVER_NAME "authorize.quake3arena.com"
266 #endif
267 #ifndef PORT_AUTHORIZE
268 #define PORT_AUTHORIZE 27952
269 #endif
270 #endif
271
272 #define PORT_MASTER 27950
273 #define PORT_UPDATE 27951
274 #define PORT_SERVER 27960
275 #define NUM_SERVER_PORTS 4 // broadcast scan this many ports after
276 // PORT_SERVER so a single machine can
277 // run multiple servers
278
279
280 // the svc_strings[] array in cl_parse.c should mirror this
281 //
282 // server to client
283 //
284 enum svc_ops_e {
285 svc_bad,
286 svc_nop,
287 svc_gamestate,
288 svc_configstring, // [short] [string] only in gamestate messages
289 svc_baseline, // only in gamestate messages
290 svc_serverCommand, // [string] to be executed by client game module
291 svc_download, // [short] size [size bytes]
292 svc_snapshot,
293 svc_EOF,
294
295 // new commands, supported only by ioquake3 protocol but not legacy
296 svc_voipSpeex, // not wrapped in USE_VOIP, so this value is reserved.
297 svc_voipOpus, //
298 };
299
300
301 //
302 // client to server
303 //
304 enum clc_ops_e {
305 clc_bad,
306 clc_nop,
307 clc_move, // [[usercmd_t]
308 clc_moveNoDelta, // [[usercmd_t]
309 clc_clientCommand, // [string] message
310 clc_EOF,
311
312 // new commands, supported only by ioquake3 protocol but not legacy
313 clc_voipSpeex, // not wrapped in USE_VOIP, so this value is reserved.
314 clc_voipOpus, //
315 };
316
317 /*
318 ==============================================================
319
320 VIRTUAL MACHINE
321
322 ==============================================================
323 */
324
325 typedef struct vm_s vm_t;
326
327 typedef enum {
328 VMI_NATIVE,
329 VMI_BYTECODE,
330 VMI_COMPILED
331 } vmInterpret_t;
332
333 typedef enum {
334 TRAP_MEMSET = 100,
335 TRAP_MEMCPY,
336 TRAP_STRNCPY,
337 TRAP_SIN,
338 TRAP_COS,
339 TRAP_ATAN2,
340 TRAP_SQRT,
341 TRAP_MATRIXMULTIPLY,
342 TRAP_ANGLEVECTORS,
343 TRAP_PERPENDICULARVECTOR,
344 TRAP_FLOOR,
345 TRAP_CEIL,
346
347 TRAP_TESTPRINTINT,
348 TRAP_TESTPRINTFLOAT
349 } sharedTraps_t;
350
351 typedef intptr_t (QDECL *vmMainProc)(int callNum, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11);
352
353 void VM_Init( void );
354 vm_t *VM_Create( const char *module, intptr_t (*systemCalls)(intptr_t *),
355 vmInterpret_t interpret );
356 // module should be bare: "cgame", not "cgame.dll" or "vm/cgame.qvm"
357
358 void VM_Free( vm_t *vm );
359 void VM_Clear(void);
360 void VM_Forced_Unload_Start(void);
361 void VM_Forced_Unload_Done(void);
362 vm_t *VM_Restart(vm_t *vm, qboolean unpure);
363
364 intptr_t QDECL VM_Call( vm_t *vm, int callNum, ... );
365
366 void VM_Debug( int level );
367
368 void *VM_ArgPtr( intptr_t intValue );
369 void *VM_ExplicitArgPtr( vm_t *vm, intptr_t intValue );
370
371 #define VMA(x) VM_ArgPtr(args[x])
372 static ID_INLINE float _vmf(intptr_t x)
373 {
374 floatint_t fi;
375 fi.i = (int) x;
376 return fi.f;
377 }
378 #define VMF(x) _vmf(args[x])
379
380
381 /*
382 ==============================================================
383
384 CMD
385
386 Command text buffering and command execution
387
388 ==============================================================
389 */
390
391 /*
392
393 Any number of commands can be added in a frame, from several different sources.
394 Most commands come from either keybindings or console line input, but entire text
395 files can be execed.
396
397 */
398
399 void Cbuf_Init (void);
400 // allocates an initial text buffer that will grow as needed
401
402 void Cbuf_AddText( const char *text );
403 // Adds command text at the end of the buffer, does NOT add a final \n
404
405 void Cbuf_ExecuteText( int exec_when, const char *text );
406 // this can be used in place of either Cbuf_AddText or Cbuf_InsertText
407
408 void Cbuf_Execute (void);
409 // Pulls off \n terminated lines of text from the command buffer and sends
410 // them through Cmd_ExecuteString. Stops when the buffer is empty.
411 // Normally called once per frame, but may be explicitly invoked.
412 // Do not call inside a command function, or current args will be destroyed.
413
414 //===========================================================================
415
416 /*
417
418 Command execution takes a null terminated string, breaks it into tokens,
419 then searches for a command or variable that matches the first token.
420
421 */
422
423 typedef void (*xcommand_t) (void);
424
425 void Cmd_Init (void);
426
427 void Cmd_AddCommand( const char *cmd_name, xcommand_t function );
428 // called by the init functions of other parts of the program to
429 // register commands and functions to call for them.
430 // The cmd_name is referenced later, so it should not be in temp memory
431 // if function is NULL, the command will be forwarded to the server
432 // as a clc_clientCommand instead of executed locally
433
434 void Cmd_RemoveCommand( const char *cmd_name );
435
436 typedef void (*completionFunc_t)( char *args, int argNum );
437
438 // don't allow VMs to remove system commands
439 void Cmd_RemoveCommandSafe( const char *cmd_name );
440
441 void Cmd_CommandCompletion( void(*callback)(const char *s) );
442 // callback with each valid string
443 void Cmd_SetCommandCompletionFunc( const char *command,
444 completionFunc_t complete );
445 void Cmd_CompleteArgument( const char *command, char *args, int argNum );
446 void Cmd_CompleteCfgName( char *args, int argNum );
447
448 int Cmd_Argc (void);
449 char *Cmd_Argv (int arg);
450 void Cmd_ArgvBuffer( int arg, char *buffer, int bufferLength );
451 char *Cmd_Args (void);
452 char *Cmd_ArgsFrom( int arg );
453 void Cmd_ArgsBuffer( char *buffer, int bufferLength );
454 char *Cmd_Cmd (void);
455 void Cmd_Args_Sanitize( void );
456 // The functions that execute commands get their parameters with these
457 // functions. Cmd_Argv () will return an empty string, not a NULL
458 // if arg > argc, so string operations are allways safe.
459
460 void Cmd_TokenizeString( const char *text );
461 void Cmd_TokenizeStringIgnoreQuotes( const char *text_in );
462 // Takes a null terminated string. Does not need to be /n terminated.
463 // breaks the string up into arg tokens.
464
465 void Cmd_ExecuteString( const char *text );
466 // Parses a single line of text into arguments and tries to execute it
467 // as if it was typed at the console
468
469
470 /*
471 ==============================================================
472
473 CVAR
474
475 ==============================================================
476 */
477
478 /*
479
480 cvar_t variables are used to hold scalar or string variables that can be changed
481 or displayed at the console or prog code as well as accessed directly
482 in C code.
483
484 The user can access cvars from the console in three ways:
485 r_draworder prints the current value
486 r_draworder 0 sets the current value to 0
487 set r_draworder 0 as above, but creates the cvar if not present
488
489 Cvars are restricted from having the same names as commands to keep this
490 interface from being ambiguous.
491
492 The are also occasionally used to communicated information between different
493 modules of the program.
494
495 */
496
497 cvar_t *Cvar_Get( const char *var_name, const char *value, int flags );
498 // creates the variable if it doesn't exist, or returns the existing one
499 // if it exists, the value will not be changed, but flags will be ORed in
500 // that allows variables to be unarchived without needing bitflags
501 // if value is "", the value will not override a previously set value.
502
503 void Cvar_Register( vmCvar_t *vmCvar, const char *varName, const char *defaultValue, int flags );
504 // basically a slightly modified Cvar_Get for the interpreted modules
505
506 void Cvar_Update( vmCvar_t *vmCvar );
507 // updates an interpreted modules' version of a cvar
508
509 void Cvar_Set( const char *var_name, const char *value );
510 // will create the variable with no flags if it doesn't exist
511
512 cvar_t *Cvar_Set2(const char *var_name, const char *value, qboolean force);
513 // same as Cvar_Set, but allows more control over setting of cvar
514
515 void Cvar_SetSafe( const char *var_name, const char *value );
516 // sometimes we set variables from an untrusted source: fail if flags & CVAR_PROTECTED
517
518 void Cvar_SetLatched( const char *var_name, const char *value);
519 // don't set the cvar immediately
520
521 void Cvar_SetValue( const char *var_name, float value );
522 void Cvar_SetValueSafe( const char *var_name, float value );
523 // expands value to a string and calls Cvar_Set/Cvar_SetSafe
524
525 float Cvar_VariableValue( const char *var_name );
526 int Cvar_VariableIntegerValue( const char *var_name );
527 // returns 0 if not defined or non numeric
528
529 char *Cvar_VariableString( const char *var_name );
530 void Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize );
531 // returns an empty string if not defined
532
533 int Cvar_Flags(const char *var_name);
534 // returns CVAR_NONEXISTENT if cvar doesn't exist or the flags of that particular CVAR.
535
536 void Cvar_CommandCompletion( void(*callback)(const char *s) );
537 // callback with each valid string
538
539 void Cvar_Reset( const char *var_name );
540 void Cvar_ForceReset(const char *var_name);
541
542 void Cvar_SetCheatState( void );
543 // reset all testing vars to a safe value
544
545 qboolean Cvar_Command( void );
546 // called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
547 // command. Returns true if the command was a variable reference that
548 // was handled. (print or change)
549
550 void Cvar_WriteVariables( fileHandle_t f );
551 // writes lines containing "set variable value" for all variables
552 // with the archive flag set to true.
553
554 void Cvar_Init( void );
555
556 char *Cvar_InfoString( int bit );
557 char *Cvar_InfoString_Big( int bit );
558 // returns an info string containing all the cvars that have the given bit set
559 // in their flags ( CVAR_USERINFO, CVAR_SERVERINFO, CVAR_SYSTEMINFO, etc )
560 void Cvar_InfoStringBuffer( int bit, char *buff, int buffsize );
561 void Cvar_CheckRange( cvar_t *cv, float minVal, float maxVal, qboolean shouldBeIntegral );
562 void Cvar_SetDescription( cvar_t *var, const char *var_description );
563
564 void Cvar_Restart(qboolean unsetVM);
565 void Cvar_Restart_f( void );
566
567 void Cvar_CompleteCvarName( char *args, int argNum );
568
569 extern int cvar_modifiedFlags;
570 // whenever a cvar is modifed, its flags will be OR'd into this, so
571 // a single check can determine if any CVAR_USERINFO, CVAR_SERVERINFO,
572 // etc, variables have been modified since the last check. The bit
573 // can then be cleared to allow another change detection.
574
575 /*
576 ==============================================================
577
578 FILESYSTEM
579
580 No stdio calls should be used by any part of the game, because
581 we need to deal with all sorts of directory and seperator char
582 issues.
583 ==============================================================
584 */
585
586 // referenced flags
587 // these are in loop specific order so don't change the order
588 #define FS_GENERAL_REF 0x01
589 #define FS_UI_REF 0x02
590 #define FS_CGAME_REF 0x04
591 // number of id paks that will never be autodownloaded from baseq3/missionpack
592 #define NUM_ID_PAKS 9
593 #define NUM_TA_PAKS 4
594
595 #define MAX_FILE_HANDLES 64
596
597 #ifdef DEDICATED
598 # define Q3CONFIG_CFG CONFIG_PREFIX "_server.cfg"
599 #else
600 # define Q3CONFIG_CFG CONFIG_PREFIX ".cfg"
601 #endif
602
603 qboolean FS_Initialized( void );
604
605 void FS_InitFilesystem ( void );
606 void FS_Shutdown( qboolean closemfp );
607
608 qboolean FS_ConditionalRestart(int checksumFeed, qboolean disconnect);
609 void FS_Restart( int checksumFeed );
610 // shutdown and restart the filesystem so changes to fs_gamedir can take effect
611
612 char **FS_ListFiles( const char *directory, const char *extension, int *numfiles );
613 // directory should not have either a leading or trailing /
614 // if extension is "/", only subdirectories will be returned
615 // the returned files will not include any directories or /
616
617 void FS_FreeFileList( char **list );
618
619 qboolean FS_FileExists_HomeData( const char *file );
620
621 qboolean FS_CreatePath (const char *OSPath);
622
•623 int FS_FindVM(void **startSearch, char *found, int foundlen, const char *name, int enableDll, int forceDll);
624
625 char *FS_BaseDir_BuildOSPath( const char *base, const char *qpath );
626 char *FS_BuildOSPath( const char *base, const char *game, const char *qpath );
627 qboolean FS_CompareZipChecksum(const char *zipfile);
628
629 int FS_LoadStack( void );
630
631 int FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize );
632 int FS_GetModList( char *listbuf, int bufsize );
633
634 void FS_GetModDescription( const char *modDir, char *description, int descriptionLen );
635
636 fileHandle_t FS_FOpenFileWrite_HomeConfig( const char *filename );
637 fileHandle_t FS_FOpenFileWrite_HomeData( const char *filename );
638 fileHandle_t FS_FOpenFileWrite_HomeState( const char *filename );
639 fileHandle_t FS_FOpenFileAppend_HomeData( const char *filename );
640 fileHandle_t FS_FCreateOpenPipeFile( const char *filename );
641 // will properly create any needed paths and deal with seperater character issues
642
643 fileHandle_t FS_BaseDir_FOpenFileWrite_HomeConfig( const char *filename );
644 fileHandle_t FS_BaseDir_FOpenFileWrite_HomeData( const char *filename );
645 fileHandle_t FS_BaseDir_FOpenFileWrite_HomeState( const char *filename );
646 long FS_BaseDir_FOpenFileRead( const char *filename, fileHandle_t *fp );
647 void FS_BaseDir_Rename_HomeData( const char *from, const char *to, qboolean safe );
648 long FS_FOpenFileRead( const char *qpath, fileHandle_t *file, qboolean uniqueFILE );
649 // if uniqueFILE is true, then a new FILE will be fopened even if the file
650 // is found in an already open pak file. If uniqueFILE is false, you must call
651 // FS_FCloseFile instead of fclose, otherwise the pak FILE would be improperly closed
652 // It is generally safe to always set uniqueFILE to true, because the majority of
653 // file IO goes through FS_ReadFile, which Does The Right Thing already.
654
655 int FS_FileIsInPAK(const char *filename, int *pChecksum );
656 // returns 1 if a file is in the PAK file, otherwise -1
657
658 int FS_Write( const void *buffer, int len, fileHandle_t f );
659
660 int FS_Read( void *buffer, int len, fileHandle_t f );
661 // properly handles partial reads and reads from other dlls
662
663 void FS_FCloseFile( fileHandle_t f );
664 // note: you can't just fclose from another DLL, due to MS libc issues
665
666 long FS_ReadFileDir(const char *qpath, void *searchPath, qboolean unpure, void **buffer);
667 long FS_ReadFile(const char *qpath, void **buffer);
668 // returns the length of the file
669 // a null buffer will just return the file length without loading
670 // as a quick check for existence. -1 length == not present
671 // A 0 byte will always be appended at the end, so string ops are safe.
672 // the buffer should be considered read-only, because it may be cached
673 // for other uses.
674
675 void FS_ForceFlush( fileHandle_t f );
676 // forces flush on files we're writing to.
677
678 void FS_FreeFile( void *buffer );
679 // frees the memory returned by FS_ReadFile
680
681 void FS_WriteFile( const char *qpath, const void *buffer, int size );
682 // writes a complete file, creating any subdirectories needed
683
684 long FS_filelength(fileHandle_t f);
685 // doesn't work for files that are opened from a pack file
686
687 int FS_FTell( fileHandle_t f );
688 // where are we?
689
690 void FS_Flush( fileHandle_t f );
691
692 void QDECL FS_Printf( fileHandle_t f, const char *fmt, ... ) Q_PRINTF_FUNC(2, 3);
693 // like fprintf
694
695 int FS_FOpenFileByMode( const char *qpath, fileHandle_t *f, fsMode_t mode );
696 // opens a file for reading, writing, or appending depending on the value of mode
697
698 int FS_Seek( fileHandle_t f, long offset, int origin );
699 // seek on a file
700
701 qboolean FS_FilenameCompare( const char *s1, const char *s2 );
702
703 const char *FS_LoadedPakNames( void );
704 const char *FS_LoadedPakChecksums( void );
705 const char *FS_LoadedPakPureChecksums( void );
706 // Returns a space separated string containing the checksums of all loaded pk3 files.
707 // Servers with sv_pure set will get this string and pass it to clients.
708
709 const char *FS_ReferencedPakNames( void );
710 const char *FS_ReferencedPakChecksums( void );
711 const char *FS_ReferencedPakPureChecksums( void );
712 // Returns a space separated string containing the checksums of all loaded
713 // AND referenced pk3 files. Servers with sv_pure set will get this string
714 // back from clients for pure validation
715
716 void FS_ClearPakReferences( int flags );
717 // clears referenced booleans on loaded pk3s
718
719 void FS_PureServerSetReferencedPaks( const char *pakSums, const char *pakNames );
720 void FS_PureServerSetLoadedPaks( const char *pakSums, const char *pakNames );
721 // If the string is empty, all data sources will be allowed.
722 // If not empty, only pk3 files that match one of the space
723 // separated checksums will be checked for files, with the
724 // sole exception of .cfg files.
725
726 qboolean FS_CheckDirTraversal(const char *checkdir);
727 qboolean FS_InvalidGameDir(const char *gamedir);
728 qboolean FS_idPak(char *pak, char *base, int numPaks);
729 qboolean FS_ComparePaks( char *neededpaks, int len, qboolean dlstring );
730
731 void FS_Remove( const char *osPath );
732 void FS_Remove_HomeData( const char *homePath );
733
734 void FS_FilenameCompletion( const char *dir, const char *ext, char *filter,
735 qboolean stripExt, void(*callback)(const char *s), qboolean allowNonPureFilesOnDisk );
736
737 const char *FS_GetCurrentGameDir(void);
738 qboolean FS_Which(const char *filename, void *searchPath);
739
740 /*
741 ==============================================================
742
743 Edit fields and command line history/completion
744
745 ==============================================================
746 */
747
748 #define MAX_EDIT_LINE 256
749 typedef struct {
750 int cursor;
751 int scroll;
752 int widthInChars;
753 char buffer[MAX_EDIT_LINE];
754 } field_t;
755
756 void Field_Clear( field_t *edit );
757 void Field_AutoComplete( field_t *edit );
758 void Field_CompleteKeyname( void );
759 void Field_CompleteFilename( const char *dir, const char *ext,
760 char *filter, qboolean stripExt,
761 qboolean allowNonPureFilesOnDisk );
762 void Field_CompleteCommand( char *cmd,
763 qboolean doCommands, qboolean doCvars );
764 void Field_CompletePlayerName( const char **names, int count );
765
766 /*
767 ==============================================================
768
769 MISC
770
771 ==============================================================
772 */
773
774 // centralizing the declarations for cl_cdkey
775 // https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=470
776 extern char cl_cdkey[34];
777
778 // returned by Sys_GetProcessorFeatures
779 typedef enum
780 {
781 CF_RDTSC = 1 << 0,
782 CF_MMX = 1 << 1,
783 CF_MMX_EXT = 1 << 2,
784 CF_3DNOW = 1 << 3,
785 CF_3DNOW_EXT = 1 << 4,
786 CF_SSE = 1 << 5,
787 CF_SSE2 = 1 << 6,
788 CF_ALTIVEC = 1 << 7
789 } cpuFeatures_t;
790
791 // centralized and cleaned, that's the max string you can send to a Com_Printf / Com_DPrintf (above gets truncated)
792 #define MAXPRINTMSG 4096
793
794
795 typedef enum {
796 // SE_NONE must be zero
797 SE_NONE = 0, // evTime is still valid
798 SE_KEY, // evValue is a key code, evValue2 is the down flag
799 SE_CHAR, // evValue is an ascii char
800 SE_MOUSE, // evValue and evValue2 are relative signed x / y moves
801 SE_JOYSTICK_AXIS, // evValue is an axis number and evValue2 is the current state (-127 to 127)
802 SE_CONSOLE // evPtr is a char*
803 } sysEventType_t;
804
805 typedef struct {
806 int evTime;
807 sysEventType_t evType;
808 int evValue, evValue2;
809 int evPtrLength; // bytes of data pointed to by evPtr, for journaling
810 void *evPtr; // this must be manually freed if not NULL
811 } sysEvent_t;
812
813 void Com_QueueEvent( int time, sysEventType_t type, int value, int value2, int ptrLength, void *ptr );
814 int Com_EventLoop( void );
815 sysEvent_t Com_GetSystemEvent( void );
816
817 char *CopyString( const char *in );
818 void Info_Print( const char *s );
819
820 void Com_BeginRedirect (char *buffer, int buffersize, void (*flush)(char *));
821 void Com_EndRedirect( void );
822 void QDECL Com_Printf( const char *fmt, ... ) Q_PRINTF_FUNC(1, 2);
823 void QDECL Com_DPrintf( const char *fmt, ... ) Q_PRINTF_FUNC(1, 2);
824 void QDECL Com_Error( int code, const char *fmt, ... ) Q_NO_RETURN Q_PRINTF_FUNC(2, 3);
825 void Com_Quit_f( void ) Q_NO_RETURN;
826 void Com_GameRestart(int checksumFeed, qboolean disconnect);
827
828 int Com_Milliseconds( void ); // will be journaled properly
829 unsigned Com_BlockChecksum( const void *buffer, int length );
830 char *Com_MD5File(const char *filename, int length, const char *prefix, int prefix_len);
831 int Com_Filter(char *filter, char *name, int casesensitive);
832 int Com_FilterPath(char *filter, char *name, int casesensitive);
833 int Com_RealTime(qtime_t *qtime);
834 qboolean Com_SafeMode( void );
835 void Com_RunAndTimeServerPacket(netadr_t *evFrom, msg_t *buf);
836
837 qboolean Com_IsVoipTarget(uint8_t *voipTargets, int voipTargetsSize, int clientNum);
838
839 void Com_StartupVariable( const char *match );
840 // checks for and removes command line "+set var arg" constructs
841 // if match is NULL, all set commands will be executed, otherwise
842 // only a set with the exact name. Only used during startup.
843
844 qboolean Com_PlayerNameToFieldString( char *str, int length, const char *name );
845 qboolean Com_FieldStringToPlayerName( char *name, int length, const char *rawname );
846 int QDECL Com_strCompare( const void *a, const void *b );
847
848
849 extern cvar_t *com_developer;
850 extern cvar_t *com_dedicated;
851 extern cvar_t *com_speeds;
852 extern cvar_t *com_timescale;
853 extern cvar_t *com_sv_running;
854 extern cvar_t *com_cl_running;
855 extern cvar_t *com_version;
856 extern cvar_t *com_blood;
857 extern cvar_t *com_buildScript; // for building release pak files
858 extern cvar_t *com_journal;
859 extern cvar_t *com_cameraMode;
860 extern cvar_t *com_ansiColor;
861 extern cvar_t *com_unfocused;
862 extern cvar_t *com_maxfpsUnfocused;
863 extern cvar_t *com_minimized;
864 extern cvar_t *com_maxfpsMinimized;
865 extern cvar_t *com_altivec;
866 extern cvar_t *com_standalone;
867 extern cvar_t *com_basegame;
868 extern cvar_t *com_homepath;
869
870 // both client and server must agree to pause
871 extern cvar_t *cl_paused;
872 extern cvar_t *sv_paused;
873
874 extern cvar_t *cl_packetdelay;
875 extern cvar_t *sv_packetdelay;
876
877 extern cvar_t *com_gamename;
878 extern cvar_t *com_protocol;
879 #ifdef LEGACY_PROTOCOL
880 extern cvar_t *com_legacyprotocol;
881 #endif
882 #ifndef DEDICATED
883 extern cvar_t *con_autochat;
884 #endif
885
886 // com_speeds times
887 extern int time_game;
888 extern int time_frontend;
889 extern int time_backend; // renderer backend time
890
891 extern int com_frameTime;
892
893 extern qboolean com_errorEntered;
894 extern qboolean com_fullyInitialized;
895
896 extern fileHandle_t com_journalFile;
897 extern fileHandle_t com_journalDataFile;
898
899 typedef enum {
900 TAG_FREE,
901 TAG_GENERAL,
902 TAG_BOTLIB,
903 TAG_RENDERER,
904 TAG_SMALL,
905 TAG_STATIC
906 } memtag_t;
907
908 /*
909
910 --- low memory ----
911 server vm
912 server clipmap
913 ---mark---
914 renderer initialization (shaders, etc)
915 UI vm
916 cgame vm
917 renderer map
918 renderer models
919
920 ---free---
921
922 temp file loading
923 --- high memory ---
924
925 */
926
927 #if !defined(NDEBUG) && !defined(BSPC)
928 #define ZONE_DEBUG
929 #endif
930
931 #ifdef ZONE_DEBUG
932 #define Z_TagMalloc(size, tag) Z_TagMallocDebug(size, tag, #size, __FILE__, __LINE__)
933 #define Z_Malloc(size) Z_MallocDebug(size, #size, __FILE__, __LINE__)
934 #define S_Malloc(size) S_MallocDebug(size, #size, __FILE__, __LINE__)
935 void *Z_TagMallocDebug( int size, int tag, char *label, char *file, int line ); // NOT 0 filled memory
936 void *Z_MallocDebug( int size, char *label, char *file, int line ); // returns 0 filled memory
937 void *S_MallocDebug( int size, char *label, char *file, int line ); // returns 0 filled memory
938 #else
939 void *Z_TagMalloc( int size, int tag ); // NOT 0 filled memory
940 void *Z_Malloc( int size ); // returns 0 filled memory
941 void *S_Malloc( int size ); // NOT 0 filled memory only for small allocations
942 #endif
943 void Z_Free( void *ptr );
944 void Z_FreeTags( int tag );
945 int Z_AvailableMemory( void );
946 void Z_LogHeap( void );
947
948 void Hunk_Clear( void );
949 void Hunk_ClearToMark( void );
950 void Hunk_SetMark( void );
951 qboolean Hunk_CheckMark( void );
952 void Hunk_ClearTempMemory( void );
953 void *Hunk_AllocateTempMemory( int size );
954 void Hunk_FreeTempMemory( void *buf );
955 int Hunk_MemoryRemaining( void );
956 void Hunk_Log( void);
957
958 void Com_TouchMemory( void );
959
960 // commandLine should not include the executable name (argv[0])
961 void Com_Init( char *commandLine );
962 void Com_Frame( void );
963 void Com_Shutdown( void );
964
965
966 /*
967 ==============================================================
968
969 CLIENT / SERVER SYSTEMS
970
971 ==============================================================
972 */
973
974 //
975 // client interface
976 //
977 void CL_InitKeyCommands( void );
978 // the keyboard binding interface must be setup before execing
979 // config files, but the rest of client startup will happen later
980
981 void CL_Init( void );
982 void CL_Disconnect( qboolean showMainMenu );
983 void CL_Shutdown(char *finalmsg, qboolean disconnect, qboolean quit);
984 void CL_Frame( int msec );
985 qboolean CL_GameCommand( void );
986 void CL_KeyEvent (int key, qboolean down, unsigned time);
987
988 void CL_CharEvent( int key );
989 // char events are for field typing, not game control
990
991 void CL_MouseEvent( int dx, int dy, int time );
992
993 void CL_JoystickEvent( int axis, int value, int time );
994
995 void CL_PacketEvent( netadr_t from, msg_t *msg );
996
997 void CL_ConsolePrint( char *text );
998
999 void CL_MapLoading( void );
1000 // do a screen update before starting to load a map
1001 // when the server is going to load a new map, the entire hunk
1002 // will be cleared, so the client must shutdown cgame, ui, and
1003 // the renderer
1004
1005 void CL_ForwardCommandToServer( const char *string );
1006 // adds the current command line as a clc_clientCommand to the client message.
1007 // things like godmode, noclip, etc, are commands directed to the server,
1008 // so when they are typed in at the console, they will need to be forwarded.
1009
1010 void CL_CDDialog( void );
1011 // bring up the "need a cd to play" dialog
1012
1013 void CL_FlushMemory( void );
1014 // dump all memory on an error
1015
1016 void CL_ShutdownAll(qboolean shutdownRef);
1017 // shutdown client
1018
1019 void CL_InitRef(void);
1020 // initialize renderer interface
1021
1022 void CL_StartHunkUsers( qboolean rendererOnly );
1023 // start all the client stuff using the hunk
1024
1025 void CL_Snd_Shutdown(void);
1026 // Restart sound subsystem
1027
1028 void Key_KeynameCompletion( void(*callback)(const char *s) );
1029 // for keyname autocompletion
1030
1031 void Key_WriteBindings( fileHandle_t f );
1032 // for writing the config files
1033
1034 void S_ClearSoundBuffer( void );
1035 // call before filesystem access
1036
1037 void SCR_DebugGraph (float value); // FIXME: move logging to common?
1038
1039 // AVI files have the start of pixel lines 4 byte-aligned
1040 #define AVI_LINE_PADDING 4
1041
1042 //
1043 // server interface
1044 //
1045 void SV_Init( void );
1046 void SV_Shutdown( char *finalmsg );
1047 void SV_Frame( int msec );
1048 void SV_PacketEvent( netadr_t from, msg_t *msg );
1049 int SV_FrameMsec(void);
1050 qboolean SV_GameCommand( void );
1051 int SV_SendQueuedPackets(void);
1052
1053 //
1054 // UI interface
1055 //
1056 qboolean UI_GameCommand( void );
1057 qboolean UI_usesUniqueCDKey(void);
1058
1059 //
1060 // input interface
1061 //
1062 void IN_Init( void *windowData );
1063 void IN_Frame( void );
1064 void IN_Shutdown( void );
1065 void IN_Restart( void );
1066
1067 /*
1068 ==============================================================
1069
1070 NON-PORTABLE SYSTEM SERVICES
1071
1072 ==============================================================
1073 */
1074
1075 #define MAX_JOYSTICK_AXIS 16
1076
1077 void Sys_Init (void);
1078
1079 // general development dll loading for virtual machine testing
1080 void * QDECL Sys_LoadGameDll( const char *name, vmMainProc *entryPoint,
1081 intptr_t (QDECL *systemcalls)(intptr_t, ...) );
1082 void Sys_UnloadDll( void *dllHandle );
1083
1084 qboolean Sys_DllExtension( const char *name );
1085
1086 char *Sys_GetCurrentUser( void );
1087
1088 void QDECL Sys_Error( const char *error, ...) Q_NO_RETURN Q_PRINTF_FUNC(1, 2);
1089 void Sys_Quit (void) Q_NO_RETURN;
1090 char *Sys_GetClipboardData( void ); // note that this isn't journaled...
1091
1092 void Sys_Print( const char *msg );
1093
1094 // Sys_Milliseconds should only be used for profiling purposes,
1095 // any game related timing information should come from event timestamps
1096 int Sys_Milliseconds (void);
1097
1098 qboolean Sys_RandomBytes( byte *string, int len );
1099
1100 // the system console is shown when a dedicated server is running
1101 void Sys_DisplaySystemConsole( qboolean show );
1102
1103 cpuFeatures_t Sys_GetProcessorFeatures( void );
1104
1105 void Sys_SetErrorText( const char *text );
1106
1107 void Sys_SendPacket( int length, const void *data, netadr_t to );
1108
1109 qboolean Sys_StringToAdr( const char *s, netadr_t *a, netadrtype_t family );
1110 //Does NOT parse port numbers, only base addresses.
1111
1112 qboolean Sys_IsLANAddress (netadr_t adr);
1113 void Sys_ShowIP(void);
1114
1115 FILE *Sys_FOpen( const char *ospath, const char *mode );
1116 qboolean Sys_Mkdir( const char *path );
1117 FILE *Sys_Mkfifo( const char *ospath );
1118 char *Sys_Cwd( void );
1119 void Sys_SetDefaultInstallPath(const char *path);
1120 char *Sys_DefaultInstallPath(void);
1121 char *Sys_SteamPath(void);
1122 char *Sys_GogPath(void);
1123 char *Sys_MicrosoftStorePath(void);
1124
1125 #ifdef __APPLE__
1126 char *Sys_DefaultAppPath(void);
1127 #endif
1128
1129 char *Sys_DefaultHomeConfigPath(void);
1130 char *Sys_DefaultHomeDataPath(void);
1131 char *Sys_DefaultHomeStatePath(void);
1132 const char *Sys_Dirname( char *path );
1133 const char *Sys_Basename( char *path );
1134 char *Sys_ConsoleInput(void);
1135
1136 char **Sys_ListFiles( const char *directory, const char *extension, char *filter, int *numfiles, qboolean wantsubs );
1137 void Sys_FreeFileList( char **list );
1138 void Sys_Sleep(int msec);
1139
1140 qboolean Sys_LowPhysicalMemory( void );
1141
1142 void Sys_SetEnv(const char *name, const char *value);
1143
1144 typedef enum
1145 {
1146 DR_YES = 0,
1147 DR_NO = 1,
1148 DR_OK = 0,
1149 DR_CANCEL = 1
1150 } dialogResult_t;
1151
1152 typedef enum
1153 {
1154 DT_INFO,
1155 DT_WARNING,
1156 DT_ERROR,
1157 DT_YES_NO,
1158 DT_OK_CANCEL
1159 } dialogType_t;
1160
1161 dialogResult_t Sys_Dialog( dialogType_t type, const char *message, const char *title );
1162 qboolean Sys_OpenFolderInFileManager( const char *path, qboolean create );
1163
1164 void Sys_RemovePIDFile( const char *gamedir );
1165 void Sys_InitPIDFile( const char *gamedir );
1166
1167 /* This is based on the Adaptive Huffman algorithm described in Sayood's Data
1168 * Compression book. The ranks are not actually stored, but implicitly defined
1169 * by the location of a node within a doubly-linked list */
1170
1171 #define NYT HMAX /* NYT = Not Yet Transmitted */
1172 #define INTERNAL_NODE (HMAX+1)
1173
1174 typedef struct nodetype {
1175 struct nodetype *left, *right, *parent; /* tree structure */
1176 struct nodetype *next, *prev; /* doubly-linked list */
1177 struct nodetype **head; /* highest ranked node in block */
1178 int weight;
1179 int symbol;
1180 } node_t;
1181
1182 #define HMAX 256 /* Maximum symbol */
1183
1184 typedef struct {
1185 int blocNode;
1186 int blocPtrs;
1187
1188 node_t* tree;
1189 node_t* lhead;
1190 node_t* ltail;
1191 node_t* loc[HMAX+1];
1192 node_t** freelist;
1193
1194 node_t nodeList[768];
1195 node_t* nodePtrs[768];
1196 } huff_t;
1197
1198 typedef struct {
1199 huff_t compressor;
1200 huff_t decompressor;
1201 } huffman_t;
1202
1203 void Huff_Compress(msg_t *buf, int offset);
1204 void Huff_Decompress(msg_t *buf, int offset);
1205 void Huff_Init(huffman_t *huff);
1206 void Huff_addRef(huff_t* huff, byte ch);
1207 int Huff_Receive (node_t *node, int *ch, byte *fin);
1208 void Huff_transmit (huff_t *huff, int ch, byte *fout, int maxoffset);
1209 void Huff_offsetReceive (node_t *node, int *ch, byte *fin, int *offset, int maxoffset);
1210 void Huff_offsetTransmit (huff_t *huff, int ch, byte *fout, int *offset, int maxoffset);
1211 void Huff_putBit( int bit, byte *fout, int *offset);
1212 int Huff_getBit( byte *fout, int *offset);
1213
1214 // don't use if you don't know what you're doing.
1215 int Huff_getBloc(void);
1216 void Huff_setBloc(int _bloc);
1217
1218
1219 extern huffman_t clientHuffTables;
1220
1221 #define SV_ENCODE_START 4
1222 #define SV_DECODE_START 12
1223 #define CL_ENCODE_START 12
1224 #define CL_DECODE_START 4
1225
1226 // flags for sv_allowDownload and cl_allowDownload
1227 #define DLF_ENABLE 1
1228 #define DLF_NO_REDIRECT 2
1229 #define DLF_NO_UDP 4
1230 #define DLF_NO_DISCONNECT 8
1231
1232 #endif // _QCOMMON_H_