Decompiled source of UltraSplash v1.0.0

doomahreal.ultrakill.UltraSplash/UltraSplash.dll

Decompiled 6 months ago
using System;
using System.Collections;
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 Microsoft.CodeAnalysis;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Events;
using UnityEngine.ResourceManagement.AsyncOperations;
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("UltraSplash")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UltraSplash")]
[assembly: AssemblyTitle("UltraSplash")]
[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 UltraSplash
{
	public class FileReader
	{
		private readonly string filePath;

		public FileReader(string filePath)
		{
			this.filePath = filePath;
		}

		public string GetRandomLine()
		{
			if (!File.Exists(filePath))
			{
				Debug.LogError((object)("File not found: " + filePath));
				return null;
			}
			string[] array = File.ReadAllLines(filePath);
			if (array.Length == 0)
			{
				Debug.LogError((object)"File is empty.");
				return null;
			}
			int num = Random.Range(0, array.Length);
			return array[num];
		}
	}
	[BepInPlugin("doomahreal.ultrakill.UltraSplash", "UltraSplash", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public float minScale = 0.85f;

		public float maxScale = 1f;

		public float animationSpeed = 1.75f;

		private TextMeshProUGUI tmpComponent;

		public static FileReader fileReader;

		private void Awake()
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string filePath = Path.Combine(directoryName, "splashes.txt");
			fileReader = new FileReader(filePath);
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (SceneHelper.CurrentScene == "Main Menu")
			{
				GameObject val = GameObject.Find("Canvas/Main Menu (1)/Title");
				if ((Object)(object)val != (Object)null)
				{
					InstantiateTMP(val.transform);
				}
				else
				{
					Debug.LogError((object)"Title GameObject not found.");
				}
			}
		}

		private void InstantiateTMP(Transform parent)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			AsyncOperationHandle<TMP_FontAsset> val = Addressables.LoadAssetAsync<TMP_FontAsset>((object)"Assets/Fonts/VCR_OSD_MONO_UI.asset");
			val.Completed += OnFontLoaded;
			void OnFontLoaded(AsyncOperationHandle<TMP_FontAsset> handle)
			{
				//IL_0003: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Invalid comparison between Unknown and I4
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Expected O, but got Unknown
				//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_0118: Unknown result type (might be due to invalid IL or missing references)
				//IL_012e: Unknown result type (might be due to invalid IL or missing references)
				if ((int)handle.Status == 1)
				{
					TMP_FontAsset result = handle.Result;
					GameObject val2 = new GameObject("TMP_Object");
					val2.transform.SetParent(parent, false);
					tmpComponent = val2.AddComponent<TextMeshProUGUI>();
					((TMP_Text)tmpComponent).font = result;
					string randomLine = fileReader.GetRandomLine();
					if (string.IsNullOrEmpty(randomLine))
					{
						CreateWindow();
					}
					else
					{
						((TMP_Text)tmpComponent).text = randomLine;
						((TMP_Text)tmpComponent).alignment = (TextAlignmentOptions)514;
						((TMP_Text)tmpComponent).overflowMode = (TextOverflowModes)0;
						((TMP_Text)tmpComponent).enableWordWrapping = false;
						((TMP_Text)tmpComponent).enableAutoSizing = true;
						val2.transform.localPosition = new Vector3(400f, -100f, 0f);
						val2.transform.localRotation = Quaternion.Euler(0f, 0f, 15f);
						((Graphic)tmpComponent).color = Color.yellow;
						((MonoBehaviour)this).StartCoroutine(AnimateText(tmpComponent));
						val2.AddComponent<TMPComponentEnableDetector>();
					}
				}
				else
				{
					Debug.LogError((object)"Failed to load font.");
				}
			}
		}

		private IEnumerator AnimateText(TextMeshProUGUI tmpComponent)
		{
			float elapsedTime = 0f;
			while (true)
			{
				elapsedTime += Time.deltaTime;
				float t = Mathf.PingPong(elapsedTime * animationSpeed, 1f);
				float easedT = Mathf.SmoothStep(0f, 1f, t);
				float scale = Mathf.Lerp(minScale, maxScale, easedT);
				((TMP_Text)tmpComponent).transform.localScale = new Vector3(scale, scale, scale);
				yield return null;
			}
		}

		private void CreateWindow()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Expected O, but got Unknown
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Canvas");
			Canvas val2 = val.AddComponent<Canvas>();
			val2.renderMode = (RenderMode)0;
			val.AddComponent<CanvasScaler>();
			val.AddComponent<GraphicRaycaster>();
			GameObject val3 = new GameObject("CloseButton");
			val3.transform.SetParent(((Component)val2).transform, false);
			RectTransform val4 = val3.AddComponent<RectTransform>();
			val4.anchorMin = Vector2.zero;
			val4.anchorMax = Vector2.one;
			val4.sizeDelta = Vector2.zero;
			Button val5 = val3.AddComponent<Button>();
			((UnityEvent)val5.onClick).AddListener(new UnityAction(CloseGame));
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string resourceName = "UltraSplash.god.png";
			Texture2D val6 = LoadTextureFromResource(executingAssembly, resourceName);
			if ((Object)(object)val6 != (Object)null)
			{
				Image val7 = val3.AddComponent<Image>();
				val7.sprite = Sprite.Create(val6, new Rect(0f, 0f, (float)((Texture)val6).width, (float)((Texture)val6).height), Vector2.one * 0.5f);
			}
			else
			{
				Debug.LogError((object)"Failed to load button image from embedded resources.");
			}
			GameObject val8 = new GameObject("AdditionalText");
			val8.transform.SetParent(val3.transform, false);
			TextMeshProUGUI val9 = val8.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val9).font = ((TMP_Text)tmpComponent).font;
			((TMP_Text)val9).enableWordWrapping = false;
			((TMP_Text)val9).enableAutoSizing = true;
			string name = SteamClient.Name;
			((TMP_Text)val9).text = "Where is my splash file, " + name + ".";
			((TMP_Text)val9).alignment = (TextAlignmentOptions)514;
			((Graphic)val9).color = Color.red;
			RectTransform val10 = val8.GetComponent<RectTransform>();
			if ((Object)(object)val10 == (Object)null)
			{
				val10 = val8.AddComponent<RectTransform>();
			}
			val10.sizeDelta = new Vector2(800f, 600f);
			AudioSource[] array = Object.FindObjectsOfType<AudioSource>();
			AudioSource[] array2 = array;
			foreach (AudioSource val11 in array2)
			{
				val11.volume = 0f;
			}
		}

		private Texture2D LoadTextureFromResource(Assembly assembly, string resourceName)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			Texture2D val = null;
			try
			{
				using Stream stream = assembly.GetManifestResourceStream(resourceName);
				if (stream != null)
				{
					byte[] array = new byte[stream.Length];
					stream.Read(array, 0, array.Length);
					val = new Texture2D(2, 2);
					ImageConversion.LoadImage(val, array);
				}
				else
				{
					Debug.LogError((object)("Resource '" + resourceName + "' not found."));
				}
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Failed to load texture from resource: " + ex.Message));
			}
			return val;
		}

		private void CloseGame()
		{
			Application.Quit();
		}
	}
	public class TMPComponentEnableDetector : MonoBehaviour
	{
		private TextMeshProUGUI tmpComponent;

		private void Awake()
		{
			tmpComponent = ((Component)this).GetComponent<TextMeshProUGUI>();
		}

		private void OnEnable()
		{
			UpdateSplashText();
		}

		private void UpdateSplashText()
		{
			string randomLine = Plugin.fileReader.GetRandomLine();
			if (!string.IsNullOrEmpty(randomLine))
			{
				((TMP_Text)tmpComponent).text = randomLine;
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "UltraSplash";

		public const string PLUGIN_NAME = "UltraSplash";

		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)
		{
		}
	}
}