diff --git a/src/Core/Input/CursorUnlocker.cs b/src/Core/Input/CursorUnlocker.cs index c72590d..bb23dbc 100644 --- a/src/Core/Input/CursorUnlocker.cs +++ b/src/Core/Input/CursorUnlocker.cs @@ -166,15 +166,17 @@ namespace UnityExplorer.Core.Input PrefixMethod(typeof(EventSystem), "SetSelectedGameObject", - new Type[] { typeof(GameObject), typeof(BaseEventData) }, - new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_EventSystem_SetSelectedGameObject))), - new Type[] { typeof(GameObject), typeof(BaseEventData), typeof(int) }); // some games use a modified version of uGUI that includes this extra int argument on this method. + new Type[] { typeof(GameObject), typeof(BaseEventData), typeof(int) }, + new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_EventSystem_SetSelectedGameObject))), + // most games use these arguments, we'll use them as our "backup". + new Type[] { typeof(GameObject), typeof(BaseEventData) }); - PrefixMethod(typeof(PointerInputModule), - "ClearSelection", - new Type[] { }, - new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_PointerInputModule_ClearSelection)))); + //// Not sure if this one is needed. + //PrefixMethod(typeof(PointerInputModule), + // "ClearSelection", + // new Type[0], + // new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_PointerInputModule_ClearSelection)))); } catch (Exception ex) { @@ -222,11 +224,6 @@ namespace UnityExplorer.Core.Input // Prevent setting non-UnityExplorer objects as selected when menu is open - public static bool Prefix_PointerInputModule_ClearSelection() - { - return !(UIManager.ShowMenu && UIManager.CanvasRoot); - } - public static bool Prefix_EventSystem_SetSelectedGameObject(GameObject __0) { if (!UIManager.ShowMenu || !UIManager.CanvasRoot) @@ -235,6 +232,11 @@ namespace UnityExplorer.Core.Input return __0 && __0.transform.root.gameObject.GetInstanceID() == UIManager.CanvasRoot.GetInstanceID(); } + //public static bool Prefix_PointerInputModule_ClearSelection() + //{ + // return !(UIManager.ShowMenu && UIManager.CanvasRoot); + //} + // Force EventSystem.current to be UnityExplorer's when menu is open public static void Prefix_EventSystem_set_current(ref EventSystem value) diff --git a/src/Loader/ML/MelonLoaderConfigHandler.cs b/src/Loader/ML/MelonLoaderConfigHandler.cs index 3a8bbf0..2f6ca3a 100644 --- a/src/Loader/ML/MelonLoaderConfigHandler.cs +++ b/src/Loader/ML/MelonLoaderConfigHandler.cs @@ -1,7 +1,4 @@ -#if ML - -#if !ML_LEGACY // ML 0.3.1+ config handler - +#if ML using MelonLoader; using System; using System.Collections.Generic; @@ -77,130 +74,4 @@ namespace UnityExplorer.Loader.ML } } } - -#else // ML 0.3.0 config handler - -using MelonLoader; -using MelonLoader.Tomlyn.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; -using UnityExplorer.Core; -using UnityExplorer.Core.Config; - -namespace UnityExplorer.Loader.ML -{ - public class MelonLoaderConfigHandler : ConfigHandler - { - internal const string CTG_NAME = "UnityExplorer"; - - internal MelonPreferences_Category prefCategory; - - public override void Init() - { - prefCategory = MelonPreferences.CreateCategory(CTG_NAME, $"{CTG_NAME} Settings"); - - try { MelonPreferences.Mapper.RegisterMapper(KeycodeReader, KeycodeWriter); } catch { } - try { MelonPreferences.Mapper.RegisterMapper(AnchorReader, AnchorWriter); } catch { } - } - - public override void LoadConfig() - { - foreach (var entry in ConfigManager.ConfigElements) - { - var key = entry.Key; - if (prefCategory.GetEntry(key) is MelonPreferences_Entry) - { - var config = entry.Value; - config.BoxedValue = config.GetLoaderConfigValue(); - } - } - } - - public override void RegisterConfigElement(ConfigElement config) - { - var entry = prefCategory.CreateEntry(config.Name, config.Value, null, config.IsInternal) as MelonPreferences_Entry; - - entry.OnValueChangedUntyped += () => - { - if ((entry.Value == null && config.Value == null) || config.Value.Equals(entry.Value)) - return; - - config.Value = entry.Value; - }; - } - - public override void SetConfigValue(ConfigElement config, T value) - { - if (prefCategory.GetEntry(config.Name) is MelonPreferences_Entry entry) - { - entry.Value = value; - entry.Save(); - } - } - - public override T GetConfigValue(ConfigElement config) - { - if (prefCategory.GetEntry(config.Name) is MelonPreferences_Entry entry) - return entry.Value; - - return default; - } - - public override void OnAnyConfigChanged() - { - } - - public override void SaveConfig() - { - MelonPreferences.Save(); - } - - // Enum config handlers - - public static KeyCode KeycodeReader(TomlObject value) - { - try - { - KeyCode kc = (KeyCode)Enum.Parse(typeof(KeyCode), (value as TomlString).Value); - - if (kc == default) - throw new Exception(); - - return kc; - } - catch - { - return KeyCode.F7; - } - } - - public static TomlObject KeycodeWriter(KeyCode value) - { - return MelonPreferences.Mapper.ToToml(value.ToString()); - } - - public static UI.UIManager.VerticalAnchor AnchorReader(TomlObject value) - { - try - { - return (UI.UIManager.VerticalAnchor)Enum.Parse(typeof(UI.UIManager.VerticalAnchor), (value as TomlString).Value); - } - catch - { - return UI.UIManager.VerticalAnchor.Top; - } - } - - public static TomlObject AnchorWriter(UI.UIManager.VerticalAnchor anchor) - { - return MelonPreferences.Mapper.ToToml(anchor.ToString()); - } - } -} - -#endif - #endif \ No newline at end of file