]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Misc gamedir-related fixes
authorbones_was_here <bones_was_here@xonotic.au>
Tue, 30 Apr 2024 10:19:59 +0000 (20:19 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Thu, 2 May 2024 21:02:37 +0000 (07:02 +1000)
Fixes two cvars being writable that shouldn't be.

Fixes MVM getgamedirinfo() builtin returning stale data (wasn't updated
by fs_rescan).

Fixes `startdemos` not working when changing to a mod that uses it,
after previously having had a map loaded.

Fixes `menu_main` being unavailable to quake.rc when changing to a mod
that uses it instead of `startdemos`.

Fixes `menu_restart` not performing the full MR_Init() (updates video
modes etc).

Fixes a race where it was possible to segfault by handling keyboard
events meant for MENU QC after MR_Shutdown() but before MR_Init() (by
calling directly instead of adding `menu_restart` to the cbuf).

Fixes an inconsistent extern declaration found by ubsan.

Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
cl_main.c
cmd.h
common.c
fs.c
host.c
menu.c

index b4d7760c328b40db27b44b224684aa11557fc521..7a40ad459df500fda4dc7f6d96b51e22edfd02b7 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -2800,7 +2800,7 @@ void CL_StartVideo(void)
 
 extern cvar_t host_framerate;
 extern cvar_t host_speeds;
-extern qbool serverlist_querystage;
+extern uint8_t serverlist_querystage;
 double CL_Frame (double time)
 {
        static double clframetime;
diff --git a/cmd.h b/cmd.h
index a94ddb16665d9fe91623af7fea8a5f5b91e79bbc..9aa59adbdc7140fba1388317aa9e40865ce3036c 100644 (file)
--- a/cmd.h
+++ b/cmd.h
@@ -218,7 +218,8 @@ void Cmd_Shutdown(void);
 
 /// called by Host_Init, this marks cvars, commands and aliases with their init values
 void Cmd_SaveInitState(void);
-/// called by FS_GameDir_f, this restores cvars, commands and aliases to init values
+/// Restores cvars, commands and aliases to their init values
+/// and deletes any that were added since init.
 void Cmd_RestoreInitState(void);
 
 /// called by the init functions of other parts of the program to
index f4e459af3e104d8a883a3a1447f86f19f044fa2a..f0f2fcce3842875b769c20b0f80e89e4f53439ac 100644 (file)
--- a/common.c
+++ b/common.c
@@ -29,8 +29,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "quakedef.h"
 #include "utf8lib.h"
 
-cvar_t registered = {CF_CLIENT | CF_SERVER, "registered","0", "indicates if this is running registered quake (whether gfx/pop.lmp was found)"};
-cvar_t cmdline = {CF_CLIENT | CF_SERVER, "cmdline","0", "contains commandline the engine was launched with"};
+cvar_t registered = {CF_CLIENT | CF_SERVER | CF_READONLY, "registered","0", "indicates if this is running registered quake (whether gfx/pop.lmp was found)"};
+cvar_t cmdline = {CF_CLIENT | CF_SERVER | CF_READONLY, "cmdline","0", "contains commandline the engine was launched with"};
 
 // FIXME: Find a better place for these.
 cvar_t cl_playermodel = {CF_CLIENT | CF_SERVER | CF_USERINFO | CF_ARCHIVE, "playermodel", "", "current player model in Nexuiz/Xonotic"};
diff --git a/fs.c b/fs.c
index df9cf04fdbe929b1073cd38f5da0a3ce9685c841..6e4259717b0c3ffbd733557a995f23d0ece5e296 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -1541,12 +1541,15 @@ static void FS_AddSelfPack(void)
 FS_Rescan
 ================
 */
+static void FS_ListGameDirs(void);
 void FS_Rescan (void)
 {
        int i;
        char gamedirbuf[MAX_INPUTLINE];
        char vabuf[1024];
 
+       FS_ListGameDirs();
+
        FS_ClearSearchPath();
 
        // update the com_modname (used for server info)
@@ -1732,10 +1735,8 @@ qbool FS_ChangeGameDirs(int numgamedirs, const char *gamedirs[], qbool failmissi
        Host_SaveConfig(CONFIGFILENAME);
 
        if (cls.demoplayback)
-       {
                CL_Disconnect();
-               cls.demonum = 0;
-       }
+       cls.demonum = 0; // make sure startdemos will work if the mod uses it
 
        // unload all sounds so they will be reloaded from the new files as needed
        S_UnloadAllSounds_f(cmd_local);
@@ -1744,7 +1745,7 @@ qbool FS_ChangeGameDirs(int numgamedirs, const char *gamedirs[], qbool failmissi
        FS_Rescan();
 
        // reload assets after the config is executed
-       Cbuf_InsertText(cmd_local, "\nloadconfig\n");
+       Cbuf_InsertText(cmd_local, "\nloadconfig\nr_restart\n");
 
        return true;
 }
@@ -2261,8 +2262,6 @@ static void FS_Init_Dir (void)
        if (!strcmp(fs_basedir, fs_userdir))
                fs_userdir[0] = 0;
 
-       FS_ListGameDirs();
-
        // -game <gamedir>
        // Adds basedir/gamedir as an override game
        // LadyHavoc: now supports multiple -game directories
diff --git a/host.c b/host.c
index 3f06d38e8ead78a23507cd5424575a62bc7e399c..7ce6406d21faeee15b6749d5b9ba9b0431b8d565 100644 (file)
--- a/host.c
+++ b/host.c
@@ -252,12 +252,13 @@ static void Host_LoadConfig_f(cmd_state_t *cmd)
        // Xonotic QC complains/breaks if its cvars are deleted before its m_shutdown() is called
        if(MR_Shutdown)
                MR_Shutdown();
-       // append a menu restart command to execute after the config
-       Cbuf_AddText(cmd, "\nmenu_restart\n");
 #endif
-       // reset all cvars, commands and aliases to init values
        Cmd_RestoreInitState();
-       // reset cvars to their defaults, and then exec startup scripts again
+#ifdef CONFIG_MENU
+       // Must re-add menu.c commands or load menu.dat before executing quake.rc or handling events
+       MR_Init();
+#endif
+       // exec startup scripts again
        Host_AddConfigText(cmd);
 }
 
diff --git a/menu.c b/menu.c
index de4b100817e8d52d94c419db7b4ac77965ecf1e9..2c93c36b9ca9035ed356f69935175f2d80b83148 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -5477,7 +5477,7 @@ void MR_Restart(void)
 {
        if(MR_Shutdown)
                MR_Shutdown ();
-       MR_SetRouting (false);
+       MR_Init();
 }
 
 static void MR_Restart_f(cmd_state_t *cmd)