diff --git a/lib/BepInEx.dll b/lib/BepInEx.5/BepInEx.dll similarity index 100% rename from lib/BepInEx.dll rename to lib/BepInEx.5/BepInEx.dll diff --git a/lib/MelonLoader.dll b/lib/MelonLoader.dll deleted file mode 100644 index 7ea7b22..0000000 Binary files a/lib/MelonLoader.dll and /dev/null differ diff --git a/lib/MelonLoader/MelonLoader.dll b/lib/MelonLoader/MelonLoader.dll new file mode 100644 index 0000000..133715e Binary files /dev/null and b/lib/MelonLoader/MelonLoader.dll differ diff --git a/src/Core/Input/CursorUnlocker.cs b/src/Core/Input/CursorUnlocker.cs index a76f82b..f8f9e69 100644 --- a/src/Core/Input/CursorUnlocker.cs +++ b/src/Core/Input/CursorUnlocker.cs @@ -7,11 +7,7 @@ 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 { @@ -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; -// } -// } -// } -//} \ No newline at end of file +} \ No newline at end of file diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index 1943a21..f8e329c 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -59,40 +59,25 @@ namespace UnityExplorer // Default delay is 1 second which is usually enough. private static IEnumerator SetupCoroutine() { - float f = Time.realtimeSinceStartup; - float delay = ConfigManager.Startup_Delay_Time.Value; - while (Time.realtimeSinceStartup - f < delay) - yield return null; + 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(); - // 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 - //InspectorManager.Inspect(UIManager.CanvasRoot.gameObject.GetComponent()); - InspectorManager.Inspect(typeof(TestClass)); - //InspectorManager.InspectType(typeof(ReflectionUtility)); - - //var tex = Resources.FindObjectsOfTypeAll()[0]; - //InspectorManager.Inspect(tex); + //InspectorManager.Inspect(typeof(TestClass)); } /// diff --git a/src/ILRepack.targets b/src/ILRepack.targets index 0c368c0..944a663 100644 --- a/src/ILRepack.targets +++ b/src/ILRepack.targets @@ -12,6 +12,8 @@ + + OnLogWarning => MelonLogger.Warning; public Action OnLogError => MelonLogger.Error; - // TEMPORARY - JUST REQUIRED UNTIL ML 0.3.1 RELEASED - public Harmony.HarmonyInstance HarmonyInstance => Instance.Harmony; - public override void OnApplicationStart() { Instance = this; @@ -47,11 +40,6 @@ namespace UnityExplorer ExplorerCore.Init(this); } - //public override void OnUpdate() - //{ - // ExplorerCore.Update(); - //} - public void SetupCursorPatches() { try diff --git a/src/Loader/ML/MelonLoaderConfigHandler.cs b/src/Loader/ML/MelonLoaderConfigHandler.cs index 0ac90e9..0fa3db2 100644 --- a/src/Loader/ML/MelonLoaderConfigHandler.cs +++ b/src/Loader/ML/MelonLoaderConfigHandler.cs @@ -1,154 +1,78 @@ -#if ML -using MelonLoader; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; -using UnityExplorer.Core; -using UnityExplorer.Core.Config; - -// TEMPORARY - JUST REQUIRED UNTIL ML 0.3.1 RELEASED -using MelonLoader.Tomlyn.Model; - -// ML 0.3.1 SUPPORT -//using Tomlet; -//using Tomlet.Models; - -namespace UnityExplorer.Loader.ML -{ - public class MelonLoaderConfigHandler : ConfigHandler - { - internal const string CTG_NAME = "UnityExplorer"; - - internal MelonPreferences_Category prefCategory; - - public override void Init() - { - prefCategory = MelonPreferences.CreateCategory(CTG_NAME, $"{CTG_NAME} Settings"); - - // TEMPORARY - JUST REQUIRED UNTIL ML 0.3.1 RELEASED - try { MelonPreferences.Mapper.RegisterMapper(KeycodeReader, KeycodeWriter); } catch { } - //try { MelonPreferences.Mapper.RegisterMapper(MenuPagesReader, MenuPagesWriter); } catch { } - - // ML 0.3.1 SUPPORT - //try { TomletMain.RegisterMapper(KeycodeWriter, KeycodeReader); } catch { } - } - - public override void LoadConfig() - { - foreach (var entry in ConfigManager.ConfigElements) - { - var key = entry.Key; - if (prefCategory.GetEntry(key) is MelonPreferences_Entry) - { - var config = entry.Value; - config.BoxedValue = config.GetLoaderConfigValue(); - } - } - } - - public override void RegisterConfigElement(ConfigElement config) - { - var entry = prefCategory.CreateEntry(config.Name, config.Value, null, config.IsInternal) as MelonPreferences_Entry; - - entry.OnValueChangedUntyped += () => - { - if ((entry.Value == null && config.Value == null) || config.Value.Equals(entry.Value)) - return; - - config.Value = entry.Value; - }; - } - - public override void SetConfigValue(ConfigElement config, T value) - { - if (prefCategory.GetEntry(config.Name) is MelonPreferences_Entry entry) - { - entry.Value = value; - entry.Save(); - } - } - - public override T GetConfigValue(ConfigElement config) - { - if (prefCategory.GetEntry(config.Name) is MelonPreferences_Entry 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()); - //} - } -} - +#if ML +using MelonLoader; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; +using UnityExplorer.Core; +using UnityExplorer.Core.Config; + +namespace UnityExplorer.Loader.ML +{ + public class MelonLoaderConfigHandler : ConfigHandler + { + internal const string CTG_NAME = "UnityExplorer"; + + internal MelonPreferences_Category prefCategory; + + public override void Init() + { + prefCategory = MelonPreferences.CreateCategory(CTG_NAME, $"{CTG_NAME} Settings"); + } + + public override void LoadConfig() + { + foreach (var entry in ConfigManager.ConfigElements) + { + var key = entry.Key; + if (prefCategory.GetEntry(key) is MelonPreferences_Entry) + { + var config = entry.Value; + config.BoxedValue = config.GetLoaderConfigValue(); + } + } + } + + public override void RegisterConfigElement(ConfigElement config) + { + var entry = prefCategory.CreateEntry(config.Name, config.Value, null, config.IsInternal) as MelonPreferences_Entry; + + entry.OnValueChangedUntyped += () => + { + if ((entry.Value == null && config.Value == null) || config.Value.Equals(entry.Value)) + return; + + config.Value = entry.Value; + }; + } + + public override void SetConfigValue(ConfigElement config, T value) + { + if (prefCategory.GetEntry(config.Name) is MelonPreferences_Entry entry) + { + entry.Value = value; + //entry.Save(); + } + } + + public override T GetConfigValue(ConfigElement config) + { + if (prefCategory.GetEntry(config.Name) is MelonPreferences_Entry entry) + return entry.Value; + + return default; + } + + public override void OnAnyConfigChanged() + { + } + + public override void SaveConfig() + { + MelonPreferences.Save(); + } + } +} + #endif \ No newline at end of file diff --git a/src/UnityExplorer.csproj b/src/UnityExplorer.csproj index 1109f21..697a1f1 100644 --- a/src/UnityExplorer.csproj +++ b/src/UnityExplorer.csproj @@ -10,7 +10,6 @@ 512 true - ..\Release\UnityExplorer.MelonLoader.Il2Cpp\ false @@ -114,7 +113,7 @@ - ..\lib\MelonLoader.dll + ..\lib\MelonLoader\MelonLoader.dll False