Decompiled source of PainsCompanyLogo v2.0.0

plugins/LiquidStainRemover.dll

Decompiled 4 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using UnityEngine;
using UnityEngine.UI;
using Utils;

[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("LiquidStainRemover")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+6f83db066e9f6f419deb5c41e373eb16532b0d16")]
[assembly: AssemblyProduct("LiquidStainRemover")]
[assembly: AssemblyTitle("LiquidStainRemover")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
internal class <Module>
{
	static <Module>()
	{
	}
}
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;
		}
	}
}
[BepInPlugin("flowerwater.liquidStainRemover", "LiquidStain Remover", "1.1.9")]
public class LiquidStainRemoverPlugin : BaseUnityPlugin
{
	public const string ModGuid = "flowerwater.liquidStainRemover";

	public const string ModName = "LiquidStain Remover";

	public const string ModVersion = "1.1.9";

	public static ConfigEntry<bool> disableLogoChanges;

	public static byte[] logo;

	public static Sprite logo2;

	private void Awake()
	{
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: 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)
		disableLogoChanges = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Disable Logo Changes", true, "Prevents the Logo from being changed aswell. (Technically this pulls a random image from the Folder™\ufe0f and uses that for the logo so this can be used to have random logos if you want to.)");
		ToolModules.InitHooks();
		string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Folder");
		int num = Random.Range(0, Directory.GetFiles(path).Length);
		int num2 = 0;
		string[] files = Directory.GetFiles(path);
		foreach (string path2 in files)
		{
			if (num2 == num)
			{
				logo = File.ReadAllBytes(path2);
			}
			num2++;
		}
		Texture2D val = LoadTexture(logo, 545, 249);
		logo2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(272.5f, 124.5f), 100f, 1u, (SpriteMeshType)1, new Vector4(0f, 0f, 0f, 0f), true);
	}

	public static Texture2D LoadTexture(byte[] bytes, int width, int height)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Texture2D val = new Texture2D(width, height, (TextureFormat)5, false, false);
		ImageConversion.LoadImage(val, bytes);
		((Texture)val).filterMode = (FilterMode)0;
		return val;
	}
}
[DefaultExecutionOrder(-1)]
internal static class ToolModules
{
	private static Hook? menuManagerUpdateHook;

	private static Hook? menuManagerStartHook;

	private static Transform? loadingScreenImageTransform;

	private static Transform? headerImageTransform;

	private static Transform? loadingImageTransform;

	private static Sprite OriginalLogo;

	public static void InitHooks()
	{
		menuManagerUpdateHook = HookUtils.NewHook<MenuManager>("Update", typeof(ToolModules), "OnMenuManagerUpdate");
		menuManagerUpdateHook = HookUtils.NewHook<MenuManager>("Start", typeof(ToolModules), "OnMenuManagerStart");
	}

	private static void OnMenuManagerUpdate(Action<MenuManager> orig, MenuManager self)
	{
		orig(self);
		try
		{
			if (loadingScreenImageTransform != null)
			{
				Graphic[] componentsInChildren = ((Component)loadingScreenImageTransform).GetComponentsInChildren<Graphic>();
				foreach (Graphic val in componentsInChildren)
				{
					if (!((Object)(object)((Component)val).transform == (Object)(object)loadingScreenImageTransform))
					{
						((Behaviour)val).enabled = false;
					}
				}
			}
			if (headerImageTransform != null)
			{
				Graphic[] componentsInChildren2 = ((Component)headerImageTransform).GetComponentsInChildren<Graphic>();
				foreach (Graphic val2 in componentsInChildren2)
				{
					if (!((Object)(object)((Component)val2).transform == (Object)(object)headerImageTransform))
					{
						((Behaviour)val2).enabled = false;
					}
				}
			}
			if (LiquidStainRemoverPlugin.disableLogoChanges.Value)
			{
				try
				{
					((Component)headerImageTransform).GetComponent<Image>().overrideSprite = LiquidStainRemoverPlugin.logo2;
				}
				catch (Exception)
				{
				}
				try
				{
					((Component)loadingImageTransform).GetComponent<Image>().sprite = LiquidStainRemoverPlugin.logo2;
					return;
				}
				catch (Exception)
				{
					throw;
				}
			}
		}
		catch (Exception)
		{
		}
	}

	private static void OnMenuManagerStart(Action<MenuManager> orig, MenuManager self)
	{
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			loadingScreenImageTransform = null;
			headerImageTransform = null;
			loadingImageTransform = null;
			if (loadingScreenImageTransform == null)
			{
				loadingScreenImageTransform = ((Component)self).transform.parent.Find("MenuContainer/LoadingScreen/Image");
			}
			if (headerImageTransform == null)
			{
				headerImageTransform = ((Component)self).transform.parent.Find("MenuContainer/MainButtons");
				RectTransform[] componentsInChildren = ((Component)headerImageTransform).GetComponentsInChildren<RectTransform>();
				foreach (RectTransform val in componentsInChildren)
				{
					if (((Component)val).GetComponents<Component>().Length == 3 && (Object)(object)((Component)val).gameObject != (Object)(object)((Component)headerImageTransform).gameObject && Object.op_Implicit((Object)(object)((Component)val).GetComponent<RectTransform>()) && Object.op_Implicit((Object)(object)((Component)val).GetComponent<CanvasRenderer>()) && Object.op_Implicit((Object)(object)((Component)val).GetComponent<Image>()))
					{
						headerImageTransform = ((Component)val).gameObject.transform;
						break;
					}
				}
			}
			if (loadingImageTransform == null)
			{
				loadingImageTransform = ((Component)self).transform.parent.Find("MenuContainer/LoadingScreen/Image");
			}
		}
		catch
		{
		}
		orig(self);
		Component[] components = ((Component)self).GetComponents<Component>();
		foreach (Component val2 in components)
		{
			if (((object)val2).GetType().ToString() != "UnityEngine.Transform" && ((object)val2).GetType().ToString() != "MenuManager" && ((object)val2).GetType().ToString() != "UnityEngine.AudioSource")
			{
				((Behaviour)val2).enabled = false;
			}
		}
	}
}
namespace Utils
{
	internal static class HookUtils
	{
		private const BindingFlags DefaultFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private const BindingFlags StaticFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		public static Hook NewHook<TTarget, TDest>(string targetMethodName, string destMethodName, TDest instance)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			MethodInfo method = typeof(TTarget).GetMethod(targetMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			MethodInfo method2 = typeof(TDest).GetMethod(destMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			return new Hook((MethodBase)method, method2, (object)instance);
		}

		public static Hook NewHook<TTarget>(string targetMethodName, MethodInfo destMethod)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			MethodInfo method = typeof(TTarget).GetMethod(targetMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			return new Hook((MethodBase)method, destMethod);
		}

		public static Hook NewHook<TTarget>(string targetMethodName, Type destType, string destMethodName)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			MethodInfo method = typeof(TTarget).GetMethod(targetMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			MethodInfo method2 = destType.GetMethod(destMethodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			return new Hook((MethodBase)method, method2);
		}

		public static ILHook NewILHook<TTarget>(string targetMethodName, Manipulator manipulator)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			MethodInfo method = typeof(TTarget).GetMethod(targetMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			return new ILHook((MethodBase)method, manipulator);
		}
	}
}