nosoop / SM-LevelKeyValuesStripper

Stripper:Source port to Level KeyValues.
GNU General Public License v3.0
6 stars 2 forks source link

[Suggestion] Map Prefix Support #1

Open MAGNAT2645 opened 3 years ago

MAGNAT2645 commented 3 years ago

Would be good to have map prefix support, so we don't have to put most stuff in global_filters.cfg and just use configs like koth_.cfg (any koth maps), ctf_covid19_.cfg (any version of ctf_covid19) etc.

In my case, i want to play FF2 on koth maps, so i put:

modify:
{
    match:
    {
    "classname" "tf_logic_koth"
    }
    replace:
    {
    "classname" "tf_logic_arena"
    }
}

into global_filters. BUT i have cp_sulfur map which is koth + cp hybrid so that map has tf_logic_koth. Stripper replaces it to arena mode too but i don't want arena on cp_sulfur.

For now i have this workaround: addons/stripper/maps/cp_sulfur_rc2.cfg

modify:
{
    match:
    {
    "classname" "tf_logic_arena"
    }
    replace:
    {
    "classname" "tf_logic_koth"
    }
}
nosoop commented 3 years ago

Good idea. Don't have any reason for me to implement and test it myself, but I'd be happy to take the PR for it.

If you'd like to give this a try, I have a function for prefix-based file detection in use here, which can then be injected at this location in the plugin.

MAGNAT2645 commented 3 years ago

There's also a code from MapConfig with prefix support:

#define CONFIG_DIR "sourcemod/map-cfg/"

void ExecuteMapSpecificConfigs() {
    char szConfigFile[PLATFORM_MAX_PATH];
    ArrayList hConfigs = new ArrayList( PLATFORM_MAX_PATH );

    {
        char szCurrentMap[PLATFORM_MAX_PATH];
        GetCurrentMap( szCurrentMap, sizeof szCurrentMap );

        {
            int iMapSepPos = FindCharInString( szCurrentMap, '/', true );
            if ( iMapSepPos != -1 )
                strcopy( szCurrentMap, sizeof szCurrentMap, szCurrentMap[iMapSepPos + 1] );
        }

        LogMessage( "Searching specific configs for %s", szCurrentMap );

        DirectoryListing hDir = OpenDirectory( "cfg/" ... CONFIG_DIR );
        if ( hDir == null ) {
            LogError( "Error iterating folder cfg/" ... CONFIG_DIR ... ", folder doesn't exist !" );
            return;
        }

        char szExplode[2][64];
        FileType nFileType;

        while ( hDir.GetNext( szConfigFile, sizeof szConfigFile, nFileType ) ) {
            if ( nFileType != FileType_File )
                continue;

            ExplodeString( szConfigFile, ".", szExplode, 2, sizeof szExplode[] );

            if ( strcmp( szExplode[1], "cfg", false ) == 0 ) {
                if ( strncmp( szCurrentMap, szExplode, strlen( szExplode ), false ) == 0 )
                    hConfigs.PushString( szConfigFile );
            }
        }

        hDir.Close();
    }

    hConfigs.Sort( Sort_Ascending, Sort_String );

    for ( int i = 0, size = hConfigs.Length; i < size; i++ ) {
        hConfigs.GetString( i, szConfigFile, sizeof szConfigFile );
        LogMessage( "Executing map specific config: %s", szConfigFile );
        ServerCommand( "exec " ... CONFIG_DIR ... "%s", szConfigFile );
    }

    hConfigs.Close();
}