alliedmodders / amxmodx

AMX Mod X - Half-Life 1 Scripting and Administration
http://www.amxmodx.org/
496 stars 197 forks source link

Crash - Ham_Item_GetWeaponPtr #754

Open DarthMan opened 5 years ago

DarthMan commented 5 years ago

Hello. I have not tested in other Half-Life One engine based games, but on the internet computer game Team Fortress Classic the HAM forward Ham_Item_GetWeaponPtr crashes the server whenever being used on a valid entity edict. So if I do something like if(ExecuteHam(Ham_Item_GetWeaponPtr, iEnt) != FM_NULLENT) where iEnt is a valid entity edict that exists on the map I am getting a nice crash with no errors on Windows, but segmentation fault on Linux. The forward is supposed to return minus one if the given entity is not a weapon, the correct entity identifier otherwise.

Arkshine commented 4 years ago

Can you please provide a simple test plugin and how to reproduce the crash?

Also, please try again, and before, update to the latest AMXX version, whatever 1.9 or master. Do the same for the game as well. Just to make sure.

DarthMan commented 4 years ago

Sure, I'll make a test example. But my guess is that it crashes simply because it's checking if an entity that's actually not an item is a weapon. So more like if being called on classes such as infotarget it would crash, whereas with classes such as item it will return -1 and weapon_ the weapon entity id.

DarthMan commented 4 years ago

Here I'm attaching a test plug-in. Also, can you update the gamedata files for TFC and the other goldsrc games excluding CS 1.6? It seems that a new memebr was added to CbaseMonster so some pdata offsets are no longer valid.

In this example it is suposed to check if the player is a weapon, but, rather than crashing, still return -1 even if it's not part of CBasePlayerItem/Weapon. But it crashes instead. Test it on TFC. I am using latest AMXX v1.10 dev build.


#include <hamsandwich>

public plugin_init()
{
    register_clcmd("say /weapontest", "OnWeaponTest");
}

public OnWeaponTest(const iID)
{
    client_print(iID, print_chat, "Is the player a weapon ? Answer: %d", ExecuteHam(Ham_Item_GetWeaponPtr, iID));
}
DarthMan commented 4 years ago

Also, take a look here: https://github.com/ValveSoftware/halflife/issues/2458

m_flLastYawTime or whatever is the new member that was added.

Arkshine commented 4 years ago

Please keep content related only to the actual issue. I've already created one in #765.

DarthMan commented 4 years ago

Please keep content related only to the actual issue. I've already created one in #765.

Ok sure. just wanted to make you sure that u'll see the message. I am not sure if it was added yet in the stable Half-Life build, but TFC got an update last week which includes the fixes and the new member. By the way, it's just 1 offset that was added. So all you have to do is add +4 to everything derived from CBaseMonster and add the new offset.

DarthMan commented 4 years ago

Have you tested the attached plug-in? Does it crash the server? My intention was to use it on my EntMod when searching for entities to tell if an entity is a weapon, then get it's owner, if ti equals the player, skip it. That's because I sue a special technique for the ent to grab entities with solidity <= SOLID_TRIGGER. So that's what I was tyring to use the function for. I was hoping that it would return -1, but it crashed the server.

Arkshine commented 4 years ago

I can reproduce the crash under windows. Basically, the function from the game returns 0x0000001. The value is not null but is not a valid pointer. That's why, it passes the check and crash at some point. Not sure why though.

@WPMGPRoSToTeMa any idea?