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

speaker entity does not handle invalid preset values correctly #3178

Open
SamVanheer opened this issue Nov 30, 2021 · 0 comments
Open

speaker entity does not handle invalid preset values correctly #3178

SamVanheer opened this issue Nov 30, 2021 · 0 comments

Comments

@SamVanheer
Copy link

The speaker entity has a keyvalue preset used to select a predefined sound to play. The code to select this preset does not handle invalid values and will leave the sound name pointer uninitialized:

halflife/dlls/sound.cpp

Lines 1873 to 1894 in c7240b9

if (m_preset)
{
// go lookup preset text, assign szSoundFile
switch (m_preset)
{
case 1: szSoundFile = "C1A0_"; break;
case 2: szSoundFile = "C1A1_"; break;
case 3: szSoundFile = "C1A2_"; break;
case 4: szSoundFile = "C1A3_"; break;
case 5: szSoundFile = "C1A4_"; break;
case 6: szSoundFile = "C2A1_"; break;
case 7: szSoundFile = "C2A2_"; break;
case 8: szSoundFile = "C2A3_"; break;
case 9: szSoundFile = "C2A4_"; break;
case 10: szSoundFile = "C2A5_"; break;
case 11: szSoundFile = "C3A1_"; break;
case 12: szSoundFile = "C3A2_"; break;
}
} else
szSoundFile = (char*) STRING(pev->message);
if (szSoundFile[0] == '!')

To fix this an additional case is required:

if (m_preset)
{
	// go lookup preset text, assign szSoundFile
	switch (m_preset)
	{
	case 1: szSoundFile =  "C1A0_"; break;
	case 2: szSoundFile =  "C1A1_"; break;
	case 3: szSoundFile =  "C1A2_"; break;
	case 4: szSoundFile =  "C1A3_"; break;
	case 5: szSoundFile =  "C1A4_"; break; 
	case 6: szSoundFile =  "C2A1_"; break;
	case 7: szSoundFile =  "C2A2_"; break;
	case 8: szSoundFile =  "C2A3_"; break;
	case 9: szSoundFile =  "C2A4_"; break;
	case 10: szSoundFile = "C2A5_"; break;
	case 11: szSoundFile = "C3A1_"; break;
	case 12: szSoundFile = "C3A2_"; break;
	default: szSoundFile = ""; break;
	}
}
else
	szSoundFile = (char*) STRING(pev->message);

Initializing it to an empty string will cause it to enter this branch:

halflife/dlls/sound.cpp

Lines 1903 to 1915 in c7240b9

else
{
// make random announcement from sentence group
if (SENTENCEG_PlayRndSz(ENT(pev), szSoundFile, flvolume, flattenuation, flags, pitch) < 0)
ALERT(at_console, "Level Design Error!\nSPEAKER has bad sentence group name: %s\n",szSoundFile);
// set next announcement time for random 5 to 10 minute delay
pev->nextthink = gpGlobals->time +
RANDOM_FLOAT(ANNOUNCE_MINUTES_MIN * 60.0, ANNOUNCE_MINUTES_MAX * 60.0);
CTalkMonster::g_talkWaitTime = gpGlobals->time + 5; // time delay until it's ok to speak: used so that two NPCs don't talk at once
}

Since there is no way for there to be a sentence group with an empty name nothing will be played and the error message in the code above will be printed.

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

No branches or pull requests

2 participants