From 80db1b3dd284db971625d3cc607ff31002d18c43 Mon Sep 17 00:00:00 2001 From: GalaxyMaster2 <10052298+GalaxyMaster2@users.noreply.github.com> Date: Sun, 1 Jan 2023 01:36:06 +0100 Subject: [PATCH] fix potential nullref when harmony patches are run --- ...teCutSoundEffectManager_Max_Active_SoundEffects_Patch.cs | 2 +- HitsoundTweaks/HitsoundTweaksController.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/HitsoundTweaks/HarmonyPatches/NoteCutSoundEffectManager_Max_Active_SoundEffects_Patch.cs b/HitsoundTweaks/HarmonyPatches/NoteCutSoundEffectManager_Max_Active_SoundEffects_Patch.cs index 5659003..c4fd693 100644 --- a/HitsoundTweaks/HarmonyPatches/NoteCutSoundEffectManager_Max_Active_SoundEffects_Patch.cs +++ b/HitsoundTweaks/HarmonyPatches/NoteCutSoundEffectManager_Max_Active_SoundEffects_Patch.cs @@ -25,7 +25,7 @@ static IEnumerable Transpiler(IEnumerable inst if (code[i].opcode == OpCodes.Callvirt && (MethodInfo)code[i].operand == AccessTools.PropertyGetter(typeof(List), "Count")) { // subtract 8 to give some overhead, don't go below base game value of 64 - code[i + 1].operand = Mathf.Max(HitsoundTweaksController.Instance.NumVirtualVoices - 8, 64); + code[i + 1].operand = Mathf.Max(HitsoundTweaksController.CurrentNumVirtualVoices - 8, 64); break; } } diff --git a/HitsoundTweaks/HitsoundTweaksController.cs b/HitsoundTweaks/HitsoundTweaksController.cs index 8bab045..ea0b6c7 100644 --- a/HitsoundTweaks/HitsoundTweaksController.cs +++ b/HitsoundTweaks/HitsoundTweaksController.cs @@ -13,7 +13,7 @@ public class HitsoundTweaksController : MonoBehaviour { public static HitsoundTweaksController Instance { get; private set; } - public int NumVirtualVoices = 32; + public static int CurrentNumVirtualVoices = 32; #region Monobehaviour Messages /// @@ -39,7 +39,7 @@ private void Awake() Plugin.Log?.Info($"Attempting to set number of real voices to {config.numRealVoices}"); AudioSettings.Reset(config); var newConfig = AudioSettings.GetConfiguration(); - NumVirtualVoices = newConfig.numVirtualVoices; + CurrentNumVirtualVoices = newConfig.numVirtualVoices; if (newConfig.numVirtualVoices == config.numVirtualVoices) { @@ -48,7 +48,7 @@ private void Awake() else { Plugin.Log?.Warn($"Failed to set number of virtual voices to the desired value"); - Plugin.Log?.Info($"Number of virtual voices is currently: {NumVirtualVoices}"); + Plugin.Log?.Info($"Number of virtual voices is currently: {CurrentNumVirtualVoices}"); } if (newConfig.numRealVoices == config.numRealVoices)