Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions Game.Client/C_BaseAnimating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte>)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++;
Expand Down
2 changes: 2 additions & 0 deletions Game.Client/C_BaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 17 additions & 0 deletions Game.Client/C_BaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
3 changes: 2 additions & 1 deletion Game.Client/C_RecipientFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ public PVSFilter(in Vector3 origin) : base() {
public class LocalPlayerFilter : C_RecipientFilter
{
public LocalPlayerFilter() : base() {

if (C_BasePlayer.GetLocalPlayer() != null)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A little surprised this didnt exist already

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah same lol that's why weapon reload sounds didn't worked in some case

AddRecipient(C_BasePlayer.GetLocalPlayer());
}
}

Expand Down
2 changes: 1 addition & 1 deletion Game.Shared/AmmoDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions Game.Shared/GarrysMod/WeaponPistol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
15 changes: 15 additions & 0 deletions Game.Shared/GarrysMod/WeaponRPG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
60 changes: 60 additions & 0 deletions Game.Shared/GarrysMod/WeaponShotgun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
12 changes: 12 additions & 0 deletions Game.UI/OptionsSubAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +31,9 @@ public class OptionsSubAudio : PropertyPage
public OptionsSubAudio(Panel? parent, ReadOnlySpan<char> 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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
}
Expand Down
Loading
Loading