Decompiled source of RevisitStingers v1.2.1

RevisitStingers.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Diagnostics;
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;

[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("RevisitStingers")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Replay interior stingers when they are somewhere they shouldn't be")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+450e4a7a579ad3f40109f106bb8d09c782e5d3f2")]
[assembly: AssemblyProduct("RevisitStingers")]
[assembly: AssemblyTitle("RevisitStingers")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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 RevisitStingers
{
	[BepInPlugin("butterystancakes.lethalcompany.revisitstingers", "Revisit Stingers", "1.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string PLUGIN_GUID = "butterystancakes.lethalcompany.revisitstingers";

		private const string PLUGIN_NAME = "Revisit Stingers";

		private const string PLUGIN_VERSION = "1.2.0";

		internal static ConfigEntry<float> configMaxRarity;

		internal static ConfigEntry<float> configInterruptMusic;

		internal static ConfigEntry<float> configFallbackChance;

		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			//IL_00bf: 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)";
			configMaxRarity = ((BaseUnityPlugin)this).Config.Bind<float>("Misc", "MaxRarity", 0.06f, new ConfigDescription("The highest spawn chance (0.06 = 6%) an interior can have on a specific moon for it to be considered \"rare\". Rare interiors will always play the stinger.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			configInterruptMusic = ((BaseUnityPlugin)this).Config.Bind<float>("Misc", "InterruptMusic", 0f, new ConfigDescription("The percentage chance for the stinger to play if you enter the building while an ambient music track is playing." + text, (AcceptableValueBase)(object)val, Array.Empty<object>()));
			configFallbackChance = ((BaseUnityPlugin)this).Config.Bind<float>("Misc", "FallbackChance", 0f, new ConfigDescription("The percentage chance that the stinger will still play, even if you are in a common interior and there is no music playing on the surface." + text, (AcceptableValueBase)(object)val, Array.Empty<object>()));
			new Harmony("butterystancakes.lethalcompany.revisitstingers").PatchAll();
			Logger.LogInfo((object)"Revisit Stingers v1.2.0 loaded");
		}
	}
	[HarmonyPatch]
	internal class RevisitStingersPatches
	{
		[HarmonyPatch(typeof(EntranceTeleport), "TeleportPlayer")]
		[HarmonyPrefix]
		private static void EntranceTeleportPreTeleportPlayer(EntranceTeleport __instance, bool ___checkedForFirstTime)
		{
			if (ReplayStinger.beenInsideThisRound || !__instance.FindExitPoint())
			{
				return;
			}
			ReplayStinger.beenInsideThisRound = true;
			if (___checkedForFirstTime || !ES3.Load<bool>($"PlayedDungeonEntrance{RoundManager.Instance.currentDungeonType}", "LCGeneralSaveData", false))
			{
				return;
			}
			try
			{
				AudioClip firstTimeAudio = RoundManager.Instance.dungeonFlowTypes[RoundManager.Instance.currentDungeonType].firstTimeAudio;
				if (ReplayStinger.StingerShouldReplay())
				{
					((MonoBehaviour)__instance).StartCoroutine(ReplayStinger.DelayedStinger(firstTimeAudio));
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError((object)"Ran into an error attempting to replay stinger - this is likely due to an incompatibility with modded content");
				Plugin.Logger.LogError((object)ex.Message);
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "SetShipReadyToLand")]
		[HarmonyPostfix]
		private static void StartOfRoundPostSetShipReadyToLand()
		{
			ReplayStinger.beenInsideThisRound = false;
		}

		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		[HarmonyPostfix]
		private static void StartOfRoundPostAwake()
		{
			ReplayStinger.beenInsideThisRound = false;
		}
	}
	internal class ReplayStinger
	{
		internal static bool beenInsideThisRound;

		internal static bool StingerShouldReplay()
		{
			if (Plugin.configInterruptMusic.Value > 0f && SoundManager.Instance.musicSource.isPlaying && Random.value <= Plugin.configInterruptMusic.Value)
			{
				return true;
			}
			IntWithRarity[] dungeonFlowTypes = StartOfRound.Instance.currentLevel.dungeonFlowTypes;
			if (dungeonFlowTypes != null && dungeonFlowTypes.Length > 1 && (!StartOfRound.Instance.isChallengeFile || !ES3.Load<bool>("FinishedChallenge", "LCChallengeFile", false)))
			{
				int num = 0;
				float num2 = 0f;
				IntWithRarity[] dungeonFlowTypes2 = StartOfRound.Instance.currentLevel.dungeonFlowTypes;
				foreach (IntWithRarity val in dungeonFlowTypes2)
				{
					if (val.id == RoundManager.Instance.currentDungeonType)
					{
						num = val.rarity;
					}
					num2 += (float)val.rarity;
				}
				if (num > 0 && (float)num / num2 <= Plugin.configMaxRarity.Value)
				{
					return true;
				}
			}
			if (Plugin.configFallbackChance.Value > 0f)
			{
				return Random.value <= Plugin.configFallbackChance.Value;
			}
			return false;
		}

		internal static IEnumerator DelayedStinger(AudioClip stinger)
		{
			yield return (object)new WaitForSeconds(0.6f);
			HUDManager.Instance.UIAudio.PlayOneShot(stinger);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "RevisitStingers";

		public const string PLUGIN_NAME = "RevisitStingers";

		public const string PLUGIN_VERSION = "1.2.0";
	}
}