1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 
21 // qcommon.h -- definitions common between client and server, but not game.dll
22 
23 #include "q_shared.h"
24 #include "qfiles.h"
25 #include "com_public.h"
26 #include "protocol.h"
27 #include "q_msg.h"
28 
29 #define APPLICATION     "q2pro"
30 
31 #define	INITDIRNAME		"baseq2pro"
32 #define	BASEDIRNAME		"baseq2"
33 #define BASEDIRDESCRIPTION	"Quake II"
34 
35 #ifdef __unix__
36 #define HOMEDIRNAME     ".q2pro"
37 #endif
38 
39 
40 /*
41 ==============================================================
42 
43 CMD
44 
45 Command text buffering and command execution
46 
47 ==============================================================
48 */
49 
50 #define CMD_BUFFER_SIZE		( 1 << 16 )		// bumped max config size up to 64K
51 
52 #define	ALIAS_LOOP_COUNT		16
53 
54 typedef struct {
55 	sizebuf_t	text;
56 	int			waitCount;
57 	int			aliasCount; // for detecting runaway loops
58 	void		(*exec)( const char * );
59 } cmdbuf_t;
60 
61 extern byte			cmd_buffer_text[CMD_BUFFER_SIZE];
62 extern cmdbuf_t		cmd_buffer;
63 
64 /*
65 
66 Any number of commands can be added in a frame, from several different sources.
67 Most commands come from either keybindings or console line input, but remote
68 servers can also send across commands and entire text files can be execed.
69 
70 The + command line options are also added to the command buffer.
71 
72 The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute ();
73 
74 */
75 
76 void Cbuf_Init( void );
77 // allocates an initial text buffer that will grow as needed
78 
79 void Cbuf_AddTextEx( cmdbuf_t *buf, const char *text );
80 // as new commands are generated from the console or keybindings,
81 // the text is added to the end of the command buffer.
82 
83 void Cbuf_InsertTextEx( cmdbuf_t *buf, const char *text );
84 // when a command wants to issue other commands immediately, the text is
85 // inserted at the beginning of the buffer, before any remaining unexecuted
86 // commands.
87 
88 void Cbuf_ExecuteEx( cmdbuf_t *buf );
89 // Pulls off \n terminated lines of text from the command buffer and sends
90 // them through Cmd_ExecuteString.  Stops when the buffer is empty.
91 // Normally called once per frame, but may be explicitly invoked.
92 // Do not call inside a command function!
93 
94 #define Cbuf_AddText( text )	Cbuf_AddTextEx( &cmd_buffer, text )
95 #define Cbuf_InsertText( text )	Cbuf_InsertTextEx( &cmd_buffer, text )
96 #define Cbuf_Execute()			Cbuf_ExecuteEx( &cmd_buffer )
97 
98 //===========================================================================
99 
100 /*
101 
102 Command execution takes a null terminated string, breaks it into tokens,
103 then searches for a command or variable that matches the first token.
104 
105 */
106 
107 void	Cmd_Init( void );
108 
109 qboolean Cmd_Exists( const char *cmd_name );
110 // used by the cvar code to check for cvar / command name overlap
111 
112 xcommand_t Cmd_FindFunction( const char *name );
113 xmacro_t Cmd_FindMacroFunction( const char *name );
114 xgenerator_t Cmd_FindGenerator( const char *name );
115 
116 char *Cmd_AliasCommand( const char *name );
117 void Cmd_AliasSet( const char *name, const char *cmd );
118 
119 const char *Cmd_CommandGenerator( const char *text, int state );
120 const char *Cmd_AliasGenerator( const char *text, int state );
121 // attempts to match a partial command for automatic command line completion
122 // returns NULL if nothing fits
123 
124 void	Cmd_TokenizeString( const char *text, qboolean macroExpand );
125 // Takes a null terminated string.  Does not need to be /n terminated.
126 // breaks the string up into arg tokens.
127 
128 void	Cmd_ExecuteString( const char *text );
129 // Parses a single line of text into arguments and tries to execute it
130 // as if it was typed at the console
131 
132 void	Cmd_ForwardToServer( void );
133 // adds the current command line as a clc_stringcmd to the client message.
134 // things like godmode, noclip, etc, are commands directed to the server,
135 // so when they are typed in at the console, they will need to be forwarded.
136 
137 char *Cmd_MacroExpandString( const char *text, qboolean aliasHack );
138 
139 void Cbuf_ExecuteText( cbufExecWhen_t exec_when, const char *text );
140 // this can be used in place of either Cbuf_AddText or Cbuf_InsertText
141 
142 void	Cmd_AddCommand( const char *cmd_name, xcommand_t function );
143 void	Cmd_AddCommandEx( const char *cmd_name, xcommand_t function, xgenerator_t generator );
144 // called by the init functions of other parts of the program to
145 // register commands and functions to call for them.
146 // The cmd_name is referenced later, so it should not be in temp memory
147 // if function is NULL, the command will be forwarded to the server
148 // as a clc_stringcmd instead of executed locally
149 void	Cmd_RemoveCommand( const char *cmd_name );
150 
151 void Cmd_AddMacro( const char *name, xmacro_t function );
152 
153 int		Cmd_Argc( void );
154 char	*Cmd_Argv( int arg );
155 char	*Cmd_Args( void );
156 char	*Cmd_RawArgs( void );
157 char	*Cmd_ArgsFrom( int from );
158 char	*Cmd_RawArgsFrom( int from );
159 void	Cmd_ArgsBuffer( char *buffer, int bufferSize );
160 void	Cmd_ArgvBuffer( int arg, char *buffer, int bufferSize );
161 int Cmd_EnumParam( int start, const char *sp, const char *lp );
162 int Cmd_CheckParam( const char *sp, const char *lp );
163 char *Cmd_FindParam( const char *sp, const char *lp );
164 int Cmd_ArgOffset( int arg );
165 int Cmd_FindArgForOffset( int offset );
166 char *Cmd_RawString( void );
167 // The functions that execute commands get their parameters with these
168 // functions. Cmd_Argv () will return an empty string, not a NULL
169 // if arg > argc, so string operations are always safe.
170 
171 void Cmd_Alias_f( void );
172 
173 typedef struct {
174 	qboolean numeric;
175 	char *string;
176 	float value;
177 } cmdEval_t;
178 
179 qboolean Cmd_EvaluateExpression( int firstArg, cmdEval_t *result );
180 
181 typedef enum {
182 	TRIG_CLIENT_SYSTEM,
183 	TRIG_CLIENT_CHAT,
184 	TRIG_CLIENT_PRINT,
185 	TRIG_CLIENT_CENTERPRINT,
186 	TRIG_SERVER_SYSTEM,
187 	TRIG_SERVER_BPRINT,
188 	TRIG_SERVER_DPRINT
189 } trigChannel_t;
190 
191 void Cmd_ExecTrigger( trigChannel_t chan, const char *string );
192 
193 void Cmd_FillAPI( cmdAPI_t *api );
194 
195 
196 /*
197 ==============================================================
198 
199 CVAR
200 
201 ==============================================================
202 */
203 
204 /*
205 
206 cvar_t variables are used to hold scalar or string variables that can be changed or displayed at the console or prog code as well as accessed directly
207 in C code.
208 
209 The user can access cvars from the console in three ways:
210 r_draworder			prints the current value
211 r_draworder 0		sets the current value to 0
212 set r_draworder 0	as above, but creates the cvar if not present
213 Cvars are restricted from having the same names as commands to keep this
214 interface from being ambiguous.
215 */
216 
217 typedef enum {
218 	CVAR_SET_CONSOLE,
219 	CVAR_SET_COMMAND_LINE,
220 	CVAR_SET_DIRECT
221 } cvarSetSource_t;
222 
223 extern	cvar_t	*cvar_vars;
224 extern	uint32	cvar_latchedModified;
225 extern	uint32	cvar_infoModified;
226 
227 void Cvar_SetByVar( cvar_t *var, const char *value, cvarSetSource_t source );
228 
229 cvar_t *Cvar_UserSet( const char *var_name, const char *value );
230 
231 cvar_t *Cvar_ForceSet (const char *var_name, const char *value);
232 // will set the variable even if NOSET or LATCH
233 
234 cvar_t 	*Cvar_FullSet( const char *var_name, const char *value,
235 					  int flags, cvarSetSource_t source );
236 
237 void Cvar_ClampInteger( cvar_t *var, int min, int max );
238 void Cvar_ClampValue( cvar_t *var, float min, float max );
239 
240 const char *Cvar_Generator( const char *text, int state );
241 // attempts to match a partial variable name for command line completion
242 // returns NULL if nothing fits
243 
244 void	Cvar_GetLatchedVars (void);
245 // any CVAR_LATCHEDED variables that have been set will now take effect
246 
247 void Cvar_FixCheats( void );
248 
249 qboolean Cvar_Command (void);
250 // called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
251 // command.  Returns qtrue if the command was a variable reference that
252 // was handled. (print or change)
253 
254 void 	Cvar_WriteVariables( fileHandle_t f );
255 // appends lines containing "set variable value" for all variables
256 // with the archive flag set to qtrue.
257 
258 void	Cvar_Init (void);
259 
260 char *Cvar_BitInfo( int bit );
261 char *Cvar_BitInfo_Big( int bit );
262 //
263 // returns an info string containing all the CVAR_USERINFO cvars
264 #define Cvar_Userinfo()     Cvar_BitInfo( CVAR_USERINFO )
265 
266 // returns an info string containing all the CVAR_SERVERINFO cvars
267 #define Cvar_Serverinfo()   Cvar_BitInfo( CVAR_SERVERINFO )
268 
269 cvar_t *Cvar_ForceSetEx( const char *var_name, const char *value, int flags );
270 
271 qboolean CL_CheatsOK( void );
272 
273 qboolean Cvar_Exists( const char *name );
274 
275 cvar_t *Cvar_Get( const char *var_name, const char *value, int flags );
276 // creates the variable if it doesn't exist, or returns the existing one
277 // if it exists, the value will not be changed, but flags will be ORed in
278 // that allows variables to be unarchived without needing bitflags
279 
280 cvar_t 	*Cvar_Set( const char *var_name, const char *value );
281 cvar_t 	*Cvar_SetEx( const char *var_name, const char *value, cvarSetSource_t source );
282 // will create the variable if it doesn't exist
283 
284 void	Cvar_SetValue( const char *var_name, float value );
285 void Cvar_SetInteger( const char *var_name, int value );
286 void Cvar_SetIntegerHex( const char *var_name, uint32 value );
287 // expands value to a string and calls Cvar_Set
288 
289 float	Cvar_VariableValue( const char *var_name );
290 int Cvar_VariableInteger( const char *var_name );
291 // returns 0 if not defined or non numeric
292 
293 char	*Cvar_VariableString( const char *var_name );
294 void Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufferSize );
295 // returns an empty string if not defined
296 
297 cvar_t *Cvar_FindVar( const char *var_name );
298 
299 void Cvar_Set_f( void );
300 
301 void Cvar_Subsystem( cvarSubsystem_t subsystem );
302 
303 void Cvar_FillAPI( cvarAPI_t *api );
304 
305 /*
306 ==============================================================
307 
308 NET
309 
310 ==============================================================
311 */
312 
313 // net.h -- quake's interface to the networking layer
314 
315 #define	PORT_ANY	-1
316 
317 #define MAX_PACKETLEN	4096		// max length of a single packet
318 #define	PACKET_HEADER	10			// two ints and a short
319 #define MAX_PACKETLEN_WRITABLE    ( MAX_PACKETLEN - PACKET_HEADER )
320 
321 typedef enum netadrtype_e {
322 	NA_BAD,
323 	NA_LOOPBACK,
324 	NA_BROADCAST,
325 	NA_IP
326 } netadrtype_t;
327 
328 typedef enum netsrc_e {
329 	NS_CLIENT,
330 	NS_SERVER,
331 	NS_COUNT
332 } netsrc_t;
333 
334 typedef enum netflag_e {
335 	NET_NONE	= 0,
336 	NET_CLIENT	= ( 1 << 0 ),
337 	NET_SERVER	= ( 1 << 1 )
338 } netflag_t;
339 
340 typedef struct netadr_s {
341 	netadrtype_t	type;
342 
343 	byte	ip[4];
344 
345 	unsigned short	port;
346 } netadr_t;
347 
348 void		NET_Init( void );
349 void		NET_Shutdown( void );
350 
351 void		NET_Config( netflag_t flag );
352 
353 int			NET_GetPacket( netsrc_t sock, netadr_t *fromAddress );
354 int			NET_SendPacket( netsrc_t sock, const netadr_t *to, int length, const byte *data );
355 qboolean	NET_GetLoopPacket( netsrc_t sock );
356 
357 qboolean	NET_IsEqualAdr( const netadr_t *a, const netadr_t *b );
358 qboolean	NET_IsEqualBaseAdr( const netadr_t *a, const netadr_t *b );
359 
360 char *		NET_AdrToString( const netadr_t *a );
361 qboolean	NET_StringToAdr( const char *s, netadr_t *a );
362 void		NET_Sleep( int msec );
363 
364 qboolean	NET_IsLANAddress( const netadr_t *adr );
365 #define		NET_IsLocalAddress( adr )	( (adr)->type == NA_LOOPBACK )
366 
367 //============================================================================
368 
369 typedef enum netchan_type_e {
370 	NETCHAN_OLD,
371 	NETCHAN_NEW
372 } netchan_type_t;
373 
374 typedef struct netchan_s {
375 	netchan_type_t	type;
376 	int			protocol;
377     int         maxpacketlen;
378 
379 	qboolean	fatal_error;
380 
381 	netsrc_t	sock;
382 
383 	int			dropped;			// between last packet and previous
384 
385 	int			last_received;		// for timeouts
386 	int			last_sent;			// for retransmits
387 
388 	netadr_t	remote_address;
389 	int			qport;				// qport value to write when transmitting
390 
391 	sizebuf_t	message;		// writing buffer for reliable data
392 
393 	int			reliable_length;
394 
395 	qboolean	reliable_ack_pending;	// set to qtrue each time reliable is received
396 	qboolean	fragment_pending;
397 
398 	// sequencing variables
399 	int			incoming_sequence;
400 	int			incoming_acknowledged;
401 	int			outgoing_sequence;
402 
403 	int			(*Transmit)( struct netchan_s *, int, const byte * );
404 	int			(*TransmitNextFragment)( struct netchan_s * );
405 	qboolean	(*Process)( struct netchan_s * );
406 	qboolean	(*ShouldUpdate)( struct netchan_s * );
407 } netchan_t;
408 
409 extern netadr_t     net_from;
410 
411 extern cvar_t       *net_qport;
412 extern cvar_t       *net_maxmsglen;
413 extern cvar_t       *net_chantype;
414 
415 void Netchan_Init( void );
416 int Netchan_OutOfBand( netsrc_t sock, const netadr_t *adr, int length,
417         const byte *data );
418 int Netchan_OutOfBandPrint( netsrc_t sock, const netadr_t *adr,
419         const char *format, ... );
420 netchan_t *Netchan_Setup( netsrc_t sock, netchan_type_t type,
421         const netadr_t *adr, int qport, int maxpacketlen, int protocol );
422 void Netchan_Close( netchan_t *netchan );
423 
424 /*
425 ==============================================================
426 
427 CMODEL
428 
429 ==============================================================
430 */
431 
432 typedef struct mapsurface_s {  // used internally due to name len probs //ZOID
433 	csurface_t	c;
434 	char		rname[32];
435 } mapsurface_t;
436 
437 typedef struct cnode_s {
438 	cplane_t			*plane;				// never NULL to differentiate from leafs
439 	struct cnode_s		*children[2];
440 } cnode_t;
441 
442 typedef struct {
443 	cplane_t		*plane;
444 	mapsurface_t	*surface;
445 } cbrushside_t;
446 
447 typedef struct {
448 	int				contents;
449 	int				numsides;
450 	cbrushside_t	*firstbrushside;
451 	int				checkcount;		// to avoid repeated testings
452 } cbrush_t;
453 
454 typedef struct {
455 	cplane_t	*plane;			// always NULL to differentiate from nodes
456 	int			contents;
457 	int			cluster;
458 	int			area;
459 	cbrush_t	**firstleafbrush;
460 	int			numleafbrushes;
461 } cleaf_t;
462 
463 typedef struct {
464 	int		numareaportals;
465 	int		firstareaportal;
466 	int		floodvalid;
467 } carea_t;
468 
469 typedef struct {
470 	uint32		portalnum;
471 	uint32		otherarea;
472 } careaportal_t;
473 
474 typedef struct cmodel_s {
475 	vec3_t		mins, maxs;
476 	vec3_t		origin;		// for sounds or lights
477 	cnode_t		*headnode;
478 } cmodel_t;
479 
480 typedef struct cmcache_s {
481 	char		name[MAX_QPATH];
482 	mempool_t	pool;
483 	uint32		checksum;
484 	qboolean	onlyVis;
485 	int			refcount;
486 
487 	int			numbrushsides;
488 	cbrushside_t *brushsides;
489 
490 	int				numtexinfo;
491 	mapsurface_t	*surfaces;
492 
493 	int				numplanes;
494 	cplane_t		*planes;
495 
496 	int			numnodes;
497 	cnode_t		*nodes;
498 
499 	int			numleafs;
500 	cleaf_t		*leafs;
501 
502 	int			numleafbrushes;
503 	cbrush_t	**leafbrushes;
504 
505 	int			numcmodels;
506 	cmodel_t	*cmodels;
507 
508 	int			numbrushes;
509 	cbrush_t	*brushes;
510 
511 	int			numclusters;
512 	int			numvisibility;
513 	int			visrowsize;
514 	dvis_t		*vis;
515 
516 	int			numEntityChars;
517 	char		*entitystring;
518 
519 	int			numareas;
520 	carea_t		*areas;
521 
522 	int			numareaportals;
523 	careaportal_t *areaportals;
524 } cmcache_t;
525 
526 typedef struct {
527 	cmcache_t	*cache;
528 	int			*floodnums;			// if two areas have equal floodnums, they are connected
529 	qboolean	*portalopen;
530 } cm_t;
531 
532 #define CM_LOAD_CLIENT	1
533 #define CM_LOAD_VISONLY	2
534 
535 void		CM_Init( void );
536 
537 void		CM_FreeMap( cm_t *cm );
538 qboolean	CM_LoadMap( cm_t *cm, const char *name, uint32 flags, uint32 *checksum );
539 cmodel_t	*CM_InlineModel( cm_t *cm, const char *name );	// *1, *2, etc
540 
541 int CM_NumClusters( cm_t *cm );
542 int CM_NumInlineModels( cm_t *cm );
543 char *CM_EntityString( cm_t *cm );
544 cnode_t *CM_NodeNum( cm_t *cm, int number );
545 
546 // creates a clipping hull for an arbitrary box
547 cnode_t *CM_HeadnodeForBox( vec3_t mins, vec3_t maxs );
548 
549 
550 // returns an ORed contents mask
551 int			CM_PointContents( vec3_t p, cnode_t *headnode );
552 int			CM_TransformedPointContents( vec3_t p, cnode_t *headnode,
553 									vec3_t origin, vec3_t angles );
554 
555 void		CM_BoxTrace( trace_t *trace, vec3_t start, vec3_t end,
556 						  vec3_t mins, vec3_t maxs,
557 						  cnode_t *headnode, int brushmask );
558 void		CM_TransformedBoxTrace( trace_t *trace, vec3_t start, vec3_t end,
559 						  vec3_t mins, vec3_t maxs,
560 						  cnode_t * headnode, int brushmask,
561 						  vec3_t origin, vec3_t angles );
562 
563 byte		*CM_ClusterPVS( cm_t *cm, int cluster);
564 byte		*CM_ClusterPHS( cm_t *cm, int cluster );
565 byte		*CM_FatPVS( cm_t *cm, const vec3_t org );
566 
567 cleaf_t		*CM_PointLeaf( cm_t *cm, vec3_t p );
568 
569 // call with topnode set to the headnode, returns with topnode
570 // set to the first node that splits the box
571 int			CM_BoxLeafs( cm_t *cm, vec3_t mins, vec3_t maxs, cleaf_t **list,
572 							int listsize, cnode_t **topnode );
573 
574 #define CM_LeafContents( leaf )		(leaf)->contents
575 #define CM_LeafCluster( leaf )		(leaf)->cluster
576 #define CM_LeafArea( leaf )		(leaf)->area
577 
578 void		CM_SetAreaPortalState ( cm_t *cm, int portalnum, qboolean open );
579 qboolean	CM_AreasConnected( cm_t *cm, int area1, int area2 );
580 
581 int			CM_WriteAreaBits( cm_t *cm, byte *buffer, int area );
582 int			CM_WritePortalBits( cm_t *cm, byte *buffer );
583 void		CM_SetPortalStates( cm_t *cm, byte *buffer, int bytes );
584 qboolean	CM_HeadnodeVisible( cnode_t *headnode, byte *visbits );
585 
586 void		CM_WritePortalState( cm_t *cm, fileHandle_t f );
587 void		CM_ReadPortalState( cm_t *cm, fileHandle_t f );
588 
589 /*
590 ==============================================================
591 
592 PLAYER MOVEMENT CODE
593 
594 Common between server and client so prediction matches
595 
596 ==============================================================
597 */
598 
599 typedef struct {
600 	qboolean	airaccelerate;
601 	qboolean	strafeHack;
602 	int			qwmod;
603 	float		speedMultiplier;
604 	float		upspeed;
605 	float		maxspeed;
606 	float		friction;
607 	float		waterfriction;
608 #ifdef PMOVE_HACK
609 	vec3_t		origin;
610 	vec3_t		velocity;
611 	qboolean	highprec;
612 #endif
613 } pmoveParams_t;
614 
615 void Pmove( pmove_t *pmove, pmoveParams_t *params );
616 
617 /*
618 ==============================================================
619 
620 FILESYSTEM
621 
622 ==============================================================
623 */
624 
625 void	FS_Init( void );
626 void	FS_Shutdown( qboolean total );
627 qboolean FS_NeedRestart( void );
628 void FS_Restart( void );
629 qboolean FS_SafeToRestart( void );
630 
631 qboolean FS_CopyFile( const char *src, const char *dst );
632 qboolean FS_RemoveFile( const char *path );
633 qboolean FS_RenameFile( const char *from, const char *to );
634 
635 char *FS_CopyExtraInfo( const char *name, const fsFileInfo_t *info );
636 
637 int		FS_FOpenFile( const char *filename, fileHandle_t *f, uint32 mode );
638 void	FS_FCloseFile( fileHandle_t hFile );
639 
640 int		FS_LoadFile( const char *path, void  **buffer );
641 int		FS_LoadFileEx( const char *path, void **buffer, uint32 flags );
642 void	FS_FreeFile( void *buffer );
643 void	FS_FlushCache( void );
644 // a null buffer will just return the file length without loading
645 // a -1 length is not present
646 
647 int		FS_Read( void *buffer, int len, fileHandle_t hFile );
648 int		FS_Write( const void *buffer, int len, fileHandle_t hFile );
649 // properly handles partial reads
650 
651 void	FS_FPrintf( fileHandle_t f, const char *format, ... );
652 
653 int		FS_Tell( fileHandle_t f );
654 int		FS_RawTell( fileHandle_t f );
655 
656 int		FS_GetFileLength( fileHandle_t f );
657 int		FS_GetFileLengthNoCache( fileHandle_t f );
658 
659 int		FS_WildCmp( const char *filter, const char *string );
660 
661 char	**FS_ListFiles( const char *path, const char *extension, uint32 flags, int *numFiles );
662 void	FS_FreeFileList( char **list );
663 
664 qboolean	FS_LastFileFromPak( void );
665 
666 void	FS_CreatePath( const char *path );
667 
668 const char *FS_GetFileName( fileHandle_t f );
669 const char *FS_GetFileFullPath( fileHandle_t f );
670 
671 char	*FS_Gamedir( void );
672 char	*FS_NextPath( char *prevpath );
673 
674 void FS_FillAPI( fsAPI_t *api );
675 
676 /*
677 ==============================================================
678 
679 MDFOUR
680 
681 ==============================================================
682 */
683 
684 struct mdfour {
685 	uint32 A, B, C, D;
686 	uint32 totalN;
687 };
688 
689 typedef struct mdfour mdfour_t;
690 
691 void mdfour_begin( struct mdfour *md );
692 void mdfour_update( struct mdfour *md, uint8 *in, int n );
693 void mdfour_result( struct mdfour *md, uint8 *out );
694 
695 uint32	Com_BlockChecksum( void *buffer, int length );
696 
697 /*
698 ==============================================================
699 
700 MISC
701 
702 ==============================================================
703 */
704 
705 void		Com_BeginRedirect (int target, char *buffer, int buffersize, void (*flush));
706 void		Com_EndRedirect (void);
707 
708 void		Com_LevelPrint( comPrintType_t type, const char *str );
709 void		Com_LevelError( comErrorType_t code, const char *str )
710     __attribute__(( noreturn ));
711 
712 void		Com_FillAPI( commonAPI_t *api );
713 
714 void 		Com_Quit (void);
715 
716 byte		COM_BlockSequenceCRCByte (byte *base, int length, int sequence);
717 
718 void		Com_ProcessEvents( void );
719 
720 const char *Com_FileNameGenerator( const char *path, const char *ext, const char *partial,
721 								  qboolean stripExtension, int state );
722 const char *Com_FileNameGeneratorByFilter( const char *path, const char *filter, const char *partial,
723 										  qboolean stripExtension, int state );
724 
725 /* may return pointer to static memory */
726 char    *Cvar_CopyString( const char *in );
727 
728 void	Z_Free( void *ptr );
729 void	*Z_TagMalloc( size_t size, memtag_t tag );
730 void    *Z_TagMallocz( size_t size, memtag_t tag );
731 char    *Z_TagCopyString( const char *in, memtag_t tag );
732 void	Z_FreeTags( memtag_t tag );
733 void	Z_LeakTest( memtag_t tag );
734 void	Z_Check( void );
735 
736 void    Z_TagReserve( size_t size, memtag_t tag );
737 void    *Z_ReservedAlloc( size_t size );
738 char    *Z_ReservedCopyString( const char *in );
739 
740 #define Z_Malloc( size )    Z_TagMalloc( size, TAG_GENERAL )
741 #define Z_Mallocz( size )    Z_TagMallocz( size, TAG_GENERAL )
742 #define Z_Reserve( size )   Z_TagReserve( size, TAG_GENERAL )
743 #define Z_CopyString( string )   Z_TagCopyString( string, TAG_GENERAL )
744 
745 extern	cvar_t	*developer;
746 extern	cvar_t	*dedicated;
747 extern	cvar_t	*host_speeds;
748 
749 extern	cvar_t	*mvd_running;
750 extern	cvar_t	*sv_running;
751 extern	cvar_t	*sv_paused;
752 extern	cvar_t	*cl_running;
753 extern	cvar_t	*cl_paused;
754 extern	cvar_t	*com_timedemo;
755 extern	cvar_t	*com_sleep;
756 
757 extern	FILE *log_stats_file;
758 
759 // host_speeds times
760 extern	int		time_before_game;
761 extern	int		time_after_game;
762 extern	int		time_before_ref;
763 extern	int		time_after_ref;
764 
765 extern uint32	com_eventTime; /* system time of the last event */
766 extern uint32	com_framenum;
767 
768 extern fileHandle_t	com_logFile;
769 
770 void Qcommon_Init( char *commandLine );
771 void Qcommon_Frame( void );
772 void Qcommon_Shutdown( qboolean fatalError );
773 
774 // this is in the client code, but can be used for debugging from server
775 void SCR_DebugGraph (float value, int color);
776 
777 // interface to zlib
778 void		Com_ZLibDeflateAbort( void );
779 qboolean	Com_ZLibDeflateStart( sizebuf_t *outputBuf );
780 qboolean	Com_ZLibDeflateChunk( sizebuf_t *inputBuf );
781 qboolean	Com_ZLibDeflateFinish( void );
782 qboolean	Com_ZLibDeflateBuffer( sizebuf_t *inputBuf, sizebuf_t *outputBuf );
783 qboolean	Com_ZLibInflateBuffer( sizebuf_t *inputBuf, sizebuf_t *outputBuf, int length );
784 
785 /*
786 ==============================================================
787 
788 NON-PORTABLE SYSTEM SERVICES
789 
790 ==============================================================
791 */
792 
793 // loads the dll and calls the api init function
794 void	*Sys_LoadGameLibrary( void *parms );
795 void	Sys_FreeGameLibrary( void );
796 void	Sys_FreeModule( void *handle );
797 moduleEntry_t	Sys_LoadModule( const char *name, void **handle );
798 
799 int		Sys_Milliseconds( void );
800 uint32	Sys_Realtime( void );
801 char	*Sys_GetClipboardData( void );
802 void	Sys_SetClipboardData( const char *data );
803 
804 void	Hunk_Begin( mempool_t *pool, int maxsize );
805 void	*Hunk_Alloc( mempool_t *pool, int size );
806 void	Hunk_Free( mempool_t *pool );
807 
808 void	Sys_Init( void );
809 void	Sys_FillAPI( sysAPI_t *api );
810 
811 char	*Sys_ConsoleInput( void );
812 void	Sys_ConsoleOutput( const char *string );
813 void	Sys_Error( const char *error, ... )
814     __attribute__(( noreturn, format ( printf, 1, 2 ) ));
815 void	Sys_Quit( void );
816 
817 char	**Sys_ListFiles( const char *path, const char *extension, uint32 flags, int *numFiles );
818 void	Sys_FreeFileList( char **list );
819 
820 void	Sys_Mkdir( const char *path );
821 qboolean Sys_RemoveFile( const char *path );
822 qboolean Sys_RenameFile( const char *from, const char *to );
823 qboolean Sys_GetFileInfo( const char *path, fsFileInfo_t *info );
824 
825 char	*Sys_GetCurrentDirectory( void );
826 void	Sys_Sleep( uint32 msec );
827 
828 void	Sys_DebugBreak( void );
829 
830 char	*Sys_NetErrorString( void );
831 
832 #ifdef USE_ANTICHEAT
833 qboolean Sys_GetAntiCheatAPI( void );
834 #endif
835 
836 /*
837 ==============================================================
838 
839 CLIENT / SERVER SYSTEMS
840 
841 ==============================================================
842 */
843 
844 extern cvar_t	*info_password;
845 extern cvar_t	*info_spectator;
846 extern cvar_t	*info_name;
847 extern cvar_t	*info_skin;
848 extern cvar_t	*info_rate;
849 extern cvar_t	*info_fov;
850 extern cvar_t	*info_msg;
851 extern cvar_t	*info_hand;
852 extern cvar_t	*info_gender;
853 
854 extern	cvar_t *allow_download;
855 extern	cvar_t *allow_download_players;
856 extern	cvar_t *allow_download_models;
857 extern	cvar_t *allow_download_sounds;
858 extern	cvar_t *allow_download_maps;
859 extern	cvar_t *allow_download_demos;
860 extern	cvar_t *allow_download_other;
861 
862 void CL_PumpEvents( void );
863 void CL_PacketEvent( int ret );
864 void CL_MouseEvent( int dx, int dy );
865 void CL_Init (void);
866 void CL_Disconnect( comErrorType_t type, const char *text );
867 void CL_Shutdown (void);
868 void CL_Frame (int msec);
869 void Con_Print( const char *text );
870 void Con_Printf( const char *fmt, ... );
871 void Con_SetMaxHeight( float frac );
872 void SCR_BeginLoadingPlaque (void);
873 void CL_LocalConnect( void );
874 void CL_InputFrame( void );
875 void CL_AppActivate( qboolean active );
876 void CL_UpdateUserinfo( cvar_t *var, cvarSetSource_t source );
877 
878 void	Key_Init( void );
879 void	Key_Event( uint32 key, qboolean down, uint32 time );
880 void	Key_CharEvent( int key );
881 void	Key_WriteBindings( fileHandle_t f );
882 
883 typedef enum server_state_e {
884 	ss_dead,			// no map loaded
885 	ss_loading,			// spawning level edicts
886 	ss_game,			// actively running
887 	ss_broadcast,
888 	ss_cinematic,
889 	ss_demo,
890 	ss_pic
891 } server_state_t;
892 
893 typedef enum killtype_e {
894 	KILL_RESTART,
895 	KILL_DISCONNECT,
896 	KILL_DROP
897 } killtype_t;
898 
899 void SV_PacketEvent( int ret );
900 void SV_Init (void);
901 void SV_Shutdown( const char *finalmsg, killtype_t type );
902 void SV_Frame (int msec);
903 qboolean MVD_GetDemoPercent( int *percent, int *bufferPercent );
904 void MVD_PacketEvent( int ret );
905 
906 
907 
908