From 07ecb8e9884c8a93b28d50960aef16f195052e80 Mon Sep 17 00:00:00 2001 From: Space V <40030799+spacevx@users.noreply.github.com> Date: Thu, 12 Nov 2026 07:12:06 +0100 Subject: [PATCH 1/7] Interval.Read w/ invariant culture --- Source.Common/BaseTypes.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Source.Common/BaseTypes.cs b/Source.Common/BaseTypes.cs index a13bacfa7..fe2ce1e1c 100644 --- a/Source.Common/BaseTypes.cs +++ b/Source.Common/BaseTypes.cs @@ -29,12 +29,11 @@ public static Interval Read(ReadOnlySpan str) { int comma = str.IndexOf(','); if (comma >= 0) { - float.TryParse(str[..comma], out tmp.Start); - float.TryParse(str[(comma + 1)..], out float range); - tmp.Range = range - tmp.Start; + tmp.Start = (float)atof(str[..comma]); + tmp.Range = (float)atof(str[(comma + 1)..]) - tmp.Start; } else if (!str.IsEmpty) - float.TryParse(str, out tmp.Start); + tmp.Start = (float)atof(str); return tmp; } From 834fec3b9a0e87d034d5a5576553a8862ed57572 Mon Sep 17 00:00:00 2001 From: Space V <40030799+spacevx@users.noreply.github.com> Date: Thu, 12 Nov 2026 07:12:06 +0100 Subject: [PATCH 2/7] GMod sound effect volume slider --- Game.UI/OptionsSubAudio.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Game.UI/OptionsSubAudio.cs b/Game.UI/OptionsSubAudio.cs index 24caefc50..d7ca1751f 100644 --- a/Game.UI/OptionsSubAudio.cs +++ b/Game.UI/OptionsSubAudio.cs @@ -18,6 +18,9 @@ public class OptionsSubAudio : PropertyPage ComboBox SoundQualityCombo; CvarSlider SFXSlider; CvarSlider MusicSlider; +#if GMOD_DLL + CvarSlider GModSFXSlider; +#endif ComboBox CloseCaptionCombo; bool RequireRestart; ComboBox SpokenLanguageCombo; @@ -28,6 +31,9 @@ public class OptionsSubAudio : PropertyPage public OptionsSubAudio(Panel? parent, ReadOnlySpan name) : base(parent, name) { SFXSlider = new(this, "SFXSlider", "#GameUI_SoundEffectVolume", 0.0f, 1.0f, "volume"); MusicSlider = new(this, "MusicSlider", "#GameUI_MusicVolume", 0.0f, 1.0f, "Snd_MusicVolume"); +#if GMOD_DLL + GModSFXSlider = new(this, "GModSFXSlider", "#GameUI_SoundFXVolume", 0.0f, 1.0f, "volume_sfx"); +#endif CloseCaptionCombo = new(this, "CloseCaptionCheck", 6, false); CloseCaptionCombo.AddItem("#GameUI_NoClosedCaptions", null); @@ -60,6 +66,9 @@ public override void OnResetData() { RequireRestart = false; SFXSlider.Reset(); MusicSlider.Reset(); +#if GMOD_DLL + GModSFXSlider.Reset(); +#endif ConVarRef closecaption = new("closecaption"); ConVarRef cc_subtitles = new("cc_subtitles"); @@ -103,6 +112,9 @@ public void OnControlModified(Panel sender) { public override void OnApplyChanges() { SFXSlider.ApplyChanges(); MusicSlider.ApplyChanges(); +#if GMOD_DLL + GModSFXSlider.ApplyChanges(); +#endif // More to do } From 7f0e9d512ed5e026e5bb2ea10acb181c27d5264f Mon Sep 17 00:00:00 2001 From: Space V <40030799+spacevx@users.noreply.github.com> Date: Thu, 12 Nov 2026 07:12:06 +0100 Subject: [PATCH 3/7] Apply volume_sfx in the mixer like gmod --- Source.AudioSystem/SndDsp.Presets.cs | 41 ++++++++++++++++++++++++++++ Source.AudioSystem/SndMix.cs | 9 ++++++ 2 files changed, 50 insertions(+) diff --git a/Source.AudioSystem/SndDsp.Presets.cs b/Source.AudioSystem/SndDsp.Presets.cs index c3290f567..a70fafc34 100644 --- a/Source.AudioSystem/SndDsp.Presets.cs +++ b/Source.AudioSystem/SndDsp.Presets.cs @@ -373,8 +373,37 @@ static void PSET_Free(Pset? ppset) { // OP_RIGHT - process right channel in place // OP_LEFT_DUPLICATe - process left channel, duplicate into right +#if GMOD_DLL + static int g_DspCurrentPreset; + static bool DSP_UsesSfxVolume() => g_DspCurrentPreset >= 35 && g_DspCurrentPreset <= 38; + [MethodImpl(MethodImplOptions.AggressiveOptimization)] static void PSET_GetNextN(Pset ppset, Span pbuffer, int SampleCount, int op) { + PSET_GetNextNUnscaled(ppset, pbuffer, SampleCount, op); + + if (!DSP_UsesSfxVolume()) + return; + + float sfxVolume = Source.Common.Audio.SndGain.volume_sfx.GetFloat(); + for (int i = 0; i < SampleCount; i++) { + pbuffer[i].Left = (int)(pbuffer[i].Left * sfxVolume); + pbuffer[i].Right = (int)(pbuffer[i].Right * sfxVolume); + } + } + + [MethodImpl(MethodImplOptions.AggressiveOptimization)] + static int PSET_GetNext(Pset ppset, int x) { + int y = PSET_GetNextUnscaled(ppset, x); + return DSP_UsesSfxVolume() ? (int)(y * Source.Common.Audio.SndGain.volume_sfx.GetFloat()) : y; + } +#endif + + [MethodImpl(MethodImplOptions.AggressiveOptimization)] +#if GMOD_DLL + static void PSET_GetNextNUnscaled(Pset ppset, Span pbuffer, int SampleCount, int op) { +#else + static void PSET_GetNextN(Pset ppset, Span pbuffer, int SampleCount, int op) { +#endif Span pbf = pbuffer; Span pprc; int count = ppset.cprcs; @@ -415,7 +444,11 @@ static void PSET_GetNextN(Pset ppset, Span pbuffer, int Samp // x is input sample [MethodImpl(MethodImplOptions.AggressiveOptimization)] +#if GMOD_DLL + static int PSET_GetNextUnscaled(Pset ppset, int x) { +#else static int PSET_GetNext(Pset ppset, int x) { +#endif // pset_simple and pset_linear have no internal state: // this is REQUIRED for all presets that have a batch getnextN equivalent! @@ -3197,6 +3230,10 @@ public static void DSP_Process(int idsp, PortableSamplePair[] pbfront, PortableS int cprocs; // output cannels (1, 2 or 4) Dsp pdsp; +#if GMOD_DLL + g_DspCurrentPreset = 0; +#endif + if (idsp < 0 || idsp >= CDSPS) return; @@ -3235,6 +3272,10 @@ public static void DSP_Process(int idsp, PortableSamplePair[] pbfront, PortableS if (pdsp.ipset == 0 && pdsp.ipsetprev == 0) return; +#if GMOD_DLL + g_DspCurrentPreset = pdsp.ipset != 0 ? pdsp.ipset : pdsp.ipsetprev; +#endif + cchan_in = (pbrear != null ? 4 : 2) + (pbcenter != null ? 1 : 0); cprocs = pdsp.cchan; diff --git a/Source.AudioSystem/SndMix.cs b/Source.AudioSystem/SndMix.cs index b2b76d0c5..57180953d 100644 --- a/Source.AudioSystem/SndMix.cs +++ b/Source.AudioSystem/SndMix.cs @@ -2220,6 +2220,15 @@ public static bool MIX_ScaleChannelVolume(PaintBuffer ppaint, Channel channel, S } +#if GMOD_DLL + if (channel.Mixer != null && !(channel.Flags.Dry && channel.DistMult <= 0) + && channel.Mixer.GetSource().GetAudioSourceType() != AudioSourceType.AUDIO_SOURCE_VOICE) { + float sfxVolume = SndGain.volume_sfx.GetFloat(); + for (i = 0; i < CCHANVOLUMES; i++) + volume[i] = Math.Clamp((int)(volume[i] * sfxVolume), 0, 255); + } +#endif + bool fzerovolume = true; for (i = 0; i < CCHANVOLUMES; i++) { From 46abe7ce226ce7770bf7ae825ec580e01e6c3548 Mon Sep 17 00:00:00 2001 From: Space V <40030799+spacevx@users.noreply.github.com> Date: Thu, 12 Nov 2026 07:12:06 +0100 Subject: [PATCH 4/7] Fix ammo indices starting at 0 --- Game.Shared/AmmoDef.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Game.Shared/AmmoDef.cs b/Game.Shared/AmmoDef.cs index c3c0a8193..cb389edcb 100644 --- a/Game.Shared/AmmoDef.cs +++ b/Game.Shared/AmmoDef.cs @@ -46,7 +46,7 @@ public class AmmoDef public static Ammo NULL = default; - public int AmmoIndex; + public int AmmoIndex = 1; public Ammo[] AmmoType = new Ammo[MAX_AMMO_TYPES]; public ref Ammo GetAmmoOfIndex(int ammoIndex) { From 6de166057d2b58e505ca4005a9fa0b840bbd6dfc Mon Sep 17 00:00:00 2001 From: Space V <40030799+spacevx@users.noreply.github.com> Date: Thu, 12 Nov 2026 07:12:06 +0100 Subject: [PATCH 5/7] Pistol, rpg and shotgun reloads --- Game.Shared/GarrysMod/WeaponPistol.cs | 9 ++++ Game.Shared/GarrysMod/WeaponRPG.cs | 15 +++++++ Game.Shared/GarrysMod/WeaponShotgun.cs | 60 ++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/Game.Shared/GarrysMod/WeaponPistol.cs b/Game.Shared/GarrysMod/WeaponPistol.cs index 9c7ae2ac8..0a076010c 100644 --- a/Game.Shared/GarrysMod/WeaponPistol.cs +++ b/Game.Shared/GarrysMod/WeaponPistol.cs @@ -40,6 +40,15 @@ public partial class WeaponPistol : HL2MPMachineGun public const TimeUnit_t PISTOL_ACCURACY_SHOT_PENALTY_TIME = 0.2;// Applied amount of time each shot adds to the time we must recover from public const TimeUnit_t PISTOL_ACCURACY_MAXIMUM_PENALTY_TIME = 1.5;// Maximum penalty to deal out + public override bool Reload() { + bool ret = DefaultReload(GetMaxClip1(), GetMaxClip2(), Activity.ACT_VM_RELOAD); + if (ret) { + WeaponSound(Shared.WeaponSound.Reload); + AccuracyPenalty = 0.0f; + } + return ret; + } + public override void ItemPostFrame() { base.ItemPostFrame(); diff --git a/Game.Shared/GarrysMod/WeaponRPG.cs b/Game.Shared/GarrysMod/WeaponRPG.cs index de0defd63..69ebe3c9f 100644 --- a/Game.Shared/GarrysMod/WeaponRPG.cs +++ b/Game.Shared/GarrysMod/WeaponRPG.cs @@ -41,6 +41,21 @@ public WeaponRPG() { [NetworkVar("m_vecLaserDot")] public partial Vector3 LaserDot { get; set; } public override float GetFireRate() => 1f; + + public override bool Reload() { + BaseCombatCharacter? owner = GetOwner(); + if (owner == null) + return false; + + if (owner.GetAmmoCount(PrimaryAmmoType) <= 0) + return false; + + WeaponSound(Shared.WeaponSound.Reload); + + SendWeaponAnim(Activity.ACT_VM_RELOAD); + + return true; + } } [LinkEntityToClass("env_laserdot")] diff --git a/Game.Shared/GarrysMod/WeaponShotgun.cs b/Game.Shared/GarrysMod/WeaponShotgun.cs index a284dbaa2..1e53edaa9 100644 --- a/Game.Shared/GarrysMod/WeaponShotgun.cs +++ b/Game.Shared/GarrysMod/WeaponShotgun.cs @@ -237,6 +237,66 @@ private bool StartReload() { return true; } + public override bool Reload() { + if (!InReload) + Warning("ERROR: Shotgun Reload called incorrectly!\n"); + + BaseCombatCharacter? owner = GetOwner(); + + if (owner == null) + return false; + + if (owner.GetAmmoCount(PrimaryAmmoType) <= 0) + return false; + + if (iClip1 >= GetMaxClip1()) + return false; + + int j = Math.Min(1, owner.GetAmmoCount(PrimaryAmmoType)); + + if (j <= 0) + return false; + + FillClip(); + WeaponSound(Shared.WeaponSound.Reload); + SendWeaponAnim(Activity.ACT_VM_RELOAD); + + owner.NextAttack = gpGlobals.CurTime; + NextPrimaryAttack = gpGlobals.CurTime + SequenceDuration(); + + return true; + } + + public override void FinishReload() { + SetBodygroup(1, 1); + + BaseCombatCharacter? owner = GetOwner(); + + if (owner == null) + return; + + InReload = false; + + SendWeaponAnim(Activity.ACT_SHOTGUN_RELOAD_FINISH); + + owner.NextAttack = gpGlobals.CurTime; + NextPrimaryAttack = gpGlobals.CurTime + SequenceDuration(); + } + + private void FillClip() { + BaseCombatCharacter? owner = GetOwner(); + + if (owner == null) + return; + + if (owner.GetAmmoCount(PrimaryAmmoType) > 0) { + if (Clip1() < GetMaxClip1()) { + iClip1++; + owner.RemoveAmmo(1, PrimaryAmmoType); + } + } + } + public override void PrimaryAttack() { // Only the player fires this way so we can cast BasePlayer? player = ToBasePlayer(GetOwner()); From 7ae4b754829e05e9864881fd04ae4fe08b2bfad7 Mon Sep 17 00:00:00 2001 From: Space V <40030799+spacevx@users.noreply.github.com> Date: Thu, 12 Nov 2026 07:12:06 +0100 Subject: [PATCH 6/7] Fix LocalPlayerFilter not adding the local player --- Game.Client/C_RecipientFilter.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Game.Client/C_RecipientFilter.cs b/Game.Client/C_RecipientFilter.cs index d82b0d63a..23a6f9ed2 100644 --- a/Game.Client/C_RecipientFilter.cs +++ b/Game.Client/C_RecipientFilter.cs @@ -220,7 +220,8 @@ public PVSFilter(in Vector3 origin) : base() { public class LocalPlayerFilter : C_RecipientFilter { public LocalPlayerFilter() : base() { - + if (C_BasePlayer.GetLocalPlayer() != null) + AddRecipient(C_BasePlayer.GetLocalPlayer()); } } From 15dd1a5fe3c599387ffe19225a9e408c564196a7 Mon Sep 17 00:00:00 2001 From: Space V <40030799+spacevx@users.noreply.github.com> Date: Thu, 12 Nov 2026 07:12:06 +0100 Subject: [PATCH 7/7] Client animation sound events --- Game.Client/C_BaseAnimating.cs | 120 +++++++++++++++++++++++++++++++++ Game.Client/C_BaseEntity.cs | 2 + Game.Client/C_BaseViewModel.cs | 17 +++++ 3 files changed, 139 insertions(+) diff --git a/Game.Client/C_BaseAnimating.cs b/Game.Client/C_BaseAnimating.cs index 609a4b68a..c6ff6d8d9 100644 --- a/Game.Client/C_BaseAnimating.cs +++ b/Game.Client/C_BaseAnimating.cs @@ -305,8 +305,128 @@ public void InvalidateBoneCache() { MostRecentModelBoneCounter = ModelBoneCounter - 1; LastBoneSetupTime = -TimeUnit_t.MaxValue; } + public const int CL_EVENT_SOUND = 5004; + + static bool IsClientAnimEvent(MStudioEvent ev) { + if ((ev.Type & (int)AnimEventType.NewEventSystem) != 0) + return (ev.Type & (int)AnimEventType.Client) != 0; + + return ev.Event >= 5000; + } + + static string EventOptions(MStudioEvent ev) => System.Text.Encoding.ASCII.GetString(((ReadOnlySpan)ev.Options()).SliceNullTerminatedString()); + public virtual void DoAnimationEvents(StudioHdr hdr) { + if (hdr == null) + return; + + if (GetSequence() == -1) + return; + + float eventCycle = (float)GetCycle(); + + if (!IsVisible() && !IsViewModel()) + return; + + int numSeq = hdr.GetNumSeq(); + if (numSeq < 1) { + Warning($"{GetDebugName()}[{EntIndex()}]: no sequences?\n"); + return; + } + + int seqNum = GetSequence(); + if (seqNum >= numSeq) { + Warning($"{GetDebugName()}[{EntIndex()}]: Playing sequence {seqNum} but there's only {numSeq} in total?\n"); + return; + } + + MStudioSeqDesc seqdesc = hdr.Seqdesc(seqNum); + if (seqdesc.NumEvents == 0) + return; + + Animation.GetEventIndexForSequence(seqdesc); + + bool resetEvents = ResetEventsParity != PrevResetEventsParity; + PrevResetEventsParity = ResetEventsParity; + + if (EventSequence != GetSequence() || resetEvents) { + EventSequence = GetSequence(); + eventCycle = 0.0f; + PrevEventCycle = -0.01f; + } + + if (eventCycle == PrevEventCycle) + return; + bool looped = false; + if (eventCycle <= PrevEventCycle) { + if (PrevEventCycle - eventCycle > 0.5) + looped = true; + else + return; + } + + if (looped) { + for (int i = 0; i < (int)seqdesc.NumEvents; i++) { + MStudioEvent ev = seqdesc.Event(i); + if (!IsClientAnimEvent(ev)) + continue; + + if (ev.Cycle <= PrevEventCycle) + continue; + + FireEvent(in GetAbsOrigin(), in GetAbsAngles(), ev.Event, EventOptions(ev)); + } + + PrevEventCycle = eventCycle - 0.001f; + } + + for (int i = 0; i < (int)seqdesc.NumEvents; i++) { + MStudioEvent ev = seqdesc.Event(i); + if (!IsClientAnimEvent(ev)) + continue; + + if (ev.Cycle > PrevEventCycle && ev.Cycle <= eventCycle) + FireEvent(in GetAbsOrigin(), in GetAbsAngles(), ev.Event, EventOptions(ev)); + } + + PrevEventCycle = eventCycle; + } + + public virtual void FireEvent(in Vector3 origin, in QAngle angles, int ev, string options) { + switch (ev) { + case (int)AnimEventId.AE_CL_PLAYSOUND: { + LocalPlayerFilter filter = new(); + if (Attachments.Count > 0) { + GetAttachment(1, out Vector3 attachOrigin, out _); + EmitSound(filter, GetSoundSourceIndex(), options, in attachOrigin, out _); + } + else + EmitSound(filter, GetSoundSourceIndex(), options, in GetAbsOrigin(), out _); + } + break; + case (int)AnimEventId.AE_CL_STOPSOUND: + StopSound(GetSoundSourceIndex(), options); + break; + case CL_EVENT_SOUND: + FireObsoleteEvent(in origin, in angles, ev, options); + break; + } + } + + public virtual void FireObsoleteEvent(in Vector3 origin, in QAngle angles, int ev, string options) { + switch (ev) { + case CL_EVENT_SOUND: { + LocalPlayerFilter filter = new(); + if (Attachments.Count > 0) { + GetAttachment(1, out Vector3 attachOrigin, out _); + EmitSound(filter, GetSoundSourceIndex(), options, in attachOrigin, out _); + } + else + EmitSound(filter, GetSoundSourceIndex(), options); + } + break; + } } public bool IsBoneCacheValid() => MostRecentModelBoneCounter == ModelBoneCounter; public static void InvalidateBoneCaches() => ModelBoneCounter++; diff --git a/Game.Client/C_BaseEntity.cs b/Game.Client/C_BaseEntity.cs index 8b6539b5f..a34dd59b8 100644 --- a/Game.Client/C_BaseEntity.cs +++ b/Game.Client/C_BaseEntity.cs @@ -2604,6 +2604,8 @@ public void SetDestroyedOnRecreateEntities() { public virtual ref readonly BaseHandle GetRefEHandle() { return ref RefEHandle; } + + public int GetSoundSourceIndex() => GetRefEHandle().GetEntryIndex(); public virtual void SetRefEHandle(in BaseHandle handle) { RefEHandle.Index = handle.Index; } diff --git a/Game.Client/C_BaseViewModel.cs b/Game.Client/C_BaseViewModel.cs index 56f4d9763..43b00cf52 100644 --- a/Game.Client/C_BaseViewModel.cs +++ b/Game.Client/C_BaseViewModel.cs @@ -7,6 +7,9 @@ namespace Game.Client; #if GMOD_DLL using Game.Client.GarrysMod; +using Game.Shared; + +using System.Numerics; #endif public partial class C_BaseViewModel @@ -207,4 +210,18 @@ public override bool Interpolate(TimeUnit_t currentTime) { public override RenderGroup GetRenderGroup() { return RenderGroup.ViewModelOpaque; } + + public override void FireEvent(in Vector3 origin, in QAngle angles, int ev, string options) { + if (ev == (int)AnimEventId.AE_CL_PLAYSOUND || ev == CL_EVENT_SOUND) { + C_BaseEntity? owner = GetOwner(); + if (owner != null) { + LocalPlayerFilter filter = new(); + EmitSound(filter, owner.GetSoundSourceIndex(), options, in GetAbsOrigin(), out _); + return; + } + } + + if (GetOwningWeapon() != null) + base.FireEvent(in origin, in angles, ev, options); + } }