using ABI_RC.Core.InteractionSystem; using cohtml; using System; using System.Collections.Generic; using UnityEngine; namespace ml_lme { static class Settings { public enum LeapTrackingMode { Screentop = 0, Desktop, HMD } enum ModSetting { Enabled, DesktopX, DesktopY, DesktopZ, FingersOnly, Model, Mode, AngleX, AngleY, AngleZ, Head, HeadX, HeadY, HeadZ, TrackElbows, Input, InteractThreadhold, GripThreadhold }; static bool ms_enabled = false; static Vector3 ms_desktopOffset = new Vector3(0f, -0.45f, 0.3f); static bool ms_fingersOnly = false; static bool ms_modelVisibility = false; static LeapTrackingMode ms_trackingMode = LeapTrackingMode.Desktop; static Vector3 ms_rootAngle = Vector3.zero; static bool ms_headAttach = false; static Vector3 ms_headOffset = new Vector3(0f, -0.3f, 0.15f); static bool ms_trackElbows = true; static bool ms_input = true; static float ms_interactThreadhold = 0.8f; static float ms_gripThreadhold = 0.4f; static MelonLoader.MelonPreferences_Category ms_category = null; static List ms_entries = null; static public event Action EnabledChange; static public event Action DesktopOffsetChange; static public event Action FingersOnlyChange; static public event Action ModelVisibilityChange; static public event Action TrackingModeChange; static public event Action RootAngleChange; static public event Action HeadAttachChange; static public event Action HeadOffsetChange; static public event Action TrackElbowsChange; static public event Action InputChange; static public event Action InteractThreadholdChange; static public event Action GripThreadholdChange; internal static void Init() { ms_category = MelonLoader.MelonPreferences.CreateCategory("LME"); ms_entries = new List() { ms_category.CreateEntry(ModSetting.Enabled.ToString(), ms_enabled), ms_category.CreateEntry(ModSetting.DesktopX.ToString(), 0), ms_category.CreateEntry(ModSetting.DesktopY.ToString(), -45), ms_category.CreateEntry(ModSetting.DesktopZ.ToString(), 30), ms_category.CreateEntry(ModSetting.FingersOnly.ToString(), ms_modelVisibility), ms_category.CreateEntry(ModSetting.Model.ToString(), ms_modelVisibility), ms_category.CreateEntry(ModSetting.Mode.ToString(), (int)ms_trackingMode), ms_category.CreateEntry(ModSetting.AngleX.ToString(), 0), ms_category.CreateEntry(ModSetting.AngleY.ToString(), 0), ms_category.CreateEntry(ModSetting.AngleZ.ToString(), 0), ms_category.CreateEntry(ModSetting.Head.ToString(), ms_headAttach), ms_category.CreateEntry(ModSetting.HeadX.ToString(), 0), ms_category.CreateEntry(ModSetting.HeadY.ToString(), -30), ms_category.CreateEntry(ModSetting.HeadZ.ToString(), 15), ms_category.CreateEntry(ModSetting.TrackElbows.ToString(), true), ms_category.CreateEntry(ModSetting.Input.ToString(), true), ms_category.CreateEntry(ModSetting.InteractThreadhold.ToString(), 80), ms_category.CreateEntry(ModSetting.GripThreadhold.ToString(), 40), }; Load(); MelonLoader.MelonCoroutines.Start(WaitMainMenuUi()); } static System.Collections.IEnumerator WaitMainMenuUi() { while(ViewManager.Instance == null) yield return null; while(ViewManager.Instance.gameMenuView == null) yield return null; while(ViewManager.Instance.gameMenuView.Listener == null) yield return null; ViewManager.Instance.gameMenuView.Listener.ReadyForBindings += () => { ViewManager.Instance.gameMenuView.View.BindCall("MelonMod_LME_Call_InpToggle", new Action(OnToggleUpdate)); ViewManager.Instance.gameMenuView.View.BindCall("MelonMod_LME_Call_InpSlider", new Action(OnSliderUpdate)); ViewManager.Instance.gameMenuView.View.BindCall("MelonMod_LME_Call_InpDropdown", new Action(OnDropdownUpdate)); }; ViewManager.Instance.gameMenuView.Listener.FinishLoad += (_) => { ViewManager.Instance.gameMenuView.View.ExecuteScript(Scripts.GetEmbeddedScript("menu.js")); foreach(var l_entry in ms_entries) ViewManager.Instance.gameMenuView.View.TriggerEvent("updateModSettingLME", l_entry.DisplayName, l_entry.GetValueAsString()); }; } static void Load() { ms_enabled = (bool)ms_entries[(int)ModSetting.Enabled].BoxedValue; ms_desktopOffset = new Vector3( (int)ms_entries[(int)ModSetting.DesktopX].BoxedValue, (int)ms_entries[(int)ModSetting.DesktopY].BoxedValue, (int)ms_entries[(int)ModSetting.DesktopZ].BoxedValue ) * 0.01f; ms_fingersOnly = (bool)ms_entries[(int)ModSetting.FingersOnly].BoxedValue; ms_modelVisibility = (bool)ms_entries[(int)ModSetting.Model].BoxedValue; ms_trackingMode = (LeapTrackingMode)(int)ms_entries[(int)ModSetting.Mode].BoxedValue; ms_rootAngle = new Vector3( (int)ms_entries[(int)ModSetting.AngleX].BoxedValue, (int)ms_entries[(int)ModSetting.AngleY].BoxedValue, (int)ms_entries[(int)ModSetting.AngleZ].BoxedValue ); ms_headAttach = (bool)ms_entries[(int)ModSetting.Head].BoxedValue; ms_headOffset = new Vector3( (int)ms_entries[(int)ModSetting.HeadX].BoxedValue, (int)ms_entries[(int)ModSetting.HeadY].BoxedValue, (int)ms_entries[(int)ModSetting.HeadZ].BoxedValue ) * 0.01f; ms_trackElbows = (bool)ms_entries[(int)ModSetting.TrackElbows].BoxedValue; ms_input = (bool)ms_entries[(int)ModSetting.Input].BoxedValue; ms_interactThreadhold = (int)ms_entries[(int)ModSetting.InteractThreadhold].BoxedValue * 0.01f; ms_gripThreadhold = (int)ms_entries[(int)ModSetting.GripThreadhold].BoxedValue * 0.01f; } static void OnToggleUpdate(string p_name, string p_value) { if(Enum.TryParse(p_name, out ModSetting l_setting)) { switch(l_setting) { case ModSetting.Enabled: { ms_enabled = bool.Parse(p_value); EnabledChange?.Invoke(ms_enabled); } break; case ModSetting.FingersOnly: { ms_fingersOnly = bool.Parse(p_value); FingersOnlyChange?.Invoke(ms_fingersOnly); } break; case ModSetting.Model: { ms_modelVisibility = bool.Parse(p_value); ModelVisibilityChange?.Invoke(ms_modelVisibility); } break; case ModSetting.Head: { ms_headAttach = bool.Parse(p_value); HeadAttachChange?.Invoke(ms_headAttach); } break; case ModSetting.TrackElbows: { ms_trackElbows = bool.Parse(p_value); TrackElbowsChange?.Invoke(ms_trackElbows); } break; case ModSetting.Input: { ms_input = bool.Parse(p_value); InputChange?.Invoke(ms_input); } break; } ms_entries[(int)l_setting].BoxedValue = bool.Parse(p_value); } } static void OnSliderUpdate(string p_name, string p_value) { if(Enum.TryParse(p_name, out ModSetting l_setting)) { switch(l_setting) { case ModSetting.DesktopX: { ms_desktopOffset.x = int.Parse(p_value) * 0.01f; DesktopOffsetChange?.Invoke(ms_desktopOffset); } break; case ModSetting.DesktopY: { ms_desktopOffset.y = int.Parse(p_value) * 0.01f; DesktopOffsetChange?.Invoke(ms_desktopOffset); } break; case ModSetting.DesktopZ: { ms_desktopOffset.z = int.Parse(p_value) * 0.01f; DesktopOffsetChange?.Invoke(ms_desktopOffset); } break; case ModSetting.AngleX: { ms_rootAngle.x = int.Parse(p_value); RootAngleChange?.Invoke(ms_rootAngle); } break; case ModSetting.AngleY: { ms_rootAngle.y = int.Parse(p_value); RootAngleChange?.Invoke(ms_rootAngle); } break; case ModSetting.AngleZ: { ms_rootAngle.z = int.Parse(p_value); RootAngleChange?.Invoke(ms_rootAngle); } break; case ModSetting.HeadX: { ms_headOffset.x = int.Parse(p_value) * 0.01f; HeadOffsetChange?.Invoke(ms_headOffset); } break; case ModSetting.HeadY: { ms_headOffset.y = int.Parse(p_value) * 0.01f; HeadOffsetChange?.Invoke(ms_headOffset); } break; case ModSetting.HeadZ: { ms_headOffset.z = int.Parse(p_value) * 0.01f; HeadOffsetChange?.Invoke(ms_headOffset); } break; case ModSetting.InteractThreadhold: { ms_interactThreadhold = int.Parse(p_value) * 0.01f; InteractThreadholdChange?.Invoke(ms_interactThreadhold); } break; case ModSetting.GripThreadhold: { ms_gripThreadhold = int.Parse(p_value) * 0.01f; GripThreadholdChange?.Invoke(ms_gripThreadhold); } break; } ms_entries[(int)l_setting].BoxedValue = int.Parse(p_value); } } static void OnDropdownUpdate(string p_name, string p_value) { if(Enum.TryParse(p_name, out ModSetting l_setting)) { switch(l_setting) { case ModSetting.Mode: { ms_trackingMode = (LeapTrackingMode)int.Parse(p_value); TrackingModeChange?.Invoke(ms_trackingMode); } break; } ms_entries[(int)l_setting].BoxedValue = int.Parse(p_value); } } public static bool Enabled { get => ms_enabled; } public static Vector3 DesktopOffset { get => ms_desktopOffset; } public static bool FingersOnly { get => ms_fingersOnly; } public static bool ModelVisibility { get => ms_modelVisibility; } public static LeapTrackingMode TrackingMode { get => ms_trackingMode; } public static Vector3 RootAngle { get => ms_rootAngle; } public static bool HeadAttach { get => ms_headAttach; } public static Vector3 HeadOffset { get => ms_headOffset; } public static bool TrackElbows { get => ms_trackElbows; } public static bool Input { get => ms_input; } public static float InteractThreadhold { get => ms_interactThreadhold; } public static float GripThreadhold { get => ms_gripThreadhold; } } }