Decompiled source of ScrewYourOldIntro v1.0.0

ScrewYourOldIntro.dll

Decompiled 13 hours ago
using System;
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.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using Configgy;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.Video;

[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("ScrewYourOldIntro")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ScrewYourOldIntro")]
[assembly: AssemblyTitle("ScrewYourOldIntro")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 ScrewYourOldIntro
{
	[BepInPlugin("doomahreak.ultrakill.intromodthingidkfuckyou", "ScrewYourOldIntro", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private ConfigBuilder config;

		[Configgable("", "Open mod's folder", 0, null)]
		public static ConfigButton boobtton = new ConfigButton((Action)OpenModFolder, (string)null);

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_0012: 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: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			new Harmony("doomahreak.ultrakill.intromodthingidkfuckyou").PatchAll();
			SceneManager.sceneLoaded += OnSceneLoaded;
			Logger.LogInfo((object)"changing your intro or something fuck you");
			config = new ConfigBuilder("doomahreak.ultrakill.intromodthingidkfuckyou", "ScrewYourOldIntro");
			config.BuildAll();
		}

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

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Expected O, but got Unknown
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Expected O, but got Unknown
			if (SceneHelper.CurrentScene != "Main Menu")
			{
				return;
			}
			GameObject val = GameObject.Find("Canvas/Main Menu (1)/LeftSide/Title");
			Image component = val.GetComponent<Image>();
			string directoryName = Path.GetDirectoryName(typeof(Plugin).Assembly.Location);
			string text = Path.Combine(directoryName, "EDIT_ME_THEN_RENAME_ME.png");
			if (!File.Exists(text))
			{
				Sprite sprite = component.sprite;
				Texture2D texture = sprite.texture;
				Rect rect = sprite.rect;
				RenderTexture temporary = RenderTexture.GetTemporary((int)((Rect)(ref rect)).width, (int)((Rect)(ref rect)).height, 0, (RenderTextureFormat)7, (RenderTextureReadWrite)1);
				Graphics.Blit((Texture)(object)texture, temporary);
				RenderTexture active = RenderTexture.active;
				RenderTexture.active = temporary;
				Texture2D val2 = new Texture2D((int)((Rect)(ref rect)).width, (int)((Rect)(ref rect)).height, (TextureFormat)4, false);
				val2.ReadPixels(new Rect(0f, 0f, ((Rect)(ref rect)).width, ((Rect)(ref rect)).height), 0, 0);
				val2.Apply();
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
				byte[] data = ImageConversion.EncodeToPNG(val2);
				WriteFileAsync(text, data);
			}
			HashSet<string> exts = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".png", ".jpg", ".jpeg" };
			List<string> source = (from f in Directory.EnumerateFiles(directoryName, "*.*", SearchOption.TopDirectoryOnly)
				where exts.Contains(Path.GetExtension(f))
				select f).ToList();
			List<string> list = source.Where((string f) => !Path.GetFileName(f).Equals("icon.png", StringComparison.OrdinalIgnoreCase) && !Path.GetFileName(f).Equals("EDIT_ME_THEN_RENAME_ME.png", StringComparison.OrdinalIgnoreCase)).ToList();
			if (list.Count == 0)
			{
				list.Add(text);
			}
			if (list.Count == 0)
			{
				return;
			}
			string text2 = list[Random.Range(0, list.Count)];
			Logger.LogInfo((object)("Chosen image: " + text2));
			Texture2D val3 = null;
			try
			{
				byte[] array = File.ReadAllBytes(text2);
				val3 = new Texture2D(2, 2);
				if (!ImageConversion.LoadImage(val3, array))
				{
					val3 = null;
				}
			}
			catch
			{
				val3 = null;
			}
			if ((Object)(object)val3 == (Object)null && File.Exists(text))
			{
				byte[] array2 = File.ReadAllBytes(text);
				val3 = new Texture2D(2, 2);
				ImageConversion.LoadImage(val3, array2);
			}
			if ((Object)(object)val3 != (Object)null)
			{
				component.sprite = Sprite.Create(val3, new Rect(0f, 0f, (float)((Texture)val3).width, (float)((Texture)val3).height), new Vector2(0.5f, 0.5f), 100f);
			}
		}

		private async Task WriteFileAsync(string path, byte[] data)
		{
			try
			{
				using FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, 4096, useAsync: true);
				await fs.WriteAsync(data, 0, data.Length);
			}
			catch (Exception ex)
			{
				Exception e = ex;
				Logger.LogError((object)$"Failed to write {path}: {e}");
			}
		}

		private static void OpenModFolder()
		{
			try
			{
				string directoryName = Path.GetDirectoryName(typeof(Plugin).Assembly.Location);
				string text = "file:///" + directoryName.Replace("\\", "/");
				Application.OpenURL(text);
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"Failed to open mod folder: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(IntroViolenceScreen), "Start")]
	public static class IntroViolenceScreen_Start_Patch
	{
		private static void Postfix(IntroViolenceScreen __instance)
		{
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			string directoryName = Path.GetDirectoryName(typeof(Plugin).Assembly.Location);
			HashSet<string> exts = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".mp4", ".webm", ".mov" };
			string[] array = (from f in Directory.EnumerateFiles(directoryName, "*.*", SearchOption.AllDirectories)
				where exts.Contains(Path.GetExtension(f))
				select f).ToArray();
			if (array.Length != 0)
			{
				string url = array[Random.Range(0, array.Length)];
				VideoPlayer player = ((Component)__instance).GetComponent<VideoPlayer>();
				player.Stop();
				player.source = (VideoSource)1;
				player.url = url;
				player.isLooping = false;
				player.prepareCompleted += (EventHandler)delegate
				{
					player.Play();
				};
				player.Prepare();
			}
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "doomahreak.ultrakill.intromodthingidkfuckyou";

		public const string PLUGIN_NAME = "ScrewYourOldIntro";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}