mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-17 14:37:49 +08:00
Remove patching in mod loader classes
This commit is contained in:
parent
97838e0b3a
commit
734e45cf9f
@ -51,8 +51,7 @@ namespace UnityExplorer
|
|||||||
public Action<object> OnLogWarning => LogSource.LogWarning;
|
public Action<object> OnLogWarning => LogSource.LogWarning;
|
||||||
public Action<object> OnLogError => LogSource.LogError;
|
public Action<object> OnLogError => LogSource.LogError;
|
||||||
|
|
||||||
// Init common to Mono and Il2Cpp
|
private void Init()
|
||||||
internal void UniversalInit()
|
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
_configHandler = new BepInExConfigHandler();
|
_configHandler = new BepInExConfigHandler();
|
||||||
@ -62,57 +61,15 @@ namespace UnityExplorer
|
|||||||
#if MONO // Mono
|
#if MONO // Mono
|
||||||
internal void Awake()
|
internal void Awake()
|
||||||
{
|
{
|
||||||
UniversalInit();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // Il2Cpp
|
#else // Il2Cpp
|
||||||
public override void Load()
|
public override void Load()
|
||||||
{
|
{
|
||||||
UniversalInit();
|
Init();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public void SetupCursorPatches()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.HarmonyInstance.PatchAll();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
ExplorerCore.Log($"Exception setting up Harmony patches:\r\n{ex.ReflectionExToString()}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(EventSystem), "current", MethodType.Setter)]
|
|
||||||
public class PATCH_EventSystem_current
|
|
||||||
{
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void Prefix_EventSystem_set_current(ref EventSystem value)
|
|
||||||
{
|
|
||||||
CursorUnlocker.Prefix_EventSystem_set_current(ref value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(Cursor), "lockState", MethodType.Setter)]
|
|
||||||
public class PATCH_Cursor_lockState
|
|
||||||
{
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void Prefix_set_lockState(ref CursorLockMode value)
|
|
||||||
{
|
|
||||||
CursorUnlocker.Prefix_set_lockState(ref value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(Cursor), "visible", MethodType.Setter)]
|
|
||||||
public class PATCH_Cursor_visible
|
|
||||||
{
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void Prefix_set_visible(ref bool value)
|
|
||||||
{
|
|
||||||
CursorUnlocker.Prefix_set_visible(ref value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
@ -15,7 +15,5 @@ namespace UnityExplorer
|
|||||||
Action<object> OnLogMessage { get; }
|
Action<object> OnLogMessage { get; }
|
||||||
Action<object> OnLogWarning { get; }
|
Action<object> OnLogWarning { get; }
|
||||||
Action<object> OnLogError { get; }
|
Action<object> OnLogError { get; }
|
||||||
|
|
||||||
void SetupCursorPatches();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,8 @@ using UnityExplorer.Core;
|
|||||||
using UnityExplorer.Core.Config;
|
using UnityExplorer.Core.Config;
|
||||||
using UnityExplorer.Core.Input;
|
using UnityExplorer.Core.Input;
|
||||||
using UnityExplorer.Loader.ML;
|
using UnityExplorer.Loader.ML;
|
||||||
#if ML_LEGACY
|
|
||||||
using Harmony;
|
|
||||||
#else
|
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.UNIVERSAL)]
|
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.UNIVERSAL)]
|
||||||
#endif
|
|
||||||
|
|
||||||
[assembly: MelonInfo(typeof(ExplorerMelonMod), ExplorerCore.NAME, ExplorerCore.VERSION, ExplorerCore.AUTHOR)]
|
[assembly: MelonInfo(typeof(ExplorerMelonMod), ExplorerCore.NAME, ExplorerCore.VERSION, ExplorerCore.AUTHOR)]
|
||||||
[assembly: MelonGame(null, null)]
|
[assembly: MelonGame(null, null)]
|
||||||
@ -42,45 +38,6 @@ namespace UnityExplorer
|
|||||||
|
|
||||||
ExplorerCore.Init(this);
|
ExplorerCore.Init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetupCursorPatches()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
PrefixProperty(typeof(Cursor),
|
|
||||||
"lockState",
|
|
||||||
new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_set_lockState))));
|
|
||||||
|
|
||||||
PrefixProperty(typeof(Cursor),
|
|
||||||
"visible",
|
|
||||||
new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_set_visible))));
|
|
||||||
|
|
||||||
PrefixProperty(typeof(EventSystem),
|
|
||||||
"current",
|
|
||||||
new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_EventSystem_set_current))));
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
ExplorerCore.Log($"Exception setting up Harmony patches:\r\n{ex.ReflectionExToString()}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void PrefixProperty(Type type, string property, HarmonyMethod prefix)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var prop = type.GetProperty(property);
|
|
||||||
#if ML_LEGACY
|
|
||||||
this.Harmony.Patch(prop.GetSetMethod(), prefix: prefix);
|
|
||||||
#else
|
|
||||||
HarmonyInstance.Patch(prop.GetSetMethod(), prefix: prefix);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
ExplorerCore.Log($"Unable to patch {type.Name}.set_{property}: {e.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
@ -21,8 +21,7 @@ namespace UnityExplorer
|
|||||||
/// Call this to initialize UnityExplorer without adding a log listener.
|
/// Call this to initialize UnityExplorer without adding a log listener.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The new (or active, if one exists) instance of ExplorerStandalone.</returns>
|
/// <returns>The new (or active, if one exists) instance of ExplorerStandalone.</returns>
|
||||||
public static ExplorerStandalone CreateInstance()
|
public static ExplorerStandalone CreateInstance() => CreateInstance(null);
|
||||||
=> CreateInstance(null);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Call this to initialize UnityExplorer and add a listener for UnityExplorer's log messages.
|
/// Call this to initialize UnityExplorer and add a listener for UnityExplorer's log messages.
|
||||||
@ -34,7 +33,8 @@ namespace UnityExplorer
|
|||||||
if (Instance != null)
|
if (Instance != null)
|
||||||
return Instance;
|
return Instance;
|
||||||
|
|
||||||
OnLog += logListener;
|
if (logListener != null)
|
||||||
|
OnLog += logListener;
|
||||||
|
|
||||||
var instance = new ExplorerStandalone();
|
var instance = new ExplorerStandalone();
|
||||||
instance.Init();
|
instance.Init();
|
||||||
@ -58,19 +58,7 @@ namespace UnityExplorer
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (s_explorerFolder == null)
|
CheckExplorerFolder();
|
||||||
{
|
|
||||||
s_explorerFolder =
|
|
||||||
Path.Combine(
|
|
||||||
Path.GetDirectoryName(
|
|
||||||
Uri.UnescapeDataString(new Uri(Assembly.GetExecutingAssembly().CodeBase)
|
|
||||||
.AbsolutePath)),
|
|
||||||
"UnityExplorer");
|
|
||||||
|
|
||||||
if (!Directory.Exists(s_explorerFolder))
|
|
||||||
Directory.CreateDirectory(s_explorerFolder);
|
|
||||||
}
|
|
||||||
|
|
||||||
return s_explorerFolder;
|
return s_explorerFolder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,45 +76,18 @@ namespace UnityExplorer
|
|||||||
ExplorerCore.Init(this);
|
ExplorerCore.Init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetupCursorPatches()
|
private void CheckExplorerFolder()
|
||||||
{
|
{
|
||||||
try
|
if (s_explorerFolder == null)
|
||||||
{
|
{
|
||||||
this.HarmonyInstance.PatchAll();
|
s_explorerFolder =
|
||||||
}
|
Path.Combine(
|
||||||
catch (Exception ex)
|
Path.GetDirectoryName(
|
||||||
{
|
Uri.UnescapeDataString(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath)),
|
||||||
ExplorerCore.Log($"Exception setting up Harmony patches:\r\n{ex.ReflectionExToString()}");
|
"UnityExplorer");
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(EventSystem), "current", MethodType.Setter)]
|
if (!Directory.Exists(s_explorerFolder))
|
||||||
public class PATCH_EventSystem_current
|
Directory.CreateDirectory(s_explorerFolder);
|
||||||
{
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void Prefix_EventSystem_set_current(ref EventSystem value)
|
|
||||||
{
|
|
||||||
CursorUnlocker.Prefix_EventSystem_set_current(ref value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(Cursor), "lockState", MethodType.Setter)]
|
|
||||||
public class PATCH_Cursor_lockState
|
|
||||||
{
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void Prefix_set_lockState(ref CursorLockMode value)
|
|
||||||
{
|
|
||||||
CursorUnlocker.Prefix_set_lockState(ref value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(Cursor), "visible", MethodType.Setter)]
|
|
||||||
public class PATCH_Cursor_visible
|
|
||||||
{
|
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void Prefix_set_visible(ref bool value)
|
|
||||||
{
|
|
||||||
CursorUnlocker.Prefix_set_visible(ref value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user