diff --git a/sp/src/game/server/filters.cpp b/sp/src/game/server/filters.cpp index da5dd61f..704cf054 100644 --- a/sp/src/game/server/filters.cpp +++ b/sp/src/game/server/filters.cpp @@ -2157,118 +2157,125 @@ class CFilterScript : public CBaseFilter public: bool PassesFilterImpl( CBaseEntity *pCaller, CBaseEntity *pEntity ) { - if ( m_ScriptScope.IsInitialized() && g_Hook_PassesFilter.CanRunInScope( m_ScriptScope ) ) + if ( !m_ScriptScope.IsInitialized() ) + { + Warning( "%s: No script scope, cannot filter\n", GetDebugName() ); + return false; + } + + if ( g_Hook_PassesFilter.CanRunInScope( m_ScriptScope ) ) { // caller, activator ScriptVariant_t functionReturn; ScriptVariant_t args[] = { ToHScript( pCaller ), ToHScript( pEntity ) }; - if ( !g_Hook_PassesFilter.Call( m_ScriptScope, &functionReturn, args ) ) - { - Warning( "%s: No PassesFilter function\n", GetDebugName() ); - } + g_Hook_PassesFilter.Call( m_ScriptScope, &functionReturn, args ); return functionReturn.m_bool; } - Warning("%s: No script scope, cannot filter\n", GetDebugName()); + Warning( "%s: No PassesFilter function\n", GetDebugName() ); return false; } bool PassesDamageFilterImpl( CBaseEntity *pCaller, const CTakeDamageInfo &info ) { - if ( m_ScriptScope.IsInitialized() && g_Hook_PassesDamageFilter.CanRunInScope( m_ScriptScope ) ) + if ( !m_ScriptScope.IsInitialized() ) + { + Warning( "%s: No script scope, cannot filter\n", GetDebugName() ); + return false; + } + + if ( g_Hook_PassesDamageFilter.CanRunInScope( m_ScriptScope ) ) { HSCRIPT pInfo = g_pScriptVM->RegisterInstance( const_cast(&info) ); // caller, info ScriptVariant_t functionReturn; ScriptVariant_t args[] = { ToHScript( pCaller ), pInfo }; - if ( !g_Hook_PassesDamageFilter.Call( m_ScriptScope, &functionReturn, args ) ) - { - // Fall back to main filter function - g_pScriptVM->RemoveInstance( pInfo ); - return PassesFilterImpl( pCaller, info.GetAttacker() ); - } + g_Hook_PassesDamageFilter.Call( m_ScriptScope, &functionReturn, args ); g_pScriptVM->RemoveInstance( pInfo ); return functionReturn.m_bool; } - Warning("%s: No script scope, cannot filter\n", GetDebugName()); - return false; + // Fall back to main filter function + return PassesFilterImpl( pCaller, info.GetAttacker() ); } bool PassesFinalDamageFilter( CBaseEntity *pCaller, const CTakeDamageInfo &info ) { - if ( m_ScriptScope.IsInitialized() && g_Hook_PassesFinalDamageFilter.CanRunInScope( m_ScriptScope ) ) + if ( !m_ScriptScope.IsInitialized() ) + { + Warning( "%s: No script scope, cannot filter\n", GetDebugName() ); + return false; + } + + if ( g_Hook_PassesFinalDamageFilter.CanRunInScope( m_ScriptScope ) ) { HSCRIPT pInfo = g_pScriptVM->RegisterInstance( const_cast(&info) ); // caller, info ScriptVariant_t functionReturn; ScriptVariant_t args[] = { ToHScript( pCaller ), pInfo }; - if ( !g_Hook_PassesFinalDamageFilter.Call( m_ScriptScope, &functionReturn, args ) ) - { - g_pScriptVM->RemoveInstance( pInfo ); - return BaseClass::PassesFinalDamageFilter( pCaller, info ); - } + g_Hook_PassesFinalDamageFilter.Call( m_ScriptScope, &functionReturn, args ); g_pScriptVM->RemoveInstance( pInfo ); return functionReturn.m_bool; } - Warning("%s: No script scope, cannot filter\n", GetDebugName()); - return false; + return BaseClass::PassesFinalDamageFilter( pCaller, info ); } bool BloodAllowed( CBaseEntity *pCaller, const CTakeDamageInfo &info ) { - if ( m_ScriptScope.IsInitialized() && g_Hook_BloodAllowed.CanRunInScope( m_ScriptScope ) ) + if ( !m_ScriptScope.IsInitialized() ) + { + Warning( "%s: No script scope, cannot filter\n", GetDebugName() ); + return false; + } + + if ( g_Hook_BloodAllowed.CanRunInScope( m_ScriptScope ) ) { HSCRIPT pInfo = g_pScriptVM->RegisterInstance( const_cast(&info) ); // caller, info ScriptVariant_t functionReturn; ScriptVariant_t args[] = { ToHScript( pCaller ), pInfo }; - if ( !g_Hook_BloodAllowed.Call( m_ScriptScope, &functionReturn, args ) ) - { - g_pScriptVM->RemoveInstance( pInfo ); - return BaseClass::BloodAllowed( pCaller, info ); - } + g_Hook_BloodAllowed.Call( m_ScriptScope, &functionReturn, args ); g_pScriptVM->RemoveInstance( pInfo ); return functionReturn.m_bool; } - Warning("%s: No script scope, cannot filter\n", GetDebugName()); - return false; + return BaseClass::BloodAllowed( pCaller, info ); } bool DamageMod( CBaseEntity *pCaller, CTakeDamageInfo &info ) { - if ( m_ScriptScope.IsInitialized() && g_Hook_DamageMod.CanRunInScope( m_ScriptScope ) ) + if ( !m_ScriptScope.IsInitialized() ) + { + Warning( "%s: No script scope, cannot filter\n", GetDebugName() ); + return false; + } + + if ( g_Hook_DamageMod.CanRunInScope( m_ScriptScope ) ) { HSCRIPT pInfo = g_pScriptVM->RegisterInstance( &info ); // caller, info ScriptVariant_t functionReturn; ScriptVariant_t args[] = { ToHScript( pCaller ), pInfo }; - if ( !g_Hook_DamageMod.Call( m_ScriptScope, &functionReturn, args ) ) - { - g_pScriptVM->RemoveInstance( pInfo ); - return BaseClass::DamageMod( pCaller, info ); - } + g_Hook_DamageMod.Call( m_ScriptScope, &functionReturn, args ); g_pScriptVM->RemoveInstance( pInfo ); return functionReturn.m_bool; } - Warning("%s: No script scope, cannot filter\n", GetDebugName()); - return false; + return BaseClass::DamageMod( pCaller, info ); } };