Decompiled source of V2 Plastic Chair v2.0.2

plugins/plastic-chair/Fuck Levi.dll

Decompiled a year ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
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 PluginConfig.API;
using PluginConfig.API.Decorators;
using PluginConfig.API.Functionals;
using UnityEngine;
using UnityEngine.ProBuilder;
using UnityEngine.SceneManagement;

[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 = "")]
[assembly: AssemblyCompany("Fuck Levi")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("haha laugh")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Fuck Levi")]
[assembly: AssemblyTitle("Fuck Levi")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace FuckLevi
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Fuck Levi";

		public const string PLUGIN_NAME = "Fuck Levi";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace PlasticChair
{
	[BepInPlugin("crash.ultrakill.plasticchair", "Plastic Chair", "1.0.0")]
	[BepInProcess("ULTRAKILL.exe")]
	public class PlasticChair : BaseUnityPlugin
	{
		public static string modlocat;

		public static ManualLogSource Cl;

		public static PlasticChair LP;

		private static PluginConfigurator config;

		public const string Name = "Plastic Chair";

		public const string Version = "1.0.0";

		public const string GUID = "crash.ultrakill.plasticchair";

		public static List<AssetBundle> UltraChair = new List<AssetBundle>();

		public static List<ButtonField> Buttons = new List<ButtonField>();

		public static int Selected = 2;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("org.Crash.FuckLevi");
			val.PatchAll(Assembly.GetExecutingAssembly());
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin crash.ultrakill.plasticchair is loaded!");
			config = PluginConfigurator.Create("Plastic Chair", "crash.ultrakill.plasticchair");
			config.SetIconWithURL("file://" + Path.Combine(ModPath(), "icon.png"));
			modlocat = ModPath();
			Cl = ((BaseUnityPlugin)this).Logger;
			LoadPrefabs();
			MakeButtons();
			LoadLastSelected();
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		public static void LoadLastSelected()
		{
			int @int = MonoSingleton<PrefsManager>.Instance.GetInt("chairStorage", 2);
			if ((Object)(object)UltraChair.ElementAtOrDefault(@int) == (Object)null)
			{
				Selected = 0;
				MonoSingleton<PrefsManager>.Instance.SetInt("chairStorage", Selected);
			}
			else
			{
				Selected = @int;
				MonoSingleton<PrefsManager>.Instance.SetInt("chairStorage", Selected);
			}
			((ConfigField)Buttons[Selected]).displayName = addSelected(((ConfigField)Buttons[Selected]).displayName);
			Cl.LogInfo((object)("Selected " + @int));
		}

		public static string addSelected(string s)
		{
			string text = s.Replace(" [SELECTED]", "");
			return text + " [SELECTED]";
		}

		public static string removeSelected(string s)
		{
			return s.Replace(" [SELECTED]", "");
		}

		public static void LoadPrefabs()
		{
			DirectoryInfo directoryInfo = new DirectoryInfo(ChairPath());
			FileInfo[] files = directoryInfo.GetFiles();
			FileInfo[] array = files;
			foreach (FileInfo fileInfo in array)
			{
				UltraChair.Add(AssetBundle.LoadFromFile(Path.Combine(ChairPath(), fileInfo.Name)));
			}
		}

		public static void MakeButtons()
		{
			//IL_0018: 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_0041: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			new ConfigHeader(config.rootPanel, "Chairs", 24);
			int num = 1;
			int lastSelected = 0;
			ButtonField val = new ButtonField(config.rootPanel, "Default", "crash.ultrakill.plasticchair");
			Buttons.Add(val);
			val.onClick += (OnClick)delegate
			{
				lastSelected = Selected;
				Selected = 0;
				MonoSingleton<PrefsManager>.Instance.SetInt("chairStorage", Selected);
				Cl.LogInfo((object)("Selected " + Selected));
				((ConfigField)Buttons[Selected]).displayName = addSelected(((ConfigField)Buttons[Selected]).displayName);
				if (lastSelected != Selected)
				{
					((ConfigField)Buttons[lastSelected]).displayName = removeSelected(((ConfigField)Buttons[lastSelected]).displayName);
				}
			};
			foreach (AssetBundle item in UltraChair)
			{
				int i = num;
				ButtonField val2 = new ButtonField(config.rootPanel, CreateNameProper(((Object)item).name), "crash.ultrakill.plasticchair");
				Buttons.Add(val2);
				val2.onClick += (OnClick)delegate
				{
					lastSelected = Selected;
					Selected = i;
					MonoSingleton<PrefsManager>.Instance.SetInt("chairStorage", Selected);
					Cl.LogInfo((object)("Selected " + Selected));
					((ConfigField)Buttons[Selected]).displayName = addSelected(((ConfigField)Buttons[Selected]).displayName);
					if (lastSelected != Selected)
					{
						((ConfigField)Buttons[lastSelected]).displayName = removeSelected(((ConfigField)Buttons[lastSelected]).displayName);
					}
				};
				num++;
			}
		}

		public static string CreateNameProper(string s)
		{
			string text = s;
			TextInfo textInfo = new CultureInfo("en-US", useUserOverride: false).TextInfo;
			text = text.Replace("_", " ");
			return textInfo.ToTitleCase(text);
		}

		public static string GameDirectory()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			string text = Application.dataPath;
			if ((int)Application.platform == 1)
			{
				text = Utility.ParentDirectory(text, 2);
			}
			else if ((int)Application.platform == 2)
			{
				text = Utility.ParentDirectory(text, 1);
			}
			return text;
		}

		public static string ModDirectory()
		{
			return Path.Combine(GameDirectory(), "BepInEx", "plugins");
		}

		public static string ModPath()
		{
			return Assembly.GetCallingAssembly().Location.Substring(0, Assembly.GetCallingAssembly().Location.LastIndexOf(Path.DirectorySeparatorChar));
		}

		public static string ChairPath()
		{
			return Path.Combine(ModPath(), "Chairs");
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			if (Selected == 0)
			{
				return;
			}
			foreach (GameObject item in GetAllObjectsInScene())
			{
				ProBuilderMesh[] components = item.GetComponents<ProBuilderMesh>();
				foreach (ProBuilderMesh val in components)
				{
					if (((Object)((Component)val).gameObject).name == "Throne")
					{
						Cl.LogInfo((object)"Found");
						ProBuilderMesh[] componentsInChildren = ((Component)val).GetComponentsInChildren<ProBuilderMesh>();
						foreach (ProBuilderMesh val2 in componentsInChildren)
						{
							val2.Clear();
							val2.Rebuild();
							val2.Refresh((RefreshMask)31);
						}
						val.Clear();
						val.Rebuild();
						val.Refresh((RefreshMask)31);
						GameObject val3 = UltraChair[Selected - 1].LoadAsset<GameObject>("Ultra_LawnChair");
						Quaternion val4 = Quaternion.Euler(-90f, 0f, -90f);
						Vector3 position = ((Component)val).gameObject.transform.position;
						position.z -= 2.71f;
						GameObject val5 = Object.Instantiate<GameObject>(val3, position, val4, ((Component)val).gameObject.transform);
						val5.transform.localScale = new Vector3(0.9f, 0.9f, 0.9f);
					}
				}
			}
		}

		private static List<GameObject> GetAllObjectsInScene()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Invalid comparison between Unknown and I4
			List<GameObject> list = new List<GameObject>();
			GameObject[] array = Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[];
			foreach (GameObject val in array)
			{
				if ((int)((Object)val).hideFlags <= 0)
				{
					list.Add(val);
				}
			}
			return list;
		}
	}
}