starting work on a cleanup/rewrite

This commit is contained in:
Sinai 2021-03-16 18:12:39 +11:00
parent 9665753dc8
commit 9e996816ef
13 changed files with 147 additions and 95 deletions

View File

@ -25,7 +25,7 @@ namespace UnityExplorer.Config
public KeyCode Main_Menu_Toggle = KeyCode.F7; public KeyCode Main_Menu_Toggle = KeyCode.F7;
public bool Force_Unlock_Mouse = true; public bool Force_Unlock_Mouse = true;
public int Default_Page_Limit = 25; 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 Log_Unity_Debug = false;
public bool Hide_On_Startup = false; public bool Hide_On_Startup = false;
public string Window_Anchors = DEFAULT_WINDOW_ANCHORS; public string Window_Anchors = DEFAULT_WINDOW_ANCHORS;

View File

@ -7,6 +7,7 @@ using UnityExplorer.Config;
using UnityExplorer.Helpers; using UnityExplorer.Helpers;
using UnityExplorer.Input; using UnityExplorer.Input;
using UnityExplorer.Inspectors; using UnityExplorer.Inspectors;
using UnityExplorer.Runtime;
using UnityExplorer.UI; using UnityExplorer.UI;
using UnityExplorer.UI.Modules; using UnityExplorer.UI.Modules;
@ -21,17 +22,16 @@ namespace UnityExplorer
public static ExplorerCore Instance { get; private set; } public static ExplorerCore Instance { get; private set; }
private static IExplorerLoader s_loader; public static IExplorerLoader Loader =>
public static IExplorerLoader Loader => s_loader
#if ML #if ML
?? (s_loader = ExplorerMelonMod.Instance); ExplorerMelonMod.Instance;
#elif BIE #elif BIE
?? (s_loader = ExplorerBepInPlugin.Instance); ExplorerBepInPlugin.Instance;
#elif STANDALONE #elif STANDALONE
?? (s_loader = ExplorerStandalone.Instance); ExplorerStandalone.Instance;
#endif #endif
public static string ExplorerFolder => Loader.ExplorerFolder; public static string EXPLORER_FOLDER => Loader.ExplorerFolder;
public ExplorerCore() public ExplorerCore()
{ {
@ -43,19 +43,16 @@ namespace UnityExplorer
Instance = this; Instance = this;
#if CPP RuntimeProvider.Init();
ReflectionHelpers.TryLoadGameModules();
#endif
if (!Directory.Exists(ExplorerFolder)) if (!Directory.Exists(EXPLORER_FOLDER))
Directory.CreateDirectory(ExplorerFolder); Directory.CreateDirectory(EXPLORER_FOLDER);
ExplorerConfig.OnLoad(); ExplorerConfig.OnLoad();
InputManager.Init(); InputManager.Init();
ForceUnlockCursor.Init();
SetupEvents(); ForceUnlockCursor.Init();
UIManager.ShowMenu = true; UIManager.ShowMenu = true;
@ -72,33 +69,7 @@ namespace UnityExplorer
UIManager.Update(); UIManager.Update();
} }
private void SetupEvents() public void OnUnityLog(string message, string stackTrace, LogType type)
{
#if CPP
try
{
Application.add_logMessageReceived(new Action<string, string, LogType>(OnUnityLog));
SceneManager.add_sceneLoaded(new Action<Scene, LoadSceneMode>((Scene a, LoadSceneMode b) => { OnSceneLoaded(); }));
SceneManager.add_activeSceneChanged(new Action<Scene, Scene>((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)
{ {
if (!DebugConsole.LogUnity) if (!DebugConsole.LogUnity)
return; return;

View File

@ -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<T>(this UnityEvent<T> action, Action<T> listener)
{
action.AddListener(listener);
}
public static void AddListener<T0, T1>(this UnityEvent<T0, T1> action, Action<T0, T1> listener)
{
action.AddListener(listener);
}
public static void AddListener<T0, T1, T2>(this UnityEvent<T0, T1, T2> action, Action<T0, T1, T2> listener)
{
action.AddListener(listener);
}
}
}
#endif

View File

@ -35,7 +35,7 @@ namespace UnityExplorer.Inspectors.Reflection
else if (typeof(Enum).IsAssignableFrom(type)) else if (typeof(Enum).IsAssignableFrom(type))
{ {
// NET 3.5 doesn't have "GetCustomAttribute", gotta use the multiple version. // 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); return typeof(InteractiveFlags);
else else
return typeof(InteractiveEnum); return typeof(InteractiveEnum);

View File

@ -96,11 +96,11 @@ namespace UnityExplorer.Inspectors
} }
} }
internal void OnSceneChange() //internal void OnSceneChange()
{ //{
m_sceneDropdown.OnCancel(null); // m_sceneDropdown.OnCancel(null);
RefreshSceneSelector(); // RefreshSceneSelector();
} //}
private void RefreshSceneSelector() private void RefreshSceneSelector()
{ {
@ -138,8 +138,11 @@ namespace UnityExplorer.Inspectors
if (anyChange) if (anyChange)
{ {
m_sceneDropdown.OnCancel(null);
m_sceneDropdownText.text = newNames[0]; m_sceneDropdownText.text = newNames[0];
SetTargetScene(newScenes[0]); SetTargetScene(newScenes[0]);
SearchPage.Instance.OnSceneChange();
} }
m_currentScenes = newScenes.ToArray(); m_currentScenes = newScenes.ToArray();

View File

@ -30,10 +30,10 @@ namespace UnityExplorer
ExplorerCore.Update(); ExplorerCore.Update();
} }
public override void OnSceneWasLoaded(int buildIndex, string sceneName) //public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{ //{
ExplorerCore.Instance.OnSceneLoaded(); // ExplorerCore.Instance.OnSceneLoaded();
} //}
} }
} }
#endif #endif

View File

@ -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<string, string, LogType>(ExplorerCore.Instance.OnUnityLog));
//SceneManager.add_sceneLoaded(
// new Action<Scene, LoadSceneMode>(ExplorerCore.Instance.OnSceneLoaded1));
//SceneManager.add_activeSceneChanged(
// new Action<Scene, Scene>(ExplorerCore.Instance.OnSceneLoaded2));
}
}
}
public static class UnityEventExtensions
{
public static void AddListener(this UnityEvent action, Action listener)
{
action.AddListener(listener);
}
public static void AddListener<T>(this UnityEvent<T> action, Action<T> listener)
{
action.AddListener(listener);
}
}
#endif

View File

@ -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

View File

@ -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();
}
}

View File

@ -198,12 +198,12 @@ namespace UnityExplorer.Tests
} }
} }
public static string TestRefInOutGeneric<T>(ref string arg0, in int arg1, out string arg2) where T : Component //public static string TestRefInOutGeneric<T>(ref string arg0, in int arg1, out string arg2) where T : Component
{ //{
arg2 = "this is arg2"; // 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 // test a non-generic dictionary

View File

@ -52,7 +52,7 @@ namespace UnityExplorer.UI.Modules
//if (!SaveToDisk) //if (!SaveToDisk)
// return; // return;
var path = ExplorerCore.ExplorerFolder + @"\Logs"; var path = ExplorerCore.EXPLORER_FOLDER + @"\Logs";
if (!Directory.Exists(path)) if (!Directory.Exists(path))
Directory.CreateDirectory(path); Directory.CreateDirectory(path);

View File

@ -109,6 +109,9 @@ namespace UnityExplorer.UI.Modules
private void RefreshResultList() private void RefreshResultList()
{ {
if (m_resultListPageHandler == null || m_results == null)
return;
m_resultListPageHandler.ListCount = m_results.Length; m_resultListPageHandler.ListCount = m_results.Length;
int newCount = 0; int newCount = 0;

View File

@ -99,11 +99,11 @@ namespace UnityExplorer.UI
ForceUnlockCursor.UpdateCursorControl(); ForceUnlockCursor.UpdateCursorControl();
} }
public static void OnSceneChange() //public static void OnSceneChange()
{ //{
SceneExplorer.Instance?.OnSceneChange(); // SceneExplorer.Instance?.OnSceneChange();
SearchPage.Instance?.OnSceneChange(); // SearchPage.Instance?.OnSceneChange();
} //}
public static void Update() public static void Update()
{ {