Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Map Prefix Support #1

Open
MAGNAT2645 opened this issue Nov 30, 2020 · 2 comments
Open

[Suggestion] Map Prefix Support #1

MAGNAT2645 opened this issue Nov 30, 2020 · 2 comments

Comments

@MAGNAT2645
Copy link

MAGNAT2645 commented Nov 30, 2020

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
Copy link
Owner

nosoop commented Dec 5, 2020

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
Copy link
Author

MAGNAT2645 commented Dec 5, 2020

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();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants