Digitalzombie 1 tahun lalu
induk
melakukan
e1bb8c9dd9

+ 1 - 40
AudioMain.cs

@@ -13,17 +13,13 @@ namespace AudioMgr
         ClipManager myClipManager, myClipManager2;
         Shot myPlayerShot;
         string rootPath = Application.dataPath + "/../Mods/";
-        //AssetBundle bundle;
+
         public static bool _debug = false;
 
         public override void OnInitializeMelon() 
 		{
-            ClassInjector.RegisterTypeInIl2Cpp<Shot>();
-            ClassInjector.RegisterTypeInIl2Cpp<Queue>();
-            ClassInjector.RegisterTypeInIl2Cpp<Stream>();
             RadioMaster.Initialize();
             Settings.OnLoad();
-            //bundle = AssetBundle.LoadFromFile(Application.dataPath + "/../Mods/sillysounds.unity3d");
         }
 
         public override void OnSceneWasLoaded(int buildIndex, string sceneName)
@@ -31,32 +27,11 @@ namespace AudioMgr
             if (sceneName.Contains("Boot"))
             {
                 AudioMaster.CreateMasterParent();
-                
-                
-                //myClipManager = new ClipManager();
-                //myClipManager2 = new ClipManager();
-
-                //myClipManager.LoadClipFromFile("start", "start.mp3", ClipManager.LoadType.Decompressed);
-                //myClipManager.LoadClipFromFile("shutdown", "shutdown.mp3", ClipManager.LoadType.Decompressed);
-                //myClipManager.LoadClipFromFile("waterfall", "waterfall.ogg", ClipManager.LoadType.Decompressed);
-
-                //myClipManager2.LoadAllClipsFromBundle(bundle);
-
-
             }
 
             if (sceneName.Contains("Menu"))
             {
                 initialized = true;
-               
-
-               //myPlayerShot = AudioMaster.CreatePlayerShot(AudioMaster.SourceType.SFX);
-
-
-                //PatchMaster.AddReplacePatch("PLAY_CROWCAWSDISTANT", myClipManager, "start", AudioMaster.SourceType.SFX);
-                //PatchMaster.AddReplacePatch("PLAY_SNDMECHDOORWOODCLOSE1", myClipManager, "shutdown", AudioMaster.SourceType.SFX);
-
-              
             }
         }
 
@@ -70,20 +45,6 @@ namespace AudioMgr
 
         public override void OnUpdate()
         {
-            
-            if (InputManager.GetKeyDown(InputManager.m_CurrentContext, KeyCode.Keypad0))
-            {
-                // myPlayerShot.PlayOneshot(myClipManager.GetClip("waterfall"));
-                PatchMaster.AddSkipPatch("PLAY_RANDOMBUILDINGCREAKS1");
-                PatchMaster.AddParameterPatch("WINDGUSTINTENSITY", 0f, PatchMaster.ParameterType.Limitter);
-                PatchMaster.AddParameterPatch("WINDACTUALSPEED", 0f, PatchMaster.ParameterType.Limitter); 
-                PatchMaster.AddParameterPatch("AMBIENTVOLUME", 0f, PatchMaster.ParameterType.Limitter);
-                PatchMaster.AddParameterPatch("GLOBALVOLUME", 0f, PatchMaster.ParameterType.Limitter);
-            }
-            if (InputManager.GetKeyDown(InputManager.m_CurrentContext, KeyCode.L))
-            {
-                //myPlayerShot.PlayOneshot(myClipManager2.GetClip("woo"));
-            }
         }
     }
 }

+ 9 - 6
AudioManager.csproj

@@ -3,7 +3,7 @@
 
     <PropertyGroup>
         <!--This needs to be changed for the mod to compile.-->
-        <TheLongDarkPath>G:\Games\Steam\steamapps\common\TheLongDark</TheLongDarkPath>
+        <TheLongDarkPath>W:/Steam/steamapps/common/TheLongDark</TheLongDarkPath>
     </PropertyGroup>
 
     <PropertyGroup>
@@ -49,16 +49,19 @@
     <!--This is the list of assemblies that the mod references. Most of these are unnecessary for normal mods, but are included here for completeness.-->
     <ItemGroup>
         <Reference Include="Il2CppAk.Wwise.Api.WAAPI">
-          <HintPath>..\..\..\..\Games\Steam\steamapps\common\TheLongDark\MelonLoader\Il2CppAssemblies\Il2CppAk.Wwise.Api.WAAPI.dll</HintPath>
+          <HintPath>W:/Steam/steamapps/common/TheLongDark/MelonLoader/Il2CppAssemblies/Il2CppAk.Wwise.Api.WAAPI.dll</HintPath>
         </Reference>
         <Reference Include="Il2CppAK.Wwise.Unity.API">
-          <HintPath>..\..\..\..\Games\Steam\steamapps\common\TheLongDark\MelonLoader\Il2CppAssemblies\Il2CppAK.Wwise.Unity.API.dll</HintPath>
+          <HintPath>W:/Steam/steamapps/common/TheLongDark/MelonLoader/Il2CppAssemblies/Il2CppAK.Wwise.Unity.API.dll</HintPath>
         </Reference>
         <Reference Include="Il2CppAK.Wwise.Unity.API.WwiseTypes">
-          <HintPath>..\..\..\..\Games\Steam\steamapps\common\TheLongDark\MelonLoader\Il2CppAssemblies\Il2CppAK.Wwise.Unity.API.WwiseTypes.dll</HintPath>
+          <HintPath>W:/Steam/steamapps/common/TheLongDark/MelonLoader/Il2CppAssemblies/Il2CppAK.Wwise.Unity.API.WwiseTypes.dll</HintPath>
         </Reference>
         <Reference Include="Il2CppAK.Wwise.Unity.MonoBehaviour">
-          <HintPath>..\..\..\..\Games\Steam\steamapps\common\TheLongDark\MelonLoader\Il2CppAssemblies\Il2CppAK.Wwise.Unity.MonoBehaviour.dll</HintPath>
+          <HintPath>W:/Steam/steamapps/common/TheLongDark/MelonLoader/Il2CppAssemblies/Il2CppAK.Wwise.Unity.MonoBehaviour.dll</HintPath>
+        </Reference>
+        <Reference Include="Il2CppTLD.SaveState">
+          <HintPath>..\..\..\..\Steam\steamapps\common\TheLongDark\MelonLoader\Il2CppAssemblies\Il2CppTLD.SaveState.dll</HintPath>
         </Reference>
         <Reference Include="MelonLoader" />
         <Reference Include="0Harmony" />
@@ -73,7 +76,7 @@
         <Reference Include="Il2CppSystem.Data" />
         <Reference Include="Il2CppSystem" />
         <Reference Include="ModSettings">
-          <HintPath>..\..\..\..\Games\Steam\steamapps\common\TheLongDark\Mods\ModSettings.dll</HintPath>
+          <HintPath>W:/Steam/steamapps/common/TheLongDark\Mods\ModSettings.dll</HintPath>
         </Reference>
         <Reference Include="UnityEngine.AnimationModule" />
         <Reference Include="UnityEngine.AssetBundleModule" />

+ 15 - 7
Components/Queue.cs

@@ -5,6 +5,7 @@ using UnityEngine;
 
 namespace AudioMgr
 {
+    [RegisterTypeInIl2Cpp]
     public class Queue : MonoBehaviour
     {
         public Queue(IntPtr intPtr) : base(intPtr)
@@ -95,16 +96,16 @@ namespace AudioMgr
             if (_playState == PlayState.Stopped)
             {
                 _playState = PlayState.Playing;
-                _audioSource.clip = _assignedClipManager.GetClipAtIndex(_activeClip).audioClip;
-                _audioSource.PlayDelayed(0.6f);
+                //_audioSource.clip = _assignedClipManager.GetClipAtIndex(_activeClip).audioClip;
+                GetNextClip();
+                _audioSource.PlayDelayed(0.5f);
             }
             else if (_playState == PlayState.Paused)
             {
                 UnPause();
             }
             else if(_playState == PlayState.Playing)
-            {                
-  
+            {                  
                 Clip nextClip = GetNextClip();
 
                 if(_audioSource.clip != nextClip.audioClip)
@@ -179,13 +180,20 @@ namespace AudioMgr
             }
             else if (_loop == Loop.Randomize)
             {
-                int randomIndex = _activeClip;
+                int randomIndex = 0;
 
-                if(_assignedClipManager.clipCount != 1)
+                if(_assignedClipManager.clipCount > 1)
                 {
-                    while (_activeClip == randomIndex)
+                    bool gotRand = false;                  
+
+                    while (!gotRand)
                     {
                         randomIndex = UnityEngine.Random.Range(0, _assignedClipManager.clipCount);
+
+                        if(randomIndex != _activeClip)
+                        {
+                            gotRand = true;
+                        }
                     }
                 }               
 

+ 1 - 0
Components/Shot.cs

@@ -7,6 +7,7 @@ using UnityEngine.Playables;
 
 namespace AudioMgr
 {
+    [RegisterTypeInIl2Cpp]
     public class Shot : MonoBehaviour
     {
         public Shot(IntPtr intPtr) : base(intPtr)

+ 1 - 0
Components/Stream.cs

@@ -7,6 +7,7 @@ using UnityEngine.Networking;
 
 namespace AudioMgr
 {
+    [RegisterTypeInIl2Cpp]
     public class Stream : MonoBehaviour
     {
         public Stream(IntPtr intPtr) : base(intPtr)

+ 6 - 0
Harmony/AudioSimplePatches.cs

@@ -26,6 +26,12 @@ namespace AudioMgr
                 return false;
             }
 
+            /*if (__instance.m_Event.Name.Contains("Play_MainMenuSurvivalMode_PanelMainMenu"))
+            {
+                MelonLogger.Msg("MainMenuSurvivalMode_PanelMainMenu");
+                return false;
+            }*/
+
             if (PatchMaster.PatchAction(__instance.name, __instance.gameObject))
             {
                 return false;

+ 8 - 1
Harmony/AuroraPatches.cs

@@ -35,7 +35,14 @@ namespace AudioMgr
         }
     }
 
-   
+    [HarmonyLib.HarmonyPatch(typeof(AuroraManager), "AuroraAudioSetIntensityRTPC")]
+    public class TempAuroraMusicPatch
+    {
+        public static bool Prefix(ref AuroraManager __instance)
+        {          
+            return false;
+        }
+    }
 
     /*
     [HarmonyLib.HarmonyPatch(typeof(AuroraActivatedToggle), "Update")]

+ 6 - 10
Harmony/RTPCPatches.cs

@@ -14,12 +14,7 @@ namespace AudioMgr
             if (AudioMain._debug)
                 MelonLogger.Msg("RTPC " + GameParameterIDs.GetString(rtpcID) + "; " + rtpcValue);
 
-
-            if (go == null)
-            {
-                return;
-            }
-
+                       
    
             // Aurora music patch
             if (Settings.options.enableAuroraTweaks && GameParameterIDs.GetString(rtpcID) == "AURORASTRENGTH") 
@@ -34,15 +29,16 @@ namespace AudioMgr
             if (Settings.options.enableWindTweaks && GameManager.GetWeatherComponent().IsIndoorScene() && (GameParameterIDs.GetString(rtpcID) == "WINDINTENSITYBLEND"))
             {            
                 if (rtpcValue > Settings.options.windVolume)
-                {
-               
+                {               
                     rtpcValue = Settings.options.windVolume;
+
+                    if (AudioMain._debug)
+                        MelonLogger.Msg("Wind Volume Overwrite " + GameParameterIDs.GetString(rtpcID) + "; " + rtpcValue);
                 }
             }
 
             if (VolumeIDs.GetRtpcIDMaster() == rtpcID)
-            {
-        
+            {        
                 VolumeMaster.SetMasterVolume(rtpcValue / 100);
 
             }

+ 5 - 0
Manager/ClipManager.cs

@@ -81,6 +81,11 @@ namespace AudioMgr
                     clipNameSplit = singleName.Split('/');
                     tmpClipName = clipNameSplit[clipNameSplit.Length-1];
 
+                    if(AudioMain._debug)
+                    {
+                        MelonLogger.Msg("Importing clip to clipmanager: " + FileNameCutter(tmpClipName));
+                    }
+
                     if (!_loadedClips.ContainsKey(tmpClipName))
                     {
                         LoadClipFromBundle(FileNameCutter(tmpClipName), singleName, assetBundle);

+ 1 - 0
Master/AudioMaster.cs

@@ -23,6 +23,7 @@ namespace AudioMgr
             if (GameManager.GetMainCamera() != null)
             {
                 _masterParent.transform.position = GameManager.GetVpFPSCamera().gameObject.transform.position;
+                _masterParent.transform.rotation = GameManager.GetVpFPSCamera().gameObject.transform.rotation;
             }
         }
 

+ 14 - 1
Master/PatchMaster.cs

@@ -1,5 +1,6 @@
 using Harmony;
 using Il2Cpp;
+using Il2CppAK.Wwise;
 using MelonLoader;
 using UnityEngine;
 
@@ -43,17 +44,29 @@ namespace AudioMgr
         {
             if (_parameterPatches.ContainsKey(parameterID))
             {
+                if (AudioMain._debug)
+                    MelonLogger.Msg("ParameterAction in Action now " + parameterID + "; " + originalValue);
+
                 if (_parameterPatches[parameterID] == ParameterType.Absolute)
                 {
+                    if (AudioMain._debug)
+                        MelonLogger.Msg("Limit to " + _parameterPatches[parameterID]);
+
                     return _parameterValues[parameterID];
                 }
                 else if(_parameterPatches[parameterID] == ParameterType.Percentage)
                 {
+                    if (AudioMain._debug)
+                        MelonLogger.Msg("Limit to " + _parameterPatches[parameterID]);
+
                     return (originalValue / 100) * _parameterValues[parameterID];
                 }
                 else if (_parameterPatches[parameterID] == ParameterType.Limitter)
                 {
-                    if(originalValue > _parameterValues[parameterID])
+                    if (AudioMain._debug)
+                        MelonLogger.Msg("Limit to " + _parameterValues[parameterID]);
+
+                    if (originalValue > _parameterValues[parameterID])
                     {
                         return _parameterValues[parameterID];
                     }

+ 73 - 0
PlayAndFade.cs

@@ -0,0 +1,73 @@
+using MelonLoader;
+using Il2CppInterop.Runtime.Injection;
+using Il2Cpp;
+using UnityEngine;
+using UnityEngine.Rendering;
+using Il2CppInterop.Runtime.Attributes;
+using System.Collections;
+
+
+namespace AudioMgr
+{
+    public class PlayAndFade
+	{
+        Shot _assignedShot;
+        Clip _assignedClip;
+        double _fadeDuration;
+        double _clipDuration;
+        double _startTime;
+        double _stopTime;
+        double _timeElapsed;
+        float _startVolume;
+
+        object _timerLoop;
+        bool _isPlaying;
+
+        public PlayAndFade(Shot targetShot, Clip audioClip, double fadeDuration)
+        {
+            _assignedShot = targetShot;
+            _assignedClip = audioClip;
+            _fadeDuration = fadeDuration;
+            
+            _startTime = AudioSettings.dspTime + 0.5;
+
+            _assignedShot.AssignClip(_assignedClip);
+            _assignedShot._audioSource.PlayScheduled(_startTime);
+            _clipDuration = _assignedClip.clipLength;
+            _startVolume = _assignedShot._audioSource.volume;
+            _stopTime = _startTime + _clipDuration - _fadeDuration;
+
+            _isPlaying = true;
+
+            _timerLoop = MelonCoroutines.Start(TimerLoop());
+        }
+
+        [HideFromIl2Cpp]
+        private IEnumerator TimerLoop()
+        {           
+            float time = 0;
+
+            while (_isPlaying)
+            {
+                _timeElapsed = AudioSettings.dspTime - _startTime;
+
+                if (_timeElapsed < _stopTime)
+                {
+                    yield return null;
+                }
+                else if (_timeElapsed > _stopTime)
+                {
+                    _assignedShot._audioSource.volume = Mathf.Lerp(_startVolume, 0, time / (float)_fadeDuration);
+                    time += Time.deltaTime;
+                }
+
+                if(_assignedShot._audioSource.volume <= 0)
+                {
+                    _assignedShot.Stop();
+                    _isPlaying = false;
+                }
+            }
+            yield return null;
+        }
+    }
+}

+ 3 - 3
Properties/AssemblyInfo.cs

@@ -4,7 +4,7 @@ using AudioMgr;
 
 [assembly: AssemblyTitle("AudioManager")]
 [assembly: AssemblyCopyright("Digitalzombie")]
-[assembly: AssemblyVersion("1.3.8")]
-[assembly: AssemblyFileVersion("1.3.8")]
-[assembly: MelonInfo(typeof(AudioMain), "AudioManager", "1.3.8", "Digitalzombie", null)]
+[assembly: AssemblyVersion("1.5.1")]
+[assembly: AssemblyFileVersion("1.5.1")]
+[assembly: MelonInfo(typeof(AudioMain), "AudioManager", "1.5.1", "Digitalzombie", null)]
 [assembly: MelonGame("Hinterland", "TheLongDark")]