Sigridwip3f1816d8 years agoHistory
1454 lines · 27.1 KB · C
RawDownload
// common.c -- misc functions used in client and server #include <stdarg.h>#include "quakedef.h" #define NUM_SAFE_ARGVS 7 static char *largv[MAX_NUM_ARGVS + NUM_SAFE_ARGVS + 1];static char *argvdummy = " "; static char *safeargvs[NUM_SAFE_ARGVS] =	{"-stdvid", "-nolan", "-nosound", "-nocdaudio", "-nojoy", "-nomouse", "-dibonly"}; cvar_t registered = {"registered","0"};cvar_t cmdline = {"cmdline","0", false, true}; bool com_modified; // set true if using non-id files bool proghack; int static_registered = 1; // only for startup check, then set bool msg_suppress_1 = 0; void COM_InitFilesystem (void); char com_token[1024];int com_argc;char **com_argv; #define CMDLINE_LENGTH 256char com_cmdline[CMDLINE_LENGTH]; bool standard_quake = true, rogue, hipnotic; // this graphic needs to be in the pak file to use registered featuresunsigned short pop[] ={ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x6600,0x0000,0x0000,0x0000,0x6600,0x0000,0x0000,0x0066,0x0000,0x0000,0x0000,0x0000,0x0067,0x0000,0x0000,0x6665,0x0000,0x0000,0x0000,0x0000,0x0065,0x6600,0x0063,0x6561,0x0000,0x0000,0x0000,0x0000,0x0061,0x6563,0x0064,0x6561,0x0000,0x0000,0x0000,0x0000,0x0061,0x6564,0x0064,0x6564,0x0000,0x6469,0x6969,0x6400,0x0064,0x6564,0x0063,0x6568,0x6200,0x0064,0x6864,0x0000,0x6268,0x6563,0x0000,0x6567,0x6963,0x0064,0x6764,0x0063,0x6967,0x6500,0x0000,0x6266,0x6769,0x6a68,0x6768,0x6a69,0x6766,0x6200,0x0000,0x0062,0x6566,0x6666,0x6666,0x6666,0x6562,0x0000,0x0000,0x0000,0x0062,0x6364,0x6664,0x6362,0x0000,0x0000,0x0000,0x0000,0x0000,0x0062,0x6662,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0061,0x6661,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x6500,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x6400,0x0000,0x0000,0x0000}; /* All of Quake's data access is through a hierchal file system, but the contents of the file system can be transparently merged from several sources. The "base directory" is the path to the directory holding the quake.exe and all game directories. The sys_* files pass this to host_init in quakeparms_t->basedir. This can be overridden with the "-basedir" command line parm to allow code debugging in a different directory. The base directory isonly used during filesystem initialization. The "game directory" is the first tree on the search path and directory that all generated files (savegames, screenshots, demos, config files) will be saved to. This can be overridden with the "-game" command line parameter. The game directory can never be changed while quake is executing. This is a precacution against having a malicious server instruct clients to write files over areas they shouldn't. The "cache directory" is only used during development to save network bandwidth, especially over ISDN / T1 lines. If there is a cache directoryspecified, when a file is found by the normal search path, it will be mirroredinto the cache directory, then opened there. FIXME:The file "parms.txt" will be read out of the game directory and appended to the current command line arguments to allow different games to initialize startup parms differently. This could be used to add a "-sspeed 22050" for the high quality sound edition. Because they are added at the end, they will not override an explicit setting on the original command line. */ //============================================================================ // ClearLink is used for new headnodesvoid ClearLink (link_t *l){	l->prev = l->next = l;} void RemoveLink (link_t *l){	l->next->prev = l->prev;	l->prev->next = l->next;} void InsertLinkBefore (link_t *l, link_t *before){	l->next = before;	l->prev = before->prev;	l->prev->next = l;	l->next->prev = l;}void InsertLinkAfter (link_t *l, link_t *after){	l->next = after->next;	l->prev = after;	l->prev->next = l;	l->next->prev = l;} /*============================================================================ 					BYTE ORDER FUNCTIONS ============================================================================*/ bool bigendien; short (*BigShort) (short l);short (*LittleShort) (short l);int (*BigLong) (int l);int (*LittleLong) (int l);float (*BigFloat) (float l);float (*LittleFloat) (float l); short ShortSwap (short l){	uint8_t b1,b2; 	b1 = l&255;	b2 = (l>>8)&255; 	return (b1<<8) + b2;} short ShortNoSwap (short l){	return l;} int LongSwap (int l){	uint8_t b1,b2,b3,b4; 	b1 = l&255;	b2 = (l>>8)&255;	b3 = (l>>16)&255;	b4 = (l>>24)&255; 	return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;} int LongNoSwap (int l){	return l;} float FloatSwap (float f){	union	{		float f;		uint8_t b[4];	} dat1, dat2; 	dat1.f = f;	dat2.b[0] = dat1.b[3];	dat2.b[1] = dat1.b[2];	dat2.b[2] = dat1.b[1];	dat2.b[3] = dat1.b[0];	return dat2.f;} float FloatNoSwap (float f){	return f;} /*============================================================================== 			MESSAGE IO FUNCTIONS Handles byte ordering and avoids alignment errors==============================================================================*/ //// writing functions// void MSG_WriteChar (sizebuf_t *sb, int c){	uint8_t *buf; #ifdef PARANOID	if (c < -128 || c > 127)		Sys_Error ("MSG_WriteChar: range error");#endif 	buf = SZ_GetSpace (sb, 1);	buf[0] = c;} void MSG_WriteByte (sizebuf_t *sb, int c){	uint8_t *buf; #ifdef PARANOID	if (c < 0 || c > 255)		Sys_Error ("MSG_WriteByte: range error");#endif 	buf = SZ_GetSpace (sb, 1);	buf[0] = c;} void MSG_WriteShort (sizebuf_t *sb, int c){	uint8_t *buf; #ifdef PARANOID	if (c < ((short)0x8000) || c > (short)0x7fff)		Sys_Error ("MSG_WriteShort: range error");#endif 	buf = SZ_GetSpace (sb, 2);	buf[0] = c&0xff;	buf[1] = c>>8;} void MSG_WriteLong (sizebuf_t *sb, int c){	uint8_t *buf; 	buf = SZ_GetSpace (sb, 4);	buf[0] = c&0xff;	buf[1] = (c>>8)&0xff;	buf[2] = (c>>16)&0xff;	buf[3] = c>>24;} void MSG_WriteFloat (sizebuf_t *sb, float f){	union	{		float f;		int l;	} dat; 	dat.f = f;	dat.l = LittleLong (dat.l); 	SZ_Write (sb, &dat.l, 4);} void MSG_WriteString (sizebuf_t *sb, char *s){	if (!s)		SZ_Write (sb, "", 1);	else		SZ_Write (sb, s, strlen(s)+1);} void MSG_WriteCoord (sizebuf_t *sb, float f){	MSG_WriteShort (sb, (int)(f*8));} void MSG_WriteAngle (sizebuf_t *sb, float f){	MSG_WriteByte (sb, ((int)f*256/360) & 255);} //// reading functions//int msg_readcount;bool msg_badread; void MSG_BeginReading (void){	msg_readcount = 0;	msg_badread = false;} // returns -1 and sets msg_badread if no more characters are availableint MSG_ReadChar (void){	int c; 	if (msg_readcount+1 > net_message.cursize)	{		msg_badread = true;		return -1;	} 	c = (signed char)net_message.data[msg_readcount];	msg_readcount++; 	return c;} int MSG_ReadByte (void){	int c; 	if (msg_readcount+1 > net_message.cursize)	{		msg_badread = true;		return -1;	} 	c = (unsigned char)net_message.data[msg_readcount];	msg_readcount++; 	return c;} int MSG_ReadShort (void){	int c; 	if (msg_readcount+2 > net_message.cursize)	{		msg_badread = true;		return -1;	} 	c = (short)(net_message.data[msg_readcount]	+ (net_message.data[msg_readcount+1]<<8)); 	msg_readcount += 2; 	return c;} int MSG_ReadLong (void){	int c; 	if (msg_readcount+4 > net_message.cursize)	{		msg_badread = true;		return -1;	} 	c = net_message.data[msg_readcount]	+ (net_message.data[msg_readcount+1]<<8)	+ (net_message.data[msg_readcount+2]<<16)	+ (net_message.data[msg_readcount+3]<<24); 	msg_readcount += 4; 	return c;} float MSG_ReadFloat (void){	union	{		uint8_t b[4];		float f;		int l;	} dat; 	dat.b[0] = net_message.data[msg_readcount];	dat.b[1] = net_message.data[msg_readcount+1];	dat.b[2] = net_message.data[msg_readcount+2];	dat.b[3] = net_message.data[msg_readcount+3];	msg_readcount += 4; 	dat.l = LittleLong (dat.l); 	return dat.f;} char *MSG_ReadString (void){	static char string[2048];	int l, c; 	l = 0;	do	{		c = MSG_ReadChar ();		if (c == -1 || c == 0)			break;		string[l] = c;		l++;	} while (l < (int)sizeof(string)-1); 	string[l] = 0; 	return string;} float MSG_ReadCoord (void){	return MSG_ReadShort() * (1.0/8);} float MSG_ReadAngle (void){	return MSG_ReadChar() * (360.0/256);} //=========================================================================== void SZ_Alloc (sizebuf_t *buf, int startsize){	if (startsize < 256)		startsize = 256;	buf->data = Hunk_AllocName (startsize, "sizebuf");	buf->maxsize = startsize;	buf->cursize = 0;} void SZ_Free (sizebuf_t *buf){// Z_Free (buf->data);// buf->data = NULL;// buf->maxsize = 0;	buf->cursize = 0;} void SZ_Clear (sizebuf_t *buf){	buf->cursize = 0;} void *SZ_GetSpace (sizebuf_t *buf, int length){	void *data; 	if (buf->cursize + length > buf->maxsize)	{		if (!buf->allowoverflow)			Sys_Error ("SZ_GetSpace: overflow without allowoverflow set"); 		if (length > buf->maxsize)			Sys_Error ("SZ_GetSpace: %i is > full buffer size", length); 		buf->overflowed = true;		Con_Printf ("SZ_GetSpace: overflow");		SZ_Clear (buf);	} 	data = buf->data + buf->cursize;	buf->cursize += length; 	return data;} void SZ_Write (sizebuf_t *buf, void *data, int length){	memmove (SZ_GetSpace(buf,length),data,length);} void SZ_Print (sizebuf_t *buf, char *data){	int len; 	len = strlen(data)+1;  	if (buf->data[buf->cursize-1])		memmove ((uint8_t *)SZ_GetSpace(buf, len),data,len); // no trailing 0	else		memmove ((uint8_t *)SZ_GetSpace(buf, len-1)-1,data,len); // write over trailing 0} //============================================================================ /*============COM_SkipPath============*/char *COM_SkipPath (char *pathname){	char *last; 	last = pathname;	while (*pathname)	{		if (*pathname=='/')			last = pathname+1;		pathname++;	}	return last;} /*============COM_StripExtension============*/void COM_StripExtension (char *in, char *out){	while (*in && *in != '.')		*out++ = *in++;	*out = 0;} 

Lines 1–500 of 1454.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t