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 "../game/q_shared.h"
24 
25 
26 #define	VERSION		3.21
27 
28 #define	BASEDIRNAME	"baseq2"
29 
30 #ifdef WIN32
31 
32 #ifdef NDEBUG
33 #define BUILDSTRING "Win32 RELEASE"
34 #else
35 #define BUILDSTRING "Win32 DEBUG"
36 #endif
37 
38 #ifdef _M_IX86
39 #define	CPUSTRING	"x86"
40 #elif defined _M_ALPHA
41 #define	CPUSTRING	"AXP"
42 #endif
43 
44 #elif defined __linux__ || defined __DragonFly__
45 
46 #define BUILDSTRING "DragonFly"
47 
48 #ifdef __i386__
49 #define CPUSTRING "i386"
50 #elif defined __alpha__
51 #define CPUSTRING "axp"
52 #else
53 #define CPUSTRING "x86_64"
54 #endif
55 
56 #elif defined __sun__
57 
58 #define BUILDSTRING "Solaris"
59 
60 #ifdef __i386__
61 #define CPUSTRING "i386"
62 #else
63 #define CPUSTRING "sparc"
64 #endif
65 
66 #else	// !WIN32
67 
68 #define BUILDSTRING "NON-WIN32"
69 #define	CPUSTRING	"NON-WIN32"
70 
71 #endif
72 
73 //============================================================================
74 
75 typedef struct sizebuf_s
76 {
77 	qboolean	allowoverflow;	// if false, do a Com_Error
78 	qboolean	overflowed;		// set to true if the buffer size failed
79 	byte	*data;
80 	int		maxsize;
81 	int		cursize;
82 	int		readcount;
83 } sizebuf_t;
84 
85 void SZ_Init (sizebuf_t *buf, byte *data, int length);
86 void SZ_Clear (sizebuf_t *buf);
87 void *SZ_GetSpace (sizebuf_t *buf, int length);
88 void SZ_Write (sizebuf_t *buf, void *data, int length);
89 void SZ_Print (sizebuf_t *buf, char *data);	// strcats onto the sizebuf
90 
91 //============================================================================
92 
93 struct usercmd_s;
94 struct entity_state_s;
95 
96 void MSG_WriteChar (sizebuf_t *sb, int c);
97 void MSG_WriteByte (sizebuf_t *sb, int c);
98 void MSG_WriteShort (sizebuf_t *sb, int c);
99 void MSG_WriteLong (sizebuf_t *sb, int c);
100 void MSG_WriteFloat (sizebuf_t *sb, float f);
101 void MSG_WriteString (sizebuf_t *sb, char *s);
102 void MSG_WriteCoord (sizebuf_t *sb, float f);
103 void MSG_WritePos (sizebuf_t *sb, vec3_t pos);
104 void MSG_WriteAngle (sizebuf_t *sb, float f);
105 void MSG_WriteAngle16 (sizebuf_t *sb, float f);
106 void MSG_WriteDeltaUsercmd (sizebuf_t *sb, struct usercmd_s *from, struct usercmd_s *cmd);
107 void MSG_WriteDeltaEntity (struct entity_state_s *from, struct entity_state_s *to, sizebuf_t *msg, qboolean force, qboolean newentity);
108 void MSG_WriteDir (sizebuf_t *sb, vec3_t vector);
109 
110 
111 void	MSG_BeginReading (sizebuf_t *sb);
112 
113 int		MSG_ReadChar (sizebuf_t *sb);
114 int		MSG_ReadByte (sizebuf_t *sb);
115 int		MSG_ReadShort (sizebuf_t *sb);
116 int		MSG_ReadLong (sizebuf_t *sb);
117 float	MSG_ReadFloat (sizebuf_t *sb);
118 char	*MSG_ReadString (sizebuf_t *sb);
119 char	*MSG_ReadStringLine (sizebuf_t *sb);
120 
121 float	MSG_ReadCoord (sizebuf_t *sb);
122 void	MSG_ReadPos (sizebuf_t *sb, vec3_t pos);
123 float	MSG_ReadAngle (sizebuf_t *sb);
124 float	MSG_ReadAngle16 (sizebuf_t *sb);
125 void	MSG_ReadDeltaUsercmd (sizebuf_t *sb, struct usercmd_s *from, struct usercmd_s *cmd);
126 
127 void	MSG_ReadDir (sizebuf_t *sb, vec3_t vector);
128 
129 void	MSG_ReadData (sizebuf_t *sb, void *buffer, int size);
130 
131 //============================================================================
132 
133 extern	qboolean		bigendien;
134 
135 extern	short	BigShort (short l);
136 extern	short	LittleShort (short l);
137 extern	int		BigLong (int l);
138 extern	int		LittleLong (int l);
139 extern	float	BigFloat (float l);
140 extern	float	LittleFloat (float l);
141 
142 //============================================================================
143 
144 
145 int	COM_Argc (void);
146 char *COM_Argv (int arg);	// range and null checked
147 void COM_ClearArgv (int arg);
148 int COM_CheckParm (char *parm);
149 void COM_AddParm (char *parm);
150 
151 void COM_Init (void);
152 void COM_InitArgv (int argc, char **argv);
153 
154 char *CopyString (char *in);
155 
156 //============================================================================
157 
158 void Info_Print (char *s);
159 
160 
161 /* crc.h */
162 
163 void CRC_Init(unsigned short *crcvalue);
164 void CRC_ProcessByte(unsigned short *crcvalue, byte data);
165 unsigned short CRC_Value(unsigned short crcvalue);
166 unsigned short CRC_Block (byte *start, int count);
167 
168 
169 
170 /*
171 ==============================================================
172 
173 PROTOCOL
174 
175 ==============================================================
176 */
177 
178 // protocol.h -- communications protocols
179 
180 #define	PROTOCOL_VERSION	34
181 
182 //=========================================
183 
184 #define	PORT_MASTER	27900
185 #define	PORT_CLIENT	27901
186 #define	PORT_SERVER	27910
187 
188 //=========================================
189 
190 #define	UPDATE_BACKUP	16	// copies of entity_state_t to keep buffered
191 							// must be power of two
192 #define	UPDATE_MASK		(UPDATE_BACKUP-1)
193 
194 
195 
196 //==================
197 // the svc_strings[] array in cl_parse.c should mirror this
198 //==================
199 
200 //
201 // server to client
202 //
203 enum svc_ops_e
204 {
205 	svc_bad,
206 
207 	// these ops are known to the game dll
208 	svc_muzzleflash,
209 	svc_muzzleflash2,
210 	svc_temp_entity,
211 	svc_layout,
212 	svc_inventory,
213 
214 	// the rest are private to the client and server
215 	svc_nop,
216 	svc_disconnect,
217 	svc_reconnect,
218 	svc_sound,					// <see code>
219 	svc_print,					// [byte] id [string] null terminated string
220 	svc_stufftext,				// [string] stuffed into client's console buffer, should be \n terminated
221 	svc_serverdata,				// [long] protocol ...
222 	svc_configstring,			// [short] [string]
223 	svc_spawnbaseline,
224 	svc_centerprint,			// [string] to put in center of the screen
225 	svc_download,				// [short] size [size bytes]
226 	svc_playerinfo,				// variable
227 	svc_packetentities,			// [...]
228 	svc_deltapacketentities,	// [...]
229 	svc_frame
230 };
231 
232 //==============================================
233 
234 //
235 // client to server
236 //
237 enum clc_ops_e
238 {
239 	clc_bad,
240 	clc_nop,
241 	clc_move,				// [[usercmd_t]
242 	clc_userinfo,			// [[userinfo string]
243 	clc_stringcmd			// [string] message
244 };
245 
246 //==============================================
247 
248 // plyer_state_t communication
249 
250 #define	PS_M_TYPE			(1<<0)
251 #define	PS_M_ORIGIN			(1<<1)
252 #define	PS_M_VELOCITY		(1<<2)
253 #define	PS_M_TIME			(1<<3)
254 #define	PS_M_FLAGS			(1<<4)
255 #define	PS_M_GRAVITY		(1<<5)
256 #define	PS_M_DELTA_ANGLES	(1<<6)
257 
258 #define	PS_VIEWOFFSET		(1<<7)
259 #define	PS_VIEWANGLES		(1<<8)
260 #define	PS_KICKANGLES		(1<<9)
261 #define	PS_BLEND			(1<<10)
262 #define	PS_FOV				(1<<11)
263 #define	PS_WEAPONINDEX		(1<<12)
264 #define	PS_WEAPONFRAME		(1<<13)
265 #define	PS_RDFLAGS			(1<<14)
266 
267 //==============================================
268 
269 // user_cmd_t communication
270 
271 // ms and light always sent, the others are optional
272 #define	CM_ANGLE1 	(1<<0)
273 #define	CM_ANGLE2 	(1<<1)
274 #define	CM_ANGLE3 	(1<<2)
275 #define	CM_FORWARD	(1<<3)
276 #define	CM_SIDE		(1<<4)
277 #define	CM_UP		(1<<5)
278 #define	CM_BUTTONS	(1<<6)
279 #define	CM_IMPULSE	(1<<7)
280 
281 //==============================================
282 
283 // a sound without an ent or pos will be a local only sound
284 #define	SND_VOLUME		(1<<0)		// a byte
285 #define	SND_ATTENUATION	(1<<1)		// a byte
286 #define	SND_POS			(1<<2)		// three coordinates
287 #define	SND_ENT			(1<<3)		// a short 0-2: channel, 3-12: entity
288 #define	SND_OFFSET		(1<<4)		// a byte, msec offset from frame start
289 
290 #define DEFAULT_SOUND_PACKET_VOLUME	1.0
291 #define DEFAULT_SOUND_PACKET_ATTENUATION 1.0
292 
293 //==============================================
294 
295 // entity_state_t communication
296 
297 // try to pack the common update flags into the first byte
298 #define	U_ORIGIN1	(1<<0)
299 #define	U_ORIGIN2	(1<<1)
300 #define	U_ANGLE2	(1<<2)
301 #define	U_ANGLE3	(1<<3)
302 #define	U_FRAME8	(1<<4)		// frame is a byte
303 #define	U_EVENT		(1<<5)
304 #define	U_REMOVE	(1<<6)		// REMOVE this entity, don't add it
305 #define	U_MOREBITS1	(1<<7)		// read one additional byte
306 
307 // second byte
308 #define	U_NUMBER16	(1<<8)		// NUMBER8 is implicit if not set
309 #define	U_ORIGIN3	(1<<9)
310 #define	U_ANGLE1	(1<<10)
311 #define	U_MODEL		(1<<11)
312 #define U_RENDERFX8	(1<<12)		// fullbright, etc
313 #define	U_EFFECTS8	(1<<14)		// autorotate, trails, etc
314 #define	U_MOREBITS2	(1<<15)		// read one additional byte
315 
316 // third byte
317 #define	U_SKIN8		(1<<16)
318 #define	U_FRAME16	(1<<17)		// frame is a short
319 #define	U_RENDERFX16 (1<<18)	// 8 + 16 = 32
320 #define	U_EFFECTS16	(1<<19)		// 8 + 16 = 32
321 #define	U_MODEL2	(1<<20)		// weapons, flags, etc
322 #define	U_MODEL3	(1<<21)
323 #define	U_MODEL4	(1<<22)
324 #define	U_MOREBITS3	(1<<23)		// read one additional byte
325 
326 // fourth byte
327 #define	U_OLDORIGIN	(1<<24)		// FIXME: get rid of this
328 #define	U_SKIN16	(1<<25)
329 #define	U_SOUND		(1<<26)
330 #define	U_SOLID		(1<<27)
331 
332 
333 /*
334 ==============================================================
335 
336 CMD
337 
338 Command text buffering and command execution
339 
340 ==============================================================
341 */
342 
343 /*
344 
345 Any number of commands can be added in a frame, from several different sources.
346 Most commands come from either keybindings or console line input, but remote
347 servers can also send across commands and entire text files can be execed.
348 
349 The + command line options are also added to the command buffer.
350 
351 The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute ();
352 
353 */
354 
355 #define	EXEC_NOW	0		// don't return until completed
356 #define	EXEC_INSERT	1		// insert at current position, but don't run yet
357 #define	EXEC_APPEND	2		// add to end of the command buffer
358 
359 void Cbuf_Init (void);
360 // allocates an initial text buffer that will grow as needed
361 
362 void Cbuf_AddText (char *text);
363 // as new commands are generated from the console or keybindings,
364 // the text is added to the end of the command buffer.
365 
366 void Cbuf_InsertText (char *text);
367 // when a command wants to issue other commands immediately, the text is
368 // inserted at the beginning of the buffer, before any remaining unexecuted
369 // commands.
370 
371 void Cbuf_ExecuteText (int exec_when, char *text);
372 // this can be used in place of either Cbuf_AddText or Cbuf_InsertText
373 
374 void Cbuf_AddEarlyCommands (qboolean clear);
375 // adds all the +set commands from the command line
376 
377 qboolean Cbuf_AddLateCommands (void);
378 // adds all the remaining + commands from the command line
379 // Returns true if any late commands were added, which
380 // will keep the demoloop from immediately starting
381 
382 void Cbuf_Execute (void);
383 // Pulls off \n terminated lines of text from the command buffer and sends
384 // them through Cmd_ExecuteString.  Stops when the buffer is empty.
385 // Normally called once per frame, but may be explicitly invoked.
386 // Do not call inside a command function!
387 
388 void Cbuf_CopyToDefer (void);
389 void Cbuf_InsertFromDefer (void);
390 // These two functions are used to defer any pending commands while a map
391 // is being loaded
392 
393 //===========================================================================
394 
395 /*
396 
397 Command execution takes a null terminated string, breaks it into tokens,
398 then searches for a command or variable that matches the first token.
399 
400 */
401 
402 typedef void (*xcommand_t) (void);
403 
404 void	Cmd_Init (void);
405 
406 void	Cmd_AddCommand (char *cmd_name, xcommand_t function);
407 // called by the init functions of other parts of the program to
408 // register commands and functions to call for them.
409 // The cmd_name is referenced later, so it should not be in temp memory
410 // if function is NULL, the command will be forwarded to the server
411 // as a clc_stringcmd instead of executed locally
412 void	Cmd_RemoveCommand (char *cmd_name);
413 
414 qboolean Cmd_Exists (char *cmd_name);
415 // used by the cvar code to check for cvar / command name overlap
416 
417 char 	*Cmd_CompleteCommand (char *partial);
418 // attempts to match a partial command for automatic command line completion
419 // returns NULL if nothing fits
420 
421 int		Cmd_Argc (void);
422 char	*Cmd_Argv (int arg);
423 char	*Cmd_Args (void);
424 // The functions that execute commands get their parameters with these
425 // functions. Cmd_Argv () will return an empty string, not a NULL
426 // if arg > argc, so string operations are always safe.
427 
428 void	Cmd_TokenizeString (char *text, qboolean macroExpand);
429 // Takes a null terminated string.  Does not need to be /n terminated.
430 // breaks the string up into arg tokens.
431 
432 void	Cmd_ExecuteString (char *text);
433 // Parses a single line of text into arguments and tries to execute it
434 // as if it was typed at the console
435 
436 void	Cmd_ForwardToServer (void);
437 // adds the current command line as a clc_stringcmd to the client message.
438 // things like godmode, noclip, etc, are commands directed to the server,
439 // so when they are typed in at the console, they will need to be forwarded.
440 
441 
442 /*
443 ==============================================================
444 
445 CVAR
446 
447 ==============================================================
448 */
449 
450 /*
451 
452 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
453 in C code.
454 
455 The user can access cvars from the console in three ways:
456 r_draworder			prints the current value
457 r_draworder 0		sets the current value to 0
458 set r_draworder 0	as above, but creates the cvar if not present
459 Cvars are restricted from having the same names as commands to keep this
460 interface from being ambiguous.
461 */
462 
463 extern	cvar_t	*cvar_vars;
464 
465 cvar_t *Cvar_Get (char *var_name, char *value, int flags);
466 // creates the variable if it doesn't exist, or returns the existing one
467 // if it exists, the value will not be changed, but flags will be ORed in
468 // that allows variables to be unarchived without needing bitflags
469 
470 cvar_t 	*Cvar_Set (char *var_name, char *value);
471 // will create the variable if it doesn't exist
472 
473 cvar_t *Cvar_ForceSet (char *var_name, char *value);
474 // will set the variable even if NOSET or LATCH
475 
476 cvar_t 	*Cvar_FullSet (char *var_name, char *value, int flags);
477 
478 void	Cvar_SetValue (char *var_name, float value);
479 // expands value to a string and calls Cvar_Set
480 
481 float	Cvar_VariableValue (char *var_name);
482 // returns 0 if not defined or non numeric
483 
484 char	*Cvar_VariableString (char *var_name);
485 // returns an empty string if not defined
486 
487 char 	*Cvar_CompleteVariable (char *partial);
488 // attempts to match a partial variable name for command line completion
489 // returns NULL if nothing fits
490 
491 void	Cvar_GetLatchedVars (void);
492 // any CVAR_LATCHED variables that have been set will now take effect
493 
494 qboolean Cvar_Command (void);
495 // called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
496 // command.  Returns true if the command was a variable reference that
497 // was handled. (print or change)
498 
499 void 	Cvar_WriteVariables (char *path);
500 // appends lines containing "set variable value" for all variables
501 // with the archive flag set to true.
502 
503 void	Cvar_Init (void);
504 
505 char	*Cvar_Userinfo (void);
506 // returns an info string containing all the CVAR_USERINFO cvars
507 
508 char	*Cvar_Serverinfo (void);
509 // returns an info string containing all the CVAR_SERVERINFO cvars
510 
511 extern	qboolean	userinfo_modified;
512 // this is set each time a CVAR_USERINFO variable is changed
513 // so that the client knows to send it to the server
514 
515 /*
516 ==============================================================
517 
518 NET
519 
520 ==============================================================
521 */
522 
523 // net.h -- quake's interface to the networking layer
524 
525 #define	PORT_ANY	-1
526 
527 #define	MAX_MSGLEN		1400		// max length of a message
528 #define	PACKET_HEADER	10			// two ints and a short
529 
530 #ifdef HAVE_IPV6
531 typedef enum {NA_LOOPBACK, NA_BROADCAST, NA_IP, NA_IPX, NA_BROADCAST_IPX, NA_IP6, NA_MULTICAST6} netadrtype_t;
532 #else
533 typedef enum {NA_LOOPBACK, NA_BROADCAST, NA_IP, NA_IPX, NA_BROADCAST_IPX} netadrtype_t;
534 #endif
535 
536 typedef enum {NS_CLIENT, NS_SERVER} netsrc_t;
537 
538 typedef struct
539 {
540 	netadrtype_t	type;
541 #ifdef HAVE_IPV6
542         /* TODO. Use sockaddr_storage instead. */
543         byte	ip[16];
544         unsigned int scope_id;
545 #else
546 	byte	ip[4];
547 #endif
548 	byte	ipx[10];
549 
550 	unsigned short	port;
551 } netadr_t;
552 
553 void		NET_Init (void);
554 void		NET_Shutdown (void);
555 
556 void		NET_Config (qboolean multiplayer);
557 
558 qboolean	NET_GetPacket (netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message);
559 void		NET_SendPacket (netsrc_t sock, int length, void *data, netadr_t to);
560 
561 qboolean	NET_CompareAdr (netadr_t a, netadr_t b);
562 qboolean	NET_CompareBaseAdr (netadr_t a, netadr_t b);
563 qboolean	NET_IsLocalAddress (netadr_t adr);
564 char		*NET_AdrToString (netadr_t a);
565 qboolean	NET_StringToAdr (char *s, netadr_t *a);
566 void		NET_Sleep(int msec);
567 
568 //============================================================================
569 
570 #define	OLD_AVG		0.99		// total = oldtotal*OLD_AVG + new*(1-OLD_AVG)
571 
572 #define	MAX_LATENT	32
573 
574 typedef struct
575 {
576 	qboolean	fatal_error;
577 
578 	netsrc_t	sock;
579 
580 	int			dropped;			// between last packet and previous
581 
582 	int			last_received;		// for timeouts
583 	int			last_sent;			// for retransmits
584 
585 	netadr_t	remote_address;
586 	int			qport;				// qport value to write when transmitting
587 
588 // sequencing variables
589 	int			incoming_sequence;
590 	int			incoming_acknowledged;
591 	int			incoming_reliable_acknowledged;	// single bit
592 
593 	int			incoming_reliable_sequence;		// single bit, maintained local
594 
595 	int			outgoing_sequence;
596 	int			reliable_sequence;			// single bit
597 	int			last_reliable_sequence;		// sequence number of last send
598 
599 // reliable staging and holding areas
600 	sizebuf_t	message;		// writing buffer to send to server
601 	byte		message_buf[MAX_MSGLEN-16];		// leave space for header
602 
603 // message is copied to this buffer when it is first transfered
604 	int			reliable_length;
605 	byte		reliable_buf[MAX_MSGLEN-16];	// unacked reliable message
606 } netchan_t;
607 
608 extern	netadr_t	net_from;
609 extern	sizebuf_t	net_message;
610 extern	byte		net_message_buffer[MAX_MSGLEN];
611 
612 
613 void Netchan_Init (void);
614 void Netchan_Setup (netsrc_t sock, netchan_t *chan, netadr_t adr, int qport);
615 
616 qboolean Netchan_NeedReliable (netchan_t *chan);
617 void Netchan_Transmit (netchan_t *chan, int length, byte *data);
618 void Netchan_OutOfBand (int net_socket, netadr_t adr, int length, byte *data);
619 void Netchan_OutOfBandPrint (int net_socket, netadr_t adr, char *format, ...);
620 qboolean Netchan_Process (netchan_t *chan, sizebuf_t *msg);
621 
622 qboolean Netchan_CanReliable (netchan_t *chan);
623 
624 
625 /*
626 ==============================================================
627 
628 CMODEL
629 
630 ==============================================================
631 */
632 
633 
634 #include "../qcommon/qfiles.h"
635 
636 cmodel_t	*CM_LoadMap (char *name, qboolean clientload, unsigned *checksum);
637 cmodel_t	*CM_InlineModel (char *name);	// *1, *2, etc
638 
639 int			CM_NumClusters (void);
640 int			CM_NumInlineModels (void);
641 char		*CM_EntityString (void);
642 
643 // creates a clipping hull for an arbitrary box
644 int			CM_HeadnodeForBox (vec3_t mins, vec3_t maxs);
645 
646 
647 // returns an ORed contents mask
648 int			CM_PointContents (vec3_t p, int headnode);
649 int			CM_TransformedPointContents (vec3_t p, int headnode, vec3_t origin, vec3_t angles);
650 
651 trace_t		CM_BoxTrace (vec3_t start, vec3_t end,
652 						  vec3_t mins, vec3_t maxs,
653 						  int headnode, int brushmask);
654 trace_t		CM_TransformedBoxTrace (vec3_t start, vec3_t end,
655 						  vec3_t mins, vec3_t maxs,
656 						  int headnode, int brushmask,
657 						  vec3_t origin, vec3_t angles);
658 
659 byte		*CM_ClusterPVS (int cluster);
660 byte		*CM_ClusterPHS (int cluster);
661 
662 int			CM_PointLeafnum (vec3_t p);
663 
664 // call with topnode set to the headnode, returns with topnode
665 // set to the first node that splits the box
666 int			CM_BoxLeafnums (vec3_t mins, vec3_t maxs, int *list,
667 							int listsize, int *topnode);
668 
669 int			CM_LeafContents (int leafnum);
670 int			CM_LeafCluster (int leafnum);
671 int			CM_LeafArea (int leafnum);
672 
673 void		CM_SetAreaPortalState (int portalnum, qboolean open);
674 qboolean	CM_AreasConnected (int area1, int area2);
675 
676 int			CM_WriteAreaBits (byte *buffer, int area);
677 qboolean	CM_HeadnodeVisible (int headnode, byte *visbits);
678 
679 void		CM_WritePortalState (FILE *f);
680 void		CM_ReadPortalState (FILE *f);
681 
682 /*
683 ==============================================================
684 
685 PLAYER MOVEMENT CODE
686 
687 Common between server and client so prediction matches
688 
689 ==============================================================
690 */
691 
692 extern float pm_airaccelerate;
693 
694 void Pmove (pmove_t *pmove);
695 
696 /*
697 ==============================================================
698 
699 FILESYSTEM
700 
701 ==============================================================
702 */
703 
704 void	FS_InitFilesystem (void);
705 void	FS_SetGamedir (char *dir);
706 char	*FS_Gamedir (void);
707 char	*FS_NextPath (char *prevpath);
708 void	FS_ExecAutoexec (void);
709 
710 int		FS_FOpenFile (char *filename, FILE **file);
711 void	FS_FCloseFile (FILE *f);
712 // note: this can't be called from another DLL, due to MS libc issues
713 
714 int		FS_LoadFile (char *path, void **buffer);
715 // a null buffer will just return the file length without loading
716 // a -1 length is not present
717 
718 void	FS_Read (void *buffer, int len, FILE *f);
719 // properly handles partial reads
720 
721 void	FS_FreeFile (void *buffer);
722 
723 void	FS_CreatePath (char *path);
724 
725 
726 /*
727 ==============================================================
728 
729 MISC
730 
731 ==============================================================
732 */
733 
734 
735 #define	ERR_FATAL	0		// exit the entire game with a popup window
736 #define	ERR_DROP	1		// print to console and disconnect from game
737 #define	ERR_QUIT	2		// not an error, just a normal exit
738 
739 #define	EXEC_NOW	0		// don't return until completed
740 #define	EXEC_INSERT	1		// insert at current position, but don't run yet
741 #define	EXEC_APPEND	2		// add to end of the command buffer
742 
743 #define	PRINT_ALL		0
744 #define PRINT_DEVELOPER	1	// only print when "developer 1"
745 
746 void		Com_BeginRedirect (int target, char *buffer, int buffersize, void (*flush));
747 void		Com_EndRedirect (void);
748 void 		Com_Printf (char *fmt, ...);
749 void 		Com_DPrintf (char *fmt, ...);
750 void		Com_MDPrintf (char *fmt, ...);
751 void 		Com_Error (int code, char *fmt, ...);
752 void 		Com_Quit (void);
753 
754 int			Com_ServerState (void);		// this should have just been a cvar...
755 void		Com_SetServerState (int state);
756 
757 unsigned	Com_BlockChecksum (void *buffer, int length);
758 byte		COM_BlockSequenceCRCByte (byte *base, int length, int sequence);
759 
760 float	frand(void);	// 0 ti 1
761 float	crand(void);	// -1 to 1
762 
763 extern	cvar_t	*developer;
764 extern	cvar_t	*modder;
765 extern	cvar_t	*dedicated;
766 extern	cvar_t	*host_speeds;
767 extern	cvar_t	*log_stats;
768 
769 extern	FILE *log_stats_file;
770 
771 // host_speeds times
772 extern	int		time_before_game;
773 extern	int		time_after_game;
774 extern	int		time_before_ref;
775 extern	int		time_after_ref;
776 
777 void Z_Free (void *ptr);
778 void *Z_Malloc (int size);			// returns 0 filled memory
779 void *Z_TagMalloc (int size, int tag);
780 void Z_FreeTags (int tag);
781 
782 void Qcommon_Init (int argc, char **argv);
783 void Qcommon_Frame (int msec);
784 void Qcommon_Shutdown (void);
785 
786 #define NUMVERTEXNORMALS	162
787 extern	vec3_t	bytedirs[NUMVERTEXNORMALS];
788 
789 // this is in the client code, but can be used for debugging from server
790 void SCR_DebugGraph (float value, int color);
791 
792 
793 /*
794 ==============================================================
795 
796 NON-PORTABLE SYSTEM SERVICES
797 
798 ==============================================================
799 */
800 
801 void	Sys_Init (void);
802 
803 void	Sys_AppActivate (void);
804 
805 void	Sys_UnloadGame (void);
806 void	*Sys_GetGameAPI (void *parms);
807 // loads the game dll and calls the api init function
808 
809 char	*Sys_ConsoleInput (void);
810 void	Sys_ConsoleOutput (char *string);
811 void	Sys_SendKeyEvents (void);
812 void	Sys_Error (char *error, ...);
813 void	Sys_Quit (void);
814 char	*Sys_GetClipboardData( void );
815 void	Sys_CopyProtect (void);
816 
817 /*
818 ==============================================================
819 
820 CLIENT / SERVER SYSTEMS
821 
822 ==============================================================
823 */
824 
825 void CL_Init (void);
826 void CL_Drop (void);
827 void CL_Shutdown (void);
828 void CL_Frame (int msec);
829 void Con_Print (char *text);
830 void SCR_BeginLoadingPlaque (void);
831 
832 void SV_Init (void);
833 void SV_Shutdown (char *finalmsg, qboolean reconnect);
834 void SV_Frame (int msec);
835 
836 
837 
838