2021-03-11 17:57:58 +11:00
|
|
|
|
#if ML
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2021-04-02 17:06:49 +11:00
|
|
|
|
using Harmony;
|
2021-03-11 17:57:58 +11:00
|
|
|
|
using MelonLoader;
|
2021-03-30 21:23:45 +11:00
|
|
|
|
using UnityEngine;
|
2021-04-02 17:06:49 +11:00
|
|
|
|
using UnityEngine.EventSystems;
|
2021-03-26 06:38:59 +11:00
|
|
|
|
using UnityExplorer;
|
2021-04-02 17:06:49 +11:00
|
|
|
|
using UnityExplorer.Core;
|
2021-03-30 19:50:04 +11:00
|
|
|
|
using UnityExplorer.Core.Config;
|
2021-04-02 17:06:49 +11:00
|
|
|
|
using UnityExplorer.Core.Input;
|
2021-03-30 19:50:04 +11:00
|
|
|
|
using UnityExplorer.Loader.ML;
|
2021-03-26 06:38:59 +11:00
|
|
|
|
|
|
|
|
|
[assembly: MelonInfo(typeof(ExplorerMelonMod), ExplorerCore.NAME, ExplorerCore.VERSION, ExplorerCore.AUTHOR)]
|
|
|
|
|
[assembly: MelonGame(null, null)]
|
2021-04-09 01:46:26 +10:00
|
|
|
|
//[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.UNIVERSAL)]
|
2021-03-11 17:57:58 +11:00
|
|
|
|
|
|
|
|
|
namespace UnityExplorer
|
|
|
|
|
{
|
|
|
|
|
public class ExplorerMelonMod : MelonMod, IExplorerLoader
|
|
|
|
|
{
|
|
|
|
|
public static ExplorerMelonMod Instance;
|
|
|
|
|
|
|
|
|
|
public string ExplorerFolder => Path.Combine("Mods", ExplorerCore.NAME);
|
|
|
|
|
public string ConfigFolder => ExplorerFolder;
|
|
|
|
|
|
2021-03-30 21:23:45 +11:00
|
|
|
|
public ConfigHandler ConfigHandler => _configHandler;
|
2021-03-30 19:50:04 +11:00
|
|
|
|
public MelonLoaderConfigHandler _configHandler;
|
|
|
|
|
|
|
|
|
|
public Action<object> OnLogMessage => MelonLogger.Msg;
|
|
|
|
|
public Action<object> OnLogWarning => MelonLogger.Warning;
|
|
|
|
|
public Action<object> OnLogError => MelonLogger.Error;
|
2021-03-11 17:57:58 +11:00
|
|
|
|
|
|
|
|
|
public Harmony.HarmonyInstance HarmonyInstance => Instance.Harmony;
|
|
|
|
|
|
|
|
|
|
public override void OnApplicationStart()
|
|
|
|
|
{
|
|
|
|
|
Instance = this;
|
2021-03-30 19:50:04 +11:00
|
|
|
|
_configHandler = new MelonLoaderConfigHandler();
|
2021-03-11 17:57:58 +11:00
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
ExplorerCore.Init(this);
|
2021-03-11 17:57:58 +11:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-01 20:55:14 +10:00
|
|
|
|
//public override void OnUpdate()
|
|
|
|
|
//{
|
|
|
|
|
// ExplorerCore.Update();
|
|
|
|
|
//}
|
2021-04-02 17:06:49 +11:00
|
|
|
|
|
2021-05-01 20:55:14 +10:00
|
|
|
|
public void SetupCursorPatches()
|
2021-04-02 17:06:49 +11:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
this.Harmony.Patch(prop.GetSetMethod(), prefix: prefix);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
ExplorerCore.Log($"Unable to patch {type.Name}.set_{property}: {e.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-11 17:57:58 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|