Decompiled source of BetterEmotes v0.0.2

BepInEx/plugins/BetterEmotes.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BetterEmotes.Patches;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BetterEmotes")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterEmotes")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f25f779c-8d2d-4593-b297-cd63057db83c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BetterEmotes
{
	internal class BetterEmotesConfig
	{
		public static ConfigEntry<KeyCode> AlternativeEmoteKey;

		public static readonly Dictionary<EmoteContext, Dictionary<emoteDirections, EmoteMeanings[]>> RawCategoryBindings = new Dictionary<EmoteContext, Dictionary<emoteDirections, EmoteMeanings[]>>();

		public static ConfigEntry<EmoteMeanings>[] RawAltEmotes = new ConfigEntry<EmoteMeanings>[4];

		public static Dictionary<EmoteContext, EmoteMeanings[]> AlternativeEmotes = new Dictionary<EmoteContext, EmoteMeanings[]>();

		public static void BindConfig(ConfigFile config)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Expected I4, but got Unknown
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected I4, but got Unknown
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			AlternativeEmoteKey = config.Bind<KeyCode>("General", "AlternativeEmoteKey", (KeyCode)308, "Press this key for alternative Emotes.");
			emoteDirections[] array = (emoteDirections[])Enum.GetValues(typeof(emoteDirections));
			RawCategoryBindings.Clear();
			EmoteContext[] array2 = (EmoteContext[])Enum.GetValues(typeof(EmoteContext));
			for (int i = 0; i < array2.Length; i++)
			{
				EmoteContext val = array2[i];
				string text = ((object)(EmoteContext)(ref val)).ToString() ?? "";
				Dictionary<emoteDirections, EmoteMeanings[]> dictionary = new Dictionary<emoteDirections, EmoteMeanings[]>();
				for (int j = 0; j < 4; j++)
				{
					emoteDirections val2 = array[j];
					EmoteMeanings[] array3 = (EmoteMeanings[])(object)new EmoteMeanings[4];
					for (int k = 0; k < 4; k++)
					{
						EmoteMeanings value = config.Bind<EmoteMeanings>(text, $"{((object)(emoteDirections)(ref val2)).ToString()}.Slot{k}", (EmoteMeanings)17, $"Emote meaning for direction {val2}, slot {k} in context {val}").Value;
						array3[k] = (EmoteMeanings)(int)value;
					}
					dictionary[val2] = array3;
				}
				RawCategoryBindings[val] = dictionary;
			}
			EmoteContext[] array4 = (EmoteContext[])Enum.GetValues(typeof(EmoteContext));
			for (int l = 0; l < array4.Length; l++)
			{
				EmoteContext key = array4[l];
				EmoteMeanings[] array5 = (EmoteMeanings[])(object)new EmoteMeanings[4];
				for (int m = 0; m < 4; m++)
				{
					emoteDirections val3 = array[m];
					array5[m] = (EmoteMeanings)(int)config.Bind<EmoteMeanings>("Alternative " + ((object)(EmoteContext)(ref key)).ToString(), $"Slot_{m}", (EmoteMeanings)7, "Alternative Emotes").Value;
				}
				AlternativeEmotes[key] = array5;
			}
		}
	}
	internal class BetterEmotesDialogFactory
	{
		public static RectTransform CreateSubdialog(TabletOptionsScreen tabletOptionsScreen, string name = "BetterEmotesConfig")
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Expected O, but got Unknown
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: 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)
			if ((Object)(object)tabletOptionsScreen == (Object)null)
			{
				Debug.LogError((object)"[BetterEmotes] TabletOptionsScreen reference is null.");
				return null;
			}
			Transform child = ((Component)tabletOptionsScreen).transform.GetChild(1);
			RectTransform val = ((child != null) ? ((Component)child).GetComponent<RectTransform>() : null);
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)"[BetterEmotes] Could not locate valid parent RectTransform for subdialog.");
				return null;
			}
			GameObject val2 = new GameObject(name, new Type[1] { typeof(RectTransform) });
			RectTransform component = val2.GetComponent<RectTransform>();
			((Transform)component).SetParent((Transform)(object)val, false);
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.pivot = new Vector2(0.5f, 0.5f);
			component.anchoredPosition = Vector2.zero;
			component.sizeDelta = Vector2.zero;
			val2.SetActive(false);
			val2.AddComponent<VerticalLayoutGroup>();
			GameObject val3 = new GameObject("General", new Type[1] { typeof(RectTransform) });
			RectTransform component2 = val3.GetComponent<RectTransform>();
			((Transform)component2).SetParent(val2.transform, false);
			Transform child2 = ((Component)tabletOptionsScreen).transform.GetChild(1).GetChild(3).GetChild(0)
				.GetChild(1)
				.GetChild(10);
			GameObject val4 = Object.Instantiate<GameObject>(((Component)child2).gameObject);
			val4.transform.SetParent((Transform)(object)component2, false);
			val4.transform.position = new Vector3(val4.transform.position.x + 2f, val4.transform.position.y + 10.25f, 0f);
			((Component)val4.transform.GetChild(2)).gameObject.SetActive(false);
			((Component)val4.transform.GetChild(0)).gameObject.GetComponent<TabletTextLabel>().text = "Alt Emote Key";
			((Component)val4.transform.GetChild(0)).gameObject.GetComponent<TabletTextLabel>().Term = "betteremotes/optionskey";
			Object.Destroy((Object)(object)((Component)val4.transform.GetChild(1).GetChild(0)).GetComponent<TabletKeyboardBindingButton>());
			CustomTabletKeyboardBindingButton customTabletKeyboardBindingButton = ((Component)val4.transform.GetChild(1).GetChild(0)).gameObject.AddComponent<CustomTabletKeyboardBindingButton>();
			((TabletButton)customTabletKeyboardBindingButton).tracksCursors = true;
			return component;
		}
	}
	[BepInPlugin("BetterEmotes", "BetterEmotes", "0.0.2")]
	public class BetterEmotesPlugin : BaseUnityPlugin
	{
		private static Harmony harmony = new Harmony("BetterEmotes");

		internal static BetterEmotesPlugin instance;

		private void Awake()
		{
			instance = this;
			BetterEmotesConfig.BindConfig(((BaseUnityPlugin)this).Config);
			PatchAll();
		}

		private void Start()
		{
		}

		private void PatchAll()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Expected O, but got Unknown
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Expected O, but got Unknown
			harmony.Patch((MethodBase)AccessTools.Method(typeof(EmoteSystem), "SetEmoteContext", (Type[])null, (Type[])null), new HarmonyMethod(typeof(EmoteSystemPatch), "SetEmoteContextPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(EmoteSystem), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(EmoteSystemPatch), "StartPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(EmoteSystem), "Update", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(EmoteSystemPatch), "UpdatePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(TabletOptionsScreen), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(TabletOptionsScreenPatch), "StartPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(TabletOptionsScreen), "OnClickSwitchSetupControllers", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(TabletOptionsScreenPatch), "OnClickSwitchSetupControllersPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(TabletOptionsScreen), "OnPressBack", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(TabletOptionsScreenPatch), "OnPressBackPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(TabletOptionsScreen), "OnDestroy", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(TabletOptionsScreenPatch), "OnDestroyPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}
	internal class CustomTabletKeyboardBindingButton : TabletButton, InputReceiver
	{
		[CompilerGenerated]
		private sealed class <RegisterPickCursorsWhenReady>d__7 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public CustomTabletKeyboardBindingButton <>4__this;

			private PickCursor[] <cursors>5__1;

			private PickCursor[] <>s__2;

			private int <>s__3;

			private PickCursor <cursor>5__4;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <RegisterPickCursorsWhenReady>d__7(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<cursors>5__1 = null;
				<>s__2 = null;
				<cursor>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Expected O, but got Unknown
				//IL_008c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<cursors>5__1 = null;
					goto IL_0061;
				case 1:
					<>1__state = -1;
					goto IL_0061;
				case 2:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 3;
					return true;
				case 3:
					{
						<>1__state = -1;
						<>s__2 = <cursors>5__1;
						for (<>s__3 = 0; <>s__3 < <>s__2.Length; <>s__3++)
						{
							<cursor>5__4 = <>s__2[<>s__3];
							((TabletStyledObject)<>4__this).AddTrackedCursor(<cursor>5__4);
							<cursor>5__4 = null;
						}
						<>s__2 = null;
						((UnityEvent<PickCursor>)(object)((TabletButton)<>4__this).OnClick).AddListener((UnityAction<PickCursor>)<>4__this.OnClickButton);
						Debug.Log((object)$"[BetterEmotes] Registered {<cursors>5__1.Length} PickCursors for TabletOptionsScreen.");
						return false;
					}
					IL_0061:
					if (<cursors>5__1 == null || <cursors>5__1.Length == 0)
					{
						<cursors>5__1 = Object.FindObjectsOfType<PickCursor>();
						<>2__current = null;
						<>1__state = 1;
						return true;
					}
					<>2__current = (object)new WaitUntil((Func<bool>)(() => ((TabletButton)<>4__this).OnClick != null));
					<>1__state = 2;
					return true;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <unfreezeNextFrame>d__12 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public CustomTabletKeyboardBindingButton <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <unfreezeNextFrame>d__12(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForFixedUpdate();
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>2__current = (object)new WaitForEndOfFrame();
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					((Component)<>4__this).GetComponentInParent<InventoryBook>().FrozenOnPage = false;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <waitForKeyPress>d__15 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public CustomTabletKeyboardBindingButton <>4__this;

			private bool <keyPressed>5__1;

			private IEnumerator <>s__2;

			private object <obj>5__3;

			private KeyCode <keyCode>5__4;

			private KeyCode <keycode>5__5;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <waitForKeyPress>d__15(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>s__2 = null;
				<obj>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0076: Unknown result type (might be due to invalid IL or missing references)
				//IL_007b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_0094: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c0: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<keyPressed>5__1 = false;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (!<keyPressed>5__1 && !<>4__this.cancel)
				{
					if (Input.anyKeyDown)
					{
						<>s__2 = Enum.GetValues(typeof(KeyCode)).GetEnumerator();
						try
						{
							while (<>s__2.MoveNext())
							{
								<obj>5__3 = <>s__2.Current;
								<keyCode>5__4 = (KeyCode)<obj>5__3;
								if (!<>4__this.IsIgnoredKey(<keyCode>5__4) && Input.GetKeyDown(<keyCode>5__4))
								{
									<keycode>5__5 = <keyCode>5__4;
									<keyPressed>5__1 = true;
									<>4__this.boundKey = <keycode>5__5;
									BetterEmotesConfig.AlternativeEmoteKey.Value = <keycode>5__5;
									break;
								}
								<obj>5__3 = null;
							}
						}
						finally
						{
							if (<>s__2 is IDisposable disposable)
							{
								disposable.Dispose();
							}
						}
						<>s__2 = null;
					}
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				<>4__this.UpdateButtonText();
				AkSoundEngine.PostEvent("UI_UPad_Options_Control_Enter", ((Component)<>4__this).gameObject);
				<>4__this.cancel = false;
				<>4__this.rebinding = false;
				((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.unfreezeNextFrame());
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <waitForNoKeys>d__14 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public CustomTabletKeyboardBindingButton <>4__this;

			private bool <keyPressed>5__1;

			private IEnumerator <>s__2;

			private object <obj>5__3;

			private KeyCode <keyCode>5__4;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <waitForNoKeys>d__14(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>s__2 = null;
				<obj>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_0076: 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_008f: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<keyPressed>5__1 = Input.anyKey;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (<keyPressed>5__1)
				{
					<keyPressed>5__1 = false;
					<>s__2 = Enum.GetValues(typeof(KeyCode)).GetEnumerator();
					try
					{
						while (<>s__2.MoveNext())
						{
							<obj>5__3 = <>s__2.Current;
							<keyCode>5__4 = (KeyCode)<obj>5__3;
							if (!<>4__this.IsIgnoredKey(<keyCode>5__4) && Input.GetKeyDown(<keyCode>5__4))
							{
								<keyPressed>5__1 = true;
								break;
							}
							<obj>5__3 = null;
						}
					}
					finally
					{
						if (<>s__2 is IDisposable disposable)
						{
							disposable.Dispose();
						}
					}
					<>s__2 = null;
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.waitForKeyPress());
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public KeyCode boundKey;

		public TabletTextLabel textLabel;

		private bool rebinding;

		private KeyboardInput keyboard;

		private bool initialized;

		private bool cancel;

		public void Start()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			textLabel = ((Component)this).GetComponentInChildren<TabletTextLabel>();
			RefreshBinding();
			keyboard = GameState.GetInstance().Keyboard;
			((Controller)keyboard).AddReceiver((InputReceiver)(object)this);
			initialized = true;
			((MonoBehaviour)this).StartCoroutine(RegisterPickCursorsWhenReady());
			base.OnClick = new TabletButtonEvent();
		}

		[IteratorStateMachine(typeof(<RegisterPickCursorsWhenReady>d__7))]
		private IEnumerator RegisterPickCursorsWhenReady()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <RegisterPickCursorsWhenReady>d__7(0)
			{
				<>4__this = this
			};
		}

		public override void Update()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			((TabletButton)this).Update();
			if (!rebinding && initialized)
			{
				if (((TabletButton)this).HasTrackedCursors && (Object)(object)((IEnumerable<PickCursor>)base.trackedCursors).FirstOrDefault((Func<PickCursor, bool>)((PickCursor c) => ((Cursor)c).LocalPlayer.UseController is KeyboardInput)) != (Object)null && Input.GetKeyDown((KeyCode)127))
				{
					boundKey = (KeyCode)0;
					BetterEmotesConfig.AlternativeEmoteKey.Value = (KeyCode)0;
				}
				UpdateButtonText();
			}
		}

		public void RefreshBinding()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			KeyboardInput val = GameState.GetInstance().Keyboard;
			boundKey = BetterEmotesConfig.AlternativeEmoteKey.Value;
			UpdateButtonText();
		}

		public void ReceiveEvent(InputEvent e)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			if ((int)e.Key == 34 && rebinding)
			{
				cancel = true;
				((MonoBehaviour)this).StartCoroutine(unfreezeNextFrame());
			}
		}

		public void OnClickButton(PickCursor pickCursor)
		{
			textLabel.text = "...?";
			rebinding = true;
			((Component)this).GetComponentInParent<InventoryBook>().FrozenOnPage = true;
			((MonoBehaviour)this).StartCoroutine(waitForNoKeys());
			AkSoundEngine.PostEvent("UI_UPad_Options_Control_Enter", ((Component)this).gameObject);
		}

		[IteratorStateMachine(typeof(<unfreezeNextFrame>d__12))]
		private IEnumerator unfreezeNextFrame()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <unfreezeNextFrame>d__12(0)
			{
				<>4__this = this
			};
		}

		private void UpdateButtonText()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected I4, but got Unknown
			KeyCode val = boundKey;
			if ((int)val > 0)
			{
				if (val - 48 > 9)
				{
					KeyCode val2 = val;
					KeyCode val3 = val2;
					switch (val3 - 256)
					{
					case 0:
					case 1:
					case 2:
					case 3:
					case 4:
					case 5:
					case 6:
					case 7:
					case 8:
					case 9:
						textLabel.text = ((object)(KeyCode)(ref boundKey)).ToString().Replace("Keypad", "No.");
						break;
					case 17:
						textLabel.text = "↑";
						break;
					case 18:
						textLabel.text = "↓";
						break;
					case 19:
						textLabel.text = "→";
						break;
					case 20:
						textLabel.text = "←";
						break;
					default:
						textLabel.text = ((object)(KeyCode)(ref boundKey)).ToString();
						break;
					}
				}
				else
				{
					textLabel.text = ((object)(KeyCode)(ref boundKey)).ToString().Replace("Alpha", "");
				}
			}
			else
			{
				textLabel.text = "...";
			}
			textLabel.UpdateDynamicText();
		}

		[IteratorStateMachine(typeof(<waitForNoKeys>d__14))]
		private IEnumerator waitForNoKeys()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <waitForNoKeys>d__14(0)
			{
				<>4__this = this
			};
		}

		[IteratorStateMachine(typeof(<waitForKeyPress>d__15))]
		private IEnumerator waitForKeyPress()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <waitForKeyPress>d__15(0)
			{
				<>4__this = this
			};
		}

		private bool IsIgnoredKey(KeyCode keyCode)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			return ((int)keyCode >= 323 && (int)keyCode <= 329) || ((int)keyCode >= 330 && (int)keyCode <= 509);
		}

		public void CancelRebind()
		{
			if (rebinding)
			{
				cancel = true;
				((MonoBehaviour)this).StartCoroutine(unfreezeNextFrame());
			}
		}
	}
}
namespace BetterEmotes.Patches
{
	internal class EmoteSystemPatch
	{
		private static Type targetType = typeof(EmoteSystem);

		private static FieldInfo possibleContentField = targetType.GetField("possibleContent", BindingFlags.Instance | BindingFlags.NonPublic);

		private static FieldInfo emoteStateField = targetType.GetField("emoteState", BindingFlags.Instance | BindingFlags.NonPublic);

		private static FieldInfo TargetVisibilityField = targetType.GetField("TargetVisibility", BindingFlags.Instance | BindingFlags.NonPublic);

		private static FieldInfo KeyBoardVisibilityTimerField = targetType.GetField("KeyBoardVisibilityTimer", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo contentTitleEnumField = AccessTools.Field(typeof(EmoteSystem), "contentTitleEnum");

		private static readonly FieldInfo UpContentEnumsField = AccessTools.Field(typeof(EmoteSystem), "UpContentEnums");

		private static readonly FieldInfo LeftContentEnumsField = AccessTools.Field(typeof(EmoteSystem), "LeftContentEnums");

		private static readonly FieldInfo RightContentEnumsField = AccessTools.Field(typeof(EmoteSystem), "RightContentEnums");

		private static readonly FieldInfo DownContentEnumsField = AccessTools.Field(typeof(EmoteSystem), "DownContentEnums");

		private static readonly MethodInfo handleEventMethod = AccessTools.Method(targetType, "handleEvent", (Type[])null, (Type[])null);

		private static EmoteContext context = (EmoteContext)2;

		public static void StartPostfix(EmoteSystem __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected I4, but got Unknown
			context = (EmoteContext)2;
			((BaseUnityPlugin)BetterEmotesPlugin.instance).Config.Reload();
			BetterEmotesConfig.BindConfig(((BaseUnityPlugin)BetterEmotesPlugin.instance).Config);
			EmoteContext[] array = (EmoteContext[])Enum.GetValues(typeof(EmoteContext));
			foreach (EmoteContext val in array)
			{
				Dictionary<emoteDirections, EmoteMeanings[]> dictionary = BetterEmotesConfig.RawCategoryBindings[val];
				EmoteContext val2 = val;
				EmoteContext val3 = val2;
				switch ((int)val3)
				{
				case 0:
					__instance.DownContentEnumsRun = dictionary[(emoteDirections)2];
					__instance.UpContentEnumsRun = dictionary[(emoteDirections)0];
					__instance.LeftContentEnumsRun = dictionary[(emoteDirections)3];
					__instance.RightContentEnumsRun = dictionary[(emoteDirections)1];
					break;
				case 1:
					__instance.DownContentEnumsBuild = dictionary[(emoteDirections)2];
					__instance.UpContentEnumsBuild = dictionary[(emoteDirections)0];
					__instance.LeftContentEnumsBuild = dictionary[(emoteDirections)3];
					__instance.RightContentEnumsBuild = dictionary[(emoteDirections)1];
					break;
				case 2:
					__instance.DownContentEnumsLobby = dictionary[(emoteDirections)2];
					__instance.UpContentEnumsLobby = dictionary[(emoteDirections)0];
					__instance.LeftContentEnumsLobby = dictionary[(emoteDirections)3];
					__instance.RightContentEnumsLobby = dictionary[(emoteDirections)1];
					break;
				}
			}
		}

		public static void UpdatePostfix(EmoteSystem __instance)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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)
			if ((((Object)(object)__instance.GamePlayer != (Object)null && __instance.LobbyPlayer.MainUser) || ((Object)(object)__instance.LobbyPlayer != (Object)null && __instance.LobbyPlayer.MainUser)) && Input.GetKeyDown(BetterEmotesConfig.AlternativeEmoteKey.Value))
			{
				__instance.animator.SetTrigger("Reset");
				possibleContentField.SetValue(__instance, BetterEmotesConfig.AlternativeEmotes[context]);
				__instance.insertString(__instance.EmoteArrayConvert(BetterEmotesConfig.AlternativeEmotes[context]));
				emoteStateField.SetValue(__instance, (object)(emoteState)2);
				TargetVisibilityField.SetValue(__instance, 1f);
				KeyBoardVisibilityTimerField.SetValue(__instance, GameSettings.GetInstance().emoteUIDisplayTime);
			}
		}

		public static void SetEmoteContextPostfix(EmoteSystem __instance, EmoteContext newContext)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			context = newContext;
		}
	}
	internal class TabletOptionsScreenPatch
	{
		private static GameObject betterEmotesSubdialog;

		private static GameObject betterEmotesButton;

		public static void StartPostfix(TabletOptionsScreen __instance)
		{
			betterEmotesButton = ((Component)((Component)__instance).transform.GetChild(1).GetChild(0).GetChild(1)
				.GetChild(0)).gameObject;
			if ((Object)(object)betterEmotesButton == (Object)null)
			{
				Debug.LogError((object)"could not find better emotes button");
				return;
			}
			((Object)betterEmotesButton).name = "Better Emotes Button";
			betterEmotesButton.SetActive(true);
			GameObject gameObject = ((Component)betterEmotesButton.transform.GetChild(0)).gameObject;
			TabletTextLabel component = gameObject.GetComponent<TabletTextLabel>();
			if ((Object)(object)component != (Object)null)
			{
				component.Term = "betteremote/quickchat";
				component.text = "Quickchat";
			}
			RectTransform val = BetterEmotesDialogFactory.CreateSubdialog(__instance);
			if (!((Object)(object)val == (Object)null))
			{
				betterEmotesSubdialog = ((Component)val).gameObject;
			}
		}

		public static void OnDestroyPostfix(TabletOptionsScreen __instance)
		{
			betterEmotesSubdialog = null;
			betterEmotesButton = null;
		}

		public static void OnPressBackPostfix(TabletOptionsScreen __instance, PickCursor pickCursor, ref bool __result)
		{
			GameObject gameObject = ((Component)betterEmotesButton.transform.GetChild(0)).gameObject;
			TabletTextLabel component = gameObject.GetComponent<TabletTextLabel>();
			if ((Object)(object)component != (Object)null)
			{
				component.Term = "betteremote/quickchat";
			}
		}

		public static void OnClickSwitchSetupControllersPostfix(TabletOptionsScreen __instance, PickCursor pickCursor)
		{
			if (!__instance.subdialogController.IsAnimating)
			{
				FieldInfo field = typeof(TabletOptionsScreen).GetField("lastEnteredSubdialog", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field != null)
				{
					field.SetValue(__instance, betterEmotesSubdialog.GetComponent<RectTransform>());
				}
				__instance.subdialogController.TransitionLeftTo(betterEmotesSubdialog.transform);
			}
		}
	}
}