Skip to content

Added VoiceHook functions#1247

Merged
KyleSanderson merged 15 commits intoalliedmodders:masterfrom
accelerator74:voicehook
Aug 18, 2020
Merged

Added VoiceHook functions#1247
KyleSanderson merged 15 commits intoalliedmodders:masterfrom
accelerator74:voicehook

Conversation

@accelerator74
Copy link
Contributor

Added hooks when a player uses a microphone:

/**
 * Called when a client is speaking.
 *
 * @param client        The client index
 */
forward void OnClientSpeaking(int client);

/**
 * Called once a client speaking end.
 *
 * @param client        The client index
 */
forward void OnClientSpeakingEnd(int client);

And native function:

/**
 * Retrieves if the certain player is speaking.
 *
 * @param client        The client index
 * @return              True if player is speaking, false otherwise.
 * @error               Invalid client index.
 */
native bool IsClientSpeaking(int client);

Sorry for double request. My fails :(

When a player leaves during a voteban, he will be banned anyway. Also added a cvar with a ban time setting.
@JoinedSenses
Copy link
Contributor

Adding comment here since other was deleted. Is there any other info that can be passed to this forward making it more useful besides just client?

@accelerator74
Copy link
Contributor Author

Is there any other info that can be passed to this forward making it more useful besides just client?

No, but there are plugins that use these hooks.

@CrazyHackGUT
Copy link
Contributor

Why support only CS:GO? I think, this PR should not be merged before you don't add support to another possible games.

@accelerator74
Copy link
Contributor Author

accelerator74 commented Apr 27, 2020

It's supported for all games. For csgo uses ClientVoice hook, for others - ProccesVoiceData.

@oscar-wos
Copy link

This is a feature I would fully take advantage off if implemented

@Headline Headline added the Feature Request user requested feature label May 8, 2020
Copy link
Member

@Headline Headline left a comment

Choose a reason for hiding this comment

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

Code-wise this looks okay to me

Copy link
Member

@KyleSanderson KyleSanderson left a comment

Choose a reason for hiding this comment

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

Copy link
Member

@KyleSanderson KyleSanderson left a comment

Choose a reason for hiding this comment

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

So close - just need to invalidate timers on disconnection / level change. Where'd you get 0.3f from? I remember a peer saying this on direct frames said this wasn't enough so I'd like to understand where the metric came from.

@accelerator74
Copy link
Contributor Author

accelerator74 commented Jul 9, 2020

Where'd you get 0.3f from? I remember a peer saying this on direct frames said this wasn't enough so I'd like to understand where the metric came from.

0.3 was taken so as not to create constantly new timers when called and the OnClientSpeakingEnd hook is called correctly. This delay is also used in franc1sco's VoiceAnnounceEX plugin.

@KyleSanderson
Copy link
Member

Where'd you get 0.3f from? I remember a peer saying this on direct frames said this wasn't enough so I'd like to understand where the metric came from.

0.3 was taken so as not to create constantly new timers when called and the OnClientSpeakingEnd hook is called correctly. This delay is also used in franc1sco's VoiceAnnounceEX plugin.

Yeah - this one in particular was really buggy with a clean imp... if there's issues we need to remember that this value is too low.

Copy link
Member

@KyleSanderson KyleSanderson left a comment

Choose a reason for hiding this comment

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

I apologize - totally not trying to bikeshed you here. I think we're super close (if there's other nits or stuff like that I'll own them after this).

Can you use CVTableHook here and compare vtables each time? That way if a client slips by this we don't miss them forever as we own the function ptr. With the flooding and other stuff going on in TF this may be used in a security fashion.

Can do something like:
https://github.com/alliedmodders/sourcemod/blob/master/extensions/sdkhooks/extension.cpp#L585
https://github.com/alliedmodders/sourcemod/blob/master/extensions/sdktools/hooks.cpp#L307

Copy link
Member

@KyleSanderson KyleSanderson left a comment

Choose a reason for hiding this comment

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

There's a merge conflict and load/unload issues in here.

@accelerator74
Copy link
Contributor Author

accelerator74 commented Jul 10, 2020

There's a merge conflict

I don’t understand what’s wrong?)

Conflicting files
extensions/sdktools/hooks.h

@asherkin
Copy link
Member

#1283 changed these hook lists from ke::Vector to std::vector. You'll want to git checkout master then git pull to update your local master branch, then git checkout voicehook and git rebase master to re-apply your changes on top of master - you'll then need to change the new ke::Vector you've added to a std::vector following the example of the other ones in that PR. Hopefully there should be no conflicts while updating, git should be able to figure it all out. If you have any trouble give a shout and someone can rebase it up for you.

Copy link
Member

@asherkin asherkin left a comment

Choose a reason for hiding this comment

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

Couple of minor comments, but this looks pretty good.

I'm a little concerned about the timer logic but it looks like it should work without letting anything slip through the cracks (once the handle clearing bug mentioned is fixed / clarified). However, alternative implementations I would find less surprising would be:

  • Cancel any existing and schedule a new timer each voice frame, so if the timer ever triggers it is because the voice frames have stopped coming it - this'd remove the need to do the manual timing checks.
  • Instead of using timers just use a frame hook that checks time / frame count globally.

@accelerator74 accelerator74 requested a review from asherkin July 11, 2020 05:51
Copy link
Member

@KyleSanderson KyleSanderson left a comment

Choose a reason for hiding this comment

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

@asherkin I think this is solid enough (after the final bug) to get into the tree. If there's quirks or other stuff they shouldn't be catastrophic.

@KyleSanderson
Copy link
Member

@asherkin what's the skinny on this one?

@asherkin
Copy link
Member

Sorry for the delay cycling back to this, things have been super crazy with moving.

This is all looking good to me other than one issue, which is that the native is a no-op if there are no active consumers of the hook. I think we should just pull this in without the native to get the hook in-tree, as plugins can easily re-build the native behaviour using the hook and it can always be discussed separately if super common.

Was going to make that change myself before pulling it (and get someone else to do a final review), but it has been too long already so leaving this comment with the reasoning if you or KyleS want to make that change before I get a chance (but I'll make sure to review and pull if that happens.)

Copy link
Member

@asherkin asherkin left a comment

Choose a reason for hiding this comment

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

LGTM, nice work!

@KyleSanderson KyleSanderson merged commit 1b86c85 into alliedmodders:master Aug 18, 2020
@accelerator74 accelerator74 deleted the voicehook branch June 12, 2021 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Request user requested feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants