Decompiled source of SixSevenClover v1.0.1

SixSevenClover.dll

Decompiled 5 hours ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("SixSevenClover")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SixSevenClover")]
[assembly: AssemblyTitle("SixSevenClover")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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;
		}
	}
}
namespace SixSevenClover
{
	public static class LanguageOverride
	{
		public static void Apply()
		{
			LanguageAPI.Add("ITEM_CLOVER_NAME", "67 Leaf Clover");
			LanguageAPI.Add("ITEM_CLOVER_PICKUP", "Rerolls proc luck. Six. Seven.");
		}
	}
	[BepInPlugin("yourname.sixsevenclover", "SixSevenClover", "1.0.0")]
	public class SixSevenCloverPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "yourname.sixsevenclover";

		public const string PluginName = "SixSevenClover";

		public const string PluginVersion = "1.0.0";

		public static AudioClip LoadedClip;

		public static float Interval = 20f;

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			Log.LogInfo("SixSevenClover loading...");
			LanguageOverride.Apply();
			((MonoBehaviour)this).StartCoroutine(LoadClip());
			CharacterBody.RecalculateStats += new hook_RecalculateStats(CharacterBody_RecalculateStats);
			Log.LogInfo("SixSevenClover loaded.");
		}

		private void OnDestroy()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			CharacterBody.RecalculateStats -= new hook_RecalculateStats(CharacterBody_RecalculateStats);
		}

		private IEnumerator LoadClip()
		{
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Sounds", "brain-rot-67.mp3");
			if (!File.Exists(text))
			{
				Log.LogError("Could not find audio file at " + text + ". Make sure Sounds/brain-rot-67.mp3 sits next to the plugin DLL.");
				yield break;
			}
			UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("file://" + text, (AudioType)13);
			try
			{
				yield return www.SendWebRequest();
				if (www.isNetworkError || www.isHttpError)
				{
					Log.LogError("Failed to load brain-rot-67.mp3: " + www.error);
					yield break;
				}
				LoadedClip = DownloadHandlerAudioClip.GetContent(www);
				((Object)LoadedClip).name = "brain-rot-67";
				Log.LogInfo($"Loaded brain-rot-67.mp3 ({LoadedClip.length:0.00}s)");
			}
			finally
			{
				((IDisposable)www)?.Dispose();
			}
		}

		private void CharacterBody_RecalculateStats(orig_RecalculateStats orig, CharacterBody self)
		{
			orig.Invoke(self);
			if (!((Object)(object)self == (Object)null) && !((Object)(object)self.inventory == (Object)null))
			{
				int itemCount = self.inventory.GetItemCount(Items.Clover);
				SixSevenBehavior component = ((Component)self).GetComponent<SixSevenBehavior>();
				if (itemCount > 0 && (Object)(object)component == (Object)null)
				{
					((Component)self).gameObject.AddComponent<SixSevenBehavior>().interval = Interval;
				}
				else if (itemCount == 0 && (Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
			}
		}
	}
	internal static class Log
	{
		private static ManualLogSource _log;

		internal static void Init(ManualLogSource log)
		{
			_log = log;
		}

		internal static void LogInfo(object data)
		{
			ManualLogSource log = _log;
			if (log != null)
			{
				log.LogInfo(data);
			}
		}

		internal static void LogError(object data)
		{
			ManualLogSource log = _log;
			if (log != null)
			{
				log.LogError(data);
			}
		}
	}
	public class SixSevenBehavior : MonoBehaviour
	{
		public float interval = 20f;

		public float volume = 0.7f;

		private float timer;

		private void FixedUpdate()
		{
			timer += Time.fixedDeltaTime;
			if (!(timer < interval))
			{
				timer = 0f;
				WinAudio.PlayDefault();
			}
		}
	}
	public static class WinAudio
	{
		[DllImport("winmm.dll", CharSet = CharSet.Unicode, EntryPoint = "mciSendStringW", ExactSpelling = true)]
		public static extern int mciSendString(string cmd, StringBuilder ret, int retLen, IntPtr hwnd);

		public static void PlayDefault()
		{
			try
			{
				string text = Path.Combine(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Sounds"), "brain-rot-67.mp3");
				mciSendString("close sixseven", null, 0, IntPtr.Zero);
				mciSendString("open \"" + text + "\" type mpegvideo alias sixseven", null, 0, IntPtr.Zero);
				mciSendString("setaudio sixseven volume to 700", null, 0, IntPtr.Zero);
				mciSendString("play sixseven from 0", null, 0, IntPtr.Zero);
			}
			catch (Exception)
			{
			}
		}
	}
}