Decompiled source of TwinStickArmSprint v1.1.1

TwinStickArmSprint.dll

Decompiled 2 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using FistVR;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("TwinStickArmSprint")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TwinStickArmSprint")]
[assembly: AssemblyTitle("TwinStickArmSprint")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace TwinStickArmSprint;

public class Patch
{
	public class HandState
	{
		public Quaternion pointerRotation_0;

		public Quaternion pointerRotation_1;

		public int baseSpeedLeft;

		public int baseSpeedRight;
	}

	public static readonly Dictionary<float, int[]> SpeedMap = new Dictionary<float, int[]>
	{
		{
			3.6f,
			new int[2] { 5, 5 }
		},
		{
			3f,
			new int[2] { 5, 4 }
		},
		{
			2.55f,
			new int[2] { 5, 3 }
		},
		{
			2.4f,
			new int[2] { 4, 4 }
		},
		{
			2.175f,
			new int[2] { 5, 2 }
		},
		{
			2.025f,
			new int[2] { 5, 1 }
		},
		{
			1.95f,
			new int[2] { 4, 3 }
		},
		{
			1.8f,
			new int[2] { 5, 0 }
		},
		{
			1.575f,
			new int[2] { 4, 2 }
		},
		{
			1.5f,
			new int[2] { 3, 3 }
		},
		{
			1.425f,
			new int[2] { 4, 1 }
		},
		{
			1.2f,
			new int[2] { 4, 0 }
		},
		{
			1.125f,
			new int[2] { 3, 2 }
		},
		{
			0.975f,
			new int[2] { 3, 1 }
		},
		{
			0.75f,
			new int[2] { 2, 2 }
		},
		{
			0.6f,
			new int[2] { 2, 1 }
		},
		{
			0.45f,
			new int[2] { 1, 1 }
		},
		{
			0.375f,
			new int[2] { 2, 0 }
		},
		{
			0.225f,
			new int[2] { 1, 0 }
		},
		{
			0f,
			new int[2]
		}
	};

	public static int GetMovementHand(FVRMovementManager instance)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Invalid comparison between Unknown and I4
		int num = ((!instance.Hands[0].IsThisTheRightHand) ? 1 : 0);
		if ((int)GM.Options.MovementOptions.TwinStickLeftRightState != 1)
		{
			return 1 - num;
		}
		return num;
	}

	[HarmonyPatch(typeof(FVRMovementManager), "ShouldFlushTouchpad")]
	[HarmonyPostfix]
	public static void Patch_ShouldFlushTouchpad(FVRMovementManager __instance, FVRViveHand hand, ref bool __result)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Invalid comparison between Unknown and I4
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Invalid comparison between Unknown and I4
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Invalid comparison between Unknown and I4
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Invalid comparison between Unknown and I4
		if (!hand.IsInStreamlinedMode && (int)hand.CMode != 3 && (int)hand.CMode != 2 && (int)__instance.Mode == 4)
		{
			bool flag = hand.IsThisTheRightHand;
			if ((int)GM.Options.MovementOptions.TwinStickLeftRightState == 1)
			{
				flag = !flag;
			}
			if (__instance.m_isLeftHandActive && !flag)
			{
				__result = true;
			}
			if (__instance.m_isRightHandActive && flag)
			{
				__result = true;
			}
		}
	}

	[HarmonyPatch(typeof(FVRMovementManager), "UpdateMovementWithHand")]
	[HarmonyPrefix]
	public static bool Patch_HandMovementUpdate(FVRMovementManager __instance, FVRViveHand hand)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Invalid comparison between Unknown and I4
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Invalid comparison between Unknown and I4
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Invalid comparison between Unknown and I4
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		if ((int)__instance.Mode == 4)
		{
			if (Plugin.HeadArmswinger == null || !Plugin.HeadArmswinger.Value)
			{
				int movementHand = GetMovementHand(__instance);
				bool secondary2AxisWestDown = false;
				bool secondary2AxisEastDown = false;
				bool touchpadWestDown = false;
				bool touchpadEastDown = false;
				if ((int)hand.CMode == 3 || (int)hand.CMode == 2)
				{
					secondary2AxisWestDown = __instance.Hands[movementHand].Input.Secondary2AxisWestDown;
					secondary2AxisEastDown = __instance.Hands[movementHand].Input.Secondary2AxisEastDown;
					__instance.Hands[movementHand].Input.Secondary2AxisWestDown = false;
					__instance.Hands[movementHand].Input.Secondary2AxisEastDown = false;
				}
				if (hand.IsInStreamlinedMode)
				{
					touchpadWestDown = __instance.Hands[movementHand].Input.TouchpadWestDown;
					touchpadEastDown = __instance.Hands[movementHand].Input.TouchpadEastDown;
					__instance.Hands[movementHand].Input.TouchpadWestDown = false;
					__instance.Hands[movementHand].Input.TouchpadEastDown = false;
				}
				__instance.HandUpdateArmSwinger(hand);
				if ((int)hand.CMode == 3 || (int)hand.CMode == 2)
				{
					__instance.Hands[movementHand].Input.Secondary2AxisWestDown = secondary2AxisWestDown;
					__instance.Hands[movementHand].Input.Secondary2AxisEastDown = secondary2AxisEastDown;
				}
				if (hand.IsInStreamlinedMode)
				{
					__instance.Hands[movementHand].Input.TouchpadWestDown = touchpadWestDown;
					__instance.Hands[movementHand].Input.TouchpadEastDown = touchpadEastDown;
				}
				TwinStickSnapturnMode twinStickSnapturnState = GM.Options.MovementOptions.TwinStickSnapturnState;
				GM.Options.MovementOptions.TwinStickSnapturnState = (TwinStickSnapturnMode)0;
				__instance.HandUpdateTwinstick(hand);
				GM.Options.MovementOptions.TwinStickSnapturnState = twinStickSnapturnState;
			}
			else
			{
				__instance.HandUpdateArmSwinger(hand);
				Vector3 forward = GM.CurrentPlayerBody.Head.forward;
				forward.y = 0f;
				((Vector3)(ref forward)).Normalize();
				__instance.worldTPAxis = forward;
			}
			__instance.AXButtonCheck(hand);
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(FVRMovementManager), "UpdateSmoothLocomotion")]
	[HarmonyPrefix]
	public static void Patch_SmoothLocomotionUpdate(FVRMovementManager __instance, out HandState __state)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Invalid comparison between Unknown and I4
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Invalid comparison between Unknown and I4
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Invalid comparison between Unknown and I4
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0300: Unknown result type (might be due to invalid IL or missing references)
		//IL_031d: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: 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)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: 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_00f0: Invalid comparison between Unknown and I4
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Invalid comparison between Unknown and I4
		__state = new HandState();
		if ((int)__instance.Mode != 4)
		{
			return;
		}
		if (Plugin.HeadArmswinger == null || !Plugin.HeadArmswinger.Value)
		{
			int movementHand = GetMovementHand(__instance);
			if ((int)__instance.Hands[0].CMode == 3 || (int)__instance.Hands[0].CMode == 2)
			{
				__instance.Hands[movementHand].Input.Secondary2AxisWestPressed = false;
				__instance.Hands[movementHand].Input.Secondary2AxisEastPressed = false;
			}
			else if (__instance.Hands[0].IsInStreamlinedMode)
			{
				__instance.Hands[movementHand].Input.TouchpadWestPressed = false;
				__instance.Hands[movementHand].Input.TouchpadEastPressed = false;
			}
			ref bool reference = ref __instance.Hands[0].Input.BYButtonPressed;
			ref bool reference2 = ref __instance.Hands[1].Input.BYButtonPressed;
			if (__instance.Hands[0].IsInStreamlinedMode)
			{
				if ((int)__instance.Hands[0].CMode == 3 || (int)__instance.Hands[0].CMode == 2)
				{
					reference = ref __instance.Hands[0].Input.Secondary2AxisNorthPressed;
					reference2 = ref __instance.Hands[1].Input.Secondary2AxisNorthPressed;
				}
				else
				{
					reference = ref __instance.Hands[0].Input.TouchpadNorthPressed;
					reference2 = ref __instance.Hands[1].Input.TouchpadNorthPressed;
				}
			}
			float magnitude = ((Vector3)(ref __instance.worldTPAxis)).magnitude;
			reference = magnitude > 0f;
			reference2 = magnitude > 0f;
			__state.pointerRotation_0 = __instance.Hands[0].PointingTransform.localRotation;
			__state.pointerRotation_1 = __instance.Hands[1].PointingTransform.localRotation;
			__state.baseSpeedLeft = GM.Options.MovementOptions.ArmSwingerBaseSpeed_Left;
			__state.baseSpeedRight = GM.Options.MovementOptions.ArmSwingerBaseSpeed_Right;
			if (!(magnitude > 0f))
			{
				return;
			}
			__instance.Hands[0].PointingTransform.forward = ((Vector3)(ref __instance.worldTPAxis)).normalized;
			__instance.Hands[1].PointingTransform.forward = ((Vector3)(ref __instance.worldTPAxis)).normalized;
			{
				foreach (float key in SpeedMap.Keys)
				{
					if (magnitude > key)
					{
						GM.Options.MovementOptions.ArmSwingerBaseSpeed_Left = SpeedMap[key][0];
						GM.Options.MovementOptions.ArmSwingerBaseSpeed_Right = SpeedMap[key][1];
						break;
					}
				}
				return;
			}
		}
		__state.baseSpeedLeft = GM.Options.MovementOptions.ArmSwingerBaseSpeed_Left;
		__state.baseSpeedRight = GM.Options.MovementOptions.ArmSwingerBaseSpeed_Right;
		__state.pointerRotation_0 = __instance.Hands[0].PointingTransform.localRotation;
		__state.pointerRotation_1 = __instance.Hands[1].PointingTransform.localRotation;
		__instance.Hands[0].PointingTransform.forward = ((Vector3)(ref __instance.worldTPAxis)).normalized;
		__instance.Hands[1].PointingTransform.forward = ((Vector3)(ref __instance.worldTPAxis)).normalized;
	}

	[HarmonyPatch(typeof(FVRMovementManager), "UpdateSmoothLocomotion")]
	[HarmonyPostfix]
	public static void Patch_SmoothLocomotionUpdateEnd(FVRMovementManager __instance, HandState __state)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Invalid comparison between Unknown and I4
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		if ((int)__instance.Mode == 4)
		{
			__instance.Hands[0].PointingTransform.localRotation = __state.pointerRotation_0;
			__instance.Hands[1].PointingTransform.localRotation = __state.pointerRotation_1;
			GM.Options.MovementOptions.ArmSwingerBaseSpeed_Left = __state.baseSpeedLeft;
			GM.Options.MovementOptions.ArmSwingerBaseSpeed_Right = __state.baseSpeedRight;
		}
	}

	[HarmonyPatch(typeof(FVRPointableButton), "Awake")]
	[HarmonyPostfix]
	public static void Patch_FixDashName(FVRPointableButton __instance)
	{
		Text component = ((Component)__instance).GetComponent<Text>();
		if ((Object)(object)component != (Object)null && component.text == "Armswinger")
		{
			if (Plugin.HeadArmswinger == null || !Plugin.HeadArmswinger.Value)
			{
				component.text = "TS Arm Sprint";
			}
			else
			{
				component.text = "Head Armswinger";
			}
		}
	}
}
[BepInPlugin("dll.h3vr.odekak.twinstickarmsprint", "TwinStick Arm Sprint", "1.1.1")]
[BepInProcess("h3vr.exe")]
public class Plugin : BaseUnityPlugin
{
	public static ConfigEntry<bool> HeadArmswinger;

	public void Start()
	{
		LoadConfigFile();
		Harmony.CreateAndPatchAll(typeof(Patch), (string)null);
	}

	private void LoadConfigFile()
	{
		HeadArmswinger = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Head-Based Armswinger", false, "If true, act like regular Armswinger (no TwinStick), except use head direction instead of controller direction.");
	}
}
internal static class PluginInfo
{
	internal const string NAME = "TwinStick Arm Sprint";

	internal const string GUID = "dll.h3vr.odekak.twinstickarmsprint";

	internal const string VERSION = "1.1.1";
}