Skip to content

Commit

Permalink
fix potential nullref when harmony patches are run
Browse files Browse the repository at this point in the history
  • Loading branch information
GalaxyMaster2 committed Jan 1, 2023
1 parent d6a9fd4 commit 80db1b3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
if (code[i].opcode == OpCodes.Callvirt && (MethodInfo)code[i].operand == AccessTools.PropertyGetter(typeof(List<NoteCutSoundEffect>), "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;
}
}
Expand Down
6 changes: 3 additions & 3 deletions HitsoundTweaks/HitsoundTweaksController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// <summary>
Expand All @@ -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)
{
Expand All @@ -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)
Expand Down

0 comments on commit 80db1b3

Please sign in to comment.