void RadarHackBlocker::RT_ProcessOnTick ( float const curtime )
{
	ProcessFilter::HumanAtLeastConnectedOrBot const filter_class;

	for( PlayerHandler::const_iterator ph ( &filter_class ); ph != PlayerHandler::end (); ph += &filter_class )
	{
		int const index ( ph.GetIndex () );

		ClientRadarData * pData ( GetPlayerDataStructByIndex ( index ) );

		if( pData->m_last_spotted_status )
		{
			RT_UpdatePlayerData ( *ph );
			RT_ProcessEntity ( ph->GetEdict () );
		}
		else
		{
			if( curtime > m_next_process )
			{
				RT_UpdatePlayerData ( *ph );
				RT_ProcessEntity ( ph->GetEdict () );
			}
		}
	}

	if( curtime > m_next_process )
	{
		m_next_process = curtime + 2.0f;
	}
}
Exemple #2
0
//---------------------------------------------------------------------------------
// Purpose: called when the plugin is unpaused (i.e should start executing again)
//---------------------------------------------------------------------------------
void CNoCheatZPlugin::UnPause ( void )
{
	GlobalTimer::GetInstance ()->EnterSection ();

	Logger::GetInstance ()->Msg<MSG_CONSOLE> ( "Unpausing ..." );
	BaseSystem::InitSystems ();
	BanRequest::GetInstance ()->Init ();

	NczPlayerManager::GetInstance ()->LoadPlayerManager (); // Mark any present player as PLAYER_CONNECTED

	SourceSdk::InterfacesProxy::Call_ServerExecute ();
	SourceSdk::InterfacesProxy::Call_ServerCommand ( "exec nocheatz.cfg\n" );
	SourceSdk::InterfacesProxy::Call_ServerExecute ();

	for( int i ( 1 ); i < MAX_PLAYERS; ++i )
	{
		PlayerHandler::const_iterator ph ( NczPlayerManager::GetInstance ()->GetPlayerHandlerByIndex ( i ) );
		if( ph >= SlotStatus::BOT )
		{
			HookEntity ( ph->GetEdict () );
			WeaponHookListener::HookWeapon ( ph );

			if( ph >= SlotStatus::PLAYER_CONNECTED )
			{
				HookBasePlayer ( ph );
			}
		}
	}
	BaseSystem::ManageSystems ();

	Logger::GetInstance ()->Msg<MSG_CHAT> ( "Plugin unpaused" );
}
void RadarHackBlocker::RT_ThinkPostCallback ( SourceSdk::edict_t const * const pent )
{
	ProcessFilter::HumanAtLeastConnectedOrBot const filter_class;

	for( PlayerHandler::const_iterator ph ( &filter_class ); ph != PlayerHandler::end (); ph += &filter_class )
	{
		int const index ( ph.GetIndex () );
		ClientRadarData * pData ( GetPlayerDataStructByIndex ( index ) );
		if( pData->m_last_spotted_status != m_players_spotted[ index ] )
		{
			pData->m_last_spotted_status = m_players_spotted[ index ];

			if( pData->m_last_spotted_status )
			{
				RT_UpdatePlayerData ( *ph );
				RT_ProcessEntity ( ph->GetEdict () );
			}
			else
			{
				//pData->m_next_update = curtime + 1.0f;
				//UpdatePlayerData(ph->playerClass);
				//ProcessEntity(Helpers::PEntityOfEntIndex(x));
			}
		}
	}
}
void OnGroundHookListener::HookOnGround ( PlayerHandler::const_iterator ph )
{
	Assert ( Helpers::isValidEdict ( ph->GetEdict () ) );
	void* unk ( ph->GetEdict ()->m_pUnk );

	HookInfo info ( unk, ConfigManager::GetInstance ()->vfid_mhgroundentity, ( DWORD ) RT_nNetworkStateChanged_m_hGroundEntity );
	HookGuard<OnGroundHookListener>::GetInstance ()->VirtualTableHook ( info );
}
void EyeAnglesTester::FireGameEvent ( SourceSdk::IGameEvent *ev ) // round_end
{
	ProcessFilter::HumanAtLeastConnected filter_class;
	for( PlayerHandler::const_iterator ph ( &filter_class ); ph != PlayerHandler::end (); ph+=&filter_class )
	{
		++( GetPlayerDataStructByIndex ( ph.GetIndex () )->ignore_last );
	}
}
void AutoAttackTester::Load ()
{
	for( PlayerHandler::const_iterator it ( PlayerHandler::begin () ); it != PlayerHandler::end (); ++it )
	{
		ResetPlayerDataStructByIndex ( it.GetIndex () );
	}

	PlayerRunCommandHookListener::RegisterPlayerRunCommandHookListener ( this, SystemPriority::UserCmdHookListener::AutoAttackTester );
}
void WeaponHookListener::HookWeapon ( PlayerHandler::const_iterator ph )
{
	LoggerAssert ( Helpers::isValidEdict ( ph->GetEdict () ) );
	void* unk ( ph->GetEdict ()->m_pUnk );

	HookInfo info_equip ( unk, ConfigManager::GetInstance ()->vfid_weaponequip, ( DWORD ) RT_nWeapon_Equip );
	HookInfo info_drop ( unk, ConfigManager::GetInstance ()->vfid_weapondrop, ( DWORD ) RT_nWeapon_Drop );
	HookGuard<WeaponHookListener>::GetInstance ()->VirtualTableHook ( info_equip );
	HookGuard<WeaponHookListener>::GetInstance ()->VirtualTableHook ( info_drop );
}
void EyeAnglesTester::Load ()
{
	for( PlayerHandler::const_iterator it ( PlayerHandler::begin () ); it != PlayerHandler::end (); ++it )
	{
		ResetPlayerDataStructByIndex ( it.GetIndex () );
	}

	SourceSdk::InterfacesProxy::GetGameEventManager ()->AddListener ( this, "round_end", true );
	PlayerRunCommandHookListener::RegisterPlayerRunCommandHookListener ( this, SystemPriority::UserCmdHookListener::EyeAnglesTester );
}
void AntiSmokeBlocker::Load ()
{
	for( PlayerHandler::const_iterator it ( PlayerHandler::begin () ); it != PlayerHandler::end (); ++it )
	{
		ResetPlayerDataStructByIndex ( it.GetIndex () );
	}

	SourceSdk::InterfacesProxy::GetGameEventManager ()->AddListener ( this, "smokegrenade_detonate", true );
	SourceSdk::InterfacesProxy::GetGameEventManager ()->AddListener ( this, "round_start", true );
	OnTickListener::RegisterOnTickListener ( this );
	SetTransmitHookListener::RegisterSetTransmitHookListener ( this, 1 );
}
bool AntiSmokeBlocker::RT_SetTransmitCallback ( PlayerHandler::const_iterator sender, PlayerHandler::const_iterator receiver )
{
	//if(!receiver) return false;

	if( GetPlayerDataStructByIndex ( receiver.GetIndex () )->is_in_smoke )
		return true;

	if( GetPlayerDataStructByIndex ( receiver.GetIndex () )->can_not_see_this_player[ sender.GetIndex () ] == true )
		return true;

	return false;
}
PlayerHandler::const_iterator NczPlayerManager::GetPlayerHandlerBySteamID ( const char * steamid ) const
{
	const char * tSteamId;

	for( PlayerHandler::const_iterator it ( PlayerHandler::begin () ); it != PlayerHandler::end (); ++it )
	{
		if( it )
		{
			tSteamId = it->GetSteamID ();
			if( strcmp ( tSteamId, steamid ) == 0 ) return it;
		}
	}

	return PlayerHandler::end ();
}
PlayerHandler::const_iterator NczPlayerManager::GetPlayerHandlerByName ( const char * playerName ) const
{
	const char * tName;

	for( PlayerHandler::const_iterator it ( PlayerHandler::begin () ); it != PlayerHandler::end (); ++it )
	{
		if( it )
		{
			tName = it->GetName ();
			if( strcmp ( tName, playerName ) ) return it;
		}
	}

	return PlayerHandler::end ();
}
Exemple #13
0
//---------------------------------------------------------------------------------
// Purpose: called when a client spawns into a server (i.e as they begin to play)
//---------------------------------------------------------------------------------
void CNoCheatZPlugin::ClientActive ( SourceSdk::edict_t *pEntity )
{
	DebugMessage ( Helpers::format ( "CNoCheatZPlugin::ClientActive (%X -> %s)", pEntity, pEntity->GetClassName () ) );

	NczPlayerManager::GetInstance ()->ClientActive ( pEntity );

	PlayerHandler::const_iterator ph ( NczPlayerManager::GetInstance ()->GetPlayerHandlerByEdict ( pEntity ) );
	if( ph >= SlotStatus::PLAYER_CONNECTED ) HookBasePlayer ( ph );
	if( ph >= SlotStatus::BOT )
	{
		WeaponHookListener::HookWeapon ( ph );
		HookEntity ( ph->GetEdict () );
	}

	ProcessFilter::HumanAtLeastConnected filter_class;
	if( NczPlayerManager::GetInstance ()->GetPlayerCount ( &filter_class ) == 1 ) AutoTVRecord::GetInstance ()->SpawnTV ();
}
PlayerHandler::const_iterator NczPlayerManager::GetPlayerHandlerByBasePlayer ( void * const BasePlayer ) const
{
	SourceSdk::edict_t * tEdict;
	for( PlayerHandler::const_iterator it ( PlayerHandler::begin () ); it != PlayerHandler::end (); ++it )
	{
		if( it )
		{
			tEdict = it->GetEdict ();
			if( Helpers::isValidEdict ( tEdict ) )
			{
				if( tEdict->GetUnknown () == BasePlayer ) return it;
			}
		}
	}

	return PlayerHandler::end ();
}
void AutoAttackTester::OnAttack2Up ( PlayerHandler::const_iterator ph, int game_tick )
{
	AttackTriggerStats * const pdata ( GetPlayerDataStructByIndex ( ph.GetIndex () ) );

	pdata->attack2_up_tick = game_tick;
	pdata->attack2_sustain_stats.Store ( game_tick - pdata->attack2_down_tick , pdata->attack2_down_tick );

	FindDetection ( ph, &( pdata->attack2_sustain_stats ) );
}
void AutoAttackTester::OnAttack2Down ( PlayerHandler::const_iterator ph, int game_tick )
{
	AttackTriggerStats * const pdata ( GetPlayerDataStructByIndex ( ph.GetIndex () ) );

	pdata->attack2_down_tick = game_tick;
}
void AntiSmokeBlocker::RT_ProcessOnTick ( float const curtime )
{
	METRICS_ENTER_SECTION ( "AntiSmokeBlocker::OnFrame" );

	SmokeListT::elem_t* it ( m_smokes.GetFirst () );

	// remove old smokes
	while( it != nullptr )
	{
		if( curtime - ( it->m_value.bang_time + ConfigManager::GetInstance ()->m_smoke_time ) > 0.0f )
			it = m_smokes.Remove ( it );
		else it = it->m_next;
	}

	ST_R_STATIC SmokeInfoT empty;
	ResetAll ( &empty );

	it = m_smokes.GetFirst ();
	if( it == nullptr ) return;

	// Test if players are immersed in smoke
	ProcessFilter::InTestsNoBot l1_filter;
	ProcessFilter::InTestsOrBot l2_filter;
	for( PlayerHandler::const_iterator ph ( &l1_filter ); ph != PlayerHandler::end (); ph+=&l1_filter )
	{
		SourceSdk::Vector delta, other_delta;

		MathInfo const & x_math ( MathCache::GetInstance ()->RT_GetCachedMaths ( ph.GetIndex () ) );

		do // At this stage, m_smokes ! empty
		{
			if( curtime - it->m_value.bang_time > ConfigManager::GetInstance ()->m_smoke_timetobang )
			{
				SourceSdk::vec_t dst;
				SourceSdk::VectorDistanceSqr ( x_math.m_eyepos, it->m_value.pos, delta, dst );
				if( dst < ConfigManager::GetInstance ()->m_innersmoke_radius_sqr )
				{
					GetPlayerDataStructByIndex ( ph.GetIndex () )->is_in_smoke = true;
				}

				/* Players can't see eachother if they are behind a smoke */

				const SourceSdk::vec_t ang_smoke ( tanf ( ConfigManager::GetInstance ()->m_smoke_radius / sqrtf ( dst ) ) );
				SourceSdk::VectorNorm ( delta );

				for( PlayerHandler::const_iterator other_ph ( &l2_filter ); other_ph != PlayerHandler::end (); other_ph+=&l2_filter )
				{
					if( ph == other_ph ) continue;

					MathInfo const & y_math ( MathCache::GetInstance ()->RT_GetCachedMaths ( other_ph.GetIndex () ) );

					// Is he behind the smoke against us ?

					SourceSdk::vec_t other_dst;
					SourceSdk::VectorDistanceSqr ( x_math.m_eyepos, y_math.m_abs_origin, other_delta, other_dst );
					if( dst + ConfigManager::GetInstance ()->m_smoke_radius < other_dst )
					{
						// Hidden by the hull of the smoke ?

						SourceSdk::VectorNorm ( other_delta );

						SourceSdk::vec_t dp;
						SourceSdk::VectorDotProduct ( other_delta, delta, dp );
						const SourceSdk::vec_t angle_player ( fabs ( acos ( dp ) ) );

						if( angle_player < ang_smoke )
						{
							GetPlayerDataStructByIndex ( ph.GetIndex () )->can_not_see_this_player[ other_ph.GetIndex () ] = true;
						}
					}
				}
			}
			it = it->m_next;
		}
		while( it != nullptr );
		it = m_smokes.GetFirst ();
	}

	METRICS_LEAVE_SECTION ( "AntiSmokeBlocker::OnFrame" );
}
void NczPlayerManager::FireGameEvent ( SourceSdk::IGameEvent* ev )
/*
player_death
player_team
player_spawn
player_connect
player_disconnect
round_freeze_end
round_end
bot_takeover
*/
{
	const char* event_name ( ev->GetName () + 6 );
	const int maxcl ( m_max_index );

	if( *event_name == 'e' ) // round_end
	{
		DebugMessage("event round_end");
		for( int x ( 1 ); x <= maxcl; ++x )
		{
			PlayerHandler::const_iterator ph ( x );
			if( ph == SlotStatus::PLAYER_IN_TESTS )
			{
				ph.GetHandler()->status = SlotStatus::PLAYER_CONNECTED;
				ph.GetHandler()->in_tests_time = std::numeric_limits<float>::max ();
				DebugMessage(Helpers::format("Players %s : Status changed from PLAYER_IN_TESTS to PLAYER_CONNECTED", ph->GetName()));
			}
			/*else if( ph == SlotStatus::PLAYER_IN_TESTS_TAKEOVER )
			{
				ph->GetTakeover ()->StopBotTakeover ();
				ph->StopBotTakeover ();
				ph.GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
				ph.GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();
			}*/
		}

		ProcessFilter::HumanAtLeastConnected filter_class;
		if( GetPlayerCount ( &filter_class ) == 0 ) AutoTVRecord::GetInstance ()->StopRecord ();

		BaseSystem::ManageSystems ();
		Logger::GetInstance ()->Flush ();

		return;
	}
	/*else*/ if( *event_name == 'f' ) // round_freeze_end = round_start
	{
		DebugMessage("event round_freeze_end");
		for( int x ( 1 ); x <= maxcl; ++x )
		{
			PlayerHandler& ph ( FullHandlersList[ x ] );
			if( ph.status == SlotStatus::INVALID ) continue;
			if( ph.status >= SlotStatus::PLAYER_CONNECTED )
			{
				ph.status = SlotStatus::PLAYER_CONNECTED;
				SourceSdk::IPlayerInfo * const pinfo ( ph.playerClass->GetPlayerInfo () );
				if( pinfo )
				{
					if( pinfo->GetTeamIndex () > 1 )
					{
						DebugMessage(Helpers::format("Players %s : Will enter in status PLAYER_IN_TESTS in 1 second", ph.playerClass->GetName()));
						ph.in_tests_time = Plat_FloatTime () + 1.0f;
					}
					else
					{
						ph.in_tests_time = std::numeric_limits<float>::max ();
					}
				}
			}
		}

		BaseSystem::ManageSystems ();
		return;
	}

	PlayerHandler::const_iterator ph ( GetPlayerHandlerByUserId ( ev->GetInt ( "userid" ) ) );

	if( *event_name == 'k' ) // bot_takeover
	{
		DebugMessage(Helpers::format("event bot_takeover : %s -> %s", ph->GetName (), GetPlayerHandlerByUserId ( ev->GetInt ( "botid" ) )->GetName ()));
		//PlayerHandler::const_iterator bh1 ( GetPlayerHandlerByUserId ( ev->GetInt ( "botid" ) ) );
		//PlayerHandler::const_iterator bh2 ( GetPlayerHandlerByUserId (  ) );
		//DebugMessage ( Helpers::format ( "Player %s taking control of bot %s or bot %d", ph->GetName (), bh1->GetName (), ev->GetInt ( "index" ) ));

		//ph->EnterBotTakeover ( ev->GetInt ( "index" ) );
		//bh2->EnterBotTakeover ( ph.GetIndex () );

		//ph.GetHandler ()->status = SlotStatus::PLAYER_IN_TESTS_TAKEOVER;
		//ph.GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();

		return;
	}

	++event_name;

	if( *event_name == 'c' ) // player_connect
	{
		if( ev->GetBool ( "bot" ) == false )
		{
			if( SourceSdk::InterfacesProxy::m_game == SourceSdk::CounterStrikeGlobalOffensive )
			{
				SourceSdk::IGameEvent_csgo* rev ( reinterpret_cast< SourceSdk::IGameEvent_csgo* >( ev ) );
				Logger::GetInstance ()->Msg<MSG_LOG> ( Helpers::format ( "Player connect : %s [%s]", rev->GetString ( "name", "unknown-name" ), rev->GetString ( "networkid", "unknown-networkid" ) ) );
			}
			else
			{
				Logger::GetInstance ()->Msg<MSG_LOG> ( Helpers::format ( "Player connect : %s [%s - %s]", ev->GetString ( "name", "unknown-name" ), ev->GetString ( "networkid", "unknown-networkid" ), ev->GetString ( "address", "unknown-address" ) ) );
			}
		}

		return;
	}
	if( *(event_name + 1) == 'i' ) // player_disconnect
	{
		if( ev->GetBool ( "bot" ) == false )
		{
			if( SourceSdk::InterfacesProxy::m_game == SourceSdk::CounterStrikeGlobalOffensive )
			{
				SourceSdk::IGameEvent_csgo* rev ( reinterpret_cast< SourceSdk::IGameEvent_csgo* >( ev ) );
				if( !rev->IsEmpty ( "name" ) )
				{
					Logger::GetInstance ()->Msg<MSG_LOG> ( Helpers::format ( "Player disconnect : %s [%s] -> Reason : %s", rev->GetString ( "name", "unknown-name" ), rev->GetString ( "networkid", "unknown-networkid" ), rev->GetString ( "reason", "unknown-reason" ) ) );
				}
			}
			else
			{
				Logger::GetInstance ()->Msg<MSG_LOG> ( Helpers::format ( "Player disconnect : %s [%s - %s] -> Reason : %s", ev->GetString ( "name", "unknown-name" ), ev->GetString ( "networkid", "unknown-networkid" ), ev->GetString ( "address", "unknown-address" ), ev->GetString ( "reason", "unknown-reason" ) ) );
			}
		}

		return;
	}
	if( *event_name == 's' ) // player_spawn(ed)
	{
		DebugMessage(Helpers::format("event player_spawn : %s", ph->GetName()));
		if( ph > SlotStatus::BOT )
		{
			SourceSdk::IPlayerInfo * const pinfo ( ph->GetPlayerInfo () );
			if( pinfo )
			{
				if( pinfo->GetTeamIndex () > 1 )
				{
					DebugMessage(Helpers::format("Players %s : Will enter in status PLAYER_IN_TESTS in 3 seconds", ph->GetName()));
					ph.GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
					ph.GetHandler ()->in_tests_time = Plat_FloatTime () + 3.0f;
				}
				else
				{
					DebugMessage(Helpers::format("Players %s : Status forced to PLAYER_CONNECTED", ph->GetName()));
					ph.GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
					ph.GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();
				}
			}
		}
		else if( ph == SlotStatus::BOT )
		{
			/*if( ph->IsControllingBot () )
			{
				ph->GetTakeover ()->StopBotTakeover (); // release link from player to bot
				ph->GetTakeover ().GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
				ph->GetTakeover ().GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();
				ph->StopBotTakeover (); // release link from bot to player
			}*/
		}
		BaseSystem::ManageSystems ();
		return;
	}
	if( *event_name == 't' ) // player_team
	{
		DebugMessage("event player_team");
		if( ph > SlotStatus::BOT )
		{
			if( ev->GetInt ( "teamid" ) > 1 )
			{
				DebugMessage(Helpers::format("Players %s : Will enter in status PLAYER_IN_TESTS in 3 seconds", ph->GetName()));
				ph.GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
				ph.GetHandler ()->in_tests_time = Plat_FloatTime () + 3.0f;
			}
			else
			{
				DebugMessage(Helpers::format("Players %s : Status forced to PLAYER_CONNECTED", ph->GetName()));
				ph.GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
				ph.GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();
			}
		}
		else if( ph == SlotStatus::BOT )
		{
			/*if( ph->IsControllingBot () )
			{
				ph->GetTakeover ()->StopBotTakeover (); // release link from player to bot
				ph->GetTakeover ().GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
				ph->GetTakeover ().GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();
				ph->StopBotTakeover (); // release link from bot to player
			}*/
		}
		BaseSystem::ManageSystems ();
		return;
	}
	//else // player_death
	//{

	DebugMessage(Helpers::format("event player_death : %s", ph->GetName()));
	if( ph == SlotStatus::BOT )
	{
		/*if( ph->IsControllingBot () ) // is bot controlled
		{
			ph->GetTakeover ()->StopBotTakeover (); // release link from player to bot
			ph->GetTakeover ().GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
			ph->GetTakeover ().GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();
			ph->StopBotTakeover (); // release link from bot to player
		}*/
	}
	if( ph </*=*/ SlotStatus::PLAYER_CONNECTED ) /// fixed :  https://github.com/L-EARN/NoCheatZ-4/issues/79#issuecomment-240174457
		return;
	DebugMessage(Helpers::format("Players %s : Status forced to PLAYER_CONNECTED", ph->GetName()));
	ph.GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
	ph.GetHandler ()->in_tests_time = std::numeric_limits<float>::max ();
	BaseSystem::ManageSystems ();
	//}
}
Exemple #19
0
//---------------------------------------------------------------------------------
// Purpose: called when the plugin is loaded, load the interface we need from the engine
//---------------------------------------------------------------------------------
bool CNoCheatZPlugin::Load ( SourceSdk::CreateInterfaceFn _interfaceFactory, SourceSdk::CreateInterfaceFn gameServerFactory )
{
	GlobalTimer::GetInstance ()->EnterSection ();

	Logger::GetInstance ()->Msg<MSG_CONSOLE> ( "Loading ..." );

	if( !SourceSdk::InterfacesProxy::Load ( gameServerFactory, _interfaceFactory ) )
	{
		Logger::GetInstance ()->Msg<MSG_ERROR> ( "SourceSdk::InterfacesProxy::Load failed" );
		return false;
	}

	void* pinstance ( SourceSdk::InterfacesProxy::ICvar_FindVar ( "nocheatz_instance" ) );
	if( pinstance )
	{
		if( SourceSdk::InterfacesProxy::ConVar_GetBool ( pinstance ) )
		{
			Logger::GetInstance ()->Msg<MSG_ERROR> ( "CNoCheatZPlugin already loaded" );
			m_bAlreadyLoaded = true;
			return false;
		}
		Assert ( "Error when testing for multiple instances" && 0 );
	}

	if( !ConfigManager::GetInstance ()->LoadConfig () )
	{
		Logger::GetInstance ()->Msg<MSG_ERROR> ( "ConfigManager::LoadConfig failed" );
		return false;
	}

	if( SourceSdk::InterfacesProxy::m_game == SourceSdk::CounterStrikeGlobalOffensive )
	{
		ncz_cmd_ptr = new SourceSdk::ConCommand_csgo ( "ncz", BaseSystem::ncz_cmd_fn, "NoCheatZ", FCVAR_DONTRECORD | 1 << 18 );
		nocheatz_instance = new SourceSdk::ConVar_csgo ( "nocheatz_instance", "0", FCVAR_DONTRECORD | 1 << 18 );

		SourceSdk::ConVar_Register_csgo ( 0 );
	}
	else
	{
		// Fix IServerPluginCallbacks vtable, because CSGO added ClientFullyConnect in the middle ...
		DWORD* vtable ( IFACE_PTR ( this ) );

		int id ( 10 );
		int const max_id ( 19 );
		do
		{
			MoveVirtualFunction ( &vtable[ id + 1 ], &vtable[ id ] );
		}
		while( ++id != max_id );

		ncz_cmd_ptr = new SourceSdk::ConCommand ( "ncz", BaseSystem::ncz_cmd_fn, "NoCheatZ", FCVAR_DONTRECORD );
		nocheatz_instance = new SourceSdk::ConVar ( "nocheatz_instance", "0", FCVAR_DONTRECORD );

		SourceSdk::ConVar_Register ( 0 );
	}

	UserMessageHookListener::HookUserMessage ();

	BaseSystem::InitSystems ();
	BanRequest::GetInstance ()->Init ();

	NczPlayerManager::GetInstance ()->LoadPlayerManager (); // Mark any present player as PLAYER_CONNECTED

	SourceSdk::InterfacesProxy::Call_ServerExecute ();
	SourceSdk::InterfacesProxy::Call_ServerCommand ( "exec nocheatz.cfg\n" );
	SourceSdk::InterfacesProxy::Call_ServerExecute ();

	for( int i ( 1 ); i < MAX_PLAYERS; ++i )
	{
		PlayerHandler::const_iterator ph ( NczPlayerManager::GetInstance ()->GetPlayerHandlerByIndex ( i ) );
		if( ph >= SlotStatus::BOT )
		{
			HookEntity ( ph->GetEdict () );
			WeaponHookListener::HookWeapon ( ph );

			if( ph >= SlotStatus::PLAYER_CONNECTED )
			{
				HookBasePlayer ( ph );
			}
		}
	}
	BaseSystem::ManageSystems ();

	SourceSdk::InterfacesProxy::ConVar_SetValue<bool> ( nocheatz_instance, true );

	Logger::GetInstance ()->Msg<MSG_CHAT> ( "Loaded" );

	return true;
}
Exemple #20
0
PlayerRunCommandRet ShotTester::RT_PlayerRunCommandCallback ( PlayerHandler::const_iterator ph, void* pCmd, void* lastcmd )
{
	PlayerRunCommandRet drop_cmd = PlayerRunCommandRet::CONTINUE;

	ShotStatsT * const playerData ( GetPlayerDataStructByIndex ( ph.GetIndex () ) );

	float const curtime ( Plat_FloatTime () );

	bool cur_in_attack;
	bool past_in_attack;

	if( SourceSdk::InterfacesProxy::m_game == SourceSdk::CounterStrikeGlobalOffensive )
	{
		cur_in_attack = ( static_cast< SourceSdk::CUserCmd_csgo* >( pCmd )->buttons & IN_ATTACK ) != 0;
		past_in_attack = ( static_cast< SourceSdk::CUserCmd_csgo* >( lastcmd )->buttons & IN_ATTACK ) != 0;
	}
	else
	{
		cur_in_attack = ( static_cast< SourceSdk::CUserCmd* >( pCmd )->buttons & IN_ATTACK ) != 0;
		past_in_attack = ( static_cast< SourceSdk::CUserCmd* >( lastcmd )->buttons & IN_ATTACK ) != 0;
	}

	if( cur_in_attack && !past_in_attack )
	{
		//SystemVerbose1(Helpers::format("Player %s : IN_ATTACK button down.", ph->GetName()));
		playerData->down_time = curtime;
	}
	else if( past_in_attack && !cur_in_attack )
	{
		playerData->up_time = curtime;
		TriggerStat ( &( playerData->clicks ), playerData->up_time, playerData->down_time, playerData->clicks.n );
		//SystemVerbose1(Helpers::format("Player %s : IN_ATTACK button up.", ph->GetName()));

		if( playerData->up_time - playerData->down_time <= SHORT_TIME )
		{
			if( curtime - playerData->last_detection > 1.0 )
			{
				if( playerData->row == 1 )
				{
					if( playerData->on_target.ratio > 25.0 && playerData->clicks.n > 50 )
					{
						Detection_TriggerBot pDetection;
						pDetection.PrepareDetectionData ( playerData );
						pDetection.PrepareDetectionLog ( *ph, this );
						pDetection.Log ();

						ph->Ban ();
					}
				}
				playerData->row = 0;
			}
			if( playerData->row > 10 )
			{
				if( playerData->short_clicks.ratio > 40.0 && playerData->clicks.n > 50 )
				{
					Detection_AutoPistol pDetection;
					pDetection.PrepareDetectionData ( playerData );
					pDetection.PrepareDetectionLog ( *ph, this );
					pDetection.Log ();

					ph->Ban ();
				}
			}
			playerData->last_detection = curtime;
			++( playerData->row );

			TriggerStat ( &( playerData->short_clicks ), playerData->up_time, playerData->down_time, playerData->clicks.n );
			if( ph->GetWpnShotType () == HAND ) TriggerStat ( &( playerData->with_hand ), playerData->up_time, playerData->down_time, playerData->clicks.n );
			else if( ph->GetWpnShotType () == PISTOL ) TriggerStat ( &( playerData->with_pistol ), playerData->up_time, playerData->down_time, playerData->clicks.n );
			else TriggerStat ( &( playerData->with_auto ), playerData->up_time, playerData->down_time, playerData->clicks.n );
			if( ph->aimingAt () > 0 ) TriggerStat ( &( playerData->on_target ), playerData->up_time, playerData->down_time, playerData->clicks.n );
			drop_cmd = PlayerRunCommandRet::INERT;

			if( this->m_verbose )
			{
				printf ( "%f - clicks ", curtime );
				OutputStat ( &( playerData->clicks ) );
				printf ( ", short_clicks " );
				OutputStat ( &( playerData->short_clicks ) );
				printf ( ", with_hand " );
				OutputStat ( &( playerData->with_hand ) );
				printf ( ", with_pistol " );
				OutputStat ( &( playerData->with_pistol ) );
				printf ( ", with_auto " );
				OutputStat ( &( playerData->with_auto ) );
				printf ( ", on_target " );
				OutputStat ( &( playerData->on_target ) );
				printf ( ", row %u\n", playerData->row );
			}
		}
	}
	return drop_cmd;
}
Exemple #21
0
PlayerRunCommandRet EyeAnglesTester::RT_PlayerRunCommandCallback ( PlayerHandler::const_iterator ph, void * const pCmd, void * const old_cmd )
{
	int const * const flags ( EntityProps::GetInstance ()->GetPropValue<int, PROP_FLAGS> ( ph->GetEdict () ) );

	/*
		FL_FROZEN			(1 << 5)
		FL_ATCONTROLS		(1 << 6)
	*/
	if( *flags & ( 3 << 5 ) ) return PlayerRunCommandRet::CONTINUE;

	PlayerRunCommandRet drop_cmd ( PlayerRunCommandRet::CONTINUE );

	EyeAngleInfoT* playerData ( GetPlayerDataStructByIndex ( ph.GetIndex () ) );
	playerData->x.abs_value = fabs ( playerData->x.value = static_cast< SourceSdk::CUserCmd_csgo* >( pCmd )->viewangles.x );
	playerData->y.abs_value = fabs ( playerData->y.value = static_cast< SourceSdk::CUserCmd_csgo* >( pCmd )->viewangles.y );
	playerData->z.abs_value = fabs ( playerData->z.value = static_cast< SourceSdk::CUserCmd_csgo* >( pCmd )->viewangles.z );

	if( playerData->x.abs_value > 89.0f || playerData->z.abs_value > 1.0f || playerData->y.abs_value > 180.0f )
	{
		if( playerData->ignore_last ) --( playerData->ignore_last );
		else drop_cmd = PlayerRunCommandRet::INERT;
	}

	if( drop_cmd > PlayerRunCommandRet::CONTINUE )
	{
		if( playerData->x.abs_value > 89.0f )
		{
			++playerData->x.detectionsCount;
			if( playerData->x.lastDetectionPrintTime + ANTIFLOOD_LOGGING_TIME < Plat_FloatTime () )
			{
				playerData->x.lastDetectionPrintTime = Plat_FloatTime ();

				Detection_EyeAngleX pDetection;
				pDetection.PrepareDetectionData ( playerData );
				pDetection.PrepareDetectionLog ( *ph, this );
				pDetection.Log ();
			}
		}
		if( playerData->y.abs_value > 180.0f )
		{
			++playerData->y.detectionsCount;
			if( playerData->y.lastDetectionPrintTime + ANTIFLOOD_LOGGING_TIME < Plat_FloatTime () )
			{
				playerData->y.lastDetectionPrintTime = Plat_FloatTime ();

				Detection_EyeAngleY pDetection;
				pDetection.PrepareDetectionData ( playerData );
				pDetection.PrepareDetectionLog ( *ph, this );
				pDetection.Log ();
			}
		}
		if( playerData->z.abs_value > 1.0f )
		{
			++playerData->z.detectionsCount;
			if( playerData->z.lastDetectionPrintTime + ANTIFLOOD_LOGGING_TIME < Plat_FloatTime () )
			{
				playerData->z.lastDetectionPrintTime = Plat_FloatTime ();

				Detection_EyeAngleZ pDetection;
				pDetection.PrepareDetectionData ( playerData );
				pDetection.PrepareDetectionLog ( *ph, this );
				pDetection.Log ();
			}
		}

		BanRequest::GetInstance ()->AddAsyncBan ( *ph, 0, "Banned by NoCheatZ 4" );
	}
	return drop_cmd;
}
void NczPlayerManager::LoadPlayerManager ()
{
	SourceSdk::InterfacesProxy::GetGameEventManager ()->AddListener ( this, "player_death", true );
	SourceSdk::InterfacesProxy::GetGameEventManager ()->AddListener ( this, "player_team", true );
	SourceSdk::InterfacesProxy::GetGameEventManager ()->AddListener ( this, "player_spawn", true );
	SourceSdk::InterfacesProxy::GetGameEventManager ()->AddListener ( this, "player_connect", true );
	SourceSdk::InterfacesProxy::GetGameEventManager ()->AddListener ( this, "player_disconnect", true );
	SourceSdk::InterfacesProxy::GetGameEventManager ()->AddListener ( this, "round_end", true );
	SourceSdk::InterfacesProxy::GetGameEventManager ()->AddListener ( this, "round_freeze_end", true );
	SourceSdk::InterfacesProxy::GetGameEventManager ()->AddListener ( this, "bot_takeover", true );

	//Helpers::FastScan_EntList();
	Helpers::m_EdictList = Helpers::PEntityOfEntIndex ( 0 );

	//if(Helpers::m_EdictList)
	//{
	//int maxcl = Helpers::GetMaxClients();

	for( PlayerHandler::const_iterator ph ( PlayerHandler::begin () ); ph != PlayerHandler::end (); ++ph )
	{
		SourceSdk::edict_t* const pEntity ( Helpers::PEntityOfEntIndex ( ph.GetIndex () ) );
		if( Helpers::isValidEdict ( pEntity ) )
		{
			void * playerinfo ( SourceSdk::InterfacesProxy::Call_GetPlayerInfo ( pEntity ) );
			if( playerinfo )
			{
				bool isfakeclient;
				if( SourceSdk::InterfacesProxy::m_game == SourceSdk::CounterStrikeGlobalOffensive )
				{
					isfakeclient = static_cast< SourceSdk::IPlayerInfo_csgo* >( playerinfo )->IsFakeClient ();
				}
				else
				{
					isfakeclient = static_cast< SourceSdk::IPlayerInfo* >( playerinfo )->IsFakeClient ();
				}
				if( isfakeclient )
				{
					ph.GetHandler ()->status = SlotStatus::BOT;
					ph.GetHandler ()->playerClass = new NczPlayer ( ph.GetIndex () );
					m_max_index = ph.GetIndex ();
				}
				else if( static_cast< SourceSdk::IPlayerInfo* >( playerinfo )->IsConnected () )
				{
					ph.GetHandler ()->status = SlotStatus::PLAYER_CONNECTED;
					ph.GetHandler ()->playerClass = new NczPlayer ( ph.GetIndex () );
					ph.GetHandler ()->playerClass->OnConnect ();
					m_max_index = ph.GetIndex ();
				}
			}
		}
	}

	//}

	if( m_max_index )
	{
		PlayerHandler::first = ( &FullHandlersList[ 1 ] );
		PlayerHandler::last = ( &FullHandlersList[ m_max_index ] );
	}
	else
	{
		PlayerHandler::first = PlayerHandler::invalid;
		PlayerHandler::last = PlayerHandler::invalid;
	}

	BaseSystem::ManageSystems ();
}