-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 95998e3
Showing
6 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
/.vs | ||
/bin | ||
/obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# StopSound | ||
Stop weapon sound for CS2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
using CounterStrikeSharp.API; | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Core.Attributes.Registration; | ||
using CounterStrikeSharp.API.Modules.Commands; | ||
using CounterStrikeSharp.API.Modules.UserMessages; | ||
using CounterStrikeSharp.API.Modules.Utils; | ||
using static CounterStrikeSharp.API.Core.Listeners; | ||
|
||
namespace StopSound | ||
{ | ||
public class StopSound : BasePlugin | ||
{ | ||
public override string ModuleName => "Stop Weapon Sound"; | ||
public override string ModuleAuthor => "Oylsister"; | ||
public override string ModuleDescription => "Prevent client to hear a noise sound from firing weapon"; | ||
public override string ModuleVersion => "Alpha 1.0"; | ||
|
||
public ulong silencer; | ||
public ulong stopsound; | ||
public ulong normal; | ||
|
||
public enum SoundMode : int | ||
{ | ||
M_NORMAL = 0, | ||
M_STOP = 1, | ||
M_SILENCER = 2 | ||
} | ||
|
||
public Dictionary<CCSPlayerController, SoundMode> ClientSoundList = new Dictionary<CCSPlayerController, SoundMode>(); | ||
|
||
public override void Load(bool hotReload) | ||
{ | ||
HookUserMessage(452, Hook_WeaponFiring, HookMode.Pre); | ||
|
||
RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull); | ||
RegisterListener<OnClientDisconnect>(OnClientDisconnected); | ||
} | ||
|
||
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo eventInfo) | ||
{ | ||
var client = @event.Userid; | ||
|
||
if (client == null) | ||
return HookResult.Continue; | ||
|
||
ClientSoundList.Add(client, SoundMode.M_NORMAL); | ||
SetStopSoundStatus(client, SoundMode.M_NORMAL); | ||
return HookResult.Continue; | ||
} | ||
|
||
private void OnClientDisconnected(int playerSlot) | ||
{ | ||
var client = Utilities.GetPlayerFromSlot(playerSlot); | ||
|
||
if (client == null) | ||
return; | ||
|
||
ClientSoundList.Remove(client); | ||
|
||
normal |= ((ulong)1L << client.Slot); | ||
stopsound |= ((ulong)1L << client.Slot); | ||
silencer &= ((ulong)1L << client.Slot); | ||
} | ||
|
||
[ConsoleCommand("css_stopsound")] | ||
[CommandHelper(1, "css_stopsound <0-2>", CommandUsage.CLIENT_ONLY)] | ||
public void StopSoundCommand(CCSPlayerController client, CommandInfo info) | ||
{ | ||
var arg = info.GetArg(1); | ||
|
||
if(int.Parse(arg) > 2 || int.Parse(arg) < 3) | ||
{ | ||
info.ReplyToCommand($"{ChatColors.Green}[Stopsound]{ChatColors.White} You can't set number more than 2 or less than 0!"); | ||
return; | ||
} | ||
|
||
var mode = (SoundMode)int.Parse(arg); | ||
SetStopSoundStatus(client, mode); | ||
} | ||
|
||
public HookResult Hook_WeaponFiring(UserMessage userMessage) | ||
{ | ||
var silencer_mask = new RecipientFilter(silencer); | ||
|
||
var weaponid = userMessage.ReadUInt("weapon_id"); | ||
var soundType = userMessage.ReadInt("sound_type"); | ||
var itemdefindex = userMessage.ReadUInt("item_def_index"); | ||
|
||
userMessage.SetUInt("weapon_id", 0); | ||
userMessage.SetInt("sound_type", 9); | ||
userMessage.SetUInt("item_def_index", 61); | ||
|
||
// send for people who use silencer. | ||
userMessage.Send(silencer_mask); | ||
|
||
var normal_mask = new RecipientFilter(normal); | ||
|
||
userMessage.SetUInt("weapon_id", weaponid); | ||
userMessage.SetInt("sound_type", soundType); | ||
userMessage.SetUInt("item_def_index", itemdefindex); | ||
userMessage.Send(normal_mask); | ||
|
||
return HookResult.Handled; | ||
} | ||
|
||
void SetStopSoundStatus(CCSPlayerController client, SoundMode mode) | ||
{ | ||
if(client == null) return; | ||
|
||
if(!ClientSoundList.ContainsKey(client)) | ||
{ | ||
ClientSoundList.Add(client, mode); | ||
} | ||
|
||
var clientMode = ClientSoundList[client]; | ||
|
||
if (mode == SoundMode.M_NORMAL) | ||
{ | ||
normal |= ((ulong)1L << client.Slot); | ||
|
||
if (clientMode == SoundMode.M_STOP) | ||
stopsound &= ((ulong)1L << client.Slot); | ||
|
||
else if (clientMode == SoundMode.M_SILENCER) | ||
silencer &= ((ulong)1L << client.Slot); | ||
} | ||
|
||
else if (mode == SoundMode.M_STOP) | ||
{ | ||
stopsound |= ((ulong)1L << client.Slot); | ||
|
||
if (clientMode == SoundMode.M_NORMAL) | ||
normal &= ((ulong)1L << client.Slot); | ||
|
||
else if (clientMode == SoundMode.M_SILENCER) | ||
silencer &= ((ulong)1L << client.Slot); | ||
} | ||
|
||
else | ||
{ | ||
silencer |= ((ulong)1L << client.Slot); | ||
|
||
if (clientMode == SoundMode.M_NORMAL) | ||
normal &= ((ulong)1L << client.Slot); | ||
|
||
else if (clientMode == SoundMode.M_STOP) | ||
stopsound &= ((ulong)1L << client.Slot); | ||
} | ||
|
||
ClientSoundList[client] = mode; | ||
client.PrintToChat($"{ChatColors.Green}[Stopsound]{ChatColors.White} You set to {ChatColors.Lime}{GetModeString(mode)}{ChatColors.White}."); | ||
} | ||
|
||
string GetModeString(SoundMode mode) | ||
{ | ||
switch (mode) | ||
{ | ||
case SoundMode.M_NORMAL: | ||
return "Enable Sound"; | ||
|
||
case SoundMode.M_SILENCER: | ||
return "Silencer Sound"; | ||
|
||
case SoundMode.M_STOP: | ||
return "No weapon sound"; | ||
|
||
default: | ||
return "Invalid"; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.264" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.9.34607.119 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StopSound", "StopSound.csproj", "{5509F47D-C4AB-4ACC-AAE0-5183881BE46F}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{5509F47D-C4AB-4ACC-AAE0-5183881BE46F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5509F47D-C4AB-4ACC-AAE0-5183881BE46F}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5509F47D-C4AB-4ACC-AAE0-5183881BE46F}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5509F47D-C4AB-4ACC-AAE0-5183881BE46F}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {4D6ACC35-BC49-4FB0-8AC9-0B46B32C0C6E} | ||
EndGlobalSection | ||
EndGlobal |