Weapon hack check
#1

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
Reply
#2

it should be GivePlayerWeaponEx instead of GivePlayerWeapon and then try as u seems using Server sided weapon cheat.
Reply
#3

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.
Reply
#4

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?
Reply
#5

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.
Reply
#6

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]);
Reply
#7

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!
Reply
#8

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.
Reply
#9

Did you debug GetPlayerWeaponData and there referenced values(weaponid and weaponammo)?
Reply
#10

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
https://sampforum.blast.hk/showthread.php?tid=220089
Reply
#11

Quote:
Originally Posted by cessil
Посмотреть сообщение
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
https://sampforum.blast.hk/showthread.php?tid=220089
I completely understand. I have also tried using GetPlayerWeapon instead of GetPlayerWeaponData to check every slot and every weapon with if and else if. It also gave me unexpected warnings. Smh, I'll sort it out some day. Thank you for the link and nice thread by the way, I'll be sure to get my head deep into it!
Reply
#12

FIXED

To anyone having trouble with this:

Under OnPlayerUpdate:

PHP код:
new currweapon GetPlayerWeapon(playerid);
new 
lastweapon GetPVarInt(playerid"LastWeap");
if(
currweapon != lastweapon)
{
    
OnPlayerWeaponChange(playeridlastweaponcurrweapon);
    
SetPVarInt(playerid"LastWeap"currweapon);

The OnPlayerWeaponChange function:

PHP код:
stock OnPlayerWeaponChange(playeridlastweapnewweap)
{
    if(
PlayerInfo[playerid][pGuns][11] != 46 && newweap == 46
    
// Assigning the parachute to pGuns (because i.e., if you jump out of a hydra, you get a parachute)
    
{
        
PlayerInfo[playerid][pGuns][11] = 46;
        return 
1;
    }
    
    if(
newweap != 0)
    {
        if(
PlayerInfo[playerid][pGuns][GetGunSlot(newweap)] != newweap)
        {
            
// ... your ban code
            
return 1;
        }
    }
    return 
1;

GetGunSlot for getting the weapon slot (obviously):

PHP код:
stock GetGunSlot(weaponid)
{
    switch(
weaponid)
    {
        case 
01: return 0;
        case 
.. 9: return 1;
        case 
10 .. 15: return 10;
        case 
16 .. 1839: return 8;
        case 
22 .. 24: return 2;
        case 
25 .. 27: return 3;
        case 
282932: return 4;
        case 
3031: return 5;
        case 
3334: return 6;
        case 
35 .. 38: return 7;
        case 
40: return 12;
        case 
41 .. 43: return 9;
        case 
44 .. 46: return 11;
    }
    return -
1;

No use of GetPlayerWeaponData leads to no bugs what so ever.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)