Decompiled source of StyleToasts v0.0.1

plugins/StyleToasts.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("StyleToasts")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("in-world text for stylish actions")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1+b3845fc774a0dd6b28468355bcd4c916210e00b2")]
[assembly: AssemblyProduct("StyleToasts")]
[assembly: AssemblyTitle("StyleToasts")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.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 StyleToasts
{
	[BepInPlugin("StyleToasts", "StyleToasts", "0.0.1")]
	public sealed class Plugin : BaseUnityPlugin
	{
		private static readonly HashSet<string> ignoredBonuses = new HashSet<string> { "ultrakill.projectileboost", "ultrakill.disrespect", "ultrakill.quickdraw", "ultrakill.parry", "ultrakill.kill" };

		private static Vector3? styleLocation = null;

		private static float scatterAmount = 0f;

		public void Awake()
		{
			Harmony.CreateAndPatchAll(((object)this).GetType(), (string)null);
		}

		private static Vector3? TakeStyleLocation()
		{
			Vector3? result = styleLocation;
			styleLocation = null;
			return result;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Coin), "RicoshotPointsCheck")]
		private static void OnRicoshot(Rigidbody ___rb)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			styleLocation = ___rb.position;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Gutterman), "ShieldBreak")]
		private static void OnShieldBreak(bool player, Rigidbody ___rb)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			if (player)
			{
				styleLocation = ___rb.position;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(StyleHUD), "AddPoints")]
		private static void OnAddPoints(string pointID, EnemyIdentifier eid)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			Rigidbody val = default(Rigidbody);
			if (eid != null && !ignoredBonuses.Contains(pointID) && ((Component)eid).TryGetComponent<Rigidbody>(ref val))
			{
				Vector3 valueOrDefault = styleLocation.GetValueOrDefault();
				if (!styleLocation.HasValue)
				{
					valueOrDefault = val.worldCenterOfMass;
					styleLocation = valueOrDefault;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StyleHUD), "AddPoints")]
		private static void AfterAddPoints(StyleHUD __instance, string pointID, int count, string prefix, string postfix)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			Vector3? val = TakeStyleLocation();
			if (!val.HasValue)
			{
				return;
			}
			Vector3 valueOrDefault = val.GetValueOrDefault();
			string localizedName = __instance.GetLocalizedName(pointID);
			if (!(localizedName == ""))
			{
				Vector3 val2 = Random.insideUnitSphere * scatterAmount;
				val2.x = 0f;
				valueOrDefault += val2;
				string text = "+ " + prefix + localizedName + postfix;
				float num = ((!(pointID == "ultrakill.bigkill")) ? 0.02f : 0.04f);
				float num2 = num;
				if (count >= 0)
				{
					text += $" x{count}";
					num2 *= (float)count;
				}
				SpawnText(valueOrDefault, num2, text);
				scatterAmount = Mathf.MoveTowards(scatterAmount, 10f, 3f);
			}
		}

		public void Update()
		{
			scatterAmount = Mathf.MoveTowards(scatterAmount, 0f, 3f * Time.deltaTime);
		}

		private static void SpawnText(Vector3 position, float scale, string text)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			ToastText toastText = new GameObject().AddComponent<ToastText>();
			toastText.Text = text;
			toastText.Size = Vector3.one * scale;
			((Component)toastText).transform.position = position;
		}
	}
	public sealed class ToastSingleton : MonoSingleton<ToastSingleton>
	{
		public GameObject Overlay { get; private set; }

		public Font Font { get; private set; }

		protected override void Awake()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			Font = Resources.FindObjectsOfTypeAll<Font>().First((Font f) => ((Object)f).name == "VCR_OSD_MONO_1.001");
			Overlay = new GameObject("Overlay");
			Canvas obj = Overlay.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)2;
			obj.sortingOrder = 1000;
			obj.scaleFactor = 5f;
			Overlay.AddComponent<GraphicRaycaster>();
		}
	}
	public sealed class ToastText : MonoBehaviour
	{
		private Text textComponent;

		private RectTransform rectComponent;

		private float age;

		public string Text
		{
			get
			{
				return textComponent.text;
			}
			set
			{
				textComponent.text = value;
			}
		}

		public Vector3 Size
		{
			get
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				return ((Transform)rectComponent).localScale;
			}
			set
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				((Transform)rectComponent).localScale = value;
			}
		}

		public void Awake()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)this).gameObject;
			RectTransform val = gameObject.AddComponent<RectTransform>();
			gameObject.AddComponent<CanvasRenderer>();
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			val.anchorMax = val2;
			Vector2 pivot = (val.anchorMin = val2);
			val.pivot = pivot;
			((Transform)val).parent = MonoSingleton<ToastSingleton>.Instance.Overlay.transform;
			((Transform)val).localScale = Vector3.one * 0.02f;
			val.sizeDelta = Vector2.one * 500f;
			rectComponent = val;
			Text val4 = gameObject.AddComponent<Text>();
			val4.font = MonoSingleton<ToastSingleton>.Instance.Font;
			val4.fontSize = 50;
			val4.alignment = (TextAnchor)4;
			((Graphic)val4).color = Color.white;
			((Graphic)val4).mainTexture.filterMode = (FilterMode)0;
			textComponent = val4;
		}

		public void Update()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			age += Time.deltaTime;
			if (age >= 2f)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			if (age >= 1f)
			{
				float num = 2f - age;
				num *= num;
				((Graphic)textComponent).canvasRenderer.SetAlpha(num);
			}
			Vector3 position = ((Component)this).transform.position;
			Vector3 val = ((Component)Camera.main).transform.position - position;
			float num2 = Mathf.Log10(((Vector3)(ref val)).magnitude);
			((Component)this).transform.Translate(Vector3.up * Time.deltaTime * num2);
			((Component)this).transform.LookAt(position - val);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "StyleToasts";

		public const string PLUGIN_NAME = "StyleToasts";

		public const string PLUGIN_VERSION = "0.0.1";
	}
}