OpenMoHAA ..
Loading...
Searching...
No Matches
qcommon.h
1/*
2===========================================================================
3Copyright (C) 1999-2005 Id Software, Inc.
4
5This file is part of Quake III Arena source code.
6
7Quake III Arena source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12Quake III Arena source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with Quake III Arena source code; if not, write to the Free Software
19Foundation, 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 "cm_public.h"
27#include "alias.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33//#define PRE_RELEASE_DEMO
34
35//============================================================================
36
37//
38// msg.c
39//
40typedef struct msg_s {
41 qboolean allowoverflow; // if false, do a Com_Error
42 qboolean overflowed; // set to true if the buffer size failed (with allowoverflow set)
43 qboolean oob; // set to true if the buffer size failed (with allowoverflow set)
44 byte *data;
45 size_t maxsize;
46 size_t cursize;
47 int readcount;
48 int bit; // for bitwise reads and writes
49} msg_t;
50
51void MSG_Init (msg_t *buf, byte *data, size_t length);
52void MSG_InitOOB( msg_t *buf, byte *data, size_t length );
53void MSG_Clear (msg_t *buf);
54void MSG_WriteData (msg_t *buf, const void *data, size_t length);
55void MSG_Bitstream(msg_t* buf);
56qboolean MSG_IsProtocolVersion15();
57
58// TTimo
59// copy a msg_t in case we need to store it as is for a bit
60// (as I needed this to keep an msg_t from a static var for later use)
61// sets data buffer as MSG_Init does prior to do the copy
62void MSG_Copy(msg_t *buf, byte *data, int length, msg_t *src);
63
64struct usercmd_s;
65struct entityState_s;
66struct playerState_s;
67
68void MSG_WriteBits( msg_t *msg, int value, int bits );
69
70void MSG_WriteChar (msg_t *sb, int c);
71void MSG_WriteByte (msg_t *sb, int c);
72void MSG_WriteShort (msg_t *sb, int c);
73
74void MSG_WriteSVC( msg_t *sb, int c );
75
76void MSG_WriteLong (msg_t *sb, int c);
77void MSG_WriteFloat (msg_t *sb, float f);
78void MSG_WriteString (msg_t *sb, const char *s);
79void MSG_WriteBigString (msg_t *sb, const char *s);
80void MSG_WriteScrambledString(msg_t* sb, const char* s);
81void MSG_WriteScrambledBigString(msg_t* sb, const char* s);
82void MSG_WriteAngle16 (msg_t *sb, float f);
83int MSG_HashKey(const char *string, int maxlen);
84void MSG_WriteEntityNum(msg_t* sb, short number);
85
86void MSG_BeginReading (msg_t *sb);
87void MSG_BeginReadingOOB(msg_t *sb);
88
89int MSG_ReadBits( msg_t *msg, int bits );
90
91int MSG_ReadChar (msg_t *sb);
92int MSG_ReadByte (msg_t *sb);
93int MSG_ReadSVC (msg_t *sb);
94int MSG_ReadShort (msg_t *sb);
95int MSG_ReadLong (msg_t *sb);
96
97void MSG_ReadDir( msg_t *msg, vec3_t dir );
98float MSG_ReadCoord( msg_t *msg );
99void MSG_GetNullEntityState(entityState_t *nullState);
100
101float MSG_ReadFloat (msg_t *sb);
102char *MSG_ReadString (msg_t *sb);
103char *MSG_ReadBigString (msg_t *sb);
104char *MSG_ReadStringLine( msg_t *sb );
105char* MSG_ReadScrambledString(msg_t* msg);
106char* MSG_ReadScrambledBigString(msg_t* msg);
107float MSG_ReadAngle8( msg_t *sb );
108float MSG_ReadAngle16 (msg_t *sb);
109void MSG_ReadData (msg_t *sb, void *buffer, int size);
110unsigned short MSG_ReadEntityNum(msg_t* sb);
111
112
113void MSG_WriteDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
114void MSG_ReadDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
115
116void MSG_WriteDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
117void MSG_ReadDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
118
119void MSG_WriteDeltaEntity( msg_t *msg, struct entityState_s *from, struct entityState_s *to
120 , qboolean force, float frameTime);
121
122void MSG_ReadSounds (msg_t *msg, server_sound_t *sounds, int *snapshot_number_of_sounds);
123void MSG_WriteSounds (msg_t *msg, server_sound_t *sounds, int snapshot_number_of_sounds);
124
125void MSG_ReadDeltaEyeInfo(msg_t *msg, usereyes_t *from, usereyes_t *to);
126
127void MSG_ReadDeltaEntity(msg_t* msg, entityState_t* from, entityState_t* to,
128 int number, float frameTime);
129
130void MSG_WriteDeltaEyeInfo (msg_t *msg, usereyes_t *from, usereyes_t *to);
131
132void MSG_WriteDeltaPlayerstate(msg_t* msg, struct playerState_s* from, struct playerState_s* to, float frameTime);
133void MSG_ReadDeltaPlayerstate(msg_t* msg, struct playerState_s* from, struct playerState_s* to, float frameTime);
134
135float MSG_ReadServerFrameTime(msg_t* msg, gameState_t* gameState);
136void MSG_WriteServerFrameTime(msg_t* msg, float value);
137
138void MSG_ReportChangeVectors_f( void );
139
140//====================
141// TA features
142//====================
143
144int MSG_PackAngle(float angle, int bits);
145int MSG_PackAnimTime(float time, int bits);
146int MSG_PackAnimWeight(float weight, int bits);
147int MSG_PackScale(float scale, int bits);
148int MSG_PackAlpha(float alpha, int bits);
149int MSG_PackCoord(float coord);
150int MSG_PackCoordExtra(float coord);
151qboolean MSG_DeltaNeeded(const void* fromField, const void* toField, int fieldType, int bits, int size);
152
153void MSG_WritePackedAngle(msg_t* msg, float value, int bits);
154void MSG_WritePackedAnimTime(msg_t* msg, float fromValue, float toValue, float frameTime, int bits);
155void MSG_WritePackedAnimWeight(msg_t* msg, float value, int bits);
156void MSG_WritePackedScale(msg_t* msg, float value, int bits);
157void MSG_WritePackedAlpha(msg_t* msg, float value, int bits);
158void MSG_WritePackedCoord(msg_t* msg, float fromValue, float toValue, int bits);
159void MSG_WritePackedCoordExtra(msg_t* msg, float fromValue, float toValue, int bits);
160void MSG_WritePackedVelocity(msg_t* msg, float value, int bits);
161void MSG_WritePackedSimple(msg_t* msg, int value, int bits);
162
163float MSG_UnpackAngle(int value, int bits);
164float MSG_UnpackAnimTime(int packed);
165float MSG_UnpackAnimWeight(int result, int bits);
166float MSG_UnpackScale(int packed);
167float MSG_UnpackAlpha(int packed, int bits);
168float MSG_UnpackCoord(int packed, int bits);
169float MSG_UnpackCoordExtra(int packed, int bits);
170
171//============================================================================
172
173/*
174==============================================================
175
176NET
177
178==============================================================
179*/
180
181#define NET_ENABLEV4 0x01
182#define NET_ENABLEV6 0x02
183// if this flag is set, always attempt ipv6 connections instead of ipv4 if a v6 address is found.
184#define NET_PRIOV6 0x04
185// disables ipv6 multicast support if set.
186#define NET_DISABLEMCAST 0x08
187
188#define PACKET_BACKUP 32 // number of old messages that must be kept on client and
189 // server for delta comrpession and ping estimation
190#define PACKET_MASK (PACKET_BACKUP-1)
191
192#define MAX_PACKET_USERCMDS 32 // max number of usercmd_t in a packet
193
194#define PORT_ANY -1
195
196#define MAX_RELIABLE_COMMANDS 512 // max string commands buffered for restransmit
197
198typedef enum {
199 NA_BAD, // an address lookup failed
200 NA_BOT,
201 NA_LOOPBACK,
202 NA_BROADCAST,
203 NA_IP,
204 NA_IPX,
205 NA_BROADCAST_IPX,
206 NA_IP6,
207 NA_MULTICAST6,
208 NA_UNSPEC
209} netadrtype_t;
210
211typedef enum {
212 //NS_MASTER,
213 NS_CLIENT,
214 NS_SERVER
215} netsrc_t;
216
217#define NET_ADDRSTRMAXLEN 48 // maximum length of an IPv6 address string including trailing '\0'
218typedef struct {
219 netadrtype_t type;
220
221 byte ip[4];
222 byte ip6[16];
223 byte ipx[10];
224
225 unsigned short port;
226 unsigned long scope_id; // Needed for IPv6 link-local addresses
227} netadr_t;
228
229void NET_Init( void );
230void NET_Shutdown( void );
231void NET_Restart_f( void );
232void NET_Config( qboolean enableNetworking );
233void NET_FlushPacketQueue(void);
234void NET_SendPacket (netsrc_t sock, size_t length, const void *data, netadr_t to);
235void QDECL NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...) Q_PRINTF_FUNC(3, 4);
236void QDECL NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len );
237
238qboolean NET_CompareAdr (netadr_t a, netadr_t b);
239qboolean NET_CompareBaseAdrMask(netadr_t a, netadr_t b, int netmask);
240qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b);
241qboolean NET_IsLocalAddress (netadr_t adr);
242const char *NET_AdrToString (netadr_t a);
243const char *NET_AdrToStringwPort (netadr_t a);
244int NET_StringToAdr ( const char *s, netadr_t *a, netadrtype_t family);
245qboolean NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_message);
246void NET_JoinMulticast6(void);
247void NET_LeaveMulticast6(void);
248void NET_Sleep(int msec);
249
250
251#define MAX_MSGLEN 49152 // max length of a message, which may
252 // be fragmented into multiple packets
253
254#define MAX_DOWNLOAD_WINDOW 48 // ACK window of 48 download chunks. Cannot set this higher, or clients
255 // will overflow the reliable commands buffer
256#define MAX_DOWNLOAD_BLKSIZE 1024 // 896 byte block chunks
257
258#define NETCHAN_GENCHECKSUM(challenge, sequence) ((challenge) ^ ((sequence) * (challenge)))
259
260
261/*
262Netchan handles packet fragmentation and out of order / duplicate suppression
263*/
264
265typedef struct {
266 netsrc_t sock;
267
268 int dropped; // between last packet and previous
269
270 netadr_t remoteAddress;
271 int qport; // qport value to write when transmitting
272
273 // sequencing variables
274 int incomingSequence;
275 int outgoingSequence;
276
277 // incoming fragment assembly buffer
278 int fragmentSequence;
279 int fragmentLength;
280 byte fragmentBuffer[MAX_MSGLEN];
281
282 // outgoing fragment buffer
283 // we need to space out the sending of large fragmented messages
284 qboolean unsentFragments;
285 size_t unsentFragmentStart;
286 size_t unsentLength;
287 byte unsentBuffer[MAX_MSGLEN];
288
289 int challenge;
290 int lastSentTime;
291 int lastSentSize;
292
293#ifdef LEGACY_PROTOCOL
294 qboolean compat;
295#endif
296} netchan_t;
297
298/*
299Packet profiling
300*/
301
302#define NETPROF_PACKET_FRAGMENTED 1
303#define NETPROF_PACKET_DROPPED 2
304#define NETPROF_PACKET_MESSAGE 4
305
306#define NETPROX_MAX_PACKETS 64
307
308typedef struct {
309 int updateTime;
310 int size;
311 int flags;
313
314typedef struct {
315 int updateTime;
316 int index;
317 netprofpacket_t packets[NETPROX_MAX_PACKETS];
318
319 // Timing
320 int lastCalcTime;
321 int lowestUpdateTime;
322 int highestUpdateTime;
323
324 // Accumulators
325 int totalPackets;
326 int totalSize;
327 int numFragmented;
328 int numDropped;
329 int numConnectionLess;
330 int totalBytesConnectionLess;
331
332 // Rates
333 int packetsPerSec;
334 int bytesPerSec;
335
336 // Percentages
337 int percentFragmented;
338 int percentDropped;
339 int percentConnectionLess;
340
341 float latency;
343
344typedef struct {
345 qboolean initialized;
346 int rate;
347 netprofpacketlist_t downstream;
348 netprofpacketlist_t upstream;
350
351void Netchan_Init( int qport );
352void Netchan_Setup(netsrc_t sock, netchan_t *chan, netadr_t adr, int qport, int challenge, qboolean compat);
353
354void Netchan_Transmit( netchan_t *chan, size_t length, const byte *data, netprofpacketlist_t *packetlist );
355void Netchan_TransmitNextFragment( netchan_t *chan, netprofpacketlist_t *packetlist );
356
357qboolean Netchan_Process( netchan_t *chan, msg_t *msg, netprofpacketlist_t *packetlist );
358
359void NetProfileAddPacket(netprofpacketlist_t* list, size_t size, int flags);
360void NetProfileSetPacketFlags(netprofpacketlist_t* list, int flags);
361void NetProfileCalcStats(netprofpacketlist_t* list, int time);
362
363/*
364==============================================================
365
366PROTOCOL
367
368==============================================================
369*/
370
371#define PROTOCOL_VERSION 17
372#define PROTOCOL_LEGACY_VERSION PROTOCOL_VERSION
373// su44: MoHAA v 1.00 uses protocol version 6
374
375// maintain a list of compatible protocols for demo playing
376// NOTE: that stuff only works with two digits protocols
377extern int demo_protocols[];
378
379// fixme : we need a new master server address
380
381#define UPDATE_SERVER_NAME "updatemoh.2015.com"
382// override on command line, config files etc.
383#ifndef MASTER_SERVER_NAME
384#define MASTER_SERVER_NAME "master.2015.com"
385#endif
386#ifndef AUTHORIZE_SERVER_NAME
387#define AUTHORIZE_SERVER_NAME "authorize.2015.com"
388#endif
389
390#define PORT_MASTER 27950
391#define PORT_UPDATE 27951
392#ifndef PORT_AUTHORIZE
393#define PORT_AUTHORIZE 27952
394#endif
395#define PORT_SERVER 12203
396#define NUM_SERVER_PORTS 4 // broadcast scan this many ports after
397 // PORT_SERVER so a single machine can
398 // run multiple servers
399
400
401// the svc_strings[] array in cl_parse.c should mirror this
402//
403// server to client
404//
405enum svc_ops_e {
406 svc_bad,
407 svc_nop,
408 svc_gamestate,
409 svc_configstring, // [short] [string] only in gamestate messages
410 svc_baseline, // only in gamestate messages
411 svc_serverCommand, // [string] to be executed by client game module
412 svc_download, // [short] size [size bytes]
413 svc_snapshot,
414 svc_centerprint,
415 svc_locprint,
416 svc_cgameMessage,
417 svc_EOF,
418
419// new commands, supported only by ioquake3 protocol but not legacy
420 svc_voipSpeex, // not wrapped in USE_VOIP, so this value is reserved.
421 svc_voipOpus, //
422};
423
424//
425// client to server
426//
427enum clc_ops_e {
428 clc_bad,
429 clc_nop,
430 clc_move, // [[usercmd_t]
431 clc_moveNoDelta, // [[usercmd_t]
432 clc_clientCommand, // [string] message
433 clc_EOF,
434
435// new commands, supported only by ioquake3 protocol but not legacy
436 clc_voipSpeex, // not wrapped in USE_VOIP, so this value is reserved.
437 clc_voipOpus, //
438};
439
440/*
441==============================================================
442
443VIRTUAL MACHINE
444
445==============================================================
446*/
447
448typedef struct vm_s vm_t;
449
450typedef enum {
451 VMI_NATIVE,
452 VMI_BYTECODE,
453 VMI_COMPILED
454} vmInterpret_t;
455
456typedef enum {
457 TRAP_MEMSET = 100,
458 TRAP_MEMCPY,
459 TRAP_STRNCPY,
460 TRAP_SIN,
461 TRAP_COS,
462 TRAP_ATAN2,
463 TRAP_SQRT,
464 TRAP_MATRIXMULTIPLY,
465 TRAP_ANGLEVECTORS,
466 TRAP_PERPENDICULARVECTOR,
467 TRAP_FLOOR,
468 TRAP_CEIL,
469
470 TRAP_TESTPRINTINT,
471 TRAP_TESTPRINTFLOAT
472} sharedTraps_t;
473
474typedef 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);
475
476void VM_Init( void );
477vm_t *VM_Create( const char *module, intptr_t (*systemCalls)(intptr_t *),
478 vmInterpret_t interpret );
479// module should be bare: "cgame", not "cgame.dll" or "vm/cgame.qvm"
480
481void VM_Free( vm_t *vm );
482void VM_Clear(void);
483void VM_Forced_Unload_Start(void);
484void VM_Forced_Unload_Done(void);
485vm_t *VM_Restart(vm_t *vm, qboolean unpure);
486
487intptr_t QDECL VM_Call( vm_t *vm, int callNum, ... );
488
489void VM_Debug( int level );
490
491void *VM_ArgPtr( intptr_t intValue );
492void *VM_ExplicitArgPtr( vm_t *vm, intptr_t intValue );
493
494#define VMA(x) VM_ArgPtr(args[x])
495static ID_INLINE float _vmf(intptr_t x)
496{
497 floatint_t fi;
498 fi.i = (int)x;
499 return fi.f;
500}
501#define VMF(x) _vmf(args[x])
502
503
504/*
505==============================================================
506
507CMD
508
509Command text buffering and command execution
510
511==============================================================
512*/
513
514/*
515
516Any number of commands can be added in a frame, from several different sources.
517Most commands come from either keybindings or console line input, but entire text
518files can be execed.
519
520*/
521
522void Cbuf_Init (void);
523// allocates an initial text buffer that will grow as needed
524
525void Cbuf_AddText( const char *text );
526// Adds command text at the end of the buffer, does NOT add a final \n
527
528void Cbuf_ExecuteText(int exec_when, const char *text );
529// this can be used in place of either Cbuf_AddText or Cbuf_InsertText
530
531void Cbuf_Execute (int msec);
532// Pulls off \n terminated lines of text from the command buffer and sends
533// them through Cmd_ExecuteString. Stops when the buffer is empty.
534// Normally called once per frame, but may be explicitly invoked.
535// Do not call inside a command function, or current args will be destroyed.
536
537void Cmd_WriteAliases( fileHandle_t f );
538
539//===========================================================================
540
541/*
542
543Command execution takes a null terminated string, breaks it into tokens,
544then searches for a command or variable that matches the first token.
545
546*/
547
548typedef void (*xcommand_t) (void);
549
550void Cmd_Init (void);
551
552void Cmd_AddCommand( const char *cmd_name, xcommand_t function );
553// called by the init functions of other parts of the program to
554// register commands and functions to call for them.
555// The cmd_name is referenced later, so it should not be in temp memory
556// if function is NULL, the command will be forwarded to the server
557// as a clc_clientCommand instead of executed locally
558
559void Cmd_RemoveCommand( const char *cmd_name );
560
561typedef void (*completionFunc_t)( const char *args, int argNum );
562
563// don't allow VMs to remove system commands
564void Cmd_RemoveCommandSafe( const char *cmd_name );
565
566void Cmd_CommandCompletion( void(*callback)(const char *s) );
567// callback with each valid string
568void Cmd_SetCommandCompletionFunc( const char *command,
569 completionFunc_t complete );
570void Cmd_CompleteArgument( const char *command, char *args, int argNum );
571void Cmd_CompleteCfgName( const char *args, int argNum );
572void Cmd_CommandCompletion( void(*callback)(const char *s) );
573const char* Cmd_CompleteCommandByNumber(const char* partial, int number);
574// callback with each valid string
575
576int Cmd_Argc (void);
577char *Cmd_Argv (int arg);
578void Cmd_ArgvBuffer( int arg, char *buffer, int bufferLength );
579char *Cmd_Args (void);
580char *Cmd_ArgsFrom( int arg );
581void Cmd_ArgsBuffer( char *buffer, int bufferLength );
582char *Cmd_Cmd (void);
583void Cmd_Args_Sanitize( void );
584// The functions that execute commands get their parameters with these
585// functions. Cmd_Argv () will return an empty string, not a NULL
586// if arg > argc, so string operations are allways safe.
587
588void Cmd_TokenizeString( const char *text );
589void Cmd_TokenizeStringIgnoreQuotes( const char *text_in );
590// Takes a null terminated string. Does not need to be /n terminated.
591// breaks the string up into arg tokens.
592
593void Cmd_ExecuteString( const char *text );
594// Parses a single line of text into arguments and tries to execute it
595// as if it was typed at the console
596
597
598/*
599==============================================================
600
601CVAR
602
603==============================================================
604*/
605
606/*
607
608cvar_t variables are used to hold scalar or string variables that can be changed
609or displayed at the console or prog code as well as accessed directly
610in C code.
611
612The user can access cvars from the console in three ways:
613r_draworder prints the current value
614r_draworder 0 sets the current value to 0
615set r_draworder 0 as above, but creates the cvar if not present
616
617Cvars are restricted from having the same names as commands to keep this
618interface from being ambiguous.
619
620The are also occasionally used to communicated information between different
621modules of the program.
622
623*/
624
625// sets the default value of a variable
626void Cvar_SetDefault( cvar_t *var, const char *var_value );
627
628cvar_t *Cvar_Get( const char *var_name, const char *value, int flags );
629// creates the variable if it doesn't exist, or returns the existing one
630// if it exists, the value will not be changed, but flags will be ORed in
631// that allows variables to be unarchived without needing bitflags
632// if value is "", the value will not override a previously set value.
633
634void Cvar_Register( vmCvar_t *vmCvar, const char *varName, const char *defaultValue, int flags );
635// basically a slightly modified Cvar_Get for the interpreted modules
636
637void Cvar_Update( vmCvar_t *vmCvar );
638// updates an interpreted modules' version of a cvar
639
640void Cvar_Set( const char *var_name, const char *value );
641// will create the variable with no flags if it doesn't exist
642
643cvar_t *Cvar_Set2( const char *var_name, const char *value, qboolean force );
644// will create the variable with no flags if it doesn't exist
645// can force
646
647cvar_t *Cvar_Next( cvar_t *var );
648// gets the next var
649
650void Cvar_SetLatched( const char *var_name, const char *value);
651// don't set the cvar immediately
652
653void Cvar_SetValue( const char *var_name, float value );
654// expands value to a string and calls Cvar_Set
655
656cvar_t *Cvar_FindVar( const char *var_name );
657float Cvar_VariableValue( const char *var_name );
658int Cvar_VariableIntegerValue(const char* var_name);
659float Cvar_VariableFloatValue(const char* var_name);
660// returns 0 if not defined or non numeric
661
662char *Cvar_VariableString( const char *var_name );
663void Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize );
664
665// find a compelte variable
666const char *Cvar_CompleteVariable( const char *partial );
667const char *Cvar_CompleteVariableByNumber( const char *partial, int number );
668// returns an empty string if not defined
669
670int Cvar_Flags(const char *var_name);
671// returns CVAR_NONEXISTENT if cvar doesn't exist or the flags of that particular CVAR.
672
673void Cvar_CommandCompletion( void(*callback)(const char *s) );
674// callback with each valid string
675
676void Cvar_Reset( const char *var_name );
677void Cvar_ForceReset(const char *var_name);
678
679void Cvar_SetCheatState( void );
680// reset all testing vars to a safe value
681
682qboolean Cvar_Command( void );
683// called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
684// command. Returns true if the command was a variable reference that
685// was handled. (print or change)
686
687void Cvar_WriteVariables( fileHandle_t f );
688// writes lines containing "set variable value" for all variables
689// with the archive flag set to true.
690
691void Cvar_Init( void );
692
693char *Cvar_InfoString( int bit );
694char *Cvar_InfoString_Big( int bit );
695// returns an info string containing all the cvars that have the given bit set
696// in their flags ( CVAR_USERINFO, CVAR_SERVERINFO, CVAR_SYSTEMINFO, etc )
697void Cvar_InfoStringBuffer( int bit, char *buff, int buffsize );
698void Cvar_CheckRange( cvar_t *cv, float minVal, float maxVal, qboolean shouldBeIntegral );
699void Cvar_SetDescription( cvar_t *var, const char *var_description );
700
701void Cvar_Restart(qboolean unsetVM);
702void Cvar_Restart_f( void );
703void Cvar_SaveGameRestart_f( void );
704
705void Cvar_CompleteCvarName(const char* args, int argNum);
706
707cvar_t *Cvar_Unset(cvar_t *cv);
708
709extern int cvar_modifiedFlags;
710extern qboolean cvar_global_force;
711// whenever a cvar is modifed, its flags will be OR'd into this, so
712// a single check can determine if any CVAR_USERINFO, CVAR_SERVERINFO,
713// etc, variables have been modified since the last check. The bit
714// can then be cleared to allow another change detection.
715
716/*
717==============================================================
718
719FILESYSTEM
720
721No stdio calls should be used by any part of the game, because
722we need to deal with all sorts of directory and seperator char
723issues.
724==============================================================
725*/
726
727// referenced flags
728// these are in loop specific order so don't change the order
729#define FS_GENERAL_REF 0x01
730#define FS_UI_REF 0x02
731#define FS_CGAME_REF 0x04
732#define FS_QAGAME_REF 0x08
733// number of id paks that will never be autodownloaded from baseq3
734#define NUM_ID_PAKS 5
735
736#define MAX_FILE_HANDLES 64
737
738#ifdef DEDICATED
739# define Q3CONFIG_CFG CONFIG_PREFIX "_server.cfg"
740#else
741# define Q3CONFIG_CFG CONFIG_PREFIX ".cfg"
742#endif
743
744qboolean FS_Initialized( void );
745
746void FS_InitFilesystem( void );
747void FS_Shutdown( qboolean closemfp );
748
749qboolean FS_ConditionalRestart( int checksumFeed, qboolean disconnect );
750void FS_Restart( int checksumFeed );
751// shutdown and restart the filesystem so changes to fs_gamedir can take effect
752
753char **FS_ListFilteredFiles( const char *path, const char *extension, const char *filter, qboolean wantSubs, int *numfiles, qboolean allowNonPureFilesOnDisk );
754char **FS_ListFiles( const char *directory, const char *extension, qboolean wantSubs, int *numfiles );
755// directory should not have either a leading or trailing /
756// if extension is "/", only subdirectories will be returned
757// the returned files will not include any directories or /
758
759void FS_FreeFileList( char **list );
760
761qboolean FS_FileExists_HomeConfig( const char *file );
762qboolean FS_FileExists_HomeData( const char *file );
763qboolean FS_FileExists_HomeState( const char *file );
764
765void FS_CorrectCase(char* path);
766qboolean FS_CreatePath (const char *OSPath);
767
768char *FS_BaseDir_BuildOSPath( const char *base, const char *qpath );
769char *FS_BuildOSPath( const char *base, const char *game, const char *qpath );
770
771int FS_LoadStack( void );
772
773int FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize );
774int FS_GetModList( char *listbuf, int bufsize );
775
776void FS_GetModDescription(const char* modDir, char* description, int descriptionLen);
777
778fileHandle_t FS_FOpenFileWrite_HomeConfig( const char *filename );
779fileHandle_t FS_FOpenFileWrite_HomeData( const char *filename );
780fileHandle_t FS_FOpenFileWrite_HomeState( const char *filename );
781fileHandle_t FS_FOpenFileAppend_HomeData( const char *filename );
782fileHandle_t FS_FCreateOpenPipeFile( const char *filename );
783fileHandle_t FS_FOpenTextFileWrite_HomeConfig(const char* qpath);
784fileHandle_t FS_FOpenTextFileWrite_HomeData(const char* qpath);
785fileHandle_t FS_FOpenTextFileWrite_HomeState(const char* qpath);
786// will properly create any needed paths and deal with seperater character issues
787
788fileHandle_t FS_BaseDir_FOpenFileWrite_HomeConfig( const char *filename );
789fileHandle_t FS_BaseDir_FOpenFileWrite_HomeData( const char *filename );
790fileHandle_t FS_BaseDir_FOpenFileWrite_HomeState( const char *filename );
791long FS_BaseDir_FOpenFileRead( const char *filename, fileHandle_t *fp );
792void FS_BaseDir_Rename_HomeData( const char *from, const char *to, qboolean safe );
793void FS_CanonicalFilename( char *filename );
794
795long FS_FOpenFileRead(const char* filename, fileHandle_t* file, qboolean uniqueFILE, qboolean quiet);
796// if uniqueFILE is true, then a new FILE will be fopened even if the file
797// is found in an already open pak file. If uniqueFILE is false, you must call
798// FS_FCloseFile instead of fclose, otherwise the pak FILE would be improperly closed
799// It is generally safe to always set uniqueFILE to true, because the majority of
800// file IO goes through FS_ReadFile, which Does The Right Thing already.
801
802int FS_FileIsInPAK(const char *filename, int *pChecksum );
803// returns 1 if a file is in the PAK file, otherwise -1
804
805size_t FS_Write( const void *buffer, size_t len, fileHandle_t f );
806
807size_t FS_Read( void *buffer, size_t len, fileHandle_t f );
808// properly handles partial reads and reads from other dlls
809
810void FS_FCloseFile( fileHandle_t f );
811// note: you can't just fclose from another DLL, due to MS libc issues
812
813long FS_ReadFileEx(const char* qpath, void** buffer, qboolean quiet);
814long FS_ReadFile(const char* qpath, void** buffer);
815const char *FS_Gamedir( void );
816// returns the length of the file
817// a null buffer will just return the file length without loading
818// as a quick check for existance. -1 length == not present
819// A 0 byte will always be appended at the end, so string ops are safe.
820// the buffer should be considered read-only, because it may be cached
821// for other uses.
822
823void FS_ForceFlush( fileHandle_t f );
824// forces flush on files we're writing to.
825
826void FS_FreeFile( void *buffer );
827// frees the memory returned by FS_ReadFile
828
829
830const char *FS_PrepFileWrite( const char *filename );
831// prepares the file to be written
832
833int FS_WriteFile( const char *qpath, const void *buffer, int size );
834// writes a complete file, creating any subdirectories needed
835
836void FS_WriteTextFile( const char *qpath, const void *buffer, int size );
837// writes a complete text file, creating any subdirectories needed
838
839long FS_filelength(fileHandle_t f);
840// doesn't work for files that are opened from a pack file
841
842int FS_FTell( fileHandle_t f );
843// where are we?
844
845void FS_Flush( fileHandle_t f );
846
847void QDECL FS_Printf( fileHandle_t f, const char *fmt, ... ) Q_PRINTF_FUNC(2, 3);
848// like fprintf
849
850int FS_FOpenFileByMode( const char *qpath, fileHandle_t *f, fsMode_t mode );
851// opens a file for reading, writing, or appending depending on the value of mode
852
853int FS_Seek( fileHandle_t f, long offset, int origin );
854// seek on a file (doesn't work for zip files!!!!!!!!)
855
856qboolean FS_FilenameCompare( const char *s1, const char *s2 );
857qboolean FS_FileNewer( const char *source, const char *destination );
858
859const char *FS_GamePureChecksum( void );
860// Returns the checksum of the pk3 from which the server loaded the qagame.qvm
861
862const char *FS_LoadedPakNames( void );
863const char *FS_LoadedPakChecksums( void );
864const char *FS_LoadedPakPureChecksums( void );
865// Returns a space separated string containing the checksums of all loaded pk3 files.
866// Servers with sv_pure set will get this string and pass it to clients.
867
868const char *FS_ReferencedPakNames( void );
869const char *FS_ReferencedPakChecksums( void );
870const char *FS_ReferencedPakPureChecksums( void );
871// Returns a space separated string containing the checksums of all loaded
872// AND referenced pk3 files. Servers with sv_pure set will get this string
873// back from clients for pure validation
874
875void FS_ClearPakReferences( int flags );
876// clears referenced booleans on loaded pk3s
877
878void FS_PureServerSetReferencedPaks( const char *pakSums, const char *pakNames );
879void FS_PureServerSetLoadedPaks( const char *pakSums, const char *pakNames );
880// If the string is empty, all data sources will be allowed.
881// If not empty, only pk3 files that match one of the space
882// separated checksums will be checked for files, with the
883// sole exception of .cfg files.
884
885qboolean FS_CheckDirTraversal(const char *checkdir);
886qboolean FS_idPak(const char *pak, const char *base);
887qboolean FS_ComparePaks( char *neededpaks, int len, qboolean dlstring );
888
889void FS_Remove( const char *osPath );
890void FS_Remove_HomeData( const char *homePath );
891
892void FS_FilenameCompletion( const char *dir, const char *ext,
893 qboolean stripExt, void(*callback)(const char *s), qboolean allowNonPureFilesOnDisk );
894
895const char* FS_GetCurrentGameDir();
896void FS_GetRelativeFilename( const char *currentDirectory, const char *absoluteFilename, char *out, size_t destlen );
897
898void FS_FileTime(const char* filename, char* date, char* size);
899
900void FS_CorrectCase(char* path);
901
902extern cvar_t* fs_debug;
903extern cvar_t* fs_mapdir;
904
905/*
906==============================================================
907
908Edit fields and command line history/completion
909
910==============================================================
911*/
912
913#define MAX_EDIT_LINE 256
914typedef struct {
915 int cursor;
916 int scroll;
917 int widthInChars;
918 char buffer[MAX_EDIT_LINE];
919} field_t;
920
921void Field_Clear( field_t *edit );
922void Field_AutoComplete( field_t *edit );
923void Field_CompleteKeyname( void );
924void Field_CompleteFilename( const char *dir,
925 const char *ext, qboolean stripExt, qboolean allowNonPureFilesOnDisk );
926void Field_CompleteCommand( char *cmd,
927 qboolean doCommands, qboolean doCvars );
928void Field_CompletePlayerName( const char **names, int count );
929/*
930==============================================================
931
932MISC
933
934==============================================================
935*/
936
937// returnbed by Sys_GetProcessorId
938#define CPUID_GENERIC 0 // any unrecognized processor
939
940#define CPUID_AXP 0x10
941
942#define CPUID_INTEL_UNSUPPORTED 0x20 // Intel 386/486
943#define CPUID_INTEL_PENTIUM 0x21 // Intel Pentium or PPro
944#define CPUID_INTEL_MMX 0x22 // Intel Pentium/MMX or P2/MMX
945#define CPUID_INTEL_KATMAI 0x23 // Intel Katmai
946
947#define CPUID_AMD_3DNOW 0x30 // AMD K6 3DNOW!
948
949/*
950==============================================================
951
952MISC
953
954==============================================================
955*/
956
957// vsnprintf is ISO/IEC 9899:1999
958// abstracting this to make it portable
959#ifdef _WIN32
960#define Q_vsnprintf _vsnprintf
961#define Q_snprintf _snprintf
962#else
963#define Q_vsnprintf vsnprintf
964#define Q_snprintf snprintf
965#endif
966
967// centralizing the declarations for cl_cdkey
968// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=470
969extern char cl_cdkey[34];
970
971// returned by Sys_GetProcessorFeatures
972typedef enum
973{
974 CF_RDTSC = 1 << 0,
975 CF_MMX = 1 << 1,
976 CF_MMX_EXT = 1 << 2,
977 CF_3DNOW = 1 << 3,
978 CF_3DNOW_EXT = 1 << 4,
979 CF_SSE = 1 << 5,
980 CF_SSE2 = 1 << 6,
981 CF_ALTIVEC = 1 << 7
982} cpuFeatures_t;
983
984// centralized and cleaned, that's the max string you can send to a Com_Printf / Com_DPrintf (above gets truncated)
985#define MAXPRINTMSG 4096
986
987
988#define MAX_RENDER_STRINGS 8
989#define MAX_RENDER_STRING_LENGTH 32
990
991char *CopyString( const char *in );
992void Info_Print( const char *s );
993
994void Com_BeginRedirect (char *buffer, int buffersize, void (*flush)(char *));
995void Com_EndRedirect( void );
996void QDECL Com_Printf( const char *fmt, ... ) Q_PRINTF_FUNC(1, 2);
997void QDECL Com_DPrintf( const char *fmt, ... ) Q_PRINTF_FUNC(1, 2);
998void QDECL Com_Error( int code, const char *fmt, ... ) Q_NO_RETURN Q_PRINTF_FUNC(2, 3);
999void Com_Quit_f( void ) Q_NO_RETURN;
1000void Com_GameRestart(int checksumFeed, qboolean disconnect);
1001
1002int Com_Milliseconds( void ); // will be journaled properly
1003unsigned Com_BlockChecksum( const void *buffer, int length );
1004char *Com_MD5File(const char *filename, int length, const char *prefix, int prefix_len);
1005int Com_HashKey(char *string, int maxlen);
1006int Com_Filter(const char *filter, const char *name, int casesensitive);
1007int Com_FilterPath(const char *filter, const char *name, int casesensitive);
1008int Com_RealTime(qtime_t *qtime);
1009qboolean Com_SafeMode( void );
1010void Com_RunAndTimeServerPacket(netadr_t *evFrom, msg_t *buf);
1011
1012qboolean Com_IsVoipTarget(uint8_t *voipTargets, int voipTargetsSize, int clientNum);
1013
1014void Com_StartupVariable( const char *match );
1015// checks for and removes command line "+set var arg" constructs
1016// if match is NULL, all set commands will be executed, otherwise
1017// only a set with the exact name. Only used during startup.
1018qboolean Com_PlayerNameToFieldString( char *str, int length, const char *name );
1019qboolean Com_FieldStringToPlayerName( char *name, int length, const char *rawname );
1020int QDECL Com_strCompare( const void *a, const void *b );
1021
1022
1023extern float currentfps;
1024extern cvar_t *paused;
1025extern cvar_t *config;
1026extern cvar_t *fps;
1027extern cvar_t *developer;
1028extern cvar_t *com_dedicated;
1029extern cvar_t *com_speeds;
1030extern cvar_t *com_timescale;
1031extern cvar_t *com_sv_running;
1032extern cvar_t *com_cl_running;
1033extern cvar_t *com_viewlog; // 0 = hidden, 1 = visible, 2 = minimized
1034extern cvar_t *com_shortversion;
1035extern cvar_t *com_version;
1036extern cvar_t *autopaused;
1037extern cvar_t *deathmatch;
1038extern cvar_t *com_blood;
1039extern cvar_t *com_buildScript; // for building release pak files
1040extern cvar_t *com_radar_range;
1041extern cvar_t *console_spam_filter;
1042extern cvar_t *com_journal;
1043extern cvar_t *com_cameraMode;
1044extern cvar_t *com_ansiColor;
1045extern cvar_t *com_unfocused;
1046extern cvar_t *com_maxfpsUnfocused;
1047extern cvar_t *com_minimized;
1048extern cvar_t *com_maxfpsMinimized;
1049extern cvar_t *com_altivec;
1050extern cvar_t *com_standalone;
1051extern cvar_t *com_gamename;
1052extern cvar_t *com_basegame;
1053extern cvar_t *com_homepath;
1054extern cvar_t *com_altivec;
1055
1056// both client and server must agree to pause
1057extern cvar_t *cl_paused;
1058extern cvar_t *sv_paused;
1059
1060extern cvar_t *cl_packetdelay;
1061extern cvar_t *sv_packetdelay;
1062
1063extern cvar_t* com_protocol;
1064#ifdef LEGACY_PROTOCOL
1065extern cvar_t* com_legacyprotocol;
1066#endif
1067#ifndef DEDICATED
1068extern cvar_t* con_autochat;
1069#endif
1070extern cvar_t* com_target_game;
1071extern cvar_t* com_target_shortversion;
1072extern cvar_t* com_target_version;
1073extern cvar_t* com_target_extension;
1074extern cvar_t* com_target_demo;
1075
1076extern cvar_t* com_updatecheck_enabled;
1077extern cvar_t* com_updatecheck_interval;
1078
1079extern int protocol_version_demo;
1080extern int protocol_version_full;
1081
1082// com_speeds times
1083extern int time_game;
1084extern int time_frontend;
1085extern int time_backend; // renderer backend time
1086
1087extern int com_frameTime;
1088extern int com_frameMsec;
1089
1090extern qboolean com_errorEntered;
1091extern qboolean com_fullyInitialized;
1092extern qboolean com_gotOriginalConfig;
1093extern qboolean com_firstConfig;
1094
1095extern fileHandle_t com_journalFile;
1096extern fileHandle_t com_journalDataFile;
1097
1098typedef enum {
1099 TAG_FREE,
1100 TAG_CONST,
1101 TAG_GENERAL,
1102 TAG_BOTLIB,
1103 TAG_RENDERER, // memory allocated from renderer
1104 TAG_GAME, // memory allocated from game
1105 TAG_CGAME, // memory allocated from client game
1106 TAG_CLIENT, // memory allocated from client
1107 TAG_TIKI, // su44: memory allocated by qcommon/tiki.c code
1108 TAG_STRINGS_AND_COMMANDS,
1109 TAG_SOUND, // memory allocated from sound
1110 TAG_STATIC,
1111 TAG_STATIC_RENDERER,
1112 TAG_SKEL, // memory allocated from skeletor
1113 TAG_TEMP, // temporary memory
1114 TAG_EXE,
1115 TAG_NUM_TOTAL_TAGS
1116} memtag_t;
1117
1118/*
1119
1120--- low memory ----
1121server vm
1122server clipmap
1123---mark---
1124renderer initialization (shaders, etc)
1125UI vm
1126cgame vm
1127renderer map
1128renderer models
1129
1130---free---
1131
1132temp file loading
1133--- high memory ---
1134
1135*/
1136
1137#if defined(_DEBUG) && !defined(BSPC)
1138 #define ZONE_DEBUG
1139#endif
1140
1141#ifdef ZONE_DEBUG
1142#define Z_TagMalloc(size, tag) Z_TagMallocDebug(size, tag, #size, __FILE__, __LINE__)
1143#define Z_Malloc(size) Z_MallocDebug(size, #size, __FILE__, __LINE__)
1144#define S_Malloc(size) S_MallocDebug(size, #size, __FILE__, __LINE__)
1145void *Z_TagMallocDebug( int size, int tag, const char *label, const char *file, int line ); // NOT 0 filled memory
1146void *Z_MallocDebug( int size, const char *label, const char *file, int line ); // returns 0 filled memory
1147void *S_MallocDebug( int size, const char *label, const char *file, int line ); // returns 0 filled memory
1148#else
1149void *Z_TagMalloc( int size, int tag ); // NOT 0 filled memory
1150void *Z_Malloc( int size ); // returns 0 filled memory
1151void *S_Malloc( int size ); // NOT 0 filled memory only for small allocations
1152#endif
1153void Z_Free( void *ptr );
1154void Z_FreeTags( int tag );
1155int Z_AvailableMemory( void );
1156void Z_LogHeap( void );
1157
1158void Hunk_Clear( void );
1159void Hunk_ClearToMark( void );
1160void Hunk_SetMark( void );
1161qboolean Hunk_CheckMark( void );
1162void Hunk_ClearTempMemory( void );
1163void *Hunk_AllocateTempMemory( int size );
1164void Hunk_FreeTempMemory( void *buf );
1165int Hunk_MemoryRemaining( void );
1166void Hunk_Log( void);
1167
1168void Com_TouchMemory( void );
1169
1170const char* Z_EmptyStringPointer(void);
1171const char* Z_NumberStringPointer(int iNum);
1172
1173// commandLine should not include the executable name (argv[0])
1174void Com_Init( char *commandLine );
1175void Com_Frame( void );
1176void Com_Shutdown( void );
1177
1178qboolean Com_SanitizeName( const char *pszOldName, char *pszNewName, size_t bufferSize );
1179const char *Com_GetArchiveFileName( const char *filename, const char *extension );
1180const char *Com_GetArchiveFolder();
1181void Com_WipeSavegame( const char *savename );
1182qboolean Com_ShiftedStrStr(const char* shifted, const char* name, int offset);
1183qboolean COM_IsMapValid(const char* name);
1184void Com_SwapSaveStruct(savegamestruct_t* save);
1185
1186
1187/*
1188==============================================================
1189
1190CLIENT / SERVER SYSTEMS
1191
1192==============================================================
1193*/
1194
1195//
1196// client interface
1197//
1198void CL_InitKeyCommands( void );
1199// the keyboard binding interface must be setup before execing
1200// config files, but the rest of client startup will happen later
1201
1202void CL_Init( void );
1203void CL_Disconnect();
1204void CL_AbnormalDisconnect();
1205void CL_Shutdown(const char *finalmsg, qboolean disconnect, qboolean quit);
1206qboolean CL_FinishedIntro(void);
1207void CL_FinishedStartStage(void);
1208void CL_SetFrameNumber(int frameNumber);
1209void CL_Frame( int msec );
1210qboolean CL_GameCommand( void );
1211void CL_KeyEvent (int key, qboolean down, unsigned time);
1212
1213void CL_Key_ForceCommand(int key, unsigned int time);
1214
1215void CL_CharEvent( int key );
1216// char events are for field typing, not game control
1217
1218void CL_GetMouseState( int *x, int *y, unsigned int *buttons );
1219
1220void CL_SetMousePos( int x, int y );
1221
1222void CL_MouseEvent( int dx, int dy, int time );
1223
1224void CL_ClearButtons( void );
1225
1226void CL_JoystickEvent( int axis, int value, int time );
1227
1228void CL_PacketEvent( netadr_t from, msg_t *msg );
1229
1230void CL_MapLoading( qboolean flush, const char *pszMapName );
1231// do a screen update before starting to load a map
1232// when the server is going to load a new map, the entire hunk
1233// will be cleared, so the client must shutdown cgame, ui, and
1234// the renderer
1235
1236void CL_ForwardCommandToServer( const char *string );
1237// adds the current command line as a clc_clientCommand to the client message.
1238// things like godmode, noclip, etc, are commands directed to the server,
1239// so when they are typed in at the console, they will need to be forwarded.
1240
1241qboolean CL_UseLargeLightmap(const char* mapName);
1242// returns true if the standard BSP file should be used
1243
1244void CL_CDDialog( void );
1245// bring up the "need a cd to play" dialog
1246
1247void CL_FlushMemory( void );
1248// dump all memory on an error
1249
1250void CL_ShutdownAll(qboolean shutdownRef);
1251// shutdown client
1252
1253void CL_InitRef(void);
1254// initialize renderer interface
1255
1256void CL_StartHunkUsers( qboolean rendererOnly );
1257// start all the client stuff using the hunk
1258
1259void CL_Snd_Shutdown(void);
1260// Restart sound subsystem
1261
1262void Key_KeynameCompletion( void(*callback)(const char *s) );
1263// for keyname autocompletion
1264
1265void Key_WriteBindings( fileHandle_t f );
1266// for writing the config files
1267
1268void S_ClearSoundBuffer( void );
1269// call before filesystem access
1270
1271float *get_camera_offset( qboolean *lookactive, qboolean *resetview );
1272
1273// AVI files have the start of pixel lines 4 byte-aligned
1274#define AVI_LINE_PADDING 4
1275
1276//
1277// server interface
1278//
1279void SV_ServerLoaded( void );
1280void SV_Init( void );
1281void SV_Shutdown( const char *finalmsg );
1282void SV_SetFrameNumber(int frameNumber);
1283void SV_Frame( int msec );
1284void SV_PacketEvent( netadr_t from, msg_t *msg );
1285int SV_FrameMsec(void);
1286void SV_CheckSaveGame(void);
1287qboolean SV_GameCommand(void);
1288int SV_SendQueuedPackets(void);
1289
1290//
1291// input interface
1292//
1293void IN_Init(void *windowData);
1294void IN_Frame(void);
1295void IN_Shutdown(void);
1296void IN_Restart(void);
1297void IN_GetMousePosition(int *x, int *y);
1298
1299typedef void (*pCursorFree)(byte *pic);
1300qboolean IN_SetCursorFromImage(const byte *pic, int width, int height, pCursorFree cursorFreeFn);
1301void IN_FreeCursor();
1302qboolean IN_IsCursorActive();
1303
1304void Com_Pause();
1305void Com_Unpause();
1306void Com_FakePause();
1307void Com_FakeUnpause();
1308void Com_Pause_f();
1309void SV_SoundCallback( int entnum, int channel_number, const char *name );
1310
1311int R_CountTextureMemory();
1312/*
1313==============================================================
1314
1315NON-PORTABLE SYSTEM SERVICES
1316
1317==============================================================
1318*/
1319
1320typedef enum {
1321 AXIS_SIDE,
1322 AXIS_FORWARD,
1323 AXIS_UP,
1324 AXIS_ROLL,
1325 AXIS_YAW,
1326 AXIS_PITCH,
1327 MAX_JOYSTICK_AXIS
1328} joystickAxis_t;
1329
1330typedef enum {
1331 // SE_NONE must be zero
1332 SE_NONE = 0, // evTime is still valid
1333 SE_KEY, // evValue is a key code, evValue2 is the down flag
1334 SE_CHAR, // evValue is an ascii char
1335 SE_MOUSE, // evValue and evValue2 are reletive signed x / y moves
1336 SE_JOYSTICK_AXIS, // evValue is an axis number and evValue2 is the current state (-127 to 127)
1337 SE_CONSOLE, // evPtr is a char*
1338 SE_PACKET // evPtr is a netadr_t followed by data bytes to evPtrLength
1339} sysEventType_t;
1340
1341typedef struct {
1342 int evTime;
1343 sysEventType_t evType;
1344 int evValue, evValue2;
1345 size_t evPtrLength; // bytes of data pointed to by evPtr, for journaling
1346 void *evPtr; // this must be manually freed if not NULL
1347} sysEvent_t;
1348
1349sysEvent_t Sys_GetEvent(void);
1350
1351void Com_QueueEvent( int time, sysEventType_t type, int value, int value2, size_t ptrLength, void *ptr );
1352int Com_EventLoop( void );
1353sysEvent_t Com_GetSystemEvent( void );
1354
1355void Sys_Init (void);
1356
1357// general development dll loading for virtual machine testing
1358void Sys_UnloadDll( void *dllHandle );
1359
1360qboolean Sys_DllExtension(const char* name);
1361
1362void Sys_UnloadGame( void );
1363void *Sys_GetGameAPI( void *parms );
1364
1365void Sys_UnloadCGame( void );
1366void *Sys_GetCGameAPI( void *parms );
1367
1368void Sys_UnloadUI( void );
1369void *Sys_GetUIAPI( void );
1370
1371//bot libraries
1372void Sys_UnloadBotLib( void );
1373void *Sys_GetBotLibAPI( void *parms );
1374
1375char *Sys_GetCurrentUser( void );
1376
1377void QDECL Sys_Error( const char *error, ...) Q_NO_RETURN Q_PRINTF_FUNC(1, 2);
1378void Sys_Quit (void) Q_NO_RETURN;
1379char *Sys_GetClipboardData( void ); // note that this isn't journaled...
1380
1381void Sys_Print( const char *msg );
1382
1383// Sys_Milliseconds should only be used for profiling purposes,
1384// any game related timing information should come from event timestamps
1385int Sys_Milliseconds (void);
1386
1387qboolean Sys_RandomBytes( byte *string, int len );
1388
1389// the system console is shown when a dedicated server is running
1390void Sys_DisplaySystemConsole( qboolean show );
1391
1392cpuFeatures_t Sys_GetProcessorFeatures( void );
1393
1394void Sys_SetErrorText( const char *text );
1395
1396void Sys_SendPacket( int length, const void *data, netadr_t to );
1397
1398qboolean Sys_StringToAdr( const char *s, netadr_t *a, netadrtype_t family );
1399qboolean Sys_GetPacket( netadr_t *net_from, msg_t *net_message );
1400
1401//Does NOT parse port numbers, only base addresses.
1402
1403qboolean Sys_IsLANAddress (netadr_t adr);
1404void Sys_ShowIP(void);
1405
1406FILE *Sys_FOpen( const char *ospath, const char *mode );
1407qboolean Sys_Mkdir( const char *path );
1408FILE *Sys_Mkfifo( const char *ospath );
1409char *Sys_Cwd( void );
1410void Sys_SetDefaultInstallPath(const char *path);
1411char *Sys_DefaultInstallPath(void);
1412char *Sys_SteamPath(void);
1413char *Sys_GogPath(void);
1414char *Sys_MicrosoftStorePath(void);
1415
1416#ifdef __APPLE__
1417char *Sys_DefaultAppPath(void);
1418#endif
1419
1420char *Sys_DefaultHomeConfigPath(void);
1421char *Sys_DefaultHomeDataPath(void);
1422char *Sys_DefaultHomeStatePath(void);
1423const char *Sys_Dirname( char *path );
1424const char *Sys_Basename( char *path );
1425char *Sys_ConsoleInput( void );
1426
1427void SetProgramPath( const char *path );
1428char *Sys_DefaultBasePath( void );
1429char *Sys_DefaultUserPath( void );
1430char *Sys_DefaultOutputPath( void );
1431
1432char **Sys_ListFiles( const char *directory, const char *extension, const char *filter, int *numfiles, qboolean wantsubs );
1433void Sys_FreeFileList( char **list );
1434void Sys_Sleep(int msec);
1435
1436void Sys_InitStreamThread(void);
1437void Sys_ShutdownStreamThread(void);
1438void Sys_BeginStreamedFile(fileHandle_t f, int readAhead);
1439void Sys_EndStreamedFile(fileHandle_t f);
1440int Sys_StreamedRead(void* buffer, int size, int count, fileHandle_t f);
1441void Sys_StreamSeek(fileHandle_t f, int offset, int origin);
1442
1443qboolean Sys_LowPhysicalMemory(void);
1444
1445void Sys_SetEnv(const char* name, const char* value);
1446
1447void SetNormalThreadPriority( void );
1448void SetBelowNormalThreadPriority( void );
1449
1450void RecoverLostAutodialData( void );
1451
1452void Sys_CloseMutex( void );
1453void Sys_ShowConsole( int visLevel, qboolean quitOnClose );
1454void Sys_DebugPrint(const char* message);
1455void Sys_PumpMessageLoop( void );
1456
1457qboolean SaveRegistryInfo( qboolean user, const char *pszName, void *pvBuf, long lSize );
1458qboolean LoadRegistryInfo( qboolean user, const char *pszName, void *pvBuf, long *plSize );
1459
1460qboolean IsFirstRun( void );
1461qboolean IsNewConfig( void );
1462qboolean IsSafeMode( void );
1463void ClearNewConfigFlag( void );
1464const char *Sys_GetWholeClipboard( void );
1465void Sys_SetClipboard( const char *contents );
1466
1467typedef enum
1468{
1469 DR_YES = 0,
1470 DR_NO = 1,
1471 DR_OK = 0,
1472 DR_CANCEL = 1
1473} dialogResult_t;
1474
1475typedef enum
1476{
1477 DT_INFO,
1478 DT_WARNING,
1479 DT_ERROR,
1480 DT_YES_NO,
1481 DT_OK_CANCEL
1482} dialogType_t;
1483
1484dialogResult_t Sys_Dialog( dialogType_t type, const char *message, const char *title );
1485qboolean Sys_OpenFolderInFileManager( const char *path, qboolean create );
1486
1487void Sys_RemovePIDFile( const char *gamedir );
1488void Sys_InitPIDFile( const char *gamedir );
1489
1490void Sys_ProcessBackgroundTasks();
1491
1492/* This is based on the Adaptive Huffman algorithm described in Sayood's Data
1493 * Compression book. The ranks are not actually stored, but implicitly defined
1494 * by the location of a node within a doubly-linked list */
1495
1496#define NYT HMAX /* NYT = Not Yet Transmitted */
1497#define INTERNAL_NODE (HMAX+1)
1498
1499typedef struct nodetype {
1500 struct nodetype *left, *right, *parent; /* tree structure */
1501 struct nodetype *next, *prev; /* doubly-linked list */
1502 struct nodetype **head; /* highest ranked node in block */
1503 int weight;
1504 int symbol;
1505} node_t;
1506
1507#define HMAX 256 /* Maximum symbol */
1508
1509typedef struct {
1510 int blocNode;
1511 int blocPtrs;
1512
1513 node_t* tree;
1514 node_t* lhead;
1515 node_t* ltail;
1516 node_t* loc[HMAX+1];
1517 node_t** freelist;
1518
1519 node_t nodeList[768];
1520 node_t* nodePtrs[768];
1521} huff_t;
1522
1523typedef struct {
1524 huff_t compressor;
1525 huff_t decompressor;
1526} huffman_t;
1527
1528void Huff_Compress(msg_t *buf, int offset);
1529void Huff_Decompress(msg_t *buf, int offset);
1530void Huff_Init(huffman_t *huff);
1531void Huff_addRef(huff_t* huff, byte ch);
1532int Huff_Receive (node_t *node, int *ch, byte *fin);
1533void Huff_transmit (huff_t *huff, int ch, byte *fout, int maxoffset);
1534void Huff_offsetReceive (node_t *node, int *ch, byte *fin, int *offset, int maxoffset);
1535void Huff_offsetTransmit (huff_t *huff, int ch, byte *fout, int *offset, int maxoffset);
1536void Huff_putBit( int bit, byte *fout, int *offset);
1537int Huff_getBit( byte *fout, int *offset);
1538
1539extern huffman_t clientHuffTables;
1540
1541#define SV_ENCODE_START 4
1542#define SV_DECODE_START 12
1543#define CL_ENCODE_START 12
1544#define CL_DECODE_START 4
1545
1546// flags for sv_allowDownload and cl_allowDownload
1547#define DLF_ENABLE 1
1548#define DLF_NO_REDIRECT 2
1549#define DLF_NO_UDP 4
1550#define DLF_NO_DISCONNECT 8
1551
1552#ifdef __cplusplus
1553}
1554#endif
1555
1556#endif // _QCOMMON_H_
Definition q_shared.h:2013
Definition qcommon.h:914
Definition q_shared.h:1693
Definition qcommon.h:1509
Definition qcommon.h:1523
Definition qcommon.h:40
Definition qcommon.h:218
Definition qcommon.h:265
Definition qcommon.h:344
Definition qcommon.h:308
Definition qcommon.h:314
Definition qcommon.h:1499
Definition q_shared.h:1744
Definition qcommon.h:1341
Definition q_shared.h:1875
Definition q_shared.h:1363
Definition q_shared.h:207