Decompiled source of RiskOfRaveRevival v1.0.0

plugins/RiskOfRaveRevival.dll

Decompiled 24 minutes ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using RoR2;
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("RiskOfRaveRevival")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RiskOfRaveRevival")]
[assembly: AssemblyTitle("RiskOfRaveRevival")]
[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;
		}
	}
}
[BepInPlugin("local.riskofraverevival", "RiskOfRave Revival", "0.1.5")]
public sealed class RiskOfRaveRevival : BaseUnityPlugin
{
	private const uint AsyncLoopFile = 131083u;

	private string audioPath;

	private bool opened;

	private bool playing;

	private bool test;

	private bool keyDown;

	private bool wasCharging;

	private bool attempted;

	private Light raveLight;

	private ConfigEntry<bool> lights;

	[DllImport("winmm.dll", CharSet = CharSet.Unicode, EntryPoint = "PlaySoundW")]
	[return: MarshalAs(UnmanagedType.Bool)]
	private static extern bool PlaySound(string sound, IntPtr module, uint flags);

	[DllImport("user32.dll")]
	private static extern short GetAsyncKeyState(int key);

	private void Awake()
	{
		lights = ((BaseUnityPlugin)this).Config.Bind<bool>("Visuals", "RainbowLight", true, (ConfigDescription)null);
		audioPath = Path.Combine(Path.GetDirectoryName(typeof(RiskOfRaveRevival).Assembly.Location), "Caramelldansen.wav");
		opened = File.Exists(audioPath);
		((BaseUnityPlugin)this).Logger.LogInfo((object)("PCM WAV path: " + audioPath + "; exists: " + opened + "; F8 toggles audio test during a run."));
		if (!opened)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"WAV missing");
		}
	}

	private void Update()
	{
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Expected O, but got Unknown
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		_ = 119;
		bool flag = (0 & 0x8000) != 0;
		bool flag2 = (Object)(object)Run.instance != (Object)null;
		if (flag && !keyDown && flag2)
		{
			test = !test;
			attempted = false;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("F8 test: " + test));
		}
		keyDown = flag;
		if (!flag2)
		{
			test = false;
		}
		TeleporterInteraction instance = TeleporterInteraction.instance;
		bool flag3 = flag2 && (Object)(object)instance != (Object)null && instance.isCharging;
		if (flag3 != wasCharging)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Teleporter charging: " + flag3));
			attempted = false;
			wasCharging = flag3;
		}
		if (!flag3 && !test)
		{
			StopRave();
			attempted = false;
			return;
		}
		if (opened && !playing && !attempted)
		{
			attempted = true;
			playing = PlaySound(audioPath, IntPtr.Zero, 131083u);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("PlaySound WAV started: " + playing));
			if (!playing)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Windows PlaySound could not start PCM WAV.");
			}
		}
		if (lights.Value && flag3 && (Object)(object)instance != (Object)null)
		{
			if ((Object)(object)raveLight == (Object)null)
			{
				GameObject val = new GameObject("RaveLight");
				val.transform.SetParent(((Component)instance).transform, false);
				val.transform.localPosition = Vector3.up * 5f;
				raveLight = val.AddComponent<Light>();
				raveLight.type = (LightType)2;
				raveLight.range = 35f;
				raveLight.intensity = 2f;
			}
			raveLight.color = Color.HSVToRGB(Mathf.Repeat(Time.time * 0.18f, 1f), 0.9f, 1f);
		}
		else if ((Object)(object)raveLight != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)raveLight).gameObject);
		}
	}

	private void StopRave()
	{
		if (playing)
		{
			PlaySound(null, IntPtr.Zero, 0u);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Playback stopped");
		}
		playing = false;
		if ((Object)(object)raveLight != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)raveLight).gameObject);
		}
	}

	private void OnDisable()
	{
		StopRave();
		wasCharging = false;
		test = false;
		attempted = false;
	}

	private void OnDestroy()
	{
		StopRave();
	}
}