From 48f7bb5ad1ffebc2038993659cba38ded945edf8 Mon Sep 17 00:00:00 2001 From: Andrei Drexler Date: Wed, 15 Nov 2023 21:02:23 +0100 Subject: [PATCH] Look for KEX savefiles in basedirs, not gamedir --- Quake/common.c | 24 ++++++++++++++++++++---- Quake/host_cmd.c | 29 +++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/Quake/common.c b/Quake/common.c index bd680cffb..cf4798716 100644 --- a/Quake/common.c +++ b/Quake/common.c @@ -2835,8 +2835,7 @@ static qboolean COM_PatchCmdLine (const char *fullpath) } else { - Con_SafePrintf ("File \"%s\" not in a mod dir, ignoring.\n", printpath); - return false; + game[0] = '\0'; } q_strlcpy (qpath, relpath, sizeof (qpath)); @@ -2865,8 +2864,16 @@ static qboolean COM_PatchCmdLine (const char *fullpath) // Map file if (q_strcasecmp (ext, "bsp") == 0) { + if (!game[0]) + { + Con_SafePrintf ("Map \"%s\" not in a mod dir, ignoring.\n", printpath); + return false; + } if (q_strncasecmp (qpath, "maps/", 5) != 0) + { + Con_SafePrintf ("Map \"%s\" not in the \"maps\" dir, ignoring.\n", printpath); return false; + } memmove (qpath, qpath + 5, strlen (qpath + 5) + 1); Cbuf_AddText (va ("menu_maps \"%s\"\n", qpath)); return true; @@ -2875,13 +2882,19 @@ static qboolean COM_PatchCmdLine (const char *fullpath) // Save file if (q_strcasecmp (ext, "sav") == 0) { - Cbuf_AddText (va ("load \"%s\"\n", qpath)); + const char *kex = game[0] ? "" : "kex"; + Cbuf_AddText (va ("load \"%s\" %s\n", qpath, kex)); return true; } // Demo file if (q_strcasecmp (ext, "dem") == 0) { + if (!game[0]) + { + Con_SafePrintf ("Demo \"%s\" not in a mod dir, ignoring.\n", printpath); + return false; + } Cbuf_AddText (va ("playdemo \"%s\"\n", qpath)); return true; } @@ -2893,7 +2906,10 @@ static qboolean COM_PatchCmdLine (const char *fullpath) break; } - Con_SafePrintf ("Unsupported file type \"%s\", ignoring.\n", printpath); + if (!game[0]) + Con_SafePrintf ("File \"%s\" not in a mod dir, ignoring.\n", printpath); + else + Con_SafePrintf ("Unsupported file type \"%s\", ignoring.\n", printpath); return false; } diff --git a/Quake/host_cmd.c b/Quake/host_cmd.c index 78c968d58..118fa9595 100644 --- a/Quake/host_cmd.c +++ b/Quake/host_cmd.c @@ -2472,11 +2472,12 @@ static void Host_Loadgame_f (void) int entnum; int version; float spawn_parms[NUM_SPAWN_PARMS]; + qboolean kexonly = false; if (cmd_source != src_command) return; - if (Cmd_Argc() != 2) + if (Cmd_Argc() < 2) { Con_Printf ("load : load a game\n"); return; @@ -2488,6 +2489,10 @@ static void Host_Loadgame_f (void) return; } + // When loading a file that doesn't belong to a mod dir we only accept KEX saves + if (Cmd_Argc () >= 3 && q_strcasecmp (Cmd_Argv (2), "kex") == 0) + kexonly = true; + if (nomonsters.value) { Con_Warning ("\"%s\" disabled automatically.\n", nomonsters.name); @@ -2500,6 +2505,21 @@ static void Host_Loadgame_f (void) COM_AddExtension (relname, ".sav", sizeof(relname)); q_snprintf (name, sizeof(name), "%s/%s", com_gamedir, relname); + + // Look for savefile in basedirs instead of gamedir + if (kexonly || !Sys_FileExists (name)) + { + for (i = com_numbasedirs - 1; i >= 0; i--) + { + q_snprintf (name, sizeof(name), "%s/%s", com_basedirs[i], relname); + if (Sys_FileExists (name)) + { + kexonly = true; + break; + } + } + } + if (!Sys_FileExists (name)) { Con_Printf ("ERROR: %s not found.\n", relname); @@ -2546,14 +2566,15 @@ static void Host_Loadgame_f (void) M_ToggleMenu_f (); } } - else if (version != SAVEGAME_VERSION) + else if (version != SAVEGAME_VERSION || kexonly) { + int expected = kexonly ? SAVEGAME_VERSION_KEX : SAVEGAME_VERSION; free (start); start = NULL; if (sv.autoloading) - Con_Printf ("ERROR: Savegame is version %i, not %i or %i\n", version, SAVEGAME_VERSION, SAVEGAME_VERSION_KEX); + Con_Printf ("ERROR: Savegame is version %i, not %i\n", version, expected); else - Host_Error ("Savegame is version %i, not %i or %i", version, SAVEGAME_VERSION, SAVEGAME_VERSION_KEX); + Host_Error ("Savegame is version %i, not %i", version, expected); Host_InvalidateSave (relname); SCR_EndLoadingPlaque (); return;