Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[All Half-Life 1 games] Melee weapons play back swing events incorrectly in some cases #3230

Open
SamVanheer opened this issue Jan 23, 2022 · 0 comments

Comments

@SamVanheer
Copy link

Melee weapons in all Half-Life 1 games play back their swing events incorrectly in some cases.

Specifically, melee weapons work by swinging twice: the first time when the player presses the attack button, the second time if the first swing didn't hit so the weapon can still hit something 0.1 seconds later since the weapon is swinging for half a second, so something could be hit the second time. Logically this is a single swing and to players it will appear to be one.

The second swing is where the problem occurs:

halflife/dlls/crowbar.cpp

Lines 196 to 198 in c7240b9

PLAYBACK_EVENT_FULL( FEV_NOTHOST, m_pPlayer->edict(), m_usCrowbar,
0.0, (float *)&g_vecZero, (float *)&g_vecZero, 0, 0, 0,
0.0, 0, 0.0 );

This event playback call will be executed for both swings. The second time the engine's internal state will be invalid for this function call, which results in the event sometimes being sent to the player to whom the weapon belongs. The FEV_NOTHOST flag is supposed to prevent this from happening.

The problem is that the engine's global host_client variable is not always set to the player that owns the weapon when the playback call is given. The global is modified in several places and likely left pointing at the last player slot available which is always the local player in singleplayer, so this bug doesn't happen there. The logic that deals with the FEV_NOTHOST flag relies on the global to check which players to skip, so it gets sent anyway.

The result is that the event is executed by both the server and client version of the weapons code, which manifests itself as the swing animation and sounds starting from the beginning again.

In Steam Half-Life this bug has already been fixed by changing the code to this:

if (fFirst)
{
	PLAYBACK_EVENT_FULL( FEV_NOTHOST, m_pPlayer->edict(), m_usCrowbar, 
		0.0, (float *)&g_vecZero, (float *)&g_vecZero, 0, 0, 0,
		0.0, 0, 0.0 );
}

This is the correct behavior for this code.

This fix has not been applied to Opposing Force's Knife and Pipe Wrench weapons. Other GoldSource engine games either use different logic that doesn't involve events or don't swing twice so they don't appear to be affected.

This is not related to #3173 and #3041.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants