Decompiled source of BugleHero v0.1.0

plugins/com.github.bwinner.BugleGuide.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.bwinner.BugleGuide")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("com.github.bwinner.BugleGuide")]
[assembly: AssemblyTitle("BugleHero")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[BepInPlugin("com.yourname.buglehero", "Bugle Hero", "1.1.0")]
public class BugleHero : BaseUnityPlugin
{
	private const int BASE_MIDI_NOTE = 60;

	private const float PITCH_MIN = 0.7f;

	private const float PITCH_MAX = 1.3f;

	private const float SMOOTH_TIME = 0.08f;

	private float smoothedPitch01;

	private float pitchVelocity;

	private Rect overlayRect;

	private Texture2D? whiteTex;

	private BugleSFX? activeBugle;

	private static readonly string[] NoteNames = new string[12]
	{
		"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A",
		"A#", "B"
	};

	private void Awake()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		overlayRect = new Rect(30f, (float)Screen.height / 2f - 100f, 180f, 200f);
		whiteTex = Texture2D.whiteTexture;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Bugle Hero loaded \ud83c\udfba");
	}

	private void Update()
	{
		((Rect)(ref overlayRect)).y = (float)Screen.height / 2f - ((Rect)(ref overlayRect)).height / 2f;
		activeBugle = FindActiveBugle();
		if (!((Object)(object)activeBugle == (Object)null) && activeBugle.hold)
		{
			float buglePitch = GetBuglePitch01();
			smoothedPitch01 = Mathf.SmoothDamp(smoothedPitch01, buglePitch, ref pitchVelocity, 0.08f);
		}
	}

	private BugleSFX FindActiveBugle()
	{
		if ((Object)(object)activeBugle != (Object)null)
		{
			return activeBugle;
		}
		BugleSFX[] array = Object.FindObjectsOfType<BugleSFX>();
		BugleSFX[] array2 = array;
		foreach (BugleSFX val in array2)
		{
			if (((Behaviour)val).isActiveAndEnabled)
			{
				return val;
			}
		}
		return null;
	}

	private float GetBuglePitch01()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		Camera main = Camera.main;
		if (!Object.op_Implicit((Object)(object)main))
		{
			return 0.5f;
		}
		Vector3 forward = ((Component)main).transform.forward;
		Vector3 normalized = ((Vector3)(ref forward)).normalized;
		float num = Vector3.Dot(normalized, Vector3.up);
		return Mathf.Clamp01((num + 1f) / 2f);
	}

	private float GetAudioPitch(float pitch01)
	{
		pitch01 = Mathf.Clamp(pitch01, 0.01f, 0.99f);
		return Mathf.Lerp(0.7f, 1.3f, pitch01);
	}

	private float AudioPitchToMidi(float audioPitch)
	{
		return 60f + 12f * Mathf.Log(audioPitch, 2f);
	}

	private void OnGUI()
	{
		if (!((Object)(object)activeBugle == (Object)null) && activeBugle.hold)
		{
			DrawOverlay();
		}
	}

	private void DrawOverlay()
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Expected O, but got Unknown
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Expected O, but got Unknown
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		float audioPitch = GetAudioPitch(smoothedPitch01);
		float num = AudioPitchToMidi(audioPitch);
		int num2 = Mathf.RoundToInt(num);
		float num3 = (num - (float)num2) * 100f;
		string arg = NoteNames[num2 % 12];
		int num4 = num2 / 12 - 1;
		bool flag = Mathf.Abs(num3) <= 5f;
		GUI.Box(overlayRect, "");
		GUIStyle val = new GUIStyle(GUI.skin.label)
		{
			fontSize = 28,
			alignment = (TextAnchor)4
		};
		val.normal.textColor = Color.white;
		GUIStyle val2 = val;
		GUI.Label(new Rect(((Rect)(ref overlayRect)).x, ((Rect)(ref overlayRect)).y + 10f, ((Rect)(ref overlayRect)).width, 40f), $"{arg}{num4}", val2);
		GUIStyle val3 = new GUIStyle(GUI.skin.label)
		{
			fontSize = 16,
			alignment = (TextAnchor)4
		};
		val3.normal.textColor = (flag ? Color.green : Color.gray);
		GUIStyle val4 = val3;
		GUI.Label(new Rect(((Rect)(ref overlayRect)).x, ((Rect)(ref overlayRect)).y + 50f, ((Rect)(ref overlayRect)).width, 25f), $"{num3:+0;-0;0}¢", val4);
		float num5 = ((Rect)(ref overlayRect)).y + 85f;
		float num6 = 90f;
		GUI.color = new Color(1f, 1f, 1f, 0.25f);
		GUI.DrawTexture(new Rect(((Rect)(ref overlayRect)).x + ((Rect)(ref overlayRect)).width / 2f - 2f, num5, 4f, num6), (Texture)(object)whiteTex);
		float num7 = num5 + (1f - smoothedPitch01) * num6;
		GUI.color = (flag ? Color.green : Color.red);
		GUI.DrawTexture(new Rect(((Rect)(ref overlayRect)).x + 20f, num7 - 2f, ((Rect)(ref overlayRect)).width - 40f, 4f), (Texture)(object)whiteTex);
		GUI.color = Color.white;
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}