From 9453ebe2aaa47b4e5773557733567e1d6aa75bcf Mon Sep 17 00:00:00 2001 From: Lorenc Pekaj Date: Sun, 13 May 2018 02:26:14 +1000 Subject: [PATCH] make anticheat more independent with y_hooks + fix death bug with explosive rounds --- pawno/include/anticheat/global.inc | 1 - pawno/include/anticheat/hitpoints.inc | 620 ++++++++++++++++-------- pawno/include/anticheat/hooks.inc | 649 ++++++-------------------- pawno/include/anticheat/player.inc | 8 - 4 files changed, 569 insertions(+), 709 deletions(-) diff --git a/pawno/include/anticheat/global.inc b/pawno/include/anticheat/global.inc index e80d9af..455db45 100644 --- a/pawno/include/anticheat/global.inc +++ b/pawno/include/anticheat/global.inc @@ -239,7 +239,6 @@ stock // Forwards (Global) public OnPlayerCheatDetected( playerid, detection ); -public OnPlayerDamagePlayer( playerid, damagedid, Float: amount, weaponid, bodypart ); // Functions (Global) diff --git a/pawno/include/anticheat/hitpoints.inc b/pawno/include/anticheat/hitpoints.inc index b0563f5..fe30f9e 100644 --- a/pawno/include/anticheat/hitpoints.inc +++ b/pawno/include/anticheat/hitpoints.inc @@ -23,222 +23,434 @@ with this program; if not, see . */ -#if !defined AC_HITPOINTS_INCLUDED +/* ** Includes ** */ +#include < YSI\y_hooks > - // Forwards - public OnPlayerTakePlayerDamage ( playerid, issuerid, &Float: amount, weaponid, bodypart ); - public OnPlayerDeathEx ( playerid, killerid, reason, Float: damage, bodypart ); +/* ** Variables ** */ +static stock + Float: p_PlayerHealth [ MAX_PLAYERS ] [ E_PLAYER_HITPOINTS ], + Float: p_PlayerArmour [ MAX_PLAYERS ] [ E_PLAYER_HITPOINTS ], + Float: p_LastDamageIssued [ MAX_PLAYERS ], + p_LastTookDamage [ MAX_PLAYERS ], + p_LastDamageIssuer [ MAX_PLAYERS ] = { INVALID_PLAYER_ID, ... }, + p_LastWeaponIssuer [ MAX_PLAYERS ] +; - // Function (AC_UpdateKillerData) +/* ** Forwards ** */ +forward OnPlayerDamagePlayer ( playerid, damagedid, Float: amount, weaponid, bodypart ); +forward OnPlayerTakePlayerDamage ( playerid, issuerid, &Float: amount, weaponid, bodypart ); +forward OnPlayerDeathEx ( playerid, killerid, reason, Float: damage, bodypart ); - stock AC_UpdateDamageInformation( playerid, attackerid, weaponid ) +// Function (AC_UpdateKillerData) + +stock AC_UpdateDamageInformation( playerid, attackerid, weaponid ) +{ + p_LastTookDamage[ playerid ] = GetTickCount( ); + p_LastDamageIssuer[ playerid ] = attackerid; + p_LastWeaponIssuer[ playerid ] = weaponid; +} + +// Function (AC_GetPlayerHealth) + +stock Float: AC_GetPlayerHealth( playerid ) + return p_PlayerHealth[ playerid ] [ E_POINTS ]; + +// Function (AddPlayerHealth) + +stock AC_AddPlayerHealth( playerid, Float:amount ) +{ + p_PlayerHealth[ playerid ] [ E_POINTS ] += amount; + p_PlayerHealth[ playerid ] [ E_SYNCED ] = false; + + return SetPlayerHealth( playerid, p_PlayerHealth[ playerid ] [ E_POINTS ] ); +} + +// Function Hook (SetPlayerHealth) + +stock AC_SetPlayerHealth( playerid, Float:amount ) +{ + p_PlayerHealth[ playerid ] [ E_POINTS ] = amount; + p_PlayerHealth[ playerid ] [ E_SYNCED ] = false; + + if( amount <= 0.0 && p_acSpawned{ playerid } ) { - p_LastTookDamage[ playerid ] = GetTickCount( ); - p_LastDamageIssuer[ playerid ] = attackerid; - p_LastWeaponIssuer[ playerid ] = weaponid; + if( ( GetTickCount( ) - p_LastTookDamage[ playerid ] ) > 2500 ) { + p_LastDamageIssuer[ playerid ] = INVALID_PLAYER_ID, p_LastWeaponIssuer[ playerid ] = 47; + } + + p_acSpawned{ playerid } = false; // They're dead! + CallRemoteFunction( "OnPlayerDeathEx", "ddfd", playerid, p_LastDamageIssuer[ playerid ], p_LastWeaponIssuer[ playerid ], 3.3, 3 ); + } + return SetPlayerHealth( playerid, amount ); +} + +#if defined _ALS_SetPlayerHealth + #undef SetPlayerHealth +#else + #define _ALS_SetPlayerHealth +#endif +#define SetPlayerHealth AC_SetPlayerHealth + +// Function Hook (SetPlayerArmour) + +stock AC_SetPlayerArmour( playerid, Float:amount ) +{ + p_PlayerArmour[ playerid ] [ E_POINTS ] = amount; + p_PlayerArmour[ playerid ] [ E_SYNCED ] = false; + return SetPlayerArmour( playerid, amount ); +} + +#if defined _ALS_SetPlayerArmour + #undef SetPlayerArmour +#else + #define _ALS_SetPlayerArmour +#endif +#define SetPlayerArmour AC_SetPlayerArmour + +// Function Hook (SetPlayerTeam) + +stock AC_SetPlayerTeam( playerid, teamid ) +{ + if( teamid != AC_DEFAULT_TEAM ) { + printf("[ACWarning] You cannot use SetPlayerTeam as you have hitpoint hack detection enabled (teamid %d, default %d).", teamid, AC_DEFAULT_TEAM ); + } + return SetPlayerTeam( playerid, AC_DEFAULT_TEAM ); +} + +#if defined _ALS_SetPlayerTeam + #undef SetPlayerTeam +#else + #define _ALS_SetPlayerArmour +#endif +#define SetPlayerTeam AC_SetPlayerTeam + +/* ** Callback Hooks ** */ +hook OnPlayerConnect( playerid ) +{ + if ( 0 <= playerid < MAX_PLAYERS ) + { + p_PlayerHealth[ playerid ] [ E_UPDATE_FAIL ] = 0; + p_PlayerArmour[ playerid ] [ E_UPDATE_FAIL ] = 0; + } + return 1; +} + +hook OnPlayerSpawn( playerid ) +{ + // Health/Armour Hack + p_PlayerHealth[ playerid ] [ E_UPDATE_FAIL ] = 0; + p_PlayerHealth[ playerid ] [ E_POINTS ] = 100.0; + + p_PlayerArmour[ playerid ] [ E_UPDATE_FAIL ] = 0; + p_PlayerArmour[ playerid ] [ E_POINTS ] = 0.0; + + SetPlayerTeam( playerid, AC_DEFAULT_TEAM ); // Set everyone the same team + return 1; +} + +hook OnPlayerTakeDamage( playerid, issuerid, Float: amount, weaponid, bodypart ) +{ + new + is_npc = IsPlayerNPC( issuerid ); + + p_LastTookDamage[ playerid ] = GetTickCount( ); + p_LastDamageIssuer[ playerid ] = issuerid; + p_LastWeaponIssuer[ playerid ] = weaponid; + p_LastDamageIssued[ playerid ] = amount; + + //if( !( issuerid != INVALID_PLAYER_ID && IsPlayerInAnyVehicle( issuerid ) && GetPlayerVehicleSeat( issuerid ) == 0 && ( weaponid == WEAPON_M4 || weaponid == WEAPON_MINIGUN ) ) ) + // return 0; + + // Allow hunter damage/sparrow + if( !( issuerid != INVALID_PLAYER_ID && IsPlayerInAnyVehicle( issuerid ) && GetPlayerVehicleSeat( issuerid ) == 0 && ( weaponid == WEAPON_M4 || weaponid == WEAPON_MINIGUN ) ) && !is_npc ) + { + // Ignore unreliable and invalid damage + if( weaponid < 0 || weaponid >= sizeof( s_ValidDamageGiven ) || s_ValidDamageGiven[ weaponid ] ) + return 0; } - // Function (AC_GetPlayerHealth) - - stock Float: AC_GetPlayerHealth( playerid ) - return p_PlayerHealth[ playerid ] [ E_POINTS ]; - - // Function (AddPlayerHealth) - - stock AC_AddPlayerHealth( playerid, Float:amount ) + if( ac_IsPlayerSpawned( playerid ) ) { - p_PlayerHealth[ playerid ] [ E_POINTS ] += amount; - p_PlayerHealth[ playerid ] [ E_SYNCED ] = false; - - return SetPlayerHealth( playerid, p_PlayerHealth[ playerid ] [ E_POINTS ] ); - } - - // Function Hook (SetPlayerHealth) - - stock AC_SetPlayerHealth( playerid, Float:amount ) - { - p_PlayerHealth[ playerid ] [ E_POINTS ] = amount; - p_PlayerHealth[ playerid ] [ E_SYNCED ] = false; - - if( amount <= 0.0 && p_acSpawned{ playerid } ) + if( issuerid != INVALID_PLAYER_ID && ! is_npc ) { + if( OnPlayerTakePlayerDamage( playerid, issuerid, amount, weaponid, bodypart ) ) + { + new Float: tmp, Float: tmp_amount = amount; + + if( p_PlayerArmour[ playerid ] [ E_POINTS ] ) + { + if( ( tmp = p_PlayerArmour[ playerid ] [ E_POINTS ] - tmp_amount ) < 0.0 ) { + tmp_amount -= p_PlayerArmour[ playerid ] [ E_POINTS ]; + p_PlayerArmour[ playerid ] [ E_POINTS ] = 0.0; + } else { + p_PlayerArmour[ playerid ] [ E_POINTS ] = tmp; + tmp_amount = 0.0; + } + } + + if( ( p_PlayerHealth[ playerid ] [ E_POINTS ] -= tmp_amount ) < 0.0 ) { + p_acSpawned{ playerid } = false; // They're dead! + CallRemoteFunction( "OnPlayerDeathEx", "ddfd", playerid, issuerid, weaponid, amount, bodypart ); + } + + SetPlayerArmour( playerid, p_PlayerArmour[ playerid ] [ E_POINTS ] ); + SetPlayerHealth( playerid, p_PlayerHealth[ playerid ] [ E_POINTS ] ); + + CallRemoteFunction( "OnPlayerDamagePlayer", "ddfdd", issuerid, playerid, amount, weaponid, bodypart ); + } + } + else + { + new Float: tmp, Float: tmp_amount = amount; + + if( !( weaponid == 53 || weaponid == 54 || weaponid == 50 ) && p_PlayerArmour[ playerid ] [ E_POINTS ] ) + { + if( ( tmp = p_PlayerArmour[ playerid ] [ E_POINTS ] - tmp_amount ) < 0.0 ) { + tmp_amount -= p_PlayerArmour[ playerid ] [ E_POINTS ]; + p_PlayerArmour[ playerid ] [ E_POINTS ] = 0.0; + } else { + p_PlayerArmour[ playerid ] [ E_POINTS ] = tmp; + tmp_amount = 0.0; + } + } + + // printf("OnPlayerTakeDamage( %d, %d, %f, %d, %d ) %f", playerid, issuerid, amount, weaponid, bodypart, p_PlayerHealth[ playerid ] [ E_POINTS ] ); + if( ( p_PlayerHealth[ playerid ] [ E_POINTS ] -= tmp_amount ) <= ( weaponid == 37 ? 0.99999 : 0.0 ) ) { + // find any possible killers prior + if( ( GetTickCount( ) - p_LastTookDamage[ playerid ] ) > 2500 ) { + p_LastDamageIssuer[ playerid ] = issuerid, p_LastWeaponIssuer[ playerid ] = weaponid; + } + p_acSpawned{ playerid } = false; // They're dead! + if ( weaponid == 37 || weaponid == 51 ) SetPlayerHealth( playerid, -1 ); // Death bug fix + CallRemoteFunction( "OnPlayerDeathEx", "ddfd", playerid, p_LastDamageIssuer[ playerid ], p_LastWeaponIssuer[ playerid ], amount, bodypart ); + } + } + } + return 1; +} + +hook OnPlayerGiveDamage( playerid, damagedid, Float: amount, weaponid, bodypart ) +{ + // Ignore unreliable and invalid damage + if ( weaponid < 0 || weaponid >= sizeof( s_ValidDamageGiven ) || !s_ValidDamageGiven[ weaponid ] ) + return 0; + + if( weaponid < 0 || weaponid >= sizeof( s_ValidMaxDamage ) || amount > s_ValidMaxDamage[ weaponid ] + 2.0 ) // 2.0 safety margin + return 0; + + if( damagedid == INVALID_PLAYER_ID ) + return 0; + + if( IsPlayerInAnyVehicle( playerid ) && GetPlayerVehicleSeat( playerid ) == 0 && ( weaponid == WEAPON_M4 || weaponid == WEAPON_MINIGUN ) ) + return 0; + + if ( !IsPlayerNPC( damagedid ) ) + { + if( !ac_IsPlayerSpawned( damagedid ) ) + return 0; + + if( ( !IsPlayerStreamedIn( playerid, damagedid ) && !( GetTickCount( ) - p_acUpdateTime[ damagedid ] >= 2595 ) ) || !IsPlayerStreamedIn( damagedid, playerid ) ) + return 0; + + //printf("OnPlayerGiveDamage( %d, %d, %f, %d, %d )", playerid, damagedid, amount, weaponid, bodypart ); + //p_LastTookDamage[ damagedid ] = GetTickCount( ); + //p_LastDamageIssuer[ damagedid ] = playerid; + //p_LastWeaponIssuer[ damagedid ] = weaponid; + //p_LastDamageIssued[ damagedid ] = amount; + + if( OnPlayerTakePlayerDamage( damagedid, playerid, amount, weaponid, bodypart ) ) + { + new + Float: tmp, + Float: distance = ac_GetDistanceBetweenPlayers( playerid, damagedid ), // Calc distance between players + Float: tmp_amount = amount // this amount is extremely unreliable + ; + //printf("Proposed dmg %f kinda %f (min: %f, max: %f, rng: %f)", amount, tmp_amount, GetWeaponMinRange( weaponid ), GetWeaponMaxRange( weaponid ), distance ); + + if( distance > s_WeaponRange[ weaponid ] + 2.0 ) + return 0; //printf(" INVALID RANGE %f (MAX %f)", distance, GetWeaponMaxRange( weaponid ) ), 0; + + if( p_PlayerArmour[ damagedid ] [ E_POINTS ] ) + { + if( ( tmp = p_PlayerArmour[ damagedid ] [ E_POINTS ] - tmp_amount ) < 0.0 ) { + tmp_amount -= p_PlayerArmour[ damagedid ] [ E_POINTS ]; + p_PlayerArmour[ damagedid ] [ E_POINTS ] = 0.0; + } else { + p_PlayerArmour[ damagedid ] [ E_POINTS ] = tmp; + tmp_amount = 0.0; + } + } + + if( ( p_PlayerHealth[ damagedid ] [ E_POINTS ] -= tmp_amount ) < 0.0 ) { + p_acSpawned{ damagedid } = false; // They're dead! + CallRemoteFunction( "OnPlayerDeathEx", "ddfd", damagedid, playerid, weaponid, amount, bodypart ); + } + + SetPlayerArmour( damagedid, p_PlayerArmour[ damagedid ] [ E_POINTS ] ); + SetPlayerHealth( damagedid, p_PlayerHealth[ damagedid ] [ E_POINTS ] ); + + CallRemoteFunction( "OnPlayerDamagePlayer", "ddfdd", playerid, damagedid, amount, weaponid, bodypart ); + } + } + return 1; +} + +// Functions (Player) +stock vCheckForHealthHacks( playerid, iTicks ) +{ + new + Float: currentHealth, + Float: currentArmour + ; + GetPlayerHealth( playerid, currentHealth ); + GetPlayerArmour( playerid, currentArmour ); + + // Lag Calculations + new + Float: fHitDamage = p_LastDamageIssued[ playerid ], + Float: fArmourDamage, + Float: fHealthDamage + ; + + if( fHitDamage > currentArmour ) { + fArmourDamage = currentArmour; + fHealthDamage = fHitDamage - currentArmour; + } + else fArmourDamage = fHitDamage; + + // Begin Health Hack Detection + if( iTicks > p_PlayerHealth[ playerid ] [ E_UPDATE_TIME ] ) + { + new currentHealthInt = floatround( currentHealth, floatround_floor ); + new healthShouldBeInt = floatround( p_PlayerHealth[ playerid ] [ E_POINTS ], floatround_floor ); + + if( currentHealthInt == healthShouldBeInt ) + p_PlayerHealth[ playerid ] [ E_SYNCED ] = true; + + if( !p_PlayerHealth[ playerid ] [ E_SYNCED ] ) + { + if( currentHealthInt > healthShouldBeInt ) + { + switch( p_PlayerHealth[ playerid ] [ E_UPDATE_FAIL ]++ ) + { + case 0 .. 9: SetPlayerHealth( playerid, p_PlayerHealth[ playerid ] [ E_POINTS ] ); + case 10: SendClientMessage( playerid, 0xa9c4e4ff, "You have been kicked as you are desynced from the server. Please relog!" ), KickPlayerTimed( playerid ), printf("[health] Player %d was desynced thus kicked.", playerid); + } + } + } + else + { + p_PlayerHealth[ playerid ] [ E_UPDATE_FAIL ] = 0; + + if( healthShouldBeInt > currentHealthInt ) + p_PlayerHealth[ playerid ] [ E_POINTS ] = currentHealth; + + if( currentHealthInt > healthShouldBeInt && currentHealthInt <= 255 && currentHealthInt > 0 ) + SetPlayerHealth( playerid, p_PlayerHealth[ playerid ] [ E_POINTS ] ); + + currentHealthInt = floatround( currentHealth, floatround_floor ); + healthShouldBeInt = floatround( p_PlayerHealth[ playerid ] [ E_POINTS ], floatround_floor ); + + new dmgOne = floatround( currentHealthInt - fHealthDamage, floatround_floor ); + new dmgTwo = floatround( currentHealthInt - fHealthDamage, floatround_ceil ); + + if( !( currentHealthInt == healthShouldBeInt || dmgOne == healthShouldBeInt || dmgTwo == healthShouldBeInt ) ) + { + SetPlayerHealth( playerid, p_PlayerHealth[ playerid ] [ E_POINTS ] ); + //printf("[health][%d] %d seems to health hack (server health: %d and client health: %d, health dmg: %f, armour dmg: %f).", playerid, playerid, healthShouldBeInt, currentHealthInt, fHealthDamage, fArmourDamage ); + } + } + p_PlayerHealth[ playerid ] [ E_UPDATE_TIME ] = iTicks + 1000; + } + + // Begin Armour Hack Detection + if( iTicks > p_PlayerArmour[ playerid ] [ E_UPDATE_TIME ] ) + { + new currentArmourInt = floatround( currentArmour, floatround_floor ); + new ArmourShouldBeInt = floatround( p_PlayerArmour[ playerid ] [ E_POINTS ], floatround_floor ); + + if( currentArmourInt == ArmourShouldBeInt ) + p_PlayerArmour[ playerid ] [ E_SYNCED ] = true; + + if( !p_PlayerArmour[ playerid ] [ E_SYNCED ] ) + { + if( currentArmourInt > ArmourShouldBeInt ) + { + switch( p_PlayerArmour[ playerid ] [ E_UPDATE_FAIL ]++ ) + { + case 0 .. 9: SetPlayerArmour( playerid, p_PlayerArmour[ playerid ] [ E_POINTS ] ); + case 10: SendClientMessage( playerid, 0xa9c4e4ff, "You have been kicked as you are desynced from the server. Please relog!" ), KickPlayerTimed( playerid ), printf("[armour] Player %d was desynced thus kicked.", playerid); + } + } + } + else + { + p_PlayerArmour[ playerid ] [ E_UPDATE_FAIL ] = 0; + + if( ArmourShouldBeInt > currentArmourInt ) + p_PlayerArmour[ playerid ] [ E_POINTS ] = currentArmour; + + if( currentArmourInt > ArmourShouldBeInt && currentArmourInt <= 255 && currentArmourInt > 0 ) + SetPlayerArmour( playerid, p_PlayerArmour[ playerid ] [ E_POINTS ] ); + + currentArmourInt = floatround( currentArmour, floatround_floor ); + ArmourShouldBeInt = floatround( p_PlayerArmour[ playerid ] [ E_POINTS ], floatround_floor ); + + new dmgOne = floatround( currentArmourInt - fArmourDamage, floatround_floor ); + new dmgTwo = floatround( currentArmourInt - fArmourDamage, floatround_ceil ); + + if( !( currentArmourInt == ArmourShouldBeInt || dmgOne == ArmourShouldBeInt || dmgTwo == ArmourShouldBeInt ) ) + { + SetPlayerArmour( playerid, p_PlayerArmour[ playerid ] [ E_POINTS ] ); + //printf("[armour] %d seems to armour hack (server armour: %d and client armour: %d, health dmg: %f, armour dmg: %f).", playerid, ArmourShouldBeInt, currentArmourInt, fHealthDamage, fArmourDamage ); + } + } + p_PlayerArmour[ playerid ] [ E_UPDATE_TIME ] = iTicks + 1000; + } +} + +hook OnPlayerDeath(playerid, killerid, reason) +{ + if ( !IsPlayerNPC( playerid ) ) + { + // Health/Armour Hack + if( GetPVarInt( playerid, "CustomKill" ) ) + { + new + customKiller = GetPVarInt( playerid, "KillerID" ); + + CallRemoteFunction( "OnPlayerDeathEx", "ddfd", playerid, customKiller != playerid ? customKiller : INVALID_PLAYER_ID, GetPVarInt( playerid, "WeaponID" ), 3.3, 3 ); + + DeletePVar( playerid, "KillerID" ); + DeletePVar( playerid, "WeaponID" ); + DeletePVar( playerid, "CustomKill" ); + } + + // Died in Vehicle + else if( GetPlayerVehicleID( playerid ) && ac_IsPlayerSpawned( playerid ) ) + { if( ( GetTickCount( ) - p_LastTookDamage[ playerid ] ) > 2500 ) - p_LastDamageIssuer[ playerid ] = INVALID_PLAYER_ID, p_LastWeaponIssuer[ playerid ] = 47; + p_LastDamageIssuer[ playerid ] = INVALID_PLAYER_ID, p_LastWeaponIssuer[ playerid ] = 51; p_acSpawned{ playerid } = false; // They're dead! - OnPlayerDeathEx( playerid, p_LastDamageIssuer[ playerid ], p_LastWeaponIssuer[ playerid ], 3.3, 3 ); - } + CallRemoteFunction( "OnPlayerDeathEx", "ddfd", playerid, p_LastDamageIssuer[ playerid ], p_LastWeaponIssuer[ playerid ], 3.3, 3 ); + } - return SetPlayerHealth( playerid, amount ); - } + // General + p_acSpawned{ playerid } = false; - #if defined _ALS_SetPlayerHealth - #undef SetPlayerHealth - #else - #define _ALS_SetPlayerHealth - #endif - #define SetPlayerHealth AC_SetPlayerHealth + // Airbrake + p_abLastTick[ playerid ] = GetTickCount( ) + 3000; + } + return 1; +} - // Function Hook (SetPlayerArmour) +/* ** Functions ** */ +stock ForcePlayerKill( playerid, killerid, weaponid ) +{ + SetPVarInt( playerid, "KillerID", killerid ); + SetPVarInt( playerid, "WeaponID", weaponid ); + SetPVarInt( playerid, "CustomKill", 1 ); - stock AC_SetPlayerArmour( playerid, Float:amount ) - { - p_PlayerArmour[ playerid ] [ E_POINTS ] = amount; - p_PlayerArmour[ playerid ] [ E_SYNCED ] = false; - return SetPlayerArmour( playerid, amount ); - } - - #if defined _ALS_SetPlayerArmour - #undef SetPlayerArmour - #else - #define _ALS_SetPlayerArmour - #endif - #define SetPlayerArmour AC_SetPlayerArmour - - // Function Hook (SetPlayerTeam) - - stock AC_SetPlayerTeam( playerid, teamid ) - { - if( teamid != AC_DEFAULT_TEAM ) - printf("[ACWarning] You cannot use SetPlayerTeam as you have hitpoint hack detection enabled (teamid %d, default %d).", teamid, AC_DEFAULT_TEAM ); - - return SetPlayerTeam( playerid, AC_DEFAULT_TEAM ); - } - - #if defined _ALS_SetPlayerTeam - #undef SetPlayerTeam - #else - #define _ALS_SetPlayerArmour - #endif - #define SetPlayerTeam AC_SetPlayerTeam - - // Functions (Player) - stock vCheckForHealthHacks( playerid, iTicks ) - { - new - Float: currentHealth, - Float: currentArmour - ; - GetPlayerHealth( playerid, currentHealth ); - GetPlayerArmour( playerid, currentArmour ); - - // Lag Calculations - new - Float: fHitDamage = p_LastDamageIssued[ playerid ], - Float: fArmourDamage, - Float: fHealthDamage - ; - - if( fHitDamage > currentArmour ) { - fArmourDamage = currentArmour; - fHealthDamage = fHitDamage - currentArmour; - } - else fArmourDamage = fHitDamage; - - // Begin Health Hack Detection - if( iTicks > p_PlayerHealth[ playerid ] [ E_UPDATE_TIME ] ) - { - new currentHealthInt = floatround( currentHealth, floatround_floor ); - new healthShouldBeInt = floatround( p_PlayerHealth[ playerid ] [ E_POINTS ], floatround_floor ); - - if( currentHealthInt == healthShouldBeInt ) - p_PlayerHealth[ playerid ] [ E_SYNCED ] = true; - - if( !p_PlayerHealth[ playerid ] [ E_SYNCED ] ) - { - if( currentHealthInt > healthShouldBeInt ) - { - switch( p_PlayerHealth[ playerid ] [ E_UPDATE_FAIL ]++ ) - { - case 0 .. 9: SetPlayerHealth( playerid, p_PlayerHealth[ playerid ] [ E_POINTS ] ); - case 10: SendClientMessage( playerid, 0xa9c4e4ff, "You have been kicked as you are desynced from the server. Please relog!" ), KickPlayerTimed( playerid ), printf("[health] Player %d was desynced thus kicked.", playerid); - } - } - } - else - { - p_PlayerHealth[ playerid ] [ E_UPDATE_FAIL ] = 0; - - if( healthShouldBeInt > currentHealthInt ) - p_PlayerHealth[ playerid ] [ E_POINTS ] = currentHealth; - - if( currentHealthInt > healthShouldBeInt && currentHealthInt <= 255 && currentHealthInt > 0 ) - SetPlayerHealth( playerid, p_PlayerHealth[ playerid ] [ E_POINTS ] ); - - currentHealthInt = floatround( currentHealth, floatround_floor ); - healthShouldBeInt = floatround( p_PlayerHealth[ playerid ] [ E_POINTS ], floatround_floor ); - - new dmgOne = floatround( currentHealthInt - fHealthDamage, floatround_floor ); - new dmgTwo = floatround( currentHealthInt - fHealthDamage, floatround_ceil ); - - if( !( currentHealthInt == healthShouldBeInt || dmgOne == healthShouldBeInt || dmgTwo == healthShouldBeInt ) ) - { - SetPlayerHealth( playerid, p_PlayerHealth[ playerid ] [ E_POINTS ] ); - //printf("[health][%d] %d seems to health hack (server health: %d and client health: %d, health dmg: %f, armour dmg: %f).", playerid, playerid, healthShouldBeInt, currentHealthInt, fHealthDamage, fArmourDamage ); - } - } - p_PlayerHealth[ playerid ] [ E_UPDATE_TIME ] = iTicks + 1000; - } - - // Begin Armour Hack Detection - if( iTicks > p_PlayerArmour[ playerid ] [ E_UPDATE_TIME ] ) - { - new currentArmourInt = floatround( currentArmour, floatround_floor ); - new ArmourShouldBeInt = floatround( p_PlayerArmour[ playerid ] [ E_POINTS ], floatround_floor ); - - if( currentArmourInt == ArmourShouldBeInt ) - p_PlayerArmour[ playerid ] [ E_SYNCED ] = true; - - if( !p_PlayerArmour[ playerid ] [ E_SYNCED ] ) - { - if( currentArmourInt > ArmourShouldBeInt ) - { - switch( p_PlayerArmour[ playerid ] [ E_UPDATE_FAIL ]++ ) - { - case 0 .. 9: SetPlayerArmour( playerid, p_PlayerArmour[ playerid ] [ E_POINTS ] ); - case 10: SendClientMessage( playerid, 0xa9c4e4ff, "You have been kicked as you are desynced from the server. Please relog!" ), KickPlayerTimed( playerid ), printf("[armour] Player %d was desynced thus kicked.", playerid); - } - } - } - else - { - p_PlayerArmour[ playerid ] [ E_UPDATE_FAIL ] = 0; - - if( ArmourShouldBeInt > currentArmourInt ) - p_PlayerArmour[ playerid ] [ E_POINTS ] = currentArmour; - - if( currentArmourInt > ArmourShouldBeInt && currentArmourInt <= 255 && currentArmourInt > 0 ) - SetPlayerArmour( playerid, p_PlayerArmour[ playerid ] [ E_POINTS ] ); - - currentArmourInt = floatround( currentArmour, floatround_floor ); - ArmourShouldBeInt = floatround( p_PlayerArmour[ playerid ] [ E_POINTS ], floatround_floor ); - - new dmgOne = floatround( currentArmourInt - fArmourDamage, floatround_floor ); - new dmgTwo = floatround( currentArmourInt - fArmourDamage, floatround_ceil ); - - if( !( currentArmourInt == ArmourShouldBeInt || dmgOne == ArmourShouldBeInt || dmgTwo == ArmourShouldBeInt ) ) - { - SetPlayerArmour( playerid, p_PlayerArmour[ playerid ] [ E_POINTS ] ); - //printf("[armour] %d seems to armour hack (server armour: %d and client armour: %d, health dmg: %f, armour dmg: %f).", playerid, ArmourShouldBeInt, currentArmourInt, fHealthDamage, fArmourDamage ); - } - } - p_PlayerArmour[ playerid ] [ E_UPDATE_TIME ] = iTicks + 1000; - } - } - - /* - @function ForcePlayerKill - @description forces a kill on a player - @return void - */ - stock ForcePlayerKill( playerid, killerid, weaponid ) - { - SetPVarInt( playerid, "KillerID", killerid ); - SetPVarInt( playerid, "WeaponID", weaponid ); - SetPVarInt( playerid, "CustomKill", 1 ); - - SetPlayerHealth( playerid, -1 ); - } - - #define AC_HITPOINTS_INCLUDED -#endif + SetPlayerHealth( playerid, -1 ); +} diff --git a/pawno/include/anticheat/hooks.inc b/pawno/include/anticheat/hooks.inc index 35d9ee6..df073e2 100644 --- a/pawno/include/anticheat/hooks.inc +++ b/pawno/include/anticheat/hooks.inc @@ -24,525 +24,182 @@ */ #if !defined AC_INCLUDED - #include < a_samp > + #define AC_INCLUDED +#else + #endinput +#endif - // Function Hook (PutPlayerInVehicle) +/* ** Includes ** */ +#include < YSI\y_hooks > - stock AC_PutPlayerInVehicle(playerid, vehicleid, seatid) +// Function Hook (PutPlayerInVehicle) + +stock AC_PutPlayerInVehicle(playerid, vehicleid, seatid) +{ + // Remote Jacking + p_remoteJackData[ playerid ] [ E_LAST_VEH ] = vehicleid; + + // Airbreak + p_abLastTick[ playerid ] = GetTickCount( ) + 3000; + return PutPlayerInVehicle(playerid, vehicleid, seatid); +} + +#if defined _ALS_PutPlayerInVehicle + #undef PutPlayerInVehicle +#else + #define _ALS_PutPlayerInVehicle +#endif +#define PutPlayerInVehicle AC_PutPlayerInVehicle + +// Callback Hook (OnPlayerConnect) + +hook OnPlayerConnect( playerid ) +{ + if ( !IsPlayerNPC( playerid ) ) { - // Remote Jacking - p_remoteJackData[ playerid ] [ E_LAST_VEH ] = vehicleid; + // Remove Vending Machines + RemoveBuildingForPlayer( playerid, 1302, 0.0, 0.0, 0.0, 6000.0 ); + RemoveBuildingForPlayer( playerid, 1209, 0.0, 0.0, 0.0, 6000.0 ); + RemoveBuildingForPlayer( playerid, 955, 0.0, 0.0, 0.0, 6000.00 ); + RemoveBuildingForPlayer( playerid, 956, 0.0, 0.0, 0.0, 6000.00 ); + RemoveBuildingForPlayer( playerid, 1775, 0.0, 0.0, 0.0, 6000.0 ); + RemoveBuildingForPlayer( playerid, 1776, 0.0, 0.0, 0.0, 6000.0 ); + RemoveBuildingForPlayer( playerid, 1977, 0.0, 0.0, 0.0, 6000.0 ); - // Airbreak - p_abLastTick[ playerid ] = GetTickCount( ) + 3000; - return PutPlayerInVehicle(playerid, vehicleid, seatid); + // Reset Variables + p_acSpawned { playerid } = false; + //p_SpectatePermission { playerid } = false; + p_abDetected { playerid } = 0; + p_abResetTimer [ playerid ] = -1; + p_abLastTick [ playerid ] = GetTickCount( ) + 3000; + p_FlyHacksWarns { playerid } = 3; + p_cbugWarns { playerid } = 0; + + for ( new i = 0; i < AC_MAX_WEAPONS; i++ ) + p_PlayerHasWeapon [ playerid ] { i } = false; + } + return 1; +} + +// Callback Hook (OnPlayerSpawn) + +hook OnPlayerSpawn( playerid ) +{ + // General + p_acSpawned{ playerid } = true; + + // Weapon Hack + for ( new i = 0; i < 3; i++ ) + { + new + weaponid = mAvailableSpawns[ p_SelectedClassID[ playerid ] ] [ E_WEAPONS ] [ i ]; + + if( weaponid != -1 && weaponid < AC_MAX_WEAPONS ) + p_PlayerHasWeapon[ playerid ] { weaponid } = true; } - #if defined _ALS_PutPlayerInVehicle - #undef PutPlayerInVehicle - #else - #define _ALS_PutPlayerInVehicle - #endif - #define PutPlayerInVehicle AC_PutPlayerInVehicle + // Airbrake + p_abDetected{ playerid } = 0; + p_abLastTick[ playerid ] = GetTickCount( ) + 3000; + return 1; +} - // Callback Hook (OnPlayerConnect) +// Hook (OnPlayerStateChange) - public OnPlayerConnect( playerid ) +hook OnPlayerStateChange( playerid, newstate, oldstate ) +{ + if ( !IsPlayerNPC( playerid ) ) { - if ( !IsPlayerNPC( playerid ) ) + // Spectate Hacks + /*if( oldstate == PLAYER_STATE_SPECTATING && newstate != PLAYER_STATE_SPECTATING ) { + p_PlayerSpectateUpdateTime[ playerid ] = GetTickCount( ) + 1250; + p_SpectatePermission{ playerid } = false; // Bugs otherwise dunno why + }*/ + + // Weapon Hacks - credits to wups + if( newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER ) { - // Remove Vending Machines - RemoveBuildingForPlayer( playerid, 1302, 0.0, 0.0, 0.0, 6000.0 ); - RemoveBuildingForPlayer( playerid, 1209, 0.0, 0.0, 0.0, 6000.0 ); - RemoveBuildingForPlayer( playerid, 955, 0.0, 0.0, 0.0, 6000.00 ); - RemoveBuildingForPlayer( playerid, 956, 0.0, 0.0, 0.0, 6000.00 ); - RemoveBuildingForPlayer( playerid, 1775, 0.0, 0.0, 0.0, 6000.0 ); - RemoveBuildingForPlayer( playerid, 1776, 0.0, 0.0, 0.0, 6000.0 ); - RemoveBuildingForPlayer( playerid, 1977, 0.0, 0.0, 0.0, 6000.0 ); + switch ( GetVehicleModel( GetPlayerVehicleID( playerid ) ) ) + { + case 457: + p_PlayerHasWeapon[ playerid ] { 2 } = true; - // Reset Variables - p_PlayerHealth [ playerid ] [ E_UPDATE_FAIL ] = 0; - p_PlayerArmour [ playerid ] [ E_UPDATE_FAIL ] = 0; - p_acSpawned { playerid } = false; - //p_SpectatePermission { playerid } = false; - p_abDetected { playerid } = 0; - p_abResetTimer [ playerid ] = -1; - p_abLastTick [ playerid ] = GetTickCount( ) + 3000; - p_FlyHacksWarns { playerid } = 3; - p_cbugWarns { playerid } = 0; + case 592, 577, 511, 512, 520, 593, 553, 476, 519, 460, 513, 548, 425, 417, 487, 488, 497, 563, 447, 469, 539: + p_PlayerHasWeapon[ playerid ] { 46 } = true; - for ( new i = 0; i < AC_MAX_WEAPONS; i++ ) - p_PlayerHasWeapon [ playerid ] { i } = false; - } - - #if defined SAMPAC_OnPlayerConnect - return SAMPAC_OnPlayerConnect( playerid ); - #else - return 1; - #endif - } - - #if defined SAMPAC_OnPlayerConnect - forward SAMPAC_OnPlayerConnect( playerid ); - #endif - #if defined _ALS_OnPlayerConnect - #undef OnPlayerConnect - #else - #define _ALS_OnPlayerConnect - #endif - #define OnPlayerConnect SAMPAC_OnPlayerConnect - - // Callback Hook (OnPlayerSpawn) - - public OnPlayerSpawn( playerid ) - { - // General - p_acSpawned{ playerid } = true; - - // Health/Armour Hack - p_PlayerHealth[ playerid ] [ E_UPDATE_FAIL ] = 0; - p_PlayerHealth[ playerid ] [ E_POINTS ] = 100.0; - - p_PlayerArmour[ playerid ] [ E_UPDATE_FAIL ] = 0; - p_PlayerArmour[ playerid ] [ E_POINTS ] = 0.0; - - SetPlayerTeam( playerid, AC_DEFAULT_TEAM ); // Set everyone the same team - - // Weapon Hack - for ( new i = 0; i < 3; i++ ) - { - new - weaponid = mAvailableSpawns[ p_SelectedClassID[ playerid ] ] [ E_WEAPONS ] [ i ]; - - if( weaponid != -1 && weaponid < AC_MAX_WEAPONS ) - p_PlayerHasWeapon[ playerid ] { weaponid } = true; + case 596, 597, 598, 599: + p_PlayerHasWeapon[ playerid ] { 25 } = true; + } } // Airbrake - p_abDetected{ playerid } = 0; - p_abLastTick[ playerid ] = GetTickCount( ) + 3000; + p_abLastTick[ playerid ] = GetTickCount( ) + 3000; + } + return 1; +} - #if defined SAMPAC_OnPlayerSpawn - return SAMPAC_OnPlayerSpawn( playerid ); - #else - return 1; - #endif - } +// Hook (OnPlayerUpdate) - #if defined SAMPAC_OnPlayerSpawn - forward SAMPAC_OnPlayerSpawn( playerid ); - #endif - #if defined _ALS_OnPlayerSpawn - #undef OnPlayerSpawn - #else - #define _ALS_OnPlayerSpawn - #endif - #define OnPlayerSpawn SAMPAC_OnPlayerSpawn +hook OnPlayerUpdate( playerid ) +{ + if( !ac_IsPlayerSpawned( playerid ) ) + return 0; // Not Spawned, No SYNC! - // Callback Hook (OnPlayerDeath) - - public OnPlayerDeath(playerid, killerid, reason) + if( !IsPlayerNPC( playerid ) ) { - if ( !IsPlayerNPC( playerid ) ) - { - // Health/Armour Hack - if( GetPVarInt( playerid, "CustomKill" ) ) - { - new - customKiller = GetPVarInt( playerid, "KillerID" ); - - CallRemoteFunction( "OnPlayerDeathEx", "ddfd", playerid, customKiller != playerid ? customKiller : INVALID_PLAYER_ID, GetPVarInt( playerid, "WeaponID" ), 3.3, 3 ); - - DeletePVar( playerid, "KillerID" ); - DeletePVar( playerid, "WeaponID" ); - DeletePVar( playerid, "CustomKill" ); - } - - else if( GetPlayerVehicleID( playerid ) && ac_IsPlayerSpawned( playerid ) ) // Died in Vehicle - { - if( ( GetTickCount( ) - p_LastTookDamage[ playerid ] ) > 2500 ) - p_LastDamageIssuer[ playerid ] = INVALID_PLAYER_ID, p_LastWeaponIssuer[ playerid ] = 51; - - p_acSpawned{ playerid } = false; // They're dead! - CallRemoteFunction( "OnPlayerDeathEx", "ddfd", playerid, p_LastDamageIssuer[ playerid ], p_LastWeaponIssuer[ playerid ], 3.3, 3 ); - } - - // General - p_acSpawned{ playerid } = false; - - // Airbrake - p_abLastTick[ playerid ] = GetTickCount( ) + 3000; - } - - #if defined SAMPAC_OnPlayerDeath - return SAMPAC_OnPlayerDeath(playerid, killerid, reason); - #else - return 1; - #endif - } - - #if defined SAMPAC_OnPlayerDeath - forward SAMPAC_OnPlayerDeath(playerid, killerid, reason); - #endif - #if defined _ALS_OnPlayerDeath - #undef OnPlayerDeath - #else - #define _ALS_OnPlayerDeath - #endif - #define OnPlayerDeath SAMPAC_OnPlayerDeath - - // Callback Hook (OnPlayerTakeDamage) - - public OnPlayerTakeDamage( playerid, issuerid, Float: amount, weaponid, bodypart ) - { - new - is_npc = IsPlayerNPC( issuerid ); - - p_LastTookDamage[ playerid ] = GetTickCount( ); - p_LastDamageIssuer[ playerid ] = issuerid; - p_LastWeaponIssuer[ playerid ] = weaponid; - p_LastDamageIssued[ playerid ] = amount; - - //if( !( issuerid != INVALID_PLAYER_ID && IsPlayerInAnyVehicle( issuerid ) && GetPlayerVehicleSeat( issuerid ) == 0 && ( weaponid == WEAPON_M4 || weaponid == WEAPON_MINIGUN ) ) ) - // return 0; - - // Allow hunter damage/sparrow - if( !( issuerid != INVALID_PLAYER_ID && IsPlayerInAnyVehicle( issuerid ) && GetPlayerVehicleSeat( issuerid ) == 0 && ( weaponid == WEAPON_M4 || weaponid == WEAPON_MINIGUN ) ) && !is_npc ) - { - // Ignore unreliable and invalid damage - if( weaponid < 0 || weaponid >= sizeof( s_ValidDamageGiven ) || s_ValidDamageGiven[ weaponid ] ) - return 0; - } - - if( ac_IsPlayerSpawned( playerid ) ) - { - if( issuerid != INVALID_PLAYER_ID && ! is_npc ) - { - if( OnPlayerTakePlayerDamage( playerid, issuerid, amount, weaponid, bodypart ) ) - { - new Float: tmp, Float: tmp_amount = amount; - - if( p_PlayerArmour[ playerid ] [ E_POINTS ] ) - { - if( ( tmp = p_PlayerArmour[ playerid ] [ E_POINTS ] - tmp_amount ) < 0.0 ) { - tmp_amount -= p_PlayerArmour[ playerid ] [ E_POINTS ]; - p_PlayerArmour[ playerid ] [ E_POINTS ] = 0.0; - } else { - p_PlayerArmour[ playerid ] [ E_POINTS ] = tmp; - tmp_amount = 0.0; - } - } - - if( ( p_PlayerHealth[ playerid ] [ E_POINTS ] -= tmp_amount ) < 0.0 ) { - p_acSpawned{ playerid } = false; // They're dead! - CallRemoteFunction( "OnPlayerDeathEx", "ddfd", playerid, issuerid, weaponid, amount, bodypart ); - } - - SetPlayerArmour( playerid, p_PlayerArmour[ playerid ] [ E_POINTS ] ); - SetPlayerHealth( playerid, p_PlayerHealth[ playerid ] [ E_POINTS ] ); - - CallRemoteFunction( "OnPlayerDamagePlayer", "ddfdd", issuerid, playerid, amount, weaponid, bodypart ); - } - } - else - { - new Float: tmp, Float: tmp_amount = amount; - - if( !( weaponid == 53 || weaponid == 54 || weaponid == 50 ) && p_PlayerArmour[ playerid ] [ E_POINTS ] ) - { - if( ( tmp = p_PlayerArmour[ playerid ] [ E_POINTS ] - tmp_amount ) < 0.0 ) { - tmp_amount -= p_PlayerArmour[ playerid ] [ E_POINTS ]; - p_PlayerArmour[ playerid ] [ E_POINTS ] = 0.0; - } else { - p_PlayerArmour[ playerid ] [ E_POINTS ] = tmp; - tmp_amount = 0.0; - } - } - - //printf("OnPlayerTakeDamage( %d, %d, %f, %d, %d ) %f", playerid, issuerid, amount, weaponid, bodypart, p_PlayerHealth[ playerid ] [ E_POINTS ] ); - if( ( p_PlayerHealth[ playerid ] [ E_POINTS ] -= tmp_amount ) <= ( weaponid == 37 ? 0.99999 : 0.0 ) ) { - p_acSpawned{ playerid } = false; // They're dead! - if ( weaponid == 37 ) SetPlayerHealth( playerid, -1 ); - CallRemoteFunction( "OnPlayerDeathEx", "ddfd", playerid, issuerid, weaponid, amount, bodypart ); - } - } - } - - #if defined SAMPAC_OnPlayerTakeDamage - return SAMPAC_OnPlayerTakeDamage(playerid, issuerid, amount, weaponid, bodypart); - #else - return 0; - #endif - } - - #if defined SAMPAC_OnPlayerTakeDamage - forward SAMPAC_OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart); - #endif - #if defined _ALS_OnPlayerTakeDamage - #undef OnPlayerTakeDamage - #else - #define _ALS_OnPlayerTakeDamage - #endif - #define OnPlayerTakeDamage SAMPAC_OnPlayerTakeDamage - - - // Callback Hook (OnPlayerGiveDamage) - - public OnPlayerGiveDamage( playerid, damagedid, Float: amount, weaponid, bodypart ) - { - // Ignore unreliable and invalid damage - if ( weaponid < 0 || weaponid >= sizeof( s_ValidDamageGiven ) || !s_ValidDamageGiven[ weaponid ] ) - return 0; - - if( weaponid < 0 || weaponid >= sizeof( s_ValidMaxDamage ) || amount > s_ValidMaxDamage[ weaponid ] + 2.0 ) // 2.0 safety margin - return 0; - - if( damagedid == INVALID_PLAYER_ID ) - return 0; - - if( IsPlayerInAnyVehicle( playerid ) && GetPlayerVehicleSeat( playerid ) == 0 && ( weaponid == WEAPON_M4 || weaponid == WEAPON_MINIGUN ) ) - return 0; - - if ( !IsPlayerNPC( damagedid ) ) - { - if( !ac_IsPlayerSpawned( damagedid ) ) - return 0; - - if( ( !IsPlayerStreamedIn( playerid, damagedid ) && !( GetTickCount( ) - p_acUpdateTime[ damagedid ] >= 2595 ) ) || !IsPlayerStreamedIn( damagedid, playerid ) ) - return 0; - - //printf("OnPlayerGiveDamage( %d, %d, %f, %d, %d )", playerid, damagedid, amount, weaponid, bodypart ); - //p_LastTookDamage[ damagedid ] = GetTickCount( ); - //p_LastDamageIssuer[ damagedid ] = playerid; - //p_LastWeaponIssuer[ damagedid ] = weaponid; - //p_LastDamageIssued[ damagedid ] = amount; - - if( OnPlayerTakePlayerDamage( damagedid, playerid, amount, weaponid, bodypart ) ) - { - new - Float: tmp, - Float: distance = ac_GetDistanceBetweenPlayers( playerid, damagedid ), // Calc distance between players - Float: tmp_amount = amount // this amount is extremely unreliable - ; - //printf("Proposed dmg %f kinda %f (min: %f, max: %f, rng: %f)", amount, tmp_amount, GetWeaponMinRange( weaponid ), GetWeaponMaxRange( weaponid ), distance ); - - if( distance > s_WeaponRange[ weaponid ] + 2.0 ) - return 0; //printf(" INVALID RANGE %f (MAX %f)", distance, GetWeaponMaxRange( weaponid ) ), 0; - - if( p_PlayerArmour[ damagedid ] [ E_POINTS ] ) - { - if( ( tmp = p_PlayerArmour[ damagedid ] [ E_POINTS ] - tmp_amount ) < 0.0 ) { - tmp_amount -= p_PlayerArmour[ damagedid ] [ E_POINTS ]; - p_PlayerArmour[ damagedid ] [ E_POINTS ] = 0.0; - } else { - p_PlayerArmour[ damagedid ] [ E_POINTS ] = tmp; - tmp_amount = 0.0; - } - } - - if( ( p_PlayerHealth[ damagedid ] [ E_POINTS ] -= tmp_amount ) < 0.0 ) { - p_acSpawned{ damagedid } = false; // They're dead! - CallRemoteFunction( "OnPlayerDeathEx", "ddfd", damagedid, playerid, weaponid, amount, bodypart ); - } - - SetPlayerArmour( damagedid, p_PlayerArmour[ damagedid ] [ E_POINTS ] ); - SetPlayerHealth( damagedid, p_PlayerHealth[ damagedid ] [ E_POINTS ] ); - - CallRemoteFunction( "OnPlayerDamagePlayer", "ddfdd", playerid, damagedid, amount, weaponid, bodypart ); - } - } - - #if defined SAMPAC_OnPlayerGiveDamage - return SAMPAC_OnPlayerGiveDamage( playerid, damagedid, Float: amount, weaponid, bodypart ); - #else - return 0; - #endif - } - - #if defined SAMPAC_OnPlayerGiveDamage - forward SAMPAC_OnPlayerGiveDamage( playerid, damagedid, Float: amount, weaponid, bodypart ); - #endif - #if defined _ALS_OnPlayerGiveDamage - #undef OnPlayerGiveDamage - #else - #define _ALS_OnPlayerGiveDamage - #endif - #define OnPlayerGiveDamage SAMPAC_OnPlayerGiveDamage - - // Hook (OnPlayerStateChange) - - public OnPlayerStateChange( playerid, newstate, oldstate ) - { - if ( !IsPlayerNPC( playerid ) ) - { - // Spectate Hacks - /*if( oldstate == PLAYER_STATE_SPECTATING && newstate != PLAYER_STATE_SPECTATING ) { - p_PlayerSpectateUpdateTime[ playerid ] = GetTickCount( ) + 1250; - p_SpectatePermission{ playerid } = false; // Bugs otherwise dunno why - }*/ - - // Weapon Hacks - credits to wups - if( newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER ) - { - switch ( GetVehicleModel( GetPlayerVehicleID( playerid ) ) ) - { - case 457: - p_PlayerHasWeapon[ playerid ] { 2 } = true; - - case 592, 577, 511, 512, 520, 593, 553, 476, 519, 460, 513, 548, 425, 417, 487, 488, 497, 563, 447, 469, 539: - p_PlayerHasWeapon[ playerid ] { 46 } = true; - - case 596, 597, 598, 599: - p_PlayerHasWeapon[ playerid ] { 25 } = true; - } - } - - // Airbrake - p_abLastTick[ playerid ] = GetTickCount( ) + 3000; - } - - #if defined SAMPAC_OnPlayerStateChange - return SAMPAC_OnPlayerStateChange( playerid, newstate, oldstate ); - #else - return 1; - #endif - } - - #if defined SAMPAC_OnPlayerStateChange - forward SAMPAC_OnPlayerStateChange( playerid, newstate, oldstate ); - #endif - #if defined _ALS_OnPlayerStateChange - #undef OnPlayerStateChange - #else - #define _ALS_OnPlayerStateChange - #endif - #define OnPlayerStateChange SAMPAC_OnPlayerStateChange - - // Hook (OnPlayerUpdate) - - public OnPlayerUpdate( playerid ) - { - if( !ac_IsPlayerSpawned( playerid ) ) - return 0; // Not Spawned, No SYNC! - - if( !IsPlayerNPC( playerid ) ) - { - new - iState = GetPlayerState( playerid ); - - p_acUpdateTime[ playerid ] = GetTickCount( ); - //bCheckForSpectatingHacks ( playerid, iState, iTicks ); - - if( iState != PLAYER_STATE_SPECTATING ) - { - bCheckForAirbrake ( playerid, p_acUpdateTime[ playerid ], iState ); - vCheckForHealthHacks ( playerid, p_acUpdateTime[ playerid ] ); - vCheckForFlyHacks ( playerid, p_acUpdateTime[ playerid ] ); - //vWeaponHackCheck ( playerid, p_acUpdateTime[ playerid ] ); - bCheckPlayerRemoteJacking ( playerid ); - } - } - - #if defined SAMPAC_OnPlayerUpdate - return SAMPAC_OnPlayerUpdate( playerid ); - #else - return 1; - #endif - } - - #if defined SAMPAC_OnPlayerUpdate - forward SAMPAC_OnPlayerUpdate( playerid ); - #endif - #if defined _ALS_OnPlayerUpdate - #undef OnPlayerUpdate - #else - #define _ALS_OnPlayerUpdate - #endif - #define OnPlayerUpdate SAMPAC_OnPlayerUpdate - - // Hook (OnPlayerRequestClass) - - public OnPlayerRequestClass( playerid, classid ) - { - // General - p_acSpawned{ playerid } = false; - p_SelectedClassID[ playerid ] = classid; - - #if defined SAMPAC_OnPlayerRequestClass - return SAMPAC_OnPlayerRequestClass( playerid, classid ); - #else - return 1; - #endif - } - - #if defined SAMPAC_OnPlayerRequestClass - forward SAMPAC_OnPlayerRequestClass( playerid, classid ); - #endif - #if defined _ALS_OnPlayerRequestClass - #undef OnPlayerRequestClass - #else - #define _ALS_OnPlayerRequestClass - #endif - #define OnPlayerRequestClass SAMPAC_OnPlayerRequestClass - - // Callback Hook (OnPlayerKeyStateChange) - - public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) - { - if( !IsPlayerNPC( playerid ) ) - { - vWeaponHackCheck ( playerid, newkeys ); - vAutoCbugKeyState ( playerid, newkeys, oldkeys ); - } - - #if defined SAMPAC_OnPlayerKeyStateChange - return SAMPAC_OnPlayerKeyStateChange(playerid, newkeys, oldkeys); - #else - return 1; - #endif - } - - #if defined SAMPAC_OnPlayerKeyStateChange - forward SAMPAC_OnPlayerKeyStateChange(playerid, newkeys, oldkeys); - #endif - #if defined _ALS_OnPlayerKeyStateChange - #undef OnPlayerKeyStateChange - #else - #define _ALS_OnPlayerKeyStateChange - #endif - #define OnPlayerKeyStateChange SAMPAC_OnPlayerKeyStateChange - - // Callback Hook (OnPlayerWeaponShot) - - public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ) - { - //printf("OnPlayerWeaponShot(%d, %d, %d, %d, %f, %f, %f)",playerid, weaponid, hittype, hitid, fX, fY, fZ); - new iState = GetPlayerState( playerid ); - if( iState == PLAYER_STATE_WASTED || !ac_IsPlayerSpawned( playerid ) ) - return 0; // Why bother, he's dead! + p_acUpdateTime[ playerid ] = GetTickCount( ); + //bCheckForSpectatingHacks ( playerid, iState, iTicks ); - vCheckForAutoCbug( playerid, weaponid ); - vCheckForSilentAimbot( playerid, hittype, hitid ); - - #if defined SAMPAC_OnPlayerWeaponShot - return SAMPAC_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, fX, fY, fZ); - #else - return 1; - #endif + if( iState != PLAYER_STATE_SPECTATING ) + { + bCheckForAirbrake ( playerid, p_acUpdateTime[ playerid ], iState ); + vCheckForHealthHacks ( playerid, p_acUpdateTime[ playerid ] ); + vCheckForFlyHacks ( playerid, p_acUpdateTime[ playerid ] ); + //vWeaponHackCheck ( playerid, p_acUpdateTime[ playerid ] ); + bCheckPlayerRemoteJacking ( playerid ); + } } + return 1; +} - #if defined SAMPAC_OnPlayerWeaponShot - forward SAMPAC_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ); - #endif - #if defined _ALS_OnPlayerWeaponShot - #undef OnPlayerWeaponShot - #else - #define _ALS_OnPlayerWeaponShot - #endif - #define OnPlayerWeaponShot SAMPAC_OnPlayerWeaponShot +// Hook (OnPlayerRequestClass) - #define AC_INCLUDED -#endif +hook OnPlayerRequestClass( playerid, classid ) +{ + // General + p_acSpawned{ playerid } = false; + p_SelectedClassID[ playerid ] = classid; + return 1; +} + +// Callback Hook (OnPlayerKeyStateChange) + +hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys) +{ + if( !IsPlayerNPC( playerid ) ) + { + vWeaponHackCheck ( playerid, newkeys ); + vAutoCbugKeyState ( playerid, newkeys, oldkeys ); + } + return 1; +} + +// Callback Hook (OnPlayerWeaponShot) + +hook OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ) +{ + //printf("OnPlayerWeaponShot(%d, %d, %d, %d, %f, %f, %f)",playerid, weaponid, hittype, hitid, fX, fY, fZ); + + new + iState = GetPlayerState( playerid ); + + if( iState == PLAYER_STATE_WASTED || !ac_IsPlayerSpawned( playerid ) ) + return 0; // Why bother, he's dead! + + vCheckForAutoCbug( playerid, weaponid ); + vCheckForSilentAimbot( playerid, hittype, hitid ); + return 1; +} diff --git a/pawno/include/anticheat/player.inc b/pawno/include/anticheat/player.inc index 4185580..e5d131b 100644 --- a/pawno/include/anticheat/player.inc +++ b/pawno/include/anticheat/player.inc @@ -48,14 +48,6 @@ new bool: p_acSpawned [ MAX_PLAYERS char ], p_acUpdateTime [ MAX_PLAYERS ], - // Health/Armour - Float: p_PlayerHealth [ MAX_PLAYERS ] [ E_PLAYER_HITPOINTS ], - Float: p_PlayerArmour [ MAX_PLAYERS ] [ E_PLAYER_HITPOINTS ], - Float: p_LastDamageIssued [ MAX_PLAYERS ], - p_LastTookDamage [ MAX_PLAYERS ], - p_LastDamageIssuer [ MAX_PLAYERS ] = { INVALID_PLAYER_ID, ... }, - p_LastWeaponIssuer [ MAX_PLAYERS ], - // Weapon Hacks bool: p_PlayerHasWeapon [ MAX_PLAYERS ] [ AC_MAX_WEAPONS char ], //p_PlayerWeaponUpdateTime [ MAX_PLAYERS ],