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

TextDrawCreate/SetString, GameTextForPlayer/All last character as space #55

Closed
IstuntmanI opened this issue Jul 21, 2017 · 1 comment
Closed

Comments

@IstuntmanI
Copy link
Contributor

IstuntmanI commented Jul 21, 2017

  • Problem:

From the TextDrawCreate wiki page:

If the last character in the text is a space (" "), the text will all be blank.

It also happens for gametexts. Not sure if it happens in TextDrawSetString too (probably does).

  • Possible solution/implementation:

Hook TextDrawCreate/TextDrawSetString/GameTextForPlayer/GameTextForAll and let them look like

stock ALS_HookedFunction( [..,] text[ ] [, ..] )
{
	if( text[ 0 ] != EOS && text[ 1 ] != EOS )
	{
		new lLastPos = 0;

		for( new i = 1; text[ i ] != EOS; i ++ )
		{
			if( text[ i ] != ' ' )
				lLastPos = i;
		}

		text[ lLastPos + 1 ] = EOS;
	}

	return HookedFunction( [..,] text [, ..] );
}

I think that I also managed to allow " " as a valid text. Maybe someone can come with a better/shorter alternative, if possible. I didn't use strlen because the code would be slower. Here are the tests:

'' -> ''
' ' -> ' '
'a' -> 'a'
'a ' -> 'a'
'ab' -> 'ab'
'ab ' -> 'ab'
'a   b' -> 'a   b'
'a   b ' -> 'a   b'
'a   b   ' -> 'a   b'
@Y-Less
Copy link
Member

Y-Less commented Jul 22, 2017

I'm not concinced strlen would be slower - use it to find the end and work backwards. You are already going through the whole string, why not do it in C instead?

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

3 participants