The engine hardcodes the names by default, but you can override it using an undocumented API:
struct TITLECOMMENT
{
const char* pBSPName;
const char* pTitleName;
};
TITLECOMMENT gTitleComments[] =
{
{"c1a1", "#C1A1TITLE"},
{"ba_yard", "#BA_YARDTITLE"}
//More title entries here
};
extern "C" void DLLEXPORT SV_SaveGameComment(char* pszBuffer, int iSizeBuffer);
extern "C" void SV_SaveGameComment(char* pszBuffer, int iSizeBuffer)
{
const char* mapName = STRING(gpGlobals->mapname);
const char* titleName = nullptr;
for (int i = 0; i < ARRAYSIZE(gTitleComments); ++i)
{
const size_t length = strlen(gTitleComments[i].pBSPName);
if (!strnicmp(mapName, gTitleComments[i].pBSPName, length))
{
titleName = gTitleComments[i].pTitleName;
if (titleName)
{
break;
}
}
}
if (!titleName)
{
titleName = mapName;
if (!titleName || !(*titleName))
{
edict_t* world = ENT(0);
//Use the full map name (e.g. "maps/c1a0.bsp").
//The engine uses the value it sends to clients (aka a variable used by client code) but this should always be valid here
//The engine sets the model field on worldspawn when it loads the map
titleName = STRING(world->v.model);
if (!strlen(titleName))
{
//The engine assigns mapName here again, but that's known to be either null or empty so to be sure this always assigns empty,
//since strncpy has undefined behavior for null src pointers
titleName = "";
}
}
}
strncpy(pszBuffer, titleName, iSizeBuffer - 1);
pszBuffer[iSizeBuffer - 1] = '\0';
}
This is basically the same as the engine implementation. The function SV_SaveGameComment is exported and looked for by the engine. It passes in a buffer that is to be filled with a localizable string that will be looked up in the game's
resource/<game>_<language>.txt
file.
For Blue Shift they changed the map naming pattern so multiple maps can use the same entry.
ba_yard
for example is used for
ba_yard1
,
ba_yard2
,
ba_yard3
,
ba_yard3a
,
ba_yard3b
,
ba_yard4
,
ba_yard4a
,
ba_yard5
and ,
ba_yard5a
. You can use this pattern but it's unlikely to be very helpful for most custom maps.
For Half-Life's English localization that's
resource/valve_english.txt
.
The maximum number of bytes that such a comment string can have is 79, plus a null terminator at the end.
If you have the game's source code you can add it there, best put next to the other exported functions in
cbase.h
and
cbase.cpp
. It can be made more flexible so as to allow any map to specify a non-localized name, or to map the name to some localizable string.
Otherwise you could modify Metamod-P and add the exported function to that instead. As long as the server dll doesn't implement the function the one exported by Metamod-P will be used.