Reimplemented ScriptVariable::entityValue

Some script events don't check if it's an actual entity, it would cause crashes.
E3L3 would crash after the player got out of the AB41: the AB41 was targetting a VehiclePoint and vehicles_thinkers.scr script set the `self.collisionent` to `self.target` which caused a crash as `VehiclePoint` doesn't inherit from `Entity`
This commit is contained in:
smallmodel 2024-05-01 20:41:39 +02:00
parent 170b4b0972
commit db01f72adc
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512

View file

@ -900,10 +900,30 @@ void ScriptVariable::SetKey(const short3& key)
#endif
Entity *ScriptVariable::entityValue(void)
Entity* ScriptVariable::entityValue(void)
{
#if defined(GAME_DLL)
return (Entity *)listenerValue();
Entity* ent;
switch (type) {
case VARIABLE_CONSTSTRING:
ent = static_cast<Entity*>(world->GetScriptTarget(Director.GetString(m_data.intValue)));
break;
case VARIABLE_STRING:
ent = static_cast<Entity*>(world->GetScriptTarget(stringValue()));
break;
case VARIABLE_LISTENER:
ent = static_cast<Entity*>(m_data.listenerValue->Pointer());
break;
default:
throw ScriptException("Cannot cast '%s' to entity", typenames[type]);
}
if (ent && !ent->isSubclassOf(Entity)) {
ScriptError("Cannot cast '%s' to entity", ent->getClassname());
}
return ent;
#else
return NULL;
#endif