Skip to content

Commit

Permalink
Look for KEX savefiles in basedirs, not gamedir
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-drexler committed Nov 15, 2023
1 parent a30008d commit 48f7bb5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
24 changes: 20 additions & 4 deletions Quake/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
29 changes: 25 additions & 4 deletions Quake/host_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <savename> : load a game\n");
return;
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 48f7bb5

Please sign in to comment.