From 52b7d22ee7f5128779ceab538cda3d0a7e63acb5 Mon Sep 17 00:00:00 2001 From: Lorenc Pekaj Date: Wed, 19 Sep 2018 10:09:14 +1000 Subject: [PATCH] move rapidfire detection and invalid bullet detection into its own ac module --- .../irresistible/anticheat/_anticheat.pwn | 4 +- .../irresistible/anticheat/rapidfire.pwn | 69 +++++++++++++++++++ gamemodes/irresistible/cnr/player.pwn | 2 - gamemodes/sf-cnr.pwn | 57 +++------------ 4 files changed, 82 insertions(+), 50 deletions(-) create mode 100644 gamemodes/irresistible/anticheat/rapidfire.pwn diff --git a/gamemodes/irresistible/anticheat/_anticheat.pwn b/gamemodes/irresistible/anticheat/_anticheat.pwn index a9cda9a..997dbb5 100644 --- a/gamemodes/irresistible/anticheat/_anticheat.pwn +++ b/gamemodes/irresistible/anticheat/_anticheat.pwn @@ -37,7 +37,8 @@ enum CHEAT_TYPE_AIRBRAKE, CHEAT_TYPE_PROAIM, CHEAT_TYPE_AUTOCBUG, - CHEAT_TYPE_FLYHACKS + CHEAT_TYPE_FLYHACKS, + CHEAT_TYPE_RAPIDFIRE }; static stock @@ -163,3 +164,4 @@ stock AC_SetPlayerSpawned( playerid, bool: spawned ) { #include "irresistible\anticheat\autocbug.pwn" #include "irresistible\anticheat\flying.pwn" #include "irresistible\anticheat\remotejack.pwn" +#include "irresistible\anticheat\rapidfire.pwn" diff --git a/gamemodes/irresistible/anticheat/rapidfire.pwn b/gamemodes/irresistible/anticheat/rapidfire.pwn new file mode 100644 index 0000000..5b72598 --- /dev/null +++ b/gamemodes/irresistible/anticheat/rapidfire.pwn @@ -0,0 +1,69 @@ +/* + * Irresistible Gaming (c) 2018 + * Developed by Lorenc Pekaj + * Module: anticheat\rapidfire.pwn + * Purpose: rapid fire detection as well as invalid bullet filtering + */ + +/* ** Includes ** */ +#include < YSI\y_hooks > + +/* ** Variables ** */ +static stock + p_RapidFireTickCount [ MAX_PLAYERS ], + p_RapidFireShots [ MAX_PLAYERS char ] +; + +/* ** Hooks ** */ +hook OnPlayerDisconnect( playerid, reason ) { + if ( 0 <= playerid < MAX_PLAYERS ) { + p_RapidFireShots{ playerid } = 0; + } + return 1; +} + +hook OnPlayerWeaponShot( playerid, weaponid, hittype, hitid, Float: fX, Float: fY, Float: fZ ) +{ + new + keys, ud, lr; + + GetPlayerKeys( playerid, keys, ud, lr ); + + // Simple. But effective. Anti-Shooting Hacks. + if ( ! ( keys & KEY_FIRE ) ) { + return Y_HOOKS_BREAK_RETURN_0; + } + + // Invalid weapon id + if ( ! ( 22 <= weaponid <= 34 ) && weaponid != 38 ) { + return Y_HOOKS_BREAK_RETURN_0; + } + + // Invalid hit (very far offset from player) + if ( hittype == BULLET_HIT_TYPE_PLAYER && ( ( fX >= 10.0 || fX <= -10.0 ) || ( fY >= 10.0 || fY <= -10.0 ) || ( fZ >= 10.0 || fZ <= -10.0 ) ) ) { + return Y_HOOKS_BREAK_RETURN_0; + } + + // Anti-Rapid Fire + if ( ! p_RapidFireTickCount[ playerid ] ) p_RapidFireTickCount[ playerid ] = GetTickCount( ); + else + { + new + iInterval = GetTickCount( ) - p_RapidFireTickCount[ playerid ]; + + if ( ( iInterval <= 35 && ( weaponid != 38 && weaponid != 28 && weaponid != 32 ) ) || ( iInterval <= 370 && ( weaponid == 34 || weaponid == 33 ) ) ) + { + if ( p_RapidFireShots{ playerid } ++ >= 5 ) { + CallLocalFunction( "OnPlayerCheatDetected", "ddd", playerid, CHEAT_TYPE_RAPIDFIRE, 0 ); + return Y_HOOKS_BREAK_RETURN_0; + } + } + else + { + p_RapidFireShots{ playerid } = 0; + } + + p_RapidFireTickCount[ playerid ] = GetTickCount( ); + } + return 1; +} diff --git a/gamemodes/irresistible/cnr/player.pwn b/gamemodes/irresistible/cnr/player.pwn index 85702f8..d4f8173 100644 --- a/gamemodes/irresistible/cnr/player.pwn +++ b/gamemodes/irresistible/cnr/player.pwn @@ -201,8 +201,6 @@ new p_SpectateWeapons [ MAX_PLAYERS ] [ 13 ] [ 2 ], bool: p_LeftCuffed [ MAX_PLAYERS char ], p_LabelColor [ MAX_PLAYERS ] = { COLOR_GREY, ... }, - p_RapidFireTickCount [ MAX_PLAYERS ], - p_RapidFireShots [ MAX_PLAYERS char ], p_BulletInvulnerbility [ MAX_PLAYERS ], p_ProgressUpdateTimer [ MAX_PLAYERS ] = { 0xFFFF, ... }, p_DeathMessage [ MAX_PLAYERS ] [ 32 ], diff --git a/gamemodes/sf-cnr.pwn b/gamemodes/sf-cnr.pwn index 95ffd41..b095342 100644 --- a/gamemodes/sf-cnr.pwn +++ b/gamemodes/sf-cnr.pwn @@ -4101,7 +4101,6 @@ public OnPlayerDisconnect( playerid, reason ) p_ToggledViewPM { playerid } = false; p_VIPExpiretime [ playerid ] = 0; p_BankMoney [ playerid ] = 0; - p_RapidFireShots{ playerid } = 0; p_Kills [ playerid ] = 0; p_Deaths [ playerid ] = 0; p_VIPLevel [ playerid ] = 0; @@ -4522,59 +4521,16 @@ public OnPlayerSpawn( playerid ) public OnPlayerWeaponShot( playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ ) { - new - keys, ud, lr - ; - GetPlayerKeys( playerid, keys, ud, lr ); - - // Simple. But effective. Anti-Shooting Hacks. - if ( !( keys & KEY_FIRE ) ) { - return 0; - } - - if ( !( 22 <= weaponid <= 34 ) && weaponid != 38 ) { - return 0; - } - if ( p_AdminLevel[ playerid ] < 1 && IsWeaponBanned( weaponid ) ) { return 0; } - if ( hittype == BULLET_HIT_TYPE_PLAYER && ( ( fX >= 10.0 || fX <= -10.0 ) || ( fY >= 10.0 || fY <= -10.0 ) || ( fZ >= 10.0 || fZ <= -10.0 ) ) ) { - return 0; - } - if ( IsPlayerAFK( playerid ) ) { return 0; } - static Float: X, Float: Y, Float: Z; - - // Anti-Rapid Fire - if ( !p_RapidFireTickCount[ playerid ] ) p_RapidFireTickCount[ playerid ] = GetTickCount( ); - else - { - new - iInterval = GetTickCount( ) - p_RapidFireTickCount[ playerid ]; - - if ( ( iInterval <= 35 && ( weaponid != 38 && weaponid != 28 && weaponid != 32 ) ) || ( iInterval <= 370 && ( weaponid == 34 || weaponid == 33 ) ) ) - { - if ( p_RapidFireShots{ playerid }++ >= 5 ) - { - if ( g_Debugging ) - { - SendClientMessageToRCON( COLOR_YELLOW, "RAPID-FIRE: %s, weapon %s, rate %d, times fucked up: %d", ReturnPlayerName( playerid ), ReturnWeaponName( weaponid ), iInterval, p_RapidFireShots{ playerid } ); - printf("[DEBUG] [RAPID-FIRE] %s | %s | rate %d | times fucked up: %d", ReturnPlayerName( playerid ), ReturnWeaponName( weaponid ), iInterval, p_RapidFireShots{ playerid } ); - } - - SendGlobalMessage( -1, ""COL_PINK"[ANTI-CHEAT]{FFFFFF} %s(%d) has been kicked for rapid-firing.", ReturnPlayerName( playerid ), playerid ); - KickPlayer( playerid ); - return 0; - } - } - else p_RapidFireShots{ playerid } = 0; - p_RapidFireTickCount[ playerid ] = GetTickCount( ); - } + static + Float: X, Float: Y, Float: Z; if ( hittype == BULLET_HIT_TYPE_PLAYER ) { @@ -12065,8 +12021,9 @@ public OnPlayerStateChange(playerid, newstate, oldstate) } } - if ( newstate == PLAYER_STATE_DRIVER ) + if ( newstate == PLAYER_STATE_DRIVER ) { CallLocalFunction( "OnPlayerDriveVehicle", "dd", playerid, vID ); + } //if ( newstate == PLAYER_STATE_ONFOOT && p_Detained{ playerid } == true && IsPlayerConnected( p_DetainedBy[ playerid ] ) ) // return PutPlayerInEmptyVehicleSeat( p_LastVehicle[ p_DetainedBy[ playerid ] ], playerid ); @@ -13760,6 +13717,12 @@ function unpause_Player( playerid ) SendClientMessageToAdmins( -1, ""COL_PINK"[ABNORMAL JACKING]"COL_GREY" %s(%d) is a suspect of jacking vehicles abnormally.", ReturnPlayerName( playerid ), playerid ); return 1; } + else if ( detection == CHEAT_TYPE_RAPIDFIRE ) + { + SendGlobalMessage( -1, ""COL_PINK"[ANTI-CHEAT]{FFFFFF} %s(%d) has been kicked for rapid-firing.", ReturnPlayerName( playerid ), playerid ); + Kick( playerid ); + return 1; + } else if ( detection == CHEAT_TYPE_AIRBRAKE ) { //SendGlobalMessage( -1, ""COL_PINK"[ANTI-CHEAT]{FFFFFF} %s(%d) has been banned for airbraking.", ReturnPlayerName( playerid ), playerid );