Skip to content

Input: Refactor +use handling to fix continuous use#1821

Merged
saibotk merged 1 commit intomasterfrom
refactor-use-handling
Feb 8, 2026
Merged

Input: Refactor +use handling to fix continuous use#1821
saibotk merged 1 commit intomasterfrom
refactor-use-handling

Conversation

@saibotk
Copy link
Member

@saibotk saibotk commented Jun 19, 2025

We refactored the "use key handling" to correctly work with entities that use the continuous use functionality, like the health station.

Why?

Previous efforts to consolidate "use key handling" led to a regression where continuous use did not work as intended anymore when directly looking at such an entity.

Though, it still worked when using the use key in the proximity of the entity without directly looking at it or running into it with the use key held down, because the server then handled the continuous use by itself.

This is behavior that the client cannot "block", so we needed to refactor this code to use the server-side continuous use handling as its only source of truth again.

The root cause for this issue was that the client suppressed further use handling after sending the net message to the server, which caused the server-side KeyPressed check to return false in the timer.
Simply changing this would not be sufficient, as we need still to suppress this handling for the other use-cases, like weapon pickup or remote use.

Changes

We mainly refactored the server-side "use key handling" to fix this issue and simplify the code. Also, the continous use execution frequency is now every tick again, instead of every 0.1 seconds.

The actual continuous execution is now handled by solely by the server again.

The TTT2PlayerUseEntity net message code was refactored to only handle its special cases like spectator use, remote use and weapon pickup. We send this message from within the bind handler on the client if applicable.
This code is still necessary, as these are cases where the normal use handling is not triggered by the server due to the items being out of reach or may not be correctly prioritized e.g. the wrong weapon being picked up instead of the intended looked at entity.

The corpse search and old UseOverride handling was moved back to the original TTT way of handling it, by utilizing the KeyRelease hook.
We did not modify the code here and merely copied over the original code again.

Removed ENT.CanUseKey from placeable entities as it is not needed anymore with the new handling.

Removed now obsolete IsSpecialUsableEntity and IsUsableEntity functions.

Refactored ClientUse function to be client only and always block further use handling.
This function is generally useful for client-side only use key handling, e.g., for UI interactions.
E.g. the C4 uses this to open the C4 menu when the use key is pressed while looking at it.

Fixes #1816

@saibotk saibotk self-assigned this Jun 19, 2025
@saibotk saibotk marked this pull request as draft June 19, 2025 23:44
@wgetJane
Copy link
Contributor

skimmed through the changes, are you sure these won't reintroduce any of the bugs fixed by #1792?

@saibotk
Copy link
Member Author

saibotk commented Jun 19, 2025

Pretty sure, as all the changes that i removed were mainly introduced as workarounds for the broken use system.
But will check doors etc. on the weekend

@saibotk
Copy link
Member Author

saibotk commented Nov 17, 2025

@TimGoll would you mind taking a look at my code here whenever you got time?

It still contains debug stuff, so don't to a picky review but rather checkout the code locally and try some interactions with entities.
I think you also know quite some intricacies about the use system and think that would be useful when testing this.

I intent to get this ready on the weekend, so we can fully review and merge this and test it with more people on the main branch.

@TimGoll
Copy link
Member

TimGoll commented Nov 17, 2025

@TimGoll would you mind taking a look at my code here whenever you got time?

It still contains debug stuff, so don't to a picky review but rather checkout the code locally and try some interactions with entities.
I think you also know quite some intricacies about the use system and think that would be useful when testing this.

I intent to get this ready on the weekend, so we can fully review and merge this and test it with more people on the main branch.

I will try to take a look at it tomorrow, but I'm unsure if I can meaningful debug it without testing it. And not sure if I got time for this week

@saibotk
Copy link
Member Author

saibotk commented Nov 17, 2025

Jeah no worries, would be nice to maybe catch stuff i am missing with this, otherwise we can test this extensively on main / the beta workshop item when this is fine code-wise.

@TimGoll
Copy link
Member

TimGoll commented Nov 20, 2025

Sorry, I did not have time yet. I hope I have some spare time friday evening

@saibotk saibotk requested a review from TimGoll January 17, 2026 19:08
@saibotk saibotk force-pushed the refactor-use-handling branch 4 times, most recently from 1ec7c16 to fbd9fba Compare January 18, 2026 01:08
@saibotk saibotk marked this pull request as ready for review January 18, 2026 01:12
@saibotk saibotk changed the title Input: Refactor +use handling Input: Refactor +use handling to fix continuous use Jan 18, 2026
We refactored the "use key handling" to correctly
work with entities that use the continuous use
functionality, like the health station.

Why?

Previous efforts to consolidate "use key handling"
led to a regression where continuous use
did not work as intended anymore when directly
looking at such an entity.

Though, it still worked when using the use key
in the proximity of the entity without directly
looking at it or running into it with the use
key held down, because the server then handled
the continuous use by itself.

This is behavior that the client cannot "block",
so we needed to refactor this code to use the
server-side continuous use handling as its only
source of truth again.

The root cause for this issue was that the client
suppressed further use handling after sending
the net message to the server, which caused the
server-side `KeyPressed` check to return false in
the timer.
Simply changing this would not be sufficient,
as we need still to suppress this handling for the
other use-cases, like weapon pickup or remote use.

Changes:

We mainly refactored the server-side
"use key handling" and client-side key suppression
to fix this issue and simplify the code.
Also, the continous use execution frequency is now
every tick again, instead of every 0.1 seconds.

The actual continuous execution is now handled by
solely by the server again.

The `TTT2PlayerUseEntity` net message code was
refactored to only handle its special cases like
spectator use, remote use and weapon pickup.
We send this message from within the bind handler
on the client if applicable.
This code is still necessary, as these are cases
where the normal use handling is not triggered
by the server due to the items being out of reach
or may not be correctly prioritized e.g.
the wrong weapon being picked up instead of
the intended looked at entity.

The corpse search and old `UseOverride` handling
was moved back to the original TTT way of handling
it, by utilizing the `KeyRelease` hook.
We did not modify the code here and merely copied
over the original code again.

Removed `ENT.CanUseKey` from placeable entities
as it is not needed anymore with the new handling.

Removed now obsolete `IsSpecialUsableEntity` and
`IsUsableEntity` functions.

Refactored `ClientUse` function to be client only
and always block further use handling.
This function is generally useful for client-side
only use key handling, e.g., for UI interactions.
E.g. the C4 uses this to open the C4 menu
when the use key is pressed while looking at it.
@saibotk saibotk force-pushed the refactor-use-handling branch from fbd9fba to f25aca2 Compare January 18, 2026 01:25
@saibotk
Copy link
Member Author

saibotk commented Jan 18, 2026

Okay @TimGoll , i finished this one up and fixed any remaining bugs i could find when testing this locally.

Also added a description and changelog!

The change is actually rather simple now, but understanding the code parts can be hard, if you have any questions ask me and i'll happily help out!

Copy link
Member

@TimGoll TimGoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me - although I'd personally keep that one (now unused) function in the code

@TimGoll
Copy link
Member

TimGoll commented Jan 27, 2026

Sorry for the late review. I really struggle with my time currently. I need 40hour days to manage all my todos. The review might look like I just skimmed through it, but I did take my time. It does look really good, especially with all these helpful comments! Additionally, this PR's description is really helpful. I think it should work. Maybe @wgetJane can confirm this, as they spent a lot of time on this as well.

Thank you!

@saibotk saibotk merged commit 2cb83f3 into master Feb 8, 2026
4 checks passed
@saibotk saibotk deleted the refactor-use-handling branch February 8, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Health station continuous use doesn't work correctly

3 participants