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

Commit 734e45c

Browse files
committed
Remove patching in mod loader classes
1 parent 97838e0 commit 734e45c

File tree

4 files changed

+16
-143
lines changed

4 files changed

+16
-143
lines changed

src/Loader/BIE/ExplorerBepInPlugin.cs

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ public ManualLogSource LogSource
5151
public Action<object> OnLogWarning => LogSource.LogWarning;
5252
public Action<object> OnLogError => LogSource.LogError;
5353

54-
// Init common to Mono and Il2Cpp
55-
internal void UniversalInit()
54+
private void Init()
5655
{
5756
Instance = this;
5857
_configHandler = new BepInExConfigHandler();
@@ -62,57 +61,15 @@ internal void UniversalInit()
6261
#if MONO // Mono
6362
internal void Awake()
6463
{
65-
UniversalInit();
64+
Init();
6665
}
6766

6867
#else // Il2Cpp
6968
public override void Load()
7069
{
71-
UniversalInit();
70+
Init();
7271
}
7372
#endif
74-
75-
public void SetupCursorPatches()
76-
{
77-
try
78-
{
79-
this.HarmonyInstance.PatchAll();
80-
}
81-
catch (Exception ex)
82-
{
83-
ExplorerCore.Log($"Exception setting up Harmony patches:\r\n{ex.ReflectionExToString()}");
84-
}
85-
}
86-
87-
[HarmonyPatch(typeof(EventSystem), "current", MethodType.Setter)]
88-
public class PATCH_EventSystem_current
89-
{
90-
[HarmonyPrefix]
91-
public static void Prefix_EventSystem_set_current(ref EventSystem value)
92-
{
93-
CursorUnlocker.Prefix_EventSystem_set_current(ref value);
94-
}
95-
}
96-
97-
[HarmonyPatch(typeof(Cursor), "lockState", MethodType.Setter)]
98-
public class PATCH_Cursor_lockState
99-
{
100-
[HarmonyPrefix]
101-
public static void Prefix_set_lockState(ref CursorLockMode value)
102-
{
103-
CursorUnlocker.Prefix_set_lockState(ref value);
104-
}
105-
}
106-
107-
[HarmonyPatch(typeof(Cursor), "visible", MethodType.Setter)]
108-
public class PATCH_Cursor_visible
109-
{
110-
[HarmonyPrefix]
111-
public static void Prefix_set_visible(ref bool value)
112-
{
113-
CursorUnlocker.Prefix_set_visible(ref value);
114-
}
115-
}
11673
}
11774
}
11875
#endif

src/Loader/IExplorerLoader.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@ public interface IExplorerLoader
1515
Action<object> OnLogMessage { get; }
1616
Action<object> OnLogWarning { get; }
1717
Action<object> OnLogError { get; }
18-
19-
void SetupCursorPatches();
2018
}
2119
}

src/Loader/ML/ExplorerMelonMod.cs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@
99
using UnityExplorer.Core.Config;
1010
using UnityExplorer.Core.Input;
1111
using UnityExplorer.Loader.ML;
12-
#if ML_LEGACY
13-
using Harmony;
14-
#else
1512
using HarmonyLib;
1613
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.UNIVERSAL)]
17-
#endif
1814

1915
[assembly: MelonInfo(typeof(ExplorerMelonMod), ExplorerCore.NAME, ExplorerCore.VERSION, ExplorerCore.AUTHOR)]
2016
[assembly: MelonGame(null, null)]
@@ -42,45 +38,6 @@ public override void OnApplicationStart()
4238

4339
ExplorerCore.Init(this);
4440
}
45-
46-
public void SetupCursorPatches()
47-
{
48-
try
49-
{
50-
PrefixProperty(typeof(Cursor),
51-
"lockState",
52-
new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_set_lockState))));
53-
54-
PrefixProperty(typeof(Cursor),
55-
"visible",
56-
new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_set_visible))));
57-
58-
PrefixProperty(typeof(EventSystem),
59-
"current",
60-
new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_EventSystem_set_current))));
61-
}
62-
catch (Exception ex)
63-
{
64-
ExplorerCore.Log($"Exception setting up Harmony patches:\r\n{ex.ReflectionExToString()}");
65-
}
66-
}
67-
68-
private void PrefixProperty(Type type, string property, HarmonyMethod prefix)
69-
{
70-
try
71-
{
72-
var prop = type.GetProperty(property);
73-
#if ML_LEGACY
74-
this.Harmony.Patch(prop.GetSetMethod(), prefix: prefix);
75-
#else
76-
HarmonyInstance.Patch(prop.GetSetMethod(), prefix: prefix);
77-
#endif
78-
}
79-
catch (Exception e)
80-
{
81-
ExplorerCore.Log($"Unable to patch {type.Name}.set_{property}: {e.Message}");
82-
}
83-
}
8441
}
8542
}
8643
#endif

src/Loader/STANDALONE/ExplorerStandalone.cs

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ public class ExplorerStandalone : IExplorerLoader
2121
/// Call this to initialize UnityExplorer without adding a log listener.
2222
/// </summary>
2323
/// <returns>The new (or active, if one exists) instance of ExplorerStandalone.</returns>
24-
public static ExplorerStandalone CreateInstance()
25-
=> CreateInstance(null);
24+
public static ExplorerStandalone CreateInstance() => CreateInstance(null);
2625

2726
/// <summary>
2827
/// Call this to initialize UnityExplorer and add a listener for UnityExplorer's log messages.
@@ -34,7 +33,8 @@ public static ExplorerStandalone CreateInstance(Action<string, LogType> logListe
3433
if (Instance != null)
3534
return Instance;
3635

37-
OnLog += logListener;
36+
if (logListener != null)
37+
OnLog += logListener;
3838

3939
var instance = new ExplorerStandalone();
4040
instance.Init();
@@ -58,19 +58,7 @@ public string ExplorerFolder
5858
{
5959
get
6060
{
61-
if (s_explorerFolder == null)
62-
{
63-
s_explorerFolder =
64-
Path.Combine(
65-
Path.GetDirectoryName(
66-
Uri.UnescapeDataString(new Uri(Assembly.GetExecutingAssembly().CodeBase)
67-
.AbsolutePath)),
68-
"UnityExplorer");
69-
70-
if (!Directory.Exists(s_explorerFolder))
71-
Directory.CreateDirectory(s_explorerFolder);
72-
}
73-
61+
CheckExplorerFolder();
7462
return s_explorerFolder;
7563
}
7664
}
@@ -88,45 +76,18 @@ private void Init()
8876
ExplorerCore.Init(this);
8977
}
9078

91-
public void SetupCursorPatches()
92-
{
93-
try
94-
{
95-
this.HarmonyInstance.PatchAll();
96-
}
97-
catch (Exception ex)
98-
{
99-
ExplorerCore.Log($"Exception setting up Harmony patches:\r\n{ex.ReflectionExToString()}");
100-
}
101-
}
102-
103-
[HarmonyPatch(typeof(EventSystem), "current", MethodType.Setter)]
104-
public class PATCH_EventSystem_current
79+
private void CheckExplorerFolder()
10580
{
106-
[HarmonyPrefix]
107-
public static void Prefix_EventSystem_set_current(ref EventSystem value)
81+
if (s_explorerFolder == null)
10882
{
109-
CursorUnlocker.Prefix_EventSystem_set_current(ref value);
110-
}
111-
}
112-
113-
[HarmonyPatch(typeof(Cursor), "lockState", MethodType.Setter)]
114-
public class PATCH_Cursor_lockState
115-
{
116-
[HarmonyPrefix]
117-
public static void Prefix_set_lockState(ref CursorLockMode value)
118-
{
119-
CursorUnlocker.Prefix_set_lockState(ref value);
120-
}
121-
}
83+
s_explorerFolder =
84+
Path.Combine(
85+
Path.GetDirectoryName(
86+
Uri.UnescapeDataString(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath)),
87+
"UnityExplorer");
12288

123-
[HarmonyPatch(typeof(Cursor), "visible", MethodType.Setter)]
124-
public class PATCH_Cursor_visible
125-
{
126-
[HarmonyPrefix]
127-
public static void Prefix_set_visible(ref bool value)
128-
{
129-
CursorUnlocker.Prefix_set_visible(ref value);
89+
if (!Directory.Exists(s_explorerFolder))
90+
Directory.CreateDirectory(s_explorerFolder);
13091
}
13192
}
13293
}

0 commit comments

Comments
 (0)