Chapter titles on save and load game screens in Half-Life mods Created 3 years ago2020-12-08 14:06:46 UTC by TheWolf TheWolf

Created 3 years ago2020-12-08 14:06:46 UTC by TheWolf TheWolf

Posted 3 years ago2020-12-08 14:06:46 UTC Post #345041
I love playing Half-Life's milions of mods, basically different experience every time. But one thing that always bothered me is that in save and load game screens the chapter titles are replaced with map names. So i want to ask how to make chapter titles in HL mods appear on those screens.
Here's what I mean: https://imgur.com/a/Wi3G7uS

BTW: this is my first time adding something on TWHL, so if I posted this in a wrong forum, then tell me and I'll move it.
Posted 3 years ago2020-12-08 14:24:35 UTC Post #345042
I'm pretty sure it's the "map description" setting in world properties that sets this for Half-Life 1 maps.
Dr. Orange Dr. OrangeSource good.
Posted 3 years ago2020-12-08 17:10:44 UTC Post #345043
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.
Posted 3 years ago2020-12-08 19:44:53 UTC Post #345044
In what file can i find it?
Posted 3 years ago2020-12-09 11:49:11 UTC Post #345047
The original function is in the engine so you won't find that.
You must be logged in to post a response.