]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - fs.c
Tell clients to reconnect before loading the next map. Should fix lag/stutter
[xonotic/darkplaces.git] / fs.c
diff --git a/fs.c b/fs.c
index a7074e5ff1f9f59b1b1861d34fe5fa766326cced..c15b8ba00f4f235225ea7c9a650903b5788104d4 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -343,9 +343,9 @@ FUNCTION PROTOTYPES
 =============================================================================
 */
 
-void FS_Dir_f(void);
-void FS_Ls_f(void);
-void FS_Which_f(void);
+void FS_Dir_f(cmd_state_t *cmd);
+void FS_Ls_f(cmd_state_t *cmd);
+void FS_Which_f(cmd_state_t *cmd);
 
 static searchpath_t *FS_FindFile (const char *name, int* index, qboolean quiet);
 static packfile_t* FS_AddFileToPack (const char* name, pack_t* pack,
@@ -382,9 +382,9 @@ char fs_gamedirs[MAX_GAMEDIRS][MAX_QPATH];
 gamedir_t *fs_all_gamedirs = NULL;
 int fs_all_gamedirs_count = 0;
 
-cvar_t scr_screenshot_name = {CVAR_NORESETTODEFAULTS, "scr_screenshot_name","dp", "prefix name for saved screenshots (changes based on -game commandline, as well as which game mode is running; the date is encoded using strftime escapes)"};
-cvar_t fs_empty_files_in_pack_mark_deletions = {0, "fs_empty_files_in_pack_mark_deletions", "0", "if enabled, empty files in a pak/pk3 count as not existing but cancel the search in further packs, effectively allowing patch pak/pk3 files to 'delete' files"};
-cvar_t cvar_fs_gamedir = {CVAR_READONLY | CVAR_NORESETTODEFAULTS, "fs_gamedir", "", "the list of currently selected gamedirs (use the 'gamedir' command to change this)"};
+cvar_t scr_screenshot_name = {CVAR_CLIENT | CVAR_NORESETTODEFAULTS, "scr_screenshot_name","dp", "prefix name for saved screenshots (changes based on -game commandline, as well as which game mode is running; the date is encoded using strftime escapes)"};
+cvar_t fs_empty_files_in_pack_mark_deletions = {CVAR_CLIENT | CVAR_SERVER, "fs_empty_files_in_pack_mark_deletions", "0", "if enabled, empty files in a pak/pk3 count as not existing but cancel the search in further packs, effectively allowing patch pak/pk3 files to 'delete' files"};
+cvar_t cvar_fs_gamedir = {CVAR_CLIENT | CVAR_SERVER | CVAR_READONLY | CVAR_NORESETTODEFAULTS, "fs_gamedir", "", "the list of currently selected gamedirs (use the 'gamedir' command to change this)"};
 
 
 /*
@@ -688,7 +688,7 @@ static int PK3_BuildFileList (pack_t *pack, const pk3_endOfCentralDir_t *eocd)
                // 1st uint8  : general purpose bit flag
                //    Check bits 0 (encryption), 3 (data descriptor after the file), and 5 (compressed patched data (?))
                //
-               // LordHavoc: bit 3 would be a problem if we were scanning the archive
+               // LadyHavoc: bit 3 would be a problem if we were scanning the archive
                // but is not a problem in the central directory where the values are
                // always real.
                //
@@ -976,7 +976,7 @@ FS_Path_f
 
 ============
 */
-static void FS_Path_f (void)
+static void FS_Path_f(cmd_state_t *cmd)
 {
        searchpath_t *s;
 
@@ -1212,7 +1212,7 @@ static qboolean FS_AddPack_Fullpath(const char *pakfile, const char *shortname,
        }
        else
        {
-               Con_Printf("unable to load pak \"%s\"\n", pakfile);
+               Con_Printf(CON_ERROR "unable to load pak \"%s\"\n", pakfile);
                return false;
        }
 }
@@ -1448,7 +1448,7 @@ void FS_Rescan (void)
 
        // -game <gamedir>
        // Adds basedir/gamedir as an override game
-       // LordHavoc: now supports multiple -game directories
+       // LadyHavoc: now supports multiple -game directories
        // set the com_modname (reported in server info)
        *gamedirbuf = 0;
        for (i = 0;i < fs_numgamedirs;i++)
@@ -1474,8 +1474,8 @@ void FS_Rescan (void)
        else
                Cvar_SetQuick (&scr_screenshot_name, gamescreenshotname);
        
-       if((i = COM_CheckParm("-modname")) && i < com_argc - 1)
-               strlcpy(com_modname, com_argv[i+1], sizeof(com_modname));
+       if((i = COM_CheckParm("-modname")) && i < sys.argc - 1)
+               strlcpy(com_modname, sys.argv[i+1], sizeof(com_modname));
 
        // If "-condebug" is in the command line, remove the previous log file
        if (COM_CheckParm ("-condebug") != 0)
@@ -1483,7 +1483,7 @@ void FS_Rescan (void)
 
        // look for the pop.lmp file and set registered to true if it is found
        if (FS_FileExists("gfx/pop.lmp"))
-               Cvar_Set ("registered", "1");
+               Cvar_SetValueQuick(&registered, 1);
        switch(gamemode)
        {
        case GAME_NORMAL:
@@ -1513,7 +1513,7 @@ void FS_Rescan (void)
        W_UnloadAll();
 }
 
-static void FS_Rescan_f(void)
+static void FS_Rescan_f(cmd_state_t *cmd)
 {
        FS_Rescan();
 }
@@ -1574,19 +1574,15 @@ qboolean FS_ChangeGameDirs(int numgamedirs, char gamedirs[][MAX_QPATH], qboolean
 
        if (cls.demoplayback)
        {
-               CL_Disconnect_f();
+               CL_Disconnect_f(&cmd_client);
                cls.demonum = 0;
        }
 
        // unload all sounds so they will be reloaded from the new files as needed
-       S_UnloadAllSounds_f();
-
-       // close down the video subsystem, it will start up again when the config finishes...
-       VID_Stop();
-       vid_opened = false;
+       S_UnloadAllSounds_f(&cmd_client);
 
        // restart the video subsystem after the config is executed
-       Cbuf_InsertText("\nloadconfig\nvid_restart\n\n");
+       Cbuf_InsertText(&cmd_client, "\nloadconfig\nvid_restart\n\n");
 
        return true;
 }
@@ -1596,13 +1592,13 @@ qboolean FS_ChangeGameDirs(int numgamedirs, char gamedirs[][MAX_QPATH], qboolean
 FS_GameDir_f
 ================
 */
-static void FS_GameDir_f (void)
+static void FS_GameDir_f(cmd_state_t *cmd)
 {
        int i;
        int numgamedirs;
        char gamedirs[MAX_GAMEDIRS][MAX_QPATH];
 
-       if (Cmd_Argc() < 2)
+       if (Cmd_Argc(cmd) < 2)
        {
                Con_Printf("gamedirs active:");
                for (i = 0;i < fs_numgamedirs;i++)
@@ -1611,7 +1607,7 @@ static void FS_GameDir_f (void)
                return;
        }
 
-       numgamedirs = Cmd_Argc() - 1;
+       numgamedirs = Cmd_Argc(cmd) - 1;
        if (numgamedirs > MAX_GAMEDIRS)
        {
                Con_Printf("Too many gamedirs (%i > %i)\n", numgamedirs, MAX_GAMEDIRS);
@@ -1619,7 +1615,7 @@ static void FS_GameDir_f (void)
        }
 
        for (i = 0;i < numgamedirs;i++)
-               strlcpy(gamedirs[i], Cmd_Argv(i+1), sizeof(gamedirs[i]));
+               strlcpy(gamedirs[i], Cmd_Argv(cmd, i+1), sizeof(gamedirs[i]));
 
        if ((cls.state == ca_connected && !cls.demoplayback) || sv.active)
        {
@@ -1765,11 +1761,11 @@ static void COM_InsertFlags(const char *buf) {
        const char **new_argv;
        int i = 0;
        int args_left = 256;
-       new_argv = (const char **)Mem_Alloc(fs_mempool, sizeof(*com_argv) * (com_argc + args_left + 2));
-       if(com_argc == 0)
+       new_argv = (const char **)Mem_Alloc(fs_mempool, sizeof(*sys.argv) * (sys.argc + args_left + 2));
+       if(sys.argc == 0)
                new_argv[0] = "dummy";  // Can't really happen.
        else
-               new_argv[0] = com_argv[0];
+               new_argv[0] = sys.argv[0];
        ++i;
        p = buf;
        while(COM_ParseToken_Console(&p))
@@ -1783,57 +1779,15 @@ static void COM_InsertFlags(const char *buf) {
                ++i;
        }
        // Now: i <= args_left + 1.
-       if (com_argc >= 1)
+       if (sys.argc >= 1)
        {
-               memcpy((char *)(&new_argv[i]), &com_argv[1], sizeof(*com_argv) * (com_argc - 1));
-               i += com_argc - 1;
+               memcpy((char *)(&new_argv[i]), &sys.argv[1], sizeof(*sys.argv) * (sys.argc - 1));
+               i += sys.argc - 1;
        }
-       // Now: i <= args_left + (com_argc || 1).
+       // Now: i <= args_left + (sys.argc || 1).
        new_argv[i] = NULL;
-       com_argv = new_argv;
-       com_argc = i;
-}
-
-/*
-================
-FS_Init_SelfPack
-================
-*/
-void FS_Init_SelfPack (void)
-{
-       PK3_OpenLibrary ();
-       fs_mempool = Mem_AllocPool("file management", 0, NULL);
-
-       // Load darkplaces.opt from the FS.
-       if (!COM_CheckParm("-noopt"))
-       {
-               char *buf = (char *) FS_SysLoadFile("darkplaces.opt", tempmempool, true, NULL);
-               if(buf)
-                       COM_InsertFlags(buf);
-               Mem_Free(buf);
-       }
-
-#ifndef USE_RWOPS
-       // Provide the SelfPack.
-       if (!COM_CheckParm("-noselfpack"))
-       {
-               if (com_selffd >= 0)
-               {
-                       fs_selfpack = FS_LoadPackPK3FromFD(com_argv[0], com_selffd, true);
-                       if(fs_selfpack)
-                       {
-                               FS_AddSelfPack();
-                               if (!COM_CheckParm("-noopt"))
-                               {
-                                       char *buf = (char *) FS_LoadFile("darkplaces.opt", tempmempool, true, NULL);
-                                       if(buf)
-                                               COM_InsertFlags(buf);
-                                       Mem_Free(buf);
-                               }
-                       }
-               }
-       }
-#endif
+       sys.argv = new_argv;
+       sys.argc = i;
 }
 
 static int FS_ChooseUserDir(userdirmode_t userdirmode, char *userdir, size_t userdirsize)
@@ -2007,12 +1961,21 @@ static int FS_ChooseUserDir(userdirmode_t userdirmode, char *userdir, size_t use
 #endif
 }
 
-/*
-================
-FS_Init
-================
-*/
-void FS_Init (void)
+void FS_Init_Commands(void)
+{
+       Cvar_RegisterVariable (&scr_screenshot_name);
+       Cvar_RegisterVariable (&fs_empty_files_in_pack_mark_deletions);
+       Cvar_RegisterVariable (&cvar_fs_gamedir);
+
+       Cmd_AddCommand(CMD_SHARED, "gamedir", FS_GameDir_f, "changes active gamedir list (can take multiple arguments), not including base directory (example usage: gamedir ctf)");
+       Cmd_AddCommand(CMD_SHARED, "fs_rescan", FS_Rescan_f, "rescans filesystem for new pack archives and any other changes");
+       Cmd_AddCommand(CMD_SHARED, "path", FS_Path_f, "print searchpath (game directories and archives)");
+       Cmd_AddCommand(CMD_SHARED, "dir", FS_Dir_f, "list files in searchpath matching an * filename pattern, one per line");
+       Cmd_AddCommand(CMD_SHARED, "ls", FS_Ls_f, "list files in searchpath matching an * filename pattern, multiple per line");
+       Cmd_AddCommand(CMD_SHARED, "which", FS_Which_f, "accepts a file name as argument and reports where the file is taken from");
+}
+
+static void FS_Init_Dir (void)
 {
        const char *p;
        int i;
@@ -2025,9 +1988,9 @@ void FS_Init (void)
        // Overrides the system supplied base directory (under GAMENAME)
 // COMMANDLINEOPTION: Filesystem: -basedir <path> chooses what base directory the game data is in, inside this there should be a data directory for the game (for example id1)
        i = COM_CheckParm ("-basedir");
-       if (i && i < com_argc-1)
+       if (i && i < sys.argc-1)
        {
-               strlcpy (fs_basedir, com_argv[i+1], sizeof (fs_basedir));
+               strlcpy (fs_basedir, sys.argv[i+1], sizeof (fs_basedir));
                i = (int)strlen (fs_basedir);
                if (i > 0 && (fs_basedir[i-1] == '\\' || fs_basedir[i-1] == '/'))
                        fs_basedir[i-1] = 0;
@@ -2041,10 +2004,10 @@ void FS_Init (void)
                dpsnprintf(fs_basedir, sizeof(fs_basedir), "/sdcard/%s/", gameuserdirname);
 #elif defined(MACOSX)
                // FIXME: is there a better way to find the directory outside the .app, without using Objective-C?
-               if (strstr(com_argv[0], ".app/"))
+               if (strstr(sys.argv[0], ".app/"))
                {
                        char *split;
-                       strlcpy(fs_basedir, com_argv[0], sizeof(fs_basedir));
+                       strlcpy(fs_basedir, sys.argv[0], sizeof(fs_basedir));
                        split = strstr(fs_basedir, ".app/");
                        if (split)
                        {
@@ -2078,8 +2041,8 @@ void FS_Init (void)
                strlcat(fs_basedir, "/", sizeof(fs_basedir));
 
        // Add the personal game directory
-       if((i = COM_CheckParm("-userdir")) && i < com_argc - 1)
-               dpsnprintf(fs_userdir, sizeof(fs_userdir), "%s/", com_argv[i+1]);
+       if((i = COM_CheckParm("-userdir")) && i < sys.argc - 1)
+               dpsnprintf(fs_userdir, sizeof(fs_userdir), "%s/", sys.argv[i+1]);
        else if (COM_CheckParm("-nohome"))
                *fs_userdir = 0; // user wants roaming installation, no userdir
        else
@@ -2138,32 +2101,32 @@ void FS_Init (void)
 
        p = FS_CheckGameDir(gamedirname1);
        if(!p || p == fs_checkgamedir_missing)
-               Con_Printf("WARNING: base gamedir %s%s/ not found!\n", fs_basedir, gamedirname1);
+               Con_Printf(CON_WARN "WARNING: base gamedir %s%s/ not found!\n", fs_basedir, gamedirname1);
 
        if(gamedirname2)
        {
                p = FS_CheckGameDir(gamedirname2);
                if(!p || p == fs_checkgamedir_missing)
-                       Con_Printf("WARNING: base gamedir %s%s/ not found!\n", fs_basedir, gamedirname2);
+                       Con_Printf(CON_WARN "WARNING: base gamedir %s%s/ not found!\n", fs_basedir, gamedirname2);
        }
 
        // -game <gamedir>
        // Adds basedir/gamedir as an override game
-       // LordHavoc: now supports multiple -game directories
-       for (i = 1;i < com_argc && fs_numgamedirs < MAX_GAMEDIRS;i++)
+       // LadyHavoc: now supports multiple -game directories
+       for (i = 1;i < sys.argc && fs_numgamedirs < MAX_GAMEDIRS;i++)
        {
-               if (!com_argv[i])
+               if (!sys.argv[i])
                        continue;
-               if (!strcmp (com_argv[i], "-game") && i < com_argc-1)
+               if (!strcmp (sys.argv[i], "-game") && i < sys.argc-1)
                {
                        i++;
-                       p = FS_CheckGameDir(com_argv[i]);
+                       p = FS_CheckGameDir(sys.argv[i]);
                        if(!p)
-                               Sys_Error("Nasty -game name rejected: %s", com_argv[i]);
+                               Sys_Error("Nasty -game name rejected: %s", sys.argv[i]);
                        if(p == fs_checkgamedir_missing)
-                               Con_Printf("WARNING: -game %s%s/ not found!\n", fs_basedir, com_argv[i]);
+                               Con_Printf(CON_WARN "WARNING: -game %s%s/ not found!\n", fs_basedir, sys.argv[i]);
                        // add the gamedir to the list of active gamedirs
-                       strlcpy (fs_gamedirs[fs_numgamedirs], com_argv[i], sizeof(fs_gamedirs[fs_numgamedirs]));
+                       strlcpy (fs_gamedirs[fs_numgamedirs], sys.argv[i], sizeof(fs_gamedirs[fs_numgamedirs]));
                        fs_numgamedirs++;
                }
        }
@@ -2175,18 +2138,69 @@ void FS_Init (void)
                fs_mutex = Thread_CreateMutex();
 }
 
-void FS_Init_Commands(void)
+/*
+================
+FS_Init_SelfPack
+================
+*/
+void FS_Init_SelfPack (void)
 {
-       Cvar_RegisterVariable (&scr_screenshot_name);
-       Cvar_RegisterVariable (&fs_empty_files_in_pack_mark_deletions);
-       Cvar_RegisterVariable (&cvar_fs_gamedir);
+       char *buf;
+
+       // Load darkplaces.opt from the FS.
+       if (!COM_CheckParm("-noopt"))
+       {
+               buf = (char *) FS_SysLoadFile("darkplaces.opt", tempmempool, true, NULL);
+               if(buf)
+               {
+                       COM_InsertFlags(buf);
+                       Mem_Free(buf);
+               }
+       }
+
+#ifndef USE_RWOPS
+       // Provide the SelfPack.
+       if (!COM_CheckParm("-noselfpack") && sys.selffd >= 0)
+       {
+               fs_selfpack = FS_LoadPackPK3FromFD(sys.argv[0], sys.selffd, true);
+               if(fs_selfpack)
+               {
+                       FS_AddSelfPack();
+                       if (!COM_CheckParm("-noopt"))
+                       {
+                               buf = (char *) FS_LoadFile("darkplaces.opt", tempmempool, true, NULL);
+                               if(buf)
+                               {
+                                       COM_InsertFlags(buf);
+                                       Mem_Free(buf);
+                               }
+                       }
+               }
+       }
+#endif
+}
+
+/*
+================
+FS_Init
+================
+*/
+
+void FS_Init(void)
+{
+       fs_mempool = Mem_AllocPool("file management", 0, NULL);
+
+       FS_Init_Commands();
+
+       PK3_OpenLibrary ();
+
+       // initialize the self-pack (must be before COM_InitGameType as it may add command line options)
+       FS_Init_SelfPack();
+
+       // detect gamemode from commandline options or executable name
+       COM_InitGameType();
 
-       Cmd_AddCommand ("gamedir", FS_GameDir_f, "changes active gamedir list (can take multiple arguments), not including base directory (example usage: gamedir ctf)");
-       Cmd_AddCommand ("fs_rescan", FS_Rescan_f, "rescans filesystem for new pack archives and any other changes");
-       Cmd_AddCommand ("path", FS_Path_f, "print searchpath (game directories and archives)");
-       Cmd_AddCommand ("dir", FS_Dir_f, "list files in searchpath matching an * filename pattern, one per line");
-       Cmd_AddCommand ("ls", FS_Ls_f, "list files in searchpath matching an * filename pattern, multiple per line");
-       Cmd_AddCommand ("which", FS_Which_f, "accepts a file name as argument and reports where the file is taken from");
+       FS_Init_Dir();
 }
 
 /*
@@ -2236,7 +2250,7 @@ static filedesc_t FS_SysOpenFiledesc(const char *filepath, const char *mode, qbo
                        opt = O_CREAT | O_APPEND;
                        break;
                default:
-                       Con_Printf ("FS_SysOpen(%s, %s): invalid mode\n", filepath, mode);
+                       Con_Printf(CON_ERROR "FS_SysOpen(%s, %s): invalid mode\n", filepath, mode);
                        return FILEDESC_INVALID;
        }
        for (ind = 1; mode[ind] != '\0'; ind++)
@@ -2253,7 +2267,7 @@ static filedesc_t FS_SysOpenFiledesc(const char *filepath, const char *mode, qbo
                                dolock = true;
                                break;
                        default:
-                               Con_Printf ("FS_SysOpen(%s, %s): unknown character in mode (%c)\n",
+                               Con_Printf(CON_ERROR "FS_SysOpen(%s, %s): unknown character in mode (%c)\n",
                                                        filepath, mode, mode[ind]);
                }
        }
@@ -2363,14 +2377,14 @@ static qfile_t *FS_OpenPackedFile (pack_t* pack, int pack_ind)
        // No Zlib DLL = no compressed files
        if (!zlib_dll && (pfile->flags & PACKFILE_FLAG_DEFLATED))
        {
-               Con_Printf("WARNING: can't open the compressed file %s\n"
+               Con_Printf(CON_WARN "WARNING: can't open the compressed file %s\n"
                                        "You need the Zlib DLL to use compressed files\n",
                                        pfile->name);
                return NULL;
        }
 #endif
 
-       // LordHavoc: FILEDESC_SEEK affects all duplicates of a handle so we do it before
+       // LadyHavoc: FILEDESC_SEEK affects all duplicates of a handle so we do it before
        // the dup() call to avoid having to close the dup_handle on error here
        if (FILEDESC_SEEK (pack->handle, pfile->offset, SEEK_SET) == -1)
        {
@@ -2835,7 +2849,7 @@ fs_offset_t FS_Write (qfile_t* file, const void* data, size_t datasize)
        {
                if (FILEDESC_SEEK (file->handle, file->buff_ind - file->buff_len, SEEK_CUR) == -1)
                {
-                       Con_Printf("WARNING: could not seek in %s.\n", file->filename);
+                       Con_Printf(CON_WARN "WARNING: could not seek in %s.\n", file->filename);
                }
        }
 
@@ -2843,7 +2857,7 @@ fs_offset_t FS_Write (qfile_t* file, const void* data, size_t datasize)
        FS_Purge (file);
 
        // Write the buffer and update the position
-       // LordHavoc: to hush a warning about passing size_t to an unsigned int parameter on Win64 we do this as multiple writes if the size would be too big for an integer (we never write that big in one go, but it's a theory)
+       // LadyHavoc: to hush a warning about passing size_t to an unsigned int parameter on Win64 we do this as multiple writes if the size would be too big for an integer (we never write that big in one go, but it's a theory)
        while (written < (fs_offset_t)datasize)
        {
                // figure out how much to write in one chunk
@@ -2877,7 +2891,7 @@ fs_offset_t FS_Read (qfile_t* file, void* buffer, size_t buffersize)
 {
        fs_offset_t count, done;
 
-       if (buffersize == 0)
+       if (buffersize == 0 || !buffer)
                return 0;
 
        // Get rid of the ungetc character
@@ -3242,9 +3256,9 @@ int FS_Seek (qfile_t* file, fs_offset_t offset, int whence)
        buffer = (unsigned char *)Mem_Alloc (tempmempool, buffersize);
 
        // Skip all data until we reach the requested offset
-       while (offset > file->position)
+       while (offset > (file->position - file->buff_len + file->buff_ind))
        {
-               fs_offset_t diff = offset - file->position;
+               fs_offset_t diff = offset - (file->position - file->buff_len + file->buff_ind);
                fs_offset_t count, len;
 
                count = (diff > buffersize) ? buffersize : diff;
@@ -3566,7 +3580,6 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
        stringlist_t dirlist;
        const char *slash, *backslash, *colon, *separator;
        char *basepath;
-       char temp[MAX_OSPATH];
 
        for (i = 0;pattern[i] == '.' || pattern[i] == ':' || pattern[i] == '/' || pattern[i] == '\\';i++)
                ;
@@ -3601,6 +3614,7 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
                        pak = searchpath->pack;
                        for (i = 0;i < pak->numfiles;i++)
                        {
+                               char temp[MAX_OSPATH];
                                strlcpy(temp, pak->files[i].name, sizeof(temp));
                                while (temp[0])
                                {
@@ -3684,6 +3698,7 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
 
                                // for each entry in matchedSet try to open the subdirectories specified in subpath
                                for( dirlistindex = 0 ; dirlistindex < matchedSet.numstrings ; dirlistindex++ ) {
+                                       char temp[MAX_OSPATH];
                                        strlcpy( temp, matchedSet.strings[ dirlistindex ], sizeof(temp) );
                                        strlcat( temp, subpath, sizeof(temp) );
                                        listdirectory( &foundSet, searchpath->filename, temp );
@@ -3707,17 +3722,17 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
 
                        for (dirlistindex = 0;dirlistindex < matchedSet.numstrings;dirlistindex++)
                        {
-                               const char *temp = matchedSet.strings[dirlistindex];
-                               if (matchpattern(temp, (char *)pattern, true))
+                               const char *matchtemp = matchedSet.strings[dirlistindex];
+                               if (matchpattern(matchtemp, (char *)pattern, true))
                                {
                                        for (resultlistindex = 0;resultlistindex < resultlist.numstrings;resultlistindex++)
-                                               if (!strcmp(resultlist.strings[resultlistindex], temp))
+                                               if (!strcmp(resultlist.strings[resultlistindex], matchtemp))
                                                        break;
                                        if (resultlistindex == resultlist.numstrings)
                                        {
-                                               stringlistappend(&resultlist, temp);
+                                               stringlistappend(&resultlist, matchtemp);
                                                if (!quiet && developer_loading.integer)
-                                                       Con_Printf("SearchDirFile: %s\n", temp);
+                                                       Con_Printf("SearchDirFile: %s\n", matchtemp);
                                        }
                                }
                        }
@@ -3828,43 +3843,43 @@ static int FS_ListDirectory(const char *pattern, int oneperline)
        return (int)numfiles;
 }
 
-static void FS_ListDirectoryCmd (const char* cmdname, int oneperline)
+static void FS_ListDirectoryCmd (cmd_state_t *cmd, const char* cmdname, int oneperline)
 {
        const char *pattern;
-       if (Cmd_Argc() >= 3)
+       if (Cmd_Argc(cmd) >= 3)
        {
                Con_Printf("usage:\n%s [path/pattern]\n", cmdname);
                return;
        }
-       if (Cmd_Argc() == 2)
-               pattern = Cmd_Argv(1);
+       if (Cmd_Argc(cmd) == 2)
+               pattern = Cmd_Argv(cmd, 1);
        else
                pattern = "*";
        if (!FS_ListDirectory(pattern, oneperline))
                Con_Print("No files found.\n");
 }
 
-void FS_Dir_f(void)
+void FS_Dir_f(cmd_state_t *cmd)
 {
-       FS_ListDirectoryCmd("dir", true);
+       FS_ListDirectoryCmd(cmd, "dir", true);
 }
 
-void FS_Ls_f(void)
+void FS_Ls_f(cmd_state_t *cmd)
 {
-       FS_ListDirectoryCmd("ls", false);
+       FS_ListDirectoryCmd(cmd, "ls", false);
 }
 
-void FS_Which_f(void)
+void FS_Which_f(cmd_state_t *cmd)
 {
        const char *filename;
        int index;
        searchpath_t *sp;
-       if (Cmd_Argc() != 2)
+       if (Cmd_Argc(cmd) != 2)
        {
-               Con_Printf("usage:\n%s <file>\n", Cmd_Argv(0));
+               Con_Printf("usage:\n%s <file>\n", Cmd_Argv(cmd, 0));
                return;
        }  
-       filename = Cmd_Argv(1);
+       filename = Cmd_Argv(cmd, 1);
        sp = FS_FindFile(filename, &index, true);
        if (!sp) {
                Con_Printf("%s isn't anywhere\n", filename);