Decompiled source of NowWatchThisDrive v0.2.0

NowWatchThisDrive.dll

Decompiled 6 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using FMOD;
using FMODUnity;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[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("NowWatchThisDrive")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NowWatchThisDrive")]
[assembly: AssemblyTitle("NowWatchThisDrive")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 NowWatchThisDrive
{
	[BepInPlugin("sbg.nowwatchthisdrive", "NowWatchThisDrive", "0.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(CourseManager), "PlayAnnouncerLineLocalOnly")]
		internal static class Patch_CourseManager_PlayAnnouncerLineLocalOnly
		{
			private static bool Prefix(AnnouncerLine line)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Invalid comparison between Unknown and I4
				if ((int)line != 5)
				{
					return true;
				}
				if (!_soundReady)
				{
					return true;
				}
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogInfo((object)"Intercepting NiceShot -> NowWatchThisDrive (FMOD)");
				}
				PlayOverride();
				return false;
			}
		}

		public const string ModGuid = "sbg.nowwatchthisdrive";

		public const string ModName = "NowWatchThisDrive";

		public const string ModVersion = "0.2.0";

		private const string AudioFileName = "NowWatchThisDrive.wav";

		internal static ManualLogSource Log;

		private static Sound _sound;

		private static bool _soundReady;

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			new Harmony("sbg.nowwatchthisdrive").PatchAll();
			Log.LogInfo((object)"NowWatchThisDrive v0.2.0 loaded (sound loads in Start).");
		}

		private void Start()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "NowWatchThisDrive.wav");
				if (!File.Exists(text))
				{
					Log.LogError((object)("Audio file missing: " + text));
					return;
				}
				System coreSystem = RuntimeManager.CoreSystem;
				RESULT val = ((System)(ref coreSystem)).createSound(text, (MODE)256, ref _sound);
				if ((int)val != 0)
				{
					Log.LogError((object)$"FMOD createSound failed: {val}");
					return;
				}
				uint num = default(uint);
				((Sound)(ref _sound)).getLength(ref num, (TIMEUNIT)1);
				_soundReady = true;
				Log.LogInfo((object)$"FMOD sound loaded: {text} ({num} ms)");
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Start failed: {arg}");
			}
		}

		internal static void PlayOverride()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (!_soundReady)
			{
				return;
			}
			try
			{
				System coreSystem = RuntimeManager.CoreSystem;
				ChannelGroup val = default(ChannelGroup);
				RESULT masterChannelGroup = ((System)(ref coreSystem)).getMasterChannelGroup(ref val);
				if ((int)masterChannelGroup != 0)
				{
					Log.LogWarning((object)$"getMasterChannelGroup: {masterChannelGroup}");
					return;
				}
				Channel val2 = default(Channel);
				RESULT val3 = ((System)(ref coreSystem)).playSound(_sound, val, false, ref val2);
				if ((int)val3 != 0)
				{
					Log.LogWarning((object)$"playSound: {val3}");
				}
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"PlayOverride failed: {arg}");
			}
		}
	}
}