Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit fa3a436

Browse files
committed
Cleanup
1 parent ca27d2b commit fa3a436

File tree

2 files changed

+16
-143
lines changed

2 files changed

+16
-143
lines changed

src/Core/Input/CursorUnlocker.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,17 @@ public static void SetupPatches()
166166

167167
PrefixMethod(typeof(EventSystem),
168168
"SetSelectedGameObject",
169-
new Type[] { typeof(GameObject), typeof(BaseEventData) },
170-
new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_EventSystem_SetSelectedGameObject))),
171-
new Type[] { typeof(GameObject), typeof(BaseEventData), typeof(int) });
172169
// some games use a modified version of uGUI that includes this extra int argument on this method.
173-
174-
PrefixMethod(typeof(PointerInputModule),
175-
"ClearSelection",
176-
new Type[] { },
177-
new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_PointerInputModule_ClearSelection))));
170+
new Type[] { typeof(GameObject), typeof(BaseEventData), typeof(int) },
171+
new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_EventSystem_SetSelectedGameObject))),
172+
// most games use these arguments, we'll use them as our "backup".
173+
new Type[] { typeof(GameObject), typeof(BaseEventData) });
174+
175+
//// Not sure if this one is needed.
176+
//PrefixMethod(typeof(PointerInputModule),
177+
// "ClearSelection",
178+
// new Type[0],
179+
// new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_PointerInputModule_ClearSelection))));
178180
}
179181
catch (Exception ex)
180182
{
@@ -222,11 +224,6 @@ private static void PrefixPropertySetter(Type type, string property, HarmonyMeth
222224

223225
// Prevent setting non-UnityExplorer objects as selected when menu is open
224226

225-
public static bool Prefix_PointerInputModule_ClearSelection()
226-
{
227-
return !(UIManager.ShowMenu && UIManager.CanvasRoot);
228-
}
229-
230227
public static bool Prefix_EventSystem_SetSelectedGameObject(GameObject __0)
231228
{
232229
if (!UIManager.ShowMenu || !UIManager.CanvasRoot)
@@ -235,6 +232,11 @@ public static bool Prefix_EventSystem_SetSelectedGameObject(GameObject __0)
235232
return __0 && __0.transform.root.gameObject.GetInstanceID() == UIManager.CanvasRoot.GetInstanceID();
236233
}
237234

235+
//public static bool Prefix_PointerInputModule_ClearSelection()
236+
//{
237+
// return !(UIManager.ShowMenu && UIManager.CanvasRoot);
238+
//}
239+
238240
// Force EventSystem.current to be UnityExplorer's when menu is open
239241

240242
public static void Prefix_EventSystem_set_current(ref EventSystem value)
Lines changed: 1 addition & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#if ML
2-
3-
#if !ML_LEGACY // ML 0.3.1+ config handler
4-
1+
#if ML
52
using MelonLoader;
63
using System;
74
using System.Collections.Generic;
@@ -77,130 +74,4 @@ public override void SaveConfig()
7774
}
7875
}
7976
}
80-
81-
#else // ML 0.3.0 config handler
82-
83-
using MelonLoader;
84-
using MelonLoader.Tomlyn.Model;
85-
using System;
86-
using System.Collections.Generic;
87-
using System.Linq;
88-
using System.Text;
89-
using UnityEngine;
90-
using UnityExplorer.Core;
91-
using UnityExplorer.Core.Config;
92-
93-
namespace UnityExplorer.Loader.ML
94-
{
95-
public class MelonLoaderConfigHandler : ConfigHandler
96-
{
97-
internal const string CTG_NAME = "UnityExplorer";
98-
99-
internal MelonPreferences_Category prefCategory;
100-
101-
public override void Init()
102-
{
103-
prefCategory = MelonPreferences.CreateCategory(CTG_NAME, $"{CTG_NAME} Settings");
104-
105-
try { MelonPreferences.Mapper.RegisterMapper(KeycodeReader, KeycodeWriter); } catch { }
106-
try { MelonPreferences.Mapper.RegisterMapper(AnchorReader, AnchorWriter); } catch { }
107-
}
108-
109-
public override void LoadConfig()
110-
{
111-
foreach (var entry in ConfigManager.ConfigElements)
112-
{
113-
var key = entry.Key;
114-
if (prefCategory.GetEntry(key) is MelonPreferences_Entry)
115-
{
116-
var config = entry.Value;
117-
config.BoxedValue = config.GetLoaderConfigValue();
118-
}
119-
}
120-
}
121-
122-
public override void RegisterConfigElement<T>(ConfigElement<T> config)
123-
{
124-
var entry = prefCategory.CreateEntry(config.Name, config.Value, null, config.IsInternal) as MelonPreferences_Entry<T>;
125-
126-
entry.OnValueChangedUntyped += () =>
127-
{
128-
if ((entry.Value == null && config.Value == null) || config.Value.Equals(entry.Value))
129-
return;
130-
131-
config.Value = entry.Value;
132-
};
133-
}
134-
135-
public override void SetConfigValue<T>(ConfigElement<T> config, T value)
136-
{
137-
if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry)
138-
{
139-
entry.Value = value;
140-
entry.Save();
141-
}
142-
}
143-
144-
public override T GetConfigValue<T>(ConfigElement<T> config)
145-
{
146-
if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry)
147-
return entry.Value;
148-
149-
return default;
150-
}
151-
152-
public override void OnAnyConfigChanged()
153-
{
154-
}
155-
156-
public override void SaveConfig()
157-
{
158-
MelonPreferences.Save();
159-
}
160-
161-
// Enum config handlers
162-
163-
public static KeyCode KeycodeReader(TomlObject value)
164-
{
165-
try
166-
{
167-
KeyCode kc = (KeyCode)Enum.Parse(typeof(KeyCode), (value as TomlString).Value);
168-
169-
if (kc == default)
170-
throw new Exception();
171-
172-
return kc;
173-
}
174-
catch
175-
{
176-
return KeyCode.F7;
177-
}
178-
}
179-
180-
public static TomlObject KeycodeWriter(KeyCode value)
181-
{
182-
return MelonPreferences.Mapper.ToToml(value.ToString());
183-
}
184-
185-
public static UI.UIManager.VerticalAnchor AnchorReader(TomlObject value)
186-
{
187-
try
188-
{
189-
return (UI.UIManager.VerticalAnchor)Enum.Parse(typeof(UI.UIManager.VerticalAnchor), (value as TomlString).Value);
190-
}
191-
catch
192-
{
193-
return UI.UIManager.VerticalAnchor.Top;
194-
}
195-
}
196-
197-
public static TomlObject AnchorWriter(UI.UIManager.VerticalAnchor anchor)
198-
{
199-
return MelonPreferences.Mapper.ToToml(anchor.ToString());
200-
}
201-
}
202-
}
203-
204-
#endif
205-
20677
#endif

0 commit comments

Comments
 (0)