DigitalzombieTLD 2 년 전
부모
커밋
e0f93189d0
11개의 변경된 파일449개의 추가작업 그리고 177개의 파일을 삭제
  1. 4 4
      AudioMain.cs
  2. 1 1
      AudioManagerSettings.cs
  3. 124 132
      Components/Queue.cs
  4. 4 1
      Components/Shot.cs
  5. 223 0
      Components/Stream.cs
  6. 25 28
      Harmony/AuroraPatches.cs
  7. 2 1
      Manager/ClipManager.cs
  8. 16 2
      Master/AudioMaster.cs
  9. 40 5
      Master/RadioMaster.cs
  10. 4 3
      Properties/AssemblyInfo.cs
  11. 6 0
      README.md

+ 4 - 4
AudioMain.cs

@@ -20,7 +20,8 @@ namespace AudioMgr
 		{
 		{
             ClassInjector.RegisterTypeInIl2Cpp<Shot>();
             ClassInjector.RegisterTypeInIl2Cpp<Shot>();
             ClassInjector.RegisterTypeInIl2Cpp<Queue>();
             ClassInjector.RegisterTypeInIl2Cpp<Queue>();
-
+            ClassInjector.RegisterTypeInIl2Cpp<Stream>();
+            RadioMaster.Initialize();
             AudioMgr.Settings.OnLoad();
             AudioMgr.Settings.OnLoad();
             //bundle = AssetBundle.LoadFromFile(Application.dataPath + "/../Mods/sillysounds.unity3d");
             //bundle = AssetBundle.LoadFromFile(Application.dataPath + "/../Mods/sillysounds.unity3d");
         }
         }
@@ -30,7 +31,7 @@ namespace AudioMgr
             if (sceneName.Contains("Boot"))
             if (sceneName.Contains("Boot"))
             {
             {
                 AudioMaster.CreateMasterParent();
                 AudioMaster.CreateMasterParent();
-                RadioMaster.Initialize();
+                
                 
                 
                 //myClipManager = new ClipManager();
                 //myClipManager = new ClipManager();
                 //myClipManager2 = new ClipManager();
                 //myClipManager2 = new ClipManager();
@@ -83,7 +84,6 @@ namespace AudioMgr
             {
             {
                 //myPlayerShot.PlayOneshot(myClipManager2.GetClip("woo"));
                 //myPlayerShot.PlayOneshot(myClipManager2.GetClip("woo"));
             }
             }
-
-            }
         }
         }
+    }
 }
 }

+ 1 - 1
AudioManagerSettings.cs

@@ -41,7 +41,7 @@ namespace AudioMgr
         [Name("Radio Volume")]
         [Name("Radio Volume")]
         [Description("Left: Silent / Right: Maximum Volume")]
         [Description("Left: Silent / Right: Maximum Volume")]
         [Slider(0, 1)]
         [Slider(0, 1)]
-        public float customRadioVolume = 1;
+        public float customRadioVolume = 0.3f;
 
 
         [Section("Wind Audio Indoor (clattering)")]
         [Section("Wind Audio Indoor (clattering)")]
 
 

+ 124 - 132
Components/Queue.cs

@@ -11,9 +11,8 @@ namespace AudioMgr
         {
         {
         }
         }
 
 
-        private Dictionary<bool, AudioSource> _audioSources;
-        private bool _toggleAudioSource = true;
-
+        private AudioSource _audioSource;
+        
         private Setting _activeSetting;
         private Setting _activeSetting;
         private AudioMaster.SourceType _sourceType;
         private AudioMaster.SourceType _sourceType;
 
 
@@ -23,9 +22,9 @@ namespace AudioMgr
         private float _upperRandomGap = 2;
         private float _upperRandomGap = 2;
         private bool _randomGap = false;
         private bool _randomGap = false;
 
 
-        private int _currentClipIndex = 0;
-
-        private object _timerLoop;
+        private int _activeClip = 0;
+        private bool _isSetup = false;
+        private float _silenceTimer = 0f;
 
 
         public enum Loop { None, Single, All, Randomize };
         public enum Loop { None, Single, All, Randomize };
         private Loop _loop = Loop.All;
         private Loop _loop = Loop.All;
@@ -41,19 +40,15 @@ namespace AudioMgr
             _sourceType = sourceType;
             _sourceType = sourceType;
             _timeGap = timeGap;
             _timeGap = timeGap;
             _loop = loopType;
             _loop = loopType;
-            _audioSources = new Dictionary<bool, AudioSource>();
-            _audioSources.Add(true, gameObject.AddComponent<AudioSource>());
-            _audioSources.Add(false, gameObject.AddComponent<AudioSource>());
-         
-            _audioSources[true].playOnAwake = false;
-            _audioSources[false].playOnAwake = false;
 
 
-            _audioSources[true].volume = VolumeMaster.GetVolume(sourceType);
-            _audioSources[false].volume = VolumeMaster.GetVolume(sourceType);
+            _audioSource = gameObject.AddComponent<AudioSource>();
+            _audioSource.playOnAwake = false;
+            _audioSource.volume = VolumeMaster.GetVolume(sourceType);
 
 
             VolumeMaster.onVolumeChange += ResetVolume;
             VolumeMaster.onVolumeChange += ResetVolume;
 
 
             ApplySettings(SettingMaster.Defaults(sourceType));
             ApplySettings(SettingMaster.Defaults(sourceType));
+            _isSetup = true;
         }
         }
 
 
         [HideFromIl2Cpp]
         [HideFromIl2Cpp]
@@ -63,57 +58,17 @@ namespace AudioMgr
             _timeGap = timeGap;
             _timeGap = timeGap;
             _loop = loopType;
             _loop = loopType;
             _sourceType = AudioMaster.SourceType.Custom;
             _sourceType = AudioMaster.SourceType.Custom;
-            _audioSources = new Dictionary<bool, AudioSource>();
-            _audioSources.Add(true, gameObject.AddComponent<AudioSource>());
-            _audioSources.Add(false, gameObject.AddComponent<AudioSource>());
-
-            _audioSources[true].playOnAwake = false;
-            _audioSources[false].playOnAwake = false;
-
-            _audioSources[true].volume = VolumeMaster.GetVolume(_sourceType);
-            _audioSources[false].volume = VolumeMaster.GetVolume(_sourceType);
+            _audioSource = gameObject.AddComponent<AudioSource>();
+            _audioSource.playOnAwake = false;
+            _audioSource.volume = VolumeMaster.GetVolume(sourceType);
 
 
             VolumeMaster.onVolumeChange += ResetVolume;
             VolumeMaster.onVolumeChange += ResetVolume;
 
 
             ApplySettings(sourceSetting);
             ApplySettings(sourceSetting);
+            _isSetup = true;
         }
         }
 
 
-        [HideFromIl2Cpp]
-        public int GetNextClip()
-        {
-            if (_loop == Loop.Single) // Keep current clip
-            {
-                return _currentClipIndex;
-            }
-            else if (_loop == Loop.Randomize)
-            {
-                int randomIndex = _currentClipIndex;
-
-                while (randomIndex == _currentClipIndex)
-                {
-                    randomIndex = UnityEngine.Random.Range(0, _assignedClipManager.clipCount - 1);
-                }
-
-                return randomIndex;
-            }
-            else if (_currentClipIndex < _assignedClipManager.clipCount - 1) // Not at the end yet, increase by 1
-            {
-                return _currentClipIndex + 1;
-            }
-            else if (_currentClipIndex >= _assignedClipManager.clipCount - 1)
-            {
-                if (_loop == Loop.All)
-                {
-                    return 0;
-                }
-                else
-                {
-                    return -1;
-                }
-            }
-
-            return -1;
-        }
+       
 
 
         [HideFromIl2Cpp]
         [HideFromIl2Cpp]
         public void SetRandomTimeGap(float lowestTimeGap, float highestTimeGap)
         public void SetRandomTimeGap(float lowestTimeGap, float highestTimeGap)
@@ -132,84 +87,129 @@ namespace AudioMgr
         [HideFromIl2Cpp]
         [HideFromIl2Cpp]
         public void Play()
         public void Play()
         {
         {
-            if (_playState == PlayState.Stopped && _assignedClipManager.clipCount > 0)
+            if(_assignedClipManager.clipCount == 0 || _isSetup == false)
+            {
+                return;
+            }
+
+            if (_playState == PlayState.Stopped)
             {
             {
                 _playState = PlayState.Playing;
                 _playState = PlayState.Playing;
-                _timerLoop = MelonCoroutines.Start(TimerLoop());
+                _audioSource.clip = _assignedClipManager.GetClipAtIndex(_activeClip).audioClip;
+                _audioSource.PlayDelayed(0.6f);
             }
             }
             else if (_playState == PlayState.Paused)
             else if (_playState == PlayState.Paused)
             {
             {
-                AudioListener.pause = false;
-                _playState = PlayState.Playing;
+                UnPause();
+            }
+            else if(_playState == PlayState.Playing)
+            {                
+  
+                Clip nextClip = GetNextClip();
+
+                if(_audioSource.clip != nextClip.audioClip)
+                {
+                    _audioSource.clip = nextClip.audioClip;
+                }
+
+                if (_playState == PlayState.Playing)
+                {
+                    _audioSource.PlayDelayed(0.5f + _timeGap);
+                }                
+            }
+        }
+
+        public void Update()
+        {
+            if (_playState == PlayState.Playing)
+            {
+                _silenceTimer += Time.deltaTime;
+
+                if (_silenceTimer >= 1f)
+                {
+                    if (!_audioSource.isPlaying)
+                    {
+                        Play();
+                    }
+                    _silenceTimer = 0f;
+                }
             }
             }
         }
         }
 
 
         [HideFromIl2Cpp]
         [HideFromIl2Cpp]
         public void Stop()
         public void Stop()
         {
         {
-            if (_timerLoop != null)
-            {
-                MelonCoroutines.Stop(_timerLoop);
+            if (_playState == PlayState.Playing)
+            {                
                 _playState = PlayState.Stopped;
                 _playState = PlayState.Stopped;
-                _audioSources[true].Stop();
-                _audioSources[false].Stop();
+                _audioSource.Stop();
             }
             }
         }
         }
 
 
-
         [HideFromIl2Cpp]
         [HideFromIl2Cpp]
-        private IEnumerator TimerLoop()
+        public void UnPause()
         {
         {
-            double _startTime;
-            double _timeToNext = 0;
-            int _nextClip = 0;
-
-            _startTime = AudioSettings.dspTime + 0.5;
-
-            if (_randomGap)
+            if (_playState == PlayState.Paused)
             {
             {
-                _timeGap = UnityEngine.Random.Range(_lowerRandomGap, _upperRandomGap);
+                _playState = PlayState.Playing;
+                _audioSource.UnPause();
             }
             }
+        }
 
 
-            _audioSources[_toggleAudioSource].clip = _assignedClipManager.GetClipAtIndex(_currentClipIndex).audioClip;
-            _audioSources[_toggleAudioSource].PlayScheduled(_startTime + _timeGap);
-
-            _timeToNext = _startTime;
-
-            while (true)
+        [HideFromIl2Cpp]
+        public void Pause()
+        {
+            if (_playState == PlayState.Playing)
             {
             {
-                if (_playState == PlayState.Playing)
-                {                    
-                    // Assign new clip                
-                    _nextClip = GetNextClip();
+                _playState = PlayState.Paused;
+                _audioSource.Pause();
+            }
+        }
 
 
-                    if (_nextClip < 0)
-                    {
-                        yield break;
-                    }
+        [HideFromIl2Cpp]
+        public Clip GetNextClip()
+        {
+            if (_loop == Loop.None) // Keep current clip
+            {                
+                Stop();
+            }
+            else if (_loop == Loop.Single) // Keep current clip
+            {
+                _activeClip = _activeClip; // duh
+            }
+            else if (_loop == Loop.Randomize)
+            {
+                int randomIndex = _activeClip;
 
 
-                    if(_randomGap)
+                if(_assignedClipManager.clipCount != 1)
+                {
+                    while (_activeClip == randomIndex)
                     {
                     {
-                        _timeGap = UnityEngine.Random.Range(_lowerRandomGap, _upperRandomGap);
+                        randomIndex = UnityEngine.Random.Range(0, _assignedClipManager.clipCount);
                     }
                     }
+                }               
 
 
-                    _toggleAudioSource = !_toggleAudioSource;
-
-                    _timeToNext = _timeToNext + _assignedClipManager.GetClipAtIndex(_currentClipIndex).clipLength + _timeGap;
-
-                    _audioSources[_toggleAudioSource].clip = _assignedClipManager.GetClipAtIndex(_nextClip).audioClip;
-                    _audioSources[_toggleAudioSource].PlayScheduled(_timeToNext);
-
-                    while (AudioSettings.dspTime < _timeToNext + 0.05)
-                    {
-                        yield return null;
-                    }                
-                    _currentClipIndex = _nextClip;
+                _activeClip = randomIndex;              
+            }
+            else if (_loop == Loop.All) // _loop == Loop.All
+            {
+                if (_activeClip < _assignedClipManager.clipCount - 1) // Not at the end yet, increase by 1
+                {
+                    _activeClip++;
                 }
                 }
-                yield return null;
-            }            
-        }
+                else if (_activeClip >= _assignedClipManager.clipCount - 1)
+                {                    
+                    _activeClip = 0;                 
+                }
+            }
 
 
+            if (_randomGap)
+            {
+                _timeGap = UnityEngine.Random.Range(_lowerRandomGap, _upperRandomGap);          
+            }
+            return _assignedClipManager.GetClipAtIndex(_activeClip);
+        }
+        
         [HideFromIl2Cpp]
         [HideFromIl2Cpp]
         public void AssignClipManager(ClipManager assignedClipManager, float timeGap, Loop loopType)
         public void AssignClipManager(ClipManager assignedClipManager, float timeGap, Loop loopType)
         {
         {
@@ -217,7 +217,7 @@ namespace AudioMgr
             _assignedClipManager = assignedClipManager;
             _assignedClipManager = assignedClipManager;
             _timeGap = timeGap;
             _timeGap = timeGap;
             _loop = loopType;
             _loop = loopType;
-            _currentClipIndex = 0;
+            _activeClip = 0;
         }
         }
        
        
         [HideFromIl2Cpp]
         [HideFromIl2Cpp]
@@ -241,38 +241,30 @@ namespace AudioMgr
         [HideFromIl2Cpp]
         [HideFromIl2Cpp]
         private void ResetVolume()
         private void ResetVolume()
         {
         {
-            if(_sourceType != AudioMaster.SourceType.Custom)
+            if(_audioSource &&  _sourceType != AudioMaster.SourceType.Custom)
             {
             {
-                _audioSources[_toggleAudioSource].volume = VolumeMaster.GetVolume(_sourceType);
-                _audioSources[!_toggleAudioSource].volume = VolumeMaster.GetVolume(_sourceType);
+                _audioSource.volume = VolumeMaster.GetVolume(_sourceType);
             }            
             }            
         }
         }
 
 
         [HideFromIl2Cpp]
         [HideFromIl2Cpp]
         public void ApplySettings(Setting newSetting)
         public void ApplySettings(Setting newSetting)
-        {
-            ApplySettingsToSingle(newSetting, true);
-            ApplySettingsToSingle(newSetting, false);
-        }
-
-        [HideFromIl2Cpp]
-        private void ApplySettingsToSingle(Setting newSetting, bool audioSource)
         {
         {
             _activeSetting = newSetting;
             _activeSetting = newSetting;
 
 
             _sourceType = _activeSetting.sourceType;
             _sourceType = _activeSetting.sourceType;
-            _audioSources[audioSource].spread = _activeSetting.spread;
-            _audioSources[audioSource].panStereo = _activeSetting.panStereo;
-            _audioSources[audioSource].dopplerLevel = _activeSetting.dopplerLevel;
-            _audioSources[audioSource].maxDistance = _activeSetting.maxDistance;
-            _audioSources[audioSource].minDistance = _activeSetting.minDistance;
-            _audioSources[audioSource].pitch = _activeSetting.pitch;
-            _audioSources[audioSource].spatialBlend = _activeSetting.spatialBlend;
-            _audioSources[audioSource].spatialize = _activeSetting.spatialize;
-            _audioSources[audioSource].rolloffFactor = _activeSetting.rolloffFactor;
-            _audioSources[audioSource].maxVolume = _activeSetting.maxVolume;
-            _audioSources[audioSource].maxVolume = _activeSetting.minVolume;
-            _audioSources[audioSource].rolloffMode = _activeSetting.rolloffMode;
+            _audioSource.spread = _activeSetting.spread;
+            _audioSource.panStereo = _activeSetting.panStereo;
+            _audioSource.dopplerLevel = _activeSetting.dopplerLevel;
+            _audioSource.maxDistance = _activeSetting.maxDistance;
+            _audioSource.minDistance = _activeSetting.minDistance;
+            _audioSource.pitch = _activeSetting.pitch;
+            _audioSource.spatialBlend = _activeSetting.spatialBlend;
+            _audioSource.spatialize = _activeSetting.spatialize;
+            _audioSource.rolloffFactor = _activeSetting.rolloffFactor;
+            _audioSource.maxVolume = _activeSetting.maxVolume;
+            _audioSource.maxVolume = _activeSetting.minVolume;
+            _audioSource.rolloffMode = _activeSetting.rolloffMode;
             //_audioSources[audioSource].SetCustomCurve(AudioSourceCurveType.CustomRolloff, _activeSetting.rollOffCurve);
             //_audioSources[audioSource].SetCustomCurve(AudioSourceCurveType.CustomRolloff, _activeSetting.rollOffCurve);
 
 
             ResetVolume();
             ResetVolume();

+ 4 - 1
Components/Shot.cs

@@ -122,7 +122,10 @@ namespace AudioMgr
         [HideFromIl2Cpp]
         [HideFromIl2Cpp]
         public void ResetVolume()
         public void ResetVolume()
         {
         {
-            _audioSource.volume = VolumeMaster.GetVolume(_sourceType);
+            if (_audioSource)
+            {
+                _audioSource.volume = VolumeMaster.GetVolume(_sourceType);
+            }
         }
         }
 
 
         [HideFromIl2Cpp]
         [HideFromIl2Cpp]

+ 223 - 0
Components/Stream.cs

@@ -0,0 +1,223 @@
+using Il2Cpp;
+using Il2CppInterop.Runtime.Attributes;
+using MelonLoader;
+using System.Collections;
+using UnityEngine;
+using UnityEngine.Networking;
+
+namespace AudioMgr
+{
+    public class Stream : MonoBehaviour
+    {
+        public Stream(IntPtr intPtr) : base(intPtr)
+        {
+        }
+
+        private AudioSource _audioSource;
+        
+        private Setting _activeSetting;
+        private AudioMaster.SourceType _sourceType;
+        private bool _isSetup;
+        private string _streamURL;
+        //private AudioClip _streamClip = null;
+        private UnityWebRequest _www;
+
+        public enum PlayState { Stopped, Playing };
+        private PlayState _playState = PlayState.Stopped;
+
+
+        [HideFromIl2Cpp]
+        public void Setup(string streamURL, AudioMaster.SourceType sourceType)
+        {
+            _streamURL = streamURL;
+            _sourceType = sourceType;
+          
+            _audioSource = gameObject.AddComponent<AudioSource>();
+            _audioSource.playOnAwake = false;
+            _audioSource.volume = VolumeMaster.GetVolume(sourceType);
+
+            VolumeMaster.onVolumeChange += ResetVolume;
+
+            ApplySettings(SettingMaster.Defaults(sourceType));
+            _isSetup = true;
+        }
+
+        [HideFromIl2Cpp]
+        public void Setup(string streamURL, Setting sourceSetting)
+        {
+            _streamURL = streamURL;
+            _sourceType = sourceType;
+            
+            _sourceType = AudioMaster.SourceType.Custom;
+            _audioSource = gameObject.AddComponent<AudioSource>();
+            _audioSource.playOnAwake = false;
+            _audioSource.volume = VolumeMaster.GetVolume(sourceType);
+
+            VolumeMaster.onVolumeChange += ResetVolume;
+
+            ApplySettings(sourceSetting);
+            _isSetup = true;
+        }
+
+        
+        private IEnumerator PlayAudioRoutine()
+        {
+            /*
+            UnityWebRequest www;
+            WWW foowww = new WWW(_streamURL);
+            www = UnityWebRequest.Get(_streamURL);
+            www.SendWebRequest();
+
+            MelonLogger.Msg("start ruotig ");
+
+        
+
+            if (!www.isNetworkError && !www.isHttpError)
+            {
+                MelonLogger.Msg("now create");
+               
+                
+               _audioSource.clip = WebRequestWWW.InternalCreateAudioClipUsingDH(www.downloadHandler, www.url, true, true, AudioType.UNKNOWN);
+
+                yield return new WaitForSeconds(10f);
+
+                MelonLogger.Msg("now play ");
+                _audioSource.PlayDelayed(1f);
+                _playState = PlayState.Playing;
+            }
+            else
+            {
+                _playState = PlayState.Stopped;
+                MelonLogger.Msg("Error while loading audioclip. Skipping " + www.error);
+            }
+                      
+            while (_playState == PlayState.Playing)
+            {
+                MelonLogger.Msg("in while ");
+                yield return null;
+            }
+
+            MelonLogger.Msg("now stop ");
+            Stop();
+            
+            */
+            yield return null;
+        }
+        
+
+       
+
+        [HideFromIl2Cpp]
+        public void Play()
+        {          
+            if (_playState == PlayState.Stopped && _isSetup == true)
+            {
+                _playState = PlayState.Playing;
+                MelonCoroutines.Start(PlayAudioRoutine());             
+
+            }
+        }
+
+
+        [HideFromIl2Cpp]
+        public void Stop()
+        {
+            _playState = PlayState.Stopped;
+            _audioSource.Stop();
+
+            _www?.Dispose();
+
+         
+        }
+        
+
+        [HideFromIl2Cpp]
+        private void OnEnable()
+        {
+            VolumeMaster.onVolumeChange += ResetVolume;         
+        }
+
+        [HideFromIl2Cpp]
+        private void OnDisable()
+        {
+            VolumeMaster.onVolumeChange -= ResetVolume;
+        }
+
+        [HideFromIl2Cpp]
+        private void OnDestroy()
+        {
+            VolumeMaster.onVolumeChange -= ResetVolume;
+        }
+
+        [HideFromIl2Cpp]
+        private void ResetVolume()
+        {
+            if(_sourceType != AudioMaster.SourceType.Custom)
+            {
+                _audioSource.volume = VolumeMaster.GetVolume(_sourceType);
+            }            
+        }
+
+        [HideFromIl2Cpp]
+        public void ApplySettings(Setting newSetting)
+        {
+            _activeSetting = newSetting;
+
+            _sourceType = _activeSetting.sourceType;
+            _audioSource.spread = _activeSetting.spread;
+            _audioSource.panStereo = _activeSetting.panStereo;
+            _audioSource.dopplerLevel = _activeSetting.dopplerLevel;
+            _audioSource.maxDistance = _activeSetting.maxDistance;
+            _audioSource.minDistance = _activeSetting.minDistance;
+            _audioSource.pitch = _activeSetting.pitch;
+            _audioSource.spatialBlend = _activeSetting.spatialBlend;
+            _audioSource.spatialize = _activeSetting.spatialize;
+            _audioSource.rolloffFactor = _activeSetting.rolloffFactor;
+            _audioSource.maxVolume = _activeSetting.maxVolume;
+            _audioSource.maxVolume = _activeSetting.minVolume;
+            _audioSource.rolloffMode = _activeSetting.rolloffMode;
+            //_audioSources[audioSource].SetCustomCurve(AudioSourceCurveType.CustomRolloff, _activeSetting.rollOffCurve);
+
+            ResetVolume();
+        }
+
+      
+
+        [HideFromIl2Cpp]
+        public PlayState playState
+        {
+            get
+            {
+                return _playState;
+            }
+        }
+
+        [HideFromIl2Cpp]
+        public AudioMaster.SourceType sourceType
+        {
+            get
+            {
+                return _sourceType;
+            }
+            set
+            {
+                _sourceType = value;
+                ApplySettings(SettingMaster.Defaults(_sourceType));
+            }
+        }
+
+        [HideFromIl2Cpp]
+        public string streamURL
+        {
+            get
+            {
+                return _streamURL;
+            }
+            set
+            {
+                _streamURL = value;              
+            }
+        }
+
+    }
+}

+ 25 - 28
Harmony/AuroraPatches.cs

@@ -8,40 +8,36 @@ namespace AudioMgr
     [HarmonyLib.HarmonyPatch(typeof(AuroraActivatedToggle), "SetState", new Type[] { typeof(AuroraActivatedToggleState) })]
     [HarmonyLib.HarmonyPatch(typeof(AuroraActivatedToggle), "SetState", new Type[] { typeof(AuroraActivatedToggleState) })]
     public class TurnOnPatch
     public class TurnOnPatch
     {
     {
-        public static void Prefix(ref AuroraActivatedToggle __instance, ref AuroraActivatedToggleState state)
-        {           
-            if (Settings.options.customRadioMusic)
+        public static bool Prefix(ref AuroraActivatedToggle __instance, ref AuroraActivatedToggleState state)
+        {            
+            if (Settings.options.customRadioMusic && RadioMaster.auroraClipManager.clipCount > 0)
             {
             {
-                if (__instance.m_ToggleOffAudio == "Stop_RadioAurora" && state == AuroraActivatedToggleState.On)
+                if (state == AuroraActivatedToggleState.On)
                 {
                 {
-                    if (Settings.options.radioWorksWithoutAurora)
-                    {
-                        __instance.m_RequiresAuroraField = false;
-                       
-                        for (int i = 0; i < __instance.transform.childCount; i++)
-                        {
-                            __instance.transform.GetChild(i).gameObject.SetActive(true);
-                        }
-                        __instance.m_ChildrenEnabled = true;
-                        //__instance.UpdateChildStatus(true);
-
-                        MelonLogger.Msg("StartPlay");
-                        RadioMaster.StartPlay(__instance.gameObject);
-                    }
-                }
+                    if (GameManager.GetAuroraManager().AuroraIsActive() || (!GameManager.GetAuroraManager().AuroraIsActive() && Settings.options.radioWorksWithoutAurora))
+                    {                     
+                        
+                        RadioMaster.StartQueue(__instance.gameObject);
+                        __instance.m_ToggleState = state;
+                        return false;
+                    }                    
+                }              
+            }
 
 
-                if (__instance.m_ToggleOffAudio == "Stop_RadioAurora" && state == AuroraActivatedToggleState.Off)
-                {
-                    if (Settings.options.radioWorksWithoutAurora)
-                    {
-                        MelonLogger.Msg("StopPlay");
-                        RadioMaster.StopPlay(__instance.gameObject);
-                    }
-                }
+            if (state == AuroraActivatedToggleState.Off)
+            {
+                RadioMaster.StopQueue(__instance.gameObject);
+                __instance.m_ToggleState = state;
+                return true;
             }
             }
+
+            return true;
         }
         }
     }
     }
 
 
+   
+
+    /*
     [HarmonyLib.HarmonyPatch(typeof(AuroraActivatedToggle), "Update")]
     [HarmonyLib.HarmonyPatch(typeof(AuroraActivatedToggle), "Update")]
     public class LightingPatch
     public class LightingPatch
     {
     {
@@ -62,11 +58,12 @@ namespace AudioMgr
     {
     {
         public static void Postfix(ref AuroraActivatedToggle __instance, ref bool __result)
         public static void Postfix(ref AuroraActivatedToggle __instance, ref bool __result)
         {
         {
-            if (Settings.options.customRadioMusic && Settings.options.radioWorksWithoutAurora)
+            if (Settings.options.customRadioMusic && Settings.options.radioWorksWithoutAurora && RadioMaster.auroraClipManager.clipCount > 0)
             {
             {
                 __result = true;
                 __result = true;
             }           
             }           
         }
         }
     }
     }
+    */
 
 
 }
 }

+ 2 - 1
Manager/ClipManager.cs

@@ -151,7 +151,8 @@ namespace AudioMgr
 
 
             if (!www.isNetworkError && !www.isHttpError)
             if (!www.isNetworkError && !www.isHttpError)
             {
             {
-                _loadedClips[clipName] = new Clip(WebRequestWWW.InternalCreateAudioClipUsingDH(www.downloadHandler, www.url, stream, compressed, AudioType.UNKNOWN), clipName);                    
+                _loadedClips[clipName] = new Clip(WebRequestWWW.InternalCreateAudioClipUsingDH(www.downloadHandler, www.url, stream, compressed, AudioType.UNKNOWN), clipName);
+                    MelonLogger.Msg("single clip loaaaded");
             }
             }
             else
             else
             {
             {

+ 16 - 2
Master/AudioMaster.cs

@@ -50,7 +50,6 @@ namespace AudioMgr
 
 
 
 
 
 
-
         public static ClipManager NewClipManager()
         public static ClipManager NewClipManager()
         {
         {
             ClipManager newManager = new ClipManager();
             ClipManager newManager = new ClipManager();
@@ -58,7 +57,22 @@ namespace AudioMgr
             return newManager;
             return newManager;
         }
         }
 
 
-  
+        public static Stream CreateStream(GameObject targetObject, string streamURL, SourceType sourceType)
+        {
+            Stream newAudioSource = targetObject.AddComponent<Stream>();
+            newAudioSource.Setup(streamURL, sourceType);
+
+            return newAudioSource;
+        }
+
+        public static Stream CreateStream(GameObject targetObject, string streamURL, Setting sourceSetting)
+        {
+            Stream newAudioSource = targetObject.AddComponent<Stream>();
+            newAudioSource.Setup(streamURL, sourceSetting);
+
+            return newAudioSource;
+        }
+
         public static Shot CreateShot(GameObject targetObject, SourceType sourceType)
         public static Shot CreateShot(GameObject targetObject, SourceType sourceType)
         {
         {
             Shot newAudioSource = targetObject.AddComponent<Shot>();
             Shot newAudioSource = targetObject.AddComponent<Shot>();

+ 40 - 5
Master/RadioMaster.cs

@@ -1,4 +1,5 @@
-using UnityEngine;
+using MelonLoader;
+using UnityEngine;
 using static Il2Cpp.BaseAi;
 using static Il2Cpp.BaseAi;
 
 
 namespace AudioMgr
 namespace AudioMgr
@@ -7,9 +8,16 @@ namespace AudioMgr
     {
     {
         public static string musicPath = @"file:///" + Application.dataPath + @"/../Mods/AuroraRadio";
         public static string musicPath = @"file:///" + Application.dataPath + @"/../Mods/AuroraRadio";
         public static ClipManager auroraClipManager;
         public static ClipManager auroraClipManager;
+        //public static bool foundFiles = false;
 
 
         public static void Initialize()
         public static void Initialize()
         {
         {
+            if (!Directory.Exists(Application.dataPath + "/../Mods/AuroraRadio"))
+            {
+                Directory.CreateDirectory(Application.dataPath + "/../Mods/AuroraRadio");
+                
+            }
+
             auroraClipManager = new ClipManager();
             auroraClipManager = new ClipManager();
 
 
             auroraClipManager.LoadClipsFromDir("AuroraRadio", ClipManager.LoadType.Stream);
             auroraClipManager.LoadClipsFromDir("AuroraRadio", ClipManager.LoadType.Stream);
@@ -34,17 +42,44 @@ namespace AudioMgr
             return radioQueue;
             return radioQueue;
         }
         }
 
 
-        public static void StartPlay(GameObject radioObject)
+        private static Stream GetOrAddStreamToRadio(GameObject radioObject, string streamURL)
+        {
+            Stream radioStream = radioObject.GetComponent<Stream>();
+
+            if (radioStream == null)
+            {
+                radioStream = AudioMaster.CreateStream(radioObject, streamURL, AudioMaster.SourceType.AuroraRadio);
+            }
+
+            radioStream.streamURL = streamURL;
+
+            return radioStream;
+        }
+        public static void StartStream(GameObject radioObject, string streamURL)
+        {
+            Stream radioStream = GetOrAddStreamToRadio(radioObject, streamURL);
+            radioStream.Play();
+        }
+        public static void StopStream(GameObject radioObject)
+        {
+            Stream radioStream = radioObject.GetComponent<Stream>();
+
+            if (radioStream != null)
+            {
+                radioStream.Stop();
+            }
+        }
+
+        public static void StartQueue(GameObject radioObject)
         {
         {
             if (auroraClipManager.clipCount > 0)
             if (auroraClipManager.clipCount > 0)
             {
             {
-                Queue radioQueue = GetOrAddQueueToRadio(radioObject);
-                radioQueue.GetNextClip();
+                Queue radioQueue = GetOrAddQueueToRadio(radioObject);              
                 radioQueue.Play();
                 radioQueue.Play();
             }
             }
         }
         }
 
 
-        public static void StopPlay(GameObject radioObject)
+        public static void StopQueue(GameObject radioObject)
         {
         {
             if (auroraClipManager.clipCount > 0)
             if (auroraClipManager.clipCount > 0)
             {
             {

+ 4 - 3
Properties/AssemblyInfo.cs

@@ -1,9 +1,10 @@
 using MelonLoader;
 using MelonLoader;
 using System.Reflection;
 using System.Reflection;
+using AudioMgr;
 
 
 [assembly: AssemblyTitle("AudioManager")]
 [assembly: AssemblyTitle("AudioManager")]
 [assembly: AssemblyCopyright("Digitalzombie")]
 [assembly: AssemblyCopyright("Digitalzombie")]
-[assembly: AssemblyVersion("1.1.0")]
-[assembly: AssemblyFileVersion("1.1.0")]
-[assembly: MelonInfo(typeof(AudioMgr.AudioMain), "AudioManager", "1.1.0", "Digitalzombie", null)]
+[assembly: AssemblyVersion("1.3.3")]
+[assembly: AssemblyFileVersion("1.3.3")]
+[assembly: MelonInfo(typeof(AudioMain), "AudioManager", "1.3.3", "Digitalzombie", null)]
 [assembly: MelonGame("Hinterland", "TheLongDark")]
 [assembly: MelonGame("Hinterland", "TheLongDark")]

+ 6 - 0
README.md

@@ -2,6 +2,12 @@
 # AudioManager
 # AudioManager
 Audio helper mod for The Long Dark. Uses Unitys native audio engine to enable easier usage of custom audio in mods.
 Audio helper mod for The Long Dark. Uses Unitys native audio engine to enable easier usage of custom audio in mods.
 
 
+### New: v1.3.3!
+- Custom music on the radio when the aurora is active ... or not:
+Put your mp3 and/or ogg files into the \Mods\AuroraRadio folder and check out the modsettings
+- Bugfixes! ... a lot of bugfixes ... 
+
+
 ### New: v1.0! Now includes features for players:
 ### New: v1.0! Now includes features for players:
 - Disable flare audio (no more hisssssss)
 - Disable flare audio (no more hisssssss)
 - Disable waterfall audio (ears stop bleeding)
 - Disable waterfall audio (ears stop bleeding)