From 0f05f00f998ea0df5695fa4597f7bfa36c229298 Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Tue, 30 Apr 2024 20:19:59 +1000 Subject: [PATCH] Misc gamedir-related fixes 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 --- cl_main.c | 2 +- cmd.h | 3 ++- common.c | 4 ++-- fs.c | 11 +++++------ host.c | 9 +++++---- menu.c | 2 +- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/cl_main.c b/cl_main.c index b4d7760c..7a40ad45 100644 --- 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 a94ddb16..9aa59adb 100644 --- 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 diff --git a/common.c b/common.c index f4e459af..f0f2fcce 100644 --- 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 df9cf04f..6e425971 100644 --- 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 // Adds basedir/gamedir as an override game // LadyHavoc: now supports multiple -game directories diff --git a/host.c b/host.c index 3f06d38e..7ce6406d 100644 --- 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 de4b1008..2c93c36b 100644 --- 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) -- 2.39.2