Decompiled source of LivePeppinoReaction v2.0.0

doomahreal.ultrakill.livepeppinoreaction/LivePeppinoReaction.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
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 Configgy;
using HarmonyLib;
using LivePeppinoReaction;
using Microsoft.CodeAnalysis;
using ULTRAKILL.Cheats;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("LivePeppinoReaction")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LivePeppinoReaction")]
[assembly: AssemblyTitle("LivePeppinoReaction")]
[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;
		}
	}
}
public class NoiseHandler : MonoBehaviour
{
	public GameObject PeppinoTV;

	public GameObject NoiseTV;

	public AudioSource Sounds;

	public AudioClip[] PeppinoScreams;

	public AudioClip[] NoiseScreams;

	public void Switch(bool sfx = false)
	{
		bool value = ((ConfigValueElement<bool>)(object)Plugin.NM).Value;
		PeppinoTV.SetActive(!value);
		NoiseTV.SetActive(value);
		if (sfx)
		{
			if (value)
			{
				int num = Random.Range(0, PeppinoScreams.Length);
				Sounds.PlayOneShot(PeppinoScreams[num]);
			}
			else
			{
				int num2 = Random.Range(0, NoiseScreams.Length);
				Sounds.PlayOneShot(NoiseScreams[num2]);
			}
		}
	}
}
public class ReactionLogic : MonoBehaviour
{
	public Image[] peppino;

	public Image[] noise;

	public Image StaticImage;

	private bool noiseMode;

	public UnityEvent<bool> OnNoiseModeChanged;

	private int previousRankIndex = -1;

	private int frameCounter = 0;

	public bool NoiseMode
	{
		get
		{
			return noiseMode;
		}
		set
		{
			noiseMode = value;
			OnNoiseModeChanged?.Invoke(noiseMode);
			UpdateMode();
			UpdateHUDBasedOnRank(MonoSingleton<StyleHUD>.Instance._rankIndex);
		}
	}

	private void Awake()
	{
		UpdateMode();
	}

	private void UpdateMode()
	{
		SetActiveAll(peppino, active: false);
		SetActiveAll(noise, active: false);
		((Component)(noiseMode ? noise : peppino)[0]).gameObject.SetActive(true);
	}

	private void SetActiveAll(Image[] array, bool active)
	{
		foreach (Image val in array)
		{
			((Component)val).gameObject.SetActive(active);
		}
	}

	private void Update()
	{
		frameCounter++;
		if (frameCounter % 5 == 0)
		{
			int rankIndex = MonoSingleton<StyleHUD>.Instance.rankIndex;
			if (rankIndex != previousRankIndex)
			{
				((Component)StaticImage).gameObject.SetActive(true);
				((MonoBehaviour)this).Invoke("UpdateHUDBasedOnRankWithDelay", 0.4f);
			}
			Image[] array = (noiseMode ? noise : peppino);
			if (((Component)array[2]).gameObject.activeSelf && MonoSingleton<StyleHUD>.Instance.currentMeter <= 0f && rankIndex == 0)
			{
				((Component)StaticImage).gameObject.SetActive(true);
				((MonoBehaviour)this).Invoke("UpdateHUDBasedOnRankWithDelay", 0.4f);
			}
			previousRankIndex = rankIndex;
		}
	}

	private void UpdateHUDBasedOnRankWithDelay()
	{
		int rankIndex = MonoSingleton<StyleHUD>.Instance.rankIndex;
		UpdateHUDBasedOnRank(rankIndex);
		((MonoBehaviour)this).Invoke("DeactivateStaticImage", 0.02f);
	}

	private void UpdateHUDBasedOnRank(int rankIndex)
	{
		Image[] array = (noiseMode ? noise : peppino);
		SetActiveAll(array, active: false);
		float currentMeter = MonoSingleton<StyleHUD>.Instance.currentMeter;
		int num = ((currentMeter > 0f && rankIndex == 0) ? 2 : ((rankIndex < 1) ? rankIndex : (rankIndex + 2)));
		if (currentMeter == 0f && rankIndex == 0)
		{
			((Component)array[0]).gameObject.SetActive(true);
		}
		else if (num >= 0 && num < array.Length)
		{
			((Component)array[num]).gameObject.SetActive(true);
		}
	}

	private void DeactivateStaticImage()
	{
		((Component)StaticImage).gameObject.SetActive(false);
	}
}
namespace LivePeppinoReaction
{
	public static class Loader
	{
		public static AssetBundle Load()
		{
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				string name = "LivePeppinoReaction.peppino.bundle";
				using Stream stream = executingAssembly.GetManifestResourceStream(name);
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				return AssetBundle.LoadFromMemory(array);
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Error loading peppino: " + ex.Message));
				return null;
			}
		}
	}
	[BepInPlugin("doomahreal.ultrakill.livepeppinoreaction", "Live Peppino Reaction", "2.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private AssetBundle Bundle;

		private GameObject Canvass;

		private GameObject CanvassInstance;

		private List<GameObject> Tv = new List<GameObject>();

		public static bool TrackRank = false;

		[Configgable("", "Noise mode:", 0, null)]
		public static ConfigToggle NM = new ConfigToggle(false);

		private bool hideUIActiveLastFrame = false;

		private int frameCounter = 0;

		public static ConfigBuilder ConfigBuilder { get; private set; }

		private void Awake()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			Bundle = Loader.Load();
			Canvass = Bundle.LoadAsset<GameObject>("pepper.prefab");
			ConfigBuilder = new ConfigBuilder("doomahreal.ultrakill.livepeppinoreaction", "Live Peppino Reaction");
			ConfigBuilder.BuildAll();
			ConfigToggle nM = NM;
			((ConfigValueElement<bool>)(object)nM).OnValueChanged = (Action<bool>)Delegate.Combine(((ConfigValueElement<bool>)(object)nM).OnValueChanged, (Action<bool>)delegate
			{
				UpdateNoiseMode(sfx: true);
			});
			SceneManager.sceneLoaded += OnSceneLoaded;
			new Harmony("doomahreal.ultrakill.livepeppinoreaction").PatchAll();
			Debug.Log((object)"Hot Meaty Italians are in your area.");
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			TrackRank = false;
			if (SceneHelper.CurrentScene != "Main Menu" && SceneHelper.CurrentScene != "Intro" && ((Scene)(ref scene)).buildIndex != 0)
			{
				CanvassInstance = Object.Instantiate<GameObject>(Canvass);
				FindChildObjects(CanvassInstance.transform);
				UpdateNoiseMode();
				TrackRank = true;
				hideUIActiveLastFrame = HideUI.Active;
				frameCounter = 0;
			}
		}

		private void FindChildObjects(Transform parent)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			Tv.Clear();
			foreach (Transform item in parent)
			{
				Transform val = item;
				Tv.Add(((Component)val).gameObject);
			}
		}

		private void UpdateNoiseMode(bool sfx = false)
		{
			if (Tv != null)
			{
				ReactionLogic reactionLogic = Object.FindObjectOfType<ReactionLogic>();
				if (!((Object)(object)reactionLogic == (Object)null))
				{
					reactionLogic.NoiseMode = ((ConfigValueElement<bool>)(object)NM).Value;
					Object.FindObjectOfType<NoiseHandler>()?.Switch(sfx);
				}
			}
		}

		private void Update()
		{
			if ((Object)(object)CanvassInstance != (Object)null && ++frameCounter % 5 == 0)
			{
				bool active = HideUI.Active;
				if (active != hideUIActiveLastFrame)
				{
					CanvassInstance.SetActive(!active);
					hideUIActiveLastFrame = active;
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LivePeppinoReaction";

		public const string PLUGIN_NAME = "LivePeppinoReaction";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}