SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 29/12/2016, 02:23 PM   #1
iamjems
Big Clucker
 
iamjems's Avatar
 
Join Date: Aug 2016
Location: Croatia
Posts: 123
Reputation: 7
Default Weapon hack check

Hello.

I am experiencing unexpected weapon hack warnings from a system that I scripted. It is using variables for all 13 weapon slots.

This is where the weapons are given:

PHP Code:
stock GivePlayerValidWeapon(playeridweaponidammo)
{
    switch(
weaponid)
    {
        case 
01:
        {
            
PlayerInfo[playerid][pGuns][0] = weaponid;
            
GivePlayerWeapon(playeridweaponidammo);
        }
        case 
.. 9:
        {
            
PlayerInfo[playerid][pGuns][1] = weaponid;
            
GivePlayerWeapon(playeridweaponidammo);
        }
        case 
222324:
        {
            
PlayerInfo[playerid][pGuns][2] = weaponid;
            
GivePlayerWeapon(playeridweaponidammo);
        }
        case 
252627:
        {
            
PlayerInfo[playerid][pGuns][3] = weaponid;
            
GivePlayerWeapon(playeridweaponidammo);
        }
        case 
282932:
        {
            
PlayerInfo[playerid][pGuns][4] = weaponid;
            
GivePlayerWeapon(playeridweaponidammo);
        }
        case 
3031:
        {
            
PlayerInfo[playerid][pGuns][5] = weaponid;
            
GivePlayerWeapon(playeridweaponidammo);
        }
        case 
3334:
        {
            
PlayerInfo[playerid][pGuns][6] = weaponid;
            
GivePlayerWeapon(playeridweaponidammo);
        }
        case 
35 .. 38:
        {
            
PlayerInfo[playerid][pGuns][7] = weaponid;
            
GivePlayerWeapon(playeridweaponidammo);
        }
        case 
16171839:
        {
            
PlayerInfo[playerid][pGuns][8] = weaponid;
            
GivePlayerWeapon(playeridweaponidammo);
        }
        case 
414243:
        {
            
PlayerInfo[playerid][pGuns][9] = weaponid;
            
GivePlayerWeapon(playeridweaponidammo);
        }
        case 
10 .. 15:
        {
            
PlayerInfo[playerid][pGuns][10] = weaponid;
            
GivePlayerWeapon(playeridweaponidammo);
        }
        case 
444546:
        {
            
PlayerInfo[playerid][pGuns][11] = weaponid;
            
GivePlayerWeapon(playeridweaponidammo);
        }
        case 
40:
        {
            
PlayerInfo[playerid][pGuns][12] = weaponid;
            
GivePlayerWeapon(playeridweaponidammo);
        }
    }
    return 
1;

This is located under my 1 second timer right now because of testing, I can use it under OnPlayerUpdate too with checking if the player's current weapon is different to his last one:

PHP Code:
new weapon[13], ammo[13];
for(new 
w=013w++)
{
    
GetPlayerWeaponData(iwweapon[w], ammo[w]);
    if(
weapon[w] != PlayerInfo[i][pGuns][w] && weapon[w] != 0)
    {
        
ExecuteHackerAction(iweapon[w]);
    }

^^ I have tried using if and else if here too for checking each slot and each weapon. Still the same problem. I found out using a loop is the same but a lot shorter and not complicated.

This isn't that important but here you go:

PHP Code:
stock ExecuteHackerAction(playeridweaponid)
{
    new 
string[144];
    
format(string,sizeof(string)," ** AdmWarning: {FFFF00}%s (ID %d) is possibly weapon hacking %s (ID %d)"GetName(playerid), playeridGetGunName(weaponid), weaponid);
    
ABroadcast(COLORREDstring1);
    
format(string,sizeof(string),"Possible weapon hack (%s)",GetGunName(weaponid));
    
AddAutomatedFlag(playeridstring);
    
format(string,sizeof(string),"%s has possibly weapon hacked %s (ID %s)"GetName(playerid), GetGunName(weaponid), weaponid);
    
Log("logs/hacks.txt"string);
    return 
1;

An example where the unexpected warning gets triggered is the tazer, givegun, takeguns and weapon pickups:

PHP Code:
if(PlayerState[playerid][pTazer] == 0)
        {
            
GetPlayerWeaponData(playerid2tazerlastweapons[0][playerid], tazerlastweapons[1][playerid]);
            if(
PlayerInfo[playerid][pGuns][2]) RemovePlayerWeapon(playeridPlayerInfo[playerid][pGuns][2]);
            
PlayerState[playerid][pTazer] = 1;
            
format(msg,sizeof(msg)," * %s unholsters their tazer."GetName(playerid));
            
ProxDetector(20.0playeridmsgCOLORRP);
            
GivePlayerValidWeapon(playerid2360000);
        }
        else
        {
            
RemovePlayerWeapon(playerid23);
            
GivePlayerValidWeapon(playeridtazerlastweapons[0][playerid], tazerlastweapons[1][playerid]);
            
PlayerInfo[playerid][pGuns][2] = tazerlastweapons[0][playerid];
            
PlayerState[playerid][pTazer] = 0;
            
format(msg,sizeof(msg)," * %s holsters their tazer."GetName(playerid));
            
ProxDetector(20.0playeridmsgCOLORRP);
        } 
PHP Code:
CMD:givegun(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] >= 3)
    {
        new 
targetidgunammo;
        new 
msg[144];
        if(
PlayerInfo[playerid][pAdminDuty] == && PlayerInfo[playerid][pAdmin] < 4) return SendMessage(playeridCOLORERROR,"AdmCmd: You must be on duty to do this. (/aduty)");
        if(
sscanf(params,"uii"targetidgunammo)) return SendMessage(playerid, -1,"USAGE: /givegun <playerid/partofname> <weaponid> <ammo>");
        if(
targetid == INVALID_PLAYER_ID) return SendMessage(playerid,COLORERROR,"AdmCmd: That player is not connected.");
        if(
InDuel[targetid]) return SendMessage(playerid,COLORERROR,"AdmCmd: That player is currently in a duel, try again later.");
        if(
PlayerState[targetid][pPrisoned] == || PlayerState[targetid][pAdmJail] == 1) return SendMessage(playerid,COLORERROR,"AdmCmd: That player is currently in jail, try again later.");
        if(
IsPlayerNPC(targetid)) return SendMessage(playerid,COLORERROR,"AdmCmd: You can't give weapons to an NPC.");
        if(
gun 46 || gun 1) return SendMessage(playerid, -1,"{00FFFF}AdmCmd:{FFFFFF} Valid weapon IDs: 1 - 46");
        if(
ammo 99999 || ammo 1) return SendMessage(playerid, -1,"{00FFFF}AdmCmd:{FFFFFF} Valid ammo: 1 - 99999");
        
GivePlayerValidWeapon(targetidgunammo);
        
format(msg,sizeof(msg)," *** AdmCmd:{FFFFFF} You have given a(n) %s (ID %d) with %d ammo to %s."GetGunName(gun), gunammoGetName(targetid));
        
SendMessage(playeridCOLORALmsg);
        
format(msg,sizeof(msg),"Admin %s has given you a(n) %s (ID %d) with %d ammo."GetName(playerid), GetGunName(gun), gunammo);
        
SendMessage(targetidCOLORWHITEmsg);
        
format(msg,sizeof(msg),"[GIVEGUN] %s has given %s a(n) %s (ID %d) with %d ammo"GetName(playerid), GetName(targetid), GetGunName(gun), gunammo);
        
Log("logs/admin.txt"msg);
        
ABroadcast(COLORLIGHTREDmsg4);
    } else return 
SendMessage(playeridCOLORERROR"You must be atleast a Head Admin to use this!");
    return 
1;

PHP Code:
CMD:takeguns(playerid,params[])
{
    new 
targetid;
    new 
msg[144];
    if(
PlayerInfo[playerid][pAdmin] >= 2)
    {
        if(
PlayerInfo[playerid][pAdminDuty] == && PlayerInfo[playerid][pAdmin] < 4) return SendMessage(playeridCOLORERROR,"AdmCmd: You must be on duty to do this. (/aduty)");
        if(
sscanf(params,"u",targetid)) return SendMessage(playerid,COLORWHITE,"{00FFFF}AdmCmd:{FFFFFF} /takeguns <playerid/partofname>");
        if(
targetid == INVALID_PLAYER_ID) return SendMessage(playerid,COLORERROR,"AdmCmd: That player is not connected.");
        if(
PlayerInfo[targetid][pAdminDuty] == && PlayerInfo[playerid][pAdmin] != 4) return SendMessage(playeridCOLORERROR,"AdmCmd: You can't do this to an on duty admin.");
        if(
InDuel[targetid]) return SendMessage(playerid,COLORERROR,"AdmCmd: That player is currently in a duel, try again later.");
        if(
PlayerInfo[targetid][pHunted] == 1) return SendMessage(playerid,COLORERROR,"AdmCmd: That player is currently hunted, try again later.");
        if(
IsPlayerNPC(targetid)) return SendMessage(playerid,COLORERROR,"AdmCmd: You can't take away guns from NPCs.");
        
ResetPlayerWeaponsEx(targetid);
        
format(msgsizeof(msg), " *** AdmCmd:{FFFFFF} You have taken away %s's weapons."GetName(targetid));
        
SendMessage(playeridCOLORALmsg);
        
format(msgsizeof(msg), "Admin %s has taken away your weapons."GetName(playerid));
        
SendMessage(targetidCOLORERRORmsg);
        
format(msg,sizeof(msg),"[TAKEGUNS] %s has taken away %s's weapons"GetName(playerid), GetName(targetid));
        
Log("logs/admin.txt"msg);
        
ABroadcast(COLORLIGHTREDmsg4);
    } else return 
SendMessage(playeridCOLORERROR"You must be atleast a Lead Admin to use this!");
    return 
1;

PHP Code:
for(new 0MAX_GUNDROPi++)
        {
            if(
pickupid == WeaponDrop[i][dPickup] && WeaponDrop[i][dWeapon] > 0)
            {
                for(new 
w=0;w<12;w++)
                {
                    
GetPlayerWeaponData(playeridwweaponammo);
                    if((
WeaponDrop[i][dWeapon] == WEAPON_DEAGLE && PlayerState[playerid][pTazer] == 1) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_SHOTGUN && weapon == WEAPON_SHOTGSPA) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_SHOTGUN && weapon == WEAPON_SAWEDOFF) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_SHOTGSPA && weapon == WEAPON_SHOTGUN) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_SHOTGSPA && weapon == WEAPON_SAWEDOFF) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_SAWEDOFF && weapon == WEAPON_SHOTGUN) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_SAWEDOFF && weapon == WEAPON_SHOTGSPA) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_AK47 && weapon == WEAPON_M4) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_M4 && weapon == WEAPON_AK47) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_UZI && weapon == WEAPON_MP5) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_UZI && weapon == WEAPON_TEC9) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_TEC9 && weapon == WEAPON_MP5) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_TEC9 && weapon == WEAPON_UZI) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_MP5 && weapon == WEAPON_UZI) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_MP5 && weapon == WEAPON_TEC9) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_SNIPER && weapon == WEAPON_RIFLE) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_RIFLE && weapon == WEAPON_SNIPER) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_GRENADE && weapon == WEAPON_TEARGAS) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_GRENADE && weapon == WEAPON_MOLTOV) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_MOLTOV && weapon == WEAPON_GRENADE) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_MOLTOV && weapon == WEAPON_TEARGAS) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_TEARGAS && weapon == WEAPON_MOLTOV) ||
                    (
WeaponDrop[i][dWeapon] == WEAPON_TEARGAS && weapon == WEAPON_GRENADE))
                    {
                        
SendMessage(playeridCOLORERROR"You already have a similar weapon to this one. Use /dropgun.");
                        return 
1;
                    }
                }

                
GivePlayerValidWeapon(playeridWeaponDrop[i][dWeapon], WeaponDrop[i][dAmmo]);
                
DestroyPickup(WeaponDrop[i][dPickup]);
                
WeaponDrop[i][dWeapon] = 0;
                
WeaponDrop[i][dSpawnedTime] = 0;
                
WeaponDrop[i][dAmmo] = 0;
                
PlayerPlaySound(playerid10520.00.00.0);
            }
        } 
This is the remove player weapon function:

PHP Code:
stock RemovePlayerWeapon(playeridweaponid)
{
    new 
plyWeapons[13][2];
    for(new 
013s++)
    {
        new 
wepammo;
        
GetPlayerWeaponData(playeridswepammo);

        if(
wep != weaponid)
        {
            
GetPlayerWeaponData(playeridsplyWeapons[s][0], plyWeapons[s][1]);
        }
        else
        {
            
PlayerInfo[playerid][pGuns][s] = 0;
        }
    }

    
ResetPlayerWeaponsEx(playerid);
     for(new 
013s++)
    {
        
GivePlayerValidWeapon(playeridplyWeapons[s][0], plyWeapons[s][1]);
    }
    return 
1;

And the resetplayerweaponsex:

PHP Code:
stock ResetPlayerWeaponsEx(playerid)
{
    
ResetPlayerWeapons(playerid);
    for(new 
013i++)
    {
        
PlayerInfo[playerid][pGuns][i] = 0;
    }
    return 
1;

Anyone have an idea why this is happening? Please help me down below. Thank you
iamjems is offline   Reply With Quote
Old 29/12/2016, 02:43 PM   #2
HydraHumza
Gangsta
 
HydraHumza's Avatar
 
Join Date: Oct 2014
Posts: 626
Reputation: 130
Default Re: Weapon hack check

it should be GivePlayerWeaponEx instead of GivePlayerWeapon and then try as u seems using Server sided weapon cheat.
__________________
Quote:
Originally Posted by Kalcor View Post
The fact is, I am right. And if you think I'm wrong, you are wrong.
HydraHumza is offline   Reply With Quote
Old 29/12/2016, 03:38 PM   #3
iamjems
Big Clucker
 
iamjems's Avatar
 
Join Date: Aug 2016
Location: Croatia
Posts: 123
Reputation: 7
Default Re: Weapon hack check

Quote:
Originally Posted by Humza View Post
it should be GivePlayerWeaponEx instead of GivePlayerWeapon and then try as u seems using Server sided weapon cheat.
stock GivePlayerValidWeapon(playerid, weaponid, ammo)

It's already there.
iamjems is offline   Reply With Quote
Old 29/12/2016, 11:01 PM   #4
denNorske
Gangsta
 
denNorske's Avatar
 
Join Date: Nov 2011
Location: Oslo, Norway
Posts: 789
Reputation: 95
Default Re: Weapon hack check

Are those examples the only places the warnings gets sent?
What if you posted the other pickups for instance, to compare the code?

I've gone through this script now at least 10 times, and I can't honestly see why it should fail. You give weapons through the new function "GivePlayerValidWeapon(playerid, weaponid, ammo)" - , and you also assured to set the correct weapon data in the arrays for it.

What happens on player death, spawn etc?
__________________
xSF source has been publicly released: Available on git (https://git.ducky.rocks/denNorske/xsf-official-gamemode)
Useful Racespawn generator: https://forum.sa-mp.com/showpost.php...postcount=3777
Get an overview over your map objects: Check it here!
denNorske is offline   Reply With Quote
Old 30/12/2016, 01:20 AM   #5
iamjems
Big Clucker
 
iamjems's Avatar
 
Join Date: Aug 2016
Location: Croatia
Posts: 123
Reputation: 7
Default Re: Weapon hack check

Quote:
Originally Posted by denNorske View Post
Are those examples the only places the warnings gets sent?
What if you posted the other pickups for instance, to compare the code?

I've gone through this script now at least 10 times, and I can't honestly see why it should fail. You give weapons through the new function "GivePlayerValidWeapon(playerid, weaponid, ammo)" - , and you also assured to set the correct weapon data in the arrays for it.

What happens on player death, spawn etc?
When a player dies or spawns, its fine. I am not sure if these all are the examples. It pops up randomly, not always.
iamjems is offline   Reply With Quote
Old 30/12/2016, 01:55 AM   #6
denNorske
Gangsta
 
denNorske's Avatar
 
Join Date: Nov 2011
Location: Oslo, Norway
Posts: 789
Reputation: 95
Default Re: Weapon hack check

Okay try to debug the script.

Add messages to print the contents of the arrays that doesn't match.

pawn Code:
if(weapon[w] != PlayerInfo[i][pGuns][w] && weapon[w] != 0)
    {
        ExecuteHackerAction(i, weapon[w]);
    }

Here for instance, find out what the contents of the arrays are here when it fails.
pawn Code:
printf("DEBUG WH Content: weapon[w] = %d\nContent: PlayerInfo[i][pGuns][w] = %d", weapon[w], PlayerInfo[i][pGuns][w]);
__________________
xSF source has been publicly released: Available on git (https://git.ducky.rocks/denNorske/xsf-official-gamemode)
Useful Racespawn generator: https://forum.sa-mp.com/showpost.php...postcount=3777
Get an overview over your map objects: Check it here!
denNorske is offline   Reply With Quote
Old 30/12/2016, 10:08 AM   #7
iamjems
Big Clucker
 
iamjems's Avatar
 
Join Date: Aug 2016
Location: Croatia
Posts: 123
Reputation: 7
Default Re: Weapon hack check

Quote:
Originally Posted by denNorske View Post
Okay try to debug the script.

Add messages to print the contents of the arrays that doesn't match.

pawn Code:
if(weapon[w] != PlayerInfo[i][pGuns][w] && weapon[w] != 0)
    {
        ExecuteHackerAction(i, weapon[w]);
    }

Here for instance, find out what the contents of the arrays are here when it fails.
pawn Code:
printf("DEBUG WH Content: weapon[w] = %d\nContent: PlayerInfo[i][pGuns][w] = %d", weapon[w], PlayerInfo[i][pGuns][w]);
Okay man, Ill try that out!
iamjems is offline   Reply With Quote
Old 30/12/2016, 10:53 AM   #8
iamjems
Big Clucker
 
iamjems's Avatar
 
Join Date: Aug 2016
Location: Croatia
Posts: 123
Reputation: 7
Default Re: Weapon hack check

I have a deagle.

I type in /tazer.

It removes the deagle, gives me a silenced pistol, a warning pops up that I may be hacking a deagle.

This is getting out of control.
iamjems is offline   Reply With Quote
Old 30/12/2016, 02:30 PM   #9
BlackBank
Gangsta
 
Join Date: Dec 2010
Location: The Netherlands
Posts: 522
Reputation: 437
Default Re: Weapon hack check

Did you debug GetPlayerWeaponData and there referenced values(weaponid and weaponammo)?
BlackBank is offline   Reply With Quote
Old 30/12/2016, 02:45 PM   #10
cessil
High-roller
 
cessil's Avatar
 
Join Date: Apr 2009
Posts: 1,346
Reputation: 296
Default Re: Weapon hack check

Quote:
Originally Posted by iamjems View Post
I have a deagle.

I type in /tazer.

It removes the deagle, gives me a silenced pistol, a warning pops up that I may be hacking a deagle.

This is getting out of control.
yes as expected, things that happen in online games are not instant, they take time.
when you set a variable it's instant, when you give someone a weapon data has to travel to their client and then the client sets the right weapon.

GetPlayerWeapon doesn't query the players client, it returns data previously sent by the client.
So when you give a player a deagle and then give them a silenced pistol the script says they should have a silenced pistol, but using GetPlayerWeaponData right under it will return a deagle since you're reading old data, you have to give the client time to update to the server, what I used to do was check every second but only warn on 5 and 10 seconds, then kick them at 15 seconds

for more reading
http://forum.sa-mp.com/showthread.php?t=220089
cessil is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
About Weapon Hack ProRakNet Scripting Help 8 02/06/2016 07:05 PM
[FilterScript] PMH's Anti Weapon Hack!!! + Ammo hack PMH Filterscripts 4 25/01/2015 11:12 AM
check user hack YazukiAkira Scripting Help 14 07/09/2014 07:34 PM
Weapon hack [HELP!!!] cuemur Scripting Help 5 29/09/2013 04:07 PM
[Help] Health hack check. moadi Scripting Help 3 02/10/2011 06:40 PM


All times are GMT. The time now is 04:15 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.