D:\ValheimDev\Dumps\Old\assembly_valheim\ZSFX.cs D:\ValheimDev\Dumps\Latest\assembly_valheim\ZSFX.cs
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
   
.public class ZSFX : MonoBehaviour  public class ZSFX : MonoBehaviour, IMonoUpdater 
{ {
    public void Awake()     public void Awake()
    {     {
        this.m_delay = UnityEngine.Random.Range(this.m_minDelay, this.m_maxDelay);         this.m_delay = UnityEngine.Random.Range(this.m_minDelay, this.m_maxDelay);
        this.m_audioSource = base.GetComponent<AudioSource>();         this.m_audioSource = base.GetComponent<AudioSource>();
        this.m_baseSpread = this.m_audioSource.spread;         this.m_baseSpread = this.m_audioSource.spread;
    }     }
   
    private void OnEnable()     private void OnEnable()
    {     {
        ZSFX.Instances.Add(this);         ZSFX.Instances.Add(this);
    }     }
   
    private void OnDisable()     private void OnDisable()
    {     {
        if (this.m_playOnAwake && this.m_audioSource.loop)         if (this.m_playOnAwake && this.m_audioSource.loop)
        {         {
            this.m_time = 0f;             this.m_time = 0f;
            this.m_delay = UnityEngine.Random.Range(this.m_minDelay, this.m_maxDelay);             this.m_delay = UnityEngine.Random.Range(this.m_minDelay, this.m_maxDelay);
            this.m_audioSource.Stop();             this.m_audioSource.Stop();
        }         }
        ZSFX.Instances.Remove(this);         ZSFX.Instances.Remove(this);
    }     }
   
.    public void CustomUpdate(float dt)     public event Action<ZSFX> OnDestroyingSfx = delegate 
      { 
      }; 
   
      private void OnDestroy() 
      { 
          this.OnDestroyingSfx(this); 
      } 
   
      public void CustomUpdate(float dt, float time)
    {     {
        if (this.m_audioSource == null)         if (this.m_audioSource == null)
        {         {
            return;             return;
        }         }
        this.m_time += dt;         this.m_time += dt;
        if (this.m_delay >= 0f && this.m_time >= this.m_delay)         if (this.m_delay >= 0f && this.m_time >= this.m_delay)
        {         {
            this.m_delay = -1f;             this.m_delay = -1f;
            if (this.m_playOnAwake)             if (this.m_playOnAwake)
            {             {
                this.Play();                 this.Play();
            }             }
        }         }
.          if (this.IsLooping())
          {
              this.m_concurrencyVolumeModifier = Mathf.MoveTowards(this.m_concurrencyVolumeModifier, (float)(this.m_disabledFromConcurrency ? 0 : 1), dt / 0.5f);
          }
        if (this.m_audioSource.isPlaying)         if (this.m_audioSource.isPlaying)
        {         {
            if (this.m_distanceReverb && this.m_audioSource.loop)             if (this.m_distanceReverb && this.m_audioSource.loop)
            {             {
                this.m_updateReverbTimer += dt;                 this.m_updateReverbTimer += dt;
                if (this.m_updateReverbTimer > 1f)                 if (this.m_updateReverbTimer > 1f)
                {                 {
                    this.m_updateReverbTimer = 0f;                     this.m_updateReverbTimer = 0f;
                    this.UpdateReverb();                     this.UpdateReverb();
                }                 }
            }             }
            if (this.m_fadeOutOnAwake && this.m_time > this.m_fadeOutDelay)             if (this.m_fadeOutOnAwake && this.m_time > this.m_fadeOutDelay)
            {             {
                this.m_fadeOutOnAwake = false;                 this.m_fadeOutOnAwake = false;
                this.FadeOut();                 this.FadeOut();
            }             }
.              float vol = this.m_vol;
              float num = 1f;
            if (this.m_fadeOutTimer >= 0f)             if (this.m_fadeOutTimer >= 0f)
            {             {
                this.m_fadeOutTimer += dt;                 this.m_fadeOutTimer += dt;
                if (this.m_fadeOutTimer >= this.m_fadeOutDuration)                 if (this.m_fadeOutTimer >= this.m_fadeOutDuration)
                {                 {
                    this.m_audioSource.volume = 0f;                     this.m_audioSource.volume = 0f;
                    this.Stop();                     this.Stop();
                    return;                     return;
                }                 }
.                float num = Mathf.Clamp01(this.m_fadeOutTimer / this.m_fadeOutDuration);                 num = 1f - Mathf.Clamp01(this.m_fadeOutTimer / this.m_fadeOutDuration);
                this.m_audioSource.volume = (1f - num) * this.m_vol;   
                return;   
            }             }
            else if (this.m_fadeInTimer >= 0f)             else if (this.m_fadeInTimer >= 0f)
            {             {
.                this.m_fadeInTimer += Time.deltaTime;                 this.m_fadeInTimer += dt;
                float num2 = Mathf.Clamp01(this.m_fadeInTimer / this.m_fadeInDuration);                 num = Mathf.Clamp01(this.m_fadeInTimer / this.m_fadeInDuration);
                this.m_audioSource.volume = num2 * this.m_vol;   
                if (this.m_fadeInTimer > this.m_fadeInDuration)                 if (this.m_fadeInTimer > this.m_fadeInDuration)
                {                 {
                    this.m_fadeInTimer = -1f;                     this.m_fadeInTimer = -1f;
                }                 }
            }             }
.              this.m_audioSource.volume = vol * num * this.m_concurrencyVolumeModifier * this.m_volumeModifier;
              float num2 = this.m_basePitch * this.m_pitchModifier;
              num2 -= num2 * this.m_reverbPitchModifier;
              this.m_audioSource.pitch = num2;
        }         }
    }     }
   
    public void FadeOut()     public void FadeOut()
    {     {
        if (this.m_fadeOutTimer < 0f)         if (this.m_fadeOutTimer < 0f)
        {         {
            this.m_fadeOutTimer = 0f;             this.m_fadeOutTimer = 0f;
        }         }
    }     }
   
    public void Stop()     public void Stop()
    {     {
        if (this.m_audioSource != null)         if (this.m_audioSource != null)
        {         {
            this.m_audioSource.Stop();             this.m_audioSource.Stop();
        }         }
    }     }
   
    public bool IsPlaying()     public bool IsPlaying()
    {     {
        return !(this.m_audioSource == null) && this.m_audioSource.isPlaying;         return !(this.m_audioSource == null) && this.m_audioSource.isPlaying;
    }     }
   
    private void UpdateReverb()     private void UpdateReverb()
    {     {
        Camera mainCamera = Utils.GetMainCamera();         Camera mainCamera = Utils.GetMainCamera();
        if (this.m_distanceReverb && this.m_audioSource.spatialBlend != 0f && mainCamera != null)         if (this.m_distanceReverb && this.m_audioSource.spatialBlend != 0f && mainCamera != null)
        {         {
            float num = Vector3.Distance(mainCamera.transform.position, base.transform.position);             float num = Vector3.Distance(mainCamera.transform.position, base.transform.position);
            bool flag = Mister.InsideMister(base.transform.position, 0f);             bool flag = Mister.InsideMister(base.transform.position, 0f);
            float num2 = (this.m_useCustomReverbDistance ? this.m_customReverbDistance : 64f);             float num2 = (this.m_useCustomReverbDistance ? this.m_customReverbDistance : 64f);
            float num3 = Mathf.Clamp01(num / num2);             float num3 = Mathf.Clamp01(num / num2);
            float num4 = Mathf.Clamp01(this.m_audioSource.maxDistance / num2) * Mathf.Clamp01(num / this.m_audioSource.maxDistance);             float num4 = Mathf.Clamp01(this.m_audioSource.maxDistance / num2) * Mathf.Clamp01(num / this.m_audioSource.maxDistance);
            float num5 = Mathf.Max(num3, num4);             float num5 = Mathf.Max(num3, num4);
            if (flag)             if (flag)
            {             {
                num5 = Mathf.Lerp(num5, 0f, num3);                 num5 = Mathf.Lerp(num5, 0f, num3);
.                this.m_audioSource.pitch = this.m_basePitch - this.m_basePitch * 0.5f * num3;                 this.m_reverbPitchModifier = 0.5f * num3;
            }             }
            this.m_audioSource.bypassReverbZones = false;             this.m_audioSource.bypassReverbZones = false;
            this.m_audioSource.reverbZoneMix = num5;             this.m_audioSource.reverbZoneMix = num5;
            if (this.m_baseSpread < 120f)             if (this.m_baseSpread < 120f)
            {             {
                float num6 = Mathf.Max(this.m_baseSpread, 45f);                 float num6 = Mathf.Max(this.m_baseSpread, 45f);
                this.m_audioSource.spread = Mathf.Lerp(num6, 120f, num5);                 this.m_audioSource.spread = Mathf.Lerp(num6, 120f, num5);
                return;                 return;
            }             }
        }         }
        else         else
        {         {
            this.m_audioSource.bypassReverbZones = true;             this.m_audioSource.bypassReverbZones = true;
        }         }
    }     }
   
    public void Play()     public void Play()
    {     {
        if (this.m_audioSource == null)         if (this.m_audioSource == null)
        {         {
            return;             return;
        }         }
        if (this.m_audioClips.Length == 0)         if (this.m_audioClips.Length == 0)
        {         {
            return;             return;
        }         }
        if (!this.m_audioSource.gameObject.activeInHierarchy)         if (!this.m_audioSource.gameObject.activeInHierarchy)
        {         {
            return;             return;
        }         }
.          if (!AudioMan.instance.RequestPlaySound(this))
          {
              return;
          }
          if (this.m_audioSource.loop && this.m_disabledFromConcurrency)
          {
              this.m_concurrencyVolumeModifier = 0f;
          }
        int num = UnityEngine.Random.Range(0, this.m_audioClips.Length);         int num = UnityEngine.Random.Range(0, this.m_audioClips.Length);
        this.m_audioSource.clip = this.m_audioClips[num];         this.m_audioSource.clip = this.m_audioClips[num];
        this.m_audioSource.pitch = UnityEngine.Random.Range(this.m_minPitch, this.m_maxPitch);         this.m_audioSource.pitch = UnityEngine.Random.Range(this.m_minPitch, this.m_maxPitch);
        this.m_basePitch = this.m_audioSource.pitch;         this.m_basePitch = this.m_audioSource.pitch;
        if (this.m_randomPan)         if (this.m_randomPan)
        {         {
            this.m_audioSource.panStereo = UnityEngine.Random.Range(this.m_minPan, this.m_maxPan);             this.m_audioSource.panStereo = UnityEngine.Random.Range(this.m_minPan, this.m_maxPan);
        }         }
        this.m_vol = UnityEngine.Random.Range(this.m_minVol, this.m_maxVol);         this.m_vol = UnityEngine.Random.Range(this.m_minVol, this.m_maxVol);
        if (this.m_fadeInDuration > 0f)         if (this.m_fadeInDuration > 0f)
        {         {
            this.m_audioSource.volume = 0f;             this.m_audioSource.volume = 0f;
            this.m_fadeInTimer = 0f;             this.m_fadeInTimer = 0f;
        }         }
        else         else
        {         {
            this.m_audioSource.volume = this.m_vol;             this.m_audioSource.volume = this.m_vol;
        }         }
        this.UpdateReverb();         this.UpdateReverb();
        this.m_audioSource.Play();         this.m_audioSource.Play();
    }     }
   
.    public static List<ZSFX> Instances { get; } = new List<ZSFX>();      public void GenerateHash() 
      { 
          this.m_hash = Guid.NewGuid().GetHashCode(); 
      } 
   
      public float GetConcurrencyDistance() 
      { 
          if (!this.m_ignoreConcurrencyDistance) 
          { 
              return Mathf.Max(1f, this.m_audioSource.minDistance); 
          } 
          return float.PositiveInfinity; 
      } 
   
      public void ConcurrencyDisable() 
      { 
          this.m_disabledFromConcurrency = true; 
      } 
   
      public void ConcurrencyEnable() 
      { 
          this.m_disabledFromConcurrency = false; 
      } 
   
      public bool IsLooping() 
      { 
          return this.m_audioSource.loop; 
      } 
   
      public void SetVolumeModifier(float v) 
      { 
          this.m_volumeModifier = v; 
      } 
   
      public float GetVolumeModifier() 
      { 
          return this.m_volumeModifier; 
      } 
   
      public void SetPitchModifier(float p) 
      { 
          this.m_pitchModifier = p; 
      } 
   
      public float GetPitchModifier() 
      { 
          return this.m_pitchModifier; 
      } 
   
      public static List<IMonoUpdater> Instances { get; } = new List<IMonoUpdater>(); 
   
    public bool m_playOnAwake = true;     public bool m_playOnAwake = true;
   
    [Header("Clips")]     [Header("Clips")]
    public AudioClip[] m_audioClips = new AudioClip[0];     public AudioClip[] m_audioClips = new AudioClip[0];
   
.      [Header("Audio System")]
      [global::Tooltip("How many of the same sound can play in a small area? Uses the min distance of 3D sounds, or 1 meter, whichever is higher")]
      public int m_maxConcurrentSources;
   
      [global::Tooltip("Ignore the distance check, don't play sound if any other of the same sound were played recently")]
      public bool m_ignoreConcurrencyDistance;
   
    [Header("Random")]     [Header("Random")]
    public float m_maxPitch = 1f;     public float m_maxPitch = 1f;
   
    public float m_minPitch = 1f;     public float m_minPitch = 1f;
   
    public float m_maxVol = 1f;     public float m_maxVol = 1f;
   
    public float m_minVol = 1f;     public float m_minVol = 1f;
   
    [Header("Fade")]     [Header("Fade")]
    public float m_fadeInDuration;     public float m_fadeInDuration;
   
    public float m_fadeOutDuration;     public float m_fadeOutDuration;
   
    public float m_fadeOutDelay;     public float m_fadeOutDelay;
   
    public bool m_fadeOutOnAwake;     public bool m_fadeOutOnAwake;
   
    [Header("Pan")]     [Header("Pan")]
    public bool m_randomPan;     public bool m_randomPan;
   
    public float m_minPan = -1f;     public float m_minPan = -1f;
   
    public float m_maxPan = 1f;     public float m_maxPan = 1f;
   
    [Header("Delay")]     [Header("Delay")]
    public float m_maxDelay;     public float m_maxDelay;
   
    public float m_minDelay;     public float m_minDelay;
   
    [Header("Reverb")]     [Header("Reverb")]
    public bool m_distanceReverb = true;     public bool m_distanceReverb = true;
   
    public bool m_useCustomReverbDistance;     public bool m_useCustomReverbDistance;
   
    public float m_customReverbDistance = 10f;     public float m_customReverbDistance = 10f;
   
.      [HideInInspector]
      public int m_hash;
   
    private const float m_globalReverbDistance = 64f;     private const float m_globalReverbDistance = 64f;
   
    private const float m_minReverbSpread = 45f;     private const float m_minReverbSpread = 45f;
   
    private const float m_maxReverbSpread = 120f;     private const float m_maxReverbSpread = 120f;
   
    private float m_delay;     private float m_delay;
   
    private float m_time;     private float m_time;
   
    private float m_fadeOutTimer = -1f;     private float m_fadeOutTimer = -1f;
   
    private float m_fadeInTimer = -1f;     private float m_fadeInTimer = -1f;
   
    private float m_vol = 1f;     private float m_vol = 1f;
.   
      private float m_concurrencyVolumeModifier = 1f;
   
      private float m_volumeModifier = 1f;
   
      private float m_pitchModifier = 1f;
   
      private float m_reverbPitchModifier;
   
      private bool m_disabledFromConcurrency;
   
    private float m_baseSpread;     private float m_baseSpread;
   
    private float m_basePitch;     private float m_basePitch;
   
    private float m_updateReverbTimer;     private float m_updateReverbTimer;
   
    private AudioSource m_audioSource;     private AudioSource m_audioSource;
} }