Decompiled source of NextTrackOnNewStage v1.0.0

NextTrackOnNewStage.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2.UI;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NextTrackOnNewStage")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2e707d1093ff56bedd51a749bf4bc0a3c1a60466")]
[assembly: AssemblyProduct("NextTrackOnNewStage")]
[assembly: AssemblyTitle("NextTrackOnNewStage")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace NextTrackOnNewStage
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("bouncyshield.NextTrackOnNewStage", "NextTrackOnNewStage", "1.0.0")]
	public class NextTrackOnNewStage : BaseUnityPlugin
	{
		public const string PluginGUID = "bouncyshield.NextTrackOnNewStage";

		public const string PluginAuthor = "bouncyshield";

		public const string PluginName = "NextTrackOnNewStage";

		public const string PluginVersion = "1.0.0";

		public static ConfigFile config;

		private const byte VK_MEDIA_NEXT_TRACK = 176;

		private const byte VK_MEDIA_PLAY_PAUSE = 179;

		public static bool nextTrackOnNewStage = true;

		public static bool ignoreShortStages = true;

		public static bool pauseOnPause = true;

		private readonly string[] shortStages = new string[2] { "bazaar", "mysteryspace" };

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			config = ((BaseUnityPlugin)this).Config;
			Options.Init();
			RoR2Application.onLoadFinished = (Action)Delegate.Combine(RoR2Application.onLoadFinished, new Action(poop));
			Hooks();
		}

		private void poop()
		{
			Options.OnLoadFinished();
		}

		private void Hooks()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			Stage.onStageStartGlobal += meow;
			PauseScreenController.OnEnable += new hook_OnEnable(paws);
			PauseScreenController.OnDisable += new hook_OnDisable(unpaws);
		}

		private void paws()
		{
			throw new NotImplementedException();
		}

		[DllImport("user32.dll")]
		private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		private void meow(Stage stage)
		{
			if (!(stage.sceneDef.baseSceneName == "outro") && (!shortStages.Contains(stage.sceneDef.baseSceneName) || !ignoreShortStages) && nextTrackOnNewStage)
			{
				keybd_event(176, 0, 0, 0);
				Log.Debug("VK_MEDIA_NEXT_TRACK");
			}
		}

		private void unpaws(orig_OnDisable orig, PauseScreenController self)
		{
			orig.Invoke(self);
			if (pauseOnPause)
			{
				keybd_event(179, 0, 0, 0);
				Log.Debug("VK_MEDIA_PLAY_PAUSE");
			}
		}

		private void paws(orig_OnEnable orig, PauseScreenController self)
		{
			orig.Invoke(self);
			if (pauseOnPause)
			{
				keybd_event(179, 0, 0, 0);
				Log.Debug("VK_MEDIA_PLAY_PAUSE");
			}
		}
	}
	public class Options
	{
		private static bool? _rooEnabled;

		public static bool rooEnabled
		{
			get
			{
				if (!_rooEnabled.HasValue)
				{
					_rooEnabled = Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");
				}
				return _rooEnabled.Value;
			}
		}

		public static ConfigEntry<bool> nextTrackOnNewStage { get; set; }

		public static ConfigEntry<bool> ignoreShortStages { get; set; }

		public static ConfigEntry<bool> pauseOnPause { get; set; }

		private static void OnSettingsChanged()
		{
			NextTrackOnNewStage.nextTrackOnNewStage = nextTrackOnNewStage.Value;
			NextTrackOnNewStage.ignoreShortStages = ignoreShortStages.Value;
			NextTrackOnNewStage.pauseOnPause = pauseOnPause.Value;
		}

		public static void Init()
		{
			nextTrackOnNewStage = NextTrackOnNewStage.config.Bind<bool>("音楽", "Next Track On New Stage", true, "The mod will attempt to skip to the next media track at the start of a new stage.");
			nextTrackOnNewStage.SettingChanged += delegate
			{
				OnSettingsChanged();
			};
			ignoreShortStages = NextTrackOnNewStage.config.Bind<bool>("音楽", "Ignore Short Stages", true, "The mod will not attempt to skip to the next media track at the start of a \"short\" stage, e.g. the Bazaar.");
			ignoreShortStages.SettingChanged += delegate
			{
				OnSettingsChanged();
			};
			pauseOnPause = NextTrackOnNewStage.config.Bind<bool>("音楽", "Pause Media On Pause Game", true, "The mod will attempt to pause the current media track while the game is paused.");
			pauseOnPause.SettingChanged += delegate
			{
				OnSettingsChanged();
			};
			if (rooEnabled)
			{
				RoOInit();
			}
		}

		public static void OnLoadFinished()
		{
			OnSettingsChanged();
		}

		private static void RoOInit()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(nextTrackOnNewStage, new CheckBoxConfig()));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ignoreShortStages, new CheckBoxConfig()));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(pauseOnPause, new CheckBoxConfig()));
			ModSettingsManager.SetModDescription("Config options for the NextTrackOnNewStage mod.");
		}
	}
}