Disabling game specific sounds

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Disabling game specific sounds

Postby decompile » Wed Feb 15, 2017 4:38 pm

Hey Guys,

Is there something like a sound hook, so I can prevent specific game sounds, lets say all "sound/player/.." sounds?
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Disabling game specific sounds

Postby Ayuto » Sat Feb 18, 2017 10:14 pm

I think you can hook and prevent playing certain sounds by hooking the virtual functions EmitSound, EmitSentenceByIndex and EmitAmbientSound. They are part of the IEngineSound class.
canibozz
Member
Posts: 32
Joined: Wed Apr 11, 2018 7:55 am

Re: Disabling game specific sounds

Postby canibozz » Fri Apr 13, 2018 9:22 am

I run into the same problem.
Iam not expecting spoon feeding answers just maybe some code snippets.

I tried to search how to PreHook the function which calls EmitSound, EmitSentenceByIndex and EmitAmbientSound.
Sadly i couldn't find it in the SDK nor in the docs of sourcepython.

I found a get_virtual_function function where you can pass an object and a function name.
I didn't know if the EmitSound function for example is in the game_event_manager or ON THE engine_server. Furthermore i don't know if the Function is even called EmitSound, EmitSentenceByIndex or EmitAmbientSound.

This is my code until now. Now i need to determinate what the event_name is. (csgo)

Syntax: Select all

# =============================================================================
# >> VIRTUAL FUNCTIONS
# =============================================================================
#Is 3 really the ID of the engine sound? How to get this index. Use get_virtual_functions instead.
#engineSoundHook = get_object_pointer(engine_server).make_virtual_function(3, Convention.THISCALL, [DataType.POINTER, DataType.POINTER, DataType.INT, DataType.POINTER], DataType.VOID)

@PreHook(get_virtual_function(game_event_manager, 'sound'))
def _pre_game_event(args):
game_event_ptr = args[1]
if not game_event_ptr:
return False

# Get the GameEvent object
game_event = make_object(GameEvent, game_event_ptr)

# Get the name of the event
event_name = game_event.name

print(event_name)
Last edited by canibozz on Fri Apr 13, 2018 12:27 pm, edited 1 time in total.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Disabling game specific sounds

Postby satoon101 » Fri Apr 13, 2018 11:31 am

What sounds are you trying to stop?
Image
canibozz
Member
Posts: 32
Joined: Wed Apr 11, 2018 7:55 am

Re: Disabling game specific sounds

Postby canibozz » Fri Apr 13, 2018 11:34 am

'Body Drop Sounds',
'Headshot Sound',
'Death Sound',
'Weapon Shoot Sounds',
'Step sounds'

Cheers!
canibozz
Member
Posts: 32
Joined: Wed Apr 11, 2018 7:55 am

Re: Disabling game specific sounds

Postby canibozz » Tue Apr 17, 2018 11:14 pm

Bumping, still needed.

I tried to continue investigating:

Syntax: Select all

from engines.sound import Attenuation, Sound, StreamSound

#Is EmitSound correct? Does every sound requested play in here?
#Body Drop, Headshot sound, death sound, weapon shoot sound, step sounds.
@PreHook(get_virtual_function(engine_sound, 'EmitSound'))
def emitSoundHook(args):
print(args)


Iam getting an error:
KeyError: 'IEngineSound'

Cheers
canibozz
Member
Posts: 32
Joined: Wed Apr 11, 2018 7:55 am

Re: Disabling game specific sounds

Postby canibozz » Thu Apr 19, 2018 12:46 pm

Bump.

I tried to hook Primary Attack but this crashes my server.

Syntax: Select all

is_awp = EntityCondition.equals_entity_classname('weapon_awp')

@EntityPreHook(is_awp, 'primary_attack')
def _secondary_knife_attack(stack_data):
entity = Entity(index_from_pointer(stack_data[0]))

engine_sound.stop_sound(index_from_pointer(stack_data[0]), Channel.WEAPON, "weapons/awp/awp1.wav")
engine_sound.stop_sound(index_from_pointer(stack_data[0]), Channel.WEAPON, "weapons/awp/awp_01.wav")
engine_sound.stop_sound(index_from_pointer(stack_data[0]), Channel.WEAPON, "weapons/awp/awp_02.wav")

@Event('server_spawn')
def load_particles(game_event):
engine_sound.precache_sound("weapons/awp/awp1.wav")
engine_sound.precache_sound("weapons/awp/awp1-distant.wav")
engine_sound.precache_sound("weapons/awp/awp_01.wav")
engine_sound.precache_sound("weapons/awp/awp_02.wav")
engine_sound.precache_sound("weapons/awp/awp_boltback.wav")
engine_sound.precache_sound("weapons/awp/awp_boltforward.wav")
engine_sound.precache_sound("weapons/awp/awp_draw.wav")



Edit:

Syntax: Select all

@PreHook(get_virtual_function(engine_sound, 'emit_sound'))

Gives a

Syntax: Select all

KeyError: 'IEngineSound'

and i don't understand why.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Disabling game specific sounds

Postby Ayuto » Thu Apr 19, 2018 4:36 pm

Please be a little bit patient. I will definitely solve your request, but I'm quite busy at the moment.

You get the KeyError, because get_virtual_function() only works for methods we have exposed via these macros:
https://github.com/Source-Python-Dev-Te ... #L160-L229

The sound methods are not exposed. To get a list of all exposed methods you can do the following steps:
  1. Run the server command "sp dump class_info class_info".
  2. Go to your logs directory and open the file "class_info.txt"
canibozz
Member
Posts: 32
Joined: Wed Apr 11, 2018 7:55 am

Re: Disabling game specific sounds

Postby canibozz » Thu Apr 19, 2018 9:41 pm

Does that mean not "yet", or are they just clientside and you can't expose it?
Because i don't see any SoundEmit Function only 'EmitAmbientSound' and this isn't called at all for the stuff i want to do (mentioned above).
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Disabling game specific sounds

Postby satoon101 » Thu Apr 19, 2018 10:22 pm

I haven't tested any of the situations you listed, but some sounds are triggered client side by events. For instance, round end sounds are triggered client side by the round_end event broadcasting to clients. So, I used the following to stop that from happening:
https://github.com/satoon101/GunGame-Te ... #L110-L114

You might try the same for some of your situations and see if that might work.

You might also try this:
viewtopic.php?f=20&t=754&p=4272#p4272

That example is for CS:S, so you'll need to update it to work with CS:GO.
Image
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Disabling game specific sounds

Postby Ayuto » Sun Apr 29, 2018 2:35 pm

Sorry, for the delay. Unfortunately, I'm unable to disable these sounds by hooking the sound sending function. I also just saw that L'In20Cible already said that most sounds are predicted by the client. That's why blocking it from the server doesn't help.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Disabling game specific sounds

Postby satoon101 » Sun Apr 29, 2018 6:26 pm

canibozz wrote:'Body Drop Sounds',
'Headshot Sound',
'Death Sound',
'Weapon Shoot Sounds',
'Step sounds'

Cheers!


For the headshot sound, I found that if you change the hitgroup in an OnTakeDamage hook, it should still do the same amount of damage, but remove the headshot sound and whiplash. If you still want the whiplash, I don't think that's going to be possible.

Syntax: Select all

from entities.hooks import EntityCondition, EntityPreHook
from memory import make_object
from players.entity import Player

@EntityPreHook(EntityCondition.is_bot_player, 'on_take_damage')
@EntityPreHook(EntityCondition.is_human_player, 'on_take_damage')
def _pre_take_damage(stack_data):
victim = make_object(Player, stack_data[0])
victim.hitgroup = 2

If you still want the hitgroup to show up correctly in events, you could track whether you need to make that change and reset it in a PreEvent.

Syntax: Select all

from entities.hooks import EntityCondition, EntityPreHook
from events.hooks import PreEvent
from memory import make_object
from players.entity import Player

reset_hitgroup = False

@EntityPreHook(EntityCondition.is_bot_player, 'on_take_damage')
@EntityPreHook(EntityCondition.is_human_player, 'on_take_damage')
def _pre_take_damage(stack_data):
global reset_hitgroup
victim = make_object(Player, stack_data[0])
if victim.hitgroup == 1:
victim.hitgroup = 2
reset_hitgroup = True

@PreEvent('player_hurt')
def _pre_hurt(game_event):
global reset_hitgroup
if not reset_hitgroup:
return
reset_hitgroup = False
game_event['hitgroup'] = 1



If you want to remove "all" step sounds, you can set sv_footsteps to 0. It's a hidden ConVar in CS:GO, so you'll have to use something like:

Syntax: Select all

from cvars import cvar, ConVarFlags
footsteps = cvar.find_var('sv_footsteps')
footsteps.set_bool(False)


The rest, I am pretty sure Ayuto is exactly right on and are completely predicted client side with no way to really stop them. At least my efforts have not yielded any good results for any of them.
Image
canibozz
Member
Posts: 32
Joined: Wed Apr 11, 2018 7:55 am

Re: Disabling game specific sounds

Postby canibozz » Mon May 07, 2018 2:54 pm

Thank you very much for your investigations.

I thought about coding an own weapon if that is possible, which has a custom viewmodel (I could use the awp model for it) and put custom deathnotice sprite. I'am not sure if that is possible tho.

Did you ever try something like this?

Cheers,
CANi
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Disabling game specific sounds

Postby satoon101 » Tue May 08, 2018 8:42 pm

I have personally never dealt with any of that stuff before. Though, if I'm thinking right, you might be able to modify the existing weapon scripts to accomplish this. I have no experience with that, either, but others on here might be able to help clarify.
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 37 guests