Decompiled source of AlternateControlsTooManyEmotes v1.0.0

TooManyEmotesAlternateControls.dll

Decompiled 2 months ago
using System;
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.Bootstrap;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LCVR.Player;
using Microsoft.CodeAnalysis;
using TooManyEmotes;
using TooManyEmotes.Config;
using TooManyEmotes.Patches;
using TooManyEmotes.UI;
using TooManyEmotesAlternateControls.Compatibility;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("TooManyEmotesAlternateControls")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5cf06ba6442ecec3ee777fa9542775e42d590e6f")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("TooManyEmotesAlternateControls")]
[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 TooManyEmotesAlternateControls
{
	[BepInPlugin("TooManyEmotesAlternateControls", "Alternate Controls for Too Many Emotes", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("TooManyEmotesAlternateControls");
			val.PatchAll();
			Logger.LogInfo((object)"Plugin TooManyEmotesAlternateControls is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "TooManyEmotesAlternateControls";

		public const string PLUGIN_NAME = "Alternate Controls for Too Many Emotes";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "TooManyEmotesAlternateControls";

		public const string PLUGIN_NAME = "My first plugin";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace TooManyEmotesAlternateControls.Patchers
{
	[HarmonyPatch]
	internal class EmoteMenuPatcher
	{
		private static int lastEmoteIndex = -1;

		private static bool hasMovedCursorInMenu = false;

		[HarmonyPatch(typeof(EmoteMenu), "GetInput")]
		[HarmonyPrefix]
		private static bool SetLastEmoteUsed()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			if (hasMovedCursorInMenu)
			{
				return true;
			}
			if (!EmoteMenu.isMenuOpen || ConfigSettings.disableEmotesForSelf.Value || LCVRCompat.LoadedAndEnabled)
			{
				return true;
			}
			if (AdditionalPanelUI.hovered || EmoteMenu.hoveredLoadoutUIIndex != -1)
			{
				return true;
			}
			RectTransform uiRectTransform = EmoteMenu.emoteUIElementsList[0].uiRectTransform;
			float num = Vector2.Distance(Vector2.op_Implicit(EmoteMenu.menuGameObject.transform.position), Vector2.op_Implicit(((Transform)uiRectTransform).position)) * 0.815f;
			Vector2 val2;
			if (!EmoteMenu.usingController)
			{
				Vector3 val = Vector2.op_Implicit(((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue());
				Camera worldCamera = HUDManager.Instance.HUDContainer.GetComponentInParent<Canvas>().worldCamera;
				val.z = Mathf.Abs(((Component)worldCamera).transform.position.z - ((Transform)EmoteMenu.menuTransform).position.z);
				val2 = Vector2.op_Implicit(worldCamera.ScreenToWorldPoint(val) - ((Transform)EmoteMenu.menuTransform).position);
			}
			else
			{
				val2 = EmoteMenu.currentThumbstickPosition;
			}
			int num2 = -1;
			if (!hasMovedCursorInMenu)
			{
				num2 = lastEmoteIndex;
			}
			if ((!EmoteMenu.usingController && ((Vector2)(ref val2)).magnitude >= num) || (EmoteMenu.usingController && EmoteMenu.currentThumbstickPosition != Vector2.zero))
			{
				hasMovedCursorInMenu = true;
				float num3 = Mathf.Atan2(val2.y, 0f - val2.x) * 57.29578f - 67.5f;
				if (num3 < 0f)
				{
					num3 += 360f;
				}
				num2 = Mathf.FloorToInt(num3 / 45f);
			}
			if (num2 != EmoteMenu.hoveredEmoteUIIndex)
			{
				EmoteMenu.OnHoveredNewElement(num2);
			}
			return false;
		}

		[HarmonyPatch(typeof(EmoteMenu), "CloseEmoteMenu")]
		[HarmonyPrefix]
		private static void OnEmoteMenuClose()
		{
			if (EmoteMenu.hoveredEmoteUIIndex != -1)
			{
				lastEmoteIndex = EmoteMenu.hoveredEmoteUIIndex;
			}
		}

		[HarmonyPatch(typeof(EmoteMenu), "OpenEmoteMenu")]
		[HarmonyPostfix]
		private static void ResetHasMovedCursorInMenu()
		{
			hasMovedCursorInMenu = false;
		}
	}
	[HarmonyPatch]
	internal class ThirdPersonEmoteControllerPatcher
	{
		private static EmoteController emoteControllerLocal = (EmoteController)(object)EmoteControllerPlayer.emoteControllerLocal;

		private static PlayerControllerB localPlayerController = StartOfRound.Instance?.localPlayerController;

		private static Camera emoteCamera = (Camera)Traverse.Create(typeof(ThirdPersonEmoteController)).Field("emoteCamera").GetValue();

		private static Camera gameplayCamera = (Camera)Traverse.Create(typeof(ThirdPersonEmoteController)).Field("gameplayCamera").GetValue();

		private static Transform localPlayerCameraContainer = (Transform)Traverse.Create(typeof(ThirdPersonEmoteController)).Property("localPlayerCameraContainer", (object[])null).GetValue();

		private static Transform emoteCameraPivot = (Transform)Traverse.Create(typeof(ThirdPersonEmoteController)).Field("emoteCameraPivot").GetValue();

		private static int cameraCollideLayerMask = (int)Traverse.Create(typeof(ThirdPersonEmoteController)).Field("cameraCollideLayerMask").GetValue();

		private static float targetCameraDistance = (float)Traverse.Create(typeof(ThirdPersonEmoteController)).Field("targetCameraDistance").GetValue();

		private static Vector2 clampCameraDistance = (Vector2)Traverse.Create(typeof(ThirdPersonEmoteController)).Field("clampCameraDistance").GetValue();

		private static bool _isMovingWhileEmoting = (bool)Traverse.Create(typeof(ThirdPersonEmoteController)).Property("isMovingWhileEmoting", (object[])null).GetValue();

		private static float _timeOfLastMovingCheck = 0f;

		private static Vector3 prevCameraDirection = new Vector3(0f, 0f, 0f);

		private static bool isMovingWhileEmoting => IsMovingWhileEmoting();

		[HarmonyPatch(typeof(ThirdPersonEmoteController), "InitLocalPlayerController")]
		[HarmonyPostfix]
		private static void InitValues()
		{
		}

		[HarmonyPatch(typeof(ThirdPersonEmoteController), "UseFreeCamWhileEmoting")]
		[HarmonyPrefix]
		private static bool IgnoreOriginalFreeCam(ref bool __result)
		{
			__result = true;
			return false;
		}

		[HarmonyPatch(typeof(PlayerControllerB), "PlayerLookInput")]
		[HarmonyPrefix]
		private static bool UseFreeCam(PlayerControllerB __instance)
		{
			//IL_001c: 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_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0474: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			if (((Vector3)(ref prevCameraDirection)).magnitude < 0.1f)
			{
				prevCameraDirection = emoteCameraPivot.forward;
			}
			if ((Object)(object)__instance != (Object)(object)localPlayerController || (Object)(object)emoteControllerLocal == (Object)null)
			{
				return true;
			}
			if (ConfigSettings.disableEmotesForSelf.Value || LCVRCompat.LoadedAndEnabled)
			{
				return true;
			}
			if (emoteControllerLocal.IsPerformingCustomEmote())
			{
				if (ThirdPersonEmoteController.firstPersonEmotesEnabled)
				{
					Plugin.Logger.LogMessage((object)$"gamplayCamera: {gameplayCamera}, localPlayerCameraContainer: {localPlayerCameraContainer}");
					if ((Object)(object)StartOfRound.Instance.activeCamera != (Object)(object)gameplayCamera)
					{
						StartOfRound.Instance.SwitchCamera(gameplayCamera);
						ThirdPersonEmoteController.CallChangeAudioListenerToObject(((Component)gameplayCamera).gameObject);
						((Behaviour)emoteCamera).enabled = false;
						if ((Object)(object)localPlayerController.currentlyHeldObjectServer != (Object)null)
						{
							localPlayerController.currentlyHeldObjectServer.parentObject = localPlayerController.localItemHolder;
						}
					}
					localPlayerCameraContainer.SetPositionAndRotation(localPlayerController.playerGlobalHead.position, ((Component)localPlayerController).transform.rotation);
					return isMovingWhileEmoting;
				}
				if ((Object)(object)StartOfRound.Instance.activeCamera != (Object)(object)emoteCamera)
				{
					((Behaviour)emoteCamera).enabled = true;
					StartOfRound.Instance.SwitchCamera(emoteCamera);
					ThirdPersonEmoteController.CallChangeAudioListenerToObject(((Component)emoteCamera).gameObject);
					if ((Object)(object)localPlayerController.currentlyHeldObjectServer != (Object)null)
					{
						localPlayerController.currentlyHeldObjectServer.parentObject = localPlayerController.serverItemHolder;
					}
				}
				Vector3 val = Vector3.back * Mathf.Clamp(targetCameraDistance, clampCameraDistance.x, clampCameraDistance.y);
				((Component)emoteCamera).transform.localPosition = Vector3.Lerp(((Component)emoteCamera).transform.localPosition, val, 10f * Time.deltaTime);
				if (!localPlayerController.quickMenuManager.isMenuOpen && !EmoteMenu.isMenuOpen)
				{
					bool flag = ((Vector2)(ref localPlayerController.moveInputVector)).magnitude > 0.2f;
					MovementActions movement = localPlayerController.playerActions.Movement;
					Vector2 val2 = ((MovementActions)(ref movement)).Look.ReadValue<Vector2>() * 0.008f * (float)IngamePlayerSettings.Instance.settings.lookSensitivity;
					if (!flag)
					{
						emoteCameraPivot.Rotate(new Vector3(0f, val2.x, 0f));
					}
					float num = emoteCameraPivot.localEulerAngles.x - val2.y;
					num = ((num > 180f) ? (num - 360f) : num);
					num = Mathf.Clamp(num, -45f, 45f);
					((Component)emoteCameraPivot).transform.localEulerAngles = new Vector3(num, emoteCameraPivot.localEulerAngles.y, 0f);
					if (flag)
					{
						Vector3 val3 = default(Vector3);
						((Vector3)(ref val3))..ctor(((Component)emoteCameraPivot).transform.forward.x, 0f, ((Component)emoteCameraPivot).transform.forward.z);
						Vector3 forward = ((Component)emoteCamera).transform.forward;
						((Component)localPlayerController).transform.rotation = Quaternion.RotateTowards(((Component)localPlayerController).transform.rotation, Quaternion.LookRotation(val3), Time.deltaTime * 720f);
						Vector3 val4 = ((Component)emoteCameraPivot).transform.parent.InverseTransformDirection(forward);
						((Component)emoteCameraPivot).transform.localRotation = Quaternion.LookRotation(val4);
					}
					RaycastHit val5 = default(RaycastHit);
					if (Physics.Raycast(emoteCameraPivot.position, -emoteCameraPivot.forward * targetCameraDistance, ref val5, targetCameraDistance, cameraCollideLayerMask))
					{
						((Component)emoteCamera).transform.localPosition = Vector3.back * Mathf.Clamp(((RaycastHit)(ref val5)).distance - 0.2f, 0f, targetCameraDistance);
					}
					prevCameraDirection = emoteCameraPivot.forward;
					return flag;
				}
			}
			return true;
		}

		private static bool IsMovingWhileEmoting()
		{
			if (Time.time - _timeOfLastMovingCheck > 0.1f)
			{
				_isMovingWhileEmoting = (bool)Traverse.Create(typeof(ThirdPersonEmoteController)).Property("isMovingWhileEmoting", (object[])null).GetValue();
			}
			return _isMovingWhileEmoting;
		}
	}
}
namespace TooManyEmotesAlternateControls.Compatibility
{
	internal static class LCVRCompat
	{
		private static bool Enabled => Chainloader.PluginInfos.ContainsKey("io.daxcess.lcvr");

		private static bool IsInVR => VRSession.InVR;

		public static bool LoadedAndEnabled => Enabled && IsInVR;
	}
}