summaryrefslogtreecommitdiff
path: root/src/qcommon
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2009-10-13 17:17:27 +0000
committerTim Angus <tim@ngus.net>2013-01-03 00:16:49 +0000
commit6efd4cef3cfcc44d6727cb0e54da26fbb74a7533 (patch)
treefdb5ee764999ac868d00c54cefb8c290f1735fd6 /src/qcommon
parentfafe107646105e680e2bd4a82d9330dffaf69c9a (diff)
* Merge ioq3-r1666
Diffstat (limited to 'src/qcommon')
-rw-r--r--src/qcommon/common.c82
-rw-r--r--src/qcommon/files.c13
-rw-r--r--src/qcommon/msg.c23
-rw-r--r--src/qcommon/q_shared.h18
-rw-r--r--src/qcommon/qcommon.h2
-rw-r--r--src/qcommon/vm_x86_64_assembler.c2
6 files changed, 83 insertions, 57 deletions
diff --git a/src/qcommon/common.c b/src/qcommon/common.c
index b97626ed..d4593e08 100644
--- a/src/qcommon/common.c
+++ b/src/qcommon/common.c
@@ -672,22 +672,6 @@ int Com_FilterPath(char *filter, char *name, int casesensitive)
}
/*
-============
-Com_HashKey
-============
-*/
-int Com_HashKey(char *string, int maxlen) {
- int register hash, i;
-
- hash = 0;
- for (i = 0; i < maxlen && string[i] != '\0'; i++) {
- hash += string[i] * (119 + i);
- }
- hash = (hash ^ (hash >> 10) ^ (hash >> 20));
- return hash;
-}
-
-/*
================
Com_RealTime
================
@@ -2361,6 +2345,43 @@ static void Com_Crash_f( void ) {
* ( int * ) 0 = 0x12345678;
}
+/*
+==================
+Com_Setenv_f
+
+For controlling environment variables
+==================
+*/
+void Com_Setenv_f(void)
+{
+ int argc = Cmd_Argc();
+ char *arg1 = Cmd_Argv(1);
+
+ if(argc > 2)
+ {
+ char *arg2 = Cmd_ArgsFrom(2);
+
+#ifdef _WIN32
+ // windows already removes env variable if value is an empty string
+ _putenv(va("%s=%s", arg1, arg2));
+#else
+ if(!*arg2)
+ unsetenv(arg1);
+ else
+ setenv(arg1, arg2, 1);
+#endif
+ }
+ else if(argc == 2)
+ {
+ char *env = getenv(arg1);
+
+ if(env)
+ Com_Printf("%s=%s\n", arg1, env);
+ else
+ Com_Printf("%s undefined\n", arg1);
+ }
+}
+
static void Com_DetectAltivec(void)
{
// Only detect if user hasn't forcibly disabled it.
@@ -2445,12 +2466,25 @@ void Com_Init( char *commandLine ) {
Com_InitJournaling();
+ // Add some commands here already so users can use them from config files
+ Cmd_AddCommand ("setenv", Com_Setenv_f);
+ if (com_developer && com_developer->integer)
+ {
+ Cmd_AddCommand ("error", Com_Error_f);
+ Cmd_AddCommand ("crash", Com_Crash_f);
+ Cmd_AddCommand ("freeze", Com_Freeze_f);
+ }
+ Cmd_AddCommand ("quit", Com_Quit_f);
+ Cmd_AddCommand ("changeVectors", MSG_ReportChangeVectors_f );
+ Cmd_AddCommand ("writeconfig", Com_WriteConfig_f );
+ Cmd_SetCommandCompletionFunc( "writeconfig", Cmd_CompleteCfgName );
+
+ // Make it execute the configuration files
Cbuf_AddText ("exec default.cfg\n");
// skip the autogen.cfg if "safe" is on the command line
- if ( !Com_SafeMode() ) {
- Cbuf_AddText ("exec " Q3CONFIG_CFG "\n");
- }
+ if (!Com_SafeMode())
+ Cbuf_AddText("exec " Q3CONFIG_CFG "\n");
Cbuf_AddText ("exec autoexec.cfg\n");
@@ -2506,16 +2540,6 @@ void Com_Init( char *commandLine ) {
com_minimized = Cvar_Get( "com_minimized", "0", CVAR_ROM );
com_maxfpsMinimized = Cvar_Get( "com_maxfpsMinimized", "0", CVAR_ARCHIVE );
- if ( com_developer && com_developer->integer ) {
- Cmd_AddCommand ("error", Com_Error_f);
- Cmd_AddCommand ("crash", Com_Crash_f );
- Cmd_AddCommand ("freeze", Com_Freeze_f);
- }
- Cmd_AddCommand ("quit", Com_Quit_f);
- Cmd_AddCommand ("changeVectors", MSG_ReportChangeVectors_f );
- Cmd_AddCommand ("writeconfig", Com_WriteConfig_f );
- Cmd_SetCommandCompletionFunc( "writeconfig", Cmd_CompleteCfgName );
-
s = va("%s %s %s", Q3_VERSION, PLATFORM_STRING, __DATE__ );
com_version = Cvar_Get ("version", s, CVAR_ROM | CVAR_SERVERINFO );
diff --git a/src/qcommon/files.c b/src/qcommon/files.c
index db7e79d4..75686111 100644
--- a/src/qcommon/files.c
+++ b/src/qcommon/files.c
@@ -250,7 +250,6 @@ static int fs_loadCount; // total files read
static int fs_loadStack; // total files in memory
static int fs_packFiles; // total number of files in packs
-static int fs_fakeChkSum;
static int fs_checksumFeed;
typedef union qfile_gus {
@@ -1175,14 +1174,6 @@ int FS_FOpenFileRead( const char *filename, fileHandle_t *file, qboolean uniqueF
continue;
}
- if ( Q_stricmp( filename + l - 4, ".cfg" ) // for config files
- && Q_stricmp( filename + l - 5, ".menu" ) // menu files
- && Q_stricmp( filename + l - 5, ".game" ) // menu files
- && Q_stricmp( filename + l - strlen(demoExt), demoExt ) // menu files
- && Q_stricmp( filename + l - 4, ".dat" ) ) { // for journal files
- fs_fakeChkSum = random();
- }
-
Q_strncpyz( fsh[*file].name, filename, sizeof( fsh[*file].name ) );
fsh[*file].zipFile = qfalse;
if ( fs_debug->integer ) {
@@ -2994,10 +2985,6 @@ const char *FS_ReferencedPakPureChecksums( void ) {
numPaks++;
}
}
- if (fs_fakeChkSum != 0) {
- // only added if a non-pure file is referenced
- Q_strcat( info, sizeof( info ), va("%i ", fs_fakeChkSum ) );
- }
}
// last checksum is the encoded number of referenced pk3s
checksum ^= numPaks;
diff --git a/src/qcommon/msg.c b/src/qcommon/msg.c
index 3d3355ec..9893a65a 100644
--- a/src/qcommon/msg.c
+++ b/src/qcommon/msg.c
@@ -312,9 +312,9 @@ void MSG_WriteString( msg_t *sb, const char *s ) {
}
Q_strncpyz( string, s, sizeof( string ) );
- // get rid of 0xff chars, because old clients don't like them
+ // get rid of 0x80+ and '%' chars, because old clients don't like them
for ( i = 0 ; i < l ; i++ ) {
- if ( ((byte *)string)[i] > 127 ) {
+ if ( ((byte *)string)[i] > 127 || string[i] == '%' ) {
string[i] = '.';
}
}
@@ -338,9 +338,9 @@ void MSG_WriteBigString( msg_t *sb, const char *s ) {
}
Q_strncpyz( string, s, sizeof( string ) );
- // get rid of 0xff chars, because old clients don't like them
+ // get rid of 0x80+ and '%' chars, because old clients don't like them
for ( i = 0 ; i < l ; i++ ) {
- if ( ((byte *)string)[i] > 127 ) {
+ if ( ((byte *)string)[i] > 127 || string[i] == '%' ) {
string[i] = '.';
}
}
@@ -514,6 +514,21 @@ void MSG_ReadData( msg_t *msg, void *data, int len ) {
}
}
+// a string hasher which gives the same hash value even if the
+// string is later modified via the legacy MSG read/write code
+int MSG_HashKey(const char *string, int maxlen) {
+ int hash, i;
+
+ hash = 0;
+ for (i = 0; i < maxlen && string[i] != '\0'; i++) {
+ if (string[i] & 0x80 || string[i] == '%')
+ hash += '.' * (119 + i);
+ else
+ hash += string[i] * (119 + i);
+ }
+ hash = (hash ^ (hash >> 10) ^ (hash >> 20));
+ return hash;
+}
/*
=============================================================================
diff --git a/src/qcommon/q_shared.h b/src/qcommon/q_shared.h
index 59c5b91d..0cf4ca91 100644
--- a/src/qcommon/q_shared.h
+++ b/src/qcommon/q_shared.h
@@ -368,20 +368,20 @@ extern vec4_t colorMdGrey;
extern vec4_t colorDkGrey;
#define Q_COLOR_ESCAPE '^'
-#define Q_IsColorString(p) ( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && isalnum(*((p)+1)) ) // ^[0-9a-zA-Z]
+#define Q_IsColorString(p) ((p) && *(p) == Q_COLOR_ESCAPE && *((p)+1) && isalnum(*((p)+1))) // ^[0-9a-zA-Z]
-#define COLOR_BLACK '0'
-#define COLOR_RED '1'
-#define COLOR_GREEN '2'
+#define COLOR_BLACK '0'
+#define COLOR_RED '1'
+#define COLOR_GREEN '2'
#define COLOR_YELLOW '3'
-#define COLOR_BLUE '4'
-#define COLOR_CYAN '5'
+#define COLOR_BLUE '4'
+#define COLOR_CYAN '5'
#define COLOR_MAGENTA '6'
-#define COLOR_WHITE '7'
-#define ColorIndex(c) ( ( (c) - '0' ) & 7 )
+#define COLOR_WHITE '7'
+#define ColorIndex(c) (((c) - '0') & 0x07)
#define S_COLOR_BLACK "^0"
-#define S_COLOR_RED "^1"
+#define S_COLOR_RED "^1"
#define S_COLOR_GREEN "^2"
#define S_COLOR_YELLOW "^3"
#define S_COLOR_BLUE "^4"
diff --git a/src/qcommon/qcommon.h b/src/qcommon/qcommon.h
index bcfd60b9..d240c2d1 100644
--- a/src/qcommon/qcommon.h
+++ b/src/qcommon/qcommon.h
@@ -75,6 +75,7 @@ void MSG_WriteFloat (msg_t *sb, float f);
void MSG_WriteString (msg_t *sb, const char *s);
void MSG_WriteBigString (msg_t *sb, const char *s);
void MSG_WriteAngle16 (msg_t *sb, float f);
+int MSG_HashKey(const char *string, int maxlen);
void MSG_BeginReading (msg_t *sb);
void MSG_BeginReadingOOB(msg_t *sb);
@@ -786,7 +787,6 @@ void Com_Quit_f( void );
int Com_Milliseconds( void ); // will be journaled properly
unsigned Com_BlockChecksum( const void *buffer, int length );
char *Com_MD5File(const char *filename, int length, const char *prefix, int prefix_len);
-int Com_HashKey(char *string, int maxlen);
int Com_Filter(char *filter, char *name, int casesensitive);
int Com_FilterPath(char *filter, char *name, int casesensitive);
int Com_RealTime(qtime_t *qtime);
diff --git a/src/qcommon/vm_x86_64_assembler.c b/src/qcommon/vm_x86_64_assembler.c
index be295e3a..5747626a 100644
--- a/src/qcommon/vm_x86_64_assembler.c
+++ b/src/qcommon/vm_x86_64_assembler.c
@@ -593,7 +593,7 @@ static void emit_mov(const char* mnemonic, arg_t arg1, arg_t arg2, void* data)
crap("value too large for 16bit register");
emit1(0x66);
}
- else if(!arg2.v.reg & R_64)
+ else if(!(arg2.v.reg & R_64))
{
if(!isu32(arg1.v.imm))
crap("value too large for 32bit register");