Raised This Month: $ Target: $400
 0% 

CHalfLifeMultiplay::DeathNotice(PlayerKilled) crash


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OnePL
BANNED
Join Date: May 2012
Location: GB
Old 02-19-2016 , 06:11   CHalfLifeMultiplay::DeathNotice(PlayerKilled) crash
Reply With Quote #1

debug.log
Spoiler


Metalist:
Code:
 [ 1] AMX Mod X        RUN   -    amxmodx_mm_i386.  v1.8.3-d  ini  Start ANY  
 [ 2] MySQL            RUN   -    mysql_amxx_i386.  v1.8.3-d  pl1  ANY   ANY  
 [ 3] FakeMeta         RUN   -    fakemeta_amxx_i3  v1.8.3-d  pl1  ANY   ANY  
 [ 4] Fun              RUN   -    fun_amxx_i386.so  v1.8.3-d  pl1  ANY   ANY  
 [ 5] Ham Sandwich     RUN   -    hamsandwich_amxx  v1.8.3-d  pl1  ANY   ANY  
 [ 6] Engine           RUN   -    engine_amxx_i386  v1.8.3-d  pl1  ANY   ANY
AMXX v1.8.3-dev-git5021
Metamod v1.21.1-am
HLDS v6153

Crash occurs after executed this stock:
PHP Code:
stock UserKill(iVictimiEnt 0iKiller 0iWeapon = -1iBody = -1iShouldgib 0iBitsDamage DMG_GENERICbool:bSuicide truebool:bAddDeath false) {
    if(!
is_user_alive(iVictim) || !(<= (iKiller iKiller iVictim) <= MaxClients && is_user_connected(iKiller iKiller iVictim))) return 0;

    static 
iMsgDeathMsg;
    if(!
iMsgDeathMsgiMsgDeathMsg get_user_msgid("DeathMsg");
    static 
iDeaths;
    if(!
bAddDeathiDeaths get_pdata_int(iVictim444);
    
set_pdata_int(iVictim75iBody == -bSuicide HIT_GENERIC get_pdata_int(iVictim75) : iBody);
    
set_pdata_int(iVictim76iBitsDamage);
    
set_pdata_int(iVictim1071);
    
set_pev(iVictimpev_dmg_inflictoriEnt iEnt iKiller iKiller iVictim);
    
set_msg_block(iMsgDeathMsgBLOCK_ONCE);
    
ExecuteHamB(Ham_KillediVictimiKiller iKiller iVictimiShouldgib);
    if(!
bAddDeathset_pdata_int(iVictim444iDeaths);

    if(
is_user_alive(iVictim)) return 0;

    static 
iBitEffect;
    
iBitEffect pev(iVictimpev_effects);
    if(
iBitEffect EF_NODRAWset_pev(iVictimpev_effectsiBitEffect EF_NODRAW);

    static 
szName[24], iLen;
    
iLen 0;

    if(!
bSuicide) {
        
iWeapon iWeapon == -get_user_weapon(iKiller) : iWeapon;

        if(
get_weaponname(iWeaponszName23)) {
            if(
CSW_ALL_GUNS 1<<iWeaponiLen 7;
            else 
copy(szName8"grenade");
        }
        else if(
iWeapon == 2copy(szName10"tracktrain");
    }
    else 
copy(szName6"world");

    
emessage_begin(MSG_ALLiMsgDeathMsg);
    
ewrite_byte(iKiller iKiller iVictim);
    
ewrite_byte(iVictim);
    
ewrite_byte(iBody == HIT_HEAD HIT_HEAD HIT_GENERIC);
    
ewrite_string(szName[iLen]);
    
emessage_end();
    return 
1;

PHP Code:
UserKill(id//suicide 

Last edited by OnePL; 02-19-2016 at 06:41.
OnePL is offline
Send a message via ICQ to OnePL Send a message via AIM to OnePL Send a message via Yahoo to OnePL Send a message via Skype™ to OnePL
JusTGo
Veteran Member
Join Date: Mar 2013
Old 02-19-2016 , 08:02   Re: CHalfLifeMultiplay::DeathNotice(PlayerKilled) crash
Reply With Quote #2

not sure but shouldn't this :
PHP Code:
if(!is_user_alive(iVictim) || !(<= (iKiller iKiller iVictim) <= MaxClients && is_user_connected(iKiller iKiller iVictim))) return 0
>>>>

PHP Code:
if(!is_user_alive(iVictim) || !(<= (iKiller iKiller iVictim) <= MaxClients && !is_user_connected(iKiller iKiller iVictim))) return 0
you forgot "!" before is_user_connected.
__________________
JusTGo is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-19-2016 , 08:36   Re: CHalfLifeMultiplay::DeathNotice(PlayerKilled) crash
Reply With Quote #3

Looks like you hit a game bug, which actually is not really a bug per se but more a wrong usage triggered by your code.

The issue can be explained easily.

The flow of execution in your context is something like that:

CBasePlayer::TakeDamage -> CBasePlayer::Killed -> CHalfLifeMultiplay::PlayerKilled -> CHalfLifeMultiplya:DeathNotice -> crash.

You are not supposed to call Killed() without defining an inflictor.
Usually, inflictor is defined from TakeDamage() and will be saved in g_pevLastInflictor global variable.

Next Killed calls PlayerKilled this way: g_pGameRules->PlayerKilled(this, pevAttacker, g_pevLastInflictor);
Then DeathNotice is called with a null inflictor.
Code:
void CHalfLifeMultiplay::DeathNotice(CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pevInflictor)
{
	const char *killer_weapon_name = "world";
	// ...
	if (pKiller->flags & FL_CLIENT)
	{
		killer_index = ENTINDEX(ENT(pKiller));

		if (pevInflictor)
		{
			// ..
		}
	}
	else
>>		killer_weapon_name = STRING(pevInflictor->classname);
Looking at your debug, you're passing 0 for killer, which means the "world".
You get a crash on the last line of the above code, because the killer is not a player, and it tries to get inflictor classname from a null pointer. You could argue there is missing check, but internally you are supposed to set g_pevLastInflictor.

You should probably call TakeDamage instead with some damage > player's current health.
__________________

Last edited by Arkshine; 02-19-2016 at 08:41.
Arkshine is offline
xxxperts
Senior Member
Join Date: Oct 2013
Location: India
Old 02-20-2016 , 04:16   Re: CHalfLifeMultiplay::DeathNotice(PlayerKilled) crash
Reply With Quote #4

Arkshine Nicely Explained _/\_
__________________
All my work is here
xxxperts is offline
OnePL
BANNED
Join Date: May 2012
Location: GB
Old 02-20-2016 , 16:39   Re: CHalfLifeMultiplay::DeathNotice(PlayerKilled) crash
Reply With Quote #5

Arkshine, thanks for your answer, but I use this stock few months and I had no such problems until now.
OnePL is offline
Send a message via ICQ to OnePL Send a message via AIM to OnePL Send a message via Yahoo to OnePL Send a message via Skype™ to OnePL
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-20-2016 , 17:25   Re: CHalfLifeMultiplay::DeathNotice(PlayerKilled) crash
Reply With Quote #6

Game code has not changed, nor it's related to AMXX anyway. Maybe you got no suicide until today or you changed something you don't remember.

g_pevLastInflictor is set only in TakeDamage like:

g_pevLastInflictor = pInflictor;
Killed();
g_pevLastInflictor = NULL;

Pretty hard to imagine your code working as it is with 0 as killer.
__________________
Arkshine is offline
OnePL
BANNED
Join Date: May 2012
Location: GB
Old 02-20-2016 , 22:00   Re: CHalfLifeMultiplay::DeathNotice(PlayerKilled) crash
Reply With Quote #7

All parameters of this stock were checked, and worked(works) perfectly
I set inflictor in this way:
PHP Code:
set_pev(iVictimpev_dmg_inflictoriEnt iEnt iKiller iKiller iVictim); 
If iEnt is set, inflictor = iEnt;
If iEnt is not set, inflictor = TBC below:
if iKiller is set, inflictor = iKiller
if iKiller is not set, inflictor = iVictim

So when I use
PHP Code:
UserKill(id
it means that, killer == inflictor (default by game, except he grenade).
iKiller attribute is equal to 0, so inflictor is iVictim (id).

Below stock also causes crashes
PHP Code:
UserKill(iVictimiKiller 0bool:bAddDeath false) {
    static 
iDeaths;
    if(!
bAddDeathiDeaths get_pdata_int(iVictim444);
    
ExecuteHamB(Ham_KillediVictimiKiller iKiller iVictim0);
    if(!
bAddDeathset_pdata_int(iVictim444iDeaths);

when I use (suicide):
PHP Code:
UserKill(id); 

Last edited by OnePL; 02-20-2016 at 22:13.
OnePL is offline
Send a message via ICQ to OnePL Send a message via AIM to OnePL Send a message via Yahoo to OnePL Send a message via Skype™ to OnePL
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-21-2016 , 05:20   Re: CHalfLifeMultiplay::DeathNotice(PlayerKilled) crash
Reply With Quote #8

Well for sure there is something fishy.

To get a valid killer's edict as "world", ExecuteHamB has to receive "0" as value.
But with your check, it should not be possible. I've actually tested your small stock under window and Linux, did not get any crash.

Looking at your crash, you're hooking Ham_Killed and crash happens from there. Are you sure you don't set killer to 0 there?
Since you can reproduce, what happens if you're using ExecuteHam without B?
__________________

Last edited by Arkshine; 02-21-2016 at 07:10.
Arkshine is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 02-21-2016 , 17:34   Re: CHalfLifeMultiplay::DeathNotice(PlayerKilled) crash
Reply With Quote #9

Quote:
Originally Posted by Arkshine View Post
Well for sure there is something fishy.

To get a valid killer's edict as "world", ExecuteHamB has to receive "0" as value.
But with your check, it should not be possible. I've actually tested your small stock under window and Linux, did not get any crash.

Looking at your crash, you're hooking Ham_Killed and crash happens from there. Are you sure you don't set killer to 0 there?
Since you can reproduce, what happens if you're using ExecuteHam without B?
I can confirm that.

PHP Code:
#0  0xf3190dd9 in CHalfLifeMultiplay::DeathNotice (this=0xa70d408, pVictim=0xa8d61e0, pKiller=0xf35bdbb8, pevInflictor=0x0) at ../cstrike/dlls/multiplay_gamerules.cpp:3808
#0  0xf3190dd9 in CHalfLifeMultiplay::DeathNotice (this=0xa70d408, pVictim=0xa8d61e0, pKiller=0xf35bdbb8, pevInflictor=0x0) at ../cstrike/dlls/multiplay_gamerules.cpp:3808
#1  0xf319704c in CHalfLifeMultiplay::PlayerKilled (this=0xa70d408, pVictim=0xa8d61e0, pKiller=0xf35bdbb8, pInflictor=0x0) at ../cstrike/dlls/multiplay_gamerules.cpp:3629
#2  0xf31b9b6b in CBasePlayer::Killed (this=0xa8d61e0, pevAttacker=0xf35bdbb8, iGib=0) at ../cstrike/dlls/player.cpp:2402
#3  0xf29638d3 in Hook_Void_Entvar_Int(Hook*, void*, entvars_s*, int) () from cstrike/addons/amxmodx/modules/hamsandwich_amxx_i386.so
#4  0xff856a50 in ?? () 
Hook_Void_Entvar_Int it's from Hamsandwich. The trick here is your ham function execution is getting hooked by a Hamsandwich forward, dealing with the crash
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross

Last edited by meTaLiCroSS; 02-21-2016 at 17:35.
meTaLiCroSS is offline
OnePL
BANNED
Join Date: May 2012
Location: GB
Old 02-21-2016 , 17:58   Re: CHalfLifeMultiplay::DeathNotice(PlayerKilled) crash
Reply With Quote #10

Problem solved, was guilty ReHLDS v1.28 (670) from Wed Feb 10 18:41:54 CET 2016
I downgraded rehlds to v1.28 (669) from Wed Feb 10 06:05:51 CET 2016 and everything works correctly

Last edited by OnePL; 02-21-2016 at 17:58.
OnePL is offline
Send a message via ICQ to OnePL Send a message via AIM to OnePL Send a message via Yahoo to OnePL Send a message via Skype™ to OnePL
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 03:54.


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