Cleanup libs, target ML 0.3.1

This commit is contained in:
Sinai 2021-05-11 20:23:52 +10:00
parent 7241247d05
commit a9f6ed8729
9 changed files with 97 additions and 397 deletions

Binary file not shown.

Binary file not shown.

View File

@ -7,11 +7,7 @@ using UnityExplorer.Core.Config;
using UnityExplorer.Core; using UnityExplorer.Core;
using UnityExplorer.UI; using UnityExplorer.UI;
using System.Collections; using System.Collections;
#if ML
using Harmony;
#else
using HarmonyLib; using HarmonyLib;
#endif
namespace UnityExplorer.Core.Input namespace UnityExplorer.Core.Input
{ {
@ -215,198 +211,4 @@ namespace UnityExplorer.Core.Input
} }
} }
} }
} }
// Was rewriting but something broke, not looking into it right now.
//using System;
//using UnityEngine;
//using UnityEngine.EventSystems;
//using UnityExplorer.Core.Input;
//using BF = System.Reflection.BindingFlags;
//using UnityExplorer.Core.Config;
//using UnityExplorer.Core;
//using UnityExplorer.UI;
//using System.Collections;
//#if ML
//using Harmony;
//#else
//using HarmonyLib;
//#endif
//namespace UnityExplorer.Core.Input
//{
// public class CursorUnlocker
// {
// public static bool Unlock
// {
// get => unlock;
// set
// {
// unlock = value;
// UpdateCursorControl();
// }
// }
// private static bool unlock;
// public static bool ShouldActuallyUnlock => UIManager.ShowMenu && Unlock;
// private static CursorLockMode lastLockMode;
// private static bool lastVisibleState;
// private static bool currentlySetting = false;
// private static Type CursorType
// => cursorType
// ?? (cursorType = ReflectionUtility.GetTypeByName("UnityEngine.Cursor"));
// private static Type cursorType;
// public static void Init()
// {
// SetupPatches();
// UpdateCursorControl();
// Unlock = ConfigManager.Force_Unlock_Mouse.Value;
// ConfigManager.Force_Unlock_Mouse.OnValueChanged += (bool val) => { Unlock = val; };
// if (ConfigManager.Aggressive_Force_Unlock.Value)
// RuntimeProvider.Instance.StartCoroutine(ForceUnlockCoroutine());
// }
// private static readonly WaitForEndOfFrame _waitForEndOfFrame = new WaitForEndOfFrame();
// private static IEnumerator ForceUnlockCoroutine()
// {
// while (true)
// {
// yield return _waitForEndOfFrame;
// UpdateCursorControl();
// }
// }
// public static void UpdateCursorControl()
// {
// currentlySetting = true;
// if (ShouldActuallyUnlock)
// {
// if (Cursor.lockState != CursorLockMode.None)
// Cursor.lockState = CursorLockMode.None;
// if (!Cursor.visible)
// Cursor.visible = true;
// SetEventSystem();
// }
// else
// {
// if (Cursor.lockState != lastLockMode)
// Cursor.lockState = lastLockMode;
// if (Cursor.visible != lastVisibleState)
// Cursor.visible = lastVisibleState;
// ReleaseEventSystem();
// }
// currentlySetting = false;
// }
// // Event system overrides
// private static bool m_settingEventSystem;
// private static EventSystem m_lastEventSystem;
// private static BaseInputModule m_lastInputModule;
// public static void SetEventSystem()
// {
// if (InputManager.CurrentType == InputType.InputSystem
// || !UIManager.EventSys
// || EventSystem.current == UIManager.EventSys)
// return;
// if (EventSystem.current && EventSystem.current != UIManager.EventSys)
// {
// m_lastEventSystem = EventSystem.current;
// m_lastEventSystem.enabled = false;
// }
// // Set to our current system
// m_settingEventSystem = true;
// UIManager.EventSys.enabled = true;
// EventSystem.current = UIManager.EventSys;
// InputManager.ActivateUIModule();
// m_settingEventSystem = false;
// }
// public static void ReleaseEventSystem()
// {
// if (InputManager.CurrentType == InputType.InputSystem
// || !UIManager.EventSys
// || EventSystem.current != UIManager.EventSys
// || !m_lastEventSystem)
// return;
// if (m_lastEventSystem.gameObject.activeInHierarchy)
// {
// m_lastEventSystem.enabled = true;
// m_settingEventSystem = true;
// EventSystem.current = m_lastEventSystem;
// m_lastInputModule?.ActivateModule();
// m_settingEventSystem = false;
// }
// }
// // Patches
// private static void SetupPatches()
// {
// if (CursorType == null)
// throw new Exception("Could not load Type 'UnityEngine.Cursor'!");
// lastLockMode = Cursor.lockState;
// lastVisibleState = Cursor.visible;
// // Let mod loader handle actual patching (only necessary until ML 0.3.1)
// ExplorerCore.Loader.SetupCursorPatches();
// }
// public static void Prefix_EventSystem_set_current(ref EventSystem value)
// {
// if (!m_settingEventSystem && value != UIManager.EventSys)
// {
// m_lastEventSystem = value;
// m_lastInputModule = value?.currentInputModule;
// if (ShouldActuallyUnlock)
// {
// value = UIManager.EventSys;
// value.enabled = true;
// }
// }
// }
// public static void Prefix_set_lockState(ref CursorLockMode value)
// {
// if (!currentlySetting)
// {
// lastLockMode = value;
// if (ShouldActuallyUnlock)
// value = CursorLockMode.None;
// }
// }
// public static void Prefix_set_visible(ref bool value)
// {
// if (!currentlySetting)
// {
// lastVisibleState = value;
// if (ShouldActuallyUnlock)
// value = true;
// }
// }
// }
//}

View File

@ -59,40 +59,25 @@ namespace UnityExplorer
// Default delay is 1 second which is usually enough. // Default delay is 1 second which is usually enough.
private static IEnumerator SetupCoroutine() private static IEnumerator SetupCoroutine()
{ {
float f = Time.realtimeSinceStartup; yield return null;
float delay = ConfigManager.Startup_Delay_Time.Value;
while (Time.realtimeSinceStartup - f < delay)
yield return null;
Log($"Creating UI, after delay of {delay} second(s)."); float start = Time.realtimeSinceStartup;
float delay = ConfigManager.Startup_Delay_Time.Value;
while (delay > 0)
{
float diff = Math.Max(Time.deltaTime, Time.realtimeSinceStartup - start);
delay -= diff;
yield return null;
}
Log($"Creating UI, after delay of {ConfigManager.Startup_Delay_Time.Value} second(s).");
UIManager.InitUI(); UIManager.InitUI();
// TEMP DEBUG TEST FOR TRANSFORM TREE
var stressTest = new GameObject("StressTest");
for (int i = 0; i < 100; i++)
{
var obj = new GameObject($"Parent_{i}");
obj.transform.parent = stressTest.transform;
for (int j = 0; j < 100; j++)
{
var obj2 = new GameObject($"Child_{j}");
obj2.transform.parent = obj.transform;
}
}
// long name object
new GameObject(new string('#', 500));
// END // END
//InspectorManager.Inspect(UIManager.CanvasRoot.gameObject.GetComponent<GraphicRaycaster>()); //InspectorManager.Inspect(typeof(TestClass));
InspectorManager.Inspect(typeof(TestClass));
//InspectorManager.InspectType(typeof(ReflectionUtility));
//var tex = Resources.FindObjectsOfTypeAll<Texture2D>()[0];
//InspectorManager.Inspect(tex);
} }
/// <summary> /// <summary>

View File

@ -12,6 +12,8 @@
<ReferenceFolders Include="..\lib\HarmonyX\Harmony\bin\Release\net35\" /> <ReferenceFolders Include="..\lib\HarmonyX\Harmony\bin\Release\net35\" />
<ReferenceFolders Include="..\lib\BepInEx.6.IL2CPP\" /> <ReferenceFolders Include="..\lib\BepInEx.6.IL2CPP\" />
<ReferenceFolders Include="..\lib\BepInEx.6.Mono\" /> <ReferenceFolders Include="..\lib\BepInEx.6.Mono\" />
<ReferenceFolders Include="..\lib\BepInEx.5\" />
<ReferenceFolders Include="..\lib\MelonLoader\" />
</ItemGroup> </ItemGroup>
<ILRepack <ILRepack
Parallel="true" Parallel="true"

View File

@ -9,16 +9,12 @@ 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;
using HarmonyLib;
// TEMPORARY - JUST REQUIRED UNTIL ML 0.3.1 RELEASED
using Harmony;
// ML 0.3.1 SUPPORT
//using HarmonyLib;
[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)]
//[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.UNIVERSAL)] [assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.UNIVERSAL)]
[assembly: MelonColor(ConsoleColor.DarkCyan)]
namespace UnityExplorer namespace UnityExplorer
{ {
@ -36,9 +32,6 @@ namespace UnityExplorer
public Action<object> OnLogWarning => MelonLogger.Warning; public Action<object> OnLogWarning => MelonLogger.Warning;
public Action<object> OnLogError => MelonLogger.Error; public Action<object> OnLogError => MelonLogger.Error;
// TEMPORARY - JUST REQUIRED UNTIL ML 0.3.1 RELEASED
public Harmony.HarmonyInstance HarmonyInstance => Instance.Harmony;
public override void OnApplicationStart() public override void OnApplicationStart()
{ {
Instance = this; Instance = this;
@ -47,11 +40,6 @@ namespace UnityExplorer
ExplorerCore.Init(this); ExplorerCore.Init(this);
} }
//public override void OnUpdate()
//{
// ExplorerCore.Update();
//}
public void SetupCursorPatches() public void SetupCursorPatches()
{ {
try try

View File

@ -1,154 +1,78 @@
#if ML #if ML
using MelonLoader; using MelonLoader;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using UnityEngine; using UnityEngine;
using UnityExplorer.Core; using UnityExplorer.Core;
using UnityExplorer.Core.Config; using UnityExplorer.Core.Config;
// TEMPORARY - JUST REQUIRED UNTIL ML 0.3.1 RELEASED namespace UnityExplorer.Loader.ML
using MelonLoader.Tomlyn.Model; {
public class MelonLoaderConfigHandler : ConfigHandler
// ML 0.3.1 SUPPORT {
//using Tomlet; internal const string CTG_NAME = "UnityExplorer";
//using Tomlet.Models;
internal MelonPreferences_Category prefCategory;
namespace UnityExplorer.Loader.ML
{ public override void Init()
public class MelonLoaderConfigHandler : ConfigHandler {
{ prefCategory = MelonPreferences.CreateCategory(CTG_NAME, $"{CTG_NAME} Settings");
internal const string CTG_NAME = "UnityExplorer"; }
internal MelonPreferences_Category prefCategory; public override void LoadConfig()
{
public override void Init() foreach (var entry in ConfigManager.ConfigElements)
{ {
prefCategory = MelonPreferences.CreateCategory(CTG_NAME, $"{CTG_NAME} Settings"); var key = entry.Key;
if (prefCategory.GetEntry(key) is MelonPreferences_Entry)
// TEMPORARY - JUST REQUIRED UNTIL ML 0.3.1 RELEASED {
try { MelonPreferences.Mapper.RegisterMapper(KeycodeReader, KeycodeWriter); } catch { } var config = entry.Value;
//try { MelonPreferences.Mapper.RegisterMapper(MenuPagesReader, MenuPagesWriter); } catch { } config.BoxedValue = config.GetLoaderConfigValue();
}
// ML 0.3.1 SUPPORT }
//try { TomletMain.RegisterMapper(KeycodeWriter, KeycodeReader); } catch { } }
}
public override void RegisterConfigElement<T>(ConfigElement<T> config)
public override void LoadConfig() {
{ var entry = prefCategory.CreateEntry(config.Name, config.Value, null, config.IsInternal) as MelonPreferences_Entry<T>;
foreach (var entry in ConfigManager.ConfigElements)
{ entry.OnValueChangedUntyped += () =>
var key = entry.Key; {
if (prefCategory.GetEntry(key) is MelonPreferences_Entry) if ((entry.Value == null && config.Value == null) || config.Value.Equals(entry.Value))
{ return;
var config = entry.Value;
config.BoxedValue = config.GetLoaderConfigValue(); config.Value = entry.Value;
} };
} }
}
public override void SetConfigValue<T>(ConfigElement<T> config, T value)
public override void RegisterConfigElement<T>(ConfigElement<T> config) {
{ if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry)
var entry = prefCategory.CreateEntry(config.Name, config.Value, null, config.IsInternal) as MelonPreferences_Entry<T>; {
entry.Value = value;
entry.OnValueChangedUntyped += () => //entry.Save();
{ }
if ((entry.Value == null && config.Value == null) || config.Value.Equals(entry.Value)) }
return;
public override T GetConfigValue<T>(ConfigElement<T> config)
config.Value = entry.Value; {
}; if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry)
} return entry.Value;
public override void SetConfigValue<T>(ConfigElement<T> config, T value) return default;
{ }
if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry)
{ public override void OnAnyConfigChanged()
entry.Value = value; {
entry.Save(); }
}
} public override void SaveConfig()
{
public override T GetConfigValue<T>(ConfigElement<T> config) MelonPreferences.Save();
{ }
if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry) }
return entry.Value; }
return default;
}
public override void OnAnyConfigChanged()
{
}
public override void SaveConfig()
{
MelonPreferences.Save();
}
// TEMPORARY - JUST REQUIRED UNTIL ML 0.3.1 RELEASED
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());
}
// ML 0.3.1 SUPPORT
/*
public static TomlValue KeycodeWriter(KeyCode value) => TomletMain.ValueFrom(value.ToString());
public static KeyCode KeycodeReader(TomlValue value)
{
try
{
KeyCode kc = (KeyCode)Enum.Parse(typeof(KeyCode), value.StringValue);
if (kc == default)
throw new Exception();
return kc;
}
catch { }
return KeyCode.F7;
}
*/
//public static UI.Main.MenuPages MenuPagesReader(TomlObject value)
//{
// try
// {
// var kc = (UI.Main.MenuPages)Enum.Parse(typeof(UI.Main.MenuPages), (value as TomlString).Value);
// if (kc == default)
// throw new Exception();
// return kc;
// }
// catch
// {
// return UI.Main.MenuPages.Home;
// }
//}
//public static TomlObject MenuPagesWriter(UI.Main.MenuPages value)
//{
// return MelonPreferences.Mapper.ToToml(value.ToString());
//}
}
}
#endif #endif

View File

@ -10,7 +10,6 @@
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
<OutputPath>..\Release\UnityExplorer.MelonLoader.Il2Cpp\</OutputPath>
<DefineConstants> <DefineConstants>
</DefineConstants> </DefineConstants>
<IsCpp>false</IsCpp> <IsCpp>false</IsCpp>
@ -114,7 +113,7 @@
<!-- MelonLoader refs --> <!-- MelonLoader refs -->
<ItemGroup Condition="'$(IsMelonLoader)'=='true'"> <ItemGroup Condition="'$(IsMelonLoader)'=='true'">
<Reference Include="MelonLoader"> <Reference Include="MelonLoader">
<HintPath>..\lib\MelonLoader.dll</HintPath> <HintPath>..\lib\MelonLoader\MelonLoader.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
</ItemGroup> </ItemGroup>