Decompiled source of LethalMinVR v1.0.1

NoteBoxz.LethalMinVR.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LCVR;
using LCVR.Input;
using LCVR.Patches.Spectating;
using LCVR.Physics;
using LCVR.Physics.Interactions;
using LCVR.Player;
using LCVR.UI;
using LethalMin;
using LethalMin.HUD;
using LethalMin.Pikmin;
using LethalMin.Utils;
using Microsoft.CodeAnalysis;
using NoteBoxz.LethalMinVR.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Animations.Rigging;
using UnityEngine.Events;
using UnityEngine.UI;
using UnityEngine.XR.Interaction.Toolkit.UI;

[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: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("LCVR")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("NoteBoxz.LethalMinVR")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LethalMinVR")]
[assembly: AssemblyTitle("NoteBoxz.LethalMinVR")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
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;
		}
	}
	[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 LethalMinVR
{
	[BepInPlugin("NoteBoxz.LethalMinVR", "LethalMinVR", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class LethalMinVR : BaseUnityPlugin
	{
		public static LethalMinVR Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		public static bool InVRMode => VRSession.InVR;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			NetcodePatcher();
			Patch();
			LethalMin.InVRMode = InVRMode;
			Logger.LogInfo((object)"NoteBoxz.LethalMinVR v1.0.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("NoteBoxz.LethalMinVR");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}

		private void NetcodePatcher()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
	public class LeaderVR : MonoBehaviour
	{
		public Leader LeaderScript = null;

		public Transform GlowMobHoldPosition = null;
	}
	public class PikminButtonVRInteractable : PikminVRInteractable
	{
		public Button buttonScript = null;

		public override bool OnButtonPress(VRInteractor interactor)
		{
			((UnityEvent)buttonScript.onClick).Invoke();
			return true;
		}

		public override void OnButtonRelease(VRInteractor interactor)
		{
		}

		public override void OnColliderEnter(VRInteractor interactor)
		{
		}

		public override void OnColliderExit(VRInteractor interactor)
		{
		}
	}
	public abstract class PikminVRInteractable : MonoBehaviour
	{
		public abstract bool OnButtonPress(VRInteractor interactor);

		public abstract void OnButtonRelease(VRInteractor interactor);

		public abstract void OnColliderEnter(VRInteractor interactor);

		public abstract void OnColliderExit(VRInteractor interactor);
	}
	public class PikminVRInteractableProvider : MonoBehaviour, VRInteractable
	{
		public PikminVRInteractable mainScript = null;

		public InteractableFlags Flags => (InteractableFlags)3;

		public bool OnButtonPress(VRInteractor interactor)
		{
			return mainScript.OnButtonPress(interactor);
		}

		public void OnButtonRelease(VRInteractor interactor)
		{
			mainScript.OnButtonRelease(interactor);
		}

		public void OnColliderEnter(VRInteractor interactor)
		{
			mainScript.OnColliderEnter(interactor);
		}

		public void OnColliderExit(VRInteractor interactor)
		{
			mainScript.OnColliderExit(interactor);
		}
	}
	public class SproutVRInteractable : PikminVRInteractable
	{
		public Sprout sproutScript = null;

		private VRInteractor? currentInteractor = null;

		[Header("Plucking Settings")]
		[Tooltip("Distance needed to pluck the sprout")]
		public float pluckThreshold = 1.5f;

		[Tooltip("Speed at which the sprout returns to its original position")]
		public float returnSpeed = 5f;

		[Tooltip("How strongly bones follow the pull direction")]
		public float boneFollowStrength = 0.8f;

		private Vector3 initialPosition;

		private bool isPlucked = false;

		private bool isReturning = false;

		private float TargetWeight = 0f;

		public Dictionary<RigBuilder, ChainIKConstraint> chainIKConstraints = new Dictionary<RigBuilder, ChainIKConstraint>();

		private void Start()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			initialPosition = ((Component)sproutScript).transform.position;
		}

		public override bool OnButtonPress(VRInteractor interactor)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			if (isPlucked)
			{
				return false;
			}
			LethalMinVR.Logger.LogInfo((object)("SproutVRInteractable: " + ((Object)interactor).name + " pressed the button on " + ((Object)((Component)this).gameObject).name));
			currentInteractor = interactor;
			((FingerCurler)interactor.FingerCurler).ForceFist(true);
			isReturning = false;
			sproutScript.PlayPullSoundServerRpc(default(ServerRpcParams));
			sproutScript.sproutAudio.PlayOneShot(sproutScript.PullSFX);
			Leader componentInParent = ((Component)interactor).GetComponentInParent<Leader>();
			if ((Object)(object)componentInParent == (Object)null)
			{
				LethalMinVR.Logger.LogError((object)("SproutVRInteractable: " + ((Object)interactor).name + " does not have a Leader component in parent!"));
				return false;
			}
			sproutScript.PlayerPluckingID = ((NetworkBehaviour)componentInParent.Controller).OwnerClientId;
			return true;
		}

		public override void OnButtonRelease(VRInteractor interactor)
		{
			if (!isPlucked)
			{
				LethalMinVR.Logger.LogInfo((object)("SproutVRInteractable: " + ((Object)interactor).name + " released the button on " + ((Object)((Component)this).gameObject).name));
				currentInteractor = null;
				((FingerCurler)interactor.FingerCurler).ForceFist(false);
				isReturning = true;
			}
		}

		public void OnDestroy()
		{
			if ((Object)(object)currentInteractor != (Object)null)
			{
				LethalMinVR.Logger.LogWarning((object)("SproutVRInteractable: " + ((Object)currentInteractor).name + " was destroyed without releasing the button on " + ((Object)((Component)this).gameObject).name));
				((FingerCurler)currentInteractor.FingerCurler).ForceFist(false);
				currentInteractor = null;
			}
		}

		public void Update()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_00b7: 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_0116: 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_012d: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)currentInteractor != (Object)null && !isPlucked)
			{
				Vector3 val = ((Component)currentInteractor).transform.position - initialPosition;
				float magnitude = ((Vector3)(ref val)).magnitude;
				if (magnitude >= pluckThreshold)
				{
					isPlucked = true;
					sproutScript.sproutAudio.PlayOneShot(sproutScript.PluckSFX);
					sproutScript.PluckAndDespawnServerRpc(sproutScript.PlayerPluckingID);
				}
				else
				{
					float num = Mathf.Clamp01(magnitude / 5f);
					((Component)sproutScript).transform.position = initialPosition + ((Vector3)(ref val)).normalized * (magnitude * num);
					TargetWeight = 1f;
				}
			}
			else if (isReturning && !isPlucked)
			{
				((Component)sproutScript).transform.position = Vector3.Lerp(((Component)sproutScript).transform.position, initialPosition, returnSpeed * Time.deltaTime);
				if (Vector3.Distance(((Component)sproutScript).transform.position, initialPosition) < 0.01f)
				{
					((Component)sproutScript).transform.position = initialPosition;
					isReturning = false;
					foreach (KeyValuePair<RigBuilder, ChainIKConstraint> chainIKConstraint in chainIKConstraints)
					{
						ChainIKConstraint value = chainIKConstraint.Value;
						((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)value).data)).target = null;
						((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)value).weight = 0f;
					}
				}
				else
				{
					TargetWeight = 0f;
				}
			}
			if (!((Object)(object)currentInteractor != (Object)null) && !isReturning)
			{
				return;
			}
			foreach (KeyValuePair<RigBuilder, ChainIKConstraint> chainIKConstraint2 in chainIKConstraints)
			{
				RigBuilder key = chainIKConstraint2.Key;
				ChainIKConstraint value2 = chainIKConstraint2.Value;
				Transform target = ((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)value2).data)).target;
				VRInteractor? obj = currentInteractor;
				Transform val2 = ((obj != null) ? ((Component)obj).transform : null);
				((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)value2).data)).target = val2;
				if ((Object)(object)target != (Object)(object)val2)
				{
					key.Build();
				}
				((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)value2).weight = Mathf.Lerp(((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)value2).weight, TargetWeight, Time.deltaTime * boneFollowStrength);
			}
		}

		public override void OnColliderEnter(VRInteractor interactor)
		{
		}

		public override void OnColliderExit(VRInteractor interactor)
		{
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "NoteBoxz.LethalMinVR";

		public const string PLUGIN_NAME = "LethalMinVR";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace LethalMinVR.Patches
{
	[HarmonyPatch(typeof(Face))]
	public static class FacePatch
	{
		[HarmonyPatch("Create")]
		[HarmonyPostfix]
		public static void CreatePostfix(VRPlayer __instance)
		{
			if (LethalMinVR.InVRMode)
			{
				Face val = Object.FindObjectOfType<Face>();
				val.ALLOWED_ITEMS.Add("Whistle");
			}
		}
	}
	[HarmonyPatch(typeof(Glowmob))]
	public static class GlowmobrPatch
	{
		[HarmonyPatch("SetLeader")]
		[HarmonyPostfix]
		public static void AwakePostfix(Glowmob __instance, Leader leader)
		{
			if (LethalMinVR.InVRMode)
			{
				__instance.holdPosition = ((Component)leader).GetComponent<LeaderVR>().GlowMobHoldPosition;
			}
		}
	}
	[HarmonyPatch(typeof(OnionHUDManager))]
	public class OnionHUDManagerPatch
	{
		[HarmonyPatch("OpenMenu")]
		[HarmonyPrefix]
		private static void OpenMenuPostfix(OnionHUDManager __instance)
		{
			if (LethalMinVR.InVRMode && !__instance.IsMenuOpen)
			{
				((Behaviour)VRSession.Instance.LocalPlayer.leftHandInteractor).enabled = true;
				((Behaviour)VRSession.Instance.LocalPlayer.rightHandInteractor).enabled = true;
				VRSession.Instance.LocalPlayer.EnableInteractorVisuals(true);
			}
		}

		[HarmonyPatch("CloseMenu")]
		[HarmonyPrefix]
		private static void CloseMenuPostfix(OnionHUDManager __instance)
		{
			if (__instance.IsMenuOpen && LethalMinVR.InVRMode)
			{
				((Behaviour)VRSession.Instance.LocalPlayer.leftHandInteractor).enabled = !VRSession.Instance.LocalPlayer.PlayerController.isPlayerDead;
				((Behaviour)VRSession.Instance.LocalPlayer.rightHandInteractor).enabled = !VRSession.Instance.LocalPlayer.PlayerController.isPlayerDead;
				VRSession.Instance.LocalPlayer.EnableInteractorVisuals(false);
			}
		}
	}
	[HarmonyPatch(typeof(PikminHUDManager))]
	public class PikminHUDManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPostFix(PikminHUDManager __instance)
		{
			__instance.element.targetAlpha = 1f;
			if (LethalMinVR.InVRMode)
			{
				AutoSetHudVRPreset(__instance);
			}
		}

		private static void AutoSetHudVRPreset(PikminHUDManager __instance)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Invalid comparison between Unknown and I4
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Invalid comparison between Unknown and I4
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			if (LethalMin.AutoSetHudVRPreset.InternalValue)
			{
				bool value = Plugin.Config.DisableArmHUD.Value;
				if ((!value || (int)LethalMin.HUDPreset.InternalValue != 4) && (value || (int)LethalMin.HUDPreset.InternalValue != 3))
				{
					HUDLayoutPresets val = (HUDLayoutPresets)(value ? 4 : 3);
					((ConfigEntryBase)LethalMin.HUDPreset.Entry).BoxedValue = val;
					__instance.SetLayout(val);
				}
			}
		}
	}
	[HarmonyPatch(typeof(PikUtils))]
	public class PikUtilsPatch
	{
		[HarmonyPatch("RevivePlayer")]
		[HarmonyPrefix]
		public static void RevivePlayerPrefix(PlayerControllerB player, Vector3 RevivePos)
		{
			if (((NetworkBehaviour)player).IsOwner && LethalMinVR.InVRMode)
			{
				CallOnPlayerRevive();
			}
		}

		public static void CallOnPlayerRevive()
		{
			SpectatorPlayerPatches.OnPlayerRevived();
		}
	}
	[HarmonyPatch(typeof(Sprout))]
	public class SproutPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPostFix(Sprout __instance)
		{
			if (LethalMinVR.InVRMode && !LethalMin.DisableSproutInteraction.InternalValue)
			{
				ReplaceInteractable(__instance);
			}
		}

		public static void ReplaceInteractable(Sprout sprout)
		{
			InteractTrigger componentInChildren = ((Component)sprout).GetComponentInChildren<InteractTrigger>();
			if ((Object)(object)componentInChildren == (Object)null)
			{
				return;
			}
			SproutModelRefences componentInChildren2 = ((Component)sprout).GetComponentInChildren<SproutModelRefences>();
			if ((Object)(object)componentInChildren2 == (Object)null)
			{
				return;
			}
			GameObject gameObject = ((Component)componentInChildren).gameObject;
			Object.Destroy((Object)(object)componentInChildren);
			HashSet<GameObject> hashSet = new HashSet<GameObject>();
			if ((Object)(object)componentInChildren2.SproutVRInteractableObject != (Object)null)
			{
				bool flag = false;
				SproutModelGeneration[] generations = componentInChildren2.Generations;
				foreach (SproutModelGeneration val in generations)
				{
					if ((Object)(object)componentInChildren2.SproutVRInteractableObject == (Object)(object)val.SproutVRInteractableObject)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					hashSet.Add(componentInChildren2.SproutVRInteractableObject);
				}
			}
			SproutModelGeneration[] generations2 = componentInChildren2.Generations;
			foreach (SproutModelGeneration val2 in generations2)
			{
				if ((Object)(object)val2.SproutVRInteractableObject != (Object)null)
				{
					hashSet.Add(val2.SproutVRInteractableObject);
				}
			}
			SproutVRInteractable sproutVRInteractable = gameObject.AddComponent<SproutVRInteractable>();
			sproutVRInteractable.sproutScript = sprout;
			if (hashSet.Count > 0)
			{
				Object.Destroy((Object)(object)((Component)sproutVRInteractable).GetComponent<Collider>());
				Object.Destroy((Object)(object)((Component)sproutVRInteractable).GetComponent<Rigidbody>());
			}
			else
			{
				gameObject.layer = LayerMask.NameToLayer("Colliders");
				gameObject.tag = "InteractTrigger";
			}
			foreach (GameObject item in hashSet)
			{
				CreateInteractableCapsule(item, sproutVRInteractable);
			}
			SetupIKSystem(componentInChildren2, sproutVRInteractable);
		}

		private static void CreateInteractableCapsule(GameObject parent, SproutVRInteractable mainInteractable)
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)1);
			val.transform.SetParent(parent.transform);
			Collider component = val.GetComponent<Collider>();
			component.isTrigger = true;
			Rigidbody val2 = val.AddComponent<Rigidbody>();
			val2.useGravity = false;
			val2.isKinematic = true;
			val.layer = LayerMask.NameToLayer("Colliders");
			val.tag = "Untagged";
			PikminVRInteractableProvider pikminVRInteractableProvider = val.AddComponent<PikminVRInteractableProvider>();
			pikminVRInteractableProvider.mainScript = mainInteractable;
			val.transform.localPosition = Vector3.zero;
			val.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
			val.transform.localRotation = Quaternion.Euler(0f, 0f, 90f);
		}

		private static void SetupIKSystem(SproutModelRefences refs, SproutVRInteractable vrInteractable)
		{
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Expected O, but got Unknown
			SproutModelRefences refs2 = refs;
			Dictionary<GameObject, List<Transform>> dictionary = new Dictionary<GameObject, List<Transform>>();
			if (!refs2.Generations.Any((SproutModelGeneration gen) => (Object)(object)refs2.Animator == (Object)(object)gen.Animator) && refs2.SproutBones != null && refs2.SproutBones.Count > 0)
			{
				dictionary[((Component)refs2).gameObject] = SortBonesFromTipToRoot(refs2.SproutBones);
			}
			SproutModelGeneration[] generations = refs2.Generations;
			foreach (SproutModelGeneration val in generations)
			{
				if (val.SproutBones != null && val.SproutBones.Count > 0)
				{
					dictionary[((Component)val).gameObject] = SortBonesFromTipToRoot(val.SproutBones);
				}
			}
			foreach (KeyValuePair<GameObject, List<Transform>> item in dictionary)
			{
				List<Transform> value = item.Value;
				GameObject key = item.Key;
				if (value.Count == 0)
				{
					LethalMinVR.Logger.LogWarning((object)("No bones found in sprout hierarchy for " + ((Object)key).name));
					continue;
				}
				RigBuilder val2 = key.AddComponent<RigBuilder>();
				Rig val3 = key.AddComponent<Rig>();
				val2.layers.Add(new RigLayer(val3, true));
				ChainIKConstraint val4 = key.AddComponent<ChainIKConstraint>();
				((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)val4).data)).root = value[value.Count - 1];
				((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)val4).data)).tip = value[0];
				((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)val4).data)).target = null;
				((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)val4).data)).chainRotationWeight = 1f;
				((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)val4).data)).tipRotationWeight = 0.5f;
				((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)val4).data)).maxIterations = 15;
				((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)val4).data)).tolerance = 0.0001f;
				vrInteractable.chainIKConstraints.Add(val2, val4);
				val2.Build();
			}
		}

		private static List<Transform> SortBonesFromTipToRoot(List<Transform> bones)
		{
			List<Transform> bones2 = bones;
			if (bones2 == null || bones2.Count == 0)
			{
				return new List<Transform>();
			}
			Transform val = ((IEnumerable<Transform>)bones2).FirstOrDefault((Func<Transform, bool>)((Transform b) => !bones2.Any((Transform otherBone) => (Object)(object)otherBone != (Object)(object)b && (Object)(object)otherBone.parent == (Object)(object)b)));
			if ((Object)(object)val == (Object)null)
			{
				LethalMinVR.Logger.LogWarning((object)"Could not identify tip bone in sprout hierarchy");
				return bones2;
			}
			List<Transform> list = new List<Transform>();
			Transform val2 = val;
			while ((Object)(object)val2 != (Object)null && bones2.Contains(val2))
			{
				list.Add(val2);
				val2 = val2.parent;
			}
			return list;
		}
	}
	[HarmonyPatch(typeof(VRHUD))]
	public static class VRHUDPatch
	{
		public static Canvas? OnionCanvas;

		public static GameObject? OnionHUD;

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		public static void AwakePostfix(VRHUD __instance)
		{
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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_0123: 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_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			float value = Plugin.Config.HUDOffsetX.Value;
			float value2 = Plugin.Config.HUDOffsetY.Value;
			GameObject gameObject = ((Component)Object.FindObjectOfType<PikminHUDManager>()).gameObject;
			if (Plugin.Config.DisableArmHUD.Value)
			{
				gameObject.transform.SetParent(((Component)__instance.FaceCanvas).transform, false);
				gameObject.transform.localPosition = new Vector3(91f + value, -185f + value2, 0f);
				gameObject.transform.localRotation = Quaternion.identity;
			}
			else
			{
				gameObject.transform.SetParent(((Component)__instance.RightHandCanvas).transform, false);
				gameObject.transform.localPosition = new Vector3(-28f, 120f, 40f);
				gameObject.transform.localRotation = Quaternion.Euler(0f, 195f, 0f);
				gameObject.transform.localScale = Vector3.one * 0.8f;
			}
			GameObject val = new GameObject("Onion VR Canvas");
			val.transform.parent = ((Component)__instance).transform;
			val.transform.localScale = Vector3.one * 0.0007f;
			OnionCanvas = val.AddComponent<Canvas>();
			OnionCanvas.worldCamera = VRSession.Instance.MainCamera;
			OnionCanvas.renderMode = (RenderMode)2;
			OnionCanvas.sortingOrder = 1;
			((Component)OnionCanvas).gameObject.AddComponent<TrackedDeviceGraphicRaycaster>();
			OnionHUD = ((Component)Object.FindObjectOfType<OnionHUDManager>()).gameObject;
			OnionHUD.transform.SetParent(((Component)OnionCanvas).transform, false);
			OnionHUD.transform.localPosition = new Vector3(0f + value, 0f + value2, LethalMin.OnionHUDZDistance.InternalValue);
			OnionHUD.transform.localRotation = Quaternion.identity;
			GameObject gameObject2 = ((Component)OnionHUD.transform.Find("AcutalUI/Darken")).gameObject;
			if ((Object)(object)gameObject2 != (Object)null)
			{
				gameObject2.SetActive(false);
			}
			else
			{
				LethalMinVR.Logger.LogError((object)"Darken object not found in OnionHUDManager");
			}
			VRHUD.MoveToFront((Component)(object)OnionCanvas);
		}

		[HarmonyPatch("LateUpdate")]
		[HarmonyPostfix]
		public static void LateUpdatePostfix(VRHUD __instance)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0084: 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: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)OnionCanvas == (Object)null) && !((Object)(object)OnionHUD == (Object)null))
			{
				Transform transform = ((Component)VRSession.Instance.MainCamera).transform;
				float value = Plugin.Config.HUDOffsetX.Value;
				float value2 = Plugin.Config.HUDOffsetY.Value;
				((Component)OnionCanvas).transform.localPosition = Vector3.Lerp(((Component)OnionCanvas).transform.localPosition, transform.forward * 0.5f, 0.4f);
				((Component)OnionCanvas).transform.rotation = Quaternion.Slerp(((Component)OnionCanvas).transform.rotation, transform.rotation, 0.4f);
				OnionHUD.transform.localPosition = new Vector3(0f + value, 0f + value2, LethalMin.OnionHUDZDistance.InternalValue);
			}
		}
	}
	[HarmonyPatch(typeof(VRPlayer))]
	public static class VRPlayerPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		public static void AwakePostfix(VRPlayer __instance)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00b9: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			if (LethalMinVR.InVRMode)
			{
				Leader localLeader = PikminManager.instance.LocalLeader;
				LeaderVR leaderVR = ((Component)__instance).gameObject.AddComponent<LeaderVR>();
				((Component)localLeader.holdPosition).transform.SetParent(__instance.Bones.LocalRightHand);
				((Component)localLeader.holdPosition).transform.localPosition = new Vector3(0f, 0f, 0f);
				((Component)localLeader.ThrowOrigin).transform.SetParent(__instance.Bones.LocalRightHand);
				((Component)localLeader.ThrowOrigin).transform.localPosition = new Vector3(0f, 0f, 0f);
				leaderVR.LeaderScript = localLeader;
				GameObject val = new GameObject("GlowMobHoldPosForwardOffset");
				val.transform.SetParent(__instance.Bones.LocalLeftHand);
				val.transform.localPosition = new Vector3(0f, 0f, 0f);
				val.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
				leaderVR.GlowMobHoldPosition = new GameObject("GlowMobHoldPosition").transform;
				leaderVR.GlowMobHoldPosition.SetParent(val.transform);
				leaderVR.GlowMobHoldPosition.localPosition = new Vector3(0f, 0f, 0f);
				((Component)leaderVR.GlowMobHoldPosition).transform.localRotation = Quaternion.Euler(-90f, 0f, 0f);
			}
		}
	}
	[HarmonyPatch(typeof(WhistleItem))]
	public class WhistleItemPatch
	{
		[HarmonyPatch("OnDismiss")]
		[HarmonyPrefix]
		public static bool OnDismissPrefix(WhistleItem __instance)
		{
			if (!LethalMinVR.InVRMode || !ConfigItem<bool>.op_Implicit(LethalMin.UseMouthTriggerForWhistle))
			{
				return true;
			}
			Face val = Object.FindObjectOfType<Face>();
			return (Object)(object)val.heldItem == (Object)(object)__instance;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace NoteBoxz.LethalMinVR.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}