Decompiled source of AtlyssPluginSettings v1.0.0

AtlyssPluginSettings.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("AtlyssPluginSettings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3906b35c6c4e41771f777c4924d97b2c414fdeef")]
[assembly: AssemblyProduct("AtlyssPluginSettings")]
[assembly: AssemblyTitle("AtlyssPluginSettings")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace AtlyssPluginSettings
{
	[BepInPlugin("net.portalsam.AtlyssPluginSettings", "PluginSettings", "1.0.0.0")]
	[BepInProcess("ATLYSS.exe")]
	public class PluginSettings : BaseUnityPlugin
	{
		internal static PluginSettings Instance;

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			Logger.LogInfo((object)"PluginSettings has been initialized!");
		}

		internal static ConfigFile GetConfig()
		{
			return ((BaseUnityPlugin)Instance).Config;
		}
	}
	internal static class SettingsManagerPatch
	{
		[HarmonyPatch(typeof(SettingsManager), "Start")]
		internal static class SettingsManagerStartPatch
		{
			private static GameObject? _dollySettingsMenuReference;

			private static GameObject? _cancelButtonReference;

			private static GameObject? _settingsHeaderReference;

			private static GameObject? _boolToggleReference;

			private static GameObject? _keyCodeReference;

			private static void Postfix(SettingsManager __instance)
			{
				//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_010e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0118: Expected O, but got Unknown
				//IL_0124: Unknown result type (might be due to invalid IL or missing references)
				//IL_012e: Expected O, but got Unknown
				//IL_0175: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
				SettingsManager __instance2 = __instance;
				KeybindButtons.Clear();
				_settingsMenuReference = GameObject.Find("_SettingsManager/Canvas_SettingsMenu");
				_dollySettingsMenuReference = GameObject.Find("_SettingsManager/Canvas_SettingsMenu/_dolly_settingsMenu");
				_cancelButtonReference = GameObject.Find("_SettingsManager/Canvas_SettingsMenu/_dolly_settingsMenu/Image_01/Button_cancelSettings");
				_inputSettingsTabReference = GameObject.Find("_SettingsManager/Canvas_SettingsMenu/_dolly_settingsMenu/_dolly_inputSettingsTab");
				_settingsHeaderReference = GameObject.Find("_SettingsManager/Canvas_SettingsMenu/_dolly_settingsMenu/_dolly_videoSettingsTab/_backdrop_videoSettings/Scroll View/Viewport/Content/_header_GameEffectSettings");
				_boolToggleReference = GameObject.Find("_SettingsManager/Canvas_SettingsMenu/_dolly_settingsMenu/_dolly_videoSettingsTab/_backdrop_videoSettings/Scroll View/Viewport/Content/_cell_proportionsToggle");
				_keyCodeReference = GameObject.Find("_SettingsManager/Canvas_SettingsMenu/_dolly_settingsMenu/_dolly_inputSettingsTab/_backdrop/Scroll View/Viewport/Content/_cell_keybinding_up");
				_resetButtonReference = GameObject.Find("_SettingsManager/Canvas_SettingsMenu/_dolly_settingsMenu/_dolly_inputSettingsTab/_backdrop/Scroll View/Viewport/Content/_cell_cameraSensitivity/Button_01");
				GameObject obj = Object.Instantiate<GameObject>(_cancelButtonReference, _dollySettingsMenuReference.transform, true);
				((Object)obj).name = "Button_pluginSettings";
				obj.transform.localPosition = new Vector3(-219f, -212f, 0f);
				obj.transform.localScale = new Vector3(1f, 1f, 1f);
				((Component)obj.transform.GetChild(0)).GetComponent<Text>().text = "Plugins";
				Button component = obj.GetComponent<Button>();
				component.onClick = new ButtonClickedEvent();
				((UnityEvent)component.onClick).AddListener((UnityAction)delegate
				{
					__instance2.Set_SettingMenuSelectionIndex(4);
				});
				_pluginSettingsTabReference = Object.Instantiate<GameObject>(_inputSettingsTabReference, _inputSettingsTabReference.transform.parent, true);
				((Object)_pluginSettingsTabReference).name = "_dolly_pluginSettingsTab";
				_pluginSettingsTabReference.transform.localPosition = new Vector3(1f, 1f, 1f);
				_pluginsContentReference = ((Component)_pluginSettingsTabReference.transform.Find("_backdrop/Scroll View/Viewport/Content")).gameObject;
				foreach (Transform item in _pluginsContentReference.transform)
				{
					Object.Destroy((Object)(object)((Component)item).gameObject);
				}
				_pluginSettingsMenuElement = _pluginSettingsTabReference.GetComponent<MenuElement>();
				SetupSettingsMenu();
				PluginSettings.Logger.LogInfo((object)"SettingsManager has been patched.");
			}

			private static void SetupSettingsMenu()
			{
				foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
				{
					ConfigFile config = pluginInfo.Value.Instance.Config;
					if (config.Keys.Count < 1)
					{
						continue;
					}
					CreateHeader(pluginInfo.Value.Metadata.Name);
					foreach (KeyValuePair<ConfigDefinition, ConfigEntryBase> item in ((object)config).GetType().GetProperty("Entries", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(config) as Dictionary<ConfigDefinition, ConfigEntryBase>)
					{
						if (item.Value.SettingType == typeof(bool))
						{
							CreateBool(item.Value, pluginInfo.Value);
						}
						else if (item.Value.SettingType == typeof(KeyCode))
						{
							CreateKeyCode(item.Value, pluginInfo.Value);
						}
						else
						{
							CreateField(item.Value, pluginInfo.Value);
						}
					}
				}
			}

			private static void CreateHeader(string headerName)
			{
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				GameObject obj = Object.Instantiate<GameObject>(_settingsHeaderReference, _pluginsContentReference.transform, true);
				((Object)obj).name = "_header_" + headerName;
				obj.transform.localScale = new Vector3(1f, 1f, 1f);
				((Component)obj.transform.GetChild(0)).GetComponent<Text>().text = headerName;
			}

			private static void CreateBool(ConfigEntryBase entry, PluginInfo plugin)
			{
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_0111: Unknown result type (might be due to invalid IL or missing references)
				//IL_012b: Unknown result type (might be due to invalid IL or missing references)
				//IL_013b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0145: Expected O, but got Unknown
				//IL_0157: Unknown result type (might be due to invalid IL or missing references)
				//IL_0161: Expected O, but got Unknown
				//IL_019c: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a6: Expected O, but got Unknown
				ConfigEntryBase entry2 = entry;
				PluginInfo plugin2 = plugin;
				GameObject val = Object.Instantiate<GameObject>(_boolToggleReference, _pluginsContentReference.transform, true);
				((Object)val).name = "_cell_" + entry2.Definition.Key;
				val.transform.localScale = new Vector3(1f, 1f, 1f);
				((Component)val.transform.GetChild(0)).GetComponent<Text>().text = entry2.Definition.Key;
				GameObject gameObject = ((Component)val.transform.GetChild(1)).gameObject;
				((Object)gameObject).name = "Toggle_" + entry2.Definition.Key;
				GameObject obj = Object.Instantiate<GameObject>(_resetButtonReference, val.transform, true);
				((Object)obj).name = "ResetButton";
				obj.transform.localScale = new Vector3(1f, 1f, 1f);
				obj.transform.localPosition = new Vector3(64f, 0f, 0f);
				obj.GetComponent<RectTransform>().sizeDelta = new Vector2(72f, 24f);
				Button component = obj.GetComponent<Button>();
				component.onClick = new ButtonClickedEvent();
				Toggle toggle = gameObject.GetComponent<Toggle>();
				toggle.onValueChanged = new ToggleEvent();
				Toggle obj2 = toggle;
				object boxedValue = entry2.BoxedValue;
				bool flag = default(bool);
				int num;
				if (boxedValue is bool)
				{
					flag = (bool)boxedValue;
					num = 1;
				}
				else
				{
					num = 0;
				}
				obj2.isOn = (byte)((uint)num & (flag ? 1u : 0u)) != 0;
				((UnityEvent)component.onClick).AddListener((UnityAction)delegate
				{
					Toggle obj3 = toggle;
					object defaultValue = entry2.DefaultValue;
					bool flag2 = default(bool);
					int num2;
					if (defaultValue is bool)
					{
						flag2 = (bool)defaultValue;
						num2 = 1;
					}
					else
					{
						num2 = 0;
					}
					obj3.isOn = (byte)((uint)num2 & (flag2 ? 1u : 0u)) != 0;
					entry2.BoxedValue = toggle.isOn;
					plugin2.Instance.Config.Save();
				});
				((UnityEvent<bool>)(object)toggle.onValueChanged).AddListener((UnityAction<bool>)delegate
				{
					entry2.BoxedValue = toggle.isOn;
					plugin2.Instance.Config.Save();
				});
			}

			private static void CreateKeyCode(ConfigEntryBase entry, PluginInfo plugin)
			{
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Expected O, but got Unknown
				//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_010d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0127: Unknown result type (might be due to invalid IL or missing references)
				//IL_0137: Unknown result type (might be due to invalid IL or missing references)
				//IL_0141: Expected O, but got Unknown
				//IL_017b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0180: Unknown result type (might be due to invalid IL or missing references)
				//IL_0187: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bd: Expected O, but got Unknown
				//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d3: Expected O, but got Unknown
				//IL_0186: Unknown result type (might be due to invalid IL or missing references)
				ConfigEntryBase entry2 = entry;
				PluginInfo plugin2 = plugin;
				GameObject val = Object.Instantiate<GameObject>(_keyCodeReference, _pluginsContentReference.transform, true);
				((Object)val).name = "_cell_keybinding_" + entry2.Definition.Key;
				val.transform.localScale = new Vector3(1f, 1f, 1f);
				((Component)val.transform.GetChild(0)).GetComponent<Text>().text = entry2.Definition.Key;
				GameObject buttonObject = ((Component)val.transform.GetChild(1)).gameObject;
				Button component = buttonObject.GetComponent<Button>();
				component.onClick = new ButtonClickedEvent();
				GameObject obj = Object.Instantiate<GameObject>(_resetButtonReference, val.transform, true);
				((Object)obj).name = "ResetButton";
				obj.transform.localScale = new Vector3(1f, 1f, 1f);
				obj.transform.localPosition = new Vector3(64f, 0f, 0f);
				obj.GetComponent<RectTransform>().sizeDelta = new Vector2(72f, 24f);
				Button component2 = obj.GetComponent<Button>();
				component2.onClick = new ButtonClickedEvent();
				Text keybindText = ((Component)buttonObject.transform.GetChild(0)).GetComponent<Text>();
				Text obj2 = keybindText;
				KeyCode val3 = (KeyCode)((entry2.BoxedValue is KeyCode val2) ? ((int)val2) : 0);
				obj2.text = ((object)(KeyCode)(ref val3)).ToString();
				KeybindButtons.Add(component);
				((UnityEvent)component.onClick).AddListener((UnityAction)delegate
				{
					((MonoBehaviour)PluginSettings.Instance).StartCoroutine(BindButtonCoroutine(buttonObject, keybindText, entry2, plugin2));
				});
				((UnityEvent)component2.onClick).AddListener((UnityAction)delegate
				{
					keybindText.text = entry2.DefaultValue.ToString();
					entry2.BoxedValue = entry2.DefaultValue;
					plugin2.Instance.Config.Save();
				});
			}

			private static void CreateField(ConfigEntryBase entry, PluginInfo plugin)
			{
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: 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_0127: Unknown result type (might be due to invalid IL or missing references)
				//IL_0131: Expected O, but got Unknown
				//IL_0170: Unknown result type (might be due to invalid IL or missing references)
				//IL_0175: Unknown result type (might be due to invalid IL or missing references)
				//IL_0187: Expected O, but got Unknown
				//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0211: Unknown result type (might be due to invalid IL or missing references)
				//IL_0272: Unknown result type (might be due to invalid IL or missing references)
				//IL_0291: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_030f: Unknown result type (might be due to invalid IL or missing references)
				//IL_032e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0376: Unknown result type (might be due to invalid IL or missing references)
				//IL_038f: Unknown result type (might be due to invalid IL or missing references)
				//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_03f1: Expected O, but got Unknown
				ConfigEntryBase entry2 = entry;
				PluginInfo plugin2 = plugin;
				GameObject val = Object.Instantiate<GameObject>(_keyCodeReference, _pluginsContentReference.transform, true);
				((Object)val).name = "_cell_input_" + entry2.Definition.Key;
				val.transform.localScale = new Vector3(1f, 1f, 1f);
				GameObject gameObject = ((Component)val.transform.GetChild(0)).gameObject;
				gameObject.GetComponent<Text>().text = entry2.Definition.Key;
				Object.Destroy((Object)(object)((Component)val.transform.GetChild(1)).gameObject);
				GameObject obj = Object.Instantiate<GameObject>(_resetButtonReference, val.transform, true);
				((Object)obj).name = "ResetButton";
				obj.transform.localScale = new Vector3(1f, 1f, 1f);
				obj.transform.localPosition = new Vector3(64f, 0f, 0f);
				obj.GetComponent<RectTransform>().sizeDelta = new Vector2(72f, 24f);
				Button component = obj.GetComponent<Button>();
				component.onClick = new ButtonClickedEvent();
				GameObject val2 = new GameObject("InputField", new Type[4]
				{
					typeof(RectTransform),
					typeof(CanvasRenderer),
					typeof(Image),
					typeof(InputField)
				})
				{
					layer = LayerMask.NameToLayer("UI")
				};
				val2.transform.SetParent(val.transform, true);
				val2.transform.localScale = new Vector3(1f, 1f, 1f);
				val2.transform.localPosition = new Vector3(187f, 0f, 0f);
				val2.GetComponent<RectTransform>().sizeDelta = new Vector2(156f, 20f);
				Image component2 = val2.GetComponent<Image>();
				((Graphic)component2).color = new Color(0.2f, 0.2f, 0.2f, 1f);
				component2.type = (Type)1;
				component2.sprite = val.GetComponent<Image>().sprite;
				InputField inputField = val2.GetComponent<InputField>();
				GameObject obj2 = Object.Instantiate<GameObject>(gameObject, val2.transform, true);
				obj2.layer = LayerMask.NameToLayer("UI");
				obj2.transform.localScale = new Vector3(1f, 1f, 1f);
				obj2.transform.localPosition = new Vector3(0f, 0f, 0f);
				((Object)obj2).name = "Text";
				Text component3 = obj2.GetComponent<Text>();
				component3.fontSize = 16;
				component3.text = "";
				obj2.GetComponent<RectTransform>().sizeDelta = new Vector2(142f, 20f);
				GameObject obj3 = Object.Instantiate<GameObject>(gameObject, val2.transform, true);
				obj3.layer = LayerMask.NameToLayer("UI");
				obj3.transform.localScale = new Vector3(1f, 1f, 1f);
				obj3.transform.localPosition = new Vector3(0f, 0f, 0f);
				((Object)obj3).name = "Placeholder";
				Text component4 = obj3.GetComponent<Text>();
				component4.fontSize = 16;
				component4.text = "Enter a value...";
				((Graphic)component4).color = new Color(1f, 1f, 1f, 0.35f);
				obj3.GetComponent<RectTransform>().sizeDelta = new Vector2(142f, 20f);
				inputField.textComponent = component3;
				inputField.placeholder = (Graphic)(object)component4;
				inputField.SetTextWithoutNotify(entry2.BoxedValue.ToString());
				inputField.MoveTextStart(true);
				((UnityEvent)component.onClick).AddListener((UnityAction)delegate
				{
					inputField.text = entry2.BoxedValue.ToString();
					entry2.BoxedValue = entry2.DefaultValue;
					plugin2.Instance.Config.Save();
				});
				((UnityEvent<string>)(object)inputField.onSubmit).AddListener((UnityAction<string>)delegate
				{
					bool flag = false;
					try
					{
						TypeConverter converter = TomlTypeConverter.GetConverter(entry2.SettingType);
						if (!TomlTypeConverter.CanConvert(entry2.SettingType))
						{
							return;
						}
						entry2.BoxedValue = converter.ConvertToObject(inputField.text, entry2.SettingType);
						flag = true;
						plugin2.Instance.Config.Save();
					}
					catch (Exception arg)
					{
						PluginSettings.Logger.LogWarning((object)$"Input String: \"{inputField.text}\" created exception: \n{arg}");
					}
					if (!flag)
					{
						inputField.text = "";
					}
				});
			}

			private static IEnumerator BindButtonCoroutine(GameObject buttonObject, Text bindButtonText, ConfigEntryBase configEntry, PluginInfo plugin)
			{
				if (_waitingForKey)
				{
					yield break;
				}
				KeyCode foundKey = (KeyCode)0;
				string oldText = bindButtonText.text;
				float keyTimer = 5f;
				while (buttonObject.activeSelf && _pluginSettingsTabReference.activeSelf && _settingsMenuReference.activeSelf)
				{
					_waitingForKey = true;
					foreach (Button keybindButton in KeybindButtons)
					{
						((Selectable)keybindButton).interactable = false;
					}
					KeyCode val = (KeyCode)0;
					foreach (KeyCode value in Enum.GetValues(typeof(KeyCode)))
					{
						if (Input.GetKeyDown(value))
						{
							val = value;
						}
					}
					if ((int)val == 27 || (int)val == 323)
					{
						break;
					}
					if ((int)val != 0)
					{
						foundKey = val;
						break;
					}
					keyTimer -= Time.deltaTime;
					bindButtonText.text = $"Press a key ({Mathf.Round(keyTimer)})";
					if (keyTimer <= 0f)
					{
						break;
					}
					yield return null;
				}
				_waitingForKey = false;
				if ((int)foundKey != 0)
				{
					bindButtonText.text = ((object)(KeyCode)(ref foundKey)).ToString();
					configEntry.BoxedValue = foundKey;
					plugin.Instance.Config.Save();
				}
				else
				{
					bindButtonText.text = oldText;
				}
				yield return (object)new WaitForSeconds(0.25f);
				foreach (Button keybindButton2 in KeybindButtons)
				{
					((Selectable)keybindButton2).interactable = true;
				}
			}
		}

		[HarmonyPatch(typeof(SettingsManager), "Set_SettingMenuSelectionIndex")]
		internal static class SettingsManagerSelectionPatch
		{
			private static void Finalizer(int _index)
			{
				if ((Object)(object)_pluginSettingsMenuElement != (Object)null)
				{
					_pluginSettingsMenuElement.isEnabled = _index == 4;
				}
			}
		}

		private static MenuElement? _pluginSettingsMenuElement;

		private static GameObject? _inputSettingsTabReference;

		private static GameObject? _pluginSettingsTabReference;

		private static GameObject? _pluginsContentReference;

		private static GameObject? _resetButtonReference;

		private static GameObject? _settingsMenuReference;

		private static readonly List<Button> KeybindButtons = new List<Button>();

		private static bool _waitingForKey;

		private const int Plugin = 4;
	}
}