Decompiled source of HalloweenAction v1.0.0

HalloweenAction.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;

[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("HalloweenAction")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Restores the spooky action ambience")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HalloweenAction")]
[assembly: AssemblyTitle("HalloweenAction")]
[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 HalloweenAction
{
	[BepInPlugin("butterystancakes.lethalcompany.halloweenaction", "Halloween Action", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string PLUGIN_GUID = "butterystancakes.lethalcompany.halloweenaction";

		private const string PLUGIN_NAME = "Halloween Action";

		private const string PLUGIN_VERSION = "1.0.0";

		internal static ManualLogSource Logger;

		internal static ConfigEntry<float> configChance;

		internal static ConfigEntry<float> configEclipseChance;

		private void Awake()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			AcceptableValueRange<float> val = new AcceptableValueRange<float>(0f, 1f);
			string text = " (0 = never, 1 = guaranteed, or anything in between - 0.5 = 50% chance)";
			configChance = ((BaseUnityPlugin)this).Config.Bind<float>("Random", "Chance", 1f, new ConfigDescription("The percentage chance for the Halloween ambience to replace the original." + text, (AcceptableValueBase)(object)val, Array.Empty<object>()));
			configEclipseChance = ((BaseUnityPlugin)this).Config.Bind<float>("Random", "EclipseChance", 1f, new ConfigDescription("The percentage chance for the Halloween ambience to replace the original during Eclipsed weather." + text, (AcceptableValueBase)(object)val, Array.Empty<object>()));
			try
			{
				AssetBundle obj = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "halloweenaction"));
				HalloweenActionPatches.lowActionHW = obj.LoadAsset<AudioClip>("LowActionHalloween");
				HalloweenActionPatches.highActionHW = obj.LoadAsset<AudioClip>("HighAction2Halloween");
				obj.Unload(false);
			}
			catch
			{
				Logger.LogError((object)"Encountered some error loading asset bundle. Did you install the plugin correctly?");
				return;
			}
			new Harmony("butterystancakes.lethalcompany.halloweenaction").PatchAll();
			Logger.LogInfo((object)"Halloween Action v1.0.0 loaded");
		}
	}
	[HarmonyPatch]
	internal class HalloweenActionPatches
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__6_0;

			internal void <SoundManagerPostStart>b__6_0()
			{
				if (StartOfRound.Instance.fearLevel <= 0f)
				{
					ChangeFearAudio();
				}
			}
		}

		internal static AudioClip lowActionHW;

		internal static AudioClip highActionHW;

		private static AudioClip lowActionOG;

		private static AudioClip highActionOG;

		private static bool randomizeThisFrame;

		[HarmonyPatch(typeof(SoundManager), "Awake")]
		[HarmonyPostfix]
		private static void SoundManagerPostAwake(SoundManager __instance)
		{
			if ((Object)(object)lowActionOG == (Object)null && !((Object)__instance.lowAction.clip).name.Contains("Halloween"))
			{
				lowActionOG = __instance.lowAction.clip;
			}
			if ((Object)(object)highActionOG == (Object)null && !((Object)__instance.highAction2.clip).name.Contains("Halloween"))
			{
				highActionOG = __instance.highAction2.clip;
			}
			Plugin.Logger.LogDebug((object)"Cached original clips");
		}

		[HarmonyPatch(typeof(SoundManager), "Start")]
		[HarmonyPostfix]
		private static void SoundManagerPostStart(SoundManager __instance)
		{
			//IL_0023: 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_002e: Expected O, but got Unknown
			ChangeFearAudio();
			SimpleEvent startNewRoundEvent = StartOfRound.Instance.StartNewRoundEvent;
			object obj = <>c.<>9__6_0;
			if (obj == null)
			{
				UnityAction val = delegate
				{
					if (StartOfRound.Instance.fearLevel <= 0f)
					{
						ChangeFearAudio();
					}
				};
				<>c.<>9__6_0 = val;
				obj = (object)val;
			}
			((UnityEvent)startNewRoundEvent).AddListener((UnityAction)obj);
		}

		[HarmonyPatch(typeof(SoundManager), "SetFearAudio")]
		[HarmonyPrefix]
		private static void SoundManagerPreSetFearAudio(bool ___lowActionAudible, bool ___highAction2audible)
		{
			randomizeThisFrame = !GameNetworkManager.Instance.localPlayerController.isPlayerDead && (___lowActionAudible || ___highAction2audible);
		}

		[HarmonyPatch(typeof(SoundManager), "SetFearAudio")]
		[HarmonyPostfix]
		private static void SoundManagerPostSetFearAudio(SoundManager __instance, bool ___lowActionAudible, bool ___highAction2audible)
		{
			if (randomizeThisFrame && !___lowActionAudible && !___highAction2audible)
			{
				ChangeFearAudio();
			}
		}

		private static void ChangeFearAudio()
		{
			float spookyChance = GetSpookyChance();
			if (spookyChance > 0f && Random.value <= spookyChance)
			{
				if ((Object)(object)SoundManager.Instance.lowAction.clip != (Object)(object)lowActionHW || (Object)(object)SoundManager.Instance.highAction2.clip != (Object)(object)highActionHW)
				{
					SoundManager.Instance.lowAction.Stop();
					SoundManager.Instance.lowAction.clip = lowActionHW;
					SoundManager.Instance.lowAction.Play();
					SoundManager.Instance.highAction2.Stop();
					SoundManager.Instance.highAction2.clip = highActionHW;
					SoundManager.Instance.highAction2.Play();
					Plugin.Logger.LogDebug((object)"SpoOoky");
				}
			}
			else if ((Object)(object)SoundManager.Instance.lowAction.clip != (Object)(object)lowActionOG || (Object)(object)SoundManager.Instance.highAction2.clip != (Object)(object)highActionOG)
			{
				SoundManager.Instance.lowAction.Stop();
				SoundManager.Instance.lowAction.clip = lowActionOG;
				SoundManager.Instance.lowAction.Play();
				SoundManager.Instance.highAction2.Stop();
				SoundManager.Instance.highAction2.clip = highActionOG;
				SoundManager.Instance.highAction2.Play();
				Plugin.Logger.LogDebug((object)"classic");
			}
		}

		private static float GetSpookyChance()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			if ((int)StartOfRound.Instance.currentLevel.currentWeather != 5)
			{
				return Plugin.configChance.Value;
			}
			return Plugin.configEclipseChance.Value;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "HalloweenAction";

		public const string PLUGIN_NAME = "HalloweenAction";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}