Skip to content

Commit

Permalink
Allow loading mod maps only
Browse files Browse the repository at this point in the history
  • Loading branch information
L-P committed Jan 14, 2024
1 parent f37b24e commit 8005659
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,10 @@ static void LoadNextMap()
SERVER_COMMAND(UTIL_VarArgs("map \"%s\"\n", mapName.c_str()));
}

static void LoadAllMaps()
// If modOnly is set to false all maps from the base game plus the mod will be
// loaded. If set to true, only the maps present in the mod maps directory will
// be loaded.
static void LoadMaps(bool modOnly)
{
if (!g_MapsToLoad.empty())
{
Expand All @@ -809,7 +812,13 @@ static void LoadAllMaps()

FileFindHandle_t handle = FILESYSTEM_INVALID_FIND_HANDLE;

const char* fileName = g_pFileSystem->FindFirst("maps/*.bsp", &handle);
const char* fileName = nullptr;
if (modOnly) {
auto dir = std::string(FileSystem_GetModDirectoryName()) + "/maps/*.bsp";
fileName = g_pFileSystem->FindFirst(dir.c_str(), &handle);
} else {
fileName = g_pFileSystem->FindFirst("maps/*.bsp", &handle);
}

if (fileName != nullptr)
{
Expand Down Expand Up @@ -866,11 +875,23 @@ static void LoadAllMaps()
}
}

static void LoadModMaps()
{
LoadMaps(true);
}

static void LoadAllMaps()
{
LoadMaps(false);
}

void InitMapLoadingUtils()
{
g_engfuncs.pfnAddServerCommand("sv_load_mod_maps", &LoadModMaps);
g_engfuncs.pfnAddServerCommand("sv_load_all_maps", &LoadAllMaps);

// Escape hatch in case the command is executed in error.
g_engfuncs.pfnAddServerCommand("sv_stop_loading_all_maps", []()
g_engfuncs.pfnAddServerCommand("sv_stop_loading_maps", []()
{ g_MapsToLoad.clear(); });
}

Expand Down

0 comments on commit 8005659

Please sign in to comment.