Decompiled source of VRJesterMod v1.0.1

plugins/VRJesterMod.dll

Decompiled 4 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Rewired.Utils;
using RoR2;
using UnityEngine;
using UnityEngine.XR;
using VRJester.Core;
using VRJester.Core.Radix;
using VRJester.Core.Recog;
using VRJester.Utils;
using VRJester.Utils.VRData;
using VRJester.Vox;
using Valve.VR;
using WindowsInput;
using WindowsInput.Native;

[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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("VRJesterMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e07bef45b54d27ac35b6fc0daa65970a4b67b019")]
[assembly: AssemblyProduct("VRJesterMod")]
[assembly: AssemblyTitle("VRJesterMod")]
[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]
	internal sealed class IsReadOnlyAttribute : Attribute
	{
	}
	[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;
		}
	}
	internal static class IsExternalInit
	{
	}
}
namespace VRJester
{
	public class Config
	{
		public string GESTURE_NAME = "GESTURE 1";

		public bool RECORD_MODE = false;

		public bool READ_DATA = false;

		public bool WRITE_DATA = false;

		public bool DEBUG_MODE = false;

		public float VHERE_RADIUS = 0.3f;

		public int INTERVAL_DELAY = 20;

		public int MAX_LISTENING_TIME = 400;

		public Dictionary<string, Dictionary<string, string>> GESTURE_ACTIONS = new Dictionary<string, Dictionary<string, string>>();

		public static Config ReadConfig()
		{
			try
			{
				StringBuilder stringBuilder = new StringBuilder();
				StreamReader streamReader = new StreamReader(Constants.CONFIG_PATH);
				string text = streamReader.ReadLine();
				stringBuilder.Append(text);
				while (text != null)
				{
					text = streamReader.ReadLine();
					stringBuilder.Append(text);
				}
				streamReader.Close();
				Console.ReadLine();
				return JsonConvert.DeserializeObject<Config>(stringBuilder.ToString());
			}
			catch (FileNotFoundException)
			{
				Log.Error("An error occurred reading config json! Attempting to generate new config...");
				WriteConfig();
			}
			catch (JsonException)
			{
				Log.Error("An error occurred reading config json!  Check if VRJesterAPI.cfg is malformed.");
			}
			return new Config();
		}

		public static Config ReadConfig(string configPath)
		{
			try
			{
				StringBuilder stringBuilder = new StringBuilder();
				StreamReader streamReader = new StreamReader(configPath);
				string text = streamReader.ReadLine();
				stringBuilder.Append(text);
				while (text != null)
				{
					text = streamReader.ReadLine();
					stringBuilder.Append(text);
				}
				streamReader.Close();
				Console.ReadLine();
				return JsonConvert.DeserializeObject<Config>(stringBuilder.ToString());
			}
			catch (FileNotFoundException)
			{
				Log.Error("An error occurred reading config json! Attempting to generate new config...");
				WriteConfig();
			}
			catch (JsonException)
			{
				Log.Error("An error occurred reading config json!  Check if VRJesterAPI.cfg is malformed.");
			}
			return ReadConfig();
		}

		public static void WriteConfig()
		{
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			try
			{
				Config config = new Config();
				Dictionary<string, string> value = new Dictionary<string, string>
				{
					["KEY_BIND"] = "R",
					["KEY_ACTION"] = "click"
				};
				config.GESTURE_ACTIONS["STRIKE"] = value;
				Dictionary<string, string> value2 = new Dictionary<string, string>
				{
					["KEY_BIND"] = "M2",
					["KEY_ACTION"] = "hold"
				};
				config.GESTURE_ACTIONS["UPPERCUT"] = value2;
				Dictionary<string, string> value3 = new Dictionary<string, string>
				{
					["KEY_BIND"] = "LSHIFT",
					["KEY_ACTION"] = "click"
				};
				config.GESTURE_ACTIONS["BURST"] = value3;
				using StreamWriter streamWriter = new StreamWriter(Constants.CONFIG_PATH);
				JsonTextWriter val = new JsonTextWriter((TextWriter)streamWriter);
				try
				{
					((JsonWriter)val).Formatting = (Formatting)1;
					JsonSerializer val2 = new JsonSerializer();
					val2.Serialize((JsonWriter)(object)val, (object)config);
				}
				finally
				{
					((IDisposable)val)?.Dispose();
				}
			}
			catch (IOException ex)
			{
				Log.Error("An error occurred writing config json!");
				Log.Error(ex.ToString());
				Log.Error(ex.StackTrace);
			}
		}

		public static void WriteConfig(Config config)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			try
			{
				using StreamWriter streamWriter = new StreamWriter(Constants.CONFIG_PATH);
				JsonTextWriter val = new JsonTextWriter((TextWriter)streamWriter);
				try
				{
					((JsonWriter)val).Formatting = (Formatting)1;
					JsonSerializer val2 = new JsonSerializer();
					val2.Serialize((JsonWriter)(object)val, (object)config);
				}
				finally
				{
					((IDisposable)val)?.Dispose();
				}
			}
			catch (IOException ex)
			{
				Log.Error("An error occurred writing config json!");
				Log.Error(ex.StackTrace);
			}
		}

		public static void WriteGestureStore()
		{
			List<GestureComponent> hmdGesture = new List<GestureComponent>();
			List<GestureComponent> list = new List<GestureComponent>();
			List<GestureComponent> list2 = new List<GestureComponent>();
			List<GestureComponent> list3 = new List<GestureComponent>();
			List<GestureComponent> list4 = new List<GestureComponent>();
			List<GestureComponent> list5 = new List<GestureComponent>();
			List<GestureComponent> list6 = new List<GestureComponent>();
			IDictionary<string, int> devicesInProximity = new Dictionary<string, int>();
			string direction = "*";
			GestureComponent item = new GestureComponent("RIGHT_CONTROLLER", "forward", 0L, 0.0, direction, devicesInProximity);
			GestureComponent item2 = new GestureComponent("RIGHT_CONTROLLER", "up", 0L, 0.0, direction, devicesInProximity);
			GestureComponent item3 = new GestureComponent("RIGHT_CONTROLLER", "forward", 2000L, 0.0, direction, devicesInProximity);
			GestureComponent item4 = new GestureComponent("LEFT_CONTROLLER", "forward", 0L, 0.0, direction, devicesInProximity);
			GestureComponent item5 = new GestureComponent("LEFT_CONTROLLER", "up", 0L, 0.0, direction, devicesInProximity);
			GestureComponent item6 = new GestureComponent("LEFT_CONTROLLER", "forward", 2000L, 0.0, direction, devicesInProximity);
			list.Add(item);
			list4.Add(item4);
			Gesture gesture = new Gesture(hmdGesture, list, list4);
			gesture.validDevices.Add("RIGHT_CONTROLLER");
			gesture.validDevices.Add("LEFT_CONTROLLER");
			GestureHandler.gestures.Store(gesture, "STRIKE");
			list2.Add(item);
			list2.Add(item2);
			list5.Add(item4);
			list5.Add(item5);
			Gesture gesture2 = new Gesture(hmdGesture, list2, list5);
			gesture2.validDevices.Add("RIGHT_CONTROLLER");
			gesture2.validDevices.Add("LEFT_CONTROLLER");
			GestureHandler.gestures.Store(gesture2, "UPPERCUT");
			list3.Add(item3);
			list6.Add(item6);
			Gesture gesture3 = new Gesture(hmdGesture, list3, list6);
			GestureHandler.gestures.Store(gesture3, "BURST");
			GestureHandler.gestures.Write();
		}
	}
	public abstract class Constants
	{
		public const string CONFIG_FILE = "VRJesterMod.cfg";

		public static readonly string CONFIG_PATH = Path.Combine(Paths.ConfigPath, "VRJesterMod.cfg");

		public const string GESTURE_STORE_FILE = "VRGestureStore.json";

		public static readonly string GESTURE_STORE_PATH = Path.Combine(Paths.ConfigPath, "VRGestureStore.json");

		public const string DEV_ROOT_PATH = "";

		public const string DEV_CONFIG_PATH = "";

		public const string DEV_GESTURE_STORE_PATH = "";

		public const string DEV_ARCHIVE_PATH = "";

		public const string SAMPLE_GESTURE_NAME = "GESTURE 1";

		public const bool RECORD_MODE = false;

		public const bool READ_DATA = false;

		public const bool WRITE_DATA = false;

		public const bool DEBUG_MODE = false;

		public const float VOX_LENGTH = 0.6f;

		public const float VHERE_RADIUS = 0.3f;

		public const int INTERVAL_DELAY = 20;

		public const int MAX_LISTENING_TIME = 400;

		public const double VERTICAL_DEGREE_SPAN = 0.85;

		public const float CARDINAL_DEGREE_SPAN = 45f;

		public const float DIRECTION_DEGREE_SPAN = 30f;

		public const string HMD = "HEAD_MOUNTED_DISPLAY";

		public const string RC = "RIGHT_CONTROLLER";

		public const string LC = "LEFT_CONTROLLER";

		public const string C2 = "EXTRA_TRACKER";

		public static IList<string> DEVICES = new List<string>(3) { "HEAD_MOUNTED_DISPLAY", "RIGHT_CONTROLLER", "LEFT_CONTROLLER" };
	}
	public class GestureHandler : MonoBehaviour
	{
		public static Config config = Config.ReadConfig();

		private static VRDataState vrDataState;

		private static string previousGesture = "";

		private static Gesture gesture;

		public static Gestures gestures = new Gestures(config, Constants.GESTURE_STORE_PATH);

		public static readonly Recognition recognition = new Recognition(gestures);

		private static readonly int DELAY = config.INTERVAL_DELAY;

		private static int sleep = DELAY;

		private static int limiter = config.MAX_LISTENING_TIME;

		public static Config ReloadConfigs()
		{
			config = Config.ReadConfig();
			gestures.Load();
			VRJesterMod.SetupKeyBinds();
			return config;
		}

		private void Update()
		{
			if (Input.GetKeyDown((KeyCode)103))
			{
				ReloadConfigs();
			}
			if (VRJesterMod.VR_LOADED)
			{
				if (Input.GetKeyDown((KeyCode)103))
				{
					Log.Info("Reloading configs...");
					ReloadConfigs();
					ResetJesterListener();
				}
				HandleVrGesture();
			}
		}

		private void HandleVrGesture()
		{
			vrDataState = new VRDataState();
			if (gesture == null)
			{
				gesture = new Gesture(vrDataState);
			}
			else
			{
				gesture.Track(vrDataState);
			}
			Dictionary<string, string> dictionary = recognition.Recognize(gesture);
			if (sleep != 0 && dictionary.Count != 0 && !previousGesture.Equals(dictionary["gestureName"]))
			{
				previousGesture = dictionary["gestureName"];
				((MonoBehaviour)this).StartCoroutine(TriggerAction(previousGesture));
				sleep = DELAY;
				limiter = config.MAX_LISTENING_TIME;
			}
			if (sleep == 0)
			{
				ResetJesterListener();
				sleep = DELAY;
			}
			sleep--;
		}

		private static void ResetJesterListener()
		{
			gesture = null;
			previousGesture = "";
			limiter = config.MAX_LISTENING_TIME;
		}

		private static IEnumerator TriggerAction(string gestureName)
		{
			config.GESTURE_ACTIONS.TryGetValue(gestureName, out var gestureAction);
			gestureAction.TryGetValue("KEY_BIND", out var keyBind);
			gestureAction.TryGetValue("KEY_ACTION", out var keyAction);
			VRJesterMod.KEY_MAPPINGS.TryGetValue(keyBind, out var keyCode);
			if ((int)keyCode < 5)
			{
				yield return MousePress(keyCode, keyAction);
			}
			else
			{
				yield return KeyboardPress(keyCode, keyAction);
			}
		}

		private static IEnumerator MousePress(VirtualKeyCode keyCode, string keyAction)
		{
			//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)
			if (keyAction.ToLower() == "click" && (int)keyCode == 1)
			{
				VRJesterMod.SIM.Mouse.LeftButtonDown();
				yield return null;
				yield return null;
				VRJesterMod.SIM.Mouse.LeftButtonUp();
			}
			else if (keyAction.ToLower() == "click" && (int)keyCode == 2)
			{
				VRJesterMod.SIM.Mouse.RightButtonDown();
				yield return null;
				yield return null;
				VRJesterMod.SIM.Mouse.RightButtonUp();
			}
			else if (keyAction.ToLower() == "hold" && (int)keyCode == 1)
			{
				VRJesterMod.SIM.Mouse.LeftButtonDown();
			}
			else if (keyAction.ToLower() == "release" && (int)keyCode == 1)
			{
				VRJesterMod.SIM.Mouse.LeftButtonUp();
			}
			else if (keyAction.ToLower() == "hold" && (int)keyCode == 2)
			{
				VRJesterMod.SIM.Mouse.RightButtonDown();
			}
			else if (keyAction.ToLower() == "release" && (int)keyCode == 2)
			{
				VRJesterMod.SIM.Mouse.RightButtonUp();
			}
		}

		private static IEnumerator KeyboardPress(VirtualKeyCode keyCode, string keyAction)
		{
			//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)
			if (keyAction.ToLower() == "click")
			{
				VRJesterMod.SIM.Keyboard.KeyDown(keyCode);
				yield return null;
				yield return null;
				VRJesterMod.SIM.Keyboard.KeyUp(keyCode);
			}
			else if (keyAction.ToLower() == "hold")
			{
				VRJesterMod.SIM.Keyboard.KeyDown(keyCode);
			}
			else if (keyAction.ToLower() == "release")
			{
				VRJesterMod.SIM.Keyboard.KeyUp(keyCode);
			}
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.cali.vrjester", "VRJesterMod", "1.0.0")]
	public class VRJesterMod : BaseUnityPlugin
	{
		public const string PluginAuthor = "Caliburs";

		public static CVRSystem VR_SYSTEM = null;

		public static bool VR_LOADED = false;

		public static Dictionary<string, VirtualKeyCode> KEY_MAPPINGS = new Dictionary<string, VirtualKeyCode>();

		public static InputSimulator SIM = new InputSimulator();

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			((Component)this).gameObject.AddComponent(typeof(GestureHandler));
			SetupConfig();
			SetupClient();
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, (Action)delegate
			{
				((MonoBehaviour)this).StartCoroutine(InitVRJester());
			});
		}

		private IEnumerator InitVRJester()
		{
			yield return null;
			EVRInitError eError = (EVRInitError)0;
			CVRSystem VR_SYSTEM = OpenVR.Init(ref eError, (EVRApplicationType)3, "");
			if (!ExtensionMethods.IsNullOrDestroyed((object)VR_SYSTEM))
			{
				Log.Info("OpenVR Background Process Initialized...");
				Log.Info("Is tracked device connected ?  " + VR_SYSTEM.IsTrackedDeviceConnected(0u));
				VR_LOADED = true;
			}
			else
			{
				Log.Info("Running in Non-VR Mode...");
				VR_LOADED = false;
			}
		}

		private static void SetupConfig()
		{
			Log.Info("Setting up config files...");
			if (!File.Exists(Constants.CONFIG_PATH))
			{
				Config.WriteConfig();
			}
			if (!File.Exists(Constants.GESTURE_STORE_PATH))
			{
				Config.WriteGestureStore();
			}
		}

		private static void SetupClient()
		{
			Log.Info("Setting up client...");
			GestureHandler.config = Config.ReadConfig();
			GestureHandler.gestures.Load();
			SetupKeyBinds();
		}

		public static void SetupKeyBinds()
		{
			//IL_006b: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: 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_018d: Unknown result type (might be due to invalid IL or missing references)
			Log.Info("Setting up key bindings...");
			foreach (Dictionary<string, string> value6 in GestureHandler.config.GESTURE_ACTIONS.Values)
			{
				value6.TryGetValue("KEY_BIND", out var value);
				if (value.Length == 1)
				{
					VirtualKeyCode value2 = (VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), "VK_" + value.ToUpper());
					KEY_MAPPINGS[value] = value2;
					Log.Debug("Storing key bind:  " + value + " -> " + ((object)(VirtualKeyCode)(ref value2)).ToString());
					continue;
				}
				if (value.Length == 0)
				{
					Log.Debug("Key bind not found!");
					continue;
				}
				if (value.ToUpper() == "M1")
				{
					VirtualKeyCode value3 = (VirtualKeyCode)1;
					KEY_MAPPINGS[value] = value3;
					Log.Debug("Storing key bind:  " + value + " -> " + ((object)(VirtualKeyCode)(ref value3)).ToString());
					continue;
				}
				if (value.ToUpper() == "M2")
				{
					VirtualKeyCode value4 = (VirtualKeyCode)2;
					KEY_MAPPINGS[value] = value4;
					Log.Debug("Storing key bind:  " + value + " -> " + ((object)(VirtualKeyCode)(ref value4)).ToString());
					continue;
				}
				try
				{
					VirtualKeyCode value5 = (VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), value.ToUpper());
					KEY_MAPPINGS[value] = value5;
					Log.Debug("Storing key bind:  " + value + " -> " + ((object)(VirtualKeyCode)(ref value5)).ToString());
				}
				catch (ArgumentException)
				{
					Log.Warning("Key bind not found! Failed to store key bind:  " + value);
				}
			}
		}
	}
}
namespace VRJester.Vox
{
	public class Vhere
	{
		private readonly VRDevice vrDevice;

		public readonly Config config;

		private int id;

		private int previousId;

		private string movementDirection = "idle";

		private GestureTrace gestureTrace;

		public Vector3 centroid;

		public Quaternion faceDirection;

		public float sphereRadius = 0.3f;

		public GestureTrace Trace => gestureTrace;

		public int Id
		{
			get
			{
				return id;
			}
			set
			{
				id = value;
			}
		}

		public int PreviousId
		{
			get
			{
				return previousId;
			}
			set
			{
				previousId = value;
			}
		}

		public VRDevice VrDevice => vrDevice;

		public Vhere(VRDevice vrDevice, VRPose centroidPose, Quaternion faceDirection, string configPath)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			config = Config.ReadConfig(configPath);
			if (config.VHERE_RADIUS != sphereRadius)
			{
				sphereRadius = config.VHERE_RADIUS;
			}
			id = 0;
			previousId = id;
			this.vrDevice = vrDevice;
			this.faceDirection = faceDirection;
			gestureTrace = new GestureTrace(Convert.ToString(id), vrDevice, centroidPose, faceDirection);
			UpdateVherePosition(centroidPose.Position);
		}

		public bool HasPoint(Vector3 point)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			double num = Math.Pow(point.x - centroid.x, 2.0);
			double num2 = Math.Pow(point.y - centroid.y, 2.0);
			double num3 = Math.Pow(point.z - centroid.z, 2.0);
			double num4 = Math.Sqrt(num + num2 + num3);
			return num4 <= (double)sphereRadius;
		}

		public void UpdateProximity(VRDataState vrDataState, VRDevice vrDevice)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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)
			Vector3 position = VRDataState.GetVRPose(vrDataState, vrDevice).Position;
			if (HasPoint(position))
			{
				IDictionary<string, int> devicesInProximity = gestureTrace.DevicesInProximity;
				devicesInProximity.TryGetValue(vrDevice.ToString(), out var value);
				gestureTrace.UpdateDeviceInProximity(vrDevice.ToString(), value);
			}
		}

		public VRPose GenerateVhere(VRDataState vrDataState)
		{
			//IL_007c: 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)
			VRPose vRPose = default(VRPose);
			for (int i = 0; i < Enum.GetValues(typeof(VRDevice)).Length; i++)
			{
				VRDevice vRDevice = Enum.GetValues(typeof(VRDevice)).Cast<VRDevice>().ToList()[i];
				if (vrDevice == vRDevice)
				{
					vRPose = VRDataState.GetVRPose(vrDataState, vrDevice);
				}
				else
				{
					UpdateProximity(vrDataState, vRDevice);
				}
			}
			if (!HasPoint(vRPose.Position))
			{
				UpdateVherePosition(vRPose.Position);
				Id++;
				gestureTrace.movement = movementDirection;
				movementDirection = "idle";
			}
			else
			{
				gestureTrace.AddPose(vRPose);
			}
			return vRPose;
		}

		public void UpdateVherePosition(Vector3 dif)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			centroid = dif;
		}

		public GestureTrace BeginTrace(VRPose pose)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			gestureTrace = new GestureTrace(Convert.ToString(id), vrDevice, pose, faceDirection);
			return gestureTrace;
		}
	}
}
namespace VRJester.Utils
{
	public class Calcs
	{
		public static double GetMagnitude2D(Vector3 v)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			return Math.Sqrt(Math.Pow(v.x, 2.0) + Math.Pow(v.z, 2.0));
		}

		public static double GetMagnitude3D(Vector3 v)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			return Math.Sqrt(Math.Pow(v.x, 2.0) + Math.Pow(v.y, 2.0) + Math.Pow(v.z, 2.0));
		}

		public static double GetAngle2D(Vector3 v1, Vector3 v2)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(1f, 0f, 1f);
			double num = Vector3.Dot(Vector3.Scale(v1, val), Vector3.Scale(v2, val));
			double d = num / (GetMagnitude2D(v1) * GetMagnitude2D(v2));
			return ConvertToDegrees(Math.Acos(d));
		}

		public static double GetAngle3D(Vector3 v1, Vector3 v2)
		{
			//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)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			double num = Vector3.Dot(v1, v2);
			double d = num / (GetMagnitude3D(v1) * GetMagnitude3D(v2));
			return ConvertToDegrees(Math.Acos(d));
		}

		public static double ConvertToDegrees(double radians)
		{
			return 180.0 / Math.PI * radians;
		}
	}
}
namespace VRJester.Utils.VRData
{
	public class GestureFactory
	{
		public string vrDevice;

		public string movement;

		public long elapsedTime;

		public double speed;

		public string direction;

		public IDictionary<string, int> devicesInProximity;

		public GestureFactory(string vrDevice, string movement, long elapsedTime, double speed, string direction, IDictionary<string, int> devicesInProximity)
		{
			this.vrDevice = vrDevice;
			this.movement = movement;
			this.elapsedTime = elapsedTime;
			this.speed = speed;
			this.direction = direction;
			this.devicesInProximity = devicesInProximity;
			base..ctor();
		}

		public GestureComponent CreateGestureComponent()
		{
			return new GestureComponent(vrDevice, movement, elapsedTime, speed, direction, devicesInProximity);
		}
	}
	public struct VRPose
	{
		public Vector3 Position { get; set; }

		public Quaternion Direction { get; set; }

		public VRPose(Vector3 position, Quaternion direction)
		{
			//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)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			Position = position;
			Direction = direction;
		}

		public override readonly string ToString()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			return $"Pose[ position: {Position} | rotation: {Direction} ]";
		}
	}
	public class VRDataState
	{
		private readonly VRPose hmd;

		private readonly VRPose rc;

		private readonly VRPose lc;

		public VRPose Hmd => hmd;

		public VRPose Rc => rc;

		public VRPose Lc => lc;

		public VRDataState()
		{
			hmd = SetVRPose(VRDevice.HEAD_MOUNTED_DISPLAY);
			rc = SetVRPose(VRDevice.RIGHT_CONTROLLER);
			lc = SetVRPose(VRDevice.LEFT_CONTROLLER);
		}

		public override string ToString()
		{
			return "data:\r\n\t hmd: " + hmd.ToString() + "\r\n\t rc: " + rc.ToString() + "\r\n\t lc: " + lc;
		}

		public VRPose SetVRPose(VRDevice vrDevice)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			XRNode val;
			switch (vrDevice)
			{
			case VRDevice.HEAD_MOUNTED_DISPLAY:
				val = (XRNode)3;
				break;
			case VRDevice.RIGHT_CONTROLLER:
				val = (XRNode)5;
				break;
			case VRDevice.LEFT_CONTROLLER:
				val = (XRNode)4;
				break;
			default:
				Log.Info("VRDevice not yet supported. Defaulting to HMD instead");
				val = (XRNode)3;
				break;
			}
			InputDevice deviceAtXRNode = InputDevices.GetDeviceAtXRNode(val);
			Vector3 position = default(Vector3);
			((InputDevice)(ref deviceAtXRNode)).TryGetFeatureValue(CommonUsages.devicePosition, ref position);
			Quaternion direction = default(Quaternion);
			((InputDevice)(ref deviceAtXRNode)).TryGetFeatureValue(CommonUsages.deviceRotation, ref direction);
			return new VRPose(position, direction);
		}

		public static VRPose GetVRPose(VRDataState vrDataState, VRDevice vrDevice)
		{
			switch (vrDevice)
			{
			case VRDevice.HEAD_MOUNTED_DISPLAY:
				return vrDataState.hmd;
			case VRDevice.RIGHT_CONTROLLER:
				return vrDataState.rc;
			case VRDevice.LEFT_CONTROLLER:
				return vrDataState.lc;
			default:
				Log.Error("VRDevice not yet supported!");
				return default(VRPose);
			}
		}
	}
	public enum VRDevice
	{
		HEAD_MOUNTED_DISPLAY,
		RIGHT_CONTROLLER,
		LEFT_CONTROLLER
	}
}
namespace VRJester.Core
{
	public class Gesture
	{
		private readonly IList<Vhere> vhereList = new List<Vhere>();

		public List<GestureComponent> hmdGesture = new List<GestureComponent>();

		public List<GestureComponent> rcGesture = new List<GestureComponent>();

		public List<GestureComponent> lcGesture = new List<GestureComponent>();

		public IList<string> validDevices = new List<string>();

		public Gesture(VRDataState vrDataState)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			VRPose hmd = vrDataState.Hmd;
			VRPose rc = vrDataState.Rc;
			VRPose lc = vrDataState.Lc;
			Vhere item = new Vhere(VRDevice.HEAD_MOUNTED_DISPLAY, hmd, hmd.Direction, Constants.CONFIG_PATH);
			Vhere item2 = new Vhere(VRDevice.RIGHT_CONTROLLER, rc, hmd.Direction, Constants.CONFIG_PATH);
			Vhere item3 = new Vhere(VRDevice.LEFT_CONTROLLER, lc, hmd.Direction, Constants.CONFIG_PATH);
			vhereList.Add(item);
			vhereList.Add(item2);
			vhereList.Add(item3);
		}

		public Gesture(List<GestureComponent> hmdGesture, List<GestureComponent> rcGesture, List<GestureComponent> lcGesture)
		{
			if (hmdGesture != null)
			{
				this.hmdGesture = hmdGesture;
			}
			if (rcGesture != null)
			{
				this.rcGesture = rcGesture;
			}
			if (lcGesture != null)
			{
				this.lcGesture = lcGesture;
			}
		}

		public Gesture(Dictionary<string, List<GestureComponent>> gesture)
		{
			foreach (string key in gesture.Keys)
			{
				IList<string> list = key.Split(new char[1] { '|' });
				if (list.Contains("HEAD_MOUNTED_DISPLAY"))
				{
					IDictionary<string, string> newValues = new Dictionary<string, string> { ["VrDevice"] = "HEAD_MOUNTED_DISPLAY" };
					if (list.Count > 1)
					{
						validDevices.Add("HEAD_MOUNTED_DISPLAY");
					}
					hmdGesture = GestureComponent.Copy(gesture[key], newValues);
				}
				if (list.Contains("RIGHT_CONTROLLER"))
				{
					IDictionary<string, string> newValues2 = new Dictionary<string, string> { ["VrDevice"] = "RIGHT_CONTROLLER" };
					if (list.Count > 1)
					{
						validDevices.Add("RIGHT_CONTROLLER");
					}
					rcGesture = GestureComponent.Copy(gesture[key], newValues2);
				}
				if (list.Contains("LEFT_CONTROLLER"))
				{
					IDictionary<string, string> newValues3 = new Dictionary<string, string> { ["VrDevice"] = "LEFT_CONTROLLER" };
					if (list.Count > 1)
					{
						validDevices.Add("LEFT_CONTROLLER");
					}
					lcGesture = GestureComponent.Copy(gesture[key], newValues3);
				}
			}
		}

		public override string ToString()
		{
			return "Gesture:\r\n  hmdGesture: " + string.Join(",", hmdGesture) + "\r\n  rcGesture: " + string.Join(",", rcGesture) + "\r\n  lcGesture: " + string.Join(",", lcGesture);
		}

		public void Track(VRDataState vrDataRoomPre)
		{
			foreach (Vhere vhere in vhereList)
			{
				VRPose vRPose = vhere.GenerateVhere(vrDataRoomPre);
				int id = vhere.Id;
				if (vhere.PreviousId != id)
				{
					vhere.PreviousId = id;
					GestureTrace trace = vhere.Trace;
					trace.CompleteTrace(vRPose);
					vhere.BeginTrace(vRPose);
					switch (vhere.VrDevice)
					{
					case VRDevice.HEAD_MOUNTED_DISPLAY:
						hmdGesture.Add(trace.ToGestureComponent());
						break;
					case VRDevice.RIGHT_CONTROLLER:
						rcGesture.Add(trace.ToGestureComponent());
						break;
					case VRDevice.LEFT_CONTROLLER:
						lcGesture.Add(trace.ToGestureComponent());
						break;
					}
				}
			}
		}

		public List<GestureComponent> GetGesture(string vrDevice)
		{
			List<GestureComponent> result = new List<GestureComponent>();
			switch (vrDevice)
			{
			case "HEAD_MOUNTED_DISPLAY":
				result = hmdGesture;
				break;
			case "RIGHT_CONTROLLER":
				result = rcGesture;
				break;
			case "LEFT_CONTROLLER":
				result = lcGesture;
				break;
			}
			return result;
		}
	}
	public class GestureComponent : ICloneable
	{
		public readonly string VrDevice;

		public readonly string Movement;

		public readonly string Direction;

		public readonly long ElapsedTime;

		public readonly double Speed;

		public readonly IDictionary<string, int> DevicesInProximity;

		public GestureComponent(string VrDevice, string Movement, long ElapsedTime, double Speed, string Direction, IDictionary<string, int> DevicesInProximity)
		{
			this.VrDevice = VrDevice;
			this.Movement = Movement;
			this.Direction = Direction;
			this.ElapsedTime = ElapsedTime;
			this.Speed = Speed;
			this.DevicesInProximity = DevicesInProximity;
			base..ctor();
		}

		public object Clone()
		{
			return MemberwiseClone();
		}

		public override string ToString()
		{
			return string.Format("GCPath[ {0} | Movement={1} | Direction={2} | Time={3:D} | Speed={4:F} | Proximity Devices:{5}]", VrDevice, Movement, Direction, ElapsedTime, Speed, string.Join(",", DevicesInProximity));
		}

		public override int GetHashCode()
		{
			int hashCode = Movement.GetHashCode();
			long elapsedTime = ElapsedTime;
			int num = hashCode - elapsedTime.GetHashCode();
			double speed = Speed;
			return num - speed.GetHashCode() + Direction.GetHashCode() - string.Join("", DevicesInProximity.Keys).GetHashCode();
		}

		public override bool Equals(object obj)
		{
			if (this == obj)
			{
				return true;
			}
			if (obj.GetType() != typeof(GestureComponent))
			{
				return false;
			}
			GestureComponent gestureComponent = (GestureComponent)obj;
			return VrDevice == gestureComponent.VrDevice && Movement == gestureComponent.Movement && Direction == gestureComponent.Direction && object.Equals(ElapsedTime, gestureComponent.ElapsedTime) && object.Equals(Speed, gestureComponent.Speed) && DevicesInProximity.Keys.SequenceEqual(gestureComponent.DevicesInProximity.Keys);
		}

		public bool Matches(GestureComponent gesturePath)
		{
			return VrDevice.Equals(gesturePath.VrDevice) && Movement.Equals(gesturePath.Movement) && ElapsedTime <= gesturePath.ElapsedTime && Speed <= gesturePath.Speed && IsWithinDirection(Direction, gesturePath.Direction) && IsWithinProximity(DevicesInProximity, gesturePath.DevicesInProximity);
		}

		public static bool StartsWith(List<GestureComponent> gesture, List<GestureComponent> subGesture)
		{
			try
			{
				return gesture.GetRange(0, subGesture.Count).Equals(subGesture);
			}
			catch (IndexOutOfRangeException)
			{
				return false;
			}
		}

		public static bool MatchesWith(List<GestureComponent> gesture, List<GestureComponent> subGesture)
		{
			try
			{
				for (int i = 0; i < subGesture.Count; i++)
				{
					if (!subGesture[i].Matches(gesture[i]))
					{
						return false;
					}
				}
				return true;
			}
			catch (IndexOutOfRangeException)
			{
				return false;
			}
			catch (ArgumentOutOfRangeException)
			{
				return false;
			}
		}

		private static bool IsWithinDirection(string Direction, string otherDirection)
		{
			if (Direction.Equals("*"))
			{
				return true;
			}
			return Direction.Equals(otherDirection);
		}

		private static bool IsWithinProximity(IDictionary<string, int> devices, IDictionary<string, int> otherDevices)
		{
			if (devices.Count == 0)
			{
				return true;
			}
			return object.Equals(devices.Keys, otherDevices.Keys);
		}

		public static List<GestureComponent> Concat(List<GestureComponent> gestureComponent1, List<GestureComponent> gestureComponent2)
		{
			if (gestureComponent1 == null)
			{
				gestureComponent1 = new List<GestureComponent>();
			}
			if (gestureComponent2 == null)
			{
				gestureComponent2 = new List<GestureComponent>();
			}
			return gestureComponent1.Concat(gestureComponent2).ToList();
		}

		public static List<GestureComponent> Copy(List<GestureComponent> gesture, IDictionary<string, string> newValues)
		{
			List<GestureComponent> list = new List<GestureComponent>();
			foreach (GestureComponent item2 in gesture)
			{
				newValues.TryGetValue("VrDevice", out var value);
				string vrDevice = ((value == null) ? item2.VrDevice : value);
				string movement = item2.Movement;
				string direction = item2.Direction;
				long elapsedTime = item2.ElapsedTime;
				double speed = item2.Speed;
				IDictionary<string, int> devicesInProximity = item2.DevicesInProximity;
				GestureComponent item = new GestureComponent(vrDevice, movement, elapsedTime, speed, direction, devicesInProximity);
				list.Add(item);
			}
			return list;
		}
	}
	public static class Extensions
	{
		public static bool IsEqual(this List<GestureComponent> gesture, List<GestureComponent> otherGesture)
		{
			bool result = true;
			if (gesture.Count == otherGesture.Count)
			{
				for (int i = 0; i < gesture.Count; i++)
				{
					if (gesture[i].Equals(otherGesture[i]))
					{
						result = true;
						continue;
					}
					result = false;
					break;
				}
			}
			else
			{
				result = false;
			}
			return result;
		}

		public static int HashCode(this List<GestureComponent> gesture)
		{
			int num = 1;
			foreach (GestureComponent item in gesture)
			{
				num = 31 * num + (item?.GetHashCode() ?? 0);
			}
			return num;
		}
	}
	public class Gestures
	{
		private readonly string gestureStorePath;

		public readonly GestureStore gestureStore;

		public Dictionary<string, string> gestureNameSpace;

		public Dictionary<int, string> hmdGestureMapping;

		public Dictionary<int, string> rcGestureMapping;

		public Dictionary<int, string> lcGestureMapping;

		public RadixTree hmdGestures;

		public RadixTree rcGestures;

		public RadixTree lcGestures;

		public Dictionary<string, IList<string>> eitherDeviceGestures;

		public Config config;

		public Gestures(Config config, string gestureStorePath)
		{
			this.gestureStorePath = gestureStorePath;
			gestureStore = new GestureStore();
			gestureNameSpace = new Dictionary<string, string>();
			hmdGestureMapping = new Dictionary<int, string>();
			rcGestureMapping = new Dictionary<int, string>();
			lcGestureMapping = new Dictionary<int, string>();
			hmdGestures = new RadixTree("HEAD_MOUNTED_DISPLAY");
			rcGestures = new RadixTree("RIGHT_CONTROLLER");
			lcGestures = new RadixTree("LEFT_CONTROLLER");
			eitherDeviceGestures = new Dictionary<string, IList<string>>();
			this.config = config;
			base..ctor();
		}

		public GestureStore Read()
		{
			try
			{
				StringBuilder stringBuilder = new StringBuilder();
				StreamReader streamReader = new StreamReader(gestureStorePath);
				string text = streamReader.ReadLine();
				stringBuilder.Append(text);
				while (text != null)
				{
					text = streamReader.ReadLine();
					stringBuilder.Append(text);
				}
				streamReader.Close();
				Console.ReadLine();
				return JsonConvert.DeserializeObject<GestureStore>(stringBuilder.ToString());
			}
			catch (Exception ex) when (ex is FileNotFoundException || ex is JsonException)
			{
				Log.Error("An error occurred reading gesture store json!");
				Log.Error(ex);
			}
			return null;
		}

		public void Load()
		{
			GestureStore gestureStore = Read();
			Clear();
			if (gestureStore == null)
			{
				return;
			}
			HashSet<string> hashSet = new HashSet<string>(gestureStore.GESTURES.Keys);
			foreach (string item in hashSet)
			{
				try
				{
					Gesture gesture = new Gesture(gestureStore.GESTURES[item]);
					Store(gesture, item);
				}
				catch (NullReferenceException data)
				{
					Log.Error(data);
					Log.Error("SKIPPING LOADING GESTURE: " + item);
				}
			}
		}

		public void Store(Gesture gesture, string name)
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (string dEVICE in Constants.DEVICES)
			{
				if (gesture.validDevices.Count > 0)
				{
					eitherDeviceGestures[name] = gesture.validDevices;
					string value = StoreToMapping(gesture, name, dEVICE);
					if (!stringBuilder.ToString().Contains(value))
					{
						stringBuilder.Append(value);
					}
				}
				else
				{
					stringBuilder.Append(StoreToMapping(gesture, name, dEVICE));
				}
			}
			string key = stringBuilder.ToString();
			gestureNameSpace[key] = name;
		}

		public void Store(RadixTree gestureTree, Dictionary<int, string> gestureMapping, List<GestureComponent> gesture, string name)
		{
			gestureTree.Insert(gesture);
			gestureMapping[gesture.HashCode()] = name;
			string key = gesture.HashCode().ToString() ?? "";
			gestureNameSpace[key] = name;
		}

		public string StoreToMapping(Gesture gesture, string name, string vrDevice)
		{
			string text = "";
			RadixTree radixTree = GetRadixTree(vrDevice);
			List<GestureComponent> gesture2 = gesture.GetGesture(vrDevice);
			Dictionary<int, string> gestureMapping = GetGestureMapping(vrDevice);
			if (gesture2.Count > 0)
			{
				radixTree.Insert(gesture2);
				if (!gestureMapping.ContainsKey(gesture2.HashCode()))
				{
					gestureMapping.Add(gesture2.HashCode(), name);
				}
				text += gesture2.HashCode();
			}
			return text;
		}

		public void Write()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			WriteGestures("HEAD_MOUNTED_DISPLAY", hmdGestures.root, new List<GestureComponent>());
			WriteGestures("RIGHT_CONTROLLER", rcGestures.root, new List<GestureComponent>());
			WriteGestures("LEFT_CONTROLLER", lcGestures.root, new List<GestureComponent>());
			try
			{
				using StreamWriter streamWriter = new StreamWriter(gestureStorePath);
				JsonTextWriter val = new JsonTextWriter((TextWriter)streamWriter);
				try
				{
					((JsonWriter)val).Formatting = (Formatting)1;
					JsonSerializer val2 = new JsonSerializer();
					val2.Serialize((JsonWriter)(object)val, (object)gestureStore);
				}
				finally
				{
					((IDisposable)val)?.Dispose();
				}
			}
			catch (IOException ex)
			{
				Log.Error("An error occurred writing config json!");
				Log.Error(ex.StackTrace);
			}
		}

		private void WriteGestures(string vrDevice, Node current, List<GestureComponent> result)
		{
			if (current.isGesture)
			{
				GetGestureMapping(vrDevice).TryGetValue(result.HashCode(), out var value);
				eitherDeviceGestures.TryGetValue(value, out var value2);
				gestureStore.AddGesture(vrDevice, value, result, value2);
			}
			foreach (Branch value3 in current.paths.Values)
			{
				WriteGestures(vrDevice, value3.next, GestureComponent.Concat(result, value3.gesture));
			}
		}

		public void Clear()
		{
			gestureNameSpace = new Dictionary<string, string>();
			hmdGestures = new RadixTree("HEAD_MOUNTED_DISPLAY");
			rcGestures = new RadixTree("RIGHT_CONTROLLER");
			lcGestures = new RadixTree("LEFT_CONTROLLER");
			hmdGestureMapping = new Dictionary<int, string>();
			rcGestureMapping = new Dictionary<int, string>();
			lcGestureMapping = new Dictionary<int, string>();
			eitherDeviceGestures = new Dictionary<string, IList<string>>();
		}

		private Dictionary<int, string> GetGestureMapping(string vrDevice)
		{
			Dictionary<int, string> result = new Dictionary<int, string>();
			switch (vrDevice)
			{
			case "HEAD_MOUNTED_DISPLAY":
				result = hmdGestureMapping;
				break;
			case "RIGHT_CONTROLLER":
				result = rcGestureMapping;
				break;
			case "LEFT_CONTROLLER":
				result = lcGestureMapping;
				break;
			}
			return result;
		}

		private RadixTree GetRadixTree(string vrDevice)
		{
			RadixTree result = null;
			switch (vrDevice)
			{
			case "HEAD_MOUNTED_DISPLAY":
				result = hmdGestures;
				break;
			case "RIGHT_CONTROLLER":
				result = rcGestures;
				break;
			case "LEFT_CONTROLLER":
				result = lcGestures;
				break;
			}
			return result;
		}
	}
	public class GestureStore
	{
		public Dictionary<string, Dictionary<string, List<GestureComponent>>> GESTURES = new Dictionary<string, Dictionary<string, List<GestureComponent>>>();

		public virtual void AddGesture(string vrDevice, string gestureName, List<GestureComponent> gesture, IList<string> validDevices)
		{
			GESTURES.TryGetValue(gestureName, out var value);
			if (ExtensionMethods.IsNullOrDestroyed((object)value))
			{
				value = new Dictionary<string, List<GestureComponent>>();
			}
			if (validDevices != null)
			{
				vrDevice = string.Join("|", validDevices);
				List<GestureComponent> value2 = GestureComponent.Copy(gesture, new Dictionary<string, string> { { "VrDevice", vrDevice } });
				value[vrDevice] = value2;
				GESTURES[gestureName] = value;
			}
			else
			{
				value[vrDevice] = gesture;
				GESTURES[gestureName] = value;
			}
		}
	}
	public class GestureTrace
	{
		public string voxId;

		public string vrDevice;

		public string movement = "idle";

		public string direction = "*";

		public long elapsedTime = 0L;

		public double speed;

		public readonly IDictionary<string, int> devicesInProximity = new Dictionary<string, int>();

		private Vector3 front;

		private Vector3 back;

		private Vector3 right;

		private Vector3 left;

		private readonly IList<VRPose> poses = new List<VRPose>();

		public Quaternion faceDirection;

		public string VoxId => voxId;

		public string VrDevice => vrDevice;

		public string Movement
		{
			get
			{
				return movement;
			}
			set
			{
				movement = value;
			}
		}

		public long ElapsedTime
		{
			get
			{
				return elapsedTime;
			}
			set
			{
				if (elapsedTime == 0)
				{
					elapsedTime = value;
				}
				else
				{
					elapsedTime = (value - elapsedTime) / 1000000;
				}
			}
		}

		public double Speed => speed;

		public string Direction
		{
			get
			{
				return direction;
			}
			set
			{
				direction = value;
			}
		}

		public IDictionary<string, int> DevicesInProximity => devicesInProximity;

		public GestureTrace(string voxId, VRDevice vrDevice, VRPose pose, Quaternion faceDirection)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			this.voxId = voxId;
			this.vrDevice = vrDevice.ToString();
			this.faceDirection = faceDirection;
			SetMovementBuckets(faceDirection);
			ElapsedTime = NanoTime();
			poses.Add(pose);
		}

		public override string ToString()
		{
			return $"VRDEVICE: {vrDevice} | MOVED: {movement} | Time Elapsed: {elapsedTime:D}ms";
		}

		public GestureComponent ToGestureComponent()
		{
			return new GestureComponent(VrDevice, Movement, ElapsedTime, Speed, Direction, DevicesInProximity);
		}

		public void SetTrajectory(Vector3 gestureVector, ref string gestureTrajectory)
		{
			//IL_0001: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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)
			//IL_00d5: 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_0125: 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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			if ((double)gestureVector.y > 0.85)
			{
				gestureTrajectory = "up";
				return;
			}
			if ((double)gestureVector.y < -0.85)
			{
				gestureTrajectory = "down";
				return;
			}
			if (Calcs.GetAngle2D(front, gestureVector) <= 45.0)
			{
				gestureTrajectory = "forward";
				return;
			}
			if (Calcs.GetAngle2D(back, gestureVector) <= 45.0)
			{
				gestureTrajectory = "back";
				return;
			}
			if (Calcs.GetAngle2D(right, gestureVector) <= 45.0)
			{
				gestureTrajectory = "right";
				return;
			}
			if (Calcs.GetAngle2D(left, gestureVector) <= 45.0)
			{
				gestureTrajectory = "left";
				return;
			}
			Log.Warning("NO MOVEMENT RECOGNIZED!");
			Vector3 val = front;
			string? text = ((object)(Vector3)(ref val)).ToString();
			val = gestureVector;
			Log.Warning("VECTORS: " + text + " | " + ((object)(Vector3)(ref val)).ToString());
			Log.Warning("ANGLE BETWEEN FACING DIRECTION AND VECTOR: " + Calcs.GetAngle2D(front, gestureVector));
		}

		public void SetSpeed(Vector3 end)
		{
			//IL_0002: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			speed = Calcs.GetMagnitude3D(end - poses[0].Position) / (double)elapsedTime * 1000000000000.0;
		}

		public void UpdateDeviceInProximity(string vrDevice, int? times)
		{
			devicesInProximity[vrDevice] = times.Value + 1;
		}

		public void AddPose(VRPose pose)
		{
			poses.Add(pose);
		}

		public void CompleteTrace(VRPose end)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = poses[0].Position;
			Vector3 gestureVector = Vector3.Normalize(end.Position - position);
			Vector3 gestureVector2 = Vector3.Normalize(end.Direction * Vector3.forward);
			SetTrajectory(gestureVector, ref movement);
			SetTrajectory(gestureVector2, ref direction);
			SetSpeed(end.Position);
			ElapsedTime = NanoTime();
		}

		private void SetMovementBuckets(Quaternion faceDirection)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: 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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//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_002a: 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)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			front = faceDirection * Vector3.forward;
			back = faceDirection * Vector3.back;
			right = faceDirection * Vector3.right;
			left = faceDirection * Vector3.left;
		}

		private static long NanoTime()
		{
			long num = 10000 * Stopwatch.GetTimestamp();
			num /= 10000;
			return num * 100;
		}
	}
}
namespace VRJester.Core.Recog
{
	public class Recognition
	{
		public Gestures gestures;

		public Recognition(Gestures gestures)
		{
			this.gestures = gestures;
			base..ctor();
		}

		public virtual Dictionary<string, string> Recognize(Gesture gesture)
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			string text = "";
			List<GestureComponent> list = gestures.hmdGestures.Search(gesture.hmdGesture);
			List<GestureComponent> list2 = gestures.rcGestures.Search(gesture.rcGesture);
			List<GestureComponent> list3 = gestures.lcGestures.Search(gesture.lcGesture);
			if (list != null)
			{
				text += list.HashCode();
				gestures.hmdGestureMapping.TryGetValue(list.HashCode(), out var value);
				dictionary["HEAD_MOUNTED_DISPLAY"] = value;
			}
			if (list2 != null)
			{
				text += list2.HashCode();
				gestures.hmdGestureMapping.TryGetValue(list2.HashCode(), out var value2);
				dictionary["RIGHT_CONTROLLER"] = value2;
			}
			if (list3 != null)
			{
				text += list3.HashCode();
				gestures.hmdGestureMapping.TryGetValue(list3.HashCode(), out var value3);
				dictionary["LEFT_CONTROLLER"] = value3;
			}
			gestures.gestureNameSpace.TryGetValue(text, out var value4);
			dictionary["gestureName"] = value4;
			if (GestureHandler.config.DEBUG_MODE)
			{
				DebugLog(gesture, list, list2, list3, text, dictionary);
			}
			return (value4 != null) ? dictionary : new Dictionary<string, string>();
		}

		public virtual void DebugLog(Gesture gesture, List<GestureComponent> foundHmdGesture, List<GestureComponent> foundRcGesture, List<GestureComponent> foundLcGesture, string id, Dictionary<string, string> ctx)
		{
			Log.Debug("TOTAL GESTURES IN NAMESPACE:  " + gestures.gestureNameSpace.Count);
			foreach (KeyValuePair<string, string> item in gestures.gestureNameSpace)
			{
				Log.Debug("ID: " + item.Key + " -> " + item.Value);
			}
			if (gesture.hmdGesture.Any() || gesture.rcGesture.Any() || gesture.lcGesture.Any())
			{
				Log.Debug(gesture);
			}
			if (!ExtensionMethods.IsNullOrDestroyed((object)foundHmdGesture))
			{
				Log.Debug("foundHmdGesture:  " + string.Join(", ", foundHmdGesture));
			}
			if (!ExtensionMethods.IsNullOrDestroyed((object)foundRcGesture))
			{
				Log.Debug("foundRcGesture:  " + string.Join(", ", foundRcGesture));
			}
			if (!ExtensionMethods.IsNullOrDestroyed((object)foundLcGesture))
			{
				Log.Debug("foundLcGesture:  " + string.Join(", ", foundLcGesture));
			}
			if (id != "")
			{
				Log.Debug("RECOGNIZE ID:  " + id);
			}
			if (ctx.Count != 0)
			{
				Log.Debug("RECOGNIZED: " + ctx["gestureName"]);
			}
		}
	}
}
namespace VRJester.Core.Radix
{
	public class Branch
	{
		public List<GestureComponent> gesture;

		public Node next;

		public Branch(List<GestureComponent> gesture, Node next)
		{
			this.gesture = gesture;
			this.next = next;
			base..ctor();
		}

		public Branch(List<GestureComponent> gesture)
			: this(gesture, new Node(isGesture: true))
		{
		}

		public override string ToString()
		{
			return "Branch[gesture=" + string.Join(", ", gesture) + "]";
		}
	}
	internal class MetaData
	{
		internal long elapsedTime;

		internal double speed;

		internal IDictionary<string, int> devicesInProximity;

		protected internal MetaData(long elapsedTime, double speed, IDictionary<string, int> devicesInProximity)
		{
			this.elapsedTime = elapsedTime;
			this.speed = speed;
			this.devicesInProximity = devicesInProximity;
		}

		protected internal virtual bool IsClosestFit(long maxTime, double maxSpeed)
		{
			return ClosestTime(maxTime) && ClosestSpeed(maxSpeed);
		}

		protected internal virtual bool ClosestTime(long maxTime)
		{
			return elapsedTime >= maxTime;
		}

		protected internal virtual bool ClosestSpeed(double maxSpeed)
		{
			return speed >= maxSpeed;
		}
	}
	public class Node
	{
		public bool isGesture;

		public Dictionary<GestureComponent, Branch> paths;

		public Node(bool isGesture)
		{
			this.isGesture = isGesture;
			paths = new Dictionary<GestureComponent, Branch>();
			base..ctor();
		}

		public virtual Branch GetTransition(GestureComponent transitionGestureComponent)
		{
			Branch value;
			return paths.TryGetValue(transitionGestureComponent, out value) ? value : null;
		}

		public virtual void AddGestureComponent(List<GestureComponent> gestureComponent, Node next)
		{
			paths[gestureComponent[0]] = new Branch(gestureComponent, next);
		}

		public virtual int TotalGestureComponent()
		{
			return paths.Count;
		}

		public virtual Branch GetMatchedPath(GestureComponent transitionPath)
		{
			Branch result = null;
			long maxTime = 0L;
			double maxSpeed = 0.0;
			foreach (GestureComponent key in paths.Keys)
			{
				if (key.Matches(transitionPath))
				{
					MetaData metaData = new MetaData(key.ElapsedTime, key.Speed, key.DevicesInProximity);
					if (metaData.IsClosestFit(maxTime, maxSpeed))
					{
						maxTime = key.ElapsedTime;
						maxSpeed = key.Speed;
						result = paths[key];
					}
				}
			}
			return result;
		}

		public override string ToString()
		{
			return "Node[ isGesture=" + isGesture + ", paths=" + paths?.ToString() + "]";
		}
	}
	public class RadixTree
	{
		public string vrDevice;

		private const int NO_MISMATCH = -1;

		public Node root;

		public RadixTree(string vrDevice)
		{
			this.vrDevice = vrDevice;
			root = new Node(isGesture: false);
			base..ctor();
		}

		private int GetFirstMismatchGestureComponent(List<GestureComponent> gesture, List<GestureComponent> edgeGestureComponent)
		{
			int num = Math.Min(gesture.Count, edgeGestureComponent.Count);
			for (int i = 1; i < num; i++)
			{
				if (!gesture[i].Equals(edgeGestureComponent[i]))
				{
					return i;
				}
			}
			return -1;
		}

		public virtual void PrintAllGestures(Dictionary<int, string> gestureMapping)
		{
			PrintAllGestures(root, new List<GestureComponent>(), gestureMapping);
		}

		private void PrintAllGestures(Node current, List<GestureComponent> result, Dictionary<int, string> gestureMapping)
		{
			if (current.isGesture)
			{
				gestureMapping.TryGetValue(result.HashCode(), out var value);
				string text = string.Join(",", result.Select((GestureComponent c) => c.ToString()));
				Log.Info(value + ": " + text);
			}
			foreach (Branch value2 in current.paths.Values)
			{
				PrintAllGestures(value2.next, GestureComponent.Concat(result, value2.gesture), gestureMapping);
			}
		}

		public virtual void PrintAllPaths()
		{
			PrintAllPaths(root, "");
		}

		private void PrintAllPaths(Node current, string indent)
		{
			int num = current.TotalGestureComponent() - 1;
			int num2 = 0;
			foreach (Branch value in current.paths.Values)
			{
				if (num2 == num)
				{
					Log.Info(indent.Replace("+", "L") + string.Join(",", value.gesture));
				}
				else
				{
					Log.Info(indent.Replace("+", "|") + string.Join(",", value.gesture));
				}
				int num3 = ((indent.Length / 2 == 0) ? 4 : (indent.Length / 2));
				int num4 = value.gesture.ToString().Length / 3;
				string text = new string(new char[num3]).Replace("\0", " ");
				string text2 = new string(new char[num4]).Replace("\0", "-");
				string indent2 = text + "+" + text2 + "->";
				num2++;
				PrintAllPaths(value.next, indent2);
			}
		}

		public virtual void Insert(List<GestureComponent> gesture)
		{
			Node next = root;
			int num;
			for (int i = 0; i < gesture.Count; i += num)
			{
				GestureComponent gestureComponent = gesture[i];
				Branch transition = next.GetTransition(gestureComponent);
				List<GestureComponent> range = gesture.GetRange(i, gesture.Count - i);
				if (transition == null)
				{
					next.paths[gestureComponent] = new Branch(range);
					break;
				}
				num = GetFirstMismatchGestureComponent(range, transition.gesture);
				if (num == -1)
				{
					if (range.Count == transition.gesture.Count)
					{
						transition.next.isGesture = true;
						break;
					}
					if (range.Count < transition.gesture.Count)
					{
						List<GestureComponent> range2 = transition.gesture.GetRange(range.Count - 1, range.Count);
						transition.gesture = range;
						Node node = new Node(isGesture: true);
						Node next2 = transition.next;
						transition.next = node;
						node.AddGestureComponent(range2, next2);
						break;
					}
					num = transition.gesture.Count;
				}
				else
				{
					List<GestureComponent> range3 = transition.gesture.GetRange(num, transition.gesture.Count);
					transition.gesture = transition.gesture.GetRange(0, num);
					Node next3 = transition.next;
					transition.next = new Node(isGesture: false);
					transition.next.AddGestureComponent(range3, next3);
				}
				next = transition.next;
			}
		}

		public virtual void Delete(List<GestureComponent> gesture)
		{
			root = Delete(root, gesture);
		}

		private Node Delete(Node current, List<GestureComponent> gesture)
		{
			if (gesture.Count == 0)
			{
				if (current.paths.Count == 0 && current != root)
				{
					return null;
				}
				current.isGesture = false;
				return current;
			}
			GestureComponent gestureComponent = gesture[0];
			Branch transition = current.GetTransition(gestureComponent);
			if (transition == null || !GestureComponent.StartsWith(gesture, transition.gesture))
			{
				return current;
			}
			Node node = Delete(transition.next, gesture.GetRange(transition.gesture.Count, gesture.Count));
			if (node == null)
			{
				current.paths.Remove(gestureComponent);
				if (current.TotalGestureComponent() == 0 && !current.isGesture && current != root)
				{
					return null;
				}
			}
			else if (node.TotalGestureComponent() == 1 && !node.isGesture)
			{
				current.paths.Remove(gestureComponent);
				foreach (Branch value in node.paths.Values)
				{
					current.AddGestureComponent(GestureComponent.Concat(transition.gesture, value.gesture), value.next);
				}
			}
			return current;
		}

		public virtual List<GestureComponent> Search(List<GestureComponent> gesture)
		{
			List<GestureComponent> list = null;
			Node next = root;
			int num = 0;
			while (num < gesture.Count)
			{
				GestureComponent transitionPath = gesture[num];
				Branch matchedPath = next.GetMatchedPath(transitionPath);
				if (matchedPath == null)
				{
					return null;
				}
				List<GestureComponent> range = gesture.GetRange(num, gesture.Count - num);
				if (!GestureComponent.MatchesWith(range, matchedPath.gesture))
				{
					return null;
				}
				num += matchedPath.gesture.Count;
				next = matchedPath.next;
				list = GestureComponent.Concat(list, matchedPath.gesture);
			}
			return list;
		}
	}
}

patchers/VRJesterPatcher.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using Mono.Cecil;

[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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("VRJesterPatcher")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e07bef45b54d27ac35b6fc0daa65970a4b67b019")]
[assembly: AssemblyProduct("VRJesterPatcher")]
[assembly: AssemblyTitle("VRJesterPatcher")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace VRJesterPatcher;

public static class VRJesterPatcher
{
	private static readonly ManualLogSource Logger = Logger.CreateLogSource("VRJesterPatcher");

	internal static string VRPatcherPath => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

	internal static string ManagedPath => Paths.ManagedPath;

	[Obsolete("Should not be used!", true)]
	public static IEnumerable<string> TargetDLLs { get; } = new string[0];


	[Obsolete("Should not be used!", true)]
	public static void Initialize()
	{
		Logger.LogInfo((object)"Checking for VRJester Libraries...");
		string[] fileNames = new string[1] { "WindowsInput.dll" };
		if (CopyFiles(ManagedPath, fileNames, "libs."))
		{
			Logger.LogInfo((object)"Successfully copied VRJester plugins!");
		}
		else
		{
			Logger.LogInfo((object)"VRJester plugins already present");
		}
		Logger.LogInfo((object)"Checking for binding files...");
	}

	private static bool CopyFiles(string destinationPath, string[] fileNames, string embedFolder)
	{
		DirectoryInfo directoryInfo = new DirectoryInfo(destinationPath);
		FileInfo[] files = directoryInfo.GetFiles();
		bool result = false;
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		string name = executingAssembly.GetName().Name;
		foreach (string fileName in fileNames)
		{
			if (Array.Exists(files, (FileInfo file) => fileName == file.Name))
			{
				continue;
			}
			result = true;
			using Stream stream = executingAssembly.GetManifestResourceStream(name + "." + embedFolder + fileName);
			using FileStream destination = new FileStream(Path.Combine(directoryInfo.FullName, fileName), FileMode.Create, FileAccess.ReadWrite, FileShare.Delete);
			Logger.LogInfo((object)("Copying " + fileName));
			stream.CopyTo(destination);
		}
		return result;
	}

	[Obsolete("Should not be used!", true)]
	public static void Patch(AssemblyDefinition ad)
	{
	}
}