diff --git a/src/Config/ExplorerConfig.cs b/src/Config/ExplorerConfig.cs index 75dbb75..0784494 100644 --- a/src/Config/ExplorerConfig.cs +++ b/src/Config/ExplorerConfig.cs @@ -25,7 +25,7 @@ namespace UnityExplorer.Config public KeyCode Main_Menu_Toggle = KeyCode.F7; public bool Force_Unlock_Mouse = true; public int Default_Page_Limit = 25; - public string Default_Output_Path = Path.Combine(ExplorerCore.ExplorerFolder, "Output"); + public string Default_Output_Path = Path.Combine(ExplorerCore.EXPLORER_FOLDER, "Output"); public bool Log_Unity_Debug = false; public bool Hide_On_Startup = false; public string Window_Anchors = DEFAULT_WINDOW_ANCHORS; diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index 3d84bf3..ecda7be 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -7,6 +7,7 @@ using UnityExplorer.Config; using UnityExplorer.Helpers; using UnityExplorer.Input; using UnityExplorer.Inspectors; +using UnityExplorer.Runtime; using UnityExplorer.UI; using UnityExplorer.UI.Modules; @@ -21,17 +22,16 @@ namespace UnityExplorer public static ExplorerCore Instance { get; private set; } - private static IExplorerLoader s_loader; - public static IExplorerLoader Loader => s_loader + public static IExplorerLoader Loader => #if ML - ?? (s_loader = ExplorerMelonMod.Instance); + ExplorerMelonMod.Instance; #elif BIE - ?? (s_loader = ExplorerBepInPlugin.Instance); + ExplorerBepInPlugin.Instance; #elif STANDALONE - ?? (s_loader = ExplorerStandalone.Instance); + ExplorerStandalone.Instance; #endif - public static string ExplorerFolder => Loader.ExplorerFolder; + public static string EXPLORER_FOLDER => Loader.ExplorerFolder; public ExplorerCore() { @@ -43,19 +43,16 @@ namespace UnityExplorer Instance = this; -#if CPP - ReflectionHelpers.TryLoadGameModules(); -#endif + RuntimeProvider.Init(); - if (!Directory.Exists(ExplorerFolder)) - Directory.CreateDirectory(ExplorerFolder); + if (!Directory.Exists(EXPLORER_FOLDER)) + Directory.CreateDirectory(EXPLORER_FOLDER); ExplorerConfig.OnLoad(); InputManager.Init(); - ForceUnlockCursor.Init(); - SetupEvents(); + ForceUnlockCursor.Init(); UIManager.ShowMenu = true; @@ -72,33 +69,7 @@ namespace UnityExplorer UIManager.Update(); } - private void SetupEvents() - { -#if CPP - try - { - Application.add_logMessageReceived(new Action(OnUnityLog)); - - SceneManager.add_sceneLoaded(new Action((Scene a, LoadSceneMode b) => { OnSceneLoaded(); })); - SceneManager.add_activeSceneChanged(new Action((Scene a, Scene b) => { OnSceneLoaded(); })); - } - catch - { - // exceptions here are non-fatal, just ignore. - } -#else - Application.logMessageReceived += OnUnityLog; - SceneManager.sceneLoaded += (Scene a, LoadSceneMode b) => { OnSceneLoaded(); }; - SceneManager.activeSceneChanged += (Scene a, Scene b) => { OnSceneLoaded(); }; -#endif - } - - internal void OnSceneLoaded() - { - UIManager.OnSceneChange(); - } - - private void OnUnityLog(string message, string stackTrace, LogType type) + public void OnUnityLog(string message, string stackTrace, LogType type) { if (!DebugConsole.LogUnity) return; diff --git a/src/Helpers/EventHelper.cs b/src/Helpers/EventHelper.cs deleted file mode 100644 index 375ebee..0000000 --- a/src/Helpers/EventHelper.cs +++ /dev/null @@ -1,33 +0,0 @@ -#if CPP -using System; -using UnityEngine.Events; - -namespace UnityExplorer.Helpers -{ - // Possibly temporary, just so Il2Cpp can do the same style "AddListener" as Mono. - // Just saves me having a preprocessor directive for every single AddListener. - - public static class EventHelper - { - public static void AddListener(this UnityEvent action, Action listener) - { - action.AddListener(listener); - } - - public static void AddListener(this UnityEvent action, Action listener) - { - action.AddListener(listener); - } - - public static void AddListener(this UnityEvent action, Action listener) - { - action.AddListener(listener); - } - - public static void AddListener(this UnityEvent action, Action listener) - { - action.AddListener(listener); - } - } -} -#endif \ No newline at end of file diff --git a/src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs b/src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs index 6087e03..b51f43e 100644 --- a/src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs +++ b/src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs @@ -35,7 +35,7 @@ namespace UnityExplorer.Inspectors.Reflection else if (typeof(Enum).IsAssignableFrom(type)) { // NET 3.5 doesn't have "GetCustomAttribute", gotta use the multiple version. - if (type.GetCustomAttributes(typeof(FlagsAttribute), true) is object[] fa && fa.Length > 0) + if (type.GetCustomAttributes(typeof(FlagsAttribute), true) is object[] fa && fa.Any()) return typeof(InteractiveFlags); else return typeof(InteractiveEnum); diff --git a/src/Inspectors/SceneExplorer.cs b/src/Inspectors/SceneExplorer.cs index 514286f..35d124b 100644 --- a/src/Inspectors/SceneExplorer.cs +++ b/src/Inspectors/SceneExplorer.cs @@ -96,11 +96,11 @@ namespace UnityExplorer.Inspectors } } - internal void OnSceneChange() - { - m_sceneDropdown.OnCancel(null); - RefreshSceneSelector(); - } + //internal void OnSceneChange() + //{ + // m_sceneDropdown.OnCancel(null); + // RefreshSceneSelector(); + //} private void RefreshSceneSelector() { @@ -138,8 +138,11 @@ namespace UnityExplorer.Inspectors if (anyChange) { + m_sceneDropdown.OnCancel(null); m_sceneDropdownText.text = newNames[0]; SetTargetScene(newScenes[0]); + + SearchPage.Instance.OnSceneChange(); } m_currentScenes = newScenes.ToArray(); diff --git a/src/Loader/ExplorerMelonMod.cs b/src/Loader/ExplorerMelonMod.cs index 05ee943..d859cf3 100644 --- a/src/Loader/ExplorerMelonMod.cs +++ b/src/Loader/ExplorerMelonMod.cs @@ -30,10 +30,10 @@ namespace UnityExplorer ExplorerCore.Update(); } - public override void OnSceneWasLoaded(int buildIndex, string sceneName) - { - ExplorerCore.Instance.OnSceneLoaded(); - } + //public override void OnSceneWasLoaded(int buildIndex, string sceneName) + //{ + // ExplorerCore.Instance.OnSceneLoaded(); + //} } } #endif \ No newline at end of file diff --git a/src/Runtime/Il2Cpp/Il2CppProvider.cs b/src/Runtime/Il2Cpp/Il2CppProvider.cs new file mode 100644 index 0000000..76c9119 --- /dev/null +++ b/src/Runtime/Il2Cpp/Il2CppProvider.cs @@ -0,0 +1,47 @@ +#if CPP +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; +using UnityEngine.Events; +using UnityEngine.SceneManagement; +using UnityExplorer.Helpers; + +namespace UnityExplorer.Runtime.Il2Cpp +{ + public class Il2CppProvider : RuntimeProvider + { + public override void Initialize() + { + ReflectionHelpers.TryLoadGameModules(); + } + + public override void SetupEvents() + { + Application.add_logMessageReceived( + new Action(ExplorerCore.Instance.OnUnityLog)); + + //SceneManager.add_sceneLoaded( + // new Action(ExplorerCore.Instance.OnSceneLoaded1)); + + //SceneManager.add_activeSceneChanged( + // new Action(ExplorerCore.Instance.OnSceneLoaded2)); + } + } +} + +public static class UnityEventExtensions +{ + public static void AddListener(this UnityEvent action, Action listener) + { + action.AddListener(listener); + } + + public static void AddListener(this UnityEvent action, Action listener) + { + action.AddListener(listener); + } +} + +#endif \ No newline at end of file diff --git a/src/Runtime/Mono/MonoProvider.cs b/src/Runtime/Mono/MonoProvider.cs new file mode 100644 index 0000000..b50d608 --- /dev/null +++ b/src/Runtime/Mono/MonoProvider.cs @@ -0,0 +1,26 @@ +#if MONO +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; +using UnityEngine.SceneManagement; + +namespace UnityExplorer.Runtime.Mono +{ + public class MonoProvider : RuntimeProvider + { + public override void Initialize() + { + } + + public override void SetupEvents() + { + Application.logMessageReceived += ExplorerCore.Instance.OnUnityLog; + //SceneManager.sceneLoaded += ExplorerCore.Instance.OnSceneLoaded1; + //SceneManager.activeSceneChanged += ExplorerCore.Instance.OnSceneLoaded2; + } + } +} + +#endif \ No newline at end of file diff --git a/src/Runtime/RuntimeProvider.cs b/src/Runtime/RuntimeProvider.cs new file mode 100644 index 0000000..157aea4 --- /dev/null +++ b/src/Runtime/RuntimeProvider.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UnityExplorer.Runtime +{ + // Work in progress, this will be used to replace all the "if CPP / if MONO" + // pre-processor directives all over the codebase. + + public abstract class RuntimeProvider + { + public static RuntimeProvider Instance; + + public RuntimeProvider() + { + Initialize(); + + SetupEvents(); + } + + public static void Init() => +#if CPP + Instance = new Il2Cpp.Il2CppProvider(); +#else + Instance = new Mono.MonoProvider(); +#endif + + + public abstract void Initialize(); + + public abstract void SetupEvents(); + + } +} diff --git a/src/Tests/Tests.cs b/src/Tests/Tests.cs index 7846676..d5abf2d 100644 --- a/src/Tests/Tests.cs +++ b/src/Tests/Tests.cs @@ -198,12 +198,12 @@ namespace UnityExplorer.Tests } } - public static string TestRefInOutGeneric(ref string arg0, in int arg1, out string arg2) where T : Component - { - arg2 = "this is arg2"; + //public static string TestRefInOutGeneric(ref string arg0, in int arg1, out string arg2) where T : Component + //{ + // arg2 = "this is arg2"; - return $"T: '{typeof(T).FullName}', ref arg0: '{arg0}', in arg1: '{arg1}', out arg2: '{arg2}'"; - } + // return $"T: '{typeof(T).FullName}', ref arg0: '{arg0}', in arg1: '{arg1}', out arg2: '{arg2}'"; + //} // test a non-generic dictionary diff --git a/src/UI/Modules/DebugConsole.cs b/src/UI/Modules/DebugConsole.cs index f025855..6f84a76 100644 --- a/src/UI/Modules/DebugConsole.cs +++ b/src/UI/Modules/DebugConsole.cs @@ -52,7 +52,7 @@ namespace UnityExplorer.UI.Modules //if (!SaveToDisk) // return; - var path = ExplorerCore.ExplorerFolder + @"\Logs"; + var path = ExplorerCore.EXPLORER_FOLDER + @"\Logs"; if (!Directory.Exists(path)) Directory.CreateDirectory(path); diff --git a/src/UI/Modules/SearchPage.cs b/src/UI/Modules/SearchPage.cs index f071ab8..c66c16f 100644 --- a/src/UI/Modules/SearchPage.cs +++ b/src/UI/Modules/SearchPage.cs @@ -109,6 +109,9 @@ namespace UnityExplorer.UI.Modules private void RefreshResultList() { + if (m_resultListPageHandler == null || m_results == null) + return; + m_resultListPageHandler.ListCount = m_results.Length; int newCount = 0; diff --git a/src/UI/UIManager.cs b/src/UI/UIManager.cs index 0c62ce4..caee6e1 100644 --- a/src/UI/UIManager.cs +++ b/src/UI/UIManager.cs @@ -99,11 +99,11 @@ namespace UnityExplorer.UI ForceUnlockCursor.UpdateCursorControl(); } - public static void OnSceneChange() - { - SceneExplorer.Instance?.OnSceneChange(); - SearchPage.Instance?.OnSceneChange(); - } + //public static void OnSceneChange() + //{ + // SceneExplorer.Instance?.OnSceneChange(); + // SearchPage.Instance?.OnSceneChange(); + //} public static void Update() {