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

Fix entity name matching #498

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TotallyMehis
Copy link

Entity name matching is broken with certain characters. For example, character 'X' will match to '8'. This will have unintended side-effects in the map logic. It worked fine in Source SDK 2006 because the comparison used tolower.
Problems caused by this is quite rare due to the fact that most maps use numbers and lowercase letters only.

Example of the problem:

#include <cstdio>

int main()
{
    auto badmatch = []( unsigned char cName, unsigned char cQuery ) {
        /* */if ( cName - 'A' <= (unsigned char)'Z' - 'A' && cName - 'A' + 'a' == cQuery )
            return true;
        else if ( cName - 'a' <= (unsigned char)'z' - 'a' && cName - 'a' + 'A' == cQuery )
            return true;
            
        return false;
    };
    
    auto goodmatch = []( unsigned char cName, unsigned char cQuery ) {
        /* */if ( (unsigned char)(cName - 'A') <= (unsigned char)('Z' - 'A') && (unsigned char)(cName - 'A' + 'a') == cQuery )
            return true;
        else if ( (unsigned char)(cName - 'a') <= (unsigned char)('z' - 'a') && (unsigned char)(cName - 'a' + 'A') == cQuery )
            return true;
            
        return false;
    };
    
    // Loop through all characters.
    for ( auto i = 0; i <= 255; i++ )
    {
        auto cQuery = (unsigned char)i;
        for ( auto j = 0; j <= 255; j++ )
        {
            auto cName = (unsigned char)j;
            
            if ( cName == cQuery )
                continue;
            
            if ( badmatch( cName, cQuery ) )
            //if ( goodmatch( cName, cQuery ) )
            {
                printf("%c (%x) matches %c (%x)\n", cName, cName, cQuery, cQuery );
            }
        }
    }
}

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

Successfully merging this pull request may close these issues.

1 participant