Decompiled source of PaApi v1.0.0

plugins/PaApi.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Events;
using UnityEngine.Localization;
using UnityEngine.Localization.PropertyVariants.TrackedProperties;
using UnityEngine.Localization.Settings;
using UnityEngine.Localization.Tables;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;
using VGFunctions;

[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("PaApi")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Example Custom Trigger")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+6849495d38226770d50213add399af3dfd0d30dd")]
[assembly: AssemblyProduct("PaApi")]
[assembly: AssemblyTitle("PaApi")]
[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 PaApi
{
	public static class EventHelper
	{
		public static T GetEvent<T>(this object target, string eventName) where T : Delegate
		{
			Type type = target.GetType();
			FieldInfo field = type.GetField(eventName, BindingFlags.Instance | BindingFlags.NonPublic);
			return (T)field.GetValue(target);
		}

		public static HitDelegate GetHitEvent(this VGPlayer player)
		{
			return ((object)player).GetEvent<HitDelegate>("HitEvent");
		}

		public static DeathDelegate GetDeathEvent(this VGPlayer player)
		{
			return ((object)player).GetEvent<DeathDelegate>("DeathEvent");
		}
	}
	public class PaApiTableProvider : ITableProvider
	{
		public AsyncOperationHandle<TTable> ProvideTableAsync<TTable>(string tableCollectionName, Locale locale) where TTable : LocalizationTable
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			if (typeof(TTable) == typeof(StringTable) && (tableCollectionName == "me.ytarame.PaApi" || SettingsHelper.ModSettingsDefinitions.ContainsKey(tableCollectionName)))
			{
				StringTable val = ScriptableObject.CreateInstance<StringTable>();
				((LocalizationTable)val).SharedData = ScriptableObject.CreateInstance<SharedTableData>();
				((LocalizationTable)val).SharedData.TableCollectionName = tableCollectionName;
				((LocalizationTable)val).LocaleIdentifier = locale.Identifier;
				return Addressables.ResourceManager.CreateCompletedOperation<TTable>((TTable)(object)((val is TTable) ? val : null), (string)null);
			}
			return default(AsyncOperationHandle<TTable>);
		}
	}
	[HarmonyPatch(typeof(ShowChangeLog))]
	internal static class UiPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void PreStart()
		{
			SettingsHelper.SetupMenu();
		}
	}
	[HarmonyPatch(typeof(SettingsManager))]
	internal static class SettingsPatch
	{
		[HarmonyPatch("UpdateSettingsFile")]
		[HarmonyPostfix]
		private static void PostSave()
		{
			SettingsHelper.Save();
		}
	}
	[HarmonyPatch(typeof(UI_Slider))]
	internal static class SliderPatch
	{
		[HarmonyPatch("GetWidthOfBar")]
		[HarmonyPrefix]
		private static bool PreGetWidth(UI_Slider __instance, ref int __result)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			if (__instance.Values.Length != 0)
			{
				__result = __instance.Values.Length;
				if ((int)__instance.Type == 1)
				{
					__result--;
				}
				return false;
			}
			float num = __instance.VisualRange.y - __instance.VisualRange.x;
			__result = (((double)num > 1.0) ? Mathf.RoundToInt(num) : Mathf.RoundToInt(num * 10f));
			return false;
		}

		[HarmonyPatch("UpdateTextValue")]
		[HarmonyPrefix]
		private static bool PreUpdateValueText(UI_Slider __instance)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Invalid comparison between Unknown and I4
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			((Component)__instance.ValueText).gameObject.SetActive(__instance.ShowValue);
			if (!__instance.ShowValue)
			{
				return false;
			}
			if (__instance.Values.Length != 0)
			{
				int num = __instance.GetWidthOfBar();
				if ((int)__instance.Type == 0)
				{
					num--;
				}
				int num2 = Mathf.CeilToInt(Mathf.Clamp(LSMath.SuperLerp(__instance.Range.x, __instance.Range.y, 0f, (float)num, __instance.Value), 0f, (float)(__instance.Values.Length - 1)));
				if (num2 < 0)
				{
					num2 = 0;
				}
				if (num2 >= __instance.Values.Length)
				{
					num2 = __instance.Values.Length - 1;
				}
				string text = __instance.Values[num2];
				if (text.Contains("$"))
				{
					try
					{
						text = text.Replace("$", "");
						text = LocalizationSettings.StringDatabase.GetLocalizedString(TableReference.op_Implicit("General UI"), TableEntryReference.op_Implicit(text), LocalizationSettings.SelectedLocale, (FallbackBehavior)0, Array.Empty<object>());
					}
					catch
					{
						text = text.Replace("$", "");
					}
				}
				SingletonBase<UIStateManager>.Inst.RefreshTextCache(__instance.ValueText, text);
			}
			else
			{
				SingletonBase<UIStateManager>.Inst.RefreshTextCache(__instance.ValueText, __instance.Value.ToString("f1"));
			}
			return false;
		}
	}
	[BepInPlugin("me.ytarame.PaApi", "PaApi", "1.0.0")]
	[BepInProcess("Project Arrhythmia.exe")]
	internal class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private Harmony _harmony;

		public const string Guid = "me.ytarame.PaApi";

		private const string Name = "PaApi";

		private const string Version = "1.0.0";

		private void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("me.ytarame.PaApi");
			_harmony.PatchAll();
			((LocalizedDatabase<StringTable, StringTableEntry>)(object)LocalizationSettings.StringDatabase).TableProvider = (ITableProvider)(object)new PaApiTableProvider();
			Logger.LogInfo((object)"Plugin me.ytarame.PaApi is loaded!");
		}
	}
	public static class SettingsHelper
	{
		public class SettingsBuilder
		{
			[CompilerGenerated]
			[DebuggerBrowsable(DebuggerBrowsableState.Never)]
			private string <guid>P;

			[CompilerGenerated]
			[DebuggerBrowsable(DebuggerBrowsableState.Never)]
			private Color <color>P;

			[CompilerGenerated]
			[DebuggerBrowsable(DebuggerBrowsableState.Never)]
			private int <residingPage>P;

			private Transform _settingsPanel;

			private int _itemCount;

			private int _pageCount;

			public SettingsBuilder(string guid, Transform settingsPanel, Color color, int residingPage)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				<guid>P = guid;
				<color>P = color;
				<residingPage>P = residingPage;
				_settingsPanel = settingsPanel;
				_itemCount = 0;
				_pageCount = 0;
				base..ctor();
			}

			public void EndPage()
			{
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
				if (_itemCount != 0)
				{
					if (_pageCount == 0)
					{
						RectTransform val = AddPageSwapButtons(_settingsPanel.parent.GetChild(0), _settingsBook, _modPage, null, <guid>P + " page 1");
						val.pivot = new Vector2(0f, 0.5f);
						val.anchorMin = Vector2.zero;
						val.anchorMax = Vector2.up;
						val.anchoredPosition = new Vector2(0f, -135f);
						val.sizeDelta = new Vector2(372f, 80f);
					}
					else
					{
						SetupSwapPageButtons($"{<guid>P} page {_pageCount - 1}", $"{<guid>P} page {_pageCount + 1}");
					}
					_itemCount = 0;
					CreateNewModSettingsPage(_settingsPanel.parent, ++_pageCount);
				}
			}

			private void CheckPageEnd()
			{
				if (_itemCount >= 10)
				{
					EndPage();
				}
				_itemCount++;
			}

			internal void Finished()
			{
				if (_pageCount != 0)
				{
					SetupSwapPageButtons($"{<guid>P} page {_pageCount - 1}", null);
				}
			}

			public void Label(string label)
			{
				CheckPageEnd();
				TextMeshProUGUI componentInChildren = Object.Instantiate<GameObject>(_labelPrefab, _settingsPanel).GetComponentInChildren<TextMeshProUGUI>();
				UI_Text component = ((Component)((TMP_Text)componentInChildren).transform.parent).GetComponent<UI_Text>();
				_modPage.SubElements.Add((UIElement)(object)component);
				((TMP_Text)componentInChildren).text = label;
				SingletonBase<UIStateManager>.Inst.RefreshTextCache(componentInChildren, label);
				((UIElement)(object)component).SetLocalization(componentInChildren, <guid>P, label, label);
			}

			public void Spacer()
			{
				CheckPageEnd();
				Object.Instantiate<GameObject>(_spacerPrefab, _settingsPanel);
			}

			public void Toggle(string label, ConfigEntry<bool> config, Action<bool> callback = null)
			{
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
				CheckPageEnd();
				UI_Toggle component = Object.Instantiate<GameObject>(_togglePrefab, _settingsPanel).GetComponent<UI_Toggle>();
				component.Value = config.Value;
				component.DataID = null;
				((TMP_Text)component.ToggleLabel).text = label;
				component.OnValueChanged.AddListener((UnityAction<bool>)delegate(bool x)
				{
					config.Value = x;
					callback?.Invoke(x);
				});
				((TMP_Text)component.ToggleLabel).text = label;
				SingletonBase<UIStateManager>.inst.RefreshTextCache(component.ToggleLabel, label);
				_modPage.SubElements.Add((UIElement)(object)component);
				((UIElement)(object)component).SetLocalization(component.ToggleLabel, <guid>P, label, label);
				component.OverrideNormalColor = <color>P;
				callback?.Invoke(config.Value);
			}

			public void Slider(string label, ConfigEntry<int> config, VisualType visualType, params string[] values)
			{
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				Slider(label, config.Value, 1f, delegate(float f)
				{
					config.Value = (int)f;
				}, visualType, values);
			}

			public void Slider(string label, float changeAmount, ConfigEntry<float> config, VisualType visualType, params string[] values)
			{
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				Slider(label, config.Value, changeAmount, delegate(float f)
				{
					config.Value = f;
				}, visualType, values);
			}

			public void Slider(string label, ConfigEntry<int> config, VisualType visualType, Vector2 range)
			{
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				Slider(label, config.Value, 1f, delegate(float f)
				{
					config.Value = (int)f;
				}, visualType, range);
			}

			public void Slider(string label, float changeAmount, ConfigEntry<float> config, VisualType visualType, Vector2 range)
			{
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				Slider(label, config.Value, changeAmount, delegate(float f)
				{
					config.Value = f;
				}, visualType, range);
			}

			public void Slider(string label, float value, float changeAmount, UnityAction<float> callback, VisualType visualType, params string[] values)
			{
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				CheckPageEnd();
				UI_Slider component = Object.Instantiate<GameObject>(_sliderPrefab, _settingsPanel).GetComponent<UI_Slider>();
				component.Values = values;
				component.Range = new Vector2(0f, (float)(values.Length - 1));
				component.VisualRange = component.Range;
				Internal_InstantiateSlider(component, label, value, changeAmount, callback, visualType);
			}

			public void Slider(string label, float value, float changeAmount, UnityAction<float> callback, VisualType visualType, Vector2 range)
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				CheckPageEnd();
				UI_Slider component = Object.Instantiate<GameObject>(_sliderPrefab, _settingsPanel).GetComponent<UI_Slider>();
				component.Range = range;
				component.VisualRange = range;
				Internal_InstantiateSlider(component, label, value, changeAmount, callback, visualType);
			}

			private void Internal_InstantiateSlider(UI_Slider slider, string label, float value, float changeAmount, UnityAction<float> callback, VisualType visualType)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Unknown result type (might be due to invalid IL or missing references)
				slider.DataID = null;
				slider.DataIDType = (DataType)3;
				slider.Value = value;
				((TMP_Text)slider.Label).text = label;
				slider.ChangeAmount = changeAmount;
				slider.Type = visualType;
				slider.OnValueChanged.AddListener(callback);
				((UIElement)slider).originalNonLocalizedText.Clear();
				SingletonBase<UIStateManager>.inst.RefreshTextCache(slider.Label, label);
				_modPage.SubElements.Add((UIElement)(object)slider);
				((UIElement)(object)slider).SetLocalization(slider.Label, <guid>P, label, label);
				((Graphic)slider.CenterText).color = <color>P;
				callback?.Invoke(value);
			}

			private void CreateNewModSettingsPage(Transform panel, int page)
			{
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e8: Expected O, but got Unknown
				//IL_017d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0187: Expected O, but got Unknown
				_settingsPanel = Object.Instantiate<Transform>(panel, ((Component)_settingsBook).transform).Find("Right");
				((Object)_settingsPanel.parent).name = $"{<guid>P}  page {page}";
				for (int i = 0; i < _settingsPanel.childCount; i++)
				{
					Object.Destroy((Object)(object)((Component)_settingsPanel.GetChild(i)).gameObject);
				}
				_modPage = new Page
				{
					_ID = $"{<guid>P} page {page}",
					PageContainer = ((Component)_settingsPanel.parent).gameObject,
					SubElements = new List<UIElement>(1) { (UIElement)(object)((Component)_settingsPanel.parent.GetChild(0).GetChild(0)).GetComponent<UI_Button>() }
				};
				_settingsBook.Pages.Add(_modPage);
				UI_Text component = ((Component)_settingsPanel.parent.GetChild(0).GetChild(1)).GetComponent<UI_Text>();
				_modPage.SubElements.Add((UIElement)(object)component);
				UI_Text component2 = ((Component)_settingsPanel.parent.GetChild(2)).GetComponent<UI_Text>();
				_modPage.SubElements.Add((UIElement)(object)component2);
				MultiElementButton component3 = ((Component)_settingsPanel.parent.GetChild(0).GetChild(0)).GetComponent<MultiElementButton>();
				((UnityEvent)((Button)component3).onClick).AddListener((UnityAction)delegate
				{
					_settingsBook.ForceSwapPage($"PaApi.ModSettings.{<residingPage>P}");
				});
			}

			private void SetupSwapPageButtons(string leftPage, string rightPage)
			{
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b4: Expected O, but got Unknown
				//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cc: Expected O, but got Unknown
				//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Expected O, but got Unknown
				//IL_0105: Unknown result type (might be due to invalid IL or missing references)
				//IL_010f: Expected O, but got Unknown
				Transform child = _settingsPanel.parent.GetChild(0).GetChild(2);
				MultiElementButton component = ((Component)child.GetChild(0)).GetComponent<MultiElementButton>();
				MultiElementButton component2 = ((Component)child.GetChild(1)).GetComponent<MultiElementButton>();
				UI_Button item = (UI_Button)(object)(component.uiElement = (UIElement)(object)((Component)component).GetComponent<UI_Button>());
				UI_Button item2 = (UI_Button)(object)(component2.uiElement = (UIElement)(object)((Component)component2).GetComponent<UI_Button>());
				_modPage.SubElements.Add((UIElement)(object)item);
				_modPage.SubElements.Add((UIElement)(object)item2);
				if (string.IsNullOrEmpty(leftPage))
				{
					component.LockButtonState(true);
				}
				else
				{
					((Button)component).onClick = new ButtonClickedEvent();
					((UnityEvent)((Button)component).onClick).AddListener((UnityAction)delegate
					{
						_settingsBook.ForceSwapPage(leftPage);
					});
				}
				if (string.IsNullOrEmpty(rightPage))
				{
					component2.LockButtonState(true);
					return;
				}
				((Button)component2).onClick = new ButtonClickedEvent();
				((UnityEvent)((Button)component2).onClick).AddListener((UnityAction)delegate
				{
					_settingsBook.ForceSwapPage(rightPage);
				});
			}
		}

		internal struct SettingsDefinition
		{
			public string Name;

			public Color Color;

			public ConfigFile File;

			public Action<SettingsBuilder> SettingsBuilder;

			public SettingsDefinition(string name, Color color, ConfigFile file, Action<SettingsBuilder> settingsBuilder)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				Name = name;
				Color = color;
				File = file;
				SettingsBuilder = settingsBuilder;
			}
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__16_0;

			internal void <CreateSettingsListPage>b__16_0()
			{
				_settingsBook.ForceSwapPage("Blank");
			}
		}

		private static Page _modSettingsPage;

		private static Page _modPage;

		private static UI_Book _settingsBook;

		private static Transform _settingTabButtonPrefab;

		private static GameObject _sliderPrefab;

		private static GameObject _togglePrefab;

		private static GameObject _labelPrefab;

		private static GameObject _spacerPrefab;

		internal static readonly Dictionary<string, SettingsDefinition> ModSettingsDefinitions = new Dictionary<string, SettingsDefinition>();

		private static readonly Color DefaultColor = new Color(0f, 0.6824f, 0.9373f, 1f);

		private static Transform _blankPage;

		public static void RegisterModSettings(string modGuid, string SettingsName, Color? color, ConfigFile file, Action<SettingsBuilder> SettingsBuilder)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (ModSettingsDefinitions.ContainsKey(modGuid))
			{
				Plugin.Logger.LogFatal((object)("Tried to register mod with GUID " + modGuid + " more than once! This is not necessary."));
			}
			else
			{
				ModSettingsDefinitions.Add(modGuid, new SettingsDefinition(SettingsName, (Color)(((??)color) ?? DefaultColor), file, SettingsBuilder));
			}
		}

		internal static void SetupMenu()
		{
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Expected O, but got Unknown
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Expected O, but got Unknown
			_settingTabButtonPrefab = GameObject.Find("Canvas/Window/Content/Settings/Blank").transform.GetChild(0).GetChild(0);
			if (!Object.op_Implicit((Object)(object)_settingTabButtonPrefab))
			{
				Plugin.Logger.LogError((object)"No settings tab found, SetupMenu was called at a incorrect time or scene changed");
				return;
			}
			_settingsBook = ((Component)_settingTabButtonPrefab.parent.parent.parent).GetComponent<UI_Book>();
			Transform val = ((Component)_settingsBook).transform.Find("Audio/Right");
			_sliderPrefab = ((Component)val.Find("Music")).gameObject;
			_togglePrefab = ((Component)val.Find("Checkpoint SFX")).gameObject;
			_labelPrefab = ((Component)val.Find("General Title")).gameObject;
			_spacerPrefab = ((Component)val.Find("spacer")).gameObject;
			GameObject val2 = Object.Instantiate<GameObject>(((Component)_settingTabButtonPrefab.GetChild(1)).gameObject, _settingTabButtonPrefab);
			((Object)val2).name = "Mod Settings";
			MultiElementButton component = val2.GetComponent<MultiElementButton>();
			((Button)component).onClick = new ButtonClickedEvent();
			UI_Button modUiButton = val2.GetComponent<UI_Button>();
			((UnityEvent)((Button)component).onClick).AddListener((UnityAction)delegate
			{
				_settingsBook.ForceSwapPage("PaApi.ModSettings.0");
				modUiButton.OnClick();
			});
			((TMP_Text)modUiButton.Text).text = "Mod Settings";
			SingletonBase<UIStateManager>.Inst.RefreshTextCache(modUiButton.Text, "Mod Settings");
			((UIElement)(object)modUiButton).SetLocalization(modUiButton.Text, "me.ytarame.PaApi", "mod settings", "Mod Settings");
			((Component)((Component)_settingsBook).transform.parent.parent.parent).GetComponent<UI_Book>().Pages[6].SubElements.Add((UIElement)(object)modUiButton);
			_blankPage = ((Component)_settingsBook).transform.Find("Blank");
			UI_Text component2 = ((Component)_blankPage.GetChild(3)).GetComponent<UI_Text>();
			((TMP_Text)component2.Text).text = "▒\n▒▒<space=32px>▒\n▒▓▒▒<space=64px>▒▒\n▒<space=32px>▒▒<space=32px>▒\n▒▒▒<space=32px>▒\n▒▒▓▒▒<space=64px>▒\n▒▒▒▒▓▒▒\n▒▒<space=64px>▒▒▒<space=64px>▒\n▓▒▒▓▒▒<space=32px>▒▒▒▒▒";
			Transform val3 = CreateSettingsListPage(0);
			int num = 0;
			int num2 = 0;
			foreach (KeyValuePair<string, SettingsDefinition> modSettingsDefinition in ModSettingsDefinitions)
			{
				num++;
				SetupModSettings(modSettingsDefinition, val3, num2);
				if (num % 5 == 0 && num + 1 <= ModSettingsDefinitions.Count)
				{
					if (num2 == 0)
					{
						AddPageSwapButtons(val3, _settingsBook, _modSettingsPage, null, "PaApi.ModSettings.1");
					}
					else if (num + 5 < ModSettingsDefinitions.Count)
					{
						AddPageSwapButtons(val3, _settingsBook, _modSettingsPage, $"PaApi.ModSettings.{num2 - 1}", $"PaApi.ModSettings.{num2 + 1}");
					}
					else
					{
						AddPageSwapButtons(val3, _settingsBook, _modSettingsPage, $"PaApi.ModSettings.{num2 - 1}", null);
					}
					num2++;
					val3 = CreateSettingsListPage(num2);
				}
			}
		}

		private static void SetupModSettings(KeyValuePair<string, SettingsDefinition> setting, Transform modSettingsButtonList, int page)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Expected O, but got Unknown
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Expected O, but got Unknown
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Expected O, but got Unknown
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			Transform val = Object.Instantiate<Transform>(((Component)_settingsBook).transform.Find("Audio"), ((Component)_settingsBook).transform).Find("Right");
			((Object)val.parent).name = setting.Key + " page 0";
			for (int i = 0; i < val.childCount; i++)
			{
				Object.Destroy((Object)(object)((Component)val.GetChild(i)).gameObject);
			}
			_modPage = new Page
			{
				_ID = setting.Key + " page 0",
				PageContainer = ((Component)val.parent).gameObject,
				SubElements = new List<UIElement>(1) { (UIElement)(object)((Component)val.parent.GetChild(0).GetChild(0)).GetComponent<UI_Button>() }
			};
			_settingsBook.Pages.Add(_modPage);
			MultiElementButton component = ((Component)val.parent.GetChild(0).GetChild(0)).GetComponent<MultiElementButton>();
			((Button)component).onClick = new ButtonClickedEvent();
			((UnityEvent)((Button)component).onClick).AddListener((UnityAction)delegate
			{
				_settingsBook.ForceSwapPage($"PaApi.ModSettings.{page}");
			});
			string text = ASCII.Get2HighASCII(setting.Value.Name + " Settings", 80, 3);
			UI_Text component2 = ((Component)val.parent.GetChild(0).GetChild(1)).GetComponent<UI_Text>();
			component2.Text = ((Component)component2).GetComponent<TextMeshProUGUI>();
			((TMP_Text)component2.Text).text = text;
			SingletonBase<UIStateManager>.Inst.RefreshTextCache(component2.Text, text);
			((UIElement)component2).originalNonLocalizedText[component2.Text] = text;
			_modPage.SubElements.Add((UIElement)(object)component2);
			UI_Text component3 = ((Component)val.parent.GetChild(2)).GetComponent<UI_Text>();
			((Graphic)component3.Text).color = setting.Value.Color;
			_modPage.SubElements.Add((UIElement)(object)component3);
			GameObject val2 = Object.Instantiate<GameObject>(((Component)_settingTabButtonPrefab.GetChild(1)).gameObject, modSettingsButtonList);
			MultiElementButton component4 = val2.GetComponent<MultiElementButton>();
			((Button)component4).onClick = new ButtonClickedEvent();
			UI_Button uiButton = val2.GetComponent<UI_Button>();
			((UnityEvent)((Button)component4).onClick).AddListener((UnityAction)delegate
			{
				_settingsBook.ForceSwapPage(setting.Key + " page 0");
				uiButton.OnClick();
			});
			((TMP_Text)uiButton.Text).text = setting.Value.Name;
			SingletonBase<UIStateManager>.Inst.RefreshTextCache(uiButton.Text, setting.Value.Name);
			((UIElement)(object)uiButton).SetLocalization(uiButton.Text, setting.Key, "PaApi Setting Tab Button", setting.Value.Name);
			_modSettingsPage.SubElements.Add((UIElement)(object)uiButton);
			SettingsBuilder settingsBuilder = new SettingsBuilder(setting.Key, val, setting.Value.Color, page);
			setting.Value.SettingsBuilder?.Invoke(settingsBuilder);
			settingsBuilder.Finished();
		}

		private static Transform CreateSettingsListPage(int page)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			Transform val = Object.Instantiate<Transform>(_blankPage, ((Component)_settingsBook).transform);
			Transform child = val.GetChild(0).GetChild(0);
			((Object)((Component)val).gameObject).name = $"PaApi Mod Settings {page}";
			for (int i = 1; i < child.childCount; i++)
			{
				Object.Destroy((Object)(object)((Component)child.GetChild(i)).gameObject);
			}
			MultiElementButton component = ((Component)child.GetChild(0)).GetComponent<MultiElementButton>();
			((Button)component).onClick = new ButtonClickedEvent();
			ButtonClickedEvent onClick = ((Button)component).onClick;
			object obj = <>c.<>9__16_0;
			if (obj == null)
			{
				UnityAction val2 = delegate
				{
					_settingsBook.ForceSwapPage("Blank");
				};
				<>c.<>9__16_0 = val2;
				obj = (object)val2;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			_modSettingsPage = new Page
			{
				_ID = $"PaApi.ModSettings.{page}",
				PageContainer = ((Component)val).gameObject,
				SubElements = new List<UIElement>(2)
				{
					(UIElement)(object)((Component)child.GetChild(0)).GetComponent<UI_Button>(),
					(UIElement)(object)((Component)val.GetChild(3)).GetComponent<UI_Text>()
				}
			};
			_settingsBook.Pages.Add(_modSettingsPage);
			return child;
		}

		private static RectTransform AddPageSwapButtons(Transform buttonList, UI_Book containingBook, Page containingPage, string leftPage, string rightPage)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Expected O, but got Unknown
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Expected O, but got Unknown
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Expected O, but got Unknown
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Expected O, but got Unknown
			GameObject val = new GameObject();
			val.transform.SetParent(buttonList, false);
			((Object)val).name = "Page Swap PaApi";
			FlexibleGridLayout val2 = val.AddComponent<FlexibleGridLayout>();
			val2.spacing = new Vector2(10f, 0f);
			((LayoutGroup)val2).childAlignment = (TextAnchor)4;
			Transform transform = ((Component)val2).transform;
			RectTransform val3 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			Vector2 sizeDelta = val3.sizeDelta;
			sizeDelta.y = 160f;
			val3.sizeDelta = sizeDelta;
			MultiElementButton component = Object.Instantiate<GameObject>(((Component)_settingTabButtonPrefab.GetChild(1)).gameObject, val.transform).GetComponent<MultiElementButton>();
			MultiElementButton component2 = Object.Instantiate<GameObject>(((Component)_settingTabButtonPrefab.GetChild(1)).gameObject, val.transform).GetComponent<MultiElementButton>();
			UI_Button val4 = (UI_Button)(object)(component.uiElement = (UIElement)(object)((Component)component).GetComponent<UI_Button>());
			UI_Button val5 = (UI_Button)(object)(component2.uiElement = (UIElement)(object)((Component)component2).GetComponent<UI_Button>());
			((Component)val4).transform.localScale = Vector3.one;
			((UIElement)(object)val4).SetLocalization(val4.Text, "me.ytarame.PaApi", "PrevPage", "prev");
			((Component)val5).transform.localScale = Vector3.one;
			((UIElement)(object)val5).SetLocalization(val5.Text, "me.ytarame.PaApi", "NextPage", "next");
			containingPage.SubElements.Add((UIElement)(object)val4);
			containingPage.SubElements.Add((UIElement)(object)val5);
			if (string.IsNullOrEmpty(leftPage))
			{
				component.LockButtonState(true);
			}
			else
			{
				((Button)component).onClick = new ButtonClickedEvent();
				((UnityEvent)((Button)component).onClick).AddListener((UnityAction)delegate
				{
					containingBook.ForceSwapPage(leftPage);
				});
			}
			if (string.IsNullOrEmpty(rightPage))
			{
				component2.LockButtonState(true);
			}
			else
			{
				((Button)component2).onClick = new ButtonClickedEvent();
				((UnityEvent)((Button)component2).onClick).AddListener((UnityAction)delegate
				{
					containingBook.ForceSwapPage(rightPage);
				});
			}
			return val3;
		}

		internal static void Save()
		{
			foreach (KeyValuePair<string, SettingsDefinition> modSettingsDefinition in ModSettingsDefinitions)
			{
				ConfigFile file = modSettingsDefinition.Value.File;
				if (file != null && !file.SaveOnConfigSet)
				{
					file.Save();
				}
			}
		}
	}
	public static class UIElementExtension
	{
		public static void SetLocalization(this UIElement element, TextMeshProUGUI text, string table, string entry, string value)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			element.InitGraphics();
			if (element.localizers.TryGetValue(text, out var value2))
			{
				ITrackedProperty obj = value2.TrackedObjects[0].TrackedProperties[0];
				LocalizedStringProperty val = (LocalizedStringProperty)(object)((obj is LocalizedStringProperty) ? obj : null);
				if (val != null)
				{
					val.LocalizedString = new LocalizedString(TableReference.op_Implicit(table), TableEntryReference.op_Implicit(entry));
					((DetailedLocalizationTable<StringTableEntry>)(object)((LocalizedDatabase<StringTable, StringTableEntry>)(object)LocalizationSettings.StringDatabase).GetTable(TableReference.op_Implicit(table), (Locale)null)).AddEntry(entry, value);
					return;
				}
			}
			Plugin.Logger.LogWarning((object)("Tried to set invalid locale for object [" + ((Object)element).name + "], entry [" + entry + "]"));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "PaApi";

		public const string PLUGIN_NAME = "PaApi";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}