Fixed filter_script not functioning properly

This commit is contained in:
Blixibon 2022-07-24 19:21:05 -05:00
parent 636898fd79
commit 0cf49fbfa0

View File

@ -2157,118 +2157,125 @@ class CFilterScript : public CBaseFilter
public: public:
bool PassesFilterImpl( CBaseEntity *pCaller, CBaseEntity *pEntity ) 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 // caller, activator
ScriptVariant_t functionReturn; ScriptVariant_t functionReturn;
ScriptVariant_t args[] = { ToHScript( pCaller ), ToHScript( pEntity ) }; ScriptVariant_t args[] = { ToHScript( pCaller ), ToHScript( pEntity ) };
if ( !g_Hook_PassesFilter.Call( m_ScriptScope, &functionReturn, args ) ) g_Hook_PassesFilter.Call( m_ScriptScope, &functionReturn, args );
{
Warning( "%s: No PassesFilter function\n", GetDebugName() );
}
return functionReturn.m_bool; return functionReturn.m_bool;
} }
Warning("%s: No script scope, cannot filter\n", GetDebugName()); Warning( "%s: No PassesFilter function\n", GetDebugName() );
return false; return false;
} }
bool PassesDamageFilterImpl( CBaseEntity *pCaller, const CTakeDamageInfo &info ) 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<CTakeDamageInfo*>(&info) ); HSCRIPT pInfo = g_pScriptVM->RegisterInstance( const_cast<CTakeDamageInfo*>(&info) );
// caller, info // caller, info
ScriptVariant_t functionReturn; ScriptVariant_t functionReturn;
ScriptVariant_t args[] = { ToHScript( pCaller ), pInfo }; ScriptVariant_t args[] = { ToHScript( pCaller ), pInfo };
if ( !g_Hook_PassesDamageFilter.Call( m_ScriptScope, &functionReturn, args ) ) g_Hook_PassesDamageFilter.Call( m_ScriptScope, &functionReturn, args );
{
// Fall back to main filter function
g_pScriptVM->RemoveInstance( pInfo );
return PassesFilterImpl( pCaller, info.GetAttacker() );
}
g_pScriptVM->RemoveInstance( pInfo ); g_pScriptVM->RemoveInstance( pInfo );
return functionReturn.m_bool; return functionReturn.m_bool;
} }
Warning("%s: No script scope, cannot filter\n", GetDebugName()); // Fall back to main filter function
return false; return PassesFilterImpl( pCaller, info.GetAttacker() );
} }
bool PassesFinalDamageFilter( CBaseEntity *pCaller, const CTakeDamageInfo &info ) 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<CTakeDamageInfo*>(&info) ); HSCRIPT pInfo = g_pScriptVM->RegisterInstance( const_cast<CTakeDamageInfo*>(&info) );
// caller, info // caller, info
ScriptVariant_t functionReturn; ScriptVariant_t functionReturn;
ScriptVariant_t args[] = { ToHScript( pCaller ), pInfo }; ScriptVariant_t args[] = { ToHScript( pCaller ), pInfo };
if ( !g_Hook_PassesFinalDamageFilter.Call( m_ScriptScope, &functionReturn, args ) ) g_Hook_PassesFinalDamageFilter.Call( m_ScriptScope, &functionReturn, args );
{
g_pScriptVM->RemoveInstance( pInfo );
return BaseClass::PassesFinalDamageFilter( pCaller, info );
}
g_pScriptVM->RemoveInstance( pInfo ); g_pScriptVM->RemoveInstance( pInfo );
return functionReturn.m_bool; return functionReturn.m_bool;
} }
Warning("%s: No script scope, cannot filter\n", GetDebugName()); return BaseClass::PassesFinalDamageFilter( pCaller, info );
return false;
} }
bool BloodAllowed( CBaseEntity *pCaller, const CTakeDamageInfo &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<CTakeDamageInfo*>(&info) ); HSCRIPT pInfo = g_pScriptVM->RegisterInstance( const_cast<CTakeDamageInfo*>(&info) );
// caller, info // caller, info
ScriptVariant_t functionReturn; ScriptVariant_t functionReturn;
ScriptVariant_t args[] = { ToHScript( pCaller ), pInfo }; ScriptVariant_t args[] = { ToHScript( pCaller ), pInfo };
if ( !g_Hook_BloodAllowed.Call( m_ScriptScope, &functionReturn, args ) ) g_Hook_BloodAllowed.Call( m_ScriptScope, &functionReturn, args );
{
g_pScriptVM->RemoveInstance( pInfo );
return BaseClass::BloodAllowed( pCaller, info );
}
g_pScriptVM->RemoveInstance( pInfo ); g_pScriptVM->RemoveInstance( pInfo );
return functionReturn.m_bool; return functionReturn.m_bool;
} }
Warning("%s: No script scope, cannot filter\n", GetDebugName()); return BaseClass::BloodAllowed( pCaller, info );
return false;
} }
bool DamageMod( CBaseEntity *pCaller, CTakeDamageInfo &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 ); HSCRIPT pInfo = g_pScriptVM->RegisterInstance( &info );
// caller, info // caller, info
ScriptVariant_t functionReturn; ScriptVariant_t functionReturn;
ScriptVariant_t args[] = { ToHScript( pCaller ), pInfo }; ScriptVariant_t args[] = { ToHScript( pCaller ), pInfo };
if ( !g_Hook_DamageMod.Call( m_ScriptScope, &functionReturn, args ) ) g_Hook_DamageMod.Call( m_ScriptScope, &functionReturn, args );
{
g_pScriptVM->RemoveInstance( pInfo );
return BaseClass::DamageMod( pCaller, info );
}
g_pScriptVM->RemoveInstance( pInfo ); g_pScriptVM->RemoveInstance( pInfo );
return functionReturn.m_bool; return functionReturn.m_bool;
} }
Warning("%s: No script scope, cannot filter\n", GetDebugName()); return BaseClass::DamageMod( pCaller, info );
return false;
} }
}; };