Raised This Month: $51 Target: $400
 12% 

Ham_Item_GetItemInfo broken (Linux)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PartialCloning
Senior Member
Join Date: Dec 2015
Old 07-24-2017 , 15:24   Ham_Item_GetItemInfo broken (Linux)
Reply With Quote #1

Ham_Item_GetItemInfo "breaks" any weapon it's hooked for on linux.

Steps to reproduce:
1. Start up the server.
2. Change the map.
3. Try to use any weapon.

PHP Code:
//    Copyright © 2016 Vaqtincha
/*************************************************
 *    Credits:
 *
 *    - ConnorMcLeod (plugin "Bp Ammo Features" - Ham_GiveAmmo code)
 *
 *************************************************/

/**■■■■■■■■■■■■■■■■■■■■■■■■■■■■ CONFIG START ■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/

enum
{
    
MAX_AMMO_338MAGNUM        30,     // (CSW_AWP)
    
MAX_AMMO_762NATO        90,     // (CSW_SCOUT, CSW_G3SG1, CSW_AK47)
    
MAX_AMMO_556NATOBOX        200,    // (CSW_M249)
    
MAX_AMMO_556NATO        90,     // (CSW_AUG, CSW_SG550, CSW_GALIL, CSW_FAMAS, CSW_M4A1, CSW_SG552)
    
MAX_AMMO_BUCKSHOT        32,    // (CSW_XM1014, CSW_M3)
    
MAX_AMMO_45ACP            100,    // (CSW_MAC10, CSW_UMP45, CSW_USP)
    
MAX_AMMO_57MM            100,    // (CSW_P90, CSW_FIVESEVEN)
    
MAX_AMMO_50AE            35,     // (CSW_DEAGLE)
    
MAX_AMMO_357SIG            52,     // (CSW_P228)
    
MAX_AMMO_9MM            120,    // (CSW_MP5NAVY, CSW_TMP, CSW_ELITE, CSW_GLOCK18)

    
MAX_AMMO_FLASHBANG        3,      // (CSW_FLASHBANG)
    
MAX_AMMO_HEGRENADE        2,      // (CSW_HEGRENADE)
    
MAX_AMMO_SMOKEGRENADE    1       // (CSW_SMOKEGRENADE)
}

enum
{
    
AMOUNT_AMMO_338MAGNUM    10,     // (CSW_AWP)
    
AMOUNT_AMMO_762NATO        30,     // (CSW_SCOUT, CSW_G3SG1, CSW_AK47)
    
AMOUNT_AMMO_556NATOBOX    30,    // (CSW_M249) 
    
AMOUNT_AMMO_556NATO        10,    // (CSW_AUG, CSW_SG550, CSW_GALIL, CSW_FAMAS, CSW_M4A1, CSW_SG552)
    
AMOUNT_AMMO_BUCKSHOT    8,     // (CSW_XM1014, CSW_M3)
    
AMOUNT_AMMO_45ACP        12,    // (CSW_MAC10, CSW_UMP45, CSW_USP)
    
AMOUNT_AMMO_57MM        50,    // (CSW_P90, CSW_FIVESEVEN)
    
AMOUNT_AMMO_50AE        7,     // (CSW_DEAGLE)
    
AMOUNT_AMMO_357SIG        13,     // (CSW_P228)
    
AMOUNT_AMMO_9MM            30,    // (CSW_MP5NAVY, CSW_TMP, CSW_ELITE, CSW_GLOCK18)

    
AMOUNT_AMMO_FLASHBANG    1,      // (CSW_FLASHBANG)
    
AMOUNT_AMMO_HEGRENADE    1,      // (CSW_HEGRENADE)
    
AMOUNT_AMMO_SMOKEGRENADE 1    // (CSW_SMOKEGRENADE)
}

/**■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ CONFIG END ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/

enum _:AmmoDatas AmountMax }

enum _:AmmoIds
{
    
ammo_none
    
ammo_338magnum 1
    
ammo_762nato
    
ammo_556natobox
    
ammo_556nato
    
ammo_buckshot,
    
ammo_45acp
    
ammo_57mm
    
ammo_50ae
    
ammo_357sig
    
ammo_9mm
    
ammo_flashbang
    
ammo_hegrenade,
    
ammo_smokegrenade
    
//, ammo_c4
}

new const 
g_szAmmoTypes[AmmoIds][] = {
    
""
    
"338Magnum"
    
"762Nato"
    
"556NatoBox"
    
"556Nato"
    
"buckshot"
    
"45acp"
    
"57mm"
    
"50AE"
    
"357SIG",
    
"9mm",
    
"Flashbang"
    
"HEGrenade",
    
"SmokeGrenade"
    
//, "C4"
}

new const 
g_eAmmoDatas[AmmoIds][AmmoDatas] = {
    {-
1,  -1},
    {
AMOUNT_AMMO_338MAGNUMMAX_AMMO_338MAGNUM},
    {
AMOUNT_AMMO_762NATOMAX_AMMO_762NATO},
    {
AMOUNT_AMMO_556NATOBOXMAX_AMMO_556NATOBOX},
    {
AMOUNT_AMMO_556NATOMAX_AMMO_556NATO},
    {
AMOUNT_AMMO_BUCKSHOTMAX_AMMO_BUCKSHOT},
    {
AMOUNT_AMMO_45ACPMAX_AMMO_45ACP},
    {
AMOUNT_AMMO_57MMMAX_AMMO_57MM},
    {
AMOUNT_AMMO_50AEMAX_AMMO_50AE},
    {
AMOUNT_AMMO_357SIGMAX_AMMO_357SIG},
    {
AMOUNT_AMMO_9MMMAX_AMMO_9MM},
    {
AMOUNT_AMMO_FLASHBANGMAX_AMMO_FLASHBANG}, 
    {
AMOUNT_AMMO_HEGRENADEMAX_AMMO_HEGRENADE}, 
    {
AMOUNT_AMMO_SMOKEGRENADEMAX_AMMO_SMOKEGRENADE}
}


#include <amxmodx>
#include <hamsandwich>

const EXP_WPN_BS = ((1<<CSW_KNIFE)|(1<<CSW_C4))

new 
HamHook:g_hGetItemInfo[CSW_P90+1]
new 
Trie:g_tAmmoIndex


public plugin_end()
{
    
TrieDestroy(g_tAmmoIndex)
}

public 
plugin_precache() 
{
    new 
szWeaponName[20], i
    g_tAmmoIndex 
TrieCreate()

    for(
1sizeof(g_szAmmoTypes); i++)
    {
        
TrieSetCell(g_tAmmoIndexg_szAmmoTypes[i], i)
    }

    for(
CSW_P228<= CSW_P90i++)
    {
        if(!(
EXP_WPN_BS & (1<<i)) && get_weaponname(iszWeaponNamecharsmax(szWeaponName))) 
        {
            
g_hGetItemInfo[i] = RegisterHam(Ham_Item_GetItemInfoszWeaponName"CBasePlayerItem_GetItemInfo", .Post true)
        }
    }
}

public 
plugin_init()
{
    
register_plugin("BpAmmo Control""0.0.1""Vaqtincha")

    
RegisterHam(Ham_GiveAmmo"player""CBasePlayer_GiveAmmo", .Post false)
    
DisableForwards()
}

public 
CBasePlayerItem_GetItemInfo(pItemiItemInfo
{
    new 
szAmmoType[13], iAmmoIndex
    GetHamItemInfo
(iItemInfoHam_ItemInfo_pszAmmo1szAmmoTypecharsmax(szAmmoType))

    if(!
TrieGetCell(g_tAmmoIndexszAmmoTypeiAmmoIndex))
    {
        return 
HAM_IGNORED
    
}

    
SetHamItemInfo(iItemInfoHam_ItemInfo_iMaxAmmo1g_eAmmoDatas[iAmmoIndex][Max])
    
    return 
HAM_IGNORED
}

public 
CBasePlayer_GiveAmmo(const pPlayeriAmountszAmmoType[], iMax)
{
    new 
iAmmoIndexiRet HAM_IGNORED

    
if(!TrieGetCell(g_tAmmoIndexszAmmoTypeiAmmoIndex))
    {
        return 
HAM_IGNORED
    
}

    new 
iAmountCust g_eAmmoDatas[iAmmoIndex][Amount]
    if(
iAmount && iAmountCust != iAmount)
    {
        
SetHamParamInteger(2iAmountCust)
        
iRet HAM_HANDLED
    
}

    new 
iCustMax g_eAmmoDatas[iAmmoIndex][Max]
    if(
iMax != iCustMax)
    {
        
SetHamParamInteger(4iCustMax)
        
iRet HAM_HANDLED
    
}

    return 
iRet
}

DisableForwards()
{
    new 
szWeaponName[20], i
    
for(CSW_P228<= CSW_P90i++)
    {
        if(!(
EXP_WPN_BS & (1<<i)) && get_weaponname(iszWeaponNamecharsmax(szWeaponName))) 
        {
            if(
g_hGetItemInfo[i])
                
DisableHamForward(g_hGetItemInfo[i])
        }
    }

PartialCloning is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 07-24-2017 , 15:32   Re: Ham_Item_GetItemInfo broken (Linux)
Reply With Quote #2

Hooking Ham_Item_GetItemInfo without doing anything is enough to reproduce this. It breaks the weapon list, ammo, everything.

Code:
#include <amxmodx> #include <fun> #include <hamsandwich> public plugin_precache() {     new szWeaponName[20];     for(new i = CSW_P228; i <= CSW_P90; i++)     {         if(get_weaponname(i, szWeaponName, charsmax(szWeaponName)))         {             RegisterHam(Ham_Item_GetItemInfo, szWeaponName, "CBasePlayerItem_GetItemInfo", .Post = true)         }     } } public CBasePlayerItem_GetItemInfo(pItem, iItemInfo) {     return HAM_IGNORED } public plugin_init() {     RegisterHam(Ham_Spawn, "player", "OnSpawnPost",  .Post = true); } public OnSpawnPost(id) {     if(is_user_alive(id))     {         give_item(id, "weapon_ak47")         give_item(id, "weapon_m4a1")         give_item(id, "weapon_usp")     } }
PartialCloning is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-25-2017 , 09:01   Re: Ham_Item_GetItemInfo broken (Linux)
Reply With Quote #3

I don't have linux server right now.

What does it mean "broken"?
What engine (reHLDS) version?
What amxx version?

Did you try the above test plugin without any third-party plugins?
Are you sure you're using the proper hamdata.ini file?

The handler in Ham looks fine and under windows there is no issue.
__________________

Last edited by Arkshine; 07-25-2017 at 09:19.
Arkshine is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 07-25-2017 , 09:23   Re: Ham_Item_GetItemInfo broken (Linux)
Reply With Quote #4

Broken means your weaponlist shows no weapons (but you can press lastinv to switch weapons), you don't see ammo, you can't shoot.

Hooking the "WeaponList" message shows that it's not called for any weapon that "RegisterHam(Ham_Item_GetItemInfo" is hooked for. Essentially, if you hook "RegisterHam(Ham_Item_GetItemInfo" for a weapon, the client thinks it doesn't exists because it never gets the WeaponList message as the server never sets it here: https://github.com/s1lentq/ReGameDLL...layer.cpp#L261

Latest default engine, latest AMXmodX dev build. Tested without other third party plugins. Using hamdata from a fresh install of the latest AMXmodX dev build.
PartialCloning is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-26-2017 , 03:27   Re: Ham_Item_GetItemInfo broken (Linux)
Reply With Quote #5

Actually, there is something wrong with your code. "get_weaponname" can't work in plugin_precache() at this point because such data is based on "WeaponList" message fired when the server is activated (meaning it works starting from plugin_init()).
"RegisterHam" is probably never called and that you would still have an issue in game means the issue is somewhere else.
__________________

Last edited by Arkshine; 07-26-2017 at 04:02.
Arkshine is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-26-2017 , 04:25   Re: Ham_Item_GetItemInfo broken (Linux)
Reply With Quote #6

PHP Code:
#include <amxmodx>

public plugin_precache()
{
    new 
WeaponName[32]
    
get_weaponname(CSW_AK47WeaponNamecharsmax(WeaponName))
    
server_print("Result = %s"WeaponName)

On windows it works, weird.
Code:
Result = weapon_ak47
__________________
HamletEagle is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-26-2017 , 06:38   Re: Ham_Item_GetItemInfo broken (Linux)
Reply With Quote #7

On _first_ server start, it won't work but once data are saved, it will work afterward.
__________________
Arkshine is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 07-26-2017 , 06:38   Re: Ham_Item_GetItemInfo broken (Linux)
Reply With Quote #8

@HamletEagle, nope, it doesn't work on first map.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
PartialCloning
Senior Member
Join Date: Dec 2015
Old 07-26-2017 , 11:22   Re: Ham_Item_GetItemInfo broken (Linux)
Reply With Quote #9

Quote:
Originally Posted by Arkshine View Post
Actually, there is something wrong with your code. "get_weaponname" can't work in plugin_precache() at this point because such data is based on "WeaponList" message fired when the server is activated (meaning it works starting from plugin_init()).
"RegisterHam" is probably never called and that you would still have an issue in game means the issue is somewhere else.
Actually I said in my first post that to reproduce it, you have to "2. Change the map.".

I'm 100% sure the issue is with Ham_Item_GetItemInfo. Using this code, no other third party plugins, latest dev, the issue is 100% reproducible. You don't have to change the map now as we're not using get_weaponname.

Code:
#include <amxmodx> #include <fun> #include <hamsandwich> public plugin_precache() {     RegisterHam(Ham_Item_GetItemInfo, "weapon_p228", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_scout", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_hegrenade", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_xm1014", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_c4", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_mac10", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_aug", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_smokegrenade", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_elite", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_fiveseven", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_ump45", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_sg550", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_galil", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_famas", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_usp", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_glock18", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_awp", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_mp5navy", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_m249", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_m3", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_m4a1", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_tmp", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_g3sg1", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_flashbang", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_deagle", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_sg552", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_ak47", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_knife", "CBasePlayerItem_GetItemInfo", .Post = true);     RegisterHam(Ham_Item_GetItemInfo, "weapon_p90", "CBasePlayerItem_GetItemInfo", .Post = true); } public CBasePlayerItem_GetItemInfo(pItem, iItemInfo) {     return HAM_IGNORED; } public plugin_init() {     RegisterHam(Ham_Spawn, "player", "OnSpawnPost",  .Post = true); } public OnSpawnPost(id) {     if(is_user_alive(id))     {         give_item(id, "weapon_ak47");         give_item(id, "weapon_m4a1");         give_item(id, "weapon_usp");     } }

@PRoSToTeM@/@HamletEagle/@AnybodyWithaLinuxServer can you run the plugin above and confirm the bug is reproducible so no time is wasted in assuming the issue is from something else?


Edit: @PRoSToTeM@, can you review your Hamsandwich: fix HAM_OVERRIDE in post hooks (bug 6443)? It changes stuff that seems to be used in "Hook_Void_ItemInfo".

Last edited by PartialCloning; 07-26-2017 at 11:34.
PartialCloning is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-26-2017 , 11:47   Re: Ham_Item_GetItemInfo broken (Linux)
Reply With Quote #10

Yes, some weird things are happening for me as well. It doesn't happen for windows.
__________________
Arkshine is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 02:14.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode