Decompiled source of StyleFLASHES v1.1.0

styleFLASHES.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Decorators;
using PluginConfig.API.Fields;
using UnityEngine;
using UnityEngine.Networking;
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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("styleFLASHES")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Style FLASHES")]
[assembly: AssemblyTitle("styleFLASHES")]
[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 styleFLASHES
{
	public static class SFConfig
	{
		private static PluginConfigurator config;

		public static FloatField fadeTime;

		public static FloatField imageAlpha;

		public static FloatField audioVolume;

		private static string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		public static void Init()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Expected O, but got Unknown
			config = PluginConfigurator.Create("Style FLASHES", "styleFLASHES");
			config.SetIconWithURL("file://" + Path.Combine(directory, "icon.png"));
			ConfigHeader val = new ConfigHeader(config.rootPanel, "Flash : Visual", 24);
			fadeTime = new FloatField(config.rootPanel, "Flash Fade Time", "fade_time", 0.25f);
			fadeTime.maximumValue = 1f;
			fadeTime.minimumValue = 0.1f;
			imageAlpha = new FloatField(config.rootPanel, "Flash Alpha", "image_alpha", 1f);
			imageAlpha.maximumValue = 1f;
			imageAlpha.minimumValue = 0f;
			ConfigHeader val2 = new ConfigHeader(config.rootPanel, "Flash : Audio", 24);
			audioVolume = new FloatField(config.rootPanel, "Audio Volume", "audio_vol", 1f);
			audioVolume.maximumValue = 4f;
			audioVolume.minimumValue = 0f;
		}
	}
	public class Flash : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <FadeOut>d__1 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Image image;

			public float fadeTime;

			public float startingAlpha;

			public Flash <>4__this;

			private float <elapsedTime>5__1;

			private Color <c>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <FadeOut>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<elapsedTime>5__1 = 0f;
					<c>5__2 = ((Graphic)image).color;
					break;
				case 1:
					<>1__state = -1;
					<elapsedTime>5__1 += Time.deltaTime;
					<c>5__2.a = (1f - Mathf.Clamp01(<elapsedTime>5__1 / fadeTime)) * startingAlpha;
					((Graphic)image).color = <c>5__2;
					break;
				}
				if (<elapsedTime>5__1 < fadeTime)
				{
					<>2__current = <>4__this.fadeInstruction;
					<>1__state = 1;
					return true;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public YieldInstruction fadeInstruction = new YieldInstruction();

		[IteratorStateMachine(typeof(<FadeOut>d__1))]
		public IEnumerator FadeOut(Image image, float fadeTime, float startingAlpha)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <FadeOut>d__1(0)
			{
				<>4__this = this,
				image = image,
				fadeTime = fadeTime,
				startingAlpha = startingAlpha
			};
		}

		private void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("/Canvas");
			GameObject gameObject = ((Component)this).gameObject;
			RectTransform component = gameObject.GetComponent<RectTransform>();
			Image component2 = gameObject.GetComponent<Image>();
			((Transform)component).localScale = Vector3.one;
			component.anchoredPosition = new Vector2(0f, 0f);
			component.sizeDelta = val.GetComponent<RectTransform>().sizeDelta * 1f;
		}

		public void fade()
		{
			((Component)this).gameObject.GetComponent<AudioSource>().Play();
			((MonoBehaviour)this).StartCoroutine(FadeOut(((Component)this).gameObject.GetComponent<Image>(), SFConfig.fadeTime.value, SFConfig.imageAlpha.value));
		}
	}
	public class SFGroup : MonoSingleton<SFGroup>
	{
		public CanvasGroup group;

		protected override void Awake()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("/Canvas");
			group = new GameObject("SFGroup", new Type[1] { typeof(RectTransform) }).AddComponent<CanvasGroup>();
			RectTransform component = ((Component)group).gameObject.GetComponent<RectTransform>();
			((Transform)component).SetParent(val.transform);
			group.interactable = false;
			group.blocksRaycasts = false;
			((Transform)component).localScale = Vector3.one;
			component.anchoredPosition = new Vector2(0f, 0f);
		}
	}
	[BepInPlugin("styleFLASHES", "Style FLASHES", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static class PatchMethods
		{
			[HarmonyPostfix]
			[HarmonyPatch(typeof(StyleHUD), "AddPoints")]
			private static void LikeAfterAddPoints(int points, string pointID)
			{
				//IL_0121: Unknown result type (might be due to invalid IL or missing references)
				//IL_0127: Expected O, but got Unknown
				string bonus = pointID.Replace("<color=orange>", "_Orange", StringComparison.OrdinalIgnoreCase).Replace("<color=#00ffffff>", "_Cyan", StringComparison.OrdinalIgnoreCase).Replace("<color=#00FFFF>", "_Cyan", StringComparison.OrdinalIgnoreCase)
					.Replace("<color=red>", "_Red", StringComparison.OrdinalIgnoreCase)
					.Replace("<color=green>", "_Green", StringComparison.OrdinalIgnoreCase)
					.Replace("<color=grey>", "_Grey", StringComparison.OrdinalIgnoreCase)
					.Replace("</color>", "_e", StringComparison.OrdinalIgnoreCase);
				Logger.LogInfo((object)("remvoe this: " + bonus));
				Sprite val = imagePool.Where((Sprite obj) => ((Object)obj).name == bonus).SingleOrDefault();
				AudioClip val2 = audioPool.Where((AudioClip obj) => ((Object)obj).name == bonus).SingleOrDefault();
				if (!((Object)(object)val == (Object)null) || !((Object)(object)val2 == (Object)null))
				{
					GameObject val3 = new GameObject("StyleFlash", new Type[3]
					{
						typeof(CanvasRenderer),
						typeof(Image),
						typeof(AudioSource)
					});
					if ((Object)(object)val != (Object)null)
					{
						Logger.LogInfo((object)("Displaying image for style: " + ((Object)val).name));
					}
					else
					{
						((Behaviour)val3.GetComponent<Image>()).enabled = false;
					}
					val3.GetComponent<Image>().sprite = val;
					if ((Object)(object)val2 != (Object)null)
					{
						Logger.LogInfo((object)("Playing audio for style: " + ((Object)val2).name));
						val3.GetComponent<AudioSource>().clip = val2;
						val3.GetComponent<AudioSource>().volume = SFConfig.audioVolume.value;
					}
					val3.transform.SetParent(((Component)MonoSingleton<SFGroup>.Instance.group).transform, false);
					Flash flash = val3.AddComponent<Flash>();
					flash.fade();
				}
			}
		}

		internal static ManualLogSource Logger;

		public Harmony harm;

		public static List<string> imageTypes = new List<string> { ".jpeg", ".jpg", ".png", ".bmp" };

		public static List<string> audioTypes = new List<string> { ".mp3", ".ogg", ".wav", ".aif" };

		public static List<Sprite> imagePool = new List<Sprite>();

		public static List<AudioClip> audioPool = new List<AudioClip>();

		public static string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin styleFLASHES is loaded!");
			SFConfig.Init();
			Logger.LogInfo((object)"Also loaded my config menu.");
		}

		public void Start()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			UpdatePools();
			harm = new Harmony("styleFLASHES");
			harm.PatchAll(typeof(PatchMethods));
		}

		public static void UpdatePools()
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			imagePool = new List<Sprite>();
			audioPool = new List<AudioClip>();
			foreach (string item in Directory.EnumerateFiles(Path.Combine(Path.Combine(directory, "assets"))))
			{
				for (int i = 0; i < imageTypes.Count; i++)
				{
					if (string.Equals(imageTypes[i], Path.GetExtension(item), StringComparison.OrdinalIgnoreCase))
					{
						byte[] array = File.ReadAllBytes(item);
						Texture2D val = new Texture2D(0, 0, (TextureFormat)4, false);
						((Texture)val).filterMode = (FilterMode)0;
						ImageConversion.LoadImage(val, array);
						Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
						((Object)val2).name = Path.GetFileNameWithoutExtension(item);
						imagePool.Add(val2);
						Logger.LogInfo((object)("Loaded image " + ((Object)val2).name + "..."));
						break;
					}
				}
				for (int j = 0; j < audioTypes.Count; j++)
				{
					if (string.Equals(audioTypes[j], Path.GetExtension(item), StringComparison.OrdinalIgnoreCase))
					{
						UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(item, (AudioType)0);
						audioClip.SendWebRequest();
						while (!audioClip.isDone)
						{
						}
						AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
						string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(item);
						((Object)content).name = fileNameWithoutExtension;
						audioPool.Add(content);
						Logger.LogInfo((object)("Loaded audio clip " + ((Object)content).name + "..."));
						break;
					}
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "styleFLASHES";

		public const string PLUGIN_NAME = "Style FLASHES";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}