From 1a809d5a62aaec84f6b7ec6725ff1ac3a2cb57ef Mon Sep 17 00:00:00 2001 From: arion <53127594+Arion-Kun@users.noreply.github.com> Date: Thu, 11 Mar 2021 02:12:09 +0200 Subject: [PATCH] Add files via upload --- AssemblyInfo.cs | 2 +- Core.cs | 15 ++++++++++++--- MicSensitivity.cs | 22 ++++++++++------------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs index 96e79df..b56c066 100644 --- a/AssemblyInfo.cs +++ b/AssemblyInfo.cs @@ -12,7 +12,7 @@ internal static class AssemblyInfo { internal const string Name = "MicSensitivity"; - internal const string Version = "1.4.2"; + internal const string Version = "1.4.3"; internal const string Description = ""; diff --git a/Core.cs b/Core.cs index 806aa93..122efbd 100644 --- a/Core.cs +++ b/Core.cs @@ -56,7 +56,15 @@ internal static float userVolumePeak } } } - internal static bool isInstantiated => CurrentUser != null && IsInWorld && uInstance != null; + + internal static bool isInstantiated + { + get + { + if (CurrentUser == null || !IsInWorld) return false; + return uInstance != null; // Im guessing having it complete the check above ^ first, prevents uInstance from throwing a null ref at the CurrentUser level and checks if uspeaker is present. + } + } internal static IEnumerator WorldJoinedCoroutine() { for (;;) @@ -67,7 +75,8 @@ internal static IEnumerator WorldJoinedCoroutine() { yield return new WaitForSeconds(1); { - SensitivitySetup(); + if (!UseMod) yield break; + userVolumeThreshold = SensitivityValue; userVolumePeak = SensitivityValue * 2; } sw.Stop(); yield break; @@ -78,7 +87,7 @@ internal static IEnumerator WorldJoinedCoroutine() MelonLogger.Warning("WorldJoinedCoroutine took too long and was stopped."); yield break; } - yield return new WaitForSeconds(1); + yield return new WaitForSeconds(1); // IEnumerator Speed Control } } private static Il2CppSystem.Object FindInstance(Type WhereLooking, Type WhatLooking) // Credits to Teo diff --git a/MicSensitivity.cs b/MicSensitivity.cs index 4eea60d..ab4fec5 100644 --- a/MicSensitivity.cs +++ b/MicSensitivity.cs @@ -31,25 +31,23 @@ public override void OnSceneWasLoaded(int buildIndex, string sceneName) // World public override void OnPreferencesSaved() { InternalConfigRefresh(); - SensitivitySetup(); - if (UseMod) return; - userVolumeThreshold = DefaultPeak; //Defaulted if Mod is not used. - userVolumePeak = DefaultThreshold; //Defaulted if Mod is not used. + if (UseMod && isInstantiated) + { + userVolumeThreshold = SensitivityValue; userVolumePeak = SensitivityValue * 2; + } + else if (!UseMod && isInstantiated) // This is most likely due to the need to update to 1.4.3, People who don't use the Mod get a null ref if another mod calls the method. + { + userVolumeThreshold = DefaultPeak; //Defaulted if Mod is not used. + userVolumePeak = DefaultThreshold; //Defaulted if Mod is not used. + } } #endregion #region The Actual Mod - internal static bool UseMod; + internal static bool UseMod = false; internal static float SensitivityValue = 0; private const float DefaultThreshold = 0.01f; private const float DefaultPeak = 0.02f; - - internal static void SensitivitySetup() - { - if (!UseMod) return; - if (!isInstantiated) return; - userVolumeThreshold = SensitivityValue; userVolumePeak = SensitivityValue * 2; - } #endregion } } \ No newline at end of file