ValveSoftware / Source-1-Games

Source 1 based games such as TF2 and Counter-Strike: Source
633 stars 74 forks source link

[TF2] damage_for_force_calc in OnTakeDamage is broken #6056

Open Doclic opened 2 months ago

Doclic commented 2 months ago

The following vscript should, when executed, make all damage knock players back as if they took only one point of damage:

function
OnScriptHook_OnTakeDamage(params)
{
    params.damage_for_force_calc = 1.0;
}

__CollectGameEventCallbacks(this);

This however doesn't happen, damage force is still calculated normally, using params.damage.

Doclic commented 2 months ago

After doing a bit of digging, it seems that in CBaseEntity::TakeDamage, damage_for_force_calc is set before calling the hook, and it's retrieved after, but the retrieved value is not used anywhere.

Edit: I spent a bit more time on reversing, and the CTakeDamageInfo passed to CBaseEntity::OnTakeDamage has m_flDamageForForce properly set: image I wanted to try hooking to OnTakeDamage via a SourceMod plugin instead of a VScript, but SourceMod doesn't expose m_flDamageForForce.

While reverse-engineering, I've also found that damage_custom is effectively useless, reported in #4481.